diff options
author | Jose M. Guisado <jguisado@soleta.eu> | 2022-04-18 10:59:35 +0200 |
---|---|---|
committer | Jose M. Guisado <jguisado@soleta.eu> | 2022-04-21 09:47:04 +0200 |
commit | 902e0195055099c9ab59567407e5e5a90e80e7e7 (patch) | |
tree | e90fea613fcecffa694b3448311b0ee62f98af85 /src/utils/menu.py | |
parent | 79d3062f8166f17a0b8566184c4c3a8b0c9073c6 (diff) |
Add utils modules
* disk.py
Disk discovery
* fs.py
Uses psutil to fetch fs usage information
* menu.py
ogBrowser menu generation
* net.py: gets nic status information
IP address, MAC address and ethernet speed.
* probe.py: probes mountpoints for operating systems
Uses hivexget command to try fetching Windows installation
information.
Looks for /etc/os-release for probing linux systems.
Diffstat (limited to 'src/utils/menu.py')
-rw-r--r-- | src/utils/menu.py | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/src/utils/menu.py b/src/utils/menu.py new file mode 100644 index 0000000..48e2641 --- /dev/null +++ b/src/utils/menu.py @@ -0,0 +1,58 @@ +# +# Copyright (C) 2022 Soleta Networks <info@soleta.eu> +# +# This program is free software: you can redistribute it and/or modify it under +# the terms of the GNU Affero General Public License as published by the +# Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. + +""" +Utility module for ogBrowser menu generation +""" + +import os +import socket + +from src.utils.net import getifaddr, getifhwaddr, ethtool + +MENU_TEMPLATE = """ +<div align="center" style="font-family: Arial, Helvetica, sans-serif;"> +<p style="color:#999999; font-size: 16px; margin: 2em;"> +<table border="1" width="100%"> +<tr> +<td rowspan="2"><p align="left"><img border="0" src="../images/iconos/logoopengnsys.png"><p> </td> +<td> Hostname </td> <td> IP </td> <td> MAC </td> <td> SPEED </td> </tr> +<tr> <td>{hostname} </td> <td> {ip} </td> <td> {mac} </td> <td> {speed} </td> </tr> +</table> +</p> + +{boot_list} + +<p><a href="command:poweroff">Power Off</a></p> +</div> +""" + +MENU_OS_TEMPLATE = "<p><a href=\"command:bootOs {diskno} {partno}\">Boot {os} ({diskno}, {partno})</a></p>" + +def generate_menu(part_setup): + """ + Writes html menu to /opt/opengnsys/log/{ip}.info.html based on a partition + setup + """ + device = os.getenv('DEVICE') + if not device: + return False + + ip = getifaddr(device) + mac = getifhwaddr(device) + speed = ethtool(device) + hostname = socket.gethostname() + menufile = f'/opt/opengnsys/log/{ip}.info.html' + + l = [MENU_OS_TEMPLATE.format(diskno=part['disk'], partno=part['partition'], os=part['os']) + for part in part_setup if part['os']] + boot_list = '\n'.join(l) + + with open(menufile, 'w') as f: + f.write(MENU_TEMPLATE.format(hostname=hostname, ip=ip, mac=mac, speed=speed, boot_list=boot_list)) + return True |