sync: auto-sync from GURU-5070 at 2026-06-15 20:03:03
Author: Mike Swanson Machine: GURU-5070 Timestamp: 2026-06-15 20:03:03
This commit is contained in:
@@ -87,7 +87,7 @@ def call(method,path,body=None,csrf=None,want_headers=False):
|
|||||||
r=urllib.request.Request(base+path,data=data,method=method)
|
r=urllib.request.Request(base+path,data=data,method=method)
|
||||||
r.add_header('Content-Type','application/json')
|
r.add_header('Content-Type','application/json')
|
||||||
if csrf:r.add_header('X-CSRF-Token',csrf)
|
if csrf:r.add_header('X-CSRF-Token',csrf)
|
||||||
resp=op.open(r,timeout=20);hdr=dict(resp.headers);txt=resp.read().decode('utf-8','replace')
|
resp=op.open(r,timeout=20);hdr=resp.headers;txt=resp.read().decode('utf-8','replace')
|
||||||
return (txt,hdr) if want_headers else txt
|
return (txt,hdr) if want_headers else txt
|
||||||
# login + CSRF
|
# login + CSRF
|
||||||
try:_,hd=call('POST','/api/auth/login',{'username':os.environ['RW_U'],'password':os.environ['RW_P']},want_headers=True)
|
try:_,hd=call('POST','/api/auth/login',{'username':os.environ['RW_U'],'password':os.environ['RW_P']},want_headers=True)
|
||||||
|
|||||||
@@ -36,20 +36,17 @@ CJ="$(mktemp)"; trap 'rm -f "$CJ"' EXIT
|
|||||||
base="https://$HOST:$PORT"
|
base="https://$HOST:$PORT"
|
||||||
# UniFi OS login -> session cookie
|
# UniFi OS login -> session cookie
|
||||||
code=$(curl -sk -c "$CJ" -o /dev/null -w '%{http_code}' -X POST "$base/api/auth/login" \
|
code=$(curl -sk -c "$CJ" -o /dev/null -w '%{http_code}' -X POST "$base/api/auth/login" \
|
||||||
-H 'Content-Type: application/json' --data-binary "$(python -c 'import json,os;print(json.dumps({"username":os.environ["U"],"password":os.environ["P"]}))' U="$U" P="$P")")
|
-H 'Content-Type: application/json' --data-binary "$(python -c 'import json,sys;print(json.dumps({"username":sys.argv[1],"password":sys.argv[2]}))' "$U" "$P")")
|
||||||
[ "$code" = "200" ] || { echo "[ERROR] login HTTP $code"; exit 1; }
|
[ "$code" = "200" ] || { echo "[ERROR] login HTTP $code"; exit 1; }
|
||||||
|
|
||||||
# resolve site short name (classic API keys on the short name, not the _id)
|
# resolve site short name (classic API keys on the short name, not the _id or display name)
|
||||||
SHORT="$SITEARG"
|
SHORT="$(curl -sk -b "$CJ" "$base/proxy/network/api/self/sites" | python -c "
|
||||||
if [[ "$SITEARG" =~ ^[0-9a-f]{24}$ || ! "$SITEARG" =~ ^[a-z0-9]{8}$ ]]; then
|
|
||||||
SHORT="$(curl -sk -b "$CJ" "$base/proxy/network/api/self/sites" | python -c "
|
|
||||||
import sys,json
|
import sys,json
|
||||||
d=json.load(sys.stdin).get('data',[])
|
d=json.load(sys.stdin).get('data',[]); q='''$SITEARG'''.lower()
|
||||||
q='''$SITEARG'''.lower()
|
|
||||||
for s in d:
|
for s in d:
|
||||||
if s.get('_id')=='''$SITEARG''' or q in (s.get('desc','').lower()): print(s.get('name')); break
|
if s.get('_id')=='''$SITEARG''' or s.get('name')=='''$SITEARG''' or q in (s.get('desc','').lower()): print(s.get('name')); break
|
||||||
" 2>/dev/null)"
|
" 2>/dev/null)"
|
||||||
fi
|
[ -n "$SHORT" ] || SHORT="$SITEARG"
|
||||||
[ -n "$SHORT" ] || { echo "[ERROR] could not resolve site '$SITEARG'"; exit 1; }
|
[ -n "$SHORT" ] || { echo "[ERROR] could not resolve site '$SITEARG'"; exit 1; }
|
||||||
echo "[INFO] site short=$SHORT"
|
echo "[INFO] site short=$SHORT"
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user