Esempio n. 1
0
include_once './lib/functions.php';
include_once './lib/class.dlfile.php';
if (count($argv) >= 2) {
    print "\n";
    printd("start\n");
    $fileId = (int) $argv[1];
    if (!$fileId) {
        exit;
    }
    $dbh = dbConnect();
    $file = new dlfile($CONFIG['DB_HOST'], $CONFIG['DB_NAME'], $CONFIG['DB_USER'], $CONFIG['DB_PASS']);
    $hosters = getDbTable($dbh, 'hosters');
    dbClose($dbh);
    if ($file->loadById($fileId)) {
        $file->packetLoad();
        $packetDirBn = getPacketFilename($file->packet->get('id'), $file->packet->get('name'));
        $packetDownloadDir = 'downloads/loading/' . $packetDirBn;
        $packetFinishedDir = 'downloads/finished/' . $packetDirBn;
        printd("packet id: " . $file->packet->get('id') . "\n");
        printd("file id: {$fileId}\n");
        printd("download dir: '{$packetDownloadDir}'\n");
        printd("speed: " . $file->packet->get('speed') . "\n");
        printd("uri: '" . $file->get('uri') . "'\n");
        if (!file_exists($packetDownloadDir)) {
            mkdir($packetDownloadDir);
            chmod($packetDownloadDir, 0755);
        }
        $thisHoster = null;
        foreach ($hosters as $id => $hostersThisHoster) {
            if (preg_match('/' . $hostersThisHoster['searchPattern'] . '/i', $file->get('uri'))) {
                $thisHoster = $hostersThisHoster;
Esempio n. 2
0
function main()
{
    global $CONFIG, $SCHEDULER_LAST;
    print "\n";
    printd("start\n");
    printd("cwd: " . getcwd() . "\n");
    $date = date('Ymd');
    fileWrite($CONFIG['PHPDL_STACK_PIDFILE'], posix_getpid());
    $n = 0;
    while (!$SHUTDOWN) {
        $n++;
        $dbh = dbConnect();
        $scheduler = scheduler($dbh);
        $filesDownloading = filesDownloading($dbh);
        if ($SCHEDULER_LAST != $scheduler) {
            plog("scheduler '{$scheduler}' matched\n");
            $SCHEDULER_LAST = $scheduler;
        }
        $res = mysql_query("select id from packets where archive = '0' and active = '1' and ftime = '0' order by sortnr, id;", $dbh);
        if (mysql_num_rows($res)) {
            while ($row = mysql_fetch_assoc($res)) {
                $packet = new dlpacket($CONFIG['DB_HOST'], $CONFIG['DB_NAME'], $CONFIG['DB_USER'], $CONFIG['DB_PASS']);
                if ($packet->loadById($row['id'])) {
                    $packetDirBn = getPacketFilename($packet->get('id'), $packet->get('name'));
                    $packetDownloadDir = 'downloads/loading/' . $packetDirBn;
                    $packetFinishedDir = 'downloads/finished/' . $packetDirBn;
                    if ($packet->loadFiles()) {
                        if ($packet->filesUnfinished()) {
                            if ($scheduler > 0) {
                                if ($filesDownloading < $CONFIG['DL_SLOTS']) {
                                    if (!$packet->get('stime')) {
                                        $packet->save('stime', mktime());
                                    }
                                    if ($nextfile = $packet->getFileNextUnfinished()) {
                                        while ($nextfile->get('error')) {
                                            printd("nextfile " . $nextfile->get('id') . "\n");
                                            $nextfile = $packet->getFileNextUnfinished();
                                            if (!$nextfile) {
                                                break;
                                            }
                                            sleep(1);
                                        }
                                        if ($nextfile) {
                                            printd("packet " . $packet->get('id') . ": download " . $nextfile->get('id') . "\n");
                                            $sh = 'php wget.php ' . $nextfile->get('id') . ' 1>> log/wget.' . $date . '.log 2>> log/wget.' . $date . '.log &';
                                            printd("exec '{$sh}'\n");
                                            system($sh);
                                            sleep(1);
                                            break;
                                        }
                                    }
                                } else {
                                    plog("no free download slots (" . $CONFIG['DL_SLOTS'] . ")\n");
                                }
                            }
                        } else {
                            printd("packet " . $packet->get('id') . ": all files finished\n");
                            if (!$packet->get('stime')) {
                                $packet->set('stime', mktime());
                            }
                            $packet->save('ftime', mktime());
                            $packet->md5Verify();
                            $packet->sizeVerify();
                            if (!$packet->fileErrors()) {
                                if (file_exists($packetFinishedDir)) {
                                    $files = scandir($packetDownloadDir);
                                    foreach ($files as $file) {
                                        if ($file != '.' && $file != '..' && file_exists($packetDownloadDir . '/' . $file)) {
                                            rename($packetDownloadDir . '/' . $file, $packetFinishedDir . '/' . $file);
                                        }
                                    }
                                    reset($files);
                                    rmdir($packetDownloadDir);
                                } else {
                                    rename($packetDownloadDir, $packetFinishedDir);
                                }
                            }
                        }
                    }
                }
                unset($packet);
            }
        } else {
            plog("no active download\n");
        }
        dbClose($dbh);
        $SHUTDOWN = shutdownCheck();
        sleep(5);
    }
    shutdown();
}
Esempio n. 3
0
 $packetC = 0;
 while ($row = mysql_fetch_assoc($res)) {
     if ($packet->reloadById($row['id'])) {
         $packetC++;
         $packet->loadFiles();
         $packetId = $packet->get('id');
         $packetFilesFinished = $packet->filesFinished();
         $packetFilesC = $packet->filesC();
         $packetFilesFinishedPercent = 0;
         $packetFilesErrorsTypes = $packet->getFilesErrorsTypes();
         $packetIsFinished = $packet->isFinished();
         $packetIsOwnedByUser = $user->get('id') == $packet->get('_user');
         if ($packetFilesC) {
             $packetFilesFinishedPercent = (int) ($packetFilesFinished / $packetFilesC * 100);
         }
         $packetDirBn = getPacketFilename($packetId, $packet->get('name'));
         $packetDownloadDir = 'downloads/loading/' . $packetDirBn;
         $packetFinishedDir = 'downloads/finished/' . $packetDirBn;
         $move = '';
         if ($packetNum > 1) {
             if ($packetC == 1) {
                 $move = '<a href="?a=packetMoveExec&amp;id=' . $packetId . '&amp;sortnr=' . $packet->get('sortnr') . '&amp;dir=d"><img src="img/button_down.gif" border="0" /></a>';
             } elseif ($packetC <= $packetNum - 1) {
                 $move = '<a href="?a=packetMoveExec&amp;id=' . $packetId . '&amp;sortnr=' . $packet->get('sortnr') . '&amp;dir=d"><img src="img/button_down.gif" border="0" /></a> <a href="?a=packetMoveExec&amp;id=' . $packetId . '&amp;sortnr=' . $packet->get('sortnr') . '&amp;dir=u"><img src="img/button_up.gif" border="0" /></a>';
             } else {
                 $move = '<a href="?a=packetMoveExec&amp;id=' . $packetId . '&amp;sortnr=' . $packet->get('sortnr') . '&amp;dir=u"><img src="img/button_up.gif" border="0" /></a>';
             }
         }
         $trClass = '';
         $status = array();
         if (!$packet->get('stime')) {