Commit f462da82 authored by José Luis  Gutiérrez's avatar José Luis Gutiérrez Committed by Alessandro Rubini

www: updating network setup to dotconfig & adding date to dotconfig backupfile

Network setup now uses dotconfig file instead of
/etc/network/interfaces. It supports now DHCP Only, DHCP Once and Static
IP.
After any change in the network configuration the WRS reboots. This
shall be changed when the proper script performs this action properly.
In functions.php, checking, adding and deleting "pairs" in dotconfig
have been developed to make it easier for the configuration of different
services.
Dotconfig backup file includes the current date of the backup file.

New and improved help messages have been added.
parent 19eb6fbf
......@@ -183,7 +183,7 @@ $WRS_FORMS = Array(
vname => "ethip",
),
NETWORK_SETUP_01 => Array(
key => "CONFIG_ETH0_NETMASK",
key => "CONFIG_ETH0_MASK",
name => NETMASK,
value => $_SESSION["WRS_INFO"][NETMASK],
vname => "ethnetmask",
......
......@@ -146,7 +146,7 @@ function wrs_main_info(){
$format = "table";
$section = "WRS_TABLE_INFO";
$subsection = "DASHBOARD";
print_info($section, $subsection, $formatID, $class, $infoname, $format);
// Print dinamic stuff (PPSi status, WR Date, SNMP Server & NTP)
......@@ -347,9 +347,12 @@ function check_monit_status(){
function wrs_interface_setup(){
$interfaces = shell_exec('cat '.$GLOBALS['interfacesfile'].' | grep dhcp');
return (strcmp($interfaces[0],"#")) ? "dhcp" : "static";
//return (!empty($_SESSION["KCONFIG"]["CONFIG_ETH0_DHCP"])) ? "dhcp" : "static"; /* for dotconfig */
if(!empty($_SESSION["KCONFIG"]["CONFIG_ETH0_DHCP"]))
return "dhcponly";
else if (!empty($_SESSION["KCONFIG"]["CONFIG_ETH0_DHCP_ONCE"]))
return "dhcponce";
else
return "static";
}
/*
* It checks whether the filesystem is writable or not.
......@@ -705,10 +708,10 @@ function wrs_management(){
} else if (!empty($_FILES['kconfig']['name'])){
$uploaddir = $GLOBALS['etcdir'];
$uploadfile = $uploaddir . basename($_FILES['kconfig']['name']);
$uploadfile = $uploaddir.$GLOBALS['kconfigfilename'];
echo '<pre>';
if (($_FILES['kconfig']['name']==$GLOBALS['kconfigfilename']) && move_uploaded_file($_FILES['kconfig']['tmp_name'], $uploadfile)) {
echo "<center>File is valid, and was successfully uploaded to ".$GLOBALS['etcdir']." folder. Applying changes\n";
if (move_uploaded_file($_FILES['kconfig']['tmp_name'], $uploadfile)) {
echo "<center>File is valid, and was successfully uploaded to ".$GLOBALS['etcdir']." folder. Applying changes and rebooting\n";
sleep(1);
wrs_reboot();
} else {
......@@ -720,8 +723,9 @@ function wrs_management(){
} else if (!strcmp($cmd, "Backup")){
//Prepare backup
$backupfile=$GLOBALS['kconfigfilename'];
shell_exec("cd ".$GLOBALS['etcdir']."; cp ".$backupfile." /var/www/download/".$backupfile);
$date = date('Ymd-His');
$backupfile="wrs-".$GLOBALS['kconfigfilename'].$date.".backup";
shell_exec("cd ".$GLOBALS['etcdir']."; cp ".$GLOBALS['kconfigfilename']." /var/www/download/".$backupfile);
$backupfile="/download/$backupfile";
//Download the file
......@@ -769,9 +773,7 @@ function wrs_management(){
header('Location: management.php');
}
}
/**
......@@ -1046,22 +1048,47 @@ function wrs_display_help($help_id, $name){
} else if (!strcmp($help_id, "network")){
$message = "<br><b>Set a DHCP network interface configuration or a static one.</b>";
$message .= "<br><b>If you set a static configuration, you have to define: </b>";
$message = "<br><b>Set a DHCP network interface configuration or a static one for the management port.</b>";
$message .= "<br><b>DHCP only will always try to get an IP address using DHCP. DHCP + Static will try only one time to get an IP address using DHCP, in case it fails, it will
use a static configuration given by the user. For the static option no DHCP action is performed.</b>";
$message .= "<br><b>If you set a Static configuration or DHCP + Static, you have to define: </b>";
$message .= "<br><b><ul><li>IP Address --> IP Address of your switch</b></li>";
$message .= "<br><b><li>Netmask --> Netmask</b></li>";
$message .= "<br><b><li>Network--> IP Address of your network</b></li>";
$message .= "<br><b><li>Broadcast --> Broadcast address</b></li>";
$message .= "<br><b><li>Gateway--> Gateway of the switch network</b></li></ul>";
$message .= "<br><br><b>NOTE: This network configuration only works for NAND-flashed switches. If you are using a NFS server, the configurtion is set by default in busybox and it is not possible to be changed.</b>";
$message .= "<br><br><b>NOTE: This network configuration only works for NAND-flashed switches. If you are using a NFS server, the configuration is set by default in busybox and it is not possible to be changed.</b>";
} else if (!strcmp($help_id, "firmware")){
$message = "<p>Firmware features: <br>
- <b>Flash firmware</b>: It flashes a new firmware to the switch. Do it under your own risk.<br>
</p>";
} else if (!strcmp($help_id, "auxclk")){
$message = "<p>Aux. Clock configuration: <br>
- <b>Please refer to the WRS manual to configure correctly this feature.<br>
$message = "<p>Aux. Clock configuration: <br>";
$message .= "These are the parameters of a clock signal generated on the
clk2 SMC connector.";
$message .= "By default wrs auxclk is called by init scripts to generate 10MHz clock signal with 50% duty
cycle. This configuration can be modified by using various options:";
$message .= "<br><b><ul><li> freq <f> --> Desired frequency of the generated clock signal in MHz. Available range from 4kHz
to 250MHz.</b></li>";
$message .= "<br><b><li>duty <frac> --> Desired duty cycle given as a fraction (e.g. 0.5, 0.4).</b></li>";
$message .= "<br><b><li>cshift <csh> --> Coarse shift (granularity 2ns) of the generated clock signal. This parameter can be
used to get desired delay relation between generated 1-PPS and clk2. The delay
between 1-PPS and clk2 is constant for a given bitstream but may be different
for various hardware versions and re-synthesized gateware. Therefore it should be
measured and adjusted only once for given hardware and gateware version.</b></li>";
$message .= "<br><b><li>sigdel <steps> --> Clock signal generated from the FPGA is cleaned by a discrete flip-flop. It may
happen that generated aux clock is in phase with the flip-flop clock. In that case
it is visible on the oscilloscope that clk2 clock is jittering by 4ns. The --sigdel
parameter allows to add a precise delay to the FPGA-generated clock to avoid such
jitter. This delay is specified in steps, where each step is around 150ps. This value,
same as the --cshift parameter, is constant for a given bitstream so should be
verified only once..</b></li>";
$message .= "<br><b><li>ppshift <steps> --> If one needs to precisely align 1-PPS output with the clk2 aux clock using --cshift
parameter is not enough as it has 4ns granularity. In that case --ppshift lets you
shift 1-PPS output by a configured number of 150ps steps. However, please have in
mind that 1-PPS output is used as a reference for WR calibration procedure. There-
fore, once this parameter is modified, the device should be re-calibrated. Otherwise,
1-PPS output will be shifted from the WR timescale by <steps>*150ps.</b></li>";
$message .= "<br><center><b>Please refer to the WRS manual to configure correctly this feature.<br></center>
</p>";
} else if (!strcmp($help_id, "dotconfig")){
$message = file_get_contents($GLOBALS['kconfigfile']);
......@@ -1230,6 +1257,33 @@ function load_kconfig(){
$_SESSION['KCONFIG'] = parse_ini_file($GLOBALS['kconfigfile']);
}
/*
* It checks whether a CONFIG__ element in the web interface exists or not
* in kconfig. In case it doesn't, it includes it at the end of the file
* with an empty value.
*
* @author José Luis Gutiérrez <jlgutierrez@ugr.es>
* @pre: this is done when a new non-existing CONFIG__ value must be added
* in kconfig, after using this function, the value must be fulfilled and
* call save_kconfig().
*
*/
function check_add_existing_kconfig($element){
$file = file_get_contents($GLOBALS['kconfigfile']);
$pos = strrpos($file, $element);
$element .= '""'."\n";
if ($pos === false){
file_put_contents($GLOBALS['kconfigfile'], $element, FILE_APPEND | LOCK_EX);
}
}
function delete_from_kconfig($element){
shell_exec("sed -i '/".$element."/d' ".$GLOBALS['kconfigfile']);
}
/*
* It saves the dotconfig configuration to dotfile file
* and changes it from master to Grandmaster and vicecersa
......
......@@ -22,10 +22,25 @@
<?php $_SESSION['advance']=""; ?>
<?php
/* This will be part of the code when using dotconfig for DHCP/FIX IP
if((empty($_POST["networkgroup"]))){
echo '<FORM method="POST">
<table id="daemon" border="0" align="center">
<tr>
<td align=left>eth0 Setup: </td>
<td><input type="radio" name="networkgroup" value="DHCPONLY"'; if(!strcmp(wrs_interface_setup(), "dhcponly")) echo "checked";
echo ' > DHCP Only <br>
<input type="radio" name="networkgroup" value="DHCPONCE"'; if(!strcmp(wrs_interface_setup(), "dhcponce")) echo "checked";
echo ' > DHCP + Static<br>
<input type="radio" name="networkgroup" value="STATIC"'; if(!strcmp(wrs_interface_setup(), "static")) echo "checked";
echo ' > Static IP<br></td>
<td><INPUT type="submit" value="Change" class="btn"></td>
</tr>
</table>
</FORM>
<br>';
$formatID = "alternatecolor";
$class = "altrowstable firstcol";
$infoname = "Current eth0";
......@@ -46,53 +61,27 @@
print_info($section, $subsection, $formatID, $class, $infoname, $format);
echo '<hr><p align="right">Click <A HREF="dns.php">here</A> to modify DNS configuration</p>';
}
if ((!empty($_POST["networkgroup"])) && (!strcmp(htmlspecialchars($_POST["networkgroup"]),"DHCP"))){
$DHCP_LINE = 'CONFIG_ETH0_DHCP="y"'."\n";
file_put_contents($GLOBALS['kconfigfile'], $DHCP_LINE, FILE_APPEND | LOCK_EX);
if ((!empty($_POST["networkgroup"])) && (!strcmp(htmlspecialchars($_POST["networkgroup"]),"DHCPONLY"))){
echo '<center>DHCP is now set for eth0<br>Rebooting switch</center>';
$_SESSION["KCONFIG"]["CONFIG_ETH0_DHCP"]="y";
//Let's reboot
wrs_reboot();
check_add_existing_kconfig("CONFIG_ETH0_DHCP=");
}
if ((!empty($_POST["networkgroup"])) && (!strcmp(htmlspecialchars($_POST["networkgroup"]),"Static"))){
delete_from_kconfig("CONFIG_ETH0_DHCP_ONCE=");
delete_from_kconfig("CONFIG_ETH0_STATIC=");
delete_from_kconfig("CONFIG_ETH0_IP=");
delete_from_kconfig("CONFIG_ETH0_MASK=");
delete_from_kconfig("CONFIG_ETH0_NETWORK=");
delete_from_kconfig("CONFIG_ETH0_BROADCAST=");
delete_from_kconfig("CONFIG_ETH0_GATEWAY=");
$formatID = "alternatecolor";
$class = "altrowstable firstcol";
$infoname = "eth0";
$format = "table";
$section = "WRS_FORMS";
$subsection = "NETWORK_SETUP";
print_form($section, $subsection, $formatID, $class, $infoname, $format);
}*/
/* end of dotconfig version */
if((empty($_POST["networkgroup"]))){
save_kconfig();
apply_kconfig();
wrs_reboot();
//shell_exec("/etc/init.d/network restart > /dev/null 2>&1 &"); /* restart network */
echo '<FORM method="POST">
<table id="daemon" border="0" align="center">
<tr>
<th align=left>eth0 Setup: </th>
<th><input type="radio" name="networkgroup" value="DHCP"'; if(!strcmp(wrs_interface_setup(), "dhcp")) echo "checked";
echo ' > DHCP <br>
<input type="radio" name="networkgroup" value="Static"'; if(!strcmp(wrs_interface_setup(), "static")) echo "checked";
echo ' > Static <br>
<th><INPUT type="submit" value="Change" class="btn"></th>
</tr>
</table>
</FORM>
<br>';
$formatID = "alternatecolor";
$class = "altrowstable firstcol";
$infoname = "Current eth0";
......@@ -102,46 +91,35 @@
print_info($section, $subsection, $formatID, $class, $infoname, $format);
echo '<br>';
$formatID = "alternatecolor1";
$class = "altrowstable firstcol";
$infoname = "DNS Configuration";
$format = "table";
$section = "WRS_FORMS";
$subsection = "DNS_SETUP";
print_info($section, $subsection, $formatID, $class, $infoname, $format);
echo '<hr><p align="right">Click <A HREF="dns.php">here</A> to modify DNS configuration</p>';
echo '<br><center>"DHCP Only" is now set for eth0<br>Rebooting network service...</center>';
}
if ((!empty($_POST["networkgroup"])) && (!strcmp(htmlspecialchars($_POST["networkgroup"]),"DHCPONCE"))){
if ((!empty($_POST["networkgroup"])) && (!strcmp(htmlspecialchars($_POST["networkgroup"]),"DHCP"))){
$interface_file = $GLOBALS['interfacesfile'];
$tmpfile="/tmp/interfaces";
shell_exec('rm '.$interface_file);
$output="# Configure Loopback\nauto lo\niface lo inet loopback\n\n#Force eth0 to be configured by DHCP\nauto eth0\niface eth0 inet dhcp\n\n# Uncomment this example for static configuration\n";
$output.="#iface eth0 inet static\n";
$output.="#\taddress 192.168.1.10";
$output.="\n#\tnetmask 255.255.255.0";
$output.="\n#\tnetwork 192.168.1.0";
$output.="\n#\tbroadcast 192.168.1.255";
$output.="\n#\tgateway 192.168.1.1\n";
$file = fopen($tmpfile,"w+");
fwrite($file,$output);
fclose($file);
//We move the file to /usr/etc/network
copy($tmpfile, $interface_file);
echo '<center>DHCP is now set for eth0<br>Rebooting switch</center>';
//Let's reboot
wrs_reboot();
echo '<p>Please enter the static setup in case DHCP fails: </p><br>';
echo '<FORM method="POST">
<table border="0" align="center" class="altrowstable" id="alternatecolor">
<tr>
<td>IP Address: </td>
<td><INPUT type="text" value="192.168.1.10" name="ip" ></td>
</tr>
<tr>
<td>Netmask: </td>
<td><INPUT type="text" value="255.255.255.0" name="netmask" ></td>
</tr>
<tr>
<td>Broadcast: </td>
<td><INPUT type="text" value="192.168.1.255" name="broadcast" ></td>
</tr>
</table>
<INPUT type="submit" value="Save New Configuration" class="btn last">
<INPUT type="hidden" value="DHCPONCE" name="dhcp">
</FORM>';
}
if ((!empty($_POST["networkgroup"])) && (!strcmp(htmlspecialchars($_POST["networkgroup"]),"Static"))){
if ((!empty($_POST["networkgroup"])) && (!strcmp(htmlspecialchars($_POST["networkgroup"]),"STATIC"))){
echo '<FORM method="POST">
<table border="0" align="center" class="altrowstable" id="alternatecolor">
......@@ -153,47 +131,65 @@
<td>Netmask: </td>
<td><INPUT type="text" value="255.255.255.0" name="netmask" ></td>
</tr>
<tr>
<td>Network: </td>
<td><INPUT type="text" value="192.168.1.0" name="network" ></td>
</tr>
<tr>
<td>Broadcast: </td>
<td><INPUT type="text" value="192.168.1.255" name="broadcast" ></td>
</tr>
<tr>
<td>Gateway: </td>
<td><INPUT type="text" value="192.168.1.1" name="gateway" ></td>
</tr>
</table>
<INPUT type="submit" value="Save New Configuration" class="btn last">
</FORM>';
}
if ((!empty($_POST["ip"])) && (!empty($_POST["netmask"])) && (!empty($_POST["network"])) && (!empty($_POST["broadcast"])) && (!empty($_POST["gateway"]))){
$interface_file = $GLOBALS['interfacesfile'];
$tmpfile="/tmp/interfaces";
shell_exec('rm '.$interface_file);
$output="# Configure Loopback\nauto lo\niface lo inet loopback\n\n#Force eth0 to be configured by DHCP\n#auto eth0\n#iface eth0 inet dhcp\n\n# Uncomment this example for static configuration\n";
$output.="iface eth0 inet static\n";
$output.="\taddress ".$_POST["ip"];
$output.="\n\tnetmask ".$_POST["netmask"];
$output.="\n\tnetwork ".$_POST["network"];
$output.="\n\tbroadcast ".$_POST["broadcast"];
$output.="\n\tgateway ".$_POST["gateway"]."\n";
$file = fopen($tmpfile,"w+");
fwrite($file,$output);
fclose($file);
//We move the file to /usr/etc/network
copy($tmpfile, $interface_file);
echo '<center>New static configuration saved for eth0<br>Changes will take place after reboot.</center>';
if ((!empty($_POST["ip"])) && (!empty($_POST["netmask"])) && (!empty($_POST["broadcast"]))){
//Let's reboot
if (!empty($_POST["dhcp"])){
$_SESSION["KCONFIG"]["CONFIG_ETH0_DHCP_ONCE"]="y";
$_SESSION["KCONFIG"]["CONFIG_ETH0_IP"]=$_POST["ip"];
$_SESSION["KCONFIG"]["CONFIG_ETH0_MASK"]=$_POST["netmask"];
$_SESSION["KCONFIG"]["CONFIG_ETH0_NETWORK"]="";
$_SESSION["KCONFIG"]["CONFIG_ETH0_BROADCAST"]=$_POST["broadcast"];
$_SESSION["KCONFIG"]["CONFIG_ETH0_GATEWAY"]="";
check_add_existing_kconfig("CONFIG_ETH0_DHCP_ONCE=");
check_add_existing_kconfig("CONFIG_ETH0_IP=");
check_add_existing_kconfig("CONFIG_ETH0_MASK=");
check_add_existing_kconfig("CONFIG_ETH0_NETWORK=");
check_add_existing_kconfig("CONFIG_ETH0_BROADCAST=");
check_add_existing_kconfig("CONFIG_ETH0_GATEWAY=");
delete_from_kconfig("CONFIG_ETH0_DHCP=");
delete_from_kconfig("CONFIG_ETH0_STATIC=");
echo '<br><center>"DHCP Once" is now set for eth0<br>Rebooting network service...</center>';
}else{
$_SESSION["KCONFIG"]["CONFIG_ETH0_STATIC"]="y";
$_SESSION["KCONFIG"]["CONFIG_ETH0_IP"]=$_POST["ip"];
$_SESSION["KCONFIG"]["CONFIG_ETH0_MASK"]=$_POST["netmask"];
$_SESSION["KCONFIG"]["CONFIG_ETH0_NETWORK"]="";
$_SESSION["KCONFIG"]["CONFIG_ETH0_BROADCAST"]=$_POST["broadcast"];
$_SESSION["KCONFIG"]["CONFIG_ETH0_GATEWAY"]="";
check_add_existing_kconfig("CONFIG_ETH0_STATIC=");
check_add_existing_kconfig("CONFIG_ETH0_IP=");
check_add_existing_kconfig("CONFIG_ETH0_MASK=");
check_add_existing_kconfig("CONFIG_ETH0_NETWORK=");
check_add_existing_kconfig("CONFIG_ETH0_BROADCAST=");
check_add_existing_kconfig("CONFIG_ETH0_GATEWAY=");
delete_from_kconfig("CONFIG_ETH0_DHCP_ONCE=");
delete_from_kconfig("CONFIG_ETH0_DHCP=");
echo '<br><center>"Static Only" is now set for eth0<br>Rebooting network service...</center>';
}
save_kconfig();
apply_kconfig();
//shell_exec("/etc/init.d/network restart > /dev/null 2>&1 &"); /* restart network */
wrs_reboot();
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment