@scrypted/server 0.0.81 → 0.0.85

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of @scrypted/server might be problematic. Click here for more details.

@@ -4,9 +4,8 @@ import http from 'http';
4
4
  import https from 'https';
5
5
  import express from 'express';
6
6
  import bodyParser from 'body-parser';
7
- import cluster from 'cluster';
8
7
  import net from 'net';
9
- import { startPluginClusterWorker as startPluginRemoteClusterWorker } from './plugin/plugin-host';
8
+ import { startPluginRemote } from './plugin/plugin-host';
10
9
  import { ScryptedRuntime } from './runtime';
11
10
  import level from './level';
12
11
  import { Plugin, ScryptedUser, Settings } from './db-types';
@@ -46,11 +45,8 @@ function listenServerPort(env: string, port: number, server: any) {
46
45
  })
47
46
  }
48
47
 
49
- if (!cluster.isMaster) {
50
- startPluginRemoteClusterWorker();
51
- }
52
- else if (process.argv[2] === 'child') {
53
- startPluginRemoteClusterWorker();
48
+ if (process.argv[2] === 'child') {
49
+ startPluginRemote();
54
50
  }
55
51
  else {
56
52
  installSourceMapSupport({
@@ -77,15 +73,14 @@ else {
77
73
  try {
78
74
  const target = await doconnect();
79
75
  socket.pipe(target).pipe(socket);
80
- socket.on('error', () => {
81
- socket.destroy();
82
- target.destroy();
83
- });
84
- target.on('error', e => {
85
- console.error('debugger target error', e);
76
+ const destroy = () => {
86
77
  socket.destroy();
87
78
  target.destroy();
88
- });
79
+ }
80
+ socket.on('error', destroy);
81
+ target.on('error', destroy);
82
+ socket.on('close', destroy);
83
+ target.on('close', destroy);
89
84
  return;
90
85
  }
91
86
  catch (e) {
@@ -151,14 +146,22 @@ else {
151
146
 
152
147
  const keys = certSetting.value;
153
148
 
154
- const secure = https.createServer({ key: keys.serviceKey, cert: keys.certificate }, app);
149
+ const httpsServerOptions = process.env.SCRYPTED_HTTPS_OPTIONS_FILE
150
+ ? JSON.parse(fs.readFileSync(process.env.SCRYPTED_HTTPS_OPTIONS_FILE).toString())
151
+ : {};
152
+
153
+ const mergedHttpsServerOptions = Object.assign({
154
+ key: keys.serviceKey,
155
+ cert: keys.certificate
156
+ }, httpsServerOptions);
157
+ const secure = https.createServer(mergedHttpsServerOptions, app);
155
158
  listenServerPort('SCRYPTED_SECURE_PORT', SCRYPTED_SECURE_PORT, secure);
156
159
  const insecure = http.createServer(app);
157
160
  listenServerPort('SCRYPTED_INSECURE_PORT', SCRYPTED_INSECURE_PORT, insecure);
158
161
 
159
162
  // legacy secure port 9443 is now in use by portainer.
160
163
  let shownLegacyPortAlert = false
161
- const legacySecure = https.createServer({ key: keys.serviceKey, cert: keys.certificate }, (req, res) => {
164
+ const legacySecure = https.createServer(mergedHttpsServerOptions, (req, res) => {
162
165
  if (!shownLegacyPortAlert) {
163
166
  const core = scrypted.findPluginDevice('@scrypted/core');
164
167
  if (core) {
@@ -228,7 +231,7 @@ else {
228
231
  return;
229
232
  }
230
233
  next();
231
- })
234
+ });
232
235
 
233
236
  console.log('#######################################################');
234
237
  console.log(`Scrypted Server (Local) : https://localhost:${SCRYPTED_SECURE_PORT}/`);
@@ -246,6 +249,10 @@ else {
246
249
  console.log('Ports can be changed with environment variables.')
247
250
  console.log('https: $SCRYPTED_SECURE_PORT')
248
251
  console.log('http : $SCRYPTED_INSECURE_PORT')
252
+ console.log('Certificate can be modified via tls.createSecureContext options in')
253
+ console.log('JSON file located at SCRYPTED_HTTPS_OPTIONS_FILE environment variable:');
254
+ console.log('export SCRYPTED_HTTPS_OPTIONS_FILE=/path/to/options.json');
255
+ console.log('https://nodejs.org/api/tls.html#tlscreatesecurecontextoptions')
249
256
  console.log('#######################################################');
250
257
  const scrypted = new ScryptedRuntime(db, insecure, secure, app);
251
258
  await scrypted.start();
@@ -339,15 +346,22 @@ else {
339
346
  }
340
347
 
341
348
  const waitDebug = new Promise<void>((resolve, reject) => {
342
- setTimeout(() => reject(new Error('timed out waiting for debug session')), 10000);
349
+ setTimeout(() => reject(new Error('timed out waiting for debug session')), 30000);
343
350
  debugServer.on('connection', resolve);
344
351
  });
345
352
 
346
353
  workerInspectPort = Math.round(Math.random() * 10000) + 30000;
347
- const pluginHost = await scrypted.installPlugin(plugin, {
348
- waitDebug,
349
- inspectPort: workerInspectPort,
350
- });
354
+ try {
355
+ await scrypted.installPlugin(plugin, {
356
+ waitDebug,
357
+ inspectPort: workerInspectPort,
358
+ });
359
+ }
360
+ catch (e) {
361
+ res.status(500);
362
+ res.send(e.toString());
363
+ return
364
+ }
351
365
 
352
366
  res.send({
353
367
  workerInspectPort,
@@ -119,6 +119,14 @@ export class PluginComponent {
119
119
  }
120
120
 
121
121
  async getRemoteServicePort(pluginId: string, name: string): Promise<number> {
122
+ if (name === 'console') {
123
+ const consoleServer = await this.scrypted.plugins[pluginId].consoleServer;
124
+ return consoleServer.readPort;
125
+ }
126
+ if (name === 'console-writer') {
127
+ const consoleServer = await this.scrypted.plugins[pluginId].consoleServer;
128
+ return consoleServer.writePort;
129
+ }
122
130
  return this.scrypted.plugins[pluginId].remote.getServicePort(name);
123
131
  }
124
132
  }
@@ -0,0 +1,4 @@
1
+ {
2
+ "key": "-----BEGIN RSA PRIVATE KEY-----\r\nMIIEowIBAAKCAQEA3bLZP9mrM22Oq2dmCR1hMWbUueNvemaV4AebCysht9HkJbbI\r\nxISgqJPP3BGirGe/M1D8USv4/cYSeiWEh7cEnSzz5JWlzCxRAAHWQIUups66qaIe\r\nfTb0Lb5rfdWkX3pWiEVhKN39AJsOk+dHLoJG4/SxPKG74Fg3sqkbCjmyZm/MEfDM\r\nRLKyFbt3yQvktFQ4324ycMgX2FL1oq3UFBRcku6oGPbgQ3AMas8UGw5HrKp+Nk8c\r\n2Hd5+V/0pO0CmqlhEnMjBiBHIequzOI74dMjWvPVtBi0ULHRLsGzLy+es9VOzOTi\r\nMbHhdqpsdSGh0swOPQmgnzLmR2SrRY3TbvG/1QIDAQABAoIBAD1UhsklHDlj6337\r\nYrzOxd52xg6Onn5L9tY9BGU4j2FczTKpuCy1TASWr3//2PK82KYHl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