@@ -22,3 +22,6 @@ yellowtent ALL=(root) NOPASSWD: /home/yellowtent/box/src/scripts/reboot.sh
|
||||
Defaults!/home/yellowtent/box/src/scripts/reloadcollectd.sh env_keep="HOME NODE_ENV"
|
||||
yellowtent ALL=(root) NOPASSWD: /home/yellowtent/box/src/scripts/reloadcollectd.sh
|
||||
|
||||
Defaults!/home/yellowtent/box/src/scripts/settimezone.sh env_keep="HOME NODE_ENV"
|
||||
yellowtent ALL=(root) NOPASSWD: /home/yellowtent/box/src/scripts/settimezone.sh
|
||||
|
||||
|
||||
+29
-3
@@ -53,7 +53,8 @@ var BACKUP_BOX_CMD = path.join(__dirname, 'scripts/backupbox.sh'),
|
||||
RELOAD_NGINX_CMD = path.join(__dirname, 'scripts/reloadnginx.sh'),
|
||||
BACKUP_APP_CMD = path.join(__dirname, 'scripts/backupapp.sh'),
|
||||
RESTORE_APP_CMD = path.join(__dirname, 'scripts/restoreapp.sh'),
|
||||
REBOOT_CMD = path.join(__dirname, '../scripts/reboot.sh');
|
||||
REBOOT_CMD = path.join(__dirname, 'scripts/reboot.sh'),
|
||||
SET_TIMEZONE_CMD = path.join(__dirname, 'scripts/settimezone.sh');
|
||||
|
||||
var gBackupTimerId = null,
|
||||
gAddMailDnsRecordsTimerId = null,
|
||||
@@ -119,20 +120,45 @@ function uninitialize(callback) {
|
||||
callback(null);
|
||||
}
|
||||
|
||||
function activate(username, password, email, callback) {
|
||||
function setTimezone(ip, callback) {
|
||||
assert(typeof ip === 'string');
|
||||
assert(typeof callback === 'function');
|
||||
|
||||
debug('setTimezone ip:%s', ip);
|
||||
|
||||
superagent.get('http://www.telize.com/geoip/' + ip).end(function (error, result) {
|
||||
if (error || result.statusCode !== 200) {
|
||||
debug('Failed to get geo location', error);
|
||||
return callback(null);
|
||||
}
|
||||
|
||||
if (!result.body.timezone) {
|
||||
debug('No timezone in geoip response');
|
||||
return callback(null);
|
||||
}
|
||||
|
||||
debug('Setting timezone to ', result.body.timezone);
|
||||
|
||||
shell.sudo('setTimezone', [ SET_TIMEZONE_CMD, result.body.timezone ], callback);
|
||||
});
|
||||
}
|
||||
|
||||
function activate(username, password, email, ip, callback) {
|
||||
assert(typeof username === 'string');
|
||||
assert(typeof password === 'string');
|
||||
assert(typeof email === 'string');
|
||||
assert(typeof ip === 'string');
|
||||
assert(typeof callback === 'function');
|
||||
|
||||
debug('activating user:%s email:%s', username, email);
|
||||
|
||||
setTimezone(ip, function () { });
|
||||
|
||||
user.createOwner(username, password, email, function (error, userObject) {
|
||||
if (error && error.reason === UserError.ALREADY_EXISTS) return callback(new CloudronError(CloudronError.ALREADY_PROVISIONED));
|
||||
if (error && error.reason === UserError.BAD_USERNAME) return callback(new CloudronError(CloudronError.BAD_USERNAME));
|
||||
if (error && error.reason === UserError.BAD_PASSWORD) return callback(new CloudronError(CloudronError.BAD_PASSWORD));
|
||||
if (error && error.reason === UserError.BAD_EMAIL) return callback(new CloudronError(CloudronError.BAD_EMAIL));
|
||||
|
||||
if (error) return callback(new CloudronError(CloudronError.INTERNAL_ERROR, error));
|
||||
|
||||
clientdb.getByAppId('webadmin', function (error, result) {
|
||||
|
||||
@@ -52,9 +52,10 @@ function activate(req, res, next) {
|
||||
var password = req.body.password;
|
||||
var email = req.body.email;
|
||||
|
||||
debug('activate: ' + username);
|
||||
var ip = req.headers['x-forwarded-for'] || req.connection.remoteAddress;
|
||||
debug('activate: username:%s ip:%s', username, ip);
|
||||
|
||||
cloudron.activate(username, password, email, function (error, info) {
|
||||
cloudron.activate(username, password, email, ip, function (error, info) {
|
||||
if (error && error.reason === CloudronError.ALREADY_PROVISIONED) return next(new HttpError(409, 'Already setup'));
|
||||
if (error && error.reason === CloudronError.BAD_USERNAME) return next(new HttpError(400, 'Bad username'));
|
||||
if (error && error.reason === CloudronError.BAD_PASSWORD) return next(new HttpError(400, 'Bad password'));
|
||||
|
||||
Executable
+19
@@ -0,0 +1,19 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -eu -o pipefail
|
||||
|
||||
if [[ ${EUID} -ne 0 ]]; then
|
||||
echo "This script should be run as root." > /dev/stderr
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ $# == 1 && "$1" == "--check" ]]; then
|
||||
echo "OK"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [[ "${NODE_ENV}" == "cloudron" ]]; then
|
||||
echo "$1" > /etc/timezone
|
||||
dpkg-reconfigure -f noninteractive tzdata
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user