mirror of
https://github.com/openwrt-xiaomi/xmir-patcher.git
synced 2026-09-22 22:57:55 +03:00
connect5: Cleanup code (set_systime)
This commit is contained in:
+8
-44
@@ -228,42 +228,6 @@ def exec_cmd(command, fn = '/tmp/e', run_as_sh = True):
|
|||||||
exec_tiny_cmd(f"chmod +x {fn}")
|
exec_tiny_cmd(f"chmod +x {fn}")
|
||||||
exec_tiny_cmd(f"sh {fn}")
|
exec_tiny_cmd(f"sh {fn}")
|
||||||
|
|
||||||
def get_dev_systime():
|
|
||||||
# http://192.168.31.1/cgi-bin/luci/;stok=14b996378966455753104d187c1150b4/api/misystem/sys_time
|
|
||||||
# response: {"time":{"min":32,"day":4,"index":0,"month":10,"year":2023,"sec":7,"hour":6,"timezone":"XXX"},"code":0}
|
|
||||||
res = requests.get(gw.apiurl + 'misystem/sys_time')
|
|
||||||
try:
|
|
||||||
dres = json.loads(res.text)
|
|
||||||
code = dres['code']
|
|
||||||
except Exception:
|
|
||||||
raise ExploitError(f'Error on parse response for command "sys_time" => {res.text}')
|
|
||||||
if code != 0:
|
|
||||||
raise ExploitError(f'Error on get sys_time => {res.text}')
|
|
||||||
return dres['time']
|
|
||||||
|
|
||||||
def set_dev_systime(dst, year = 0, month = 0, day = 0, hour = 0, min = 0, sec = 0, timezone = ""):
|
|
||||||
if dst:
|
|
||||||
year = dst['year']
|
|
||||||
month = dst['month']
|
|
||||||
day = dst['day']
|
|
||||||
hour = dst['hour']
|
|
||||||
min = dst['min']
|
|
||||||
sec = dst['sec']
|
|
||||||
timezone = dst['timezone']
|
|
||||||
params = {
|
|
||||||
'time': f"{year}-{month}-{day} {hour}:{min}:{sec}",
|
|
||||||
'timezone': timezone
|
|
||||||
}
|
|
||||||
res = requests.get(gw.apiurl + 'misystem/set_sys_time', params = params)
|
|
||||||
try:
|
|
||||||
dres = json.loads(res.text)
|
|
||||||
code = dres['code']
|
|
||||||
except Exception:
|
|
||||||
raise ExploitError(f'Error on parse response for command "set_sys_time" => {res.text}')
|
|
||||||
if code != 0:
|
|
||||||
raise ExploitError(f'Error on exec command "set_sys_time" => {res}')
|
|
||||||
return res.text
|
|
||||||
|
|
||||||
|
|
||||||
# Test smartcontroller interface
|
# Test smartcontroller interface
|
||||||
res = get_all_scenes()
|
res = get_all_scenes()
|
||||||
@@ -282,14 +246,11 @@ else:
|
|||||||
die(f'Smartcontroller return Error: {res}')
|
die(f'Smartcontroller return Error: {res}')
|
||||||
|
|
||||||
# get device orig system time
|
# get device orig system time
|
||||||
dst = get_dev_systime()
|
dst = gw.get_device_systime()
|
||||||
if 'timezone' in dst:
|
|
||||||
if "'" in dst['timezone'] or ";" in dst['timezone']:
|
|
||||||
dst['timezone'] = "GMT0"
|
|
||||||
|
|
||||||
print('Enable smartcontroller scene executor ...')
|
print('Enable smartcontroller scene executor ...')
|
||||||
# echo "OK" > /tmp/ntp.status
|
# echo "OK" > /tmp/ntp.status
|
||||||
res = set_dev_systime(dst)
|
gw.set_device_systime(dst, wait = True)
|
||||||
|
|
||||||
#print('Change date ...')
|
#print('Change date ...')
|
||||||
#time.sleep(20)
|
#time.sleep(20)
|
||||||
@@ -306,13 +267,15 @@ while datetime.datetime.now() - start_time <= datetime.timedelta(seconds = 32):
|
|||||||
#print(res)
|
#print(res)
|
||||||
except Exception:
|
except Exception:
|
||||||
try:
|
try:
|
||||||
set_dev_systime(dst)
|
gw.set_device_systime(dst, wait = False)
|
||||||
|
time.sleep(1)
|
||||||
reset_smart_task()
|
reset_smart_task()
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
print('============ smartcontroller failed ============')
|
print('============ smartcontroller failed ============')
|
||||||
|
time.sleep(2)
|
||||||
raise
|
raise
|
||||||
dxt = get_dev_systime()
|
dxt = gw.get_device_systime()
|
||||||
if dxt['year'] == 2033 and dxt['month'] == 1 and dxt['day'] == 2:
|
if dxt['year'] == 2033 and dxt['month'] == 1 and dxt['day'] == 2:
|
||||||
if dxt['hour'] == 3 and dxt['min'] == 4:
|
if dxt['hour'] == 3 and dxt['min'] == 4:
|
||||||
sc_activated = True
|
sc_activated = True
|
||||||
@@ -320,8 +283,9 @@ while datetime.datetime.now() - start_time <= datetime.timedelta(seconds = 32):
|
|||||||
|
|
||||||
# restore orig system time
|
# restore orig system time
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
set_dev_systime(dst)
|
gw.set_device_systime(dst, wait = False)
|
||||||
if not sc_activated:
|
if not sc_activated:
|
||||||
|
time.sleep(1)
|
||||||
reset_smart_task()
|
reset_smart_task()
|
||||||
die('Exploit "smartcontroller" not working!!!')
|
die('Exploit "smartcontroller" not working!!!')
|
||||||
|
|
||||||
|
|||||||
+3
-1
@@ -322,7 +322,7 @@ class Gateway():
|
|||||||
dst['timezone'] = "GMT0"
|
dst['timezone'] = "GMT0"
|
||||||
return dst
|
return dst
|
||||||
|
|
||||||
def set_device_systime(self, dst, year = 0, month = 0, day = 0, hour = 0, min = 0, sec = 0, timezone = ""):
|
def set_device_systime(self, dst, year = 0, month = 0, day = 0, hour = 0, min = 0, sec = 0, timezone = "", wait = True):
|
||||||
if dst:
|
if dst:
|
||||||
year = dst['year']
|
year = dst['year']
|
||||||
month = dst['month']
|
month = dst['month']
|
||||||
@@ -335,6 +335,8 @@ class Gateway():
|
|||||||
dres = self.api_request('API/misystem/set_sys_time', params)
|
dres = self.api_request('API/misystem/set_sys_time', params)
|
||||||
if not dres or dres['code'] != 0:
|
if not dres or dres['code'] != 0:
|
||||||
raise RuntimeError(f'Error on exec command "set_sys_time" => {dres}')
|
raise RuntimeError(f'Error on exec command "set_sys_time" => {dres}')
|
||||||
|
if wait:
|
||||||
|
time.sleep(3.1) # because internal code exec: "echo 'ok,xiaoqiang' > /tmp/ntp.status; sleep 3; date -s \""..time.."\""
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def get_diag_paras(self):
|
def get_diag_paras(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user