|
|
@ -17,27 +17,29 @@ const distDir = path.join(__dirname, 'client'); |
|
|
|
const trim = (str: string): string => str.replace(/\/*$/, ''); |
|
|
|
|
|
|
|
export default function createServer( |
|
|
|
{ base, port, host }: Server, |
|
|
|
{ base, port, host, title, bypasshelmet }: Server, |
|
|
|
{ key, cert }: SSLBuffer |
|
|
|
): SocketIO.Server { |
|
|
|
const basePath = trim(base); |
|
|
|
events.emit( |
|
|
|
'debug', |
|
|
|
`key: ${key}, cert: ${cert}, port: ${port}, base: ${base}` |
|
|
|
`key: ${key}, cert: ${cert}, port: ${port}, base: ${base}, title: ${title}` |
|
|
|
); |
|
|
|
|
|
|
|
const html = ( |
|
|
|
req: express.Request, |
|
|
|
res: express.Response |
|
|
|
): express.Response => |
|
|
|
): express.Response => { |
|
|
|
const resourcePath = /^\/ssh\//.test(req.url) ? '../' : ''; |
|
|
|
res.send(`<!doctype html>
|
|
|
|
<html lang="en"> |
|
|
|
<head> |
|
|
|
<meta charset="UTF-8"> |
|
|
|
<meta http-equiv="X-UA-Compatible" content="IE=edge"> |
|
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no"> |
|
|
|
<title>WeTTy - The Web Terminal Emulator</title> |
|
|
|
<link rel="stylesheet" href="${basePath}/public/index.css" /> |
|
|
|
<title>${title}</title> |
|
|
|
<link rel="stylesheet" href="${resourcePath}public/index.css" /> |
|
|
|
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.8.1/css/all.css" integrity="sha384-50oBUHEmvpQ+1lW4y57PTFmhCaXp0ML5d60M1M7uH2+nqUivzIebhndOJK28anvf" crossorigin="anonymous"> |
|
|
|
</head> |
|
|
|
<body> |
|
|
|
<div id="overlay"> |
|
|
@ -46,29 +48,29 @@ export default function createServer( |
|
|
|
<input type="button" onclick="location.reload();" value="reconnect" /> |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
<div id="options"> |
|
|
|
<a class="toggler" |
|
|
|
href="#" |
|
|
|
alt="Toggle options"><i class="fas fa-cogs"></i></a> |
|
|
|
<textarea class="editor"></textarea> |
|
|
|
</div> |
|
|
|
<div id="terminal"></div> |
|
|
|
<script src="${basePath}/public/index.js"></script> |
|
|
|
<script src="${resourcePath}public/index.js"></script> |
|
|
|
</body> |
|
|
|
</html>`);
|
|
|
|
} |
|
|
|
|
|
|
|
const app = express(); |
|
|
|
app |
|
|
|
.use(morgan('combined', { stream: logger.stream })) |
|
|
|
.use(helmet({ frameguard: false })) |
|
|
|
.use(helmet({ frameguard: !bypasshelmet })) |
|
|
|
.use(compression()) |
|
|
|
.use(favicon(path.join(distDir, 'favicon.ico'))) |
|
|
|
.use(`${basePath}/public`, express.static(distDir)) |
|
|
|
.use((req, res, next) => { |
|
|
|
if ( |
|
|
|
req.url.substr(-1) === '/' && |
|
|
|
req.url.length > 1 && |
|
|
|
!/\?[^]*\//.test(req.url) |
|
|
|
) |
|
|
|
res.redirect(301, req.url.slice(0, -1)); |
|
|
|
if (req.url === basePath) res.redirect(301, req.url + '/'); |
|
|
|
else next(); |
|
|
|
}) |
|
|
|
.get(basePath, html) |
|
|
|
.get(`${basePath}/ssh/:user`, html); |
|
|
|
}).get(basePath, html).get(`${basePath}/ssh/:user`, html); |
|
|
|
|
|
|
|
return socket( |
|
|
|
!isUndefined(key) && !isUndefined(cert) |
|
|
|