polaris-vpn 0.1.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/CHANGELOG.md +17 -0
- package/LICENSE +177 -0
- package/README.md +99 -0
- package/package.json +42 -0
- package/src/cli.js +127 -0
- package/src/commands/check.js +101 -0
- package/src/commands/servers.js +89 -0
- package/src/commands/start.js +91 -0
- package/src/commands/status.js +63 -0
- package/src/commands/stop.js +32 -0
- package/src/net/ip.js +50 -0
- package/src/tunnel/ssh.js +134 -0
- package/src/ui/display.js +40 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [0.1.0] - 2026-06-27
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- MVP release of Polaris CLI.
|
|
13
|
+
- `polaris start`: Setup a SOCKS5 SSH proxy.
|
|
14
|
+
- `polaris stop`: Stop the active tunnel.
|
|
15
|
+
- `polaris status`: Check tunnel status.
|
|
16
|
+
- `polaris check`: 3-point privacy leak check (IP, DNS, IPv6).
|
|
17
|
+
- `polaris add/list/use`: Save and manage server profiles.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
# Apache License
|
|
2
|
+
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
<http://www.apache.org/licenses/>
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
package/README.md
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
# polaris — Leave no trace
|
|
2
|
+
|
|
3
|
+

|
|
4
|
+
|
|
5
|
+
Your True North in Digital Privacy. `polaris` is a production-quality, open-source, self-hosted VPN CLI tool. It wraps SSH dynamic port forwarding into a beautiful CLI experience.
|
|
6
|
+
|
|
7
|
+
## Prerequisites
|
|
8
|
+
|
|
9
|
+
- SSH access to any VPS (Virtual Private Server).
|
|
10
|
+
- Node.js >= 18
|
|
11
|
+
|
|
12
|
+
We highly recommend **Oracle Cloud Free Tier** for your VPS.
|
|
13
|
+
|
|
14
|
+
## Install
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
npm install -g polaris-vpn
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Quickstart (30 seconds)
|
|
21
|
+
|
|
22
|
+
Once you have your server's IP address and SSH credentials (e.g. `ubuntu@1.2.3.4`), just run:
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
polaris start --server ubuntu@1.2.3.4
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
This will instantly create an encrypted SOCKS5 proxy on `127.0.0.1:1080` and route your traffic through it.
|
|
29
|
+
|
|
30
|
+
Verify it's working:
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
polaris check
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
When you're done:
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
polaris stop
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## Command Reference
|
|
43
|
+
|
|
44
|
+
| Command | Description |
|
|
45
|
+
| --- | --- |
|
|
46
|
+
| `polaris start --server user@host [--port 1080]` | Start the encrypted SSH tunnel. |
|
|
47
|
+
| `polaris stop` | Stop the active tunnel. |
|
|
48
|
+
| `polaris status` | Show current tunnel status, IP, and uptime. |
|
|
49
|
+
| `polaris check` | Run a 3-point privacy check (IP, DNS leak, IPv6 leak). |
|
|
50
|
+
| `polaris add <alias> --server user@host` | Save a server profile for quick access. |
|
|
51
|
+
| `polaris list` | List all saved server profiles. |
|
|
52
|
+
| `polaris use <alias>` | Set a saved profile as the active default. |
|
|
53
|
+
|
|
54
|
+
> All commands support the `--json` flag for machine-readable output.
|
|
55
|
+
|
|
56
|
+
## Oracle Cloud Free Tier Setup
|
|
57
|
+
|
|
58
|
+
The recommended free server is Oracle Cloud Always Free tier:
|
|
59
|
+
|
|
60
|
+
- **ARM VM (A1.Flex)**: 2 OCPUs, 12 GB RAM — completely free forever.
|
|
61
|
+
- 10 TB outbound bandwidth/month — more than enough for personal use.
|
|
62
|
+
- Best regions from South/Southeast Asia: India (Hyderabad) ~30ms, Singapore ~50ms, Japan (Tokyo) ~80ms.
|
|
63
|
+
- Sign up at [cloud.oracle.com](https://cloud.oracle.com) (requires a credit card for verification but charges nothing for Always Free resources).
|
|
64
|
+
- After VM creation, just grab the IP and SSH key, and run `polaris start --server ubuntu@<your-oracle-ip>`.
|
|
65
|
+
|
|
66
|
+
## Shared Server Model
|
|
67
|
+
|
|
68
|
+
One Oracle VM can serve multiple people:
|
|
69
|
+
|
|
70
|
+
- Light browsing (1–2 Mbps/user): 25–50 people comfortably.
|
|
71
|
+
- YouTube/social (5 Mbps/user): 8–10 people simultaneously.
|
|
72
|
+
- One person owns the VM, others get SSH keys.
|
|
73
|
+
- Or each person creates their own free Oracle account for full isolation.
|
|
74
|
+
|
|
75
|
+
## How It Works
|
|
76
|
+
|
|
77
|
+
`polaris` uses standard SSH dynamic port forwarding (`-D` flag) behind the scenes. It sets up a secure, encrypted tunnel from your local machine to your server, and exposes a local SOCKS5 proxy. This gives you instant VPN-like privacy without installing *any* server-side software.
|
|
78
|
+
|
|
79
|
+
## Trust Model
|
|
80
|
+
|
|
81
|
+
- **You own the server**: No reliance on third-party VPN providers.
|
|
82
|
+
- **Zero telemetry**: No tracking, no crash reporting, no analytics.
|
|
83
|
+
- **No central infra**: We run nothing. You bring your own VPS.
|
|
84
|
+
- **Open Source**: Apache 2.0 licensed, fully auditable.
|
|
85
|
+
|
|
86
|
+
## Roadmap
|
|
87
|
+
|
|
88
|
+
- **v0.1**: MVP — SSH SOCKS5 tunnel (Current)
|
|
89
|
+
- **v0.2**: TLS tunnel + DNS-over-HTTPS + leak checker
|
|
90
|
+
- **v0.5**: WireGuard full tunnel + server provisioning
|
|
91
|
+
- **v1.0**: AmneziaWG stealth mode + multi-peer + QR codes + kill switch
|
|
92
|
+
|
|
93
|
+
## Contributing
|
|
94
|
+
|
|
95
|
+
Contributions, issues, and feature requests are welcome!
|
|
96
|
+
|
|
97
|
+
## License
|
|
98
|
+
|
|
99
|
+
Apache 2.0
|
package/package.json
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "polaris-vpn",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Your True North in Digital Privacy. A self-hosted VPN CLI.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"bin": {
|
|
7
|
+
"polaris": "src/cli.js"
|
|
8
|
+
},
|
|
9
|
+
"files": [
|
|
10
|
+
"src",
|
|
11
|
+
"README.md",
|
|
12
|
+
"LICENSE",
|
|
13
|
+
"CHANGELOG.md"
|
|
14
|
+
],
|
|
15
|
+
"engines": {
|
|
16
|
+
"node": ">=18"
|
|
17
|
+
},
|
|
18
|
+
"scripts": {
|
|
19
|
+
"start": "node ./src/cli.js"
|
|
20
|
+
},
|
|
21
|
+
"license": "Apache-2.0",
|
|
22
|
+
"keywords": [
|
|
23
|
+
"vpn",
|
|
24
|
+
"privacy",
|
|
25
|
+
"tunnel",
|
|
26
|
+
"socks5",
|
|
27
|
+
"proxy",
|
|
28
|
+
"cli",
|
|
29
|
+
"wireguard",
|
|
30
|
+
"self-hosted",
|
|
31
|
+
"oracle-cloud"
|
|
32
|
+
],
|
|
33
|
+
"dependencies": {
|
|
34
|
+
"chalk": "^5.6.2",
|
|
35
|
+
"cli-table3": "^0.6.5",
|
|
36
|
+
"commander": "^15.0.0",
|
|
37
|
+
"conf": "^15.1.0",
|
|
38
|
+
"node-fetch": "^3.3.2",
|
|
39
|
+
"ora": "^9.4.1",
|
|
40
|
+
"socks-proxy-agent": "^10.1.0"
|
|
41
|
+
}
|
|
42
|
+
}
|
package/src/cli.js
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { Command } from 'commander';
|
|
3
|
+
import { readFileSync } from 'fs';
|
|
4
|
+
import { fileURLToPath } from 'url';
|
|
5
|
+
import path from 'path';
|
|
6
|
+
import { printBanner, printError } from './ui/display.js';
|
|
7
|
+
|
|
8
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
9
|
+
const __dirname = path.dirname(__filename);
|
|
10
|
+
const pkg = JSON.parse(readFileSync(path.join(__dirname, '..', 'package.json'), 'utf-8'));
|
|
11
|
+
|
|
12
|
+
const program = new Command();
|
|
13
|
+
|
|
14
|
+
program
|
|
15
|
+
.name('polaris')
|
|
16
|
+
.description(pkg.description)
|
|
17
|
+
.version(pkg.version)
|
|
18
|
+
.option('--json', 'Output results in JSON format');
|
|
19
|
+
|
|
20
|
+
// Helper to check if we should print the banner
|
|
21
|
+
const willPrintJson = () => process.argv.includes('--json');
|
|
22
|
+
|
|
23
|
+
program
|
|
24
|
+
.command('start')
|
|
25
|
+
.description('Start the encrypted SSH tunnel')
|
|
26
|
+
.option('-s, --server <user@host>', 'SSH server to connect to')
|
|
27
|
+
.option('-p, --port <number>', 'Local SOCKS5 port to bind', '1080')
|
|
28
|
+
.action(async (options, cmd) => {
|
|
29
|
+
if (!cmd.optsWithGlobals().json) printBanner();
|
|
30
|
+
try {
|
|
31
|
+
const run = (await import('./commands/start.js')).default;
|
|
32
|
+
await run(cmd.optsWithGlobals());
|
|
33
|
+
} catch (err) {
|
|
34
|
+
if (!cmd.optsWithGlobals().json) printError('Command failed', err);
|
|
35
|
+
process.exit(1);
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
program
|
|
40
|
+
.command('stop')
|
|
41
|
+
.description('Stop the active tunnel')
|
|
42
|
+
.action(async (options, cmd) => {
|
|
43
|
+
if (!cmd.optsWithGlobals().json) printBanner();
|
|
44
|
+
try {
|
|
45
|
+
const run = (await import('./commands/stop.js')).default;
|
|
46
|
+
await run(cmd.optsWithGlobals());
|
|
47
|
+
} catch (err) {
|
|
48
|
+
if (!cmd.optsWithGlobals().json) printError('Command failed', err);
|
|
49
|
+
process.exit(1);
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
program
|
|
54
|
+
.command('status')
|
|
55
|
+
.description('Show current tunnel status, IP, and uptime')
|
|
56
|
+
.action(async (options, cmd) => {
|
|
57
|
+
if (!cmd.optsWithGlobals().json) printBanner();
|
|
58
|
+
try {
|
|
59
|
+
const run = (await import('./commands/status.js')).default;
|
|
60
|
+
await run(cmd.optsWithGlobals());
|
|
61
|
+
} catch (err) {
|
|
62
|
+
if (!cmd.optsWithGlobals().json) printError('Command failed', err);
|
|
63
|
+
process.exit(1);
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
program
|
|
68
|
+
.command('check')
|
|
69
|
+
.description('Run a 3-point privacy check (IP, DNS leak, IPv6 leak)')
|
|
70
|
+
.action(async (options, cmd) => {
|
|
71
|
+
if (!cmd.optsWithGlobals().json) printBanner();
|
|
72
|
+
try {
|
|
73
|
+
const run = (await import('./commands/check.js')).default;
|
|
74
|
+
await run(cmd.optsWithGlobals());
|
|
75
|
+
} catch (err) {
|
|
76
|
+
if (!cmd.optsWithGlobals().json) printError('Command failed', err);
|
|
77
|
+
process.exit(1);
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
program
|
|
82
|
+
.command('add <alias>')
|
|
83
|
+
.description('Save a server profile for quick access')
|
|
84
|
+
.requiredOption('-s, --server <user@host>', 'SSH server for this profile')
|
|
85
|
+
.action(async (alias, options, cmd) => {
|
|
86
|
+
if (!cmd.optsWithGlobals().json) printBanner();
|
|
87
|
+
try {
|
|
88
|
+
const { addServer } = await import('./commands/servers.js');
|
|
89
|
+
await addServer(alias, cmd.optsWithGlobals());
|
|
90
|
+
} catch (err) {
|
|
91
|
+
if (!cmd.optsWithGlobals().json) printError('Command failed', err);
|
|
92
|
+
process.exit(1);
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
program
|
|
97
|
+
.command('list')
|
|
98
|
+
.description('List all saved server profiles')
|
|
99
|
+
.action(async (options, cmd) => {
|
|
100
|
+
if (!cmd.optsWithGlobals().json) printBanner();
|
|
101
|
+
try {
|
|
102
|
+
const { listServers } = await import('./commands/servers.js');
|
|
103
|
+
await listServers(cmd.optsWithGlobals());
|
|
104
|
+
} catch (err) {
|
|
105
|
+
if (!cmd.optsWithGlobals().json) printError('Command failed', err);
|
|
106
|
+
process.exit(1);
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
program
|
|
111
|
+
.command('use <alias>')
|
|
112
|
+
.description('Set a saved profile as the active default')
|
|
113
|
+
.action(async (alias, options, cmd) => {
|
|
114
|
+
if (!cmd.optsWithGlobals().json) printBanner();
|
|
115
|
+
try {
|
|
116
|
+
const { useServer } = await import('./commands/servers.js');
|
|
117
|
+
await useServer(alias, cmd.optsWithGlobals());
|
|
118
|
+
} catch (err) {
|
|
119
|
+
if (!cmd.optsWithGlobals().json) printError('Command failed', err);
|
|
120
|
+
process.exit(1);
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
program.parseAsync(process.argv).catch(err => {
|
|
125
|
+
if (!willPrintJson()) printError('Fatal error', err);
|
|
126
|
+
process.exit(1);
|
|
127
|
+
});
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import chalk from 'chalk';
|
|
2
|
+
import { getTunnelInfo } from '../tunnel/ssh.js';
|
|
3
|
+
import { getPublicIp, getProxiedIp, checkDns, checkIpv6Leak } from '../net/ip.js';
|
|
4
|
+
import { createTable, createSpinner, printError } from '../ui/display.js';
|
|
5
|
+
|
|
6
|
+
export default async (options) => {
|
|
7
|
+
const isJson = options.json;
|
|
8
|
+
const info = getTunnelInfo();
|
|
9
|
+
|
|
10
|
+
if (!isJson) {
|
|
11
|
+
console.log(chalk.cyan.bold('\nRunning Privacy Check...\n'));
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const spinner = isJson ? null : createSpinner('Running tests...').start();
|
|
15
|
+
const results = { ip: null, dns: null, ipv6: null };
|
|
16
|
+
const details = {};
|
|
17
|
+
|
|
18
|
+
try {
|
|
19
|
+
// 1. IP Check
|
|
20
|
+
if (spinner) spinner.text = 'Checking IP address...';
|
|
21
|
+
if (info) {
|
|
22
|
+
try {
|
|
23
|
+
const tunnelIp = await getProxiedIp(info.port);
|
|
24
|
+
results.ip = true;
|
|
25
|
+
details.ip = `Tunnel active: ${tunnelIp}`;
|
|
26
|
+
} catch (e) {
|
|
27
|
+
results.ip = false;
|
|
28
|
+
details.ip = `Tunnel process running but proxy failed: ${e.message}`;
|
|
29
|
+
}
|
|
30
|
+
} else {
|
|
31
|
+
const pubIp = await getPublicIp();
|
|
32
|
+
results.ip = false;
|
|
33
|
+
details.ip = `No tunnel active. Exposed IP: ${pubIp}`;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// 2. DNS Leak Check
|
|
37
|
+
if (spinner) spinner.text = 'Checking DNS...';
|
|
38
|
+
const dnsResult = await checkDns();
|
|
39
|
+
if (!dnsResult.success) {
|
|
40
|
+
results.dns = false;
|
|
41
|
+
details.dns = 'DNS resolution failed';
|
|
42
|
+
} else {
|
|
43
|
+
// In a real full VPN this would check if it's our VPN's DNS.
|
|
44
|
+
// Since this is just a SOCKS5 proxy, system DNS is usually used.
|
|
45
|
+
// We flag it as warning/fail if it's likely an ISP DNS, but for MVP
|
|
46
|
+
// we'll just check if we can resolve and list the servers used.
|
|
47
|
+
const servers = dnsResult.servers.join(', ');
|
|
48
|
+
// SOCKS5 doesn't automatically tunnel DNS for all OS commands,
|
|
49
|
+
// but browsers can be configured to use SOCKS5 for DNS.
|
|
50
|
+
results.dns = true;
|
|
51
|
+
details.dns = `Using system DNS: ${servers}`;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// 3. IPv6 Leak Check
|
|
55
|
+
if (spinner) spinner.text = 'Checking IPv6 leaks...';
|
|
56
|
+
const ipv6 = await checkIpv6Leak();
|
|
57
|
+
if (ipv6) {
|
|
58
|
+
results.ipv6 = false;
|
|
59
|
+
details.ipv6 = `IPv6 address detected: ${ipv6} (potential leak)`;
|
|
60
|
+
} else {
|
|
61
|
+
results.ipv6 = true;
|
|
62
|
+
details.ipv6 = 'No IPv6 address detected';
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (spinner) spinner.stop();
|
|
66
|
+
|
|
67
|
+
if (isJson) {
|
|
68
|
+
console.log(JSON.stringify({ results, details }));
|
|
69
|
+
} else {
|
|
70
|
+
const table = createTable(['Check', 'Status', 'Details']);
|
|
71
|
+
|
|
72
|
+
const formatResult = (pass) => pass ? chalk.green('✓ PASS') : chalk.red('✗ FAIL');
|
|
73
|
+
|
|
74
|
+
table.push(
|
|
75
|
+
['IP Address', formatResult(results.ip), details.ip],
|
|
76
|
+
// If dns is "pass" but we know it's a SOCKS proxy, it's actually a warning that DNS isn't tunneled OS-wide
|
|
77
|
+
['DNS Leak', results.dns ? chalk.yellow('⚠ WARN') : formatResult(results.dns), details.dns],
|
|
78
|
+
['IPv6 Leak', formatResult(results.ipv6), details.ipv6]
|
|
79
|
+
);
|
|
80
|
+
|
|
81
|
+
console.log(table.toString());
|
|
82
|
+
console.log();
|
|
83
|
+
|
|
84
|
+
if (!info) {
|
|
85
|
+
console.log(chalk.yellow('Note: Your traffic is currently exposed. Run "polaris start" to connect.'));
|
|
86
|
+
} else {
|
|
87
|
+
console.log(chalk.cyan('Note: SOCKS5 proxies only tunnel apps configured to use them (like your browser).'));
|
|
88
|
+
console.log(chalk.cyan(' System-wide DNS leaks are expected until v0.5 (WireGuard).'));
|
|
89
|
+
}
|
|
90
|
+
console.log();
|
|
91
|
+
}
|
|
92
|
+
} catch (err) {
|
|
93
|
+
if (spinner) spinner.stop();
|
|
94
|
+
if (isJson) {
|
|
95
|
+
console.log(JSON.stringify({ error: err.message }));
|
|
96
|
+
} else {
|
|
97
|
+
printError('Failed to run privacy checks', err);
|
|
98
|
+
}
|
|
99
|
+
process.exitCode = 1;
|
|
100
|
+
}
|
|
101
|
+
};
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import Conf from 'conf';
|
|
2
|
+
import { printSuccess, printError, printInfo, createTable } from '../ui/display.js';
|
|
3
|
+
import chalk from 'chalk';
|
|
4
|
+
|
|
5
|
+
const config = new Conf({ projectName: 'polaris' });
|
|
6
|
+
|
|
7
|
+
export const addServer = async (alias, options) => {
|
|
8
|
+
const isJson = options.json;
|
|
9
|
+
const server = options.server;
|
|
10
|
+
|
|
11
|
+
if (!server) {
|
|
12
|
+
if (isJson) {
|
|
13
|
+
console.log(JSON.stringify({ error: 'Missing --server argument' }));
|
|
14
|
+
} else {
|
|
15
|
+
printError('You must provide a server with --server <user@host>');
|
|
16
|
+
}
|
|
17
|
+
process.exitCode = 1;
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const profiles = config.get('servers', {});
|
|
22
|
+
profiles[alias] = server;
|
|
23
|
+
config.set('servers', profiles);
|
|
24
|
+
|
|
25
|
+
// Auto-set as active if it's the first one
|
|
26
|
+
if (!config.get('activeServer')) {
|
|
27
|
+
config.set('activeServer', alias);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (isJson) {
|
|
31
|
+
console.log(JSON.stringify({ success: true, alias, server }));
|
|
32
|
+
} else {
|
|
33
|
+
printSuccess(`Saved profile '${alias}' -> ${server}`);
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export const listServers = async (options) => {
|
|
38
|
+
const isJson = options.json;
|
|
39
|
+
const profiles = config.get('servers', {});
|
|
40
|
+
const activeAlias = config.get('activeServer');
|
|
41
|
+
|
|
42
|
+
const aliases = Object.keys(profiles);
|
|
43
|
+
|
|
44
|
+
if (isJson) {
|
|
45
|
+
console.log(JSON.stringify({ servers: profiles, active: activeAlias }));
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (aliases.length === 0) {
|
|
50
|
+
printInfo('No server profiles saved yet. Use "polaris add <alias> --server <user@host>".');
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const table = createTable(['Alias', 'Server', 'Active']);
|
|
55
|
+
|
|
56
|
+
for (const alias of aliases) {
|
|
57
|
+
const isActive = alias === activeAlias;
|
|
58
|
+
table.push([
|
|
59
|
+
isActive ? chalk.green.bold(alias) : alias,
|
|
60
|
+
profiles[alias],
|
|
61
|
+
isActive ? chalk.green('★') : ''
|
|
62
|
+
]);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
console.log('\n' + table.toString() + '\n');
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
export const useServer = async (alias, options) => {
|
|
69
|
+
const isJson = options.json;
|
|
70
|
+
const profiles = config.get('servers', {});
|
|
71
|
+
|
|
72
|
+
if (!profiles[alias]) {
|
|
73
|
+
if (isJson) {
|
|
74
|
+
console.log(JSON.stringify({ error: `Profile '${alias}' not found` }));
|
|
75
|
+
} else {
|
|
76
|
+
printError(`Profile '${alias}' not found. Run "polaris list" to see saved profiles.`);
|
|
77
|
+
}
|
|
78
|
+
process.exitCode = 1;
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
config.set('activeServer', alias);
|
|
83
|
+
|
|
84
|
+
if (isJson) {
|
|
85
|
+
console.log(JSON.stringify({ success: true, active: alias, server: profiles[alias] }));
|
|
86
|
+
} else {
|
|
87
|
+
printSuccess(`Set '${alias}' as the active profile.`);
|
|
88
|
+
}
|
|
89
|
+
};
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import chalk from 'chalk';
|
|
2
|
+
import Conf from 'conf';
|
|
3
|
+
import { printError, printSuccess, printInfo, createSpinner, printWarning } from '../ui/display.js';
|
|
4
|
+
import { getPublicIp, getProxiedIp } from '../net/ip.js';
|
|
5
|
+
import { spawnSSH, waitForSocks, saveTunnelInfo, getTunnelInfo } from '../tunnel/ssh.js';
|
|
6
|
+
|
|
7
|
+
const config = new Conf({ projectName: 'polaris' });
|
|
8
|
+
|
|
9
|
+
export default async (options) => {
|
|
10
|
+
const isJson = options.json;
|
|
11
|
+
let server = options.server;
|
|
12
|
+
const port = parseInt(options.port || '1080', 10);
|
|
13
|
+
|
|
14
|
+
if (!server) {
|
|
15
|
+
// Try to load default from profile if not provided
|
|
16
|
+
const profiles = config.get('servers', {});
|
|
17
|
+
const activeAlias = config.get('activeServer');
|
|
18
|
+
if (activeAlias && profiles[activeAlias]) {
|
|
19
|
+
server = profiles[activeAlias];
|
|
20
|
+
} else {
|
|
21
|
+
if (isJson) {
|
|
22
|
+
console.log(JSON.stringify({ error: 'No server specified' }));
|
|
23
|
+
} else {
|
|
24
|
+
printError('No server specified. Use --server <user@host> or set an active profile with "polaris use".');
|
|
25
|
+
}
|
|
26
|
+
process.exitCode = 1;
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// Check if already running
|
|
32
|
+
const info = getTunnelInfo();
|
|
33
|
+
if (info) {
|
|
34
|
+
if (isJson) {
|
|
35
|
+
console.log(JSON.stringify({ error: 'Tunnel already running', pid: info.pid }));
|
|
36
|
+
} else {
|
|
37
|
+
printError(`Tunnel is already running (PID: ${info.pid}) connected to ${info.server}. Run "polaris stop" first.`);
|
|
38
|
+
}
|
|
39
|
+
process.exitCode = 1;
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
let oldIp;
|
|
44
|
+
const spinner = isJson ? null : createSpinner('Fetching current IP...').start();
|
|
45
|
+
|
|
46
|
+
try {
|
|
47
|
+
oldIp = await getPublicIp();
|
|
48
|
+
if (!isJson) {
|
|
49
|
+
spinner.succeed(`Current IP: ${chalk.cyan(oldIp)}`);
|
|
50
|
+
spinner.text = 'Starting SSH SOCKS5 tunnel...';
|
|
51
|
+
spinner.start();
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const pid = spawnSSH(server, port);
|
|
55
|
+
saveTunnelInfo(pid, server, port);
|
|
56
|
+
|
|
57
|
+
if (!isJson) {
|
|
58
|
+
spinner.text = 'Waiting for proxy to become ready...';
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
await waitForSocks(port);
|
|
62
|
+
|
|
63
|
+
if (!isJson) {
|
|
64
|
+
spinner.text = 'Verifying IP through proxy...';
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const newIp = await getProxiedIp(port);
|
|
68
|
+
|
|
69
|
+
if (!isJson) {
|
|
70
|
+
spinner.stop();
|
|
71
|
+
printSuccess(`Tunnel established successfully to ${server}`);
|
|
72
|
+
console.log(`\n ${chalk.dim('Old IP:')} ${chalk.red(oldIp)}`);
|
|
73
|
+
console.log(` ${chalk.dim('New IP:')} ${chalk.green(newIp)}`);
|
|
74
|
+
console.log(` ${chalk.dim('Proxy :')} ${chalk.cyan(`socks5://127.0.0.1:${port}`)}`);
|
|
75
|
+
|
|
76
|
+
console.log(chalk.dim('\nTunnel is running in the background. Leave this terminal or close it, it will stay alive.'));
|
|
77
|
+
console.log(chalk.dim('Run "polaris status" to check, or "polaris stop" to end.'));
|
|
78
|
+
} else {
|
|
79
|
+
console.log(JSON.stringify({ success: true, oldIp, newIp, proxy: `socks5://127.0.0.1:${port}`, pid }));
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
} catch (err) {
|
|
83
|
+
if (!isJson && spinner) spinner.stop();
|
|
84
|
+
if (isJson) {
|
|
85
|
+
console.log(JSON.stringify({ error: err.message }));
|
|
86
|
+
} else {
|
|
87
|
+
printError('Failed to start tunnel', err);
|
|
88
|
+
}
|
|
89
|
+
process.exitCode = 1;
|
|
90
|
+
}
|
|
91
|
+
};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { getTunnelInfo } from '../tunnel/ssh.js';
|
|
2
|
+
import { getProxiedIp, getPublicIp } from '../net/ip.js';
|
|
3
|
+
import { createTable, createSpinner, printError } from '../ui/display.js';
|
|
4
|
+
import chalk from 'chalk';
|
|
5
|
+
|
|
6
|
+
export default async (options) => {
|
|
7
|
+
const isJson = options.json;
|
|
8
|
+
const info = getTunnelInfo();
|
|
9
|
+
|
|
10
|
+
if (!info) {
|
|
11
|
+
if (isJson) {
|
|
12
|
+
console.log(JSON.stringify({ status: 'down' }));
|
|
13
|
+
} else {
|
|
14
|
+
console.log(chalk.red.bold('\n● Tunnel is DOWN\n'));
|
|
15
|
+
}
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
let currentIp = 'Unknown';
|
|
20
|
+
const spinner = isJson ? null : createSpinner('Checking proxy status...').start();
|
|
21
|
+
|
|
22
|
+
try {
|
|
23
|
+
currentIp = await getProxiedIp(info.port);
|
|
24
|
+
if (spinner) spinner.stop();
|
|
25
|
+
|
|
26
|
+
if (isJson) {
|
|
27
|
+
const uptimeMs = Date.now() - new Date(info.startTime).getTime();
|
|
28
|
+
console.log(JSON.stringify({
|
|
29
|
+
status: 'up',
|
|
30
|
+
server: info.server,
|
|
31
|
+
port: info.port,
|
|
32
|
+
pid: info.pid,
|
|
33
|
+
ip: currentIp,
|
|
34
|
+
uptimeMs
|
|
35
|
+
}));
|
|
36
|
+
} else {
|
|
37
|
+
console.log(chalk.green.bold('\n● Tunnel is UP\n'));
|
|
38
|
+
|
|
39
|
+
const uptimeMin = Math.floor((Date.now() - new Date(info.startTime).getTime()) / 60000);
|
|
40
|
+
const table = createTable(['Property', 'Value']);
|
|
41
|
+
|
|
42
|
+
table.push(
|
|
43
|
+
['Status', chalk.green('Connected')],
|
|
44
|
+
['Server', info.server],
|
|
45
|
+
['Proxy', `socks5://127.0.0.1:${info.port}`],
|
|
46
|
+
['Current IP', chalk.cyan(currentIp)],
|
|
47
|
+
['Uptime', `${uptimeMin} minutes`],
|
|
48
|
+
['PID', info.pid.toString()]
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
console.log(table.toString());
|
|
52
|
+
console.log('');
|
|
53
|
+
}
|
|
54
|
+
} catch (err) {
|
|
55
|
+
if (spinner) spinner.stop();
|
|
56
|
+
if (isJson) {
|
|
57
|
+
console.log(JSON.stringify({ status: 'error', error: err.message }));
|
|
58
|
+
} else {
|
|
59
|
+
printError('Tunnel process is running, but proxy is unresponsive', err);
|
|
60
|
+
}
|
|
61
|
+
process.exitCode = 1;
|
|
62
|
+
}
|
|
63
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { stopTunnel, getTunnelInfo } from '../tunnel/ssh.js';
|
|
2
|
+
import { printSuccess, printInfo, printError } from '../ui/display.js';
|
|
3
|
+
|
|
4
|
+
export default async (options) => {
|
|
5
|
+
const isJson = options.json;
|
|
6
|
+
const info = getTunnelInfo();
|
|
7
|
+
|
|
8
|
+
if (!info) {
|
|
9
|
+
if (isJson) {
|
|
10
|
+
console.log(JSON.stringify({ success: true, message: 'No active tunnel found.' }));
|
|
11
|
+
} else {
|
|
12
|
+
printInfo('No active tunnel found.');
|
|
13
|
+
}
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
try {
|
|
18
|
+
stopTunnel();
|
|
19
|
+
if (isJson) {
|
|
20
|
+
console.log(JSON.stringify({ success: true, message: 'Tunnel stopped successfully.' }));
|
|
21
|
+
} else {
|
|
22
|
+
printSuccess('Tunnel stopped successfully.');
|
|
23
|
+
}
|
|
24
|
+
} catch (err) {
|
|
25
|
+
if (isJson) {
|
|
26
|
+
console.log(JSON.stringify({ error: err.message }));
|
|
27
|
+
} else {
|
|
28
|
+
printError('Error stopping tunnel', err);
|
|
29
|
+
}
|
|
30
|
+
process.exitCode = 1;
|
|
31
|
+
}
|
|
32
|
+
};
|
package/src/net/ip.js
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import fetch from 'node-fetch';
|
|
2
|
+
import { SocksProxyAgent } from 'socks-proxy-agent';
|
|
3
|
+
import dns from 'dns';
|
|
4
|
+
import { promisify } from 'util';
|
|
5
|
+
|
|
6
|
+
const resolve4 = promisify(dns.resolve4);
|
|
7
|
+
|
|
8
|
+
export const getPublicIp = async () => {
|
|
9
|
+
const res = await fetch('https://api64.ipify.org?format=json');
|
|
10
|
+
if (!res.ok) throw new Error(`HTTP ${res.status} from ipify.org`);
|
|
11
|
+
const data = await res.json();
|
|
12
|
+
return data.ip;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export const getProxiedIp = async (port) => {
|
|
16
|
+
const agent = new SocksProxyAgent(`socks5h://127.0.0.1:${port}`);
|
|
17
|
+
const res = await fetch('https://api64.ipify.org?format=json', { agent });
|
|
18
|
+
if (!res.ok) throw new Error(`HTTP ${res.status} from ipify.org via proxy`);
|
|
19
|
+
const data = await res.json();
|
|
20
|
+
return data.ip;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
// Simple DNS leak check by resolving via system dns
|
|
24
|
+
export const checkDns = async () => {
|
|
25
|
+
try {
|
|
26
|
+
const servers = dns.getServers();
|
|
27
|
+
const resolved = await resolve4('example.com');
|
|
28
|
+
return { success: resolved.length > 0, servers };
|
|
29
|
+
} catch (err) {
|
|
30
|
+
return { success: false, servers: dns.getServers(), error: err.message };
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
// Returns IPv6 address if leaked, null otherwise
|
|
35
|
+
export const checkIpv6Leak = async () => {
|
|
36
|
+
try {
|
|
37
|
+
const controller = new AbortController();
|
|
38
|
+
const timeout = setTimeout(() => controller.abort(), 3000);
|
|
39
|
+
const res = await fetch('https://ipv6.icanhazip.com', { signal: controller.signal });
|
|
40
|
+
clearTimeout(timeout);
|
|
41
|
+
|
|
42
|
+
if (res.ok) {
|
|
43
|
+
const text = await res.text();
|
|
44
|
+
return text.trim() || null;
|
|
45
|
+
}
|
|
46
|
+
return null;
|
|
47
|
+
} catch (err) {
|
|
48
|
+
return null; // Timeout or network error typically means IPv6 is disabled/unreachable
|
|
49
|
+
}
|
|
50
|
+
};
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { spawn } from 'child_process';
|
|
2
|
+
import net from 'net';
|
|
3
|
+
import fs from 'fs';
|
|
4
|
+
import path from 'path';
|
|
5
|
+
import os from 'os';
|
|
6
|
+
|
|
7
|
+
const CONFIG_DIR = path.join(os.homedir(), '.config', 'polaris');
|
|
8
|
+
const PID_FILE = path.join(CONFIG_DIR, 'tunnel.pid');
|
|
9
|
+
const CONFIG_FILE = path.join(CONFIG_DIR, 'config.json');
|
|
10
|
+
|
|
11
|
+
const ensureDir = () => {
|
|
12
|
+
if (!fs.existsSync(CONFIG_DIR)) {
|
|
13
|
+
fs.mkdirSync(CONFIG_DIR, { recursive: true });
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export const spawnSSH = (server, port) => {
|
|
18
|
+
// We want to run SSH as a detached child process so it survives terminal close.
|
|
19
|
+
// -D port: Dynamic SOCKS5 forwarding
|
|
20
|
+
// -N: Do not execute a remote command
|
|
21
|
+
// -o StrictHostKeyChecking=no: Don't prompt for host key verification
|
|
22
|
+
// -o ServerAliveInterval=30: Keep connection alive
|
|
23
|
+
// -o ExitOnForwardFailure=yes: Exit if port forwarding fails
|
|
24
|
+
|
|
25
|
+
const args = [
|
|
26
|
+
'-D', String(port),
|
|
27
|
+
'-N',
|
|
28
|
+
'-o', 'StrictHostKeyChecking=no',
|
|
29
|
+
'-o', 'ServerAliveInterval=30',
|
|
30
|
+
'-o', 'ExitOnForwardFailure=yes',
|
|
31
|
+
server
|
|
32
|
+
];
|
|
33
|
+
|
|
34
|
+
const child = spawn('ssh', args, {
|
|
35
|
+
detached: true,
|
|
36
|
+
stdio: 'ignore' // We don't want to capture stdio, keep it completely detached
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
child.unref(); // Allow the parent process to exit independently
|
|
40
|
+
|
|
41
|
+
return child.pid;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
// Poll the local port until it accepts connections
|
|
45
|
+
export const waitForSocks = async (port, timeoutMs = 30000) => {
|
|
46
|
+
const start = Date.now();
|
|
47
|
+
|
|
48
|
+
while (Date.now() - start < timeoutMs) {
|
|
49
|
+
try {
|
|
50
|
+
await new Promise((resolve, reject) => {
|
|
51
|
+
const socket = new net.Socket();
|
|
52
|
+
|
|
53
|
+
socket.setTimeout(1000);
|
|
54
|
+
|
|
55
|
+
socket.on('connect', () => {
|
|
56
|
+
socket.destroy();
|
|
57
|
+
resolve(true);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
socket.on('timeout', () => {
|
|
61
|
+
socket.destroy();
|
|
62
|
+
reject(new Error('timeout'));
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
socket.on('error', (err) => {
|
|
66
|
+
socket.destroy();
|
|
67
|
+
reject(err);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
socket.connect(port, '127.0.0.1');
|
|
71
|
+
});
|
|
72
|
+
return true; // Connection successful
|
|
73
|
+
} catch (err) {
|
|
74
|
+
// Wait 500ms before retrying
|
|
75
|
+
await new Promise(r => setTimeout(r, 500));
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
throw new Error(`Timed out waiting for SOCKS5 proxy on port ${port} to become ready`);
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
export const saveTunnelInfo = (pid, server, port) => {
|
|
83
|
+
ensureDir();
|
|
84
|
+
fs.writeFileSync(PID_FILE, String(pid), 'utf-8');
|
|
85
|
+
|
|
86
|
+
const config = {
|
|
87
|
+
server,
|
|
88
|
+
port,
|
|
89
|
+
startTime: new Date().toISOString()
|
|
90
|
+
};
|
|
91
|
+
fs.writeFileSync(CONFIG_FILE, JSON.stringify(config, null, 2), 'utf-8');
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
export const getTunnelInfo = () => {
|
|
95
|
+
if (!fs.existsSync(PID_FILE) || !fs.existsSync(CONFIG_FILE)) {
|
|
96
|
+
return null;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
try {
|
|
100
|
+
const pid = parseInt(fs.readFileSync(PID_FILE, 'utf-8').trim(), 10);
|
|
101
|
+
const config = JSON.parse(fs.readFileSync(CONFIG_FILE, 'utf-8'));
|
|
102
|
+
|
|
103
|
+
// Check if process actually exists
|
|
104
|
+
try {
|
|
105
|
+
process.kill(pid, 0); // test signal 0 to check if alive
|
|
106
|
+
} catch (e) {
|
|
107
|
+
if (e.code === 'ESRCH') {
|
|
108
|
+
// Process doesn't exist, tunnel is dead, cleanup
|
|
109
|
+
clearTunnelInfo();
|
|
110
|
+
return null;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
return { pid, ...config };
|
|
115
|
+
} catch (err) {
|
|
116
|
+
return null;
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
export const stopTunnel = () => {
|
|
121
|
+
const info = getTunnelInfo();
|
|
122
|
+
if (info) {
|
|
123
|
+
try {
|
|
124
|
+
process.kill(info.pid, 'SIGTERM');
|
|
125
|
+
} catch (e) {
|
|
126
|
+
// Ignore errors if process already dead
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
clearTunnelInfo();
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
export const clearTunnelInfo = () => {
|
|
133
|
+
if (fs.existsSync(PID_FILE)) fs.unlinkSync(PID_FILE);
|
|
134
|
+
};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import chalk from 'chalk';
|
|
2
|
+
import ora from 'ora';
|
|
3
|
+
import Table from 'cli-table3';
|
|
4
|
+
|
|
5
|
+
export const printBanner = () => {
|
|
6
|
+
console.log(chalk.cyan.bold('\npolaris — Leave no trace.'));
|
|
7
|
+
console.log(chalk.dim('Your True North in Digital Privacy.\n'));
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export const createSpinner = (text) => {
|
|
11
|
+
return ora({ text, color: 'cyan' });
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export const printError = (msg, err = null) => {
|
|
15
|
+
console.error(chalk.red.bold(`\n✗ Error: ${msg}`));
|
|
16
|
+
if (err && err.message) {
|
|
17
|
+
console.error(chalk.dim(err.message));
|
|
18
|
+
} else if (err) {
|
|
19
|
+
console.error(chalk.dim(String(err)));
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export const printSuccess = (msg) => {
|
|
24
|
+
console.log(chalk.green(`✓ ${msg}`));
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export const printInfo = (msg) => {
|
|
28
|
+
console.log(chalk.cyan(`ℹ ${msg}`));
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export const printWarning = (msg) => {
|
|
32
|
+
console.log(chalk.yellow(`⚠ ${msg}`));
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export const createTable = (head = []) => {
|
|
36
|
+
return new Table({
|
|
37
|
+
head: head.map(h => chalk.cyan(h)),
|
|
38
|
+
style: { head: [], border: [] }
|
|
39
|
+
});
|
|
40
|
+
};
|