def FlashXM(cmd): cam = DVRIPCam(GetIP(devices[cmd[1]]["HostIP"]), "admin", cmd[2]) if cam.login(): cmd[4](_("Auth success")) cam.upgrade(cmd[3], 0x4000, cmd[4]) else: cmd[4](_("Auth failed"))
def open_telnet(host_ip, port, **kwargs): make_telnet = kwargs.get('telnet', False) make_backup = kwargs.get('backup', False) user = kwargs.get('username', 'admin') password = kwargs.get('password', '') cam = DVRIPCam(host_ip, user=user, password=password) if not cam.login(): print(f"Cannot connect {host_ip}") return upinfo = cam.get_upgrade_info() hw = upinfo["Hardware"] print(f"Modifiying camera {hw}") sysinfo = cam.get_system_info() swver = extract_gen(sysinfo["SoftWareVersion"]) print(f"Firmware generation {swver}") desc = { "Hardware": hw, "DevID": f"{swver}1001000000000000", "CompatibleVersion": 2, "Vendor": "General", "CRC": "1ce6242100007636", } upcmd = [] if make_telnet: upcmd.append(cmd_telnetd(port)) elif make_backup: upcmd = cmd_backup() else: upcmd.append(cmd_armebenv(swver)) desc['UpgradeCommand'] = upcmd add_flashes(desc, swver) zipfname = "upgrade.bin" make_zip(zipfname, json.dumps(desc, indent=2)) cam.upgrade(zipfname) cam.close() os.remove(zipfname) if make_backup: print("Check backup") return if not make_telnet: port = 23 print("Waiting for camera is rebooting...") for i in range(10): time.sleep(4) if check_port(host_ip, port): tport = f" {port}" if port != 23 else '' print(f"Now use 'telnet {host_ip}{tport}' to login") return print("Something went wrong") return