Add System Info and System Control (foundation)

This commit is contained in:
zlolz 2016-06-12 00:17:44 +00:00
parent f3ebe5ea4f
commit de7c0f7d79
4 changed files with 142 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`:
```sh
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
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
```
Once those modifications are done, git clone the files to `/var/www`.

7
dist/css/custom.css vendored
View file

@ -27,4 +27,9 @@
.btn-primary:hover {
background-color: #c61931;
border-color: #c61931;
}
}
.info-item {
width: 160px;
float: left;
}

View file

@ -161,50 +161,53 @@ function DisplayDashboard(){
<div class="panel-body">
<p><?php echo $status; ?></p>
<div class="row">
<div class="col-md-6">
<div class="panel panel-default">
<div class="panel-body">
<h4>Interface Information</h4>
Interface Name : wlan0<br />
IP Address : <?php echo $strIPAddress ?><br />
Subnet Mask : <?php echo $strNetMask ?><br />
Mac Address : <?php echo $strHWAddress ?><br />
<div class="col-md-6">
<div class="panel panel-default">
<div class="panel-body">
<h4>Interface Information</h4>
<div class="info-item">Interface Name</div> wlan0</br>
<div class="info-item">IP Address</div> <?php echo $strIPAddress ?></br>
<div class="info-item">Subnet Mask</div> <?php echo $strNetMask ?></br>
<div class="info-item">Mac Address</div> <?php echo $strHWAddress ?></br></br>
<h4>Interface Statistics</h4>
Received Packets : <?php echo $strRxPackets ?><br />
Received Bytes : <?php echo $strRxBytes ?><br /><br />
Transferred Packets : <?php echo $strTxPackets ?><br />
Transferred Bytes : <?php echo $strTxBytes ?><br />
</div><!-- /.panel-body -->
</div><!-- /.panel-default -->
</div><!-- /.col-md-6 -->
<h4>Interface Statistics</h4>
<div class="info-item">Received Packets</div> <?php echo $strRxPackets ?></br>
<div class="info-item">Received Bytes</div> <?php echo $strRxBytes ?></br></br>
<div class="info-item">Transferred Packets</div> <?php echo $strTxPackets ?></br>
<div class="info-item">Transferred Bytes</div> <?php echo $strTxBytes ?></br>
</div><!-- /.panel-body -->
</div><!-- /.panel-default -->
</div><!-- /.col-md-6 -->
<div class="col-md-6">
<div class="panel panel-default">
<div class="panel-body wireless">
<div class="col-md-6">
<div class="panel panel-default">
<div class="panel-body wireless">
<h4>Wireless Information</h4>
Connected To : <?php echo $strSSID ?><br />
AP Mac Address : <?php echo $strBSSID ?><br />
Bitrate : <?php echo $strBitrate ?><br />
Transmit Power : <?php echo $strTxPower ?><br />
Frequency : <?php echo $strFrequency ?><br />
Link Quality :
<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 ?>%;">
<?php echo $strLinkQuality ?>%
</div>
</div>
Signal Level :
<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 ?>%;">
<?php echo $strSignalLevel ?>%
</div>
</div>
</div><!-- /.panel-body -->
</div><!-- /.panel-default -->
</div><!-- /.col-md-6 -->
</div>
<div class="info-item">Connected To</div> <?php echo $strSSID ?></br>
<div class="info-item">AP Mac Address</div> <?php echo $strBSSID ?></br>
<div class="info-item">Bitrate</div> <?php echo $strBitrate ?></br>
<div class="info-item">Transmit Power</div> <?php echo $strTxPower ?></br>
<div class="info-item">Frequency</div> <?php echo $strFrequency ?></br></br>
<div class="info-item">Link Quality</div>
<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 ?>%;"><?php echo $strLinkQuality ?>%
</div>
</div>
<div class="info-item">Signal Level</div>
<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 ?>%;"><?php echo $strSignalLevel ?>%
</div>
</div>
</div><!-- /.panel-body -->
</div><!-- /.panel-default -->
</div><!-- /.col-md-6 -->
</div><!-- /.row -->
<div class="col-lg-12">
<div class="row">
@ -982,6 +985,91 @@ function DisplayTorProxyConfig(){
<?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 = sprintf('%d', floor($hours - ($days * 24)));
$minutes = sprintf('%d', 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]);
?>
<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>
<div class="info-item">Memory Used</div>
<div class="progress">
<div class="progress-bar progress-bar-info 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><!-- /.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>
<a href="index.php?page=admin_conf"><i class="fa fa-dashboard fa-fw"></i> Configure RaspAP</a>
</li>
<li>
<a href="index.php?page=system_info"><i class="fa fa-circle fa-fw"></i> System</a>
</li>
</ul>
</div><!-- /.navbar-collapse -->
</div><!-- /.navbar-default -->
@ -176,6 +179,9 @@ $page = $_GET['page'];
case "save_hostapd_conf":
SaveHostAPDConfig();
break;
case "system_info":
DisplaySystem();
break;
default:
DisplayDashboard();
}