1
0
mirror of https://github.com/billz/raspap-webgui.git synced 2023-10-10 13:37:24 +02:00

Merge pull request #9 from zlolz/add-system-controls

Add System Info and System Control (foundation)
This commit is contained in:
Bill Zimmerman 2016-06-12 20:10:39 +02:00 committed by GitHub
commit d8f23eeda8
4 changed files with 154 additions and 48 deletions

View File

@ -43,12 +43,7 @@ So what I have done is added the `www-data` user to the sudoers file, but with r
Add the following to the end of `/etc/sudoers`: Add the following to the end of `/etc/sudoers`:
```sh ```sh
www-data ALL=(ALL) NOPASSWD:/sbin/ifdown wlan0,/sbin/ifup wlan0,/bin/cat www-data ALL=(ALL) NOPASSWD:/sbin/ifdown wlan0,/sbin/ifup wlan0,/bin/cat /etc/wpa_supplicant/wpa_supplicant.conf,/bin/cp /tmp/wifidata /etc/wpa_supplicant/wpa_supplicant.conf,/sbin/wpa_cli scan_results, /sbin/wpa_cli scan,/bin/cp /tmp/hostapddata /etc/hostapd/hostapd.conf, /etc/init.d/hostapd start,/etc/init.d/hostapd stop,/etc/init.d/dnsmasq start, /etc/init.d/dnsmasq stop,/bin/cp /tmp/dhcpddata /etc/dnsmasq.conf, /sbin/shutdown -h now, /sbin/reboot
/etc/wpa_supplicant/wpa_supplicant.conf,/bin/cp /tmp/wifidata
/etc/wpa_supplicant/wpa_supplicant.conf,/sbin/wpa_cli scan_results,
/sbin/wpa_cli scan,/bin/cp /tmp/hostapddata /etc/hostapd/hostapd.conf,
/etc/init.d/hostapd start,/etc/init.d/hostapd stop,/etc/init.d/dnsmasq start,
/etc/init.d/dnsmasq stop,/bin/cp /tmp/dhcpddata /etc/dnsmasq.conf
``` ```
Once those modifications are done, git clone the files to `/var/www`. Once those modifications are done, git clone the files to `/var/www`.

5
dist/css/custom.css vendored
View File

@ -28,3 +28,8 @@
background-color: #c61931; background-color: #c61931;
border-color: #c61931; border-color: #c61931;
} }
.info-item {
width: 160px;
float: left;
}

View File

@ -165,16 +165,16 @@ function DisplayDashboard(){
<div class="panel panel-default"> <div class="panel panel-default">
<div class="panel-body"> <div class="panel-body">
<h4>Interface Information</h4> <h4>Interface Information</h4>
Interface Name : wlan0<br /> <div class="info-item">Interface Name</div> wlan0</br>
IP Address : <?php echo $strIPAddress ?><br /> <div class="info-item">IP Address</div> <?php echo $strIPAddress ?></br>
Subnet Mask : <?php echo $strNetMask ?><br /> <div class="info-item">Subnet Mask</div> <?php echo $strNetMask ?></br>
Mac Address : <?php echo $strHWAddress ?><br /> <div class="info-item">Mac Address</div> <?php echo $strHWAddress ?></br></br>
<h4>Interface Statistics</h4> <h4>Interface Statistics</h4>
Received Packets : <?php echo $strRxPackets ?><br /> <div class="info-item">Received Packets</div> <?php echo $strRxPackets ?></br>
Received Bytes : <?php echo $strRxBytes ?><br /><br /> <div class="info-item">Received Bytes</div> <?php echo $strRxBytes ?></br></br>
Transferred Packets : <?php echo $strTxPackets ?><br /> <div class="info-item">Transferred Packets</div> <?php echo $strTxPackets ?></br>
Transferred Bytes : <?php echo $strTxBytes ?><br /> <div class="info-item">Transferred Bytes</div> <?php echo $strTxBytes ?></br>
</div><!-- /.panel-body --> </div><!-- /.panel-body -->
</div><!-- /.panel-default --> </div><!-- /.panel-default -->
</div><!-- /.col-md-6 --> </div><!-- /.col-md-6 -->
@ -183,28 +183,31 @@ function DisplayDashboard(){
<div class="panel panel-default"> <div class="panel panel-default">
<div class="panel-body wireless"> <div class="panel-body wireless">
<h4>Wireless Information</h4> <h4>Wireless Information</h4>
Connected To : <?php echo $strSSID ?><br /> <div class="info-item">Connected To</div> <?php echo $strSSID ?></br>
AP Mac Address : <?php echo $strBSSID ?><br /> <div class="info-item">AP Mac Address</div> <?php echo $strBSSID ?></br>
Bitrate : <?php echo $strBitrate ?><br /> <div class="info-item">Bitrate</div> <?php echo $strBitrate ?></br>
Transmit Power : <?php echo $strTxPower ?><br /> <div class="info-item">Transmit Power</div> <?php echo $strTxPower ?></br>
Frequency : <?php echo $strFrequency ?><br /> <div class="info-item">Frequency</div> <?php echo $strFrequency ?></br></br>
Link Quality : <div class="info-item">Link Quality</div>
<div class="progress"> <div class="progress">
<div class="progress-bar progress-bar-info progress-bar-striped active" role="progressbar" aria-valuenow="<?php echo $strLinkQuality ?>" aria-valuemin="0" aria-valuemax="100" style="width: <?php echo $strLinkQuality ?>%;"> <div class="progress-bar progress-bar-info progress-bar-striped active"
<?php echo $strLinkQuality ?>% role="progressbar"
aria-valuenow="<?php echo $strLinkQuality ?>" aria-valuemin="0" aria-valuemax="100"
style="width: <?php echo $strLinkQuality ?>%;"><?php echo $strLinkQuality ?>%
</div> </div>
</div> </div>
Signal Level : <div class="info-item">Signal Level</div>
<div class="progress"> <div class="progress">
<div class="progress-bar progress-bar-info progress-bar-striped active" role="progressbar" aria-valuenow="<?php echo $strSignalLevel ?>" aria-valuemin="0" aria-valuemax="100" style="width: <?php echo $strSignalLevel ?>%;"> <div class="progress-bar progress-bar-info progress-bar-striped active"
<?php echo $strSignalLevel ?>% role="progressbar"
aria-valuenow="<?php echo $strSignalLevel ?>" aria-valuemin="0" aria-valuemax="100"
style="width: <?php echo $strSignalLevel ?>%;"><?php echo $strSignalLevel ?>%
</div> </div>
</div> </div>
</div><!-- /.panel-body --> </div><!-- /.panel-body -->
</div><!-- /.panel-default --> </div><!-- /.panel-default -->
</div><!-- /.col-md-6 --> </div><!-- /.col-md-6 -->
</div> </div><!-- /.row -->
<div class="col-lg-12"> <div class="col-lg-12">
<div class="row"> <div class="row">
@ -982,6 +985,103 @@ function DisplayTorProxyConfig(){
<?php <?php
} }
/**
*
*
*/
function DisplaySystem(){
// hostname
exec("hostname -f", $hostarray);
$hostname = $hostarray[0];
// uptime
$uparray = explode(" ", exec("cat /proc/uptime"));
$seconds = round($uparray[0], 0);
$minutes = $seconds / 60;
$hours = $minutes / 60;
$days = floor($hours / 24);
$hours = floor($hours - ($days * 24));
$minutes = floor($minutes - ($days * 24 * 60) - ($hours * 60));
$uptime= '';
if ($days != 0) { $uptime .= $days . ' day' . (($days > 1)? 's ':' '); }
if ($hours != 0) { $uptime .= $hours . ' hour' . (($hours > 1)? 's ':' '); }
if ($minutes != 0) { $uptime .= $minutes . ' minute' . (($minutes > 1)? 's ':' '); }
// mem used
exec("free -m | awk '/Mem:/ { total=$2 } /buffers\/cache/ { used=$3 } END { print used/total*100}'", $memarray);
$memused = floor($memarray[0]);
if ($memused > 90) { $memused_status = "danger"; }
elseif ($memused > 75) { $memused_status = "warning"; }
elseif ($memused > 0) { $memused_status = "success"; }
// cpu load
$cores = exec("grep -c ^processor /proc/cpuinfo");
$loadavg = exec("awk '{print $1}' /proc/loadavg");
$cpuload = floor(($loadavg * 100) / $cores);
if ($cpuload > 90) { $cpuload_status = "danger"; }
elseif ($cpuload > 75) { $cpuload_status = "warning"; }
elseif ($cpuload > 0) { $cpuload_status = "success"; }
?>
<div class="row">
<div class="col-lg-12">
<div class="panel panel-primary">
<div class="panel-heading"><i class="fa fa-circle fa-fw"></i> System</div>
<div class="panel-body">
<?php
if (isset($_POST['system_reboot'])) {
echo '<div class="alert alert-warning">System Rebooting Now!</div>';
$result = shell_exec("sudo /sbin/reboot");
}
if (isset($_POST['system_shutdown'])) {
echo '<div class="alert alert-warning">System Shutting Down Now!</div>';
$result = shell_exec("sudo /sbin/shutdown -h now");
}
?>
<div class="row">
<div class="col-md-6">
<div class="panel panel-default">
<div class="panel-body">
<h4>System Information</h4>
<div class="info-item">Hostname</div> <?php echo $hostname ?></br>
<div class="info-item">Uptime</div> <?php echo $uptime ?></br></br>
<div class="info-item">Memory Used</div>
<div class="progress">
<div class="progress-bar progress-bar-<?php echo $memused_status ?> progress-bar-striped active"
role="progressbar"
aria-valuenow="<?php echo $memused ?>" aria-valuemin="0" aria-valuemax="100"
style="width: <?php echo $memused ?>%;"><?php echo $memused ?>%
</div>
</div>
<div class="info-item">CPU Load</div>
<div class="progress">
<div class="progress-bar progress-bar-<?php echo $cpuload_status ?> progress-bar-striped active"
role="progressbar"
aria-valuenow="<?php echo $cpuload ?>" aria-valuemin="0" aria-valuemax="100"
style="width: <?php echo $cpuload ?>%;"><?php echo $cpuload ?>%
</div>
</div>
</div><!-- /.panel-body -->
</div><!-- /.panel-default -->
</div><!-- /.col-md-6 -->
</div><!-- /.row -->
<form action="?page=system_info" method="POST">
<input type="submit" class="btn btn-warning" name="system_reboot" value="Reboot" />
<input type="submit" class="btn btn-warning" name="system_shutdown" value="Shutdown" />
<input type="button" class="btn btn-outline btn-primary" value="Refresh" onclick="document.location.reload(true)" />
</form>
</div><!-- /.panel-body -->
</div><!-- /.panel-primary -->
</div><!-- /.col-lg-12 -->
</div><!-- /.row -->
<?php
}
/** /**
* *
* *

View File

@ -133,6 +133,9 @@ $page = $_GET['page'];
<li> <li>
<a href="index.php?page=admin_conf"><i class="fa fa-dashboard fa-fw"></i> Configure RaspAP</a> <a href="index.php?page=admin_conf"><i class="fa fa-dashboard fa-fw"></i> Configure RaspAP</a>
</li> </li>
<li>
<a href="index.php?page=system_info"><i class="fa fa-circle fa-fw"></i> System</a>
</li>
</ul> </ul>
</div><!-- /.navbar-collapse --> </div><!-- /.navbar-collapse -->
</div><!-- /.navbar-default --> </div><!-- /.navbar-default -->
@ -176,6 +179,9 @@ $page = $_GET['page'];
case "save_hostapd_conf": case "save_hostapd_conf":
SaveHostAPDConfig(); SaveHostAPDConfig();
break; break;
case "system_info":
DisplaySystem();
break;
default: default:
DisplayDashboard(); DisplayDashboard();
} }