import socket, hashlib class R: def __init__(s,h,p=8728): s.h=h; s.p=p; s.s=None def c(s,u,p): s.s=socket.socket(); s.s.settimeout(15) s.s.connect((s.h,s.p)) s._ws('/login','=name='+u,'=password='+p) r=s._rr() if any(isinstance(x,tuple) for x in r): for x in r: if isinstance(x,dict) and 'ret' in x: ch=x['ret'] if ch and len(ch)==32: hh=hashlib.md5(b'\x00'+p.encode()+bytes.fromhex(ch)).hexdigest() s._ws('/login','=name='+u,'=response=00'+hh); s._rr() return s def _el(s,l): if l<0x80: return bytes([l]) elif l<0x4000: l|=0x8000; return bytes([(l>>8)&0xFF,l&0xFF]) else: return bytes([0xC0|((l>>16)&0x0F),(l>>8)&0xFF,l&0xFF]) if l<0x200000 else bytes([0xE0|((l>>24)&0x07),(l>>16)&0xFF,(l>>8)&0xFF,l&0xFF]) def _ww(s,w): s.s.sendall(s._el(len(w))+w.encode()) def _ws(s,c,*ws): s._ww(c); [s._ww(w) for w in ws]; s.s.sendall(b'\x00') def _rw(s): f=s.s.recv(1) if f==b'\x00': return None lb=f[0]; l=lb if lb&0x80: if (lb&0xC0)==0x80: l=((lb&0x3F)<<8)+s.s.recv(1)[0] elif (lb&0xE0)==0xC0: l=((lb&0x1F)<<16)+(s.s.recv(1)[0]<<8)+s.s.recv(1)[0] else: l=((lb&0x0F)<<24)+(s.s.recv(1)[0]<<16)+(s.s.recv(1)[0]<<8)+s.s.recv(1)[0] d=b'' while len(d)=3 else '' else: d[w]='' rs.append(d) elif r=='!trap': rs.append(('!trap',t)) return rs def cmd(s,c,**a): ws=[c] for k,v in a.items(): ws.append(('?' if k.startswith('?') else '=')+k+'='+v) s._ws(*ws) return s._rr() def close(s): if s.s: s.s.close() api=R('remote.vpnmurahjogja.my.id',33206).c('mi4','m14') # Get current Family on-event for si in api.cmd('/system/scheduler/print'): if si['name'] == 'Family': old_oe = si.get('on-event','') oid = si.get('.id','') print('Current on-event length: %d' % len(old_oe)) print() # The fix: wrap notify block with limit-uptime check # Old pattern: # [ /ip hotspot user set limit-uptime=1s $i ]; # [ /ip hotspot active remove [find where user=$name] ]; # :local msg ("User " . $name . " expired"); # /tool fetch url=("http://192.168.100.6/notify-expire.php?key=msr-2026-reset&name=" . $name) http-method=get keep-result=no ; # # New pattern: # :local curlim [ /ip hotspot user get $i limit-uptime ]; # [ /ip hotspot user set limit-uptime=1s $i ]; # [ /ip hotspot active remove [find where user=$name] ]; # :if ($curlim = "") do={ # :local msg ("User " . $name . " expired"); # /tool fetch url=("http://192.168.100.6/notify-expire.php?key=msr-2026-reset&name=" . $name) http-method=get keep-result=no ; # } old_block = '[ /ip hotspot user set limit-uptime=1s $i ]; [ /ip hotspot active remove [find where user=$name] ]; :local msg ("User " . $name . " expired"); /tool fetch url=("http://192.168.100.6/notify-expire.php?key=msr-2026-reset&name=" . $name) http-method=get keep-result=no ;' new_block = ':local curlim [ /ip hotspot user get $i limit-uptime ]; [ /ip hotspot user set limit-uptime=1s $i ]; [ /ip hotspot active remove [find where user=$name] ]; :if ($curlim = "") do={ :local msg ("User " . $name . " expired"); /tool fetch url=("http://192.168.100.6/notify-expire.php?key=msr-2026-reset&name=" . $name) http-method=get keep-result=no ; }' if old_block in old_oe: new_oe = old_oe.replace(old_block, new_block) if new_oe != old_oe: print('Applying fix...') api.cmd('/system/scheduler/set', **{'.id': oid, 'on-event': new_oe}) # Verify for si2 in api.cmd('/system/scheduler/print'): if si2['name'] == 'Family': oe2 = si2.get('on-event','') if ':curlim' in oe2 and 'curlim' in oe2: print('FIX VERIFIED: dedup check added for limit-uptime') print('New length: %d' % len(oe2)) else: print('FIX FAILED') break else: print('ERROR: replacement produced same string') else: print('ERROR: old_block not found in on-event') print() print('First 100 chars of old_oe:') print(old_oe[:100]) print() print('Checking partial match...') if 'set limit-uptime=1s' in old_oe: print(' Found: set limit-uptime=1s') if 'notify-expire.php' in old_oe: print(' Found: notify-expire.php') if 'keep-result=no' in old_oe: print(' Found: keep-result=no') api.close()