init: workspace opencode sync

This commit is contained in:
2026-08-15 00:28:08 +07:00
commit 2451170708
122 changed files with 10549 additions and 0 deletions
+130
View File
@@ -0,0 +1,130 @@
import paramiko
import time
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect('192.168.100.2', username='mi4', password='m14', look_for_keys=False, allow_agent=False)
def router_cmd(cmd, wait=0.5):
time.sleep(wait)
stdin, stdout, stderr = client.exec_command(cmd)
time.sleep(0.5)
out = stdout.read().decode().strip()
err = stderr.read().decode().strip()
if err: print(f" ERR: {err[:150]}")
return out
def flush_shell(chan):
out = b''
chan.settimeout(1.0)
while True:
try:
chunk = chan.recv(65535)
if not chunk: break
out += chunk
except:
break
return out.decode(errors='replace')
schedulers = ["Bulanan2", "Bulanan4", "vc-2K3J", "vc-5K10J", "Family", "DevB2"]
print("=== Fixing scheduler on-event ===")
for s in schedulers:
print(f"\n--- {s} ---")
raw = router_cmd(f':put [/system scheduler get {s} on-event]')
if not raw:
print(" Empty on-event, skipping")
continue
if ':pic' not in raw:
print(" No :pic found, skipping")
continue
fixed = raw.replace(':pic', ':pick')
count = raw.count(':pic')
print(f" Fixed {count} :pic -> :pick (len={len(fixed)})")
# Escape for CLI: $->\$, "->\", \->\\
esc = fixed.replace('\\', '\\\\').replace('"', '\\"').replace('$', '\\$')
temp = f"tmp_{s}"
chan = client.invoke_shell()
chan.settimeout(10)
time.sleep(1.5)
flush_shell(chan)
chan.send(f'/system script remove {temp}\n'); time.sleep(1); flush_shell(chan)
chan.send(f'/system script add name={temp} source="{esc}"\n'); time.sleep(2)
out = flush_shell(chan)
if 'failure' in out.lower():
print(f" Script create FAILED: {out[:150]}")
chan.close()
continue
print(" Temp script OK")
chan.send(f'/system scheduler set {s} on-event=[/system script get {temp} source]\n')
time.sleep(2); out = flush_shell(chan)
if 'failure' in out.lower():
print(f" Scheduler set FAILED: {out[:150]}")
else:
print(" Scheduler set OK")
chan.send(f'/system script remove {temp}\n'); time.sleep(1); flush_shell(chan)
chan.close()
print("\n=== Verification (scheduler on-event) ===")
for s in schedulers:
oe = router_cmd(f':put [/system scheduler get {s} on-event]')
hp = ':pic' in oe; hk = ':pick' in oe
print(f" {s}: {'OK' if hk and not hp else 'BROKEN'} (pic={hp} pick={hk})")
profiles = ["Bulanan2", "Bulanan4", "vc-2K3J", "vc-5K10J", "Family", "home", "DevB2"]
print("\n\n=== Fixing profile on-login ===")
for p in profiles:
print(f"\n--- {p} ---")
raw = router_cmd(f':put [/ip hotspot user/profile get {p} on-login]')
if not raw:
print(" Empty on-login, skipping")
continue
if ':pic' not in raw:
print(" No :pic found, skipping")
continue
fixed = raw.replace(':pic', ':pick')
count = raw.count(':pic')
print(f" Fixed {count} :pic -> :pick")
esc = fixed.replace('\\', '\\\\').replace('"', '\\"').replace('$', '\\$')
temp = f"tmp_{p}"
chan = client.invoke_shell()
chan.settimeout(10)
time.sleep(1.5)
flush_shell(chan)
chan.send(f'/system script remove {temp}\n'); time.sleep(1); flush_shell(chan)
chan.send(f'/system script add name={temp} source="{esc}"\n'); time.sleep(2)
out = flush_shell(chan)
if 'failure' in out.lower():
print(f" Script create FAILED: {out[:150]}")
chan.close()
continue
print(" Temp script OK")
chan.send(f'/ip hotspot user/profile set {p} on-login=[/system script get {temp} source]\n')
time.sleep(2); out = flush_shell(chan)
if 'failure' in out.lower():
print(f" Profile set FAILED: {out[:150]}")
else:
print(" Profile set OK")
chan.send(f'/system script remove {temp}\n'); time.sleep(1); flush_shell(chan)
chan.close()
print("\n=== Profile Verification ===")
for p in profiles:
ol = router_cmd(f':put [/ip hotspot user/profile get {p} on-login]')
hp = ':pic' in ol; hk = ':pick' in ol
print(f" {p}: {'OK' if hk and not hp else 'BROKEN'} (pic={hp} pick={hk})")
client.close()
print("\nALL DONE")