mirror of
https://github.com/RaspAP/raspap-webgui.git
synced 2024-11-25 09:00:25 +00:00
Merge with upstream master
This commit is contained in:
commit
fa849e55de
7 changed files with 81 additions and 25 deletions
|
@ -54,16 +54,19 @@ $(document).on("click", ".js-add-dhcp-static-lease", function(e) {
|
|||
var container = $(".js-new-dhcp-static-lease");
|
||||
var mac = $("input[name=mac]", container).val().trim();
|
||||
var ip = $("input[name=ip]", container).val().trim();
|
||||
var comment = $("input[name=comment]", container).val().trim();
|
||||
if (mac == "" || ip == "") {
|
||||
return;
|
||||
}
|
||||
var row = $("#js-dhcp-static-lease-row").html()
|
||||
.replace("{{ mac }}", mac)
|
||||
.replace("{{ ip }}", ip);
|
||||
.replace("{{ ip }}", ip)
|
||||
.replace("{{ comment }}", comment);
|
||||
$(".js-dhcp-static-lease-container").append(row);
|
||||
|
||||
$("input[name=mac]", container).val("");
|
||||
$("input[name=ip]", container).val("");
|
||||
$("input[name=comment]", container).val("");
|
||||
});
|
||||
|
||||
$(document).on("click", ".js-remove-dhcp-static-lease", function(e) {
|
||||
|
|
|
@ -1,11 +1,24 @@
|
|||
<?php
|
||||
|
||||
class System {
|
||||
public function hostname() {
|
||||
/**
|
||||
* Sytem info class
|
||||
*
|
||||
* @description System info class for RaspAP
|
||||
* @author Bill Zimmerman <billzimmerman@gmail.com>
|
||||
* @license https://github.com/raspap/raspap-webgui/blob/master/LICENSE
|
||||
*/
|
||||
|
||||
namespace RaspAP\System;
|
||||
|
||||
class Sysinfo
|
||||
{
|
||||
public function hostname()
|
||||
{
|
||||
return shell_exec("hostname -f");
|
||||
}
|
||||
|
||||
public function uptime() {
|
||||
public function uptime()
|
||||
{
|
||||
$uparray = explode(" ", exec("cat /proc/uptime"));
|
||||
$seconds = round($uparray[0], 0);
|
||||
$minutes = $seconds / 60;
|
||||
|
@ -15,10 +28,10 @@ class System {
|
|||
$minutes = floor($minutes - ($days * 24 * 60) - ($hours * 60));
|
||||
$uptime= '';
|
||||
if ($days != 0) {
|
||||
$uptime .= $days . ' day' . (($days > 1)? 's ':' ');
|
||||
$uptime .= $days . ' day' . (($days > 1)? 's ':' ');
|
||||
}
|
||||
if ($hours != 0) {
|
||||
$uptime .= $hours . ' hour' . (($hours > 1)? 's ':' ');
|
||||
$uptime .= $hours . ' hour' . (($hours > 1)? 's ':' ');
|
||||
}
|
||||
if ($minutes != 0) {
|
||||
$uptime .= $minutes . ' minute' . (($minutes > 1)? 's ':' ');
|
||||
|
@ -27,33 +40,40 @@ class System {
|
|||
return $uptime;
|
||||
}
|
||||
|
||||
public function usedMemory() {
|
||||
public function usedMemory()
|
||||
{
|
||||
$used = shell_exec("free -m | awk '/Mem:/ { total=$2 ; used=$3 } END { print used/total*100}'");
|
||||
return floor($used);
|
||||
}
|
||||
|
||||
public function processorCount() {
|
||||
public function processorCount()
|
||||
{
|
||||
$procs = shell_exec("nproc --all");
|
||||
return intval($procs);
|
||||
}
|
||||
|
||||
public function loadAvg1Min() {
|
||||
public function loadAvg1Min()
|
||||
{
|
||||
$load = exec("awk '{print $1}' /proc/loadavg");
|
||||
return floatval($load);
|
||||
}
|
||||
|
||||
public function systemLoadPercentage() {
|
||||
public function systemLoadPercentage()
|
||||
{
|
||||
return intval(($this->loadAvg1Min() * 100) / $this->processorCount());
|
||||
}
|
||||
|
||||
public function systemTemperature() {
|
||||
public function systemTemperature()
|
||||
{
|
||||
$cpuTemp = file_get_contents("/sys/class/thermal/thermal_zone0/temp");
|
||||
return number_format((float)$cpuTemp/1000, 1);
|
||||
}
|
||||
|
||||
public function hostapdStatus() {
|
||||
public function hostapdStatus()
|
||||
{
|
||||
exec('pidof hostapd | wc -l', $status);
|
||||
return $status;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -154,6 +154,20 @@ function validateDHCPInput()
|
|||
return $errors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compares to string IPs
|
||||
*
|
||||
* @param string $ip1
|
||||
* @param string $ip2
|
||||
* @return boolean $result
|
||||
*/
|
||||
function compareIPs($ip1, $ip2)
|
||||
{
|
||||
$ipu1 = sprintf('%u', ip2long($ip1["ip"])) + 0;
|
||||
$ipu2 = sprintf('%u', ip2long($ip2["ip"])) + 0;
|
||||
return $ipu1 > $ipu2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates a dnsmasq configuration
|
||||
*
|
||||
|
@ -171,13 +185,25 @@ function updateDnsmasqConfig($iface,$status)
|
|||
$config .= $_POST['RangeLeaseTime'];
|
||||
}
|
||||
$config .= $_POST['RangeLeaseTimeUnits'].PHP_EOL;
|
||||
// Static leases
|
||||
$staticLeases = array();
|
||||
for ($i=0; $i < count($_POST["static_leases"]["mac"]); $i++) {
|
||||
$mac = trim($_POST["static_leases"]["mac"][$i]);
|
||||
$ip = trim($_POST["static_leases"]["ip"][$i]);
|
||||
$comment = trim($_POST["static_leases"]["comment"][$i]);
|
||||
if ($mac != "" && $ip != "") {
|
||||
$config .= "dhcp-host=$mac,$ip".",set:known".PHP_EOL;
|
||||
$staticLeases[] = array('mac' => $mac, 'ip' => $ip, 'comment' => $comment);
|
||||
}
|
||||
}
|
||||
// Sort ascending by IPs
|
||||
usort($staticLeases, "compareIPs");
|
||||
// Update config
|
||||
for ($i = 0; $i < count($staticLeases); $i++) {
|
||||
$mac = $staticLeases[$i]['mac'];
|
||||
$ip = $staticLeases[$i]['ip'];
|
||||
$comment = $staticLeases[$i]['comment'];
|
||||
$config .= "dhcp-host=$mac,$ip # $comment".PHP_EOL;
|
||||
}
|
||||
if ($_POST['no-resolv'] == "1") {
|
||||
$config .= "no-resolv".PHP_EOL;
|
||||
}
|
||||
|
@ -191,9 +217,6 @@ function updateDnsmasqConfig($iface,$status)
|
|||
}
|
||||
$config .= PHP_EOL;
|
||||
}
|
||||
if ($_POST['dhcp-ignore'] == "1") {
|
||||
$config .= 'dhcp-ignore=tag:!known'.PHP_EOL;
|
||||
}
|
||||
file_put_contents("/tmp/dnsmasqdata", $config);
|
||||
$msg = file_exists(RASPI_DNSMASQ_PREFIX.$iface.'.conf') ? 'updated' : 'added';
|
||||
system('sudo cp /tmp/dnsmasqdata '.RASPI_DNSMASQ_PREFIX.$iface.'.conf', $result);
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
require_once 'app/lib/system.php';
|
||||
|
||||
$system = new System();
|
||||
$system = new \RaspAP\System\Sysinfo;
|
||||
|
||||
$hostname = $system->hostname();
|
||||
$uptime = $system->uptime();
|
||||
|
|
|
@ -153,7 +153,7 @@ function DisplaySystem()
|
|||
);
|
||||
|
||||
#fetch system status variables.
|
||||
$system = new System();
|
||||
$system = new \RaspAP\System\Sysinfo;
|
||||
|
||||
$hostname = $system->hostname();
|
||||
$uptime = $system->uptime();
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
with the contributions of our <a href="https://github.com/raspap/raspap-webgui/graphs/contributors">developer community</a>
|
||||
and <a href="https://crowdin.com/project/raspap">language translators</a>.
|
||||
Learn more about joining the project as a <a href="https://docs.raspap.com/#get-involved">code contributor</a>,
|
||||
<a href="https://docs.raspap.com/translations/">translator</a> or <a href="https://github.com/sponsors/RaspAP">financial sponsor</a> with immediate access to <a href="https://github.com/sponsors/RaspAP#exclusive-features">exclusive features</a> available to <strong>Insiders</strong>.</div>
|
||||
<a href="https://docs.raspap.com/translations.html">translator</a> or <a href="https://github.com/sponsors/RaspAP">financial sponsor</a> with immediate access to <a href="https://github.com/sponsors/RaspAP#exclusive-features">exclusive features</a> available to <strong>Insiders</strong>.</div>
|
||||
<div class="mt-3">Project documentation is available at <a href="https://docs.raspap.com/">https://docs.raspap.com/</a></div>
|
||||
<div class="mt-3 project-links">
|
||||
<div class="row">
|
||||
|
|
|
@ -9,14 +9,18 @@
|
|||
</p>
|
||||
<div class="dhcp-static-leases js-dhcp-static-lease-container">
|
||||
<?php foreach ($hosts as $host) : ?>
|
||||
<?php list($host, $comment) = array_map("trim", explode("#", $host)); ?>
|
||||
<?php list($mac, $ip) = array_map("trim", explode(",", $host)); ?>
|
||||
<div class="row dhcp-static-lease-row js-dhcp-static-lease-row">
|
||||
<div class="col-md-5 col-xs-5">
|
||||
<div class="col-md-4 col-xs-3">
|
||||
<input type="text" name="static_leases[mac][]" value="<?php echo htmlspecialchars($mac, ENT_QUOTES) ?>" placeholder="<?php echo _("MAC address") ?>" class="form-control">
|
||||
</div>
|
||||
<div class="col-md-5 col-xs-4">
|
||||
<div class="col-md-3 col-xs-3">
|
||||
<input type="text" name="static_leases[ip][]" value="<?php echo htmlspecialchars($ip, ENT_QUOTES) ?>" placeholder="<?php echo _("IP address") ?>" class="form-control">
|
||||
</div>
|
||||
<div class="col-md-3 col-xs-3">
|
||||
<input type="text" name="static_leases[comment][]" value="<?php echo htmlspecialchars($comment, ENT_QUOTES) ?>" placeholder="<?php echo _("Optional Comment") ?>" class="form-control">
|
||||
</div>
|
||||
<div class="col-md-2 col-xs-3">
|
||||
<button type="button" class="btn btn-outline-danger js-remove-dhcp-static-lease"><i class="far fa-trash-alt"></i></button>
|
||||
</div>
|
||||
|
@ -25,12 +29,15 @@
|
|||
</div>
|
||||
|
||||
<div class="row dhcp-static-lease-row js-new-dhcp-static-lease">
|
||||
<div class="col-md-5 col-xs-5">
|
||||
<div class="col-md-4 col-xs-3">
|
||||
<input type="text" name="mac" value="" placeholder="<?php echo _("MAC address") ?>" class="form-control" autofocus="autofocus">
|
||||
</div>
|
||||
<div class="col-md-5 col-xs-4">
|
||||
<div class="col-md-3 col-xs-3">
|
||||
<input type="text" name="ip" value="" placeholder="<?php echo _("IP address") ?>" class="form-control">
|
||||
</div>
|
||||
<div class="col-md-3 col-xs-3">
|
||||
<input type="text" name="comment" value="" placeholder="<?php echo _("Optional Comment") ?>" class="form-control">
|
||||
</div>
|
||||
<div class="col-md-2 col-xs-3">
|
||||
<button type="button" class="btn btn-outline-success js-add-dhcp-static-lease"><i class="far fa-plus-square"></i></button>
|
||||
</div>
|
||||
|
@ -53,12 +60,15 @@
|
|||
|
||||
<template id="js-dhcp-static-lease-row">
|
||||
<div class="row dhcp-static-lease-row js-dhcp-static-lease-row">
|
||||
<div class="col-md-5 col-xs-5">
|
||||
<div class="col-md-4 col-xs-3">
|
||||
<input type="text" name="static_leases[mac][]" value="{{ mac }}" placeholder="<?php echo _("MAC address") ?>" class="form-control">
|
||||
</div>
|
||||
<div class="col-md-5 col-xs-4">
|
||||
<div class="col-md-3 col-xs-3">
|
||||
<input type="text" name="static_leases[ip][]" value="{{ ip }}" placeholder="<?php echo _("IP address") ?>" class="form-control">
|
||||
</div>
|
||||
<div class="col-md-3 col-xs-3">
|
||||
<input type="text" name="static_leases[comment][]" value="{{ comment }}" placeholder="<?php echo _("Optional Comment") ?>" class="form-control">
|
||||
</div>
|
||||
<div class="col-md-2 col-xs-3">
|
||||
<button type="button" class="btn btn-outline-danger js-remove-dhcp-static-lease"><i class="far fa-trash-alt"></i></button>
|
||||
</div>
|
||||
|
|
Loading…
Reference in a new issue