forked from ptisp/cloudash
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.js
59 lines (54 loc) · 1.41 KB
/
install.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
48
49
50
51
52
53
54
55
56
57
58
59
var MongoClient = require('mongodb').MongoClient,
ObjectId = require('mongodb').ObjectID,
fs = require('fs'),
crypto = require('crypto');
console.log('Running install script.');
try {
fs.statSync('./config.js').isFile();
} catch (err) {
console.log('ERROR: config.js missing!');
process.exit(1);
}
var config = require('./config');
var password = Math.random().toString(36).substr(2, 12);
var insertUser = function(db, callback) {
db.collection('users').insertOne({
'auth': {
'username': 'admin',
'password': crypto.createHash('md5').update(password).digest("hex")
},
'about': {
'name': 'ADMIN',
'phone': '+000.000000000',
'nif': '000000000'
},
'address': {
'street': 'Constancia',
'city': 'Constancia',
'country': 'Portugal',
'zip': '0000-00'
},
'details': {
'created': '',
'lastlogin': '',
'lastip': ''
},
'maxresources': {
'memory': '',
'storage': '',
'cpu': ''
},
'type': 'admin',
'status': 'active'
}, function(err, result) {
console.log("User Inserted into DB");
callback(result);
});
};
MongoClient.connect(config.mongodb || process.env.CLOUDASH_MONGODB, function(err, db) {
insertUser(db, function() {
db.close();
console.log('Installation finished.');
console.log('Login with username: admin and password: ' + password + ' at ' + config.url);
});
});