Fix deprecations
This commit is contained in:
1 parent
0861b2db40
commit
595f0eddf1
6 files changed
+41
-48
No files matched your search
@@ -17,7 +17,6 @@
|
|||||||
* along with GenieACS. If not, see <http://www.gnu.org/licenses/>.
|
* along with GenieACS. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { parse } from "url";
|
|
||||||
import * as db from "./db";
|
import * as db from "./db";
|
||||||
import * as common from "./common";
|
import * as common from "./common";
|
||||||
import * as cache from "./cache";
|
import * as cache from "./cache";
|
||||||
@@ -80,7 +79,7 @@ export async function connectionRequest(
|
|||||||
).value || [""])[0];
|
).value || [""])[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
const remoteAddress = parse(connectionRequestUrl).host;
|
const remoteAddress = new URL(connectionRequestUrl).hostname;
|
||||||
|
|
||||||
const evalCallback = (exp): Expression => {
|
const evalCallback = (exp): Expression => {
|
||||||
if (!Array.isArray(exp)) return exp;
|
if (!Array.isArray(exp)) return exp;
|
||||||
|
|||||||
+13
-13
@@ -19,7 +19,7 @@
|
|||||||
|
|
||||||
import * as crypto from "crypto";
|
import * as crypto from "crypto";
|
||||||
import * as dgram from "dgram";
|
import * as dgram from "dgram";
|
||||||
import { parse } from "url";
|
import { URL } from "url";
|
||||||
import * as http from "http";
|
import * as http from "http";
|
||||||
import { evaluateAsync } from "./common/expression";
|
import { evaluateAsync } from "./common/expression";
|
||||||
import { Expression } from "./types";
|
import { Expression } from "./types";
|
||||||
@@ -61,24 +61,26 @@ async function extractAuth(
|
|||||||
}
|
}
|
||||||
|
|
||||||
function httpGet(
|
function httpGet(
|
||||||
|
url: URL,
|
||||||
options: http.RequestOptions,
|
options: http.RequestOptions,
|
||||||
_debug: boolean,
|
_debug: boolean,
|
||||||
deviceId: string
|
deviceId: string
|
||||||
): Promise<{ statusCode: number; headers: http.IncomingHttpHeaders }> {
|
): Promise<{ statusCode: number; headers: http.IncomingHttpHeaders }> {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const req = http
|
const req = http
|
||||||
.get(options, (res) => {
|
.get(url, options, (res) => {
|
||||||
res.resume();
|
res.resume();
|
||||||
resolve({ statusCode: res.statusCode, headers: res.headers });
|
resolve({ statusCode: res.statusCode, headers: res.headers });
|
||||||
if (_debug) {
|
if (_debug) {
|
||||||
debug.outgoingHttpRequest(req, deviceId, options, null);
|
debug.outgoingHttpRequest(req, deviceId, "GET", url, null);
|
||||||
debug.incomingHttpResponse(res, deviceId, null);
|
debug.incomingHttpResponse(res, deviceId, null);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.on("error", (err) => {
|
.on("error", (err) => {
|
||||||
req.destroy();
|
req.destroy();
|
||||||
reject(err);
|
reject(err);
|
||||||
if (_debug) debug.outgoingHttpRequestError(req, deviceId, options, err);
|
if (_debug)
|
||||||
|
debug.outgoingHttpRequestError(req, deviceId, "GET", url, err);
|
||||||
})
|
})
|
||||||
.on("timeout", () => {
|
.on("timeout", () => {
|
||||||
req.destroy();
|
req.destroy();
|
||||||
@@ -94,15 +96,13 @@ export async function httpConnectionRequest(
|
|||||||
_debug: boolean,
|
_debug: boolean,
|
||||||
deviceId: string
|
deviceId: string
|
||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
const options: http.RequestOptions = parse(address);
|
const url = new URL(address);
|
||||||
if (options.protocol !== "http:")
|
if (url.protocol !== "http:")
|
||||||
return "Invalid connection request URL or protocol";
|
return "Invalid connection request URL or protocol";
|
||||||
|
|
||||||
options.agent = new http.Agent({
|
const options: http.RequestOptions = {
|
||||||
maxSockets: 1,
|
agent: new http.Agent({ maxSockets: 1, keepAlive: true, timeout: timeout }),
|
||||||
keepAlive: true,
|
};
|
||||||
timeout: timeout,
|
|
||||||
});
|
|
||||||
|
|
||||||
let authHeader: Record<string, string>;
|
let authHeader: Record<string, string>;
|
||||||
let username: string;
|
let username: string;
|
||||||
@@ -145,12 +145,12 @@ export async function httpConnectionRequest(
|
|||||||
|
|
||||||
let res: { statusCode: number; headers: http.IncomingHttpHeaders };
|
let res: { statusCode: number; headers: http.IncomingHttpHeaders };
|
||||||
try {
|
try {
|
||||||
res = await httpGet(opts, _debug, deviceId);
|
res = await httpGet(url, opts, _debug, deviceId);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
// Workaround for some devices unexpectedly closing the connection
|
// Workaround for some devices unexpectedly closing the connection
|
||||||
if (authHeader) {
|
if (authHeader) {
|
||||||
try {
|
try {
|
||||||
res = await httpGet(opts, _debug, deviceId);
|
res = await httpGet(url, opts, _debug, deviceId);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
return `Connection request error: ${err.message}`;
|
return `Connection request error: ${err.message}`;
|
||||||
}
|
}
|
||||||
|
|||||||
+12
-15
@@ -17,12 +17,7 @@
|
|||||||
* along with GenieACS. If not, see <http://www.gnu.org/licenses/>.
|
* along with GenieACS. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {
|
import { IncomingMessage, ServerResponse, ClientRequest } from "http";
|
||||||
IncomingMessage,
|
|
||||||
ServerResponse,
|
|
||||||
ClientRequest,
|
|
||||||
RequestOptions,
|
|
||||||
} from "http";
|
|
||||||
import { Socket } from "net";
|
import { Socket } from "net";
|
||||||
import { appendFileSync } from "fs";
|
import { appendFileSync } from "fs";
|
||||||
import { stringify } from "./common/yaml";
|
import { stringify } from "./common/yaml";
|
||||||
@@ -99,7 +94,8 @@ export function outgoingHttpResponse(
|
|||||||
export function outgoingHttpRequest(
|
export function outgoingHttpRequest(
|
||||||
httpRequest: ClientRequest,
|
httpRequest: ClientRequest,
|
||||||
deviceId: string,
|
deviceId: string,
|
||||||
options: RequestOptions,
|
method: "GET" | "PUT" | "POST" | "DELETE",
|
||||||
|
url: URL,
|
||||||
body: string
|
body: string
|
||||||
): void {
|
): void {
|
||||||
if (!DEBUG_FILE) return;
|
if (!DEBUG_FILE) return;
|
||||||
@@ -111,9 +107,9 @@ export function outgoingHttpRequest(
|
|||||||
remoteAddress: con.remoteAddress,
|
remoteAddress: con.remoteAddress,
|
||||||
deviceId: deviceId,
|
deviceId: deviceId,
|
||||||
connection: getConnectionTimestamp(con),
|
connection: getConnectionTimestamp(con),
|
||||||
remotePort: options.port,
|
remotePort: url.port,
|
||||||
method: options.method || "GET",
|
method: method,
|
||||||
url: options.path,
|
url: url.pathname + url.search,
|
||||||
headers: httpRequest.getHeaders(),
|
headers: httpRequest.getHeaders(),
|
||||||
body: body,
|
body: body,
|
||||||
};
|
};
|
||||||
@@ -128,7 +124,8 @@ export function outgoingHttpRequest(
|
|||||||
export function outgoingHttpRequestError(
|
export function outgoingHttpRequestError(
|
||||||
httpRequest: ClientRequest,
|
httpRequest: ClientRequest,
|
||||||
deviceId: string,
|
deviceId: string,
|
||||||
options: RequestOptions,
|
method: "GET" | "PUT" | "POST" | "DELETE",
|
||||||
|
url: URL,
|
||||||
err: Error
|
err: Error
|
||||||
): void {
|
): void {
|
||||||
if (!DEBUG_FILE) return;
|
if (!DEBUG_FILE) return;
|
||||||
@@ -136,12 +133,12 @@ export function outgoingHttpRequestError(
|
|||||||
const msg = {
|
const msg = {
|
||||||
event: "outgoing HTTP request",
|
event: "outgoing HTTP request",
|
||||||
timestamp: now,
|
timestamp: now,
|
||||||
remoteAddress: options.hostname,
|
remoteAddress: url.hostname,
|
||||||
deviceId: deviceId,
|
deviceId: deviceId,
|
||||||
connection: null,
|
connection: null,
|
||||||
remotePort: options.port,
|
remotePort: url.port,
|
||||||
method: options.method,
|
method: method,
|
||||||
url: options.path,
|
url: url.pathname + url.search,
|
||||||
headers: httpRequest.getHeaders(),
|
headers: httpRequest.getHeaders(),
|
||||||
error: err.message,
|
error: err.message,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -18,7 +18,6 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import * as url from "url";
|
import * as url from "url";
|
||||||
import * as querystring from "querystring";
|
|
||||||
import { IncomingMessage, ServerResponse } from "http";
|
import { IncomingMessage, ServerResponse } from "http";
|
||||||
import { Collection, GridFSBucket } from "mongodb";
|
import { Collection, GridFSBucket } from "mongodb";
|
||||||
import { onConnect } from "./db";
|
import { onConnect } from "./db";
|
||||||
@@ -64,7 +63,7 @@ export async function listener(
|
|||||||
}
|
}
|
||||||
|
|
||||||
const urlParts = url.parse(request.url, true);
|
const urlParts = url.parse(request.url, true);
|
||||||
const filename = querystring.unescape(urlParts.pathname.substring(1));
|
const filename = decodeURIComponent(urlParts.pathname.substring(1));
|
||||||
|
|
||||||
const log = {
|
const log = {
|
||||||
message: "Fetch file",
|
message: "Fetch file",
|
||||||
|
|||||||
+13
-14
@@ -19,7 +19,6 @@
|
|||||||
|
|
||||||
import * as url from "url";
|
import * as url from "url";
|
||||||
import { Collection, GridFSBucket, ObjectId } from "mongodb";
|
import { Collection, GridFSBucket, ObjectId } from "mongodb";
|
||||||
import * as querystring from "querystring";
|
|
||||||
import * as vm from "vm";
|
import * as vm from "vm";
|
||||||
import * as config from "./config";
|
import * as config from "./config";
|
||||||
import { onConnect } from "./db";
|
import { onConnect } from "./db";
|
||||||
@@ -103,13 +102,13 @@ export function listener(
|
|||||||
|
|
||||||
logger.accessInfo(
|
logger.accessInfo(
|
||||||
Object.assign({}, urlParts.query, {
|
Object.assign({}, urlParts.query, {
|
||||||
remoteAddress: request.connection.remoteAddress,
|
remoteAddress: request.socket.remoteAddress,
|
||||||
message: `${request.method} ${urlParts.pathname}`,
|
message: `${request.method} ${urlParts.pathname}`,
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
if (PRESETS_REGEX.test(urlParts.pathname)) {
|
if (PRESETS_REGEX.test(urlParts.pathname)) {
|
||||||
const presetName = querystring.unescape(
|
const presetName = decodeURIComponent(
|
||||||
PRESETS_REGEX.exec(urlParts.pathname)[1]
|
PRESETS_REGEX.exec(urlParts.pathname)[1]
|
||||||
);
|
);
|
||||||
if (request.method === "PUT") {
|
if (request.method === "PUT") {
|
||||||
@@ -156,7 +155,7 @@ export function listener(
|
|||||||
response.end("405 Method Not Allowed");
|
response.end("405 Method Not Allowed");
|
||||||
}
|
}
|
||||||
} else if (OBJECTS_REGEX.test(urlParts.pathname)) {
|
} else if (OBJECTS_REGEX.test(urlParts.pathname)) {
|
||||||
const objectName = querystring.unescape(
|
const objectName = decodeURIComponent(
|
||||||
OBJECTS_REGEX.exec(urlParts.pathname)[1]
|
OBJECTS_REGEX.exec(urlParts.pathname)[1]
|
||||||
);
|
);
|
||||||
if (request.method === "PUT") {
|
if (request.method === "PUT") {
|
||||||
@@ -203,7 +202,7 @@ export function listener(
|
|||||||
response.end("405 Method Not Allowed");
|
response.end("405 Method Not Allowed");
|
||||||
}
|
}
|
||||||
} else if (PROVISIONS_REGEX.test(urlParts.pathname)) {
|
} else if (PROVISIONS_REGEX.test(urlParts.pathname)) {
|
||||||
const provisionName = querystring.unescape(
|
const provisionName = decodeURIComponent(
|
||||||
PROVISIONS_REGEX.exec(urlParts.pathname)[1]
|
PROVISIONS_REGEX.exec(urlParts.pathname)[1]
|
||||||
);
|
);
|
||||||
if (request.method === "PUT") {
|
if (request.method === "PUT") {
|
||||||
@@ -261,7 +260,7 @@ export function listener(
|
|||||||
response.end("405 Method Not Allowed");
|
response.end("405 Method Not Allowed");
|
||||||
}
|
}
|
||||||
} else if (VIRTUAL_PARAMETERS_REGEX.test(urlParts.pathname)) {
|
} else if (VIRTUAL_PARAMETERS_REGEX.test(urlParts.pathname)) {
|
||||||
const virtualParameterName = querystring.unescape(
|
const virtualParameterName = decodeURIComponent(
|
||||||
VIRTUAL_PARAMETERS_REGEX.exec(urlParts.pathname)[1]
|
VIRTUAL_PARAMETERS_REGEX.exec(urlParts.pathname)[1]
|
||||||
);
|
);
|
||||||
if (request.method === "PUT") {
|
if (request.method === "PUT") {
|
||||||
@@ -323,8 +322,8 @@ export function listener(
|
|||||||
}
|
}
|
||||||
} else if (TAGS_REGEX.test(urlParts.pathname)) {
|
} else if (TAGS_REGEX.test(urlParts.pathname)) {
|
||||||
const r = TAGS_REGEX.exec(urlParts.pathname);
|
const r = TAGS_REGEX.exec(urlParts.pathname);
|
||||||
const deviceId = querystring.unescape(r[1]);
|
const deviceId = decodeURIComponent(r[1]);
|
||||||
const tag = querystring.unescape(r[2]);
|
const tag = decodeURIComponent(r[2]);
|
||||||
if (request.method === "POST") {
|
if (request.method === "POST") {
|
||||||
collections.devices.updateOne(
|
collections.devices.updateOne(
|
||||||
{ _id: deviceId },
|
{ _id: deviceId },
|
||||||
@@ -352,7 +351,7 @@ export function listener(
|
|||||||
}
|
}
|
||||||
} else if (FAULTS_REGEX.test(urlParts.pathname)) {
|
} else if (FAULTS_REGEX.test(urlParts.pathname)) {
|
||||||
if (request.method === "DELETE") {
|
if (request.method === "DELETE") {
|
||||||
const faultId = querystring.unescape(
|
const faultId = decodeURIComponent(
|
||||||
FAULTS_REGEX.exec(urlParts.pathname)[1]
|
FAULTS_REGEX.exec(urlParts.pathname)[1]
|
||||||
);
|
);
|
||||||
const deviceId = faultId.split(":", 1)[0];
|
const deviceId = faultId.split(":", 1)[0];
|
||||||
@@ -397,7 +396,7 @@ export function listener(
|
|||||||
}
|
}
|
||||||
} else if (DEVICE_TASKS_REGEX.test(urlParts.pathname)) {
|
} else if (DEVICE_TASKS_REGEX.test(urlParts.pathname)) {
|
||||||
if (request.method === "POST") {
|
if (request.method === "POST") {
|
||||||
const deviceId = querystring.unescape(
|
const deviceId = decodeURIComponent(
|
||||||
DEVICE_TASKS_REGEX.exec(urlParts.pathname)[1]
|
DEVICE_TASKS_REGEX.exec(urlParts.pathname)[1]
|
||||||
);
|
);
|
||||||
if (body.length) {
|
if (body.length) {
|
||||||
@@ -564,7 +563,7 @@ export function listener(
|
|||||||
}
|
}
|
||||||
} else if (TASKS_REGEX.test(urlParts.pathname)) {
|
} else if (TASKS_REGEX.test(urlParts.pathname)) {
|
||||||
const r = TASKS_REGEX.exec(urlParts.pathname);
|
const r = TASKS_REGEX.exec(urlParts.pathname);
|
||||||
const taskId = querystring.unescape(r[1]);
|
const taskId = decodeURIComponent(r[1]);
|
||||||
const action = r[2];
|
const action = r[2];
|
||||||
if (!action || action === "/") {
|
if (!action || action === "/") {
|
||||||
if (request.method === "DELETE") {
|
if (request.method === "DELETE") {
|
||||||
@@ -650,7 +649,7 @@ export function listener(
|
|||||||
response.end();
|
response.end();
|
||||||
}
|
}
|
||||||
} else if (FILES_REGEX.test(urlParts.pathname)) {
|
} else if (FILES_REGEX.test(urlParts.pathname)) {
|
||||||
const filename = querystring.unescape(
|
const filename = decodeURIComponent(
|
||||||
FILES_REGEX.exec(urlParts.pathname)[1]
|
FILES_REGEX.exec(urlParts.pathname)[1]
|
||||||
);
|
);
|
||||||
if (request.method === "PUT") {
|
if (request.method === "PUT") {
|
||||||
@@ -697,7 +696,7 @@ export function listener(
|
|||||||
response.end("405 Method Not Allowed");
|
response.end("405 Method Not Allowed");
|
||||||
}
|
}
|
||||||
} else if (PING_REGEX.test(urlParts.pathname)) {
|
} else if (PING_REGEX.test(urlParts.pathname)) {
|
||||||
const host = querystring.unescape(PING_REGEX.exec(urlParts.pathname)[1]);
|
const host = decodeURIComponent(PING_REGEX.exec(urlParts.pathname)[1]);
|
||||||
ping(host, (err, res, stdout) => {
|
ping(host, (err, res, stdout) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
if (!res) {
|
if (!res) {
|
||||||
@@ -723,7 +722,7 @@ export function listener(
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const deviceId = querystring.unescape(
|
const deviceId = decodeURIComponent(
|
||||||
DELETE_DEVICE_REGEX.exec(urlParts.pathname)[1]
|
DELETE_DEVICE_REGEX.exec(urlParts.pathname)[1]
|
||||||
);
|
);
|
||||||
apiFunctions
|
apiFunctions
|
||||||
|
|||||||
+1
-2
@@ -30,7 +30,6 @@ import { generateSalt, hashPassword } from "../auth";
|
|||||||
import { del } from "../cache";
|
import { del } from "../cache";
|
||||||
import Authorizer from "../common/authorizer";
|
import Authorizer from "../common/authorizer";
|
||||||
import { ping } from "../ping";
|
import { ping } from "../ping";
|
||||||
import * as url from "url";
|
|
||||||
import { decodeTag } from "../common";
|
import { decodeTag } from "../common";
|
||||||
import { stringify as yamlStringify } from "../common/yaml";
|
import { stringify as yamlStringify } from "../common/yaml";
|
||||||
|
|
||||||
@@ -579,7 +578,7 @@ router.post("/devices/:id/tasks", async (ctx) => {
|
|||||||
if (exp[1] === "REMOTE_ADDRESS") {
|
if (exp[1] === "REMOTE_ADDRESS") {
|
||||||
for (const root of ["InternetGatewayDevice", "Device"]) {
|
for (const root of ["InternetGatewayDevice", "Device"]) {
|
||||||
const p = device[`${root}.ManagementServer.ConnectionRequestURL`];
|
const p = device[`${root}.ManagementServer.ConnectionRequestURL`];
|
||||||
if (p && p.value) return url.parse(p.value[0]).host;
|
if (p && p.value) return new URL(p.value[0]).hostname;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user