Exemple #1
0
function check_for_torrent(&$item, $key, $opts)
{
    global $matched, $test_run, $config_values;
    if (!(strtolower($item['Feed']) == 'all' || $item['Feed'] === '' || $item['Feed'] == $opts['URL'])) {
        return;
    }
    $rs = $opts['Obj'];
    $title = strtolower($rs['title']);
    switch (_isset($config_values['Settings'], 'MatchStyle')) {
        case 'simple':
            $hit = $item['Filter'] != '' && strpos(strtr($title, " .", "__"), strtr(strtolower($item['Filter']), " .", "__")) === 0 && ($item['Not'] == '' or my_strpos($title, strtolower($item['Not'])) === FALSE) && ($item['Quality'] == 'All' or $item['Quality'] == '' or my_strpos($title, strtolower($item['Quality'])) !== FALSE);
            break;
        case 'glob':
            $hit = $item['Filter'] != '' && fnmatch(strtolower($item['Filter']), $title) && ($item['Not'] == '' or !fnmatch(strtolower($item['Not']), $title)) && ($item['Quality'] == 'All' or $item['Quality'] == '' or strpos($title, strtolower($item['Quality'])) !== FALSE);
            break;
        case 'regexp':
        default:
            $hit = $item['Filter'] != '' && preg_match('/\\b' . strtolower(str_replace(' ', '[\\s._]', $item['Filter'])) . '\\b/', $title) && ($item['Not'] == '' or !preg_match('/' . strtolower($item['Not']) . '/', $title)) && ($item['Quality'] == 'All' or $item['Quality'] == '' or preg_match('/' . strtolower($item['Quality']) . '/', $title));
            break;
    }
    if (strtolower($item['Filter']) == "any") {
        $hit = 1;
        $any = 1;
    }
    if ($hit) {
        $guess = guess_match($title, TRUE);
    }
    if ($hit && episode_filter($guess, $item['Episodes']) == true) {
        $matched = 'match';
        if (preg_match('/^\\d+p$/', $item['Episode'])) {
            $item['Episode'] = preg_replace('/^(\\d+)p/', '\\1', $item['Episode']);
            $PROPER = 1;
        }
        if (check_cache($rs['title'])) {
            if (!$any && _isset($config_values['Settings'], 'Only Newer') == 1) {
                if (!empty($guess['episode']) && preg_match('/^(\\d+)x(\\d+)p?$|^(\\d{8})p?$/i', $guess['episode'], $regs)) {
                    if (isset($regs[3]) && preg_match('/^(\\d{8})$/', $regs[3]) && $item['Episode'] >= $regs[3]) {
                        _debug($item['Name'] . ": " . $item['Episode'] . ' >= ' . $regs[3] . "\r\n", 1);
                        $matched = "old";
                        return FALSE;
                    } else {
                        if (isset($regs[1]) && preg_match('/^(\\d{1,3})$/', $regs[1]) && $item['Season'] > $regs[1]) {
                            _debug($item['Name'] . ": " . $item['Season'] . ' > ' . $regs[1] . "\r\n", 1);
                            $matched = "old";
                            return FALSE;
                        } else {
                            if (isset($regs[2]) && preg_match('/^(\\d{1,3})$/', $regs[1]) && $item['Season'] == $regs[1] && $item['Episode'] >= $regs[2]) {
                                if (!preg_match('/proper|repack|rerip/i', $rs['title'])) {
                                    _debug($item['Name'] . ": " . $item['Episode'] . ' >= ' . $regs[2] . "\r\n", 1);
                                    $matched = "old";
                                    return FALSE;
                                } else {
                                    if ($PROPER == 1) {
                                        _debug("Allready downloaded this Proper, Repack or Rerip of " . $item['Name'] . " {$regs['1']}x{$regs['2']}{$regs['3']}\r\n");
                                        $matched = "old";
                                        return FALSE;
                                    }
                                }
                            }
                        }
                    }
                } else {
                    if ($guess['episode'] == 'fullSeason') {
                        $matched = "season";
                        return FALSE;
                    } else {
                        if ($guess['episode'] != 'noShow' && !preg_match('/^(\\d{1,2} \\d{1,2} \\d{2,4})$/', $guess['episode']) || $config_values['Settings']['Require Episode Info'] == 1) {
                            _debug("{$item} is not in a workable format.");
                            $matched = "nomatch";
                            return FALSE;
                        }
                    }
                }
            }
            _debug('Match found for ' . $rs['title'] . "\n");
            if ($test_run) {
                $matched = 'test';
                return;
            }
            if ($link = get_torrent_link($rs)) {
                $response = client_add_torrent($link, NULL, $rs['title'], $opts['URL'], $item);
                if (preg_match('/^Error:/', $response)) {
                    _debug("Failed adding torrent {$link}\n", -1);
                    return FALSE;
                } else {
                    add_cache($rs['title']);
                }
            } else {
                _debug("Unable to find URL for " . $rs['title'] . "\n", -1);
                $matched = "nourl";
            }
        }
    }
}
function client_add_torrent($filename, $dest, $title, $feed = NULL, &$fav = NULL, $retried = false)
{
    global $config_values, $hit, $tw_version;
    if (strtolower($fav['Filter']) == "any") {
        $any = 1;
    }
    $hit = 1;
    if (preg_match("/^magnet:/", $filename)) {
        $tor = $filename;
        $magnet = 1;
    }
    if (!$magnet) {
        $filename = htmlspecialchars_decode($filename);
        // Detect and append cookies from the feed url
        $url = $filename;
        if ($feed && preg_match('/:COOKIE:/', $feed) && !preg_match('/:COOKIE:/', $url)) {
            $url .= stristr($feed, ':COOKIE:');
        }
        $get = curl_init();
        $response = check_for_cookies($url);
        if ($response) {
            $url = $response['url'];
            $cookies = $response['cookies'];
        }
        $getOptions[CURLOPT_URL] = $url;
        if (isset($cookies)) {
            $getOptions[CURLOPT_COOKIE] = $cookies;
        }
        //$getOptions[CURLOPT_USERAGENT] = 'Python-urllib/1.17';
        $getOptions[CURLOPT_USERAGENT] = "TWX/{$tw_version['0']}";
        get_curl_defaults($getOptions);
        curl_setopt_array($get, $getOptions);
        $tor = curl_exec($get);
        curl_close($get);
        if (strncasecmp($tor, 'd8:announce', 11) != 0) {
            // Check for torrent magic-entry
            //This was not a torrent-file, so it's poroperly some kind og xml / html.
            if (!$retried) {
                //Try to retrieve a .torrent link from the content.
                $link = find_torrent_link($url, $tor);
                return client_add_torrent($link, $dest, $title, $feed, $fav, $url);
            } else {
                _debug("No torrent file found on {$url}. Exitting.\n");
                if (isset($retried)) {
                    $url = $retried;
                }
                return "Error: No torrent file found on {$url}.";
            }
        }
        if (!$tor) {
            print '<pre>' . print_r($_GET, TRUE) . '</pre>';
            _debug("Couldn't open torrent: {$filename} \n", -1);
            return "Error: Couldn't open torrent: {$filename}";
        }
    }
    $tor_info = new BDecode("", $tor);
    if (!($tor_name = $tor_info->{'result'}['info']['name'])) {
        $tor_name = $title;
    }
    if (!isset($dest)) {
        $dest = $config_values['Settings']['Download Dir'];
    }
    if (isset($fav) && $fav['Save In'] != 'Default') {
        $dest = $fav['Save In'];
    }
    $dest = get_deep_dir(preg_replace('/\\/$/', '', $dest), $tor_name);
    if (!file_exists($dest) or !is_dir($dest)) {
        $old_umask = umask(0);
        if (file_exists($dest)) {
            unlink($dest);
        }
        mkdir($dest, 0777, TRUE);
        umask($old_umask);
    }
    foreach ($config_values['Feeds'] as $key => $feedLink) {
        if ($feedLink['Link'] == "{$feed}") {
            $idx = $key;
        }
    }
    if ($config_values['Feeds'][$idx]['seedRatio'] >= 0) {
        $seedRatio = $config_values['Feeds'][$idx]['seedRatio'];
    } else {
        $seedRatio = $config_values['Settings']['Default Seed Ratio'];
    }
    if (!$seedRatio) {
        $seedRatio = -1;
    }
    switch ($config_values['Settings']['Client']) {
        case 'Transmission':
            $return = transmission_add_torrent($tor, $dest, $title, _isset($fav, '$seedRatio', $seedRatio));
            break;
        case 'folder':
            if ($magnet) {
                _debug("Can not save magnet links to a folder\n");
            } else {
                $return = folder_add_torrent($tor, $dest, $tor_name);
            }
            break;
        default:
            _debug("Invalid Torrent Client: " . $config_values['Settings']['Client'] . "\n", -1);
            exit(1);
    }
    if ($return === 0) {
        add_history($tor_name);
        _debug("Started: {$tor_name} in {$dest}\n", 0);
        if (isset($fav)) {
            run_script('favstart', $title);
            if ($config_values['Settings']['Email Notifications'] == 1) {
                $subject = "TW-X: {$tor_name} started downloading.";
                $msg = "TorrentWatch started downloading {$tor_name}";
                MailNotify($msg, $subject);
            }
            if (!$any) {
                updateFavoriteEpisode($fav, $title);
                _debug("Updated Favorites");
            }
        } else {
            run_script('nonfavstart', $title);
        }
        if ($config_values['Settings']['Save Torrents']) {
            file_put_contents("{$dest}/{$tor_name}.torrent", $tor);
        }
        return "Success";
    } else {
        _debug("Failed Starting: {$tor_name}  Error: {$return}\n", -1);
        $msg = "TorrentWatch-X tried to start \"{$tor_name}\". But this failed with the following error:\n\n";
        $msg .= "{$return}\n";
        $subject = "TW-X: Error while trying to start {$tor_name}.";
        MailNotify($msg, $subject);
        run_script('error', $title, $msg);
        return "Error: {$return}";
    }
}
 /**
  * Update the content of the resource identified by the URI given as argument. The resource has to exist before
  * content can be uploaded to it. Any existing content will be overridden. Throws Exception if the content type is
  * not supported or if the resource does not exist.
  *
  * @param $uri
  * @param Model\Content\Content $content
  * @throws Exception
  */
 public function updateResourceContent($uri, Content $content)
 {
     $client = new Client();
     $request = $client->put($this->getServiceUrl($uri), array("User-Agent" => "Marmotta Client Library (PHP)", "Content-Type" => $content->getMimetype() . "; rel=content"), $content->getData());
     // set authentication if given in configuration
     if (!_isset($this->config->getUsername())) {
         $request->setAuth($this->config->getUsername(), $this->config->getPassword());
     }
     $response = $request->send();
     if ($response->getStatusCode() >= 400) {
         throw new Exception("could not update resource {$uri}; " . $response->getReasonPhrase());
     }
 }
	You should have received a copy of the GNU General Public License
	along with BTPD Web/Gaya GUI; if not, write to the Free Software
	Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA


****************************************************************/
require_once "class.BEncodeLib.php";
require_once "class.btpdControl.php";
require_once "utils.php";
//###########################################################
// Init
//###########################################################
$globalinfo = getStartupconfig();
$globalinfo["torrentId"] = intval(_isset($_REQUEST, "t", 0));
$globalinfo['page'] = intval(_isset($_REQUEST, 'pg', 0));
$globalinfo["btpdControl"] = new btpdControl($globalinfo["APP_HOME"]);
$stdGetFields = array();
//Setup info
$setup = tr_sessionAccessor();
$session = parseSession($setup);
//Stats
/*
$globalinfo['stats'] = tr_sessionStats();
*/
//###########################################################
// Actions
//###########################################################
if (isset($_REQUEST['list'])) {
    $tor_IdList = parse_torrent_list($_REQUEST['list']);
    if (isset($_REQUEST['action-delete'])) {
function _AH_FORM($connection, $ADMIN_MODE = false)
{
    global $L;
    $RealmID = isset($_GET['R']) ? (int) $_GET['R'] : null;
    $PostQuery = isset($_POST['U']) ? trim($_POST['U']) : null;
    if (isset($PostQuery)) {
        $PostQuery = !empty($PostQuery) ? $PostQuery : null;
    }
    $Done = null;
    $H = $ADMIN_MODE ? $L[221] : $L[95];
    $Q_STR = "SELECT DATE(`whenItDone`),`action`,`text`,`realmName`,`charName`,`myth_coins_spend`,`myth_coins_balance`,`IP`\n                                    FROM `account_billing_history` ";
    _getRealmArray($connection);
    echo "\n            <div class = 'text-center'>\n                <h2>" . $H . "</h2>";
    if ($ADMIN_MODE) {
        if (isset($PostQuery) && isset($_SESSION['R']['Username']) && $PostQuery === $_SESSION['R']['Username']) {
            $Done = true;
        } else {
            if (!isset($PostQuery) && isset($_SESSION['R']['Username'])) {
                $Done = true;
            } else {
                $_SESSION['R']['Username'] = isset($PostQuery) ? $PostQuery : null;
            }
        }
        if (!isset($Done) && isset($_SESSION['R']['Username'])) {
            $_SESSION['R']['ID'] = _lookForAccount($connection, $_SESSION['R']['Username']);
        }
        $PLACEHOLDER = isset($_SESSION['R']['ID']) ? $_SESSION['R']['Username'] : $L[219];
        if (isset($_SESSION['R']['ID'])) {
            $InfoAccountQuery = mysql_query("SELECT\n                `t2`.`myth_coins`,`t1`.`id`,`t1`.`email`,`t1`.`last_ip`,DATE(`t1`.`joindate`) AS `joindate`,DATE(`t1`.`last_login`) AS `last_login`\n                FROM `account` `t1` LEFT JOIN `account_details` `t2` ON `t1`.`id` = `t2`.`id` WHERE `t1`.`id` = " . $_SESSION['R']['ID'] . ";", $connection) or die(mysql_error());
            $InfoAccountResult = mysql_fetch_array($InfoAccountQuery);
            echo "\n                <div class = 'modal hide' id = 'ModifyFirePoints'>\n                    <div class = 'modal-header'>\n                        <button type = 'button' class = 'close' data-dismiss = 'modal'>×</button>\n                        <h3>" . $_SESSION['R']['Username'] . "</h3>\n                    </div>\n                    <form action = " . $_SERVER['PHP_SELF'] . " method = 'POST'>\n                        <div class = 'modal-body'>\n                        <p class = 'text-center'>" . $L[253] . "</p>\n                            <input name = 'HowMuch' type = 'text' size = '60' placeholder = '" . $L[255] . "'>\n                            <input name = 'HowMuchReason' type = 'text' size = '100' placeholder = '" . $L[256] . "'>\n                        </div>\n                        <div class = 'modal-footer'>\n                            <a href = '#' class = 'btn' data-dismiss = 'modal'>" . $L[254] . "</a>\n                            <input class = 'btn' type = 'submit' value = '" . $L[146] . "' />\n                        </div>\n                    </form>\n                </div>\n                <div class = 'modal hide' id = 'AccountInfo'>\n                    <div class = 'modal-header'>\n                        <button type = 'button' class = 'close' data-dismiss = 'modal'>×</button>\n                        <h3>" . $_SESSION['R']['Username'] . "</h3>\n                    </div>\n                    <div class = 'modal-body'>\n                        <table class = 'table table-hover'>\n                            <tr class = 'menuBar'>\n                                <td>#</td>\n                                <td>" . $_SESSION['R']['ID'] . "</td>\n                            </tr><tr>\n                                <td>" . $L[271] . "</td>\n                                <td>" . $InfoAccountResult['email'] . "</td>\n                            </tr><tr>\n                                <td>" . $L[272] . "</td>\n                                <td>" . $InfoAccountResult['joindate'] . "</td>\n                            </tr><tr>\n                                <td>" . $L[273] . "</td>\n                                <td>" . $InfoAccountResult['last_login'] . "</td>\n                            </tr><tr>\n                                <td>" . $L[274] . "</td>\n                                <td>" . $InfoAccountResult['last_ip'] . "</td>\n                            </tr>\n                            </tr><tr>\n                                <td><i class = 'icon-fire'></i></td>\n                                <td>" . $InfoAccountResult['myth_coins'] . "</td>\n                            </tr>\n                        </table>\n                    </div>\n                </div>\n                <script>\n                \$('ModifyFirePoints').click(function() {\n                    \$('#ModifyFirePoints').modal('toggle');\n                })\n                \$('AccountInfo').click(function() {\n                    \$('#AccountInfo').modal('toggle');\n                })\n                </script>";
        }
        $D = !isset($_SESSION['R']['Username']) ? "disabled = 'disabled'" : "";
        echo "\n            <form action = " . $_SERVER['PHP_SELF'] . " method = 'POST'>\n                <input name = 'U' type = 'text' size = '60' placeholder = '" . $PLACEHOLDER . "'>\n                <input class = 'btn btn-info BillingB' type = 'submit' value = '" . $L[220] . "' />\n                <a href = '?CL'><input class = 'btn btn-inverse BillingB' " . $D . " value = '" . $L[251] . "'/></a>\n                <a class = 'btn BillingB' data-toggle = 'modal' href = '#ModifyFirePoints' " . $D . ">" . $L[252] . "<i class = 'icon-fire'></i></a>\n                <a class = 'btn BillingB' data-toggle = 'modal' href = '#AccountInfo' " . $D . ">" . $L[261] . "</a>\n            </form>";
        $STR_P1 = isset($_SESSION['R']['ID']) ? "`id` = " . (int) $_SESSION['R']['ID'] : "";
        $STR_P2 = _AH_REALMID(isset($RealmID) ? $RealmID : -1);
        if (!empty($STR_P1) || !empty($STR_P2)) {
            $Q_STR .= " WHERE ";
        }
        $Q_STR .= $STR_P1;
        if (!empty($STR_P1) && !empty($STR_P2)) {
            $Q_STR .= " AND ";
        }
        $Q_STR .= $STR_P2;
    } else {
        $Q_STR .= " WHERE `id` = " . (int) _getAccountID();
        if (isset($RealmID)) {
            $Q_STR .= " AND ";
        }
        $Q_STR .= _AH_REALMID(isset($RealmID) ? $RealmID : -1);
    }
    $Q_STR .= " ORDER BY `whenItDone` DESC;";
    echo "\n            </div>\n            <ul class = 'nav nav-tabs'>";
    echo !isset($RealmID) ? "<li class = 'active'>" : "<li>";
    echo "<a href = '?ALL'>" . $L[110] . "</a></li>";
    foreach ($_SESSION['R']['W'] as $ID => $NA) {
        echo $RealmID === (int) $ID ? "<li class = 'active'>" : "<li>";
        echo "<a href = '?R=" . $ID . "'>" . $NA['N'] . "</a></li>";
    }
    echo "</ul>";
    $query = mysql_query($Q_STR, $connection) or die(mysql_error());
    $row_num = mysql_num_rows($query);
    if ($row_num < 1) {
        echo _getAlreadyEffectSTR("<h2>" . $L[163] . "</h2>");
    } else {
        echo "\n            <fieldset>\n            <table class = 'table table-hover'>\n                <tr class = 'menuBar'>\n                    <td>" . $L[140] . "</td>\n                    <td>" . $L[141] . "</td>\n                    <td>" . $L[119] . "</td>\n                    <td>" . $L[142] . "</td>\n                    <td>" . $L[64] . "</td>\n                    <td>" . $L[260] . "</td>\n                    <td>" . $L[143] . "</td>\n                </tr>";
        while ($result = mysql_fetch_array($query)) {
            if ($result['action'] === 14 && _isset($result['text'])) {
                $STR = explode('_REPLACE_', $result['text']);
                $result['text'] = $STR[0] . _getWHLanguage() . $STR[1];
            }
            echo "<tr class = '" . _AH_TR_STR($result, $result['action']) . "'>\n                            <td>" . $result[0] . "</td>\n                            <td>" . _AH_STR($result['action'], !empty($result['text']) ? $result['text'] : "") . "</td>\n                            <td>" . $result['realmName'] . "</td>\n                            <td>" . $result['charName'] . "</td>\n                            <td>" . _AH_PRICE_STR($result['myth_coins_spend']) . "</td>\n                            <td>" . $result['myth_coins_balance'] . " <i class = 'icon-fire'></i></td>\n                            <td>" . $result['IP'] . "</td>\n                        </tr>";
        }
        echo "\n            </table>\n            </fieldset>";
    }
}
function tor_getRatio($t)
{
    return round(_isset($t, btpdControl::TOTUP, 0) / _isset($t, btpdControl::CSIZE, 0), 2);
}
Exemple #7
0
 public function deleteResource($uri)
 {
     $client = new Client();
     $request = $client->delete($this->getServiceUrl($uri), array("User-Agent" => "Marmotta Client Library (PHP)"));
     // set authentication if given in configuration
     if (!_isset($this->config->getUsername())) {
         $request->setAuth($this->config->getUsername(), $this->config->getPassword());
     }
     $response = $request->send();
     if ($response->getStatusCode() >= 400) {
         throw new Exception("could not delete resource {$uri}; " . $response->getReasonPhrase());
     }
 }
Exemple #8
0
$main_timer = timer_init();
if (file_exists(platform_getConfigFile())) {
    read_config_file();
} else {
    setup_default_config();
}
if (isset($config_values['Settings']['Verbose'])) {
    $verbosity = $config_values['Settings']['Verbose'];
}
parse_args();
_debug(date("F j, Y, g:i a") . "\n", 0);
if (isset($config_values['Feeds'])) {
    load_feeds($config_values['Feeds'], 1);
    feeds_perform_matching($config_values['Feeds']);
}
if (_isset($config_values['Settings'], 'Run Torrentwatch', FALSE) and !$test_run and $config_values['Settings']['Watch Dir']) {
    global $hit;
    $hit = 0;
    foreach ($config_values['Favorites'] as $fav) {
        $guess = guess_match(html_entity_decode($_GET['title']));
        $name = trim(strtr($guess['key'], "._", "  "));
        if ($name == $fav['Name']) {
            $downloadDir = $fav['Save In'];
        }
    }
    if (!$downloadDir || $downloadDir == "Default") {
        $downloadDir = $config_values['Settings']['Download Dir'];
    }
    check_for_torrents($config_values['Settings']['Watch Dir'], $downloadDir);
    if (!$hit) {
        _debug("No New Torrents to add from watch folder\n", 0);