-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathaction.php
91 lines (91 loc) · 3.17 KB
/
action.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
<?php
require_once "webmastconfig.php";
include "config.php";
require_once "Client.php";
$client = new \JsonRPC\Client ( 'http://' . HOST . ':' . PORT . '/jsonrpc', SECRET );
$debug = false;
if(! $_GET['gid']) {
$_GET['gid'] = 0;
}
ini_set ( 'display_errors', 'On' );
if($debug) {
error_log ( '***********************\ncall action=' . $_GET['action'] );
}
if($_GET['action'] == 'pause') {
$client->execute ( 'aria2.pause', array($_GET['gid']) );
}elseif($_GET['action'] == 'resume') {
$client->execute ( 'aria2.unpause', array($_GET['gid']) );
}elseif($_GET['action'] == 'removeExt') {
$status = $client->execute ( 'aria2.tellStatus', array($_GET['gid']) );
if($status != null) {
if($status != null) {
$path = $status['files'];
$rmpath = $path;
if($path != null) {
$rmpath = $path[0]['path'];
}
if($status['status'] == 'complete') {
$client->execute ( 'aria2.removeDownloadResult', array($_GET['gid']) );
}else if($status['status'] == 'failed' || $status['status'] == 'error') {
$client->execute ( 'aria2.removeDownloadResult', array($_GET['gid']) );
}else {
$client->execute ( 'aria2.forceRemove', array($_GET['gid']) );
}
if($rmpath != null) {
unlink ( $rmpath );
}
}
}
}elseif($_GET['action'] == 'remove') {
$status = $client->execute ( 'aria2.tellStatus', array($_GET['gid']) );
if($status != null) {
$path = $status['files'];
$rmpath = $path;
if($path != null) {
$rmpath = $path[0]['path'];
}
if($status['status'] == 'complete') {
$client->execute ( 'aria2.removeDownloadResult', array($_GET['gid']) );
}else if($status['status'] == 'failed'|| $status['status'] == 'error') {
$client->execute ( 'aria2.removeDownloadResult', array($_GET['gid']) );
if($rmpath != null) {
unlink ( $rmpath );
}
}else {
$client->execute ( 'aria2.forceRemove', array($_GET['gid']) );
}
}
}elseif($_GET['action'] == 'pauseall') {
$client->execute ( 'aria2.forcePauseAll' );
}elseif($_GET['action'] == 'unpauseall') {
$client->execute ( 'aria2.unpauseAll' );
}elseif($_GET['action'] == 'purge') {
$client->execute ( 'aria2.purgeDownloadResult' );
}elseif($_GET['action'] == 'savesession') {
$client->execute ( 'aria2.saveSession' );
}elseif($_GET['action'] == 'redownload_failed') {
$downloads = $client->execute ( 'aria2.tellStopped', array(0, 1000) );
foreach($downloads as $download) {
if($download['status'] == 'error') {
$uri = $download['files'][0]['uris'][0]['uri'] . PHP_EOL;
try {
$response = $client->execute ( 'aria2.addUri', array(array(trim ( $uri ))) );
}catch(Exception $e) {
die ( $e->getMessage () );
}
}
}
}
if($_GET['action'] == 'moveup') {
$client->execute ( 'aria2.changePosition', array($_GET['gid'], - 1, 'POS_CUR') );
}elseif($_GET['action'] == 'movedown') {
$client->execute ( 'aria2.changePosition', array($_GET['gid'], + 1, 'POS_CUR') );
}elseif($_GET['action'] == 'movetop') {
$client->execute ( 'aria2.changePosition', array($_GET['gid'], 0, 'POS_SET') );
}elseif($_GET['action'] == 'movebottom') {
$client->execute ( 'aria2.changePosition', array($_GET['gid'], 2000, 'POS_END') );
}
if($debug) {
error_log ( '------------------\n' );
}
header ( 'Location: index.php?type=' . $_GET['type'] );