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

www: migrating sfp and endpoint configuration to dot-config

endpointcalibration.php: migrated to dotconfig and data structures.
endpointmode.php: migrated to dotconfig and data structures.
(modifymode.php is part of this change)
sfpcalibration.php: migrated to dotconfig and data structures.

wrs-data.php: removed NETWORK_SETUP duplicated info
parent 2d71f410
......@@ -184,34 +184,6 @@ $WRS_FORMS = Array(
),
),
NETWORK_SETUP => Array(
NETWORK_SETUP_00 => Array(
name => "IP Address",
value => "192.168.1.53",
vname => "ip",
),
NETWORK_SETUP_01 => Array(
name => "Netmask",
value => "255.255.255.0",
vname => "netmask",
),
NETWORK_SETUP_02 => Array(
name => "Broadcast",
value => "192.168.1.255",
vname => "broadcast",
),
NETWORK_SETUP_03 => Array(
name => "Network",
value => "192.168.1.0",
vname => "network",
),
NETWORK_SETUP_04 => Array(
name => "Gateway",
value => "192.168.1.1",
vname => "gateway",
),
),
CONFIG_PPSI => Array(
CONFIG_PPSI_00 => Array(
name => "Clock Class",
......
......@@ -22,139 +22,63 @@
<?php session_is_started() ?>
<div>
<?php
$file_init = 'global = {'."\n";
$file_init .= "\t".'sfp_database_path = "'.$GLOBALS['etcdir'].'sfp_database.conf";'."\n";
$file_init .= '};'."\n\n";
$file_init .= 'timing = {'."\n\n";
$file_end = '};'."\n";;
// Warning message
echo "<hr>
NOTE: This action will delete the previous wrsw_hal.conf file. <a href='showfile.php?help_id=file&name=wrsw_hal.conf'
onClick='showPopup(this.href);return(false);'> (see current configuration) </a>
<center>*If you do not know how to calibrate endpoints please click on <a href='http://www.ohwr.org/projects/white-rabbit/wiki/Calibration' target='_blank'> here </a>*";
echo '<br>**all fields are mandatory**</center></div><hr><br><br>';
//echo '<tr><td> <b><center> </center></b></td></tr>';
if (empty($_POST['newconf'])){
// Starting the form (timing + ports)
echo '<form method="post">';
echo "<table border='1' align='left' class='altrowstable firstcol' id='alternatecolor'>";
// Timing values:
echo '<tr class="sub"><th>Switch Timing Values</th></tr>';
echo '<tr><td>PPS Width: </td><td><INPUT type="text" value = "100000" name="pps" > </td></tr>';
echo '<tr><td>Use NMEA: </td><td><INPUT type="text" value = "1" name="nmea" > </td></tr>';
echo '<tr><td>Switch Mode: [Master/GrandMaster] </td><td><INPUT type="text" value = "GrandMaster" name="switchmode" > </td></tr>';
// port values:
for($i=0; $i<18; $i++){
echo '<tr class="empty"><th></th></tr>';
echo '<tr class="sub"><th>Endpoint '.($i+1).'</th></tr>';
if($i<4){ echo '<tr><td>Rx min:</td><td><INPUT type="text" value = "160000" name="rx'.$i.'" > </td></tr>';
}else{ echo '<tr><td>Rx min:</td><td><INPUT type="text" value = "161200" name="rx'.$i.'" > </td></tr>';}
echo '<tr><td>Tx min:</td><td><INPUT type="text" value = "0" name="tx'.$i.'" > </td></tr>';
echo '<tr><td>Mac address:</td><td><INPUT type="text" value = "auto" name="mac'.$i.'" > </td></tr>';
if($i==0){ echo '<tr><td>Endpoint mode: [wr_slave/wr_master] </td><td><INPUT type="text" value = "wr_slave" name="mode'.$i.'" > </td></tr>';
}else{ echo '<tr><td>Endpoint mode: [wr_slave/wr_master] </td><td><INPUT type="text" value = "wr_master" name="mode'.$i.'" > </td></tr>';}
}
echo '</table>';
echo '<div>';
echo '<input type="hidden" name="newconf" value="newconf">';
echo '<input align="right" type="submit" value="Create new file & Reboot" class="btn last">';
echo '</div>';
echo '</form>';
}
<center>NOTE: If you do not know how to calibrate endpoints
please click on <a href='http://www.ohwr.org/projects/white-rabbit/wiki/Calibration'
target='_blank'> here </a>*<hr><br>";
if (!empty($_POST['newconf'])){
$outputfile = $file_init;
$error = false;
if( empty($_POST['pps']) || empty($_POST['nmea']) || empty($_POST['switchmode'])){
$error = true;
}
// Switch mode must be Master or GrandMaster
if (!((!strcmp($_POST['switchmode'], "Master")) || !(strcmp($_POST['switchmode'], "GrandMaster")))){
$error = true;
}
if(!$error){
$outputfile .= "\t"."pps_width = ".$_POST['pps']."; -- PPS pulse width"."\n";
$outputfile .= "--"."\t"."use_nmea = ".$_POST['nmea']."; -- take UTC seconds from NMEA GPS clock connected to /dev/ttyS2"."\n";
$outputfile .= "--"."\t"."mode = ".'"'.$_POST['switchmode'].'"'."; -- grand-master with external reference"."\n";
$outputfile .= "};"."\n\n";
}
$outputfile .= "ports = {"."\n\n";
for($i=0; $i<18 && (!$error); $i++){
if( empty($_POST['mac'.$i]) || empty($_POST['mode'.$i]) /*|| empty($_POST['tx'.$i])*/ || empty($_POST['rx'.$i])){
$error = true;
echo '<br>ERROR!!'.$i."--".empty($_POST['mac'.$i])."--".empty($_POST['mode'.$i])."--".empty($_POST['tx'.$i])."--".empty($_POST['rx'.$i]);
}
// Switch mode must be Master or GrandMaster
if (!((!strcmp($_POST['mode'.$i], "wr_master")) || !(strcmp($_POST['mode'.$i], "wr_slave")))){
$error = true;
}
$outputfile .= "\t"."wr".$i." = {"."\n";
$outputfile .= "\t\t".'phy_rx_min = '.$_POST['rx'.$i].';'."\t"."-- minimal RX latency introduced by the PHY (in picoseconds)"."\n";
$outputfile .= "\t\t".'phy_tx_min = '.$_POST['tx'.$i].';'."\n\n";
$outputfile .= "\t\t".'mac_addr = '.'"'.$_POST['mac'.$i].'"'.';'."\n";
$outputfile .= "\t\t".'mode = '.'"'.$_POST['mode'.$i].'"'.';'."\n";
$outputfile .= "\t"."};"."\n\n";
}
$outputfile .= $file_end;
}
$formatID = "alternatecolor";
$class = "altrowstable firstcol";
$infoname = "Endpoint Configuration";
$size = "8";
$header = array ("WR port","Tx","Rx","Mode","Fiber");
$matrix = array ("key=CONFIG_PORT00_PARAMS,".$_SESSION["KCONFIG"]["CONFIG_PORT00_PARAMS"],
"key=CONFIG_PORT01_PARAMS,".$_SESSION["KCONFIG"]["CONFIG_PORT01_PARAMS"],
"key=CONFIG_PORT02_PARAMS,".$_SESSION["KCONFIG"]["CONFIG_PORT02_PARAMS"],
"key=CONFIG_PORT03_PARAMS,".$_SESSION["KCONFIG"]["CONFIG_PORT03_PARAMS"],
"key=CONFIG_PORT04_PARAMS,".$_SESSION["KCONFIG"]["CONFIG_PORT04_PARAMS"],
"key=CONFIG_PORT05_PARAMS,".$_SESSION["KCONFIG"]["CONFIG_PORT05_PARAMS"],
"key=CONFIG_PORT06_PARAMS,".$_SESSION["KCONFIG"]["CONFIG_PORT06_PARAMS"],
"key=CONFIG_PORT07_PARAMS,".$_SESSION["KCONFIG"]["CONFIG_PORT07_PARAMS"],
"key=CONFIG_PORT08_PARAMS,".$_SESSION["KCONFIG"]["CONFIG_PORT08_PARAMS"],
"key=CONFIG_PORT09_PARAMS,".$_SESSION["KCONFIG"]["CONFIG_PORT09_PARAMS"],
"key=CONFIG_PORT10_PARAMS,".$_SESSION["KCONFIG"]["CONFIG_PORT10_PARAMS"],
"key=CONFIG_PORT11_PARAMS,".$_SESSION["KCONFIG"]["CONFIG_PORT11_PARAMS"],
"key=CONFIG_PORT12_PARAMS,".$_SESSION["KCONFIG"]["CONFIG_PORT12_PARAMS"],
"key=CONFIG_PORT13_PARAMS,".$_SESSION["KCONFIG"]["CONFIG_PORT13_PARAMS"],
"key=CONFIG_PORT14_PARAMS,".$_SESSION["KCONFIG"]["CONFIG_PORT14_PARAMS"],
"key=CONFIG_PORT15_PARAMS,".$_SESSION["KCONFIG"]["CONFIG_PORT15_PARAMS"],
"key=CONFIG_PORT16_PARAMS,".$_SESSION["KCONFIG"]["CONFIG_PORT16_PARAMS"],
"key=CONFIG_PORT17_PARAMS,".$_SESSION["KCONFIG"]["CONFIG_PORT17_PARAMS"],
);
print_multi_form($matrix, $header, $formatID, $class, $infoname, $size);
if(process_multi_form($matrix)){
save_kconfig();
apply_kconfig();
if(!empty($_POST['newconf']) && !$error){
//We save the changes in a temporarely file in /tmp
$file = fopen("/tmp/wrsw_hal.conf","w+");
fwrite($file,$outputfile);
fclose($file);
header ('Location: endpointcalibration.php');
//We move the file to /wr/etc/
copy('/tmp/wrsw_hal.conf', $GLOBALS['etcdir'].'wrsw_hal.conf');
echo '<center><font color="green">File successfully created. Rebooting switch. </font></center>';
wrs_reboot();
}else if(!empty($_POST['newconf']) && $error){
echo '<center><font color="red">WARNING: Conf. file not created. Please fill in all fields</font></center>';
echo '<center><font color="red">* Switch mode must be Master or GrandMaster </font></center>';
echo '<center><font color="red">** Endpoint mode must be wr_slave or wr_master </font></center>';
}
$formatID = "alternatecolor1";
$class = "altrowstable firstcol";
$infoname = "Available Fibers";
$size = "12";
$header = array ("#","Alpha");
$matrix = array ("id=0,key=CONFIG_FIBER00_PARAMS,".$_SESSION["KCONFIG"]["CONFIG_FIBER00_PARAMS"],
"id=1,key=CONFIG_FIBER01_PARAMS,".$_SESSION["KCONFIG"]["CONFIG_FIBER01_PARAMS"],
"id=2,key=CONFIG_FIBER02_PARAMS,".$_SESSION["KCONFIG"]["CONFIG_FIBER02_PARAMS"],
"id=3,key=CONFIG_FIBER03_PARAMS,".$_SESSION["KCONFIG"]["CONFIG_FIBER03_PARAMS"]);
print_multi_form($matrix, $header, $formatID, $class, $infoname, $size);
?>
</div>
......
......@@ -23,29 +23,21 @@
<?php
//Load all
//$modes = parse_wrsw_hal_file();
$modes = parse_ppsi_conf_file();
$modes = parse_endpoint_modes();
echo '<table class="altrowstable" id="alternatecolor" style="width:100%;text-align:center">';
//echo '<tr><th><center>Endpoint</center></th><th><center>Mode</center></th></tr>';
for($i = 0; $i < 9; $i++){
echo '<tr>';
echo '<th>wr'.($i+1).'</td>';
echo '<td><a href="modifymode.php?wr='.($i+1).'&mode='.$modes[$i+1].'">'.$modes[$i+1].'</a></th>';
echo '<th>wr'.($i).'</td>';
echo '<td><a href="modifymode.php?wr='.($i).'&mode='.$modes[$i].'">'.$modes[$i].'</a></th>';
echo '<th>wr'.($i+1+9).'</th>';
echo '<td><a href="modifymode.php?wr='.($i+1+9).'&mode='.$modes[$i+1+9].'">'.$modes[$i+1+9].'</a></td>';
echo '<th>wr'.($i+9).'</th>';
echo '<td><a href="modifymode.php?wr='.($i+9).'&mode='.$modes[$i+9].'">'.$modes[$i+9].'</a></td>';
echo '</tr>';
}
//echo '</tr>';
}
echo '</table>';
echo '<br>';
//wrs_check_writeable();
echo '<br>';
?>
<div>
......@@ -55,22 +47,6 @@
<INPUT type="submit" value="Restart PPSi" class="btn">
</FORM>
</div>
<?php
if (!empty($_POST["hal"])){
//We must relaunch ptpd too. (by default)
shell_exec("killall ppsi");
$ptp_command = "/wr/bin/ppsi > /dev/null 2>&1 &";
$output = shell_exec($ptp_command);
//Relaunching wrsw_hal to commit endpoint changes
//shell_exec("killall wrsw_hal");
//shell_exec("/wr/bin/wrsw_hal -c ".$GLOBALS['etcdir']."wrsw_hal.conf > /dev/null 2>&1 &");
}
?>
</div>
</div>
......
......@@ -232,8 +232,10 @@ function print_form($section, $subsection, $formatID, $class, $infoname, $format
function process_form($section, $subsection){
foreach ($_SESSION[$section][$subsection] as $row) {
if(!empty($_POST)){
$modified = false;
if(!empty($_POST)){
foreach ($_SESSION[$section][$subsection] as $row) {
$_SESSION["KCONFIG"][$row["key"]]=$_POST[$row["vname"]];
$_SESSION[$section][$subsection][$row["value"]] = $_POST[$row["vname"]];
$modified = true;
......@@ -242,6 +244,86 @@ function process_form($section, $subsection){
return $modified;
}
function print_multi_form($matrix, $header, $formatID, $class, $infoname, $size){
echo '<FORM method="POST">
<table border="0" align="center" class="'.$class.'" id="'.$formatID.'" width="100%" >';
if (!empty($infoname)) echo '<tr><th>'.$infoname.'</th></tr>';
// Printing fist line with column names.
if (!empty($header)){
echo "<tr class='sub'>";
foreach ($header as $column){
echo "<td>".($column)."</td>";
}
echo "</tr>";
}
$i = 0;
// Printing the content of the form.
foreach ($matrix as $array){
$elements = explode(",",$array);
$first = 0;
echo "<tr>";
foreach ($elements as $element){
$column = explode("=",$element);
if ($column[0]=="key"){
echo '<INPUT type="hidden" value="'.$column[1].'" name="key'.$i.'" >';
}else{
echo '<td align="center"><INPUT size="'.$size.'" type="text" value="'.$column[1].'" name="'.$column[0].$i.'" ></td>';
$first = 1;
}
}
echo "</tr>";
$i++;
$first = 0;
}
echo '</table>';
echo '<INPUT type="submit" value="Save New Configuration" class="btn last">';
echo '</FORM>';
}
function process_multi_form($matrix){
$modified = false;
$i=0;
if(!empty($_POST)){
foreach ($matrix as $array){
$elements = explode(",",$array);
foreach ($elements as $element){
$column = explode("=",$element);
if($column[0]!="key"){
$output .= preg_replace('/[0-9]+/', '', $column[0].$i)."=". $_POST[$column[0].$i].",";
}else{
$key = $_POST[$column[0].$i];
}
//$_SESSION["KCONFIG"][$row["key"]]=$_POST[$row["vname"]];
//$_SESSION[$section][$subsection][$row["value"]] = $_POST[$row["vname"]];
}
$output = rtrim($output, ",");
// We have the line, put it in kconfig.
$_SESSION["KCONFIG"][$key]=$output;
// Clean output
$output="";
$i++;
}
$modified = true;
}
return $modified;
}
function check_ntp_server(){
$ntpserver = $_SESSION['KCONFIG']["CONFIG_NTP_SERVER"];
if(!strcmp($ntpserver, "")){
......@@ -579,7 +661,7 @@ function wrs_management(){
rename($uploadfile, "/update/".($_FILES['file']['name']));
unlink($uploadfile);
//Reboot switch
sleep(10);
sleep(1);
wrs_reboot();
}
else if(substr($uploadfname,0,14)=="wr-switch-sw-v" && substr($uploadfname,-13)=="_binaries.tar")
......@@ -587,7 +669,7 @@ function wrs_management(){
rename($uploadfile, "/update/wrs-firmware.tar");
unlink($uploadfile);
//Reboot switch
sleep(10);
sleep(1);
wrs_reboot();
}
else
......@@ -1007,13 +1089,22 @@ function parse_wrsw_hal_file(){
return $file;
}
function parse_ppsi_conf_file(){
function parse_endpoint_modes(){
$file = shell_exec('cat '.$GLOBALS['etcdir'].'ppsi.conf | grep role');
$file = str_replace("role", "", $file);
$file = explode(" ", $file);
return $file;
$modes = array();
for($i = 0; $i < 18; $i++){
$endpoint = intval($i);
$endpoint = sprintf("%02s", $endpoint);
$endpoint = strval($endpoint);
$role = $_SESSION["KCONFIG"]["CONFIG_PORT".$endpoint."_PARAMS"];
$role = explode(",",$role);
$role = str_replace("role=","",$role[3]);
array_push($modes,$role);
}
return $modes;
}
/*
* Obtains the content the switch mode from wrsw_hal.conf file
......@@ -1053,131 +1144,6 @@ function modify_switch_mode(){
}
function wrs_modify_endpoint_mode($endpoint, $mode){
switch ($mode) {
case "master":
$new_mode = "slave";
break;
case "slave":
$new_mode = "auto";
break;
case "auto":
$new_mode = "master";
break;
}
// ### Code for ppsi.conf ###
if($endpoint>0 && $endpoint<19 && (((!strcmp($mode, "slave"))) || ((!strcmp($mode, "master"))) || ((!strcmp($mode, "auto"))))){
$file = $GLOBALS['etcdir'].$GLOBALS['ppsiconf'];
$lines = file($file);
$output = "";
$count = 0;
$end_aux = $endpoint;
if($endpoint == 1){ //Slave port
$endpoint= "port slave";
}else{ //Master ports
$endpoint= "port master".($end_aux-1)."\n";
}
$found = false;
foreach($lines as $line_num => $line)
{
if(substr_count($line, $endpoint)>0){
$found = true;
}
if($found)$count++;
if($count==3){
$output.='role '.$new_mode."\n";
$count = 0;
$found = false;
}else{
$output.=$line;
}
}
//We save the changes in a temporarely file in /tmp
$file = fopen("/tmp/".$GLOBALS['ppsiconf'],"w+");
fwrite($file,$output);
fclose($file);
//We move the file to /wr/etc/
copy('/tmp/'.$GLOBALS['ppsiconf'], $GLOBALS['etcdir'].$GLOBALS['ppsiconf']);
//echo '<br><br><br><br><br><br><br><br><center>Endpoint wr'.$end_aux.' is now '.$new_mode.'</center>';
}else{
echo '<br>Wrong parameters for endpoint-mode';
}
// ##### old code for wrsw_hal.conf ######
switch ($mode) {
case "master":
$new_mode = "wr_slave";
break;
case "slave":
$new_mode = "wr_master";
break;
case "auto":
$new_mode = "wr_slave";
break;
}
echo $mode, "---", $new_mode;
if($endpoint>0 && $endpoint<19 && (((!strcmp($mode, "slave"))) || ((!strcmp($mode, "master"))) || ((!strcmp($mode, "auto"))))){
$file = $GLOBALS['etcdir'].$GLOBALS['wrswhalconf'];
$lines = file($file);
$output = "";
$count = 0;
$end_aux = $endpoint;
$endpoint = 'wr'.($endpoint-1).' =';
$found = false;
foreach($lines as $line_num => $line)
{
if(substr_count($line, $endpoint)>0){
$found = true;
}
if($found)$count++;
if($count==6){
$output.=' mode = "'.$new_mode.'";'."\n";
$count = 0;
$found = false;
}else{
$output.=$line;
}
}
//We save the changes in a temporarely file in /tmp
$file = fopen("/tmp/".$GLOBALS['wrswhalconf'],"w+");
fwrite($file,$output);
fclose($file);
//We move the file to /wr/etc/
copy('/tmp/'.$GLOBALS['wrswhalconf'], $GLOBALS['etcdir'].$GLOBALS['wrswhalconf']);
}else{
echo '<br>Wrong parameters for endpoint-mode';
}
}
function session_is_started(){
ob_start();
......
......@@ -22,10 +22,30 @@
<?php
$endpoint = $_GET["wr"];
$endpoint = intval($_GET["wr"]);
$endpoint = sprintf("%02s", $endpoint);
$endpoint = strval($endpoint);
$mode = $_GET["mode"];
wrs_modify_endpoint_mode($endpoint, $mode);
switch ($mode) {
case "master":
$new_mode = "slave";
break;
case "slave":
$new_mode = "auto";
break;
case "auto":
$new_mode = "master";
break;
}
$string = $_SESSION["KCONFIG"]["CONFIG_PORT".$endpoint."_PARAMS"];
$string = str_replace($mode,$new_mode,$string);
$_SESSION["KCONFIG"]["CONFIG_PORT".$endpoint."_PARAMS"] = $string;
save_kconfig();
apply_kconfig();
header('Location: endpointmode.php');
exit;
......
......@@ -25,107 +25,46 @@
<?php
$file_init = '-- The VENDOR_SERIAL field can be set to an empty string to provide class-level'."\n";
$file_init .= '-- information as opposed to device-level information.'."\n\n";
$file_init .= 'sfpdb = {'."\n";
$file_end = '}'."\n";;
$formatID = "alternatecolor";
$class = "altrowstable firstcol";
$infoname = "SFP Calibration";
$size = "12";
$header = array ("SFP Name","Tx","Rx","wl_txrx");
$matrix = array();
if (empty($_POST['number'])){
echo '<div><form method="post">
Number of new SPFs to be added: <INPUT type="text" value="2" name="number" >
<input type="submit" value="Add" class="btn">
</form></div>';
echo "<div id='bottommsg'>
<hr>
NOTE: This action will delete the previous sfp_database.conf file. <a href='showfile.php?help_id=file&name=sfp_database.conf'
onClick='showPopup(this.href);return(false);'> (see current configuration) </a>
<center>**If you do not know how to calibrate SFPs please click on <a href='http://www.ohwr.org/projects/white-rabbit/wiki/Calibration' target='_blank'> here </a>**</center>
</div>";
}else{
echo '*all fields are mandatory<br><br>';
echo '<form method="post">';
echo "<div><table class='altrowstable firstcol' id='alternatecolor'>";
//echo '<tr><td> <b><center> </center></b></td></tr>';
for($i = 0; $i < 18; $i++){
$endpoint = intval($i);
$endpoint = sprintf("%02s", $endpoint);
$endpoint = strval($endpoint);
if (($_POST['number']!=2)){
for($i=0; $i<$_POST['number']; $i++){
echo '<tr><th>SFP '.($i+1).'</th></tr>';
echo '<tr><td>Part Number</td><td><INPUT type="text" name="sfpnumber'.$i.'" > </td></tr>';
echo '<tr><td>Alpha</td><td><INPUT type="text" name="alpha'.$i.'" > </td></tr>';
echo '<tr><td>Delta Tx</td><td><INPUT type="text" name="tx'.$i.'" > </td></tr>';
echo '<tr><td>Delta Rx</td><td><INPUT type="text" name="rx'.$i.'" > </td></tr>';
}
}else{
for($i=0; $i<$_POST['number']; $i++){
echo '<tr><th>SFP '.($i+1).'</th></tr>';
if($i==0){
echo '<tr><td>Part Number</td><td><INPUT type="text" value = "AXGE-1254-0531" name="sfpnumber'.$i.'" > </td></tr>';
echo '<tr><td>Alpha</td><td><INPUT type="text" value="2.67871791665542e-04" name="alpha'.$i.'" > </td></tr>';
echo '<tr><td>Delta Tx</td><td><INPUT type="text" value="10" name="tx'.$i.'" > </td></tr>';
echo '<tr><td>Delta Rx</td><td><INPUT type="text" value="10" name="rx'.$i.'" > </td></tr>';
}else{
echo '<tr><td>Part Number</td><td><INPUT type="text" value = "AXGE-3454-0531" name="sfpnumber'.$i.'" > </td></tr>';
echo '<tr><td>Alpha</td><td><INPUT type="text" value="-2.67800055584799e-04" name="alpha'.$i.'" > </td></tr>';
echo '<tr><td>Delta Tx</td><td><INPUT type="text" value="10" name="tx'.$i.'" > </td></tr>';
echo '<tr><td>Delta Rx</td><td><INPUT type="text" value="10" name="rx'.$i.'" > </td></tr>';
}
}
if(!empty($_SESSION["KCONFIG"]["CONFIG_SFP".$endpoint."_PARAMS"])){
array_push($matrix, "key=CONFIG_SFP".$endpoint."_PARAMS,".$_SESSION["KCONFIG"]["CONFIG_SFP".$endpoint."_PARAMS"]);
$last = $i;
}
echo '</table>';
echo '<input type="hidden" name="newconf" value="newconf">';
echo '<input type="hidden" name="newnumber" value="'.$_POST['number'].'">';
echo '<input type="submit" value="Create new file & Reboot" class="btn last">';
echo '</form>';
echo '</div>';
}
if (!empty($_POST['newconf'])){
$outputfile = $file_init;
$error = false;
for($i=0; $i<$_POST['newnumber'] && (!$error); $i++){
if(empty($_POST['sfpnumber'.$i]) || empty($_POST['alpha'.$i]) || empty($_POST['tx'.$i]) || empty($_POST['rx'.$i])){
$error = true;
}
$outputfile .= " {"."\n";
$outputfile .= "\t".'part_num = "'.$_POST['sfpnumber'.$i].'",'."\n";
$outputfile .= "\t"."alpha = ".$_POST['alpha'.$i].','."\n";
$outputfile .= "\t"."delta_tx = ".$_POST['tx'.$i].','."\n";
$outputfile .= "\t"."delta_rx = ".$_POST['rx'.$i]."\n";
$outputfile .= " },"."\n\n";
if(!empty($_GET["add"])){
$last++;
if($last<10){
$last = sprintf("%02s", $last);
$last = strval($last);
array_push($matrix, "key=CONFIG_SFP".$last."_PARAMS,name=empty,tx=empty,rx=empty,wl_txrx=empty");
}else{
echo "<center>There is only space for 9 SFP configurations.</center>";
}
$outputfile .= $file_end;
}
print_multi_form($matrix, $header, $formatID, $class, $infoname, $size);
echo '<hr><p align="right">Click <A HREF="sfpcalibration.php?add=y">here</A> to a new SFP</p>';
if(process_multi_form($matrix)){
save_kconfig();
apply_kconfig();
if(!empty($_POST['newconf']) && !$error){
//We save the changes in a temporarely file in /tmp
$file = fopen("/tmp/sfp_database.conf","w+");
fwrite($file,$outputfile);
fclose($file);
//We move the file to /wr/etc/
copy('/tmp/sfp_database.conf',$GLOBALS['etcdir'].'sfp_database.conf');
echo '<center><font color="green">File successfully created. Rebooting switch. </font></center>';
wrs_reboot();
header ('Location: sfpcalibration.php');
}else if(!empty($_POST['newconf']) && $error){
echo '<center><font color="red">WARNING: Conf. file not created. Please fill in all fields</font></center>';
}
?>
......
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