mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-01 03:26:04 +01:00
install script + patching up integration with install wizard
This commit is contained in:
163
app.js
163
app.js
@@ -1,54 +1,131 @@
|
||||
var categories = require('./src/categories.js'),
|
||||
templates = require('./public/src/templates.js'),
|
||||
webserver = require('./src/webserver.js'),
|
||||
websockets = require('./src/websockets.js'),
|
||||
admin = {
|
||||
'categories': require('./src/admin/categories.js')
|
||||
},
|
||||
fs = require('fs');
|
||||
// Read config.js to grab redis info
|
||||
var fs = require('fs'),
|
||||
path = require('path'),
|
||||
utils = require('./public/src/utils.js');
|
||||
|
||||
DEVELOPMENT = true;
|
||||
console.log('Info: Checking for valid base configuration file');
|
||||
fs.readFile(path.join(__dirname, 'config.json'), function(err, data) {
|
||||
if (!err) {
|
||||
global.config = JSON.parse(data);
|
||||
global.config.url = global.config.base_url + (global.config.use_port ? ':' + global.config.port : '') + '/';
|
||||
global.config.upload_url = global.config.url + 'uploads/';
|
||||
console.log('Info: Base Configuration OK.');
|
||||
|
||||
global.configuration = {};
|
||||
global.templates = {};
|
||||
var meta = require('./src/meta.js');
|
||||
meta.config.get(function(config) {
|
||||
for(c in config) {
|
||||
if (config.hasOwnProperty(c)) {
|
||||
global.config[c] = config[c];
|
||||
}
|
||||
}
|
||||
|
||||
(function(config) {
|
||||
config['ROOT_DIRECTORY'] = __dirname;
|
||||
var categories = require('./src/categories.js'),
|
||||
templates = require('./public/src/templates.js'),
|
||||
webserver = require('./src/webserver.js'),
|
||||
websockets = require('./src/websockets.js'),
|
||||
admin = {
|
||||
'categories': require('./src/admin/categories.js')
|
||||
};
|
||||
|
||||
templates.init([
|
||||
'header', 'footer', 'logout', 'admin/header', 'admin/footer', 'admin/index',
|
||||
'emails/reset', 'emails/reset_plaintext', 'emails/email_confirm', 'emails/email_confirm_plaintext',
|
||||
'emails/header', 'emails/footer', 'install/header', 'install/footer', 'install/redis'
|
||||
]);
|
||||
|
||||
templates.ready(function() {
|
||||
webserver.init();
|
||||
});
|
||||
DEVELOPMENT = true;
|
||||
|
||||
//setup scripts to be moved outside of the app in future.
|
||||
function setup_categories() {
|
||||
console.log('Checking categories...');
|
||||
categories.getAllCategories(function(data) {
|
||||
if (data.categories.length === 0) {
|
||||
console.log('Setting up default categories...');
|
||||
global.configuration = {};
|
||||
global.templates = {};
|
||||
|
||||
fs.readFile(config.ROOT_DIRECTORY + '/install/data/categories.json', function(err, default_categories) {
|
||||
default_categories = JSON.parse(default_categories);
|
||||
|
||||
for (var category in default_categories) {
|
||||
admin.categories.create(default_categories[category]);
|
||||
}
|
||||
});
|
||||
(function(config) {
|
||||
config['ROOT_DIRECTORY'] = __dirname;
|
||||
|
||||
} else {
|
||||
console.log('Good.');
|
||||
}
|
||||
});
|
||||
}
|
||||
templates.init([
|
||||
'header', 'footer', 'logout', 'admin/header', 'admin/footer', 'admin/index',
|
||||
'emails/reset', 'emails/reset_plaintext', 'emails/email_confirm', 'emails/email_confirm_plaintext',
|
||||
'emails/header', 'emails/footer', 'install/header', 'install/footer', 'install/redis'
|
||||
]);
|
||||
|
||||
templates.ready(function() {
|
||||
webserver.init();
|
||||
});
|
||||
|
||||
setup_categories();
|
||||
//setup scripts to be moved outside of the app in future.
|
||||
function setup_categories() {
|
||||
console.log('Info: Checking categories...');
|
||||
categories.getAllCategories(function(data) {
|
||||
if (data.categories.length === 0) {
|
||||
console.log('Info: Setting up default categories...');
|
||||
|
||||
|
||||
fs.readFile(config.ROOT_DIRECTORY + '/install/data/categories.json', function(err, default_categories) {
|
||||
default_categories = JSON.parse(default_categories);
|
||||
|
||||
}(global.configuration));
|
||||
for (var category in default_categories) {
|
||||
admin.categories.create(default_categories[category]);
|
||||
}
|
||||
});
|
||||
|
||||
} else {
|
||||
console.log('Info: Good.');
|
||||
}
|
||||
});
|
||||
}
|
||||
setup_categories();
|
||||
}(global.configuration));
|
||||
});
|
||||
} else {
|
||||
// New install, ask setup questions
|
||||
console.log('Info: Configuration not found, starting NodeBB setup');
|
||||
var ask = function(question, callback) {
|
||||
process.stdin.resume();
|
||||
process.stdout.write(question + ': ');
|
||||
|
||||
process.stdin.once('data', function(data) {
|
||||
callback(data.toString().trim());
|
||||
});
|
||||
}
|
||||
|
||||
process.stdout.write(
|
||||
"\nWelcome to NodeBB!\nThis looks like a new installation, so you'll have to answer a " +
|
||||
"few questions about your environment before we can proceed with the setup.\n\n\nWhat is...\n\n"
|
||||
);
|
||||
|
||||
ask('... the publically accessible URL of this installation? (http://localhost)', function(base_url) {
|
||||
ask('... the port number of your install? (4567)', function(port) {
|
||||
ask('Will you be using a port number to access NodeBB? (y)', function(use_port) {
|
||||
ask('... the host IP or address of your Redis instance? (127.0.0.1)', function(redis_host) {
|
||||
ask('... the host port of your Redis instance? (6379)', function(redis_port) {
|
||||
ask('... your NodeBB secret? (keyboard mash for a bit here)', function(secret) {
|
||||
if (!base_url) base_url = 'http://localhost';
|
||||
if (!port) port = 4567;
|
||||
if (!use_port) use_port = true; else use_port = (use_port === 'y' ? true : false);
|
||||
if (!redis_host) redis_host = '127.0.0.1';
|
||||
if (!redis_port) redis_port = 6379;
|
||||
if (!secret) secret = utils.generateUUID();
|
||||
|
||||
var fs = require('fs'),
|
||||
path = require('path'),
|
||||
config = {
|
||||
secret: secret,
|
||||
base_url: base_url,
|
||||
port: port,
|
||||
use_port: use_port,
|
||||
redis: {
|
||||
host: redis_host,
|
||||
port: redis_port
|
||||
}
|
||||
}
|
||||
|
||||
fs.writeFile(path.join(__dirname, 'config.json'), JSON.stringify(config, null, 4), function(err) {
|
||||
if (err) throw err;
|
||||
else {
|
||||
process.stdout.write(
|
||||
"\n\nConfiguration Saved OK\n\nPlease start NodeBB again and navigate to " +
|
||||
base_url + (use_port ? ':' + port : '') + "/install to continue setup.\n\n"
|
||||
);
|
||||
process.exit();
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
@@ -10,9 +10,7 @@
|
||||
"admin/twitter[^]*": "admin/twitter",
|
||||
"admin/facebook[^]*": "admin/facebook",
|
||||
"admin/gplus[^]*": "admin/gplus",
|
||||
"install/?$": "install/redis",
|
||||
"install/basic/?": "install/basic",
|
||||
"install/redis/?": "install/redis",
|
||||
"install/?$": "install/mail",
|
||||
"install/mail/?": "install/mail",
|
||||
"install/social/?": "install/social",
|
||||
"install/privileges/?": "install/privileges",
|
||||
|
||||
@@ -5,17 +5,26 @@
|
||||
config: undefined,
|
||||
prepare: function() {
|
||||
// Bounce if config is not ready
|
||||
if (nodebb_setup.config === undefined) {
|
||||
ajaxify.go('install/redis');
|
||||
app.alert({
|
||||
alert_id: 'config-ready',
|
||||
type: 'error',
|
||||
timeout: 10000,
|
||||
title: 'NodeBB Configuration Not Ready!',
|
||||
message: 'NodeBB cannot proceed with setup at this time as Redis database information ' +
|
||||
'was not found. Please enter the information below.'
|
||||
});
|
||||
// if (nodebb_setup.config === undefined) {
|
||||
// ajaxify.go('install/redis');
|
||||
// app.alert({
|
||||
// alert_id: 'config-ready',
|
||||
// type: 'error',
|
||||
// timeout: 10000,
|
||||
// title: 'NodeBB Configuration Not Ready!',
|
||||
// message: 'NodeBB cannot proceed with setup at this time as Redis database information ' +
|
||||
// 'was not found. Please enter the information below.'
|
||||
// });
|
||||
|
||||
// return;
|
||||
// }
|
||||
|
||||
// Come back in 500ms if the config isn't ready yet
|
||||
if (nodebb_setup.config === undefined) {
|
||||
console.log('Config not ready...');
|
||||
setTimeout(function() {
|
||||
nodebb_setup.prepare();
|
||||
}, 500);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -106,6 +115,11 @@
|
||||
}
|
||||
}, false);
|
||||
|
||||
socket.emit('api:config.get');
|
||||
socket.on('api:config.get', function(data) {
|
||||
nodebb_setup.config = data;
|
||||
});
|
||||
|
||||
socket.on('api:config.set', function(data) {
|
||||
if (data.status === 'ok') {
|
||||
app.alert({
|
||||
|
||||
@@ -33,12 +33,6 @@
|
||||
</button>
|
||||
<div class="nav-collapse collapse">
|
||||
<ul class="nav nodebb-inline-block">
|
||||
<li>
|
||||
<a data-tab="redis" href="/install/redis"><i class="icon-hdd"></i> Redis</a>
|
||||
</li>
|
||||
<li>
|
||||
<a data-tab="basic" href="/install/basic"><i class="icon-cog"></i> Basic</a>
|
||||
</li>
|
||||
<li>
|
||||
<a data-tab="email" href="/install/email"><i class="icon-envelope"></i> Mail</a>
|
||||
</li>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
|
||||
<h1>Step 3 – Mailer Information</h1>
|
||||
<h1>Mailer Information</h1>
|
||||
|
||||
<form class="form-inline">
|
||||
<p>
|
||||
@@ -25,9 +25,6 @@
|
||||
<div class="pull-right">
|
||||
<button data-path="social" class="btn btn-primary btn-large">Next – <i class="icon-facebook"></i> Social</button>
|
||||
</div>
|
||||
<div>
|
||||
<button data-path="basic" class="btn btn-primary btn-large">Previous – <i class="icon-cog"></i> Basic</button>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
(function() {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
|
||||
<h1>Step 5 – User Privilege Thresholds</h1>
|
||||
<h1>User Privilege Thresholds</h1>
|
||||
|
||||
<form class="form-inline">
|
||||
<p>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
|
||||
<h1>Step 4 – Social Media Logins (Optional)</h1>
|
||||
<h1>Social Media Logins</h1>
|
||||
|
||||
<form class="form-inline">
|
||||
<p>
|
||||
@@ -9,26 +9,26 @@
|
||||
|
||||
<h3>Facebook</h3>
|
||||
<p>
|
||||
<label>Application ID</label> <input type="text" class="input-medium" data-field="social/facebook/app_id" />
|
||||
<label>Application ID</label> <input type="text" class="input-medium" data-field="social:facebook:app_id" />
|
||||
</p>
|
||||
<p>
|
||||
<label>Application Secret</label> <input type="text" class="input-large" data-field="social/facebook/secret" />
|
||||
<label>Application Secret</label> <input type="text" class="input-large" data-field="social:facebook:secret" />
|
||||
</p>
|
||||
|
||||
<h3>Twitter</h3>
|
||||
<p>
|
||||
<label>Application Key</label> <input type="text" class="input-medium" data-field="social/twitter/key" />
|
||||
<label>Application Key</label> <input type="text" class="input-medium" data-field="social:twitter:key" />
|
||||
</p>
|
||||
<p>
|
||||
<label>Application Secret</label> <input type="text" class="input-large" data-field="social/twitter/secret" />
|
||||
<label>Application Secret</label> <input type="text" class="input-large" data-field="social:twitter:secret" />
|
||||
</p>
|
||||
|
||||
<h3>Google</h3>
|
||||
<p>
|
||||
<label>Application Key</label> <input type="text" class="input-xxlarge" data-field="social/google/key" />
|
||||
<label>Application ID</label> <input type="text" class="input-xxlarge" data-field="social:google:id" />
|
||||
</p>
|
||||
<p>
|
||||
<label>Application Secret</label> <input type="text" class="input-large" data-field="social/google/secret" />
|
||||
<label>Application Secret</label> <input type="text" class="input-large" data-field="social:google:secret" />
|
||||
</p>
|
||||
</form>
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
var config = require('../config.js'),
|
||||
utils = require('./../public/src/utils.js'),
|
||||
var utils = require('./../public/src/utils.js'),
|
||||
RDB = require('./redis.js'),
|
||||
async = require('async');
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
var config = require('../config.js'),
|
||||
RDB = require('./redis.js'),
|
||||
var RDB = require('./redis.js'),
|
||||
async = require('async'),
|
||||
utils = require('../public/src/utils.js');
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@ var RDB = require('./redis.js'),
|
||||
posts = require('./posts.js'),
|
||||
threadTools = require('./threadTools.js'),
|
||||
user = require('./user.js'),
|
||||
config = require('../config.js'),
|
||||
async = require('async'),
|
||||
marked = require('marked');
|
||||
|
||||
@@ -35,8 +34,8 @@ marked.setOptions({
|
||||
// DRY fail in threadTools.
|
||||
|
||||
user.getUserField(uid, 'reputation', function(reputation) {
|
||||
next(null, reputation >= config.privilege_thresholds.manage_content);
|
||||
});
|
||||
next(null, reputation >= global.config['privileges:manage_content']);
|
||||
});
|
||||
}
|
||||
|
||||
async.parallel([getThreadPrivileges, isOwnPost, hasEnoughRep], function(err, results) {
|
||||
|
||||
@@ -4,7 +4,6 @@ var RDB = require('./redis.js'),
|
||||
user = require('./user.js'),
|
||||
topics = require('./topics.js'),
|
||||
favourites = require('./favourites.js'),
|
||||
config = require('../config.js'),
|
||||
threadTools = require('./threadTools.js'),
|
||||
async = require('async');
|
||||
|
||||
|
||||
@@ -3,11 +3,9 @@
|
||||
ERROR_LOGS = true,
|
||||
|
||||
redis = require('redis'),
|
||||
config = require('../config.js'),
|
||||
utils = require('./../public/src/utils.js');
|
||||
|
||||
|
||||
RedisDB.exports = redis.createClient(config.redis.port, config.redis.host, config.redis.options);
|
||||
RedisDB.exports = redis.createClient(global.config.redis.port, global.config.redis.host);
|
||||
|
||||
RedisDB.exports.handle = function(error) {
|
||||
if (error !== null) {
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
(function(Auth) {
|
||||
|
||||
var passport = require('passport'),
|
||||
passportLocal = require('passport-local').Strategy,
|
||||
passportTwitter = require('passport-twitter').Strategy,
|
||||
@@ -7,11 +6,7 @@
|
||||
passportFacebook = require('passport-facebook').Strategy,
|
||||
login_strategies = [],
|
||||
|
||||
user_module = require('./../user.js'),
|
||||
config = require('./../../config.js');
|
||||
|
||||
|
||||
|
||||
user_module = require('./../user.js');
|
||||
|
||||
passport.use(new passportLocal(function(user, password, next) {
|
||||
user_module.loginViaLocal(user, password, function(login) {
|
||||
@@ -20,10 +15,10 @@
|
||||
});
|
||||
}));
|
||||
|
||||
if (config.twitter && config.twitter.key && config.twitter.key.length > 0 && config.twitter.secret.length > 0) {
|
||||
if (global.config['social:twitter:key'] && global.config['social:twitter:secret']) {
|
||||
passport.use(new passportTwitter({
|
||||
consumerKey: config.twitter.key,
|
||||
consumerSecret: config.twitter.secret,
|
||||
consumerKey: global.config['social:twitter:key'],
|
||||
consumerSecret: global.config['social:twitter:secret'],
|
||||
callbackURL: config.url + 'auth/twitter/callback'
|
||||
}, function(token, tokenSecret, profile, done) {
|
||||
user_module.loginViaTwitter(profile.id, profile.username, function(err, user) {
|
||||
@@ -35,10 +30,10 @@
|
||||
login_strategies.push('twitter');
|
||||
}
|
||||
|
||||
if (config.google && config.google.id.length > 0 && config.google.secret.length > 0) {
|
||||
if (global.config['social:google:id'] && global.config['social:google:secret']) {
|
||||
passport.use(new passportGoogle({
|
||||
clientID: config.google.id,
|
||||
clientSecret: config.google.secret,
|
||||
clientID: global.config['social:google:id'],
|
||||
clientSecret: global.config['social:google:secret'],
|
||||
callbackURL: config.url + 'auth/google/callback'
|
||||
}, function(accessToken, refreshToken, profile, done) {
|
||||
user_module.loginViaGoogle(profile.id, profile.displayName, profile.emails[0].value, function(err, user) {
|
||||
@@ -50,10 +45,10 @@
|
||||
login_strategies.push('google');
|
||||
}
|
||||
|
||||
if (config.facebook && config.facebook.app_id.length > 0 && config.facebook.secret.length > 0) {
|
||||
if (global.config['social:facebook:app_id'] && global.config['social:facebook:secret']) {
|
||||
passport.use(new passportFacebook({
|
||||
clientID: config.facebook.app_id,
|
||||
clientSecret: config.facebook.secret,
|
||||
clientID: global.config['social:facebook:app_id'],
|
||||
clientSecret: global.config['social:facebook:secret'],
|
||||
callbackURL: config.url + 'auth/facebook/callback'
|
||||
}, function(accessToken, refreshToken, profile, done) {
|
||||
user_module.loginViaFacebook(profile.id, profile.displayName, profile.emails[0].value, function(err, user) {
|
||||
|
||||
@@ -1,12 +1,9 @@
|
||||
|
||||
|
||||
var user = require('./../user.js'),
|
||||
fs = require('fs'),
|
||||
utils = require('./../../public/src/utils.js'),
|
||||
config = require('../../config.js'),
|
||||
marked = require('marked');
|
||||
|
||||
|
||||
(function(User) {
|
||||
User.create_routes = function(app) {
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@ var RDB = require('./redis.js'),
|
||||
topics = require('./topics.js'),
|
||||
categories = require('./categories.js'),
|
||||
user = require('./user.js'),
|
||||
config = require('../config.js'),
|
||||
async = require('async');
|
||||
|
||||
|
||||
@@ -23,7 +22,7 @@ var RDB = require('./redis.js'),
|
||||
// DRY fail in postTools
|
||||
|
||||
user.getUserField(uid, 'reputation', function(reputation) {
|
||||
next(null, reputation >= config.privilege_thresholds.manage_thread);
|
||||
next(null, reputation >= global.config['privileges:manage_topic']);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@ var RDB = require('./redis.js')
|
||||
posts = require('./posts.js'),
|
||||
utils = require('./../public/src/utils.js'),
|
||||
user = require('./user.js'),
|
||||
config = require('../config.js'),
|
||||
categories = require('./categories.js'),
|
||||
posts = require('./posts.js'),
|
||||
marked = require('marked'),
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
var config = require('../config.js'),
|
||||
utils = require('./../public/src/utils.js'),
|
||||
var utils = require('./../public/src/utils.js'),
|
||||
RDB = require('./redis.js'),
|
||||
crypto = require('crypto'),
|
||||
emailjs = require('emailjs'),
|
||||
|
||||
@@ -3,9 +3,8 @@ var express = require('express'),
|
||||
server = require('http').createServer(WebServer),
|
||||
RedisStore = require('connect-redis')(express),
|
||||
path = require('path'),
|
||||
config = require('../config.js'),
|
||||
redis = require('redis'),
|
||||
redisServer = redis.createClient(config.redis.port, config.redis.host, config.redis.options),
|
||||
redisServer = redis.createClient(global.config.redis.port, global.config.redis.host),
|
||||
marked = require('marked'),
|
||||
utils = require('../public/src/utils.js'),
|
||||
fs = require('fs'),
|
||||
@@ -36,7 +35,7 @@ var express = require('express'),
|
||||
client: redisServer,
|
||||
ttl: 60*60*24*14
|
||||
}),
|
||||
secret: config.secret,
|
||||
secret: global.config.secret,
|
||||
key: 'express.sid'
|
||||
}));
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
var SocketIO = require('socket.io').listen(global.server, { log:false }),
|
||||
cookie = require('cookie'),
|
||||
connect = require('connect'),
|
||||
config = require('../config.js'),
|
||||
user = require('./user.js'),
|
||||
posts = require('./posts.js'),
|
||||
favourites = require('./favourites.js'),
|
||||
@@ -26,7 +25,7 @@ var SocketIO = require('socket.io').listen(global.server, { log:false }),
|
||||
io.set('authorization', function(handshakeData, accept) {
|
||||
if (handshakeData.headers.cookie) {
|
||||
handshakeData.cookie = cookie.parse(handshakeData.headers.cookie);
|
||||
handshakeData.sessionID = connect.utils.parseSignedCookie(handshakeData.cookie['express.sid'], config.secret);
|
||||
handshakeData.sessionID = connect.utils.parseSignedCookie(handshakeData.cookie['express.sid'], global.config.secret);
|
||||
|
||||
if (handshakeData.cookie['express.sid'] == handshakeData.sessionID) {
|
||||
return accept('Cookie is invalid.', false);
|
||||
@@ -302,18 +301,9 @@ var SocketIO = require('socket.io').listen(global.server, { log:false }),
|
||||
});
|
||||
});
|
||||
|
||||
socket.on('api:config.setup', function(data) {
|
||||
async.parallel([
|
||||
function(next) {
|
||||
meta.config.set('redis/host', data['redis/host'], next);
|
||||
},
|
||||
function(next) {
|
||||
meta.config.set('redis/port', data['redis/port'], next);
|
||||
}
|
||||
], function(err) {
|
||||
meta.config.get(function(config) {
|
||||
socket.emit('api:config.setup', config);
|
||||
});
|
||||
socket.on('api:config.get', function(data) {
|
||||
meta.config.get(function(config) {
|
||||
socket.emit('api:config.get', config);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user