38 lines
2.0 KiB
Python
38 lines
2.0 KiB
Python
#!/usr/bin/env python3
|
|
"""Run a GM/console command on the LOCAL mangosd through SOAP (127.0.0.1:7878; owner 2026-11-28).
|
|
|
|
ops/local_gm.py 'account set gmlevel <account> 5'
|
|
ops/local_gm.py 'reload all_item' # any console command, no leading dot
|
|
|
|
Authenticates as the LOCAL GM test account (342) using the harness fixture; the credentials are read from disk and
|
|
never printed. LOCAL server only - never point this at a public server."""
|
|
import base64, html, json, re, sys, urllib.request
|
|
from pathlib import Path
|
|
|
|
LOGIN = Path('/home/praxis/.claude/jobs/8f9a0552/tmp/login342/login.py')
|
|
|
|
def credentials():
|
|
src = LOGIN.read_text()
|
|
fixture = Path(re.search(r"ACCOUNT_FIXTURE=Path\('([^']+)'\)", src).group(1))
|
|
secret_name = re.search(r"ACCOUNT_FIXTURE\.parent/'([^']+)'", src).group(1)
|
|
user = re.search(r"ui\.type_text\(d,'([^']+)'\)", src).group(1)
|
|
json.loads(fixture.read_bytes()) # same fixture the client login uses
|
|
return user, (fixture.parent / secret_name).read_text().strip()
|
|
|
|
def run(command):
|
|
user, secret = credentials()
|
|
body = ('<?xml version="1.0" encoding="utf-8"?><SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" '
|
|
'xmlns:ns1="urn:MaNGOS"><SOAP-ENV:Body><ns1:executeCommand><command>' + html.escape(command) +
|
|
'</command></ns1:executeCommand></SOAP-ENV:Body></SOAP-ENV:Envelope>').encode()
|
|
auth = base64.b64encode(f'{user}:{secret}'.encode()).decode()
|
|
req = urllib.request.Request('http://127.0.0.1:7878/', body, {'Content-Type': 'text/xml', 'Authorization': 'Basic ' + auth})
|
|
try:
|
|
out = urllib.request.urlopen(req, timeout=30).read().decode(errors='replace')
|
|
except urllib.error.HTTPError as e:
|
|
out = e.read().decode(errors='replace')
|
|
m = re.search(r'<result>(.*?)</result>', out, re.S) or re.search(r'<faultstring>(.*?)</faultstring>', out, re.S)
|
|
return html.unescape(m.group(1)).strip() if m else out[:500]
|
|
|
|
if __name__ == '__main__':
|
|
print(run(' '.join(sys.argv[1:])))
|