Files
webgui/emhttp/plugins/dynamix/scripts/wireless
bergware 01e4027460 Revamp services management
Put update requests in a job queue and replace the job queue when new update requests are presented within the scheduled wait time
This approach makes only the last update request running
New log entries are provided to follow execution of the jobs
2025-02-16 21:33:00 +01:00

48 lines
1.6 KiB
PHP
Executable File

#!/usr/bin/php -q
<?PHP
/* Copyright 2005-2025, Lime Technology
* Copyright 2012-2025, Bergware International.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License version 2,
* as published by the Free Software Foundation.
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*/
?>
<?
$docroot = $_SERVER['DOCUMENT_ROOT'] ?: "/usr/local/emhttp";
require_once "$docroot/plugins/dynamix/include/Wrappers.php";
$arg = $argv[1] ?? '';
$state = $arg ? 'saved' : 'active';
$ini = '/var/local/emhttp/wireless.ini';
$cfg = '/boot/config/wireless.cfg';
$wifi = is_file($cfg) ? (array)parse_ini_file($cfg,true) : [];
$port = array_key_first($wifi);
$text = ["PORT=\"$port\""];
if ($arg == 'yes') {
exec("/etc/rc.d/rc.wireless start &>/dev/null &");
} elseif ($arg == 'no') {
exec("/etc/rc.d/rc.wireless stop");
exec("$docroot/webGui/scripts/update_services");
} elseif (($wifi['wlan0']['WIFI']??'') == 'yes') {
foreach ($wifi as $network => $block) {
if ($network == $port) continue;
if (($block['GROUP']??'') == $state && (!$arg || $arg == $network)) {
$text[] = "SSID=\"$network\"";
unset($block['GROUP']);
foreach ($block as $key => $value) $text[] = "$key=\"$value\"";
}
}
if (count($text)>2) {
exec("/etc/rc.d/rc.wireless stop");
file_put_contents_atomic($ini,implode("\n",$text)."\n");
exec("/etc/rc.d/rc.wireless join &>/dev/null &");
exec("$docroot/webGui/scripts/update_services 20");
}
}
?>