diagnostics: inspect deployed hotspot access without changing network state
This commit is contained in:
1 parent
0c01e5d88b
commit
8962de008e
2 files changed
+35
-38
No files matched your search
@@ -1,50 +1,21 @@
|
|||||||
name: build-download
|
name: diagnose-hotspot-access
|
||||||
|
|
||||||
on:
|
on:
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
|
|
||||||
permissions:
|
permissions:
|
||||||
contents: read
|
contents: read
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build-download:
|
diagnose:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- uses: actions/checkout@v4
|
||||||
uses: actions/checkout@v4
|
- name: Read-only production diagnosis
|
||||||
|
|
||||||
- name: Build image
|
|
||||||
run: |
|
|
||||||
docker build -t git.jf.eng.br/jfeng/hotspot:latest -t git.jf.eng.br/jfeng/hotspot:${{ github.sha }} ./backend
|
|
||||||
|
|
||||||
- name: Smoke test image
|
|
||||||
shell: bash
|
shell: bash
|
||||||
run: |
|
run: |
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
container=$(docker run -d git.jf.eng.br/jfeng/hotspot:${{ github.sha }})
|
docker inspect pix-hotspot --format 'IMAGE={{.Config.Image}} PORTS={{json .NetworkSettings.Ports}}'
|
||||||
trap 'docker rm -f "$container" >/dev/null' EXIT
|
docker exec -i pix-hotspot node --input-type=module < backend/diagnose-hotspot.mjs
|
||||||
for attempt in {1..15}; do
|
- name: Recent access errors
|
||||||
if docker exec "$container" node -e "fetch('http://127.0.0.1:3000/api/health').then(r=>{if(!r.ok)process.exit(1)}).catch(()=>process.exit(1))"; then
|
if: always()
|
||||||
docker exec "$container" node -e "Promise.all(['/api/plans','/admin'].map(p=>fetch('http://127.0.0.1:3000'+p).then(r=>{if(!r.ok)throw Error(p)}))).catch(()=>process.exit(1))"
|
|
||||||
exit 0
|
|
||||||
fi
|
|
||||||
sleep 1
|
|
||||||
done
|
|
||||||
docker logs "$container"
|
|
||||||
exit 1
|
|
||||||
|
|
||||||
- name: Export Docker archive
|
|
||||||
shell: bash
|
shell: bash
|
||||||
run: |
|
run: |
|
||||||
set -euo pipefail
|
docker logs --since 2h --tail 2000 pix-hotspot 2>&1 | node -e 'let s="";process.stdin.on("data",x=>s+=x);process.stdin.on("end",()=>console.log(s.split("\n").filter(l=>/\[ACESSO/.test(l)).slice(-40).map(l=>l.replace(/(?:[0-9a-f]{2}:){5}[0-9a-f]{2}/gi,"[MAC]").replace(/(?:\d{1,3}\.){3}\d{1,3}/g,"[IP]")).join("\n")));'
|
||||||
docker save git.jf.eng.br/jfeng/hotspot:latest git.jf.eng.br/jfeng/hotspot:${{ github.sha }} | gzip > pix-hotspot-image.tar.gz
|
|
||||||
sha256sum pix-hotspot-image.tar.gz > pix-hotspot-image.tar.gz.sha256
|
|
||||||
|
|
||||||
- name: Upload image for ZimaOS
|
|
||||||
uses: actions/upload-artifact@v3
|
|
||||||
with:
|
|
||||||
name: pix-hotspot-zimaos
|
|
||||||
path: |
|
|
||||||
pix-hotspot-image.tar.gz
|
|
||||||
pix-hotspot-image.tar.gz.sha256
|
|
||||||
retention-days: 7
|
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
import fs from 'node:fs';
|
||||||
|
import crypto from 'node:crypto';
|
||||||
|
import config from '/app/src/config.js';
|
||||||
|
import { rosCommand } from '/app/src/ros.js';
|
||||||
|
const hash=v=>crypto.createHash('sha256').update(String(v)).digest('hex').slice(0,10);
|
||||||
|
const redact=s=>String(s).replace(/(?:[0-9a-f]{2}:){5}[0-9a-f]{2}/gi,m=>'device-'+hash(m)).replace(/(?:\d{1,3}\.){3}\d{1,3}/g,m=>m.split('.').slice(0,3).join('.')+'.x');
|
||||||
|
const object=row=>Object.fromEntries(row.filter(v=>v[0]==='=').map(v=>{const i=v.indexOf('=',1);return [v.slice(1,i),v.slice(i+1)];}));
|
||||||
|
console.log('CONFIG',JSON.stringify({routerHost:config.mikrotik.host,routerPort:config.mikrotik.port,routerUser:config.mikrotik.user,server:config.mikrotik.server,hotspotIp:config.hotspotIp,baseUrl:config.baseUrl,port:config.port,freeSeconds:config.freeAccessSeconds,cooldown:config.freeAccessCooldownSeconds,processUid:fs.readFileSync('/proc/1/status','utf8').match(/^Uid:.*$/m)?.[0]}));
|
||||||
|
for(const [label,words] of [
|
||||||
|
['RESOURCE',['/system/resource/print','=.proplist=version,architecture-name,board-name']],
|
||||||
|
['HOTSPOTS',['/ip/hotspot/print','=.proplist=name,interface,profile,disabled']],
|
||||||
|
['HOTSPOT-PROFILES',['/ip/hotspot/profile/print','=.proplist=name,login-by,hotspot-address,dns-name,html-directory']],
|
||||||
|
['FREE-PROFILE',['/ip/hotspot/user/profile/print','?name=pix-free','=.proplist=.id,name,rate-limit,session-timeout,shared-users,add-mac-cookie']],
|
||||||
|
['API-USER',['/user/print','?name='+config.mikrotik.user,'=.proplist=name,group,disabled']],
|
||||||
|
['HOSTS',['/ip/hotspot/host/print','=.proplist=address,to-address,mac-address,server,authorized,bypassed']],
|
||||||
|
['ACTIVE',['/ip/hotspot/active/print','=.proplist=user,address,mac-address,server,uptime,session-time-left']],
|
||||||
|
['FREE-USERS',['/ip/hotspot/user/print','?profile=pix-free','=.proplist=name,server,profile,disabled,limit-uptime,uptime,mac-address']],
|
||||||
|
['FILTER',['/ip/firewall/filter/print','=.proplist=chain,action,disabled,comment,in-interface,out-interface,src-address,dst-address,protocol,dst-port,connection-state,jump-target']],
|
||||||
|
]) {
|
||||||
|
try {const rows=(await rosCommand(words)).map(object);console.log(label,redact(JSON.stringify(rows.map(r=>label==='ACTIVE'||label==='FREE-USERS'?{...r,user:r.user?'account-'+hash(r.user):undefined,name:r.name?'account-'+hash(r.name):undefined}:r))));}
|
||||||
|
catch(e){console.log(label+'-ERROR',redact(e.message));}
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
const db=JSON.parse(fs.readFileSync(config.dataDir+'/db.json','utf8'));
|
||||||
|
console.log('TEMP-RECORDS',JSON.stringify((db.tempAccess||[]).map(t=>({device:hash(t.mac),createdAt:t.createdAt,expiresAt:t.expiresAt,revoked:t.revoked}))));
|
||||||
|
} catch(e){console.log('DB-ERROR',redact(e.message));}
|
||||||
Reference in new issue
Block a user