Example #1
0
function getMagLink($hashvalue)
{
    $username = "******";
    $password = "******";
    $url = "http://localhost:9091/transmission/rpc";
    $hash = array($hashvalue);
    $rpc = new TransmissionRPC($url, $username, $password);
    $request = array("magnetLink");
    return $rpc->get($hash, $request);
}
function transmission_action()
{
    global $_, $conf, $myUser;
    if ($_['action'] == 'transmission_widget_load') {
        header('Content-type: application/json');
        $rpc = new TransmissionRPC();
        if ($conf->get('user', 'transmission') != '') {
            $rpc->username = $conf->get('user', 'transmission');
        }
        if ($conf->get('pswd', 'transmission') != '') {
            $rpc->password = $conf->get('pswd', 'transmission');
        }
        $rpc->url = 'http://' . $conf->get('ip', 'transmission') . ':' . $conf->get('port', 'transmission') . '/transmission/rpc';
        $response['title'] = 'Transmission';
        $response['content'] = '<div style="width: 100%">';
        try {
            $rpc->return_as_array = true;
            $result = $rpc->get(array(), array('name', 'percentDone', 'id'));
            $torrents = $result['arguments']['torrents'];
            $response['content'] .= '<ul>';
            foreach ($torrents as $torrent) {
                $response['content'] .= '<li title="' . $torrent['name'] . '"> ' . substr($torrent['name'], 0, 40) . ' <span class="label ' . ($torrent['percentDone'] == 1 ? 'label-success' : ($torrent['percentDone'] > 0.5 ? 'label-info' : 'label-warning')) . '">' . $torrent['percentDone'] * 100 . '%</span></li>';
            }
            $response['content'] .= '</ul>';
            $rpc->return_as_array = false;
        } catch (Exception $e) {
            $response['content'] .= 'Erreur de connexion';
        }
        $response['content'] .= '</div>';
        echo json_encode($response);
        exit(0);
    }
    if ($_['action'] == 'transmission_plugin_setting') {
        if (isset($_['ip'])) {
            $conf->put('ip', $_['ip'], 'transmission');
        }
        if (isset($_['port'])) {
            $conf->put('port', $_['port'], 'transmission');
        }
        if (isset($_['user'])) {
            $conf->put('user', $_['user'], 'transmission');
        }
        if (isset($_['pswd'])) {
            $conf->put('pswd', $_['pswd'], 'transmission');
        }
        header('location:setting.php?section=preference&block=transmission');
    }
}
Example #3
0
include_once 'dbconfig.php';
$vodhash = $_POST['vodhash'];
$b = $_POST['vodsmalldes'];
echo "the vod hash is " . $vodhash . "</br>";
echo "the vod small_des is " . $b . "</br>";
$dblink = mysql_connect($mysql_host, $mysql_user, $mysql_pass);
mysql_query("SET NAMES UTF8");
mysql_select_db("nexus_rsss", $dblink);
$outres = mysql_query("SELECT * FROM torrents WHERE small_descr='{$b}'", $dblink);
while ($info = mysql_fetch_assoc($outres)) {
    $byrhash = $info["hash"];
}
mysql_close($dblink);
echo "the byr hash is " . $byrhash . "</br>";
error_log("byrhash is {$byrhash}", 3, "/var/www/html/transmission/error.log");
//use transmission rpc to remove
$rpc = new TransmissionRPC();
error_log("************new rpc generate", 3, "/var/www/html/transmission/error.log");
$request = array("id");
$hash = array($vodhash, $byrhash);
$v = $rpc->get($hash, $request);
//print_r($v);
error_log("**************gogogogo1", 3, "/var/www/html/transmission/error.log");
$id1 = $v->arguments->torrents["0"]->id;
$id2 = $v->arguments->torrents["1"]->id;
echo "</br>" . $id1 . " " . $id2;
error_log("*************", 3, "/var/www/html/transmission/error.log");
error_log("id1 is {$id1}", 3, "/var/www/html/transmission/error.log");
$re1 = $rpc->remove($id1);
$re2 = $rpc->remove($id2);
print_r($re);
Example #4
0
// A more complex example
//$rpc = new TransmissionRPC('http://somehost:9091/transmission/rpc', 'testuser', 'testpassword');
//$rpc->debug = true;
try {
    $result = $rpc->sstats();
    print "GET SESSION STATS... [{$result->result}]\n";
    sleep(2);
    $result = $rpc->add($test_torrent, '/tmp');
    $id = $result->arguments->torrent_added->id;
    print "ADD TORRENT TEST... [{$result->result}] (id={$id})\n";
    sleep(2);
    $result = $rpc->set($id, array('uploadLimit' => 10));
    print "SET TORRENT INFO TEST... [{$result->result}]\n";
    sleep(2);
    $rpc->return_as_array = true;
    $result = $rpc->get($id, array('uploadLimit'));
    print "GET TORRENT INFO AS ARRAY TEST... [{$result['result']}]\n";
    $rpc->return_as_array = false;
    sleep(2);
    $result = $rpc->get($id, array('uploadLimit'));
    print "GET TORRENT INFO AS OBJECT TEST... [{$result->result}]\n";
    sleep(2);
    $result2 = $result->arguments->torrents[0]->uploadLimit == 10 ? 'success' : 'failed';
    print "VERIFY TORRENT INFO SET/GET... [{$result2}] (" . $result->arguments->torrents[0]->uploadLimit . ")\n";
    $result = $rpc->stop($id);
    print "STOP TORRENT TEST... [{$result->result}]\n";
    sleep(2);
    $result = $rpc->verify($id);
    print "VERIFY TORRENT TEST... [{$result->result}]\n";
    sleep(10);
    $result = $rpc->start($id);
$rpc->username = $transmission_admin;
$rpc->password = $transmission_pass;
if ($_GET['stop'] == 'all') {
    $rpc->stop(array());
}
if ($_GET['start'] == 'all') {
    $rpc->start(array());
}
if (!empty($_GET['dllimit'])) {
    $rpc->sessionSet(array(), array('speed-limit-down' => intval($_GET['dllimit']), 'speed-limit-down-enabled' => true));
    echo "Download speed set to " . $_GET['dllimit'];
}
if (!empty($_GET['ullimit'])) {
    $rpc->sessionSet(array(), array('speed-limit-up' => intval($_GET['ullimit']), 'speed-limit-up-enabled' => true));
    echo "Upload speed set to " . $_GET['ullimit'];
}
$torrents = $rpc->get();
if (!empty($torrents->arguments->torrents)) {
    foreach ($torrents->arguments->torrents as $item) {
        $id = $item->id;
        if ($_GET['start'] == $id) {
            $rpc->start($id);
        }
        if ($_GET['stop'] == $id) {
            $rpc->stop($id);
        }
        if ($_GET['remove'] == $id) {
            $rpc->remove($id, true);
        }
    }
}