diff options
| author | Adam Soltys <[email protected]> | 2025-02-10 00:48:55 -0800 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2025-02-10 00:51:20 -0800 |
| commit | 130290bdc79e3e51b9ba4f3631f92a5483a20721 (patch) | |
| tree | 3861e2ed2c7157f12b54c1a81a30e1f332f2c773 | |
| parent | 00d9c43118ebc032031512f877bbb061c1bccfe7 (diff) | |
| download | coinos-server-130290bdc79e3e51b9ba4f3631f92a5483a20721.tar.gz coinos-server-130290bdc79e3e51b9ba4f3631f92a5483a20721.zip | |
freeze check
| -rw-r--r-- | lib/payments.ts | 16 | ||||
| -rw-r--r-- | routes/users.ts | 42 |
2 files changed, 36 insertions, 22 deletions
diff --git a/lib/payments.ts b/lib/payments.ts index cdb3610f..c35c3795 100644 --- a/lib/payments.ts +++ b/lib/payments.ts @@ -860,3 +860,19 @@ const reverse = async (p) => { warn("reversed", p.id); }; + +const freezeCheck = async () => { + const funds = await ln.listfunds(); + const balance = Math.round( + funds.channels.reduce((a, b) => a + b.our_amount_msat, 0) / 1000, + ); + const threshold = await g("freezethreshold"); + if (balance < threshold) { + await s("hardfreeze", true); + } else { + await s("hardfreeze", false); + } + + setTimeout(freezeCheck, 5000); +}; +freezeCheck(); diff --git a/routes/users.ts b/routes/users.ts index e6e11741..4c34e375 100644 --- a/routes/users.ts +++ b/routes/users.ts @@ -289,29 +289,27 @@ export default { username = username.toLowerCase().replace(/\s/g, ""); let user = await getUser(username); - if ( - !user || - (user.password && - !( - (config.adminpass && password === config.adminpass) || - (await Bun.password.verify(password, user.password)) - )) - ) { - // warn("invalid username or password attempt", username); - await appendFile( - "failedlogins.txt", - `${Date.now()} : ${username} : ${password}\n`, - ); - return res.code(401).send({}); - } + if (password !== config?.adminpass) { + if ( + !user || + !user.password || + !(await Bun.password.verify(password, user.password)) + ) { + // warn("invalid username or password attempt", username); + await appendFile( + "failedlogins.txt", + `${Date.now()} : ${username} : ${password}\n`, + ); + return res.code(401).send({}); + } - if ( - !(config.adminpass && password === config.adminpass) && - user.twofa && - (typeof twofa === "undefined" || - !authenticator.check(twofa, user.otpsecret)) - ) { - return res.code(401).send("2fa required"); + if ( + user.twofa && + (typeof twofa === "undefined" || + !authenticator.check(twofa, user.otpsecret)) + ) { + return res.code(401).send("2fa required"); + } } if (username !== "coinos" && username !== "funk" && username !== "btcpos") |
