diff options
-rw-r--r-- | localwebsite/classes/MyOpenWrtUtils.php | 10 | ||||
-rw-r--r-- | localwebsite/handlers/InverterHandler.php | 4 | ||||
-rw-r--r-- | localwebsite/handlers/MiscHandler.php | 5 | ||||
-rw-r--r-- | localwebsite/handlers/ModemHandler.php | 27 | ||||
-rw-r--r-- | localwebsite/templates-web/index.twig | 6 | ||||
-rw-r--r-- | localwebsite/templates-web/routing_header.twig | 2 |
6 files changed, 35 insertions, 19 deletions
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 @@ <h6 class="mt-4">Другое</h6> <ul class="list-group list-group-flush"> - <li class="list-group-item"><a href="/inverter/">Инвертор</a> (<a href="{{ grafana_inverter_url }}">Grafana</a>)</li> - <li class="list-group-item"><a href="/pump/">Насос</a></li> + <li class="list-group-item"><a href="/inverter/">Инвертор</a> (<a href="/inverter/?alt=1">alt</a>, <a href="{{ grafana_inverter_url }}">Grafana</a>)</li> + <li class="list-group-item"><a href="/pump/">Насос</a> (<a href="/pump/?alt=1">alt</a>)</li> <li class="list-group-item"><a href="/sensors/">Датчики</a> (<a href="{{ grafana_sensors_url }}">Grafana</a>)</li> </ul> @@ -32,4 +32,4 @@ {% endfor %} <li class="list-group-item"><a href="/cams/stat/">Статистика</a></li> </ul> -</div>
\ No newline at end of file +</div> 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'} ] %} |