small changes
This commit is contained in:
parent
ed4b74362e
commit
8accb3fd2f
8 changed files with 42 additions and 25 deletions
|
@ -6,8 +6,22 @@ import { oConf } from "../../sys/config.js";
|
|||
import { sha256, verify } from "../../sys/crypto.js";
|
||||
import { accounts, db, signupOTA as signupOTATable } from "../../sys/db.js";
|
||||
import { get64, uts } from "../../sys/tools.js";
|
||||
import { addTempToken, postClient } from "../post.js";
|
||||
import { Act, Client, STATE } from "../user.js";
|
||||
|
||||
export const requestTempToken: Act = {
|
||||
state: STATE.no,
|
||||
right: 0,
|
||||
data: {},
|
||||
func: async (client: Client, data: any, aws: (code: string, data: any) => void): Promise<void> => {
|
||||
if (!(client instanceof postClient)) return void aws("error", "mode");
|
||||
let token = addTempToken(client);
|
||||
aws("ok", {
|
||||
token
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
export const signup: Act = {
|
||||
state: STATE.no,
|
||||
right: 0,
|
||||
|
|
0
src/api/acts/server.ts
Normal file
0
src/api/acts/server.ts
Normal file
|
@ -28,7 +28,9 @@ export const addPostMethods = (server: express.Express) => {
|
|||
let client: postClient | null = null;
|
||||
try {
|
||||
let auth = authorization.parse(req.headers["authorization"] ?? "");
|
||||
if (auth.token != null && typeof auth.token == "string") {
|
||||
if (auth.scheme == "outbagServer") {
|
||||
|
||||
} else if (auth.token != null && typeof auth.token == "string") {
|
||||
if (tempTokens[auth.token] != null) {
|
||||
client = tempTokens[auth.token];
|
||||
} else {
|
||||
|
@ -72,7 +74,7 @@ export const addPostMethods = (server: express.Express) => {
|
|||
}
|
||||
}
|
||||
|
||||
class postClient extends Client {
|
||||
export class postClient extends Client {
|
||||
lastReq = uts();
|
||||
constructor(ip: string) {
|
||||
super(ip);
|
||||
|
|
|
@ -3,10 +3,11 @@ import { accounts, db, roomMembers, rooms } from "../sys/db.js";
|
|||
import { addBruteforcePotantial } from "../sys/bruteforce.js";
|
||||
|
||||
export const STATE = {
|
||||
no: 0b0001,
|
||||
remoteP: 0b0010,
|
||||
remote: 0b0100,
|
||||
client: 0b1000
|
||||
no: 0b00001,
|
||||
remoteP: 0b00010,
|
||||
remote: 0b00100,
|
||||
client: 0b01000,
|
||||
server: 0b10000,
|
||||
};
|
||||
|
||||
export const MODE = {
|
||||
|
|
|
@ -15,7 +15,7 @@ export const wsOnConnection = (socket: ws.WebSocket, req: http.IncomingMessage)
|
|||
|
||||
let clients: wsClient[] = [];
|
||||
|
||||
class wsClient extends Client {
|
||||
export class wsClient extends Client {
|
||||
socket: ws.WebSocket;
|
||||
open = true;
|
||||
activeRequests = 0;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { outbagURL } from "./outbagURL.js";
|
||||
import { outbagURL, outbagURLshort } from "./outbagURL.js";
|
||||
import { db, serverCerts } from "../sys/db.js"
|
||||
import { eq, exists, insert, not, remove, select, update } from "dblang";
|
||||
import { eq, insert, select, update } from "dblang";
|
||||
import { error, log } from "../sys/log.js";
|
||||
import { uts } from "../sys/tools.js";
|
||||
import { getSettings, setSettings, SETTINGS } from "../sys/settings.js"
|
||||
|
@ -27,7 +27,6 @@ export const startUpdateCerts = () => {
|
|||
}, 100);
|
||||
}
|
||||
|
||||
|
||||
async function updateRemote(url: string, pKey: string = ""): Promise<boolean | string> {
|
||||
var urlP = await outbagURL(url);
|
||||
return new Promise((res, rej) => {
|
||||
|
@ -63,9 +62,9 @@ async function updateRemote(url: string, pKey: string = ""): Promise<boolean | s
|
|||
return;
|
||||
}
|
||||
res(false);
|
||||
})
|
||||
})
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
export const getRemote = async (url: string) => {
|
||||
let query = await select([serverCerts.publicKey, serverCerts.expires], serverCerts)
|
||||
|
@ -74,4 +73,4 @@ export const getRemote = async (url: string) => {
|
|||
if (query.length == 0 || query[0][serverCerts.expires] < uts() - 60)
|
||||
return await updateRemote(url, query[0][serverCerts.publicKey]);
|
||||
return query[0][serverCerts.publicKey];
|
||||
}
|
||||
};
|
||||
|
|
|
@ -72,7 +72,8 @@ serverCerts.addAttributes({
|
|||
serverCertID: { type: INT, primaryKey: true, autoIncrement: true },
|
||||
url: { type: TEXT },
|
||||
publicKey: { type: TEXT },
|
||||
expires: { type: BIGINT }
|
||||
expires: { type: BIGINT },
|
||||
token: { type: TEXT, notNull: false },
|
||||
});
|
||||
|
||||
export const signupOTA = db.newTable("signupOTA");
|
||||
|
|
Loading…
Reference in a new issue