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

Local Management Tool - login & Logout included

New features for the local management tool:

- Login
- Logout
- Included session check in .php files
- Menu and topmenu modificaded for logged users
- Slave.png improved.
parent 74fdb454
......@@ -16,7 +16,9 @@
</div>
<div class="rightpanel">
<div class="rightbody">
<h1 class="title">Endpoint Configuration <a href='help.php?help_id=endpoint' onClick='showPopup(this.href);return(false);'><img align=right src="./img/question.png"></a></h1>
<h1 class="title">Endpoint Tool <a href='help.php?help_id=endpoint' onClick='showPopup(this.href);return(false);'><img align=right src="./img/question.png"></a></h1>
<?php session_is_started() ?>
<?php
echo '<form method=POST>
......@@ -37,8 +39,8 @@
echo '<option value="wr">Modify Registers</option>';
//echo '<option value="rt">Show Flags</option>';
echo '<option value="lock">Lock Endpoint</option>';
echo '<option value="master">Make Master</option>';
echo '<option value="gm">Make GrandMaster</option>';
//echo '<option value="master">Make Master</option>';
//echo '<option value="gm">Make GrandMaster</option>';
echo '</select>
......
......@@ -4,5 +4,5 @@
<p>White Rabbit Project - Open Hardware and Source Project <a class="footer-link" target="_blank"
href="http://www.ohwr.org/projects/white-rabbit/wiki">White-Rabbit OHR</a>
<a href='sysinfo.php' target="_blank"><IMG SRC='img/light_php.png' align=right , vspace=7, hspace=5, width=100 , hight=100 , border=0 , alt='PHP Info'></a>
<img src="img/footnote.gif" class="copyright" alt="White-Rabbit OHR"></a>
<img src="img/footnote.gif" alt="White-Rabbit OHR"></a>
</p>
<?php
/*
* Displays the current status of each enpoint.
*
......@@ -83,6 +84,7 @@ function wrs_main_info(){
$str = shell_exec("uname -n");
if(strcmp($str,"(none)")) shell_exec("/bin/busybox hostname -F /etc/hostname");
echo '<tr><th><b>Hostname:</b></th><th><center>'; $str = shell_exec("uname -n"); echo $str; echo '</center></th></tr>';
echo '<tr><th> <b>Switch Mode:</b> </th><th><center>'; $str = check_switch_mode(); echo $str; echo '</center></th></tr>';
echo '<tr><th> <b>IP Address:</b> </th><th><center>'; $ip = shell_exec("ifconfig eth0 | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}'"); echo $ip; echo '</center></th></tr>';
echo '<tr><th> <b>OS Release:</b> </th><th><center>'; $str = shell_exec("uname -r"); echo $str; echo '</center></th></tr>';
echo '<tr><th> <b>OS name:</b> </th><th><center>'; $str = shell_exec("uname -s"); echo $str; echo '</center></th></tr>';
......@@ -272,6 +274,8 @@ function wr_endpoint_phytool($option1, $endpoint){
echo 'Grandmastering finished' ;
} else if(!strcmp($option1, "hal_conf")){
}
}
......@@ -461,6 +465,10 @@ function wrs_management(){
echo '<br><br><br>Partition is now READ-ONLY';
}else if (!strcmp($cmd, "size")){
php_file_transfer_size(htmlspecialchars($_POST["size"]));
}else if (!strcmp($cmd, "change")){
modify_switch_mode();
$mode = check_switch_mode();
echo '<br><br><br>Switch is now '.$mode;
}
}
......@@ -688,5 +696,123 @@ function extension($filename){
return substr(strrchr($filename, '.'), 1);
}
/*
* Obtains the content of wrsw_hal_file
*
* @author José Luis Gutiérrez <jlgutierrez@ugr.es>
*
* @return $file: string containing endpoints master/slave
*
*/
function parse_wrsw_hal_file(){
$file = shell_exec('cat /wr/etc/wrsw_hal.conf | grep wr_');
$file = str_replace("mode =", "", $file);
$file = str_replace('"', "", $file);
$file = str_replace(';', "", $file);
$file = str_replace('wr_', "", $file);
$file = explode(" ", $file);
return $file;
}
/*
* Obtains the content the switch mode from wrsw_hal.conf file
*
* @author José Luis Gutiérrez <jlgutierrez@ugr.es>
*
* @return true for GrandMaster mode, false for Master mode.
*
*/
function check_switch_mode(){
$status = shell_exec("cat /wr/etc/wrsw_hal.conf | grep -c GrandMaster");
if($status>0){
return "GrandMaster";
} else {
return "Master";
}
}
/*
* Obtains the current mode of the switch from wrsw_hal.conf file
* and changes it from master to Grandmaster and vicecersa
*
* @author José Luis Gutiérrez <jlgutierrez@ugr.es>
*
*
*/
function modify_switch_mode(){
if (!strcmp(check_switch_mode(), "GrandMaster")){
$cmd = 'sed -i "s/mode = \"GrandMaster\"/mode = \"Master\"/g" /wr/etc/wrsw_hal.conf';
}else{
$cmd = 'sed -i "s/mode = \"Master\"/mode = \"GrandMaster\"/g" /wr/etc/wrsw_hal.conf';
}
shell_exec($cmd);
}
function wrs_modify_endpoint_mode($endpoint, $mode){
(!strcmp($mode, "master")) ? $new_mode = "wr_slave" : $new_mode = "wr_master";
if($endpoint>0 && $endpoint<19 && (((!strcmp($mode, "slave"))) || ((!strcmp($mode, "master"))))){
$file = "/wr/etc/wrsw_hal.conf";
$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/wrsw_hal.conf","w+");
fwrite($file,$output);
fclose($file);
//We move the file to /wr/etc/
copy('/tmp/wrsw_hal.conf', '/wr/etc/wrsw_hal.conf');
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';
}
}
function session_is_started(){
ob_start();
$login_url = "./index.php";
if (!isset($_SESSION['myusername'])) {
echo '<br><br><br><center>Please <a href="' . $login_url . '">login.</center></a>';
exit;
}
}
?>
<?php ob_start();?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>White-Rabbit Local Management Tool</title>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1">
<link href="css/style.css" rel="stylesheet" type="text/css">
<!-- Javascript goes in the document HEAD -->
<script type="text/javascript">
function altRows(id){
......
......@@ -18,7 +18,7 @@
<div class="rightbody">
<h1 class="title">Load LM32 & FPGA Files <a href='help.php?help_id=load' onClick='showPopup(this.href);return(false);'><img align=right src="./img/question.png"></a></h1>
<?php session_is_started() ?>
<table border="0" align="center">
......
<?php include 'functions.php'; include 'head.php'; ?>
<body>
<div class="main">
<div class="page">
<div class="header" >
<!--<h1>White-Rabbit Switch Tool</h1>-->
<div class="header-ports" ><?php wrs_header_ports(); ?></div>
<div class="topmenu">
<?php include 'topmenu.php' ?>
</div>
</div>
<div class="content">
<div class="leftpanel">
<h2>Main Menu</h2>
<?php include 'menu.php' ?>
</div>
<div class="rightpanel">
<div class="rightbody">
<h1 class="title">Login <a href='help.php?help_id=login' onClick='showPopup(this.href);return(false);'><img align=right src="./img/question.png"></a></h1>
<?php
ob_start();
$message="";
if(count($_POST)>0) {
$users = shell_exec('cat /etc/users');
$users = explode(" ", $users);
$username = $_POST["login"];
$password = $_POST["password"];
if ((!strcmp($username, "root")) && (!strcmp($password, ""))){
session_start();
$_SESSION["myusername"] = $username;
echo 'Logged in as '.$_SESSION["myusername"];
header('Location: index.php');
}else{
echo 'Invalid Username or Password';
}
}
//if(isset($_SESSION["user_id"])) {
//header("Location:index.php");
?>
</div>
</div>
</div>
<div class="footer">
<?php include 'footer.php' ?>
</div>
</div>
</div>
</body>
</html>
<?php include 'functions.php'; include 'head.php'; ?>
<body>
<div class="main">
<div class="page">
<div class="header" >
<!--<h1>White-Rabbit Switch Tool</h1>-->
<div class="header-ports" ><?php wrs_header_ports(); ?></div>
<div class="topmenu">
<?php include 'topmenu.php' ?>
</div>
</div>
<div class="content">
<div class="leftpanel">
<h2>Main Menu</h2>
<?php include 'menu.php' ?>
</div>
<div class="rightpanel">
<div class="rightbody">
<h1 class="title">Dashboard <a href='help.php?help_id=logout' onClick='showPopup(this.href);return(false);'><img align=right src="./img/question.png"></a></h1>
<?php
//ob_start();
unset($_SESSION["myusername"]);
unset($_SESSION["mypassword"]);
echo '<br><br><center><h3>Logged out</h3></center>';
header('Location: index.php');
?>
</div>
</div>
</div>
<div class="footer">
<?php include 'footer.php' ?>
</div>
</div>
</div>
</body>
</html>
......@@ -18,7 +18,15 @@
<div class="rightbody">
<h1 class="title">Switch Management <a href='help.php?help_id=management' onClick='showPopup(this.href);return(false);'><img align=right src="./img/question.png"></a></h1>
<?php session_is_started() ?>
<table border="0" align="center">
<tr>
<form method="post">
<th><center>Switch Mode: (<?php $str = check_switch_mode(); echo $str; ?>) </center><input type="hidden" name="cmd" value="change"></th>
<th><input type="submit" value="Change Mode" class="btn"></th>
</form>
</tr>
<tr>
<form method="post">
<th><center>Halt system: </center><input type="hidden" name="cmd" value="halt"></th>
......@@ -61,6 +69,7 @@
<?php
wrs_management();
wrs_check_writeable();
?>
......
<ul>
<li><a href="index.php"> Dashboard </a></li>
<?php if(file_exists('/wr/bin/wrsw_rtud_new')) {echo '<li><a href="vlan.php"> VLAN Configuration </a></li>';}?>
<li><a href="ptp.php"> PTP Configuration </a></li>
<li><a href="endpoint.php"> Endpoint Configuration </a></li>
<li><a href="management.php"> Switch Management </a></li>
<li><a href="load.php"> LM32 & FPGA </a></li>
<li><a href="terminal.php"> Console </a></li>
</ul>
<?php
//session_start();
if (!isset($_SESSION['myusername'])) {
echo '</ul><br><hr>';
echo '<div class="login">
<h3>Login</h3>
<form method="post" action="login.php">
<p><input type="text" name="login" value="" placeholder="Username"></p>
<p><input type="password" name="password" value="" placeholder="Password"></p>
<!--<p class="remember_me">
<label>
<input type="checkbox" name="remember_me" id="remember_me">
Remember me on this computer
</label>
</p>-->
<p class="submit"><input type="submit" name="commit" value="Login" class="btn"></p>
</form>
</div>';
}else{
//The rest of the menu for logged users
if(file_exists('/wr/bin/wrsw_rtud_new')) {echo '<li><a href="vlan.php"> VLAN Configuration </a></li>';}
echo '<li><a href="ptp.php"> PTP Configuration </a></li>';
echo '<li><a href="endpointmode.php"> Endpoint Mode</a></li>';
echo '<li><a href="endpoint.php"> Endpoint Tool </a></li>';
echo '<li><a href="load.php"> LM32 & FPGA </a></li>';
echo '<li><a href="management.php"> Switch Management </a></li>';
//echo '<li><a href="administration.php"> Switch Administration </a></li>';
echo '<li><a href="terminal.php"> Console </a></li>';
echo '</ul><br><hr>';
echo '<b>User: <font color="blue">'.$_SESSION["myusername"].' </font></b>';
echo '<a href="./logout.php">(logout)</a>';
}
?>
<hr>
......
......@@ -18,6 +18,8 @@
<div class="rightbody">
<h1 class="title">PTP Configuration <a href='help.php?help_id=ptp' onClick='showPopup(this.href);return(false);'><img align=right src="./img/question.png"></a></h1>
<?php session_is_started() ?>
<FORM method="POST">
<table border="0" align="center">
<tr>
......
......@@ -18,6 +18,8 @@
<div class="rightbody">
<h1 class="title">White-Rabbit Switch Console <a href='help.php?help_id=console' onClick='showPopup(this.href);return(false);'><img align=right src="./img/question.png"></a></h1>
<?php session_is_started() ?>
<FORM action="terminal.php" method="POST" accept-charset="UTF-8">
Unix Command: <input type="text" name="cmd">
<input type="submit" value="Enter" class="btn">
......
<?php
session_start();
if (!isset($_SESSION['myusername'])) {
<ul>
echo '<ul>
<li><a href="index.php"> Dashboard </a></li>
<?php if(file_exists('/wr/bin/wrsw_rtud_new')) {echo '<li><a href="vlan.php"> VLAN Configuration </a></li>';}?>
<li><a href="ptp.php"> PTP Configuration </a></li>
<li><a href="endpoint.php"> Endpoint Configuration </a></li>
<li><a href="contact.php"> Contact Us </a></li>
</ul>
</ul>';
}else{
echo '<ul>
<li><a href="index.php"> Dashboard </a></li>
<li><a href="ptp.php"> PTP Configuration </a></li>
<li><a href="endpoint.php"> Endpoint Configuration </a></li>
<li><a href="endpointmode.php"> Endpoint Mode</a></li>
<li><a href="management.php"> Switch Management </a></li>
<li><a href="contact.php"> Contact Us </a></li>
</ul>';
}
?>
......@@ -18,6 +18,8 @@
<div class="rightbody">
<h1 class="title">VLAN Configuration <a href='help.php?help_id=vlan' onClick='showPopup(this.href);return(false);'><img align=right src="./img/question.png"></a></h1>
<?php session_is_started() ?>
<?php
echo '<table align=center border="1" class="altrowstable" id="alternatecolor">';
echo '<tr><th>Endpoint</th><th>VLANs</th></tr>';
......
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