78 lines
2.2 KiB
Python
78 lines
2.2 KiB
Python
import librouteros
|
|
|
|
api = librouteros.connect('192.168.100.2', 'mi4', 'm14', port=8728)
|
|
|
|
schedulers = ["Bulanan2", "Bulanan4", "vc-2K3J", "vc-5K10J", "Family", "DevB2"]
|
|
|
|
for name in schedulers:
|
|
items = list(api('/system/scheduler/print', **{'?name': name}))
|
|
if not items:
|
|
print(f"{name}: not found")
|
|
continue
|
|
|
|
item = items[0]
|
|
oe = item['on-event']
|
|
|
|
if ':pic' not in oe:
|
|
print(f"{name}: already fixed")
|
|
continue
|
|
|
|
fixed = oe.replace(':pic', ':pick')
|
|
count = oe.count(':pic')
|
|
|
|
# Try set with kwargs (word=value syntax)
|
|
try:
|
|
api('/system/scheduler/set', '.id=' + item['.id'], 'on-event=' + fixed)
|
|
print(f"{name}: set OK (fixed {count})")
|
|
except Exception as e:
|
|
print(f"{name}: ERROR - {e}")
|
|
# Try alt approach: set disabled and on-event separately
|
|
try:
|
|
api('/system/scheduler/set', '.id=' + item['.id'], 'on-event=' + fixed)
|
|
except Exception as e2:
|
|
print(f"{name}: alt also failed - {e2}")
|
|
|
|
# Verify
|
|
print("\n=== Verification ===")
|
|
all_ok = True
|
|
for item in list(api('/system/scheduler/print')):
|
|
name = item['name']
|
|
oe = item.get('on-event', '')
|
|
if ':pic' in oe:
|
|
print(f" STILL BROKEN: {name}")
|
|
all_ok = False
|
|
else:
|
|
print(f" OK: {name}")
|
|
if all_ok:
|
|
print(" ALL SCHEDULERS FIXED!")
|
|
|
|
# Fix profile on-login
|
|
print("\n=== Fixing profile on-login ===")
|
|
for item in list(api('/ip/hotspot/user/profile/print')):
|
|
name = item['name']
|
|
ol = item.get('on-login', '')
|
|
if ':pic' not in ol:
|
|
print(f"{name}: already fixed")
|
|
continue
|
|
fixed = ol.replace(':pic', ':pick')
|
|
count = ol.count(':pic')
|
|
try:
|
|
api('/ip/hotspot/user/profile/set', '.id=' + item['.id'], 'on-login=' + fixed)
|
|
print(f"{name}: fixed {count}")
|
|
except Exception as e:
|
|
print(f"{name}: ERROR - {e}")
|
|
|
|
# Verify profiles
|
|
print("\n=== Profile Verification ===")
|
|
all_ok = True
|
|
for item in list(api('/ip/hotspot/user/profile/print')):
|
|
name = item['name']
|
|
ol = item.get('on-login', '')
|
|
if ':pic' in ol:
|
|
print(f" STILL BROKEN: {name} (on-login)")
|
|
all_ok = False
|
|
if all_ok:
|
|
print(" ALL PROFILES FIXED!")
|
|
|
|
api.close()
|