diff --git a/conf-sshd.sh b/conf-sshd.sh index 1416707..5e5391a 100644 --- a/conf-sshd.sh +++ b/conf-sshd.sh @@ -7,7 +7,7 @@ sshkey_url="https://q-ssh.lamgc.me/ssh.keys" # 默认的 Cron 执行计划, 每天凌晨 0 点执行 default_cron="0 0 * * *" # 脚本 Url -script_url="https://q-ssh.lamgc.me" +script_url="https://q-ssh.lamgc.me/script.sh" ############ 脚本区 ########## diff --git a/install-ssh-worker/src/index.js b/install-ssh-worker/src/index.js index c639bd6..cddd733 100644 --- a/install-ssh-worker/src/index.js +++ b/install-ssh-worker/src/index.js @@ -5,7 +5,9 @@ const githubInstSshProjectName = "quickly-conf-sshd"; const baseUrl = `https://${githubUserName.toLowerCase()}.github.io/${githubInstSshProjectName}/`; const installScriptUrl = `${baseUrl}/conf-sshd.sh`; // 如果出现 Github 无法使用的情况, 可以修改 sshKeyUrl 来变更位置. -const sshKeyUrls = [`https://github.com/${githubUserName}.keys`]; +const sshKeyUrls = [ + `https://github.com/${githubUserName}.keys` +]; // 建议在此设置备用的 SSH 公钥, 以防 Github 无法使用. const backupSshKeys = ``; @@ -13,6 +15,26 @@ function getUserAgent(request) { return request.headers.get("User-Agent"); } +async function sendScriptContent() { + let scriptResp = await fetch(new Request(installScriptUrl)); + if (scriptResp.ok) { + let scriptContent = await scriptResp.text(); + return new Response(scriptContent, { + headers: { + "content-type": "text/plain; charset=utf-8" + } + }); + } else { + return new Response("Failed to get install script.", { + status: 500, + statusText: "Failed to get install script", + headers: { + "content-type": "text/plain; charset=utf-8" + } + }); + } +} + export default { async fetch(request, env) { const { pathname } = new URL(request.url); @@ -46,23 +68,7 @@ export default { } else if (pathname === "/") { const userAgent = getUserAgent(request); if (userAgent != null && userAgent.match(/curl|libcurl/) !== null) { - let scriptResp = await fetch(new Request(installScriptUrl)); - if (scriptResp.ok) { - let scriptContent = await scriptResp.text(); - return new Response(scriptContent, { - headers: { - "content-type": "text/plain; charset=utf-8" - } - }); - } else { - return new Response("Failed to get install script.", { - status: 500, - statusText: "Failed to get install script", - headers: { - "content-type": "text/plain; charset=utf-8" - } - }); - } + return await sendScriptContent(); } else { return new Response("", { status: 301, @@ -72,6 +78,13 @@ export default { } }); } + } else if (pathname === "/script.sh") { + return await sendScriptContent(); + } else { + return new Response("Not found.", { + status: 404, + statusText: "Not Found" + }) } } }