diff --git a/.gitignores b/.gitignore similarity index 69% rename from .gitignores rename to .gitignore index 89b27c8..b65fedb 100644 --- a/.gitignores +++ b/.gitignore @@ -1,4 +1,5 @@ *.pyc +__pycache__/ config.py *.log *.json diff --git a/Dockerfile b/Dockerfile index 58365bd..a2d4241 100644 --- a/Dockerfile +++ b/Dockerfile @@ -17,7 +17,7 @@ # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ############################################################################### -FROM python:alpine3.17 +FROM python:alpine3.20 COPY entrypoint /entrypoint diff --git a/README.md b/README.md index beaa4d3..1e94583 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ The main difference between HBMonitor v1 and v2 is the layout, i.e. the main page shows condensed information and on the subpages, you can see the individual content that was shown on v1 -HBMonv2 is tested on Debian v10 & v11 +HBMonv2 is tested on Debian v10, v11, v12 & v13 This version of HBMonv2 requires a web server like apache2, lighttpd and php support running on the server. @@ -96,21 +96,6 @@ php support running on the server. ***************************************************************************************** --- -After update distribution of Linux jinja2 to version 3.x you can find problem with run HBMonitor with error: - - ValueError: The 'monitor' package was not installed in a way that PackageLoader understands. - - -You must uninstall jinja2 and reinstalling with this version Jinja2==2.11.3 - - pip3 uninstall jinja2 - -and - - pip3 install Jinja2==2.11.3 - ---- - **hbmonitor3 by KC1AWV** Python 3 implementation of N0MJS HBmonitor for HBlink https://github.com/kc1awv/hbmonitor3 diff --git a/install.sh b/install.sh index 2dc9e5a..53f57d0 100644 --- a/install.sh +++ b/install.sh @@ -1,6 +1,7 @@ #! /bin/bash # Install the required support programs +apt-get update apt-get install python3 python3-pip python3-dev libffi-dev libssl-dev cargo sed -y -pip3 install setuptools wheel +pip3 install --upgrade setuptools wheel pip3 install -r requirements.txt diff --git a/monitor.py b/monitor.py index 21bed31..0972c50 100644 --- a/monitor.py +++ b/monitor.py @@ -62,7 +62,7 @@ from collections import deque from time import time # Web templating environment -from jinja2 import Environment, PackageLoader, select_autoescape +from jinja2 import Environment, FileSystemLoader, select_autoescape # Utilities from K0USY Group sister project from dmr_utils3.utils import int_id, try_download, bytes_4 @@ -315,14 +315,20 @@ def add_hb_peer(_peer_conf, _ctable_loc, _peer): # if the Frequency is 000.xxx assume it's not an RF peer, otherwise format the text fields # (9 char, but we are just software) see https://wiki.brandmeister.network/index.php/Homebrew/example/php2 - if _peer_conf['TX_FREQ'].strip().isdigit() and _peer_conf['RX_FREQ'].strip().isdigit() and str(type(_peer_conf['TX_FREQ'])).find("bytes") != -1 and str(type(_peer_conf['RX_FREQ'])).find("bytes") != -1: - if _peer_conf['TX_FREQ'][:3] == b'000' or _peer_conf['TX_FREQ'][:1] == b'0' or _peer_conf['RX_FREQ'][:3] == b'000' or _peer_conf['RX_FREQ'][:1] == b'0': + try: + if isinstance(_peer_conf['TX_FREQ'], bytes) and isinstance(_peer_conf['RX_FREQ'], bytes) and \ + _peer_conf['TX_FREQ'].strip().isdigit() and _peer_conf['RX_FREQ'].strip().isdigit(): + if _peer_conf['TX_FREQ'][:3] == b'000' or _peer_conf['TX_FREQ'][:1] == b'0' or \ + _peer_conf['RX_FREQ'][:3] == b'000' or _peer_conf['RX_FREQ'][:1] == b'0': + _ctable_peer['TX_FREQ'] = 'N/A' + _ctable_peer['RX_FREQ'] = 'N/A' + else: + _ctable_peer['TX_FREQ'] = _peer_conf['TX_FREQ'][:3].decode('utf-8') + '.' + _peer_conf['TX_FREQ'][3:7].decode('utf-8') + ' MHz' + _ctable_peer['RX_FREQ'] = _peer_conf['RX_FREQ'][:3].decode('utf-8') + '.' + _peer_conf['RX_FREQ'][3:7].decode('utf-8') + ' MHz' + else: _ctable_peer['TX_FREQ'] = 'N/A' _ctable_peer['RX_FREQ'] = 'N/A' - else: - _ctable_peer['TX_FREQ'] = _peer_conf['TX_FREQ'][:3].decode('utf-8') + '.' + _peer_conf['TX_FREQ'][3:7].decode('utf-8') + ' MHz' - _ctable_peer['RX_FREQ'] = _peer_conf['RX_FREQ'][:3].decode('utf-8') + '.' + _peer_conf['RX_FREQ'][3:7].decode('utf-8') + ' MHz' - else: + except (AttributeError, ValueError, KeyError): _ctable_peer['TX_FREQ'] = 'N/A' _ctable_peer['RX_FREQ'] = 'N/A' # timeslots are kinda complicated too. 0 = none, 1 or 2 mean that one slot, 3 is both, and anything else it considered DMO @@ -338,37 +344,37 @@ def add_hb_peer(_peer_conf, _ctable_loc, _peer): _ctable_peer['SLOTS'] = 'Simplex' # Simple translation items - if str(type(_peer_conf['PACKAGE_ID'])).find("bytes") != -1: + if isinstance(_peer_conf['PACKAGE_ID'], bytes): _ctable_peer['PACKAGE_ID'] = _peer_conf['PACKAGE_ID'].decode('utf-8') else: _ctable_peer['PACKAGE_ID'] = _peer_conf['PACKAGE_ID'] - if str(type(_peer_conf['SOFTWARE_ID'])).find("bytes") != -1: + if isinstance(_peer_conf['SOFTWARE_ID'], bytes): _ctable_peer['SOFTWARE_ID'] = _peer_conf['SOFTWARE_ID'].decode('utf-8') else: _ctable_peer['SOFTWARE_ID'] = _peer_conf['SOFTWARE_ID'] - if str(type(_peer_conf['LOCATION'])).find("bytes") != -1: + if isinstance(_peer_conf['LOCATION'], bytes): _ctable_peer['LOCATION'] = _peer_conf['LOCATION'].decode('utf-8').strip() else: _ctable_peer['LOCATION'] = _peer_conf['LOCATION'] - if str(type(_peer_conf['DESCRIPTION'])).find("bytes") != -1: + if isinstance(_peer_conf['DESCRIPTION'], bytes): _ctable_peer['DESCRIPTION'] = _peer_conf['DESCRIPTION'].decode('utf-8').strip() else: _ctable_peer['DESCRIPTION'] = _peer_conf['DESCRIPTION'] - if str(type(_peer_conf['URL'])).find("bytes") != -1: + if isinstance(_peer_conf['URL'], bytes): _ctable_peer['URL'] = _peer_conf['URL'].decode('utf-8').strip() else: _ctable_peer['URL'] = _peer_conf['URL'] - if str(type(_peer_conf['CALLSIGN'])).find("bytes") != -1: + if isinstance(_peer_conf['CALLSIGN'], bytes): _ctable_peer['CALLSIGN'] = _peer_conf['CALLSIGN'].decode('utf-8').strip() else: _ctable_peer['CALLSIGN'] = _peer_conf['CALLSIGN'] - if str(type(_peer_conf['COLORCODE'])).find("bytes") != -1: + if isinstance(_peer_conf['COLORCODE'], bytes): _ctable_peer['COLORCODE'] = _peer_conf['COLORCODE'].decode('utf-8').strip() else: _ctable_peer['COLORCODE'] = _peer_conf['COLORCODE'] @@ -417,22 +423,22 @@ def build_hblink_table(_config, _stats_table): _stats_table['PEERS'][_hbp] = {} _stats_table['PEERS'][_hbp]['MODE'] = _hbp_data['MODE'] - if str(type(_hbp_data['LOCATION'])).find("bytes") != -1: + if isinstance(_hbp_data['LOCATION'], bytes): _stats_table['PEERS'][_hbp]['LOCATION'] = _hbp_data['LOCATION'].decode('utf-8').strip() else: _stats_table['PEERS'][_hbp]['LOCATION'] = _hbp_data['LOCATION'] - if str(type(_hbp_data['DESCRIPTION'])).find("bytes") != -1: + if isinstance(_hbp_data['DESCRIPTION'], bytes): _stats_table['PEERS'][_hbp]['DESCRIPTION'] = _hbp_data['DESCRIPTION'].decode('utf-8').strip() else: _stats_table['PEERS'][_hbp]['DESCRIPTION'] = _hbp_data['DESCRIPTION'] - if str(type(_hbp_data['URL'])).find("bytes") != -1: - _stats_table['PEERS'][_hbp]['URL'] = _hbp_data['DESCRIPTION'].decode('utf-8').strip() + if isinstance(_hbp_data['URL'], bytes): + _stats_table['PEERS'][_hbp]['URL'] = _hbp_data['URL'].decode('utf-8').strip() else: - _stats_table['PEERS'][_hbp]['URL'] = _hbp_data['DESCRIPTION'] + _stats_table['PEERS'][_hbp]['URL'] = _hbp_data['URL'] - if str(type(_hbp_data['CALLSIGN'])).find("bytes") != -1: + if isinstance(_hbp_data['CALLSIGN'], bytes): _stats_table['PEERS'][_hbp]['CALLSIGN'] = _hbp_data['CALLSIGN'].decode('utf-8').strip() else: _stats_table['PEERS'][_hbp]['CALLSIGN'] = _hbp_data['CALLSIGN'] @@ -1028,7 +1034,7 @@ if __name__ == '__main__': # Jinja2 Stuff env = Environment( - loader=PackageLoader('monitor', 'templates'), + loader=FileSystemLoader(os.path.join(os.path.dirname(__file__), 'templates')), autoescape=select_autoescape(['html', 'xml']) )