|
|
@@ -13,7 +13,7 @@ import { sshBaseArgs } from '../sshkey.js'
|
|
|
|
|
|
const SSH_TIMEOUT_MS = 8000
|
|
|
const HTTP_TIMEOUT_MS = 4000
|
|
|
-const LOGIN_COOLDOWN_MS = 5 * 60 * 1000 // el GL bloquea logins tras N fallos
|
|
|
+const LOGIN_COOLDOWN_MS = 15 * 60 * 1000 // el GL bloquea logins tras N fallos; no alimentar el lockout
|
|
|
|
|
|
export class AdGuardGlinetClient {
|
|
|
/**
|
|
|
@@ -42,9 +42,12 @@ export class AdGuardGlinetClient {
|
|
|
})
|
|
|
}
|
|
|
|
|
|
- /** Login GL completo en el router → sid (cookie Admin-Token). */
|
|
|
+ /** Login GL completo en el router → sid (cookie Admin-Token).
|
|
|
+ * Flujo (del propio binario gl-ngx-session):
|
|
|
+ * challenge → nonce+salt+alg → pw=openssl passwd -alg -salt salt pass
|
|
|
+ * → hash=sha256("<user>:<pw>:<nonce>") → login → sid */
|
|
|
async login() {
|
|
|
- // Cooldown tras fallo: el GL bloquea logins tras N intentos (303 s)
|
|
|
+ // Cooldown tras fallo: el GL bloquea logins tras N intentos (600 s)
|
|
|
if (this.loginFailUntil && Date.now() < this.loginFailUntil) {
|
|
|
throw new Error(`login GL en cooldown (${Math.ceil((this.loginFailUntil - Date.now()) / 1000)} s)`)
|
|
|
}
|
|
|
@@ -53,14 +56,14 @@ export class AdGuardGlinetClient {
|
|
|
const esc = this.pass.replace(/'/g, `'\\''`)
|
|
|
const script = [
|
|
|
`PASS='${esc}'`,
|
|
|
- `RESP=$(curl -s -m 5 -X POST http://127.0.0.1/rpc -H 'Content-Type: application/json' -d '{"jsonrpc":"2.0","id":1,"method":"challenge","params":{"username":"${this.user}"}}')`,
|
|
|
- 'SALT=$(echo "$RESP" | jsonfilter -e @.result.salt)',
|
|
|
- 'NONCE=$(echo "$RESP" | jsonfilter -e @.result.nonce)',
|
|
|
- 'ALG=$(echo "$RESP" | jsonfilter -e @.result.alg)',
|
|
|
- 'CIPHER=$(openssl passwd -$ALG -salt "$SALT" "$PASS")',
|
|
|
- 'HASH=$(echo -n "$CIPHER:$NONCE" | md5sum | cut -d" " -f1)',
|
|
|
- `RESP2=$(curl -s -m 5 -X POST http://127.0.0.1/rpc -H 'Content-Type: application/json' -d "{\\"jsonrpc\\":\\"2.0\\",\\"id\\":1,\\"method\\":\\"login\\",\\"params\\":{\\"username\\":\\"${this.user}\\",\\"hash\\":\\"$HASH\\"}}")`,
|
|
|
- 'SID=$(echo "$RESP2" | jsonfilter -e @.result.sid 2>/dev/null)',
|
|
|
+ `RESP=$(ubus call gl-session challenge '{"username":"${this.user}"}')`,
|
|
|
+ 'NONCE=$(jsonfilter -s "$RESP" -e \'@.data.nonce\')',
|
|
|
+ 'SALT=$(jsonfilter -s "$RESP" -e \'@.data.salt\')',
|
|
|
+ 'ALG=$(jsonfilter -s "$RESP" -e \'@.data.alg\')',
|
|
|
+ 'PW=$(openssl passwd -$ALG -salt "$SALT" "$PASS")',
|
|
|
+ `HASH=$(echo -n "${this.user}:$PW:$NONCE" | sha256sum | cut -d' ' -f1)`,
|
|
|
+ `RESP2=$(ubus call gl-session login '{"username":"${this.user}","hash":"'$HASH'"}')`,
|
|
|
+ 'SID=$(jsonfilter -s "$RESP2" -e \'@.data.sid\')',
|
|
|
'echo "SID:$SID"',
|
|
|
].join(' && ')
|
|
|
const out = await this.ssh(script).catch((err) => {
|