Skip to content

Commit 8ac7d0f

Browse files
committed
docs: mirror upstream Code.gs locally (assets/apps_script/)
Two reasons to pin a copy in the repo: 1. Users on networks where raw.githubusercontent.com is intermittent can still get the deploy-ready file via a repo ZIP / clone. 2. The Apps Script relay protocol between mhrv-rs and Code.gs is informal — upstream changes can silently break us. Keeping a snapshot lets future-us diff against what we tested against when diagnosing protocol-drift bugs. Fetched verbatim from: https://raw.githubusercontent.com/masterking32/MasterHttpRelayVPN/refs/heads/python_testing/apps_script/Code.gs Credit stays with @masterking32. The assets/apps_script/README.md next to it calls out that we don't modify this file — users deploy it as-is into their own Google Apps Script project. Updated the Setup Guide link in both the English and Persian sections so offline / restricted-network users have a fallback path.
1 parent fdd0f81 commit 8ac7d0f

3 files changed

Lines changed: 156 additions & 2 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ This part is unchanged from the original project. Follow @masterking32's guide o
8888

8989
1. Open <https://script.google.com> while signed into your Google account.
9090
2. **New project**, delete the default code.
91-
3. Copy the contents of [`Code.gs` from the original repo](https://github.com/masterking32/MasterHttpRelayVPN/blob/python_testing/Code.gs) ([raw](https://raw.githubusercontent.com/masterking32/MasterHttpRelayVPN/refs/heads/python_testing/Code.gs)) into the editor.
91+
3. Copy the contents of [`Code.gs` from the original repo](https://github.com/masterking32/MasterHttpRelayVPN/blob/python_testing/apps_script/Code.gs) ([raw](https://raw.githubusercontent.com/masterking32/MasterHttpRelayVPN/refs/heads/python_testing/apps_script/Code.gs)) into the editor. If that URL is unreachable from your network, there's a mirrored copy in this repo at [`assets/apps_script/Code.gs`](assets/apps_script/Code.gs) — same file, pulled from upstream.
9292
4. Change `const AUTH_KEY = "..."` to a strong secret only you know.
9393
5. **Deploy → New deployment → Web app**.
9494
- Execute as: **Me**
@@ -385,7 +385,7 @@ Original project: <https://github.com/masterking32/MasterHttpRelayVPN> by [@mast
385385

386386
۱. به <https://script.google.com> بروید و با حساب گوگل خودتان وارد شوید
387387
۲. روی **`New project`** کلیک کنید و کد پیش‌فرض را پاک کنید
388-
۳. محتوای فایل [`Code.gs`](https://github.com/masterking32/MasterHttpRelayVPN/blob/python_testing/Code.gs) را از ریپوی اصلی کپی کنید و داخل ویرایشگر بچسبانید
388+
۳. محتوای فایل [`Code.gs`](https://github.com/masterking32/MasterHttpRelayVPN/blob/python_testing/apps_script/Code.gs) را از ریپوی اصلی کپی کنید و داخل ویرایشگر بچسبانید. اگر به آدرس بالا دسترسی ندارید، یک کپی از همین فایل داخل این ریپو هم هست: [`assets/apps_script/Code.gs`](assets/apps_script/Code.gs)
389389
۴. بالای کد، خط `const AUTH_KEY = "..."` را پیدا کنید و مقدار آن را به یک رمز قوی و خاص خودتان تغییر دهید (یک رشتهٔ تصادفی حداقل ۱۶ کاراکتری کافی است، مثلاً `aK8f3xM9pQ2nL5vR`)
390390
۵. روی دکمهٔ آبی **`Deploy`** در بالا سمت راست کلیک کنید و **`New deployment`** را بزنید
391391
۶. **`Type`** را روی **`Web app`** بگذارید و این تنظیمات را اعمال کنید:

assets/apps_script/Code.gs

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
/**
2+
* DomainFront Relay — Google Apps Script
3+
*
4+
* TWO modes:
5+
* 1. Single: POST { k, m, u, h, b, ct, r } → { s, h, b }
6+
* 2. Batch: POST { k, q: [{m,u,h,b,ct,r}, ...] } → { q: [{s,h,b}, ...] }
7+
* Uses UrlFetchApp.fetchAll() — all URLs fetched IN PARALLEL.
8+
*
9+
* DEPLOYMENT:
10+
* 1. Go to https://script.google.com → New project
11+
* 2. Delete the default code, paste THIS entire file
12+
* 3. Click Deploy → New deployment
13+
* 4. Type: Web app | Execute as: Me | Who has access: Anyone
14+
* 5. Copy the Deployment ID into config.json as "script_id"
15+
*
16+
* CHANGE THE AUTH KEY BELOW TO YOUR OWN SECRET!
17+
*/
18+
19+
const AUTH_KEY = "CHANGE_ME_TO_A_STRONG_SECRET";
20+
21+
// Keep browser capability headers (sec-ch-ua*, sec-fetch-*) intact.
22+
// Some modern apps, notably Google Meet, use them for browser gating.
23+
const SKIP_HEADERS = {
24+
host: 1, connection: 1, "content-length": 1,
25+
"transfer-encoding": 1, "proxy-connection": 1, "proxy-authorization": 1,
26+
"priority": 1, te: 1,
27+
};
28+
29+
function doPost(e) {
30+
try {
31+
var req = JSON.parse(e.postData.contents);
32+
if (req.k !== AUTH_KEY) return _json({ e: "unauthorized" });
33+
34+
// Batch mode: { k, q: [...] }
35+
if (Array.isArray(req.q)) return _doBatch(req.q);
36+
37+
// Single mode
38+
return _doSingle(req);
39+
} catch (err) {
40+
return _json({ e: String(err) });
41+
}
42+
}
43+
44+
function _doSingle(req) {
45+
if (!req.u || typeof req.u !== "string" || !req.u.match(/^https?:\/\//i)) {
46+
return _json({ e: "bad url" });
47+
}
48+
var opts = _buildOpts(req);
49+
var resp = UrlFetchApp.fetch(req.u, opts);
50+
return _json({
51+
s: resp.getResponseCode(),
52+
h: _respHeaders(resp),
53+
b: Utilities.base64Encode(resp.getContent()),
54+
});
55+
}
56+
57+
function _doBatch(items) {
58+
var fetchArgs = [];
59+
var errorMap = {};
60+
61+
for (var i = 0; i < items.length; i++) {
62+
var item = items[i];
63+
if (!item.u || typeof item.u !== "string" || !item.u.match(/^https?:\/\//i)) {
64+
errorMap[i] = "bad url";
65+
continue;
66+
}
67+
var opts = _buildOpts(item);
68+
opts.url = item.u;
69+
fetchArgs.push({ _i: i, _o: opts });
70+
}
71+
72+
// fetchAll() processes all requests in parallel inside Google
73+
var responses = [];
74+
if (fetchArgs.length > 0) {
75+
responses = UrlFetchApp.fetchAll(fetchArgs.map(function(x) { return x._o; }));
76+
}
77+
78+
var results = [];
79+
var rIdx = 0;
80+
for (var i = 0; i < items.length; i++) {
81+
if (errorMap.hasOwnProperty(i)) {
82+
results.push({ e: errorMap[i] });
83+
} else {
84+
var resp = responses[rIdx++];
85+
results.push({
86+
s: resp.getResponseCode(),
87+
h: _respHeaders(resp),
88+
b: Utilities.base64Encode(resp.getContent()),
89+
});
90+
}
91+
}
92+
return _json({ q: results });
93+
}
94+
95+
function _buildOpts(req) {
96+
var opts = {
97+
method: (req.m || "GET").toLowerCase(),
98+
muteHttpExceptions: true,
99+
followRedirects: req.r !== false,
100+
validateHttpsCertificates: true,
101+
escaping: false,
102+
};
103+
if (req.h && typeof req.h === "object") {
104+
var headers = {};
105+
for (var k in req.h) {
106+
if (req.h.hasOwnProperty(k) && !SKIP_HEADERS[k.toLowerCase()]) {
107+
headers[k] = req.h[k];
108+
}
109+
}
110+
opts.headers = headers;
111+
}
112+
if (req.b) {
113+
opts.payload = Utilities.base64Decode(req.b);
114+
if (req.ct) opts.contentType = req.ct;
115+
}
116+
return opts;
117+
}
118+
119+
function _respHeaders(resp) {
120+
try {
121+
if (typeof resp.getAllHeaders === "function") {
122+
return resp.getAllHeaders();
123+
}
124+
} catch (err) {}
125+
return resp.getHeaders();
126+
}
127+
128+
function doGet(e) {
129+
return HtmlService.createHtmlOutput(
130+
"<!DOCTYPE html><html><head><title>My App</title></head>" +
131+
'<body style="font-family:sans-serif;max-width:600px;margin:40px auto">' +
132+
"<h1>Welcome</h1><p>This application is running normally.</p>" +
133+
"</body></html>"
134+
);
135+
}
136+
137+
function _json(obj) {
138+
return ContentService.createTextOutput(JSON.stringify(obj)).setMimeType(
139+
ContentService.MimeType.JSON
140+
);
141+
}

assets/apps_script/README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Apps Script source (mirrored)
2+
3+
The file `Code.gs` next to this README is a verbatim snapshot of the upstream script you deploy in your own Google Apps Script project:
4+
5+
- Upstream: <https://github.com/masterking32/MasterHttpRelayVPN/blob/python_testing/apps_script/Code.gs>
6+
- Raw link: <https://raw.githubusercontent.com/masterking32/MasterHttpRelayVPN/refs/heads/python_testing/apps_script/Code.gs>
7+
8+
This copy lives in our repo for two reasons:
9+
10+
1. **Survives upstream outages**: if the user is on a network where raw.githubusercontent.com is temporarily unreachable but they can clone or ZIP this repo, they still have the deploy-ready file.
11+
2. **Pins what we tested against**: the relay protocol between `mhrv-rs` and the script is informal; upstream changes can silently break us. Keeping a snapshot here lets us diff and see if a spec drift is responsible for any reported breakage.
12+
13+
All credit for `Code.gs` goes to [@masterking32](https://github.com/masterking32) — we do not modify it. If you're using mhrv-rs, follow the upstream deploy instructions in the script's header comment. The only edit **you** must make is the `AUTH_KEY` constant — set it to a strong secret and reuse that exact string in your `mhrv-rs` config.

0 commit comments

Comments
 (0)