@aivin-labs/cli 1.0.57 → 1.0.60
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/bin/cli.mjs +2 -1
- package/bin/lib/auth.mjs +119 -88
- package/bin/lib/context.mjs +58 -5
- package/bin/lib/loginHandoff.mjs +87 -0
- package/bin/lib/openFile.mjs +29 -4
- package/bin/lib/remote/client.mjs +1456 -1454
- package/bin/lib/remote/credentials.mjs +131 -125
- package/bin/lib/remote/desktop/castAuth.mjs +274 -259
- package/bin/lib/remote/desktop/castConsent.mjs +155 -154
- package/bin/lib/remote/desktop/castTrust.mjs +220 -183
- package/bin/lib/remote/desktop/desktopCastSource.mjs +77 -31
- package/bin/lib/remote/desktop/strings.mjs +158 -138
- package/bin/lib/remote/desktop/traySource.mjs +89 -15
- package/bin/lib/remote/desktop/webrtcWorker.mjs +4 -0
- package/bin/lib/remote/dpapiHelper.mjs +91 -0
- package/bin/lib/remote/gui/index.mjs +839 -567
- package/bin/lib/remote/gui/windowsHostSource.mjs +2418 -2127
- package/bin/lib/remote/tokenStore.mjs +19 -2
- package/package.json +1 -1
|
@@ -1,138 +1,158 @@
|
|
|
1
|
-
/** Chữ trên menu khay hệ thống (Aivin.exe) — ghi vào launch.cfg theo ngôn ngữ máy (mascotLang). */
|
|
2
|
-
export const TRAY_STRINGS = Object.freeze({
|
|
3
|
-
vi: {
|
|
4
|
-
running: 'Đang chạy — sẵn sàng nhận việc',
|
|
5
|
-
paused: 'Đang tạm dừng — từ chối mọi việc từ xa',
|
|
6
|
-
stopped: 'Đang không chạy',
|
|
7
|
-
notPaired: 'Chưa kết nối với Aivin',
|
|
8
|
-
connecting: 'Đang kết nối…',
|
|
9
|
-
open: 'Mở Aivin',
|
|
10
|
-
quickChat: 'Quick chat',
|
|
11
|
-
quickVoice: 'Quick voice',
|
|
12
|
-
terminal: 'Mở Terminal',
|
|
13
|
-
server: 'Máy chủ',
|
|
14
|
-
serverCloud: 'Cloud',
|
|
15
|
-
serverVn: 'VN',
|
|
16
|
-
serverLocal: 'Local',
|
|
17
|
-
serverConfirm: 'Đổi máy chủ sang {server}? Việc đang chạy trên máy này sẽ bị dừng.',
|
|
18
|
-
connect: 'Đăng nhập để kết nối…',
|
|
19
|
-
pause: 'Tạm dừng nhận việc',
|
|
20
|
-
resume: 'Tiếp tục nhận việc',
|
|
21
|
-
startup: 'Khởi động cùng Windows',
|
|
22
|
-
mascot: 'Linh vật trên màn hình',
|
|
23
|
-
mascotShow: 'Hiện linh vật',
|
|
24
|
-
mascotHide: 'Ẩn linh vật',
|
|
25
|
-
version: 'Phiên bản: {version}',
|
|
26
|
-
updateUpToDate: 'Đã là bản mới nhất',
|
|
27
|
-
updateAvailable: 'Có bản mới ({version}) — Bấm cập nhật',
|
|
28
|
-
updateChecking: 'Đang kiểm tra cập nhật...',
|
|
29
|
-
updateCheckNow: 'Kiểm tra cập nhật',
|
|
30
|
-
updateUpdating: 'Đang tải bản cập nhật...',
|
|
31
|
-
quit: 'Thoát Aivin',
|
|
32
|
-
firstRun: 'Aivin đang chạy ở khay hệ thống — bấm biểu tượng để mở.',
|
|
33
|
-
connectHint: 'Aivin đang ở khay hệ thống — bấm biểu tượng rồi chọn “Đăng nhập để kết nối”.',
|
|
34
|
-
connected: 'Đã kết nối máy này với Aivin.',
|
|
35
|
-
pairFailed: 'Không kết nối được — mã sai hoặc đã hết hạn. Tạo mã mới trong Aivin rồi thử lại.',
|
|
36
|
-
pairPrompt: 'Nhập mã kết nối từ Aivin (khung chat → Browser ▾ → Thêm máy tính này):',
|
|
37
|
-
pairOk: 'Kết nối',
|
|
38
|
-
pairCancel: 'Huỷ',
|
|
39
|
-
connectCode: 'Tôi có mã kết nối',
|
|
40
|
-
connectBrowserHint: 'Đang mở trang đăng nhập. Sau khi bạn cấp quyền, Aivin sẽ tự kết nối máy tính này.',
|
|
41
|
-
connectPairing: 'Đăng nhập thành công. Đang liên kết máy tính…',
|
|
42
|
-
connectFailed: 'Chưa kết nối được. Hãy thử lại hoặc dùng mã kết nối.',
|
|
43
|
-
connectDone: 'Đã kết nối máy tính này với Aivin Cloud.',
|
|
44
|
-
shortcut: 'Aivin — cho các agent Aivin làm việc trên máy tính này',
|
|
45
|
-
openWith: 'Mở bằng AIVIN Office Suite',
|
|
46
|
-
share: 'Gửi cho AIVIN Bot',
|
|
47
|
-
workHere: 'Làm việc ở đây với AIVIN Bot',
|
|
48
|
-
uninstallPrompt: 'Gỡ AIVIN Bot khỏi máy này?\n\nỨng dụng, lệnh aivin và kết nối của máy với tài khoản sẽ bị xoá.\nCó xoá luôn dữ liệu (ghi nhớ của bot, bản sao tệp để hoàn tác, phiên đăng nhập trình duyệt)? Xoá rồi không lấy lại được.\n\nYes = gỡ và xoá dữ liệu\nNo = gỡ, giữ dữ liệu\nCancel = không gỡ',
|
|
49
|
-
uninstallFailed: 'Không gỡ tự động được. Mở Terminal và chạy: aivin uninstall',
|
|
50
|
-
stopCast: 'Ngưng kết nối cast ({device})',
|
|
51
|
-
trustedDevices: 'Thiết bị
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
},
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
1
|
+
/** Chữ trên menu khay hệ thống (Aivin.exe) — ghi vào launch.cfg theo ngôn ngữ máy (mascotLang). */
|
|
2
|
+
export const TRAY_STRINGS = Object.freeze({
|
|
3
|
+
vi: {
|
|
4
|
+
running: 'Đang chạy — sẵn sàng nhận việc',
|
|
5
|
+
paused: 'Đang tạm dừng — từ chối mọi việc từ xa',
|
|
6
|
+
stopped: 'Đang không chạy',
|
|
7
|
+
notPaired: 'Chưa kết nối với Aivin',
|
|
8
|
+
connecting: 'Đang kết nối…',
|
|
9
|
+
open: 'Mở Aivin',
|
|
10
|
+
quickChat: 'Quick chat',
|
|
11
|
+
quickVoice: 'Quick voice',
|
|
12
|
+
terminal: 'Mở Terminal',
|
|
13
|
+
server: 'Máy chủ',
|
|
14
|
+
serverCloud: 'Cloud',
|
|
15
|
+
serverVn: 'VN',
|
|
16
|
+
serverLocal: 'Local',
|
|
17
|
+
serverConfirm: 'Đổi máy chủ sang {server}? Việc đang chạy trên máy này sẽ bị dừng.',
|
|
18
|
+
connect: 'Đăng nhập để kết nối…',
|
|
19
|
+
pause: 'Tạm dừng nhận việc',
|
|
20
|
+
resume: 'Tiếp tục nhận việc',
|
|
21
|
+
startup: 'Khởi động cùng Windows',
|
|
22
|
+
mascot: 'Linh vật trên màn hình',
|
|
23
|
+
mascotShow: 'Hiện linh vật',
|
|
24
|
+
mascotHide: 'Ẩn linh vật',
|
|
25
|
+
version: 'Phiên bản: {version}',
|
|
26
|
+
updateUpToDate: 'Đã là bản mới nhất',
|
|
27
|
+
updateAvailable: 'Có bản mới ({version}) — Bấm cập nhật',
|
|
28
|
+
updateChecking: 'Đang kiểm tra cập nhật...',
|
|
29
|
+
updateCheckNow: 'Kiểm tra cập nhật',
|
|
30
|
+
updateUpdating: 'Đang tải bản cập nhật...',
|
|
31
|
+
quit: 'Thoát Aivin',
|
|
32
|
+
firstRun: 'Aivin đang chạy ở khay hệ thống — bấm biểu tượng để mở.',
|
|
33
|
+
connectHint: 'Aivin đang ở khay hệ thống — bấm biểu tượng rồi chọn “Đăng nhập để kết nối”.',
|
|
34
|
+
connected: 'Đã kết nối máy này với Aivin.',
|
|
35
|
+
pairFailed: 'Không kết nối được — mã sai hoặc đã hết hạn. Tạo mã mới trong Aivin rồi thử lại.',
|
|
36
|
+
pairPrompt: 'Nhập mã kết nối từ Aivin (khung chat → Browser ▾ → Thêm máy tính này):',
|
|
37
|
+
pairOk: 'Kết nối',
|
|
38
|
+
pairCancel: 'Huỷ',
|
|
39
|
+
connectCode: 'Tôi có mã kết nối',
|
|
40
|
+
connectBrowserHint: 'Đang mở trang đăng nhập. Sau khi bạn cấp quyền, Aivin sẽ tự kết nối máy tính này.',
|
|
41
|
+
connectPairing: 'Đăng nhập thành công. Đang liên kết máy tính…',
|
|
42
|
+
connectFailed: 'Chưa kết nối được. Hãy thử lại hoặc dùng mã kết nối.',
|
|
43
|
+
connectDone: 'Đã kết nối máy tính này với Aivin Cloud.',
|
|
44
|
+
shortcut: 'Aivin — cho các agent Aivin làm việc trên máy tính này',
|
|
45
|
+
openWith: 'Mở bằng AIVIN Office Suite',
|
|
46
|
+
share: 'Gửi cho AIVIN Bot',
|
|
47
|
+
workHere: 'Làm việc ở đây với AIVIN Bot',
|
|
48
|
+
uninstallPrompt: 'Gỡ AIVIN Bot khỏi máy này?\n\nỨng dụng, lệnh aivin và kết nối của máy với tài khoản sẽ bị xoá.\nCó xoá luôn dữ liệu (ghi nhớ của bot, bản sao tệp để hoàn tác, phiên đăng nhập trình duyệt)? Xoá rồi không lấy lại được.\n\nYes = gỡ và xoá dữ liệu\nNo = gỡ, giữ dữ liệu\nCancel = không gỡ',
|
|
49
|
+
uninstallFailed: 'Không gỡ tự động được. Mở Terminal và chạy: aivin uninstall',
|
|
50
|
+
stopCast: 'Ngưng kết nối cast ({device})',
|
|
51
|
+
trustedDevices: 'Thiết bị vào thẳng không cần hỏi',
|
|
52
|
+
trustedAccount: 'Chỉ tài khoản {account} mới vào được',
|
|
53
|
+
trustedLastUsed: 'Dùng lần cuối: {when}',
|
|
54
|
+
trustedPlace: 'Vị trí: {place}',
|
|
55
|
+
trustedIp: 'IP: {ip}',
|
|
56
|
+
trustedSince: 'Cho vào thẳng từ {date}',
|
|
57
|
+
trustedRemove: 'Gỡ thiết bị này',
|
|
58
|
+
trustedRemoveAll: 'Gỡ tất cả',
|
|
59
|
+
trustedHint: 'Thấy thiết bị lạ: gỡ đi và đổi mật khẩu',
|
|
60
|
+
agoNow: 'vừa xong',
|
|
61
|
+
agoMin: '{n} phút trước',
|
|
62
|
+
agoHour: '{n} giờ trước',
|
|
63
|
+
agoDay: '{n} ngày trước',
|
|
64
|
+
castDisconnected: 'Đã ngưng kết nối từ {device}. Thiết bị này sẽ cần xác nhận nếu muốn kết nối lại.',
|
|
65
|
+
fileType: 'Tài liệu mở bằng AIVIN Office Suite',
|
|
66
|
+
},
|
|
67
|
+
en: {
|
|
68
|
+
running: 'Running — ready for work',
|
|
69
|
+
paused: 'Paused — refusing all remote work',
|
|
70
|
+
stopped: 'Not running',
|
|
71
|
+
notPaired: 'Not connected to Aivin',
|
|
72
|
+
connecting: 'Connecting…',
|
|
73
|
+
open: 'Open Aivin',
|
|
74
|
+
quickChat: 'Quick chat',
|
|
75
|
+
quickVoice: 'Quick voice',
|
|
76
|
+
terminal: 'Open Terminal',
|
|
77
|
+
server: 'Server',
|
|
78
|
+
serverCloud: 'Cloud',
|
|
79
|
+
serverVn: 'VN',
|
|
80
|
+
serverLocal: 'Local',
|
|
81
|
+
serverConfirm: 'Switch to {server}? Current work on this computer will be stopped.',
|
|
82
|
+
connect: 'Sign in to connect…',
|
|
83
|
+
pause: 'Pause work',
|
|
84
|
+
resume: 'Resume work',
|
|
85
|
+
startup: 'Start with Windows',
|
|
86
|
+
mascot: 'Desktop mascot',
|
|
87
|
+
mascotShow: 'Show mascot',
|
|
88
|
+
mascotHide: 'Hide mascot',
|
|
89
|
+
version: 'Version: {version}',
|
|
90
|
+
updateUpToDate: 'Up to date',
|
|
91
|
+
updateAvailable: 'New version available ({version}) — Click to update',
|
|
92
|
+
updateChecking: 'Checking for updates...',
|
|
93
|
+
updateCheckNow: 'Check for updates',
|
|
94
|
+
updateUpdating: 'Downloading update...',
|
|
95
|
+
quit: 'Quit Aivin',
|
|
96
|
+
firstRun: 'Aivin is running in the system tray — click the icon to open it.',
|
|
97
|
+
connectHint: 'Aivin is in the system tray — click the icon, then choose “Sign in to connect”.',
|
|
98
|
+
connected: 'This computer is now connected to Aivin.',
|
|
99
|
+
pairFailed: 'Could not connect — the code is wrong or expired. Create a new code in Aivin and try again.',
|
|
100
|
+
pairPrompt: 'Enter the connect code from Aivin (chat box → Browser ▾ → Add this computer):',
|
|
101
|
+
pairOk: 'Connect',
|
|
102
|
+
pairCancel: 'Cancel',
|
|
103
|
+
connectCode: 'I have a connect code',
|
|
104
|
+
connectBrowserHint: 'Opening sign-in. Aivin will connect this computer after you grant access.',
|
|
105
|
+
connectPairing: 'Signed in. Linking this computer…',
|
|
106
|
+
connectFailed: 'Could not connect. Try again or use a connect code.',
|
|
107
|
+
connectDone: 'This computer is connected to Aivin Cloud.',
|
|
108
|
+
shortcut: 'Aivin — lets your Aivin agents work on this computer',
|
|
109
|
+
openWith: 'Open with AIVIN Office Suite',
|
|
110
|
+
share: 'Share with AIVIN Bot',
|
|
111
|
+
workHere: 'Work here with AIVIN Bot',
|
|
112
|
+
uninstallPrompt: 'Remove AIVIN Bot from this computer?\n\nThe app, the aivin command and this computer\'s connection to your account will be removed.\nAlso delete your data (the bot\'s memory, file copies kept for undo, browser sign-ins)? This cannot be undone.\n\nYes = remove and delete data\nNo = remove, keep data\nCancel = do not remove',
|
|
113
|
+
uninstallFailed: 'Could not remove it automatically. Open a terminal and run: aivin uninstall',
|
|
114
|
+
stopCast: 'Disconnect cast from {device}',
|
|
115
|
+
trustedDevices: 'Devices allowed without asking',
|
|
116
|
+
trustedAccount: 'Only account {account} can connect',
|
|
117
|
+
trustedLastUsed: 'Last used: {when}',
|
|
118
|
+
trustedPlace: 'Location: {place}',
|
|
119
|
+
trustedIp: 'IP: {ip}',
|
|
120
|
+
trustedSince: 'Allowed since {date}',
|
|
121
|
+
trustedRemove: 'Remove this device',
|
|
122
|
+
trustedRemoveAll: 'Remove all',
|
|
123
|
+
trustedHint: "Don't recognize one? Remove it and change your password",
|
|
124
|
+
agoNow: 'just now',
|
|
125
|
+
agoMin: '{n} min ago',
|
|
126
|
+
agoHour: '{n} h ago',
|
|
127
|
+
agoDay: '{n} days ago',
|
|
128
|
+
castDisconnected: 'Disconnected cast from {device}. Future casts will require confirmation.',
|
|
129
|
+
fileType: 'Document opened with AIVIN Office Suite',
|
|
130
|
+
},
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
/** Chữ khác đi theo hệ điều hành (macOS: thanh menu; macOS / Linux: khởi động cùng máy thay vì cùng Windows). */
|
|
134
|
+
const PLATFORM_STRINGS = Object.freeze({
|
|
135
|
+
darwin: {
|
|
136
|
+
vi: {
|
|
137
|
+
startup: 'Mở khi đăng nhập',
|
|
138
|
+
firstRun: 'Aivin đang chạy trên thanh menu — bấm biểu tượng để xem.',
|
|
139
|
+
connectHint: 'Aivin đang ở khay hệ thống — bấm biểu tượng rồi chọn “Đăng nhập để kết nối”.',
|
|
140
|
+
folder: 'Mở thư mục Aivin trong Finder',
|
|
141
|
+
},
|
|
142
|
+
en: {
|
|
143
|
+
startup: 'Open at login',
|
|
144
|
+
firstRun: 'Aivin is running in the menu bar — click its icon to see it.',
|
|
145
|
+
connectHint: 'Aivin is in the system tray — click its icon, then choose “Sign in to connect”.',
|
|
146
|
+
folder: 'Show Aivin folder in Finder',
|
|
147
|
+
},
|
|
148
|
+
},
|
|
149
|
+
linux: {
|
|
150
|
+
vi: { startup: 'Khởi động cùng máy' },
|
|
151
|
+
en: { startup: 'Start at login' },
|
|
152
|
+
},
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
export function trayStrings(lang, platform = 'win32') {
|
|
156
|
+
const code = TRAY_STRINGS[lang] ? lang : 'en';
|
|
157
|
+
return { ...TRAY_STRINGS[code], ...(PLATFORM_STRINGS[platform]?.[code] || {}) };
|
|
158
|
+
}
|
|
@@ -830,6 +830,9 @@ namespace AivinDesktop {
|
|
|
830
830
|
Match mDev = Regex.Match(castTxt, "\"viewer_device\"\\s*:\\s*\"([^\"]+)\"");
|
|
831
831
|
if (mDev.Success && !string.IsNullOrEmpty(mDev.Groups[1].Value)) {
|
|
832
832
|
castDevice = mDev.Groups[1].Value;
|
|
833
|
+
// Nơi theo IP: chủ máy biết ai đang điều khiển, không chỉ tên máy (tên do trình duyệt tự khai).
|
|
834
|
+
string place = JsonText(castTxt, "viewer_place");
|
|
835
|
+
if (place.Length > 0) castDevice += " · " + place.Split(',')[0].Trim();
|
|
833
836
|
} else {
|
|
834
837
|
Match mId = Regex.Match(castTxt, "\"viewer_id\"\\s*:\\s*\"([^\"]+)\"");
|
|
835
838
|
castDevice = mId.Success ? mId.Groups[1].Value : "Remote device";
|
|
@@ -851,40 +854,111 @@ namespace AivinDesktop {
|
|
|
851
854
|
}
|
|
852
855
|
|
|
853
856
|
/** Danh sách chỉ để hiện và gỡ — daemon mới là bên kiểm chữ ký và cho vào. Rỗng / daemon không chạy thì ẩn cả mục, menu giữ gọn. */
|
|
857
|
+
static string JsonText(string obj, string field) {
|
|
858
|
+
Match m = Regex.Match(obj, "\"" + field + "\"\\s*:\\s*\"([^\"]*)\"");
|
|
859
|
+
return m.Success ? m.Groups[1].Value : "";
|
|
860
|
+
}
|
|
861
|
+
|
|
862
|
+
static double JsonNumber(string obj, string field) {
|
|
863
|
+
Match m = Regex.Match(obj, "\"" + field + "\"\\s*:\\s*([0-9]+)");
|
|
864
|
+
double v;
|
|
865
|
+
return m.Success && double.TryParse(m.Groups[1].Value, out v) ? v : 0;
|
|
866
|
+
}
|
|
867
|
+
|
|
868
|
+
/** "2 giờ trước" — chủ máy nhận ra thiết bị theo lần dùng gần nhất dễ hơn ngày được tin. */
|
|
869
|
+
string Ago(double nowMs, double atMs) {
|
|
870
|
+
double min = Math.Max(0, (nowMs - atMs) / 60000);
|
|
871
|
+
if (min < 1) return cfg.T("agoNow");
|
|
872
|
+
if (min < 60) return cfg.T("agoMin").Replace("{n}", ((int)min).ToString());
|
|
873
|
+
if (min < 1440) return cfg.T("agoHour").Replace("{n}", ((int)(min / 60)).ToString());
|
|
874
|
+
return cfg.T("agoDay").Replace("{n}", ((int)(min / 1440)).ToString());
|
|
875
|
+
}
|
|
876
|
+
|
|
877
|
+
ToolStripMenuItem InfoItem(string text) {
|
|
878
|
+
ToolStripMenuItem item = Item(text, delegate { });
|
|
879
|
+
item.Enabled = false;
|
|
880
|
+
return item;
|
|
881
|
+
}
|
|
882
|
+
|
|
883
|
+
static void StyleDropDown(ToolStripMenuItem item) {
|
|
884
|
+
ToolStripDropDownMenu drop = item.DropDown as ToolStripDropDownMenu;
|
|
885
|
+
if (drop != null) { drop.ShowImageMargin = false; drop.ShowCheckMargin = false; }
|
|
886
|
+
item.DropDown.BackColor = Color.White;
|
|
887
|
+
item.DropDown.Font = new Font("Segoe UI", 9.5f, FontStyle.Regular);
|
|
888
|
+
item.DropDown.Padding = new Padding(2, 6, 2, 6);
|
|
889
|
+
}
|
|
890
|
+
|
|
891
|
+
/**
|
|
892
|
+
* Danh sách chỉ để hiện và gỡ — daemon mới là bên kiểm chữ ký và cho vào. Rỗng / daemon không chạy thì ẩn cả mục, menu giữ gọn.
|
|
893
|
+
* Mỗi thiết bị là một menu con: dòng chính "tên · nơi · lần dùng cuối", bên trong là tài khoản / IP / ngày được tin và nút gỡ.
|
|
894
|
+
* Chỉ tài khoản chủ máy xem được (BE chặn), nên tài khoản hiện một lần ở đầu: thấy thiết bị lạ nghĩa là tài khoản đã lộ.
|
|
895
|
+
*/
|
|
854
896
|
void RefreshTrustedDevices(bool running) {
|
|
897
|
+
// key, name, place, ip, account, lastUsed(ms), added date
|
|
855
898
|
var rows = new List<string[]>();
|
|
899
|
+
var lastUsed = new List<double>();
|
|
900
|
+
double nowMs = (DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalMilliseconds;
|
|
856
901
|
try {
|
|
857
902
|
if (running && File.Exists(TrustedDevicesFile)) {
|
|
858
|
-
double nowMs = (DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalMilliseconds;
|
|
859
903
|
foreach (Match row in Regex.Matches(File.ReadAllText(TrustedDevicesFile), "\\{[^{}]*\\}")) {
|
|
860
|
-
|
|
861
|
-
Match
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
if (!key.Success || !expires.Success || double.Parse(expires.Groups[1].Value) < nowMs) continue;
|
|
904
|
+
string obj = row.Value;
|
|
905
|
+
Match key = Regex.Match(obj, "\"key\"\\s*:\\s*\"([A-Za-z0-9+/=]+)\"");
|
|
906
|
+
double expires = JsonNumber(obj, "expires_at");
|
|
907
|
+
if (!key.Success || expires < nowMs) continue;
|
|
865
908
|
DateTime when;
|
|
866
|
-
string date = DateTime.TryParse(
|
|
867
|
-
|
|
909
|
+
string date = DateTime.TryParse(JsonText(obj, "added_at"), out when) ? when.ToString("dd/MM/yyyy") : "";
|
|
910
|
+
double used = JsonNumber(obj, "last_used_at");
|
|
911
|
+
int at = 0;
|
|
912
|
+
while (at < lastUsed.Count && lastUsed[at] >= used) at++;
|
|
913
|
+
lastUsed.Insert(at, used);
|
|
914
|
+
rows.Insert(at, new string[] { key.Groups[1].Value, JsonText(obj, "name"), JsonText(obj, "place"), JsonText(obj, "ip"), JsonText(obj, "account"), date });
|
|
868
915
|
}
|
|
869
916
|
}
|
|
870
917
|
} catch { }
|
|
871
918
|
|
|
872
919
|
trustedMenu.Visible = rows.Count > 0;
|
|
873
|
-
|
|
874
|
-
|
|
920
|
+
// Chữ "x phút trước" đổi theo thời gian: dựng lại khi chữ hiện ra đổi, không chỉ khi danh sách đổi.
|
|
921
|
+
var texts = new List<string>();
|
|
922
|
+
for (int i = 0; i < rows.Count; i++) {
|
|
923
|
+
string[] row = rows[i];
|
|
924
|
+
string where = row[2].Length > 0 ? row[2].Split(',')[0].Trim() : "";
|
|
925
|
+
texts.Add(row[1] + (where.Length > 0 ? " · " + where : "") + (lastUsed[i] > 0 ? " · " + Ago(nowMs, lastUsed[i]) : ""));
|
|
926
|
+
}
|
|
927
|
+
string account = "";
|
|
928
|
+
foreach (string[] row in rows) { if (row[4].Length > 0) { account = row[4]; break; } }
|
|
929
|
+
var shown = new StringBuilder(account);
|
|
930
|
+
for (int i = 0; i < rows.Count; i++) shown.Append('|').Append(rows[i][0]).Append('|').Append(texts[i]).Append('|').Append(rows[i][2]).Append('|').Append(rows[i][3]);
|
|
875
931
|
if (shown.ToString() == trustedShown) return;
|
|
876
932
|
trustedShown = shown.ToString();
|
|
877
933
|
|
|
878
934
|
trustedMenu.DropDownItems.Clear();
|
|
879
|
-
|
|
935
|
+
if (account.Length > 0) {
|
|
936
|
+
trustedMenu.DropDownItems.Add(InfoItem(cfg.T("trustedAccount").Replace("{account}", account)));
|
|
937
|
+
trustedMenu.DropDownItems.Add(new ToolStripSeparator());
|
|
938
|
+
}
|
|
939
|
+
for (int i = 0; i < rows.Count; i++) {
|
|
940
|
+
string[] row = rows[i];
|
|
880
941
|
string key = row[0];
|
|
881
|
-
|
|
882
|
-
|
|
942
|
+
SubmenuItem device = new SubmenuItem(texts[i]);
|
|
943
|
+
device.Padding = new Padding(16, 6, 24, 6);
|
|
944
|
+
StyleDropDown(device);
|
|
945
|
+
if (lastUsed[i] > 0) device.DropDownItems.Add(InfoItem(cfg.T("trustedLastUsed").Replace("{when}", Ago(nowMs, lastUsed[i]))));
|
|
946
|
+
if (row[2].Length > 0) device.DropDownItems.Add(InfoItem(cfg.T("trustedPlace").Replace("{place}", row[2])));
|
|
947
|
+
if (row[3].Length > 0) device.DropDownItems.Add(InfoItem(cfg.T("trustedIp").Replace("{ip}", row[3])));
|
|
948
|
+
if (row[5].Length > 0) device.DropDownItems.Add(InfoItem(cfg.T("trustedSince").Replace("{date}", row[5])));
|
|
949
|
+
device.DropDownItems.Add(new ToolStripSeparator());
|
|
950
|
+
ToolStripMenuItem remove = Item(cfg.T("trustedRemove"), delegate { SendTrustAction("{\"action\":\"untrust\",\"key\":\"" + key + "\"}"); });
|
|
951
|
+
remove.ForeColor = Color.FromArgb(210, 45, 45);
|
|
952
|
+
device.DropDownItems.Add(remove);
|
|
953
|
+
trustedMenu.DropDownItems.Add(device);
|
|
883
954
|
}
|
|
955
|
+
trustedMenu.DropDownItems.Add(new ToolStripSeparator());
|
|
884
956
|
if (rows.Count > 1) {
|
|
885
|
-
trustedMenu.DropDownItems.Add(new ToolStripSeparator());
|
|
886
957
|
trustedMenu.DropDownItems.Add(Item(cfg.T("trustedRemoveAll"), delegate { SendTrustAction("{\"action\":\"untrust_all\"}"); }));
|
|
887
958
|
}
|
|
959
|
+
ToolStripMenuItem hint = InfoItem(cfg.T("trustedHint"));
|
|
960
|
+
hint.Font = new Font("Segoe UI", 8.5f, FontStyle.Regular);
|
|
961
|
+
trustedMenu.DropDownItems.Add(hint);
|
|
888
962
|
}
|
|
889
963
|
|
|
890
964
|
void SendTrustAction(string json) {
|
|
@@ -1238,7 +1312,7 @@ namespace AivinDesktop {
|
|
|
1238
1312
|
Refresh();
|
|
1239
1313
|
Balloon(cfg.T("connectBrowserHint"), ToolTipIcon.Info);
|
|
1240
1314
|
ThreadPool.QueueUserWorkItem(delegate {
|
|
1241
|
-
int loginResult = RunCliAndWait("login");
|
|
1315
|
+
int loginResult = RunCliAndWait("login --app desktop");
|
|
1242
1316
|
if (quitting) return;
|
|
1243
1317
|
if (loginResult != 0) {
|
|
1244
1318
|
UI(delegate {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import net from 'net';
|
|
2
|
+
import os from 'os';
|
|
2
3
|
import readline from 'readline';
|
|
3
4
|
import { spawn } from 'child_process';
|
|
4
5
|
import { createDesktopWebRtc } from './desktopWebRtc.mjs';
|
|
@@ -24,6 +25,9 @@ export const DESKTOP_WEBRTC_WORKER_ARG = '__desktop-webrtc-worker';
|
|
|
24
25
|
const VIDEO_LIVE_MS = 3000;
|
|
25
26
|
|
|
26
27
|
export async function runDesktopWebRtcWorker({ input = process.stdin, output = process.stdout } = {}) {
|
|
28
|
+
// Bộ mã hoá hình chạy bằng CPU: máy bận mà ở mức thường thì có lượt đứng hình vài giây (đo 13/11/2026, 24 luồng đốt CPU: trung vị
|
|
29
|
+
// 104 ms, lượt tệ nhất 3 s; trên mức thường: 94 ms, tệ nhất 106 ms). Không lên High để không giành ứng dụng người dùng đang dùng.
|
|
30
|
+
try { os.setPriority(process.pid, os.constants.priority.PRIORITY_ABOVE_NORMAL); } catch { /* không đổi được thì chạy mức thường */ }
|
|
27
31
|
const send = (msg) => { try { output.write(JSON.stringify(msg) + '\n'); } catch { /* daemon đã đóng */ } };
|
|
28
32
|
let lastRawAt = 0;
|
|
29
33
|
let lastState = '';
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { createHash } from 'crypto';
|
|
2
|
+
import { execFileSync } from 'child_process';
|
|
3
|
+
import fs from 'fs';
|
|
4
|
+
import path from 'path';
|
|
5
|
+
import { REMOTE_CONFIG_DIR } from './constants.mjs';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* DPAPI nhanh trên Windows (13/11/2026): tệp exe nhỏ biên dịch một lần bằng csc của .NET Framework có sẵn trong Windows, đặt trong
|
|
9
|
+
* `~/.aivin/bin` (thư mục bị chặn với mọi công cụ từ xa). Mỗi lần giải ~0,1 s thay vì ~1–4 s của PowerShell — đủ nhanh để CLI giải khoá
|
|
10
|
+
* API ở MỖI lệnh. Không biên dịch được (máy chặn csc, diệt virus xoá tệp) → `null`, tokenStore lùi về PowerShell như cũ.
|
|
11
|
+
* Định dạng bản mã giống hệt bản PowerShell (UTF-8, entropy, CurrentUser, base64) nên đọc được bản mã cũ.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
const SOURCE = `using System; using System.Text; using System.Security.Cryptography;
|
|
15
|
+
class AivinDpapi {
|
|
16
|
+
static int Main(string[] a) {
|
|
17
|
+
try {
|
|
18
|
+
if (a.Length < 2) return 2;
|
|
19
|
+
string input = Console.In.ReadToEnd();
|
|
20
|
+
byte[] entropy = Encoding.UTF8.GetBytes(a[1]);
|
|
21
|
+
if (a[0] == "protect") {
|
|
22
|
+
Console.Out.Write(Convert.ToBase64String(ProtectedData.Protect(Encoding.UTF8.GetBytes(input), entropy, DataProtectionScope.CurrentUser)));
|
|
23
|
+
return 0;
|
|
24
|
+
}
|
|
25
|
+
if (a[0] == "unprotect") {
|
|
26
|
+
Console.Out.Write(Encoding.UTF8.GetString(ProtectedData.Unprotect(Convert.FromBase64String(input.Trim()), entropy, DataProtectionScope.CurrentUser)));
|
|
27
|
+
return 0;
|
|
28
|
+
}
|
|
29
|
+
return 2;
|
|
30
|
+
} catch { return 1; }
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
`;
|
|
34
|
+
|
|
35
|
+
const VERSION = createHash('sha256').update(SOURCE).digest('hex').slice(0, 10);
|
|
36
|
+
const BIN_DIR = path.join(REMOTE_CONFIG_DIR, 'bin');
|
|
37
|
+
export const DPAPI_HELPER_PATH = path.join(BIN_DIR, `aivin-dpapi-${VERSION}.exe`);
|
|
38
|
+
const FAILED_MARK = path.join(BIN_DIR, `aivin-dpapi-${VERSION}.failed`);
|
|
39
|
+
/** Biên dịch hỏng thì thôi thử lại trong ngần này — không bắt mọi lệnh chờ csc. */
|
|
40
|
+
const RETRY_AFTER_FAIL_MS = 24 * 3600_000;
|
|
41
|
+
const RUN_TIMEOUT_MS = 10_000;
|
|
42
|
+
|
|
43
|
+
export const DpapiMode = Object.freeze({ PROTECT: 'protect', UNPROTECT: 'unprotect' });
|
|
44
|
+
|
|
45
|
+
let resolved; // undefined = chưa dò; null = không dùng được; chuỗi = đường dẫn exe
|
|
46
|
+
|
|
47
|
+
function cscPath(env = process.env) {
|
|
48
|
+
const windir = env.WINDIR || env.SystemRoot || 'C:\\Windows';
|
|
49
|
+
return ['Framework64', 'Framework'].map((d) => path.join(windir, 'Microsoft.NET', d, 'v4.0.30319', 'csc.exe')).find((p) => fs.existsSync(p)) || null;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function recentlyFailed() {
|
|
53
|
+
try { return Date.now() - fs.statSync(FAILED_MARK).mtimeMs < RETRY_AFTER_FAIL_MS; } catch { return false; }
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function build() {
|
|
57
|
+
const csc = cscPath();
|
|
58
|
+
if (!csc) return null;
|
|
59
|
+
fs.mkdirSync(BIN_DIR, { recursive: true });
|
|
60
|
+
const src = path.join(BIN_DIR, `aivin-dpapi-${VERSION}.cs`);
|
|
61
|
+
const tmp = `${DPAPI_HELPER_PATH}.${process.pid}.tmp`;
|
|
62
|
+
try {
|
|
63
|
+
fs.writeFileSync(src, SOURCE, 'utf8');
|
|
64
|
+
execFileSync(csc, ['-nologo', '-target:exe', '-optimize+', '-r:System.Security.dll', `-out:${tmp}`, src], { timeout: 60_000, windowsHide: true, stdio: 'ignore' });
|
|
65
|
+
fs.renameSync(tmp, DPAPI_HELPER_PATH);
|
|
66
|
+
return DPAPI_HELPER_PATH;
|
|
67
|
+
} catch {
|
|
68
|
+
try { fs.rmSync(tmp, { force: true }); } catch { /* không có thì thôi */ }
|
|
69
|
+
try { fs.writeFileSync(FAILED_MARK, new Date().toISOString()); } catch { /* chỉ là dấu */ }
|
|
70
|
+
return fs.existsSync(DPAPI_HELPER_PATH) ? DPAPI_HELPER_PATH : null;
|
|
71
|
+
} finally {
|
|
72
|
+
try { fs.rmSync(src, { force: true }); } catch { /* không có thì thôi */ }
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** Đường dẫn exe (biên dịch lần đầu nếu cần); `null` khi không phải Windows hoặc không dựng được. */
|
|
77
|
+
export function dpapiHelper({ platform = process.platform } = {}) {
|
|
78
|
+
if (resolved !== undefined) return resolved;
|
|
79
|
+
if (platform !== 'win32' || process.env.AIVIN_DPAPI_HELPER === '0') return (resolved = null);
|
|
80
|
+
if (fs.existsSync(DPAPI_HELPER_PATH)) return (resolved = DPAPI_HELPER_PATH);
|
|
81
|
+
if (recentlyFailed()) return (resolved = null);
|
|
82
|
+
return (resolved = build());
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** Chạy exe; lỗi (bản mã của máy / tài khoản khác…) → ném lỗi như nhánh PowerShell. */
|
|
86
|
+
export function runDpapiHelper(exe, mode, input, entropy) {
|
|
87
|
+
return execFileSync(exe, [mode, entropy], { input, encoding: 'utf8', timeout: RUN_TIMEOUT_MS, windowsHide: true, stdio: ['pipe', 'pipe', 'pipe'] }).trim();
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** Chỉ cho test: quên kết quả dò. */
|
|
91
|
+
export function resetDpapiHelperForTest() { resolved = undefined; }
|