xynginc 1.0.92 → 1.0.94
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/index.js +7 -1
- package/dist/mods/getHostEnv.d.ts +5 -0
- package/dist/mods/getHostEnv.js +73 -0
- package/dist/startPlugin.js +15 -27
- package/package.json +1 -1
- package/xypriss.plugin.xsig +4 -4
package/dist/index.js
CHANGED
|
@@ -7,6 +7,7 @@ import { Plugin } from "xypriss";
|
|
|
7
7
|
import { Logger } from "./mods/logger";
|
|
8
8
|
import { validateConfig } from "./mods/validateConfig";
|
|
9
9
|
import { startXNCPlugin } from "./startPlugin";
|
|
10
|
+
import { getHostEnv } from "./mods/getHostEnv";
|
|
10
11
|
/**
|
|
11
12
|
* XyNginC Plugin for XyPriss.
|
|
12
13
|
* Automates Nginx and SSL management for your server.
|
|
@@ -17,6 +18,11 @@ import { startXNCPlugin } from "./startPlugin";
|
|
|
17
18
|
export default function XNCP(options) {
|
|
18
19
|
const { domains, autoReload = true, autoFixFirewall = false, binaryPath, autoDownload = true, version = "latest", installRequirements = true, sudoPassword, } = options;
|
|
19
20
|
const pkg = Plugin.manifest(__sys__);
|
|
21
|
+
const effectiveSudoPassword = sudoPassword ||
|
|
22
|
+
getHostEnv("SUDO_PASSWORD") ||
|
|
23
|
+
getHostEnv("XY_SUDO_PASSWORD") ||
|
|
24
|
+
getHostEnv("XYPRISS_SUDO_PASSWORD") ||
|
|
25
|
+
"";
|
|
20
26
|
return Plugin.create({
|
|
21
27
|
name: pkg.name,
|
|
22
28
|
version: pkg.version,
|
|
@@ -35,7 +41,7 @@ export default function XNCP(options) {
|
|
|
35
41
|
version,
|
|
36
42
|
domains,
|
|
37
43
|
installRequirements,
|
|
38
|
-
sudoPassword:
|
|
44
|
+
sudoPassword: effectiveSudoPassword,
|
|
39
45
|
});
|
|
40
46
|
},
|
|
41
47
|
onServerStop: async () => {
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import path from "path";
|
|
3
|
+
/**
|
|
4
|
+
* Recovers environment variables from the host application, bypassing
|
|
5
|
+
* the XyPriss caller-isolation sandbox if not explicitly injected.
|
|
6
|
+
*/
|
|
7
|
+
export function getHostEnv(key) {
|
|
8
|
+
// 1. Inspect XyPriss internal Symbol-keyed store map on globalThis
|
|
9
|
+
try {
|
|
10
|
+
const symbols = Object.getOwnPropertySymbols(globalThis);
|
|
11
|
+
const envStoreSym = symbols.find((s) => s.description === "__xy_env_store__" ||
|
|
12
|
+
String(s).includes("__xy_env_store__"));
|
|
13
|
+
if (envStoreSym && globalThis[envStoreSym]) {
|
|
14
|
+
const storeMap = globalThis[envStoreSym];
|
|
15
|
+
for (const [root, env] of storeMap.entries()) {
|
|
16
|
+
if (env && typeof env[key] === "string" && env[key].length > 0) {
|
|
17
|
+
return env[key];
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
catch {
|
|
23
|
+
// Ignore error
|
|
24
|
+
}
|
|
25
|
+
// 2. Direct process.env check for whitelisted prefixes (allowed by XyPriss Environment Shield)
|
|
26
|
+
try {
|
|
27
|
+
const prefixes = ["", "XY_", "XYPRISS_", "__"];
|
|
28
|
+
for (const prefix of prefixes) {
|
|
29
|
+
const val = process.env[`${prefix}${key}`];
|
|
30
|
+
if (typeof val === "string" && val.length > 0) {
|
|
31
|
+
return val;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
// Shield might block
|
|
37
|
+
}
|
|
38
|
+
// 3. Fallback: Parse .env directly from process.cwd() or parent directories
|
|
39
|
+
try {
|
|
40
|
+
let currentDir = process.cwd();
|
|
41
|
+
const systemRoot = path.parse(currentDir).root;
|
|
42
|
+
while (currentDir && currentDir !== systemRoot) {
|
|
43
|
+
const envPath = path.join(currentDir, ".env");
|
|
44
|
+
if (fs.existsSync(envPath)) {
|
|
45
|
+
const content = fs.readFileSync(envPath, "utf-8");
|
|
46
|
+
const lines = content.replace(/\r\n?/gm, "\n").split("\n");
|
|
47
|
+
for (const line of lines) {
|
|
48
|
+
const trimmed = line.trim();
|
|
49
|
+
if (!trimmed || trimmed.startsWith("#"))
|
|
50
|
+
continue;
|
|
51
|
+
const match = trimmed.match(/^([^=]+)=(.*)$/);
|
|
52
|
+
if (match) {
|
|
53
|
+
const varName = match[1].trim();
|
|
54
|
+
if (varName === key) {
|
|
55
|
+
let value = match[2].trim();
|
|
56
|
+
// Remove surrounding quotes if present
|
|
57
|
+
if ((value.startsWith('"') && value.endsWith('"')) ||
|
|
58
|
+
(value.startsWith("'") && value.endsWith("'"))) {
|
|
59
|
+
value = value.slice(1, -1);
|
|
60
|
+
}
|
|
61
|
+
return value;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
currentDir = path.dirname(currentDir);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
catch {
|
|
70
|
+
// Ignore error
|
|
71
|
+
}
|
|
72
|
+
return undefined;
|
|
73
|
+
}
|
package/dist/startPlugin.js
CHANGED
|
@@ -1,35 +1,23 @@
|
|
|
1
1
|
import { ensureBinary } from "./mods/ensureBinary";
|
|
2
2
|
import { Logger } from "./mods/logger";
|
|
3
3
|
import { addDomain, applyConfig, checkRequirements, getStatus, installRequirementsHandler, listDomains, reloadNginx, removeDomain, testNginx, } from "./mods/requirements";
|
|
4
|
+
import { getHostEnv } from "./mods/getHostEnv";
|
|
4
5
|
const getSudo = (sudoPassword) => {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
globalThis.__sys__?._internalRoot ||
|
|
10
|
-
process.cwd();
|
|
11
|
-
if (typeof __sys__.__env__.getForRoot === "function") {
|
|
12
|
-
pwd = __sys__.__env__.getForRoot("SUDO_PASSWORD", projectRoot);
|
|
13
|
-
}
|
|
14
|
-
if (!pwd) {
|
|
15
|
-
pwd = __sys__.__env__.get("SUDO_PASSWORD");
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
// Strip wrapping quotes if present in .env (e.g., SUDO_PASSWORD="Test")
|
|
19
|
-
if (pwd) {
|
|
20
|
-
if ((pwd.startsWith('"') && pwd.endsWith('"')) ||
|
|
21
|
-
(pwd.startsWith("'") && pwd.endsWith("'"))) {
|
|
22
|
-
pwd = pwd.slice(1, -1);
|
|
23
|
-
}
|
|
6
|
+
// 1. Direct option passed by the user
|
|
7
|
+
if (sudoPassword) {
|
|
8
|
+
Logger.info(`[XyNginC] Using sudo password provided via plugin options(${sudoPassword.slice(0, 2)}***).`);
|
|
9
|
+
return `echo '${sudoPassword}' | sudo -S`;
|
|
24
10
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
11
|
+
// 2. Multi-tier resolution of SUDO_PASSWORD from the host environment
|
|
12
|
+
const envPwd = getHostEnv("SUDO_PASSWORD") ||
|
|
13
|
+
getHostEnv("XY_SUDO_PASSWORD") ||
|
|
14
|
+
getHostEnv("XYPRISS_SUDO_PASSWORD") ||
|
|
15
|
+
(typeof __sys__ !== "undefined"
|
|
16
|
+
? __sys__.__env__?.get("SUDO_PASSWORD")
|
|
17
|
+
: undefined);
|
|
18
|
+
if (envPwd) {
|
|
19
|
+
Logger.info("[XyNginC] Using sudo password injected from environment variables.");
|
|
20
|
+
return `echo '${envPwd}' | sudo -S`;
|
|
33
21
|
}
|
|
34
22
|
Logger.warn("[XyNginC] ⚠️ No sudo password provided. Falling back to non-interactive mode (sudo -n).");
|
|
35
23
|
Logger.warn("[XyNginC] ⚠️ If the command requires a password, it will fail immediately instead of hanging.");
|
package/package.json
CHANGED
package/xypriss.plugin.xsig
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
--- XYPRISS SIGNATURE (G3) ---
|
|
2
|
-
Manifest: xynginc@1.0.
|
|
2
|
+
Manifest: xynginc@1.0.94
|
|
3
3
|
Min-Engine: 1.0.81
|
|
4
|
-
Fingerprint: sha256:
|
|
4
|
+
Fingerprint: sha256:02cff76c2401603f866188ef21d27dcc33cb8786e4353384ae479b51cb185e4b
|
|
5
5
|
Identity: ed25519:0e2e1accdbba45480979305256d50d368ae6cc2c0d7ee378c5f1999ae834cf58
|
|
6
6
|
Privileges: XHS.HOOK.LIFECYCLE.REGISTER,XHS.HOOK.LIFECYCLE.SERVER_START,XHS.HOOK.LIFECYCLE.SERVER_STOP,XHS.HOOK.LIFECYCLE.SERVER_READY
|
|
7
|
-
Expires: 2027-09-
|
|
7
|
+
Expires: 2027-09-12T18:05:47Z
|
|
8
8
|
Revision: sha256:none
|
|
9
9
|
--- BEGIN CRYPTOGRAPHIC PROOF ---
|
|
10
|
-
base64:
|
|
10
|
+
base64:mdMvFSrts0+fvRJHfgoqVfjr7Sc5QosURA5ZuYacpdCzdUOtFyeBrGPB/uScomtRQD4LWU3X8Ms4Q5UsiiYHBA==
|
|
11
11
|
--- END XYPRISS SIGNATURE ---
|