Skip to content

Node.js based forum software built for the modern web

installation wizard under /install

Julian Lam65b6010d74a0
diff --git a/app.js b/app.js
index 56b95a1cee..4005af1aa1 100644
--- a/app.js
+++ b/app.js
@@ -18,7 +18,7 @@ global.templates = {};
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/basic'
+ 'emails/header', 'emails/footer', 'install/header', 'install/footer', 'install/redis'
]);
templates.ready(function() {
diff --git a/public/templates/config.json b/public/templates/config.json
index 04aa514a26..5af89957fb 100644
--- a/public/templates/config.json
+++ b/public/templates/config.json
@@ -1,25 +1,29 @@
{
- "custom_mapping": {
- "admin/topics[^]*": "admin/topics",
- "admin/categories[^]*": "admin/categories",
- "admin/users[^]*": "admin/users",
- "admin/redis[^]*": "admin/redis",
- "admin/index[^]*": "admin/index",
- "admin/themes[^]*": "admin/themes",
- "admin/settings[^]*": "admin/settings",
- "admin/twitter[^]*": "admin/twitter",
- "admin/facebook[^]*": "admin/facebook",
- "admin/gplus[^]*": "admin/gplus",
- "install/?$": "install/basic",
- "install/basic/?$": "install/basic",
- "users[^]*edit": "accountedit",
- "users[^]*friends": "friends",
- "users/[^]*": "account",
- "latest": "category",
- "popular": "category",
- "active": "category"
- },
- "force_refresh": {
- "logout": true
- }
+ "custom_mapping": {
+ "admin/topics[^]*": "admin/topics",
+ "admin/categories[^]*": "admin/categories",
+ "admin/users[^]*": "admin/users",
+ "admin/redis[^]*": "admin/redis",
+ "admin/index[^]*": "admin/index",
+ "admin/themes[^]*": "admin/themes",
+ "admin/settings[^]*": "admin/settings",
+ "admin/twitter[^]*": "admin/twitter",
+ "admin/facebook[^]*": "admin/facebook",
+ "admin/gplus[^]*": "admin/gplus",
+ "install/?$": "install/redis",
+ "install/basic/?": "install/basic",
+ "install/redis/?": "install/redis",
+ "install/mail/?": "install/mail",
+ "install/social/?": "install/social",
+ "install/privileges/?": "install/privileges",
+ "users[^]*edit": "accountedit",
+ "users[^]*friends": "friends",
+ "users/[^]*": "account",
+ "latest": "category",
+ "popular": "category",
+ "active": "category"
+ },
+ "force_refresh": {
+ "logout": true
+ }
}
\ No newline at end of file
diff --git a/public/templates/install/basic.tpl b/public/templates/install/basic.tpl
index 9ab273509e..5a656fc21d 100644
--- a/public/templates/install/basic.tpl
+++ b/public/templates/install/basic.tpl
@@ -1,28 +1,51 @@
-<h1>Step 1 &ndash; Basic Information</h1>
+<h1>Step 2 &ndash; Basic Information</h1>
-<p class="lead">
- Thanks for choosing to install NodeBB! We&apos;ll need some information to set up your installation
- configuration...
-</p>
-
-<h3>Path Information</h3>
-<p>
- Please enter the web-accessible url that will be used to point to the NodeBB installation. If you are using a port number in the address,
- <strong>include it in the field below, not here</strong>
- <input type="text" class="input-large" data-field="base_url" placeholder="http://www.example.org" />
-</p>
+<form class="form-inline">
+ <h3>Path Information</h3>
+ <p>
+ Please enter the web-accessible url that will be used to point to the NodeBB installation. If you are using a port number in the address,
+ <strong>include it in the field below, not here</strong>. Do not include a trailing slash.<br />
+ <input type="text" class="input-large" data-field="base_url" placeholder="http://www.example.org" />
+ </p>
-<p>
- <label class="checkbox"><input type="checkbox" data-field="use_port" /> Use port</label>
-</p>
+ <p>
+ <label class="checkbox"><input type="checkbox" data-field="use_port" checked /> Use port</label>
+ </p>
+ <p>
+ <label>Port</label> <input type="number" class="input-mini" data-field="port" value="4567" placeholder="4567" />
+ </p>
-<form class="form-inline">
- <label>Port</label> <input type="text" data-field="port" />
+ <p>
+ Path to uploads folder (relative to the root of the NodeBB install)<br />
+ <input type="text" class="input-large" data-field="upload_url" value="/public/uploads" placeholder="/public/uploads" />
+ </p>
</form>
<h3>NodeBB Secret</h3>
<p>
This "secret" is used to encode user sessions, so they are not stored in plaintext. Enter a bunch of random characters below:
</p>
-<input type="text" class="input-xxlarge" data-field="secret" placeholder="n239he#dh9j9$jc4h%y4yuhnx9y(&#y9ryn9c3" />
\ No newline at end of file
+<input type="text" class="input-xxlarge" data-field="secret" placeholder="n239he#dh9j9$jc4h%y4yuhnx9y(&#y9ryn9c3" />
+
+<hr />
+<div class="pull-right">
+ <button data-path="mail" class="btn btn-primary btn-large">Next &ndash; <i class="icon-envelope"></i> Mail</button>
+</div>
+<div>
+ <button data-path="redis" class="btn btn-primary btn-large">Previous &ndash; <i class="icon-hdd"></i> Redis</button>
+</div>
+
+<script>
+ (function() {
+ nodebb_setup.prepare();
+
+ var portToggle = document.querySelector('input[data-field="use_port"]'),
+ portEl = document.querySelector('input[data-field="port"]');
+
+ portToggle.addEventListener('change', function(e) {
+ if (e.target.checked) portEl.disabled = false;
+ else portEl.disabled = true;
+ });
+ })();
+</script>
\ No newline at end of file
diff --git a/public/templates/install/footer.tpl b/public/templates/install/footer.tpl
index 9c25607790..9823d43371 100644
--- a/public/templates/install/footer.tpl
+++ b/public/templates/install/footer.tpl
@@ -1,3 +1,130 @@
</div>
+ <script>
+ var nodebb_setup = {
+ 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.'
+ });
+
+ return;
+ }
+
+ // Populate the fields on the page from the config
+ var fields = document.querySelectorAll('#content [data-field]'),
+ numFields = fields.length,
+ x, key, inputType;
+ for(x=0;x<numFields;x++) {
+ key = fields[x].getAttribute('data-field');
+ inputType = fields[x].getAttribute('type');
+ if (nodebb_setup.config[key]) {
+ switch(inputType) {
+ case 'text':
+ case 'textarea':
+ case 'number':
+ fields[x].value = nodebb_setup.config[key];
+ break;
+
+ case 'checkbox':
+ fields[x].checked = nodebb_setup.config[key] ? true : false;
+ break;
+ }
+ } else {
+ // Save defaults, if they're not found in the config
+ var defaultFields = [
+ 'use_port', 'port', 'upload_url', 'mailer:host',
+ 'mailer:port', 'privileges:manage_content',
+ 'privileges:manage_topic'
+ ],
+ defaultVal;
+ if (defaultFields.indexOf(key) !== -1) {
+ console.log('saving default value: ', key);
+ switch(inputType) {
+ case 'text':
+ case 'textarea':
+ case 'number':
+ defaultVal = fields[x].value;
+ break;
+
+ case 'checkbox':
+ defaultVal = fields[x].checked ? '1' : '0';
+ break;
+ }
+ socket.emit('api:config.set', {
+ key: key,
+ value: defaultVal
+ });
+ nodebb_setup.config[key] = defaultVal;
+ }
+ }
+ }
+ }
+ };
+
+ (function() {
+ // Listen for field changes and auto-save on change
+ var contentEl = document.getElementById('content');
+
+ contentEl.addEventListener('change', function(e) {
+ if (e.target.hasAttribute('data-field')) {
+ var key = e.target.getAttribute('data-field'),
+ value;
+
+ switch(e.target.getAttribute('type')) {
+ case 'text':
+ case 'textarea':
+ case 'number':
+ value = e.target.value;
+ break;
+ case 'checkbox':
+ value = e.target.checked ? 1 : 0;
+ break;
+
+ default:
+ return false;
+ break;
+ }
+
+ socket.emit('api:config.set', { key: key, value: value });
+ nodebb_setup.config[key] = value;
+ }
+ }, false);
+ contentEl.addEventListener('click', function(e) {
+ if (e.target.hasAttribute('data-path')) {
+ var href = 'install/' + e.target.getAttribute('data-path');
+ console.log(href);
+ if (!e.target.disabled) ajaxify.go(href);
+ }
+ }, false);
+
+ socket.on('api:config.set', function(data) {
+ if (data.status === 'ok') {
+ app.alert({
+ alert_id: 'config_status',
+ timeout: 2500,
+ title: 'Configuration Saved',
+ message: 'Your changes to the NodeBB configuration have been saved',
+ type: 'success'
+ });
+ } else {
+ app.alert({
+ alert_id: 'config_status',
+ timeout: 2500,
+ title: 'Configuration Not Saved',
+ message: 'NodeBB encountered a problem saving your changes',
+ type: 'error'
+ });
+ }
+ });
+ })();
+ </script>
</body>
\ No newline at end of file
diff --git a/public/templates/install/header.tpl b/public/templates/install/header.tpl
index 535efe3092..d598b0bb06 100644
--- a/public/templates/install/header.tpl
+++ b/public/templates/install/header.tpl
@@ -25,7 +25,7 @@
<div class="navbar navbar-inverse navbar-fixed-top">
<div class="navbar-inner">
<div class="container">
- <a class="brand" href="/">NodeBB Installation</a>
+ <a class="brand" href="/install">NodeBB Installation</a>
<button type="button" class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
@@ -34,12 +34,25 @@
<div class="nav-collapse collapse">
<ul class="nav nodebb-inline-block">
<li>
- <a data-tab="basic" href="#"><i class="icon-cog"></i> Basic</a>
+ <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>
+ <li>
+ <a data-tab="social" href="/install/social"><i class="icon-facebook"></i> Social</a>
+ </li>
+ <li>
+ <a data-tab="privileges" href="/install/privileges"><i class="icon-legal"></i> Privileges</a>
</li>
</ul>
</div>
</div>
</div>
</div>
+ <div id="alert_window"></div>
<div class="container" id="content">
\ No newline at end of file
diff --git a/public/templates/install/mail.tpl b/public/templates/install/mail.tpl
new file mode 100644
index 0000000000..42ba612a18
--- /dev/null
+++ b/public/templates/install/mail.tpl
@@ -0,0 +1,36 @@
+
+<h1>Step 3 &ndash; Mailer Information</h1>
+
+<form class="form-inline">
+ <p>
+ The mailer information is used when sending out registration confirmation emails to new users.
+ It is also used to send password reset emails to users who have forgotten their password.
+ </p>
+ <p>
+ The defaults here correspond to a local <code>sendmail</code> server, although any third-party
+ mail server can be used.
+ </p>
+ <p>
+ <label>Hostname</label> <input type="text" class="input-medium" data-field="mailer:host" value="127.0.0.1" placeholder="127.0.0.1" />
+ </p>
+ <p>
+ <label>Port</label> <input type="number" class="input-mini" data-field="mailer:port" value="25" placeholder="25" />
+ </p>
+ <p>
+ <label>From</label> <input type="text" class="input-large" data-field="mailer:from" placeholder="John Smith <[email protected]>" />
+ </p>
+</form>
+
+<hr />
+<div class="pull-right">
+ <button data-path="social" class="btn btn-primary btn-large">Next &ndash; <i class="icon-facebook"></i> Social</button>
+</div>
+<div>
+ <button data-path="basic" class="btn btn-primary btn-large">Previous &ndash; <i class="icon-cog"></i> Basic</button>
+</div>
+
+<script>
+ (function() {
+ nodebb_setup.prepare();
+ })();
+</script>
\ No newline at end of file
diff --git a/public/templates/install/privileges.tpl b/public/templates/install/privileges.tpl
new file mode 100644
index 0000000000..466febc9c5
--- /dev/null
+++ b/public/templates/install/privileges.tpl
@@ -0,0 +1,40 @@
+
+<h1>Step 5 &ndash; User Privilege Thresholds</h1>
+
+<form class="form-inline">
+ <p>
+ Privilege thresholds grants a community membership the ability to moderate itself.
+ These numbers denote the minimum amount of user reputation required before the
+ corresponding privilege is unlocked.
+ </p>
+ <p>
+ Reputation is gained when other users favourite posts that you have made.
+ </p>
+
+ <p>
+ <label>Manage Content</label> <input type="number" class="input-mini" value="1000" placeholder="1000" data-field="privileges:manage_content" />
+ </p>
+ <p>
+ Users with reach the "Manage Content" threshold are able to edit/delete other users' posts.
+ </p>
+ <p>
+ <label>Manage Topics</label> <input type="number" class="input-mini" value="2000" placeholder="2000" data-field="privileges:manage_topic" />
+ </p>
+ <p>
+ Users with reach the "Manage Topics" threshold are able to edit, lock, pin, close, and delete topics.
+ </p>
+</form>
+
+<hr />
+<div class="pull-right">
+ <a href="/" class="btn btn-success btn-large"><i class="icon-thumbs-up"></i> Start using NodeBB!</a>
+</div>
+<div>
+ <button data-path="social" class="btn btn-primary btn-large">Previous &ndash; <i class="icon-facebook"></i> Social</button>
+</div>
+
+<script>
+ (function() {
+ nodebb_setup.prepare();
+ })();
+</script>
\ No newline at end of file
diff --git a/public/templates/install/redis.tpl b/public/templates/install/redis.tpl
new file mode 100644
index 0000000000..e60954ee89
--- /dev/null
+++ b/public/templates/install/redis.tpl
@@ -0,0 +1,81 @@
+
+<h1>Step 1 &ndash; Establish Redis Connection</h1>
+
+<p class="lead">
+ Thanks for choosing to install NodeBB! We&apos;ll need some information to set up your installation
+ configuration...
+</p>
+<p>
+ Please enter the details of your Redis server here. If redis is hosted on the same
+ server as NodeBB, you can leave the default values as-is.
+</p>
+
+<form class="form-horizontal">
+ <div class="control-group">
+ <label class="control-label" for="redis-hostname">Hostname</label>
+ <div class="controls">
+ <input type="text" id="redis-hostname" class="input-medium" placeholder="127.0.0.1" value="127.0.0.1" />
+ </div>
+ </div>
+ <div class="control-group">
+ <label class="control-label" for="redis-port">Port</label>
+ <div class="controls">
+ <input type="number" id="redis-port" class="input-mini" placeholder="6379" value="6379" />
+ </div>
+ </div>
+ <div class="control-group">
+ <div class="controls">
+ <button class="btn" id="test-redis">Test</button>
+ </div>
+ </div>
+</form>
+
+<hr />
+<div class="pull-right">
+ <button data-path="basic" class="btn btn-primary btn-large" disabled>Next &ndash; <i class="icon-cog"></i> Basic</button>
+</div>
+
+<script>
+ (function() {
+ var testRedisEl = document.getElementById('test-redis');
+ testRedisEl.addEventListener('click', function(e) {
+ e.preventDefault();
+
+ if (e.target.className.indexOf('testing') === -1) {
+ e.target.className += ' testing';
+ e.target.innerHTML = '<i class="icon-spinner icon-spin"></i> Testing';
+ socket.once('api:config.redisTest', function(data) {
+ if (data && data.status === 'ok') {
+ e.target.className = 'btn btn-success testing';
+ e.target.innerHTML = 'Redis Connection Successful!';
+
+ app.alert({
+ type: 'success',
+ timeout: 10000,
+ alert_id: 'config-ready',
+ title: 'Setup Ready!',
+ message: 'NodeBB is ready to continue with the setup process. ' +
+ 'Any changes you make now will be saved automatically'
+ });
+
+ // Grab configs from the db and enable the 'next' button
+ socket.emit('api:config.setup', {
+ 'redis/host': document.getElementById('redis-hostname').value,
+ 'redis/port': document.getElementById('redis-port').value
+ });
+ } else {
+ e.target.className = 'btn btn-danger';
+ e.target.innerHTML = 'Could not connect to Redis, click here to test again';
+ }
+ });
+ socket.emit('api:config.redisTest');
+ }
+ });
+
+ var nextBtn = document.querySelector('button[data-path="basic"]');
+ socket.once('api:config.setup', function(data) {
+ nodebb_setup.config = data;
+ nextBtn.disabled = false;
+ });
+ })();
+</script>
diff --git a/public/templates/install/social.tpl b/public/templates/install/social.tpl
new file mode 100644
index 0000000000..046021dbf5
--- /dev/null
+++ b/public/templates/install/social.tpl
@@ -0,0 +1,47 @@
+
+<h1>Step 4 &ndash; Social Media Logins (Optional)</h1>
+
+<form class="form-inline">
+ <p>
+ You may opt to allow users to register and login in via a social media account, if that
+ social network supports doing so.
+ </p>
+
+ <h3>Facebook</h3>
+ <p>
+ <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" />
+ </p>
+
+ <h3>Twitter</h3>
+ <p>
+ <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" />
+ </p>
+
+ <h3>Google</h3>
+ <p>
+ <label>Application Key</label> <input type="text" class="input-xxlarge" data-field="social/google/key" />
+ </p>
+ <p>
+ <label>Application Secret</label> <input type="text" class="input-large" data-field="social/google/secret" />
+ </p>
+</form>
+
+<hr />
+<div class="pull-right">
+ <button data-path="privileges" class="btn btn-primary btn-large">Next &ndash; <i class="icon-legal"></i> Privileges</button>
+</div>
+<div>
+ <button data-path="mail" class="btn btn-primary btn-large">Previous &ndash; <i class="icon-envelope"></i> Mail</button>
+</div>
+
+<script>
+ (function() {
+ nodebb_setup.prepare();
+ })();
+</script>
\ No newline at end of file
diff --git a/src/meta.js b/src/meta.js
new file mode 100644
index 0000000000..f4fd57edc2
--- /dev/null
+++ b/src/meta.js
@@ -0,0 +1,59 @@
+var config = require('../config.js'),
+ utils = require('./../public/src/utils.js'),
+ RDB = require('./redis.js'),
+ async = require('async');
+
+(function(Meta) {
+ Meta.testRedis = function(callback) {
+ RDB.set('nodebb-redis-test', 'foobar', function(err, res) {
+ if (!err) {
+ RDB.get('nodebb-redis-test', function(err, res) {
+ if (!err && res === 'foobar') {
+ callback(true);
+ } else {
+ callback(false);
+ }
+ });
+ } else {
+ callback(false);
+ }
+ });
+ }
+
+ Meta.config = {
+ get: function(callback) {
+ var config = {};
+
+ async.waterfall([
+ function(next) {
+ RDB.hkeys('config', function(err, keys) {
+ next(err, keys);
+ });
+ },
+ function(keys, next) {
+ async.each(keys, function(key, next) {
+ RDB.hget('config', key, function(err, value) {
+ if (!err) {
+ config[key] = value;
+ }
+
+ next(err);
+ });
+ }, next);
+ }
+ ], function(err) {
+ if (!err) {
+ config.status = 'ok';
+ callback(config);
+ } else callback({
+ status: 'error'
+ });
+ });
+ },
+ set: function(field, value, callback) {
+ RDB.hset('config', field, value, function(err, res) {
+ callback(err);
+ });
+ }
+ }
+}(exports));
\ No newline at end of file
diff --git a/src/routes/install.js b/src/routes/install.js
index e882aa954a..5b352fcd71 100644
--- a/src/routes/install.js
+++ b/src/routes/install.js
@@ -5,7 +5,7 @@ var RDB = require('../redis.js');
Install.create_routes = function(app) {
(function() {
- var routes = ['basic'];
+ var routes = ['basic', 'redis', 'mail', 'social', 'privileges'];
for (var i=0, ii=routes.length; i<ii; i++) {
(function(route) {
@@ -21,7 +21,7 @@ var RDB = require('../redis.js');
res.send(templates['install/header'] + app.create_route('install/basic') + templates['install/footer']);
});
app.get('/install/index', function(req, res) {
- res.send(templates['install/header'] + app.create_route('install/index') + templates['install/footer']);
+ res.send(templates['install/header'] + app.create_route('install/basic') + templates['install/footer']);
});
diff --git a/src/webserver.js b/src/webserver.js
index 111b50b40e..48c3b9fca2 100644
--- a/src/webserver.js
+++ b/src/webserver.js
@@ -18,7 +18,8 @@ var express = require('express'),
admin = require('./routes/admin.js'),
userRoute = require('./routes/user.js'),
installRoute = require('./routes/install.js'),
- auth = require('./routes/authentication.js');
+ auth = require('./routes/authentication.js'),
+ meta = require('./meta.js');
(function(app) {
var templates = null;
@@ -222,13 +223,8 @@ var express = require('express'),
app.get('/api/:method/:id*', api_method);
app.get('/test', function(req, res) {
- // notifications.remove_by_uniqueId('foobar', 1, function(success) {
- // res.send('remove: ' + success);
- // });
- notifications.create('a bunch more text', 5, '/category/2/general-discussion', 'foobar', function(nid) {
- notifications.push(nid, 1, function() {
- res.send('nid: ' + nid)
- });
+ meta.config.get(function(config) {
+ res.send(JSON.stringify(config, null, 4));
});
});
diff --git a/src/websockets.js b/src/websockets.js
index 0a3c15d826..a40f5216b6 100644
--- a/src/websockets.js
+++ b/src/websockets.js
@@ -11,7 +11,9 @@ var SocketIO = require('socket.io').listen(global.server, { log:false }),
categories = require('./categories.js'),
notifications = require('./notifications.js'),
threadTools = require('./threadTools.js'),
- postTools = require('./postTools.js');
+ postTools = require('./postTools.js'),
+ meta = require('./meta.js'),
+ async = require('async');
(function(io) {
var users = {},
@@ -292,6 +294,35 @@ var SocketIO = require('socket.io').listen(global.server, { log:false }),
});
}
});
+
+ socket.on('api:config.redisTest', function() {
+ meta.testRedis(function(success) {
+ socket.emit('api:config.redisTest', {
+ status: success ? 'ok' : 'error'
+ });
+ });
+ });
+
+ 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.set', function(data) {
+ meta.config.set(data.key, data.value, function(err) {
+ if (!err) socket.emit('api:config.set', { status: 'ok' });
+ });
+ });
});
}(SocketIO));