def test_router_wget(self): # Create router router = Router(1, "vlan1", 21, "10.223.254.254", 16, "192.168.1.1", 24, "root", "root", 1) router.model = "TP-LINK TL-WR841N/ND v9" router.mac = "e8:de:27:b7:7c:e2" # Has to be matched with the current mode (normal, configuration) router.mode = Mode.configuration assert isinstance(router, Router) # Create NetworkCrtl network_ctrl = NetworkCtrl(router, 'eth0') assert isinstance(network_ctrl, NetworkCtrl) self.assertRaises(Exception, network_ctrl.connect_with_remote_system()) # Create test file 'test_wget.txt' path = os.path.dirname(__file__) file = open(path + '/test_wget.txt', 'w+') # The Router downloads this file via wget from the raspberryPi network_ctrl.remote_system_wget(path + '/test_wget.txt', '/tmp/') # Tests if the file has successful downloaded output = network_ctrl.send_command( "test -f '/tmp/test_wget.txt' && echo True") self.assertEqual(output, "['True\\n']") # Test output = network_ctrl.send_command( "rm '/tmp/test_wget.txt' && echo True") self.assertEqual(output, "['True\\n']") file.close() network_ctrl.exit()
def test_router_wget(self): # Create router router = Router(1, "vlan1", 21, "10.223.254.254", 16, "192.168.1.1", 24, "root", "root", 1) router.model = "TP-LINK TL-WR841N/ND v9" router.mac = "e8:de:27:b7:7c:e2" # Has to be matched with the current mode (normal, configuration) router.mode = Mode.configuration assert isinstance(router, Router) # Create NetworkCrtl network_ctrl = NetworkCtrl(router, 'eth0') assert isinstance(network_ctrl, NetworkCtrl) self.assertRaises(Exception, network_ctrl.connect_with_remote_system()) # Create test file 'test_wget.txt' path = os.path.dirname(__file__) file = open(path + '/test_wget.txt', 'w+') # The Router downloads this file via wget from the raspberryPi network_ctrl.remote_system_wget(path + '/test_wget.txt', '/tmp/') # Tests if the file has successful downloaded output = network_ctrl.send_command("test -f '/tmp/test_wget.txt' && echo True") self.assertEqual(output, "['True\\n']") # Test output = network_ctrl.send_command("rm '/tmp/test_wget.txt' && echo True") self.assertEqual(output, "['True\\n']") file.close() network_ctrl.exit()
def run(self): """ Copies the firmware image onto the Router, proves if the firmware is in the right file(/tmp/<firmware_name>.bin) and does a Sysupgrade. """ network_ctrl = NetworkCtrl(self.router) try: network_ctrl.connect_with_remote_system() except Exception as e: logging.warning("%s[-] Couldn't sysupgrade the Router(" + str(self.router.id) + ")", LoggerSetup.get_log_deep(2)) logging.warning(str(e)) return network_ctrl.remote_system_wget(self.router.firmware.file, '/tmp/', self.web_server_ip) # sysupgrade -n <firmware_name> // -n verwirft die letzte firmware arg = '-n' if self.n else '' if not self.debug: logging.debug("%sSysupgrade (this will force a TimeoutError)...", LoggerSetup.get_log_deep(2)) try: network_ctrl.send_command('sysupgrade ' + arg + ' ' + '/tmp/' + self.router.firmware.name) except TimeoutError: try: Dhclient.update_ip(self.router.vlan_iface_name) self._success_handling() except FileExistsError: self._success_handling() pass except Exception: self._execption_hanling() except Exception: self._execption_hanling() network_ctrl.exit()
def run(self): """ Copies the firmware image onto the Router, proves if the firmware is in the right file(/tmp/<firmware_name>.bin) and does a Sysupgrade. :return: """ network_ctrl = NetworkCtrl(self.router) try: network_ctrl.connect_with_remote_system() except Exception as e: logging.warning("[-] Couldn't sysupgrade the Router(" + str(self.router.id) + ")") logging.warning(str(e)) return network_ctrl.remote_system_wget(self.router.firmware.file, '/tmp/', self.web_server_ip) # sysupgrade -n <firmware_name> // -n verwirft die letzte firmware arg = '-n' if self.n else '' if not self.debug: logging.debug("sysupgrade ...") try: network_ctrl.send_command('sysupgrade ' + arg + ' ' + '/tmp/' + self.router.firmware.name) except TimeoutError: logging.info("%s[+] Router was set into normal mode", LoggerSetup.get_log_deep(2)) self.router.mode = Mode.configuration if Dhclient.update_ip(self.router.vlan_iface_name) == 1: self.router.mode = Mode.unknown logging.error("%s[-] Something went wrong. Use command 'online -r " + str(self.router.id) + "'", LoggerSetup.get_log_deep(2)) except Exception as e: self.router.mode = Mode.unknown logging.error("[-] Something went wrong. Use command 'online -r " + str(self.router.id) + "'") logging.error(str(e)) network_ctrl.exit()
def run(self): """ Instantiate a NetworkCtrl, proves if the firmware is on the Router(/tmp/<firmware_name>.bin) and does a Sysupgrade. :return: """ network_ctrl = NetworkCtrl(self.router, 'eth0') network_ctrl.connect_with_remote_system() network_ctrl.remote_system_wget(self.router.firmware.file, '/tmp/') # sysupgrade -n <firmware_name> // -n verwirft die letzte firmware arg = '-n' if self.n else '' network_ctrl.send_command('sysupgrade ' + arg + ' ' + '/tmp/' + self.router.firmware.name) network_ctrl.exit()
def run(self): """ Instantiate a NetworkCtrl, proves if the firmware is on the Router(/tmp/<firmware_name>.bin) and does a Sysupgrade. :return: """ network_ctrl = NetworkCtrl(self.router, 'eth0') network_ctrl.connect_with_remote_system() network_ctrl.remote_system_wget(self.router.firmware.file, '/tmp/') # sysupgrade -n <firmware_name> // -n verwirft die letzte firmware arg = '-n' if self.n else '' network_ctrl.send_command('sysupgrade ' + arg + ' ' + '/tmp/' + self.router.firmware.name) network_ctrl.exit()
def run(self): """ Copies the firmware image onto the Router, proves if the firmware is in the right file(/tmp/<firmware_name>.bin) and does a Sysupgrade. :return: """ network_ctrl = NetworkCtrl(self.router) try: network_ctrl.connect_with_remote_system() except Exception as e: logging.warning("[-] Couldn't sysupgrade the Router(" + str(self.router.id) + ")") logging.warning(str(e)) return network_ctrl.remote_system_wget(self.router.firmware.file, '/tmp/', self.web_server_ip) # sysupgrade -n <firmware_name> // -n verwirft die letzte firmware arg = '-n' if self.n else '' if not self.debug: logging.debug("sysupgrade ...") try: network_ctrl.send_command('sysupgrade ' + arg + ' ' + '/tmp/' + self.router.firmware.name) except TimeoutError: logging.info("%s[+] Router was set into normal mode", LoggerSetup.get_log_deep(2)) self.router.mode = Mode.configuration if Dhclient.update_ip(self.router.vlan_iface_name) == 1: self.router.mode = Mode.unknown logging.error( "%s[-] Something went wrong. Use command 'online -r " + str(self.router.id) + "'", LoggerSetup.get_log_deep(2)) except Exception as e: self.router.mode = Mode.unknown logging.error( "[-] Something went wrong. Use command 'online -r " + str(self.router.id) + "'") logging.error(str(e)) network_ctrl.exit()
def run(self): """ Copies the firmware image onto the Router, proves if the firmware is in the right file(/tmp/<firmware_name>.bin) and does a Sysupgrade. """ network_ctrl = NetworkCtrl(self.router) try: network_ctrl.connect_with_remote_system() except Exception as e: logging.warning( "%s[-] Couldn't sysupgrade the Router(" + str(self.router.id) + ")", LoggerSetup.get_log_deep(2)) logging.warning(str(e)) return network_ctrl.remote_system_wget(self.router.firmware.file, '/tmp/', self.web_server_ip) # sysupgrade -n <firmware_name> // -n verwirft die letzte firmware arg = '-n' if self.n else '' if not self.debug: logging.debug("%sSysupgrade (this will force a TimeoutError)...", LoggerSetup.get_log_deep(2)) try: network_ctrl.send_command('sysupgrade ' + arg + ' ' + '/tmp/' + self.router.firmware.name) except TimeoutError: try: Dhclient.update_ip(self.router.vlan_iface_name) self._success_handling() except FileExistsError: self._success_handling() pass except Exception: self._execption_hanling() except Exception: self._execption_hanling() network_ctrl.exit()