forked from mambaru/btp-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cmd.php
46 lines (40 loc) · 1.48 KB
/
cmd.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
<?php
if (!isset($argv[1])) die('cmd.php get|set|delete');
$cmd = $argv[1];
$param = array();
for ($i=2;$i<count($argv);$i++) {
$t = explode('=',$argv[$i],2);
if (!isset($t[1])) throw new Exception();
$param[$t[0]] = $t[1];
}
if (!isset($param['host'])) $param['host'] = '127.0.0.1';
if (!isset($param['port'])) $param['port'] = 22400;
require "Json.php";
function send($method,$data,$conn = null) {
if (!$conn) $conn = $GLOBALS['conn'];
echo $method."\n\t\t".json_encode($data)."\n";
try {
$r = $conn->request($method,$data)->get();
echo "\t\t".var_export($r,true)."\n";
return $r;
} catch (Exception $e) {
echo "FAIL: ";
print_r($e);
}
}
$conn = new JsonRpc_Connection(array('host'=>$param['host'],'port'=>$param['port']));
unset($param['host']);
unset($param['port']);
// это просто некий демонстрационный скрипт. пользуйтесь, если посчитаете нужным
if ($cmd=='op1') {
print_r($conn->request('get_list',array('script'=>'?'))->get());
exit;
print_r($conn->request('get_graph',array('service'=>'hitlist_typed'))->get());
} elseif ($cmd == 'op2') {
foreach ($conn->request('get_list',array('script'=>'?'))->get() as $script) {
$list = $conn->request('get_list',array('service'=>'?','script'=>$script))->get();
if (in_array('kyototycoon_kyoto_main',$list)) echo $script."\n";
}
} else {
send($cmd,$param,$conn);
}