mirror of
https://github.com/billz/raspap-webgui.git
synced 2023-10-10 13:37:24 +02:00
Switch client on: wait for connection w/ timeout
add new switchClientState.sh to be used in hilink service (calls the php getClients code)
This commit is contained in:
parent
11e2724afa
commit
3b64697b4a
34
config/client_config/switchClientState.sh
Normal file
34
config/client_config/switchClientState.sh
Normal file
@ -0,0 +1,34 @@
|
||||
#!/bin/bash
|
||||
# start with "sudo"
|
||||
# parameters: up or on
|
||||
#
|
||||
# switch client state to UP
|
||||
# the actual code is in PHP
|
||||
|
||||
# get webroot
|
||||
webroot=$(cat /etc/lighttpd/lighttpd.conf | sed -rn 's/server.document-root\s*=\s*\"(.*)\"\s*$/\1/p')
|
||||
if [ -z "$webroot" ] || [ ! -d "$webroot" ]; then
|
||||
exit
|
||||
fi
|
||||
cd $webroot
|
||||
|
||||
state=""
|
||||
if [ ! -z $1 ] && [[ $1 =~ ^(up|on|UP|ON)$ ]]; then
|
||||
state="up"
|
||||
elif [ ! -z $1 ] && [[ $1 =~ ^(down|off|DOWN|OFF)$ ]]; then
|
||||
state="down"
|
||||
fi
|
||||
|
||||
[ -z "$state" ] && exit
|
||||
|
||||
php << _EOF_
|
||||
<?php
|
||||
require_once("includes/config.php");
|
||||
require_once("includes/get_clients.php");
|
||||
|
||||
load_client_config();
|
||||
setClientState("$state");
|
||||
?>
|
||||
_EOF_
|
||||
|
||||
|
@ -190,6 +190,15 @@ function findCurrentClientIndex($clients) {
|
||||
return $devid;
|
||||
}
|
||||
|
||||
function waitClientConnected($dev, $timeout=10) {
|
||||
do {
|
||||
exec('ifconfig -a | grep -i '.$dev.' -A 1 | grep -oP "(?<=inet )([0-9]{1,3}\.){3}[0-9]{1,3}"',$res);
|
||||
$connected= !empty($res);
|
||||
if(!$connected) sleep(1);
|
||||
} while(!$connected && --$timeout > 0);
|
||||
return $connected;
|
||||
}
|
||||
|
||||
function setClientState($state) {
|
||||
$clients=getClients();
|
||||
if ( ($idx = findCurrentClientIndex($clients)) >= 0) {
|
||||
@ -218,6 +227,7 @@ function setClientState($state) {
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if($state=="up") waitClientConnected($dev["name"],15);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user