diff options
-rw-r--r-- | bin/web_kbn.py | 77 | ||||
-rw-r--r-- | include/py/homekit/modem/__init__.py | 1 | ||||
-rw-r--r-- | include/py/homekit/modem/config.py | 5 | ||||
-rw-r--r-- | localwebsite/handlers/ModemHandler.php | 6 | ||||
-rw-r--r-- | localwebsite/htdocs/assets/modem.js | 29 | ||||
-rw-r--r-- | web/kbn_assets/app.css (renamed from localwebsite/htdocs/assets/app.css) | 0 | ||||
-rw-r--r-- | web/kbn_assets/app.js (renamed from localwebsite/htdocs/assets/app.js) | 32 | ||||
-rw-r--r-- | web/kbn_assets/bootstrap.min.css (renamed from localwebsite/htdocs/assets/bootstrap.min.css) | 0 | ||||
-rw-r--r-- | web/kbn_assets/bootstrap.min.js (renamed from localwebsite/htdocs/assets/bootstrap.min.js) | 0 | ||||
-rw-r--r-- | web/kbn_assets/h265webjs-dist/h265webjs-v20221106-reminified.js (renamed from localwebsite/htdocs/assets/h265webjs-dist/h265webjs-v20221106-reminified.js) | 0 | ||||
-rw-r--r-- | web/kbn_assets/h265webjs-dist/h265webjs-v20221106.js (renamed from localwebsite/htdocs/assets/h265webjs-dist/h265webjs-v20221106.js) | 0 | ||||
-rw-r--r-- | web/kbn_assets/h265webjs-dist/missile-120func-v20221120.js (renamed from localwebsite/htdocs/assets/h265webjs-dist/missile-120func-v20221120.js) | 0 | ||||
-rw-r--r-- | web/kbn_assets/h265webjs-dist/missile-120func-v20221120.wasm (renamed from localwebsite/htdocs/assets/h265webjs-dist/missile-120func-v20221120.wasm) | bin | 2190151 -> 2190151 bytes | |||
-rw-r--r-- | web/kbn_assets/h265webjs-dist/missile-120func.js (renamed from localwebsite/htdocs/assets/h265webjs-dist/missile-120func.js) | 0 | ||||
-rw-r--r-- | web/kbn_assets/h265webjs-dist/missile-256mb-v20221120.js (renamed from localwebsite/htdocs/assets/h265webjs-dist/missile-256mb-v20221120.js) | 0 | ||||
-rw-r--r-- | web/kbn_assets/h265webjs-dist/missile-256mb-v20221120.wasm (renamed from localwebsite/htdocs/assets/h265webjs-dist/missile-256mb-v20221120.wasm) | bin | 2108889 -> 2108889 bytes | |||
-rw-r--r-- | web/kbn_assets/h265webjs-dist/missile-256mb.js (renamed from localwebsite/htdocs/assets/h265webjs-dist/missile-256mb.js) | 0 | ||||
-rw-r--r-- | web/kbn_assets/h265webjs-dist/missile-512mb-v20221120.js (renamed from localwebsite/htdocs/assets/h265webjs-dist/missile-512mb-v20221120.js) | 0 | ||||
-rw-r--r-- | web/kbn_assets/h265webjs-dist/missile-512mb-v20221120.wasm (renamed from localwebsite/htdocs/assets/h265webjs-dist/missile-512mb-v20221120.wasm) | bin | 2108889 -> 2108889 bytes | |||
-rw-r--r-- | web/kbn_assets/h265webjs-dist/missile-512mb.js (renamed from localwebsite/htdocs/assets/h265webjs-dist/missile-512mb.js) | 0 | ||||
-rw-r--r-- | web/kbn_assets/h265webjs-dist/missile-format.js (renamed from localwebsite/htdocs/assets/h265webjs-dist/missile-format.js) | 0 | ||||
-rw-r--r-- | web/kbn_assets/h265webjs-dist/missile-v20221120.js (renamed from localwebsite/htdocs/assets/h265webjs-dist/missile-v20221120.js) | 0 | ||||
-rw-r--r-- | web/kbn_assets/h265webjs-dist/missile-v20221120.wasm (renamed from localwebsite/htdocs/assets/h265webjs-dist/missile-v20221120.wasm) | bin | 2108891 -> 2108891 bytes | |||
-rw-r--r-- | web/kbn_assets/h265webjs-dist/missile.js (renamed from localwebsite/htdocs/assets/h265webjs-dist/missile.js) | 0 | ||||
-rw-r--r-- | web/kbn_assets/h265webjs-dist/raw-parser.js (renamed from localwebsite/htdocs/assets/h265webjs-dist/raw-parser.js) | 0 | ||||
-rw-r--r-- | web/kbn_assets/h265webjs-dist/worker-fetch-dist.js (renamed from localwebsite/htdocs/assets/h265webjs-dist/worker-fetch-dist.js) | 0 | ||||
-rw-r--r-- | web/kbn_assets/h265webjs-dist/worker-parse-dist.js (renamed from localwebsite/htdocs/assets/h265webjs-dist/worker-parse-dist.js) | 0 | ||||
-rw-r--r-- | web/kbn_assets/hls.js (renamed from localwebsite/htdocs/assets/hls.js) | 0 | ||||
-rw-r--r-- | web/kbn_assets/inverter.js (renamed from localwebsite/htdocs/assets/inverter.js) | 0 | ||||
-rw-r--r-- | web/kbn_assets/polyfills.js (renamed from localwebsite/htdocs/assets/polyfills.js) | 0 | ||||
-rw-r--r-- | web/kbn_templates/base.html | 4 | ||||
-rw-r--r-- | web/kbn_templates/index.html | 39 |
32 files changed, 143 insertions, 50 deletions
diff --git a/bin/web_kbn.py b/bin/web_kbn.py index b66e2a5..e160fde 100644 --- a/bin/web_kbn.py +++ b/bin/web_kbn.py @@ -5,11 +5,13 @@ import aiohttp_jinja2 import os import __py_include +from io import StringIO from typing import Optional from homekit.config import config, AppConfigUnit from homekit.util import homekit_path from aiohttp import web from homekit import http +from homekit.modem import ModemsConfig class WebKbnConfig(AppConfigUnit): @@ -18,10 +20,50 @@ class WebKbnConfig(AppConfigUnit): @classmethod def schema(cls) -> Optional[dict]: return { - 'listen_addr': cls._addr_schema(required=True) + 'listen_addr': cls._addr_schema(required=True), + 'assets_public_path': {'type': 'string'} } +STATIC_FILES = [ + 'bootstrap.min.css', + 'bootstrap.min.js', + 'polyfills.js', + 'app.js', + 'app.css' +] + + +def get_js_link(file, version) -> str: + if version: + file += f'?version={version}' + return f'<script src="{config.app_config["assets_public_path"]}/{file}" type="text/javascript"></script>' + + +def get_css_link(file, version) -> str: + if version: + file += f'?version={version}' + return f'<link rel="stylesheet" type="text/css" href="{config.app_config["assets_public_path"]}/{file}">' + + +def get_head_static() -> str: + buf = StringIO() + for file in STATIC_FILES: + v = 1 + try: + q_ind = file.index('?') + v = file[q_ind+1:] + file = file[:file.index('?')] + except ValueError: + pass + + if file.endswith('.js'): + buf.write(get_js_link(file, v)) + else: + buf.write(get_css_link(file, v)) + return buf.getvalue() + + class WebSite(http.HTTPServer): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) @@ -31,20 +73,29 @@ class WebSite(http.HTTPServer): loader=jinja2.FileSystemLoader(homekit_path('web', 'kbn_templates')) ) + self.app.router.add_static('/assets/', path=homekit_path('web', 'kbn_assets')) + self.get('/', self.get_index) + self.get('/modems', self.get_modems) + + async def render_page(self, + req: http.Request, + context: Optional[dict] = None): + if context is None: + context = {} + context = { + **context, + 'head_static': get_head_static(), + 'title': 'this is title' + } + response = aiohttp_jinja2.render_template('index.html', req, context=context) + return response + + async def get_index(self, req: http.Request): + return await self.render_page(req) - @staticmethod - async def get_index(req: http.Request): - # context = { - # 'username': request.match_info.get("username", ""), - # 'current_date': 'January 27, 2017' - # } - # response = aiohttp_jinja2.render_template("example.html", request, - # context=context) - # return response - - message = "nothing here, keep lurking" - return http.Response(text=message, content_type='text/plain') + async def get_modems(self, req: http.Request): + pass if __name__ == '__main__': diff --git a/include/py/homekit/modem/__init__.py b/include/py/homekit/modem/__init__.py new file mode 100644 index 0000000..20e75b7 --- /dev/null +++ b/include/py/homekit/modem/__init__.py @@ -0,0 +1 @@ +from .config import ModemsConfig
\ No newline at end of file diff --git a/include/py/homekit/modem/config.py b/include/py/homekit/modem/config.py new file mode 100644 index 0000000..039d759 --- /dev/null +++ b/include/py/homekit/modem/config.py @@ -0,0 +1,5 @@ +from ..config import ConfigUnit + + +class ModemsConfig(ConfigUnit): + pass diff --git a/localwebsite/handlers/ModemHandler.php b/localwebsite/handlers/ModemHandler.php index b54b82c..fb91084 100644 --- a/localwebsite/handlers/ModemHandler.php +++ b/localwebsite/handlers/ModemHandler.php @@ -7,12 +7,6 @@ use libphonenumber\PhoneNumberUtil; class ModemHandler extends RequestHandler { - public function __construct() - { - parent::__construct(); - $this->tpl->add_static('modem.js'); - } - public function GET_status_page() { global $config; diff --git a/localwebsite/htdocs/assets/modem.js b/localwebsite/htdocs/assets/modem.js deleted file mode 100644 index 9fdb91d..0000000 --- a/localwebsite/htdocs/assets/modem.js +++ /dev/null @@ -1,29 +0,0 @@ -var ModemStatus = { - _modems: [], - - init: function(modems) { - for (var i = 0; i < modems.length; i++) { - var modem = modems[i]; - this._modems.push(new ModemStatusUpdater(modem)); - } - } -}; - - -function ModemStatusUpdater(id) { - this.id = id; - this.elem = ge('modem_data_'+id); - this.fetch(); -} -extend(ModemStatusUpdater.prototype, { - fetch: function() { - ajax.get('/modem/get.ajax', { - id: this.id - }).then(({response}) => { - var {html} = response; - this.elem.innerHTML = html; - - // TODO enqueue rerender - }); - }, -});
\ No newline at end of file diff --git a/localwebsite/htdocs/assets/app.css b/web/kbn_assets/app.css index 3146bcf..3146bcf 100644 --- a/localwebsite/htdocs/assets/app.css +++ b/web/kbn_assets/app.css diff --git a/localwebsite/htdocs/assets/app.js b/web/kbn_assets/app.js index 37f1307..c187f89 100644 --- a/localwebsite/htdocs/assets/app.js +++ b/web/kbn_assets/app.js @@ -316,4 +316,34 @@ window.Cameras = { return video.canPlayType('application/vnd.apple.mpegurl'); }, }; -})();
\ No newline at end of file +})(); + + +var ModemStatus = { + _modems: [], + + init: function(modems) { + for (var i = 0; i < modems.length; i++) { + var modem = modems[i]; + this._modems.push(new ModemStatusUpdater(modem)); + } + } +}; + +function ModemStatusUpdater(id) { + this.id = id; + this.elem = ge('modem_data_'+id); + this.fetch(); +} +extend(ModemStatusUpdater.prototype, { + fetch: function() { + ajax.get('/modem/get.ajax', { + id: this.id + }).then(({response}) => { + var {html} = response; + this.elem.innerHTML = html; + + // TODO enqueue rerender + }); + }, +});
\ No newline at end of file diff --git a/localwebsite/htdocs/assets/bootstrap.min.css b/web/kbn_assets/bootstrap.min.css index edfbbb0..edfbbb0 100644 --- a/localwebsite/htdocs/assets/bootstrap.min.css +++ b/web/kbn_assets/bootstrap.min.css diff --git a/localwebsite/htdocs/assets/bootstrap.min.js b/web/kbn_assets/bootstrap.min.js index aed031f..aed031f 100644 --- a/localwebsite/htdocs/assets/bootstrap.min.js +++ b/web/kbn_assets/bootstrap.min.js diff --git a/localwebsite/htdocs/assets/h265webjs-dist/h265webjs-v20221106-reminified.js b/web/kbn_assets/h265webjs-dist/h265webjs-v20221106-reminified.js index 9a9f036..9a9f036 100644 --- a/localwebsite/htdocs/assets/h265webjs-dist/h265webjs-v20221106-reminified.js +++ b/web/kbn_assets/h265webjs-dist/h265webjs-v20221106-reminified.js diff --git a/localwebsite/htdocs/assets/h265webjs-dist/h265webjs-v20221106.js b/web/kbn_assets/h265webjs-dist/h265webjs-v20221106.js index e877ade..e877ade 100644 --- a/localwebsite/htdocs/assets/h265webjs-dist/h265webjs-v20221106.js +++ b/web/kbn_assets/h265webjs-dist/h265webjs-v20221106.js diff --git a/localwebsite/htdocs/assets/h265webjs-dist/missile-120func-v20221120.js b/web/kbn_assets/h265webjs-dist/missile-120func-v20221120.js index fd26bc7..fd26bc7 100644 --- a/localwebsite/htdocs/assets/h265webjs-dist/missile-120func-v20221120.js +++ b/web/kbn_assets/h265webjs-dist/missile-120func-v20221120.js diff --git a/localwebsite/htdocs/assets/h265webjs-dist/missile-120func-v20221120.wasm b/web/kbn_assets/h265webjs-dist/missile-120func-v20221120.wasm Binary files differindex de5b4f7..de5b4f7 100644 --- a/localwebsite/htdocs/assets/h265webjs-dist/missile-120func-v20221120.wasm +++ b/web/kbn_assets/h265webjs-dist/missile-120func-v20221120.wasm diff --git a/localwebsite/htdocs/assets/h265webjs-dist/missile-120func.js b/web/kbn_assets/h265webjs-dist/missile-120func.js index fd26bc7..fd26bc7 100644 --- a/localwebsite/htdocs/assets/h265webjs-dist/missile-120func.js +++ b/web/kbn_assets/h265webjs-dist/missile-120func.js diff --git a/localwebsite/htdocs/assets/h265webjs-dist/missile-256mb-v20221120.js b/web/kbn_assets/h265webjs-dist/missile-256mb-v20221120.js index fb8f13d..fb8f13d 100644 --- a/localwebsite/htdocs/assets/h265webjs-dist/missile-256mb-v20221120.js +++ b/web/kbn_assets/h265webjs-dist/missile-256mb-v20221120.js diff --git a/localwebsite/htdocs/assets/h265webjs-dist/missile-256mb-v20221120.wasm b/web/kbn_assets/h265webjs-dist/missile-256mb-v20221120.wasm Binary files differindex ee7d92a..ee7d92a 100644 --- a/localwebsite/htdocs/assets/h265webjs-dist/missile-256mb-v20221120.wasm +++ b/web/kbn_assets/h265webjs-dist/missile-256mb-v20221120.wasm diff --git a/localwebsite/htdocs/assets/h265webjs-dist/missile-256mb.js b/web/kbn_assets/h265webjs-dist/missile-256mb.js index fb8f13d..fb8f13d 100644 --- a/localwebsite/htdocs/assets/h265webjs-dist/missile-256mb.js +++ b/web/kbn_assets/h265webjs-dist/missile-256mb.js diff --git a/localwebsite/htdocs/assets/h265webjs-dist/missile-512mb-v20221120.js b/web/kbn_assets/h265webjs-dist/missile-512mb-v20221120.js index 49ec3b6..49ec3b6 100644 --- a/localwebsite/htdocs/assets/h265webjs-dist/missile-512mb-v20221120.js +++ b/web/kbn_assets/h265webjs-dist/missile-512mb-v20221120.js diff --git a/localwebsite/htdocs/assets/h265webjs-dist/missile-512mb-v20221120.wasm b/web/kbn_assets/h265webjs-dist/missile-512mb-v20221120.wasm Binary files differindex 71432e4..71432e4 100644 --- a/localwebsite/htdocs/assets/h265webjs-dist/missile-512mb-v20221120.wasm +++ b/web/kbn_assets/h265webjs-dist/missile-512mb-v20221120.wasm diff --git a/localwebsite/htdocs/assets/h265webjs-dist/missile-512mb.js b/web/kbn_assets/h265webjs-dist/missile-512mb.js index 49ec3b6..49ec3b6 100644 --- a/localwebsite/htdocs/assets/h265webjs-dist/missile-512mb.js +++ b/web/kbn_assets/h265webjs-dist/missile-512mb.js diff --git a/localwebsite/htdocs/assets/h265webjs-dist/missile-format.js b/web/kbn_assets/h265webjs-dist/missile-format.js index 8f7eddf..8f7eddf 100644 --- a/localwebsite/htdocs/assets/h265webjs-dist/missile-format.js +++ b/web/kbn_assets/h265webjs-dist/missile-format.js diff --git a/localwebsite/htdocs/assets/h265webjs-dist/missile-v20221120.js b/web/kbn_assets/h265webjs-dist/missile-v20221120.js index c498b84..c498b84 100644 --- a/localwebsite/htdocs/assets/h265webjs-dist/missile-v20221120.js +++ b/web/kbn_assets/h265webjs-dist/missile-v20221120.js diff --git a/localwebsite/htdocs/assets/h265webjs-dist/missile-v20221120.wasm b/web/kbn_assets/h265webjs-dist/missile-v20221120.wasm Binary files differindex 629ce98..629ce98 100644 --- a/localwebsite/htdocs/assets/h265webjs-dist/missile-v20221120.wasm +++ b/web/kbn_assets/h265webjs-dist/missile-v20221120.wasm diff --git a/localwebsite/htdocs/assets/h265webjs-dist/missile.js b/web/kbn_assets/h265webjs-dist/missile.js index c498b84..c498b84 100644 --- a/localwebsite/htdocs/assets/h265webjs-dist/missile.js +++ b/web/kbn_assets/h265webjs-dist/missile.js diff --git a/localwebsite/htdocs/assets/h265webjs-dist/raw-parser.js b/web/kbn_assets/h265webjs-dist/raw-parser.js index edc91a3..edc91a3 100644 --- a/localwebsite/htdocs/assets/h265webjs-dist/raw-parser.js +++ b/web/kbn_assets/h265webjs-dist/raw-parser.js diff --git a/localwebsite/htdocs/assets/h265webjs-dist/worker-fetch-dist.js b/web/kbn_assets/h265webjs-dist/worker-fetch-dist.js index e845d0e..e845d0e 100644 --- a/localwebsite/htdocs/assets/h265webjs-dist/worker-fetch-dist.js +++ b/web/kbn_assets/h265webjs-dist/worker-fetch-dist.js diff --git a/localwebsite/htdocs/assets/h265webjs-dist/worker-parse-dist.js b/web/kbn_assets/h265webjs-dist/worker-parse-dist.js index 2e5d0ea..2e5d0ea 100644 --- a/localwebsite/htdocs/assets/h265webjs-dist/worker-parse-dist.js +++ b/web/kbn_assets/h265webjs-dist/worker-parse-dist.js diff --git a/localwebsite/htdocs/assets/hls.js b/web/kbn_assets/hls.js index ce60c4f..ce60c4f 100644 --- a/localwebsite/htdocs/assets/hls.js +++ b/web/kbn_assets/hls.js diff --git a/localwebsite/htdocs/assets/inverter.js b/web/kbn_assets/inverter.js index 72d985c..72d985c 100644 --- a/localwebsite/htdocs/assets/inverter.js +++ b/web/kbn_assets/inverter.js diff --git a/localwebsite/htdocs/assets/polyfills.js b/web/kbn_assets/polyfills.js index e851999..e851999 100644 --- a/localwebsite/htdocs/assets/polyfills.js +++ b/web/kbn_assets/polyfills.js diff --git a/web/kbn_templates/base.html b/web/kbn_templates/base.html index e567a90..43f7d2a 100644 --- a/web/kbn_templates/base.html +++ b/web/kbn_templates/base.html @@ -9,11 +9,13 @@ window.console && console.error(error); } </script> - {{ head_static }} + {{ head_static | safe }} </head> <body> <div class="container py-3"> +{% block content %} {% endblock %} + {% if js %} <script>{{ js|raw }}</script> {% endif %} diff --git a/web/kbn_templates/index.html b/web/kbn_templates/index.html new file mode 100644 index 0000000..1921b87 --- /dev/null +++ b/web/kbn_templates/index.html @@ -0,0 +1,39 @@ +{% extends "base.html" %} + +{% block content %} +<div class="container py-4"> + <nav aria-label="breadcrumb"> + <ol class="breadcrumb"> + <li class="breadcrumb-item active" aria-current="page">Главная</li> + </ol> + </nav> + +<!-- {% if auth_user %}--> +<!-- <div class="mb-4 alert alert-secondary">--> +<!-- Вы авторизованы как <b>{{ auth_user.username }}</b>. <a href="/deauth/">Выйти</a>--> +<!-- </div>--> +<!-- {% endif %}--> + + <h6>Интернет</h6> + <ul class="list-group list-group-flush"> + <li class="list-group-item"><a href="/modem/">Модемы</a></li> + <li class="list-group-item"><a href="/routing/">Маршрутизация</a></li> + <li class="list-group-item"><a href="/sms/">SMS-сообщения</a></li> + </ul> + + <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="/sensors/">Датчики</a> (<a href="{{ grafana_sensors_url }}">Grafana</a>)</li> + </ul> + + <h6 class="mt-4"><a href="/cams/"><b>Все камеры</b></a> (<a href="/cams/?high=1">HQ</a>)</h6> + <ul class="list-group list-group-flush"> + {% for id, name in cameras %} + <li class="list-group-item"><a href="/cams/{{ id }}/">{{ name }}</a> (<a href="/cams/{{ id }}/?high=1">HQ</a>)</li> + {% endfor %} + <li class="list-group-item"><a href="/cams/stat/">Статистика</a></li> + </ul> +</div> +{% endblock %}
\ No newline at end of file |