forked from shobhit-pathak/cs2-rcon-panel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdb.js
47 lines (40 loc) · 1.22 KB
/
db.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
const Database = require('better-sqlite3');
const bcrypt = require('bcrypt');
const better_sqlite_client = new Database('cspanel.db');
better_sqlite_client.exec(`
CREATE TABLE IF NOT EXISTS servers (
id INTEGER PRIMARY KEY,
serverIP TEXT NOT NULL,
serverPort INTEGER NOT NULL,
rconPassword TEXT NOT NULL
)
`);
better_sqlite_client.exec(`
CREATE TABLE IF NOT EXISTS users (
id INTEGER PRIMARY KEY,
username TEXT NOT NULL UNIQUE,
password TEXT NOT NULL
)
`);
const default_username = 'cspanel';
const default_password = 'v67ic55x4ghvjfj';
// Hash the default password
const hashed_password = bcrypt.hashSync(default_password, 10);
// Check if the default user already exists
const existing_user = better_sqlite_client.prepare(`
SELECT * FROM users WHERE username = ?
`).get(default_username);
if (existing_user) {
console.log('Default user already exists');
} else {
// Insert the default user into the users table
const insert_query = better_sqlite_client.prepare(`
INSERT INTO users (username, password)
VALUES (?, ?)
`);
insert_query.run(default_username, hashed_password);
console.log('Default user created successfully.');
}
module.exports = {
better_sqlite_client
};