mirror of
https://github.com/RaspAP/raspap-webgui.git
synced 2024-11-25 09:00:25 +00:00
Replace switchClientState.sh by php function in get_clients.php
Cleanup display of client on dashboard
This commit is contained in:
parent
76e2eecaec
commit
2b4c9472e6
5 changed files with 90 additions and 97 deletions
|
@ -1,49 +0,0 @@
|
|||
#!/bin/bash
|
||||
#
|
||||
# parameters: up or down
|
||||
# current client from getClients.sh
|
||||
#
|
||||
# requires: getClients.sh, onoff_huawei_hilink.sh in same path
|
||||
# ifconfig, ifup, ifdown, systemd-cat
|
||||
#
|
||||
#
|
||||
# zbchristian 2020
|
||||
|
||||
path=`dirname $0`
|
||||
clients=$($path/getClients.sh simple)
|
||||
|
||||
if [[ -z $clients ]] || [[ $(echo $clients| grep -oP '(?<="clients": )\d') == 0 ]]; then echo "$0 : No client found"|systemd-cat; exit; fi
|
||||
|
||||
devs=( $(echo $clients | grep -oP '(?<="name": ")\w*(?=")') )
|
||||
types=( $(echo $clients | grep -oP '(?<="type": )\d') )
|
||||
|
||||
# find the device with the max type number
|
||||
imax=0
|
||||
type=0
|
||||
for i in "${!devs[@]}"; do
|
||||
if [[ ${types[$i]} > $type ]]; then imax=$i; type=${types[$i]}; fi
|
||||
done
|
||||
device=${devs[$imax]}
|
||||
|
||||
echo "$0: try to set $device $1" | systemd-cat
|
||||
|
||||
connected=`ifconfig -a | grep -i $device -A 1 | grep -oP "(?<=inet )([0-9]{1,3}\.){3}[0-9]{1,3}"`
|
||||
|
||||
if [ -z "$connected" ] && [[ $1 == "up" ]]; then
|
||||
if [[ $type == 3 ]]; then ip link set $device up; fi
|
||||
if [[ $type == 5 ]]; then ifup $device; fi
|
||||
fi
|
||||
if [[ ! -z "$connected" ]] && [[ $1 == "down" ]]; then
|
||||
if [[ $type == 3 ]]; then ip link set $device down; fi
|
||||
if [[ $type == 5 ]]; then ifdown $device; fi
|
||||
fi
|
||||
if [[ $type == 4 ]]; then
|
||||
ipadd=$(echo $connected | grep -oP "([0-9]{1,3}\.){2}[0-9]{1,3}")".1" # get ip address of the Hilink API
|
||||
mode=0
|
||||
if [[ $1 == "up" ]]; then mode=1; fi
|
||||
if [[ -f /etc/raspap/networking/mobiledata.ini ]]; then
|
||||
pin=$(cat /etc/raspap/networking/mobiledata.ini | sed -rn 's/pin = ([0-9]*)$/\1/p' )
|
||||
fi
|
||||
$path/onoff_huawei_hilink.sh -c $mode -h $ipadd -p $pin
|
||||
fi
|
||||
|
|
@ -96,19 +96,9 @@ function DisplayDashboard(&$extraFooterScripts)
|
|||
$clientinfo=array("name"=>"none","type"=>-1,"connected"=>"n");
|
||||
$raspi_client=$_SESSION['wifi_client_interface'];
|
||||
load_client_config();
|
||||
$client_devs = getClients(false);
|
||||
if(!empty($client_devs)) {
|
||||
$ncl=$client_devs["clients"];
|
||||
if($ncl > 0) {
|
||||
$ty=-1;
|
||||
foreach($client_devs["device"] as $dev) {
|
||||
if(($id=array_search($dev["type"],$_SESSION["net-device-types"])) > $ty && !$dev["isAP"]) {
|
||||
$ty=$id;
|
||||
$clientinfo=$dev;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$all_clients = getClients(false);
|
||||
$clientinfo = array("name" => "none", "connected" => "n");
|
||||
if ( ($idx = findCurrentClientIndex($all_clients)) >= 0) $clientinfo = $all_clients["device"][$idx];
|
||||
if ($clientinfo["name"] != "none") $raspi_client = $clientinfo["name"];
|
||||
$interfaceState = $clientinfo["connected"] == "y" ? 'UP' : 'DOWN';
|
||||
$txPower="";
|
||||
|
@ -127,7 +117,8 @@ function DisplayDashboard(&$extraFooterScripts)
|
|||
// Pressed stop button
|
||||
if ($interfaceState === 'UP') {
|
||||
$status->addMessage(sprintf(_('Interface is going %s.'), _('down')), 'warning');
|
||||
exec('sudo /usr/local/sbin/switchClientState.sh down');
|
||||
setClientState("down");
|
||||
// exec('sudo /usr/local/sbin/switchClientState.sh down');
|
||||
$status->addMessage(sprintf(_('Interface is now %s.'), _('down')), 'success');
|
||||
} elseif ($interfaceState === 'unknown') {
|
||||
$status->addMessage(_('Interface state unknown.'), 'danger');
|
||||
|
@ -138,7 +129,8 @@ function DisplayDashboard(&$extraFooterScripts)
|
|||
// Pressed start button
|
||||
if ($interfaceState === 'DOWN') {
|
||||
$status->addMessage(sprintf(_('Interface is going %s.'), _('up')), 'warning');
|
||||
exec('sudo /usr/local/sbin/switchClientState.sh up');
|
||||
setClientState("up");
|
||||
// exec('sudo /usr/local/sbin/switchClientState.sh up');
|
||||
exec('sudo ip -s a f label ' . $raspi_client);
|
||||
$status->addMessage(sprintf(_('Interface is now %s.'), _('up')), 'success');
|
||||
} elseif ($interfaceState === 'unknown') {
|
||||
|
@ -151,8 +143,6 @@ function DisplayDashboard(&$extraFooterScripts)
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// brought in from template
|
||||
$arrHostapdConf = parse_ini_file(RASPI_CONFIG.'/hostapd.ini');
|
||||
$bridgedEnable = $arrHostapdConf['BridgedEnable'];
|
||||
|
|
|
@ -128,7 +128,10 @@ function getClients($simple=true) {
|
|||
$cl["device"][$i]["connected"] = "y";
|
||||
$cl["device"][$i]["wan_ip"] = $ipadd[0];
|
||||
}
|
||||
else $cl["device"][$i]["connected"] = "n";
|
||||
else {
|
||||
$cl["device"][$i]["connected"] = "n";
|
||||
$cl["device"][$i]["wan_ip"] = "-";
|
||||
}
|
||||
unset($res);
|
||||
exec("$path/info_huawei.sh operator hilink $apiadd",$res);
|
||||
$cl["device"][$i]["operator"] = $res[0];
|
||||
|
@ -170,5 +173,52 @@ function load_client_config() {
|
|||
}
|
||||
}
|
||||
|
||||
?>
|
||||
function findCurrentClientIndex($clients) {
|
||||
$devid = -1;
|
||||
if(!empty($clients)) {
|
||||
$ncl=$clients["clients"];
|
||||
if($ncl > 0) {
|
||||
$ty=-1;
|
||||
foreach($clients["device"] as $i => $dev) {
|
||||
if(($id=array_search($dev["type"],$_SESSION["net-device-types"])) > $ty && !$dev["isAP"]) {
|
||||
$ty=$id;
|
||||
$devid=$i;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return $devid;
|
||||
}
|
||||
|
||||
function setClientState($state) {
|
||||
$clients=getClients();
|
||||
if ( ($idx = findCurrentClientIndex($clients)) >= 0) {
|
||||
$dev = $clients["device"][$idx];
|
||||
exec('ifconfig -a | grep -i '.$dev["name"].' -A 1 | grep -oP "(?<=inet )([0-9]{1,3}\.){3}[0-9]{1,3}"',$res);
|
||||
if ( !empty($res)) $connected=$res[0];
|
||||
switch($dev["type"]) {
|
||||
case "wlan":
|
||||
if($state =="up") exec('sudo ip link set '.$dev["name"].' up');
|
||||
if(!empty($connected) && $state =="down") exec('sudo ip link set '.$dev["name"].' down');
|
||||
break;
|
||||
case "hilink":
|
||||
preg_match("/^([0-9]{1,3}\.){3}/",$connected,$ipadd);
|
||||
$ipadd = $ipadd[0].'1'; // ip address of the Hilink api
|
||||
$mode = ($state == "up") ? 1 : 0;
|
||||
if (file_exists(RASPI_CONFIG."/networking/mobiledata.ini")) {
|
||||
$dat = parse_ini_file(RASPI_CONFIG."/networking/mobiledata.ini");
|
||||
$pin = (isset($dat["pin"]) && preg_match("/^[0-9]*$/",$dat["pin"])) ? $dat["pin"] : "";
|
||||
exec('sudo '.RASPI_CLIENT_SCRIPT_PATH.'/onoff_huawei_hilink.sh -c '.$mode.' -h '.$ipadd.' -p '.$pin);
|
||||
}
|
||||
break;
|
||||
case "ppp":
|
||||
if($state == "up") exec('ipup '.$dev["name"]);
|
||||
if(!empty($connected) && $state == "down") exec('ipup '.$dev["name"]);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -30,6 +30,8 @@ www-data ALL=(ALL) NOPASSWD:/sbin/reboot
|
|||
www-data ALL=(ALL) NOPASSWD:/sbin/ip link set wlan[0-9] down
|
||||
www-data ALL=(ALL) NOPASSWD:/sbin/ip link set wlan[0-9] up
|
||||
www-data ALL=(ALL) NOPASSWD:/sbin/ip -s a f label wlan[0-9]
|
||||
www-data ALL=(ALL) NOPASSWD:/sbin/ifup *
|
||||
www-data ALL=(ALL) NOPASSWD:/sbin/ifdown *
|
||||
www-data ALL=(ALL) NOPASSWD:/bin/cp /etc/raspap/networking/dhcpcd.conf /etc/dhcpcd.conf
|
||||
www-data ALL=(ALL) NOPASSWD:/etc/raspap/hostapd/enablelog.sh
|
||||
www-data ALL=(ALL) NOPASSWD:/etc/raspap/hostapd/disablelog.sh
|
||||
|
@ -43,8 +45,7 @@ www-data ALL=(ALL) NOPASSWD:/bin/cp /tmp/dnsmasqdata /etc/dnsmasq.d/090_adblock.
|
|||
www-data ALL=(ALL) NOPASSWD:/bin/cp /tmp/dnsmasq_custom /etc/raspap/adblock/custom.txt
|
||||
www-data ALL=(ALL) NOPASSWD:/etc/raspap/adblock/update_blocklist.sh
|
||||
www-data ALL=(ALL) NOPASSWD:/usr/bin/socat - /dev/ttyUSB[0-9]
|
||||
www-data ALL=(ALL) NOPASSWD:/usr/local/sbin/switchClientState.sh up
|
||||
www-data ALL=(ALL) NOPASSWD:/usr/local/sbin/switchClientState.sh down
|
||||
www-data ALL=(ALL) NOPASSWD:/usr/local/sbin/onoff_huawei_hilink.sh *
|
||||
www-data ALL=(ALL) NOPASSWD:/bin/sed -i * /etc/wvdial.conf
|
||||
www-data ALL=(ALL) NOPASSWD:/bin/sed -i * /etc/udev/rules.d/80-raspap-net-devices.rules
|
||||
www-data ALL=(ALL) NOPASSWD:/usr/bin/tee -a /etc/udev/rules.d/80-raspap-net-devices.rules
|
||||
|
|
|
@ -35,35 +35,36 @@
|
|||
<h4><?php echo _("$client_title"); ?></h4>
|
||||
<div class="row justify-content-md-center">
|
||||
<div class="col-md">
|
||||
<?php $valEcho=function($cl,$id) {$val = isset($cl[$id])&& !empty($cl[$id]) ? $cl[$id] : "-"; echo htmlspecialchars($val,ENT_QUOTES);} ?>
|
||||
<?php if ($clientinfo["type"] == "wlan") : // WIRELESS ?>
|
||||
<div class="info-item"><?php echo _("Connected To"); ?></div><div><?php echo htmlspecialchars($clientinfo["ssid"], ENT_QUOTES); ?></div>
|
||||
<div class="info-item"><?php echo _("AP Mac Address"); ?></div><div><?php echo htmlspecialchars($clientinfo["ap-mac"], ENT_QUOTES); ?></div>
|
||||
<div class="info-item"><?php echo _("Bitrate"); ?></div><div><?php echo htmlspecialchars($clientinfo["bitrate"], ENT_QUOTES); ?></div>
|
||||
<div class="info-item"><?php echo _("Signal Level"); ?></div><div><?php echo htmlspecialchars($clientinfo["signal"], ENT_QUOTES); ?></div>
|
||||
<div class="info-item"><?php echo _("Connected To"); ?></div><div><?php $valEcho($clientinfo,"ssid"); ?></div>
|
||||
<div class="info-item"><?php echo _("AP Mac Address"); ?></div><div><?php $valEcho($clientinfo,"ap-mac"); ?></div>
|
||||
<div class="info-item"><?php echo _("Bitrate"); ?></div><div><?php $valEcho($clientinfo,"bitrate"); ?></div>
|
||||
<div class="info-item"><?php echo _("Signal Level"); ?></div><div><?php $valEcho($clientinfo,"signal"); ?></div>
|
||||
<div class="info-item"><?php echo _("Transmit Power"); ?></div><div><?php echo htmlspecialchars($txPower, ENT_QUOTES); ?></div>
|
||||
<div class="info-item"><?php echo _("Frequency"); ?></div><div><?php echo htmlspecialchars($clientinfo["freq"]." MHz", ENT_QUOTES); ?></div>
|
||||
<div class="info-item"><?php echo _("Frequency"); ?></div><div><?php $valEcho($clientinfo,"freq"); ?></div>
|
||||
<?php elseif ($clientinfo["type"] == "phone" ) : // Smartphones (tethering over USB) ?>
|
||||
<div class="info-item"><?php echo _("Device"); ?></div><div><?php echo htmlspecialchars($clientinfo["vendor"]." ".$clientinfo["model"], ENT_QUOTES); ?></div>
|
||||
<div class="info-item"><?php echo _("IP Address"); ?></div><div><?php echo htmlspecialchars($clientinfo["ipaddress"], ENT_QUOTES); ?></div>
|
||||
<div class="info-item"><?php echo _("Device"); ?></div><div><?php $valEcho($clientinfo,"vendor")." ". $valEcho($clientinfo,"model"); ?></div>
|
||||
<div class="info-item"><?php echo _("IP Address"); ?></div><div><?php $valEcho($clientinfo,"ipaddress"); ?></div>
|
||||
<?php elseif ($clientinfo["type"] == "hilink" ) : // MOBILE DATA - ROUTER MODE (HILINK) ?>
|
||||
<?php
|
||||
exec('ip route list | sed -rn "s/default via (([0-9]{1,3}\.){3}[0-9]{1,3}).*dev '.$clientinfo["name"].'.*/\1/p"',$gw); // get gateway
|
||||
$gw=empty($gw) ? "" : $gw[0];
|
||||
?>
|
||||
<div class="info-item"><?php echo _("Device"); ?></div><div><?php echo htmlspecialchars($clientinfo["model"], ENT_QUOTES)." (Hilink)"; ?></div>
|
||||
<div class="info-item"><?php echo _("Connection mode"); ?></div><div><?php echo htmlspecialchars($clientinfo["mode"], ENT_QUOTES); ?></div>
|
||||
<div class="info-item"><?php echo _("Signal quality"); ?></div><div><?php echo htmlspecialchars($clientinfo["signal"], ENT_QUOTES); ?></div>
|
||||
<div class="info-item"><?php echo _("Network"); ?></div><div><?php echo htmlspecialchars($clientinfo["operator"], ENT_QUOTES); ?></div>
|
||||
<div class="info-item"><?php echo _("WAN IP"); ?></div><div><?php echo htmlspecialchars($clientinfo["ipaddress"], ENT_QUOTES); ?></div>
|
||||
<div class="info-item"><?php echo _("Device"); ?></div><div><?php $valEcho($clientinfo,"model")." (Hilink)"; ?></div>
|
||||
<div class="info-item"><?php echo _("Connection mode"); ?></div><div><?php $valEcho($clientinfo,"mode"); ?></div>
|
||||
<div class="info-item"><?php echo _("Signal quality"); ?></div><div><?php $valEcho($clientinfo,"signal"); ?></div>
|
||||
<div class="info-item"><?php echo _("Network"); ?></div><div><?php $valEcho($clientinfo,"operator"); ?></div>
|
||||
<div class="info-item"><?php echo _("WAN IP"); ?></div><div><?php $valEcho($clientinfo,"wan_ip"); ?></div>
|
||||
<div class="info-item"><?php echo _("Web-GUI"); ?></div><div><?php if(!empty($gw)) echo '<a href="http://'.$gw.'" >'.$gw."</a>"; ?></div>
|
||||
<?php elseif ($clientinfo["type"] == "ppp" ) : // MOBILE DATA MODEM) ?>
|
||||
<div class="info-item"><?php echo _("Device"); ?></div><div><?php echo htmlspecialchars($clientinfo["model"], ENT_QUOTES); ?></div>
|
||||
<div class="info-item"><?php echo _("Connection mode"); ?></div><div><?php echo htmlspecialchars($clientinfo["mode"], ENT_QUOTES); ?></div>
|
||||
<div class="info-item"><?php echo _("Signal strength"); ?></div><div><?php echo htmlspecialchars($clientinfo["signal"], ENT_QUOTES); ?></div>
|
||||
<div class="info-item"><?php echo _("Network"); ?></div><div><?php echo htmlspecialchars($clientinfo["operator"], ENT_QUOTES); ?></div>
|
||||
<div class="info-item"><?php echo _("Device"); ?></div><div><?php $valEcho($clientinfo,"model"); ?></div>
|
||||
<div class="info-item"><?php echo _("Connection mode"); ?></div><div><?php $valEcho($clientinfo,"mode"); ?></div>
|
||||
<div class="info-item"><?php echo _("Signal strength"); ?></div><div><?php $valEcho($clientinfo,"signal"); ?></div>
|
||||
<div class="info-item"><?php echo _("Network"); ?></div><div><?php $valEcho($clientinfo,"operator"); ?></div>
|
||||
<?php elseif ($clientinfo["type"] == "eth" ) : // ETHERNET ?>
|
||||
<div class="info-item"><?php echo _("Device"); ?></div><div><?php echo htmlspecialchars($clientinfo["vendor"]." ".$clientinfo["model"], ENT_QUOTES); ?></div>
|
||||
<div class="info-item"><?php echo _("IP Address"); ?></div><div><?php echo htmlspecialchars($clientinfo["ipaddress"], ENT_QUOTES); ?></div>
|
||||
<div class="info-item"><?php echo _("Device"); ?></div><div><?php $valEcho($clientinfo,"vendor")." ".$valEcho($clientinfo,"model"); ?></div>
|
||||
<div class="info-item"><?php echo _("IP Address"); ?></div><div><?php echo $valEcho($clientinfo,"ipaddress"); ?></div>
|
||||
<?php else : // NO CLIENT ?>
|
||||
<div class="info-item"><?php echo _("No Client device found"); ?></div>
|
||||
<?php endif; ?>
|
||||
|
|
Loading…
Reference in a new issue