xynginc 1.0.25 → 1.0.71
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/dist/constant.d.ts +4 -0
- package/dist/constant.d.ts.map +1 -0
- package/dist/constant.js +11 -0
- package/dist/constant.js.map +1 -0
- package/dist/downloadBinary.d.ts +8 -0
- package/dist/downloadBinary.d.ts.map +1 -0
- package/dist/downloadBinary.js +99 -0
- package/dist/downloadBinary.js.map +1 -0
- package/dist/ensureBinary.d.ts +12 -0
- package/dist/ensureBinary.d.ts.map +1 -0
- package/dist/ensureBinary.js +51 -0
- package/dist/ensureBinary.js.map +1 -0
- package/dist/execAsync.d.ts +3 -0
- package/dist/execAsync.d.ts.map +1 -0
- package/dist/execAsync.js +7 -0
- package/dist/execAsync.js.map +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +15 -424
- package/dist/index.js.map +1 -1
- package/dist/requirements.d.ts +84 -0
- package/dist/requirements.d.ts.map +1 -0
- package/dist/requirements.js +238 -0
- package/dist/requirements.js.map +1 -0
- package/dist/startPlugin.d.ts +11 -0
- package/dist/startPlugin.d.ts.map +1 -0
- package/dist/startPlugin.js +68 -0
- package/dist/startPlugin.js.map +1 -0
- package/dist/validateConfig.d.ts +9 -0
- package/dist/validateConfig.d.ts.map +1 -0
- package/dist/validateConfig.js +37 -0
- package/dist/validateConfig.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constant.d.ts","sourceRoot":"","sources":["../src/constant.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,WAAW,YAAY,CAAC;AACrC,eAAO,MAAM,WAAW,yBAAyB,CAAC;AAClD,eAAO,MAAM,UAAU,QAAiC,CAAC"}
|
package/dist/constant.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
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
|
+
exports.BINARY_DIR = exports.GITHUB_REPO = exports.BINARY_NAME = void 0;
|
|
7
|
+
const path_1 = __importDefault(require("path"));
|
|
8
|
+
exports.BINARY_NAME = "xynginc";
|
|
9
|
+
exports.GITHUB_REPO = "Nehonix-Team/xynginc";
|
|
10
|
+
exports.BINARY_DIR = path_1.default.join(__dirname, "../bin");
|
|
11
|
+
//# sourceMappingURL=constant.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constant.js","sourceRoot":"","sources":["../src/constant.ts"],"names":[],"mappings":";;;;;;AAAA,gDAAwB;AAEX,QAAA,WAAW,GAAG,SAAS,CAAC;AACxB,QAAA,WAAW,GAAG,sBAAsB,CAAC;AACrC,QAAA,UAAU,GAAG,cAAI,CAAC,IAAI,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Downloads the xynginc binary from GitHub releases.
|
|
3
|
+
*
|
|
4
|
+
* @param version - The version to download (e.g., "latest" or "v1.4.5").
|
|
5
|
+
* @returns The path to the downloaded binary.
|
|
6
|
+
*/
|
|
7
|
+
export declare function downloadBinary(version: string): Promise<string>;
|
|
8
|
+
//# sourceMappingURL=downloadBinary.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"downloadBinary.d.ts","sourceRoot":"","sources":["../src/downloadBinary.ts"],"names":[],"mappings":"AAOA;;;;;GAKG;AACH,wBAAsB,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CA0DrE"}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.downloadBinary = downloadBinary;
|
|
37
|
+
const logger_1 = require("./logger");
|
|
38
|
+
const https = __importStar(require("https"));
|
|
39
|
+
const fs = __importStar(require("fs"));
|
|
40
|
+
const path = __importStar(require("path"));
|
|
41
|
+
const os = __importStar(require("os"));
|
|
42
|
+
const constant_1 = require("./constant");
|
|
43
|
+
/**
|
|
44
|
+
* Downloads the xynginc binary from GitHub releases.
|
|
45
|
+
*
|
|
46
|
+
* @param version - The version to download (e.g., "latest" or "v1.4.5").
|
|
47
|
+
* @returns The path to the downloaded binary.
|
|
48
|
+
*/
|
|
49
|
+
async function downloadBinary(version) {
|
|
50
|
+
const platform = os.platform();
|
|
51
|
+
const arch = os.arch();
|
|
52
|
+
if (platform !== "linux") {
|
|
53
|
+
throw new Error(`[XyNginC] Unsupported platform: ${platform}. Only Linux is supported.`);
|
|
54
|
+
}
|
|
55
|
+
const binaryName = `${constant_1.BINARY_NAME}-${platform}-${arch}`;
|
|
56
|
+
const downloadUrl = version === "latest"
|
|
57
|
+
? `https://github.com/${constant_1.GITHUB_REPO}/releases/latest/download/${binaryName}`
|
|
58
|
+
: `https://github.com/${constant_1.GITHUB_REPO}/releases/download/${version}/${binaryName}`;
|
|
59
|
+
logger_1.Logger.info(`[XyNginC] Downloading from: ${downloadUrl}`);
|
|
60
|
+
// Create bin directory
|
|
61
|
+
if (!fs.existsSync(constant_1.BINARY_DIR)) {
|
|
62
|
+
fs.mkdirSync(constant_1.BINARY_DIR, { recursive: true });
|
|
63
|
+
}
|
|
64
|
+
const localPath = path.join(constant_1.BINARY_DIR, constant_1.BINARY_NAME);
|
|
65
|
+
return new Promise((resolve, reject) => {
|
|
66
|
+
const file = fs.createWriteStream(localPath);
|
|
67
|
+
https
|
|
68
|
+
.get(downloadUrl, (response) => {
|
|
69
|
+
if (response.statusCode === 302 || response.statusCode === 301) {
|
|
70
|
+
// Follow redirect
|
|
71
|
+
https
|
|
72
|
+
.get(response.headers.location, (redirectResponse) => {
|
|
73
|
+
redirectResponse.pipe(file);
|
|
74
|
+
file.on("finish", () => {
|
|
75
|
+
file.close();
|
|
76
|
+
fs.chmodSync(localPath, 0o755); // Make executable
|
|
77
|
+
logger_1.Logger.success("[XyNginC] ✓ Binary downloaded successfully");
|
|
78
|
+
resolve(localPath);
|
|
79
|
+
});
|
|
80
|
+
})
|
|
81
|
+
.on("error", reject);
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
response.pipe(file);
|
|
85
|
+
file.on("finish", () => {
|
|
86
|
+
file.close();
|
|
87
|
+
fs.chmodSync(localPath, 0o755); // Make executable
|
|
88
|
+
logger_1.Logger.success("[XyNginC] ✓ Binary downloaded successfully");
|
|
89
|
+
resolve(localPath);
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
})
|
|
93
|
+
.on("error", (err) => {
|
|
94
|
+
fs.unlinkSync(localPath); // Delete partial file
|
|
95
|
+
reject(new Error(`Failed to download binary: ${err.message}`));
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
//# sourceMappingURL=downloadBinary.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"downloadBinary.js","sourceRoot":"","sources":["../src/downloadBinary.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAaA,wCA0DC;AAvED,qCAAkC;AAClC,6CAA+B;AAC/B,uCAAyB;AACzB,2CAA6B;AAC7B,uCAAyB;AACzB,yCAAkE;AAElE;;;;;GAKG;AACI,KAAK,UAAU,cAAc,CAAC,OAAe;IAClD,MAAM,QAAQ,GAAG,EAAE,CAAC,QAAQ,EAAE,CAAC;IAC/B,MAAM,IAAI,GAAG,EAAE,CAAC,IAAI,EAAE,CAAC;IAEvB,IAAI,QAAQ,KAAK,OAAO,EAAE,CAAC;QACzB,MAAM,IAAI,KAAK,CACb,mCAAmC,QAAQ,4BAA4B,CACxE,CAAC;IACJ,CAAC;IAED,MAAM,UAAU,GAAG,GAAG,sBAAW,IAAI,QAAQ,IAAI,IAAI,EAAE,CAAC;IACxD,MAAM,WAAW,GACf,OAAO,KAAK,QAAQ;QAClB,CAAC,CAAC,sBAAsB,sBAAW,6BAA6B,UAAU,EAAE;QAC5E,CAAC,CAAC,sBAAsB,sBAAW,sBAAsB,OAAO,IAAI,UAAU,EAAE,CAAC;IAEr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AAC,QAAQ,EAAE,GAAG,EAAE;oBACrB,IAAI,CAAC,KAAK,EAAE,CAAC;oBACb,EAAE,CAAC,SAAS,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC,CAAC,kBAAkB;oBAClD,eAAM,CAAC,OAAO,CAAC,4CAA4C,CAAC,CAAC;oBAC7D,OAAO,CAAC,SAAS,CAAC,CAAC;gBACrB,CAAC,CAAC,CAAC;YACL,CAAC;QACH,CAAC,CAAC;aACD,EAAE,CAAC,OAAO,EAAE,CAAC,GAAG,EAAE,EAAE;YACnB,EAAE,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC,CAAC,sBAAsB;YAChD,MAAM,CAAC,IAAI,KAAK,CAAC,8BAA8B,GAAG,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;QACjE,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ensures the xynginc binary exists.
|
|
3
|
+
* It checks the custom path, the system PATH, and the local bin directory.
|
|
4
|
+
* If not found and autoDownload is enabled, it downloads the binary.
|
|
5
|
+
*
|
|
6
|
+
* @param customPath - Optional custom path to the binary.
|
|
7
|
+
* @param autoDownload - Whether to download the binary if missing.
|
|
8
|
+
* @param version - The version to download.
|
|
9
|
+
* @returns The absolute path to the binary.
|
|
10
|
+
*/
|
|
11
|
+
export declare function ensureBinary(customPath: string | undefined, autoDownload: boolean, version: string): Promise<string>;
|
|
12
|
+
//# sourceMappingURL=ensureBinary.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ensureBinary.d.ts","sourceRoot":"","sources":["../src/ensureBinary.ts"],"names":[],"mappings":"AAOA;;;;;;;;;GASG;AACH,wBAAsB,YAAY,CAChC,UAAU,EAAE,MAAM,GAAG,SAAS,EAC9B,YAAY,EAAE,OAAO,EACrB,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,MAAM,CAAC,CAgCjB"}
|
|
@@ -0,0 +1,51 @@
|
|
|
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
|
+
exports.ensureBinary = ensureBinary;
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const logger_1 = require("./logger");
|
|
10
|
+
const execAsync_1 = require("./execAsync");
|
|
11
|
+
const constant_1 = require("./constant");
|
|
12
|
+
const downloadBinary_1 = require("./downloadBinary");
|
|
13
|
+
/**
|
|
14
|
+
* Ensures the xynginc binary exists.
|
|
15
|
+
* It checks the custom path, the system PATH, and the local bin directory.
|
|
16
|
+
* If not found and autoDownload is enabled, it downloads the binary.
|
|
17
|
+
*
|
|
18
|
+
* @param customPath - Optional custom path to the binary.
|
|
19
|
+
* @param autoDownload - Whether to download the binary if missing.
|
|
20
|
+
* @param version - The version to download.
|
|
21
|
+
* @returns The absolute path to the binary.
|
|
22
|
+
*/
|
|
23
|
+
async function ensureBinary(customPath, autoDownload, version) {
|
|
24
|
+
// 1. Try custom path
|
|
25
|
+
if (customPath && fs_1.default.existsSync(customPath)) {
|
|
26
|
+
return customPath;
|
|
27
|
+
}
|
|
28
|
+
// 2. Try PATH
|
|
29
|
+
try {
|
|
30
|
+
const { stdout } = await (0, execAsync_1.execAsync)("which xynginc");
|
|
31
|
+
const globalPath = stdout.trim();
|
|
32
|
+
if (globalPath && fs_1.default.existsSync(globalPath)) {
|
|
33
|
+
return globalPath;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
// Not in PATH
|
|
38
|
+
}
|
|
39
|
+
// 3. Try local bin directory
|
|
40
|
+
const localPath = path_1.default.join(constant_1.BINARY_DIR, constant_1.BINARY_NAME);
|
|
41
|
+
if (fs_1.default.existsSync(localPath)) {
|
|
42
|
+
return localPath;
|
|
43
|
+
}
|
|
44
|
+
// 4. Auto-download if enabled
|
|
45
|
+
if (autoDownload) {
|
|
46
|
+
logger_1.Logger.info("[XyNginC] Binary not found, downloading...");
|
|
47
|
+
return await (0, downloadBinary_1.downloadBinary)(version);
|
|
48
|
+
}
|
|
49
|
+
throw new Error("[XyNginC] Binary not found. Install xynginc or set 'autoDownload: true'");
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=ensureBinary.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ensureBinary.js","sourceRoot":"","sources":["../src/ensureBinary.ts"],"names":[],"mappings":";;;;;AAiBA,oCAoCC;AArDD,4CAAmB;AACnB,gDAAuB;AACvB,qCAAiC;AACjC,2CAAwC;AACxC,yCAAqD;AACrD,qDAAkD;AAElD;;;;;;;;;GASG;AACI,KAAK,UAAU,YAAY,CAChC,UAA8B,EAC9B,YAAqB,EACrB,OAAe;IAEf,qBAAqB;IACrB,IAAI,UAAU,IAAI,YAAE,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE,CAAC;QAC5C,OAAO,UAAU,CAAC;IACpB,CAAC;IAED,cAAc;IACd,IAAI,CAAC;QACH,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,IAAA,qBAAS,EAAC,eAAe,CAAC,CAAC;QACpD,MAAM,UAAU,GAAG,MAAM,CAAC,IAAI,EAAE,CAAC;QACjC,IAAI,UAAU,IAAI,YAAE,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE,CAAC;YAC5C,OAAO,UAAU,CAAC;QACpB,CAAC;IACH,CAAC;IAAC,MAAM,CAAC;QACP,cAAc;IAChB,CAAC;IAED,6BAA6B;IAC7B,MAAM,SAAS,GAAG,cAAI,CAAC,IAAI,CAAC,qBAAU,EAAE,sBAAW,CAAC,CAAC;IACrD,IAAI,YAAE,CAAC,UAAU,CAAC,SAAS,CAAC,EAAE,CAAC;QAC7B,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,8BAA8B;IAC9B,IAAI,YAAY,EAAE,CAAC;QACjB,eAAM,CAAC,IAAI,CAAC,4CAA4C,CAAC,CAAC;QAC1D,OAAO,MAAM,IAAA,+BAAc,EAAC,OAAO,CAAC,CAAC;IACvC,CAAC;IAED,MAAM,IAAI,KAAK,CACb,yEAAyE,CAC1E,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"execAsync.d.ts","sourceRoot":"","sources":["../src/execAsync.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAGrC,eAAO,MAAM,SAAS,2BAAkB,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.execAsync = void 0;
|
|
4
|
+
const child_process_1 = require("child_process");
|
|
5
|
+
const util_1 = require("util");
|
|
6
|
+
exports.execAsync = (0, util_1.promisify)(child_process_1.exec);
|
|
7
|
+
//# sourceMappingURL=execAsync.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"execAsync.js","sourceRoot":"","sources":["../src/execAsync.ts"],"names":[],"mappings":";;;AAAA,iDAAqC;AACrC,+BAAiC;AAEpB,QAAA,SAAS,GAAG,IAAA,gBAAS,EAAC,oBAAI,CAAC,CAAC"}
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAQA,OAAO,EACL,aAAa,EACb,mBAAmB,EACnB,oBAAoB,EACrB,MAAM,SAAS,CAAC;AAIjB;;;;;;GAMG;AACH,MAAM,CAAC,OAAO,UAAU,IAAI,CAAC,OAAO,EAAE,oBAAoB,mCAsCzD;AAGD,YAAY,EAAE,aAAa,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,CAAC;AAGzE,eAAO,MAAM,OAAO,aAAO,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -4,52 +4,13 @@
|
|
|
4
4
|
* Copyright © 2025 NEHONIX - www.nehonix.com
|
|
5
5
|
* Licensed under NEHONIX Open Source License (NOSL) v1.0
|
|
6
6
|
*/
|
|
7
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
8
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
9
|
-
};
|
|
10
7
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
8
|
exports.XyNginC = void 0;
|
|
12
9
|
exports.default = XNCP;
|
|
13
10
|
const xypriss_1 = require("xypriss");
|
|
14
|
-
const child_process_1 = require("child_process");
|
|
15
|
-
const util_1 = require("util");
|
|
16
|
-
const path_1 = __importDefault(require("path"));
|
|
17
|
-
const fs_1 = __importDefault(require("fs"));
|
|
18
|
-
const os_1 = __importDefault(require("os"));
|
|
19
|
-
const https_1 = __importDefault(require("https"));
|
|
20
11
|
const logger_1 = require("./logger");
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
* Executes a shell command and streams its stdout/stderr line-by-line in real-time,
|
|
24
|
-
* preserving ANSI color codes printed by the Go binary.
|
|
25
|
-
*/
|
|
26
|
-
function execStream(command) {
|
|
27
|
-
return new Promise((resolve, reject) => {
|
|
28
|
-
const child = (0, child_process_1.spawn)(command, { shell: true });
|
|
29
|
-
let stderrData = "";
|
|
30
|
-
child.stdout.on("data", (data) => {
|
|
31
|
-
// Print raw data so inner ANSI codes from Go are preserved directly in PM2
|
|
32
|
-
process.stdout.write(data);
|
|
33
|
-
});
|
|
34
|
-
child.stderr.on("data", (data) => {
|
|
35
|
-
const msg = data.toString();
|
|
36
|
-
// Filter out the interactive sudo prompt from stderr output
|
|
37
|
-
if (!msg.includes("[sudo] password for")) {
|
|
38
|
-
process.stdout.write(data); // Write to stdout to avoid PM2 red-error highlighting
|
|
39
|
-
}
|
|
40
|
-
stderrData += msg;
|
|
41
|
-
});
|
|
42
|
-
child.on("close", (code) => {
|
|
43
|
-
if (code === 0)
|
|
44
|
-
resolve();
|
|
45
|
-
else
|
|
46
|
-
reject(new Error(`Command failed with code ${code}.`));
|
|
47
|
-
});
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
const BINARY_NAME = "xynginc";
|
|
51
|
-
const GITHUB_REPO = "Nehonix-Team/xynginc";
|
|
52
|
-
const BINARY_DIR = path_1.default.join(__dirname, "../bin");
|
|
12
|
+
const validateConfig_1 = require("./validateConfig");
|
|
13
|
+
const startPlugin_1 = require("./startPlugin");
|
|
53
14
|
/**
|
|
54
15
|
* XyNginC Plugin for XyPriss.
|
|
55
16
|
* Automates Nginx and SSL management for your server.
|
|
@@ -59,400 +20,30 @@ const BINARY_DIR = path_1.default.join(__dirname, "../bin");
|
|
|
59
20
|
*/
|
|
60
21
|
function XNCP(options) {
|
|
61
22
|
const { domains, autoReload = true, binaryPath, autoDownload = true, version = "latest", installRequirements = true, sudoPassword, } = options;
|
|
62
|
-
const getSudo = () => {
|
|
63
|
-
// Attempt multiple ways to get the password, including XyPriss internal env if somehow exposed
|
|
64
|
-
const envPwd = process.env.SUDO_PASSWORD ||
|
|
65
|
-
global.__sys__?.$env?.("SUDO_PASSWORD");
|
|
66
|
-
const pwd = sudoPassword || envPwd;
|
|
67
|
-
if (pwd) {
|
|
68
|
-
if (sudoPassword) {
|
|
69
|
-
logger_1.Logger.info(`[XyNginC] Using sudo password provided via plugin options(${sudoPassword}).`);
|
|
70
|
-
}
|
|
71
|
-
else {
|
|
72
|
-
logger_1.Logger.info("[XyNginC] Using sudo password injected from environment variables.");
|
|
73
|
-
}
|
|
74
|
-
return `echo '${pwd}' | sudo -S`;
|
|
75
|
-
}
|
|
76
|
-
logger_1.Logger.warn("[XyNginC] ⚠️ No sudo password provided. Falling back to non-interactive mode (sudo -n).");
|
|
77
|
-
logger_1.Logger.warn("[XyNginC] ⚠️ If the command requires a password, it will fail immediately instead of hanging.");
|
|
78
|
-
// Return non-interactive sudo to prevent infinite blocking/hanging
|
|
79
|
-
return "sudo -n";
|
|
80
|
-
};
|
|
81
23
|
return xypriss_1.Plugin.create({
|
|
82
24
|
name: "xynginc",
|
|
83
|
-
version: "1.0.
|
|
25
|
+
version: "1.0.70",
|
|
84
26
|
description: "XyPriss Nginx Controller - Automatic Nginx & SSL management",
|
|
85
|
-
onRegister: async () => {
|
|
27
|
+
onRegister: async (server) => {
|
|
86
28
|
logger_1.Logger.info("[XyNginC] Registering plugin...");
|
|
87
29
|
// Validate config
|
|
88
|
-
validateConfig({ domains, autoReload });
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
// Check if requirements are satisfied
|
|
99
|
-
const requirementsOk = await checkRequirements(binary, getSudo());
|
|
100
|
-
// Install requirements if enabled and needed
|
|
101
|
-
if (!requirementsOk && installRequirements) {
|
|
102
|
-
logger_1.Logger.info("[XyNginC] Requirements missing, installing automatically...");
|
|
103
|
-
await installRequirementsHandler(binary, getSudo());
|
|
104
|
-
logger_1.Logger.info("[XyNginC] Requirements installed, re-checking...");
|
|
105
|
-
await checkRequirements(binary, getSudo());
|
|
106
|
-
}
|
|
107
|
-
else if (!requirementsOk) {
|
|
108
|
-
throw new Error("[XyNginC] System requirements not satisfied. Install with 'installRequirements: true' or run: sudo xynginc install");
|
|
109
|
-
}
|
|
110
|
-
// 3. Apply configuration
|
|
111
|
-
logger_1.Logger.info("[XyNginC] Applying configuration...");
|
|
112
|
-
await applyConfig(binary, { domains, auto_reload: autoReload }, getSudo());
|
|
113
|
-
logger_1.Logger.success("[XyNginC] Configuration applied successfully!");
|
|
114
|
-
// Expose CLI helper methods on server
|
|
115
|
-
server.xynginc = {
|
|
116
|
-
addDomain: (domain, port, ssl = false, email, maxBodySize) => addDomain(binary, domain, port, ssl, email, maxBodySize, getSudo()),
|
|
117
|
-
removeDomain: (domain) => removeDomain(binary, domain, getSudo()),
|
|
118
|
-
listDomains: () => listDomains(binary, getSudo()),
|
|
119
|
-
reload: () => reloadNginx(binary, getSudo()),
|
|
120
|
-
test: () => testNginx(binary, getSudo()),
|
|
121
|
-
status: () => getStatus(binary, getSudo()),
|
|
122
|
-
installRequirements: () => installRequirementsHandler(binary, getSudo()),
|
|
123
|
-
};
|
|
124
|
-
logger_1.Logger.info("[XyNginC] Server methods available: server.xynginc.*");
|
|
125
|
-
}
|
|
126
|
-
catch (error) {
|
|
127
|
-
logger_1.Logger.error(`[XyNginC] ✖ Failed to initialize: ${error}`);
|
|
128
|
-
throw error;
|
|
129
|
-
}
|
|
30
|
+
(0, validateConfig_1.validateConfig)({ domains, autoReload });
|
|
31
|
+
await (0, startPlugin_1.startXNCPlugin)(server, {
|
|
32
|
+
autoDownload,
|
|
33
|
+
autoReload,
|
|
34
|
+
binaryPath: binaryPath,
|
|
35
|
+
version,
|
|
36
|
+
domains,
|
|
37
|
+
installRequirements,
|
|
38
|
+
sudoPassword: sudoPassword || "",
|
|
39
|
+
});
|
|
130
40
|
},
|
|
41
|
+
onServerStart: async (_server) => { },
|
|
131
42
|
onServerStop: async () => {
|
|
132
43
|
logger_1.Logger.info("[XyNginC] Shutting down Nginx Controller...");
|
|
133
44
|
},
|
|
134
45
|
});
|
|
135
46
|
}
|
|
136
|
-
/**
|
|
137
|
-
* Validates the plugin configuration.
|
|
138
|
-
*
|
|
139
|
-
* @param config - The configuration to validate.
|
|
140
|
-
* @throws Error if the configuration is invalid.
|
|
141
|
-
*/
|
|
142
|
-
function validateConfig(config) {
|
|
143
|
-
if (!config.domains || config.domains.length === 0) {
|
|
144
|
-
throw new Error("[XyNginC] Configuration error: 'domains' array cannot be empty");
|
|
145
|
-
}
|
|
146
|
-
for (const domain of config.domains) {
|
|
147
|
-
if (!domain.domain || typeof domain.domain !== "string") {
|
|
148
|
-
throw new Error("[XyNginC] Configuration error: 'domain' must be a non-empty string");
|
|
149
|
-
}
|
|
150
|
-
if (!domain.port ||
|
|
151
|
-
typeof domain.port !== "number" ||
|
|
152
|
-
domain.port < 1 ||
|
|
153
|
-
domain.port > 65535) {
|
|
154
|
-
throw new Error(`[XyNginC] Configuration error: 'port' must be between 1-65535 for ${domain.domain}`);
|
|
155
|
-
}
|
|
156
|
-
if (domain.ssl && !domain.email) {
|
|
157
|
-
throw new Error(`[XyNginC] Configuration error: 'email' is required when SSL is enabled for ${domain.domain}`);
|
|
158
|
-
}
|
|
159
|
-
// Set default host to localhost if not provided
|
|
160
|
-
if (!domain.host) {
|
|
161
|
-
domain.host = "localhost";
|
|
162
|
-
}
|
|
163
|
-
// Set default maxBodySize if not provided
|
|
164
|
-
if (!domain.maxBodySize) {
|
|
165
|
-
domain.maxBodySize = "20M";
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
/**
|
|
170
|
-
* Ensures the xynginc binary exists.
|
|
171
|
-
* It checks the custom path, the system PATH, and the local bin directory.
|
|
172
|
-
* If not found and autoDownload is enabled, it downloads the binary.
|
|
173
|
-
*
|
|
174
|
-
* @param customPath - Optional custom path to the binary.
|
|
175
|
-
* @param autoDownload - Whether to download the binary if missing.
|
|
176
|
-
* @param version - The version to download.
|
|
177
|
-
* @returns The absolute path to the binary.
|
|
178
|
-
*/
|
|
179
|
-
async function ensureBinary(customPath, autoDownload, version) {
|
|
180
|
-
// 1. Try custom path
|
|
181
|
-
if (customPath && fs_1.default.existsSync(customPath)) {
|
|
182
|
-
return customPath;
|
|
183
|
-
}
|
|
184
|
-
// 2. Try PATH
|
|
185
|
-
try {
|
|
186
|
-
const { stdout } = await execAsync("which xynginc");
|
|
187
|
-
const globalPath = stdout.trim();
|
|
188
|
-
if (globalPath && fs_1.default.existsSync(globalPath)) {
|
|
189
|
-
return globalPath;
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
catch {
|
|
193
|
-
// Not in PATH
|
|
194
|
-
}
|
|
195
|
-
// 3. Try local bin directory
|
|
196
|
-
const localPath = path_1.default.join(BINARY_DIR, BINARY_NAME);
|
|
197
|
-
if (fs_1.default.existsSync(localPath)) {
|
|
198
|
-
return localPath;
|
|
199
|
-
}
|
|
200
|
-
// 4. Auto-download if enabled
|
|
201
|
-
if (autoDownload) {
|
|
202
|
-
logger_1.Logger.info("[XyNginC] Binary not found, downloading...");
|
|
203
|
-
return await downloadBinary(version);
|
|
204
|
-
}
|
|
205
|
-
throw new Error("[XyNginC] Binary not found. Install xynginc or set 'autoDownload: true'");
|
|
206
|
-
}
|
|
207
|
-
/**
|
|
208
|
-
* Downloads the xynginc binary from GitHub releases.
|
|
209
|
-
*
|
|
210
|
-
* @param version - The version to download (e.g., "latest" or "v1.4.5").
|
|
211
|
-
* @returns The path to the downloaded binary.
|
|
212
|
-
*/
|
|
213
|
-
async function downloadBinary(version) {
|
|
214
|
-
const platform = os_1.default.platform();
|
|
215
|
-
const arch = os_1.default.arch();
|
|
216
|
-
if (platform !== "linux") {
|
|
217
|
-
throw new Error(`[XyNginC] Unsupported platform: ${platform}. Only Linux is supported.`);
|
|
218
|
-
}
|
|
219
|
-
const binaryName = `${BINARY_NAME}-${platform}-${arch}`;
|
|
220
|
-
const downloadUrl = version === "latest"
|
|
221
|
-
? `https://github.com/${GITHUB_REPO}/releases/latest/download/${binaryName}`
|
|
222
|
-
: `https://github.com/${GITHUB_REPO}/releases/download/${version}/${binaryName}`;
|
|
223
|
-
logger_1.Logger.info(`[XyNginC] Downloading from: ${downloadUrl}`);
|
|
224
|
-
// Create bin directory
|
|
225
|
-
if (!fs_1.default.existsSync(BINARY_DIR)) {
|
|
226
|
-
fs_1.default.mkdirSync(BINARY_DIR, { recursive: true });
|
|
227
|
-
}
|
|
228
|
-
const localPath = path_1.default.join(BINARY_DIR, BINARY_NAME);
|
|
229
|
-
return new Promise((resolve, reject) => {
|
|
230
|
-
const file = fs_1.default.createWriteStream(localPath);
|
|
231
|
-
https_1.default
|
|
232
|
-
.get(downloadUrl, (response) => {
|
|
233
|
-
if (response.statusCode === 302 || response.statusCode === 301) {
|
|
234
|
-
// Follow redirect
|
|
235
|
-
https_1.default
|
|
236
|
-
.get(response.headers.location, (redirectResponse) => {
|
|
237
|
-
redirectResponse.pipe(file);
|
|
238
|
-
file.on("finish", () => {
|
|
239
|
-
file.close();
|
|
240
|
-
fs_1.default.chmodSync(localPath, 0o755); // Make executable
|
|
241
|
-
logger_1.Logger.success("[XyNginC] ✓ Binary downloaded successfully");
|
|
242
|
-
resolve(localPath);
|
|
243
|
-
});
|
|
244
|
-
})
|
|
245
|
-
.on("error", reject);
|
|
246
|
-
}
|
|
247
|
-
else {
|
|
248
|
-
response.pipe(file);
|
|
249
|
-
file.on("finish", () => {
|
|
250
|
-
file.close();
|
|
251
|
-
fs_1.default.chmodSync(localPath, 0o755); // Make executable
|
|
252
|
-
logger_1.Logger.success("[XyNginC] ✓ Binary downloaded successfully");
|
|
253
|
-
resolve(localPath);
|
|
254
|
-
});
|
|
255
|
-
}
|
|
256
|
-
})
|
|
257
|
-
.on("error", (err) => {
|
|
258
|
-
fs_1.default.unlinkSync(localPath); // Delete partial file
|
|
259
|
-
reject(new Error(`Failed to download binary: ${err.message}`));
|
|
260
|
-
});
|
|
261
|
-
});
|
|
262
|
-
}
|
|
263
|
-
/**
|
|
264
|
-
* Checks if system requirements (Nginx, Certbot) are satisfied using the binary.
|
|
265
|
-
*
|
|
266
|
-
* @param binaryPath - Path to the xynginc binary.
|
|
267
|
-
* @param sudoCmd - Sudo prefix to use.
|
|
268
|
-
* @returns True if requirements are met, false otherwise.
|
|
269
|
-
*/
|
|
270
|
-
async function checkRequirements(binaryPath, sudoCmd) {
|
|
271
|
-
try {
|
|
272
|
-
await execStream(`${sudoCmd} ${binaryPath} check`);
|
|
273
|
-
return true;
|
|
274
|
-
}
|
|
275
|
-
catch (error) {
|
|
276
|
-
logger_1.Logger.warn(`[XyNginC] System requirements check failed: ${error.message}`);
|
|
277
|
-
return false;
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
/**
|
|
281
|
-
* Installs system requirements using the binary in interactive mode.
|
|
282
|
-
*
|
|
283
|
-
* @param binaryPath - Path to the xynginc binary.
|
|
284
|
-
* @param sudoCmd - Sudo prefix to use.
|
|
285
|
-
*/
|
|
286
|
-
async function installRequirementsHandler(binaryPath, sudoCmd) {
|
|
287
|
-
return new Promise((resolve, reject) => {
|
|
288
|
-
logger_1.Logger.info("[XyNginC] Launching interactive installer...");
|
|
289
|
-
logger_1.Logger.info("[XyNginC] Please respond to any prompts in the terminal.");
|
|
290
|
-
// Handle process environmental logic if running via non-interactive sudo -S
|
|
291
|
-
const cmd = sudoCmd.includes("-S")
|
|
292
|
-
? `${sudoCmd} ${binaryPath} install`
|
|
293
|
-
: `sudo ${binaryPath} install`;
|
|
294
|
-
// Spawn the process with inherited stdio for full interactivity
|
|
295
|
-
const installProcess = (0, child_process_1.spawn)(cmd, {
|
|
296
|
-
stdio: "inherit", // This allows the subprocess to use the parent's stdin/stdout/stderr
|
|
297
|
-
shell: true,
|
|
298
|
-
});
|
|
299
|
-
installProcess.on("close", (code) => {
|
|
300
|
-
if (code === 0) {
|
|
301
|
-
logger_1.Logger.success("[XyNginC] ✓ System requirements installed successfully");
|
|
302
|
-
resolve();
|
|
303
|
-
}
|
|
304
|
-
else {
|
|
305
|
-
reject(new Error(`Installation failed with exit code ${code}`));
|
|
306
|
-
}
|
|
307
|
-
});
|
|
308
|
-
installProcess.on("error", (error) => {
|
|
309
|
-
reject(new Error(`Failed to start installation: ${error.message}`));
|
|
310
|
-
});
|
|
311
|
-
});
|
|
312
|
-
}
|
|
313
|
-
/**
|
|
314
|
-
* Applies the configuration using the xynginc binary.
|
|
315
|
-
*
|
|
316
|
-
* @param binaryPath - Path to the xynginc binary.
|
|
317
|
-
* @param config - The configuration object.
|
|
318
|
-
* @param sudoCmd - Sudo prefix to use.
|
|
319
|
-
*/
|
|
320
|
-
async function applyConfig(binaryPath, config, sudoCmd) {
|
|
321
|
-
// Map camelCase to snake_case for Rust core
|
|
322
|
-
const mappedConfig = {
|
|
323
|
-
auto_reload: config.auto_reload,
|
|
324
|
-
domains: config.domains.map((d) => ({
|
|
325
|
-
domain: d.domain,
|
|
326
|
-
port: d.port,
|
|
327
|
-
ssl: d.ssl,
|
|
328
|
-
email: d.email,
|
|
329
|
-
host: d.host,
|
|
330
|
-
max_body_size: d.maxBodySize,
|
|
331
|
-
})),
|
|
332
|
-
};
|
|
333
|
-
const configJson = JSON.stringify(mappedConfig);
|
|
334
|
-
try {
|
|
335
|
-
// Test nginx BEFORE applying new config
|
|
336
|
-
logger_1.Logger.info("[XyNginC] Testing current nginx config...");
|
|
337
|
-
const testResult = await testNginx(binaryPath, sudoCmd);
|
|
338
|
-
if (!testResult) {
|
|
339
|
-
logger_1.Logger.warn("[XyNginC] ⚠️ Current nginx config has errors. Attempting to fix...");
|
|
340
|
-
}
|
|
341
|
-
// Pass config via stdin to avoid shell escaping issues
|
|
342
|
-
await execStream(`echo '${configJson}' | ${sudoCmd} ${binaryPath} apply --config -`);
|
|
343
|
-
}
|
|
344
|
-
catch (error) {
|
|
345
|
-
// If it fails, show more helpful error
|
|
346
|
-
logger_1.Logger.error(`[XyNginC] Failed to apply configuration: ${error.message}`);
|
|
347
|
-
logger_1.Logger.info("[XyNginC] Try running: sudo nginx -t");
|
|
348
|
-
logger_1.Logger.info("[XyNginC] Check: /etc/nginx/sites-enabled/");
|
|
349
|
-
throw new Error(`Failed to apply configuration: ${error.message}`);
|
|
350
|
-
}
|
|
351
|
-
}
|
|
352
|
-
/**
|
|
353
|
-
* Adds a new domain configuration using the binary.
|
|
354
|
-
*
|
|
355
|
-
* @param binaryPath - Path to the xynginc binary.
|
|
356
|
-
* @param domain - The domain name.
|
|
357
|
-
* @param port - The backend port.
|
|
358
|
-
* @param ssl - Whether to enable SSL.
|
|
359
|
-
* @param email - Optional email for SSL.
|
|
360
|
-
* @param maxBodySize - Optional maximum body size.
|
|
361
|
-
* @param sudoCmd - Sudo prefix to use.
|
|
362
|
-
*/
|
|
363
|
-
async function addDomain(binaryPath, domain, port, ssl, email, maxBodySize, sudoCmd = "sudo") {
|
|
364
|
-
const sslFlag = ssl ? "--ssl" : "";
|
|
365
|
-
const emailFlag = email ? `--email ${email}` : "";
|
|
366
|
-
const maxBodySizeFlag = maxBodySize ? `--max-body-size ${maxBodySize}` : "";
|
|
367
|
-
try {
|
|
368
|
-
const { stdout } = await execAsync(`${sudoCmd} ${binaryPath} add --domain ${domain} --port ${port} ${sslFlag} ${emailFlag} ${maxBodySizeFlag}`);
|
|
369
|
-
logger_1.Logger.info(stdout.trim());
|
|
370
|
-
}
|
|
371
|
-
catch (error) {
|
|
372
|
-
throw new Error(`Failed to add domain: ${error.message}`);
|
|
373
|
-
}
|
|
374
|
-
}
|
|
375
|
-
/**
|
|
376
|
-
* Removes a domain configuration using the binary.
|
|
377
|
-
*
|
|
378
|
-
* @param binaryPath - Path to the xynginc binary.
|
|
379
|
-
* @param domain - The domain name to remove.
|
|
380
|
-
* @param sudoCmd - Sudo prefix to use.
|
|
381
|
-
*/
|
|
382
|
-
async function removeDomain(binaryPath, domain, sudoCmd = "sudo") {
|
|
383
|
-
try {
|
|
384
|
-
const { stdout } = await execAsync(`${sudoCmd} ${binaryPath} remove ${domain}`);
|
|
385
|
-
logger_1.Logger.info(stdout.trim());
|
|
386
|
-
}
|
|
387
|
-
catch (error) {
|
|
388
|
-
throw new Error(`Failed to remove domain: ${error.message}`);
|
|
389
|
-
}
|
|
390
|
-
}
|
|
391
|
-
/**
|
|
392
|
-
* Lists all configured domains.
|
|
393
|
-
*
|
|
394
|
-
* @param binaryPath - Path to the xynginc binary.
|
|
395
|
-
* @param sudoCmd - Sudo prefix to use.
|
|
396
|
-
* @returns A list of domain names.
|
|
397
|
-
*/
|
|
398
|
-
async function listDomains(binaryPath, sudoCmd = "sudo") {
|
|
399
|
-
try {
|
|
400
|
-
const { stdout } = await execAsync(`${sudoCmd} ${binaryPath} list`);
|
|
401
|
-
// Parse output to extract domain names
|
|
402
|
-
const lines = stdout.split("\n").filter((line) => line.includes(" - "));
|
|
403
|
-
return lines.map((line) => line.trim().split(" - ")[0]);
|
|
404
|
-
}
|
|
405
|
-
catch (error) {
|
|
406
|
-
throw new Error(`Failed to list domains: ${error.message}`);
|
|
407
|
-
}
|
|
408
|
-
}
|
|
409
|
-
/**
|
|
410
|
-
* Reloads the Nginx service using the binary.
|
|
411
|
-
*
|
|
412
|
-
* @param binaryPath - Path to the xynginc binary.
|
|
413
|
-
* @param sudoCmd - Sudo prefix to use.
|
|
414
|
-
*/
|
|
415
|
-
async function reloadNginx(binaryPath, sudoCmd = "sudo") {
|
|
416
|
-
try {
|
|
417
|
-
const { stdout } = await execAsync(`${sudoCmd} ${binaryPath} reload`);
|
|
418
|
-
logger_1.Logger.info(stdout.trim());
|
|
419
|
-
}
|
|
420
|
-
catch (error) {
|
|
421
|
-
throw new Error(`Failed to reload Nginx: ${error.message}`);
|
|
422
|
-
}
|
|
423
|
-
}
|
|
424
|
-
/**
|
|
425
|
-
* Tests the Nginx configuration validity using the binary.
|
|
426
|
-
*
|
|
427
|
-
* @param binaryPath - Path to the xynginc binary.
|
|
428
|
-
* @param sudoCmd - Sudo prefix to use.
|
|
429
|
-
* @returns True if the configuration is valid.
|
|
430
|
-
*/
|
|
431
|
-
async function testNginx(binaryPath, sudoCmd = "sudo") {
|
|
432
|
-
try {
|
|
433
|
-
await execAsync(`${sudoCmd} ${binaryPath} test`);
|
|
434
|
-
return true;
|
|
435
|
-
}
|
|
436
|
-
catch {
|
|
437
|
-
return false;
|
|
438
|
-
}
|
|
439
|
-
}
|
|
440
|
-
/**
|
|
441
|
-
* Gets the status of managed sites using the binary.
|
|
442
|
-
*
|
|
443
|
-
* @param binaryPath - Path to the xynginc binary.
|
|
444
|
-
* @param sudoCmd - Sudo prefix to use.
|
|
445
|
-
* @returns The status output.
|
|
446
|
-
*/
|
|
447
|
-
async function getStatus(binaryPath, sudoCmd = "sudo") {
|
|
448
|
-
try {
|
|
449
|
-
const { stdout } = await execAsync(`${sudoCmd} ${binaryPath} status`);
|
|
450
|
-
return stdout;
|
|
451
|
-
}
|
|
452
|
-
catch (error) {
|
|
453
|
-
throw new Error(`Failed to get status: ${error.message}`);
|
|
454
|
-
}
|
|
455
|
-
}
|
|
456
47
|
// Named exports for direct usage
|
|
457
48
|
exports.XyNginC = XNCP;
|
|
458
49
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;;;;AA2DH,uBA2HC;AApLD,qCAAiC;AACjC,iDAA4C;AAC5C,+BAAiC;AACjC,gDAAwB;AACxB,4CAAoB;AACpB,4CAAoB;AACpB,kDAA0B;AAC1B,qCAAkC;AAOlC,MAAM,SAAS,GAAG,IAAA,gBAAS,EAAC,oBAAI,CAAC,CAAC;AAElC;;;GAGG;AACH,SAAS,UAAU,CAAC,OAAe;IACjC,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACrC,MAAM,KAAK,GAAG,IAAA,qBAAK,EAAC,OAAO,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;QAC9C,IAAI,UAAU,GAAG,EAAE,CAAC;QAEpB,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,EAAE;YAC/B,2EAA2E;YAC3E,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAC7B,CAAC,CAAC,CAAC;QAEH,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,EAAE;YAC/B,MAAM,GAAG,GAAG,IAAI,CAAC,QAAQ,EA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E,GAAE,CAAC;QAEpC,YAAY,EAAE,KAAK,IAAI,EAAE;YACvB,eAAM,CAAC,IAAI,CAAC,6CAA6C,CAAC,CAAC;QAC7D,CAAC;KACF,CAAC,CAAC;AACL,CAAC;AAKD,iCAAiC;AACpB,QAAA,OAAO,GAAG,IAAI,CAAC"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { XyNginCDomainConfig } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* Installs system requirements using the binary in interactive mode.
|
|
4
|
+
*
|
|
5
|
+
* @param binaryPath - Path to the xynginc binary.
|
|
6
|
+
* @param sudoCmd - Sudo prefix to use.
|
|
7
|
+
*/
|
|
8
|
+
export declare function installRequirementsHandler(binaryPath: string, sudoCmd: string): Promise<void>;
|
|
9
|
+
/**
|
|
10
|
+
* Applies the configuration using the xynginc binary.
|
|
11
|
+
*
|
|
12
|
+
* @param binaryPath - Path to the xynginc binary.
|
|
13
|
+
* @param config - The configuration object.
|
|
14
|
+
* @param sudoCmd - Sudo prefix to use.
|
|
15
|
+
*/
|
|
16
|
+
export declare function applyConfig(binaryPath: string, config: {
|
|
17
|
+
domains: XyNginCDomainConfig[];
|
|
18
|
+
auto_reload: boolean;
|
|
19
|
+
}, sudoCmd: string): Promise<void>;
|
|
20
|
+
/**
|
|
21
|
+
* Adds a new domain configuration using the binary.
|
|
22
|
+
*
|
|
23
|
+
* @param binaryPath - Path to the xynginc binary.
|
|
24
|
+
* @param domain - The domain name.
|
|
25
|
+
* @param port - The backend port.
|
|
26
|
+
* @param ssl - Whether to enable SSL.
|
|
27
|
+
* @param email - Optional email for SSL.
|
|
28
|
+
* @param maxBodySize - Optional maximum body size.
|
|
29
|
+
* @param sudoCmd - Sudo prefix to use.
|
|
30
|
+
*/
|
|
31
|
+
export declare function addDomain(binaryPath: string, domain: string, port: number, ssl: boolean, email?: string, maxBodySize?: string, sudoCmd?: string): Promise<void>;
|
|
32
|
+
/**
|
|
33
|
+
* Removes a domain configuration using the binary.
|
|
34
|
+
*
|
|
35
|
+
* @param binaryPath - Path to the xynginc binary.
|
|
36
|
+
* @param domain - The domain name to remove.
|
|
37
|
+
* @param sudoCmd - Sudo prefix to use.
|
|
38
|
+
*/
|
|
39
|
+
export declare function removeDomain(binaryPath: string, domain: string, sudoCmd?: string): Promise<void>;
|
|
40
|
+
/**
|
|
41
|
+
* Lists all configured domains.
|
|
42
|
+
*
|
|
43
|
+
* @param binaryPath - Path to the xynginc binary.
|
|
44
|
+
* @param sudoCmd - Sudo prefix to use.
|
|
45
|
+
* @returns A list of domain names.
|
|
46
|
+
*/
|
|
47
|
+
export declare function listDomains(binaryPath: string, sudoCmd?: string): Promise<string[]>;
|
|
48
|
+
/**
|
|
49
|
+
* Reloads the Nginx service using the binary.
|
|
50
|
+
*
|
|
51
|
+
* @param binaryPath - Path to the xynginc binary.
|
|
52
|
+
* @param sudoCmd - Sudo prefix to use.
|
|
53
|
+
*/
|
|
54
|
+
export declare function reloadNginx(binaryPath: string, sudoCmd?: string): Promise<void>;
|
|
55
|
+
/**
|
|
56
|
+
* Tests the Nginx configuration validity using the binary.
|
|
57
|
+
*
|
|
58
|
+
* @param binaryPath - Path to the xynginc binary.
|
|
59
|
+
* @param sudoCmd - Sudo prefix to use.
|
|
60
|
+
* @returns True if the configuration is valid.
|
|
61
|
+
*/
|
|
62
|
+
export declare function testNginx(binaryPath: string, sudoCmd?: string): Promise<boolean>;
|
|
63
|
+
/**
|
|
64
|
+
* Gets the status of managed sites using the binary.
|
|
65
|
+
*
|
|
66
|
+
* @param binaryPath - Path to the xynginc binary.
|
|
67
|
+
* @param sudoCmd - Sudo prefix to use.
|
|
68
|
+
* @returns The status output.
|
|
69
|
+
*/
|
|
70
|
+
export declare function getStatus(binaryPath: string, sudoCmd?: string): Promise<string>;
|
|
71
|
+
/**
|
|
72
|
+
* Checks if system requirements (Nginx, Certbot) are satisfied using the binary.
|
|
73
|
+
*
|
|
74
|
+
* @param binaryPath - Path to the xynginc binary.
|
|
75
|
+
* @param sudoCmd - Sudo prefix to use.
|
|
76
|
+
* @returns True if requirements are met, false otherwise.
|
|
77
|
+
*/
|
|
78
|
+
export declare function checkRequirements(binaryPath: string, sudoCmd: string): Promise<boolean>;
|
|
79
|
+
/**
|
|
80
|
+
* Executes a shell command and streams its stdout/stderr line-by-line in real-time,
|
|
81
|
+
* preserving ANSI color codes printed by the Go binary.
|
|
82
|
+
*/
|
|
83
|
+
export declare function execStream(command: string): Promise<void>;
|
|
84
|
+
//# sourceMappingURL=requirements.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"requirements.d.ts","sourceRoot":"","sources":["../src/requirements.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,mBAAmB,EACpB,MAAM,SAAS,CAAC;AAGjB;;;;;GAKG;AACH,wBAAsB,0BAA0B,CAC9C,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,IAAI,CAAC,CA+Bf;AAED;;;;;;GAMG;AACH,wBAAsB,WAAW,CAC/B,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE;IAAE,OAAO,EAAE,mBAAmB,EAAE,CAAC;IAAC,WAAW,EAAE,OAAO,CAAA;CAAE,EAChE,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,IAAI,CAAC,CAqCf;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,SAAS,CAC7B,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,EACZ,GAAG,EAAE,OAAO,EACZ,KAAK,CAAC,EAAE,MAAM,EACd,WAAW,CAAC,EAAE,MAAM,EACpB,OAAO,GAAE,MAAe,GACvB,OAAO,CAAC,IAAI,CAAC,CAaf;AAED;;;;;;GAMG;AACH,wBAAsB,YAAY,CAChC,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,MAAM,EACd,OAAO,GAAE,MAAe,GACvB,OAAO,CAAC,IAAI,CAAC,CASf;AAED;;;;;;GAMG;AACH,wBAAsB,WAAW,CAC/B,UAAU,EAAE,MAAM,EAClB,OAAO,GAAE,MAAe,GACvB,OAAO,CAAC,MAAM,EAAE,CAAC,CASnB;AAED;;;;;GAKG;AACH,wBAAsB,WAAW,CAC/B,UAAU,EAAE,MAAM,EAClB,OAAO,GAAE,MAAe,GACvB,OAAO,CAAC,IAAI,CAAC,CAOf;AAED;;;;;;GAMG;AACH,wBAAsB,SAAS,CAC7B,UAAU,EAAE,MAAM,EAClB,OAAO,GAAE,MAAe,GACvB,OAAO,CAAC,OAAO,CAAC,CAOlB;AAED;;;;;;GAMG;AACH,wBAAsB,SAAS,CAC7B,UAAU,EAAE,MAAM,EAClB,OAAO,GAAE,MAAe,GACvB,OAAO,CAAC,MAAM,CAAC,CAOjB;AAGD;;;;;;GAMG;AACH,wBAAsB,iBAAiB,CACrC,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,OAAO,CAAC,CASlB;AAID;;;GAGG;AACH,wBAAgB,UAAU,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAwBzD"}
|
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.installRequirementsHandler = installRequirementsHandler;
|
|
4
|
+
exports.applyConfig = applyConfig;
|
|
5
|
+
exports.addDomain = addDomain;
|
|
6
|
+
exports.removeDomain = removeDomain;
|
|
7
|
+
exports.listDomains = listDomains;
|
|
8
|
+
exports.reloadNginx = reloadNginx;
|
|
9
|
+
exports.testNginx = testNginx;
|
|
10
|
+
exports.getStatus = getStatus;
|
|
11
|
+
exports.checkRequirements = checkRequirements;
|
|
12
|
+
exports.execStream = execStream;
|
|
13
|
+
const logger_1 = require("./logger");
|
|
14
|
+
const child_process_1 = require("child_process");
|
|
15
|
+
const execAsync_1 = require("./execAsync");
|
|
16
|
+
/**
|
|
17
|
+
* Installs system requirements using the binary in interactive mode.
|
|
18
|
+
*
|
|
19
|
+
* @param binaryPath - Path to the xynginc binary.
|
|
20
|
+
* @param sudoCmd - Sudo prefix to use.
|
|
21
|
+
*/
|
|
22
|
+
async function installRequirementsHandler(binaryPath, sudoCmd) {
|
|
23
|
+
return new Promise((resolve, reject) => {
|
|
24
|
+
logger_1.Logger.info("[XyNginC] Launching interactive installer...");
|
|
25
|
+
logger_1.Logger.info("[XyNginC] Please respond to any prompts in the terminal.");
|
|
26
|
+
// Handle process environmental logic if running via non-interactive sudo -S
|
|
27
|
+
const cmd = sudoCmd.includes("-S")
|
|
28
|
+
? `${sudoCmd} ${binaryPath} install`
|
|
29
|
+
: `sudo ${binaryPath} install`;
|
|
30
|
+
// Spawn the process with inherited stdio for full interactivity
|
|
31
|
+
const installProcess = (0, child_process_1.spawn)(cmd, {
|
|
32
|
+
stdio: "inherit", // This allows the subprocess to use the parent's stdin/stdout/stderr
|
|
33
|
+
shell: true,
|
|
34
|
+
});
|
|
35
|
+
installProcess.on("close", (code) => {
|
|
36
|
+
if (code === 0) {
|
|
37
|
+
logger_1.Logger.success("[XyNginC] ✓ System requirements installed successfully");
|
|
38
|
+
resolve();
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
reject(new Error(`Installation failed with exit code ${code}`));
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
installProcess.on("error", (error) => {
|
|
45
|
+
reject(new Error(`Failed to start installation: ${error.message}`));
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Applies the configuration using the xynginc binary.
|
|
51
|
+
*
|
|
52
|
+
* @param binaryPath - Path to the xynginc binary.
|
|
53
|
+
* @param config - The configuration object.
|
|
54
|
+
* @param sudoCmd - Sudo prefix to use.
|
|
55
|
+
*/
|
|
56
|
+
async function applyConfig(binaryPath, config, sudoCmd) {
|
|
57
|
+
// Map camelCase to snake_case for Rust core
|
|
58
|
+
const mappedConfig = {
|
|
59
|
+
auto_reload: config.auto_reload,
|
|
60
|
+
domains: config.domains.map((d) => ({
|
|
61
|
+
domain: d.domain,
|
|
62
|
+
port: d.port,
|
|
63
|
+
ssl: d.ssl,
|
|
64
|
+
email: d.email,
|
|
65
|
+
host: d.host,
|
|
66
|
+
max_body_size: d.maxBodySize,
|
|
67
|
+
})),
|
|
68
|
+
};
|
|
69
|
+
const configJson = JSON.stringify(mappedConfig);
|
|
70
|
+
try {
|
|
71
|
+
// Test nginx BEFORE applying new config
|
|
72
|
+
logger_1.Logger.info("[XyNginC] Testing current nginx config...");
|
|
73
|
+
const testResult = await testNginx(binaryPath, sudoCmd);
|
|
74
|
+
if (!testResult) {
|
|
75
|
+
logger_1.Logger.warn("[XyNginC] ⚠️ Current nginx config has errors. Attempting to fix...");
|
|
76
|
+
}
|
|
77
|
+
// Pass config via stdin to avoid shell escaping issues
|
|
78
|
+
await execStream(`echo '${configJson}' | ${sudoCmd} ${binaryPath} apply --config -`);
|
|
79
|
+
}
|
|
80
|
+
catch (error) {
|
|
81
|
+
// If it fails, show more helpful error
|
|
82
|
+
logger_1.Logger.error(`[XyNginC] Failed to apply configuration: ${error.message}`);
|
|
83
|
+
logger_1.Logger.info("[XyNginC] Try running: sudo nginx -t");
|
|
84
|
+
logger_1.Logger.info("[XyNginC] Check: /etc/nginx/sites-enabled/");
|
|
85
|
+
throw new Error(`Failed to apply configuration: ${error.message}`);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Adds a new domain configuration using the binary.
|
|
90
|
+
*
|
|
91
|
+
* @param binaryPath - Path to the xynginc binary.
|
|
92
|
+
* @param domain - The domain name.
|
|
93
|
+
* @param port - The backend port.
|
|
94
|
+
* @param ssl - Whether to enable SSL.
|
|
95
|
+
* @param email - Optional email for SSL.
|
|
96
|
+
* @param maxBodySize - Optional maximum body size.
|
|
97
|
+
* @param sudoCmd - Sudo prefix to use.
|
|
98
|
+
*/
|
|
99
|
+
async function addDomain(binaryPath, domain, port, ssl, email, maxBodySize, sudoCmd = "sudo") {
|
|
100
|
+
const sslFlag = ssl ? "--ssl" : "";
|
|
101
|
+
const emailFlag = email ? `--email ${email}` : "";
|
|
102
|
+
const maxBodySizeFlag = maxBodySize ? `--max-body-size ${maxBodySize}` : "";
|
|
103
|
+
try {
|
|
104
|
+
const { stdout } = await (0, execAsync_1.execAsync)(`${sudoCmd} ${binaryPath} add --domain ${domain} --port ${port} ${sslFlag} ${emailFlag} ${maxBodySizeFlag}`);
|
|
105
|
+
logger_1.Logger.info(stdout.trim());
|
|
106
|
+
}
|
|
107
|
+
catch (error) {
|
|
108
|
+
throw new Error(`Failed to add domain: ${error.message}`);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Removes a domain configuration using the binary.
|
|
113
|
+
*
|
|
114
|
+
* @param binaryPath - Path to the xynginc binary.
|
|
115
|
+
* @param domain - The domain name to remove.
|
|
116
|
+
* @param sudoCmd - Sudo prefix to use.
|
|
117
|
+
*/
|
|
118
|
+
async function removeDomain(binaryPath, domain, sudoCmd = "sudo") {
|
|
119
|
+
try {
|
|
120
|
+
const { stdout } = await (0, execAsync_1.execAsync)(`${sudoCmd} ${binaryPath} remove ${domain}`);
|
|
121
|
+
logger_1.Logger.info(stdout.trim());
|
|
122
|
+
}
|
|
123
|
+
catch (error) {
|
|
124
|
+
throw new Error(`Failed to remove domain: ${error.message}`);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Lists all configured domains.
|
|
129
|
+
*
|
|
130
|
+
* @param binaryPath - Path to the xynginc binary.
|
|
131
|
+
* @param sudoCmd - Sudo prefix to use.
|
|
132
|
+
* @returns A list of domain names.
|
|
133
|
+
*/
|
|
134
|
+
async function listDomains(binaryPath, sudoCmd = "sudo") {
|
|
135
|
+
try {
|
|
136
|
+
const { stdout } = await (0, execAsync_1.execAsync)(`${sudoCmd} ${binaryPath} list`);
|
|
137
|
+
// Parse output to extract domain names
|
|
138
|
+
const lines = stdout.split("\n").filter((line) => line.includes(" - "));
|
|
139
|
+
return lines.map((line) => line.trim().split(" - ")[0]);
|
|
140
|
+
}
|
|
141
|
+
catch (error) {
|
|
142
|
+
throw new Error(`Failed to list domains: ${error.message}`);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Reloads the Nginx service using the binary.
|
|
147
|
+
*
|
|
148
|
+
* @param binaryPath - Path to the xynginc binary.
|
|
149
|
+
* @param sudoCmd - Sudo prefix to use.
|
|
150
|
+
*/
|
|
151
|
+
async function reloadNginx(binaryPath, sudoCmd = "sudo") {
|
|
152
|
+
try {
|
|
153
|
+
const { stdout } = await (0, execAsync_1.execAsync)(`${sudoCmd} ${binaryPath} reload`);
|
|
154
|
+
logger_1.Logger.info(stdout.trim());
|
|
155
|
+
}
|
|
156
|
+
catch (error) {
|
|
157
|
+
throw new Error(`Failed to reload Nginx: ${error.message}`);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Tests the Nginx configuration validity using the binary.
|
|
162
|
+
*
|
|
163
|
+
* @param binaryPath - Path to the xynginc binary.
|
|
164
|
+
* @param sudoCmd - Sudo prefix to use.
|
|
165
|
+
* @returns True if the configuration is valid.
|
|
166
|
+
*/
|
|
167
|
+
async function testNginx(binaryPath, sudoCmd = "sudo") {
|
|
168
|
+
try {
|
|
169
|
+
await (0, execAsync_1.execAsync)(`${sudoCmd} ${binaryPath} test`);
|
|
170
|
+
return true;
|
|
171
|
+
}
|
|
172
|
+
catch {
|
|
173
|
+
return false;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Gets the status of managed sites using the binary.
|
|
178
|
+
*
|
|
179
|
+
* @param binaryPath - Path to the xynginc binary.
|
|
180
|
+
* @param sudoCmd - Sudo prefix to use.
|
|
181
|
+
* @returns The status output.
|
|
182
|
+
*/
|
|
183
|
+
async function getStatus(binaryPath, sudoCmd = "sudo") {
|
|
184
|
+
try {
|
|
185
|
+
const { stdout } = await (0, execAsync_1.execAsync)(`${sudoCmd} ${binaryPath} status`);
|
|
186
|
+
return stdout;
|
|
187
|
+
}
|
|
188
|
+
catch (error) {
|
|
189
|
+
throw new Error(`Failed to get status: ${error.message}`);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Checks if system requirements (Nginx, Certbot) are satisfied using the binary.
|
|
194
|
+
*
|
|
195
|
+
* @param binaryPath - Path to the xynginc binary.
|
|
196
|
+
* @param sudoCmd - Sudo prefix to use.
|
|
197
|
+
* @returns True if requirements are met, false otherwise.
|
|
198
|
+
*/
|
|
199
|
+
async function checkRequirements(binaryPath, sudoCmd) {
|
|
200
|
+
try {
|
|
201
|
+
logger_1.Logger.info("[XyNginC] Checking system requirements...");
|
|
202
|
+
await execStream(`${sudoCmd} ${binaryPath} check`);
|
|
203
|
+
return true;
|
|
204
|
+
}
|
|
205
|
+
catch (error) {
|
|
206
|
+
logger_1.Logger.warn(`[XyNginC] System requirements check failed: ${error.message}`);
|
|
207
|
+
return false;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Executes a shell command and streams its stdout/stderr line-by-line in real-time,
|
|
212
|
+
* preserving ANSI color codes printed by the Go binary.
|
|
213
|
+
*/
|
|
214
|
+
function execStream(command) {
|
|
215
|
+
return new Promise((resolve, reject) => {
|
|
216
|
+
const child = (0, child_process_1.spawn)(command, { shell: true });
|
|
217
|
+
let stderrData = "";
|
|
218
|
+
child.stdout.on("data", (data) => {
|
|
219
|
+
// Print raw data so inner ANSI codes from Go are preserved directly in PM2
|
|
220
|
+
process.stdout.write(data);
|
|
221
|
+
});
|
|
222
|
+
child.stderr.on("data", (data) => {
|
|
223
|
+
const msg = data.toString();
|
|
224
|
+
// Filter out the interactive sudo prompt from stderr output
|
|
225
|
+
if (!msg.includes("[sudo] password for")) {
|
|
226
|
+
process.stdout.write(data); // Write to stdout to avoid PM2 red-error highlighting
|
|
227
|
+
}
|
|
228
|
+
stderrData += msg;
|
|
229
|
+
});
|
|
230
|
+
child.on("close", (code) => {
|
|
231
|
+
if (code === 0)
|
|
232
|
+
resolve();
|
|
233
|
+
else
|
|
234
|
+
reject(new Error(`Command failed with code ${code}.`));
|
|
235
|
+
});
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
//# sourceMappingURL=requirements.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"requirements.js","sourceRoot":"","sources":["../src/requirements.ts"],"names":[],"mappings":";;AAaA,gEAkCC;AASD,kCAyCC;AAaD,8BAqBC;AASD,oCAaC;AASD,kCAYC;AAQD,kCAUC;AASD,8BAUC;AASD,8BAUC;AAUD,8CAYC;AAQD,gCAwBC;AA5RD,qCAAkC;AAClC,iDAAsC;AAItC,2CAAwC;AAExC;;;;;GAKG;AACI,KAAK,UAAU,0BAA0B,CAC9C,UAAkB,EAClB,OAAe;IAEf,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACrC,eAAM,CAAC,IAAI,CAAC,8CAA8C,CAAC,CAAC;QAC5D,eAAM,CAAC,IAAI,CAAC,0DAA0D,CAAC,CAAC;QAExE,4EAA4E;QAC5E,MAAM,GAAG,GAAG,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC;YAChC,CAAC,CAAC,GAAG,OAAO,IAAI,UAAU,UAAU;YACpC,CAAC,CAAC,QAAQ,UAAU,UAAU,CAAC;QAEjC,gEAAgE;QAChE,MAAM,cAAc,GAAG,IAAA,qBAAK,EAAC,GAAG,EAAE;YAChC,KAAK,EAAE,SAAS,EAAE,qEAAqE;YACvF,KAAK,EAAE,IAAI;SACZ,CAAC,CAAC;QAEH,cAAc,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,IAAI,EAAE,EAAE;YAClC,IAAI,IAAI,KAAK,CAAC,EAAE,CAAC;gBACf,eAAM,CAAC,OAA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CAAC;AAID;;;GAGG;AACH,SAAgB,UAAU,CAAC,OAAe;IACxC,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACrC,MAAM,KAAK,GAAG,IAAA,qBAAK,EAAC,OAAO,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;QAC9C,IAAI,UAAU,GAAG,EAAE,CAAC;QAEpB,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,EAAE;YAC/B,2EAA2E;YAC3E,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAC7B,CAAC,CAAC,CAAC;QAEH,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,EAAE;YAC/B,MAAM,GAAG,GAAG,IAAI,CAAC,QAAQ,EAAE,CAAC;YAC5B,4DAA4D;YAC5D,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,qBAAqB,CAAC,EAAE,CAAC;gBACzC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,sDAAsD;YACpF,CAAC;YACD,UAAU,IAAI,GAAG,CAAC;QACpB,CAAC,CAAC,CAAC;QAEH,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,IAAI,EAAE,EAAE;YACzB,IAAI,IAAI,KAAK,CAAC;gBAAE,OAAO,EAAE,CAAC;;gBACrB,MAAM,CAAC,IAAI,KAAK,CAAC,4BAA4B,IAAI,GAAG,CAAC,CAAC,CAAC;QAC9D,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { XyNginCDomainConfig } from "./types";
|
|
2
|
+
export declare function startXNCPlugin(server: any, options: {
|
|
3
|
+
binaryPath?: string;
|
|
4
|
+
autoDownload: boolean;
|
|
5
|
+
version: string;
|
|
6
|
+
domains: XyNginCDomainConfig[];
|
|
7
|
+
autoReload: boolean;
|
|
8
|
+
installRequirements: boolean;
|
|
9
|
+
sudoPassword: string;
|
|
10
|
+
}): Promise<void>;
|
|
11
|
+
//# sourceMappingURL=startPlugin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"startPlugin.d.ts","sourceRoot":"","sources":["../src/startPlugin.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAiC9C,wBAAsB,cAAc,CAClC,MAAM,EAAE,GAAG,EACX,OAAO,EAAE;IACP,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,OAAO,CAAC;IACtB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,mBAAmB,EAAE,CAAC;IAC/B,UAAU,EAAE,OAAO,CAAC;IACpB,mBAAmB,EAAE,OAAO,CAAC;IAC7B,YAAY,EAAE,MAAM,CAAC;CACtB,iBAoFF"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.startXNCPlugin = startXNCPlugin;
|
|
4
|
+
const ensureBinary_1 = require("./ensureBinary");
|
|
5
|
+
const logger_1 = require("./logger");
|
|
6
|
+
const requirements_1 = require("./requirements");
|
|
7
|
+
const getSudo = (sudoPassword) => {
|
|
8
|
+
// Attempt multiple ways to get the password, including XyPriss internal env if somehow exposed
|
|
9
|
+
const envPwd = process.env.SUDO_PASSWORD;
|
|
10
|
+
// || (global as any).__sys__?.$env?.("SUDO_PASSWORD");
|
|
11
|
+
const pwd = sudoPassword || envPwd;
|
|
12
|
+
if (pwd) {
|
|
13
|
+
if (sudoPassword) {
|
|
14
|
+
logger_1.Logger.info(`[XyNginC] Using sudo password provided via plugin options(${sudoPassword}).`);
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
logger_1.Logger.info("[XyNginC] Using sudo password injected from environment variables.");
|
|
18
|
+
}
|
|
19
|
+
return `echo '${pwd}' | sudo -S`;
|
|
20
|
+
}
|
|
21
|
+
logger_1.Logger.warn("[XyNginC] ⚠️ No sudo password provided. Falling back to non-interactive mode (sudo -n).");
|
|
22
|
+
logger_1.Logger.warn("[XyNginC] ⚠️ If the command requires a password, it will fail immediately instead of hanging.");
|
|
23
|
+
// Return non-interactive sudo to prevent infinite blocking/hanging
|
|
24
|
+
return "sudo -n";
|
|
25
|
+
};
|
|
26
|
+
async function startXNCPlugin(server, options) {
|
|
27
|
+
const { binaryPath, autoDownload, version, domains, autoReload, installRequirements, sudoPassword, } = options;
|
|
28
|
+
logger_1.Logger.info("[XyNginC] Initializing Nginx Controller...");
|
|
29
|
+
try {
|
|
30
|
+
// 1. Ensure binary exists
|
|
31
|
+
const binary = await (0, ensureBinary_1.ensureBinary)(binaryPath, autoDownload, version);
|
|
32
|
+
logger_1.Logger.success(`[XyNginC] ✓ Binary located: ${binary}`);
|
|
33
|
+
// 2. Check system requirements
|
|
34
|
+
logger_1.Logger.info("[XyNginC] Checking system requirements...");
|
|
35
|
+
// Check if requirements are satisfied
|
|
36
|
+
const requirementsOk = await (0, requirements_1.checkRequirements)(binary, getSudo(sudoPassword));
|
|
37
|
+
// Install requirements if enabled and needed
|
|
38
|
+
if (!requirementsOk && installRequirements) {
|
|
39
|
+
logger_1.Logger.info("[XyNginC] Requirements missing, installing automatically...");
|
|
40
|
+
await (0, requirements_1.installRequirementsHandler)(binary, getSudo(sudoPassword));
|
|
41
|
+
logger_1.Logger.info("[XyNginC] Requirements installed, re-checking...");
|
|
42
|
+
await (0, requirements_1.checkRequirements)(binary, getSudo(sudoPassword));
|
|
43
|
+
}
|
|
44
|
+
else if (!requirementsOk) {
|
|
45
|
+
throw new Error("[XyNginC] System requirements not satisfied. Install with 'installRequirements: true' or run: sudo xynginc install");
|
|
46
|
+
}
|
|
47
|
+
// 3. Apply configuration
|
|
48
|
+
logger_1.Logger.info("[XyNginC] Applying configuration...");
|
|
49
|
+
await (0, requirements_1.applyConfig)(binary, { domains, auto_reload: autoReload }, getSudo(sudoPassword));
|
|
50
|
+
logger_1.Logger.success("[XyNginC] Configuration applied successfully!");
|
|
51
|
+
// Expose CLI helper methods on server
|
|
52
|
+
server.xynginc = {
|
|
53
|
+
addDomain: (domain, port, ssl = false, email, maxBodySize) => (0, requirements_1.addDomain)(binary, domain, port, ssl, email, maxBodySize, getSudo(sudoPassword)),
|
|
54
|
+
removeDomain: (domain) => (0, requirements_1.removeDomain)(binary, domain, getSudo(sudoPassword)),
|
|
55
|
+
listDomains: () => (0, requirements_1.listDomains)(binary, getSudo(sudoPassword)),
|
|
56
|
+
reload: () => (0, requirements_1.reloadNginx)(binary, getSudo(sudoPassword)),
|
|
57
|
+
test: () => (0, requirements_1.testNginx)(binary, getSudo(sudoPassword)),
|
|
58
|
+
status: () => (0, requirements_1.getStatus)(binary, getSudo(sudoPassword)),
|
|
59
|
+
installRequirements: () => (0, requirements_1.installRequirementsHandler)(binary, getSudo(sudoPassword)),
|
|
60
|
+
};
|
|
61
|
+
logger_1.Logger.info("[XyNginC] Server methods available: server.xynginc.*");
|
|
62
|
+
}
|
|
63
|
+
catch (error) {
|
|
64
|
+
logger_1.Logger.error(`[XyNginC] ✖ Failed to initialize: ${error}`);
|
|
65
|
+
throw error;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=startPlugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"startPlugin.js","sourceRoot":"","sources":["../src/startPlugin.ts"],"names":[],"mappings":";;AA8CA,wCA8FC;AA5ID,iDAA8C;AAC9C,qCAAkC;AAClC,iDAUwB;AAGxB,MAAM,OAAO,GAAG,CAAC,YAAoB,EAAE,EAAE;IACvC,+FAA+F;IAC/F,MAAM,MAAM,GACV,OAAO,CAAC,GAAG,CAAC,aAAa,CAAA;IAC3B,uDAAuD;IACvD,MAAM,GAAG,GAAG,Y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;YACtD,mBAAmB,EAAE,GAAG,EAAE,CACxB,IAAA,yCAA0B,EAAC,MAAM,EAAE,OAAO,CAAC,YAAY,CAAC,CAAC;SAC5D,CAAC;QAEF,eAAM,CAAC,IAAI,CAAC,sDAAsD,CAAC,CAAC;IACtE,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,eAAM,CAAC,KAAK,CAAC,qCAAqC,KAAK,EAAE,CAAC,CAAC;QAC3D,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { XyNginCConfig } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* Validates the plugin configuration.
|
|
4
|
+
*
|
|
5
|
+
* @param config - The configuration to validate.
|
|
6
|
+
* @throws Error if the configuration is invalid.
|
|
7
|
+
*/
|
|
8
|
+
export declare function validateConfig(config: XyNginCConfig): void;
|
|
9
|
+
//# sourceMappingURL=validateConfig.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validateConfig.d.ts","sourceRoot":"","sources":["../src/validateConfig.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAExC;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,aAAa,GAAG,IAAI,CAyC1D"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateConfig = validateConfig;
|
|
4
|
+
/**
|
|
5
|
+
* Validates the plugin configuration.
|
|
6
|
+
*
|
|
7
|
+
* @param config - The configuration to validate.
|
|
8
|
+
* @throws Error if the configuration is invalid.
|
|
9
|
+
*/
|
|
10
|
+
function validateConfig(config) {
|
|
11
|
+
if (!config.domains || config.domains.length === 0) {
|
|
12
|
+
throw new Error("[XyNginC] Configuration error: 'domains' array cannot be empty");
|
|
13
|
+
}
|
|
14
|
+
for (const domain of config.domains) {
|
|
15
|
+
if (!domain.domain || typeof domain.domain !== "string") {
|
|
16
|
+
throw new Error("[XyNginC] Configuration error: 'domain' must be a non-empty string");
|
|
17
|
+
}
|
|
18
|
+
if (!domain.port ||
|
|
19
|
+
typeof domain.port !== "number" ||
|
|
20
|
+
domain.port < 1 ||
|
|
21
|
+
domain.port > 65535) {
|
|
22
|
+
throw new Error(`[XyNginC] Configuration error: 'port' must be between 1-65535 for ${domain.domain}`);
|
|
23
|
+
}
|
|
24
|
+
if (domain.ssl && !domain.email) {
|
|
25
|
+
throw new Error(`[XyNginC] Configuration error: 'email' is required when SSL is enabled for ${domain.domain}`);
|
|
26
|
+
}
|
|
27
|
+
// Set default host to localhost if not provided
|
|
28
|
+
if (!domain.host) {
|
|
29
|
+
domain.host = "localhost";
|
|
30
|
+
}
|
|
31
|
+
// Set default maxBodySize if not provided
|
|
32
|
+
if (!domain.maxBodySize) {
|
|
33
|
+
domain.maxBodySize = "20M";
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=validateConfig.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validateConfig.js","sourceRoot":"","sources":["../src/validateConfig.ts"],"names":[],"mappings":";;AAQA,wCAyCC;AA/CD;;;;;GAKG;AACH,SAAgB,cAAc,CAAC,MAAqB;IAClD,IAAI,CAAC,MAAM,CAAC,OAAO,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACnD,MAAM,IAAI,KAAK,CACb,gEAAgE,CACjE,CAAC;IACJ,CAAC;IAED,KAAK,MAAM,MAAM,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;QACpC,IAAI,CAAC,MAAM,CAAC,MAAM,IAAI,OAAO,MAAM,CAAC,MAAM,KAAK,QAAQ,EAAE,CAAC;YACxD,MAAM,IAAI,KAAK,CACb,oEAAoE,CACrE,CAAC;QACJ,CAAC;QAED,IACE,CAAC,MAAM,CAAC,IAAI;YACZ,OAAO,MAAM,CAAC,IAAI,KAAK,QAAQ;YAC/B,MAAM,CAAC,IAAI,GAAG,CAAC;YACf,MAAM,CAAC,IAAI,GAAG,KAAK,EACnB,CAAC;YACD,MAAM,IAAI,KAAK,CACb,qEAAqE,MAAM,CAAC,MAAM,EAAE,CACrF,CAAC;QACJ,CAAC;QAED,IAAI,MAAM,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;YAChC,MAAM,IAAI,KAAK,CACb,8EAA8E,MAAM,CAAC,MAAM,EAAE,CAC9F,CAAC;QACJ,CAAC;QAED,gDAAgD;QAChD,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;YACjB,MAAM,CAAC,IAAI,GAAG,WAAW,CAAC;QAC5B,CAAC;QAED,0CAA0C;QAC1C,IAAI,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC;YACxB,MAAM,CAAC,WAAW,GAAG,KAAK,CAAC;QAC7B,CAAC;IACH,CAAC;AACH,CAAC"}
|