def initialize_bridge(bot: Bot, update: Updater, user_data: dict): session = Session.get_from(user_data) plugin = Plugin("plugins/_bridge_initialization") name, ip, stdout, stderr = next(plugin.run(session)) view.plugin_output(name, ip, "Bridge Initialization", stdout, stderr, hide_header=True).reply(update)
def update_computers_status(user_data: dict): session = Session.get_from(user_data) plugin = Plugin("plugins/_computers_status") _, _, stdout, _ = next(plugin.run(session)) # The stdout has the format `{ip} is {status}` # TODO: Remove n^2 loop by adding dicts to the computers_json structure for line in stdout.splitlines(): ip, _, status = line.split() for computer in session.computers: if ip == computer.ip: computer.status = status
def update_ips(bot: Bot, update: Updater, user_data: dict): """ Get all the macs and its associated ips from the local network. Then, iterate through all the computers in :obj:`Computers`. If one of the computer macs match with one of the local macs, update its associated ip to the new value. Args: bot (:obj:`telegram.bot.Bot`): The telegram bot instance. update (:obj:`telegram.ext.update.Updater`): The Updater associated to the bot. user_data (:obj:`dict`): The dictionary with user variables. """ session = Session.get_from(user_data) # Get all the local ips for every local mac plugin = Plugin("plugins/_local_arp_scan") # Change view to executing view.plugin_start(plugin.name).edit(update) _, _, stdout, _ = next(plugin.run(session)) local_ips = {} for line in stdout.splitlines(): ip, mac = line.strip().split() local_ips[mac] = ip for computer in session.computers.get_included_computers(): if computer.mac.lower() in local_ips: last_ip = computer.ip computer.ip = local_ips[computer.mac.lower()] view.update_ip_output(computer, last_ip).reply(update) session.computers.save() menu.new_main(bot, update, user_data)