mirror of
https://github.com/LamGC/quickly-conf-sshd.git
synced 2025-04-29 22:27:32 +00:00
允许 Shell 脚本强指定请求脚本内容.
This commit is contained in:
parent
b65f1b8ceb
commit
a916923eea
@ -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"
|
||||
|
||||
############ 脚本区 ##########
|
||||
|
||||
|
@ -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"
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user