126 lines
4.3 KiB
JavaScript
126 lines
4.3 KiB
JavaScript
|
#!/usr/bin/env node
|
|||
|
|
|||
|
/**
|
|||
|
* Script to create a default superuser account
|
|||
|
* This script creates a superuser without requiring interactive input
|
|||
|
*
|
|||
|
* Usage: node scripts/create-default-superuser.js
|
|||
|
*/
|
|||
|
|
|||
|
import crypto from 'crypto';
|
|||
|
import fs from 'fs';
|
|||
|
|
|||
|
function generateId() {
|
|||
|
return crypto.randomBytes(16).toString('hex');
|
|||
|
}
|
|||
|
|
|||
|
function createSuperUser(userData) {
|
|||
|
const now = new Date().toISOString();
|
|||
|
|
|||
|
return {
|
|||
|
id: generateId(),
|
|||
|
email: userData.email,
|
|||
|
username: userData.username,
|
|||
|
displayName: userData.displayName,
|
|||
|
avatarUrl: userData.avatarUrl,
|
|||
|
bio: userData.bio,
|
|||
|
isAdmin: true,
|
|||
|
isModerator: true,
|
|||
|
isSuperUser: true,
|
|||
|
permissions: [
|
|||
|
'user:create',
|
|||
|
'user:read',
|
|||
|
'user:update',
|
|||
|
'user:delete',
|
|||
|
'user:promote',
|
|||
|
'script:approve',
|
|||
|
'script:reject',
|
|||
|
'script:delete',
|
|||
|
'comment:moderate',
|
|||
|
'system:configure',
|
|||
|
'analytics:view',
|
|||
|
'backup:manage'
|
|||
|
],
|
|||
|
createdAt: now,
|
|||
|
updatedAt: now,
|
|||
|
// In a real app, this would be hashed
|
|||
|
passwordHash: crypto.createHash('sha256').update(userData.password).digest('hex')
|
|||
|
};
|
|||
|
}
|
|||
|
|
|||
|
function main() {
|
|||
|
console.log('🚀 ScriptShare Default Super User Creation Tool');
|
|||
|
console.log('==============================================\n');
|
|||
|
|
|||
|
try {
|
|||
|
// Default superuser data
|
|||
|
const defaultSuperUser = createSuperUser({
|
|||
|
email: 'admin@scriptshare.com',
|
|||
|
username: 'admin',
|
|||
|
displayName: 'System Administrator',
|
|||
|
password: 'admin123',
|
|||
|
bio: 'Default system administrator account',
|
|||
|
avatarUrl: ''
|
|||
|
});
|
|||
|
|
|||
|
console.log('✅ Default Super User Created Successfully!');
|
|||
|
console.log('===========================================');
|
|||
|
console.log(`ID: ${defaultSuperUser.id}`);
|
|||
|
console.log(`Email: ${defaultSuperUser.email}`);
|
|||
|
console.log(`Username: @${defaultSuperUser.username}`);
|
|||
|
console.log(`Display Name: ${defaultSuperUser.displayName}`);
|
|||
|
console.log(`Password: admin123 (CHANGE THIS IN PRODUCTION!)`);
|
|||
|
console.log(`Super User: ${defaultSuperUser.isSuperUser ? 'Yes' : 'No'}`);
|
|||
|
console.log(`Admin: ${defaultSuperUser.isAdmin ? 'Yes' : 'No'}`);
|
|||
|
console.log(`Moderator: ${defaultSuperUser.isModerator ? 'Yes' : 'No'}`);
|
|||
|
console.log(`Permissions: ${defaultSuperUser.permissions.length} total`);
|
|||
|
console.log(`Created: ${defaultSuperUser.createdAt}`);
|
|||
|
|
|||
|
console.log('\n📋 Next Steps:');
|
|||
|
console.log('1. Save this user data to your database');
|
|||
|
console.log('2. Use these credentials to log into the admin panel:');
|
|||
|
console.log(' - Email: admin@scriptshare.com');
|
|||
|
console.log(' - Password: admin123');
|
|||
|
console.log('3. CHANGE THE PASSWORD IMMEDIATELY after first login');
|
|||
|
console.log('4. Create additional admin users through the web interface');
|
|||
|
|
|||
|
// Save to a JSON file for reference
|
|||
|
const outputPath = './default-superuser-account.json';
|
|||
|
fs.writeFileSync(outputPath, JSON.stringify(defaultSuperUser, null, 2));
|
|||
|
console.log(`\n💾 User data saved to: ${outputPath}`);
|
|||
|
|
|||
|
// Also save to localStorage format for the web app
|
|||
|
const webAppData = {
|
|||
|
id: defaultSuperUser.id,
|
|||
|
email: defaultSuperUser.email,
|
|||
|
username: defaultSuperUser.username,
|
|||
|
displayName: defaultSuperUser.displayName,
|
|||
|
avatarUrl: defaultSuperUser.avatarUrl,
|
|||
|
bio: defaultSuperUser.bio,
|
|||
|
isAdmin: defaultSuperUser.isAdmin,
|
|||
|
isModerator: defaultSuperUser.isModerator,
|
|||
|
isSuperUser: defaultSuperUser.isSuperUser,
|
|||
|
permissions: defaultSuperUser.permissions,
|
|||
|
createdAt: defaultSuperUser.createdAt,
|
|||
|
updatedAt: defaultSuperUser.updatedAt
|
|||
|
};
|
|||
|
|
|||
|
const webAppPath = './webapp-superuser.json';
|
|||
|
fs.writeFileSync(webAppPath, JSON.stringify(webAppData, null, 2));
|
|||
|
console.log(`💾 Web app user data saved to: ${webAppPath}`);
|
|||
|
|
|||
|
console.log('\n⚠️ IMPORTANT SECURITY NOTES:');
|
|||
|
console.log('- This is a default account for development only');
|
|||
|
console.log('- Change the password immediately after first login');
|
|||
|
console.log('- Delete this script in production environments');
|
|||
|
console.log('- Use strong, unique passwords in production');
|
|||
|
|
|||
|
} catch (error) {
|
|||
|
console.error('❌ Error creating super user:', error.message);
|
|||
|
process.exit(1);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
// Run the main function
|
|||
|
main();
|