-
-
Notifications
You must be signed in to change notification settings - Fork 65
Expand file tree
/
Copy pathcheck-admin.mjs
More file actions
73 lines (61 loc) · 2.7 KB
/
Copy pathcheck-admin.mjs
File metadata and controls
73 lines (61 loc) · 2.7 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import Database from 'better-sqlite3';
import bcrypt from 'bcrypt';
const dbPath = process.env.DATABASE_PATH || '/data/meshmonitor.db';
console.log(`\n🔍 Checking admin user in: ${dbPath}\n`);
const db = new Database(dbPath);
// Check if users table exists
const tableCheck = db.prepare(`
SELECT name FROM sqlite_master WHERE type='table' AND name='users'
`).get();
if (!tableCheck) {
console.error('❌ Users table does not exist! Database may not be initialized.');
console.log('\nTip: Make sure the container has started completely and initialized the database.\n');
db.close();
process.exit(1);
}
// Get admin user
const admin = db.prepare(`
SELECT id, username, password_hash, is_admin, is_active, created_at
FROM users
WHERE username = 'admin'
`).get();
if (!admin) {
console.error('❌ Admin user not found in database!');
console.log('\nThis suggests the database initialization did not complete.');
console.log('Check the container logs for errors during startup.\n');
db.close();
process.exit(1);
}
console.log('✅ Admin user found:');
console.log(` ID: ${admin.id}`);
console.log(` Username: ${admin.username}`);
console.log(` Is Admin: ${admin.is_admin ? 'Yes' : 'No'}`);
console.log(` Is Active: ${admin.is_active ? 'Yes' : 'No'}`);
console.log(` Created: ${new Date(admin.created_at).toLocaleString()}`);
console.log(` Password Hash: ${admin.password_hash ? admin.password_hash.substring(0, 20) + '...' : 'NULL'}`);
if (!admin.password_hash) {
console.error('\n❌ Password hash is NULL! User cannot login.');
console.log('\nRun: node reset-admin.mjs to set a new password\n');
db.close();
process.exit(1);
}
if (!admin.is_active) {
console.error('\n❌ User is inactive! User cannot login.');
db.close();
process.exit(1);
}
// Test password "changeme"
console.log('\n🔐 Testing default password "changeme"...');
const defaultPasswordWorks = await bcrypt.compare('changeme', admin.password_hash);
if (defaultPasswordWorks) {
console.log('✅ Default password "changeme" works!\n');
console.log('═══════════════════════════════════════════════════════════');
console.log(' Username: admin');
console.log(' Password: changeme');
console.log('═══════════════════════════════════════════════════════════\n');
} else {
console.log('❌ Default password "changeme" does NOT work.');
console.log('\nThe password has been changed from the default.');
console.log('If you forgot the password, run: node reset-admin.mjs\n');
}
db.close();