make sysinfo provider a setting
This commit is contained in:
@@ -12,12 +12,27 @@ let assert = require('assert'),
|
||||
once = require('once'),
|
||||
path = require('path'),
|
||||
paths = require('./paths.js'),
|
||||
sysinfo = require('./sysinfo.js');
|
||||
settings = require('./settings.js');
|
||||
|
||||
// the logic here is also used in the cloudron-support tool
|
||||
const AUTHORIZED_KEYS_FILEPATH = constants.TEST ? path.join(paths.baseDir(), 'authorized_keys') : ((sysinfo.provider() === 'ec2' || sysinfo.provider() === 'lightsail' || sysinfo.provider() === 'ami') ? '/home/ubuntu/.ssh/authorized_keys' : '/root/.ssh/authorized_keys'),
|
||||
AUTHORIZED_KEYS_USER = constants.TEST ? process.getuid() : ((sysinfo.provider() === 'ec2' || sysinfo.provider() === 'lightsail' || sysinfo.provider() === 'ami') ? 'ubuntu' : 'root'),
|
||||
AUTHORIZED_KEYS_CMD = path.join(__dirname, 'scripts/remotesupport.sh');
|
||||
const AUTHORIZED_KEYS_CMD = path.join(__dirname, 'scripts/remotesupport.sh');
|
||||
|
||||
function sshInfo() {
|
||||
let filePath, user;
|
||||
|
||||
if (constants.TEST) {
|
||||
filePath = path.join(paths.baseDir(), 'authorized_keys');
|
||||
user = process.getuid();
|
||||
} else if (settings.provider() === 'ec2' || settings.provider() === 'lightsail' || settings.provider() === 'ami') {
|
||||
filePath = '/home/ubuntu/.ssh/authorized_keys';
|
||||
user = 'ubuntu';
|
||||
} else {
|
||||
filePath = '/root/.ssh/authorized_keys';
|
||||
user = 'root';
|
||||
}
|
||||
|
||||
return { filePath, user };
|
||||
}
|
||||
|
||||
function getRemoteSupport(callback) {
|
||||
assert.strictEqual(typeof callback, 'function');
|
||||
@@ -25,7 +40,7 @@ function getRemoteSupport(callback) {
|
||||
callback = once(callback); // exit may or may not be called after an 'error'
|
||||
|
||||
let result = '';
|
||||
let cp = shell.sudo('support', [ AUTHORIZED_KEYS_CMD, 'is-enabled', AUTHORIZED_KEYS_FILEPATH ], {}, function (error) {
|
||||
let cp = shell.sudo('support', [ AUTHORIZED_KEYS_CMD, 'is-enabled', sshInfo().filePath ], {}, function (error) {
|
||||
if (error) callback(new BoxError(BoxError.FS_ERROR, error));
|
||||
|
||||
callback(null, { enabled: result.trim() === 'true' });
|
||||
@@ -36,7 +51,8 @@ function getRemoteSupport(callback) {
|
||||
function enableRemoteSupport(enable, callback) {
|
||||
assert.strictEqual(typeof callback, 'function');
|
||||
|
||||
shell.sudo('support', [ AUTHORIZED_KEYS_CMD, enable ? 'enable' : 'disable', AUTHORIZED_KEYS_FILEPATH, AUTHORIZED_KEYS_USER ], {}, function (error) {
|
||||
let si = sshInfo();
|
||||
shell.sudo('support', [ AUTHORIZED_KEYS_CMD, enable ? 'enable' : 'disable', si.filePath, si.user ], {}, function (error) {
|
||||
if (error) callback(new BoxError(BoxError.FS_ERROR, error));
|
||||
|
||||
callback();
|
||||
|
||||
Reference in New Issue
Block a user