Skip to content

Commit f8233fb

Browse files
committed
Ran the format command because code needs to look better
1 parent dab3a5d commit f8233fb

20 files changed

Lines changed: 541 additions & 306 deletions

File tree

server-src/pinggy.js

Lines changed: 64 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,79 +1,90 @@
1-
const { spawn } = require('node:child_process');
1+
const { spawn } = require("node:child_process");
22

33
// Configuration
44
let serverPort = process.env.PORT || process.env.serverPort || 3000;
55
const filterLinks = ["https://dashboard.pinggy.io", "https://pinggy.io"];
66
const maxPinggy = 25; // Total concurrent tunnels
77

88
const commandArgs = [
9-
['ssh', [
10-
'-p', '443',
11-
'-o', 'StrictHostKeyChecking=no',
12-
'-o', 'ServerAliveInterval=30',
13-
'-R', `0:localhost:${serverPort}`,
14-
'-L', '4300:127.0.0.1:4300',
15-
'qr@free.pinggy.io'
16-
]]
9+
[
10+
"ssh",
11+
[
12+
"-p",
13+
"443",
14+
"-o",
15+
"StrictHostKeyChecking=no",
16+
"-o",
17+
"ServerAliveInterval=30",
18+
"-R",
19+
`0:localhost:${serverPort}`,
20+
"-L",
21+
"4300:127.0.0.1:4300",
22+
"qr@free.pinggy.io",
23+
],
24+
],
1725
];
1826

19-
var activeTunnels = new Map();
27+
var activeTunnels = new Map();
2028
var curPinggy = 0;
2129

2230
function spawnTunnel(index) {
23-
if (curPinggy >= maxPinggy) return;
24-
25-
curPinggy += 1;
26-
const [cmdName, args] = commandArgs[index];
27-
const child = spawn(cmdName, args);
28-
const pid = child.pid;
31+
if (curPinggy >= maxPinggy) return;
2932

30-
child.stdout.on('data', (data) => {
31-
const output = data.toString();
32-
33-
// Improved URL regex to catch URLs even if they are surrounded by ANSI codes
34-
const urlRegex = /https:\/\/[^\s"'<>]+/g;
35-
const foundLinks = output.match(urlRegex);
33+
curPinggy += 1;
34+
const [cmdName, args] = commandArgs[index];
35+
const child = spawn(cmdName, args);
36+
const pid = child.pid;
3637

37-
if (foundLinks) {
38-
foundLinks.forEach(link => {
39-
const s = link.trim().replace(/\x1B\[[0-9;]*[mK]/g, ""); // Clean ANSI colors
40-
41-
if (!filterLinks.some(f => s.startsWith(f)) && !activeTunnels.has(pid)) {
42-
activeTunnels.set(pid, {
43-
url: s,
44-
ts: Date.now()
45-
});
46-
}
47-
});
48-
}
49-
});
38+
child.stdout.on("data", (data) => {
39+
const output = data.toString();
40+
41+
// Improved URL regex to catch URLs even if they are surrounded by ANSI codes
42+
const urlRegex = /https:\/\/[^\s"'<>]+/g;
43+
const foundLinks = output.match(urlRegex);
44+
45+
if (foundLinks) {
46+
foundLinks.forEach((link) => {
47+
const s = link.trim().replace(/\x1B\[[0-9;]*[mK]/g, ""); // Clean ANSI colors
5048

51-
// Capture errors to help with debugging
52-
child.stderr.on('data', (data) => {
53-
if (data.toString().includes("Permission denied")) {
54-
console.error(`[Error] PID ${pid} check your SSH keys.`);
49+
if (
50+
!filterLinks.some((f) => s.startsWith(f)) &&
51+
!activeTunnels.has(pid)
52+
) {
53+
activeTunnels.set(pid, {
54+
url: s,
55+
ts: Date.now(),
56+
});
5557
}
56-
});
58+
});
59+
}
60+
});
61+
62+
// Capture errors to help with debugging
63+
child.stderr.on("data", (data) => {
64+
if (data.toString().includes("Permission denied")) {
65+
console.error(`[Error] PID ${pid} check your SSH keys.`);
66+
}
67+
});
68+
69+
child.on("close", (code) => {
70+
curPinggy -= 1;
71+
activeTunnels.delete(pid);
5772

58-
child.on('close', (code) => {
59-
curPinggy -= 1;
60-
activeTunnels.delete(pid);
61-
62-
// Staggered restart to avoid spamming the CPU
63-
setTimeout(() => {
64-
spawnTunnel(index);
65-
}, 5000);
66-
});
73+
// Staggered restart to avoid spamming the CPU
74+
setTimeout(() => {
75+
spawnTunnel(index);
76+
}, 5000);
77+
});
6778
}
6879

6980
// Initial Boot
7081
for (let i = 0; i < maxPinggy; i++) {
71-
// Distribute processes evenly across providers
72-
spawnTunnel(i % commandArgs.length);
82+
// Distribute processes evenly across providers
83+
spawnTunnel(i % commandArgs.length);
7384
}
7485

7586
function getActiveAltLinks() {
76-
return Array.from(activeTunnels.values());
87+
return Array.from(activeTunnels.values());
7788
}
7889

79-
module.exports = { getActiveAltLinks };
90+
module.exports = { getActiveAltLinks };

server-src/server.js

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,11 @@ function isPrivateIp(ip) {
8888
if (!ip) return false;
8989

9090
// Clean up Node's IPv6-mapped IPv4 prefix (::ffff:)
91-
const cleanIp = ip.replace(/^::ffff:/, '').trim();
91+
const cleanIp = ip.replace(/^::ffff:/, "").trim();
9292

93-
if (cleanIp === '::1' || cleanIp === 'localhost') return true;
93+
if (cleanIp === "::1" || cleanIp === "localhost") return true;
9494

95-
const parts = cleanIp.split('.');
95+
const parts = cleanIp.split(".");
9696
if (parts.length !== 4) return false;
9797

9898
const first = parseInt(parts[0], 10);
@@ -109,24 +109,24 @@ function isPrivateIp(ip) {
109109
function getIPFromRequest(req) {
110110
// 1. Priority: The 'cf-connecting-ip' is provided by Render's edge.
111111
// This is the "gold standard" and is very hard to spoof.
112-
const cfIp = req.headers['cf-connecting-ip'];
112+
const cfIp = req.headers["cf-connecting-ip"];
113113
if (cfIp) return cfIp.trim();
114114

115115
// 2. Fallback: Parse the X-Forwarded-For list.
116-
const xff = req.headers['x-forwarded-for'];
116+
const xff = req.headers["x-forwarded-for"];
117117
if (xff) {
118118
// We split the list into an array of IPs.
119-
const IPs = xff.split(',').map(ip => ip.trim());
119+
const IPs = xff.split(",").map((ip) => ip.trim());
120120

121121
// On Render, the user's real IP is ALWAYS the first one (index 0).
122122
// The others are Render/Azure/Cloudflare proxies.
123123
if (IPs.length > 0) {
124-
return IPs[0];
124+
return IPs[0];
125125
}
126126
}
127127

128128
// 3. Final Fallback: The direct connection IP (usually a proxy IP on Render)
129-
return (req.socket.remoteAddress || "").replace(/^::ffff:/, '').trim();
129+
return (req.socket.remoteAddress || "").replace(/^::ffff:/, "").trim();
130130
}
131131

132132
var ipBanReasons = {
@@ -2919,15 +2919,15 @@ const server = http.createServer(async function (req, res) {
29192919
}
29202920
}
29212921

2922-
if (urlsplit[1] == "tunnels.json") {
2923-
res.setHeader("content-type", "application/json");
2924-
res.end(JSON.stringify(pinggy.getActiveAltLinks(), null, " "));
2925-
return;
2926-
}
2927-
if (urlsplit[1] == "sendtmp") {
2928-
res.end("Y");
2929-
return;
2930-
}
2922+
if (urlsplit[1] == "tunnels.json") {
2923+
res.setHeader("content-type", "application/json");
2924+
res.end(JSON.stringify(pinggy.getActiveAltLinks(), null, " "));
2925+
return;
2926+
}
2927+
if (urlsplit[1] == "sendtmp") {
2928+
res.end("Y");
2929+
return;
2930+
}
29312931

29322932
if (urlsplit[1] == "webpush" && WEBPUSH_ENABLED) {
29332933
if (urlsplit[2] == "key" && req.method == "GET") {
Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,37 @@
11
module.exports = [
22
'Waiting for the signal to "Open Chromebooks"...',
3-
'Converting late-night logic to server uptime...',
3+
"Converting late-night logic to server uptime...",
44
'Automating the "busy work" module...',
5-
'Pretending to understand the documentation...',
6-
'Calculating the optimal code-to-coffee ratio...',
7-
'Loading the procrastination bypass protocol...',
8-
'Consulting with Gemini for a quick debug...',
5+
"Pretending to understand the documentation...",
6+
"Calculating the optimal code-to-coffee ratio...",
7+
"Loading the procrastination bypass protocol...",
8+
"Consulting with Gemini for a quick debug...",
99
'Optimizing the "looks like I\'m working" terminal...',
10-
'Refreshing the socket connection...',
11-
'Buffering: Retrying failed packet delivery...',
12-
'Syncing local repo with production...',
13-
'Converting sleep deprivation into clean code...',
14-
'Installing focus module... (Warning: Low battery)',
15-
'Searching for that missing semicolon...',
10+
"Refreshing the socket connection...",
11+
"Buffering: Retrying failed packet delivery...",
12+
"Syncing local repo with production...",
13+
"Converting sleep deprivation into clean code...",
14+
"Installing focus module... (Warning: Low battery)",
15+
"Searching for that missing semicolon...",
1616
'Loading the "deploy now, sleep later" mentality...',
17-
'Compiling technical debt into features...',
18-
'Rendering the next major update...',
19-
'Optimizing low-latency algorithms...',
20-
'Loading patch #47...',
17+
"Compiling technical debt into features...",
18+
"Rendering the next major update...",
19+
"Optimizing low-latency algorithms...",
20+
"Loading patch #47...",
2121
'Buffering: "It worked on my local machine"...',
22-
'Parsing complex error logs...',
22+
"Parsing complex error logs...",
2323
'Initializing the "v0.0.1" protocol...',
24-
'Waiting for the terminal to respond...',
25-
'Converting study hall into dev time...',
26-
'Negotiating with the API gods...',
27-
'Redirecting CPU resources to the chat engine...',
28-
'Booting up the backup server...',
29-
'Compressing high-resolution assets...',
24+
"Waiting for the terminal to respond...",
25+
"Converting study hall into dev time...",
26+
"Negotiating with the API gods...",
27+
"Redirecting CPU resources to the chat engine...",
28+
"Booting up the backup server...",
29+
"Compressing high-resolution assets...",
3030
'Syncing with that "midnight deadline" energy...',
31-
'Loading the experimental feature set...',
32-
'Rendering the 11:59 PM commit...',
31+
"Loading the experimental feature set...",
32+
"Rendering the 11:59 PM commit...",
3333
'Buffering: "The cache ate my update"...',
34-
'Initializing Chromebook optimization mode...',
35-
'Converting lunch period into a sprint session...',
34+
"Initializing Chromebook optimization mode...",
35+
"Converting lunch period into a sprint session...",
3636
'Loading the "ship it anyway" strategy...',
3737
];

src/menu.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,14 @@ var elementJSON = [
7474
textContent: "Updates",
7575
href: "./updates",
7676
},
77-
//Alternative links button.
77+
//Alternative links button.
7878
{
7979
element: "a",
8080
className: "menuBarItem",
8181
textContent: "Alt links",
8282
href: "./alts",
8383
},
84-
//Uptime button.
84+
//Uptime button.
8585
{
8686
element: "a",
8787
className: "menuBarItem",

src/pages/about.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ var randomRantsAbout = [
3636
},
3737
{
3838
element: "p",
39-
textContent: "Whenever you've got something on your mind, just share it here with the crew!",
39+
textContent:
40+
"Whenever you've got something on your mind, just share it here with the crew!",
4041
style: { fontSize: "1.1em", lineHeight: "0px", marginBottom: "1em" },
4142
},
4243

@@ -76,7 +77,8 @@ var randomRantsAbout = [
7677
{ element: "br" },
7778
{
7879
element: "li",
79-
textContent: "People who enjoy high-energy, spontaneous digital spaces.",
80+
textContent:
81+
"People who enjoy high-energy, spontaneous digital spaces.",
8082
},
8183
],
8284
},
@@ -173,7 +175,7 @@ var randomRantsAbout = [
173175
},
174176
{
175177
element: "p",
176-
textContent: "Customize your identity so people know it's you:",
178+
textContent: "Customize your identity so people know it's you:",
177179
style: { fontSize: "1em", marginBottom: "0.5em" },
178180
children: [],
179181
},
@@ -265,7 +267,8 @@ var randomRantsAbout = [
265267
children: [
266268
{
267269
element: "h2",
268-
textContent: "User-moderated rooms, users get to run rooms however they want.",
270+
textContent:
271+
"User-moderated rooms, users get to run rooms however they want.",
269272
style: { fontSize: "1.5em", marginTop: "1.2em" },
270273
children: [],
271274
},

0 commit comments

Comments
 (0)