aiservermanager 0.6.6 → 0.7.0
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/backend/dist/files/grantLogonServiceRight.ps1 +171 -0
- package/backend/dist/files/winsw/LICENSE-WinSW.txt +21 -0
- package/backend/dist/files/winsw/WinSW-x64.exe +0 -0
- package/backend/dist/helpers/ExecTools.js +22 -5
- package/backend/dist/helpers/ExecTools.js.map +1 -1
- package/backend/dist/helpers/ServerIdentity.js +64 -0
- package/backend/dist/helpers/ServerIdentity.js.map +1 -0
- package/backend/dist/index.js +18 -4
- package/backend/dist/index.js.map +1 -1
- package/backend/dist/models/ServiceConfig.js +54 -6
- package/backend/dist/models/ServiceConfig.js.map +1 -1
- package/backend/dist/routes/serviceRoutes.js +11 -3
- package/backend/dist/routes/serviceRoutes.js.map +1 -1
- package/backend/dist/routes/systemRoutes.js +3 -1
- package/backend/dist/routes/systemRoutes.js.map +1 -1
- package/backend/dist/services/controllers/systemctlController.js +29 -3
- package/backend/dist/services/controllers/systemctlController.js.map +1 -1
- package/backend/dist/services/controllers/windowsServiceController.js +419 -93
- package/backend/dist/services/controllers/windowsServiceController.js.map +1 -1
- package/backend/dist/services/helpers/winswConfig.js +248 -0
- package/backend/dist/services/helpers/winswConfig.js.map +1 -0
- package/backend/dist/services/helpers/winswLog.js +28 -0
- package/backend/dist/services/helpers/winswLog.js.map +1 -0
- package/backend/dist/services/serviceConfigController.js +25 -6
- package/backend/dist/services/serviceConfigController.js.map +1 -1
- package/backend/dist/services/serviceManager.js +11 -4
- package/backend/dist/services/serviceManager.js.map +1 -1
- package/backend/public/browser/{chunk-XHW7OYSF.js → chunk-P5KEWYS5.js} +1 -1
- package/backend/public/browser/chunk-QZRO6WVW.js +4 -0
- package/backend/public/browser/index.html +1 -1
- package/backend/public/browser/{main-FY4VDMXL.js → main-2RRTWG2U.js} +48 -48
- package/package.json +1 -1
- package/backend/public/browser/chunk-3RZETQM3.js +0 -4
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
param(
|
|
2
|
+
[string]$Domain = $env:SM_ACCOUNT_DOMAIN,
|
|
3
|
+
[string]$User = $env:SM_ACCOUNT_NAME,
|
|
4
|
+
[string]$Right = "SeServiceLogonRight"
|
|
5
|
+
)
|
|
6
|
+
|
|
7
|
+
# Grants a user right to a service account through the LSA policy API — the same
|
|
8
|
+
# store secpol.msc edits. The Service Control Manager refuses to log a service
|
|
9
|
+
# account on (error 1069, System log event 7041) until the account holds
|
|
10
|
+
# SeServiceLogonRight, and registering the service does not grant it.
|
|
11
|
+
#
|
|
12
|
+
# Account is taken from the command line or from SM_ACCOUNT_DOMAIN /
|
|
13
|
+
# SM_ACCOUNT_NAME, so the caller never puts the identity in a shell string.
|
|
14
|
+
# Prints "OK: …" on success, "FAIL: …" plus a non-zero exit code otherwise.
|
|
15
|
+
$code = @'
|
|
16
|
+
using System;
|
|
17
|
+
using System.Runtime.InteropServices;
|
|
18
|
+
|
|
19
|
+
public static class LsaRights
|
|
20
|
+
{
|
|
21
|
+
[StructLayout(LayoutKind.Sequential)]
|
|
22
|
+
private struct LSA_UNICODE_STRING
|
|
23
|
+
{
|
|
24
|
+
public ushort Length;
|
|
25
|
+
public ushort MaximumLength;
|
|
26
|
+
public IntPtr Buffer;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
[StructLayout(LayoutKind.Sequential)]
|
|
30
|
+
private struct LSA_OBJECT_ATTRIBUTES
|
|
31
|
+
{
|
|
32
|
+
public int Length;
|
|
33
|
+
public IntPtr RootDirectory;
|
|
34
|
+
public IntPtr ObjectName;
|
|
35
|
+
public int Attributes;
|
|
36
|
+
public IntPtr SecurityDescriptor;
|
|
37
|
+
public IntPtr SecurityQualityOfService;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
private const int POLICY_ALL_ACCESS = 0x000F003F;
|
|
41
|
+
private const int STATUS_OBJECT_NAME_NOT_FOUND = unchecked((int)0xC0000034);
|
|
42
|
+
|
|
43
|
+
[DllImport("advapi32.dll", SetLastError = true)]
|
|
44
|
+
private static extern int LsaOpenPolicy(IntPtr SystemName, ref LSA_OBJECT_ATTRIBUTES ObjectAttributes, int Access, out IntPtr PolicyHandle);
|
|
45
|
+
|
|
46
|
+
[DllImport("advapi32.dll", SetLastError = true)]
|
|
47
|
+
private static extern int LsaAddAccountRights(IntPtr PolicyHandle, byte[] AccountSid, LSA_UNICODE_STRING[] UserRights, int CountOfRights);
|
|
48
|
+
|
|
49
|
+
[DllImport("advapi32.dll")]
|
|
50
|
+
private static extern int LsaEnumerateAccountRights(IntPtr PolicyHandle, byte[] AccountSid, out IntPtr UserRights, out uint CountOfRights);
|
|
51
|
+
|
|
52
|
+
[DllImport("advapi32.dll")]
|
|
53
|
+
private static extern int LsaFreeMemory(IntPtr Buffer);
|
|
54
|
+
|
|
55
|
+
[DllImport("advapi32.dll")]
|
|
56
|
+
private static extern int LsaClose(IntPtr PolicyHandle);
|
|
57
|
+
|
|
58
|
+
[DllImport("advapi32.dll")]
|
|
59
|
+
private static extern int LsaNtStatusToWinError(int Status);
|
|
60
|
+
|
|
61
|
+
private static int Open(out IntPtr policy)
|
|
62
|
+
{
|
|
63
|
+
var oa = new LSA_OBJECT_ATTRIBUTES { Length = Marshal.SizeOf(typeof(LSA_OBJECT_ATTRIBUTES)) };
|
|
64
|
+
return LsaOpenPolicy(IntPtr.Zero, ref oa, POLICY_ALL_ACCESS, out policy);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
private static LSA_UNICODE_STRING ToLsaString(string value)
|
|
68
|
+
{
|
|
69
|
+
return new LSA_UNICODE_STRING
|
|
70
|
+
{
|
|
71
|
+
Length = (ushort)(value.Length * 2),
|
|
72
|
+
MaximumLength = (ushort)((value.Length + 1) * 2),
|
|
73
|
+
Buffer = Marshal.StringToHGlobalUni(value)
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** 0 on success, otherwise the Win32 error that the NT status maps to. */
|
|
78
|
+
public static int Grant(byte[] sid, string[] rights)
|
|
79
|
+
{
|
|
80
|
+
IntPtr policy;
|
|
81
|
+
int status = Open(out policy);
|
|
82
|
+
if (status != 0) return LsaNtStatusToWinError(status);
|
|
83
|
+
try
|
|
84
|
+
{
|
|
85
|
+
var strings = new LSA_UNICODE_STRING[rights.Length];
|
|
86
|
+
for (int i = 0; i < rights.Length; i++) strings[i] = ToLsaString(rights[i]);
|
|
87
|
+
status = LsaAddAccountRights(policy, sid, strings, rights.Length);
|
|
88
|
+
foreach (var s in strings) Marshal.FreeHGlobal(s.Buffer);
|
|
89
|
+
return status == 0 ? 0 : LsaNtStatusToWinError(status);
|
|
90
|
+
}
|
|
91
|
+
finally { LsaClose(policy); }
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** Rights already assigned to the account; empty when it has none. */
|
|
95
|
+
public static string[] Enumerate(byte[] sid)
|
|
96
|
+
{
|
|
97
|
+
IntPtr policy;
|
|
98
|
+
int status = Open(out policy);
|
|
99
|
+
if (status != 0) throw new COMException("LsaOpenPolicy failed", LsaNtStatusToWinError(status));
|
|
100
|
+
try
|
|
101
|
+
{
|
|
102
|
+
IntPtr rightsPtr;
|
|
103
|
+
uint count;
|
|
104
|
+
status = LsaEnumerateAccountRights(policy, sid, out rightsPtr, out count);
|
|
105
|
+
if (status == STATUS_OBJECT_NAME_NOT_FOUND) return new string[0];
|
|
106
|
+
if (status != 0) throw new COMException("LsaEnumerateAccountRights failed", LsaNtStatusToWinError(status));
|
|
107
|
+
try
|
|
108
|
+
{
|
|
109
|
+
var result = new string[count];
|
|
110
|
+
int size = Marshal.SizeOf(typeof(LSA_UNICODE_STRING));
|
|
111
|
+
for (uint i = 0; i < count; i++)
|
|
112
|
+
{
|
|
113
|
+
var us = (LSA_UNICODE_STRING)Marshal.PtrToStructure(IntPtr.Add(rightsPtr, (int)i * size), typeof(LSA_UNICODE_STRING));
|
|
114
|
+
result[i] = Marshal.PtrToStringUni(us.Buffer, us.Length / 2);
|
|
115
|
+
}
|
|
116
|
+
return result;
|
|
117
|
+
}
|
|
118
|
+
finally { LsaFreeMemory(rightsPtr); }
|
|
119
|
+
}
|
|
120
|
+
finally { LsaClose(policy); }
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
'@
|
|
124
|
+
|
|
125
|
+
function Fail([string]$message) {
|
|
126
|
+
Write-Output "FAIL: $message"
|
|
127
|
+
exit 1
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
if (-not $User) { Fail "no account name (pass -User or set SM_ACCOUNT_NAME)" }
|
|
131
|
+
|
|
132
|
+
try {
|
|
133
|
+
Add-Type -TypeDefinition $code -ErrorAction Stop
|
|
134
|
+
} catch {
|
|
135
|
+
Fail "cannot load the LSA policy API: $($_.Exception.Message)"
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
# A user@domain identity carries its own domain; anything else needs one, and the
|
|
139
|
+
# caller already expanded the "." (local machine) shorthand.
|
|
140
|
+
try {
|
|
141
|
+
if (-not $Domain -and $User.Contains("@")) {
|
|
142
|
+
$identity = New-Object System.Security.Principal.NTAccount($User)
|
|
143
|
+
} elseif ($Domain) {
|
|
144
|
+
$identity = New-Object System.Security.Principal.NTAccount($Domain, $User)
|
|
145
|
+
} else {
|
|
146
|
+
$identity = New-Object System.Security.Principal.NTAccount($User)
|
|
147
|
+
}
|
|
148
|
+
$sid = $identity.Translate([System.Security.Principal.SecurityIdentifier])
|
|
149
|
+
} catch {
|
|
150
|
+
Fail "cannot resolve account '$($(if ($Domain) { "$Domain\" }) + $User)': $($_.Exception.Message.Trim())"
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
$sidBytes = New-Object byte[] $sid.BinaryLength
|
|
154
|
+
$sid.GetBinaryForm($sidBytes, 0)
|
|
155
|
+
$fullName = "$($sid.Translate([System.Security.Principal.NTAccount]))"
|
|
156
|
+
|
|
157
|
+
try {
|
|
158
|
+
if ([LsaRights]::Enumerate($sidBytes) -contains $Right) {
|
|
159
|
+
Write-Output "OK: $fullName already has $Right"
|
|
160
|
+
exit 0
|
|
161
|
+
}
|
|
162
|
+
$grantStatus = [LsaRights]::Grant($sidBytes, @($Right))
|
|
163
|
+
} catch {
|
|
164
|
+
Fail "$($Right): $($_.Exception.Message.Trim())"
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
if ($grantStatus -ne 0) {
|
|
168
|
+
Fail "cannot grant $Right to $fullName (Win32 error $grantStatus). Granting a user right needs the 'Manage auditing and security log' privilege — run the backend elevated, or assign the right in secpol.msc (Local Policies → User Rights Assignment)."
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
Write-Output "OK: granted $Right to $fullName"
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2008-2020 Kohsuke Kawaguchi, Sun Microsystems, Inc., CloudBees, Inc., Oleg Nenashev and other contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
Binary file
|
|
@@ -27,10 +27,23 @@ class ExecTools {
|
|
|
27
27
|
* On Windows the shell is PowerShell; on Linux it is /bin/sh.
|
|
28
28
|
*/
|
|
29
29
|
static async safeExecWithCode(command, opts) {
|
|
30
|
-
const timeout = opts?.timeout ?? 10_000;
|
|
31
30
|
const shell = process.platform === "win32" ? "powershell.exe" : "/bin/sh";
|
|
31
|
+
return this.track((0, child_process_1.spawn)(command, { shell, timeout: undefined }), opts?.timeout ?? 10_000);
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Run an executable directly, without a shell, and return its exit code.
|
|
35
|
+
* Never throws.
|
|
36
|
+
*
|
|
37
|
+
* Use this instead of safeExecWithCode for a known program: a shell would have
|
|
38
|
+
* to quote the path, and PowerShell reads a command line that starts with a
|
|
39
|
+
* quoted path as an expression rather than a call ("Unexpected token …").
|
|
40
|
+
*/
|
|
41
|
+
static async safeExecFileWithCode(command, args, opts) {
|
|
42
|
+
return this.track((0, child_process_1.spawn)(command, args, { cwd: opts?.cwd, windowsHide: true, env: opts?.env ? { ...process.env, ...opts.env } : undefined }), opts?.timeout ?? 10_000);
|
|
43
|
+
}
|
|
44
|
+
/** Collect a spawned child's output and exit code, killing it once the timeout expires. */
|
|
45
|
+
static track(child, timeout) {
|
|
32
46
|
return new Promise((resolve) => {
|
|
33
|
-
const child = (0, child_process_1.spawn)(command, { shell, timeout: undefined });
|
|
34
47
|
let stdout = "";
|
|
35
48
|
let stderr = "";
|
|
36
49
|
let resolved = false;
|
|
@@ -40,22 +53,26 @@ class ExecTools {
|
|
|
40
53
|
resolve(out);
|
|
41
54
|
}
|
|
42
55
|
};
|
|
43
|
-
child.stdout
|
|
56
|
+
child.stdout?.on("data", (chunk) => {
|
|
44
57
|
stdout += chunk.toString();
|
|
45
58
|
});
|
|
46
|
-
child.stderr
|
|
59
|
+
child.stderr?.on("data", (chunk) => {
|
|
47
60
|
stderr += chunk.toString();
|
|
48
61
|
});
|
|
49
62
|
child.on("close", (code) => {
|
|
63
|
+
clearTimeout(timer);
|
|
50
64
|
done({ stdout, stderr, exitCode: code ?? 1 });
|
|
51
65
|
});
|
|
52
66
|
child.on("error", (err) => {
|
|
67
|
+
clearTimeout(timer);
|
|
53
68
|
done({ stdout: "", stderr: err.message, exitCode: 1 });
|
|
54
69
|
});
|
|
55
|
-
setTimeout(() => {
|
|
70
|
+
const timer = setTimeout(() => {
|
|
56
71
|
child.kill();
|
|
57
72
|
done({ stdout, stderr: `Timeout after ${timeout}ms`, exitCode: 1 });
|
|
58
73
|
}, timeout);
|
|
74
|
+
// A finished command must not keep the process (or a test worker) alive.
|
|
75
|
+
timer.unref();
|
|
59
76
|
});
|
|
60
77
|
}
|
|
61
78
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExecTools.js","sourceRoot":"","sources":["../../src/helpers/ExecTools.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"ExecTools.js","sourceRoot":"","sources":["../../src/helpers/ExecTools.ts"],"names":[],"mappings":";;;AAAA,iDAA0E;AAC1E,+BAAiC;AAEjC,MAAM,IAAI,GAAG,IAAA,gBAAS,EAAC,oBAAY,CAAC,CAAC;AAqBrC,MAAa,SAAS;IACpB;;;OAGG;IACI,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,OAAe,EAAE,IAAkB;QAC9D,MAAM,OAAO,GAAG,IAAI,EAAE,GAAG,CAAC,CAAC,CAAC,EAAE,GAAG,OAAO,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;QACxE,OAAO,IAAI,CAAC,OAAO,EAAE;YACnB,OAAO,EAAE,IAAI,EAAE,OAAO,IAAI,MAAM;YAChC,SAAS,EAAE,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AC,KAAa,EAAE,EAAE;gBACxC,MAAM,IAAI,KAAK,CAAC,QAAQ,EAAE,CAAC;YAC7B,CAAC,CAAC,CAAC;YACH,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,EAAE;gBACrB,IAAI,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;YAC3B,CAAC,CAAC,CAAC;YACH,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,GAAU,EAAE,EAAE;gBAC/B,IAAI,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,GAAG,CAAC,OAAO,EAAE,CAAC,CAAC;YAC5C,CAAC,CAAC,CAAC;YAEH,UAAU,CAAC,GAAG,EAAE;gBACd,KAAK,CAAC,IAAI,EAAE,CAAC;gBACb,IAAI,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,iBAAiB,OAAO,IAAI,EAAE,CAAC,CAAC;YAC7D,CAAC,EAAE,OAAO,CAAC,CAAC;QACd,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AA/HD,8BA+HC"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ServerIdentity = void 0;
|
|
4
|
+
const ExecTools_1 = require("./ExecTools");
|
|
5
|
+
/**
|
|
6
|
+
* Identity of the running backend — PID, listen address, start time and
|
|
7
|
+
* privilege level.
|
|
8
|
+
*
|
|
9
|
+
* The dashboard can be served by a stale instance (an older dev server that
|
|
10
|
+
* already holds the port), so the UI needs to say which process answers its
|
|
11
|
+
* requests and whether that process can control services at all.
|
|
12
|
+
*/
|
|
13
|
+
class ServerIdentity {
|
|
14
|
+
static startedAt = new Date();
|
|
15
|
+
static privileged = null;
|
|
16
|
+
static get port() {
|
|
17
|
+
return parseInt(process.env.PORT ?? "4243", 10);
|
|
18
|
+
}
|
|
19
|
+
static get host() {
|
|
20
|
+
return process.env.HOST ?? "127.0.0.1";
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Whether the process may manage OS services: Administrator on Windows,
|
|
24
|
+
* root or passwordless sudo on Linux. The answer cannot change while the
|
|
25
|
+
* process runs, so it is cached once known.
|
|
26
|
+
*/
|
|
27
|
+
static async isPrivileged() {
|
|
28
|
+
if (this.privileged !== null)
|
|
29
|
+
return this.privileged;
|
|
30
|
+
if (process.platform === "win32") {
|
|
31
|
+
const { stdout } = await ExecTools_1.ExecTools.safeExec("[bool]([Security.Principal.WindowsPrincipal]" +
|
|
32
|
+
"[Security.Principal.WindowsIdentity]::GetCurrent())" +
|
|
33
|
+
".IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)");
|
|
34
|
+
const answer = stdout.trim().toUpperCase();
|
|
35
|
+
if (answer !== "TRUE" && answer !== "FALSE")
|
|
36
|
+
return false;
|
|
37
|
+
this.privileged = answer === "TRUE";
|
|
38
|
+
return this.privileged;
|
|
39
|
+
}
|
|
40
|
+
const { stdout } = await ExecTools_1.ExecTools.safeExec("id -u");
|
|
41
|
+
if (stdout.trim() === "0") {
|
|
42
|
+
this.privileged = true;
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
45
|
+
const sudo = await ExecTools_1.ExecTools.safeExecWithCode("sudo -n true");
|
|
46
|
+
if (sudo.exitCode === 0) {
|
|
47
|
+
this.privileged = true;
|
|
48
|
+
}
|
|
49
|
+
return this.privileged ?? false;
|
|
50
|
+
}
|
|
51
|
+
/** Snapshot of the process identity for the dashboard. */
|
|
52
|
+
static async describe() {
|
|
53
|
+
return {
|
|
54
|
+
pid: process.pid,
|
|
55
|
+
platform: process.platform,
|
|
56
|
+
host: this.host,
|
|
57
|
+
port: this.port,
|
|
58
|
+
startedAt: this.startedAt.toISOString(),
|
|
59
|
+
privileged: await this.isPrivileged(),
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
exports.ServerIdentity = ServerIdentity;
|
|
64
|
+
//#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AAC,UAAU,GAAG,IAAI,CAAC;YACvB,OAAO,IAAI,CAAC;QACd,CAAC;QAED,MAAM,IAAI,GAAG,MAAM,qBAAS,CAAC,gBAAgB,CAAC,cAAc,CAAC,CAAC;QAC9D,IAAI,IAAI,CAAC,QAAQ,KAAK,CAAC,EAAE,CAAC;YACxB,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC;QACzB,CAAC;QACD,OAAO,IAAI,CAAC,UAAU,IAAI,KAAK,CAAC;IAClC,CAAC;IAED,0DAA0D;IACnD,MAAM,CAAC,KAAK,CAAC,QAAQ;QAC1B,OAAO;YACL,GAAG,EAAE,OAAO,CAAC,GAAG;YAChB,QAAQ,EAAE,OAAO,CAAC,QAAQ;YAC1B,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,SAAS,EAAE,IAAI,CAAC,SAAS,CAAC,WAAW,EAAE;YACvC,UAAU,EAAE,MAAM,IAAI,CAAC,YAAY,EAAE;SACtC,CAAC;IACJ,CAAC;;AAvDH,wCAwDC"}
|
package/backend/dist/index.js
CHANGED
|
@@ -15,11 +15,12 @@ const hfRoutes_1 = __importDefault(require("./routes/hfRoutes"));
|
|
|
15
15
|
const lmStudioRoutes_1 = __importDefault(require("./routes/lmStudioRoutes"));
|
|
16
16
|
const authRoutes_1 = __importDefault(require("./routes/authRoutes"));
|
|
17
17
|
const authMiddleware_1 = require("./middleware/authMiddleware");
|
|
18
|
+
const ServerIdentity_1 = require("./helpers/ServerIdentity");
|
|
18
19
|
const types_1 = require("./di/types");
|
|
19
20
|
const container = (0, container_1.createContainer)();
|
|
20
21
|
const app = (0, express_1.default)();
|
|
21
|
-
const PORT =
|
|
22
|
-
const HOST =
|
|
22
|
+
const PORT = ServerIdentity_1.ServerIdentity.port;
|
|
23
|
+
const HOST = ServerIdentity_1.ServerIdentity.host;
|
|
23
24
|
app.use((0, cors_1.default)());
|
|
24
25
|
app.use(express_1.default.json());
|
|
25
26
|
// ── Public: frontend (must be before auth middleware) ──
|
|
@@ -49,7 +50,20 @@ const sm = container.get(types_1.SERVICE_MANAGER);
|
|
|
49
50
|
sm.bootstrap().catch((err) => {
|
|
50
51
|
console.error("[ServiceManager] bootstrap failed:", err);
|
|
51
52
|
});
|
|
52
|
-
app.listen(PORT, HOST, () => {
|
|
53
|
-
console.log(`aiservermanager backend listening on http://${HOST}:${PORT}`);
|
|
53
|
+
const server = app.listen(PORT, HOST, () => {
|
|
54
|
+
console.log(`aiservermanager backend listening on http://${HOST}:${PORT} (pid ${process.pid})`);
|
|
55
|
+
});
|
|
56
|
+
/**
|
|
57
|
+
* A second instance would otherwise die with a bare EADDRINUSE stack trace
|
|
58
|
+
* while the dashboard keeps talking to whatever already owns the port.
|
|
59
|
+
*/
|
|
60
|
+
server.on("error", (err) => {
|
|
61
|
+
const taken = err.code === "EADDRINUSE";
|
|
62
|
+
const probe = process.platform === "win32" ? `netstat -ano | findstr :${PORT}` : `ss -ltnp | grep ":${PORT} "`;
|
|
63
|
+
console.error(taken
|
|
64
|
+
? `aiservermanager backend cannot listen on ${HOST}:${PORT} — another process owns the port.\n` +
|
|
65
|
+
`Stop it with "${probe}" and keep a single instance; this one (pid ${process.pid}) exits.`
|
|
66
|
+
: `aiservermanager backend failed to listen on ${HOST}:${PORT}: ${err.message}`);
|
|
67
|
+
process.exit(1);
|
|
54
68
|
});
|
|
55
69
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;AAAA,4BAA0B;AAC1B,sDAA8B;AAC9B,gDAAwB;AACxB,gDAAwB;AACxB,8CAAiD;AACjD,mEAA2C;AAC3C,2EAAmD;AACnD,yEAAiD;AACjD,iEAAyC;AACzC,6EAAqD;AACrD,qEAA6C;AAC7C,gEAA6D;AAC7D,sCAA6C;AAG7C,MAAM,SAAS,GAAG,IAAA,2BAAe,GAAE,CAAC;AACpC,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AEH;;;GAGG;AACH,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,GAAU,EAAE,EAAE;IAChC,MAAM,KAAK,GAAI,GAA6B,CAAC,IAAI,KAAK,YAAY,CAAC;IACnE,MAAM,KAAK,GACT,OAAO,CAAC,QAAQ,KAAK,OAAO,CAAC,CAAC,CAAC,2BAA2B,IAAI,EAAE,CAAC,CAAC,CAAC,qBAAqB,IAAI,IAAI,CAAC;IAEnG,OAAO,CAAC,KAAK,CACX,KAAK;QACH,CAAC,CAAC,4CAA4C,IAAI,IAAI,IAAI,qCAAqC;YAC3F,iBAAiB,KAAK,+CAA+C,OAAO,CAAC,GAAG,UAAU;QAC9F,CAAC,CAAC,+CAA+C,IAAI,IAAI,IAAI,KAAK,GAAG,CAAC,OAAO,EAAE,CAClF,CAAC;IACF,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.RESTART_VALUES = exports.USER_GROUP_REGEX = void 0;
|
|
3
|
+
exports.RESTART_VALUES = exports.SERVICE_ACCOUNT_REGEX = exports.USER_GROUP_REGEX = void 0;
|
|
4
|
+
exports.isServiceAccount = isServiceAccount;
|
|
4
5
|
exports.buildInstallOptions = buildInstallOptions;
|
|
5
6
|
exports.parseConfigFile = parseConfigFile;
|
|
6
7
|
exports.serializeConfig = serializeConfig;
|
|
@@ -10,6 +11,16 @@ exports.buildExecStart = buildExecStart;
|
|
|
10
11
|
const ENV_KEY_REGEX = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
11
12
|
/** Valid systemd user/group name (subset accepted by the unit file). */
|
|
12
13
|
exports.USER_GROUP_REGEX = /^[a-zA-Z_][a-zA-Z0-9_-]*$/;
|
|
14
|
+
/**
|
|
15
|
+
* Account a Windows service may run as: a bare name (local account),
|
|
16
|
+
* DOMAIN\name, .\name or name@domain (UPN). systemd accepts USER_GROUP_REGEX
|
|
17
|
+
* only, so the platform controllers decide which forms they can pass through.
|
|
18
|
+
*/
|
|
19
|
+
exports.SERVICE_ACCOUNT_REGEX = /^[A-Za-z0-9_.$@-]{1,128}(?:\\[A-Za-z0-9_.$-]{1,128})?$/;
|
|
20
|
+
/** Whether the value names an account on either platform. */
|
|
21
|
+
function isServiceAccount(value) {
|
|
22
|
+
return exports.USER_GROUP_REGEX.test(value) || exports.SERVICE_ACCOUNT_REGEX.test(value);
|
|
23
|
+
}
|
|
13
24
|
/** Supported systemd Restart= values. */
|
|
14
25
|
exports.RESTART_VALUES = [
|
|
15
26
|
"no",
|
|
@@ -26,13 +37,19 @@ function buildInstallOptions(cfg) {
|
|
|
26
37
|
environment: cfg.environment,
|
|
27
38
|
user: cfg.user,
|
|
28
39
|
group: cfg.group,
|
|
40
|
+
runAsPassword: cfg.runAsPassword,
|
|
41
|
+
stopCommand: cfg.stopCommand,
|
|
29
42
|
restart: cfg.restart,
|
|
43
|
+
workingDirectory: cfg.workingDirectory,
|
|
44
|
+
executable: cfg.command,
|
|
45
|
+
args: cfg.flags,
|
|
30
46
|
};
|
|
31
47
|
}
|
|
32
48
|
/**
|
|
33
49
|
* Parse a config file into a ServiceConfig. Lines with "type=", "command=",
|
|
34
|
-
* "unit.user=", "unit.group=", "unit.
|
|
35
|
-
* every other non-empty line is a raw
|
|
50
|
+
* "unit.user=", "unit.group=", "unit.password=", "unit.stop=", "unit.restart=",
|
|
51
|
+
* "unit.cwd=" or "env.KEY=" are metadata; every other non-empty line is a raw
|
|
52
|
+
* CLI argument.
|
|
36
53
|
*/
|
|
37
54
|
function parseConfigFile(name, raw) {
|
|
38
55
|
const flags = [];
|
|
@@ -41,7 +58,9 @@ function parseConfigFile(name, raw) {
|
|
|
41
58
|
let type;
|
|
42
59
|
let user;
|
|
43
60
|
let group;
|
|
61
|
+
let stopCommand;
|
|
44
62
|
let restart;
|
|
63
|
+
let workingDirectory;
|
|
45
64
|
for (const line of raw.split("\n")) {
|
|
46
65
|
const trimmed = line.trim();
|
|
47
66
|
if (!trimmed || trimmed.startsWith("#"))
|
|
@@ -57,7 +76,7 @@ function parseConfigFile(name, raw) {
|
|
|
57
76
|
}
|
|
58
77
|
else if (trimmed.startsWith("unit.user=")) {
|
|
59
78
|
const val = trimmed.slice("unit.user=".length).trim();
|
|
60
|
-
if (
|
|
79
|
+
if (isServiceAccount(val))
|
|
61
80
|
user = val;
|
|
62
81
|
}
|
|
63
82
|
else if (trimmed.startsWith("unit.group=")) {
|
|
@@ -65,12 +84,27 @@ function parseConfigFile(name, raw) {
|
|
|
65
84
|
if (exports.USER_GROUP_REGEX.test(val))
|
|
66
85
|
group = val;
|
|
67
86
|
}
|
|
87
|
+
else if (trimmed.startsWith("unit.password=")) {
|
|
88
|
+
// Deliberately dropped: the account password is never kept on disk, it
|
|
89
|
+
// arrives with the save request and is handed to WinSW once. Reading the
|
|
90
|
+
// key here only stops such a line from becoming a CLI argument.
|
|
91
|
+
}
|
|
92
|
+
else if (trimmed.startsWith("unit.stop=")) {
|
|
93
|
+
const val = trimmed.slice("unit.stop=".length).trim();
|
|
94
|
+
if (val)
|
|
95
|
+
stopCommand = val;
|
|
96
|
+
}
|
|
68
97
|
else if (trimmed.startsWith("unit.restart=")) {
|
|
69
98
|
const val = trimmed.slice("unit.restart=".length).trim();
|
|
70
99
|
if (exports.RESTART_VALUES.includes(val)) {
|
|
71
100
|
restart = val;
|
|
72
101
|
}
|
|
73
102
|
}
|
|
103
|
+
else if (trimmed.startsWith("unit.cwd=")) {
|
|
104
|
+
const val = trimmed.slice("unit.cwd=".length).trim();
|
|
105
|
+
if (val)
|
|
106
|
+
workingDirectory = val;
|
|
107
|
+
}
|
|
74
108
|
else if (trimmed.startsWith("env.")) {
|
|
75
109
|
const eqIdx = trimmed.indexOf("=");
|
|
76
110
|
if (eqIdx > 0) {
|
|
@@ -93,17 +127,25 @@ function parseConfigFile(name, raw) {
|
|
|
93
127
|
environment: envKeys.length ? environment : undefined,
|
|
94
128
|
user,
|
|
95
129
|
group,
|
|
130
|
+
stopCommand,
|
|
96
131
|
restart,
|
|
132
|
+
workingDirectory,
|
|
97
133
|
};
|
|
98
134
|
}
|
|
99
|
-
/**
|
|
135
|
+
/**
|
|
136
|
+
* Serialize a ServiceConfig back to a config file string.
|
|
137
|
+
*
|
|
138
|
+
* The account password is intentionally not written: it is only ever sent with
|
|
139
|
+
* a save request and handed to WinSW during registration, so nothing readable
|
|
140
|
+
* is left behind. Re-registering the service therefore asks for it again.
|
|
141
|
+
*/
|
|
100
142
|
function serializeConfig(cfg) {
|
|
101
143
|
const lines = [];
|
|
102
144
|
if (cfg.type) {
|
|
103
145
|
lines.push(`type=${cfg.type}`);
|
|
104
146
|
}
|
|
105
147
|
lines.push(`command=${cfg.command}`);
|
|
106
|
-
if (cfg.user &&
|
|
148
|
+
if (cfg.user && isServiceAccount(cfg.user)) {
|
|
107
149
|
lines.push(`unit.user=${cfg.user}`);
|
|
108
150
|
}
|
|
109
151
|
if (cfg.group && exports.USER_GROUP_REGEX.test(cfg.group)) {
|
|
@@ -112,6 +154,12 @@ function serializeConfig(cfg) {
|
|
|
112
154
|
if (cfg.restart && exports.RESTART_VALUES.includes(cfg.restart)) {
|
|
113
155
|
lines.push(`unit.restart=${cfg.restart}`);
|
|
114
156
|
}
|
|
157
|
+
if (cfg.workingDirectory) {
|
|
158
|
+
lines.push(`unit.cwd=${cfg.workingDirectory}`);
|
|
159
|
+
}
|
|
160
|
+
if (cfg.stopCommand && !/[\r\n]/.test(cfg.stopCommand)) {
|
|
161
|
+
lines.push(`unit.stop=${cfg.stopCommand}`);
|
|
162
|
+
}
|
|
115
163
|
if (cfg.environment) {
|
|
116
164
|
for (const [key, value] of Object.entries(cfg.environment)) {
|
|
117
165
|
if (ENV_KEY_REGEX.test(key) && !/[\r\n]/.test(value)) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ServiceConfig.js","sourceRoot":"","sources":["../../src/models/ServiceConfig.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"ServiceConfig.js","sourceRoot":"","sources":["../../src/models/ServiceConfig.ts"],"names":[],"mappings":";;;AAkBA,4CAEC;AA8CD,kDAYC;AAuCD,0CAqEC;AASD,0CAgCC;AAOD,sDAOC;AAGD,wCAEC;AAnPD,8DAA8D;AAC9D,MAAM,aAAa,GAAG,0BAA0B,CAAC;AAEjD,wEAAwE;AAC3D,QAAA,gBAAgB,GAAG,2BAA2B,CAAC;AAE5D;;;;GAIG;AACU,QAAA,qBAAqB,GAChC,wDAAwD,CAAC;AAE3D,6DAA6D;AAC7D,SAAgB,gBAAgB,CAAC,KAAa;IAC5C,OAAO,wBAAgB,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,6BAAqB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AAC3E,CAAC;AAED,yCAAyC;AAC5B,QAAA,cAAc,GAAG;IAC5B,IAAI;IACJ,YAAY;IACZ,YAAY;IACZ,aAAa;IACb,aAAa;IACb,UAAU;IACV,QAAQ;CACA,CAAC;AAkCX,mFAAmF;AACnF,SAAgB,mBAAmB,CAAC,GAAkB;IACpD,OAAO;QACL,WAAW,EAAE,GAAG,CAAC,WAAW;QAC5B,IAAI,EAAE,GAAG,CAAC,IAAI;QACd,KAAK,EAAE,GAAG,CAAC,KAAK;QAChB,aAAa,EAAE,GAAG,CAAC,aAAa;QAChC,WAAW,EAAE,GAAG,CAAC,WAAW;QAC5B,OAAO,EAAE,GAAG,CAAC,OAAO;QACpB,gBAAgB,EAAE,GAAG,CAAC,gBAAgB;QACtC,UAAU,EAAE,GAAG,CAAC,OAAO;QACvB,IAAI,EAAE,GAAG,CAAC,KAAK;KAChB,CAAC;AACJ,CAAC;AAiCD;;;;;GAKG;AACH,SAAgB,eAAe,CAAC,IAAY,EAAE,GAAW;IACvD,MAAM,KAAK,GAAa,EAAE,CAAC;IAC3B,MAAM,WAAW,GA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AAC,IAAI,CAAC,GAAG,CAAC,CAAC;SAC1C,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE;QACpB,MAAM,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QACtF,OAAO,eAAe,GAAG,KAAK,OAAO,GAAG,CAAC;IAC3C,CAAC,CAAC,CAAC;AACP,CAAC;AAED,8DAA8D;AAC9D,SAAgB,cAAc,CAAC,GAAkB;IAC/C,OAAO,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,OAAO,IAAI,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC;AAClF,CAAC"}
|
|
@@ -35,15 +35,20 @@ function serviceRoutes(container) {
|
|
|
35
35
|
res.status(status).json({ error: err instanceof Error ? err.message : "Unknown error" });
|
|
36
36
|
}
|
|
37
37
|
});
|
|
38
|
-
/**
|
|
38
|
+
/**
|
|
39
|
+
* Install the OS service for a custom config that is not registered yet:
|
|
40
|
+
* { name: "llama", runAsPassword?: "…" }. The password is asked by the UI at
|
|
41
|
+
* this moment for a Windows service that runs as a user; it is not stored.
|
|
42
|
+
*/
|
|
39
43
|
router.post("/install", async (req, res) => {
|
|
40
44
|
try {
|
|
41
45
|
const { name } = req.body;
|
|
42
46
|
if (!name) {
|
|
43
47
|
return res.status(400).json({ error: "'name' is required" });
|
|
44
48
|
}
|
|
49
|
+
const runAsPassword = typeof req.body.runAsPassword === "string" ? req.body.runAsPassword : undefined;
|
|
45
50
|
const sm = container.get(types_1.SERVICE_MANAGER);
|
|
46
|
-
const result = await sm.installService(name);
|
|
51
|
+
const result = await sm.installService(name, runAsPassword);
|
|
47
52
|
res.json(result);
|
|
48
53
|
}
|
|
49
54
|
catch (err) {
|
|
@@ -91,6 +96,8 @@ function serviceRoutes(container) {
|
|
|
91
96
|
environment: body.environment ?? {},
|
|
92
97
|
user: typeof body.user === "string" && body.user.trim() ? body.user.trim() : undefined,
|
|
93
98
|
group: typeof body.group === "string" && body.group.trim() ? body.group.trim() : undefined,
|
|
99
|
+
// Asked for at save time on Windows; never written to the config file.
|
|
100
|
+
runAsPassword: typeof body.runAsPassword === "string" && body.runAsPassword ? body.runAsPassword : undefined,
|
|
94
101
|
restart: body.restart,
|
|
95
102
|
};
|
|
96
103
|
const scc = container.get(types_1.SERVICE_CONFIG_CONTROLLER);
|
|
@@ -148,8 +155,9 @@ function serviceRoutes(container) {
|
|
|
148
155
|
router.post("/config/:name/restore", async (req, res) => {
|
|
149
156
|
try {
|
|
150
157
|
const name = Array.isArray(req.params.name) ? req.params.name[0] : req.params.name;
|
|
158
|
+
const runAsPassword = typeof req.body?.runAsPassword === "string" ? req.body.runAsPassword : undefined;
|
|
151
159
|
const scc = container.get(types_1.SERVICE_CONFIG_CONTROLLER);
|
|
152
|
-
const result = await scc.restoreService(name);
|
|
160
|
+
const result = await scc.restoreService(name, runAsPassword);
|
|
153
161
|
if (!result.ok) {
|
|
154
162
|
return res.status(404).json({ error: result.error });
|
|
155
163
|
}
|