-
Notifications
You must be signed in to change notification settings - Fork 813
/
key.php
265 lines (245 loc) · 7.7 KB
/
key.php
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
<?php
$content = "";
session_start();
if ((isset($_SESSION['admin'])) && ($_SESSION['admin'] == true)) {
if (isset($_POST["message"])) {
if ($_POST["action"] == "save") {
$handle = fopen(__DIR__ . "/apikey.php", "w") or die("Writing file failed.");
if ($handle) {
fwrite($handle, "<?php header('HTTP/1.1 404 Not Found');exit; ?>\n" . $_POST["message"]);
fclose($handle);
exit;
}
} elseif ($_POST["action"] == "check") {
$lines = explode("\n", $_POST["message"]);
$i = 0;
$validkey = "";
$invalidkey = "";
while ($i < count($lines)) {
$line = $lines[$i];
$headers = [
'Accept: application/json',
'Content-Type: application/json',
'Authorization: Bearer ' . $line
];
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_URL, 'https://api.openai.com/v1/models/gpt-3.5-turbo');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($ch);
curl_close($ch);
$complete = json_decode($response);
if (isset($complete->error)) {
$invalidkey .= $line . "\n";
} else {
$validkey .= $line . "\n";
}
$i++;
}
echo $validkey;
exit;
}
}
$line = 0;
$handle = @fopen(__DIR__ . "/apikey.php", "r");
if ($handle) {
while (($buffer = fgets($handle)) !== false) {
$line++;
if ($line > 1) {
$content .= $buffer;
}
}
fclose($handle);
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>API_KEY配置信息</title>
<script src="js/jquery-3.6.4.min.js"></script>
<script src="js/layer.min.js" type="application/javascript"></script>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f2f2f2;
}
.container {
margin: 50px auto;
width: 80%;
max-width: 800px;
background-color: #fff;
padding: 20px;
border-radius: 10px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
}
textarea {
width: calc(100% - 20px);
height: 200px;
padding: 10px;
border: none;
border-radius: 5px;
box-shadow: 0 0 5px rgba(0, 0, 0, 0.2);
resize: none;
font-size: 16px;
line-height: 1.5;
margin-bottom: 20px;
}
.btn {
display: inline-block;
padding: 10px 20px;
background-color: #4CAF50;
color: #fff;
border: none;
border-radius: 5px;
font-size: 16px;
cursor: pointer;
margin-right: 10px;
transition: background-color 0.3s ease;
}
.btn:hover {
background-color: #3e8e41;
}
</style>
</head>
<body>
<div class="container">
<h1>API_KEY配置信息</h1>
<textarea placeholder="请按一行一回车的方式录入" id="tt"><?php echo $content; ?></textarea>
<button class="btn" onclick="checkit();">验证有效性</button> <button class="btn" onclick="saveit();">保存当前设置</button>
</div>
</body>
<script>
function saveit() {
$.ajax({
type: "POST",
url: "key.php",
data: {
message: $("#tt").val(),
action: "save",
},
success: function(results) {
layer.msg('保存成功,您可以刷新本网页确认');
}
});
}
function checkit() {
var loading = layer.msg('验证中,这需要一些时间,请稍候...', {
icon: 16,
shade: 0.4,
time: false //取消自动关闭
});
$.ajax({
type: "POST",
url: "key.php",
data: {
message: $("#tt").val(),
action: "check",
},
success: function(results) {
$("#tt").val(results);
layer.close(loading);
layer.msg('验证完毕,无效API_KEY已被删除,请记得点保存设置。');
}
});
}
</script>
</html>
<?php
exit;
}
// 定义用户名和密码常量
define('USERNAME', 'admin');
define('PASSWORD', 'admin@2023');
// 判断是否提交了表单
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
// 获取表单提交的用户名和密码
$username = $_POST['username'];
$password = $_POST['password'];
// 判断用户名和密码是否正确
if ($username == USERNAME && $password == PASSWORD) {
// 登录成功,跳转到首页
$_SESSION['admin'] = true;
header("Location: key.php");
exit;
} else {
// 登录失败,显示错误信息
$error = '用户名或密码错误';
$_SESSION['admin'] = false;
}
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>登录页面</title>
<style>
body {
background-color: #f2f2f2;
font-family: Arial, sans-serif;
display: flex;
align-items: center;
height: 100vh;
}
h1 {
text-align: center;
color: #333;
}
form {
width: 400px;
margin: auto;
background-color: #fff;
padding: 20px;
border-radius: 5px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
}
label {
display: block;
margin-bottom: 10px;
color: #333;
}
input[type="text"],
input[type="password"] {
width: 100%;
padding: 10px;
border: 1px solid #ccc;
border-radius: 3px;
box-sizing: border-box;
margin-bottom: 20px;
}
button[type="submit"] {
background-color: #333;
color: #fff;
padding: 10px 20px;
border: none;
border-radius: 3px;
cursor: pointer;
}
button[type="submit"]:hover {
background-color: #555;
}
p.error {
color: red;
margin-top: 10px;
}
</style>
</head>
<body>
<?php if (isset($error)) : ?>
<script>
alert('<?php echo $error; ?>');
</script>
<?php endif; ?>
<form method="post">
<h1>API_KEY管理后台</h1>
<p> <label>用户名:</label> <input type="text" name="username"> </p>
<p> <label>密码:</label> <input type="password" name="password"> </p>
<p style="text-align:center"> <button type="submit">登录</button> </p>
</form>
</body>
</html>