Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return;
}
}
// apply existing site's properties in
_.defaults(requestData, me.sites[request.path[1]]);
}
// create new site
try {
cfgResult = me.writeSiteConfig(requestData);
if (cfgResult.isNew) {
// write primary hostname to /etc/hosts
if (me.options.localhost) {
hostile.set(me.options.localhost, cfgResult.site.primary_hostname);
console.log('added ' + cfgResult.site.primary_hostname + ' to /etc/hosts');
}
// notify plugins
me.emit('siteCreated', cfgResult.site, requestData, {
databaseReady: function () {
// execute onSiteCreated within site's container
console.log('Executing Site::onSiteCreated() via php-cli');
phpProc = spawn(phpShellScript, [cfgResult.site.handle]);
phpProc.stdout.on('data', function (data) { console.log('php-cli stdout: ' + data); });
phpProc.stderr.on('data', function (data) { console.log('php-cli stderr: ' + data); });
function _phpExec (code) {
//console.log('php> '+code);
phpProc.stdin.write(code+'\n');
p = p.then(() => new Promise((resolve, reject) => {
// TODO: Are we sure they map to those IPs on Linux? Should precede with docker inspect?
var ip = process.platform === 'linux' ? '172.17.0.' + (2 + i) : '127.0.0.1';
hostile.set(ip, host, (err) => err ? reject(err) : resolve());
}));
});
ngrok.connect({ port: server.http.address().port }, function (err, url) {
if (err) return t.fail(err)
var host = url.replace('https://', '')
hostile.set('127.0.0.1', host, function (err) {
if (err) return t.fail(err)
request(url + ':' + server.address().port)
.get('/')
.end(function (err, res) {
if (err) return t.fail(err)
t.equal(res.text, 'Hello World\n', 'should respond to https request')
ngrok.disconnect(url)
server.close()
hostile.remove('127.0.0.1', host)
})
})
})
})
activatePortForwarding(minIp, port).then(() => {
hostile.set('# local.dev', port);
hostile.set(minIp, url);
console.log(chalk.green(`
Added local.dev :
localhost:${chalk.green(`${port} <-`)} ${chalk.green(url)}
`));
});
});
const add = function( hosts ) {
hostile.set( '127.0.0.1', hosts.join(' '), function( err ) {
if (err) {
console.error(err)
} else {
console.log('Added to hosts file successfully!')
}
});
};
hostile.get(false, (err, lines) => {
const isDefined = lines.some(line => line[0] === host.ip && line[1] === host.domain)
if (isDefined) {
return reject(`host [${host.ip} ${host.domain}] has been used`)
}
hostile.set(host.ip, host.domain, err => {
if (err) {
return reject(`Failed to add [${host.ip} ${host.domain}]: ${err.message}`)
}
if (host.alias) {
setAliases({ ...aliases, [host.ip + host.domain]: host.alias })
}
setSysHosts(sysHosts => [...sysHosts, { ...host, disabled: false, alias: aliases[host.ip + host.domain] }])
resolve()
})
})
})
sites.forEach(site => {
try {
hostile.set('127.0.0.1', site)
log(`🚫 Blocking ${site}`)
} catch(err) {
error(err.message, true)
}
})
exports.configure = (config, err) => {
const tasks = [
{
label: 'Setting rule in /etc/hosts',
command: hostile.set('127.0.0.1', config.testHost),
},
];
doTasks('Configure vhost ❖', ' Configure vhost', tasks, err, true);
}
queue.push(function (cb){
hostile.set(ip || '127.0.0.1', domain, function (err) {
if (err) {
logger.error(err)
} else {
logger.info('set hosts successfully! ' + domain)
}
cb();
});
});
deal();
return new Promise((resolve, reject) => {
hostile.set(host.ip, host.domain, err => {
if (err) {
return reject(
'failed adding ' + host.ip + '\n\n Please Make sure you have permission to modify ' + HOSTS + ' file'
)
}
if (host.alias) {
localStorage.setItem(ALIAS_PREFIX + host.ip + host.domain, host.alias)
}
host.disabled = false
resolve(host)
})
})
})