iobroker.eusec 1.1.0 → 1.1.2
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.
- package/README.md +13 -0
- package/admin/i18n/uk/translations.json +26 -0
- package/build/lib/interfaces.js +16 -2
- package/build/lib/interfaces.js.map +7 -1
- package/build/lib/log.js +70 -48
- package/build/lib/log.js.map +7 -1
- package/build/lib/tools.js +79 -84
- package/build/lib/tools.js.map +7 -1
- package/build/lib/types.js +92 -61
- package/build/lib/types.js.map +7 -1
- package/build/lib/utils.js +239 -234
- package/build/lib/utils.js.map +7 -1
- package/build/lib/video.js +243 -258
- package/build/lib/video.js.map +7 -1
- package/build/lib/web.js +58 -84
- package/build/lib/web.js.map +7 -1
- package/build/main.js +1177 -1421
- package/build/main.js.map +7 -1
- package/io-package.json +32 -4
- package/package.json +20 -42
package/build/lib/web.js
CHANGED
|
@@ -1,90 +1,64 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
})
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
10
|
+
for (let key of __getOwnPropNames(from))
|
|
11
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
12
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
13
|
+
}
|
|
14
|
+
return to;
|
|
27
15
|
};
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
* Reads files from localhost server
|
|
37
|
-
*
|
|
38
|
-
* @class
|
|
39
|
-
* @param {object} server http or https node.js object
|
|
40
|
-
* @param {object} webSettings settings of the web server, like <pre><code>{secure: settings.secure, port: settings.port}</code></pre>
|
|
41
|
-
* @param {object} adapter web adapter object
|
|
42
|
-
* @param {object} instanceSettings instance object with common and native
|
|
43
|
-
* @param {object} app express application
|
|
44
|
-
* @return {object} object instance
|
|
45
|
-
*/
|
|
16
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
17
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
18
|
+
mod
|
|
19
|
+
));
|
|
20
|
+
var import_path = __toESM(require("path"));
|
|
21
|
+
var import_fs = __toESM(require("fs"));
|
|
22
|
+
var import_mime = __toESM(require("mime"));
|
|
23
|
+
var utils = __toESM(require("@iobroker/adapter-core"));
|
|
46
24
|
class ProxyEufySecurity {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
this.config.route = this.config.route.substr(1);
|
|
56
|
-
}
|
|
57
|
-
const root_path = path_1.default.join(utils.getAbsoluteDefaultDataDir(), this.namespace);
|
|
58
|
-
this.app.use("/" + this.config.route, (req, res) => {
|
|
59
|
-
const fileName = path_1.default.join(root_path, req.url.substring(1));
|
|
60
|
-
const normalized_filename = path_1.default.resolve(fileName);
|
|
61
|
-
if (normalized_filename.startsWith(root_path)) {
|
|
62
|
-
res.setHeader("Access-Control-Allow-Origin", "*");
|
|
63
|
-
res.setHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
|
|
64
|
-
if (fs_1.default.existsSync(normalized_filename)) {
|
|
65
|
-
const stat = fs_1.default.statSync(normalized_filename);
|
|
66
|
-
if (!stat.isDirectory()) {
|
|
67
|
-
let data;
|
|
68
|
-
try {
|
|
69
|
-
data = fs_1.default.readFileSync(normalized_filename);
|
|
70
|
-
}
|
|
71
|
-
catch (e) {
|
|
72
|
-
res.status(500).send(`[eufy-security] Cannot read file: ${e}`);
|
|
73
|
-
return;
|
|
74
|
-
}
|
|
75
|
-
res.contentType(mime_1.default.getType(path_1.default.extname(normalized_filename).substring(1)) || "html");
|
|
76
|
-
res.status(200).send(data);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
else {
|
|
80
|
-
res.status(404).send('[eufy-security] File "' + normalized_filename + '" not found.');
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
else {
|
|
84
|
-
res.status(403).send('[eufy-security] Access to file "' + normalized_filename + '" denied.');
|
|
85
|
-
}
|
|
86
|
-
});
|
|
25
|
+
constructor(server, webSettings, adapter, instanceSettings, app) {
|
|
26
|
+
this.app = app;
|
|
27
|
+
this.config = instanceSettings ? instanceSettings.native : {};
|
|
28
|
+
this.namespace = instanceSettings ? instanceSettings._id.substring("system.adapter.".length) : "eufy-security";
|
|
29
|
+
this.config.route = this.config.route || this.namespace + "/";
|
|
30
|
+
this.config.port = parseInt(this.config.port, 10) || 80;
|
|
31
|
+
if (this.config.route[0] === "/") {
|
|
32
|
+
this.config.route = this.config.route.substr(1);
|
|
87
33
|
}
|
|
34
|
+
const root_path = import_path.default.join(utils.getAbsoluteDefaultDataDir(), this.namespace);
|
|
35
|
+
this.app.use("/" + this.config.route, (req, res) => {
|
|
36
|
+
const fileName = import_path.default.join(root_path, req.url.substring(1));
|
|
37
|
+
const normalized_filename = import_path.default.resolve(fileName);
|
|
38
|
+
if (normalized_filename.startsWith(root_path)) {
|
|
39
|
+
res.setHeader("Access-Control-Allow-Origin", "*");
|
|
40
|
+
res.setHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
|
|
41
|
+
if (import_fs.default.existsSync(normalized_filename)) {
|
|
42
|
+
const stat = import_fs.default.statSync(normalized_filename);
|
|
43
|
+
if (!stat.isDirectory()) {
|
|
44
|
+
let data;
|
|
45
|
+
try {
|
|
46
|
+
data = import_fs.default.readFileSync(normalized_filename);
|
|
47
|
+
} catch (e) {
|
|
48
|
+
res.status(500).send(`[eufy-security] Cannot read file: ${e}`);
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
res.contentType(import_mime.default.getType(import_path.default.extname(normalized_filename).substring(1)) || "html");
|
|
52
|
+
res.status(200).send(data);
|
|
53
|
+
}
|
|
54
|
+
} else {
|
|
55
|
+
res.status(404).send('[eufy-security] File "' + normalized_filename + '" not found.');
|
|
56
|
+
}
|
|
57
|
+
} else {
|
|
58
|
+
res.status(403).send('[eufy-security] Access to file "' + normalized_filename + '" denied.');
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
}
|
|
88
62
|
}
|
|
89
63
|
module.exports = ProxyEufySecurity;
|
|
90
|
-
//# sourceMappingURL=web.js.map
|
|
64
|
+
//# sourceMappingURL=web.js.map
|
package/build/lib/web.js.map
CHANGED
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/lib/web.ts"],
|
|
4
|
+
"sourcesContent": ["import express from \"express\";\r\nimport path from \"path\";\r\nimport fs from \"fs\";\r\nimport mime from \"mime\";\r\nimport * as utils from \"@iobroker/adapter-core\";\r\n\r\n/**\r\n * ProxyEufySecurity class\r\n *\r\n * Reads files from localhost server\r\n *\r\n * @class\r\n * @param {object} server http or https node.js object\r\n * @param {object} webSettings settings of the web server, like <pre><code>{secure: settings.secure, port: settings.port}</code></pre>\r\n * @param {object} adapter web adapter object\r\n * @param {object} instanceSettings instance object with common and native\r\n * @param {object} app express application\r\n * @return {object} object instance\r\n */\r\nclass ProxyEufySecurity {\r\n\r\n private app: express.Application;\r\n private config: any;\r\n private namespace: any;\r\n\r\n constructor(server: any, webSettings: any, adapter: ioBroker.Adapter, instanceSettings: any, app: express.Application) {\r\n this.app = app;\r\n this.config = instanceSettings ? instanceSettings.native : {};\r\n this.namespace = instanceSettings ? instanceSettings._id.substring(\"system.adapter.\".length) : \"eufy-security\";\r\n this.config.route = this.config.route || (this.namespace + \"/\");\r\n this.config.port = parseInt(this.config.port, 10) || 80;\r\n\r\n // remove leading slash\r\n if (this.config.route[0] === \"/\") {\r\n this.config.route = this.config.route.substr(1);\r\n }\r\n\r\n const root_path = path.join(utils.getAbsoluteDefaultDataDir(), this.namespace);\r\n this.app.use(\"/\" + this.config.route, (req: express.Request, res: express.Response) => {\r\n const fileName = path.join(root_path, req.url.substring(1));\r\n const normalized_filename = path.resolve(fileName);\r\n\r\n if (normalized_filename.startsWith(root_path)) {\r\n\r\n res.setHeader(\"Access-Control-Allow-Origin\", \"*\");\r\n res.setHeader(\"Access-Control-Allow-Headers\", \"Origin, X-Requested-With, Content-Type, Accept\");\r\n\r\n if (fs.existsSync(normalized_filename)) {\r\n const stat = fs.statSync(normalized_filename);\r\n if (!stat.isDirectory()) {\r\n let data;\r\n try {\r\n data = fs.readFileSync(normalized_filename);\r\n } catch (e) {\r\n res.status(500).send(`[eufy-security] Cannot read file: ${e}`);\r\n return;\r\n }\r\n res.contentType(mime.getType(path.extname(normalized_filename).substring(1)) || \"html\");\r\n res.status(200).send(data);\r\n }\r\n } else {\r\n res.status(404).send('[eufy-security] File \"' + normalized_filename +'\" not found.');\r\n }\r\n } else {\r\n res.status(403).send('[eufy-security] Access to file \"' + normalized_filename +'\" denied.');\r\n }\r\n });\r\n }\r\n}\r\n\r\nmodule.exports = ProxyEufySecurity;"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;AACA,kBAAiB;AACjB,gBAAe;AACf,kBAAiB;AACjB,YAAuB;AAevB,MAAM,kBAAkB;AAAA,EAMpB,YAAY,QAAa,aAAkB,SAA2B,kBAAuB,KAA0B;AACnH,SAAK,MAAc;AACnB,SAAK,SAAc,mBAAmB,iBAAiB,SAAS,CAAC;AACjE,SAAK,YAAc,mBAAmB,iBAAiB,IAAI,UAAU,kBAAkB,MAAM,IAAI;AACjG,SAAK,OAAO,QAAQ,KAAK,OAAO,SAAU,KAAK,YAAY;AAC3D,SAAK,OAAO,OAAO,SAAS,KAAK,OAAO,MAAM,EAAE,KAAK;AAGrD,QAAI,KAAK,OAAO,MAAM,OAAO,KAAK;AAC9B,WAAK,OAAO,QAAQ,KAAK,OAAO,MAAM,OAAO,CAAC;AAAA,IAClD;AAEA,UAAM,YAAY,YAAAA,QAAK,KAAK,MAAM,0BAA0B,GAAG,KAAK,SAAS;AAC7E,SAAK,IAAI,IAAI,MAAM,KAAK,OAAO,OAAO,CAAC,KAAsB,QAA0B;AACnF,YAAM,WAAW,YAAAA,QAAK,KAAK,WAAW,IAAI,IAAI,UAAU,CAAC,CAAC;AAC1D,YAAM,sBAAsB,YAAAA,QAAK,QAAQ,QAAQ;AAEjD,UAAI,oBAAoB,WAAW,SAAS,GAAG;AAE3C,YAAI,UAAU,+BAA+B,GAAG;AAChD,YAAI,UAAU,gCAAgC,gDAAgD;AAE9F,YAAI,UAAAC,QAAG,WAAW,mBAAmB,GAAG;AACpC,gBAAM,OAAO,UAAAA,QAAG,SAAS,mBAAmB;AAC5C,cAAI,CAAC,KAAK,YAAY,GAAG;AACrB,gBAAI;AACJ,gBAAI;AACA,qBAAO,UAAAA,QAAG,aAAa,mBAAmB;AAAA,YAC9C,SAAS,GAAP;AACE,kBAAI,OAAO,GAAG,EAAE,KAAK,qCAAqC,GAAG;AAC7D;AAAA,YACJ;AACA,gBAAI,YAAY,YAAAC,QAAK,QAAQ,YAAAF,QAAK,QAAQ,mBAAmB,EAAE,UAAU,CAAC,CAAC,KAAK,MAAM;AACtF,gBAAI,OAAO,GAAG,EAAE,KAAK,IAAI;AAAA,UAC7B;AAAA,QACJ,OAAO;AACH,cAAI,OAAO,GAAG,EAAE,KAAK,2BAA2B,sBAAqB,cAAc;AAAA,QACvF;AAAA,MACJ,OAAO;AACH,YAAI,OAAO,GAAG,EAAE,KAAK,qCAAqC,sBAAqB,WAAW;AAAA,MAC9F;AAAA,IACJ,CAAC;AAAA,EACL;AACJ;AAEA,OAAO,UAAU;",
|
|
6
|
+
"names": ["path", "fs", "mime"]
|
|
7
|
+
}
|