-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi.php
69 lines (56 loc) · 1.6 KB
/
api.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
<?php
namespace Aria2API;
require 'vendor/autoload.php';
use Aria2;
class A2
{
private $aria2;
public function __construct($conn_str = null)
{
$this->aria2 = new Aria2(is_null($conn_str) ? "http://127.0.0.1:6800/jsonrpc" : $conn_str);
}
public function getVersion()
{
return json_encode(["version" => "0.0.1"]);
}
public function getStats()
{
$globOptions = $this->aria2->getGlobalOption();
$globStat = $this->aria2->getGlobalStat();
return json_encode([
"globOpt" => $globOptions,
"globStats" => $globStat
]);
}
public function getActiveList()
{
$list = $this->aria2->tellActive();
return json_encode($list);
}
public function getWaitingList(int $start, int $end)
{
$list = $this->aria2->tellWaiting($start, $end);
return json_encode($list);
}
public function getStoppedList(int $start, int $end)
{
$list = $this->aria2->tellStopped($start, $end);
return json_encode($list);
}
public function changeGlobalOption(string $opt, string $value)
{
$list = $this->aria2->changeGlobalOption([$opt => $value]);
return json_encode($list);
}
public function serviceStatus()
{
$status = "Inactive";
$boolval = false;
$out = shell_exec("systemctl status aria2-deamon-rpc.service");
if (strpos($out, "active (running)")) {
$status = "Active";
$boolval = true;
}
return json_encode(["status" => $status, "b" => $boolval]);
}
}