';
$htmlMain .= '
Select action to perform on all items in the transfer list:
';
$htmlMain .= '
Stop All Transfers';
$htmlMain .= '
';
$htmlMain .= ' Start All Transfers ';
$htmlMain .= '
';
$htmlMain .= ' Resume All Transfers ';
$htmlMain .= 'Note: \'Start All Transfers\' will start all transfers in the transfer list, regardless of whether they have been started previously or not. \'Resume All Transfers\' will only start those transfers that have previously been started and are currently in the \'stopped\' state';
$htmlMain .= '
';
break;
case "1": // Transfers-Stop
$htmlTitle = "Transfers - Stop";
$htmlMain .= 'Transfers Stopped: ';
$htmlMain .= '';
$transferList = getTransferArray();
foreach ($transferList as $transfer) {
if (isTransferRunning($transfer)) {
$ch = ClientHandler::getInstance(getTransferClient($transfer));
$ch->stop($transfer);
$htmlMain .= ' - '.$transfer."";
$htmlMain .= "\n";
}
}
$htmlMain .= ' ';
$htmlMain .= ' ';
break;
case "2": // Transfers-Start
$htmlTitle = "Transfers - Start";
$htmlMain .= 'Transfers Started: ';
$htmlMain .= '';
$transferList = getTransferArray();
foreach ($transferList as $transfer) {
if (!isTransferRunning($transfer)) {
$ch = ClientHandler::getInstance(getTransferClient($transfer));
$ch->start($transfer, false, false);
$htmlMain .= ' - '.$transfer."";
$htmlMain .= "\n";
}
}
$htmlMain .= ' ';
$htmlMain .= ' ';
break;
case "3": // Transfers-Resume
$htmlTitle = "Transfers - Resume";
$htmlMain .= 'Transfers Resumed: ';
$htmlMain .= '';
$transferList = getTransferArray();
$sf = new StatFile("");
foreach ($transferList as $transfer) {
$sf->init($transfer);
if (((trim($sf->running)) == 0) && (!isTransferRunning($transfer))) {
$ch = ClientHandler::getInstance(getTransferClient($transfer));
$ch->start($transfer, false, false);
$htmlMain .= ' - '.$transfer."";
$htmlMain .= "\n";
}
}
$htmlMain .= ' ';
$htmlMain .= ' ';
break;
}
$htmlMain .= 'Transfers: ';
$htmlMain .= '';
$transferList = getTransferArray();
foreach ($transferList as $transfer) {
$htmlMain .= ' - '.$transfer."";
if (isTransferRunning($transfer))
$htmlMain .= " (running)";
$htmlMain .= "\n";
}
$htmlMain .= ' ';
printPage();
exit();
}
/**
* processes
*
* @param $action
*/
function sa_processes($action = "") {
global $cfg, $error, $statusImage, $statusMessage, $htmlTitle, $htmlTop, $htmlMain;
if ($action == "")
return;
buildPage("p");
switch ($action) {
case "0": // Processes-main
$htmlTitle = "Processes";
$htmlMain .= '';
$htmlMain .= 'View currently running torrentflux-b4rt processes: ';
$htmlMain .= ' All - detailed process list';
$htmlMain .= '
';
$htmlMain .= ' Transfers - simple list of running transfers with option to force stop individual transfers';
$htmlMain .= ' ';
break;
case "1": // Processes - All
$htmlTitle = "Processes - All";
$htmlMain .= '
';
$htmlMain .= '
';
$htmlMain .= '
fluxd ';
$htmlMain .= '
';
$htmlMain .= tfb_htmlencode(shell_exec("ps auxww | ".$cfg['bin_grep']." fluxd | ".$cfg['bin_grep']." -v grep"));
$htmlMain .= ' ';
$htmlMain .= '
fluazu ';
$htmlMain .= '
';
$htmlMain .= tfb_htmlencode(shell_exec("ps auxww | ".$cfg['bin_grep']." fluazu.py | ".$cfg['bin_grep']." -v grep"));
$htmlMain .= ' ';
$clients = array('tornado', 'transmission', 'mainline', 'wget', 'nzbperl', 'azureus');
foreach ($clients as $client) {
$ch = ClientHandler::getInstance($client);
$htmlMain .= '
'.$client.' ';
$htmlMain .= ' ';
$htmlMain .= '
';
$htmlMain .= tfb_htmlencode(shell_exec("ps auxww | ".$cfg['bin_grep']." ".tfb_shellencode($ch->binClient)." | ".$cfg['bin_grep']." -v grep"));
$htmlMain .= ' ';
$htmlMain .= '
';
$htmlMain .= '
';
$htmlMain .= $ch->runningProcessInfo();
$htmlMain .= ' ';
}
$htmlMain .= '
';
break;
case "2": // Processes - Transfers
$htmlTitle = "Processes - Transfers";
$htmlMain .= '';
$htmlMain .= '
'.$cfg["_USER"].'
'.$cfg["_FILE"].'
'.$cfg["_FORCESTOP"].'
';
$running = getRunningClientProcesses();
foreach ($running as $rng) {
$rt = RunningTransfer::getInstance($rng['pinfo'], $rng['client']);
$htmlMain .= '';
$htmlMain .= '';
$htmlMain .= tfb_htmlencodekeepspaces($rt->transferowner);
$htmlMain .= '
';
$htmlMain .= '';
$htmlMain .= $rt->transferFile;
$htmlMain .= '
';
$htmlMain .= '';
$htmlMain .= 'transferFile);
$htmlMain .= "&pid=".$rt->processId;
$htmlMain .= '"> ';
$htmlMain .= ' ';
}
$htmlMain .= '
';
$htmlMain .= '
';
break;
}
printPage();
exit();
}
/**
* 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 .= 'Select the maintenance task you wish to perform below: ';
$htmlMain .= ' Main - clean up stale files; resume stalled transfers';
$htmlMain .= '
';
$htmlMain .= ' Kill - kill rebel processes';
$htmlMain .= '
';
$htmlMain .= ' Clean - clean up stale cache/pid/template files';
$htmlMain .= '
';
$htmlMain .= ' Repair - check for erroneous stat/pid files, fix bad db entries, prune old db items';
$htmlMain .= '
';
$htmlMain .= ' Reset - reset transfer totals, xfer stats and personal settings';
$htmlMain .= '
';
$htmlMain .= ' Lock - lock access to the frontend';
$htmlMain .= ' ';
break;
case "1": // Maintenance: Main
$htmlTitle = "Maintenance - Main";
$htmlMain .= '
';
$htmlMain .= 'Standard ';
$htmlMain .= 'Standard Maintenance Run - same as on index-page and automatic called on every login ';
$htmlMain .= ' Standard Maintenance Run ';
$htmlMain .= '
';
$htmlMain .= 'Extended ';
$htmlMain .= 'Extended Maintenance Run - like a standard run but will also restart all dead transfers. ';
$htmlMain .= ' Extended Maintenance Run ';
$htmlMain .= ' ';
break;
case "11": // Maintenance: Main: Standard Maintenance-Run
$htmlTitle = "Maintenance - Main - Standard Maintenance Run";
$htmlMain .= ' ';
$htmlMain .= 'Standard Maintenance Run: ';
require_once("inc/classes/MaintenanceAndRepair.php");
MaintenanceAndRepair::maintenance(MAINTENANCEANDREPAIR_TYPE_STD);
$htmlMain .= ' done ';
$htmlMain .= ' ';
break;
case "12": // Maintenance: Main
$htmlTitle = "Maintenance - Main - Extended Maintenance Run";
$htmlMain .= ' ';
$htmlMain .= 'Extended Maintenance Run: ';
require_once("inc/classes/MaintenanceAndRepair.php");
MaintenanceAndRepair::maintenance(MAINTENANCEANDREPAIR_TYPE_EXT);
$htmlMain .= ' done ';
$htmlMain .= ' ';
break;
case "2": // Maintenance-Kill
$htmlTitle = "Maintenance - Kill";
$htmlMain .= ' ';
$htmlMain .= 'DON\'T do this or you will screw up things for sure! ';
$htmlMain .= 'This is only meant as emergency \'last resort\' if things have already gone terribly wrong already. Please use this only if you know what you are doing.
ALL the selected process types will be killed, not just those related to torrentflux-b4rt!!! ';
$htmlMain .= '';
$htmlMain .= 'PHP ';
$htmlMain .= 'Kill all PHP processes: ';
$htmlMain .= ' PHP Kill ';
$htmlMain .= '
';
$htmlMain .= 'Python ';
$htmlMain .= 'Kill all python processes: ';
$htmlMain .= ' Python Kill ';
$htmlMain .= '
';
$htmlMain .= 'Perl ';
$htmlMain .= 'Kill all perl processes: ';
$htmlMain .= ' Perl Kill ';
$htmlMain .= '
';
$htmlMain .= 'Transmissioncli ';
$htmlMain .= 'Kill all transmissioncli processes: ';
$htmlMain .= ' Transmissioncli Kill ';
$htmlMain .= '
';
$htmlMain .= 'Wget ';
$htmlMain .= 'Kill all wget processes: ';
$htmlMain .= ' Wget Kill ';
$htmlMain .= '
';
$htmlMain .= 'VLC ';
$htmlMain .= 'Kill all VLC processes: ';
$htmlMain .= ' VLC Kill ';
$htmlMain .= ' ';
break;
case "21": // Maintenance-Kill: php
$htmlTitle = "Maintenance - Kill - PHP";
$htmlMain .= ' ';
$htmlMain .= 'Kill all PHP processes: done ';
$htmlMain .= ' ';
$htmlMain .= 'Process list (filtered) before call: ';
$htmlMain .= '
';
$htmlMain .= tfb_htmlencode(trim(shell_exec("ps auxww | ".$cfg['bin_grep']." php | ".$cfg['bin_grep']." -v grep")));
$htmlMain .= ' ';
$htmlMain .= ' ';
$callResult = trim(shell_exec("killall -9 php 2> /dev/null"));
if ((isset($callResult)) && ($callResult != "")) {
$htmlMain .= ' ';
$htmlMain .= 'Call Result: ';
$htmlMain .= ''.tfb_htmlencode($callResult).' ';
$htmlMain .= ' ';
}
sleep(2); // just 2 sec
$htmlMain .= 'Process list (filtered) after call: ';
$htmlMain .= '';
$htmlMain .= tfb_htmlencode(trim(shell_exec("ps auxww | ".$cfg['bin_grep']." php | ".$cfg['bin_grep']." -v grep")));
$htmlMain .= ' ';
$htmlMain .= ' ';
break;
case "22": // Maintenance-Kill: python
$htmlTitle = "Maintenance - Kill - Python";
$htmlMain .= ' ';
$htmlMain .= 'Kill all python processes: done ';
$htmlMain .= ' ';
$htmlMain .= 'Process list (filtered) before call: ';
$htmlMain .= '';
$htmlMain .= tfb_htmlencode(trim(shell_exec("ps auxww | ".$cfg['bin_grep']." python | ".$cfg['bin_grep']." -v grep")));
$htmlMain .= ' ';
$htmlMain .= ' ';
$callResult = trim(shell_exec("killall -9 python 2> /dev/null"));
if ((isset($callResult)) && ($callResult != "")) {
$htmlMain .= ' ';
$htmlMain .= 'Call Result: ';
$htmlMain .= ''.tfb_htmlencode($callResult).' ';
$htmlMain .= ' ';
}
sleep(2); // just 2 sec
$htmlMain .= 'Process list (filtered) after call: ';
$htmlMain .= '';
$htmlMain .= tfb_htmlencode(trim(shell_exec("ps auxww | ".$cfg['bin_grep']." python | ".$cfg['bin_grep']." -v grep")));
$htmlMain .= ' ';
$htmlMain .= ' ';
break;
case "23": // Maintenance-Kill: perl
$htmlTitle = "Maintenance - Kill - Perl";
$htmlMain .= ' ';
$htmlMain .= 'Kill all perl processes: done ';
$htmlMain .= ' ';
$htmlMain .= 'Process list (filtered) before call: ';
$htmlMain .= '';
$htmlMain .= tfb_htmlencode(trim(shell_exec("ps auxww | ".$cfg['bin_grep']." perl | ".$cfg['bin_grep']." -v grep")));
$htmlMain .= ' ';
$htmlMain .= ' ';
$callResult = trim(shell_exec("killall -9 perl 2> /dev/null"));
if ((isset($callResult)) && ($callResult != "")) {
$htmlMain .= ' ';
$htmlMain .= 'Call Result: ';
$htmlMain .= ''.tfb_htmlencode($callResult).' ';
$htmlMain .= ' ';
}
sleep(2); // just 2 sec
$htmlMain .= 'Process list (filtered) after call: ';
$htmlMain .= '';
$htmlMain .= tfb_htmlencode(trim(shell_exec("ps auxww | ".$cfg['bin_grep']." perl | ".$cfg['bin_grep']." -v grep")));
$htmlMain .= ' ';
$htmlMain .= ' ';
break;
case "24": // Maintenance-Kill: transmissioncli
$htmlTitle = "Maintenance - Kill - Transmissioncli";
$htmlMain .= ' ';
$htmlMain .= 'Kill all transmissioncli processes: done ';
$htmlMain .= ' ';
$htmlMain .= 'Process list (filtered) before call: ';
$htmlMain .= '';
$htmlMain .= tfb_htmlencode(trim(shell_exec("ps auxww | ".$cfg['bin_grep']." transmissioncli | ".$cfg['bin_grep']." -v grep")));
$htmlMain .= ' ';
$htmlMain .= ' ';
$callResult = trim(shell_exec("killall -9 transmissioncli 2> /dev/null"));
if ((isset($callResult)) && ($callResult != "")) {
$htmlMain .= ' ';
$htmlMain .= 'Call Result: ';
$htmlMain .= ''.tfb_htmlencode($callResult).' ';
$htmlMain .= ' ';
}
sleep(2); // just 2 sec
$htmlMain .= 'Process list (filtered) after call: ';
$htmlMain .= '';
$htmlMain .= tfb_htmlencode(trim(shell_exec("ps auxww | ".$cfg['bin_grep']." transmissioncli | ".$cfg['bin_grep']." -v grep")));
$htmlMain .= ' ';
$htmlMain .= ' ';
break;
case "25": // Maintenance-Kill: wget
$htmlTitle = "Maintenance - Kill - Wget";
$htmlMain .= ' ';
$htmlMain .= 'Kill all wget processes: done ';
$htmlMain .= ' ';
$htmlMain .= 'Process list (filtered) before call: ';
$htmlMain .= '';
$htmlMain .= tfb_htmlencode(trim(shell_exec("ps auxww | ".$cfg['bin_grep']." wget | ".$cfg['bin_grep']." -v grep")));
$htmlMain .= ' ';
$htmlMain .= ' ';
$callResult = trim(shell_exec("killall -9 wget 2> /dev/null"));
if ((isset($callResult)) && ($callResult != "")) {
$htmlMain .= ' ';
$htmlMain .= 'Call Result: ';
$htmlMain .= ''.tfb_htmlencode($callResult).' ';
$htmlMain .= ' ';
}
sleep(2); // just 2 sec
$htmlMain .= 'Process list (filtered) after call: ';
$htmlMain .= '';
$htmlMain .= tfb_htmlencode(trim(shell_exec("ps auxww | ".$cfg['bin_grep']." wget | ".$cfg['bin_grep']." -v grep")));
$htmlMain .= ' ';
$htmlMain .= ' ';
break;
case "26": // Maintenance-Kill: vlc
$htmlTitle = "Maintenance - Kill - VLC";
$htmlMain .= ' ';
$htmlMain .= 'Kill all VLC processes: done ';
$htmlMain .= ' ';
$htmlMain .= 'Process list (filtered) before call: ';
$htmlMain .= '';
$htmlMain .= tfb_htmlencode(trim(shell_exec("ps auxww | ".$cfg['bin_grep']." vlc | ".$cfg['bin_grep']." -v grep")));
$htmlMain .= ' ';
$htmlMain .= ' ';
$callResult = trim(shell_exec("killall -9 vlc 2> /dev/null"));
if ((isset($callResult)) && ($callResult != "")) {
$htmlMain .= ' ';
$htmlMain .= 'Call Result: ';
$htmlMain .= ''.tfb_htmlencode($callResult).' ';
$htmlMain .= ' ';
}
sleep(2); // just 2 sec
$htmlMain .= 'Process list (filtered) after call: ';
$htmlMain .= '';
$htmlMain .= tfb_htmlencode(trim(shell_exec("ps auxww | ".$cfg['bin_grep']." vlc | ".$cfg['bin_grep']." -v grep")));
$htmlMain .= ' ';
$htmlMain .= ' ';
break;
case "3": // Maintenance-Clean
$htmlTitle = "Maintenance - Clean";
$htmlMain .= ' Select the action to perform below:Please stop any running transfers BEFORE cleaning the PID or cache files!!! ';
$htmlMain .= 'Process ID (PID) File Leftovers ';
$htmlMain .= 'Delete stale PID files from deleted transfers: ';
$htmlMain .= ' PID File Clean ';
$htmlMain .= '';
$htmlMain .= 'BitTornado ';
$htmlMain .= 'Delete the BitTornado cache: ';
$htmlMain .= ' BitTornado Clean ';
$htmlMain .= '
';
$htmlMain .= 'Transmission ';
$htmlMain .= 'Delete Transmission cache: ';
$htmlMain .= ' Transmission Clean ';
$htmlMain .= '
';
$htmlMain .= 'BitTorrent Mainline ';
$htmlMain .= 'Delete BitTorrent Mainline cache: ';
$htmlMain .= ' BitTorrent Mainline Clean ';
$htmlMain .= '
';
$htmlMain .= 'Template Cache ';
$htmlMain .= 'Delete the Torrentflux-b4rt template cache: ';
$htmlMain .= ' Template Cache Clean ';
$htmlMain .= ' ';
break;
case "31": // Maintenance-Clean: pid-file-clean
$htmlTitle = "Maintenance - Clean - PID Files";
$htmlMain .= 'Cleaning stale PID files: ';
$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 .= ' Deleted stale PID files:
'.$result.' ';
else
$htmlMain .= ' No stale PID files found. ';
break;
case "32": // Maintenance-Clean: tornado-clean
$htmlTitle = "Maintenance - Clean - BitTornado";
$htmlMain .= 'Cleaning BitTornado cache: ';
$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 .= ' Deleted cache: '.$result.' ';
else
$htmlMain .= ' Nothing found. ';
break;
case "33": // Maintenance-Clean: transmission-clean
$htmlTitle = "Maintenance - Clean - Transmission";
$htmlMain .= 'Cleaning Transmission cache: ';
$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 .= ' Deleted cache: '.$result.' ';
else
$htmlMain .= ' Nothing found. ';
break;
case "34": // Maintenance-Clean: mainline-clean
$htmlTitle = "Maintenance - Clean - BitTorrent Mainline";
$htmlMain .= 'Cleaning BitTorrent Mainline cache: ';
$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 .= ' Deleted cache: '.$result.' ';
else
$htmlMain .= ' Nothing found. ';
break;
case "35": // Maintenance-Clean:template-cache-clean
$htmlTitle = "Maintenance - Clean - Template Cache";
$htmlMain .= 'Cleaning Torrentflux-b4rt Template Cache: ';
$result = cleanDir($cfg["path"].'.templateCache');
if (strlen($result) > 0)
$htmlMain .= ' Deleted compiled templates: '.$result.' ';
else
$htmlMain .= ' No compiled templates found. ';
break;
case "4": // Maintenance: Repair
$htmlTitle = "Maintenance - Repair";
$htmlMain .= ' ';
$htmlMain .= 'DON\'T do this if your system is running as it should. You WILL break something. ';
$htmlMain .= ' 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. 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. ';
$htmlMain .= ' Repair ';
$htmlMain .= ' ';
break;
case "41": // Maintenance: Repair
$htmlTitle = "Maintenance - Repair";
$htmlMain .= ' ';
$htmlMain .= 'Repairing Torrentflux-b4rt:';
require_once("inc/classes/MaintenanceAndRepair.php");
MaintenanceAndRepair::repair();
$htmlMain .= ' done ';
$htmlMain .= ' ';
break;
case "5": // Maintenance: Reset
$htmlTitle = "Maintenance - Reset";
$htmlMain .= ' Select the item you wish to reset below: ';
$htmlMain .= 'Transfer Totals ';
$htmlMain .= 'Reset the transfer totals (totals uploaded/downloaded in the transfer list): ';
$htmlMain .= ' Reset Transfer Totals ';
$htmlMain .= '';
$htmlMain .= 'Xfer Stats ';
$htmlMain .= 'Reset the transfer statistics: ';
$htmlMain .= ' Reset Xfer Stats ';
$htmlMain .= '
';
$htmlMain .= 'Personal Settings ';
$htmlMain .= 'Reset the personal settings of all users: ';
$htmlMain .= ' Reset Personal Settings ';
$htmlMain .= ' ';
break;
case "51": // Maintenance: Reset - transfer-totals
$htmlTitle = "Maintenance - Reset - Transfer Totals";
$htmlMain .= ' ';
$htmlMain .= 'Resetting transfer totals: ';
$result = resetAllTransferTotals();
$htmlMain .= ($result === true)
? ' Done '
: 'Error: '.$result;
$htmlMain .= ' ';
break;
case "52": // Maintenance: Reset - xfer
$htmlTitle = "Maintenance - Reset - Transfer Statistics";
$htmlMain .= ' ';
$htmlMain .= 'Resetting xfer stats: ';
$result = Xfer::resetStats();
$htmlMain .= ($result === true)
? ' Done '
: 'Error: '.$result;
$htmlMain .= ' ';
break;
case "53": // Maintenance: Reset - personal-settings
$htmlTitle = "Maintenance - Reset - Personal Settings";
$htmlMain .= ' ';
$htmlMain .= 'Resetting personal settings: ';
$result = deleteAllUserSettings();
$htmlMain .= ($result === true)
? ' Done '
: 'Error: '.$result;
$htmlMain .= ' ';
break;
case "6": // Maintenance: Lock
$htmlTitle = "Maintenance - Lock Torrentflux-b4rt Frontend";
$htmlMain .= ' Lock/unlock access to the Torrentflux-b4rt frontend. Only the superadmin can access the locked frontend.
';
switch ($cfg['webapp_locked']) {
case 0:
$htmlMain .= 'Frontend currently unlocked. ';
break;
case 1:
$htmlMain .= 'Frontend currently locked. ';
break;
}
$htmlMain .= '';
$htmlMain .= ' ';
$htmlMain .= ($cfg['webapp_locked'] == 1)
? 'Unlock'
: 'Lock';
$htmlMain .= ' Frontend ';
$htmlMain .= ' ';
break;
case "61": // Maintenance: lock/unlock
$htmlTitle = "Maintenance - Lock";
$htmlMain .= ' ';
switch ($cfg['webapp_locked']) {
case 0:
$result = setWebappLock(1);
$htmlMain .= "Locking frontend: ";
$htmlMain .= ($result === true)
? 'Done '
: 'Error: '.$result;
break;
case 1:
$result = setWebappLock(0);
$htmlMain .= "Unlocking frontend: ";
$htmlMain .= ($result === true)
? 'Done '
: 'Error: '.$result;
break;
}
$htmlMain .= ' ';
break;
}
printPage();
exit();
}
/**
* backup
*
* @param $action
*/
function sa_backup($action = "") {
global $cfg, $error, $statusImage, $statusMessage, $htmlTitle, $htmlTop, $htmlMain;
if ($action == "")
return;
switch ($action) {
case "0": // choose backup-type
buildPage("b");
$htmlTitle = "Backup - Create";
$htmlMain .= ' Select the format and location to save the backup to: ';
$htmlMain .= '
';
$htmlMain .= '
';
$htmlMain .= 'Notes: "Backup on Server" will save the backup archive to the following path: ';
$htmlMain .= ''.tfb_htmlencodekeepspaces($cfg["path"] . _DIR_BACKUP).'/ ';
$htmlMain .= ' ';
$htmlMain .= '"Backup to Client" will create the backup archive and prompt you to save in your web browser.Please wait until the backup is complete. Don\'t click stuff while backup archive is being created - you will be informed if something goes wrong so no need to stress it. ';
$htmlMain .= "
What Data is Backed Up? ";
$htmlMain .= "";
$htmlMain .= "Document root directory structure - all files underneath the webserver document root folder where you installed Torrentflux-b4rt. ";
$htmlMain .= "The Transfers folder directory structure - all files in the .transfers folder located in the path configured in the admin pages 'server' tab. ";
$htmlMain .= "The fluxd folder directory structure - all files in the .fluxd folder located in the path configured in the admin pages 'server' tab. ";
$htmlMain .= "The MRTG folder directory structure - all files in the .mrtg folder located in the path configured in the admin pages 'server' tab. ";
$htmlMain .= "The Torrentflux-b4rt database - the database used to store information used in the day to day running of torrentflux-b4rt. ";
$htmlMain .= " ";
printPage();
exit();
case "1": // server-backup
buildPage("b");
$htmlTitle = "Backup - Create - Server";
printPageStart(1);
echo $htmlMain;
$backupArchive = backupCreate(true, tfb_getRequestVar('c'));
if ($backupArchive == "") {
sendLine(' ');
sendLine('Backup - Error ');
sendLine($error);
} else {
sendLine(' ');
sendLine('Backup Created ');
sendLine(' Archive of backup is '.tfb_htmlencodekeepspaces($backupArchive).' ');
sendLine(' ');
sendLine(backupListDisplay());
}
printPageEnd(1);
exit();
case "2": // client-backup
$backupArchive = backupCreate(false, tfb_getRequestVar('c'));
if ($backupArchive == "") {
buildPage("-b");
$htmlTitle = "Backup - Create - Client";
$htmlMain .= ' ';
$htmlMain .= 'Backup - Error ';
$htmlMain .= $error;
printPage();
} else {
backupSend($backupArchive,true);
}
exit();
case "3": // backup-list
$htmlTitle = "Backup - Backups on Server";
buildPage("b");
$htmlMain .= ' ';
$htmlMain .= backupListDisplay();
printPage();
exit();
case "4": // download backup
$backupArchive = tfb_getRequestVar('f');
if (backupParamCheck($backupArchive)) {
backupSend($backupArchive,false);
} else {
buildPage("-b");
$htmlTitle = "Backup - Download";
$htmlMain .= ' ';
$htmlMain .= 'Backup - Error ';
$htmlMain .= tfb_htmlencodekeepspaces($backupArchive).' is not a valid Backup-ID';
printPage();
}
exit();
case "5": // delete backup
$backupArchive = tfb_getRequestVar('f');
if (backupParamCheck($backupArchive)) {
backupDelete($backupArchive);
buildPage("b");
$htmlTitle = "Backup - Delete";
$htmlMain .= ' ';
$htmlMain .= ''.tfb_htmlencodekeepspaces($backupArchive).' deleted.';
$htmlMain .= ' ';
$htmlMain .= backupListDisplay();
} else {
buildPage("-b");
$htmlTitle = "Backup - Delete";
$htmlMain .= ' ';
$htmlMain .= 'Backup - Error ';
$htmlMain .= tfb_htmlencodekeepspaces($backupArchive).' is not a valid Backup-ID';
}
printPage();
exit();
}
exit();
}
/**
* log
*
* @param $action
*/
function sa_log($action = "") {
global $cfg, $error, $statusImage, $statusMessage, $htmlTitle, $htmlTop, $htmlMain;
if ($action == "")
return;
buildPage("l");
switch ($action) {
case "0": // log-main
$htmlTitle = "Log Viewer";
$htmlMain .= ' Select the type of log you want to view below:';
$htmlMain .= ' fluxd - STDOUT logfiles for the torrentflux-b4rt fluxd daemon';
$htmlMain .= '
';
$htmlMain .= ' fluxd-error - STDERR logfiles for the torrentflux-b4rt fluxd daemon';
$htmlMain .= '
';
$htmlMain .= ' fluazu - logfiles for the fluazu interface to Azureus';
$htmlMain .= '
';
$htmlMain .= ' BitTorrent Mainline - centralised logfile for the BitTorrent Mainline client';
$htmlMain .= '
';
$htmlMain .= ' Transfers - logfiles for transfers in the current transfer list';
$htmlMain .= ' ';
break;
case "1": // fluxd-log
$htmlTitle = "log - fluxd";
$htmlMain .= '
';
$htmlMain .= '
';
$htmlMain .= tfb_htmlencode(@file_get_contents($cfg["path"].'.fluxd/fluxd.log'));
$htmlMain .= ' ';
$htmlMain .= '
';
break;
case "2": // fluxd-error-log
$htmlTitle = "log - fluxd - error-log";
$htmlMain .= '';
$htmlMain .= '
';
$htmlMain .= tfb_htmlencode(@file_get_contents($cfg["path"].'.fluxd/fluxd-error.log'));
$htmlMain .= ' ';
$htmlMain .= '
';
break;
case "3": // fluazu-log
$htmlTitle = "log - fluazu";
$htmlMain .= '';
$htmlMain .= '
';
$htmlMain .= tfb_htmlencode(@file_get_contents($cfg["path"].'.fluazu/fluazu.log'));
$htmlMain .= ' ';
$htmlMain .= '
';
break;
case "5": // mainline-log
$htmlTitle = "log - mainline";
$htmlMain .= '';
$htmlMain .= '
';
$mainlineLog = $cfg["path"].'.bittorrent/tfmainline.log';
if (is_file($mainlineLog))
$htmlMain .= tfb_htmlencode(@file_get_contents($mainlineLog));
else
$htmlMain .= "mainline-log not found.";
$htmlMain .= ' ';
$htmlMain .= '
';
break;
case "8": // transfers
$htmlTitle = "log - transfers";
$htmlMain .= " Select the transfer you wish to view the logfile for from below: ";
$logList = getTransferArray('na');
if ((isset($logList)) && (is_array($logList))) {
$htmlMain .= '';
}
break;
case "9": // transfer-log
if (isset($_REQUEST["transfer"])) {
$transfer = trim(tfb_getRequestVarRaw('transfer'));
// shorten name if too long
if(strlen($transfer) >= 70)
$htmlTitle = "log - transfer-log - ".tfb_htmlencodekeepspaces(substr($transfer, 0, 67))."...";
else
$htmlTitle = "log - transfer-log - ".tfb_htmlencodekeepspaces($transfer);
$htmlMain .= '';
$htmlMain .= '
';
$htmlMain .= tfb_htmlencode(getTransferLog($transfer));
$htmlMain .= ' ';
$htmlMain .= '
';
} else {
$htmlTitle = "log - transfer-log";
$htmlMain .= 'Error. missing params ';
}
break;
}
printPage();
exit();
}
/**
* misc
*
* @param $action
*/
function sa_misc($action = "") {
global $cfg, $error, $statusImage, $statusMessage, $htmlTitle, $htmlTop, $htmlMain;
if ($action == "")
return;
buildPage("y");
switch ($action) {
case "0": // misc-main
$htmlTitle = "Miscellaneous Admin Tasks";
$htmlMain .= ' Select the task you wish to perform from below:';
$htmlMain .= ' Lists - view a list of currently installed torrentflux-b4rt files';
$htmlMain .= '
';
$htmlMain .= ' Checksum Validation - check the integrity of installed torrentflux-b4rt files';
$htmlMain .= '
';
$htmlMain .= ' Check Requirements - check your server meets the requirements to run torrentflux-b4rt';
$htmlMain .= ' ';
break;
case "1": // misc - Lists
$htmlTitle = "Misc - File Lists";
$htmlMain .= ' Select an option from below:
';
$htmlMain .= ' Files (';
$htmlMain .= 'html ';
$htmlMain .= ' / ';
$htmlMain .= 'text ';
$htmlMain .= ') - list files currently installed';
$htmlMain .= '
';
$htmlMain .= ' Checksums (';
$htmlMain .= 'html ';
$htmlMain .= ' / ';
$htmlMain .= 'text ';
$htmlMain .= ') - list checksums of files currently installed';
$htmlMain .= ' ';
break;
case "11": // Misc - File-List - html
printFileList($cfg['docroot'], 1, 2);
exit();
case "12": // Misc - File-List - text
@header("Content-Type: text/plain");
printFileList($cfg['docroot'], 1, 1);
exit();
case "13": // Misc - Checksums-List - html
printFileList($cfg['docroot'], 2, 2);
exit();
case "14": // Misc - Checksums-List - text
@header("Content-Type: text/plain");
printFileList($cfg['docroot'], 2, 1);
exit();
case "3": // Misc - Checksums
$htmlTitle = "Misc - Checksum Validation";
$htmlMain .= '
';
$htmlMain .= ' Checksums of '._VERSION.' ';
$htmlMain .= '
';
$htmlMain .= ' Validate local files ';
$htmlMain .= ' ';
break;
case "35": // Misc - Checksums - Latest
@header("Content-Type: text/plain");
echo getDataFromUrl(_SUPERADMIN_URLBASE._FILE_CHECKSUMS_PRE._VERSION._FILE_CHECKSUMS_SUF);
exit();
case "36": // Misc - Checksums - Validate
validateLocalFiles();
exit();
case "5": // misc - Check
$htmlTitle = "Misc - Check Requirements";
$htmlMain .= ' Select the requirements you wish to check from below:
';
$htmlMain .= "PHP Web Check your PHP web installation meets the requirements for web based activities in torrentflux-b4rt: ";
$htmlMain .= ' Check PHP Web Requirements ';
$htmlMain .= "PHP CLI Check your PHP commandline binary installation meets the requirements for commandline based activities in torrentflux-b4rt: ";
$htmlMain .= ' Check PHP CLI Binary Requirements ';
$htmlMain .= "Perl Check your Perl installation meets the requirements for perl based activities in torrentflux-b4rt: ";
$htmlMain .= ' Check Perl Requirements ';
$htmlMain .= ' ';
break;
case "51": // misc - Check - php-web
$htmlTitle = "Misc - Check Requirements - PHP Web Installation";
$htmlMain .= '
';
$htmlMain .= phpCheckWeb();
$htmlMain .= '
';
break;
case "52": // misc - Check - php-cli
$htmlTitle = "Misc - Check Requirements - PHP CLI Binary Installation";
$htmlMain .= '';
$htmlMain .= '
';
$htmlMain .= tfb_htmlencode(safePhpCli($cfg["bin_php"], tfb_shellencode($cfg["docroot"]."bin/check/check-cli.php")));
$htmlMain .= ' ';
$htmlMain .= '
';
break;
case "53": // misc - Check - Perl
$htmlTitle = "Misc - Check Requirements - Perl";
$htmlMain .= '';
$htmlMain .= '
';
$htmlMain .= tfb_htmlencode(shell_exec($cfg["perlCmd"]." ".tfb_shellencode($cfg["docroot"]."bin/check/check.pl")." all"));
$htmlMain .= ' ';
$htmlMain .= '
';
break;
case "531": // misc - Check - Perl - nzbperl
$htmlTitle = "Misc - Check Requirements - Nzbperl";
$htmlMain .= '';
$htmlMain .= '
';
$htmlMain .= tfb_htmlencode(shell_exec($cfg["perlCmd"]." ".tfb_shellencode($cfg["docroot"]."bin/check/check.pl")." nzbperl"));
$htmlMain .= ' ';
$htmlMain .= '
';
break;
}
printPage();
exit();
}
/**
* tfb
*
* @param $action
*/
function sa_tfb($action = "") {
global $cfg, $error, $statusImage, $statusMessage, $htmlTitle, $htmlTop, $htmlMain;
if ($action == "")
return;
buildPage("z");
switch ($action) {
case "0": // main
$htmlTitle = "About";
$htmlMain .= ' Select the information you wish to view from below:';
$htmlMain .= ' Version - check your torrentflux-b4rt version is up to date';
$htmlMain .= '
';
$htmlMain .= ' News - view the release news for each version of torrentflux-b4rt';
$htmlMain .= '
';
$htmlMain .= ' Changelog - view the changelogs for each version of torrentflux-b4rt';
$htmlMain .= ' ';
break;
case "1": // Version
$htmlTitle = "About - Version";
// version-check
$versionAvailable = trim(getDataFromUrl(_SUPERADMIN_URLBASE._SUPERADMIN_PROXY));
if ((isset($versionAvailable)) && ($versionAvailable != "")) {
// set image
if ($versionAvailable == _VERSION || (substr(_VERSION, 0, 3)) == "svn")
$statusImage = "green.gif";
else
$statusImage = "red.gif";
// version-text
$htmlMain .= ' ';
if (strpos(_VERSION, "svn") !== false) {
$htmlMain .= 'This Version: '._VERSION;
$htmlMain .= ' ';
$htmlMain .= 'Latest Release: ';
$htmlMain .= $versionAvailable;
$htmlMain .= ' ';
$htmlMain .= 'This Version is a svn-Version. ';
} else {
if ($versionAvailable != _VERSION) {
$htmlMain .= 'This Version: ';
$htmlMain .= ''._VERSION.' ';
$htmlMain .= ' ';
$htmlMain .= 'Available Version: ';
$htmlMain .= $versionAvailable;
$htmlMain .= ' ';
$htmlMain .= 'There is a new Version available ! ';
$htmlMain .= ' ';
$htmlMain .= '
';
$htmlMain .= 'Current Release: ';
$htmlMain .= ' ';
$htmlMain .= ' '._URL_RELEASE.' ';
$htmlMain .= ' ';
$htmlMain .= 'Homepage: ';
$htmlMain .= ' ';
$htmlMain .= ' '._URL_HOME.' ';
$htmlMain .= ' ';
} else {
$htmlMain .= 'This Version: '._VERSION;
$htmlMain .= ' ';
$htmlMain .= 'Available Version: ';
$htmlMain .= $versionAvailable;
$htmlMain .= ' ';
$htmlMain .= 'This Version looks good. ';
}
}
$htmlMain .= ' ';
} else { // could not get the version
$statusImage = "black.gif";
$htmlTop = 'Error. ';
$htmlMain = ' ';
$htmlMain .= 'Error getting available version. ';
$htmlMain .= ' ';
$htmlMain .= 'Current Release: ';
$htmlMain .= ' ';
$htmlMain .= ' '._URL_RELEASE.' ';
$htmlMain .= ' ';
$htmlMain .= 'Homepage: ';
$htmlMain .= ' ';
$htmlMain .= ' '._URL_HOME.' ';
$htmlMain .= ' ';
}
break;
case "2": // News
$htmlTitle = "About - News";
$htmlMain .= ' ';
$htmlMain .= @gzinflate(getDataFromUrl(_SUPERADMIN_URLBASE . _SUPERADMIN_PROXY ."?a=0"));
$htmlMain .= ' ';
break;
case "3": // Changelog;
$htmlTitle = "About - Changelog";
$htmlMain .= '';
$htmlMain .= '
';
$htmlMain .= tfb_htmlencode(@gzinflate(getDataFromUrl(_SUPERADMIN_URLBASE . _SUPERADMIN_PROXY ."?a=1")));
$htmlMain .= ' ';
$htmlMain .= '
';
break;
}
printPage();
exit();
}
/**
* update
*
* @param $action
*/
function sa_update($action = "") {
global $cfg, $error, $statusImage, $statusMessage, $htmlTitle, $htmlTop, $htmlMain;
if ($action == "")
return;
switch ($action) {
case "0":
// get updateIndex to check if update from this version possible
$updateIndexData = trim(getDataFromUrl(_SUPERADMIN_URLBASE . _SUPERADMIN_PROXY ."?u=0&v=" . _VERSION));
if ((isset($updateIndexData)) && ($updateIndexData != "")) {
$updateIndexVars = explode("\n",$updateIndexData);
$updatePossible = trim($updateIndexVars[0]);
if ($updatePossible != "1") {
buildPage("-u");
printPage();
exit();
} else {
$htmlTop = "Update - Check ";
$htmlMain = " Update from your Version possible.";
$htmlMain .= ' ';
$htmlMain .= '';
$htmlMain .= ' ';
$statusImage = "yellow.gif";
$htmlTitle = "Update";
printPage();
exit();
}
} else {
buildPage("-u");
printPage();
exit();
}
break;
case "1":
// get db-settings
$updateDBData = trim(getDataFromUrl(_SUPERADMIN_URLBASE . _SUPERADMIN_PROXY ."?u=1&v=" . _VERSION));
if ((isset($updateDBData)) && ($updateDBData != "")) {
$updateDBVars = explode("\n",$updateDBData);
$updateNeeded = trim($updateDBVars[0]);
if ($updateNeeded == "0") {
$htmlTop = "Update - Database ";
$htmlMain = " Database-Update in this Update not needed.";
$htmlMain .= ' ';
$htmlMain .= '';
$htmlMain .= ' ';
$statusImage = "yellow.gif";
$htmlTitle = "Update";
printPage();
exit();
} else if ($updateNeeded == "1") {
$htmlTop = "Update - Database ";
$htmlMain = " Database-Update in this Update is needed.";
$htmlMain .= ' ';
$htmlMain .= 'Type: '.$cfg["db_type"].' ';
$htmlMain .= ' ';
$htmlMain .= '';
$htmlMain .= ' ';
$statusImage = "yellow.gif";
$htmlTitle = "Update";
printPage();
exit();
} else {
updateError($updateDBData);
exit();
}
} else {
updateError();
}
break;
case "2":
// get sql-data
$updateSQLData = @trim(gzinflate(getDataFromUrl(_SUPERADMIN_URLBASE . _SUPERADMIN_PROXY ."?u=2&v=" . _VERSION . "&d=".$cfg["db_type"])));
if ((isset($updateSQLData)) && ($updateSQLData != "")) {
sendLine('Update - Database Updating Database... Please Wait... ');
$updateSQLStates = explode("\n",$updateSQLData);
// get ado-connection
$dbCon = getAdoConnection();
if (!$dbCon) {
echo ' Error updating Database. Please restore backup and try again (or do manual update). ';
echo $dbCon->ErrorMsg();
exit();
} else {
foreach ($updateSQLStates as $sqlState) {
$sqlState = trim($sqlState);
if ((isset($sqlState)) && ($sqlState != "") && ((substr($sqlState, 0, 2)) != "--")) {
sendLine(''.$sqlState);
$dbCon->Execute($sqlState);
if($dbCon->ErrorNo() == 0) {
sendLine(' Ok ');
} else { // damn there was an error
// close ado-connection
$dbCon->Close();
// talk and out
echo 'Error updating Database. Please restore backup and try again (or do manual update). ';
exit();
}
}
}
// close ado-connection
$dbCon->Close();
// talk and continue
sendLine('Database-Update done. ');
sendLine('
');
exit();
}
} else {
updateError("\n"."cant get update-sql."."\n".$updateSQLData);
}
break;
case "3":
// get file-list
$updateFileList = @trim(gzinflate(getDataFromUrl(_SUPERADMIN_URLBASE . _SUPERADMIN_PROXY ."?u=3&v=" . _VERSION)));
if ((isset($updateFileList)) && ($updateFileList != "")) {
sendLine('Update - Files ');
sendLine(' ');
sendLine('Files that require an update in this Version:');
sendLine('');
sendLine($updateFileList);
sendLine(' ');
sendLine('');
sendLine('Ensure script can write to docroot '.$cfg['docroot'].' now ! ');
exit();
} else {
updateError("\n"."cant get file-list."."\n".$updateFileList);
}
break;
case "4":
sendLine('Update - Files Updating Files... Please Wait... ');
sendLine('Getting Update-Archive: ');
@ini_set("allow_url_fopen", "1");
@ini_set("user_agent", "torrentflux-b4rt/". _VERSION);
// get md5
$md5hash = getDataFromUrl(_SUPERADMIN_URLBASE . _SUPERADMIN_PROXY ."?u=4&v=" . _VERSION);
if ((!isset($md5hash)) || (strlen($md5hash) != 32)) {
sendLine(' Error getting Update-Archive. Please restore backup and try again (or do manual update). ');
exit();
}
// download archive
$fileHandle = @fopen($cfg['docroot']._UPDATE_ARCHIVE, "w");
$urlHandle = @fopen(_SUPERADMIN_URLBASE . _SUPERADMIN_PROXY ."?u=5&v=" . _VERSION, 'r');
if (($fileHandle) && ($urlHandle)) {
$results = array();
$i = 0;
stream_set_timeout($urlHandle, 15);
$info = stream_get_meta_data($urlHandle);
while ((!feof($urlHandle)) && (!$info['timed_out'])) {
$data = @fgets($urlHandle, 8192);
$results[$i] = @fwrite($fileHandle, $data);
$info = stream_get_meta_data($urlHandle);
sendLine('.');
$i++;
}
@fclose($fileHandle);
@fclose($urlHandle);
$done = true;
foreach ($results as $result) {
if ($result === false)
$done = false;
}
if ($done) {
sendLine('done ');
} else {
sendLine('Error writing archive '.$cfg['docroot']._UPDATE_ARCHIVE.' . Please restore backup and try again (or do manual update). ');
exit();
}
} else {
sendLine('Error updating files. Please restore backup and try again (or do manual update). ');
exit();
}
// validate archive
sendLine('Validating Update-Archive: ');
if ((file_exists($cfg['docroot']._UPDATE_ARCHIVE))
&& ($md5hash == @md5_file($cfg['docroot']._UPDATE_ARCHIVE))) {
sendLine('Ok ('.$md5hash.' ) ');
} else {
sendLine('failed Please restore backup and try again (or do manual update). ');
exit();
}
// extract archive
sendLine('Extracting Update-Archive: ');
sendLine('');
$cmd = 'cd '.tfb_shellencode($cfg['docroot']).' && tar jxvf '._UPDATE_ARCHIVE;
$cmd .= ' 2>&1';
$handle = @popen($cmd, 'r');
while (!@feof($handle)) {
$read = @fread($handle, 64);
sendLine(nl2br($read));
}
@pclose($handle);
sendLine(' ');
sendLine('done ');
// delete archive
sendLine('Deleting Update-Archive: ');
if (@unlink($cfg['docroot']._UPDATE_ARCHIVE))
sendLine('done ');
else
sendLine('failed remove archive '.$cfg['docroot']._UPDATE_ARCHIVE.' manual now.');
// version-file
sendLine('Updating Version-Information: ');
$versionAvailable = trim(getDataFromUrl(_SUPERADMIN_URLBASE._SUPERADMIN_PROXY));
if ((isset($versionAvailable)) && ($versionAvailable != "")) {
if ($handle = @fopen("version.php", "w")) {
if (@fwrite($handle, '')) {
@fclose($handle);
sendLine(' done ');
} else {
@fclose($handle);
sendLine('Error writing version-file Please restore backup and try again (or do manual update). ');
exit();
}
} else {
sendLine(' ');
sendLine('Error writing version-file Please restore backup and try again (or do manual update). ');
exit();
}
} else {
sendLine('Error getting version-file Please restore backup and try again (or do manual update). ');
exit();
}
sendLine('');
// done
sendLine('Done Updating Files.
');
sendLine('Update to '.$versionAvailable.' completed. ');
sendLine('');
sendLine(' ');
// flush cache
cacheFlush();
// exit
exit();
}
exit();
}
/**
* fluxd
*
* @param $action
*/
function sa_fluxd($action = "") {
global $cfg, $error, $statusImage, $statusMessage, $htmlTitle, $htmlTop, $htmlMain;
if ($action == "")
return;
switch ($action) {
case "0": // fluxd-main
$htmlTitle = "fluxd";
break;
case "1": // fluxd-log
$htmlTitle = "fluxd - log";
$htmlMain .= '';
$htmlMain .= '
';
$htmlMain .= tfb_htmlencode(@file_get_contents($cfg["path"].'.fluxd/fluxd.log'));
$htmlMain .= ' ';
$htmlMain .= '
';
break;
case "2": // fluxd-error-log
$htmlTitle = "fluxd - error-log";
$htmlMain .= '';
$htmlMain .= '
';
$htmlMain .= tfb_htmlencode(@file_get_contents($cfg["path"].'.fluxd/fluxd-error.log'));
$htmlMain .= ' ';
$htmlMain .= '
';
break;
case "3": // fluxd-ps
$htmlTitle = "fluxd - ps";
$htmlMain .= '';
$htmlMain .= '
';
$htmlMain .= tfb_htmlencode(shell_exec("ps auxww | ".$cfg['bin_grep']." fluxd | ".$cfg['bin_grep']." -v grep"));
$htmlMain .= ' ';
$htmlMain .= '
';
break;
case "4": // fluxd-status
$htmlTitle = "fluxd - status";
if (Fluxd::isRunning()) {
$htmlMain .= '';
$htmlMain .= '
';
$htmlMain .= tfb_htmlencode(Fluxd::status());
$htmlMain .= ' ';
$htmlMain .= '
';
} else {
$htmlMain .= 'fluxd not running ';
}
break;
case "5": // fluxd-check
$htmlTitle = "fluxd - check";
$htmlMain .= '';
$htmlMain .= '
';
$htmlMain .= tfb_htmlencode(shell_exec($cfg["perlCmd"]." -I ".tfb_shellencode($cfg["docroot"]."bin/fluxd")." -I ".tfb_shellencode($cfg["docroot"]."bin/lib")." ".tfb_shellencode($cfg["docroot"]."bin/fluxd/fluxd.pl")." check"));
$htmlMain .= ' ';
$htmlMain .= '
';
break;
case "6": // fluxd-db-debug
$htmlTitle = "fluxd - db-debug";
$htmlMain .= '';
$htmlMain .= '
';
$htmlMain .= tfb_htmlencode(shell_exec($cfg["perlCmd"]." -I ".tfb_shellencode($cfg["docroot"]."bin/fluxd")." -I ".tfb_shellencode($cfg["docroot"]."bin/lib")." ".tfb_shellencode($cfg["docroot"]."bin/fluxd/fluxd.pl")." debug db ".tfb_shellencode($cfg["docroot"])." ".tfb_shellencode($cfg["path"])." ".tfb_shellencode($cfg["bin_php"])));
$htmlMain .= ' ';
$htmlMain .= '
';
break;
case "9": // fluxd-version
$htmlTitle = "fluxd - version";
$htmlMain .= '';
$htmlMain .= '
';
$htmlMain .= tfb_htmlencode(shell_exec($cfg["perlCmd"]." -I ".tfb_shellencode($cfg["docroot"]."bin/fluxd")." -I ".tfb_shellencode($cfg["docroot"]."bin/lib")." ".tfb_shellencode($cfg["docroot"]."bin/fluxd/fluxd.pl")." version"));
$htmlMain .= ' ';
$htmlMain .= '
';
break;
}
printPage();
exit();
}
/**
* fluazu
*
* @param $action
*/
function sa_fluazu($action = "") {
global $cfg, $error, $statusImage, $statusMessage, $htmlTitle, $htmlTop, $htmlMain;
if ($action == "")
return;
switch ($action) {
case "0": // fluazu-main
$htmlTitle = "fluazu";
break;
case "1": // fluazu-log
$htmlTitle = "fluazu - log";
$htmlMain .= '';
$htmlMain .= '
';
$htmlMain .= tfb_htmlencode(@file_get_contents($cfg["path"].'.fluazu/fluazu.log'));
$htmlMain .= ' ';
$htmlMain .= '
';
break;
case "3": // fluazu-ps
$htmlTitle = "fluazu - ps";
$htmlMain .= '';
$htmlMain .= '
';
$htmlMain .= tfb_htmlencode(shell_exec("ps auxww | ".$cfg['bin_grep']." fluazu.py | ".$cfg['bin_grep']." -v grep"));
$htmlMain .= ' ';
$htmlMain .= '
';
break;
case "9": // fluazu-version
$htmlTitle = "fluazu - version";
$htmlMain .= '';
$htmlMain .= '
';
$htmlMain .= tfb_htmlencode(shell_exec("cd ".tfb_shellencode($cfg["docroot"]."bin/clients/fluazu/")."; ".$cfg["pythonCmd"]." -OO fluazu.py --version"));
$htmlMain .= ' ';
$htmlMain .= '
';
break;
}
printPage();
exit();
}
/**
* superadminAuthentication
*
* @param $message
*/
function superadminAuthentication($message = "") {
if (!IsSuperAdmin()) {
@header("Content-Type: text/plain");
echo "\nAccess Error"."\n\n";
if ((isset($message)) && ($message != ""))
echo $message."\n";
else
echo "Only SuperAdmin can access superadmin-page.\n";
exit();
}
}
/**
* builds page
*
* @param $action
*/
function buildPage($action) {
global $cfg, $statusImage, $statusMessage, $htmlTitle, $htmlTop, $htmlMain;
// navi
$htmlTop .= 'Transfer Bulk-ops ';
$htmlTop .= ' | ';
$htmlTop .= 'Processes ';
$htmlTop .= ' | ';
$htmlTop .= 'Maintenance ';
$htmlTop .= ' | ';
$htmlTop .= 'Backup ';
$htmlTop .= ' | ';
$htmlTop .= 'Log ';
$htmlTop .= ' | ';
$htmlTop .= 'Misc ';
$htmlTop .= ' | ';
$htmlTop .= 'About ';
// body
switch($action) {
case "b": // backup passthru
case "-b": // backup-error passthru
if ($action == "b")
$statusImage = "yellow.gif";
else
$statusImage = "red.gif";
//
$htmlMain .= '';
break;
case "-u": // update-error passthru
$statusImage = "red.gif";
$htmlTitle = "Update";
$htmlMain = 'Update from your version not possible. ';
$htmlMain .= ' ';
$htmlMain .= 'Please use the most recent tarball and perform a manual update.';
$htmlMain .= ' ';
break;
case "t": // transfers passthru
$statusImage = "black.gif";
break;
case "p": // processes passthru
$statusImage = "black.gif";
$htmlMain .= '';
$htmlMain .= 'All ';
$htmlMain .= ' | ';
$htmlMain .= 'Transfers ';
$htmlMain .= ' Processes ';
$htmlMain .= '
';
break;
case "m": // maintenance passthru
$statusImage = "black.gif";
$htmlMain .= '';
$htmlMain .= 'Main ';
$htmlMain .= ' | ';
$htmlMain .= 'Kill ';
$htmlMain .= ' | ';
$htmlMain .= 'Clean ';
$htmlMain .= ' | ';
$htmlMain .= 'Repair ';
$htmlMain .= ' | ';
$htmlMain .= 'Reset ';
$htmlMain .= ' | ';
$htmlMain .= 'Lock ';
$htmlMain .= ' Maintenance ';
$htmlMain .= '
';
break;
case "l": // log passthru
$statusImage = "black.gif";
$htmlMain .= '';
$htmlMain .= 'fluxd ';
$htmlMain .= ' | ';
$htmlMain .= 'fluxd-error ';
$htmlMain .= ' | ';
$htmlMain .= 'fluazu ';
$htmlMain .= ' | ';
$htmlMain .= 'mainline ';
$htmlMain .= ' | ';
$htmlMain .= 'transfers ';
$htmlMain .= ' Log ';
$htmlMain .= '
';
break;
case "y": // misc passthru
$statusImage = "black.gif";
$htmlMain .= '';
break;
case "z": // about passthru
$statusImage = "black.gif";
$htmlMain .= '';
$htmlMain .= 'Version ';
$htmlMain .= ' | ';
$htmlMain .= 'News ';
$htmlMain .= ' | ';
$htmlMain .= 'Changelog ';
$htmlMain .= ' About ';
$htmlMain .= '
';
break;
case "f": // fluxd passthru
$htmlTop = "";
$statusImage = "";
$htmlMain .= '';
$htmlMain .= 'log ';
$htmlMain .= ' | ';
$htmlMain .= 'error-log ';
$htmlMain .= ' | ';
$htmlMain .= 'ps ';
if (Fluxd::isRunning()) {
$htmlMain .= ' | ';
$htmlMain .= 'status ';
} else {
$htmlMain .= ' | ';
$htmlMain .= 'check ';
$htmlMain .= ' | ';
$htmlMain .= 'db-debug ';
$htmlMain .= ' | ';
$htmlMain .= 'version ';
}
$htmlMain .= ' fluxd ';
$htmlMain .= '
';
break;
case "_": // default
default:
$htmlTitle = "SuperAdmin";
$statusImage = "black.gif";
$htmlMain = '';
$htmlMain .= '
Select the superadmin task you wish to perform below: ';
$htmlMain .= ' Transfer Bulk Ops - bulk start/stop/resume transfers';
$htmlMain .= '
';
$htmlMain .= ' Processes - view detailed process info; force stop transfer processes';
$htmlMain .= '
';
$htmlMain .= ' Maintenance - clean up and maintenance';
$htmlMain .= '
';
$htmlMain .= ' Backup - create backups; download saved backups';
$htmlMain .= '
';
$htmlMain .= ' Log - view logs';
$htmlMain .= '
';
$htmlMain .= ' Misc - test for PHP and Perl requirements; view list of installed files';
$htmlMain .= '
';
$htmlMain .= ' About - version checking, updates, news, changelog; check installed file integrity';
$htmlMain .= '
';
break;
}
}
/**
* echo a string. use echo or sendLine
*
* @param $string: string to echo
* @param $mode: 0 = echo | 1 = sendLine
*/
function doEcho($string, $mode = 0) {
switch ($mode) {
case 0:
echo $string;
return;
case 1:
sendLine($string);
return;
}
}
/**
* prints the page
*/
function printPage() {
printPageStart(0);
global $htmlMain;
echo $htmlMain;
printPageEnd(0);
}
/**
* prints the page-start
*/
function printPageStart($echoMode = 0) {
global $cfg, $statusImage, $statusMessage, $htmlTitle, $htmlTop, $htmlMain;
doEcho('',$echoMode);
doEcho('',$echoMode);
doEcho(''.$cfg["pagetitle"].' - SuperAdmin ',$echoMode);
doEcho(' ',$echoMode);
doEcho(' ',$echoMode);
// theme-switch
if ((strpos($cfg["theme"], '/')) === false)
doEcho(' ',$echoMode);
else
doEcho(' ',$echoMode);
doEcho(' ',$echoMode);
doEcho('',$echoMode);
doEcho('',$echoMode);
doEcho('',$echoMode);
doEcho('
',$echoMode);
doEcho('',$echoMode);
doEcho('',$echoMode);
doEcho('',$echoMode);
doEcho('',$echoMode);
doEcho('',$echoMode);
doEcho('',$echoMode);
doEcho('',$echoMode);
doEcho(''.$cfg["pagetitle"]." - ".$htmlTitle.' ',$echoMode);
doEcho('',$echoMode);
doEcho(' ',$echoMode);
doEcho('
',$echoMode);
doEcho(' ',$echoMode);
doEcho(' ',$echoMode);
doEcho('',$echoMode);
doEcho('',$echoMode);
doEcho('',$echoMode);
doEcho('
',$echoMode);
doEcho('',$echoMode);
doEcho('',$echoMode);
doEcho('',$echoMode);
doEcho('
',$echoMode);
doEcho('',$echoMode);
doEcho('',$echoMode);
doEcho($htmlTop,$echoMode);
doEcho(' ',$echoMode);
doEcho('',$echoMode);
if ($statusImage != "") {
if ($statusImage != "yellow.gif")
doEcho('',$echoMode);
doEcho(' ',$echoMode);
if ($statusImage != "yellow.gif")
doEcho(' ',$echoMode);
}
doEcho(' ',$echoMode);
doEcho(' ',$echoMode);
doEcho('
',$echoMode);
doEcho('
',$echoMode);
doEcho('',$echoMode);
doEcho('',$echoMode);
doEcho('',$echoMode);
doEcho('
',$echoMode);
}
/**
* prints the page-end
*/
function printPageEnd($echoMode = 0) {
doEcho('
',$echoMode);
doEcho('
',$echoMode);
doEcho(' ',$echoMode);
doEcho(' ',$echoMode);
doEcho('
',$echoMode);
doEcho('
',$echoMode);
doEcho(' ',$echoMode);
doEcho('
',$echoMode);
doEcho('
',$echoMode);
doEcho(' ',$echoMode);
doEcho(' ',$echoMode);
doEcho('
',$echoMode);
doEcho(' ',$echoMode);
doEcho(' ',$echoMode);
doEcho('
',$echoMode);
doEcho('
',$echoMode);
doEcho('',$echoMode);
doEcho('',$echoMode);
}
/**
* bails out cause of version-error.
*/
function updateErrorNice($message = "") {
global $statusImage, $statusMessage, $htmlTop, $htmlMain;
$htmlTop = "Update ";
$htmlMain = 'Update from your Version not possible. ';
$htmlMain .= ' ';
$htmlMain .= 'Please use the most recent tarball and perform a manual update.';
$htmlMain .= ' ';
if ((isset($message)) && ($message != "") && (trim($message) != "0"))
$htmlMain .= ''.$message.' ';
$statusImage = "red.gif";
printPage();
exit();
}
/**
* bails out cause of version-error.
*/
function updateError($message = "") {
$errorString = "ERROR processing auto-update. please do manual update.";
if ((isset($message)) && ($message != ""))
$errorString .= "\n".$message;
@header("Content-Type: text/plain");
echo $errorString;
exit();
}
/**
* get a ado-connection to our database.
*
* @return database-connection or false on error
*/
function getAdoConnection() {
global $cfg;
// create ado-object
$db = &ADONewConnection($cfg["db_type"]);
// connect
$result = @ $db->Connect($cfg["db_host"], $cfg["db_user"], $cfg["db_pass"], $cfg["db_name"]);
// check for error
if ($db->ErrorNo() != 0 || !$result)
return false;
// return db-connection
return $db;
}
/**
* get release-list
*
* @return release-list as html-snip
*/
function getReleaseList() {
global $cfg, $error;
$retVal = "";
$releaseList = @gzinflate(getDataFromUrl(_SUPERADMIN_URLBASE . _SUPERADMIN_PROXY ."?a=3"));
if ((isset($releaseList)) && ($releaseList != "")) {
$retVal .= 'Available Tarballs: ';
$retVal .= ' ';
$retVal .= '';
$retVal .= '';
$retVal .= ' ';
$retVal .= 'Version ';
$retVal .= 'Checksum ';
$retVal .= ' ';
$releaseListFiles = explode("\n",$releaseList);
foreach ($releaseListFiles as $release) {
$release = trim($release);
if ((isset($release)) && ($release != "")) {
$tempArray = explode("_", $release);
$tempString = array_pop($tempArray);
$releaseVersion = substr($tempString, 0, -8);
$retVal .= '';
$retVal .= '';
$retVal .= '';
$retVal .= ' ';
$retVal .= ' ';
$retVal .= ' ';
$retVal .= '';
$retVal .= '';
$retVal .= $releaseVersion;
$retVal .= ' ';
$retVal .= ' ';
$retVal .= '';
$retVal .= '';
$retVal .= 'md5';
$retVal .= ' ';
$retVal .= ' ';
$retVal .= ' ';
}
}
$retVal .= '
';
}
return $retVal;
}
/**
* cleans a dir (deletes all files)
*
* @param $dir
* @return string with deleted files
*/
function cleanDir($dir) {
if (((strlen($dir) > 0)) && (substr($dir, -1 ) != "/"))
$dir .= "/";
$result = "";
$dirHandle = false;
$dirHandle = @opendir($dir);
if ($dirHandle === false) return $result;
while (false !== ($file = @readdir($dirHandle))) {
if ((@is_file($dir.$file)) && ((substr($file, 0, 1)) != ".")) {
if (@unlink($dir.$file) === true)
$result .= tfb_htmlencode($file)."\n";
else
$result .= "ERROR: ".tfb_htmlencode($file)."\n";
}
}
@closedir($dirHandle);
return $result;
}
/**
* formats a timestamp-string to human readable format.
*
* @param $timestampString string with prop. timestamp
* @return string with human-readable date
*/
function formatHumanDate($timestampString) {
return gmstrftime("%b %d %Y %H:%M:%S", mktime(
intval(substr($timestampString, 8, 2)),
intval(substr($timestampString, 10, 2)),
intval(substr($timestampString, 12, 2)),
intval(substr($timestampString, 4, 2)),
intval(substr($timestampString, 6, 2)),
intval(substr($timestampString, 0, 4))
));
}
/**
* formats a size-string to human readable format.
*
* @param $sizeInByte number with bytes
* @return string with human-readable size
*/
function formatHumanSize($sizeInByte) {
if ($sizeInByte > (1073741824)) // > 1G
return (string) (round($sizeInByte/(1073741824), 1))."G";
if ($sizeInByte > (1048576)) // > 1M
return (string) (round($sizeInByte/(1048576), 1))."M";
if ($sizeInByte > (1024)) // > 1k
return (string) (round($sizeInByte/(1024), 1))."k";
return (string) $sizeInByte;
}
/**
* checks if backup-id is a valid backup-archive
*
* @param $param the param with the backup-id
* @param boolean if archive-name is a valid backup-archive
*/
function backupParamCheck($param) {
global $cfg, $error;
// sanity-checks
if (preg_match("/\\\/", urldecode($param)))
return false;
if (preg_match("/\.\./", urldecode($param)))
return false;
// check id
$fileList = backupList();
if ((isset($fileList)) && ($fileList != "")) {
$validFiles = explode("\n",$fileList);
return (in_array($param, $validFiles));
} else {
return false;
}
return false;
}
/**
* build backup-list
*
* @return backup-list as string
*/
function backupListDisplay() {
global $cfg, $error;
// backup-dir
$dirBackup = $cfg["path"]. _DIR_BACKUP . '/';
//
$retVal = "";
$fileList = backupList();
if ((isset($fileList)) && ($fileList != "")) {
$retVal .= '';
$retVal .= '';
$retVal .= 'Version ';
$retVal .= 'Date ';
$retVal .= 'Comp. ';
$retVal .= 'Size ';
$retVal .= ' ';
$retVal .= ' ';
// theme-switch
if ((strpos($cfg["theme"], '/')) === false)
$theme = $cfg["theme"];
else
$theme = "tf_standard_themes";
$backupListFiles = explode("\n",$fileList);
foreach ($backupListFiles as $backup) {
$backup = trim($backup);
$backupFile = $dirBackup.$backup;
if ((isset($backup)) && ($backup != "") && (is_file($backupFile))) {
$backupElements = explode("_",$backup);
$retVal .= '';
$retVal .= ''.$backupElements[1].' ';
$retVal .= ''.formatHumanDate(substr($backupElements[2], 0, 14)).' ';
$lastChar = substr($backupElements[2], -1, 1);
$retVal .= '';
switch ($lastChar) {
case "r":
$retVal .= 'none';
break;
case "z":
$retVal .= 'gzip';
break;
case "2":
$retVal .= 'bzip2';
break;
default:
$retVal .= 'unknown';
break;
}
$retVal .= ' ';
$retVal .= ''.(string)(formatHumanSize(filesize($backupFile))).' ';
$retVal .= '';
$retVal .= '';
$retVal .= ' ';
$retVal .= ' ';
$retVal .= ' ';
$retVal .= '';
$retVal .= ' ';
$retVal .= ' ';
$retVal .= ' ';
$retVal .= ' ';
}
}
$retVal .= '
';
} else {
$retVal .= 'No Backups on Server ';
}
return $retVal;
}
/**
* get backup-list
*
* @return backup-list as string or empty string on error / no files
*/
function backupList() {
global $cfg, $error;
// backup-dir
$dirBackup = $cfg["path"]. _DIR_BACKUP;
if (file_exists($dirBackup)) {
if ($dirHandle = opendir($dirBackup)) {
$fileList = "";
while (false !== ($file = readdir($dirHandle))) {
if ( substr($file, 0, 7) == "backup_" )
$fileList .= $file . "\n";
}
closedir($dirHandle);
return $fileList;
} else {
return "";
}
} else {
return "";
}
}
/**
* deletes a backup of a flux-installation
*
* @param $filename the file with the backup
*/
function backupDelete($filename) {
global $cfg;
$backupFile = $cfg["path"]. _DIR_BACKUP . '/' . $filename;
@unlink($backupFile);
AuditAction($cfg["constants"]["admin"], "Backup Deleted: ".$filename);
}
/**
* sends a backup of flux-installation to a client
*
* @param $filename the file with the backup
* @param $delete boolean if file should be deleted.
*/
function backupSend($filename, $delete = false) {
global $cfg;
$backupFile = $cfg["path"]. _DIR_BACKUP . '/' . $filename;
if ($delete) {
@session_write_close();
@ob_end_clean();
if (connection_status() != 0)
return false;
set_time_limit(0);
}
if (!is_file($backupFile))
return false;
// log before we screw up the file-name
AuditAction($cfg["constants"]["admin"], "Backup Sent: ".$filename);
// filenames in IE containing dots will screw up the filename
if (strstr($_SERVER['HTTP_USER_AGENT'], "MSIE"))
$filename = preg_replace('/\./', '%2e', $filename, substr_count($filename, '.') - 1);
// send data
@header("Cache-Control: no-cache");
@header("Pragma: no-cache");
@header("Content-Type: application/octet-stream");
@header("Content-Length: " .(string)(filesize($backupFile)) );
@header('Content-Disposition: attachment; filename="'.$filename.'"');
@header("Content-Transfer-Encoding: binary\n");
if ($delete) { // read data to mem, delete file and send complete
$data = file_get_contents($backupFile);
@unlink($backupFile);
echo $data;
} else { // read / write file with 8kb-buffer
if ($handle = fopen($backupFile, 'rb')){
while ((!feof($handle)) && (connection_status() == 0)) {
print(fread($handle, 8192));
flush();
}
fclose($handle);
}
}
// return
if ($delete) {
return true;
} else {
return((connection_status()==0) and !connection_aborted());
}
}
/**
* backup of flux-installation
*
* @param $talk: boolean if function should talk
* @param $compression: 0 = none | 1 = gzip | 2 = bzip2
* @return string with name of backup-archive, string with "" in error-case.
*/
function backupCreate($talk = false, $compression = 0) {
global $cfg, $error;
// backup-dir
$dirBackup = $cfg["path"]. _DIR_BACKUP;
if (!checkDirectory($dirBackup)) {
$error = "Errors when checking/creating backup-dir: ".tfb_htmlencodekeepspaces($dirBackup);
return "";
}
// files and more strings
$backupName = "backup_". _VERSION ."_".date("YmdHis");
$fileArchiveName = $backupName.".tar";
$tarSwitch = "-cf";
switch ($compression) {
case 1:
$fileArchiveName .= ".gz";
$tarSwitch = "-zcf";
break;
case 2:
$fileArchiveName .= ".bz2";
$tarSwitch = "-jcf";
break;
}
// files
$files = array();
$files['archive'] = $dirBackup . '/' . $fileArchiveName;
$files['db'] = $dirBackup . '/database.sql';
$files['docroot'] = $dirBackup . '/docroot.tar';
$files['transfers'] = $dirBackup . '/transfers.tar';
$files['fluxd'] = $dirBackup . '/fluxd.tar';
$files['mrtg'] = $dirBackup . '/mrtg.tar';
// exec
$exec = array();
$exec['transfers'] = ((@is_dir($cfg["transfer_file_path"])) === true);
$exec['fluxd'] = ((@is_dir($cfg["path"].'.fluxd')) === true);
$exec['mrtg'] = ((@is_dir($cfg["path"].'.mrtg')) === true);
// commands
$commands = array();
$commands['archive'] = "cd ".tfb_shellencode($dirBackup)."; tar ".$tarSwitch." ".$fileArchiveName." ";
$commands['db'] = "";
switch ($cfg["db_type"]) {
case "mysql":
$commands['db'] = "mysqldump -h ".tfb_shellencode($cfg["db_host"])." -u ".tfb_shellencode($cfg["db_user"])." --password=".tfb_shellencode($cfg["db_pass"])." --all -f ".tfb_shellencode($cfg["db_name"])." > ".tfb_shellencode($files['db']);
$commands['archive'] .= 'database.sql ';
break;
case "sqlite":
$commands['db'] = "sqlite ".tfb_shellencode($cfg["db_host"])." .dump > ".tfb_shellencode($files['db']);
$commands['archive'] .= 'database.sql ';
break;
case "postgres":
$commands['db'] = "pg_dump -h ".tfb_shellencode($cfg["db_host"])." -D ".tfb_shellencode($cfg["db_name"])." -U ".tfb_shellencode($cfg["db_user"])." -f ".tfb_shellencode($files['db']);
$commands['archive'] .= 'database.sql ';
break;
}
$commands['archive'] .= 'docroot.tar';
if ($exec['transfers'] === true)
$commands['archive'] .= ' transfers.tar';
if ($exec['fluxd'] === true)
$commands['archive'] .= ' fluxd.tar';
if ($exec['mrtg'] === true)
$commands['archive'] .= ' mrtg.tar';
//$commands['docroot'] = "cd ".tfb_shellencode($dirBackup)."; tar -cf docroot.tar ".tfb_shellencode($cfg["docroot"]); // with path of docroot
$commands['docroot'] = "cd ".tfb_shellencode($cfg["docroot"])."; tar -cf ".tfb_shellencode($files['docroot'])." ."; // only content of docroot
$commands['transfers'] = "cd ".tfb_shellencode($cfg["transfer_file_path"])."; tar -cf ".tfb_shellencode($files['transfers'])." .";
$commands['fluxd'] = "cd ".tfb_shellencode($cfg["path"].'.fluxd')."; tar -cf ".tfb_shellencode($files['fluxd'])." .";
$commands['mrtg'] = "cd ".tfb_shellencode($cfg["path"].'.mrtg')."; tar -cf ".tfb_shellencode($files['mrtg'])." .";
// action
if ($talk)
sendLine(' ');
// database-command
if ($commands['db'] != "") {
if ($talk)
sendLine('Backup of Database '.tfb_htmlencodekeepspaces($cfg["db_name"]).' ...');
shell_exec($commands['db']);
}
if ($talk)
sendLine(' Ok ');
// docroot-command
if ($talk)
sendLine('Backup of Docroot '.tfb_htmlencodekeepspaces($cfg["docroot"]).' ...');
shell_exec($commands['docroot']);
if ($talk)
sendLine(' Ok ');
// transfers-command
if ($exec['transfers'] === true) {
if ($talk)
sendLine('Backup of transfers '.tfb_htmlencodekeepspaces($cfg["transfer_file_path"]).' ...');
shell_exec($commands['transfers']);
if ($talk)
sendLine(' Ok ');
}
// fluxd-command
if ($exec['fluxd'] === true) {
if ($talk)
sendLine('Backup of fluxd '.tfb_htmlencodekeepspaces($cfg["path"].'.fluxd').' ...');
shell_exec($commands['fluxd']);
if ($talk)
sendLine(' Ok ');
}
// mrtg-command
if ($exec['mrtg'] === true) {
if ($talk)
sendLine('Backup of mrtg '.tfb_htmlencodekeepspaces($cfg["path"].'.mrtg').' ...');
shell_exec($commands['mrtg']);
if ($talk)
sendLine(' Ok ');
}
// create the archive
if ($talk)
sendLine('Creating Archive '.$fileArchiveName.' ...');
shell_exec($commands['archive']);
if ($talk)
sendLine(' Ok ');
// delete temp-file(s)
if ($talk)
sendLine('Deleting temp-files ...');
if ($commands['db'] != "")
@unlink($files['db']);
@unlink($files['docroot']);
@unlink($files['transfers']);
@unlink($files['fluxd']);
@unlink($files['mrtg']);
if ($talk)
sendLine(' Ok ');
// log
if ($talk)
sendLine('Backup Complete. ');
AuditAction($cfg["constants"]["admin"], "Backup Created: ".$fileArchiveName);
return $fileArchiveName;
}
/**
* validate Local Files
*/
function validateLocalFiles() {
sendLine('Validate Files ');
sendLine('Getting Checksum-list ');
// download list
$checksumsString = "";
@ini_set("allow_url_fopen", "1");
@ini_set("user_agent", "torrentflux-b4rt/". _VERSION);
if ($urlHandle = @fopen(_SUPERADMIN_URLBASE._FILE_CHECKSUMS_PRE._VERSION._FILE_CHECKSUMS_SUF, 'r')) {
stream_set_timeout($urlHandle, 15);
$info = stream_get_meta_data($urlHandle);
while ((!feof($urlHandle)) && (!$info['timed_out'])) {
$checksumsString .= @fgets($urlHandle, 8192);
$info = stream_get_meta_data($urlHandle);
sendLine('.');
}
@fclose($urlHandle);
}
if (empty($checksumsString))
exit('error getting checksum-list from '._SUPERADMIN_URLBASE);
sendLine('done ');
sendLine('Processing list ');
// remote Checksums
$remoteChecksums = array();
$remoteSums = explode("\n", $checksumsString);
$remoteSums = array_map('trim', $remoteSums);
foreach ($remoteSums as $remSum) {
$tempAry = explode(";", $remSum);
if ((!empty($tempAry[0])) && (!empty($tempAry[1]))) {
$remoteChecksums[$tempAry[0]] = $tempAry[1];
sendLine('.');
}
}
$remoteChecksumsCount = count($remoteChecksums);
sendLine('done ('.$remoteChecksumsCount.') ');
// local Checksums
sendLine('Getting local checksums ');
$localChecksums = getFileChecksums(true);
$localChecksumsCount = count($localChecksums);
sendLine('done ('.$localChecksumsCount.') ');
// init some arrays
$filesMissing = array();
$filesNew = array();
$filesOk = array();
$filesChanged = array();
// validate
sendLine('Validating... ');
// validate pass 1
foreach ($remoteChecksums as $file => $md5) {
$line = tfb_htmlencodekeepspaces($file);
if (isset($localChecksums[$file])) {
if ($md5 == $localChecksums[$file]) {
array_push($filesOk, $file);
$line .= ' Ok ';
} else {
array_push($filesChanged, $file);
$line .= ' Changed ';
}
} else {
array_push($filesMissing, $file);
$line .= ' Missing ';
}
sendLine($line." ");
}
// validate pass 2
foreach ($localChecksums as $file => $md5)
if (!isset($remoteChecksums[$file]))
array_push($filesNew, $file);
// summary
sendLine('Done. ');
// files Total
sendLine(''._VERSION.': '.$remoteChecksumsCount.' ');
sendLine('Local: '.$localChecksumsCount.' ');
// files Ok
sendLine('Unchanged: '.count($filesOk).' ');
// files Missing
sendLine('Missing: '.count($filesMissing).' ');
// files Changed
sendLine('Changed: '.count($filesChanged).' ');
// files New
sendLine('New: '.count($filesNew).' ');
if (count($filesNew) > 0) {
sendLine('New Files: ');
foreach ($filesNew as $newFile)
sendLine(tfb_htmlencodekeepspaces($newFile).' ');
}
}
/**
* phpCheckWeb
*
* @return string
*/
function phpCheckWeb() {
$retVal = " ";
$errors = 0;
$warnings = 0;
$dbsupported = 0;
$errorsMessages = array();
$warningsMessages = array();
// PHP-Version
$retVal .= '1. PHP-Version
';
$phpVersion = 'PHP-Version: '.PHP_VERSION.' ';
if (PHP_VERSION < 4.3) {
$phpVersion .= 'Failed ';
$errors++;
array_push($errorsMessages, "PHP-Version: 4.3 or higher required.");
} else {
$phpVersion .= 'Passed ';
}
$retVal .= $phpVersion;
// PHP-Extensions
$retVal .= '2. PHP-Extensions
';
$retVal .= "";
$loadedExtensions = get_loaded_extensions();
// session
$session = 'session ';
if (in_array("session", $loadedExtensions)) {
$session .= 'Passed ';
} else {
$session .= 'Failed ';
$errors++;
array_push($errorsMessages, "PHP-Extensions: session required.");
}
$retVal .= $session.' ';
// pcre
$pcre = 'pcre ';
if (in_array("pcre", $loadedExtensions)) {
$pcre .= 'Passed ';
} else {
$pcre .= 'Failed ';
$errors++;
array_push($errorsMessages, "PHP-Extensions: pcre required.");
}
$retVal .= $pcre.' ';
// sockets
$sockets = 'sockets ';
if (in_array("sockets", $loadedExtensions)) {
$sockets .= 'Passed ';
} else {
$sockets .= 'Failed ';
$warnings++;
array_push($warningsMessages, "PHP-Extensions: sockets required for communication with fluxd. fluxd cannot work without sockets.");
}
$retVal .= $sockets.' ';
//
$retVal .= " ";
// PHP-Configuration
$retVal .= '3. PHP-Configuration
';
$retVal .= "";
// safe_mode
$safe_mode = 'safe_mode ';
if ((ini_get("safe_mode")) == 0) {
$safe_mode .= 'Passed ';
} else {
$safe_mode .= 'Failed ';
$errors++;
array_push($errorsMessages, "PHP-Configuration: safe_mode must be turned off.");
}
$retVal .= $safe_mode.' ';
// allow_url_fopen
$allow_url_fopen = 'allow_url_fopen ';
if ((ini_get("allow_url_fopen")) == 1) {
$allow_url_fopen .= 'Passed ';
} else {
$allow_url_fopen .= 'Failed ';
array_push($warningsMessages, "PHP-Configuration: allow_url_fopen must be turned on. some features wont work if it is turned off.");
$warnings++;
}
$retVal .= $allow_url_fopen.' ';
// register_globals
$register_globals = 'register_globals ';
if ((ini_get("register_globals")) == 0) {
$register_globals .= 'Passed ';
} else {
$register_globals .= 'Failed ';
$errors++;
array_push($errorsMessages, "PHP-Configuration: register_globals must be turned off.");
}
$retVal .= $register_globals.' ';
//
$retVal .= " ";
// PHP-Database-Support
$retVal .= '4. PHP-Database-Support
';
$retVal .= "";
// define valid db-types
$databaseTypes = array();
$databaseTypes['mysql'] = 'mysql_connect';
$databaseTypes['mysqli'] = 'mysqli_connect';
$databaseTypes['sqlite'] = 'sqlite_open';
$databaseTypes['postgres'] = 'pg_connect';
// test db-types
foreach ($databaseTypes as $databaseTypeName => $databaseTypeFunction) {
$dbtest = ''.$databaseTypeName.' ';
if (function_exists($databaseTypeFunction)) {
$dbtest .= 'Passed ';
$dbsupported++;
} else {
$dbtest .= 'Failed ';
}
$retVal .= $dbtest.' ';
}
$retVal .= " ";
// db-state
if ($dbsupported == 0) {
$errors++;
array_push($errorsMessages, "PHP-Database-Support: no supported database-type found.");
}
// OS-Specific
// get os
$osString = php_uname('s');
if (isset($osString)) {
if (!(stristr($osString, 'linux') === false)) /* linux */
define('_OS', 1);
else if (!(stristr($osString, 'bsd') === false)) /* bsd */
define('_OS', 2);
else
define('_OS', 0);
} else {
define('_OS', 0);
}
$retVal .= '5. OS-Specific ('.$osString.' '.php_uname('r').')
';
switch (_OS) {
case 1: // linux
$retVal .= 'No Special Requirements on Linux-OS. Passed ';
break;
case 2: // bsd
$retVal .= "";
// posix
$posix = 'posix ';
if ((function_exists('posix_geteuid')) && (function_exists('posix_getpwuid'))) {
$posix .= 'Passed ';
} else {
$posix .= 'Failed ';
$warnings++;
array_push($warningsMessages, "OS-Specific: PHP-extension posix missing. some netstat-features wont work without.");
}
$retVal .= $posix.' ';
$retVal .= " ";
break;
case 0: // unknown
default:
$retVal .= "OS not supported. ";
$errors++;
array_push($errorsMessages, "OS-Specific: ".$osString." not supported.");
break;
}
// summary
$retVal .= 'Summary
';
// state
$state = "State: ";
if (($warnings + $errors) == 0) {
// good
$state .= 'Ok ';
$state .= " ";
$retVal .= $state;
$retVal .= "torrentflux-b4rt should run on this system.";
} else {
if (($errors == 0) && ($warnings > 0)) {
// may run with flaws
$state .= 'Warning ';
$state .= " ";
$retVal .= $state;
$retVal .= "torrentflux-b4rt may run on this system, but there may be problems.";
} else {
// not ok
$state .= 'Failed ';
$state .= " ";
$retVal .= $state;
$retVal .= "torrentflux-b4rt cannot run on this system.";
}
}
// errors
if (count($errorsMessages) > 0) {
$retVal .= 'Errors: ';
$retVal .= "
";
foreach ($errorsMessages as $errorsMessage) {
$retVal .= "".$errorsMessage." ";
}
$retVal .= " ";
}
// warnings
if (count($warningsMessages) > 0) {
$retVal .= 'Warnings: ';
$retVal .= "
";
foreach ($warningsMessages as $warningsMessage) {
$retVal .= "".$warningsMessage." ";
}
$retVal .= " ";
}
// return
return $retVal;
}
?>