2014-05-12 20:08:19 +02:00
|
|
|
'use strict';
|
|
|
|
|
2016-06-11 17:15:19 +02:00
|
|
|
var commandLineArgs = require('command-line-args');
|
|
|
|
var commandLineUsage = require('command-line-usage');
|
|
|
|
|
|
|
|
var commandLineDefs = [
|
|
|
|
{ name: 'help', alias: 'h', type: Boolean, description: 'Show this help' },
|
2016-06-26 20:21:45 +02:00
|
|
|
{ name: 'config', alias: 'c', type: String, description: 'Location of config.json' },
|
|
|
|
{ name: 'version', alias: 'v', type: Boolean, description: 'Show ffffng version' }
|
2016-06-11 17:15:19 +02:00
|
|
|
];
|
|
|
|
|
|
|
|
var commandLineOptions;
|
|
|
|
try {
|
|
|
|
commandLineOptions = commandLineArgs(commandLineDefs);
|
|
|
|
} catch (e) {
|
|
|
|
console.error(e.message);
|
|
|
|
console.error('Try \'--help\' for more information.');
|
|
|
|
process.exit(1);
|
|
|
|
}
|
|
|
|
|
2016-06-26 20:21:45 +02:00
|
|
|
var fs = require('graceful-fs');
|
|
|
|
|
|
|
|
var packageJsonFile = __dirname + '/../package.json';
|
|
|
|
var version = 'unknown';
|
|
|
|
if (fs.existsSync(packageJsonFile)) {
|
|
|
|
version = JSON.parse(fs.readFileSync(packageJsonFile, 'utf8')).version;
|
|
|
|
}
|
|
|
|
|
|
|
|
function usage() {
|
2016-06-11 17:15:19 +02:00
|
|
|
console.log(commandLineUsage([
|
|
|
|
{
|
2016-06-26 20:21:45 +02:00
|
|
|
header: 'ffffng - ' + version + ' - Freifunk node management form',
|
2016-06-11 17:15:19 +02:00
|
|
|
optionList: commandLineDefs
|
|
|
|
}
|
|
|
|
]));
|
|
|
|
}
|
|
|
|
|
2016-06-26 20:21:45 +02:00
|
|
|
if (commandLineOptions.help) {
|
|
|
|
usage();
|
|
|
|
process.exit(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (commandLineOptions.version) {
|
|
|
|
console.log('ffffng - ' + version);
|
|
|
|
process.exit(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!commandLineOptions.config) {
|
|
|
|
usage();
|
|
|
|
process.exit(1);
|
|
|
|
}
|
2016-06-11 17:15:19 +02:00
|
|
|
|
2016-05-20 22:38:13 +02:00
|
|
|
var deepExtend = require('deep-extend');
|
|
|
|
|
|
|
|
var defaultConfig = {
|
|
|
|
server: {
|
|
|
|
baseUrl: 'http://localhost:8080',
|
|
|
|
port: 8080,
|
|
|
|
|
|
|
|
databaseFile: '/tmp/ffffng.sqlite',
|
|
|
|
peersPath: '/tmp/peers',
|
|
|
|
|
2016-05-24 16:40:57 +02:00
|
|
|
logging: {
|
2016-05-24 19:14:09 +02:00
|
|
|
directory: '/tmp/logs',
|
|
|
|
debug: false,
|
2016-07-29 12:53:20 +02:00
|
|
|
profile: false,
|
2016-05-24 19:14:09 +02:00
|
|
|
logRequests: false
|
2016-05-24 16:40:57 +02:00
|
|
|
},
|
|
|
|
|
2016-05-24 19:40:02 +02:00
|
|
|
internal: {
|
|
|
|
active: false,
|
|
|
|
user: 'admin',
|
|
|
|
password: 'secret'
|
|
|
|
},
|
|
|
|
|
2016-05-20 22:38:13 +02:00
|
|
|
email: {
|
2016-05-21 17:06:24 +02:00
|
|
|
from: 'Freifunk Knotenformular <no-reply@musterstadt.freifunk.net>',
|
|
|
|
|
|
|
|
// For details see: https://nodemailer.com/2-0-0-beta/setup-smtp/
|
|
|
|
smtp: {
|
|
|
|
host: 'mail.example.com',
|
|
|
|
port: '465',
|
|
|
|
secure: true,
|
|
|
|
auth: {
|
|
|
|
user: 'user@example.com',
|
|
|
|
pass: 'pass'
|
|
|
|
}
|
|
|
|
}
|
2016-05-24 14:42:25 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
map: {
|
2017-03-03 22:02:26 +01:00
|
|
|
nodesJsonUrl: ['http://map.musterstadt.freifunk.net/nodes.json']
|
2016-05-20 22:38:13 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
client: {
|
|
|
|
community: {
|
|
|
|
name: 'Freifunk Musterstadt',
|
|
|
|
domain: 'musterstadt.freifunk.net',
|
|
|
|
contactEmail: 'kontakt@musterstadt.freifunk.net'
|
|
|
|
},
|
|
|
|
map: {
|
2016-05-24 14:42:25 +02:00
|
|
|
mapUrl: 'http://map.musterstadt.freifunk.net'
|
2014-06-06 21:22:57 +02:00
|
|
|
},
|
2016-05-20 22:38:13 +02:00
|
|
|
monitoring: {
|
2016-05-24 19:14:09 +02:00
|
|
|
enabled: false
|
2016-05-20 22:38:13 +02:00
|
|
|
},
|
|
|
|
coordsSelector: {
|
|
|
|
showInfo: false,
|
|
|
|
showBorderForDebugging: false,
|
|
|
|
localCommunityPolygon: [],
|
|
|
|
lat: 53.565278,
|
|
|
|
lng: 10.001389,
|
2016-07-14 16:28:17 +02:00
|
|
|
defaultZoom: 10,
|
|
|
|
layers: {}
|
2014-06-06 21:22:57 +02:00
|
|
|
}
|
2016-05-20 22:38:13 +02:00
|
|
|
}
|
|
|
|
};
|
2014-06-06 23:00:32 +02:00
|
|
|
|
2016-06-11 17:15:19 +02:00
|
|
|
var configJSONFile = commandLineOptions.config;
|
2016-05-20 22:38:13 +02:00
|
|
|
var configJSON = {};
|
2014-06-06 23:00:32 +02:00
|
|
|
|
2016-05-20 22:38:13 +02:00
|
|
|
if (fs.existsSync(configJSONFile)) {
|
|
|
|
configJSON = JSON.parse(fs.readFileSync(configJSONFile, 'utf8'));
|
2016-06-11 17:15:19 +02:00
|
|
|
} else {
|
|
|
|
console.error('config.json not found: ' + configJSONFile);
|
|
|
|
process.exit(1);
|
2016-05-20 22:38:13 +02:00
|
|
|
}
|
|
|
|
|
2017-05-06 17:31:34 +02:00
|
|
|
var _ = require('lodash');
|
|
|
|
|
2017-05-06 16:58:42 +02:00
|
|
|
function stripTrailingSlash(obj, field) {
|
|
|
|
var url = obj[field];
|
|
|
|
if (_.isString(url) && _.last(url) === '/') {
|
|
|
|
obj[field] = url.substr(0, url.length - 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-20 22:38:13 +02:00
|
|
|
var config = deepExtend({}, defaultConfig, configJSON);
|
|
|
|
|
2017-05-06 16:58:42 +02:00
|
|
|
stripTrailingSlash(config.server, 'baseUrl');
|
|
|
|
stripTrailingSlash(config.client.map, 'mapUrl');
|
|
|
|
|
2017-05-06 18:40:59 +02:00
|
|
|
var url = require('url');
|
|
|
|
config.server.rootPath = url.parse(config.server.baseUrl).pathname;
|
|
|
|
config.client.rootPath = config.server.rootPath;
|
|
|
|
|
2016-05-20 22:38:13 +02:00
|
|
|
module.exports = config;
|
2014-06-06 23:00:32 +02:00
|
|
|
|
2016-06-07 14:08:04 +02:00
|
|
|
angular.module('ffffng').constant('config', config);
|
2016-06-26 20:21:45 +02:00
|
|
|
angular.module('ffffng').constant('version', version);
|