# # Copyright (C) 2020-2024 Soleta Networks # # 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 * MENU_TEMPLATE = """

Hostname IP MAC SPEED
{hostname} {ip} {mac} {speed}

{boot_list}

Power Off

""" MENU_OS_TEMPLATE = "

Boot {os} ({diskno}, {partno})

" def generate_menu(part_setup): """ Writes html menu to /opt/opengnsys/log/{ip}.info.html based on a partition setup """ device = get_ethernet_interface() 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