-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathopen_directory.js
93 lines (80 loc) · 2.96 KB
/
open_directory.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
function sendToDiscordWebhook(webhookURL, content) {
return new Promise(function(resolve, reject){
fetch(webhookURL, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
content: content
}),
})
.then(response => {
if (response.ok) {
resolve(true);
} else {
resolve(false);
}
})
.catch(error => {
reject(false);
});
});
}
export default {
async fetch(request, env, ctx) {
const url = new URL(request.url);
const discordWebhookURL = "webHookURL"; // change this to your webhook
await sendToDiscordWebhook(discordWebhookURL, `View: ${request.headers.get("cf-connecting-ip")}, ${url.pathname}`)
const headers = new Headers({
'Content-Type': 'text/html'
});
var html = `
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html>
<head>
<title>Index of /home/suyogya/public_html</title>
</head>
<body>
<h1>Index of /home/suyogya/public_html</h1>
<table>
<tr><th valign="top"> </th><th><a href="?C=N;O=D">Name</a></th><th><a href="?C=M;O=A">Last modified</a></th><th><a href="?C=S;O=A">Size</a></th><th><a href="?C=D;O=A">Description</a></th></tr>
<tr><th colspan="5"><hr></th></tr>
<tr><td valign="top"> </td><td><a href="/public/">Parent Directory</a> </td><td> </td><td align="right"> - </td><td> </td></tr>
<tr><td valign="top"> </td><td><a href="files/">files/</a> </td><td align="right">2023-10-07 10:50 </td><td align="right"> - </td><td> </td></tr>
<tr><td valign="top"> </td><td><a href="files_old/">files_old/</a> </td><td align="right">2019-03-25 05:38 </td><td align="right"> - </td><td> </td></tr>
<tr><td valign="top"> </td><td><a href="static/">static/</a> </td><td align="right">2022-04-03 03:21 </td><td align="right"> - </td><td> </td></tr>
<tr><th colspan="5"><hr></th></tr>
</table>
</body></html>
`
if (url.pathname === "/message") {
const messageParam = url.searchParams.get("message") || false;
const discordUrl = "webHookURL"; // enter webhook URL for secret message endpoint
if(messageParam){
const discordStatus = await sendToDiscordWebhook(discordUrl, `${messageParam}, ${request.headers.get("cf-connecting-ip")}`);
if (discordStatus){
return new Response("Success", {
status: 200,
headers: headers
});
}else{
return new Response("Fail", {
status: 404,
headers: headers
});
}
} else {
return new Response("Fail", {
status: 404,
headers: headers
});
}
} else{
return new Response(html, {
status: 200,
headers: headers
});
}
},
};