Move getIp to sysinfo.js
This commit is contained in:
+2
-2
@@ -12,7 +12,6 @@ var addons = require('./addons.js'),
|
||||
assert = require('assert'),
|
||||
async = require('async'),
|
||||
clientdb = require('./clientdb.js'),
|
||||
cloudron = require('./cloudron.js'),
|
||||
config = require('../config.js'),
|
||||
database = require('./database.js'),
|
||||
DatabaseError = require('./databaseerror.js'),
|
||||
@@ -29,6 +28,7 @@ var addons = require('./addons.js'),
|
||||
safe = require('safetydance'),
|
||||
shell = require('./shell.js'),
|
||||
superagent = require('superagent'),
|
||||
sysinfo = require('./sysinfo.js'),
|
||||
tokendb = require('./tokendb.js'),
|
||||
util = require('util'),
|
||||
uuid = require('node-uuid'),
|
||||
@@ -442,7 +442,7 @@ function downloadIcon(app, callback) {
|
||||
function registerSubdomain(app, callback) {
|
||||
debugApp(app, 'Registering subdomain');
|
||||
|
||||
var record = { subdomain: app.location, type: 'A', value: cloudron.getIp() };
|
||||
var record = { subdomain: app.location, type: 'A', value: sysinfo.getIp() };
|
||||
|
||||
superagent
|
||||
.post(config.apiServerOrigin() + '/api/v1/subdomains')
|
||||
|
||||
+5
-27
@@ -24,9 +24,7 @@ exports = module.exports = {
|
||||
sendHeartbeat: sendHeartbeat,
|
||||
|
||||
reboot: reboot,
|
||||
migrate: migrate,
|
||||
|
||||
getIp: getIp
|
||||
migrate: migrate
|
||||
};
|
||||
|
||||
var addons = require('./addons.js'),
|
||||
@@ -46,6 +44,7 @@ var addons = require('./addons.js'),
|
||||
settings = require('./settings.js'),
|
||||
shell = require('./shell.js'),
|
||||
superagent = require('superagent'),
|
||||
sysinfo = require('./sysinfo.js'),
|
||||
tokendb = require('./tokendb.js'),
|
||||
updater = require('./updater.js'),
|
||||
user = require('./user.js'),
|
||||
@@ -61,8 +60,7 @@ var BACKUP_BOX_CMD = path.join(__dirname, 'scripts/backupbox.sh'),
|
||||
BACKUP_SWAP_CMD = path.join(__dirname, 'scripts/backupswap.sh');
|
||||
|
||||
var gAddMailDnsRecordsTimerId = null,
|
||||
gCloudronDetails = null, // cached cloudron details like region,size...
|
||||
gCachedIp = null;
|
||||
gCloudronDetails = null; // cached cloudron details like region,size...
|
||||
|
||||
function CloudronError(reason, errorOrMessage) {
|
||||
assert.strictEqual(typeof reason, 'string');
|
||||
@@ -129,8 +127,6 @@ function uninitialize(callback) {
|
||||
clearTimeout(gAddMailDnsRecordsTimerId);
|
||||
gAddMailDnsRecordsTimerId = null;
|
||||
|
||||
gCachedIp = null;
|
||||
|
||||
callback(null);
|
||||
}
|
||||
|
||||
@@ -305,24 +301,6 @@ function backup(callback) {
|
||||
});
|
||||
}
|
||||
|
||||
function getIp() {
|
||||
if (gCachedIp) return gCachedIp;
|
||||
|
||||
var ifaces = os.networkInterfaces();
|
||||
for (var dev in ifaces) {
|
||||
if (dev.match(/^(en|eth|wlp).*/) === null) continue;
|
||||
|
||||
for (var i = 0; i < ifaces[dev].length; i++) {
|
||||
if (ifaces[dev][i].family === 'IPv4') {
|
||||
gCachedIp = ifaces[dev][i].address;
|
||||
return gCachedIp;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
function getStatus(callback) {
|
||||
assert.strictEqual(typeof callback, 'function');
|
||||
|
||||
@@ -370,7 +348,7 @@ function getConfig(callback) {
|
||||
webServerOrigin: config.webServerOrigin(),
|
||||
isDev: /dev/i.test(config.get('boxVersionsUrl')),
|
||||
fqdn: config.fqdn(),
|
||||
ip: getIp(),
|
||||
ip: sysinfo.getIp(),
|
||||
version: config.version(),
|
||||
update: updater.getUpdateInfo(),
|
||||
progress: progress.get(),
|
||||
@@ -411,7 +389,7 @@ function sendMailDnsRecordsRequest(callback) {
|
||||
// note that dmarc requires special DNS records for external RUF and RUA
|
||||
var records = [
|
||||
// softfail all mails not from our IP. Note that this uses IP instead of 'a' should we use a load balancer in the future
|
||||
{ subdomain: '', type: 'TXT', value: '"v=spf1 ip4:' + getIp() + ' ~all"' },
|
||||
{ subdomain: '', type: 'TXT', value: '"v=spf1 ip4:' + sysinfo.getIp() + ' ~all"' },
|
||||
// t=s limits the domainkey to this domain and not it's subdomains
|
||||
{ subdomain: DKIM_SELECTOR + '._domainkey', type: 'TXT', value: '"v=DKIM1; t=s; p=' + publicKey + '"' },
|
||||
// DMARC requires special setup if report email id is in different domain
|
||||
|
||||
+2
-1
@@ -31,6 +31,7 @@ var assert = require('assert'),
|
||||
path = require('path'),
|
||||
safe = require('safetydance'),
|
||||
smtpTransport = require('nodemailer-smtp-transport'),
|
||||
sysinfo = require('./sysinfo.js'),
|
||||
userdb = require('./userdb.js'),
|
||||
util = require('util'),
|
||||
_ = require('underscore');
|
||||
@@ -62,7 +63,7 @@ function uninitialize(callback) {
|
||||
}
|
||||
|
||||
function checkDns() {
|
||||
digitalocean.checkPtrRecord(cloudron.getIp(), config.fqdn(), function (error, ok) {
|
||||
digitalocean.checkPtrRecord(sysinfo.getIp(), config.fqdn(), function (error, ok) {
|
||||
if (error || !ok) {
|
||||
debug('PTR record not setup yet');
|
||||
gCheckDnsTimerId = setTimeout(checkDns, 10000);
|
||||
|
||||
@@ -31,6 +31,7 @@ var appdb = require('../../appdb.js'),
|
||||
request = require('superagent'),
|
||||
safe = require('safetydance'),
|
||||
server = require('../../server.js'),
|
||||
sysinfo = require('../../sysinfo.js'),
|
||||
url = require('url'),
|
||||
util = require('util'),
|
||||
uuid = require('node-uuid'),
|
||||
@@ -498,7 +499,7 @@ describe('App installation', function () {
|
||||
hockInstance
|
||||
.get('/api/v1/apps/' + APP_STORE_ID + '/versions/' + APP_MANIFEST.version + '/icon')
|
||||
.replyWithFile(200, path.resolve(__dirname, '../../../webadmin/src/img/appicon_fallback.png'))
|
||||
.post('/api/v1/subdomains?token=' + config.token(), { records: [ { subdomain: APP_LOCATION, type: 'A', value: cloudron.getIp() } ] })
|
||||
.post('/api/v1/subdomains?token=' + config.token(), { records: [ { subdomain: APP_LOCATION, type: 'A', value: sysinfo.getIp() } ] })
|
||||
.reply(201, { ids: [ 'dnsrecordid' ] }, { 'Content-Type': 'application/json' })
|
||||
.delete('/api/v1/subdomains/dnsrecordid?token=' + config.token())
|
||||
.reply(204, { }, { 'Content-Type': 'application/json' });
|
||||
@@ -918,12 +919,12 @@ describe('App installation - port bindings', function () {
|
||||
// app install
|
||||
.get('/api/v1/apps/' + APP_STORE_ID + '/versions/' + APP_MANIFEST.version + '/icon')
|
||||
.replyWithFile(200, path.resolve(__dirname, '../../../webadmin/src/img/appicon_fallback.png'))
|
||||
.post('/api/v1/subdomains?token=' + config.token(), { records: [ { subdomain: APP_LOCATION, type: 'A', value: cloudron.getIp() } ] })
|
||||
.post('/api/v1/subdomains?token=' + config.token(), { records: [ { subdomain: APP_LOCATION, type: 'A', value: sysinfo.getIp() } ] })
|
||||
.reply(201, { ids: [ 'dnsrecordid' ] }, { 'Content-Type': 'application/json' })
|
||||
// app configure
|
||||
.delete('/api/v1/subdomains/dnsrecordid?token=' + config.token())
|
||||
.reply(204, { }, { 'Content-Type': 'application/json' })
|
||||
.post('/api/v1/subdomains?token=' + config.token(), { records: [ { subdomain: APP_LOCATION_NEW, type: 'A', value: cloudron.getIp() } ] })
|
||||
.post('/api/v1/subdomains?token=' + config.token(), { records: [ { subdomain: APP_LOCATION_NEW, type: 'A', value: sysinfo.getIp() } ] })
|
||||
.reply(201, { ids: [ 'anotherdnsid' ] }, { 'Content-Type': 'application/json' })
|
||||
// app remove
|
||||
.delete('/api/v1/subdomains/anotherdnsid?token=' + config.token())
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
'use strict';
|
||||
|
||||
var os = require('os');
|
||||
|
||||
exports = module.exports = {
|
||||
getIp: getIp
|
||||
};
|
||||
|
||||
var gCachedIp = null;
|
||||
|
||||
function getIp() {
|
||||
if (gCachedIp) return gCachedIp;
|
||||
|
||||
var ifaces = os.networkInterfaces();
|
||||
for (var dev in ifaces) {
|
||||
if (dev.match(/^(en|eth|wlp).*/) === null) continue;
|
||||
|
||||
for (var i = 0; i < ifaces[dev].length; i++) {
|
||||
if (ifaces[dev][i].family === 'IPv4') {
|
||||
gCachedIp = ifaces[dev][i].address;
|
||||
return gCachedIp;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ var addons = require('../addons.js'),
|
||||
net = require('net'),
|
||||
nock = require('nock'),
|
||||
paths = require('../paths.js'),
|
||||
sysinfo = require('../sysinfo.js'),
|
||||
_ = require('underscore');
|
||||
|
||||
var MANIFEST = {
|
||||
@@ -199,7 +200,7 @@ describe('apptask', function () {
|
||||
it('registers subdomain', function (done) {
|
||||
nock.cleanAll();
|
||||
var scope = nock(config.apiServerOrigin())
|
||||
.post('/api/v1/subdomains?token=' + config.token(), { records: [ { subdomain: APP.location, type: 'A', value: cloudron.getIp() } ] })
|
||||
.post('/api/v1/subdomains?token=' + config.token(), { records: [ { subdomain: APP.location, type: 'A', value: sysinfo.getIp() } ] })
|
||||
.reply(201, { ids: [ APP.dnsRecordId ] });
|
||||
|
||||
apptask._registerSubdomain(APP, function (error) {
|
||||
|
||||
Reference in New Issue
Block a user