@scrypted/server 0.0.114 → 0.0.119
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.
- package/.vscode/launch.json +1 -0
- package/dist/http-interfaces.js +11 -4
- package/dist/http-interfaces.js.map +1 -1
- package/dist/level.js.map +1 -1
- package/dist/plugin/media.js +3 -3
- package/dist/plugin/media.js.map +1 -1
- package/dist/plugin/plugin-console.js.map +1 -1
- package/dist/plugin/plugin-device.js +25 -0
- package/dist/plugin/plugin-device.js.map +1 -1
- package/dist/plugin/plugin-host-api.js +2 -2
- package/dist/plugin/plugin-host-api.js.map +1 -1
- package/dist/plugin/plugin-host.js +110 -226
- package/dist/plugin/plugin-host.js.map +1 -1
- package/dist/plugin/plugin-lazy-remote.js.map +1 -1
- package/dist/plugin/plugin-remote-worker.js +252 -0
- package/dist/plugin/plugin-remote-worker.js.map +1 -0
- package/dist/plugin/plugin-remote.js +39 -15
- package/dist/plugin/plugin-remote.js.map +1 -1
- package/dist/plugin/plugin-repl.js +3 -1
- package/dist/plugin/plugin-repl.js.map +1 -1
- package/dist/plugin/system.js +11 -6
- package/dist/plugin/system.js.map +1 -1
- package/dist/rpc.js +22 -3
- package/dist/rpc.js.map +1 -1
- package/dist/runtime.js +19 -4
- package/dist/runtime.js.map +1 -1
- package/dist/scrypted-main.js +4 -437
- package/dist/scrypted-main.js.map +1 -1
- package/dist/scrypted-plugin-main.js +8 -0
- package/dist/scrypted-plugin-main.js.map +1 -0
- package/dist/scrypted-server-main.js +448 -0
- package/dist/scrypted-server-main.js.map +1 -0
- package/package.json +7 -6
- package/python/media.py +1 -12
- package/python/plugin-remote.py +22 -7
- package/python/rpc.py +5 -4
- package/src/http-interfaces.ts +12 -5
- package/src/level.ts +0 -2
- package/src/plugin/media.ts +3 -3
- package/src/plugin/plugin-api.ts +9 -1
- package/src/plugin/plugin-console.ts +0 -1
- package/src/plugin/plugin-device.ts +26 -2
- package/src/plugin/plugin-host-api.ts +2 -2
- package/src/plugin/plugin-host.ts +121 -252
- package/src/plugin/plugin-http.ts +2 -2
- package/src/plugin/plugin-lazy-remote.ts +1 -1
- package/src/plugin/plugin-remote-worker.ts +271 -0
- package/src/plugin/plugin-remote.ts +46 -17
- package/src/plugin/plugin-repl.ts +4 -2
- package/src/plugin/system.ts +15 -13
- package/src/rpc.ts +28 -4
- package/src/runtime.ts +19 -4
- package/src/scrypted-main.ts +5 -508
- package/src/scrypted-plugin-main.ts +6 -0
- package/src/scrypted-server-main.ts +516 -0
|
@@ -0,0 +1,448 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const path_1 = __importDefault(require("path"));
|
|
7
|
+
const process_1 = __importDefault(require("process"));
|
|
8
|
+
const http_1 = __importDefault(require("http"));
|
|
9
|
+
const https_1 = __importDefault(require("https"));
|
|
10
|
+
const express_1 = __importDefault(require("express"));
|
|
11
|
+
const body_parser_1 = __importDefault(require("body-parser"));
|
|
12
|
+
const net_1 = __importDefault(require("net"));
|
|
13
|
+
const runtime_1 = require("./runtime");
|
|
14
|
+
const level_1 = __importDefault(require("./level"));
|
|
15
|
+
const db_types_1 = require("./db-types");
|
|
16
|
+
const server_settings_1 = require("./server-settings");
|
|
17
|
+
const crypto_1 = __importDefault(require("crypto"));
|
|
18
|
+
const cookie_parser_1 = __importDefault(require("cookie-parser"));
|
|
19
|
+
const axios_1 = __importDefault(require("axios"));
|
|
20
|
+
const query_string_1 = __importDefault(require("query-string"));
|
|
21
|
+
const rpc_1 = require("./rpc");
|
|
22
|
+
const fs_1 = __importDefault(require("fs"));
|
|
23
|
+
const mkdirp_1 = __importDefault(require("mkdirp"));
|
|
24
|
+
const source_map_support_1 = require("source-map-support");
|
|
25
|
+
const http_auth_1 = __importDefault(require("http-auth"));
|
|
26
|
+
const semver_1 = __importDefault(require("semver"));
|
|
27
|
+
const info_1 = require("./services/info");
|
|
28
|
+
const addresses_1 = require("./addresses");
|
|
29
|
+
const sleep_1 = require("./sleep");
|
|
30
|
+
const cert_1 = require("./cert");
|
|
31
|
+
const plugin_error_1 = require("./plugin/plugin-error");
|
|
32
|
+
const plugin_volume_1 = require("./plugin/plugin-volume");
|
|
33
|
+
if (!semver_1.default.gte(process_1.default.version, '16.0.0')) {
|
|
34
|
+
throw new Error('"node" version out of date. Please update node to v16 or higher.');
|
|
35
|
+
}
|
|
36
|
+
process_1.default.on('unhandledRejection', error => {
|
|
37
|
+
if (error?.constructor !== rpc_1.RPCResultError && error?.constructor !== plugin_error_1.PluginError) {
|
|
38
|
+
throw error;
|
|
39
|
+
}
|
|
40
|
+
console.warn('unhandled rejection of RPC Result', error);
|
|
41
|
+
});
|
|
42
|
+
function listenServerPort(env, port, server) {
|
|
43
|
+
server.listen(port);
|
|
44
|
+
server.on('error', (e) => {
|
|
45
|
+
console.error(`Failed to listen on port ${port}. It may be in use.`);
|
|
46
|
+
console.error(`Use the environment variable ${env} to change the port.`);
|
|
47
|
+
throw e;
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
(0, source_map_support_1.install)({
|
|
51
|
+
environment: 'node',
|
|
52
|
+
});
|
|
53
|
+
let workerInspectPort = undefined;
|
|
54
|
+
async function doconnect() {
|
|
55
|
+
return new Promise((resolve, reject) => {
|
|
56
|
+
const target = net_1.default.connect(workerInspectPort);
|
|
57
|
+
target.once('error', reject);
|
|
58
|
+
target.once('connect', () => resolve(target));
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
const debugServer = net_1.default.createServer(async (socket) => {
|
|
62
|
+
if (!workerInspectPort) {
|
|
63
|
+
socket.destroy();
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
for (let i = 0; i < 10; i++) {
|
|
67
|
+
try {
|
|
68
|
+
const target = await doconnect();
|
|
69
|
+
socket.pipe(target).pipe(socket);
|
|
70
|
+
const destroy = () => {
|
|
71
|
+
socket.destroy();
|
|
72
|
+
target.destroy();
|
|
73
|
+
};
|
|
74
|
+
socket.on('error', destroy);
|
|
75
|
+
target.on('error', destroy);
|
|
76
|
+
socket.on('close', destroy);
|
|
77
|
+
target.on('close', destroy);
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
catch (e) {
|
|
81
|
+
await (0, sleep_1.sleep)(500);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
console.warn('debugger connect timed out');
|
|
85
|
+
socket.destroy();
|
|
86
|
+
});
|
|
87
|
+
listenServerPort('SCRYPTED_DEBUG_PORT', server_settings_1.SCRYPTED_DEBUG_PORT, debugServer);
|
|
88
|
+
const app = (0, express_1.default)();
|
|
89
|
+
// parse application/x-www-form-urlencoded
|
|
90
|
+
app.use(body_parser_1.default.urlencoded({ extended: false }));
|
|
91
|
+
// parse application/json
|
|
92
|
+
app.use(body_parser_1.default.json());
|
|
93
|
+
// parse some custom thing into a Buffer
|
|
94
|
+
app.use(body_parser_1.default.raw({ type: 'application/zip', limit: 100000000 }));
|
|
95
|
+
async function start() {
|
|
96
|
+
const volumeDir = (0, plugin_volume_1.getScryptedVolume)();
|
|
97
|
+
mkdirp_1.default.sync(volumeDir);
|
|
98
|
+
const dbPath = path_1.default.join(volumeDir, 'scrypted.db');
|
|
99
|
+
const db = (0, level_1.default)(dbPath);
|
|
100
|
+
await db.open();
|
|
101
|
+
if (process_1.default.env.SCRYPTED_RESET_ALL_USERS === 'true') {
|
|
102
|
+
await db.removeAll(db_types_1.ScryptedUser);
|
|
103
|
+
}
|
|
104
|
+
let certSetting = await db.tryGet(db_types_1.Settings, 'certificate');
|
|
105
|
+
if (certSetting?.value?.version !== cert_1.CURRENT_SELF_SIGNED_CERTIFICATE_VERSION) {
|
|
106
|
+
const cert = (0, cert_1.createSelfSignedCertificate)();
|
|
107
|
+
certSetting = new db_types_1.Settings();
|
|
108
|
+
certSetting._id = 'certificate';
|
|
109
|
+
certSetting.value = cert;
|
|
110
|
+
certSetting = await db.upsert(certSetting);
|
|
111
|
+
}
|
|
112
|
+
const basicAuth = http_auth_1.default.basic({
|
|
113
|
+
realm: 'Scrypted',
|
|
114
|
+
}, async (username, password, callback) => {
|
|
115
|
+
const user = await db.tryGet(db_types_1.ScryptedUser, username);
|
|
116
|
+
if (!user) {
|
|
117
|
+
callback(false);
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
const salted = user.salt + password;
|
|
121
|
+
const hash = crypto_1.default.createHash('sha256');
|
|
122
|
+
hash.update(salted);
|
|
123
|
+
const sha = hash.digest().toString('hex');
|
|
124
|
+
callback(sha === user.passwordHash || password === user.token);
|
|
125
|
+
});
|
|
126
|
+
const keys = certSetting.value;
|
|
127
|
+
const httpsServerOptions = process_1.default.env.SCRYPTED_HTTPS_OPTIONS_FILE
|
|
128
|
+
? JSON.parse(fs_1.default.readFileSync(process_1.default.env.SCRYPTED_HTTPS_OPTIONS_FILE).toString())
|
|
129
|
+
: {};
|
|
130
|
+
const mergedHttpsServerOptions = Object.assign({
|
|
131
|
+
key: keys.serviceKey,
|
|
132
|
+
cert: keys.certificate
|
|
133
|
+
}, httpsServerOptions);
|
|
134
|
+
const secure = https_1.default.createServer(mergedHttpsServerOptions, app);
|
|
135
|
+
listenServerPort('SCRYPTED_SECURE_PORT', server_settings_1.SCRYPTED_SECURE_PORT, secure);
|
|
136
|
+
const insecure = http_1.default.createServer(app);
|
|
137
|
+
listenServerPort('SCRYPTED_INSECURE_PORT', server_settings_1.SCRYPTED_INSECURE_PORT, insecure);
|
|
138
|
+
// legacy secure port 9443 is now in use by portainer.
|
|
139
|
+
let shownLegacyPortAlert = false;
|
|
140
|
+
const legacySecure = https_1.default.createServer(mergedHttpsServerOptions, (req, res) => {
|
|
141
|
+
if (!shownLegacyPortAlert) {
|
|
142
|
+
const core = scrypted.findPluginDevice('@scrypted/core');
|
|
143
|
+
if (core) {
|
|
144
|
+
const logger = scrypted.getDeviceLogger(core);
|
|
145
|
+
shownLegacyPortAlert = true;
|
|
146
|
+
const host = (req.headers.host || 'localhost').split(':')[0];
|
|
147
|
+
const newUrl = `https://${host}:${server_settings_1.SCRYPTED_SECURE_PORT}`;
|
|
148
|
+
logger.log('a', `Due to a port conflict with Portainer, the default Scrypted URL has changed to ${newUrl}`);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
app(req, res);
|
|
152
|
+
});
|
|
153
|
+
legacySecure.listen(9443);
|
|
154
|
+
legacySecure.on('error', () => {
|
|
155
|
+
// can ignore.
|
|
156
|
+
});
|
|
157
|
+
// use a hash of the private key as the cookie secret.
|
|
158
|
+
app.use((0, cookie_parser_1.default)(crypto_1.default.createHash('sha256').update(certSetting.value.serviceKey).digest().toString('hex')));
|
|
159
|
+
app.all('*', async (req, res, next) => {
|
|
160
|
+
// this is a trap for all auth.
|
|
161
|
+
// only basic auth will fail with 401. it is up to the endpoints to manage
|
|
162
|
+
// lack of login from cookie auth.
|
|
163
|
+
const { login_user_token } = req.signedCookies;
|
|
164
|
+
if (login_user_token) {
|
|
165
|
+
const userTokenParts = login_user_token.split('#');
|
|
166
|
+
const username = userTokenParts[0];
|
|
167
|
+
const timestamp = parseInt(userTokenParts[1]);
|
|
168
|
+
if (timestamp + 86400000 < Date.now()) {
|
|
169
|
+
console.warn('login expired');
|
|
170
|
+
return next();
|
|
171
|
+
}
|
|
172
|
+
const user = await db.tryGet(db_types_1.ScryptedUser, username);
|
|
173
|
+
if (!user) {
|
|
174
|
+
console.warn('login not found');
|
|
175
|
+
return next();
|
|
176
|
+
}
|
|
177
|
+
res.locals.username = username;
|
|
178
|
+
}
|
|
179
|
+
next();
|
|
180
|
+
});
|
|
181
|
+
// allow basic auth to deploy plugins
|
|
182
|
+
app.all('/web/component/*', (req, res, next) => {
|
|
183
|
+
if (req.protocol === 'https' && req.headers.authorization && req.headers.authorization.toLowerCase()?.indexOf('basic') !== -1) {
|
|
184
|
+
const basicChecker = basicAuth.check((req) => {
|
|
185
|
+
res.locals.username = req.user;
|
|
186
|
+
next();
|
|
187
|
+
});
|
|
188
|
+
// this automatically handles unauthorized.
|
|
189
|
+
basicChecker(req, res);
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
next();
|
|
193
|
+
});
|
|
194
|
+
// verify all plugin related requests have some sort of auth
|
|
195
|
+
app.all('/web/component/*', (req, res, next) => {
|
|
196
|
+
if (!res.locals.username) {
|
|
197
|
+
res.status(401);
|
|
198
|
+
res.send('Not Authorized');
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
next();
|
|
202
|
+
});
|
|
203
|
+
console.log('#######################################################');
|
|
204
|
+
console.log(`Scrypted Server (Local) : https://localhost:${server_settings_1.SCRYPTED_SECURE_PORT}/`);
|
|
205
|
+
for (const address of (0, addresses_1.getAddresses)()) {
|
|
206
|
+
console.log(`Scrypted Server (Remote) : https://${address}:${server_settings_1.SCRYPTED_SECURE_PORT}/`);
|
|
207
|
+
}
|
|
208
|
+
console.log(`Version: : ${await new info_1.Info().getVersion()}`);
|
|
209
|
+
console.log('#######################################################');
|
|
210
|
+
console.log('Chrome Users: You may need to type "thisisunsafe" into');
|
|
211
|
+
console.log(' the window to bypass the warning. There');
|
|
212
|
+
console.log(' may be no button to continue, type the');
|
|
213
|
+
console.log(' letters "thisisunsafe" and it will proceed.');
|
|
214
|
+
console.log('#######################################################');
|
|
215
|
+
console.log('Scrypted insecure http service port:', server_settings_1.SCRYPTED_INSECURE_PORT);
|
|
216
|
+
console.log('Ports can be changed with environment variables.');
|
|
217
|
+
console.log('https: $SCRYPTED_SECURE_PORT');
|
|
218
|
+
console.log('http : $SCRYPTED_INSECURE_PORT');
|
|
219
|
+
console.log('Certificate can be modified via tls.createSecureContext options in');
|
|
220
|
+
console.log('JSON file located at SCRYPTED_HTTPS_OPTIONS_FILE environment variable:');
|
|
221
|
+
console.log('export SCRYPTED_HTTPS_OPTIONS_FILE=/path/to/options.json');
|
|
222
|
+
console.log('https://nodejs.org/api/tls.html#tlscreatesecurecontextoptions');
|
|
223
|
+
console.log('#######################################################');
|
|
224
|
+
const scrypted = new runtime_1.ScryptedRuntime(db, insecure, secure, app);
|
|
225
|
+
await scrypted.start();
|
|
226
|
+
app.get(['/web/component/script/npm/:pkg', '/web/component/script/npm/@:owner/:pkg'], async (req, res) => {
|
|
227
|
+
const { owner, pkg } = req.params;
|
|
228
|
+
let endpoint = pkg;
|
|
229
|
+
if (owner)
|
|
230
|
+
endpoint = `@${owner}/${endpoint}`;
|
|
231
|
+
try {
|
|
232
|
+
const response = await (0, axios_1.default)(`https://registry.npmjs.org/${endpoint}`);
|
|
233
|
+
res.send(response.data);
|
|
234
|
+
}
|
|
235
|
+
catch (e) {
|
|
236
|
+
res.status(500);
|
|
237
|
+
res.end();
|
|
238
|
+
}
|
|
239
|
+
});
|
|
240
|
+
app.post(['/web/component/script/install/:pkg', '/web/component/script/install/@:owner/:pkg', '/web/component/script/install/@:owner/:pkg/:tag'], async (req, res) => {
|
|
241
|
+
const { owner, pkg, tag } = req.params;
|
|
242
|
+
let endpoint = pkg;
|
|
243
|
+
if (owner)
|
|
244
|
+
endpoint = `@${owner}/${endpoint}`;
|
|
245
|
+
try {
|
|
246
|
+
const plugin = await scrypted.installNpm(endpoint, tag);
|
|
247
|
+
res.send({
|
|
248
|
+
id: scrypted.findPluginDevice(plugin.pluginId)._id,
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
catch (e) {
|
|
252
|
+
res.status(500);
|
|
253
|
+
res.end();
|
|
254
|
+
}
|
|
255
|
+
});
|
|
256
|
+
app.get('/web/component/script/search', async (req, res) => {
|
|
257
|
+
try {
|
|
258
|
+
const query = query_string_1.default.stringify({
|
|
259
|
+
text: req.query.text,
|
|
260
|
+
});
|
|
261
|
+
const response = await (0, axios_1.default)(`https://registry.npmjs.org/-/v1/search?${query}`);
|
|
262
|
+
res.send(response.data);
|
|
263
|
+
}
|
|
264
|
+
catch (e) {
|
|
265
|
+
res.status(500);
|
|
266
|
+
res.end();
|
|
267
|
+
}
|
|
268
|
+
});
|
|
269
|
+
app.post('/web/component/script/setup', async (req, res) => {
|
|
270
|
+
const npmPackage = req.query.npmPackage;
|
|
271
|
+
const plugin = await db.tryGet(db_types_1.Plugin, npmPackage) || new db_types_1.Plugin();
|
|
272
|
+
plugin._id = npmPackage;
|
|
273
|
+
plugin.packageJson = req.body;
|
|
274
|
+
await db.upsert(plugin);
|
|
275
|
+
res.send('ok');
|
|
276
|
+
});
|
|
277
|
+
app.post('/web/component/script/deploy', async (req, res) => {
|
|
278
|
+
const npmPackage = req.query.npmPackage;
|
|
279
|
+
const plugin = await db.tryGet(db_types_1.Plugin, npmPackage);
|
|
280
|
+
if (!plugin) {
|
|
281
|
+
res.status(500);
|
|
282
|
+
res.send(`npm package ${npmPackage} not found`);
|
|
283
|
+
return;
|
|
284
|
+
}
|
|
285
|
+
plugin.zip = req.body.toString('base64');
|
|
286
|
+
await db.upsert(plugin);
|
|
287
|
+
const noRebind = req.query['no-rebind'] !== undefined;
|
|
288
|
+
if (!noRebind)
|
|
289
|
+
await scrypted.installPlugin(plugin);
|
|
290
|
+
res.send('ok');
|
|
291
|
+
});
|
|
292
|
+
app.post('/web/component/script/debug', async (req, res) => {
|
|
293
|
+
const npmPackage = req.query.npmPackage;
|
|
294
|
+
const plugin = await db.tryGet(db_types_1.Plugin, npmPackage);
|
|
295
|
+
if (!plugin) {
|
|
296
|
+
res.status(500);
|
|
297
|
+
res.send(`npm package ${npmPackage} not found`);
|
|
298
|
+
return;
|
|
299
|
+
}
|
|
300
|
+
const waitDebug = new Promise((resolve, reject) => {
|
|
301
|
+
setTimeout(() => reject(new Error('timed out waiting for debug session')), 30000);
|
|
302
|
+
debugServer.on('connection', resolve);
|
|
303
|
+
});
|
|
304
|
+
workerInspectPort = Math.round(Math.random() * 10000) + 30000;
|
|
305
|
+
try {
|
|
306
|
+
await scrypted.installPlugin(plugin, {
|
|
307
|
+
waitDebug,
|
|
308
|
+
inspectPort: workerInspectPort,
|
|
309
|
+
});
|
|
310
|
+
}
|
|
311
|
+
catch (e) {
|
|
312
|
+
res.status(500);
|
|
313
|
+
res.send(e.toString());
|
|
314
|
+
return;
|
|
315
|
+
}
|
|
316
|
+
res.send({
|
|
317
|
+
workerInspectPort,
|
|
318
|
+
});
|
|
319
|
+
});
|
|
320
|
+
app.get('/logout', (req, res) => {
|
|
321
|
+
res.clearCookie('login_user_token');
|
|
322
|
+
res.send({});
|
|
323
|
+
});
|
|
324
|
+
app.post('/login', async (req, res) => {
|
|
325
|
+
const hasLogin = await db.getCount(db_types_1.ScryptedUser) > 0;
|
|
326
|
+
const { username, password, change_password } = req.body;
|
|
327
|
+
const timestamp = Date.now();
|
|
328
|
+
const maxAge = 86400000;
|
|
329
|
+
if (hasLogin) {
|
|
330
|
+
const user = await db.tryGet(db_types_1.ScryptedUser, username);
|
|
331
|
+
if (!user) {
|
|
332
|
+
res.send({
|
|
333
|
+
error: 'User does not exist.',
|
|
334
|
+
hasLogin,
|
|
335
|
+
});
|
|
336
|
+
return;
|
|
337
|
+
}
|
|
338
|
+
const salted = user.salt + password;
|
|
339
|
+
const hash = crypto_1.default.createHash('sha256');
|
|
340
|
+
hash.update(salted);
|
|
341
|
+
const sha = hash.digest().toString('hex');
|
|
342
|
+
if (user.passwordHash !== sha) {
|
|
343
|
+
res.send({
|
|
344
|
+
error: 'Incorrect password.',
|
|
345
|
+
hasLogin,
|
|
346
|
+
});
|
|
347
|
+
return;
|
|
348
|
+
}
|
|
349
|
+
const login_user_token = `${username}#${timestamp}`;
|
|
350
|
+
res.cookie('login_user_token', login_user_token, {
|
|
351
|
+
maxAge,
|
|
352
|
+
secure: true,
|
|
353
|
+
signed: true,
|
|
354
|
+
httpOnly: true,
|
|
355
|
+
});
|
|
356
|
+
if (change_password) {
|
|
357
|
+
user.salt = crypto_1.default.randomBytes(64).toString('base64');
|
|
358
|
+
user.passwordHash = crypto_1.default.createHash('sha256').update(user.salt + change_password).digest().toString('hex');
|
|
359
|
+
user.passwordDate = timestamp;
|
|
360
|
+
await db.upsert(user);
|
|
361
|
+
}
|
|
362
|
+
res.send({
|
|
363
|
+
username,
|
|
364
|
+
expiration: maxAge,
|
|
365
|
+
});
|
|
366
|
+
return;
|
|
367
|
+
}
|
|
368
|
+
const user = new db_types_1.ScryptedUser();
|
|
369
|
+
user._id = username;
|
|
370
|
+
user.salt = crypto_1.default.randomBytes(64).toString('base64');
|
|
371
|
+
user.passwordHash = crypto_1.default.createHash('sha256').update(user.salt + password).digest().toString('hex');
|
|
372
|
+
user.passwordDate = timestamp;
|
|
373
|
+
await db.upsert(user);
|
|
374
|
+
const login_user_token = `${username}#${timestamp}`;
|
|
375
|
+
res.cookie('login_user_token', login_user_token, {
|
|
376
|
+
maxAge,
|
|
377
|
+
secure: true,
|
|
378
|
+
signed: true,
|
|
379
|
+
httpOnly: true,
|
|
380
|
+
});
|
|
381
|
+
res.send({
|
|
382
|
+
username,
|
|
383
|
+
expiration: maxAge,
|
|
384
|
+
});
|
|
385
|
+
});
|
|
386
|
+
app.get('/login', async (req, res) => {
|
|
387
|
+
if (req.protocol === 'https' && req.headers.authorization) {
|
|
388
|
+
const username = await new Promise(resolve => {
|
|
389
|
+
const basicChecker = basicAuth.check((req) => {
|
|
390
|
+
resolve(req.user);
|
|
391
|
+
});
|
|
392
|
+
// this automatically handles unauthorized.
|
|
393
|
+
basicChecker(req, res);
|
|
394
|
+
});
|
|
395
|
+
const user = await db.tryGet(db_types_1.ScryptedUser, username);
|
|
396
|
+
if (!user.token) {
|
|
397
|
+
user.token = crypto_1.default.randomBytes(16).toString('hex');
|
|
398
|
+
await db.upsert(user);
|
|
399
|
+
}
|
|
400
|
+
res.send({
|
|
401
|
+
username,
|
|
402
|
+
token: user.token,
|
|
403
|
+
});
|
|
404
|
+
return;
|
|
405
|
+
}
|
|
406
|
+
const hasLogin = await db.getCount(db_types_1.ScryptedUser) > 0;
|
|
407
|
+
const { login_user_token } = req.signedCookies;
|
|
408
|
+
if (!login_user_token) {
|
|
409
|
+
res.send({
|
|
410
|
+
error: 'Not logged in.',
|
|
411
|
+
hasLogin,
|
|
412
|
+
});
|
|
413
|
+
return;
|
|
414
|
+
}
|
|
415
|
+
const userTokenParts = login_user_token.split('#');
|
|
416
|
+
const username = userTokenParts[0];
|
|
417
|
+
const timestamp = parseInt(userTokenParts[1]);
|
|
418
|
+
if (timestamp + 86400000 < Date.now()) {
|
|
419
|
+
res.send({
|
|
420
|
+
error: 'Login expired.',
|
|
421
|
+
hasLogin,
|
|
422
|
+
});
|
|
423
|
+
return;
|
|
424
|
+
}
|
|
425
|
+
const user = await db.tryGet(db_types_1.ScryptedUser, username);
|
|
426
|
+
if (!user) {
|
|
427
|
+
res.send({
|
|
428
|
+
error: 'User not found.',
|
|
429
|
+
hasLogin,
|
|
430
|
+
});
|
|
431
|
+
return;
|
|
432
|
+
}
|
|
433
|
+
if (timestamp < user.passwordDate) {
|
|
434
|
+
res.send({
|
|
435
|
+
error: 'Login invalid. Password has changed.',
|
|
436
|
+
hasLogin,
|
|
437
|
+
});
|
|
438
|
+
return;
|
|
439
|
+
}
|
|
440
|
+
res.send({
|
|
441
|
+
expiration: 86400000 - (Date.now() - timestamp),
|
|
442
|
+
username,
|
|
443
|
+
});
|
|
444
|
+
});
|
|
445
|
+
app.get('/', (_req, res) => res.redirect('/endpoint/@scrypted/core/public/'));
|
|
446
|
+
}
|
|
447
|
+
start();
|
|
448
|
+
//# sourceMappingURL=scrypted-server-main.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scrypted-server-main.js","sourceRoot":"","sources":["../src/scrypted-server-main.ts"],"names":[],"mappings":";;;;;AAAA,gDAAwB;AACxB,sDAA8B;AAC9B,gDAAwB;AACxB,kDAA0B;AAC1B,sDAA8B;AAC9B,8DAAqC;AACrC,8CAAsB;AACtB,uCAA4C;AAC5C,oDAA4B;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E,EAAE,CAAC,GAAG,CAAC,QAAQ,CAAC,kCAAkC,CAAC,CAAC,CAAC;AAClF,CAAC;AAED,KAAK,EAAE,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@scrypted/server",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.119",
|
|
4
4
|
"description": "",
|
|
5
5
|
"dependencies": {
|
|
6
|
-
"@
|
|
6
|
+
"@mapbox/node-pre-gyp": "^1.0.5",
|
|
7
|
+
"@scrypted/ffmpeg": "^1.0.9",
|
|
8
|
+
"@scrypted/sdk": "^0.0.134",
|
|
7
9
|
"adm-zip": "^0.5.3",
|
|
8
10
|
"axios": "^0.21.1",
|
|
9
11
|
"body-parser": "^1.19.0",
|
|
@@ -13,11 +15,12 @@
|
|
|
13
15
|
"express": "^4.17.1",
|
|
14
16
|
"http-auth": "^4.1.9",
|
|
15
17
|
"level": "^6.0.1",
|
|
18
|
+
"linkfs": "^2.1.0",
|
|
16
19
|
"lodash": "^4.17.21",
|
|
17
20
|
"memfs": "^3.2.2",
|
|
18
21
|
"mkdirp": "^1.0.4",
|
|
19
22
|
"node-dijkstra": "^2.5.0",
|
|
20
|
-
"node-forge": "^
|
|
23
|
+
"node-forge": "^1.2.0",
|
|
21
24
|
"node-pty": "^0.10.1",
|
|
22
25
|
"query-string": "^6.14.1",
|
|
23
26
|
"semver": "^7.3.5",
|
|
@@ -31,11 +34,9 @@
|
|
|
31
34
|
},
|
|
32
35
|
"optionalDependencies": {
|
|
33
36
|
"@koush/wrtc": "^0.5.2",
|
|
34
|
-
"ffmpeg-for-homebridge": "^0.0.9",
|
|
35
37
|
"mdns": "^2.7.2"
|
|
36
38
|
},
|
|
37
39
|
"devDependencies": {
|
|
38
|
-
"@mapbox/node-pre-gyp": "^1.0.5",
|
|
39
40
|
"@types/adm-zip": "^0.4.33",
|
|
40
41
|
"@types/cookie-parser": "^1.4.2",
|
|
41
42
|
"@types/debug": "^4.1.5",
|
|
@@ -45,7 +46,7 @@
|
|
|
45
46
|
"@types/lodash": "^4.14.168",
|
|
46
47
|
"@types/mkdirp": "^1.0.2",
|
|
47
48
|
"@types/node-dijkstra": "^2.5.1",
|
|
48
|
-
"@types/node-forge": "^0.
|
|
49
|
+
"@types/node-forge": "^1.0.0",
|
|
49
50
|
"@types/pem": "^1.9.5",
|
|
50
51
|
"@types/rimraf": "^3.0.2",
|
|
51
52
|
"@types/semver": "^7.3.8",
|
package/python/media.py
CHANGED
|
@@ -1,18 +1,7 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
import scrypted_python.scrypted_sdk
|
|
3
|
-
from scrypted_python.scrypted_sdk.types import MediaObject
|
|
4
|
-
from collections.abc import Mapping
|
|
5
|
-
from genericpath import exists
|
|
6
|
-
import asyncio
|
|
7
|
-
import json
|
|
8
|
-
import aiofiles
|
|
3
|
+
from scrypted_python.scrypted_sdk.types import MediaObject
|
|
9
4
|
import os
|
|
10
|
-
from typing_extensions import TypedDict
|
|
11
|
-
import base64
|
|
12
|
-
from os import sys
|
|
13
|
-
import time
|
|
14
|
-
import zipfile
|
|
15
|
-
import subprocess
|
|
16
5
|
from typing import Any
|
|
17
6
|
|
|
18
7
|
class MediaObjectRemote:
|
package/python/plugin-remote.py
CHANGED
|
@@ -13,15 +13,16 @@ import json
|
|
|
13
13
|
from asyncio.events import AbstractEventLoop
|
|
14
14
|
import asyncio
|
|
15
15
|
import rpc
|
|
16
|
-
from genericpath import exists
|
|
17
16
|
from collections.abc import Mapping
|
|
18
|
-
from scrypted_python.scrypted_sdk.types import DeviceManifest, MediaManager,
|
|
17
|
+
from scrypted_python.scrypted_sdk.types import DeviceManifest, MediaManager, ScryptedInterfaceProperty
|
|
19
18
|
import scrypted_python.scrypted_sdk
|
|
20
19
|
from asyncio.futures import Future
|
|
21
20
|
from asyncio.streams import StreamReader, StreamWriter
|
|
22
21
|
import os
|
|
23
22
|
from os import sys
|
|
24
23
|
import platform
|
|
24
|
+
import shutil
|
|
25
|
+
import gc
|
|
25
26
|
|
|
26
27
|
class SystemDeviceState(TypedDict):
|
|
27
28
|
lastEventTime: int
|
|
@@ -156,11 +157,19 @@ class PluginRemote:
|
|
|
156
157
|
nativeId, *values, sep=sep, end=end, flush=flush), self.loop)
|
|
157
158
|
|
|
158
159
|
async def loadZip(self, packageJson, zipData, options=None):
|
|
159
|
-
zipPath
|
|
160
|
+
zipPath: str
|
|
160
161
|
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
162
|
+
if isinstance(zipData, str):
|
|
163
|
+
zipPath = (options and options.get('filename', None)) or zipData
|
|
164
|
+
if zipPath != zipData:
|
|
165
|
+
shutil.copyfile(zipData, zipPath)
|
|
166
|
+
else:
|
|
167
|
+
zipPath = options['filename']
|
|
168
|
+
f = open(zipPath, 'wb')
|
|
169
|
+
f.write(zipData)
|
|
170
|
+
f.close()
|
|
171
|
+
|
|
172
|
+
zipData = None
|
|
164
173
|
|
|
165
174
|
zip = zipfile.ZipFile(zipPath)
|
|
166
175
|
|
|
@@ -278,7 +287,7 @@ async def readLoop(loop, peer, reader):
|
|
|
278
287
|
asyncio.run_coroutine_threadsafe(peer.handleMessage(message), loop)
|
|
279
288
|
except Exception as e:
|
|
280
289
|
print('read loop error', e)
|
|
281
|
-
|
|
290
|
+
sys.exit()
|
|
282
291
|
|
|
283
292
|
|
|
284
293
|
async def async_main(loop: AbstractEventLoop):
|
|
@@ -305,6 +314,12 @@ async def async_main(loop: AbstractEventLoop):
|
|
|
305
314
|
|
|
306
315
|
def main():
|
|
307
316
|
loop = asyncio.get_event_loop()
|
|
317
|
+
|
|
318
|
+
def gc_runner():
|
|
319
|
+
gc.collect()
|
|
320
|
+
loop.call_later(10, gc_runner)
|
|
321
|
+
gc_runner()
|
|
322
|
+
|
|
308
323
|
loop.run_until_complete(async_main(loop))
|
|
309
324
|
loop.close()
|
|
310
325
|
|
package/python/rpc.py
CHANGED
|
@@ -308,8 +308,8 @@ class RpcPeer:
|
|
|
308
308
|
|
|
309
309
|
result['result'] = self.serialize(value, False)
|
|
310
310
|
except Exception as e:
|
|
311
|
-
print('failure', method, e)
|
|
312
311
|
tb = traceback.format_exc()
|
|
312
|
+
print('failure', method, e, tb)
|
|
313
313
|
self.createErrorResult(
|
|
314
314
|
result, type(e).__name__, str(e), tb)
|
|
315
315
|
|
|
@@ -317,11 +317,12 @@ class RpcPeer:
|
|
|
317
317
|
self.send(result)
|
|
318
318
|
|
|
319
319
|
elif messageType == 'result':
|
|
320
|
-
|
|
320
|
+
id = message['id']
|
|
321
|
+
future = self.pendingResults.get(id, None)
|
|
321
322
|
if not future:
|
|
322
323
|
raise RpcResultException(
|
|
323
|
-
None, 'unknown result %s' %
|
|
324
|
-
del
|
|
324
|
+
None, 'unknown result %s' % id)
|
|
325
|
+
del self.pendingResults[id]
|
|
325
326
|
if hasattr(message, 'message') or hasattr(message, 'stack'):
|
|
326
327
|
e = RpcResultException(
|
|
327
328
|
None, message.get('message', None))
|