-
Notifications
You must be signed in to change notification settings - Fork 80
/
moreinfo.php
708 lines (683 loc) · 19.2 KB
/
moreinfo.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
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
<?php
/**
*
*/
define("PASS", "admin");
define("TYPE","d");
define("NUM", 11);
define("DISK", 20);//GB
define("MAX", 10);//GB
class Aria2{
protected $ch;
function __construct($server='http://127.0.0.1:6800/jsonrpc'){
$this->ch = curl_init($server);
curl_setopt_array($this->ch, [
CURLOPT_POST=>true,
CURLOPT_RETURNTRANSFER=>true,
CURLOPT_HEADER=>false
]);
}
function __destruct(){
curl_close($this->ch);
}
protected function req($data){
curl_setopt($this->ch, CURLOPT_POSTFIELDS, $data);
return curl_exec($this->ch);
}
function __call($name, $arg){
$data = [
'jsonrpc'=>'2.0',
'id'=>'1',
'method'=>'aria2.'.$name,
'params'=>$arg
];
$data = json_encode($data);
$response = $this->req($data);
if($response===false) {
trigger_error(curl_error($this->ch));
}
return json_decode($response, 1);
}
}
class dir{
public $dir;
public $file;
public $dirdir;
public $notex;
public $notdir;
function __construct(){
$this->notex=array("php","js","tgz","json");//不允许显示的后缀名文件
$this->notdir=array("a","phpmyadmin");//不允许显示的文件夹
if ($_GET['dir']) {
foreach ($this->notdir as $key => $value) {
if(strtolower($_GET['dir'])==$value){
$_GET['dir']=".";
}
}
$tom=trim($_GET['dir']);
$tam=str_replace("..", ".", $tom);
$this->dir="./".$tam;
}else{
$this->dir=".";
}
}
function open_dir(){
if(is_dir($this->dir)){
if($dh=opendir($this->dir)){
while(($file=readdir($dh))!==false){
$this->jugg($file);
}
sort($this->file);
sort($this->dirdir);
closedir($dh);
}
}else{
echo "error";
}
}
function jugg($jugg){
if($jugg!="."&&$jugg!=".."){
if (is_dir($this->dir."/".$jugg)) {
if(!in_array(strtolower($this->filename($jugg)), $this->notdir)){
$this->dirdir[]=$this->dir."/".$jugg;
}
}else{
$ex=array_pop(explode(".", $jugg));
if(!in_array(strtolower($ex), $this->notex)){
$this->file[]=$this->dir."/".$jugg;
}
}
}
}
function dirurl($dir){
$urf=substr($dir,2 );
return "?dir=".rawurlencode($urf);
}
function value($value){
$urf=substr($value,2 );
return $urf;
}
function type($file){
$ex=strtolower(array_pop(explode(".", $file)));
switch ($ex) {
case 'png':
case 'jpg':
case 'gif':
case 'bmp':
case 'jpeg':
return "img";
break;
case 'torrent':
return "torrent";
break;
case 'mp3':
return "mp3";
break;
case 'mp4':
case 'ogg':
case 'webm':
return "video";
break;
case 'xls':
case 'xlsx':
case 'doc':
case 'docx':
case 'ppt':
case 'pptx':
return "other";
break;
case 'pdf':
return "pdf";
break;
case 'txt':
case 'json':
case 'xml':
case 'html':
case 'md':
return "text";
break;
default:
return "other";
break;
}
}
function download($file){
return "<a href=\"".$file."\" ><span class=\"glyphicon glyphicon-download-alt\"></span></a>";
}
function other($file){
}
function img($img){
}
function pdf($pdf){
}
function video($video){
}
function mp3($mp3){
}
function torrent($torrent){
}
function filename($file){
return array_pop(explode("/", $file));
}
function text($file){
}
function size($file){
$fz=filesize($file);
if ($fz>(1024*1024*1024)) {
return sprintf("%.2f",$fz/(1024*1024*1024))."GB";
}elseif ($fz>(1024*1024)) {
return sprintf("%.2f",$fz/(1024*1024))."MB";
}elseif($fz>1024){
return sprintf("%.2f",$fz/1024)."KB";
}else{
return $fz."B";
}
}
function mtime($file){
return date("Y-m-d H:i:s",filemtime($file));
}
function atime($file){
return date("Y-m-d H:i:s",fileatime($file));
}
function ctime($file){
return date("Y-m-d H:i:s",filectime($file));
}
function icon($file){
$ex=strtolower(array_pop(explode(".", $file)));
switch ($ex) {
case 'png':
case 'jpg':
case 'gif':
case 'bmp':
case 'jpeg':
return "glyphicon glyphicon-picture";
break;
case 'torrent':
return "glyphicon glyphicon-magnet";
break;
case 'mp3':
return "glyphicon glyphicon-music";
break;
case 'mp4':
case 'ogg':
case 'webm':
return "glyphicon glyphicon-film";
break;
case 'xls':
case 'xlsx':
case 'doc':
case 'docx':
case 'ppt':
case 'pptx':
return "glyphicon glyphicon-pencil";
break;
case 'pdf':
return "glyphicon glyphicon-book";
break;
case 'txt':
case 'md':
return "glyphicon glyphicon-file";
break;
default:
return "glyphicon glyphicon-stop";
break;
}
}
function pre(){
$dir_array=explode("/", $this->dir);
$num=count($dir_array);
if($num>=2){
@array_shift($dir_array);
$url="<a class=\"text-success\" href=?>/.</a>";
foreach ($dir_array as $key => $value) {
$step=$step.$value."/";
$url=$url."<a class=\"text-success\" href=\"?dir=".$step."\">/".$value."</a>";
}
return $url;
}
}
}
/**
*
*/
class json{
public $info;
function __construct(){
if(is_file("./info.json")){
$swap=file_get_contents("./info.json");
$this->info=json_decode($swap,true);
}else{
$this->info=array("data"=>"json","gid"=>"","gid_info"=>"","this_num"=>"","this_time"=>"","hash"=>"","hash_info"=>"","length"=>"");//infoHash
$aj=json_encode($this->info);
@file_put_contents("./info.json", $aj);
}
}
function gid($gid){
return in_array($gid, $this->info['gid']);
}
function hash($hash){
return in_array($hash, $this->info['hash']);
}
function add_hash($info){
if($info["result"]['infoHash']){
$this->info['hash'][]=$info["result"]['infoHash'];
$iof['time']=time();
$iof['gid']=$info["result"]['gid'];
$iof['hash']=$info["result"]['infoHash'];
$this->info['hash_info'][]=$iof;
$this->save();
}
}
function add($gid){
$this->add_num();
$this->add_gid($gid);
$this->save();
}
function save(){
$save=json_encode($this->info);
@file_put_contents("./info.json", $save);
}
function add_num(){
$this->info['this_time']=time();
$this->info['this_num']+=1;
}
function add_gid($gid){
$ar[$gid]['time']=time();
$ar[$gid]['gid']=$gid;
$this->info['gid_info'][$gid]=$ar;
$this->info['gid'][]=$gid;
}
function jugg(){
$today=date("Ymd");
$month=date("Ym");
if(strtolower(TYPE)=="d"){
if($today==date("Ymd",$this->info['this_time'])){
if(NUM>$this->info['this_num']){
return true;
}else{
return false;
}
}else{
$this->info['this_num']=0;
return true;
}
}elseif (strtolower(TYPE)=="m") {
if($month==date("Ym",$this->info['this_time'])){
if(NUM>$this->info['this_num']){
return true;
}else{
return false;
}
}else{
$this->info['this_num']=0;
return true;
}
}else{
if($today==date("Ymd",$this->info['this_time'])){
if(NUM<$this->info['this_num']){
return true;
}else{
return false;
}
}else{
$this->info['this_num']=0;
return true;
}
}
}
function length($info){
$gid=$info['gid'];
if ($info['totalLength']>MAX*pow(2, 30)) {
return $info['gid'];//过大
}
if (!$this->info['gid_info'][$gid]['length']) {
$this->info['gid_info'][$gid]['length']=$info['totalLength'];
$this->info['length']+=$info['totalLength'];
$this->save();
}
}
}
function size($fz){
if ($fz>(1024*1024*1024)) {
return sprintf("%.2f",$fz/(1024*1024*1024))."GB";
}elseif ($fz>(1024*1024)) {
return sprintf("%.2f",$fz/(1024*1024))."MB";
}elseif($fz>1024){
return sprintf("%.2f",$fz/1024)."KB";
}else{
return $fz."B";
}
}
session_start();
$download_info=new json();
if ($_SESSION['user']) {
if (strlen($_GET['url'])>5) {//验证session才能添加操作
$download_jugg=$download_info->jugg();
if($download_info->info['length']>DISK*pow(2, 30)){
$ar['error']['message']="账户分配的磁盘已满!请联系管理员。";
echo json_encode($ar);
return;
}
if($download_jugg){
$url=trim($_GET['url']);
$dir=dirname(__FILE__);
$aria2 = new Aria2('http://127.0.0.1:6800/jsonrpc');
$json=$aria2->addUri(array($url),array('dir'=>$dir,));
$download_info->add($json['result']);
echo json_encode($json);
$gh=$aria2->tellStatus($json['result']);
$download_info->add_hash($gh);
return;
}else{
$ar['error']['message']="今日配额已经使用完";
echo json_encode($ar);
return;
}
}
}
$x=new dir();
$x->open_dir();
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="renderer" content="webkit">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://cdn.bootcss.com/bootstrap/3.3.0/css/bootstrap.min.css">
<link rel="stylesheet" href="http://cdn.bootcss.com/bootstrap/3.3.0/css/bootstrap-theme.min.css">
<script src="http://cdn.bootcss.com/jquery/1.11.1/jquery.min.js"></script>
<script src="http://cdn.bootcss.com/bootstrap/3.3.0/js/bootstrap.min.js"></script>
<script src="//cdn.bootcss.com/messenger/1.5.0/js/messenger.min.js"></script>
<link href="//cdn.bootcss.com/messenger/1.5.0/css/messenger.min.css" rel="stylesheet">
<link href="//cdn.bootcss.com/messenger/1.5.0/css/messenger-theme-future.min.css" rel="stylesheet">
<title>Webdir</title>
<style type="text/css">
body{
background-color:#F1F1FA;
}
.container{
margin-top: 100px;
border-radius:15px;
background-color:#FFFFFF;
}
</style>
</head>
<body>
<?php
if ($_POST['password']==PASS) {
$_SESSION['user']="666";
}
if($_SESSION['user']){
}else{
?>
<div class="container">
<div class="row " style="margin:20px ">
<div class="row">
<center><h2 class="text-primary">Webdir</h2></center>
</div>
<form class="form" action="" method="post">
<div class="row">
<div class="input-group col-md-4 col-md-offset-4">
<input type="password" name="password" class="form-control">
<span class="input-group-btn">
<input type="submit" name="sub" class="btn btn-success" value="登入">
</span>
</div>
</div>
</form>
</div>
</div>
<?php
return;
}
$total=DISK*pow(2, 30);
$used=$download_info->info['length'];
$free=$total-$used;//disk
$usp=round($used/$total*100,2);//used %
if(strlen($_GET['pause'])>5){
$aria2 = new Aria2('http://127.0.0.1:6800/jsonrpc');
$aria2->pause($_GET['pause']);
header("Location:".$_SERVER['HTTP_REFERER']);
return;
}
if(strlen($_GET['unpause'])>5){
$aria2 = new Aria2('http://127.0.0.1:6800/jsonrpc');
$aria2->unpause($_GET['unpause']);
header("Location:".$_SERVER['HTTP_REFERER']);
return;
}
?>
<div class="container">
<div class="row">
<div class="col-md-1" style="margin-bottom:10px; ">
<a href="
<?php echo $_SERVER['HTTP_REFERER'] ?>
"
><h2 class="btn btn-primary"><span class="glyphicon glyphicon-chevron-left " id="back"></span></h2></a>
</div>
<div class="col-md-6">
<h3>
<?php
echo $x->pre() ;
?>
</h3>
</div>
<div class="col-md-5">
<div class="input-group" style="margin-top:10px ">
<input type="text" name="magnet" id="magnet" class="form-control">
<span class="input-group-btn">
<span class="btn btn-success" id="btn-magnet">Magnet</span>
<span class="btn btn-info" id="xzz">下载列表</span>
</span>
</div>
</div>
</div>
<table class="table table-striped ">
<tr>
<th>文件名</th>
<th>大小</th>
<th>时间</th>
<th>下载</th>
</tr>
<?php
foreach ($x->dirdir as $key => $value) {
echo "<tr>";
echo "<td><a href=\"".$x->dirurl($value)."\"><span class=\"glyphicon glyphicon-list\"> ".$x->filename($value)."</span></a></td>";
echo "<td>目录</td>";
echo "<td>".$x->mtime($value)."</td>";
echo "<td></td>";
echo "</tr>";
}
foreach ($x->file as $key => $value) {
echo "<tr>";
echo "<td><span class=\" click_onload ".$x->icon($value)." fileshow\" type=\"".$x->type($value)."\" value=\"".$x->value($value)."\"> ".$x->filename($value)."</span></td>";
echo "<td>".$x->size($value)."</td>";
echo "<td>".$x->mtime($value)."</td>";
echo "<td>".$x->download($value)."</td>";
echo "</tr>";
}
?>
</table>
<div class="row">
<span class="col-md-2">Powered by <a href="https://github.com/maysrp/webdir">webdir</a></span>
<div class="col-md-6 ">
<div class="row">
<span class="col-md-2 text-right"><b>空间信息:</b></span>
<div class="col-md-10">
<div class="progress">
<div class="progress-bar
<?php
if ($usp<30) {
echo "progress-bar-success";
}elseif($usp<60){
echo "progress-bar-primary";
}elseif($usp<90){
echo "progress-bar-warning";
}else{
echo "progress-bar-danger";
}
?>" role="progressbar" aria-valuenow="<?php echo $usp ?>" aria-valuemin="0" aria-valuemax="100" style="width: <?php echo $usp ?>%;">
<?php echo $usp ?>%
</div>
</div>
</div>
</div>
</div>
<span class="col-md-4">
<b><span class="text-danger">USED:<?php echo size($used)?></span> / <span class="text-success">FREE:<?php echo size($free)?></span> / <span class="text-primary">TOTAL:<?php echo size($total)?></span></b>
</span>
</div>
</div>
<div>
<div class="modal fade bs-example-modal-lg" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="true" id="modal">
<div class="modal-dialog modal-lg">
<div class="modal-content ">
<div class="modal-header">
<h4 class="modal-title" id="myModalLabel"></h4>
</div>
<div class="modal-body text-center">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</div>
<div class="row hide" id="showdownload">
<span class="text-success"><b>下载中的任务</b></span>
<table class="table">
<tr>
<th class="text-left">文件名</th>
<th>下载速度</th>
<th>完成率</th>
<th>操作</th>
</tr>
<?php
$aria2 = new Aria2('http://127.0.0.1:6800/jsonrpc');//修改
$info=$aria2->tellActive();
foreach ($info['result'] as $key => $value) {
if ((!$download_info->gid($value['gid'])) && (!$download_info->hash($value['infoHash']))) {
continue;
}
echo "<td class=\"text-left\">".$value['bittorrent']['info']['name']."</td>";
echo "<td>".size($value['downloadSpeed'])."/S</td>";
echo "<td>".round($value['completedLength']/$value['totalLength']*100,2)."%</td>";
echo "<td><a href=\"?pause=".$value['gid']."\" class=\" btn btn-danger btn-sm \" >关闭</a></td></tr>";
$do_file=$download_info->length($value);
if ($do_file) {
$aria2->remove($do_file);
}
}
?>
</table>
<hr>
<span class="text-warning"><b>等待中的任务</b></span>
<table class="table">
<tr>
<th class="text-left">文件名</th>
<th>下载速度</th>
<th>完成率</th>
<th>操作</th>
</tr>
<?php
$info=$aria2->tellWaiting(0,100);
foreach ($info['result'] as $key => $value) {
if ((!$download_info->gid($value['gid'])) && (!$download_info->hash($value['infoHash']))) {
continue;
}
//echo "<tr><td>".$value['gid']."</td>";
echo "<td class=\"text-left\">".$value['bittorrent']['info']['name']."</td>";
echo "<td>".size($value['downloadSpeed'])."/S</td>";
echo "<td>".round($value['completedLength']/$value['totalLength']*100,2)."%</td>";
echo "<td><a href=\"?unpause=".$value['gid']."\" class=\" btn btn-success btn-sm \" >开始</a></td></tr>";
$do_file=$download_info->length($value);
if ($do_file) {
$aria2->remove($do_file);
}
}
?>
</table>
</div>
<script type="text/javascript">
$(".fileshow").click(function(){
var type=$(this).attr("type");
var name=$(this).text();
var value=$(this).attr("value");
switch(type){
case "img":
$(".modal-title").html(name);
$(".modal-body").html("<a href=\""+value+"\"><img style=\"max-width:80%;\" src=\""+value+"\"></a>");
$("#modal").modal();
break;
case "video":
$(".modal-title").html(name);
$(".modal-body").html("<video width=\"80%\" autoplay controls id=\"play\" src=\""+value+"\"></video>");
$("#modal").modal();
break;
case "mp3":
$(".modal-title").html(name);
$(".modal-body").html("<audio src=\""+value+"\" id=\"play\" autoplay controls>您的浏览器不支持 audio 标签。</audio>");
$("#modal").modal();
break;
case "text":
$(".modal-title").html(name);
$(".modal-body").html("<iframe width=\"80%\" height=\"600px\" src=\""+value+"\">");
$("#modal").modal();
break;
case "pdf":
$(".modal-title").html(name);
$(".modal-body").html("<iframe width=\"80%\" height=\"800px\" src=\""+value+"\">");
$("#modal").modal();
default:
}
})
$('#modal').on('hidden.bs.modal', function (e) {
var play=$("#play")[0];
play.pause();
})
$(".click_onload").mouseover(function(){
$(this).addClass("text-primary");
})
$(".click_onload").mouseout(function(){
$(this).removeClass("text-primary");
})
$("#btn-magnet").click(function(){
var magnet=$("#magnet").val();
$.get("?url="+magnet,function(data){
var re=eval("("+data+")");
if(typeof(mx) != 'undefined' ){
mx.hide();
}
if(re.result){
mx=Messenger().post("你已经添加一个离线任务!");
}else{
mx=Messenger().post("添加失败:"+re.error.message);
}
});
$("#magnet").val("");
})
$("#xzz").click(function(){
var show=$("#showdownload").clone();
show.removeClass("hide");
$(".modal-title").html("<h2>下载列表<small>累计使用<?php echo size($download_info->info['length']) ?>空间 | 本周期内可用离线任务<?php echo NUM-$download_info->info['this_num'] ?>个</small></h2><h5>空间总容量:<?php echo DISK ?>GB | 每个周期<?php echo NUM?>个 | 单个任务最大<?php echo MAX ?>GB | 周期单位<?php echo TYPE ?> <small> * d:表示每日;m:表示每月</small></h5>");
$(".modal-body").html(show);
$("#modal").modal();
})
</script>
</body>
</html>
<?php
$info=$aria2->tellStopped(0,6000);
foreach ($info['result'] as $key => $value) {
if ((!$download_info->gid($value['gid'])) && (!$download_info->hash($value['infoHash']))) {
continue;
}
$do_file=$download_info->length($value);
if ($do_file) {
$aria2->remove($do_file);
}
}
?>