source: ogClient-Git/src/utils/menu.py

Last change on this file was 902e019, checked in by Jose M. Guisado <jguisado@…>, 3 years ago

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.

  • Property mode set to 100644
File size: 1.8 KB
Line 
1#
2# Copyright (C) 2022 Soleta Networks <info@soleta.eu>
3#
4# This program is free software: you can redistribute it and/or modify it under
5# the terms of the GNU Affero General Public License as published by the
6# Free Software Foundation; either version 3 of the License, or
7# (at your option) any later version.
8
9"""
10Utility module for ogBrowser menu generation
11"""
12
13import os
14import socket
15
16from src.utils.net import getifaddr, getifhwaddr, ethtool
17
18MENU_TEMPLATE = """
19<div align="center" style="font-family: Arial, Helvetica, sans-serif;">
20<p style="color:#999999; font-size: 16px; margin: 2em;">
21<table border="1" width="100%">
22<tr>
23<td rowspan="2"><p align="left"><img border="0" src="../images/iconos/logoopengnsys.png"><p> </td>
24<td> Hostname </td> <td> IP </td> <td> MAC </td> <td> SPEED </td> </tr>
25<tr> <td>{hostname} </td> <td> {ip} </td> <td> {mac} </td> <td> {speed} </td> </tr>
26</table>
27</p>
28
29{boot_list}
30
31<p><a href="command:poweroff">Power Off</a></p>
32</div>
33"""
34
35MENU_OS_TEMPLATE = "<p><a href=\"command:bootOs {diskno} {partno}\">Boot {os} ({diskno}, {partno})</a></p>"
36
37def generate_menu(part_setup):
38    """
39    Writes html menu to /opt/opengnsys/log/{ip}.info.html based on a partition
40    setup
41    """
42    device = os.getenv('DEVICE')
43    if not device:
44        return False
45
46    ip = getifaddr(device)
47    mac = getifhwaddr(device)
48    speed = ethtool(device)
49    hostname = socket.gethostname()
50    menufile = f'/opt/opengnsys/log/{ip}.info.html'
51
52    l = [MENU_OS_TEMPLATE.format(diskno=part['disk'], partno=part['partition'], os=part['os'])
53         for part in part_setup if part['os']]
54    boot_list = '\n'.join(l)
55
56    with open(menufile, 'w') as f:
57        f.write(MENU_TEMPLATE.format(hostname=hostname, ip=ip, mac=mac, speed=speed, boot_list=boot_list))
58    return True
Note: See TracBrowser for help on using the repository browser.