From b7cbc2571c1870b4582ead45277d0aa7f961bec8 Mon Sep 17 00:00:00 2001 From: Evgeny Zinoviev Date: Wed, 27 Sep 2023 00:54:34 +0300 Subject: lws: routing updates --- localwebsite/classes/MyOpenWrtUtils.php | 10 +++++++++- localwebsite/handlers/InverterHandler.php | 4 +++- localwebsite/handlers/MiscHandler.php | 5 ++++- localwebsite/handlers/ModemHandler.php | 27 ++++++++++++++------------ localwebsite/templates-web/index.twig | 6 +++--- localwebsite/templates-web/routing_header.twig | 2 +- 6 files changed, 35 insertions(+), 19 deletions(-) (limited to 'localwebsite') diff --git a/localwebsite/classes/MyOpenWrtUtils.php b/localwebsite/classes/MyOpenWrtUtils.php index 6bdfec2..c140fa1 100644 --- a/localwebsite/classes/MyOpenWrtUtils.php +++ b/localwebsite/classes/MyOpenWrtUtils.php @@ -61,6 +61,14 @@ class MyOpenWrtUtils { return $list; } + public static function setUpstream(string $ip) { + return self::run(['homekit-set-default-upstream', $ip]); + } + + public static function getDefaultRoute() { + return self::run(['get-default-route']); + } + // // http functions @@ -128,4 +136,4 @@ class MyOpenWrtUtils { ]; } -} \ No newline at end of file +} diff --git a/localwebsite/handlers/InverterHandler.php b/localwebsite/handlers/InverterHandler.php index 7098e2c..5fa269f 100644 --- a/localwebsite/handlers/InverterHandler.php +++ b/localwebsite/handlers/InverterHandler.php @@ -93,10 +93,12 @@ class InverterHandler extends RequestHandler protected function getClient(): InverterdClient { global $config; + if (isset($_GET['alt']) && $_GET['alt'] == 1) + $config['inverterd_host'] = '192.168.5.223'; $inv = new InverterdClient($config['inverterd_host'], $config['inverterd_port']); $inv->setFormat('json'); return $inv; } -} \ No newline at end of file +} diff --git a/localwebsite/handlers/MiscHandler.php b/localwebsite/handlers/MiscHandler.php index 10b4426..4c5a25e 100644 --- a/localwebsite/handlers/MiscHandler.php +++ b/localwebsite/handlers/MiscHandler.php @@ -33,6 +33,9 @@ class MiscHandler extends RequestHandler public function GET_pump_page() { global $config; + if (isset($_GET['alt']) && $_GET['alt'] == 1) + $config['pump_host'] = '192.168.5.223'; + list($set) = $this->input('set'); $client = new GPIORelaydClient($config['pump_host'], $config['pump_port']); @@ -165,4 +168,4 @@ class MiscHandler extends RequestHandler phpinfo(); } -} \ No newline at end of file +} diff --git a/localwebsite/handlers/ModemHandler.php b/localwebsite/handlers/ModemHandler.php index b54b82c..23e4c9a 100644 --- a/localwebsite/handlers/ModemHandler.php +++ b/localwebsite/handlers/ModemHandler.php @@ -76,7 +76,7 @@ class ModemHandler extends RequestHandler global $config; list($error) = $this->input('error'); - $upstream = self::getCurrentSmallHomeUpstream(); + $upstream = self::getCurrentUpstream(); $current_upstream = [ 'key' => $upstream, @@ -98,12 +98,13 @@ class ModemHandler extends RequestHandler if (!isset($config['modems'][$new_upstream])) redirect('/routing/?error='.urlencode('invalid upstream')); - $current_upstream = self::getCurrentSmallHomeUpstream(); + $current_upstream = self::getCurrentUpstream(); if ($current_upstream != $new_upstream) { - if ($current_upstream != $config['routing_default']) - MyOpenWrtUtils::ipsetDel($current_upstream, $config['routing_smallhome_ip']); - if ($new_upstream != $config['routing_default']) - MyOpenWrtUtils::ipsetAdd($new_upstream, $config['routing_smallhome_ip']); + if ($new_upstream == 'mts-il') + $new_upstream_ip = '192.168.88.1'; + else + $new_upstream_ip = $config['modems'][$new_upstream]['ip']; + MyOpenWrtUtils::setUpstream($new_upstream_ip); } redirect('/routing/'); @@ -264,14 +265,16 @@ class ModemHandler extends RequestHandler } } - protected static function getCurrentSmallHomeUpstream() { + protected static function getCurrentUpstream() { global $config; + $default_route = MyOpenWrtUtils::getDefaultRoute(); + if ($default_route == '192.168.88.1') + $default_route = $config['modems']['mts-il']['ip']; $upstream = null; - $ip_sets = MyOpenWrtUtils::ipsetListAll(); - foreach ($ip_sets as $set => $ips) { - if (in_array($config['routing_smallhome_ip'], $ips)) { - $upstream = $set; + foreach ($config['modems'] as $modem_name => $modem_data) { + if ($default_route == $modem_data['ip']) { + $upstream = $modem_name; break; } } @@ -294,4 +297,4 @@ class ModemHandler extends RequestHandler redirect('/routing/ipsets/?error='.urlencode('invalid ip/network: '.$ip)); } -} \ No newline at end of file +} diff --git a/localwebsite/templates-web/index.twig b/localwebsite/templates-web/index.twig index bbf6802..b28a078 100644 --- a/localwebsite/templates-web/index.twig +++ b/localwebsite/templates-web/index.twig @@ -20,8 +20,8 @@
Другое
@@ -32,4 +32,4 @@ {% endfor %}
  • Статистика
  • - \ No newline at end of file + diff --git a/localwebsite/templates-web/routing_header.twig b/localwebsite/templates-web/routing_header.twig index 8cb5f47..7d07d0a 100644 --- a/localwebsite/templates-web/routing_header.twig +++ b/localwebsite/templates-web/routing_header.twig @@ -5,7 +5,7 @@ } %} {% set routing_tabs = [ - {tab: 'smallhome', url: '/routing/', label: 'Маленький дом'}, + {tab: 'smallhome', url: '/routing/', label: 'Интернет'}, {tab: 'ipsets', url: '/routing/ipsets/', label: 'Правила'}, {tab: 'dhcp', url: '/routing/dhcp/', label: 'DHCP'} ] %} -- cgit v1.2.3