/**
  * Maintenance
  *
  * @param $trestart
  * @return mixed
  */
 function _maintenance($trestart)
 {
     // initialize service-mod (why here ? see "fluxd-single-thread-problem")
     FluxdServiceMod::initializeServiceMod('Qmgr');
     require_once "inc/classes/MaintenanceAndRepair.php";
     MaintenanceAndRepair::maintenance($trestart ? MAINTENANCEANDREPAIR_TYPE_EXT : MAINTENANCEANDREPAIR_TYPE_STD);
     return true;
 }
 /**
  * repair
  */
 function repair()
 {
     global $instanceMaintenanceAndRepair;
     // initialize
     MaintenanceAndRepair::initialize();
     // repair run
     $instanceMaintenanceAndRepair->instance_repair();
 }
/**
 * maintenance
 *
 * @param $action
 */
function sa_maintenance($action = "")
{
    global $cfg, $error, $statusImage, $statusMessage, $htmlTitle, $htmlTop, $htmlMain;
    if ($action == "") {
        return;
    }
    buildPage("m");
    switch ($action) {
        case "0":
            // Maintenance-main
            $htmlTitle = "Maintenance";
            $htmlMain .= '<p>Select the maintenance task you wish to perform below:<br><br>';
            $htmlMain .= '<a href="' . _FILE_THIS . '?m=1"><img src="themes/' . $cfg["theme"] . '/images/arrow.gif" width="9" height="9" title="Main" border="0"> Main</a> - clean up stale files; resume stalled transfers';
            $htmlMain .= '<p>';
            $htmlMain .= '<a href="' . _FILE_THIS . '?m=2"><img src="themes/' . $cfg["theme"] . '/images/arrow.gif" width="9" height="9" title="Kill" border="0"> Kill</a> - kill rebel processes';
            $htmlMain .= '<p>';
            $htmlMain .= '<a href="' . _FILE_THIS . '?m=3"><img src="themes/' . $cfg["theme"] . '/images/arrow.gif" width="9" height="9" title="Clean" border="0"> Clean</a> - clean up stale cache/pid/template files';
            $htmlMain .= '<p>';
            $htmlMain .= '<a href="' . _FILE_THIS . '?m=4"><img src="themes/' . $cfg["theme"] . '/images/arrow.gif" width="9" height="9" title="Repair" border="0"> Repair</a> - check for erroneous stat/pid files, fix bad db entries, prune old db items';
            $htmlMain .= '<p>';
            $htmlMain .= '<a href="' . _FILE_THIS . '?m=5"><img src="themes/' . $cfg["theme"] . '/images/arrow.gif" width="9" height="9" title="Reset" border="0"> Reset</a> - reset transfer totals, xfer stats and personal settings';
            $htmlMain .= '<p>';
            $htmlMain .= '<a href="' . _FILE_THIS . '?m=6"><img src="themes/' . $cfg["theme"] . '/images/arrow.gif" width="9" height="9" title="Lock" border="0"> Lock</a> - lock access to the frontend';
            $htmlMain .= '<br><br>';
            break;
        case "1":
            // Maintenance: Main
            $htmlTitle = "Maintenance - Main";
            $htmlMain .= '<p>';
            $htmlMain .= '<strong>Standard</strong><br>';
            $htmlMain .= 'Standard Maintenance Run - same as on index-page and automatic called on every login<br>';
            $htmlMain .= '<a href="' . _FILE_THIS . '?m=11"><img src="themes/' . $cfg["theme"] . '/images/arrow.gif" width="9" height="9" title="Standard Maintenance-Run" border="0"> Standard Maintenance Run</a>';
            $htmlMain .= '<p>';
            $htmlMain .= '<strong>Extended</strong><br>';
            $htmlMain .= 'Extended Maintenance Run - like a standard run but will also restart all dead transfers.<br>';
            $htmlMain .= '<a href="' . _FILE_THIS . '?m=12"><img src="themes/' . $cfg["theme"] . '/images/arrow.gif" width="9" height="9" title="vlc-kill" border="0"> Extended Maintenance Run</a>';
            $htmlMain .= '<br><br>';
            break;
        case "11":
            // Maintenance: Main: Standard Maintenance-Run
            $htmlTitle = "Maintenance - Main - Standard Maintenance Run";
            $htmlMain .= '<br>';
            $htmlMain .= 'Standard Maintenance Run: ';
            require_once "inc/classes/MaintenanceAndRepair.php";
            MaintenanceAndRepair::maintenance(MAINTENANCEANDREPAIR_TYPE_STD);
            $htmlMain .= ' <font color="green">done</font>';
            $htmlMain .= '<br><br>';
            break;
        case "12":
            // Maintenance: Main
            $htmlTitle = "Maintenance - Main - Extended Maintenance Run";
            $htmlMain .= '<br>';
            $htmlMain .= 'Extended Maintenance Run: ';
            require_once "inc/classes/MaintenanceAndRepair.php";
            MaintenanceAndRepair::maintenance(MAINTENANCEANDREPAIR_TYPE_EXT);
            $htmlMain .= ' <font color="green">done</font>';
            $htmlMain .= '<br><br>';
            break;
        case "2":
            // Maintenance-Kill
            $htmlTitle = "Maintenance - Kill";
            $htmlMain .= '<br>';
            $htmlMain .= '<font color="red"><strong>DON\'T</strong> do this or you will screw up things for sure!</font><br><br>';
            $htmlMain .= 'This is only meant as emergency \'last resort\' if things have already gone terribly wrong already.<br>Please use this only if you know what you are doing.<br><br><hr><strong>ALL the selected process types will be killed, not just those related to torrentflux-b4rt!!!</strong><hr><br>';
            $htmlMain .= '<p>';
            $htmlMain .= '<strong>PHP</strong><br>';
            $htmlMain .= 'Kill all PHP processes:<br>';
            $htmlMain .= '<a href="' . _FILE_THIS . '?m=21"><img src="themes/' . $cfg["theme"] . '/images/arrow.gif" width="9" height="9" title="php-kill" border="0"> PHP Kill</a>';
            $htmlMain .= '<p>';
            $htmlMain .= '<strong>Python</strong><br>';
            $htmlMain .= 'Kill all python processes:<br>';
            $htmlMain .= '<a href="' . _FILE_THIS . '?m=22"><img src="themes/' . $cfg["theme"] . '/images/arrow.gif" width="9" height="9" title="python-kill" border="0"> Python Kill</a>';
            $htmlMain .= '<p>';
            $htmlMain .= '<strong>Perl</strong><br>';
            $htmlMain .= 'Kill all perl processes:<br>';
            $htmlMain .= '<a href="' . _FILE_THIS . '?m=23"><img src="themes/' . $cfg["theme"] . '/images/arrow.gif" width="9" height="9" title="perl-kill" border="0"> Perl Kill</a>';
            $htmlMain .= '<p>';
            $htmlMain .= '<strong>Transmissioncli</strong><br>';
            $htmlMain .= 'Kill all transmissioncli processes:<br>';
            $htmlMain .= '<a href="' . _FILE_THIS . '?m=24"><img src="themes/' . $cfg["theme"] . '/images/arrow.gif" width="9" height="9" title="transmissioncli-kill" border="0"> Transmissioncli Kill</a>';
            $htmlMain .= '<p>';
            $htmlMain .= '<strong>Wget</strong><br>';
            $htmlMain .= 'Kill all wget processes:<br>';
            $htmlMain .= '<a href="' . _FILE_THIS . '?m=25"><img src="themes/' . $cfg["theme"] . '/images/arrow.gif" width="9" height="9" title="wget-kill" border="0"> Wget Kill</a>';
            $htmlMain .= '<p>';
            $htmlMain .= '<strong>VLC</strong><br>';
            $htmlMain .= 'Kill all VLC processes:<br>';
            $htmlMain .= '<a href="' . _FILE_THIS . '?m=26"><img src="themes/' . $cfg["theme"] . '/images/arrow.gif" width="9" height="9" title="vlc-kill" border="0"> VLC Kill</a>';
            $htmlMain .= '<br><br>';
            break;
        case "21":
            // Maintenance-Kill: php
            $htmlTitle = "Maintenance - Kill - PHP";
            $htmlMain .= '<br>';
            $htmlMain .= 'Kill all PHP processes: <font color="green">done</font>';
            $htmlMain .= '<br><br>';
            $htmlMain .= '<strong>Process list (filtered) before call:</strong><br>';
            $htmlMain .= '<pre>';
            $htmlMain .= tfb_htmlencode(trim(shell_exec("ps auxww | " . $cfg['bin_grep'] . " php | " . $cfg['bin_grep'] . " -v grep")));
            $htmlMain .= '</pre>';
            $htmlMain .= '<br>';
            $callResult = trim(shell_exec("killall -9 php 2> /dev/null"));
            if (isset($callResult) && $callResult != "") {
                $htmlMain .= '<br>';
                $htmlMain .= 'Call Result: <br>';
                $htmlMain .= '<pre>' . tfb_htmlencode($callResult) . '</pre>';
                $htmlMain .= '<br>';
            }
            sleep(2);
            // just 2 sec
            $htmlMain .= '<strong>Process list (filtered) after call:</strong><br>';
            $htmlMain .= '<pre>';
            $htmlMain .= tfb_htmlencode(trim(shell_exec("ps auxww | " . $cfg['bin_grep'] . " php | " . $cfg['bin_grep'] . " -v grep")));
            $htmlMain .= '</pre>';
            $htmlMain .= '<br>';
            break;
        case "22":
            // Maintenance-Kill: python
            $htmlTitle = "Maintenance - Kill - Python";
            $htmlMain .= '<br>';
            $htmlMain .= 'Kill all python processes: <font color="green">done</font>';
            $htmlMain .= '<br><br>';
            $htmlMain .= '<strong>Process list (filtered) before call:</strong><br>';
            $htmlMain .= '<pre>';
            $htmlMain .= tfb_htmlencode(trim(shell_exec("ps auxww | " . $cfg['bin_grep'] . " python | " . $cfg['bin_grep'] . " -v grep")));
            $htmlMain .= '</pre>';
            $htmlMain .= '<br>';
            $callResult = trim(shell_exec("killall -9 python 2> /dev/null"));
            if (isset($callResult) && $callResult != "") {
                $htmlMain .= '<br>';
                $htmlMain .= 'Call Result: <br>';
                $htmlMain .= '<pre>' . tfb_htmlencode($callResult) . '</pre>';
                $htmlMain .= '<br>';
            }
            sleep(2);
            // just 2 sec
            $htmlMain .= '<strong>Process list (filtered) after call:</strong><br>';
            $htmlMain .= '<pre>';
            $htmlMain .= tfb_htmlencode(trim(shell_exec("ps auxww | " . $cfg['bin_grep'] . " python | " . $cfg['bin_grep'] . " -v grep")));
            $htmlMain .= '</pre>';
            $htmlMain .= '<br>';
            break;
        case "23":
            // Maintenance-Kill: perl
            $htmlTitle = "Maintenance - Kill - Perl";
            $htmlMain .= '<br>';
            $htmlMain .= 'Kill all perl processes: <font color="green">done</font>';
            $htmlMain .= '<br><br>';
            $htmlMain .= '<strong>Process list (filtered) before call:</strong><br>';
            $htmlMain .= '<pre>';
            $htmlMain .= tfb_htmlencode(trim(shell_exec("ps auxww | " . $cfg['bin_grep'] . " perl | " . $cfg['bin_grep'] . " -v grep")));
            $htmlMain .= '</pre>';
            $htmlMain .= '<br>';
            $callResult = trim(shell_exec("killall -9 perl 2> /dev/null"));
            if (isset($callResult) && $callResult != "") {
                $htmlMain .= '<br>';
                $htmlMain .= 'Call Result: <br>';
                $htmlMain .= '<pre>' . tfb_htmlencode($callResult) . '</pre>';
                $htmlMain .= '<br>';
            }
            sleep(2);
            // just 2 sec
            $htmlMain .= '<strong>Process list (filtered) after call:</strong><br>';
            $htmlMain .= '<pre>';
            $htmlMain .= tfb_htmlencode(trim(shell_exec("ps auxww | " . $cfg['bin_grep'] . " perl | " . $cfg['bin_grep'] . " -v grep")));
            $htmlMain .= '</pre>';
            $htmlMain .= '<br>';
            break;
        case "24":
            // Maintenance-Kill: transmissioncli
            $htmlTitle = "Maintenance - Kill - Transmissioncli";
            $htmlMain .= '<br>';
            $htmlMain .= 'Kill all transmissioncli processes: <font color="green">done</font>';
            $htmlMain .= '<br><br>';
            $htmlMain .= '<strong>Process list (filtered) before call:</strong><br>';
            $htmlMain .= '<pre>';
            $htmlMain .= tfb_htmlencode(trim(shell_exec("ps auxww | " . $cfg['bin_grep'] . " transmissioncli | " . $cfg['bin_grep'] . " -v grep")));
            $htmlMain .= '</pre>';
            $htmlMain .= '<br>';
            $callResult = trim(shell_exec("killall -9 transmissioncli 2> /dev/null"));
            if (isset($callResult) && $callResult != "") {
                $htmlMain .= '<br>';
                $htmlMain .= 'Call Result: <br>';
                $htmlMain .= '<pre>' . tfb_htmlencode($callResult) . '</pre>';
                $htmlMain .= '<br>';
            }
            sleep(2);
            // just 2 sec
            $htmlMain .= '<strong>Process list (filtered) after call:</strong><br>';
            $htmlMain .= '<pre>';
            $htmlMain .= tfb_htmlencode(trim(shell_exec("ps auxww | " . $cfg['bin_grep'] . " transmissioncli | " . $cfg['bin_grep'] . " -v grep")));
            $htmlMain .= '</pre>';
            $htmlMain .= '<br>';
            break;
        case "25":
            // Maintenance-Kill: wget
            $htmlTitle = "Maintenance - Kill - Wget";
            $htmlMain .= '<br>';
            $htmlMain .= 'Kill all wget processes: <font color="green">done</font>';
            $htmlMain .= '<br><br>';
            $htmlMain .= '<strong>Process list (filtered) before call:</strong><br>';
            $htmlMain .= '<pre>';
            $htmlMain .= tfb_htmlencode(trim(shell_exec("ps auxww | " . $cfg['bin_grep'] . " wget | " . $cfg['bin_grep'] . " -v grep")));
            $htmlMain .= '</pre>';
            $htmlMain .= '<br>';
            $callResult = trim(shell_exec("killall -9 wget 2> /dev/null"));
            if (isset($callResult) && $callResult != "") {
                $htmlMain .= '<br>';
                $htmlMain .= 'Call Result: <br>';
                $htmlMain .= '<pre>' . tfb_htmlencode($callResult) . '</pre>';
                $htmlMain .= '<br>';
            }
            sleep(2);
            // just 2 sec
            $htmlMain .= '<strong>Process list (filtered) after call:</strong><br>';
            $htmlMain .= '<pre>';
            $htmlMain .= tfb_htmlencode(trim(shell_exec("ps auxww | " . $cfg['bin_grep'] . " wget | " . $cfg['bin_grep'] . " -v grep")));
            $htmlMain .= '</pre>';
            $htmlMain .= '<br>';
            break;
        case "26":
            // Maintenance-Kill: vlc
            $htmlTitle = "Maintenance - Kill - VLC";
            $htmlMain .= '<br>';
            $htmlMain .= 'Kill all VLC processes: <font color="green">done</font>';
            $htmlMain .= '<br><br>';
            $htmlMain .= '<strong>Process list (filtered) before call:</strong><br>';
            $htmlMain .= '<pre>';
            $htmlMain .= tfb_htmlencode(trim(shell_exec("ps auxww | " . $cfg['bin_grep'] . " vlc | " . $cfg['bin_grep'] . " -v grep")));
            $htmlMain .= '</pre>';
            $htmlMain .= '<br>';
            $callResult = trim(shell_exec("killall -9 vlc 2> /dev/null"));
            if (isset($callResult) && $callResult != "") {
                $htmlMain .= '<br>';
                $htmlMain .= 'Call Result: <br>';
                $htmlMain .= '<pre>' . tfb_htmlencode($callResult) . '</pre>';
                $htmlMain .= '<br>';
            }
            sleep(2);
            // just 2 sec
            $htmlMain .= '<strong>Process list (filtered) after call:</strong><br>';
            $htmlMain .= '<pre>';
            $htmlMain .= tfb_htmlencode(trim(shell_exec("ps auxww | " . $cfg['bin_grep'] . " vlc | " . $cfg['bin_grep'] . " -v grep")));
            $htmlMain .= '</pre>';
            $htmlMain .= '<br>';
            break;
        case "3":
            // Maintenance-Clean
            $htmlTitle = "Maintenance - Clean";
            $htmlMain .= '<br>Select the action to perform below:<br><hr><strong>Please stop any running transfers BEFORE cleaning the PID or cache files!!!</strong><hr><br>';
            $htmlMain .= '<strong>Process ID (PID) File Leftovers</strong><br>';
            $htmlMain .= 'Delete stale PID files from deleted transfers:<br>';
            $htmlMain .= '<a href="' . _FILE_THIS . '?m=31"><img src="themes/' . $cfg["theme"] . '/images/arrow.gif" width="9" height="9" title="pid-file-clean" border="0"> PID File Clean</a>';
            $htmlMain .= '<p>';
            $htmlMain .= '<strong>BitTornado</strong><br>';
            $htmlMain .= 'Delete the BitTornado cache:<br>';
            $htmlMain .= '<a href="' . _FILE_THIS . '?m=32"><img src="themes/' . $cfg["theme"] . '/images/arrow.gif" width="9" height="9" title="tornado-clean" border="0"> BitTornado Clean</a>';
            $htmlMain .= '<p>';
            $htmlMain .= '<strong>Transmission</strong><br>';
            $htmlMain .= 'Delete Transmission cache:<br>';
            $htmlMain .= '<a href="' . _FILE_THIS . '?m=33"><img src="themes/' . $cfg["theme"] . '/images/arrow.gif" width="9" height="9" title="transmission-clean" border="0"> Transmission Clean</a>';
            $htmlMain .= '<p>';
            $htmlMain .= '<strong>BitTorrent Mainline</strong><br>';
            $htmlMain .= 'Delete BitTorrent Mainline cache:<br>';
            $htmlMain .= '<a href="' . _FILE_THIS . '?m=34"><img src="themes/' . $cfg["theme"] . '/images/arrow.gif" width="9" height="9" title="mainline-clean" border="0"> BitTorrent Mainline Clean</a>';
            $htmlMain .= '<p>';
            $htmlMain .= '<strong>Template Cache</strong><br>';
            $htmlMain .= 'Delete the Torrentflux-b4rt template cache:<br>';
            $htmlMain .= '<a href="' . _FILE_THIS . '?m=35"><img src="themes/' . $cfg["theme"] . '/images/arrow.gif" width="9" height="9" title="template-cache-clean" border="0"> Template Cache Clean</a>';
            $htmlMain .= '<br><br>';
            break;
        case "31":
            // Maintenance-Clean: pid-file-clean
            $htmlTitle = "Maintenance - Clean - PID Files";
            $htmlMain .= '<br><strong>Cleaning stale PID files:</strong><br>';
            $result = "";
            $transferList = getTransferArrayFromDB();
            if ($dirHandle = @opendir($cfg["transfer_file_path"])) {
                while (false !== ($file = readdir($dirHandle))) {
                    if (strlen($file) > 3 && substr($file, -4, 4) == ".pid") {
                        $tname = substr($file, 0, -4);
                        if (!in_array($tname, $transferList)) {
                            // transfer not in db. delete pid-file.
                            $result .= tfb_htmlencode($file) . "\n";
                            @unlink($cfg["transfer_file_path"] . $file);
                        }
                    }
                }
                closedir($dirHandle);
            }
            if (strlen($result) > 0) {
                $htmlMain .= '<br>Deleted stale PID files: <br><pre>' . $result . '</pre><br>';
            } else {
                $htmlMain .= '<br>No stale PID files found.<br><br>';
            }
            break;
        case "32":
            // Maintenance-Clean: tornado-clean
            $htmlTitle = "Maintenance - Clean - BitTornado";
            $htmlMain .= '<br><strong>Cleaning BitTornado cache:</strong><br>';
            $result = "";
            $result .= cleanDir($cfg["path"] . '.BitTornado/datacache');
            $result .= cleanDir($cfg["path"] . '.BitTornado/torrentcache');
            $result .= cleanDir($cfg["path"] . '.BitTornado/piececache');
            $result .= cleanDir($cfg["path"] . '.BitTornado/icons');
            if (strlen($result) > 0) {
                $htmlMain .= '<br>Deleted cache: <br><pre>' . $result . '</pre><br>';
            } else {
                $htmlMain .= '<br>Nothing found.<br><br>';
            }
            break;
        case "33":
            // Maintenance-Clean: transmission-clean
            $htmlTitle = "Maintenance - Clean - Transmission";
            $htmlMain .= '<br><strong>Cleaning Transmission cache:</strong><br>';
            $result = "";
            $hashes = array();
            $transferList = getTransferArray();
            foreach ($transferList as $transfer) {
                array_push($hashes, getTransferHash($transfer));
            }
            if ($dirHandle = @opendir($cfg["path"] . ".transmission/cache/")) {
                while (false !== ($file = readdir($dirHandle))) {
                    if ($file[0] == "r") {
                        $thash = substr($file, -40);
                        if (!in_array($thash, $hashes)) {
                            // torrent not in db. delete cache-file.
                            $result .= tfb_htmlencode($file) . "\n";
                            @unlink($cfg["path"] . ".transmission/cache/resume." . $thash);
                        }
                    }
                }
                closedir($dirHandle);
            }
            if (strlen($result) > 0) {
                $htmlMain .= '<br>Deleted cache: <br><pre>' . $result . '</pre><br>';
            } else {
                $htmlMain .= '<br>Nothing found.<br><br>';
            }
            break;
        case "34":
            // Maintenance-Clean: mainline-clean
            $htmlTitle = "Maintenance - Clean - BitTorrent Mainline";
            $htmlMain .= '<br><strong>Cleaning BitTorrent Mainline cache:</strong><br>';
            $result = "";
            $result .= cleanDir($cfg["path"] . '.bittorrent/console/resume');
            $result .= cleanDir($cfg["path"] . '.bittorrent/console/metainfo');
            $result .= cleanDir($cfg["path"] . '.bittorrent/console/torrents');
            $result .= cleanDir($cfg["path"] . '.bittorrent/mutex');
            if (strlen($result) > 0) {
                $htmlMain .= '<br>Deleted cache: <br><pre>' . $result . '</pre><br>';
            } else {
                $htmlMain .= '<br>Nothing found.<br><br>';
            }
            break;
        case "35":
            // Maintenance-Clean:template-cache-clean
            $htmlTitle = "Maintenance - Clean - Template Cache";
            $htmlMain .= '<br><strong>Cleaning Torrentflux-b4rt Template Cache:</strong><br>';
            $result = cleanDir($cfg["path"] . '.templateCache');
            if (strlen($result) > 0) {
                $htmlMain .= '<br>Deleted compiled templates: <br><pre>' . $result . '</pre><br>';
            } else {
                $htmlMain .= '<br>No compiled templates found.<br><br>';
            }
            break;
        case "4":
            // Maintenance: Repair
            $htmlTitle = "Maintenance - Repair";
            $htmlMain .= '<br>';
            $htmlMain .= '<hr><font color="red"><strong>DON\'T</strong> do this if your system is running as it should. You WILL break something.</font><hr>';
            $htmlMain .= '<br>The \'Repair\' action will attempt to repair any problems such as out of synch stat files, erroneous PID files, bad hash entries in the database as well as pruning the database.<br><br>Only use this after a server-reboot, if transfers were killed or if there are other problems with the webapp that can\'t be resolved another way.<br>';
            $htmlMain .= '<br><a href="' . _FILE_THIS . '?m=41"><img src="themes/' . $cfg["theme"] . '/images/arrow.gif" width="9" height="9" title="Repair" border="0"> Repair</a>';
            $htmlMain .= '<br><br>';
            break;
        case "41":
            // Maintenance: Repair
            $htmlTitle = "Maintenance - Repair";
            $htmlMain .= '<br>';
            $htmlMain .= 'Repairing Torrentflux-b4rt:';
            require_once "inc/classes/MaintenanceAndRepair.php";
            MaintenanceAndRepair::repair();
            $htmlMain .= ' <font color="green">done</font>';
            $htmlMain .= '<br><br>';
            break;
        case "5":
            // Maintenance: Reset
            $htmlTitle = "Maintenance - Reset";
            $htmlMain .= '<br>Select the item you wish to reset below:<br><br>';
            $htmlMain .= '<strong>Transfer Totals</strong><br>';
            $htmlMain .= 'Reset the transfer totals (totals uploaded/downloaded in the transfer list):<br>';
            $htmlMain .= '<a href="' . _FILE_THIS . '?m=51"><img src="themes/' . $cfg["theme"] . '/images/arrow.gif" width="9" height="9" title="transfer-totals" border="0"> Reset Transfer Totals</a>';
            $htmlMain .= '<p>';
            $htmlMain .= '<strong>Xfer Stats</strong><br>';
            $htmlMain .= 'Reset the transfer statistics:<br>';
            $htmlMain .= '<a href="' . _FILE_THIS . '?m=52"><img src="themes/' . $cfg["theme"] . '/images/arrow.gif" width="9" height="9" title="xfer-stats" border="0"> Reset Xfer Stats</a>';
            $htmlMain .= '<p>';
            $htmlMain .= '<strong>Personal Settings</strong><br>';
            $htmlMain .= 'Reset the personal settings of all users:<br>';
            $htmlMain .= '<a href="' . _FILE_THIS . '?m=53"><img src="themes/' . $cfg["theme"] . '/images/arrow.gif" width="9" height="9" title="personal-settings" border="0"> Reset Personal Settings</a>';
            $htmlMain .= '<br><br>';
            break;
        case "51":
            // Maintenance: Reset - transfer-totals
            $htmlTitle = "Maintenance - Reset - Transfer Totals";
            $htmlMain .= '<br>';
            $htmlMain .= 'Resetting transfer totals:<br>';
            $result = resetAllTransferTotals();
            $htmlMain .= $result === true ? ' <font color="green">Done</font>' : '<br><font color="red">Error:</font><br>' . $result;
            $htmlMain .= '<br><br>';
            break;
        case "52":
            // Maintenance: Reset - xfer
            $htmlTitle = "Maintenance - Reset - Transfer Statistics";
            $htmlMain .= '<br>';
            $htmlMain .= 'Resetting xfer stats:<br>';
            $result = Xfer::resetStats();
            $htmlMain .= $result === true ? ' <font color="green">Done</font>' : '<br><font color="red">Error:</font><br>' . $result;
            $htmlMain .= '<br><br>';
            break;
        case "53":
            // Maintenance: Reset - personal-settings
            $htmlTitle = "Maintenance - Reset - Personal Settings";
            $htmlMain .= '<br>';
            $htmlMain .= 'Resetting personal settings:<br>';
            $result = deleteAllUserSettings();
            $htmlMain .= $result === true ? ' <font color="green">Done</font>' : '<br><font color="red">Error:</font><br>' . $result;
            $htmlMain .= '<br><br>';
            break;
        case "6":
            // Maintenance: Lock
            $htmlTitle = "Maintenance - Lock Torrentflux-b4rt Frontend";
            $htmlMain .= '<br>Lock/unlock access to the Torrentflux-b4rt frontend.  Only the superadmin can access the locked frontend.<br><br><hr>';
            switch ($cfg['webapp_locked']) {
                case 0:
                    $htmlMain .= '<strong><font color="green">Frontend currently unlocked.</font></strong>';
                    break;
                case 1:
                    $htmlMain .= '<strong><font color="red">Frontend currently locked.</font></strong>';
                    break;
            }
            $htmlMain .= '<hr><p>';
            $htmlMain .= '<br><a href="' . _FILE_THIS . '?m=61"><img src="themes/' . $cfg["theme"] . '/images/arrow.gif" width="9" height="9" title="Repair" border="0"> ';
            $htmlMain .= $cfg['webapp_locked'] == 1 ? 'Unlock' : 'Lock';
            $htmlMain .= ' Frontend</a>';
            $htmlMain .= '<br><br>';
            break;
        case "61":
            // Maintenance: lock/unlock
            $htmlTitle = "Maintenance - Lock";
            $htmlMain .= '<br>';
            switch ($cfg['webapp_locked']) {
                case 0:
                    $result = setWebappLock(1);
                    $htmlMain .= "Locking frontend:<br>";
                    $htmlMain .= $result === true ? '<font color="green">Done</font>' : '<br><font color="red">Error:</font><br>' . $result;
                    break;
                case 1:
                    $result = setWebappLock(0);
                    $htmlMain .= "Unlocking frontend:<br>";
                    $htmlMain .= $result === true ? '<font color="green">Done</font>' : '<br><font color="red">Error:</font><br>' . $result;
                    break;
            }
            $htmlMain .= '<br><br>';
            break;
    }
    printPage();
    exit;
}
    $_SESSION['settings']['index_ajax_update'] = $cfg["enable_index_ajax_update"] != 0 ? 1 : 0;
    $_SESSION['settings']['index_show_seeding'] = $cfg["index_show_seeding"] != 0 ? 1 : 0;
    // xfer
    if ($cfg['enable_xfer'] == 1) {
        // xfer-init
        Xfer::init();
    }
} else {
    // Check for valid theme
    if (isset($cfg["theme"])) {
        $cfg["theme"] = CheckandSetUserTheme();
    }
    // Run internal maintenance regularly
    if (!empty($_SESSION['next_int_maintenance']) && $_SESSION['next_int_maintenance'] < time()) {
        require_once "inc/classes/MaintenanceAndRepair.php";
        MaintenanceAndRepair::maintenance(MAINTENANCEANDREPAIR_TYPE_INT);
        $_SESSION['next_int_maintenance'] = null;
    }
}
// schedule next internal maintenance if needed
if (empty($_SESSION['next_int_maintenance'])) {
    $_SESSION['next_int_maintenance'] = time() + 2 * 3600 + mt_rand(-1200, 1200);
}
// 2h (+/- 20m)
// free space in MB var
$cfg["free_space"] = @disk_free_space($cfg["path"]) / 1048576;
// drive space var
$cfg['driveSpace'] = getDriveSpace($cfg["path"]);
// free space formatted var
$cfg['freeSpaceFormatted'] = formatFreeSpace($cfg["free_space"]);
// Fluxd
      ******************************************************************************/
 /*******************************************************************************
  * set
  ******************************************************************************/
 case "set":
     dispatcher_set(tfb_getRequestVar('key'), tfb_getRequestVar('val'));
     break;
     /*******************************************************************************
      * Maintenance
      ******************************************************************************/
 /*******************************************************************************
  * Maintenance
  ******************************************************************************/
 case "maintenance":
     require_once "inc/classes/MaintenanceAndRepair.php";
     MaintenanceAndRepair::maintenance(tfb_getRequestVar('trestart') == "true" ? MAINTENANCEANDREPAIR_TYPE_EXT : MAINTENANCEANDREPAIR_TYPE_STD);
     // set transfers-cache
     cacheTransfersSet();
     break;
     /*******************************************************************************
      * Cache-Flush
      ******************************************************************************/
 /*******************************************************************************
  * Cache-Flush
  ******************************************************************************/
 case "cacheFlush":
     // flush session-cache
     cacheFlush();
     // flush transfers-cache (not really needed as reload is triggered)
     cacheTransfersFlush();
     break;
Exemple #6
0
 /*******************************************************************************
  * set
  ******************************************************************************/
 case "set":
     dispatcher_set(tfb_getRequestVar('key'), tfb_getRequestVar('val'));
     break;
     /*******************************************************************************
      * Maintenance
      ******************************************************************************/
 /*******************************************************************************
  * Maintenance
  ******************************************************************************/
 case "maintenance":
     require_once "inc/classes/MaintenanceAndRepair.php";
     $type = tfb_getRequestVar('type', tfb_getRequestVar('trestart') == "true" ? MAINTENANCEANDREPAIR_TYPE_EXT : MAINTENANCEANDREPAIR_TYPE_STD);
     MaintenanceAndRepair::maintenance($type);
     // set transfers-cache
     cacheTransfersSet();
     break;
     /*******************************************************************************
      * Cache-Flush
      ******************************************************************************/
 /*******************************************************************************
  * Cache-Flush
  ******************************************************************************/
 case "cacheFlush":
     // flush session-cache
     cacheFlush();
     // flush transfers-cache (not really needed as reload is triggered)
     cacheTransfersFlush();
     break;