| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604 |
- <?php
- /* $Id: functions.superadmin.php 3304 2007-12-09 14:33:13Z warion $ */
- /*******************************************************************************
- LICENSE
- This program is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License (GPL)
- as published by the Free Software Foundation; either version 2
- of the License, or (at your option) any later version.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
- To read the license please visit http://www.gnu.org/copyleft/gpl.html
- *******************************************************************************/
- /**
- * transfers
- *
- * @param $action
- */
- function sa_transfers($action = "") {
- global $cfg, $error, $statusImage, $statusMessage, $htmlTitle, $htmlTop, $htmlMain;
- if ($action == "")
- return;
- buildPage("t");
- switch ($action) {
- case "0": // Transfers-main
- $htmlTitle = "Transfer Bulk Operations";
- $htmlMain .= '<br><div align="left">';
- $htmlMain .= '<p>Select action to perform on all items in the transfer list:</p>';
- $htmlMain .= '<a href="' . _FILE_THIS . '?t=1"><img src="themes/'.$cfg["theme"].'/images/arrow.gif" width="9" height="9" title="Stop All Transfers" border="0"> Stop All Transfers</a>';
- $htmlMain .= '<p>';
- $htmlMain .= '<a href="' . _FILE_THIS . '?t=2"><img src="themes/'.$cfg["theme"].'/images/arrow.gif" width="9" height="9" title="Start All Transfers" border="0"> Start All Transfers</a>';
- $htmlMain .= '<p>';
- $htmlMain .= '<a href="' . _FILE_THIS . '?t=3"><img src="themes/'.$cfg["theme"].'/images/arrow.gif" width="9" height="9" title="Resume All Transfers" border="0"> Resume All Transfers</a>';
- $htmlMain .= '<br><br><strong>Note:</strong><br>\'Start All Transfers\' will start all transfers in the transfer list, regardless of whether they have been started previously or not.<br><br>\'Resume All Transfers\' will only start those transfers that have previously been started and are currently in the \'stopped\' state';
- $htmlMain .= '</div><br><br>';
- break;
- case "1": // Transfers-Stop
- $htmlTitle = "Transfers - Stop";
- $htmlMain .= '<br><strong>Transfers Stopped:</strong><br>';
- $htmlMain .= '<pre>';
- $transferList = getTransferArray();
- foreach ($transferList as $transfer) {
- if (isTransferRunning($transfer)) {
- $ch = ClientHandler::getInstance(getTransferClient($transfer));
- $ch->stop($transfer);
- $htmlMain .= ' - '.$transfer."";
- $htmlMain .= "\n";
- }
- }
- $htmlMain .= '</pre>';
- $htmlMain .= '<hr><br>';
- break;
- case "2": // Transfers-Start
- $htmlTitle = "Transfers - Start";
- $htmlMain .= '<br><strong>Transfers Started:</strong><br>';
- $htmlMain .= '<pre>';
- $transferList = getTransferArray();
- foreach ($transferList as $transfer) {
- if (!isTransferRunning($transfer)) {
- $ch = ClientHandler::getInstance(getTransferClient($transfer));
- $ch->start($transfer, false, false);
- $htmlMain .= ' - '.$transfer."";
- $htmlMain .= "\n";
- }
- }
- $htmlMain .= '</pre>';
- $htmlMain .= '<hr><br>';
- break;
- case "3": // Transfers-Resume
- $htmlTitle = "Transfers - Resume";
- $htmlMain .= '<br><strong>Transfers Resumed:</strong><br>';
- $htmlMain .= '<pre>';
- $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 .= '</pre>';
- $htmlMain .= '<hr><br>';
- break;
- }
- $htmlMain .= '<br><strong>Transfers:</strong><br>';
- $htmlMain .= '<pre>';
- $transferList = getTransferArray();
- foreach ($transferList as $transfer) {
- $htmlMain .= ' - '.$transfer."";
- if (isTransferRunning($transfer))
- $htmlMain .= " (running)";
- $htmlMain .= "\n";
- }
- $htmlMain .= '</pre>';
- 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 .= '<p>';
- $htmlMain .= 'View currently running torrentflux-b4rt processes:<br><br>';
- $htmlMain .= '<a href="' . _FILE_THIS . '?p=1"><img src="themes/'.$cfg["theme"].'/images/arrow.gif" width="9" height="9" title="All" border="0"> All</a> - detailed process list';
- $htmlMain .= '<p>';
- $htmlMain .= '<a href="' . _FILE_THIS . '?p=2"><img src="themes/'.$cfg["theme"].'/images/arrow.gif" width="9" height="9" title="Transfers" border="0"> Transfers</a> - simple list of running transfers with option to force stop individual transfers';
- $htmlMain .= '<br><br>';
- break;
- case "1": // Processes - All
- $htmlTitle = "Processes - All";
- $htmlMain .= '<div align="left" id="BodyLayer" name="BodyLayer" style="border: thin solid '.$cfg['main_bgcolor'].'; position:relative; width:740; height:498; padding-left: 5px; padding-right: 5px; z-index:1; overflow: scroll; visibility: visible">';
- $htmlMain .= '<br>';
- $htmlMain .= '<p><strong>fluxd</strong>';
- $htmlMain .= '<pre>';
- $htmlMain .= tfb_htmlencode(shell_exec("ps auxww | ".$cfg['bin_grep']." fluxd | ".$cfg['bin_grep']." -v grep"));
- $htmlMain .= '</pre>';
- $htmlMain .= '<p><strong>fluazu</strong>';
- $htmlMain .= '<pre>';
- $htmlMain .= tfb_htmlencode(shell_exec("ps auxww | ".$cfg['bin_grep']." fluazu.py | ".$cfg['bin_grep']." -v grep"));
- $htmlMain .= '</pre>';
- $clients = array('tornado', 'transmission', 'mainline', 'wget', 'nzbperl', 'azureus');
- foreach ($clients as $client) {
- $ch = ClientHandler::getInstance($client);
- $htmlMain .= '<p><strong>'.$client.'</strong>';
- $htmlMain .= '<br>';
- $htmlMain .= '<pre>';
- $htmlMain .= tfb_htmlencode(shell_exec("ps auxww | ".$cfg['bin_grep']." ".tfb_shellencode($ch->binClient)." | ".$cfg['bin_grep']." -v grep"));
- $htmlMain .= '</pre>';
- $htmlMain .= '<br>';
- $htmlMain .= '<pre>';
- $htmlMain .= $ch->runningProcessInfo();
- $htmlMain .= '</pre>';
- }
- $htmlMain .= '</div>';
- break;
- case "2": // Processes - Transfers
- $htmlTitle = "Processes - Transfers";
- $htmlMain .= '<div align="left" id="BodyLayer" name="BodyLayer" style="border: thin solid '.$cfg['main_bgcolor'].'; position:relative; width:740; height:498; padding-left: 5px; padding-right: 5px; z-index:1; overflow: scroll; visibility: visible">';
- $htmlMain .= '<br>
- <table width="700" border=1 bordercolor="'.$cfg["table_admin_border"].'" cellpadding="2" cellspacing="0" bgcolor="'.$cfg["table_data_bg"].'">
- <tr><td colspan=6 bgcolor="'.$cfg["table_header_bg"].'" background="themes/'.$cfg["theme"].'/images/bar.gif">
- <table width="100%" cellpadding=0 cellspacing=0 border=0><tr><td><font class="title"> Running Items </font></td></tr></table>
- </td></tr>
- <tr>
- <td bgcolor="'.$cfg["table_header_bg"].'" width="15%" nowrap><div align=center class="title">'.$cfg["_USER"].'</div></td>
- <td bgcolor="'.$cfg["table_header_bg"].'" nowrap><div align=center class="title">'.$cfg["_FILE"].'</div></td>
- <td bgcolor="'.$cfg["table_header_bg"].'" width="1%" nowrap><div align=center class="title">'.$cfg["_FORCESTOP"].'</div></td>
- </tr>
- ';
- $running = getRunningClientProcesses();
- foreach ($running as $rng) {
- $rt = RunningTransfer::getInstance($rng['pinfo'], $rng['client']);
- $htmlMain .= '<tr bgcolor="'.$cfg["table_header_bg"].'">';
- $htmlMain .= '<td nowrap><div class="tiny">';
- $htmlMain .= tfb_htmlencodekeepspaces($rt->transferowner);
- $htmlMain .= '</div></td>';
- $htmlMain .= '<td nowrap><div align=center><div class="tiny" align="left">';
- $htmlMain .= $rt->transferFile;
- $htmlMain .= '</div></td>';
- $htmlMain .= '<td nowrap>';
- $htmlMain .= '<a href="dispatcher.php?action=forceStop&riid=_referer_';
- $htmlMain .= "&transfer=".urlencode($rt->transferFile);
- $htmlMain .= "&pid=".$rt->processId;
- $htmlMain .= '"><img src="themes/'.$cfg["theme"].'/images/kill.gif" width="16" height="16" title="'.$cfg['_FORCESTOP'].'" border="0"></a></td>';
- $htmlMain .= '</tr>';
- }
- $htmlMain .= '</table>';
- $htmlMain .= '</div>';
- 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 .= '<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();
- }
- /**
- * 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 .= '<br>Select the format and location to save the backup to:<br><br>';
- $htmlMain .= '<form name="backupServer" action="' . _FILE_THIS . '" method="post">';
- $htmlMain .= '<select name="c">';
- $htmlMain .= '<option value="0">none</option>';
- $htmlMain .= '<option value="1" selected>gzip</option>';
- $htmlMain .= '<option value="2">bzip2</option>';
- $htmlMain .= '</select> ';
- $htmlMain .= '<input type="Hidden" name="b" value="1">';
- $htmlMain .= '<input type="submit" value="Backup on Server">';
- $htmlMain .= '</form><p>';
- $htmlMain .= '<form name="backupClient" action="' . _FILE_THIS . '" method="post">';
- $htmlMain .= '<select name="c">';
- $htmlMain .= '<option value="0">none</option>';
- $htmlMain .= '<option value="1" selected>gzip</option>';
- $htmlMain .= '<option value="2">bzip2</option>';
- $htmlMain .= '</select> ';
- $htmlMain .= '<input type="Hidden" name="b" value="2">';
- $htmlMain .= '<input type="submit" value="Backup to Client">';
- $htmlMain .= '</form><p>';
- $htmlMain .= '<br><strong>Notes:</strong><br>"Backup on Server" will save the backup archive to the following path:<br>';
- $htmlMain .= '<em>'.tfb_htmlencodekeepspaces($cfg["path"] . _DIR_BACKUP).'/</em>';
- $htmlMain .= '<br><br>';
- $htmlMain .= '"Backup to Client" will create the backup archive and prompt you to save in your web browser.<br><br><strong>Please wait</strong> 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.<br><br>';
- $htmlMain .= "<hr><strong>What Data is Backed Up?</strong><br>";
- $htmlMain .= "<ul>";
- $htmlMain .= "<li>Document root directory structure -<br>all files underneath the webserver document root folder where you installed Torrentflux-b4rt.<br><br></li>";
- $htmlMain .= "<li>The Transfers folder directory structure -<br>all files in the .transfers folder located in the path configured in the admin pages 'server' tab.<br><br></li>";
- $htmlMain .= "<li>The fluxd folder directory structure -<br>all files in the .fluxd folder located in the path configured in the admin pages 'server' tab.<br><br></li>";
- $htmlMain .= "<li>The MRTG folder directory structure -<br>all files in the .mrtg folder located in the path configured in the admin pages 'server' tab.<br><br></li>";
- $htmlMain .= "<li>The Torrentflux-b4rt database -<br>the database used to store information used in the day to day running of torrentflux-b4rt.<br><br></li>";
- $htmlMain .= "</ul><hr>";
- 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('<br>');
- sendLine('<font color="red"><strong>Backup - Error</strong></font><br><br>');
- sendLine($error);
- } else {
- sendLine('<br>');
- sendLine('<strong>Backup Created</strong>');
- sendLine('<br><br>Archive of backup is <em>'.tfb_htmlencodekeepspaces($backupArchive).'</em>');
- sendLine('<br><br>');
- sendLine(backupListDisplay());
- }
- printPageEnd(1);
- exit();
- case "2": // client-backup
- $backupArchive = backupCreate(false, tfb_getRequestVar('c'));
- if ($backupArchive == "") {
- buildPage("-b");
- $htmlTitle = "Backup - Create - Client";
- $htmlMain .= '<br><br>';
- $htmlMain .= '<font color="red"><strong>Backup - Error</strong></font><br><br>';
- $htmlMain .= $error;
- printPage();
- } else {
- backupSend($backupArchive,true);
- }
- exit();
- case "3": // backup-list
- $htmlTitle = "Backup - Backups on Server";
- buildPage("b");
- $htmlMain .= '<br>';
- $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 .= '<br><br>';
- $htmlMain .= '<font color="red"><strong>Backup - Error</strong></font><br><br>';
- $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 .= '<br>';
- $htmlMain .= '<em>'.tfb_htmlencodekeepspaces($backupArchive).'</em> deleted.';
- $htmlMain .= '<br><br>';
- $htmlMain .= backupListDisplay();
- } else {
- buildPage("-b");
- $htmlTitle = "Backup - Delete";
- $htmlMain .= '<br><br>';
- $htmlMain .= '<font color="red"><strong>Backup - Error</strong></font><br><br>';
- $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 .= '<br>Select the type of log you want to view below:<p>';
- $htmlMain .= '<a href="' . _FILE_THIS . '?l=1"><img src="themes/'.$cfg["theme"].'/images/arrow.gif" width="9" height="9" title="fluxd" border="0"> fluxd</a> - STDOUT logfiles for the torrentflux-b4rt fluxd daemon';
- $htmlMain .= '<p>';
- $htmlMain .= '<a href="' . _FILE_THIS . '?l=2"><img src="themes/'.$cfg["theme"].'/images/arrow.gif" width="9" height="9" title="fluxd-error" border="0"> fluxd-error</a> - STDERR logfiles for the torrentflux-b4rt fluxd daemon';
- $htmlMain .= '<p>';
- $htmlMain .= '<a href="' . _FILE_THIS . '?l=3"><img src="themes/'.$cfg["theme"].'/images/arrow.gif" width="9" height="9" title="fluazu" border="0"> fluazu</a> - logfiles for the fluazu interface to Azureus';
- $htmlMain .= '<p>';
- $htmlMain .= '<a href="' . _FILE_THIS . '?l=5"><img src="themes/'.$cfg["theme"].'/images/arrow.gif" width="9" height="9" title="mainline" border="0"> BitTorrent Mainline</a> - centralised logfile for the BitTorrent Mainline client';
- $htmlMain .= '<p>';
- $htmlMain .= '<a href="' . _FILE_THIS . '?l=8"><img src="themes/'.$cfg["theme"].'/images/arrow.gif" width="9" height="9" title="transfers" border="0"> Transfers</a> - logfiles for transfers in the current transfer list';
- $htmlMain .= '<br><br>';
- break;
- case "1": // fluxd-log
- $htmlTitle = "log - fluxd";
- $htmlMain .= '<div align="left" id="BodyLayer" name="BodyLayer" style="border: thin solid '.$cfg['main_bgcolor'].'; position:relative; width:740; height:498; padding-left: 5px; padding-right: 5px; z-index:1; overflow: scroll; visibility: visible">';
- $htmlMain .= '<pre>';
- $htmlMain .= tfb_htmlencode(@file_get_contents($cfg["path"].'.fluxd/fluxd.log'));
- $htmlMain .= '</pre>';
- $htmlMain .= '</div>';
- break;
- case "2": // fluxd-error-log
- $htmlTitle = "log - fluxd - error-log";
- $htmlMain .= '<div align="left" id="BodyLayer" name="BodyLayer" style="border: thin solid '.$cfg['main_bgcolor'].'; position:relative; width:740; height:498; padding-left: 5px; padding-right: 5px; z-index:1; overflow: scroll; visibility: visible">';
- $htmlMain .= '<pre>';
- $htmlMain .= tfb_htmlencode(@file_get_contents($cfg["path"].'.fluxd/fluxd-error.log'));
- $htmlMain .= '</pre>';
- $htmlMain .= '</div>';
- break;
- case "3": // fluazu-log
- $htmlTitle = "log - fluazu";
- $htmlMain .= '<div align="left" id="BodyLayer" name="BodyLayer" style="border: thin solid '.$cfg['main_bgcolor'].'; position:relative; width:740; height:498; padding-left: 5px; padding-right: 5px; z-index:1; overflow: scroll; visibility: visible">';
- $htmlMain .= '<pre>';
- $htmlMain .= tfb_htmlencode(@file_get_contents($cfg["path"].'.fluazu/fluazu.log'));
- $htmlMain .= '</pre>';
- $htmlMain .= '</div>';
- break;
- case "5": // mainline-log
- $htmlTitle = "log - mainline";
- $htmlMain .= '<div align="left" id="BodyLayer" name="BodyLayer" style="border: thin solid '.$cfg['main_bgcolor'].'; position:relative; width:740; height:498; padding-left: 5px; padding-right: 5px; z-index:1; overflow: scroll; visibility: visible">';
- $htmlMain .= '<pre>';
- $mainlineLog = $cfg["path"].'.bittorrent/tfmainline.log';
- if (is_file($mainlineLog))
- $htmlMain .= tfb_htmlencode(@file_get_contents($mainlineLog));
- else
- $htmlMain .= "mainline-log not found.";
- $htmlMain .= '</pre>';
- $htmlMain .= '</div>';
- break;
- case "8": // transfers
- $htmlTitle = "log - transfers";
- $htmlMain .= "<br>Select the transfer you wish to view the logfile for from below:<br>";
- $logList = getTransferArray('na');
- if ((isset($logList)) && (is_array($logList))) {
- $htmlMain .= '<ul>';
- foreach ($logList as $logFile) {
- if ((isset($logFile)) && ($logFile != "")) {
- $htmlMain .= '<li>';
- $htmlMain .= '<a href="'. _FILE_THIS .'?l=9&transfer='.urlencode($logFile).'">';
- $htmlMain .= tfb_htmlencode($logFile);
- $htmlMain .= '</a>';
- $htmlMain .= '</li>';
- }
- }
- $htmlMain .= '</ul>';
- }
- 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 .= '<div align="left" id="BodyLayer" name="BodyLayer" style="border: thin solid '.$cfg['main_bgcolor'].'; position:relative; width:740; height:498; padding-left: 5px; padding-right: 5px; z-index:1; overflow: scroll; visibility: visible">';
- $htmlMain .= '<pre>';
- $htmlMain .= tfb_htmlencode(getTransferLog($transfer));
- $htmlMain .= '</pre>';
- $htmlMain .= '</div>';
- } else {
- $htmlTitle = "log - transfer-log";
- $htmlMain .= '<font color="red">Error. missing params</font>';
- }
- 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 .= '<br>Select the task you wish to perform from below:<p>';
- $htmlMain .= '<a href="' . _FILE_THIS . '?y=1"><img src="themes/'.$cfg["theme"].'/images/arrow.gif" width="9" height="9" title="List files installed" border="0"> Lists</a> - view a list of currently installed torrentflux-b4rt files';
- $htmlMain .= '<p>';
- $htmlMain .= '<a href="' . _FILE_THIS . '?y=3"><img src="themes/'.$cfg["theme"].'/images/arrow.gif" width="9" height="9" title="Checksum Validation" border="0"> Checksum Validation</a> - check the integrity of installed torrentflux-b4rt files';
- $htmlMain .= '<p>';
- $htmlMain .= '<a href="' . _FILE_THIS . '?y=5"><img src="themes/'.$cfg["theme"].'/images/arrow.gif" width="9" height="9" title="Check Requirements" border="0"> Check Requirements</a> - check your server meets the requirements to run torrentflux-b4rt';
- $htmlMain .= '<br><br>';
- break;
- case "1": // misc - Lists
- $htmlTitle = "Misc - File Lists";
- $htmlMain .= '<br>Select an option from below:<p>';
- $htmlMain .= '<img src="themes/'.$cfg["theme"].'/images/arrow.gif" width="9" height="9" title="Files" border="0"> Files (';
- $htmlMain .= '<a href="' . _FILE_THIS . '?y=11" target="_blank">html</a>';
- $htmlMain .= ' / ';
- $htmlMain .= '<a href="' . _FILE_THIS . '?y=12" target="_blank">text</a>';
- $htmlMain .= ') - list files currently installed';
- $htmlMain .= '<p>';
- $htmlMain .= '<img src="themes/'.$cfg["theme"].'/images/arrow.gif" width="9" height="9" title="Checksums" border="0"> Checksums (';
- $htmlMain .= '<a href="' . _FILE_THIS . '?y=13" target="_blank">html</a>';
- $htmlMain .= ' / ';
- $htmlMain .= '<a href="' . _FILE_THIS . '?y=14" target="_blank">text</a>';
- $htmlMain .= ') - list checksums of files currently installed';
- $htmlMain .= '<br><br>';
- 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 .= '<p>';
- $htmlMain .= '<a href="' . _FILE_THIS . '?y=35" target="_blank"><img src="themes/'.$cfg["theme"].'/images/arrow.gif" width="9" height="9" title="Checksums of '._VERSION.'" border="0"> Checksums of '._VERSION.'</a>';
- $htmlMain .= '<p>';
- $htmlMain .= '<a href="' . _FILE_THIS . '?y=36" target="_blank"><img src="themes/'.$cfg["theme"].'/images/arrow.gif" width="9" height="9" title="Validate local files" border="0"> Validate local files</a>';
- $htmlMain .= '<br><br>';
- 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 .= '<br>Select the requirements you wish to check from below:<p>';
- $htmlMain .= "<strong>PHP Web</strong><br>Check your PHP web installation meets the requirements for web based activities in torrentflux-b4rt:<br>";
- $htmlMain .= '<a href="' . _FILE_THIS . '?y=51"><img src="themes/'.$cfg["theme"].'/images/arrow.gif" width="9" height="9" title="php-web" border="0"> Check PHP Web Requirements</a><br><br>';
- $htmlMain .= "<strong>PHP CLI</strong><br>Check your PHP commandline binary installation meets the requirements for commandline based activities in torrentflux-b4rt:<br>";
- $htmlMain .= '<a href="' . _FILE_THIS . '?y=52"><img src="themes/'.$cfg["theme"].'/images/arrow.gif" width="9" height="9" title="php-cli" border="0"> Check PHP CLI Binary Requirements</a><br><br>';
- $htmlMain .= "<strong>Perl</strong><br>Check your Perl installation meets the requirements for perl based activities in torrentflux-b4rt:<br>";
- $htmlMain .= '<a href="' . _FILE_THIS . '?y=53"><img src="themes/'.$cfg["theme"].'/images/arrow.gif" width="9" height="9" title="Perl" border="0"> Check Perl Requirements</a>';
- $htmlMain .= '<br><br>';
- break;
- case "51": // misc - Check - php-web
- $htmlTitle = "Misc - Check Requirements - PHP Web Installation";
- $htmlMain .= '<div align="left" id="BodyLayer" name="BodyLayer" style="border: thin solid '.$cfg['main_bgcolor'].'; position:relative; width:740; height:498; padding-left: 5px; padding-right: 5px; z-index:1; overflow: scroll; visibility: visible">';
- $htmlMain .= phpCheckWeb();
- $htmlMain .= '</div>';
- break;
- case "52": // misc - Check - php-cli
- $htmlTitle = "Misc - Check Requirements - PHP CLI Binary Installation";
- $htmlMain .= '<div align="left" id="BodyLayer" name="BodyLayer" style="border: thin solid '.$cfg['main_bgcolor'].'; position:relative; width:740; height:498; padding-left: 5px; padding-right: 5px; z-index:1; overflow: scroll; visibility: visible">';
- $htmlMain .= '<pre>';
- $htmlMain .= tfb_htmlencode(safePhpCli($cfg["bin_php"], tfb_shellencode($cfg["docroot"]."bin/check/check-cli.php")));
- $htmlMain .= '</pre>';
- $htmlMain .= '</div>';
- break;
- case "53": // misc - Check - Perl
- $htmlTitle = "Misc - Check Requirements - Perl";
- $htmlMain .= '<div align="left" id="BodyLayer" name="BodyLayer" style="border: thin solid '.$cfg['main_bgcolor'].'; position:relative; width:740; height:498; padding-left: 5px; padding-right: 5px; z-index:1; overflow: scroll; visibility: visible">';
- $htmlMain .= '<pre>';
- $htmlMain .= tfb_htmlencode(shell_exec($cfg["perlCmd"]." ".tfb_shellencode($cfg["docroot"]."bin/check/check.pl")." all"));
- $htmlMain .= '</pre>';
- $htmlMain .= '</div>';
- break;
- case "531": // misc - Check - Perl - nzbperl
- $htmlTitle = "Misc - Check Requirements - Nzbperl";
- $htmlMain .= '<div align="left" id="BodyLayer" name="BodyLayer" style="border: thin solid '.$cfg['main_bgcolor'].'; position:relative; width:740; height:498; padding-left: 5px; padding-right: 5px; z-index:1; overflow: scroll; visibility: visible">';
- $htmlMain .= '<pre>';
- $htmlMain .= tfb_htmlencode(shell_exec($cfg["perlCmd"]." ".tfb_shellencode($cfg["docroot"]."bin/check/check.pl")." nzbperl"));
- $htmlMain .= '</pre>';
- $htmlMain .= '</div>';
- 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 .= '<br>Select the information you wish to view from below:<p>';
- $htmlMain .= '<a href="' . _FILE_THIS . '?z=1"><img src="themes/'.$cfg["theme"].'/images/arrow.gif" width="9" height="9" title="Version" border="0"> Version</a> - check your torrentflux-b4rt version is up to date';
- $htmlMain .= '<p>';
- $htmlMain .= '<a href="' . _FILE_THIS . '?z=2"><img src="themes/'.$cfg["theme"].'/images/arrow.gif" width="9" height="9" title="News" border="0"> News</a> - view the release news for each version of torrentflux-b4rt';
- $htmlMain .= '<p>';
- $htmlMain .= '<a href="' . _FILE_THIS . '?z=3"><img src="themes/'.$cfg["theme"].'/images/arrow.gif" width="9" height="9" title="Changelog" border="0"> Changelog</a> - view the changelogs for each version of torrentflux-b4rt';
- $htmlMain .= '<br><br>';
- 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 .= '<br>';
- if (strpos(_VERSION, "svn") !== false) {
- $htmlMain .= '<strong>This Version: </strong>'._VERSION;
- $htmlMain .= '<br><br>';
- $htmlMain .= '<strong>Latest Release: </strong>';
- $htmlMain .= $versionAvailable;
- $htmlMain .= '<br><br>';
- $htmlMain .= '<font color="blue">This Version is a svn-Version.</font>';
- } else {
- if ($versionAvailable != _VERSION) {
- $htmlMain .= '<strong>This Version: </strong>';
- $htmlMain .= '<font color="red">'._VERSION.'</font>';
- $htmlMain .= '<br><br>';
- $htmlMain .= '<strong>Available Version: </strong>';
- $htmlMain .= $versionAvailable;
- $htmlMain .= '<br><br>';
- $htmlMain .= '<strong><font color="red">There is a new Version available !</font></strong>';
- $htmlMain .= '<br><br>';
- $htmlMain .= '<form name="update" action="' . _FILE_THIS . '" method="post">';
- $htmlMain .= '<input type="Hidden" name="u" value="0">';
- $htmlMain .= '<input type="submit" value="Update to Version '.$versionAvailable.'">';
- $htmlMain .= '</form>';
- $htmlMain .= '<strong>Current Release: </strong>';
- $htmlMain .= '<br>';
- $htmlMain .= '<a href="'._URL_RELEASE.'" target="_blank"><img src="themes/'.$cfg["theme"].'/images/arrow.gif" width="9" height="9" title="Current Release" border="0"> '._URL_RELEASE.'</a>';
- $htmlMain .= '<br><br>';
- $htmlMain .= '<strong>Homepage: </strong>';
- $htmlMain .= '<br>';
- $htmlMain .= '<a href="'._URL_HOME.'" target="_blank"><img src="themes/'.$cfg["theme"].'/images/arrow.gif" width="9" height="9" title="Homepage on BerliOS" border="0"> '._URL_HOME.'</a>';
- $htmlMain .= '<br>';
- } else {
- $htmlMain .= '<strong>This Version: </strong>'._VERSION;
- $htmlMain .= '<br><br>';
- $htmlMain .= '<strong>Available Version: </strong>';
- $htmlMain .= $versionAvailable;
- $htmlMain .= '<br><br>';
- $htmlMain .= '<font color="green">This Version looks good.</font>';
- }
- }
- $htmlMain .= '<br><br>';
- } else { // could not get the version
- $statusImage = "black.gif";
- $htmlTop = '<strong><font color="red">Error.</font></strong>';
- $htmlMain = '<br>';
- $htmlMain .= '<font color="red">Error getting available version.</font>';
- $htmlMain .= '<br><br>';
- $htmlMain .= '<strong>Current Release: </strong>';
- $htmlMain .= '<br>';
- $htmlMain .= '<a href="'._URL_RELEASE.'" target="_blank"><img src="themes/'.$cfg["theme"].'/images/arrow.gif" width="9" height="9" title="Current Release" border="0"> '._URL_RELEASE.'</a>';
- $htmlMain .= '<br><br>';
- $htmlMain .= '<strong>Homepage: </strong>';
- $htmlMain .= '<br>';
- $htmlMain .= '<a href="'._URL_HOME.'" target="_blank"><img src="themes/'.$cfg["theme"].'/images/arrow.gif" width="9" height="9" title="Homepage on BerliOS" border="0"> '._URL_HOME.'</a>';
- $htmlMain .= '<br>';
- }
- break;
- case "2": // News
- $htmlTitle = "About - News";
- $htmlMain .= '<br>';
- $htmlMain .= @gzinflate(getDataFromUrl(_SUPERADMIN_URLBASE . _SUPERADMIN_PROXY ."?a=0"));
- $htmlMain .= '<br><br>';
- break;
- case "3": // Changelog;
- $htmlTitle = "About - Changelog";
- $htmlMain .= '<div align="left" id="BodyLayer" name="BodyLayer" style="border: thin solid '.$cfg['main_bgcolor'].'; position:relative; width:740; height:498; padding-left: 5px; padding-right: 5px; z-index:1; overflow: scroll; visibility: visible">';
- $htmlMain .= '<pre>';
- $htmlMain .= tfb_htmlencode(@gzinflate(getDataFromUrl(_SUPERADMIN_URLBASE . _SUPERADMIN_PROXY ."?a=1")));
- $htmlMain .= '</pre>';
- $htmlMain .= '</div>';
- 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 = "<strong>Update - Check</strong>";
- $htmlMain = "<br>Update from your Version possible.";
- $htmlMain .= '<br><br>';
- $htmlMain .= '<form name="update" action="' . _FILE_THIS . '" method="post">';
- $htmlMain .= '<input type="Hidden" name="u" value="1">';
- $htmlMain .= '<input type="submit" value="Next Step - Database-Update">';
- $htmlMain .= '</form>';
- $htmlMain .= '<br>';
- $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 = "<strong>Update - Database</strong>";
- $htmlMain = "<br>Database-Update in this Update not needed.";
- $htmlMain .= '<br><br>';
- $htmlMain .= '<form name="update" action="' . _FILE_THIS . '" method="post">';
- $htmlMain .= '<input type="Hidden" name="u" value="3">';
- $htmlMain .= '<input type="submit" value="Next Step - File-Update">';
- $htmlMain .= '</form>';
- $htmlMain .= '<br>';
- $statusImage = "yellow.gif";
- $htmlTitle = "Update";
- printPage();
- exit();
- } else if ($updateNeeded == "1") {
- $htmlTop = "<strong>Update - Database</strong>";
- $htmlMain = "<br>Database-Update in this Update is needed.";
- $htmlMain .= '<br><br>';
- $htmlMain .= 'Type: <em>'.$cfg["db_type"].'</em>';
- $htmlMain .= '<br><br>';
- $htmlMain .= '<form name="update" action="' . _FILE_THIS . '" method="post">';
- $htmlMain .= '<input type="Hidden" name="u" value="2">';
- $htmlMain .= '<input type="submit" value="Next Step - Perform Database-Update">';
- $htmlMain .= '</form>';
- $htmlMain .= '<br>';
- $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('<strong>Update - Database</strong><br><br><em>Updating Database... Please Wait...</em><ul>');
- $updateSQLStates = explode("\n",$updateSQLData);
- // get ado-connection
- $dbCon = getAdoConnection();
- if (!$dbCon) {
- echo '</em></li></ul><font color="red"><strong>Error updating Database.</strong></font><br><br>Please restore backup and try again (or do manual update).<br><br>';
- echo $dbCon->ErrorMsg();
- exit();
- } else {
- foreach ($updateSQLStates as $sqlState) {
- $sqlState = trim($sqlState);
- if ((isset($sqlState)) && ($sqlState != "") && ((substr($sqlState, 0, 2)) != "--")) {
- sendLine('<li>'.$sqlState);
- $dbCon->Execute($sqlState);
- if($dbCon->ErrorNo() == 0) {
- sendLine(' <font color="green">Ok</font></li>');
- } else { // damn there was an error
- // close ado-connection
- $dbCon->Close();
- // talk and out
- echo '</em></li></ul><font color="red"><strong>Error updating Database.</strong></font><br><br>Please restore backup and try again (or do manual update).<br><br>';
- exit();
- }
- }
- }
- // close ado-connection
- $dbCon->Close();
- // talk and continue
- sendLine('</ul><p><font color="green">Database-Update done.</font><br><br>');
- sendLine('<form name="update" action="' . _FILE_THIS . '" method="post"><input type="Hidden" name="u" value="3"><input type="submit" value="Next Step - File-Update"></form><br>');
- 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('<strong>Update - Files</strong>');
- sendLine('<br><br>');
- sendLine('Files that require an update in this Version:');
- sendLine('<pre>');
- sendLine($updateFileList);
- sendLine('</pre>');
- sendLine('<form name="update" action="' . _FILE_THIS . '" method="post">');
- sendLine('<input type="Hidden" name="u" value="4">');
- sendLine('<input type="submit" value="Next Step - Perform File-Update">');
- sendLine('</form>');
- sendLine('<strong>Ensure script can write to docroot <em>'.$cfg['docroot'].'</em> now !</strong>');
- exit();
- } else {
- updateError("\n"."cant get file-list."."\n".$updateFileList);
- }
- break;
- case "4":
- sendLine('<strong>Update - Files</strong><br><br><em>Updating Files... Please Wait...</em><br><ul>');
- sendLine('<li>Getting Update-Archive:<br>');
- @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('</li></ul><br><br><font color="red"><strong>Error getting Update-Archive.</strong></font><br><br>Please restore backup and try again (or do manual update).<br><br>');
- 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('<font color="green">done</font></li>');
- } else {
- sendLine('<br></li></ul><br><br><strong><font color="red">Error writing archive <em>'.$cfg['docroot']._UPDATE_ARCHIVE.'</em>.</font></strong><br><br>Please restore backup and try again (or do manual update).<br><br>');
- exit();
- }
- } else {
- sendLine('</li></ul><br><br><strong><font color="red">Error updating files.</font></strong><br><br>Please restore backup and try again (or do manual update).<br><br>');
- exit();
- }
- // validate archive
- sendLine('<li>Validating Update-Archive: ');
- if ((file_exists($cfg['docroot']._UPDATE_ARCHIVE))
- && ($md5hash == @md5_file($cfg['docroot']._UPDATE_ARCHIVE))) {
- sendLine('<font color="green">Ok</font> (<em>'.$md5hash.'</em>)<br></li>');
- } else {
- sendLine('<font color="red">failed</font></ul><br><br>Please restore backup and try again (or do manual update).</strong><br><br>');
- exit();
- }
- // extract archive
- sendLine('<li>Extracting Update-Archive: <br>');
- sendLine('<em>');
- $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('</em>');
- sendLine('<font color="green">done</font></li>');
- // delete archive
- sendLine('<li>Deleting Update-Archive: ');
- if (@unlink($cfg['docroot']._UPDATE_ARCHIVE))
- sendLine('<font color="green">done</font></li>');
- else
- sendLine('<font color="red">failed</font><br>remove archive '.$cfg['docroot']._UPDATE_ARCHIVE.' manual now.</li>');
- // version-file
- sendLine('<li>Updating Version-Information: ');
- $versionAvailable = trim(getDataFromUrl(_SUPERADMIN_URLBASE._SUPERADMIN_PROXY));
- if ((isset($versionAvailable)) && ($versionAvailable != "")) {
- if ($handle = @fopen("version.php", "w")) {
- if (@fwrite($handle, '<?php define("_VERSION", "'.$versionAvailable.'"); ?>')) {
- @fclose($handle);
- sendLine(' <font color="green">done</font></li>');
- } else {
- @fclose($handle);
- sendLine('</li></ul><br><br><font color="red"><strong>Error writing version-file</strong></font><br><br>Please restore backup and try again (or do manual update).<br><br>');
- exit();
- }
- } else {
- sendLine('<br><br>');
- sendLine('</li></ul><font color="red"><strong>Error writing version-file</strong></font><br><br>Please restore backup and try again (or do manual update).<br><br>');
- exit();
- }
- } else {
- sendLine('</li></ul><br><br><font color="red"><strong>Error getting version-file</strong></font><br><br>Please restore backup and try again (or do manual update).<br><br>');
- exit();
- }
- sendLine('</ul>');
- // done
- sendLine('<p><em>Done Updating Files.</em></p>');
- sendLine('<hr><br><strong>Update to '.$versionAvailable.' completed.</strong><br><br>');
- sendLine('<form name="update" action="#" method="get"><input type="submit" onClick="window.close()" value="Close"></form>');
- sendLine('<br>');
- // 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 .= '<div align="left" id="BodyLayer" name="BodyLayer" style="border: thin solid '.$cfg['main_bgcolor'].'; position:relative; width:740; height:498; padding-left: 5px; padding-right: 5px; z-index:1; overflow: scroll; visibility: visible">';
- $htmlMain .= '<pre>';
- $htmlMain .= tfb_htmlencode(@file_get_contents($cfg["path"].'.fluxd/fluxd.log'));
- $htmlMain .= '</pre>';
- $htmlMain .= '</div>';
- break;
- case "2": // fluxd-error-log
- $htmlTitle = "fluxd - error-log";
- $htmlMain .= '<div align="left" id="BodyLayer" name="BodyLayer" style="border: thin solid '.$cfg['main_bgcolor'].'; position:relative; width:740; height:498; padding-left: 5px; padding-right: 5px; z-index:1; overflow: scroll; visibility: visible">';
- $htmlMain .= '<pre>';
- $htmlMain .= tfb_htmlencode(@file_get_contents($cfg["path"].'.fluxd/fluxd-error.log'));
- $htmlMain .= '</pre>';
- $htmlMain .= '</div>';
- break;
- case "3": // fluxd-ps
- $htmlTitle = "fluxd - ps";
- $htmlMain .= '<div align="left" id="BodyLayer" name="BodyLayer" style="border: thin solid '.$cfg['main_bgcolor'].'; position:relative; width:740; height:498; padding-left: 5px; padding-right: 5px; z-index:1; overflow: scroll; visibility: visible">';
- $htmlMain .= '<pre>';
- $htmlMain .= tfb_htmlencode(shell_exec("ps auxww | ".$cfg['bin_grep']." fluxd | ".$cfg['bin_grep']." -v grep"));
- $htmlMain .= '</pre>';
- $htmlMain .= '</div>';
- break;
- case "4": // fluxd-status
- $htmlTitle = "fluxd - status";
- if (Fluxd::isRunning()) {
- $htmlMain .= '<div align="left" id="BodyLayer" name="BodyLayer" style="border: thin solid '.$cfg['main_bgcolor'].'; position:relative; width:740; height:498; padding-left: 5px; padding-right: 5px; z-index:1; overflow: scroll; visibility: visible">';
- $htmlMain .= '<pre>';
- $htmlMain .= tfb_htmlencode(Fluxd::status());
- $htmlMain .= '</pre>';
- $htmlMain .= '</div>';
- } else {
- $htmlMain .= '<br><strong>fluxd not running</strong>';
- }
- break;
- case "5": // fluxd-check
- $htmlTitle = "fluxd - check";
- $htmlMain .= '<div align="left" id="BodyLayer" name="BodyLayer" style="border: thin solid '.$cfg['main_bgcolor'].'; position:relative; width:740; height:498; padding-left: 5px; padding-right: 5px; z-index:1; overflow: scroll; visibility: visible">';
- $htmlMain .= '<pre>';
- $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 .= '</pre>';
- $htmlMain .= '</div>';
- break;
- case "6": // fluxd-db-debug
- $htmlTitle = "fluxd - db-debug";
- $htmlMain .= '<div align="left" id="BodyLayer" name="BodyLayer" style="border: thin solid '.$cfg['main_bgcolor'].'; position:relative; width:740; height:498; padding-left: 5px; padding-right: 5px; z-index:1; overflow: scroll; visibility: visible">';
- $htmlMain .= '<pre>';
- $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 .= '</pre>';
- $htmlMain .= '</div>';
- break;
- case "9": // fluxd-version
- $htmlTitle = "fluxd - version";
- $htmlMain .= '<div align="left" id="BodyLayer" name="BodyLayer" style="border: thin solid '.$cfg['main_bgcolor'].'; position:relative; width:740; height:498; padding-left: 5px; padding-right: 5px; z-index:1; overflow: scroll; visibility: visible">';
- $htmlMain .= '<pre>';
- $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 .= '</pre>';
- $htmlMain .= '</div>';
- 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 .= '<div align="left" id="BodyLayer" name="BodyLayer" style="border: thin solid '.$cfg['main_bgcolor'].'; position:relative; width:740; height:498; padding-left: 5px; padding-right: 5px; z-index:1; overflow: scroll; visibility: visible">';
- $htmlMain .= '<pre>';
- $htmlMain .= tfb_htmlencode(@file_get_contents($cfg["path"].'.fluazu/fluazu.log'));
- $htmlMain .= '</pre>';
- $htmlMain .= '</div>';
- break;
- case "3": // fluazu-ps
- $htmlTitle = "fluazu - ps";
- $htmlMain .= '<div align="left" id="BodyLayer" name="BodyLayer" style="border: thin solid '.$cfg['main_bgcolor'].'; position:relative; width:740; height:498; padding-left: 5px; padding-right: 5px; z-index:1; overflow: scroll; visibility: visible">';
- $htmlMain .= '<pre>';
- $htmlMain .= tfb_htmlencode(shell_exec("ps auxww | ".$cfg['bin_grep']." fluazu.py | ".$cfg['bin_grep']." -v grep"));
- $htmlMain .= '</pre>';
- $htmlMain .= '</div>';
- break;
- case "9": // fluazu-version
- $htmlTitle = "fluazu - version";
- $htmlMain .= '<div align="left" id="BodyLayer" name="BodyLayer" style="border: thin solid '.$cfg['main_bgcolor'].'; position:relative; width:740; height:498; padding-left: 5px; padding-right: 5px; z-index:1; overflow: scroll; visibility: visible">';
- $htmlMain .= '<pre>';
- $htmlMain .= tfb_htmlencode(shell_exec("cd ".tfb_shellencode($cfg["docroot"]."bin/clients/fluazu/")."; ".$cfg["pythonCmd"]." -OO fluazu.py --version"));
- $htmlMain .= '</pre>';
- $htmlMain .= '</div>';
- 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 .= '<a href="' . _FILE_THIS . '?t=0">Transfer Bulk-ops</a>';
- $htmlTop .= ' | ';
- $htmlTop .= '<a href="' . _FILE_THIS . '?p=0">Processes</a>';
- $htmlTop .= ' | ';
- $htmlTop .= '<a href="' . _FILE_THIS . '?m=0">Maintenance</a>';
- $htmlTop .= ' | ';
- $htmlTop .= '<a href="' . _FILE_THIS . '?b=0">Backup</a>';
- $htmlTop .= ' | ';
- $htmlTop .= '<a href="' . _FILE_THIS . '?l=0">Log</a>';
- $htmlTop .= ' | ';
- $htmlTop .= '<a href="' . _FILE_THIS . '?y=0">Misc</a>';
- $htmlTop .= ' | ';
- $htmlTop .= '<a href="' . _FILE_THIS . '?z=0">About</a>';
- // body
- switch($action) {
- case "b": // backup passthru
- case "-b": // backup-error passthru
- if ($action == "b")
- $statusImage = "yellow.gif";
- else
- $statusImage = "red.gif";
- //
- $htmlMain .= '<table width="100%" bgcolor="'.$cfg["table_data_bg"].'" border="0" cellpadding="4" cellspacing="0"><tr><td width="100%">';
- $htmlMain .= '<a href="' . _FILE_THIS . '?b=0">Create Backup</a>';
- $htmlMain .= ' | ';
- $htmlMain .= '<a href="' . _FILE_THIS . '?b=3">Backups currently on server</a>';
- $htmlMain .= '</td><td align="right" nowrap><strong>Backup</strong></td>';
- $htmlMain .= '</tr></table>';
- break;
- case "-u": // update-error passthru
- $statusImage = "red.gif";
- $htmlTitle = "Update";
- $htmlMain = '<br><font color="red"><strong>Update from your version not possible.</strong></font>';
- $htmlMain .= '<br><br>';
- $htmlMain .= 'Please use the most recent tarball and perform a manual update.';
- $htmlMain .= '<br>';
- break;
- case "t": // transfers passthru
- $statusImage = "black.gif";
- break;
- case "p": // processes passthru
- $statusImage = "black.gif";
- $htmlMain .= '<table width="100%" bgcolor="'.$cfg["table_data_bg"].'" border="0" cellpadding="4" cellspacing="0"><tr><td width="100%">';
- $htmlMain .= '<a href="' . _FILE_THIS . '?p=1">All</a>';
- $htmlMain .= ' | ';
- $htmlMain .= '<a href="' . _FILE_THIS . '?p=2">Transfers</a>';
- $htmlMain .= '</td><td align="right"><strong>Processes</strong></td>';
- $htmlMain .= '</tr></table>';
- break;
- case "m": // maintenance passthru
- $statusImage = "black.gif";
- $htmlMain .= '<table width="100%" bgcolor="'.$cfg["table_data_bg"].'" border="0" cellpadding="4" cellspacing="0"><tr><td width="100%">';
- $htmlMain .= '<a href="' . _FILE_THIS . '?m=1">Main</a>';
- $htmlMain .= ' | ';
- $htmlMain .= '<a href="' . _FILE_THIS . '?m=2">Kill</a>';
- $htmlMain .= ' | ';
- $htmlMain .= '<a href="' . _FILE_THIS . '?m=3">Clean</a>';
- $htmlMain .= ' | ';
- $htmlMain .= '<a href="' . _FILE_THIS . '?m=4">Repair</a>';
- $htmlMain .= ' | ';
- $htmlMain .= '<a href="' . _FILE_THIS . '?m=5">Reset</a>';
- $htmlMain .= ' | ';
- $htmlMain .= '<a href="' . _FILE_THIS . '?m=6">Lock</a>';
- $htmlMain .= '</td><td align="right"><strong>Maintenance</strong></td>';
- $htmlMain .= '</tr></table>';
- break;
- case "l": // log passthru
- $statusImage = "black.gif";
- $htmlMain .= '<table width="100%" bgcolor="'.$cfg["table_data_bg"].'" border="0" cellpadding="4" cellspacing="0"><tr><td width="100%">';
- $htmlMain .= '<a href="' . _FILE_THIS . '?l=1">fluxd</a>';
- $htmlMain .= ' | ';
- $htmlMain .= '<a href="' . _FILE_THIS . '?l=2">fluxd-error</a>';
- $htmlMain .= ' | ';
- $htmlMain .= '<a href="' . _FILE_THIS . '?l=3">fluazu</a>';
- $htmlMain .= ' | ';
- $htmlMain .= '<a href="' . _FILE_THIS . '?l=5">mainline</a>';
- $htmlMain .= ' | ';
- $htmlMain .= '<a href="' . _FILE_THIS . '?l=8">transfers</a>';
- $htmlMain .= '</td><td align="right"><strong>Log</strong></td>';
- $htmlMain .= '</tr></table>';
- break;
- case "y": // misc passthru
- $statusImage = "black.gif";
- $htmlMain .= '<table width="100%" bgcolor="'.$cfg["table_data_bg"].'" border="0" cellpadding="4" cellspacing="0"><tr><td width="100%">';
- $htmlMain .= '<a href="' . _FILE_THIS . '?y=1">Lists</a>';
- $htmlMain .= ' | ';
- $htmlMain .= '<a href="' . _FILE_THIS . '?y=3">Checksum Validation</a>';
- $htmlMain .= ' | ';
- $htmlMain .= '<a href="' . _FILE_THIS . '?y=5">Check Requirements</a>';
- $htmlMain .= '</td><td align="right" nowrap><strong>Misc</strong></td>';
- $htmlMain .= '</tr></table>';
- break;
- case "z": // about passthru
- $statusImage = "black.gif";
- $htmlMain .= '<table width="100%" bgcolor="'.$cfg["table_data_bg"].'" border="0" cellpadding="4" cellspacing="0"><tr><td width="100%">';
- $htmlMain .= '<a href="' . _FILE_THIS . '?z=1">Version</a>';
- $htmlMain .= ' | ';
- $htmlMain .= '<a href="' . _FILE_THIS . '?z=2">News</a>';
- $htmlMain .= ' | ';
- $htmlMain .= '<a href="' . _FILE_THIS . '?z=3">Changelog</a>';
- $htmlMain .= '</td><td align="right" nowrap><strong>About</strong></td>';
- $htmlMain .= '</tr></table>';
- break;
- case "f": // fluxd passthru
- $htmlTop = "";
- $statusImage = "";
- $htmlMain .= '<table width="100%" bgcolor="'.$cfg["table_data_bg"].'" border="0" cellpadding="4" cellspacing="0"><tr><td width="100%">';
- $htmlMain .= '<a href="' . _FILE_THIS . '?f=1">log</a>';
- $htmlMain .= ' | ';
- $htmlMain .= '<a href="' . _FILE_THIS . '?f=2">error-log</a>';
- $htmlMain .= ' | ';
- $htmlMain .= '<a href="' . _FILE_THIS . '?f=3">ps</a>';
- if (Fluxd::isRunning()) {
- $htmlMain .= ' | ';
- $htmlMain .= '<a href="' . _FILE_THIS . '?f=4">status</a>';
- } else {
- $htmlMain .= ' | ';
- $htmlMain .= '<a href="' . _FILE_THIS . '?f=5">check</a>';
- $htmlMain .= ' | ';
- $htmlMain .= '<a href="' . _FILE_THIS . '?f=6">db-debug</a>';
- $htmlMain .= ' | ';
- $htmlMain .= '<a href="' . _FILE_THIS . '?f=9">version</a>';
- }
- $htmlMain .= '</td><td align="right"><strong>fluxd</strong>';
- $htmlMain .= '</tr></table>';
- break;
- case "_": // default
- default:
- $htmlTitle = "SuperAdmin";
- $statusImage = "black.gif";
- $htmlMain = '<br><div align="left">';
- $htmlMain .= '<p>Select the superadmin task you wish to perform below:<br><br>';
- $htmlMain .= '<a href="' . _FILE_THIS . '?t=0"><img src="themes/'.$cfg["theme"].'/images/arrow.gif" width="9" height="9" title="Transfer Bulk Ops" border="0"> Transfer Bulk Ops</a> - bulk start/stop/resume transfers';
- $htmlMain .= '<p>';
- $htmlMain .= '<a href="' . _FILE_THIS . '?p=0"><img src="themes/'.$cfg["theme"].'/images/arrow.gif" width="9" height="9" title="Processes" border="0"> Processes</a> - view detailed process info; force stop transfer processes';
- $htmlMain .= '<p>';
- $htmlMain .= '<a href="' . _FILE_THIS . '?m=0"><img src="themes/'.$cfg["theme"].'/images/arrow.gif" width="9" height="9" title="Maintenance" border="0"> Maintenance</a> - clean up and maintenance';
- $htmlMain .= '<p>';
- $htmlMain .= '<a href="' . _FILE_THIS . '?b=0"><img src="themes/'.$cfg["theme"].'/images/arrow.gif" width="9" height="9" title="Backup" border="0"> Backup</a> - create backups; download saved backups';
- $htmlMain .= '<p>';
- $htmlMain .= '<a href="' . _FILE_THIS . '?l=0"><img src="themes/'.$cfg["theme"].'/images/arrow.gif" width="9" height="9" title="Log" border="0"> Log</a> - view logs';
- $htmlMain .= '<p>';
- $htmlMain .= '<a href="' . _FILE_THIS . '?y=0"><img src="themes/'.$cfg["theme"].'/images/arrow.gif" width="9" height="9" title="Misc" border="0"> Misc</a> - test for PHP and Perl requirements; view list of installed files';
- $htmlMain .= '<p>';
- $htmlMain .= '<a href="' . _FILE_THIS . '?z=0"><img src="themes/'.$cfg["theme"].'/images/arrow.gif" width="9" height="9" title="About" border="0"> About</a> - version checking, updates, news, changelog; check installed file integrity';
- $htmlMain .= '</div><br><br>';
- 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('<HTML>',$echoMode);
- doEcho('<HEAD>',$echoMode);
- doEcho('<TITLE>'.$cfg["pagetitle"].' - SuperAdmin</TITLE>',$echoMode);
- doEcho('<link rel="icon" href="themes/'.$cfg["theme"].'/images/favicon.ico" type="image/x-icon" />',$echoMode);
- doEcho('<link rel="shortcut icon" href="themes/'.$cfg["theme"].'/images/favicon.ico" type="image/x-icon" />',$echoMode);
- // theme-switch
- if ((strpos($cfg["theme"], '/')) === false)
- doEcho('<LINK REL="StyleSheet" HREF="themes/'.$cfg["theme"].'/css/default.css" TYPE="text/css">',$echoMode);
- else
- doEcho('<LINK REL="StyleSheet" HREF="themes/'.$cfg["theme"].'/style.css" TYPE="text/css">',$echoMode);
- doEcho('<META HTTP-EQUIV="Pragma" CONTENT="no-cache; charset='. $cfg['_CHARSET'] .'">',$echoMode);
- doEcho('</HEAD>',$echoMode);
- doEcho('<BODY topmargin="8" leftmargin="5" bgcolor="'.$cfg["main_bgcolor"].'">',$echoMode);
- doEcho('<div align="center">',$echoMode);
- doEcho('<table border="0" cellpadding="0" cellspacing="0">',$echoMode);
- doEcho('<tr>',$echoMode);
- doEcho('<td>',$echoMode);
- doEcho('<table border="1" bordercolor="'.$cfg["table_border_dk"].'" cellpadding="4" cellspacing="0">',$echoMode);
- doEcho('<tr>',$echoMode);
- doEcho('<td bgcolor="'.$cfg["main_bgcolor"].'" background="themes/'.$cfg["theme"].'/images/bar.gif">',$echoMode);
- doEcho('<table width="100%" cellpadding="0" cellspacing="0" border="0">',$echoMode);
- doEcho('<tr>',$echoMode);
- doEcho('<td align="left"><font class="title">'.$cfg["pagetitle"]." - ".$htmlTitle.'</font></td>',$echoMode);
- doEcho('</td>',$echoMode);
- doEcho('</tr>',$echoMode);
- doEcho('</table>',$echoMode);
- doEcho('</td>',$echoMode);
- doEcho('</tr>',$echoMode);
- doEcho('<tr>',$echoMode);
- doEcho('<td bgcolor="'.$cfg["table_header_bg"].'">',$echoMode);
- doEcho('<div align="center">',$echoMode);
- doEcho('<table width="100%" bgcolor="'.$cfg["body_data_bg"].'">',$echoMode);
- doEcho('<tr>',$echoMode);
- doEcho('<td>',$echoMode);
- doEcho('<div align="center">',$echoMode);
- doEcho('<table width="100%" cellpadding="0" cellspacing="0" border="0">',$echoMode);
- doEcho('<tr>',$echoMode);
- doEcho('<td align="left">',$echoMode);
- doEcho($htmlTop,$echoMode);
- doEcho('</td>',$echoMode);
- doEcho('<td align="right" width="16">',$echoMode);
- if ($statusImage != "") {
- if ($statusImage != "yellow.gif")
- doEcho('<a href="' . _FILE_THIS . '">',$echoMode);
- doEcho('<img src="themes/'.$cfg["theme"].'/images/'.$statusImage.'" width="16" height="16" border="0" title="'.$statusMessage.'">',$echoMode);
- if ($statusImage != "yellow.gif")
- doEcho('</a>',$echoMode);
- }
- doEcho('</td>',$echoMode);
- doEcho('</tr>',$echoMode);
- doEcho('</table>',$echoMode);
- doEcho('<table bgcolor="'.$cfg["table_header_bg"].'" width="750" cellpadding="1">',$echoMode);
- doEcho('<tr>',$echoMode);
- doEcho('<td>',$echoMode);
- doEcho('<div align="left">',$echoMode);
- doEcho('<table border="0" cellpadding="2" cellspacing="2" width="100%">',$echoMode);
- }
- /**
- * prints the page-end
- */
- function printPageEnd($echoMode = 0) {
- doEcho('</table>',$echoMode);
- doEcho('</div>',$echoMode);
- doEcho('</td>',$echoMode);
- doEcho('</tr>',$echoMode);
- doEcho('</table>',$echoMode);
- doEcho('</td>',$echoMode);
- doEcho('</tr>',$echoMode);
- doEcho('</table>',$echoMode);
- doEcho('</div>',$echoMode);
- doEcho('</td>',$echoMode);
- doEcho('</tr>',$echoMode);
- doEcho('</table>',$echoMode);
- doEcho('</td>',$echoMode);
- doEcho('</tr>',$echoMode);
- doEcho('</table>',$echoMode);
- doEcho('</div>',$echoMode);
- doEcho('</BODY>',$echoMode);
- doEcho('</HTML>',$echoMode);
- }
- /**
- * bails out cause of version-error.
- */
- function updateErrorNice($message = "") {
- global $statusImage, $statusMessage, $htmlTop, $htmlMain;
- $htmlTop = "<strong>Update</strong>";
- $htmlMain = '<br><font color="red"><strong>Update from your Version not possible.</strong></font>';
- $htmlMain .= '<br><br>';
- $htmlMain .= 'Please use the most recent tarball and perform a manual update.';
- $htmlMain .= '<br>';
- if ((isset($message)) && ($message != "") && (trim($message) != "0"))
- $htmlMain .= '<br><pre>'.$message.'</pre>';
- $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 .= '<strong>Available Tarballs: </strong>';
- $retVal .= '<br>';
- $retVal .= '<table cellpadding="2" cellspacing="1" border="1" bordercolor="'.$cfg["table_border_dk"].'" bgcolor="'.$cfg["body_data_bg"].'">';
- $retVal .= '<tr>';
- $retVal .= '<td align="center" bgcolor="'.$cfg["table_header_bg"].'"> </td>';
- $retVal .= '<td align="center" bgcolor="'.$cfg["table_header_bg"].'"><strong>Version</strong></td>';
- $retVal .= '<td align="center" bgcolor="'.$cfg["table_header_bg"].'"><strong>Checksum</strong></td>';
- $retVal .= '</tr>';
- $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 .= '<tr>';
- $retVal .= '<td align="center">';
- $retVal .= '<a href="'._SUPERADMIN_URLBASE.'files/'.$release.'">';
- $retVal .= '<img src="themes/'.$cfg["theme"].'/images/download_owner.gif" title="Download '.$releaseVersion.'" border="0">';
- $retVal .= '</a>';
- $retVal .= '</td>';
- $retVal .= '<td align="right">';
- $retVal .= '<a href="'._SUPERADMIN_URLBASE.'files/'.$release.'">';
- $retVal .= $releaseVersion;
- $retVal .= '</a>';
- $retVal .= '</td>';
- $retVal .= '<td align="right">';
- $retVal .= '<a href="'._SUPERADMIN_URLBASE.'files/'.$release.'.md5">';
- $retVal .= 'md5';
- $retVal .= '</a>';
- $retVal .= '</td>';
- $retVal .= '</tr>';
- }
- }
- $retVal .= '</table>';
- }
- 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 .= '<table cellpadding="2" cellspacing="1" border="1" bordercolor="'.$cfg["table_admin_border"].'" bgcolor="'.$cfg["body_data_bg"].'">';
- $retVal .= '<tr>';
- $retVal .= '<td align="center" bgcolor="'.$cfg["table_header_bg"].'"><strong>Version</strong></td>';
- $retVal .= '<td align="center" bgcolor="'.$cfg["table_header_bg"].'"><strong>Date</strong></td>';
- $retVal .= '<td align="center" bgcolor="'.$cfg["table_header_bg"].'"><strong>Comp.</strong></td>';
- $retVal .= '<td align="center" bgcolor="'.$cfg["table_header_bg"].'"><strong>Size</strong></td>';
- $retVal .= '<td align="center" bgcolor="'.$cfg["table_header_bg"].'"> </td>';
- $retVal .= '</tr>';
- // 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 .= '<tr>';
- $retVal .= '<td align="center">'.$backupElements[1].'</td>';
- $retVal .= '<td align="right">'.formatHumanDate(substr($backupElements[2], 0, 14)).'</td>';
- $lastChar = substr($backupElements[2], -1, 1);
- $retVal .= '<td align="center">';
- switch ($lastChar) {
- case "r":
- $retVal .= 'none';
- break;
- case "z":
- $retVal .= 'gzip';
- break;
- case "2":
- $retVal .= 'bzip2';
- break;
- default:
- $retVal .= 'unknown';
- break;
- }
- $retVal .= '</td>';
- $retVal .= '<td align="right">'.(string)(formatHumanSize(filesize($backupFile))).'</td>';
- $retVal .= '<td align="center">';
- $retVal .= '<a href="'. _FILE_THIS .'?b=4&f='.$backup.'">';
- $retVal .= '<img src="themes/'.$cfg["theme"].'/images/download_owner.gif" title="Download" border="0">';
- $retVal .= '</a>';
- $retVal .= ' ';
- $retVal .= '<a href="'. _FILE_THIS .'?b=5&f='.$backup.'">';
- $retVal .= '<img src="themes/'.$theme.'/images/delete.png" title="Delete" border="0">';
- $retVal .= '</a>';
- $retVal .= '</td>';
- $retVal .= '</tr>';
- }
- }
- $retVal .= '</table>';
- } else {
- $retVal .= '<strong>No Backups on Server</strong>';
- }
- 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('<br>');
- // database-command
- if ($commands['db'] != "") {
- if ($talk)
- sendLine('Backup of Database <em>'.tfb_htmlencodekeepspaces($cfg["db_name"]).'</em> ...');
- shell_exec($commands['db']);
- }
- if ($talk)
- sendLine(' <font color="green">Ok</font><br>');
- // docroot-command
- if ($talk)
- sendLine('Backup of Docroot <em>'.tfb_htmlencodekeepspaces($cfg["docroot"]).'</em> ...');
- shell_exec($commands['docroot']);
- if ($talk)
- sendLine(' <font color="green">Ok</font><br>');
- // transfers-command
- if ($exec['transfers'] === true) {
- if ($talk)
- sendLine('Backup of transfers <em>'.tfb_htmlencodekeepspaces($cfg["transfer_file_path"]).'</em> ...');
- shell_exec($commands['transfers']);
- if ($talk)
- sendLine(' <font color="green">Ok</font><br>');
- }
- // fluxd-command
- if ($exec['fluxd'] === true) {
- if ($talk)
- sendLine('Backup of fluxd <em>'.tfb_htmlencodekeepspaces($cfg["path"].'.fluxd').'</em> ...');
- shell_exec($commands['fluxd']);
- if ($talk)
- sendLine(' <font color="green">Ok</font><br>');
- }
- // mrtg-command
- if ($exec['mrtg'] === true) {
- if ($talk)
- sendLine('Backup of mrtg <em>'.tfb_htmlencodekeepspaces($cfg["path"].'.mrtg').'</em> ...');
- shell_exec($commands['mrtg']);
- if ($talk)
- sendLine(' <font color="green">Ok</font><br>');
- }
- // create the archive
- if ($talk)
- sendLine('Creating Archive <em>'.$fileArchiveName.'</em> ...');
- shell_exec($commands['archive']);
- if ($talk)
- sendLine(' <font color="green">Ok</font><br>');
- // 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(' <font color="green">Ok</font><br>');
- // log
- if ($talk)
- sendLine('<font color="green">Backup Complete.</font><br>');
- AuditAction($cfg["constants"]["admin"], "Backup Created: ".$fileArchiveName);
- return $fileArchiveName;
- }
- /**
- * validate Local Files
- */
- function validateLocalFiles() {
- sendLine('<h3>Validate Files</h3>');
- sendLine('<strong>Getting Checksum-list</strong>');
- // 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('<font color="green">done</font><br>');
- sendLine('<br><strong>Processing list</strong>');
- // 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('<font color="green">done</font> ('.$remoteChecksumsCount.')<br>');
- // local Checksums
- sendLine('<br><strong>Getting local checksums</strong>');
- $localChecksums = getFileChecksums(true);
- $localChecksumsCount = count($localChecksums);
- sendLine('<font color="green">done</font> ('.$localChecksumsCount.')<br>');
- // init some arrays
- $filesMissing = array();
- $filesNew = array();
- $filesOk = array();
- $filesChanged = array();
- // validate
- sendLine('<br><strong>Validating...</strong><br>');
- // 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 .= ' <font color="green"> Ok</font>';
- } else {
- array_push($filesChanged, $file);
- $line .= ' <font color="red"> Changed</font>';
- }
- } else {
- array_push($filesMissing, $file);
- $line .= ' <font color="red"> Missing</font>';
- }
- sendLine($line."<br>");
- }
- // validate pass 2
- foreach ($localChecksums as $file => $md5)
- if (!isset($remoteChecksums[$file]))
- array_push($filesNew, $file);
- // summary
- sendLine('<h3>Done.</h3>');
- // files Total
- sendLine('<strong>'._VERSION.': </strong>'.$remoteChecksumsCount.'<br>');
- sendLine('<strong>Local: </strong>'.$localChecksumsCount.'<br>');
- // files Ok
- sendLine('<strong>Unchanged: </strong>'.count($filesOk).'<br>');
- // files Missing
- sendLine('<strong>Missing: </strong>'.count($filesMissing).'<br>');
- // files Changed
- sendLine('<strong>Changed: </strong>'.count($filesChanged).'<br>');
- // files New
- sendLine('<strong>New: </strong>'.count($filesNew).'<br>');
- if (count($filesNew) > 0) {
- sendLine('<br><strong>New Files: </strong><br>');
- foreach ($filesNew as $newFile)
- sendLine(tfb_htmlencodekeepspaces($newFile).'<br>');
- }
- }
- /**
- * phpCheckWeb
- *
- * @return string
- */
- function phpCheckWeb() {
- $retVal = "<br>";
- $errors = 0;
- $warnings = 0;
- $dbsupported = 0;
- $errorsMessages = array();
- $warningsMessages = array();
- // PHP-Version
- $retVal .= '<p><strong>1. PHP-Version</strong></p>';
- $phpVersion = 'PHP-Version: <em>'.PHP_VERSION.'</em> ';
- if (PHP_VERSION < 4.3) {
- $phpVersion .= '<font color="red">Failed</font>';
- $errors++;
- array_push($errorsMessages, "PHP-Version: 4.3 or higher required.");
- } else {
- $phpVersion .= '<font color="green">Passed</font>';
- }
- $retVal .= $phpVersion;
- // PHP-Extensions
- $retVal .= '<p><strong>2. PHP-Extensions</strong></p>';
- $retVal .= "<ul>";
- $loadedExtensions = get_loaded_extensions();
- // session
- $session = '<li>session ';
- if (in_array("session", $loadedExtensions)) {
- $session .= '<font color="green">Passed</font>';
- } else {
- $session .= '<font color="red">Failed</font>';
- $errors++;
- array_push($errorsMessages, "PHP-Extensions: session required.");
- }
- $retVal .= $session.'</li>';
- // pcre
- $pcre = '<li>pcre ';
- if (in_array("pcre", $loadedExtensions)) {
- $pcre .= '<font color="green">Passed</font>';
- } else {
- $pcre .= '<font color="red">Failed</font>';
- $errors++;
- array_push($errorsMessages, "PHP-Extensions: pcre required.");
- }
- $retVal .= $pcre.'</li>';
- // sockets
- $sockets = '<li>sockets ';
- if (in_array("sockets", $loadedExtensions)) {
- $sockets .= '<font color="green">Passed</font>';
- } else {
- $sockets .= '<font color="red">Failed</font>';
- $warnings++;
- array_push($warningsMessages, "PHP-Extensions: sockets required for communication with fluxd. fluxd cannot work without sockets.");
- }
- $retVal .= $sockets.'</li>';
- //
- $retVal .= "</ul>";
- // PHP-Configuration
- $retVal .= '<p><strong>3. PHP-Configuration</strong></p>';
- $retVal .= "<ul>";
- // safe_mode
- $safe_mode = '<li>safe_mode ';
- if ((ini_get("safe_mode")) == 0) {
- $safe_mode .= '<font color="green">Passed</font>';
- } else {
- $safe_mode .= '<font color="red">Failed</font>';
- $errors++;
- array_push($errorsMessages, "PHP-Configuration: safe_mode must be turned off.");
- }
- $retVal .= $safe_mode.'</li>';
- // allow_url_fopen
- $allow_url_fopen = '<li>allow_url_fopen ';
- if ((ini_get("allow_url_fopen")) == 1) {
- $allow_url_fopen .= '<font color="green">Passed</font>';
- } else {
- $allow_url_fopen .= '<font color="red">Failed</font>';
- 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.'</li>';
- // register_globals
- $register_globals = '<li>register_globals ';
- if ((ini_get("register_globals")) == 0) {
- $register_globals .= '<font color="green">Passed</font>';
- } else {
- $register_globals .= '<font color="red">Failed</font>';
- $errors++;
- array_push($errorsMessages, "PHP-Configuration: register_globals must be turned off.");
- }
- $retVal .= $register_globals.'</li>';
- //
- $retVal .= "</ul>";
- // PHP-Database-Support
- $retVal .= '<p><strong>4. PHP-Database-Support</strong></p>';
- $retVal .= "<ul>";
- // 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 = '<li>'.$databaseTypeName.' ';
- if (function_exists($databaseTypeFunction)) {
- $dbtest .= '<font color="green">Passed</font>';
- $dbsupported++;
- } else {
- $dbtest .= '<font color="red">Failed</font>';
- }
- $retVal .= $dbtest.'</li>';
- }
- $retVal .= "</ul>";
- // 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 .= '<p><strong>5. OS-Specific ('.$osString.' '.php_uname('r').')</strong></p>';
- switch (_OS) {
- case 1: // linux
- $retVal .= 'No Special Requirements on Linux-OS. <font color="green">Passed</font>';
- break;
- case 2: // bsd
- $retVal .= "<ul>";
- // posix
- $posix = '<li>posix ';
- if ((function_exists('posix_geteuid')) && (function_exists('posix_getpwuid'))) {
- $posix .= '<font color="green">Passed</font>';
- } else {
- $posix .= '<font color="red">Failed</font>';
- $warnings++;
- array_push($warningsMessages, "OS-Specific: PHP-extension posix missing. some netstat-features wont work without.");
- }
- $retVal .= $posix.'</li>';
- $retVal .= "</ul>";
- break;
- case 0: // unknown
- default:
- $retVal .= "OS not supported.<br>";
- $errors++;
- array_push($errorsMessages, "OS-Specific: ".$osString." not supported.");
- break;
- }
- // summary
- $retVal .= '<p><strong>Summary</strong></p>';
- // state
- $state = "<strong>State: ";
- if (($warnings + $errors) == 0) {
- // good
- $state .= '<font color="green">Ok</font>';
- $state .= "</strong><br>";
- $retVal .= $state;
- $retVal .= "torrentflux-b4rt should run on this system.";
- } else {
- if (($errors == 0) && ($warnings > 0)) {
- // may run with flaws
- $state .= '<font color="orange">Warning</font>';
- $state .= "</strong><br>";
- $retVal .= $state;
- $retVal .= "torrentflux-b4rt may run on this system, but there may be problems.";
- } else {
- // not ok
- $state .= '<font color="red">Failed</font>';
- $state .= "</strong><br>";
- $retVal .= $state;
- $retVal .= "torrentflux-b4rt cannot run on this system.";
- }
- }
- // errors
- if (count($errorsMessages) > 0) {
- $retVal .= '<p><strong><font color="red">Errors: </font></strong><br>';
- $retVal .= "<ul>";
- foreach ($errorsMessages as $errorsMessage) {
- $retVal .= "<li>".$errorsMessage."</li>";
- }
- $retVal .= "</ul>";
- }
- // warnings
- if (count($warningsMessages) > 0) {
- $retVal .= '<p><strong><font color="orange">Warnings: </font></strong><br>';
- $retVal .= "<ul>";
- foreach ($warningsMessages as $warningsMessage) {
- $retVal .= "<li>".$warningsMessage."</li>";
- }
- $retVal .= "</ul>";
- }
- // return
- return $retVal;
- }
- ?>
|