dsh-pocket 1.8.0 → 1.8.1

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 (2) hide show
  1. package/lib/proxy.mjs +9 -5
  2. package/package.json +1 -1
package/lib/proxy.mjs CHANGED
@@ -76,7 +76,10 @@ function parseCookies(header) {
76
76
  return out;
77
77
  }
78
78
 
79
- function loginPageHtml(error) {
79
+ /** 登录页:按访问来源显示提示(局域网 / 公网)。 */
80
+ function loginPageHtml(error, isPublic) {
81
+ const where = isPublic ? '此公网地址' : '此局域网地址';
82
+ const whereEn = isPublic ? 'This public address' : 'This LAN address';
80
83
  return `<!doctype html><html lang="zh"><head><meta charset="utf-8">
81
84
  <meta name="viewport" content="width=device-width,initial-scale=1">
82
85
  <title>DSH Pocket · 访问验证</title>
@@ -91,7 +94,7 @@ button{width:100%;padding:10px;font-size:15px;background:#4f6ef7;color:#fff;bord
91
94
  .err{color:#dc2626;font-size:12px;margin-bottom:10px;min-height:16px}
92
95
  </style></head><body><div class="card">
93
96
  <h1>🔐 DSH Pocket</h1>
94
- <p>此公网地址受访问密码保护,请输入 8 位数字密码</p>
97
+ <p>${where}受访问密码保护,请输入 8 位数字密码 | ${whereEn} is password-protected — enter the 8-digit PIN</p>
95
98
  <div class="err">${error ? '密码错误,请重试' : ''}</div>
96
99
  <form method="post" action="/pocket-login">
97
100
  <input name="token" type="password" inputmode="numeric" maxlength="8" autocomplete="one-time-code" autofocus required>
@@ -141,9 +144,10 @@ function loopbackAuthority(headers, upstream) {
141
144
  */
142
145
  export function createPocketProxy({ port = 3081, host = '0.0.0.0', upstream = DEFAULT_UPSTREAM, log = null, injectHtml = DEFAULT_INJECT, auth = null } = {}) {
143
146
  const server = createServer((req, res) => {
144
- // 访问令牌认证(issue #13):仅公网隧道 Host 强制;局域网 IP 直连免密码
147
+ // 访问令牌认证(issue #13 + #18):局域网与公网都要求密码
145
148
  if (auth) {
146
149
  const host = String(req.headers.host ?? '');
150
+ const isPublic = /trycloudflare\.com$/i.test(host);
147
151
  const protectedHost = isProtectedHost(host, auth.isProtected);
148
152
  const token = protectedHost ? (auth.getToken?.(host) ?? null) : null;
149
153
  if (protectedHost && token) {
@@ -162,7 +166,7 @@ export function createPocketProxy({ port = 3081, host = '0.0.0.0', upstream = DE
162
166
  res.end();
163
167
  } else {
164
168
  res.writeHead(200, { 'content-type': 'text/html; charset=utf-8', 'cache-control': 'no-store' });
165
- res.end(loginPageHtml(true));
169
+ res.end(loginPageHtml(true, isPublic));
166
170
  }
167
171
  });
168
172
  return;
@@ -170,7 +174,7 @@ export function createPocketProxy({ port = 3081, host = '0.0.0.0', upstream = DE
170
174
  if (!authCheck(req, token)) {
171
175
  if (isHtmlRequest(req)) {
172
176
  res.writeHead(200, { 'content-type': 'text/html; charset=utf-8', 'cache-control': 'no-store' });
173
- res.end(loginPageHtml(false));
177
+ res.end(loginPageHtml(false, isPublic));
174
178
  } else {
175
179
  res.writeHead(401, { 'content-type': 'application/json', 'cache-control': 'no-store' });
176
180
  res.end('{"error":"unauthorized"}');
package/package.json CHANGED
@@ -76,5 +76,5 @@
76
76
  "access": "public",
77
77
  "registry": "https://registry.npmjs.org/"
78
78
  },
79
- "version": "1.8.0"
79
+ "version": "1.8.1"
80
80
  }