2016-04-20 10:03:55 +00:00
|
|
|
// external modules
|
2017-02-07 13:17:05 +00:00
|
|
|
var fs = require('fs');
|
2016-04-20 10:03:55 +00:00
|
|
|
var path = require('path');
|
|
|
|
|
|
|
|
// configs
|
|
|
|
var env = process.env.NODE_ENV || 'development';
|
|
|
|
var config = require(path.join(__dirname, '..', 'config.json'))[env];
|
|
|
|
var debug = process.env.DEBUG ? (process.env.DEBUG === 'true') : ((typeof config.debug === 'boolean') ? config.debug : (env === 'development'));
|
|
|
|
|
|
|
|
// url
|
2016-10-10 13:16:58 +00:00
|
|
|
var domain = process.env.DOMAIN || process.env.HMD_DOMAIN || config.domain || '';
|
|
|
|
var urlpath = process.env.URL_PATH || process.env.HMD_URL_PATH || config.urlpath || '';
|
|
|
|
var port = process.env.PORT || process.env.HMD_PORT || config.port || 3000;
|
|
|
|
var alloworigin = process.env.HMD_ALLOW_ORIGIN ? process.env.HMD_ALLOW_ORIGIN.split(',') : (config.alloworigin || ['localhost']);
|
2016-04-20 10:03:55 +00:00
|
|
|
|
|
|
|
var usessl = !!config.usessl;
|
2016-10-10 13:16:58 +00:00
|
|
|
var protocolusessl = (usessl === true && typeof process.env.HMD_PROTOCOL_USESSL === 'undefined' && typeof config.protocolusessl === 'undefined')
|
|
|
|
? true : (process.env.HMD_PROTOCOL_USESSL ? (process.env.HMD_PROTOCOL_USESSL === 'true') : !!config.protocolusessl);
|
|
|
|
var urladdport = process.env.HMD_URL_ADDPORT ? (process.env.HMD_URL_ADDPORT === 'true') : !!config.urladdport;
|
2016-04-20 10:03:55 +00:00
|
|
|
|
2016-10-23 14:42:47 +00:00
|
|
|
var usecdn = process.env.HMD_USECDN ? (process.env.HMD_USECDN === 'true') : ((typeof config.usecdn === 'boolean') ? config.usecdn : true);
|
2016-04-20 10:03:55 +00:00
|
|
|
|
2016-12-21 13:36:54 +00:00
|
|
|
var allowanonymous = process.env.HMD_ALLOW_ANONYMOUS ? (process.env.HMD_ALLOW_ANONYMOUS === 'true') : ((typeof config.allowanonymous === 'boolean') ? config.allowanonymous : true);
|
2016-12-15 06:07:12 +00:00
|
|
|
|
2016-12-16 07:38:05 +00:00
|
|
|
var allowfreeurl = process.env.HMD_ALLOW_FREEURL ? (process.env.HMD_ALLOW_FREEURL === 'true') : !!config.allowfreeurl;
|
|
|
|
|
2016-04-20 10:03:55 +00:00
|
|
|
// db
|
2016-12-22 13:20:43 +00:00
|
|
|
var dburl = config.dburl || process.env.HMD_DB_URL || process.env.DATABASE_URL;
|
|
|
|
var db = config.db || {};
|
2016-04-20 10:03:55 +00:00
|
|
|
|
|
|
|
// ssl path
|
2016-04-23 10:58:24 +00:00
|
|
|
var sslkeypath = config.sslkeypath || '';
|
2016-04-20 10:03:55 +00:00
|
|
|
var sslcertpath = config.sslcertpath || '';
|
|
|
|
var sslcapath = config.sslcapath || '';
|
|
|
|
var dhparampath = config.dhparampath || '';
|
|
|
|
|
|
|
|
// other path
|
|
|
|
var tmppath = config.tmppath || './tmp';
|
|
|
|
var defaultnotepath = config.defaultnotepath || './public/default.md';
|
|
|
|
var docspath = config.docspath || './public/docs';
|
|
|
|
var indexpath = config.indexpath || './public/views/index.ejs';
|
|
|
|
var hackmdpath = config.hackmdpath || './public/views/hackmd.ejs';
|
|
|
|
var errorpath = config.errorpath || './public/views/error.ejs';
|
|
|
|
var prettypath = config.prettypath || './public/views/pretty.ejs';
|
2016-05-29 09:54:24 +00:00
|
|
|
var slidepath = config.slidepath || './public/views/slide.ejs';
|
2016-04-20 10:03:55 +00:00
|
|
|
|
|
|
|
// session
|
|
|
|
var sessionname = config.sessionname || 'connect.sid';
|
|
|
|
var sessionsecret = config.sessionsecret || 'secret';
|
|
|
|
var sessionlife = config.sessionlife || 14 * 24 * 60 * 60 * 1000; //14 days
|
|
|
|
|
|
|
|
// static files
|
|
|
|
var staticcachetime = config.staticcachetime || 1 * 24 * 60 * 60 * 1000; // 1 day
|
|
|
|
|
|
|
|
// socket.io
|
2016-10-23 13:42:27 +00:00
|
|
|
var heartbeatinterval = config.heartbeatinterval || 5000;
|
|
|
|
var heartbeattimeout = config.heartbeattimeout || 10000;
|
2016-04-20 10:03:55 +00:00
|
|
|
|
|
|
|
// document
|
|
|
|
var documentmaxlength = config.documentmaxlength || 100000;
|
|
|
|
|
2016-11-14 09:07:07 +00:00
|
|
|
// image upload setting, available options are imgur/s3/filesystem
|
2016-11-17 08:28:02 +00:00
|
|
|
var imageUploadType = process.env.HMD_IMAGE_UPLOAD_TYPE || config.imageUploadType || 'imgur';
|
2016-11-14 09:07:07 +00:00
|
|
|
|
2016-11-16 04:05:24 +00:00
|
|
|
config.s3 = config.s3 || {};
|
2016-11-16 06:44:35 +00:00
|
|
|
var s3 = {
|
2016-11-17 08:28:02 +00:00
|
|
|
accessKeyId: process.env.HMD_S3_ACCESS_KEY_ID || config.s3.accessKeyId,
|
|
|
|
secretAccessKey: process.env.HMD_S3_SECRET_ACCESS_KEY || config.s3.secretAccessKey,
|
|
|
|
region: process.env.HMD_S3_REGION || config.s3.region
|
2016-11-16 06:44:35 +00:00
|
|
|
}
|
2016-11-17 08:28:02 +00:00
|
|
|
var s3bucket = process.env.HMD_S3_BUCKET || config.s3.bucket;
|
2016-11-16 04:05:24 +00:00
|
|
|
|
2016-04-20 10:03:55 +00:00
|
|
|
// auth
|
2016-10-10 13:16:58 +00:00
|
|
|
var facebook = (process.env.HMD_FACEBOOK_CLIENTID && process.env.HMD_FACEBOOK_CLIENTSECRET) ? {
|
|
|
|
clientID: process.env.HMD_FACEBOOK_CLIENTID,
|
|
|
|
clientSecret: process.env.HMD_FACEBOOK_CLIENTSECRET
|
|
|
|
} : config.facebook || false;
|
|
|
|
var twitter = (process.env.HMD_TWITTER_CONSUMERKEY && process.env.HMD_TWITTER_CONSUMERSECRET) ? {
|
|
|
|
consumerKey: process.env.HMD_TWITTER_CONSUMERKEY,
|
|
|
|
consumerSecret: process.env.HMD_TWITTER_CONSUMERSECRET
|
|
|
|
} : config.twitter || false;
|
|
|
|
var github = (process.env.HMD_GITHUB_CLIENTID && process.env.HMD_GITHUB_CLIENTSECRET) ? {
|
|
|
|
clientID: process.env.HMD_GITHUB_CLIENTID,
|
|
|
|
clientSecret: process.env.HMD_GITHUB_CLIENTSECRET
|
|
|
|
} : config.github || false;
|
|
|
|
var gitlab = (process.env.HMD_GITLAB_CLIENTID && process.env.HMD_GITLAB_CLIENTSECRET) ? {
|
|
|
|
baseURL: process.env.HMD_GITLAB_BASEURL,
|
|
|
|
clientID: process.env.HMD_GITLAB_CLIENTID,
|
|
|
|
clientSecret: process.env.HMD_GITLAB_CLIENTSECRET
|
|
|
|
} : config.gitlab || false;
|
|
|
|
var dropbox = (process.env.HMD_DROPBOX_CLIENTID && process.env.HMD_DROPBOX_CLIENTSECRET) ? {
|
|
|
|
clientID: process.env.HMD_DROPBOX_CLIENTID,
|
|
|
|
clientSecret: process.env.HMD_DROPBOX_CLIENTSECRET
|
2017-01-15 03:58:00 +00:00
|
|
|
} : (config.dropbox && config.dropbox.clientID && config.dropbox.clientSecret && config.dropbox) || false;
|
2016-10-10 13:16:58 +00:00
|
|
|
var google = (process.env.HMD_GOOGLE_CLIENTID && process.env.HMD_GOOGLE_CLIENTSECRET) ? {
|
|
|
|
clientID: process.env.HMD_GOOGLE_CLIENTID,
|
|
|
|
clientSecret: process.env.HMD_GOOGLE_CLIENTSECRET
|
2017-01-15 03:58:00 +00:00
|
|
|
} : (config.google && config.google.clientID && config.google.clientSecret && config.google) || false;
|
2016-12-13 21:31:35 +00:00
|
|
|
var ldap = config.ldap || (
|
|
|
|
process.env.HMD_LDAP_URL ||
|
|
|
|
process.env.HMD_LDAP_BINDDN ||
|
|
|
|
process.env.HMD_LDAP_BINDCREDENTIALS ||
|
|
|
|
process.env.HMD_LDAP_TOKENSECRET ||
|
|
|
|
process.env.HMD_LDAP_SEARCHBASE ||
|
|
|
|
process.env.HMD_LDAP_SEARCHFILTER ||
|
2017-01-09 11:49:23 +00:00
|
|
|
process.env.HMD_LDAP_SEARCHATTRIBUTES ||
|
|
|
|
process.env.HMD_LDAP_PROVIDERNAME
|
2016-12-13 21:31:35 +00:00
|
|
|
) || false;
|
|
|
|
if (ldap == true)
|
|
|
|
ldap = {};
|
|
|
|
if (process.env.HMD_LDAP_URL)
|
|
|
|
ldap.url = process.env.HMD_LDAP_URL;
|
|
|
|
if (process.env.HMD_LDAP_BINDDN)
|
|
|
|
ldap.bindDn = process.env.HMD_LDAP_BINDDN;
|
|
|
|
if (process.env.HMD_LDAP_BINDCREDENTIALS)
|
|
|
|
ldap.bindCredentials = process.env.HMD_LDAP_BINDCREDENTIALS;
|
|
|
|
if (process.env.HMD_LDAP_TOKENSECRET)
|
|
|
|
ldap.tokenSecret = process.env.HMD_LDAP_TOKENSECRET;
|
|
|
|
if (process.env.HMD_LDAP_SEARCHBASE)
|
|
|
|
ldap.searchBase = process.env.HMD_LDAP_SEARCHBASE;
|
|
|
|
if (process.env.HMD_LDAP_SEARCHFILTER)
|
|
|
|
ldap.searchFilter = process.env.HMD_LDAP_SEARCHFILTER;
|
|
|
|
if (process.env.HMD_LDAP_SEARCHATTRIBUTES)
|
|
|
|
ldap.searchAttributes = process.env.HMD_LDAP_SEARCHATTRIBUTES;
|
2016-12-14 10:49:33 +00:00
|
|
|
if (process.env.HMD_LDAP_TLS_CA) {
|
|
|
|
var ca = {
|
2017-02-07 13:17:05 +00:00
|
|
|
ca: process.env.HMD_LDAP_TLS_CA.split(',')
|
|
|
|
}
|
|
|
|
ldap.tlsOptions = ldap.tlsOptions ? Object.assign(ldap.tlsOptions, ca) : ca;
|
|
|
|
if (Array.isArray(ldap.tlsOptions.ca) && ldap.tlsOptions.ca.length > 0) {
|
|
|
|
var i, len, results;
|
|
|
|
results = [];
|
|
|
|
for (i = 0, len = ldap.tlsOptions.ca.length; i < len; i++) {
|
|
|
|
results.push(fs.readFileSync(ldap.tlsOptions.ca[i], 'utf8'));
|
|
|
|
}
|
|
|
|
ldap.tlsOptions.ca = results;
|
2016-12-14 10:49:33 +00:00
|
|
|
}
|
2017-01-09 11:49:23 +00:00
|
|
|
}
|
|
|
|
if (process.env.HMD_LDAP_PROVIDERNAME) {
|
|
|
|
ldap.providerName = process.env.HMD_LDAP_PROVIDERNAME;
|
2016-12-14 10:49:33 +00:00
|
|
|
}
|
2016-10-10 13:16:58 +00:00
|
|
|
var imgur = process.env.HMD_IMGUR_CLIENTID || config.imgur || false;
|
2016-12-20 02:47:37 +00:00
|
|
|
var email = process.env.HMD_EMAIL ? (process.env.HMD_EMAIL === 'true') : !!config.email;
|
2017-01-12 15:53:22 +00:00
|
|
|
var allowemailregister = process.env.HMD_ALLOW_EMAIL_REGISTER ? (process.env.HMD_ALLOW_EMAIL_REGISTER === 'true') : ((typeof config.allowemailregister === 'boolean') ? config.allowemailregister : true);
|
2016-04-20 10:03:55 +00:00
|
|
|
|
|
|
|
function getserverurl() {
|
2016-04-21 19:33:24 +00:00
|
|
|
var url = '';
|
|
|
|
if (domain) {
|
|
|
|
var protocol = protocolusessl ? 'https://' : 'http://';
|
|
|
|
url = protocol + domain;
|
|
|
|
if (urladdport && ((usessl && port != 443) || (!usessl && port != 80)))
|
|
|
|
url += ':' + port;
|
|
|
|
}
|
2016-04-20 10:03:55 +00:00
|
|
|
if (urlpath)
|
|
|
|
url += '/' + urlpath;
|
|
|
|
return url;
|
|
|
|
}
|
|
|
|
|
2017-01-02 03:19:01 +00:00
|
|
|
var version = '0.5.0';
|
|
|
|
var minimumCompatibleVersion = '0.5.0';
|
2016-06-17 08:09:33 +00:00
|
|
|
var maintenance = true;
|
2016-04-20 10:03:55 +00:00
|
|
|
var cwd = path.join(__dirname, '..');
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
version: version,
|
2016-06-17 08:31:36 +00:00
|
|
|
minimumCompatibleVersion: minimumCompatibleVersion,
|
2016-06-01 06:18:54 +00:00
|
|
|
maintenance: maintenance,
|
2016-04-20 10:03:55 +00:00
|
|
|
debug: debug,
|
|
|
|
urlpath: urlpath,
|
|
|
|
port: port,
|
|
|
|
alloworigin: alloworigin,
|
|
|
|
usessl: usessl,
|
|
|
|
serverurl: getserverurl(),
|
|
|
|
usecdn: usecdn,
|
2016-12-21 13:36:54 +00:00
|
|
|
allowanonymous: allowanonymous,
|
2016-12-16 07:38:05 +00:00
|
|
|
allowfreeurl: allowfreeurl,
|
2016-12-22 13:20:43 +00:00
|
|
|
dburl: dburl,
|
2016-04-20 10:03:55 +00:00
|
|
|
db: db,
|
|
|
|
sslkeypath: path.join(cwd, sslkeypath),
|
|
|
|
sslcertpath: path.join(cwd, sslcertpath),
|
|
|
|
sslcapath: path.join(cwd, sslcapath),
|
|
|
|
dhparampath: path.join(cwd, dhparampath),
|
|
|
|
tmppath: path.join(cwd, tmppath),
|
|
|
|
defaultnotepath: path.join(cwd, defaultnotepath),
|
|
|
|
docspath: path.join(cwd, docspath),
|
|
|
|
indexpath: path.join(cwd, indexpath),
|
|
|
|
hackmdpath: path.join(cwd, hackmdpath),
|
|
|
|
errorpath: path.join(cwd, errorpath),
|
|
|
|
prettypath: path.join(cwd, prettypath),
|
|
|
|
slidepath: path.join(cwd, slidepath),
|
|
|
|
sessionname: sessionname,
|
|
|
|
sessionsecret: sessionsecret,
|
|
|
|
sessionlife: sessionlife,
|
|
|
|
staticcachetime: staticcachetime,
|
|
|
|
heartbeatinterval: heartbeatinterval,
|
|
|
|
heartbeattimeout: heartbeattimeout,
|
|
|
|
documentmaxlength: documentmaxlength,
|
|
|
|
facebook: facebook,
|
|
|
|
twitter: twitter,
|
|
|
|
github: github,
|
2016-05-09 22:31:49 +00:00
|
|
|
gitlab: gitlab,
|
2016-04-20 10:03:55 +00:00
|
|
|
dropbox: dropbox,
|
2016-05-21 14:48:00 +00:00
|
|
|
google: google,
|
2016-12-13 21:31:35 +00:00
|
|
|
ldap: ldap,
|
2016-11-14 09:07:07 +00:00
|
|
|
imgur: imgur,
|
2016-12-01 17:58:14 +00:00
|
|
|
email: email,
|
2017-01-12 03:25:58 +00:00
|
|
|
allowemailregister: allowemailregister,
|
2016-11-16 04:05:24 +00:00
|
|
|
imageUploadType: imageUploadType,
|
|
|
|
s3: s3,
|
|
|
|
s3bucket: s3bucket
|
2016-04-23 10:58:24 +00:00
|
|
|
};
|