init: workspace opencode sync
This commit is contained in:
+121
@@ -0,0 +1,121 @@
|
||||
import socket, hashlib, time
|
||||
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)<l: d+=s.s.recv(l-len(d))
|
||||
return d.decode(errors='replace')
|
||||
def _rss(s):
|
||||
ws=[]
|
||||
while True:
|
||||
w=s._rw()
|
||||
if w is None: break
|
||||
ws.append(w)
|
||||
return ws
|
||||
def _rr(s):
|
||||
rs=[]
|
||||
while True:
|
||||
s2=s._rss()
|
||||
if not s2: break
|
||||
r=s2[0]; t=s2[1:]
|
||||
if r=='!done': break
|
||||
elif r=='!re':
|
||||
d={}
|
||||
for w in t:
|
||||
if '=' in w:
|
||||
p=w.split('=',2)
|
||||
d[p[1]]=p[2] if len(p)>=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')
|
||||
|
||||
# Try running scheduler with correct API syntax
|
||||
print('Method 1: system scheduler run with name query...')
|
||||
r = api.cmd('/system/scheduler/run', **{'?name': 'Bulanan4'})
|
||||
print(' Result: %s' % r)
|
||||
|
||||
time.sleep(2)
|
||||
|
||||
# Check Nadia
|
||||
users = api.cmd('/ip/hotspot/user/print', **{'?name': 'Nadia'})
|
||||
if users:
|
||||
u = users[0]
|
||||
print('Nadia after run: limit-uptime=%s' % u.get('limit-uptime','?'))
|
||||
else:
|
||||
print('Nadia: REMOVED!')
|
||||
|
||||
# Method 2: Direct set limit-uptime=1s
|
||||
print()
|
||||
print('Method 2: Direct set limit-uptime=1s for expired users...')
|
||||
now = 'jul/24/2026'
|
||||
expired = []
|
||||
for u in api.cmd('/ip/hotspot/user/print', **{'?profile': 'Bulanan4'}):
|
||||
c = u.get('comment','')
|
||||
n = u.get('name','')
|
||||
lim = u.get('limit-uptime','')
|
||||
if c and not lim and '/' in c:
|
||||
# Parse date
|
||||
parts = c.split(' ')[0] # "jul/20/2026"
|
||||
mon, day, year = parts.split('/')
|
||||
months = {'jan':1,'feb':2,'mar':3,'apr':4,'may':5,'jun':6,'jul':7,'aug':8,'sep':9,'oct':10,'nov':11,'dec':12}
|
||||
exp_day = int(day)
|
||||
exp_mon = months.get(mon, 0)
|
||||
exp_year = int(year)
|
||||
cur_day = 24
|
||||
cur_mon = 7
|
||||
cur_year = 2026
|
||||
exp_num = exp_year*10000 + exp_mon*100 + exp_day
|
||||
cur_num = cur_year*10000 + cur_mon*100 + cur_day
|
||||
if exp_num < cur_num:
|
||||
expired.append(u['.id'])
|
||||
print(' %s expires %s -> SET limit-uptime=1s' % (n, c))
|
||||
|
||||
if expired:
|
||||
api.cmd('/ip/hotspot/user/set', **{'numbers': ','.join(expired), 'limit-uptime': '1s'})
|
||||
print()
|
||||
print('Verifying...')
|
||||
for u in api.cmd('/ip/hotspot/user/print', **{'?profile': 'Bulanan4'}):
|
||||
n = u.get('name','')
|
||||
lim = u.get('limit-uptime','')
|
||||
if lim:
|
||||
print(' %s -> limit-uptime=%s' % (n, lim))
|
||||
else:
|
||||
print(' No expired users found')
|
||||
|
||||
api.close()
|
||||
Reference in New Issue
Block a user