witnora 0.18.8 → 0.18.9

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.
@@ -7,6 +7,8 @@ import { promisify } from "node:util";
7
7
  const execFileAsync = promisify(execFile);
8
8
  export async function installGatewayService(input) {
9
9
  const plan = createGatewayServicePlan(input);
10
+ if (plan.launcher)
11
+ await input.writeDefinition(plan.launcher.path, plan.launcher.definition);
10
12
  await input.writeDefinition(plan.definitionPath, plan.definition);
11
13
  if (plan.kind === "SYSTEMD_USER")
12
14
  await input.run("systemctl", ["--user", "daemon-reload"]);
@@ -35,6 +37,8 @@ export async function uninstallCurrentGatewayService(options) {
35
37
  if (plan.kind === "SYSTEMD_USER")
36
38
  await run("systemctl", ["--user", "daemon-reload"]);
37
39
  await rm(plan.definitionPath, { force: true });
40
+ if (plan.launcher)
41
+ await rm(plan.launcher.path, { force: true });
38
42
  return { uninstalled: true, plan };
39
43
  }
40
44
  export async function restartCurrentGatewayService(options) {
@@ -58,17 +62,23 @@ export function createGatewayServicePlan(input) {
58
62
  }
59
63
  function windowsPlan(input, id, args) {
60
64
  const definitionPath = `${input.serviceHome}\\${id}.xml`;
61
- const hiddenCommand = `& ${[input.nodeExecutable, ...args].map(powerShellArgument).join(" ")}`;
62
- const argumentsValue = ["-NoLogo", "-NoProfile", "-NonInteractive", "-WindowStyle", "Hidden", "-Command", hiddenCommand]
63
- .map(windowsArgument).join(" ");
65
+ const launcherPath = `${input.serviceHome}\\${id}.vbs`;
66
+ const commandLine = [input.nodeExecutable, ...args].map(windowsArgument).join(" ");
67
+ const launcherDefinition = [
68
+ 'Set shell = CreateObject("WScript.Shell")',
69
+ `shell.CurrentDirectory = ${vbScriptString(input.repository)}`,
70
+ `exitCode = shell.Run(${vbScriptString(commandLine)}, 0, True)`,
71
+ "WScript.Quit exitCode",
72
+ ].join("\r\n");
73
+ const argumentsValue = ["//B", "//NoLogo", launcherPath].map(windowsArgument).join(" ");
64
74
  const definition = `<?xml version="1.0" encoding="UTF-16"?>
65
75
  <Task version="1.4" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
66
76
  <Triggers><LogonTrigger><Enabled>true</Enabled><UserId>${xml(input.userId)}</UserId></LogonTrigger></Triggers>
67
77
  <Principals><Principal id="Author"><UserId>${xml(input.userId)}</UserId><LogonType>InteractiveToken</LogonType><RunLevel>LeastPrivilege</RunLevel></Principal></Principals>
68
- <Settings><MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy><StartWhenAvailable>true</StartWhenAvailable><ExecutionTimeLimit>PT0S</ExecutionTimeLimit><RestartOnFailure><Interval>PT1M</Interval><Count>999</Count></RestartOnFailure></Settings>
69
- <Actions Context="Author"><Exec><Command>powershell.exe</Command><Arguments>${xml(argumentsValue)}</Arguments><WorkingDirectory>${xml(input.repository)}</WorkingDirectory></Exec></Actions>
78
+ <Settings><MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy><StartWhenAvailable>true</StartWhenAvailable><Hidden>true</Hidden><ExecutionTimeLimit>PT0S</ExecutionTimeLimit><RestartOnFailure><Interval>PT1M</Interval><Count>999</Count></RestartOnFailure></Settings>
79
+ <Actions Context="Author"><Exec><Command>wscript.exe</Command><Arguments>${xml(argumentsValue)}</Arguments><WorkingDirectory>${xml(input.repository)}</WorkingDirectory></Exec></Actions>
70
80
  </Task>`;
71
- return { id, kind: "WINDOWS_TASK", definitionPath, definition,
81
+ return { id, kind: "WINDOWS_TASK", definitionPath, definition, launcher: { path: launcherPath, definition: launcherDefinition },
72
82
  install: { command: "schtasks.exe", args: ["/Create", "/TN", id, "/XML", definitionPath, "/F"] },
73
83
  start: { command: "schtasks.exe", args: ["/Run", "/TN", id] },
74
84
  stop: { command: "schtasks.exe", args: ["/End", "/TN", id] },
@@ -108,6 +118,6 @@ function launchdPlan(input, id, args) {
108
118
  uninstall: { command: "launchctl", args: ["bootout", domain, definitionPath] } };
109
119
  }
110
120
  function windowsArgument(value) { return `"${value.replaceAll('"', '\\"')}"`; }
111
- function powerShellArgument(value) { return `'${value.replaceAll("'", "''")}'`; }
121
+ function vbScriptString(value) { return `"${value.replaceAll('"', '""')}"`; }
112
122
  function systemd(value) { return `"${value.replaceAll("\\", "\\\\").replaceAll('"', '\\"')}"`; }
113
123
  function xml(value) { return value.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;").replaceAll('"', "&quot;").replaceAll("'", "&apos;"); }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "witnora",
3
- "version": "0.18.8",
3
+ "version": "0.18.9",
4
4
  "description": "Independent assurance for covered agent action paths across models and frameworks.",
5
5
  "type": "module",
6
6
  "license": "SEE LICENSE IN LICENSE",