chore: split config from app/server/app.js #242
This commit is contained in:
parent
3eb2488fe2
commit
f3a9478c6f
2 changed files with 112 additions and 105 deletions
|
|
@ -3,107 +3,24 @@
|
||||||
no-console: ["error", { allow: ["warn", "error"] }] */
|
no-console: ["error", { allow: ["warn", "error"] }] */
|
||||||
// app.js
|
// app.js
|
||||||
|
|
||||||
|
// eslint-disable-next-line import/order
|
||||||
|
const config = require('./config');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const fs = require('fs');
|
|
||||||
|
|
||||||
const nodeRoot = path.dirname(require.main.filename);
|
const nodeRoot = path.dirname(require.main.filename);
|
||||||
const configPath = path.join(nodeRoot, 'config.json');
|
|
||||||
const publicPath = path.join(nodeRoot, 'client', 'public');
|
const publicPath = path.join(nodeRoot, 'client', 'public');
|
||||||
const express = require('express');
|
const express = require('express');
|
||||||
const logger = require('morgan');
|
const logger = require('morgan');
|
||||||
|
|
||||||
// sane defaults if config.json or parts are missing
|
const app = express();
|
||||||
let config = {
|
const server = require('http').Server(app);
|
||||||
listen: {
|
const validator = require('validator');
|
||||||
ip: '0.0.0.0',
|
const favicon = require('serve-favicon');
|
||||||
port: 2222,
|
const io = require('socket.io')(server, {
|
||||||
},
|
serveClient: false,
|
||||||
http: {
|
path: '/ssh/socket.io',
|
||||||
origins: ['localhost:2222'],
|
origins: config.http.origins,
|
||||||
},
|
});
|
||||||
user: {
|
|
||||||
name: null,
|
|
||||||
password: null,
|
|
||||||
privatekey: null,
|
|
||||||
},
|
|
||||||
ssh: {
|
|
||||||
host: null,
|
|
||||||
port: 22,
|
|
||||||
term: 'xterm-color',
|
|
||||||
readyTimeout: 20000,
|
|
||||||
keepaliveInterval: 120000,
|
|
||||||
keepaliveCountMax: 10,
|
|
||||||
allowedSubnets: [],
|
|
||||||
},
|
|
||||||
terminal: {
|
|
||||||
cursorBlink: true,
|
|
||||||
scrollback: 10000,
|
|
||||||
tabStopWidth: 8,
|
|
||||||
bellStyle: 'sound',
|
|
||||||
},
|
|
||||||
header: {
|
|
||||||
text: null,
|
|
||||||
background: 'green',
|
|
||||||
},
|
|
||||||
session: {
|
|
||||||
name: 'WebSSH2',
|
|
||||||
secret: 'mysecret',
|
|
||||||
},
|
|
||||||
options: {
|
|
||||||
challengeButton: true,
|
|
||||||
allowreauth: true,
|
|
||||||
},
|
|
||||||
algorithms: {
|
|
||||||
kex: [
|
|
||||||
'ecdh-sha2-nistp256',
|
|
||||||
'ecdh-sha2-nistp384',
|
|
||||||
'ecdh-sha2-nistp521',
|
|
||||||
'diffie-hellman-group-exchange-sha256',
|
|
||||||
'diffie-hellman-group14-sha1',
|
|
||||||
],
|
|
||||||
cipher: [
|
|
||||||
'aes128-ctr',
|
|
||||||
'aes192-ctr',
|
|
||||||
'aes256-ctr',
|
|
||||||
'aes128-gcm',
|
|
||||||
'aes128-gcm@openssh.com',
|
|
||||||
'aes256-gcm',
|
|
||||||
'aes256-gcm@openssh.com',
|
|
||||||
'aes256-cbc',
|
|
||||||
],
|
|
||||||
hmac: ['hmac-sha2-256', 'hmac-sha2-512', 'hmac-sha1'],
|
|
||||||
compress: ['none', 'zlib@openssh.com', 'zlib'],
|
|
||||||
},
|
|
||||||
serverlog: {
|
|
||||||
client: false,
|
|
||||||
server: false,
|
|
||||||
},
|
|
||||||
accesslog: false,
|
|
||||||
verify: false,
|
|
||||||
safeShutdownDuration: 300,
|
|
||||||
};
|
|
||||||
|
|
||||||
// test if config.json exists, if not provide error message but try to run
|
|
||||||
// anyway
|
|
||||||
try {
|
|
||||||
if (fs.existsSync(configPath)) {
|
|
||||||
// eslint-disable-next-line no-console
|
|
||||||
console.log(`webssh2 service reading config from: ${configPath}`);
|
|
||||||
config = require('read-config-ng')(configPath) // eslint-disable-line
|
|
||||||
} else {
|
|
||||||
console.error(
|
|
||||||
`\n\nERROR: Missing config.json for webssh. Current config: ${JSON.stringify(config)}`
|
|
||||||
);
|
|
||||||
console.error('\n See config.json.sample for details\n\n');
|
|
||||||
}
|
|
||||||
} catch (err) {
|
|
||||||
console.error(
|
|
||||||
`\n\nERROR: Missing config.json for webssh. Current config: ${JSON.stringify(config)}`
|
|
||||||
);
|
|
||||||
console.error('\n See config.json.sample for details\n\n');
|
|
||||||
console.error(`ERROR:\n\n ${err}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
const session = require('express-session')({
|
const session = require('express-session')({
|
||||||
secret: config.session.secret,
|
secret: config.session.secret,
|
||||||
name: config.session.name,
|
name: config.session.name,
|
||||||
|
|
@ -111,17 +28,6 @@ const session = require('express-session')({
|
||||||
saveUninitialized: false,
|
saveUninitialized: false,
|
||||||
unset: 'destroy',
|
unset: 'destroy',
|
||||||
});
|
});
|
||||||
|
|
||||||
const app = express();
|
|
||||||
const server = require('http').Server(app);
|
|
||||||
|
|
||||||
const validator = require('validator');
|
|
||||||
const io = require('socket.io')(server, {
|
|
||||||
serveClient: false,
|
|
||||||
path: '/ssh/socket.io',
|
|
||||||
origins: config.http.origins,
|
|
||||||
});
|
|
||||||
const favicon = require('serve-favicon');
|
|
||||||
const appSocket = require('./socket');
|
const appSocket = require('./socket');
|
||||||
const expressOptions = require('./expressOptions');
|
const expressOptions = require('./expressOptions');
|
||||||
const myutil = require('./util');
|
const myutil = require('./util');
|
||||||
|
|
|
||||||
101
app/server/config.js
Normal file
101
app/server/config.js
Normal file
|
|
@ -0,0 +1,101 @@
|
||||||
|
/* eslint no-unused-expressions: ["error", { "allowShortCircuit": true, "allowTernary": true }],
|
||||||
|
no-console: ["error", { allow: ["warn", "error"] }] */
|
||||||
|
const fs = require('fs');
|
||||||
|
const path = require('path');
|
||||||
|
|
||||||
|
const nodeRoot = path.dirname(require.main.filename);
|
||||||
|
const configPath = path.join(nodeRoot, 'config.json');
|
||||||
|
|
||||||
|
// sane defaults if config.json or parts are missing
|
||||||
|
let config = {
|
||||||
|
listen: {
|
||||||
|
ip: '0.0.0.0',
|
||||||
|
port: 2222,
|
||||||
|
},
|
||||||
|
http: {
|
||||||
|
origins: ['localhost:2222'],
|
||||||
|
},
|
||||||
|
user: {
|
||||||
|
name: null,
|
||||||
|
password: null,
|
||||||
|
privatekey: null,
|
||||||
|
},
|
||||||
|
ssh: {
|
||||||
|
host: null,
|
||||||
|
port: 22,
|
||||||
|
term: 'xterm-color',
|
||||||
|
readyTimeout: 20000,
|
||||||
|
keepaliveInterval: 120000,
|
||||||
|
keepaliveCountMax: 10,
|
||||||
|
allowedSubnets: [],
|
||||||
|
},
|
||||||
|
terminal: {
|
||||||
|
cursorBlink: true,
|
||||||
|
scrollback: 10000,
|
||||||
|
tabStopWidth: 8,
|
||||||
|
bellStyle: 'sound',
|
||||||
|
},
|
||||||
|
header: {
|
||||||
|
text: null,
|
||||||
|
background: 'green',
|
||||||
|
},
|
||||||
|
session: {
|
||||||
|
name: 'WebSSH2',
|
||||||
|
secret: 'mysecret',
|
||||||
|
},
|
||||||
|
options: {
|
||||||
|
challengeButton: true,
|
||||||
|
allowreauth: true,
|
||||||
|
},
|
||||||
|
algorithms: {
|
||||||
|
kex: [
|
||||||
|
'ecdh-sha2-nistp256',
|
||||||
|
'ecdh-sha2-nistp384',
|
||||||
|
'ecdh-sha2-nistp521',
|
||||||
|
'diffie-hellman-group-exchange-sha256',
|
||||||
|
'diffie-hellman-group14-sha1',
|
||||||
|
],
|
||||||
|
cipher: [
|
||||||
|
'aes128-ctr',
|
||||||
|
'aes192-ctr',
|
||||||
|
'aes256-ctr',
|
||||||
|
'aes128-gcm',
|
||||||
|
'aes128-gcm@openssh.com',
|
||||||
|
'aes256-gcm',
|
||||||
|
'aes256-gcm@openssh.com',
|
||||||
|
'aes256-cbc',
|
||||||
|
],
|
||||||
|
hmac: ['hmac-sha2-256', 'hmac-sha2-512', 'hmac-sha1'],
|
||||||
|
compress: ['none', 'zlib@openssh.com', 'zlib'],
|
||||||
|
},
|
||||||
|
serverlog: {
|
||||||
|
client: false,
|
||||||
|
server: false,
|
||||||
|
},
|
||||||
|
accesslog: false,
|
||||||
|
verify: false,
|
||||||
|
safeShutdownDuration: 300,
|
||||||
|
};
|
||||||
|
|
||||||
|
// test if config.json exists, if not provide error message but try to run anyway
|
||||||
|
try {
|
||||||
|
if (fs.existsSync(configPath)) {
|
||||||
|
// eslint-disable-next-line no-console
|
||||||
|
console.info(`WebSSH2 service reading config from: ${configPath}`);
|
||||||
|
// eslint-disable-next-line global-require
|
||||||
|
config = require('read-config-ng')(configPath);
|
||||||
|
} else {
|
||||||
|
console.error(
|
||||||
|
`\n\nERROR: Missing config.json for webssh. Current config: ${JSON.stringify(config)}`
|
||||||
|
);
|
||||||
|
console.error('\n See config.json.sample for details\n\n');
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
console.error(
|
||||||
|
`\n\nERROR: Missing config.json for webssh. Current config: ${JSON.stringify(config)}`
|
||||||
|
);
|
||||||
|
console.error('\n See config.json.sample for details\n\n');
|
||||||
|
console.error(`ERROR:\n\n ${err}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = config;
|
||||||
Loading…
Reference in a new issue