pal-explorer-cli 0.4.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.
Files changed (156) hide show
  1. package/LICENSE.md +18 -0
  2. package/README.md +314 -0
  3. package/bin/pal.js +230 -0
  4. package/extensions/@palexplorer/analytics/README.md +45 -0
  5. package/extensions/@palexplorer/analytics/docs/MONETIZATION.md +14 -0
  6. package/extensions/@palexplorer/analytics/docs/PLAN.md +23 -0
  7. package/extensions/@palexplorer/analytics/docs/PRIVACY.md +38 -0
  8. package/extensions/@palexplorer/analytics/extension.json +27 -0
  9. package/extensions/@palexplorer/analytics/index.js +186 -0
  10. package/extensions/@palexplorer/analytics/test/analytics.test.js +82 -0
  11. package/extensions/@palexplorer/audit/extension.json +17 -0
  12. package/extensions/@palexplorer/audit/index.js +2 -0
  13. package/extensions/@palexplorer/auth-email/extension.json +17 -0
  14. package/extensions/@palexplorer/auth-email/index.js +102 -0
  15. package/extensions/@palexplorer/auth-oauth/extension.json +16 -0
  16. package/extensions/@palexplorer/auth-oauth/index.js +199 -0
  17. package/extensions/@palexplorer/chat/extension.json +17 -0
  18. package/extensions/@palexplorer/chat/index.js +2 -0
  19. package/extensions/@palexplorer/discovery/extension.json +16 -0
  20. package/extensions/@palexplorer/discovery/index.js +111 -0
  21. package/extensions/@palexplorer/email-notifications/extension.json +23 -0
  22. package/extensions/@palexplorer/email-notifications/index.js +242 -0
  23. package/extensions/@palexplorer/explorer-integration/extension.json +13 -0
  24. package/extensions/@palexplorer/explorer-integration/index.js +122 -0
  25. package/extensions/@palexplorer/groups/extension.json +17 -0
  26. package/extensions/@palexplorer/groups/index.js +2 -0
  27. package/extensions/@palexplorer/networks/extension.json +17 -0
  28. package/extensions/@palexplorer/networks/index.js +2 -0
  29. package/extensions/@palexplorer/share-links/extension.json +17 -0
  30. package/extensions/@palexplorer/share-links/index.js +2 -0
  31. package/extensions/@palexplorer/sync/extension.json +17 -0
  32. package/extensions/@palexplorer/sync/index.js +2 -0
  33. package/extensions/@palexplorer/user-mgmt/extension.json +17 -0
  34. package/extensions/@palexplorer/user-mgmt/index.js +2 -0
  35. package/extensions/@palexplorer/vfs/extension.json +17 -0
  36. package/extensions/@palexplorer/vfs/index.js +167 -0
  37. package/lib/capabilities.js +263 -0
  38. package/lib/commands/analytics.js +175 -0
  39. package/lib/commands/api-keys.js +131 -0
  40. package/lib/commands/audit.js +235 -0
  41. package/lib/commands/auth.js +137 -0
  42. package/lib/commands/backup.js +76 -0
  43. package/lib/commands/billing.js +148 -0
  44. package/lib/commands/chat.js +217 -0
  45. package/lib/commands/cloud-backup.js +231 -0
  46. package/lib/commands/comment.js +99 -0
  47. package/lib/commands/completion.js +203 -0
  48. package/lib/commands/compliance.js +218 -0
  49. package/lib/commands/config.js +136 -0
  50. package/lib/commands/connect.js +44 -0
  51. package/lib/commands/dept.js +294 -0
  52. package/lib/commands/device.js +146 -0
  53. package/lib/commands/download.js +226 -0
  54. package/lib/commands/explorer.js +178 -0
  55. package/lib/commands/extension.js +970 -0
  56. package/lib/commands/favorite.js +90 -0
  57. package/lib/commands/federation.js +270 -0
  58. package/lib/commands/file.js +533 -0
  59. package/lib/commands/group.js +271 -0
  60. package/lib/commands/gui-share.js +29 -0
  61. package/lib/commands/init.js +61 -0
  62. package/lib/commands/invite.js +59 -0
  63. package/lib/commands/list.js +59 -0
  64. package/lib/commands/log.js +116 -0
  65. package/lib/commands/nearby.js +108 -0
  66. package/lib/commands/network.js +251 -0
  67. package/lib/commands/notify.js +198 -0
  68. package/lib/commands/org.js +273 -0
  69. package/lib/commands/pal.js +180 -0
  70. package/lib/commands/permissions.js +216 -0
  71. package/lib/commands/pin.js +97 -0
  72. package/lib/commands/protocol.js +357 -0
  73. package/lib/commands/rbac.js +147 -0
  74. package/lib/commands/recover.js +36 -0
  75. package/lib/commands/register.js +171 -0
  76. package/lib/commands/relay.js +131 -0
  77. package/lib/commands/remote.js +368 -0
  78. package/lib/commands/revoke.js +50 -0
  79. package/lib/commands/scanner.js +280 -0
  80. package/lib/commands/schedule.js +344 -0
  81. package/lib/commands/scim.js +203 -0
  82. package/lib/commands/search.js +181 -0
  83. package/lib/commands/serve.js +438 -0
  84. package/lib/commands/server.js +350 -0
  85. package/lib/commands/share-link.js +199 -0
  86. package/lib/commands/share.js +323 -0
  87. package/lib/commands/sso.js +200 -0
  88. package/lib/commands/status.js +136 -0
  89. package/lib/commands/stream.js +562 -0
  90. package/lib/commands/su.js +187 -0
  91. package/lib/commands/sync.js +827 -0
  92. package/lib/commands/transfers.js +152 -0
  93. package/lib/commands/uninstall.js +188 -0
  94. package/lib/commands/update.js +204 -0
  95. package/lib/commands/user.js +276 -0
  96. package/lib/commands/vfs.js +84 -0
  97. package/lib/commands/web.js +52 -0
  98. package/lib/commands/webhook.js +180 -0
  99. package/lib/commands/whoami.js +59 -0
  100. package/lib/commands/workspace.js +121 -0
  101. package/lib/core/accessLog.js +54 -0
  102. package/lib/core/analytics.js +99 -0
  103. package/lib/core/backup.js +84 -0
  104. package/lib/core/billing.js +336 -0
  105. package/lib/core/bitfieldStore.js +53 -0
  106. package/lib/core/connectionManager.js +182 -0
  107. package/lib/core/dhtDiscovery.js +148 -0
  108. package/lib/core/discoveryClient.js +408 -0
  109. package/lib/core/extensionAnalyzer.js +357 -0
  110. package/lib/core/extensionSandbox.js +250 -0
  111. package/lib/core/extensionWorkerHost.js +166 -0
  112. package/lib/core/extensions.js +1082 -0
  113. package/lib/core/fileDiff.js +69 -0
  114. package/lib/core/groups.js +119 -0
  115. package/lib/core/identity.js +340 -0
  116. package/lib/core/mdnsService.js +126 -0
  117. package/lib/core/networks.js +81 -0
  118. package/lib/core/permissions.js +109 -0
  119. package/lib/core/pro.js +27 -0
  120. package/lib/core/resolver.js +74 -0
  121. package/lib/core/serverList.js +224 -0
  122. package/lib/core/sharePolicy.js +69 -0
  123. package/lib/core/shares.js +325 -0
  124. package/lib/core/signalingServer.js +441 -0
  125. package/lib/core/streamTransport.js +106 -0
  126. package/lib/core/su.js +55 -0
  127. package/lib/core/syncEngine.js +264 -0
  128. package/lib/core/syncState.js +159 -0
  129. package/lib/core/transfers.js +259 -0
  130. package/lib/core/users.js +225 -0
  131. package/lib/core/vfs.js +216 -0
  132. package/lib/core/webServer.js +702 -0
  133. package/lib/core/webrtcStream.js +396 -0
  134. package/lib/crypto/chatEncryption.js +57 -0
  135. package/lib/crypto/shareEncryption.js +195 -0
  136. package/lib/crypto/sharePassword.js +35 -0
  137. package/lib/crypto/streamEncryption.js +189 -0
  138. package/lib/package.json +1 -0
  139. package/lib/protocol/envelope.js +271 -0
  140. package/lib/protocol/handler.js +191 -0
  141. package/lib/protocol/index.js +27 -0
  142. package/lib/protocol/messages.js +247 -0
  143. package/lib/protocol/negotiation.js +127 -0
  144. package/lib/protocol/policy.js +142 -0
  145. package/lib/protocol/router.js +86 -0
  146. package/lib/protocol/sync.js +122 -0
  147. package/lib/utils/cli.js +15 -0
  148. package/lib/utils/config.js +123 -0
  149. package/lib/utils/configIntegrity.js +87 -0
  150. package/lib/utils/downloadDir.js +9 -0
  151. package/lib/utils/explorer.js +83 -0
  152. package/lib/utils/format.js +12 -0
  153. package/lib/utils/help.js +357 -0
  154. package/lib/utils/logger.js +103 -0
  155. package/lib/utils/torrent.js +203 -0
  156. package/package.json +71 -0
@@ -0,0 +1,187 @@
1
+ import chalk from 'chalk';
2
+ import readline from 'readline';
3
+ import config from '../utils/config.js';
4
+ import { setSuToken, hasSuToken, authenticate, isAuthenticated, requireSu, removeSuToken } from '../core/su.js';
5
+ import { getPrimaryServer, getServers, addServer as addDiscoveryServer, removeServer as removeDiscoveryServer, setPrimaryServer, addUserServer } from '../core/discoveryClient.js';
6
+ import { refreshServerList, healthCheckServers, getServerRoles, SERVER_ROLES, isWriteTrusted } from '../core/serverList.js';
7
+ import { parseCommaList } from '../utils/cli.js';
8
+
9
+ function prompt(question, { hidden = false } = {}) {
10
+ const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
11
+ if (hidden) {
12
+ const origWrite = process.stdout.write.bind(process.stdout);
13
+ process.stdout.write = (s) => {
14
+ if (s === question) return origWrite(s);
15
+ return origWrite('');
16
+ };
17
+ return new Promise(resolve => rl.question(question, answer => {
18
+ process.stdout.write = origWrite;
19
+ origWrite('\n');
20
+ rl.close();
21
+ resolve(answer.trim());
22
+ }));
23
+ }
24
+ return new Promise(resolve => rl.question(question, answer => { rl.close(); resolve(answer.trim()); }));
25
+ }
26
+
27
+ function confirm(question) {
28
+ return prompt(question).then(a => a.toLowerCase() === 'y');
29
+ }
30
+
31
+ export default function suCommand(program) {
32
+ const su = program.command('su').description('super user commands (network-level administration)');
33
+
34
+ su.addHelpText('after', `
35
+ The super user (SU) controls the discovery server network.
36
+ SU is separate from the local device owner role.
37
+
38
+ Setup:
39
+ $ pe su setup Set the SU token (first time only)
40
+ $ pe su auth Authenticate for this session
41
+
42
+ Server management:
43
+ $ pe su server add <url> Add a server to the network
44
+ $ pe su server remove <url> Remove a server
45
+ $ pe su server set-primary <url> Change primary server
46
+
47
+ Other:
48
+ $ pe su reset Remove the SU token
49
+ `);
50
+
51
+ su
52
+ .command('setup')
53
+ .description('set the super user token (first time or reset)')
54
+ .action(async () => {
55
+ if (hasSuToken()) {
56
+ const current = await prompt('Enter current SU token: ', { hidden: true });
57
+ if (!authenticate(current)) {
58
+ console.log(chalk.red('Invalid SU token.'));
59
+ return;
60
+ }
61
+ }
62
+ const token = await prompt('Enter new SU token: ', { hidden: true });
63
+ if (!token || token.length < 8) {
64
+ console.log(chalk.red('Token must be at least 8 characters.'));
65
+ return;
66
+ }
67
+ const confirm2 = await prompt('Confirm SU token: ', { hidden: true });
68
+ if (token !== confirm2) {
69
+ console.log(chalk.red('Tokens do not match.'));
70
+ return;
71
+ }
72
+ setSuToken(token);
73
+ authenticate(token);
74
+ console.log(chalk.green('SU token set and authenticated for this session.'));
75
+ });
76
+
77
+ su
78
+ .command('auth')
79
+ .description('authenticate as super user for this session')
80
+ .action(async () => {
81
+ if (!hasSuToken()) {
82
+ console.log(chalk.red('No SU token configured. Run "pe su setup" first.'));
83
+ return;
84
+ }
85
+ if (isAuthenticated()) {
86
+ console.log(chalk.green('Already authenticated as SU.'));
87
+ return;
88
+ }
89
+ const token = await prompt('SU token: ', { hidden: true });
90
+ if (authenticate(token)) {
91
+ console.log(chalk.green('Authenticated as super user.'));
92
+ } else {
93
+ console.log(chalk.red('Invalid SU token.'));
94
+ }
95
+ });
96
+
97
+ su
98
+ .command('reset')
99
+ .description('remove the SU token')
100
+ .action(async () => {
101
+ if (!hasSuToken()) {
102
+ console.log(chalk.yellow('No SU token is set.'));
103
+ return;
104
+ }
105
+ const token = await prompt('Enter current SU token to confirm: ', { hidden: true });
106
+ if (!authenticate(token)) {
107
+ console.log(chalk.red('Invalid SU token.'));
108
+ return;
109
+ }
110
+ removeSuToken();
111
+ console.log(chalk.green('SU token removed.'));
112
+ });
113
+
114
+ // Server management subcommands
115
+ const server = su.command('server').description('manage discovery servers (SU only)');
116
+
117
+ server
118
+ .command('add <url>')
119
+ .description('add a discovery server to the network')
120
+ .option('-y, --yes', 'Skip confirmation prompt')
121
+ .option('--skip-verify', 'Skip server verification (not recommended)')
122
+ .option('--read-only', 'Add as read-only (no writes sent to this server)')
123
+ .option('--roles <roles>', 'Comma-separated roles (discovery,signaling,turn,stun,relay,billing)')
124
+ .action(async (url, opts) => {
125
+ try { requireSu(); } catch (e) { console.log(chalk.red(e.message)); return; }
126
+ const roles = parseCommaList(opts.roles).filter(r => SERVER_ROLES.includes(r));
127
+ const trustWrites = !opts.readOnly;
128
+
129
+ if (opts.skipVerify) {
130
+ addDiscoveryServer(url, { skipVerify: true });
131
+ if (roles.length > 0) {
132
+ await addUserServer(url, roles, { trustWrites });
133
+ }
134
+ console.log(chalk.yellow('Added without verification (no pinned key).'));
135
+ return;
136
+ }
137
+
138
+ try {
139
+ console.log(chalk.blue(`Verifying server at ${url}...`));
140
+ const result = await addDiscoveryServer(url);
141
+ console.log('');
142
+ console.log(chalk.white(` Server key fingerprint: ${chalk.cyan(result.fingerprint)}`));
143
+ console.log(chalk.gray(` Trust: ${trustWrites ? 'read + write' : 'read-only'}`));
144
+ console.log('');
145
+
146
+ if (!opts.yes) {
147
+ const ok = await confirm(chalk.white(' Trust this server and add it? (y/N) '));
148
+ if (!ok) {
149
+ removeDiscoveryServer(url);
150
+ const pinned = config.get('pinnedServerKeys') || {};
151
+ delete pinned[url.replace(/\/+$/, '')];
152
+ config.set('pinnedServerKeys', pinned);
153
+ console.log(chalk.yellow(' Aborted.'));
154
+ return;
155
+ }
156
+ }
157
+
158
+ const roleResult = await addUserServer(url, roles, { trustWrites });
159
+ console.log(chalk.green(`Added server: ${url}`));
160
+ console.log(chalk.gray(` Roles: ${roleResult.roles.join(', ')}`));
161
+ console.log(chalk.gray(` Trust: ${trustWrites ? 'read + write' : 'read-only'}`));
162
+ console.log(chalk.gray(` Key pinned. Run 'pe server verify' to re-check.`));
163
+ } catch (err) {
164
+ console.log(chalk.red(`${err.message}`));
165
+ }
166
+ });
167
+
168
+ server
169
+ .command('remove <url>')
170
+ .description('remove a discovery server from the network')
171
+ .action((url) => {
172
+ try { requireSu(); } catch (e) { console.log(chalk.red(e.message)); return; }
173
+ const servers = removeDiscoveryServer(url);
174
+ console.log(chalk.green(`Removed: ${url}`));
175
+ console.log(chalk.gray(` Remaining: ${servers.length}`));
176
+ });
177
+
178
+ server
179
+ .command('set-primary <url>')
180
+ .description('set a discovery server as the primary')
181
+ .action((url) => {
182
+ try { requireSu(); } catch (e) { console.log(chalk.red(e.message)); return; }
183
+ const servers = setPrimaryServer(url);
184
+ console.log(chalk.green(`Primary set to: ${url}`));
185
+ console.log(chalk.gray(` Order: ${servers.join(', ')}`));
186
+ });
187
+ }