2015-07-20 00:09:47 -07:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
exports = module.exports = {
|
2019-10-29 15:46:33 -07:00
|
|
|
getServerIp: getServerIp,
|
2019-07-25 11:26:53 -07:00
|
|
|
|
2019-10-29 15:46:33 -07:00
|
|
|
hasIPv6: hasIPv6
|
2015-07-20 00:09:47 -07:00
|
|
|
};
|
|
|
|
|
|
2016-04-19 08:23:54 -07:00
|
|
|
var assert = require('assert'),
|
|
|
|
|
ec2 = require('./sysinfo/ec2.js'),
|
2019-07-25 11:26:53 -07:00
|
|
|
fs = require('fs'),
|
2016-10-08 16:40:58 -07:00
|
|
|
generic = require('./sysinfo/generic.js'),
|
2016-10-11 19:41:57 -07:00
|
|
|
scaleway = require('./sysinfo/scaleway.js'),
|
2019-10-29 15:46:33 -07:00
|
|
|
settings = require('./settings.js');
|
2015-07-20 00:09:47 -07:00
|
|
|
|
2019-10-29 15:46:33 -07:00
|
|
|
function getApi(config, callback) {
|
|
|
|
|
assert.strictEqual(typeof config, 'object');
|
2016-01-05 12:10:25 +01:00
|
|
|
assert.strictEqual(typeof callback, 'function');
|
2015-07-20 00:09:47 -07:00
|
|
|
|
2019-10-29 15:46:33 -07:00
|
|
|
const provider = config.provider || 'generic';
|
|
|
|
|
|
|
|
|
|
switch (provider) {
|
2019-01-24 14:58:04 -08:00
|
|
|
case 'ec2': return callback(null, ec2);
|
|
|
|
|
case 'lightsail': return callback(null, ec2);
|
|
|
|
|
case 'ami': return callback(null, ec2);
|
|
|
|
|
case 'scaleway': return callback(null, scaleway);
|
|
|
|
|
default: return callback(null, generic);
|
2016-01-06 14:34:23 +01:00
|
|
|
}
|
2015-07-20 00:09:47 -07:00
|
|
|
}
|
|
|
|
|
|
2019-10-29 15:46:33 -07:00
|
|
|
function getServerIp(callback) {
|
2016-01-05 12:10:25 +01:00
|
|
|
assert.strictEqual(typeof callback, 'function');
|
|
|
|
|
|
2019-10-29 15:46:33 -07:00
|
|
|
settings.getSysinfoConfig(function (error, config) {
|
2016-01-05 12:10:25 +01:00
|
|
|
if (error) return callback(error);
|
|
|
|
|
|
2019-10-29 15:46:33 -07:00
|
|
|
getApi(config, function (error, api) {
|
|
|
|
|
if (error) return callback(error);
|
|
|
|
|
|
|
|
|
|
api.getServerIp(config, callback);
|
|
|
|
|
});
|
2016-01-05 12:10:25 +01:00
|
|
|
});
|
|
|
|
|
}
|
2019-07-25 11:26:53 -07:00
|
|
|
|
|
|
|
|
function hasIPv6() {
|
|
|
|
|
const IPV6_PROC_FILE = '/proc/net/if_inet6';
|
|
|
|
|
// on contabo, /proc/net/if_inet6 is an empty file. so just exists is not enough
|
|
|
|
|
return fs.existsSync(IPV6_PROC_FILE) && fs.readFileSync(IPV6_PROC_FILE, 'utf8').trim().length !== 0;
|
|
|
|
|
}
|