-
Notifications
You must be signed in to change notification settings - Fork 80
/
wadir-dplay.php
611 lines (589 loc) · 18.3 KB
/
wadir-dplay.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
<?php
/**
*
*/
define("PASS", "admin");
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");//不允许显示的后缀名文件
$this->notdir=array("a","phpmyadmin");//不允许显示的文件夹
if (isset($_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 ex($string){
$ar=explode(".", $string);
$ex=array_pop($ar);
return strtolower($ex);
}
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=$this->ex($jugg);
if(!in_array($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=$this->ex($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 md5($file){
return md5_file($file);
}
function other($file){
}
function img($img){
}
function pdf($pdf){
}
function video($video){
}
function mp3($mp3){
}
function torrent($torrent){
}
function filename($file){
$ar=explode("/", $file);
return array_pop($ar);
}
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=$this->ex($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>";
$step="";
foreach ($dir_array as $key => $value) {
$step=$step.$value."/";
$url=$url."<a class=\"text-success\" href=\"?dir=".$step."\">/".$value."</a>";
}
return $url;
}
}
}
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();
if ($_SESSION['user']==PASS) {
$_GET['url']=isset($_GET['url'])?$_GET['url']:"";
if (strlen($_GET['url'])>5) {//验证session才能添加操作
$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,));
echo json_encode($json);
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="https://cdn.bootcss.com/bootstrap/3.3.0/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/3.3.0/css/bootstrap-theme.min.css">
<script src="https://cdn.bootcss.com/jquery/1.11.1/jquery.min.js"></script>
<script src="https://cdn.bootcss.com/bootstrap/3.3.0/js/bootstrap.min.js"></script>
<script src="https://cdn.bootcss.com/messenger/1.5.0/js/messenger.min.js"></script>
<link href="https://cdn.bootcss.com/messenger/1.5.0/css/messenger.min.css" rel="stylesheet">
<link href="https://cdn.bootcss.com/messenger/1.5.0/css/messenger-theme-future.min.css" rel="stylesheet">
<script type="text/javascript" src="https://cdn.bootcss.com/dplayer/1.1.2/DPlayer.min.js"></script>
<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
$time=time();
$token=base64_encode($_SERVER['REMOTE_ADDR'].":".$time.":".$_SERVER['HTTP_HOST']);
if(isset($_POST['password'])){
if ($_POST['password']==PASS) {
$_SESSION['user']=PASS;
}
}
if($_SESSION['user']==PASS){
}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;
}
$free=@disk_free_space(".");//disk
$total=@disk_total_space(".");
$used=$total-$free;
$usp=round($used/$total*100,2);//used %
$_GET['pause']=isset($_GET['pause'])?$_GET['pause']:"";
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;
}
$_GET['unpause']=isset($_GET['unpause'])?$_GET['unpause']:"";
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;
}
$_GET['remove']=isset($_GET['remove'])?$_GET['remove']:"";
if(strlen($_GET['remove'])>5){
$aria2 = new Aria2('http://127.0.0.1:6800/jsonrpc');
$aria2->remove($_GET['remove']);
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']=isset($_SERVER['HTTP_REFERER'])?$_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)."\" md5=\"".$x->md5($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) {
//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=\"?pause=".$value['gid']."\" class=\" btn btn-warning btn-sm \" >关闭</a> <a href=\"?remove=".$value['gid']."\" class=\" btn btn-danger btn-sm \" >删除</a></td></tr>";
}
?>
</table>
<hr>
<span class="text-warning"><b>等待中的任务</b></span>
<hr>
<table class="table">
<tr>
<th class="text-left">文件名</th>
<th>下载速度</th>
<th>完成率</th>
<th>操作</th>
</tr>
<?php
$info=$aria2->tellWaiting(0,1000);
foreach ($info['result'] as $key => $value) {
//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> <a href=\"?remove=".$value['gid']."\" class=\" btn btn-danger btn-sm \" >删除</a></td></tr>";
}
?>
</table>
</div>
<script type="text/javascript">
$(".fileshow").click(function(){
var type=$(this).attr("type");
var name=$(this).text();
var value=$(this).attr("value");
var md5=$(this).attr("md5");
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 "mp3":
case "video":
$(".modal-title").html("");
$(".modal-title").html(name);
$(".modal-body").html("");
$(".modal-body").html("<div id=\"player1\" class=\"dplayer\"></div>");
//$(".modal-body").html("<video width=\"80%\" autoplay controls id=\"play\" src=\""+value+"\"></video>");
$("#modal").modal();
dp = new DPlayer({
element: document.getElementById('player1'), // Optional, player element
autoplay: false, // Optional, autoplay video, not supported by mobile browsers
theme: '#FADFA3', // Optional, theme color, default: #b7daff
loop: true, // Optional, loop play music, default: true
lang: 'zh', // Optional, language, `zh` for Chinese, `en` for English, default: Navigator language
screenshot: true, // Optional, enable screenshot function, default: false, NOTICE: if set it to true, video and video poster must enable Cross-Origin
hotkey: true, // Optional, binding hot key, including left right and Space, default: true
preload: 'auto', // Optional, the way to load music, can be 'none' 'metadata' 'auto', default: 'auto'
video: { // Required, video info
url: value, // Required, video url
pic: 'a.jpg' // Optional, music picture
},
danmaku: { // Optional, showing danmaku, ignore this option to hide danmaku
id: md5, // Required, danmaku id, NOTICE: it must be unique, can not use these in your new player: `https://api.prprpr.me/dplayer/list`
api: 'http://dm.loli.mba:1024', // Required, danmaku api
token: '<?php echo $token ?>', // Optional, danmaku token for api
maximum: 1000, // Optional, maximum quantity of danmaku IP base64
}
});
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) {
if(window.dp){
dp.pause();
}
var play=$("#play")[0];
if(play){
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("下载列表");
$(".modal-body").html(show);
$("#modal").modal();
})
</script>
</body>
</html>