@scrypted/server 0.0.80 → 0.0.84

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.

Files changed (38) hide show
  1. package/dist/plugin/plugin-console.js +93 -0
  2. package/dist/plugin/plugin-console.js.map +1 -0
  3. package/dist/plugin/plugin-device.js +6 -1
  4. package/dist/plugin/plugin-device.js.map +1 -1
  5. package/dist/plugin/plugin-host-api.js +1 -1
  6. package/dist/plugin/plugin-host-api.js.map +1 -1
  7. package/dist/plugin/plugin-host.js +74 -174
  8. package/dist/plugin/plugin-host.js.map +1 -1
  9. package/dist/plugin/plugin-npm-dependencies.js +2 -2
  10. package/dist/plugin/plugin-npm-dependencies.js.map +1 -1
  11. package/dist/plugin/plugin-remote.js +7 -9
  12. package/dist/plugin/plugin-remote.js.map +1 -1
  13. package/dist/plugin/plugin-repl.js +69 -0
  14. package/dist/plugin/plugin-repl.js.map +1 -0
  15. package/dist/runtime.js +2 -21
  16. package/dist/runtime.js.map +1 -1
  17. package/dist/scrypted-main.js +21 -15
  18. package/dist/scrypted-main.js.map +1 -1
  19. package/dist/services/plugin.js +8 -0
  20. package/dist/services/plugin.js.map +1 -1
  21. package/dist/state.js +1 -1
  22. package/dist/state.js.map +1 -1
  23. package/package.json +2 -2
  24. package/python/plugin-remote.py +45 -20
  25. package/python/rpc.py +1 -1
  26. package/src/plugin/plugin-api.ts +2 -2
  27. package/src/plugin/plugin-console.ts +115 -0
  28. package/src/plugin/plugin-device.ts +7 -1
  29. package/src/plugin/plugin-host-api.ts +1 -1
  30. package/src/plugin/plugin-host.ts +72 -198
  31. package/src/plugin/plugin-npm-dependencies.ts +2 -3
  32. package/src/plugin/plugin-remote.ts +11 -10
  33. package/src/plugin/plugin-repl.ts +74 -0
  34. package/src/runtime.ts +2 -28
  35. package/src/scrypted-main.ts +24 -17
  36. package/src/services/plugin.ts +8 -0
  37. package/src/state.ts +1 -1
  38. package/test/test-cert.json +4 -0
@@ -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', () => {
76
+ const destroy = () => {
81
77
  socket.destroy();
82
78
  target.destroy();
83
- });
84
- target.on('error', e => {
85
- console.error('debugger target error', e);
86
- socket.destroy();
87
- 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();
@@ -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
  }
package/src/state.ts CHANGED
@@ -236,7 +236,7 @@ export function setState(pluginDevice: PluginDevice, property: string, value: an
236
236
  }
237
237
 
238
238
  export function getState(pluginDevice: PluginDevice, property: string): any {
239
- const ret = pluginDevice.state[property]?.value;
239
+ const ret = pluginDevice.state?.[property]?.value;
240
240
  if (typeof ret === 'object')
241
241
  return JSON.parse(JSON.stringify(ret));
242
242
  return ret;
@@ -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//2PK82KYHl2WVNpJtwxrL\r\nWjh5JuucTfREedNbxySrXWwH6/n1Yqoe0TRuiWpGLVJoUcqf+2RDXTeDAcSzIHtG\r\nFekF3TqerJFLZMARZ4cjRPm1MGcprnn03fNB8deLAw2Fhf/VSdgjB+KZkAFQLrS2\r\n+k48wp8G9k8fDnj/83Y6Bn4FpZidbPVKryOjvwjuukFfqTus1ag7MVAy/VbzGSPp\r\nfDbQFv6bbS+7YQ4/ycYjLmP73AAxu4h7ggGybpTaAQK2H2pMKHHQB3DOyTFf80Yi\r\n/aujghkCgYEA9X/IV20lQMkU+te8KEQTYpr1XT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