omo-web 0.0.0-stage → 0.1.1
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/LICENSE +21 -0
- package/README.md +23 -2
- package/bin/launcher-settings.js +116 -0
- package/bin/launcher-tls.js +67 -0
- package/bin/listen-address.js +20 -0
- package/bin/locale.js +6 -0
- package/bin/omo-web.js +98 -0
- package/bin/tui.js +645 -0
- package/bin/windows-password.js +79 -0
- package/dist/app.js +7 -0
- package/dist/server.js +12524 -0
- package/package.json +31 -4
- package/public/dag-graph.css +80 -0
- package/public/favicon.svg +13 -0
- package/public/icons.svg +89 -0
- package/public/index.html +486 -0
- package/public/licenses/teenyicons.txt +25 -0
- package/public/licenses/zod.txt +21 -0
- package/public/styles.css +422 -0
- package/public/tool-ledger.css +354 -0
- package/public/workbench.css +782 -0
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { execFile } from "node:child_process";
|
|
2
|
+
import { join, resolve } from "node:path";
|
|
3
|
+
|
|
4
|
+
const identity = String.raw`
|
|
5
|
+
$ErrorActionPreference = 'Stop'
|
|
6
|
+
$path = $env:OMO_WEB_ACL_PATH
|
|
7
|
+
$sid = [System.Security.Principal.WindowsIdentity]::GetCurrent().User
|
|
8
|
+
$sidType = [System.Security.Principal.SecurityIdentifier]
|
|
9
|
+
`;
|
|
10
|
+
|
|
11
|
+
function powershell(script, path, input = "") {
|
|
12
|
+
const executable = join(process.env.SystemRoot || "C:\\Windows", "System32", "WindowsPowerShell", "v1.0", "powershell.exe");
|
|
13
|
+
const encoded = Buffer.from(`${identity}\n${script}`, "utf16le").toString("base64");
|
|
14
|
+
return new Promise((accept, reject) => {
|
|
15
|
+
const child = execFile(executable, ["-NoLogo", "-NoProfile", "-NonInteractive", "-EncodedCommand", encoded], {
|
|
16
|
+
env: { ...process.env, OMO_WEB_ACL_PATH: resolve(path) }, encoding: "buffer", timeout: 8000,
|
|
17
|
+
maxBuffer: 4096, windowsHide: true,
|
|
18
|
+
}, (error, bytes) => {
|
|
19
|
+
if (error) reject(new Error("Windows password file or its ACL could not be verified."));
|
|
20
|
+
else accept(bytes);
|
|
21
|
+
});
|
|
22
|
+
child.stdin?.on("error", reject);
|
|
23
|
+
child.stdin?.end(input);
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function readWindowsPasswordFile(path) {
|
|
28
|
+
return powershell(String.raw`
|
|
29
|
+
$file = [IO.File]::Open($path, [IO.FileMode]::Open, [IO.FileAccess]::Read, [IO.FileShare]::Read)
|
|
30
|
+
try {
|
|
31
|
+
# Read permissions and bytes from the same handle; do not reopen the path.
|
|
32
|
+
$acl = $file.GetAccessControl()
|
|
33
|
+
$raw = [System.Security.AccessControl.RawSecurityDescriptor]::new($acl.GetSecurityDescriptorBinaryForm(), 0)
|
|
34
|
+
$trusted = @($sid.Value, 'S-1-5-18', 'S-1-5-32-544')
|
|
35
|
+
if ($null -eq $raw.DiscretionaryAcl -or $trusted -notcontains $acl.GetOwner($sidType).Value) {
|
|
36
|
+
throw 'Expected a private ACL'
|
|
37
|
+
}
|
|
38
|
+
foreach ($rule in $acl.GetAccessRules($true, $true, $sidType)) {
|
|
39
|
+
if ($rule.AccessControlType -eq 'Allow' -and $trusted -notcontains $rule.IdentityReference.Value) {
|
|
40
|
+
throw 'Unexpected allowed account'
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
$buffer = New-Object byte[] 131
|
|
44
|
+
$offset = 0
|
|
45
|
+
while ($offset -lt $buffer.Length) {
|
|
46
|
+
$count = $file.Read($buffer, $offset, $buffer.Length - $offset)
|
|
47
|
+
if ($count -eq 0) { break }
|
|
48
|
+
$offset += $count
|
|
49
|
+
}
|
|
50
|
+
if ($offset -gt 130) { throw 'Password file is too large' }
|
|
51
|
+
[Console]::OpenStandardOutput().Write($buffer, 0, $offset)
|
|
52
|
+
} finally {
|
|
53
|
+
$file.Dispose()
|
|
54
|
+
}
|
|
55
|
+
`, path);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export async function createWindowsPasswordFile(path, password) {
|
|
59
|
+
if (!/^[\x20-\x7e]{20,128}$/.test(password) || /[\r\n]/.test(password)) throw new Error("Invalid password.");
|
|
60
|
+
await createWindowsPrivateFile(path, Buffer.from(`${password}\n`, "ascii"));
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export async function createWindowsPrivateFile(path, bytes) {
|
|
64
|
+
await powershell(String.raw`
|
|
65
|
+
$bytes = [Convert]::FromBase64String([Console]::In.ReadToEnd())
|
|
66
|
+
$acl = [System.Security.AccessControl.FileSecurity]::new()
|
|
67
|
+
$acl.SetOwner($sid)
|
|
68
|
+
$acl.SetAccessRuleProtection($true, $false)
|
|
69
|
+
$acl.AddAccessRule([System.Security.AccessControl.FileSystemAccessRule]::new($sid, 'FullControl', 'Allow'))
|
|
70
|
+
# CreateNew enforces no overwrite. The ACL is applied at creation, not afterward.
|
|
71
|
+
$file = [IO.FileStream]::new($path, [IO.FileMode]::CreateNew,
|
|
72
|
+
[System.Security.AccessControl.FileSystemRights]::Write, [IO.FileShare]::None, 4096, [IO.FileOptions]::None, $acl)
|
|
73
|
+
try {
|
|
74
|
+
$file.Write($bytes, 0, $bytes.Length)
|
|
75
|
+
} finally {
|
|
76
|
+
$file.Dispose()
|
|
77
|
+
}
|
|
78
|
+
`, path, bytes.toString("base64"));
|
|
79
|
+
}
|