Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
var tlsCheckOptions = ['cert', 'key', 'pfx', 'ca'];
var usingSSL = false;
Object.keys(options).forEach(function(k) {
httpOptions[k] = options[k];
if (tlsCheckOptions.indexOf(k) > -1) {
usingSSL = true;
}
});
// If any tls options were specified, use ssl and not plain
httpOptions.plain = (usingSSL) ? false : true;
httpOptions.ssl = (usingSSL) ? true : false;
this.server = spdy.createServer(httpOptions);
// internal server for z2z, allways ssl: false, plain: true
this.spdyServer = spdy.createServer({
windowSize: 1024 * 1024,
plain: true,
ssl: false
});
var ValidWSUrls = [
/^\/events$/, // /events
/^\/events\?.+$/, // /events?topic=query:where type="led"
/^\/servers\/(.+)\/events/, // /servers/BC2832FD-9437-4473-A4A8-AC1D56B12C61/events
/^\/peers\/(.+)$/, // /peers/123123...
/^\/peer-management$/, // /peer-management
];
function match(request) {
return ValidWSUrls.some(function(re) {
return re.test(request.url);
});
fs.writeFileSync(certPath, pems.private + pems.cert, { encoding: "utf-8" });
}
const fakeCert = fs.readFileSync(certPath);
options.https.key = options.https.key || fakeCert;
options.https.cert = options.https.cert || fakeCert;
if(!options.https.spdy) {
options.https.spdy = {
protocols: ["h2", "http/1.1"]
};
}
this.listeningApp = spdy.createServer(options.https, app);
} else {
this.listeningApp = http.createServer(app);
}
// Proxy websockets without the initial http request
// https://github.com/chimurai/http-proxy-middleware#external-websocket-upgrade
websocketProxies.forEach(function(wsProxy) {
this.listeningApp.on("upgrade", wsProxy.upgrade);
}, this);
}
var fmt = mergeFormatters(options.formatters);
this.acceptable = fmt.acceptable;
this.formatters = fmt.formatters;
this.proxyEvents = [
'clientError',
'close',
'connection',
'error',
'listening',
'secureConnection'
];
if (options.spdy) {
this.spdy = true;
this.server = spdy.createServer(options.spdy);
} else if (options.http2) {
// http2 module is not available < v8.4.0 (only with flag <= 8.8.0)
// load http2 module here to avoid experimental warning in other cases
if (!http2) {
try {
http2 = require('http2');
patchResponse(http2.Http2ServerResponse);
patchRequest(http2.Http2ServerRequest);
// eslint-disable-next-line no-empty
} catch (err) {}
}
assert(
http2,
'http2 module is not available, ' +
'upgrade your Node.js version to >= 8.8.0'
let group = req.params.group
data[group].block = req.body
return res.json(data[group].block)
})
app.get('/api/unifi-clients', (req, res) => {
controllerLogin( () =>
controller.getAllUsers(nconf.get('controller:site'), (err, users) => {
clients = {}
users[0].forEach(user => clients[user.mac] = user.name || user.hostname || user.mac )
res.status(200).json(users[0] || [{name: "Error: " + err.code}])
})
)
})
spdy.createServer(serverOptions, app)
.listen(port, host, (error) => {
if (error) {
console.error(error)
return process.exit(1)
} else {
debug('Listening on port', port)
controllerLogin( () =>
controller.getAllUsers(nconf.get('controller:site'), (err, users) => {
users[0].forEach(user => clients[user.mac] = user.name || user.hostname || user.mac )
})
)
Object.values(data).forEach(group => {
scheduleJobs(group.name, group.timers)
})
}
opts['spdy'] = { protocols: ['h2', 'http/1.1', 'http/1.0'] };
}
if (push && !http1) {
console.log('HTTP server: using HTTP 2 push.');
} else if (push && http1) {
console.log('HTTP server: no push support on HTTP 1.');
}
if (preload) {
console.log('HTTP server: using .');
}
_cacheEverything();
server = spdy.createServer(opts, _onRequest);
console.log('HTTP server: listening...')
server.listen(44333);
});
var fd
if (options.use_ssl)
try {
fd = bind(443)
bus.port = 443
bus.redirect_port_80()
} catch (e) {fd = find_a_port()}
else fd = find_a_port()
var http_server = http.createServer(ssl_options)
http_server.listen({fd: fd}, () => {
console.log('Listening on '+protocol+'://:'+bus.port)
})
}
else {
bus.port = bus.options.port
var http_server = http.createServer(ssl_options)
http_server.listen(bus.options.port, () => {
console.log('Listening on '+protocol+'://:'+bus.port)
})
}
bus[options.name || 'http_server'] = http_server
},
path = require('path'),
spdy = require('spdy'),
http = require('http'),
app = express();
let cache = {};
app.set('etag', false);
app.use(express.static('./'));
http.createServer(app).listen(3000, () => {
return console.log(`HTTP/1 use http://localhost:3000`);
});
spdy
.createServer(
{
key: fs.readFileSync(path.join(__dirname, '../http2-keys/server.key')),
cert: fs.readFileSync(path.join(__dirname, '../http2-keys/server.crt')),
spdy: { protocols: ['h2', 'http/1.1', 'http/1.0'] }
},
app
)
.listen(3001, err => {
if (err) {
throw new Error(err);
}
console.log(`
HTTP/2 use https://localhost:3001`);
});
const h2c = app => spdy.createServer({ spdy: { plain: true, ssl: false, connection: { maxStreams: 262144 } } }, app).setTimeout(0)
/***************************************************
},
...options
};
if (key != null) {
tcpCfg.key = fs.readFileSync(key);
}
if (cert != null) {
tcpCfg.cert = fs.readFileSync(cert);
}
this.protocol = "https";
this.baseURL = getBaseURL(this);
ModuleManager.setServer(this.host, this.port, null);
this.initServer(spdy.createServer(tcpCfg));
}
const h2c = app => spdy.createServer({ spdy: { plain: true, ssl: false, connection: { maxStreams: 262144 } } }, app).setTimeout(0)
/***************************************************