forked from codehub666/94list
-
Notifications
You must be signed in to change notification settings - Fork 0
/
function.php
513 lines (443 loc) · 16 KB
/
function.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
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
<?php
/**
* 函数库
* 开源仓库地址:https://github.com/codehub666/94list.git
* 作者官网:https://api.94speed.com/
* 作者邮箱:[email protected]
* 声明:本程序是免费开源项目,核心代码均未加密,其要旨是为了方便文件分享与下载,重点是GET被没落的PHP语法学习。开源项目所涉及的接口均为官方开放接口,需使用正版SVIP会员账号进行代理提取高速链接,无破坏官方接口行为,本身不存违法。仅供自己参考学习使用,禁止商用。诺违规使用官方会限制或封禁你的账号,包括你的IP,如无官方授权进行商业用途会对你造成更严重后果。源码仅供学习,如无视声明使用产生正负面结果(限速,被封等)与都作者无关。
*/
session_start();
$v="0.0.1";
if (file_exists(__DIR__ . "/config.php")) {
require_once(__DIR__ . "/config.php");
if_login() && error_reporting(E_ALL) && ini_set('display_errors', 1);
}
function get_config() {
$sql = "SELECT * FROM `config`";
$connectDatabase = connectDatabase();
$result = $connectDatabase->query($sql);
$response = array();
$row = $result->fetch_assoc();
$connectDatabase->close();
return $row;
}
function gethead($url, $header) {
$ch = curl_init($url);
setCurl($ch, $header);
curl_setopt_array($ch, [
CURLOPT_HEADER => true,
CURLOPT_NOBODY => true,
CURLOPT_FOLLOWLOCATION => false,
]);
$response = curl_exec($ch);
$headerSize = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
curl_close($ch);
return substr($response, 0, $headerSize);
}
function UseCookie(){
$sql = "SELECT * FROM `bd_user` WHERE (`state` = 0 OR `state` = -2) AND `switch` = 0 ORDER BY RAND() LIMIT 1;";
$connectDatabase = connectDatabase();
$result = $connectDatabase->query($sql);
$response = array();
$row = $result->fetch_assoc();
$connectDatabase->close();
return $row;
}
function connectDatabase() {
global $hostname, $username, $password, $database;
$connection = mysqli_connect($hostname, $username, $password, $database);
if (!$connection) {
$response["success"] = false;
$response["message"] = "连接数据库失败:" . mysqli_connect_error();
return json_encode($response);
} else {
return $connection;
}
}
function if_login() {
if (isset($_SESSION['user'])) {
$user = $_SESSION['user'];
$connectDatabase = connectDatabase();
$sql = "SELECT * FROM `admin` WHERE `user` LIKE '$user'";
$result = $connectDatabase->query($sql);
if ($result->num_rows == 1) {
return true;
}
$connectDatabase->close();
}
return false;
}
function login() {
$user = $_POST['user'];
$pass = $_POST['pass'];
$sql = "SELECT * FROM `admin` WHERE `user` = '$user'";
$connectDatabase = connectDatabase();
$result = $connectDatabase->query($sql);
if($result){
if ($result->num_rows == 1) {
$row = $result->fetch_assoc();
if ($pass == $row['pass']) {
$_SESSION['user'] = $user;
$response["success"] = true;
$response["message"] = "登录成功,感谢使用";
} else {
$response["success"] = false;
$response["message"] = "密码错误";
}
} else {
$response["success"] = false;
$response["message"] = "账号不存在";
}
}else{
$response["success"] = false;
$response["message"] = "查询失败,可能是数据库出现问题";
}
$connectDatabase->close();
return json_encode($response);
}
function importSQLFile($connection) {
$sqlFile = './install/install.sql';
$sql = file_get_contents($sqlFile);
$sqlStatements = explode(';', $sql);
foreach ($sqlStatements as $sqlStatement) {
$sqlStatement = trim($sqlStatement);
if (!empty($sqlStatement)) {
if ($connection->query($sqlStatement) !== TRUE) {
return false;
}
}
}
return true;
}
function delete_bd_user() {
$id=$_POST['id'];
$connectDatabase = connectDatabase();
$sql = "DELETE FROM bd_user WHERE `bd_user`.`id` = $id";
$result = $connectDatabase->query($sql);
if ($result === true) {
$response["success"] = true;
$response["message"] ="账号数据删除成功";
} else {
$response["success"] = false;
$response["message"] ="删除失败,".$connectDatabase->error."";
}
$connectDatabase->close();
return json_encode($response);
}
function get_account_list(){//输出账号列表
$connectDatabase = connectDatabase();
// 执行查询
$sql = "SELECT * FROM `bd_user` ORDER BY `bd_user`.`id` DESC";
$result = $connectDatabase->query($sql);
if ($result) {
$data = array();
while ($row = $result->fetch_assoc()) {
$data[] = $row;
}
$response["success"] = true;
$response["message"] ="列表渲染数据获取成功";
$response["list"] = $data;
} else {
$response["success"] = false;
$response["message"] = "查询列表失败,".$connectDatabase->error."";
}
$connectDatabase->close();
return json_encode($response);
}
function createDatabase() {
if (!file_exists("./config.php")) {
$response = array();
$hostname = $_POST["hostname"];
$username = $_POST["username"];
$password = $_POST["password"];
$database = $_POST["database"];
$connection = mysqli_connect($hostname, $username, $password, $database);
if ($connection) {
$configContent = "<?php\n";
$configContent .= "\$hostname = \"$hostname\";\n";
$configContent .= "\$username = \"$username\";\n";
$configContent .= "\$password = \"$password\";\n";
$configContent .= "\$database = \"$database\";\n";
$configContent .= "?>";
if (file_put_contents("./config.php", $configContent)) {
if (importSQLFile($connection)) {
$response["success"] = true;
$response["message"] = "数据库连接并配置成功";
} else {
$response["success"] = true;
$response["message"] = "导入基础数据库失败,可能你这个数据库中已经有基础数据了,可无视这个报错";
}
} else {
$response["success"] = false;
$response["message"] = "无权限配置数据库信息";
}
$connection->close();
} else {
$response["success"] = false;
$response["message"] = "连接失败,请检查数据库信息";
}
} else {
$response["success"] = false;
$response["message"] = "已经配置过数据库连接信息";
}
return json_encode($response);
}
function setCurl($ch, array $header) {
$options = array(
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_SSL_VERIFYHOST => 0,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => $header,
CURLOPT_TIMEOUT => 8,
);
curl_setopt_array($ch, $options);
}
function get(string $url, array $header) {
$ch = curl_init($url);
setCurl($ch, $header);
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
function post(string $url, $data, array $header) {
$ch = curl_init($url);
setCurl($ch, $header);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
function get_bd_info() {//获取用户信息
$cookie = $_POST['cookie'];
$header = array(
'Cookie: ' . $cookie
);
$result = get('https://pan.baidu.com/rest/2.0/xpan/nas?method=uinfo', $header);
if ($result === false) {
$response["success"] = false;
$response["message"] = "后端通讯错误";
} else {
$decodedResult = json_decode($result, true);
if ($decodedResult !== null) {
$response["success"] = true;
$response["data"] = $decodedResult;
} else {
$response["success"] = false;
$response["message"] = "JSON 解码错误";
}
}
return json_encode($response);
}
function revise_info(){
$connectDatabase = connectDatabase();
$title = $_POST['title'];
$AnnounceSwitch = $_POST['AnnounceSwitch'];
$AnnounceSwitch = ($AnnounceSwitch == "true") ? 1 : 0;
$Announce = $_POST['Announce'];
$user_agent = $_POST['user_agent'];
$cookie = $_POST['cookie'];
$sql = "UPDATE `config` SET `title` = '$title', `user_agent` = '$user_agent', `cookie` = '$cookie', `AnnounceSwitch` = '$AnnounceSwitch', `Announce` = '$Announce' WHERE `config`.`id` = 1;";
$result = $connectDatabase->query($sql);
if ($result === true) {
$response["success"] = true;
$response["message"] = '修改基础信息成功';
} else {
$response["success"] = false;
$response["message"] = '修改基础信息失败';
}
$connectDatabase->close();
return json_encode($response);
}
function switch_bd_user(){
$id=$_POST['id'];
$switch=$_POST['switch'];
$switch = ($switch === '-1') ? '0' : (($switch === '0') ? '-1' : $switch);
$sql="UPDATE `bd_user` SET `switch` = '$switch' WHERE `bd_user`.`id` = $id;";
$connectDatabase = connectDatabase();
$result = $connectDatabase->query($sql);
if ($result === true) {
$response["success"] = true;
$response["message"] ="更改状态成功";
$response["switch"]=$switch;
} else {
$response["success"] = false;
$response["message"] ="更改状态失败,".$connectDatabase->error."";
}
$connectDatabase->close();
return json_encode($response);
}
function add() {
$cookie = $_POST['cookie'];
$name = $_POST['name'];
$vip_type = $_POST['vip_type'];
$currentDateTime = date('Y-m-d H:i:s');
$sql = "INSERT INTO `bd_user` (`id`, `name`, `cookie`, `add_time`, `use`, `state`, `switch`, `vip_type`)
VALUES (NULL, '$name', '$cookie', '$currentDateTime', '$currentDateTime', '-2', '0', '$vip_type');";
$connectDatabase = connectDatabase();
$result = $connectDatabase->query($sql);
$response = [
"success" => false,
"message" => "代理账号插入失败:" . $connectDatabase->error
];
if ($result) {
$response["success"] = true;
$response["message"] = "代理账号插入成功";
}
return json_encode($response);
}
function get_sign() {
$shareid = $_POST['shareid'];
$uk = $_POST['uk'];
$get_config = get_config();
$header = [
'Cookie: ' . $get_config['cookie']
];
$result = get('https://pan.baidu.com/share/tplconfig?shareid=' . $shareid . '&uk=' . $uk . '&fields=sign,timestamp&channel=chunlei&web=1&app_id=250528&clienttype=0', $header);
$decodedResult = json_decode($result, true);
$errno = $decodedResult["errno"];
$response = [
"success" => false,
"message" => "未知错误代码:" . $errno
];
switch ($errno) {
case '0':
$response["success"] = true;
$response["message"] = "取链信息值已经获取到位";
$response["data"] = $decodedResult;
break;
case '9019':
$response["message"] = "错误代码:" . $errno . ",获取信息的代理账号有问题";
break;
}
return json_encode($response);
}
function BanCookie($id){//cookie失效,封禁一下
$sql="UPDATE `bd_user` SET `state` = '-1' WHERE `bd_user`.`id` = $id;";
$connectDatabase = connectDatabase();
$connectDatabase->query($sql);
$connectDatabase->close();
}
function UpdateCookieTime($id){
$currentDateTime = date('Y-m-d H:i:s');
$sql="UPDATE `bd_user` SET `use` = '$currentDateTime', `state` = '0' WHERE `bd_user`.`id` = $id;";
$connectDatabase = connectDatabase();
$connectDatabase->query($sql);
$connectDatabase->close();
}
function extractStr($str, $left, $right) {
$start = strpos($str, $left);
if ($start !== false) {
$end = strpos($str, $right, $start);
if ($end !== false) {
$start += strlen($left);
$result = substr($str, $start, $end - $start);
if ($left === "Location") {
$result = substr($result, 10);
}
return $result;
}
}
return '';
}
function down_file(){
$fs_id=$_POST['fs_id'];
$time=$_POST['time'];
$uk=$_POST['uk'];
$sign=$_POST['sign'];
$randsk=$_POST['randsk'];
$share_id=$_POST['share_id'];
$get_config=get_config();
$UseCookie=UseCookie();
$cookie = isset($UseCookie['cookie']) ? $UseCookie['cookie'] : null;
if($cookie==null){
$response["success"] = false;
$response["message"] = "仓库已经没有可用的代理账号提供服务。";
return json_encode($response);
}
$user_agent=$get_config['user_agent'];
$url = 'https://pan.baidu.com/api/sharedownload?channel=chunlei&clienttype=12&sign=' . $sign . '×tamp=' . $time . '&web=1';
$data = "encrypt=0" . "&extra=" . urlencode('{"sekey":"' . urldecode($randsk) . '"}') . "&fid_list=[$fs_id]" . "&primaryid=$share_id" . "&uk=$uk" . "&product=share&type=nolimit";
$header = array(
"User-Agent:$user_agent",
"Cookie:$cookie",
"Referer: https://pan.baidu.com/disk/home",
"Host: pan.baidu.com",
);
$result=post($url, $data, $header);
$decodedResult = json_decode($result, true);
$errno=$decodedResult["errno"];
switch ($errno) {
case '0':
UpdateCookieTime($UseCookie['id']);
$headerArray = array( 'User-Agent:'.$user_agent.'', 'Cookie:'.$cookie.'' );
$gethead=gethead($decodedResult["list"][0]['dlink'],$headerArray);
$realLink = extractStr($gethead, "http://", "\r\n");
if($realLink==""){
$response["success"] = false;
$response["message"] = "获取跳转链接出错";
}else{
$response["success"] = true;
$response["message"] = "下载数据获取成功";
$response["data"]["user_agent"]=$user_agent;
$response['data']['dlink']="https://$realLink";
$response["data"]["fs_id"]=$decodedResult["list"][0]['fs_id'];
$response["data"]["md5"]=$decodedResult["list"][0]['md5'];
}
break;
case '9019':
case '8001':
BanCookie($UseCookie['id']);
$response["success"] = false;
$response["message"] = "错误代码".$errno.",代理账号失效或者IP被封禁。";
break;
case '110':
$response["success"] = false;
$response["message"] = "当前代理ip已被BAN,请通知一下管理。";
break;
default:
$response["success"] = false;
$response["message"] = "未知错误代码:".$errno."";
break;
}
return json_encode($response);
}
function get_list() {
$shorturl = $_POST['shorturl'];
$dir = $_POST['dir'];
$root = ($dir == '') ? 1 : 0;
$pwd = $_POST['pwd'];
$page = $_POST['page'];
$num = $_POST['num'];
$order = "time";
$data = 'shorturl=' . $shorturl . '&dir=' . $dir . '&root=' . $root . '=&pwd=' . $pwd . '&page=1&num=1000&order=time';
$get_config = get_config();
$header = array(
'Cookie: ' . $get_config['cookie']
);
$result = post("https://pan.baidu.com/share/wxlist?channel=weixin&version=2.2.2&clienttype=25&web=1&qq-pf-to=pcqq.c2c", $data, $header);
$decodedResult = json_decode($result, true);
$errno = $decodedResult["errno"];
$response = [
"success" => false,
"message" => "未知错误代码:" . $errno
];
switch ($errno) {
case '0':
$response["success"] = true;
$response["message"] = "列表数据获取成功";
$response["list"] = $decodedResult["data"]["list"];
$response["data"]["uk"] = $decodedResult["data"]["uk"];
$response["data"]["shareid"] = $decodedResult["data"]["shareid"];
$response["data"]["randsk"] = $decodedResult["data"]["seckey"];
break;
case '9019':
$response["message"] = "通知一下管理员获取列表的代理账号出现问题";
break;
case '-130':
$response["message"] = "错误 " . $errno . ",可能你这个链接已经失效或者无法访问";
break;
}
return json_encode($response);
}
?>