functions.superadmin.php 105 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604
  1. <?php
  2. /* $Id: functions.superadmin.php 3304 2007-12-09 14:33:13Z warion $ */
  3. /*******************************************************************************
  4. LICENSE
  5. This program is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU General Public License (GPL)
  7. as published by the Free Software Foundation; either version 2
  8. of the License, or (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. To read the license please visit http://www.gnu.org/copyleft/gpl.html
  14. *******************************************************************************/
  15. /**
  16. * transfers
  17. *
  18. * @param $action
  19. */
  20. function sa_transfers($action = "") {
  21. global $cfg, $error, $statusImage, $statusMessage, $htmlTitle, $htmlTop, $htmlMain;
  22. if ($action == "")
  23. return;
  24. buildPage("t");
  25. switch ($action) {
  26. case "0": // Transfers-main
  27. $htmlTitle = "Transfer Bulk Operations";
  28. $htmlMain .= '<br><div align="left">';
  29. $htmlMain .= '<p>Select action to perform on all items in the transfer list:</p>';
  30. $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>';
  31. $htmlMain .= '<p>';
  32. $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>';
  33. $htmlMain .= '<p>';
  34. $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>';
  35. $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';
  36. $htmlMain .= '</div><br><br>';
  37. break;
  38. case "1": // Transfers-Stop
  39. $htmlTitle = "Transfers - Stop";
  40. $htmlMain .= '<br><strong>Transfers Stopped:</strong><br>';
  41. $htmlMain .= '<pre>';
  42. $transferList = getTransferArray();
  43. foreach ($transferList as $transfer) {
  44. if (isTransferRunning($transfer)) {
  45. $ch = ClientHandler::getInstance(getTransferClient($transfer));
  46. $ch->stop($transfer);
  47. $htmlMain .= ' - '.$transfer."";
  48. $htmlMain .= "\n";
  49. }
  50. }
  51. $htmlMain .= '</pre>';
  52. $htmlMain .= '<hr><br>';
  53. break;
  54. case "2": // Transfers-Start
  55. $htmlTitle = "Transfers - Start";
  56. $htmlMain .= '<br><strong>Transfers Started:</strong><br>';
  57. $htmlMain .= '<pre>';
  58. $transferList = getTransferArray();
  59. foreach ($transferList as $transfer) {
  60. if (!isTransferRunning($transfer)) {
  61. $ch = ClientHandler::getInstance(getTransferClient($transfer));
  62. $ch->start($transfer, false, false);
  63. $htmlMain .= ' - '.$transfer."";
  64. $htmlMain .= "\n";
  65. }
  66. }
  67. $htmlMain .= '</pre>';
  68. $htmlMain .= '<hr><br>';
  69. break;
  70. case "3": // Transfers-Resume
  71. $htmlTitle = "Transfers - Resume";
  72. $htmlMain .= '<br><strong>Transfers Resumed:</strong><br>';
  73. $htmlMain .= '<pre>';
  74. $transferList = getTransferArray();
  75. $sf = new StatFile("");
  76. foreach ($transferList as $transfer) {
  77. $sf->init($transfer);
  78. if (((trim($sf->running)) == 0) && (!isTransferRunning($transfer))) {
  79. $ch = ClientHandler::getInstance(getTransferClient($transfer));
  80. $ch->start($transfer, false, false);
  81. $htmlMain .= ' - '.$transfer."";
  82. $htmlMain .= "\n";
  83. }
  84. }
  85. $htmlMain .= '</pre>';
  86. $htmlMain .= '<hr><br>';
  87. break;
  88. }
  89. $htmlMain .= '<br><strong>Transfers:</strong><br>';
  90. $htmlMain .= '<pre>';
  91. $transferList = getTransferArray();
  92. foreach ($transferList as $transfer) {
  93. $htmlMain .= ' - '.$transfer."";
  94. if (isTransferRunning($transfer))
  95. $htmlMain .= " (running)";
  96. $htmlMain .= "\n";
  97. }
  98. $htmlMain .= '</pre>';
  99. printPage();
  100. exit();
  101. }
  102. /**
  103. * processes
  104. *
  105. * @param $action
  106. */
  107. function sa_processes($action = "") {
  108. global $cfg, $error, $statusImage, $statusMessage, $htmlTitle, $htmlTop, $htmlMain;
  109. if ($action == "")
  110. return;
  111. buildPage("p");
  112. switch ($action) {
  113. case "0": // Processes-main
  114. $htmlTitle = "Processes";
  115. $htmlMain .= '<p>';
  116. $htmlMain .= 'View currently running torrentflux-b4rt processes:<br><br>';
  117. $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';
  118. $htmlMain .= '<p>';
  119. $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';
  120. $htmlMain .= '<br><br>';
  121. break;
  122. case "1": // Processes - All
  123. $htmlTitle = "Processes - All";
  124. $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">';
  125. $htmlMain .= '<br>';
  126. $htmlMain .= '<p><strong>fluxd</strong>';
  127. $htmlMain .= '<pre>';
  128. $htmlMain .= tfb_htmlencode(shell_exec("ps auxww | ".$cfg['bin_grep']." fluxd | ".$cfg['bin_grep']." -v grep"));
  129. $htmlMain .= '</pre>';
  130. $htmlMain .= '<p><strong>fluazu</strong>';
  131. $htmlMain .= '<pre>';
  132. $htmlMain .= tfb_htmlencode(shell_exec("ps auxww | ".$cfg['bin_grep']." fluazu.py | ".$cfg['bin_grep']." -v grep"));
  133. $htmlMain .= '</pre>';
  134. $clients = array('tornado', 'transmission', 'mainline', 'wget', 'nzbperl', 'azureus');
  135. foreach ($clients as $client) {
  136. $ch = ClientHandler::getInstance($client);
  137. $htmlMain .= '<p><strong>'.$client.'</strong>';
  138. $htmlMain .= '<br>';
  139. $htmlMain .= '<pre>';
  140. $htmlMain .= tfb_htmlencode(shell_exec("ps auxww | ".$cfg['bin_grep']." ".tfb_shellencode($ch->binClient)." | ".$cfg['bin_grep']." -v grep"));
  141. $htmlMain .= '</pre>';
  142. $htmlMain .= '<br>';
  143. $htmlMain .= '<pre>';
  144. $htmlMain .= $ch->runningProcessInfo();
  145. $htmlMain .= '</pre>';
  146. }
  147. $htmlMain .= '</div>';
  148. break;
  149. case "2": // Processes - Transfers
  150. $htmlTitle = "Processes - Transfers";
  151. $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">';
  152. $htmlMain .= '<br>
  153. <table width="700" border=1 bordercolor="'.$cfg["table_admin_border"].'" cellpadding="2" cellspacing="0" bgcolor="'.$cfg["table_data_bg"].'">
  154. <tr><td colspan=6 bgcolor="'.$cfg["table_header_bg"].'" background="themes/'.$cfg["theme"].'/images/bar.gif">
  155. <table width="100%" cellpadding=0 cellspacing=0 border=0><tr><td><font class="title"> Running Items </font></td></tr></table>
  156. </td></tr>
  157. <tr>
  158. <td bgcolor="'.$cfg["table_header_bg"].'" width="15%" nowrap><div align=center class="title">'.$cfg["_USER"].'</div></td>
  159. <td bgcolor="'.$cfg["table_header_bg"].'" nowrap><div align=center class="title">'.$cfg["_FILE"].'</div></td>
  160. <td bgcolor="'.$cfg["table_header_bg"].'" width="1%" nowrap><div align=center class="title">'.$cfg["_FORCESTOP"].'</div></td>
  161. </tr>
  162. ';
  163. $running = getRunningClientProcesses();
  164. foreach ($running as $rng) {
  165. $rt = RunningTransfer::getInstance($rng['pinfo'], $rng['client']);
  166. $htmlMain .= '<tr bgcolor="'.$cfg["table_header_bg"].'">';
  167. $htmlMain .= '<td nowrap><div class="tiny">';
  168. $htmlMain .= tfb_htmlencodekeepspaces($rt->transferowner);
  169. $htmlMain .= '</div></td>';
  170. $htmlMain .= '<td nowrap><div align=center><div class="tiny" align="left">';
  171. $htmlMain .= $rt->transferFile;
  172. $htmlMain .= '</div></td>';
  173. $htmlMain .= '<td nowrap>';
  174. $htmlMain .= '<a href="dispatcher.php?action=forceStop&riid=_referer_';
  175. $htmlMain .= "&transfer=".urlencode($rt->transferFile);
  176. $htmlMain .= "&pid=".$rt->processId;
  177. $htmlMain .= '"><img src="themes/'.$cfg["theme"].'/images/kill.gif" width="16" height="16" title="'.$cfg['_FORCESTOP'].'" border="0"></a></td>';
  178. $htmlMain .= '</tr>';
  179. }
  180. $htmlMain .= '</table>';
  181. $htmlMain .= '</div>';
  182. break;
  183. }
  184. printPage();
  185. exit();
  186. }
  187. /**
  188. * maintenance
  189. *
  190. * @param $action
  191. */
  192. function sa_maintenance($action = "") {
  193. global $cfg, $error, $statusImage, $statusMessage, $htmlTitle, $htmlTop, $htmlMain;
  194. if ($action == "")
  195. return;
  196. buildPage("m");
  197. switch ($action) {
  198. case "0": // Maintenance-main
  199. $htmlTitle = "Maintenance";
  200. $htmlMain .= '<p>Select the maintenance task you wish to perform below:<br><br>';
  201. $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';
  202. $htmlMain .= '<p>';
  203. $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';
  204. $htmlMain .= '<p>';
  205. $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';
  206. $htmlMain .= '<p>';
  207. $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';
  208. $htmlMain .= '<p>';
  209. $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';
  210. $htmlMain .= '<p>';
  211. $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';
  212. $htmlMain .= '<br><br>';
  213. break;
  214. case "1": // Maintenance: Main
  215. $htmlTitle = "Maintenance - Main";
  216. $htmlMain .= '<p>';
  217. $htmlMain .= '<strong>Standard</strong><br>';
  218. $htmlMain .= 'Standard Maintenance Run - same as on index-page and automatic called on every login<br>';
  219. $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>';
  220. $htmlMain .= '<p>';
  221. $htmlMain .= '<strong>Extended</strong><br>';
  222. $htmlMain .= 'Extended Maintenance Run - like a standard run but will also restart all dead transfers.<br>';
  223. $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>';
  224. $htmlMain .= '<br><br>';
  225. break;
  226. case "11": // Maintenance: Main: Standard Maintenance-Run
  227. $htmlTitle = "Maintenance - Main - Standard Maintenance Run";
  228. $htmlMain .= '<br>';
  229. $htmlMain .= 'Standard Maintenance Run: ';
  230. require_once("inc/classes/MaintenanceAndRepair.php");
  231. MaintenanceAndRepair::maintenance(MAINTENANCEANDREPAIR_TYPE_STD);
  232. $htmlMain .= ' <font color="green">done</font>';
  233. $htmlMain .= '<br><br>';
  234. break;
  235. case "12": // Maintenance: Main
  236. $htmlTitle = "Maintenance - Main - Extended Maintenance Run";
  237. $htmlMain .= '<br>';
  238. $htmlMain .= 'Extended Maintenance Run: ';
  239. require_once("inc/classes/MaintenanceAndRepair.php");
  240. MaintenanceAndRepair::maintenance(MAINTENANCEANDREPAIR_TYPE_EXT);
  241. $htmlMain .= ' <font color="green">done</font>';
  242. $htmlMain .= '<br><br>';
  243. break;
  244. case "2": // Maintenance-Kill
  245. $htmlTitle = "Maintenance - Kill";
  246. $htmlMain .= '<br>';
  247. $htmlMain .= '<font color="red"><strong>DON\'T</strong> do this or you will screw up things for sure!</font><br><br>';
  248. $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>';
  249. $htmlMain .= '<p>';
  250. $htmlMain .= '<strong>PHP</strong><br>';
  251. $htmlMain .= 'Kill all PHP processes:<br>';
  252. $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>';
  253. $htmlMain .= '<p>';
  254. $htmlMain .= '<strong>Python</strong><br>';
  255. $htmlMain .= 'Kill all python processes:<br>';
  256. $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>';
  257. $htmlMain .= '<p>';
  258. $htmlMain .= '<strong>Perl</strong><br>';
  259. $htmlMain .= 'Kill all perl processes:<br>';
  260. $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>';
  261. $htmlMain .= '<p>';
  262. $htmlMain .= '<strong>Transmissioncli</strong><br>';
  263. $htmlMain .= 'Kill all transmissioncli processes:<br>';
  264. $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>';
  265. $htmlMain .= '<p>';
  266. $htmlMain .= '<strong>Wget</strong><br>';
  267. $htmlMain .= 'Kill all wget processes:<br>';
  268. $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>';
  269. $htmlMain .= '<p>';
  270. $htmlMain .= '<strong>VLC</strong><br>';
  271. $htmlMain .= 'Kill all VLC processes:<br>';
  272. $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>';
  273. $htmlMain .= '<br><br>';
  274. break;
  275. case "21": // Maintenance-Kill: php
  276. $htmlTitle = "Maintenance - Kill - PHP";
  277. $htmlMain .= '<br>';
  278. $htmlMain .= 'Kill all PHP processes: <font color="green">done</font>';
  279. $htmlMain .= '<br><br>';
  280. $htmlMain .= '<strong>Process list (filtered) before call:</strong><br>';
  281. $htmlMain .= '<pre>';
  282. $htmlMain .= tfb_htmlencode(trim(shell_exec("ps auxww | ".$cfg['bin_grep']." php | ".$cfg['bin_grep']." -v grep")));
  283. $htmlMain .= '</pre>';
  284. $htmlMain .= '<br>';
  285. $callResult = trim(shell_exec("killall -9 php 2> /dev/null"));
  286. if ((isset($callResult)) && ($callResult != "")) {
  287. $htmlMain .= '<br>';
  288. $htmlMain .= 'Call Result: <br>';
  289. $htmlMain .= '<pre>'.tfb_htmlencode($callResult).'</pre>';
  290. $htmlMain .= '<br>';
  291. }
  292. sleep(2); // just 2 sec
  293. $htmlMain .= '<strong>Process list (filtered) after call:</strong><br>';
  294. $htmlMain .= '<pre>';
  295. $htmlMain .= tfb_htmlencode(trim(shell_exec("ps auxww | ".$cfg['bin_grep']." php | ".$cfg['bin_grep']." -v grep")));
  296. $htmlMain .= '</pre>';
  297. $htmlMain .= '<br>';
  298. break;
  299. case "22": // Maintenance-Kill: python
  300. $htmlTitle = "Maintenance - Kill - Python";
  301. $htmlMain .= '<br>';
  302. $htmlMain .= 'Kill all python processes: <font color="green">done</font>';
  303. $htmlMain .= '<br><br>';
  304. $htmlMain .= '<strong>Process list (filtered) before call:</strong><br>';
  305. $htmlMain .= '<pre>';
  306. $htmlMain .= tfb_htmlencode(trim(shell_exec("ps auxww | ".$cfg['bin_grep']." python | ".$cfg['bin_grep']." -v grep")));
  307. $htmlMain .= '</pre>';
  308. $htmlMain .= '<br>';
  309. $callResult = trim(shell_exec("killall -9 python 2> /dev/null"));
  310. if ((isset($callResult)) && ($callResult != "")) {
  311. $htmlMain .= '<br>';
  312. $htmlMain .= 'Call Result: <br>';
  313. $htmlMain .= '<pre>'.tfb_htmlencode($callResult).'</pre>';
  314. $htmlMain .= '<br>';
  315. }
  316. sleep(2); // just 2 sec
  317. $htmlMain .= '<strong>Process list (filtered) after call:</strong><br>';
  318. $htmlMain .= '<pre>';
  319. $htmlMain .= tfb_htmlencode(trim(shell_exec("ps auxww | ".$cfg['bin_grep']." python | ".$cfg['bin_grep']." -v grep")));
  320. $htmlMain .= '</pre>';
  321. $htmlMain .= '<br>';
  322. break;
  323. case "23": // Maintenance-Kill: perl
  324. $htmlTitle = "Maintenance - Kill - Perl";
  325. $htmlMain .= '<br>';
  326. $htmlMain .= 'Kill all perl processes: <font color="green">done</font>';
  327. $htmlMain .= '<br><br>';
  328. $htmlMain .= '<strong>Process list (filtered) before call:</strong><br>';
  329. $htmlMain .= '<pre>';
  330. $htmlMain .= tfb_htmlencode(trim(shell_exec("ps auxww | ".$cfg['bin_grep']." perl | ".$cfg['bin_grep']." -v grep")));
  331. $htmlMain .= '</pre>';
  332. $htmlMain .= '<br>';
  333. $callResult = trim(shell_exec("killall -9 perl 2> /dev/null"));
  334. if ((isset($callResult)) && ($callResult != "")) {
  335. $htmlMain .= '<br>';
  336. $htmlMain .= 'Call Result: <br>';
  337. $htmlMain .= '<pre>'.tfb_htmlencode($callResult).'</pre>';
  338. $htmlMain .= '<br>';
  339. }
  340. sleep(2); // just 2 sec
  341. $htmlMain .= '<strong>Process list (filtered) after call:</strong><br>';
  342. $htmlMain .= '<pre>';
  343. $htmlMain .= tfb_htmlencode(trim(shell_exec("ps auxww | ".$cfg['bin_grep']." perl | ".$cfg['bin_grep']." -v grep")));
  344. $htmlMain .= '</pre>';
  345. $htmlMain .= '<br>';
  346. break;
  347. case "24": // Maintenance-Kill: transmissioncli
  348. $htmlTitle = "Maintenance - Kill - Transmissioncli";
  349. $htmlMain .= '<br>';
  350. $htmlMain .= 'Kill all transmissioncli processes: <font color="green">done</font>';
  351. $htmlMain .= '<br><br>';
  352. $htmlMain .= '<strong>Process list (filtered) before call:</strong><br>';
  353. $htmlMain .= '<pre>';
  354. $htmlMain .= tfb_htmlencode(trim(shell_exec("ps auxww | ".$cfg['bin_grep']." transmissioncli | ".$cfg['bin_grep']." -v grep")));
  355. $htmlMain .= '</pre>';
  356. $htmlMain .= '<br>';
  357. $callResult = trim(shell_exec("killall -9 transmissioncli 2> /dev/null"));
  358. if ((isset($callResult)) && ($callResult != "")) {
  359. $htmlMain .= '<br>';
  360. $htmlMain .= 'Call Result: <br>';
  361. $htmlMain .= '<pre>'.tfb_htmlencode($callResult).'</pre>';
  362. $htmlMain .= '<br>';
  363. }
  364. sleep(2); // just 2 sec
  365. $htmlMain .= '<strong>Process list (filtered) after call:</strong><br>';
  366. $htmlMain .= '<pre>';
  367. $htmlMain .= tfb_htmlencode(trim(shell_exec("ps auxww | ".$cfg['bin_grep']." transmissioncli | ".$cfg['bin_grep']." -v grep")));
  368. $htmlMain .= '</pre>';
  369. $htmlMain .= '<br>';
  370. break;
  371. case "25": // Maintenance-Kill: wget
  372. $htmlTitle = "Maintenance - Kill - Wget";
  373. $htmlMain .= '<br>';
  374. $htmlMain .= 'Kill all wget processes: <font color="green">done</font>';
  375. $htmlMain .= '<br><br>';
  376. $htmlMain .= '<strong>Process list (filtered) before call:</strong><br>';
  377. $htmlMain .= '<pre>';
  378. $htmlMain .= tfb_htmlencode(trim(shell_exec("ps auxww | ".$cfg['bin_grep']." wget | ".$cfg['bin_grep']." -v grep")));
  379. $htmlMain .= '</pre>';
  380. $htmlMain .= '<br>';
  381. $callResult = trim(shell_exec("killall -9 wget 2> /dev/null"));
  382. if ((isset($callResult)) && ($callResult != "")) {
  383. $htmlMain .= '<br>';
  384. $htmlMain .= 'Call Result: <br>';
  385. $htmlMain .= '<pre>'.tfb_htmlencode($callResult).'</pre>';
  386. $htmlMain .= '<br>';
  387. }
  388. sleep(2); // just 2 sec
  389. $htmlMain .= '<strong>Process list (filtered) after call:</strong><br>';
  390. $htmlMain .= '<pre>';
  391. $htmlMain .= tfb_htmlencode(trim(shell_exec("ps auxww | ".$cfg['bin_grep']." wget | ".$cfg['bin_grep']." -v grep")));
  392. $htmlMain .= '</pre>';
  393. $htmlMain .= '<br>';
  394. break;
  395. case "26": // Maintenance-Kill: vlc
  396. $htmlTitle = "Maintenance - Kill - VLC";
  397. $htmlMain .= '<br>';
  398. $htmlMain .= 'Kill all VLC processes: <font color="green">done</font>';
  399. $htmlMain .= '<br><br>';
  400. $htmlMain .= '<strong>Process list (filtered) before call:</strong><br>';
  401. $htmlMain .= '<pre>';
  402. $htmlMain .= tfb_htmlencode(trim(shell_exec("ps auxww | ".$cfg['bin_grep']." vlc | ".$cfg['bin_grep']." -v grep")));
  403. $htmlMain .= '</pre>';
  404. $htmlMain .= '<br>';
  405. $callResult = trim(shell_exec("killall -9 vlc 2> /dev/null"));
  406. if ((isset($callResult)) && ($callResult != "")) {
  407. $htmlMain .= '<br>';
  408. $htmlMain .= 'Call Result: <br>';
  409. $htmlMain .= '<pre>'.tfb_htmlencode($callResult).'</pre>';
  410. $htmlMain .= '<br>';
  411. }
  412. sleep(2); // just 2 sec
  413. $htmlMain .= '<strong>Process list (filtered) after call:</strong><br>';
  414. $htmlMain .= '<pre>';
  415. $htmlMain .= tfb_htmlencode(trim(shell_exec("ps auxww | ".$cfg['bin_grep']." vlc | ".$cfg['bin_grep']." -v grep")));
  416. $htmlMain .= '</pre>';
  417. $htmlMain .= '<br>';
  418. break;
  419. case "3": // Maintenance-Clean
  420. $htmlTitle = "Maintenance - Clean";
  421. $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>';
  422. $htmlMain .= '<strong>Process ID (PID) File Leftovers</strong><br>';
  423. $htmlMain .= 'Delete stale PID files from deleted transfers:<br>';
  424. $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>';
  425. $htmlMain .= '<p>';
  426. $htmlMain .= '<strong>BitTornado</strong><br>';
  427. $htmlMain .= 'Delete the BitTornado cache:<br>';
  428. $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>';
  429. $htmlMain .= '<p>';
  430. $htmlMain .= '<strong>Transmission</strong><br>';
  431. $htmlMain .= 'Delete Transmission cache:<br>';
  432. $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>';
  433. $htmlMain .= '<p>';
  434. $htmlMain .= '<strong>BitTorrent Mainline</strong><br>';
  435. $htmlMain .= 'Delete BitTorrent Mainline cache:<br>';
  436. $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>';
  437. $htmlMain .= '<p>';
  438. $htmlMain .= '<strong>Template Cache</strong><br>';
  439. $htmlMain .= 'Delete the Torrentflux-b4rt template cache:<br>';
  440. $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>';
  441. $htmlMain .= '<br><br>';
  442. break;
  443. case "31": // Maintenance-Clean: pid-file-clean
  444. $htmlTitle = "Maintenance - Clean - PID Files";
  445. $htmlMain .= '<br><strong>Cleaning stale PID files:</strong><br>';
  446. $result = "";
  447. $transferList = getTransferArrayFromDB();
  448. if ($dirHandle = @opendir($cfg["transfer_file_path"])) {
  449. while (false !== ($file = readdir($dirHandle))) {
  450. if ((strlen($file) > 3) && ((substr($file, -4, 4)) == ".pid")) {
  451. $tname = substr($file, 0, -4);
  452. if (!in_array($tname, $transferList)) {
  453. // transfer not in db. delete pid-file.
  454. $result .= tfb_htmlencode($file)."\n";
  455. @unlink($cfg["transfer_file_path"].$file);
  456. }
  457. }
  458. }
  459. closedir($dirHandle);
  460. }
  461. if (strlen($result) > 0)
  462. $htmlMain .= '<br>Deleted stale PID files: <br><pre>'.$result.'</pre><br>';
  463. else
  464. $htmlMain .= '<br>No stale PID files found.<br><br>';
  465. break;
  466. case "32": // Maintenance-Clean: tornado-clean
  467. $htmlTitle = "Maintenance - Clean - BitTornado";
  468. $htmlMain .= '<br><strong>Cleaning BitTornado cache:</strong><br>';
  469. $result = "";
  470. $result .= cleanDir($cfg["path"].'.BitTornado/datacache');
  471. $result .= cleanDir($cfg["path"].'.BitTornado/torrentcache');
  472. $result .= cleanDir($cfg["path"].'.BitTornado/piececache');
  473. $result .= cleanDir($cfg["path"].'.BitTornado/icons');
  474. if (strlen($result) > 0)
  475. $htmlMain .= '<br>Deleted cache: <br><pre>'.$result.'</pre><br>';
  476. else
  477. $htmlMain .= '<br>Nothing found.<br><br>';
  478. break;
  479. case "33": // Maintenance-Clean: transmission-clean
  480. $htmlTitle = "Maintenance - Clean - Transmission";
  481. $htmlMain .= '<br><strong>Cleaning Transmission cache:</strong><br>';
  482. $result = "";
  483. $hashes = array();
  484. $transferList = getTransferArray();
  485. foreach ($transferList as $transfer)
  486. array_push($hashes, getTransferHash($transfer));
  487. if ($dirHandle = @opendir($cfg["path"].".transmission/cache/")) {
  488. while (false !== ($file = readdir($dirHandle))) {
  489. if ($file{0} == "r") {
  490. $thash = substr($file, -40);
  491. if (!in_array($thash, $hashes)) {
  492. // torrent not in db. delete cache-file.
  493. $result .= tfb_htmlencode($file)."\n";
  494. @unlink($cfg["path"].".transmission/cache/resume.".$thash);
  495. }
  496. }
  497. }
  498. closedir($dirHandle);
  499. }
  500. if (strlen($result) > 0)
  501. $htmlMain .= '<br>Deleted cache: <br><pre>'.$result.'</pre><br>';
  502. else
  503. $htmlMain .= '<br>Nothing found.<br><br>';
  504. break;
  505. case "34": // Maintenance-Clean: mainline-clean
  506. $htmlTitle = "Maintenance - Clean - BitTorrent Mainline";
  507. $htmlMain .= '<br><strong>Cleaning BitTorrent Mainline cache:</strong><br>';
  508. $result = "";
  509. $result .= cleanDir($cfg["path"].'.bittorrent/console/resume');
  510. $result .= cleanDir($cfg["path"].'.bittorrent/console/metainfo');
  511. $result .= cleanDir($cfg["path"].'.bittorrent/console/torrents');
  512. $result .= cleanDir($cfg["path"].'.bittorrent/mutex');
  513. if (strlen($result) > 0)
  514. $htmlMain .= '<br>Deleted cache: <br><pre>'.$result.'</pre><br>';
  515. else
  516. $htmlMain .= '<br>Nothing found.<br><br>';
  517. break;
  518. case "35": // Maintenance-Clean:template-cache-clean
  519. $htmlTitle = "Maintenance - Clean - Template Cache";
  520. $htmlMain .= '<br><strong>Cleaning Torrentflux-b4rt Template Cache:</strong><br>';
  521. $result = cleanDir($cfg["path"].'.templateCache');
  522. if (strlen($result) > 0)
  523. $htmlMain .= '<br>Deleted compiled templates: <br><pre>'.$result.'</pre><br>';
  524. else
  525. $htmlMain .= '<br>No compiled templates found.<br><br>';
  526. break;
  527. case "4": // Maintenance: Repair
  528. $htmlTitle = "Maintenance - Repair";
  529. $htmlMain .= '<br>';
  530. $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>';
  531. $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>';
  532. $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>';
  533. $htmlMain .= '<br><br>';
  534. break;
  535. case "41": // Maintenance: Repair
  536. $htmlTitle = "Maintenance - Repair";
  537. $htmlMain .= '<br>';
  538. $htmlMain .= 'Repairing Torrentflux-b4rt:';
  539. require_once("inc/classes/MaintenanceAndRepair.php");
  540. MaintenanceAndRepair::repair();
  541. $htmlMain .= ' <font color="green">done</font>';
  542. $htmlMain .= '<br><br>';
  543. break;
  544. case "5": // Maintenance: Reset
  545. $htmlTitle = "Maintenance - Reset";
  546. $htmlMain .= '<br>Select the item you wish to reset below:<br><br>';
  547. $htmlMain .= '<strong>Transfer Totals</strong><br>';
  548. $htmlMain .= 'Reset the transfer totals (totals uploaded/downloaded in the transfer list):<br>';
  549. $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>';
  550. $htmlMain .= '<p>';
  551. $htmlMain .= '<strong>Xfer Stats</strong><br>';
  552. $htmlMain .= 'Reset the transfer statistics:<br>';
  553. $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>';
  554. $htmlMain .= '<p>';
  555. $htmlMain .= '<strong>Personal Settings</strong><br>';
  556. $htmlMain .= 'Reset the personal settings of all users:<br>';
  557. $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>';
  558. $htmlMain .= '<br><br>';
  559. break;
  560. case "51": // Maintenance: Reset - transfer-totals
  561. $htmlTitle = "Maintenance - Reset - Transfer Totals";
  562. $htmlMain .= '<br>';
  563. $htmlMain .= 'Resetting transfer totals:<br>';
  564. $result = resetAllTransferTotals();
  565. $htmlMain .= ($result === true)
  566. ? ' <font color="green">Done</font>'
  567. : '<br><font color="red">Error:</font><br>'.$result;
  568. $htmlMain .= '<br><br>';
  569. break;
  570. case "52": // Maintenance: Reset - xfer
  571. $htmlTitle = "Maintenance - Reset - Transfer Statistics";
  572. $htmlMain .= '<br>';
  573. $htmlMain .= 'Resetting xfer stats:<br>';
  574. $result = Xfer::resetStats();
  575. $htmlMain .= ($result === true)
  576. ? ' <font color="green">Done</font>'
  577. : '<br><font color="red">Error:</font><br>'.$result;
  578. $htmlMain .= '<br><br>';
  579. break;
  580. case "53": // Maintenance: Reset - personal-settings
  581. $htmlTitle = "Maintenance - Reset - Personal Settings";
  582. $htmlMain .= '<br>';
  583. $htmlMain .= 'Resetting personal settings:<br>';
  584. $result = deleteAllUserSettings();
  585. $htmlMain .= ($result === true)
  586. ? ' <font color="green">Done</font>'
  587. : '<br><font color="red">Error:</font><br>'.$result;
  588. $htmlMain .= '<br><br>';
  589. break;
  590. case "6": // Maintenance: Lock
  591. $htmlTitle = "Maintenance - Lock Torrentflux-b4rt Frontend";
  592. $htmlMain .= '<br>Lock/unlock access to the Torrentflux-b4rt frontend. Only the superadmin can access the locked frontend.<br><br><hr>';
  593. switch ($cfg['webapp_locked']) {
  594. case 0:
  595. $htmlMain .= '<strong><font color="green">Frontend currently unlocked.</font></strong>';
  596. break;
  597. case 1:
  598. $htmlMain .= '<strong><font color="red">Frontend currently locked.</font></strong>';
  599. break;
  600. }
  601. $htmlMain .= '<hr><p>';
  602. $htmlMain .= '<br><a href="' . _FILE_THIS . '?m=61"><img src="themes/'.$cfg["theme"].'/images/arrow.gif" width="9" height="9" title="Repair" border="0"> ';
  603. $htmlMain .= ($cfg['webapp_locked'] == 1)
  604. ? 'Unlock'
  605. : 'Lock';
  606. $htmlMain .= ' Frontend</a>';
  607. $htmlMain .= '<br><br>';
  608. break;
  609. case "61": // Maintenance: lock/unlock
  610. $htmlTitle = "Maintenance - Lock";
  611. $htmlMain .= '<br>';
  612. switch ($cfg['webapp_locked']) {
  613. case 0:
  614. $result = setWebappLock(1);
  615. $htmlMain .= "Locking frontend:<br>";
  616. $htmlMain .= ($result === true)
  617. ? '<font color="green">Done</font>'
  618. : '<br><font color="red">Error:</font><br>'.$result;
  619. break;
  620. case 1:
  621. $result = setWebappLock(0);
  622. $htmlMain .= "Unlocking frontend:<br>";
  623. $htmlMain .= ($result === true)
  624. ? '<font color="green">Done</font>'
  625. : '<br><font color="red">Error:</font><br>'.$result;
  626. break;
  627. }
  628. $htmlMain .= '<br><br>';
  629. break;
  630. }
  631. printPage();
  632. exit();
  633. }
  634. /**
  635. * backup
  636. *
  637. * @param $action
  638. */
  639. function sa_backup($action = "") {
  640. global $cfg, $error, $statusImage, $statusMessage, $htmlTitle, $htmlTop, $htmlMain;
  641. if ($action == "")
  642. return;
  643. switch ($action) {
  644. case "0": // choose backup-type
  645. buildPage("b");
  646. $htmlTitle = "Backup - Create";
  647. $htmlMain .= '<br>Select the format and location to save the backup to:<br><br>';
  648. $htmlMain .= '<form name="backupServer" action="' . _FILE_THIS . '" method="post">';
  649. $htmlMain .= '<select name="c">';
  650. $htmlMain .= '<option value="0">none</option>';
  651. $htmlMain .= '<option value="1" selected>gzip</option>';
  652. $htmlMain .= '<option value="2">bzip2</option>';
  653. $htmlMain .= '</select>&nbsp;&nbsp;';
  654. $htmlMain .= '<input type="Hidden" name="b" value="1">';
  655. $htmlMain .= '<input type="submit" value="Backup on Server">';
  656. $htmlMain .= '</form><p>';
  657. $htmlMain .= '<form name="backupClient" action="' . _FILE_THIS . '" method="post">';
  658. $htmlMain .= '<select name="c">';
  659. $htmlMain .= '<option value="0">none</option>';
  660. $htmlMain .= '<option value="1" selected>gzip</option>';
  661. $htmlMain .= '<option value="2">bzip2</option>';
  662. $htmlMain .= '</select>&nbsp;&nbsp;';
  663. $htmlMain .= '<input type="Hidden" name="b" value="2">';
  664. $htmlMain .= '<input type="submit" value="Backup to Client">';
  665. $htmlMain .= '</form><p>';
  666. $htmlMain .= '<br><strong>Notes:</strong><br>"Backup on Server" will save the backup archive to the following path:<br>';
  667. $htmlMain .= '<em>'.tfb_htmlencodekeepspaces($cfg["path"] . _DIR_BACKUP).'/</em>';
  668. $htmlMain .= '<br><br>';
  669. $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>';
  670. $htmlMain .= "<hr><strong>What Data is Backed Up?</strong><br>";
  671. $htmlMain .= "<ul>";
  672. $htmlMain .= "<li>Document root directory structure -<br>all files underneath the webserver document root folder where you installed Torrentflux-b4rt.<br><br></li>";
  673. $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>";
  674. $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>";
  675. $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>";
  676. $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>";
  677. $htmlMain .= "</ul><hr>";
  678. printPage();
  679. exit();
  680. case "1": // server-backup
  681. buildPage("b");
  682. $htmlTitle = "Backup - Create - Server";
  683. printPageStart(1);
  684. echo $htmlMain;
  685. $backupArchive = backupCreate(true, tfb_getRequestVar('c'));
  686. if ($backupArchive == "") {
  687. sendLine('<br>');
  688. sendLine('<font color="red"><strong>Backup - Error</strong></font><br><br>');
  689. sendLine($error);
  690. } else {
  691. sendLine('<br>');
  692. sendLine('<strong>Backup Created</strong>');
  693. sendLine('<br><br>Archive of backup is <em>'.tfb_htmlencodekeepspaces($backupArchive).'</em>');
  694. sendLine('<br><br>');
  695. sendLine(backupListDisplay());
  696. }
  697. printPageEnd(1);
  698. exit();
  699. case "2": // client-backup
  700. $backupArchive = backupCreate(false, tfb_getRequestVar('c'));
  701. if ($backupArchive == "") {
  702. buildPage("-b");
  703. $htmlTitle = "Backup - Create - Client";
  704. $htmlMain .= '<br><br>';
  705. $htmlMain .= '<font color="red"><strong>Backup - Error</strong></font><br><br>';
  706. $htmlMain .= $error;
  707. printPage();
  708. } else {
  709. backupSend($backupArchive,true);
  710. }
  711. exit();
  712. case "3": // backup-list
  713. $htmlTitle = "Backup - Backups on Server";
  714. buildPage("b");
  715. $htmlMain .= '<br>';
  716. $htmlMain .= backupListDisplay();
  717. printPage();
  718. exit();
  719. case "4": // download backup
  720. $backupArchive = tfb_getRequestVar('f');
  721. if (backupParamCheck($backupArchive)) {
  722. backupSend($backupArchive,false);
  723. } else {
  724. buildPage("-b");
  725. $htmlTitle = "Backup - Download";
  726. $htmlMain .= '<br><br>';
  727. $htmlMain .= '<font color="red"><strong>Backup - Error</strong></font><br><br>';
  728. $htmlMain .= tfb_htmlencodekeepspaces($backupArchive).' is not a valid Backup-ID';
  729. printPage();
  730. }
  731. exit();
  732. case "5": // delete backup
  733. $backupArchive = tfb_getRequestVar('f');
  734. if (backupParamCheck($backupArchive)) {
  735. backupDelete($backupArchive);
  736. buildPage("b");
  737. $htmlTitle = "Backup - Delete";
  738. $htmlMain .= '<br>';
  739. $htmlMain .= '<em>'.tfb_htmlencodekeepspaces($backupArchive).'</em> deleted.';
  740. $htmlMain .= '<br><br>';
  741. $htmlMain .= backupListDisplay();
  742. } else {
  743. buildPage("-b");
  744. $htmlTitle = "Backup - Delete";
  745. $htmlMain .= '<br><br>';
  746. $htmlMain .= '<font color="red"><strong>Backup - Error</strong></font><br><br>';
  747. $htmlMain .= tfb_htmlencodekeepspaces($backupArchive).' is not a valid Backup-ID';
  748. }
  749. printPage();
  750. exit();
  751. }
  752. exit();
  753. }
  754. /**
  755. * log
  756. *
  757. * @param $action
  758. */
  759. function sa_log($action = "") {
  760. global $cfg, $error, $statusImage, $statusMessage, $htmlTitle, $htmlTop, $htmlMain;
  761. if ($action == "")
  762. return;
  763. buildPage("l");
  764. switch ($action) {
  765. case "0": // log-main
  766. $htmlTitle = "Log Viewer";
  767. $htmlMain .= '<br>Select the type of log you want to view below:<p>';
  768. $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';
  769. $htmlMain .= '<p>';
  770. $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';
  771. $htmlMain .= '<p>';
  772. $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';
  773. $htmlMain .= '<p>';
  774. $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';
  775. $htmlMain .= '<p>';
  776. $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';
  777. $htmlMain .= '<br><br>';
  778. break;
  779. case "1": // fluxd-log
  780. $htmlTitle = "log - fluxd";
  781. $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">';
  782. $htmlMain .= '<pre>';
  783. $htmlMain .= tfb_htmlencode(@file_get_contents($cfg["path"].'.fluxd/fluxd.log'));
  784. $htmlMain .= '</pre>';
  785. $htmlMain .= '</div>';
  786. break;
  787. case "2": // fluxd-error-log
  788. $htmlTitle = "log - fluxd - error-log";
  789. $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">';
  790. $htmlMain .= '<pre>';
  791. $htmlMain .= tfb_htmlencode(@file_get_contents($cfg["path"].'.fluxd/fluxd-error.log'));
  792. $htmlMain .= '</pre>';
  793. $htmlMain .= '</div>';
  794. break;
  795. case "3": // fluazu-log
  796. $htmlTitle = "log - fluazu";
  797. $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">';
  798. $htmlMain .= '<pre>';
  799. $htmlMain .= tfb_htmlencode(@file_get_contents($cfg["path"].'.fluazu/fluazu.log'));
  800. $htmlMain .= '</pre>';
  801. $htmlMain .= '</div>';
  802. break;
  803. case "5": // mainline-log
  804. $htmlTitle = "log - mainline";
  805. $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">';
  806. $htmlMain .= '<pre>';
  807. $mainlineLog = $cfg["path"].'.bittorrent/tfmainline.log';
  808. if (is_file($mainlineLog))
  809. $htmlMain .= tfb_htmlencode(@file_get_contents($mainlineLog));
  810. else
  811. $htmlMain .= "mainline-log not found.";
  812. $htmlMain .= '</pre>';
  813. $htmlMain .= '</div>';
  814. break;
  815. case "8": // transfers
  816. $htmlTitle = "log - transfers";
  817. $htmlMain .= "<br>Select the transfer you wish to view the logfile for from below:<br>";
  818. $logList = getTransferArray('na');
  819. if ((isset($logList)) && (is_array($logList))) {
  820. $htmlMain .= '<ul>';
  821. foreach ($logList as $logFile) {
  822. if ((isset($logFile)) && ($logFile != "")) {
  823. $htmlMain .= '<li>';
  824. $htmlMain .= '<a href="'. _FILE_THIS .'?l=9&transfer='.urlencode($logFile).'">';
  825. $htmlMain .= tfb_htmlencode($logFile);
  826. $htmlMain .= '</a>';
  827. $htmlMain .= '</li>';
  828. }
  829. }
  830. $htmlMain .= '</ul>';
  831. }
  832. break;
  833. case "9": // transfer-log
  834. if (isset($_REQUEST["transfer"])) {
  835. $transfer = trim(tfb_getRequestVarRaw('transfer'));
  836. // shorten name if too long
  837. if(strlen($transfer) >= 70)
  838. $htmlTitle = "log - transfer-log - ".tfb_htmlencodekeepspaces(substr($transfer, 0, 67))."...";
  839. else
  840. $htmlTitle = "log - transfer-log - ".tfb_htmlencodekeepspaces($transfer);
  841. $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">';
  842. $htmlMain .= '<pre>';
  843. $htmlMain .= tfb_htmlencode(getTransferLog($transfer));
  844. $htmlMain .= '</pre>';
  845. $htmlMain .= '</div>';
  846. } else {
  847. $htmlTitle = "log - transfer-log";
  848. $htmlMain .= '<font color="red">Error. missing params</font>';
  849. }
  850. break;
  851. }
  852. printPage();
  853. exit();
  854. }
  855. /**
  856. * misc
  857. *
  858. * @param $action
  859. */
  860. function sa_misc($action = "") {
  861. global $cfg, $error, $statusImage, $statusMessage, $htmlTitle, $htmlTop, $htmlMain;
  862. if ($action == "")
  863. return;
  864. buildPage("y");
  865. switch ($action) {
  866. case "0": // misc-main
  867. $htmlTitle = "Miscellaneous Admin Tasks";
  868. $htmlMain .= '<br>Select the task you wish to perform from below:<p>';
  869. $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';
  870. $htmlMain .= '<p>';
  871. $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';
  872. $htmlMain .= '<p>';
  873. $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';
  874. $htmlMain .= '<br><br>';
  875. break;
  876. case "1": // misc - Lists
  877. $htmlTitle = "Misc - File Lists";
  878. $htmlMain .= '<br>Select an option from below:<p>';
  879. $htmlMain .= '<img src="themes/'.$cfg["theme"].'/images/arrow.gif" width="9" height="9" title="Files" border="0"> Files (';
  880. $htmlMain .= '<a href="' . _FILE_THIS . '?y=11" target="_blank">html</a>';
  881. $htmlMain .= ' / ';
  882. $htmlMain .= '<a href="' . _FILE_THIS . '?y=12" target="_blank">text</a>';
  883. $htmlMain .= ') - list files currently installed';
  884. $htmlMain .= '<p>';
  885. $htmlMain .= '<img src="themes/'.$cfg["theme"].'/images/arrow.gif" width="9" height="9" title="Checksums" border="0"> Checksums (';
  886. $htmlMain .= '<a href="' . _FILE_THIS . '?y=13" target="_blank">html</a>';
  887. $htmlMain .= ' / ';
  888. $htmlMain .= '<a href="' . _FILE_THIS . '?y=14" target="_blank">text</a>';
  889. $htmlMain .= ') - list checksums of files currently installed';
  890. $htmlMain .= '<br><br>';
  891. break;
  892. case "11": // Misc - File-List - html
  893. printFileList($cfg['docroot'], 1, 2);
  894. exit();
  895. case "12": // Misc - File-List - text
  896. @header("Content-Type: text/plain");
  897. printFileList($cfg['docroot'], 1, 1);
  898. exit();
  899. case "13": // Misc - Checksums-List - html
  900. printFileList($cfg['docroot'], 2, 2);
  901. exit();
  902. case "14": // Misc - Checksums-List - text
  903. @header("Content-Type: text/plain");
  904. printFileList($cfg['docroot'], 2, 1);
  905. exit();
  906. case "3": // Misc - Checksums
  907. $htmlTitle = "Misc - Checksum Validation";
  908. $htmlMain .= '<p>';
  909. $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>';
  910. $htmlMain .= '<p>';
  911. $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>';
  912. $htmlMain .= '<br><br>';
  913. break;
  914. case "35": // Misc - Checksums - Latest
  915. @header("Content-Type: text/plain");
  916. echo getDataFromUrl(_SUPERADMIN_URLBASE._FILE_CHECKSUMS_PRE._VERSION._FILE_CHECKSUMS_SUF);
  917. exit();
  918. case "36": // Misc - Checksums - Validate
  919. validateLocalFiles();
  920. exit();
  921. case "5": // misc - Check
  922. $htmlTitle = "Misc - Check Requirements";
  923. $htmlMain .= '<br>Select the requirements you wish to check from below:<p>';
  924. $htmlMain .= "<strong>PHP Web</strong><br>Check your PHP web installation meets the requirements for web based activities in torrentflux-b4rt:<br>";
  925. $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>';
  926. $htmlMain .= "<strong>PHP CLI</strong><br>Check your PHP commandline binary installation meets the requirements for commandline based activities in torrentflux-b4rt:<br>";
  927. $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>';
  928. $htmlMain .= "<strong>Perl</strong><br>Check your Perl installation meets the requirements for perl based activities in torrentflux-b4rt:<br>";
  929. $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>';
  930. $htmlMain .= '<br><br>';
  931. break;
  932. case "51": // misc - Check - php-web
  933. $htmlTitle = "Misc - Check Requirements - PHP Web Installation";
  934. $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">';
  935. $htmlMain .= phpCheckWeb();
  936. $htmlMain .= '</div>';
  937. break;
  938. case "52": // misc - Check - php-cli
  939. $htmlTitle = "Misc - Check Requirements - PHP CLI Binary Installation";
  940. $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">';
  941. $htmlMain .= '<pre>';
  942. $htmlMain .= tfb_htmlencode(safePhpCli($cfg["bin_php"], tfb_shellencode($cfg["docroot"]."bin/check/check-cli.php")));
  943. $htmlMain .= '</pre>';
  944. $htmlMain .= '</div>';
  945. break;
  946. case "53": // misc - Check - Perl
  947. $htmlTitle = "Misc - Check Requirements - Perl";
  948. $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">';
  949. $htmlMain .= '<pre>';
  950. $htmlMain .= tfb_htmlencode(shell_exec($cfg["perlCmd"]." ".tfb_shellencode($cfg["docroot"]."bin/check/check.pl")." all"));
  951. $htmlMain .= '</pre>';
  952. $htmlMain .= '</div>';
  953. break;
  954. case "531": // misc - Check - Perl - nzbperl
  955. $htmlTitle = "Misc - Check Requirements - Nzbperl";
  956. $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">';
  957. $htmlMain .= '<pre>';
  958. $htmlMain .= tfb_htmlencode(shell_exec($cfg["perlCmd"]." ".tfb_shellencode($cfg["docroot"]."bin/check/check.pl")." nzbperl"));
  959. $htmlMain .= '</pre>';
  960. $htmlMain .= '</div>';
  961. break;
  962. }
  963. printPage();
  964. exit();
  965. }
  966. /**
  967. * tfb
  968. *
  969. * @param $action
  970. */
  971. function sa_tfb($action = "") {
  972. global $cfg, $error, $statusImage, $statusMessage, $htmlTitle, $htmlTop, $htmlMain;
  973. if ($action == "")
  974. return;
  975. buildPage("z");
  976. switch ($action) {
  977. case "0": // main
  978. $htmlTitle = "About";
  979. $htmlMain .= '<br>Select the information you wish to view from below:<p>';
  980. $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';
  981. $htmlMain .= '<p>';
  982. $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';
  983. $htmlMain .= '<p>';
  984. $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';
  985. $htmlMain .= '<br><br>';
  986. break;
  987. case "1": // Version
  988. $htmlTitle = "About - Version";
  989. // version-check
  990. $versionAvailable = trim(getDataFromUrl(_SUPERADMIN_URLBASE._SUPERADMIN_PROXY));
  991. if ((isset($versionAvailable)) && ($versionAvailable != "")) {
  992. // set image
  993. if ($versionAvailable == _VERSION || (substr(_VERSION, 0, 3)) == "svn")
  994. $statusImage = "green.gif";
  995. else
  996. $statusImage = "red.gif";
  997. // version-text
  998. $htmlMain .= '<br>';
  999. if (strpos(_VERSION, "svn") !== false) {
  1000. $htmlMain .= '<strong>This Version: </strong>'._VERSION;
  1001. $htmlMain .= '<br><br>';
  1002. $htmlMain .= '<strong>Latest Release: </strong>';
  1003. $htmlMain .= $versionAvailable;
  1004. $htmlMain .= '<br><br>';
  1005. $htmlMain .= '<font color="blue">This Version is a svn-Version.</font>';
  1006. } else {
  1007. if ($versionAvailable != _VERSION) {
  1008. $htmlMain .= '<strong>This Version: </strong>';
  1009. $htmlMain .= '<font color="red">'._VERSION.'</font>';
  1010. $htmlMain .= '<br><br>';
  1011. $htmlMain .= '<strong>Available Version: </strong>';
  1012. $htmlMain .= $versionAvailable;
  1013. $htmlMain .= '<br><br>';
  1014. $htmlMain .= '<strong><font color="red">There is a new Version available !</font></strong>';
  1015. $htmlMain .= '<br><br>';
  1016. $htmlMain .= '<form name="update" action="' . _FILE_THIS . '" method="post">';
  1017. $htmlMain .= '<input type="Hidden" name="u" value="0">';
  1018. $htmlMain .= '<input type="submit" value="Update to Version '.$versionAvailable.'">';
  1019. $htmlMain .= '</form>';
  1020. $htmlMain .= '<strong>Current Release: </strong>';
  1021. $htmlMain .= '<br>';
  1022. $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>';
  1023. $htmlMain .= '<br><br>';
  1024. $htmlMain .= '<strong>Homepage: </strong>';
  1025. $htmlMain .= '<br>';
  1026. $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>';
  1027. $htmlMain .= '<br>';
  1028. } else {
  1029. $htmlMain .= '<strong>This Version: </strong>'._VERSION;
  1030. $htmlMain .= '<br><br>';
  1031. $htmlMain .= '<strong>Available Version: </strong>';
  1032. $htmlMain .= $versionAvailable;
  1033. $htmlMain .= '<br><br>';
  1034. $htmlMain .= '<font color="green">This Version looks good.</font>';
  1035. }
  1036. }
  1037. $htmlMain .= '<br><br>';
  1038. } else { // could not get the version
  1039. $statusImage = "black.gif";
  1040. $htmlTop = '<strong><font color="red">Error.</font></strong>';
  1041. $htmlMain = '<br>';
  1042. $htmlMain .= '<font color="red">Error getting available version.</font>';
  1043. $htmlMain .= '<br><br>';
  1044. $htmlMain .= '<strong>Current Release: </strong>';
  1045. $htmlMain .= '<br>';
  1046. $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>';
  1047. $htmlMain .= '<br><br>';
  1048. $htmlMain .= '<strong>Homepage: </strong>';
  1049. $htmlMain .= '<br>';
  1050. $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>';
  1051. $htmlMain .= '<br>';
  1052. }
  1053. break;
  1054. case "2": // News
  1055. $htmlTitle = "About - News";
  1056. $htmlMain .= '<br>';
  1057. $htmlMain .= @gzinflate(getDataFromUrl(_SUPERADMIN_URLBASE . _SUPERADMIN_PROXY ."?a=0"));
  1058. $htmlMain .= '<br><br>';
  1059. break;
  1060. case "3": // Changelog;
  1061. $htmlTitle = "About - Changelog";
  1062. $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">';
  1063. $htmlMain .= '<pre>';
  1064. $htmlMain .= tfb_htmlencode(@gzinflate(getDataFromUrl(_SUPERADMIN_URLBASE . _SUPERADMIN_PROXY ."?a=1")));
  1065. $htmlMain .= '</pre>';
  1066. $htmlMain .= '</div>';
  1067. break;
  1068. }
  1069. printPage();
  1070. exit();
  1071. }
  1072. /**
  1073. * update
  1074. *
  1075. * @param $action
  1076. */
  1077. function sa_update($action = "") {
  1078. global $cfg, $error, $statusImage, $statusMessage, $htmlTitle, $htmlTop, $htmlMain;
  1079. if ($action == "")
  1080. return;
  1081. switch ($action) {
  1082. case "0":
  1083. // get updateIndex to check if update from this version possible
  1084. $updateIndexData = trim(getDataFromUrl(_SUPERADMIN_URLBASE . _SUPERADMIN_PROXY ."?u=0&v=" . _VERSION));
  1085. if ((isset($updateIndexData)) && ($updateIndexData != "")) {
  1086. $updateIndexVars = explode("\n",$updateIndexData);
  1087. $updatePossible = trim($updateIndexVars[0]);
  1088. if ($updatePossible != "1") {
  1089. buildPage("-u");
  1090. printPage();
  1091. exit();
  1092. } else {
  1093. $htmlTop = "<strong>Update - Check</strong>";
  1094. $htmlMain = "<br>Update from your Version possible.";
  1095. $htmlMain .= '<br><br>';
  1096. $htmlMain .= '<form name="update" action="' . _FILE_THIS . '" method="post">';
  1097. $htmlMain .= '<input type="Hidden" name="u" value="1">';
  1098. $htmlMain .= '<input type="submit" value="Next Step - Database-Update">';
  1099. $htmlMain .= '</form>';
  1100. $htmlMain .= '<br>';
  1101. $statusImage = "yellow.gif";
  1102. $htmlTitle = "Update";
  1103. printPage();
  1104. exit();
  1105. }
  1106. } else {
  1107. buildPage("-u");
  1108. printPage();
  1109. exit();
  1110. }
  1111. break;
  1112. case "1":
  1113. // get db-settings
  1114. $updateDBData = trim(getDataFromUrl(_SUPERADMIN_URLBASE . _SUPERADMIN_PROXY ."?u=1&v=" . _VERSION));
  1115. if ((isset($updateDBData)) && ($updateDBData != "")) {
  1116. $updateDBVars = explode("\n",$updateDBData);
  1117. $updateNeeded = trim($updateDBVars[0]);
  1118. if ($updateNeeded == "0") {
  1119. $htmlTop = "<strong>Update - Database</strong>";
  1120. $htmlMain = "<br>Database-Update in this Update not needed.";
  1121. $htmlMain .= '<br><br>';
  1122. $htmlMain .= '<form name="update" action="' . _FILE_THIS . '" method="post">';
  1123. $htmlMain .= '<input type="Hidden" name="u" value="3">';
  1124. $htmlMain .= '<input type="submit" value="Next Step - File-Update">';
  1125. $htmlMain .= '</form>';
  1126. $htmlMain .= '<br>';
  1127. $statusImage = "yellow.gif";
  1128. $htmlTitle = "Update";
  1129. printPage();
  1130. exit();
  1131. } else if ($updateNeeded == "1") {
  1132. $htmlTop = "<strong>Update - Database</strong>";
  1133. $htmlMain = "<br>Database-Update in this Update is needed.";
  1134. $htmlMain .= '<br><br>';
  1135. $htmlMain .= 'Type: <em>'.$cfg["db_type"].'</em>';
  1136. $htmlMain .= '<br><br>';
  1137. $htmlMain .= '<form name="update" action="' . _FILE_THIS . '" method="post">';
  1138. $htmlMain .= '<input type="Hidden" name="u" value="2">';
  1139. $htmlMain .= '<input type="submit" value="Next Step - Perform Database-Update">';
  1140. $htmlMain .= '</form>';
  1141. $htmlMain .= '<br>';
  1142. $statusImage = "yellow.gif";
  1143. $htmlTitle = "Update";
  1144. printPage();
  1145. exit();
  1146. } else {
  1147. updateError($updateDBData);
  1148. exit();
  1149. }
  1150. } else {
  1151. updateError();
  1152. }
  1153. break;
  1154. case "2":
  1155. // get sql-data
  1156. $updateSQLData = @trim(gzinflate(getDataFromUrl(_SUPERADMIN_URLBASE . _SUPERADMIN_PROXY ."?u=2&v=" . _VERSION . "&d=".$cfg["db_type"])));
  1157. if ((isset($updateSQLData)) && ($updateSQLData != "")) {
  1158. sendLine('<strong>Update - Database</strong><br><br><em>Updating Database... Please Wait...</em><ul>');
  1159. $updateSQLStates = explode("\n",$updateSQLData);
  1160. // get ado-connection
  1161. $dbCon = getAdoConnection();
  1162. if (!$dbCon) {
  1163. 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>';
  1164. echo $dbCon->ErrorMsg();
  1165. exit();
  1166. } else {
  1167. foreach ($updateSQLStates as $sqlState) {
  1168. $sqlState = trim($sqlState);
  1169. if ((isset($sqlState)) && ($sqlState != "") && ((substr($sqlState, 0, 2)) != "--")) {
  1170. sendLine('<li>'.$sqlState);
  1171. $dbCon->Execute($sqlState);
  1172. if($dbCon->ErrorNo() == 0) {
  1173. sendLine(' <font color="green">Ok</font></li>');
  1174. } else { // damn there was an error
  1175. // close ado-connection
  1176. $dbCon->Close();
  1177. // talk and out
  1178. 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>';
  1179. exit();
  1180. }
  1181. }
  1182. }
  1183. // close ado-connection
  1184. $dbCon->Close();
  1185. // talk and continue
  1186. sendLine('</ul><p><font color="green">Database-Update done.</font><br><br>');
  1187. 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>');
  1188. exit();
  1189. }
  1190. } else {
  1191. updateError("\n"."cant get update-sql."."\n".$updateSQLData);
  1192. }
  1193. break;
  1194. case "3":
  1195. // get file-list
  1196. $updateFileList = @trim(gzinflate(getDataFromUrl(_SUPERADMIN_URLBASE . _SUPERADMIN_PROXY ."?u=3&v=" . _VERSION)));
  1197. if ((isset($updateFileList)) && ($updateFileList != "")) {
  1198. sendLine('<strong>Update - Files</strong>');
  1199. sendLine('<br><br>');
  1200. sendLine('Files that require an update in this Version:');
  1201. sendLine('<pre>');
  1202. sendLine($updateFileList);
  1203. sendLine('</pre>');
  1204. sendLine('<form name="update" action="' . _FILE_THIS . '" method="post">');
  1205. sendLine('<input type="Hidden" name="u" value="4">');
  1206. sendLine('<input type="submit" value="Next Step - Perform File-Update">');
  1207. sendLine('</form>');
  1208. sendLine('<strong>Ensure script can write to docroot <em>'.$cfg['docroot'].'</em> now !</strong>');
  1209. exit();
  1210. } else {
  1211. updateError("\n"."cant get file-list."."\n".$updateFileList);
  1212. }
  1213. break;
  1214. case "4":
  1215. sendLine('<strong>Update - Files</strong><br><br><em>Updating Files... Please Wait...</em><br><ul>');
  1216. sendLine('<li>Getting Update-Archive:<br>');
  1217. @ini_set("allow_url_fopen", "1");
  1218. @ini_set("user_agent", "torrentflux-b4rt/". _VERSION);
  1219. // get md5
  1220. $md5hash = getDataFromUrl(_SUPERADMIN_URLBASE . _SUPERADMIN_PROXY ."?u=4&v=" . _VERSION);
  1221. if ((!isset($md5hash)) || (strlen($md5hash) != 32)) {
  1222. 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>');
  1223. exit();
  1224. }
  1225. // download archive
  1226. $fileHandle = @fopen($cfg['docroot']._UPDATE_ARCHIVE, "w");
  1227. $urlHandle = @fopen(_SUPERADMIN_URLBASE . _SUPERADMIN_PROXY ."?u=5&v=" . _VERSION, 'r');
  1228. if (($fileHandle) && ($urlHandle)) {
  1229. $results = array();
  1230. $i = 0;
  1231. stream_set_timeout($urlHandle, 15);
  1232. $info = stream_get_meta_data($urlHandle);
  1233. while ((!feof($urlHandle)) && (!$info['timed_out'])) {
  1234. $data = @fgets($urlHandle, 8192);
  1235. $results[$i] = @fwrite($fileHandle, $data);
  1236. $info = stream_get_meta_data($urlHandle);
  1237. sendLine('.');
  1238. $i++;
  1239. }
  1240. @fclose($fileHandle);
  1241. @fclose($urlHandle);
  1242. $done = true;
  1243. foreach ($results as $result) {
  1244. if ($result === false)
  1245. $done = false;
  1246. }
  1247. if ($done) {
  1248. sendLine('<font color="green">done</font></li>');
  1249. } else {
  1250. 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>');
  1251. exit();
  1252. }
  1253. } else {
  1254. 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>');
  1255. exit();
  1256. }
  1257. // validate archive
  1258. sendLine('<li>Validating Update-Archive: ');
  1259. if ((file_exists($cfg['docroot']._UPDATE_ARCHIVE))
  1260. && ($md5hash == @md5_file($cfg['docroot']._UPDATE_ARCHIVE))) {
  1261. sendLine('<font color="green">Ok</font> (<em>'.$md5hash.'</em>)<br></li>');
  1262. } else {
  1263. sendLine('<font color="red">failed</font></ul><br><br>Please restore backup and try again (or do manual update).</strong><br><br>');
  1264. exit();
  1265. }
  1266. // extract archive
  1267. sendLine('<li>Extracting Update-Archive: <br>');
  1268. sendLine('<em>');
  1269. $cmd = 'cd '.tfb_shellencode($cfg['docroot']).' && tar jxvf '._UPDATE_ARCHIVE;
  1270. $cmd .= ' 2>&1';
  1271. $handle = @popen($cmd, 'r');
  1272. while (!@feof($handle)) {
  1273. $read = @fread($handle, 64);
  1274. sendLine(nl2br($read));
  1275. }
  1276. @pclose($handle);
  1277. sendLine('</em>');
  1278. sendLine('<font color="green">done</font></li>');
  1279. // delete archive
  1280. sendLine('<li>Deleting Update-Archive: ');
  1281. if (@unlink($cfg['docroot']._UPDATE_ARCHIVE))
  1282. sendLine('<font color="green">done</font></li>');
  1283. else
  1284. sendLine('<font color="red">failed</font><br>remove archive '.$cfg['docroot']._UPDATE_ARCHIVE.' manual now.</li>');
  1285. // version-file
  1286. sendLine('<li>Updating Version-Information: ');
  1287. $versionAvailable = trim(getDataFromUrl(_SUPERADMIN_URLBASE._SUPERADMIN_PROXY));
  1288. if ((isset($versionAvailable)) && ($versionAvailable != "")) {
  1289. if ($handle = @fopen("version.php", "w")) {
  1290. if (@fwrite($handle, '<?php define("_VERSION", "'.$versionAvailable.'"); ?>')) {
  1291. @fclose($handle);
  1292. sendLine(' <font color="green">done</font></li>');
  1293. } else {
  1294. @fclose($handle);
  1295. 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>');
  1296. exit();
  1297. }
  1298. } else {
  1299. sendLine('<br><br>');
  1300. 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>');
  1301. exit();
  1302. }
  1303. } else {
  1304. 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>');
  1305. exit();
  1306. }
  1307. sendLine('</ul>');
  1308. // done
  1309. sendLine('<p><em>Done Updating Files.</em></p>');
  1310. sendLine('<hr><br><strong>Update to '.$versionAvailable.' completed.</strong><br><br>');
  1311. sendLine('<form name="update" action="#" method="get"><input type="submit" onClick="window.close()" value="Close"></form>');
  1312. sendLine('<br>');
  1313. // flush cache
  1314. cacheFlush();
  1315. // exit
  1316. exit();
  1317. }
  1318. exit();
  1319. }
  1320. /**
  1321. * fluxd
  1322. *
  1323. * @param $action
  1324. */
  1325. function sa_fluxd($action = "") {
  1326. global $cfg, $error, $statusImage, $statusMessage, $htmlTitle, $htmlTop, $htmlMain;
  1327. if ($action == "")
  1328. return;
  1329. switch ($action) {
  1330. case "0": // fluxd-main
  1331. $htmlTitle = "fluxd";
  1332. break;
  1333. case "1": // fluxd-log
  1334. $htmlTitle = "fluxd - log";
  1335. $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">';
  1336. $htmlMain .= '<pre>';
  1337. $htmlMain .= tfb_htmlencode(@file_get_contents($cfg["path"].'.fluxd/fluxd.log'));
  1338. $htmlMain .= '</pre>';
  1339. $htmlMain .= '</div>';
  1340. break;
  1341. case "2": // fluxd-error-log
  1342. $htmlTitle = "fluxd - error-log";
  1343. $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">';
  1344. $htmlMain .= '<pre>';
  1345. $htmlMain .= tfb_htmlencode(@file_get_contents($cfg["path"].'.fluxd/fluxd-error.log'));
  1346. $htmlMain .= '</pre>';
  1347. $htmlMain .= '</div>';
  1348. break;
  1349. case "3": // fluxd-ps
  1350. $htmlTitle = "fluxd - ps";
  1351. $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">';
  1352. $htmlMain .= '<pre>';
  1353. $htmlMain .= tfb_htmlencode(shell_exec("ps auxww | ".$cfg['bin_grep']." fluxd | ".$cfg['bin_grep']." -v grep"));
  1354. $htmlMain .= '</pre>';
  1355. $htmlMain .= '</div>';
  1356. break;
  1357. case "4": // fluxd-status
  1358. $htmlTitle = "fluxd - status";
  1359. if (Fluxd::isRunning()) {
  1360. $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">';
  1361. $htmlMain .= '<pre>';
  1362. $htmlMain .= tfb_htmlencode(Fluxd::status());
  1363. $htmlMain .= '</pre>';
  1364. $htmlMain .= '</div>';
  1365. } else {
  1366. $htmlMain .= '<br><strong>fluxd not running</strong>';
  1367. }
  1368. break;
  1369. case "5": // fluxd-check
  1370. $htmlTitle = "fluxd - check";
  1371. $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">';
  1372. $htmlMain .= '<pre>';
  1373. $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"));
  1374. $htmlMain .= '</pre>';
  1375. $htmlMain .= '</div>';
  1376. break;
  1377. case "6": // fluxd-db-debug
  1378. $htmlTitle = "fluxd - db-debug";
  1379. $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">';
  1380. $htmlMain .= '<pre>';
  1381. $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"])));
  1382. $htmlMain .= '</pre>';
  1383. $htmlMain .= '</div>';
  1384. break;
  1385. case "9": // fluxd-version
  1386. $htmlTitle = "fluxd - version";
  1387. $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">';
  1388. $htmlMain .= '<pre>';
  1389. $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"));
  1390. $htmlMain .= '</pre>';
  1391. $htmlMain .= '</div>';
  1392. break;
  1393. }
  1394. printPage();
  1395. exit();
  1396. }
  1397. /**
  1398. * fluazu
  1399. *
  1400. * @param $action
  1401. */
  1402. function sa_fluazu($action = "") {
  1403. global $cfg, $error, $statusImage, $statusMessage, $htmlTitle, $htmlTop, $htmlMain;
  1404. if ($action == "")
  1405. return;
  1406. switch ($action) {
  1407. case "0": // fluazu-main
  1408. $htmlTitle = "fluazu";
  1409. break;
  1410. case "1": // fluazu-log
  1411. $htmlTitle = "fluazu - log";
  1412. $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">';
  1413. $htmlMain .= '<pre>';
  1414. $htmlMain .= tfb_htmlencode(@file_get_contents($cfg["path"].'.fluazu/fluazu.log'));
  1415. $htmlMain .= '</pre>';
  1416. $htmlMain .= '</div>';
  1417. break;
  1418. case "3": // fluazu-ps
  1419. $htmlTitle = "fluazu - ps";
  1420. $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">';
  1421. $htmlMain .= '<pre>';
  1422. $htmlMain .= tfb_htmlencode(shell_exec("ps auxww | ".$cfg['bin_grep']." fluazu.py | ".$cfg['bin_grep']." -v grep"));
  1423. $htmlMain .= '</pre>';
  1424. $htmlMain .= '</div>';
  1425. break;
  1426. case "9": // fluazu-version
  1427. $htmlTitle = "fluazu - version";
  1428. $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">';
  1429. $htmlMain .= '<pre>';
  1430. $htmlMain .= tfb_htmlencode(shell_exec("cd ".tfb_shellencode($cfg["docroot"]."bin/clients/fluazu/")."; ".$cfg["pythonCmd"]." -OO fluazu.py --version"));
  1431. $htmlMain .= '</pre>';
  1432. $htmlMain .= '</div>';
  1433. break;
  1434. }
  1435. printPage();
  1436. exit();
  1437. }
  1438. /**
  1439. * superadminAuthentication
  1440. *
  1441. * @param $message
  1442. */
  1443. function superadminAuthentication($message = "") {
  1444. if (!IsSuperAdmin()) {
  1445. @header("Content-Type: text/plain");
  1446. echo "\nAccess Error"."\n\n";
  1447. if ((isset($message)) && ($message != ""))
  1448. echo $message."\n";
  1449. else
  1450. echo "Only SuperAdmin can access superadmin-page.\n";
  1451. exit();
  1452. }
  1453. }
  1454. /**
  1455. * builds page
  1456. *
  1457. * @param $action
  1458. */
  1459. function buildPage($action) {
  1460. global $cfg, $statusImage, $statusMessage, $htmlTitle, $htmlTop, $htmlMain;
  1461. // navi
  1462. $htmlTop .= '<a href="' . _FILE_THIS . '?t=0">Transfer Bulk-ops</a>';
  1463. $htmlTop .= ' | ';
  1464. $htmlTop .= '<a href="' . _FILE_THIS . '?p=0">Processes</a>';
  1465. $htmlTop .= ' | ';
  1466. $htmlTop .= '<a href="' . _FILE_THIS . '?m=0">Maintenance</a>';
  1467. $htmlTop .= ' | ';
  1468. $htmlTop .= '<a href="' . _FILE_THIS . '?b=0">Backup</a>';
  1469. $htmlTop .= ' | ';
  1470. $htmlTop .= '<a href="' . _FILE_THIS . '?l=0">Log</a>';
  1471. $htmlTop .= ' | ';
  1472. $htmlTop .= '<a href="' . _FILE_THIS . '?y=0">Misc</a>';
  1473. $htmlTop .= ' | ';
  1474. $htmlTop .= '<a href="' . _FILE_THIS . '?z=0">About</a>';
  1475. // body
  1476. switch($action) {
  1477. case "b": // backup passthru
  1478. case "-b": // backup-error passthru
  1479. if ($action == "b")
  1480. $statusImage = "yellow.gif";
  1481. else
  1482. $statusImage = "red.gif";
  1483. //
  1484. $htmlMain .= '<table width="100%" bgcolor="'.$cfg["table_data_bg"].'" border="0" cellpadding="4" cellspacing="0"><tr><td width="100%">';
  1485. $htmlMain .= '<a href="' . _FILE_THIS . '?b=0">Create Backup</a>';
  1486. $htmlMain .= ' | ';
  1487. $htmlMain .= '<a href="' . _FILE_THIS . '?b=3">Backups currently on server</a>';
  1488. $htmlMain .= '</td><td align="right" nowrap><strong>Backup</strong></td>';
  1489. $htmlMain .= '</tr></table>';
  1490. break;
  1491. case "-u": // update-error passthru
  1492. $statusImage = "red.gif";
  1493. $htmlTitle = "Update";
  1494. $htmlMain = '<br><font color="red"><strong>Update from your version not possible.</strong></font>';
  1495. $htmlMain .= '<br><br>';
  1496. $htmlMain .= 'Please use the most recent tarball and perform a manual update.';
  1497. $htmlMain .= '<br>';
  1498. break;
  1499. case "t": // transfers passthru
  1500. $statusImage = "black.gif";
  1501. break;
  1502. case "p": // processes passthru
  1503. $statusImage = "black.gif";
  1504. $htmlMain .= '<table width="100%" bgcolor="'.$cfg["table_data_bg"].'" border="0" cellpadding="4" cellspacing="0"><tr><td width="100%">';
  1505. $htmlMain .= '<a href="' . _FILE_THIS . '?p=1">All</a>';
  1506. $htmlMain .= ' | ';
  1507. $htmlMain .= '<a href="' . _FILE_THIS . '?p=2">Transfers</a>';
  1508. $htmlMain .= '</td><td align="right"><strong>Processes</strong></td>';
  1509. $htmlMain .= '</tr></table>';
  1510. break;
  1511. case "m": // maintenance passthru
  1512. $statusImage = "black.gif";
  1513. $htmlMain .= '<table width="100%" bgcolor="'.$cfg["table_data_bg"].'" border="0" cellpadding="4" cellspacing="0"><tr><td width="100%">';
  1514. $htmlMain .= '<a href="' . _FILE_THIS . '?m=1">Main</a>';
  1515. $htmlMain .= ' | ';
  1516. $htmlMain .= '<a href="' . _FILE_THIS . '?m=2">Kill</a>';
  1517. $htmlMain .= ' | ';
  1518. $htmlMain .= '<a href="' . _FILE_THIS . '?m=3">Clean</a>';
  1519. $htmlMain .= ' | ';
  1520. $htmlMain .= '<a href="' . _FILE_THIS . '?m=4">Repair</a>';
  1521. $htmlMain .= ' | ';
  1522. $htmlMain .= '<a href="' . _FILE_THIS . '?m=5">Reset</a>';
  1523. $htmlMain .= ' | ';
  1524. $htmlMain .= '<a href="' . _FILE_THIS . '?m=6">Lock</a>';
  1525. $htmlMain .= '</td><td align="right"><strong>Maintenance</strong></td>';
  1526. $htmlMain .= '</tr></table>';
  1527. break;
  1528. case "l": // log passthru
  1529. $statusImage = "black.gif";
  1530. $htmlMain .= '<table width="100%" bgcolor="'.$cfg["table_data_bg"].'" border="0" cellpadding="4" cellspacing="0"><tr><td width="100%">';
  1531. $htmlMain .= '<a href="' . _FILE_THIS . '?l=1">fluxd</a>';
  1532. $htmlMain .= ' | ';
  1533. $htmlMain .= '<a href="' . _FILE_THIS . '?l=2">fluxd-error</a>';
  1534. $htmlMain .= ' | ';
  1535. $htmlMain .= '<a href="' . _FILE_THIS . '?l=3">fluazu</a>';
  1536. $htmlMain .= ' | ';
  1537. $htmlMain .= '<a href="' . _FILE_THIS . '?l=5">mainline</a>';
  1538. $htmlMain .= ' | ';
  1539. $htmlMain .= '<a href="' . _FILE_THIS . '?l=8">transfers</a>';
  1540. $htmlMain .= '</td><td align="right"><strong>Log</strong></td>';
  1541. $htmlMain .= '</tr></table>';
  1542. break;
  1543. case "y": // misc passthru
  1544. $statusImage = "black.gif";
  1545. $htmlMain .= '<table width="100%" bgcolor="'.$cfg["table_data_bg"].'" border="0" cellpadding="4" cellspacing="0"><tr><td width="100%">';
  1546. $htmlMain .= '<a href="' . _FILE_THIS . '?y=1">Lists</a>';
  1547. $htmlMain .= ' | ';
  1548. $htmlMain .= '<a href="' . _FILE_THIS . '?y=3">Checksum Validation</a>';
  1549. $htmlMain .= ' | ';
  1550. $htmlMain .= '<a href="' . _FILE_THIS . '?y=5">Check Requirements</a>';
  1551. $htmlMain .= '</td><td align="right" nowrap><strong>Misc</strong></td>';
  1552. $htmlMain .= '</tr></table>';
  1553. break;
  1554. case "z": // about passthru
  1555. $statusImage = "black.gif";
  1556. $htmlMain .= '<table width="100%" bgcolor="'.$cfg["table_data_bg"].'" border="0" cellpadding="4" cellspacing="0"><tr><td width="100%">';
  1557. $htmlMain .= '<a href="' . _FILE_THIS . '?z=1">Version</a>';
  1558. $htmlMain .= ' | ';
  1559. $htmlMain .= '<a href="' . _FILE_THIS . '?z=2">News</a>';
  1560. $htmlMain .= ' | ';
  1561. $htmlMain .= '<a href="' . _FILE_THIS . '?z=3">Changelog</a>';
  1562. $htmlMain .= '</td><td align="right" nowrap><strong>About</strong></td>';
  1563. $htmlMain .= '</tr></table>';
  1564. break;
  1565. case "f": // fluxd passthru
  1566. $htmlTop = "";
  1567. $statusImage = "";
  1568. $htmlMain .= '<table width="100%" bgcolor="'.$cfg["table_data_bg"].'" border="0" cellpadding="4" cellspacing="0"><tr><td width="100%">';
  1569. $htmlMain .= '<a href="' . _FILE_THIS . '?f=1">log</a>';
  1570. $htmlMain .= ' | ';
  1571. $htmlMain .= '<a href="' . _FILE_THIS . '?f=2">error-log</a>';
  1572. $htmlMain .= ' | ';
  1573. $htmlMain .= '<a href="' . _FILE_THIS . '?f=3">ps</a>';
  1574. if (Fluxd::isRunning()) {
  1575. $htmlMain .= ' | ';
  1576. $htmlMain .= '<a href="' . _FILE_THIS . '?f=4">status</a>';
  1577. } else {
  1578. $htmlMain .= ' | ';
  1579. $htmlMain .= '<a href="' . _FILE_THIS . '?f=5">check</a>';
  1580. $htmlMain .= ' | ';
  1581. $htmlMain .= '<a href="' . _FILE_THIS . '?f=6">db-debug</a>';
  1582. $htmlMain .= ' | ';
  1583. $htmlMain .= '<a href="' . _FILE_THIS . '?f=9">version</a>';
  1584. }
  1585. $htmlMain .= '</td><td align="right"><strong>fluxd</strong>';
  1586. $htmlMain .= '</tr></table>';
  1587. break;
  1588. case "_": // default
  1589. default:
  1590. $htmlTitle = "SuperAdmin";
  1591. $statusImage = "black.gif";
  1592. $htmlMain = '<br><div align="left">';
  1593. $htmlMain .= '<p>Select the superadmin task you wish to perform below:<br><br>';
  1594. $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';
  1595. $htmlMain .= '<p>';
  1596. $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';
  1597. $htmlMain .= '<p>';
  1598. $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';
  1599. $htmlMain .= '<p>';
  1600. $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';
  1601. $htmlMain .= '<p>';
  1602. $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';
  1603. $htmlMain .= '<p>';
  1604. $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';
  1605. $htmlMain .= '<p>';
  1606. $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';
  1607. $htmlMain .= '</div><br><br>';
  1608. break;
  1609. }
  1610. }
  1611. /**
  1612. * echo a string. use echo or sendLine
  1613. *
  1614. * @param $string: string to echo
  1615. * @param $mode: 0 = echo | 1 = sendLine
  1616. */
  1617. function doEcho($string, $mode = 0) {
  1618. switch ($mode) {
  1619. case 0:
  1620. echo $string;
  1621. return;
  1622. case 1:
  1623. sendLine($string);
  1624. return;
  1625. }
  1626. }
  1627. /**
  1628. * prints the page
  1629. */
  1630. function printPage() {
  1631. printPageStart(0);
  1632. global $htmlMain;
  1633. echo $htmlMain;
  1634. printPageEnd(0);
  1635. }
  1636. /**
  1637. * prints the page-start
  1638. */
  1639. function printPageStart($echoMode = 0) {
  1640. global $cfg, $statusImage, $statusMessage, $htmlTitle, $htmlTop, $htmlMain;
  1641. doEcho('<HTML>',$echoMode);
  1642. doEcho('<HEAD>',$echoMode);
  1643. doEcho('<TITLE>'.$cfg["pagetitle"].' - SuperAdmin</TITLE>',$echoMode);
  1644. doEcho('<link rel="icon" href="themes/'.$cfg["theme"].'/images/favicon.ico" type="image/x-icon" />',$echoMode);
  1645. doEcho('<link rel="shortcut icon" href="themes/'.$cfg["theme"].'/images/favicon.ico" type="image/x-icon" />',$echoMode);
  1646. // theme-switch
  1647. if ((strpos($cfg["theme"], '/')) === false)
  1648. doEcho('<LINK REL="StyleSheet" HREF="themes/'.$cfg["theme"].'/css/default.css" TYPE="text/css">',$echoMode);
  1649. else
  1650. doEcho('<LINK REL="StyleSheet" HREF="themes/'.$cfg["theme"].'/style.css" TYPE="text/css">',$echoMode);
  1651. doEcho('<META HTTP-EQUIV="Pragma" CONTENT="no-cache; charset='. $cfg['_CHARSET'] .'">',$echoMode);
  1652. doEcho('</HEAD>',$echoMode);
  1653. doEcho('<BODY topmargin="8" leftmargin="5" bgcolor="'.$cfg["main_bgcolor"].'">',$echoMode);
  1654. doEcho('<div align="center">',$echoMode);
  1655. doEcho('<table border="0" cellpadding="0" cellspacing="0">',$echoMode);
  1656. doEcho('<tr>',$echoMode);
  1657. doEcho('<td>',$echoMode);
  1658. doEcho('<table border="1" bordercolor="'.$cfg["table_border_dk"].'" cellpadding="4" cellspacing="0">',$echoMode);
  1659. doEcho('<tr>',$echoMode);
  1660. doEcho('<td bgcolor="'.$cfg["main_bgcolor"].'" background="themes/'.$cfg["theme"].'/images/bar.gif">',$echoMode);
  1661. doEcho('<table width="100%" cellpadding="0" cellspacing="0" border="0">',$echoMode);
  1662. doEcho('<tr>',$echoMode);
  1663. doEcho('<td align="left"><font class="title">'.$cfg["pagetitle"]." - ".$htmlTitle.'</font></td>',$echoMode);
  1664. doEcho('</td>',$echoMode);
  1665. doEcho('</tr>',$echoMode);
  1666. doEcho('</table>',$echoMode);
  1667. doEcho('</td>',$echoMode);
  1668. doEcho('</tr>',$echoMode);
  1669. doEcho('<tr>',$echoMode);
  1670. doEcho('<td bgcolor="'.$cfg["table_header_bg"].'">',$echoMode);
  1671. doEcho('<div align="center">',$echoMode);
  1672. doEcho('<table width="100%" bgcolor="'.$cfg["body_data_bg"].'">',$echoMode);
  1673. doEcho('<tr>',$echoMode);
  1674. doEcho('<td>',$echoMode);
  1675. doEcho('<div align="center">',$echoMode);
  1676. doEcho('<table width="100%" cellpadding="0" cellspacing="0" border="0">',$echoMode);
  1677. doEcho('<tr>',$echoMode);
  1678. doEcho('<td align="left">',$echoMode);
  1679. doEcho($htmlTop,$echoMode);
  1680. doEcho('</td>',$echoMode);
  1681. doEcho('<td align="right" width="16">',$echoMode);
  1682. if ($statusImage != "") {
  1683. if ($statusImage != "yellow.gif")
  1684. doEcho('<a href="' . _FILE_THIS . '">',$echoMode);
  1685. doEcho('<img src="themes/'.$cfg["theme"].'/images/'.$statusImage.'" width="16" height="16" border="0" title="'.$statusMessage.'">',$echoMode);
  1686. if ($statusImage != "yellow.gif")
  1687. doEcho('</a>',$echoMode);
  1688. }
  1689. doEcho('</td>',$echoMode);
  1690. doEcho('</tr>',$echoMode);
  1691. doEcho('</table>',$echoMode);
  1692. doEcho('<table bgcolor="'.$cfg["table_header_bg"].'" width="750" cellpadding="1">',$echoMode);
  1693. doEcho('<tr>',$echoMode);
  1694. doEcho('<td>',$echoMode);
  1695. doEcho('<div align="left">',$echoMode);
  1696. doEcho('<table border="0" cellpadding="2" cellspacing="2" width="100%">',$echoMode);
  1697. }
  1698. /**
  1699. * prints the page-end
  1700. */
  1701. function printPageEnd($echoMode = 0) {
  1702. doEcho('</table>',$echoMode);
  1703. doEcho('</div>',$echoMode);
  1704. doEcho('</td>',$echoMode);
  1705. doEcho('</tr>',$echoMode);
  1706. doEcho('</table>',$echoMode);
  1707. doEcho('</td>',$echoMode);
  1708. doEcho('</tr>',$echoMode);
  1709. doEcho('</table>',$echoMode);
  1710. doEcho('</div>',$echoMode);
  1711. doEcho('</td>',$echoMode);
  1712. doEcho('</tr>',$echoMode);
  1713. doEcho('</table>',$echoMode);
  1714. doEcho('</td>',$echoMode);
  1715. doEcho('</tr>',$echoMode);
  1716. doEcho('</table>',$echoMode);
  1717. doEcho('</div>',$echoMode);
  1718. doEcho('</BODY>',$echoMode);
  1719. doEcho('</HTML>',$echoMode);
  1720. }
  1721. /**
  1722. * bails out cause of version-error.
  1723. */
  1724. function updateErrorNice($message = "") {
  1725. global $statusImage, $statusMessage, $htmlTop, $htmlMain;
  1726. $htmlTop = "<strong>Update</strong>";
  1727. $htmlMain = '<br><font color="red"><strong>Update from your Version not possible.</strong></font>';
  1728. $htmlMain .= '<br><br>';
  1729. $htmlMain .= 'Please use the most recent tarball and perform a manual update.';
  1730. $htmlMain .= '<br>';
  1731. if ((isset($message)) && ($message != "") && (trim($message) != "0"))
  1732. $htmlMain .= '<br><pre>'.$message.'</pre>';
  1733. $statusImage = "red.gif";
  1734. printPage();
  1735. exit();
  1736. }
  1737. /**
  1738. * bails out cause of version-error.
  1739. */
  1740. function updateError($message = "") {
  1741. $errorString = "ERROR processing auto-update. please do manual update.";
  1742. if ((isset($message)) && ($message != ""))
  1743. $errorString .= "\n".$message;
  1744. @header("Content-Type: text/plain");
  1745. echo $errorString;
  1746. exit();
  1747. }
  1748. /**
  1749. * get a ado-connection to our database.
  1750. *
  1751. * @return database-connection or false on error
  1752. */
  1753. function getAdoConnection() {
  1754. global $cfg;
  1755. // create ado-object
  1756. $db = &ADONewConnection($cfg["db_type"]);
  1757. // connect
  1758. $result = @ $db->Connect($cfg["db_host"], $cfg["db_user"], $cfg["db_pass"], $cfg["db_name"]);
  1759. // check for error
  1760. if ($db->ErrorNo() != 0 || !$result)
  1761. return false;
  1762. // return db-connection
  1763. return $db;
  1764. }
  1765. /**
  1766. * get release-list
  1767. *
  1768. * @return release-list as html-snip
  1769. */
  1770. function getReleaseList() {
  1771. global $cfg, $error;
  1772. $retVal = "";
  1773. $releaseList = @gzinflate(getDataFromUrl(_SUPERADMIN_URLBASE . _SUPERADMIN_PROXY ."?a=3"));
  1774. if ((isset($releaseList)) && ($releaseList != "")) {
  1775. $retVal .= '<strong>Available Tarballs: </strong>';
  1776. $retVal .= '<br>';
  1777. $retVal .= '<table cellpadding="2" cellspacing="1" border="1" bordercolor="'.$cfg["table_border_dk"].'" bgcolor="'.$cfg["body_data_bg"].'">';
  1778. $retVal .= '<tr>';
  1779. $retVal .= '<td align="center" bgcolor="'.$cfg["table_header_bg"].'">&nbsp;</td>';
  1780. $retVal .= '<td align="center" bgcolor="'.$cfg["table_header_bg"].'"><strong>Version</strong></td>';
  1781. $retVal .= '<td align="center" bgcolor="'.$cfg["table_header_bg"].'"><strong>Checksum</strong></td>';
  1782. $retVal .= '</tr>';
  1783. $releaseListFiles = explode("\n",$releaseList);
  1784. foreach ($releaseListFiles as $release) {
  1785. $release = trim($release);
  1786. if ((isset($release)) && ($release != "")) {
  1787. $tempArray = explode("_", $release);
  1788. $tempString = array_pop($tempArray);
  1789. $releaseVersion = substr($tempString, 0, -8);
  1790. $retVal .= '<tr>';
  1791. $retVal .= '<td align="center">';
  1792. $retVal .= '<a href="'._SUPERADMIN_URLBASE.'files/'.$release.'">';
  1793. $retVal .= '<img src="themes/'.$cfg["theme"].'/images/download_owner.gif" title="Download '.$releaseVersion.'" border="0">';
  1794. $retVal .= '</a>';
  1795. $retVal .= '</td>';
  1796. $retVal .= '<td align="right">';
  1797. $retVal .= '<a href="'._SUPERADMIN_URLBASE.'files/'.$release.'">';
  1798. $retVal .= $releaseVersion;
  1799. $retVal .= '</a>';
  1800. $retVal .= '</td>';
  1801. $retVal .= '<td align="right">';
  1802. $retVal .= '<a href="'._SUPERADMIN_URLBASE.'files/'.$release.'.md5">';
  1803. $retVal .= 'md5';
  1804. $retVal .= '</a>';
  1805. $retVal .= '</td>';
  1806. $retVal .= '</tr>';
  1807. }
  1808. }
  1809. $retVal .= '</table>';
  1810. }
  1811. return $retVal;
  1812. }
  1813. /**
  1814. * cleans a dir (deletes all files)
  1815. *
  1816. * @param $dir
  1817. * @return string with deleted files
  1818. */
  1819. function cleanDir($dir) {
  1820. if (((strlen($dir) > 0)) && (substr($dir, -1 ) != "/"))
  1821. $dir .= "/";
  1822. $result = "";
  1823. $dirHandle = false;
  1824. $dirHandle = @opendir($dir);
  1825. if ($dirHandle === false) return $result;
  1826. while (false !== ($file = @readdir($dirHandle))) {
  1827. if ((@is_file($dir.$file)) && ((substr($file, 0, 1)) != ".")) {
  1828. if (@unlink($dir.$file) === true)
  1829. $result .= tfb_htmlencode($file)."\n";
  1830. else
  1831. $result .= "ERROR: ".tfb_htmlencode($file)."\n";
  1832. }
  1833. }
  1834. @closedir($dirHandle);
  1835. return $result;
  1836. }
  1837. /**
  1838. * formats a timestamp-string to human readable format.
  1839. *
  1840. * @param $timestampString string with prop. timestamp
  1841. * @return string with human-readable date
  1842. */
  1843. function formatHumanDate($timestampString) {
  1844. return gmstrftime("%b %d %Y %H:%M:%S", mktime(
  1845. intval(substr($timestampString, 8, 2)),
  1846. intval(substr($timestampString, 10, 2)),
  1847. intval(substr($timestampString, 12, 2)),
  1848. intval(substr($timestampString, 4, 2)),
  1849. intval(substr($timestampString, 6, 2)),
  1850. intval(substr($timestampString, 0, 4))
  1851. ));
  1852. }
  1853. /**
  1854. * formats a size-string to human readable format.
  1855. *
  1856. * @param $sizeInByte number with bytes
  1857. * @return string with human-readable size
  1858. */
  1859. function formatHumanSize($sizeInByte) {
  1860. if ($sizeInByte > (1073741824)) // > 1G
  1861. return (string) (round($sizeInByte/(1073741824), 1))."G";
  1862. if ($sizeInByte > (1048576)) // > 1M
  1863. return (string) (round($sizeInByte/(1048576), 1))."M";
  1864. if ($sizeInByte > (1024)) // > 1k
  1865. return (string) (round($sizeInByte/(1024), 1))."k";
  1866. return (string) $sizeInByte;
  1867. }
  1868. /**
  1869. * checks if backup-id is a valid backup-archive
  1870. *
  1871. * @param $param the param with the backup-id
  1872. * @param boolean if archive-name is a valid backup-archive
  1873. */
  1874. function backupParamCheck($param) {
  1875. global $cfg, $error;
  1876. // sanity-checks
  1877. if (preg_match("/\\\/", urldecode($param)))
  1878. return false;
  1879. if (preg_match("/\.\./", urldecode($param)))
  1880. return false;
  1881. // check id
  1882. $fileList = backupList();
  1883. if ((isset($fileList)) && ($fileList != "")) {
  1884. $validFiles = explode("\n",$fileList);
  1885. return (in_array($param, $validFiles));
  1886. } else {
  1887. return false;
  1888. }
  1889. return false;
  1890. }
  1891. /**
  1892. * build backup-list
  1893. *
  1894. * @return backup-list as string
  1895. */
  1896. function backupListDisplay() {
  1897. global $cfg, $error;
  1898. // backup-dir
  1899. $dirBackup = $cfg["path"]. _DIR_BACKUP . '/';
  1900. //
  1901. $retVal = "";
  1902. $fileList = backupList();
  1903. if ((isset($fileList)) && ($fileList != "")) {
  1904. $retVal .= '<table cellpadding="2" cellspacing="1" border="1" bordercolor="'.$cfg["table_admin_border"].'" bgcolor="'.$cfg["body_data_bg"].'">';
  1905. $retVal .= '<tr>';
  1906. $retVal .= '<td align="center" bgcolor="'.$cfg["table_header_bg"].'"><strong>Version</strong></td>';
  1907. $retVal .= '<td align="center" bgcolor="'.$cfg["table_header_bg"].'"><strong>Date</strong></td>';
  1908. $retVal .= '<td align="center" bgcolor="'.$cfg["table_header_bg"].'"><strong>Comp.</strong></td>';
  1909. $retVal .= '<td align="center" bgcolor="'.$cfg["table_header_bg"].'"><strong>Size</strong></td>';
  1910. $retVal .= '<td align="center" bgcolor="'.$cfg["table_header_bg"].'">&nbsp;</td>';
  1911. $retVal .= '</tr>';
  1912. // theme-switch
  1913. if ((strpos($cfg["theme"], '/')) === false)
  1914. $theme = $cfg["theme"];
  1915. else
  1916. $theme = "tf_standard_themes";
  1917. $backupListFiles = explode("\n",$fileList);
  1918. foreach ($backupListFiles as $backup) {
  1919. $backup = trim($backup);
  1920. $backupFile = $dirBackup.$backup;
  1921. if ((isset($backup)) && ($backup != "") && (is_file($backupFile))) {
  1922. $backupElements = explode("_",$backup);
  1923. $retVal .= '<tr>';
  1924. $retVal .= '<td align="center">'.$backupElements[1].'</td>';
  1925. $retVal .= '<td align="right">'.formatHumanDate(substr($backupElements[2], 0, 14)).'</td>';
  1926. $lastChar = substr($backupElements[2], -1, 1);
  1927. $retVal .= '<td align="center">';
  1928. switch ($lastChar) {
  1929. case "r":
  1930. $retVal .= 'none';
  1931. break;
  1932. case "z":
  1933. $retVal .= 'gzip';
  1934. break;
  1935. case "2":
  1936. $retVal .= 'bzip2';
  1937. break;
  1938. default:
  1939. $retVal .= 'unknown';
  1940. break;
  1941. }
  1942. $retVal .= '</td>';
  1943. $retVal .= '<td align="right">'.(string)(formatHumanSize(filesize($backupFile))).'</td>';
  1944. $retVal .= '<td align="center">';
  1945. $retVal .= '<a href="'. _FILE_THIS .'?b=4&f='.$backup.'">';
  1946. $retVal .= '<img src="themes/'.$cfg["theme"].'/images/download_owner.gif" title="Download" border="0">';
  1947. $retVal .= '</a>';
  1948. $retVal .= '&nbsp;&nbsp;';
  1949. $retVal .= '<a href="'. _FILE_THIS .'?b=5&f='.$backup.'">';
  1950. $retVal .= '<img src="themes/'.$theme.'/images/delete.png" title="Delete" border="0">';
  1951. $retVal .= '</a>';
  1952. $retVal .= '</td>';
  1953. $retVal .= '</tr>';
  1954. }
  1955. }
  1956. $retVal .= '</table>';
  1957. } else {
  1958. $retVal .= '<strong>No Backups on Server</strong>';
  1959. }
  1960. return $retVal;
  1961. }
  1962. /**
  1963. * get backup-list
  1964. *
  1965. * @return backup-list as string or empty string on error / no files
  1966. */
  1967. function backupList() {
  1968. global $cfg, $error;
  1969. // backup-dir
  1970. $dirBackup = $cfg["path"]. _DIR_BACKUP;
  1971. if (file_exists($dirBackup)) {
  1972. if ($dirHandle = opendir($dirBackup)) {
  1973. $fileList = "";
  1974. while (false !== ($file = readdir($dirHandle))) {
  1975. if ( substr($file, 0, 7) == "backup_" )
  1976. $fileList .= $file . "\n";
  1977. }
  1978. closedir($dirHandle);
  1979. return $fileList;
  1980. } else {
  1981. return "";
  1982. }
  1983. } else {
  1984. return "";
  1985. }
  1986. }
  1987. /**
  1988. * deletes a backup of a flux-installation
  1989. *
  1990. * @param $filename the file with the backup
  1991. */
  1992. function backupDelete($filename) {
  1993. global $cfg;
  1994. $backupFile = $cfg["path"]. _DIR_BACKUP . '/' . $filename;
  1995. @unlink($backupFile);
  1996. AuditAction($cfg["constants"]["admin"], "Backup Deleted: ".$filename);
  1997. }
  1998. /**
  1999. * sends a backup of flux-installation to a client
  2000. *
  2001. * @param $filename the file with the backup
  2002. * @param $delete boolean if file should be deleted.
  2003. */
  2004. function backupSend($filename, $delete = false) {
  2005. global $cfg;
  2006. $backupFile = $cfg["path"]. _DIR_BACKUP . '/' . $filename;
  2007. if ($delete) {
  2008. @session_write_close();
  2009. @ob_end_clean();
  2010. if (connection_status() != 0)
  2011. return false;
  2012. set_time_limit(0);
  2013. }
  2014. if (!is_file($backupFile))
  2015. return false;
  2016. // log before we screw up the file-name
  2017. AuditAction($cfg["constants"]["admin"], "Backup Sent: ".$filename);
  2018. // filenames in IE containing dots will screw up the filename
  2019. if (strstr($_SERVER['HTTP_USER_AGENT'], "MSIE"))
  2020. $filename = preg_replace('/\./', '%2e', $filename, substr_count($filename, '.') - 1);
  2021. // send data
  2022. @header("Cache-Control: no-cache");
  2023. @header("Pragma: no-cache");
  2024. @header("Content-Type: application/octet-stream");
  2025. @header("Content-Length: " .(string)(filesize($backupFile)) );
  2026. @header('Content-Disposition: attachment; filename="'.$filename.'"');
  2027. @header("Content-Transfer-Encoding: binary\n");
  2028. if ($delete) { // read data to mem, delete file and send complete
  2029. $data = file_get_contents($backupFile);
  2030. @unlink($backupFile);
  2031. echo $data;
  2032. } else { // read / write file with 8kb-buffer
  2033. if ($handle = fopen($backupFile, 'rb')){
  2034. while ((!feof($handle)) && (connection_status() == 0)) {
  2035. print(fread($handle, 8192));
  2036. flush();
  2037. }
  2038. fclose($handle);
  2039. }
  2040. }
  2041. // return
  2042. if ($delete) {
  2043. return true;
  2044. } else {
  2045. return((connection_status()==0) and !connection_aborted());
  2046. }
  2047. }
  2048. /**
  2049. * backup of flux-installation
  2050. *
  2051. * @param $talk: boolean if function should talk
  2052. * @param $compression: 0 = none | 1 = gzip | 2 = bzip2
  2053. * @return string with name of backup-archive, string with "" in error-case.
  2054. */
  2055. function backupCreate($talk = false, $compression = 0) {
  2056. global $cfg, $error;
  2057. // backup-dir
  2058. $dirBackup = $cfg["path"]. _DIR_BACKUP;
  2059. if (!checkDirectory($dirBackup)) {
  2060. $error = "Errors when checking/creating backup-dir: ".tfb_htmlencodekeepspaces($dirBackup);
  2061. return "";
  2062. }
  2063. // files and more strings
  2064. $backupName = "backup_". _VERSION ."_".date("YmdHis");
  2065. $fileArchiveName = $backupName.".tar";
  2066. $tarSwitch = "-cf";
  2067. switch ($compression) {
  2068. case 1:
  2069. $fileArchiveName .= ".gz";
  2070. $tarSwitch = "-zcf";
  2071. break;
  2072. case 2:
  2073. $fileArchiveName .= ".bz2";
  2074. $tarSwitch = "-jcf";
  2075. break;
  2076. }
  2077. // files
  2078. $files = array();
  2079. $files['archive'] = $dirBackup . '/' . $fileArchiveName;
  2080. $files['db'] = $dirBackup . '/database.sql';
  2081. $files['docroot'] = $dirBackup . '/docroot.tar';
  2082. $files['transfers'] = $dirBackup . '/transfers.tar';
  2083. $files['fluxd'] = $dirBackup . '/fluxd.tar';
  2084. $files['mrtg'] = $dirBackup . '/mrtg.tar';
  2085. // exec
  2086. $exec = array();
  2087. $exec['transfers'] = ((@is_dir($cfg["transfer_file_path"])) === true);
  2088. $exec['fluxd'] = ((@is_dir($cfg["path"].'.fluxd')) === true);
  2089. $exec['mrtg'] = ((@is_dir($cfg["path"].'.mrtg')) === true);
  2090. // commands
  2091. $commands = array();
  2092. $commands['archive'] = "cd ".tfb_shellencode($dirBackup)."; tar ".$tarSwitch." ".$fileArchiveName." ";
  2093. $commands['db'] = "";
  2094. switch ($cfg["db_type"]) {
  2095. case "mysql":
  2096. $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']);
  2097. $commands['archive'] .= 'database.sql ';
  2098. break;
  2099. case "sqlite":
  2100. $commands['db'] = "sqlite ".tfb_shellencode($cfg["db_host"])." .dump > ".tfb_shellencode($files['db']);
  2101. $commands['archive'] .= 'database.sql ';
  2102. break;
  2103. case "postgres":
  2104. $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']);
  2105. $commands['archive'] .= 'database.sql ';
  2106. break;
  2107. }
  2108. $commands['archive'] .= 'docroot.tar';
  2109. if ($exec['transfers'] === true)
  2110. $commands['archive'] .= ' transfers.tar';
  2111. if ($exec['fluxd'] === true)
  2112. $commands['archive'] .= ' fluxd.tar';
  2113. if ($exec['mrtg'] === true)
  2114. $commands['archive'] .= ' mrtg.tar';
  2115. //$commands['docroot'] = "cd ".tfb_shellencode($dirBackup)."; tar -cf docroot.tar ".tfb_shellencode($cfg["docroot"]); // with path of docroot
  2116. $commands['docroot'] = "cd ".tfb_shellencode($cfg["docroot"])."; tar -cf ".tfb_shellencode($files['docroot'])." ."; // only content of docroot
  2117. $commands['transfers'] = "cd ".tfb_shellencode($cfg["transfer_file_path"])."; tar -cf ".tfb_shellencode($files['transfers'])." .";
  2118. $commands['fluxd'] = "cd ".tfb_shellencode($cfg["path"].'.fluxd')."; tar -cf ".tfb_shellencode($files['fluxd'])." .";
  2119. $commands['mrtg'] = "cd ".tfb_shellencode($cfg["path"].'.mrtg')."; tar -cf ".tfb_shellencode($files['mrtg'])." .";
  2120. // action
  2121. if ($talk)
  2122. sendLine('<br>');
  2123. // database-command
  2124. if ($commands['db'] != "") {
  2125. if ($talk)
  2126. sendLine('Backup of Database <em>'.tfb_htmlencodekeepspaces($cfg["db_name"]).'</em> ...');
  2127. shell_exec($commands['db']);
  2128. }
  2129. if ($talk)
  2130. sendLine(' <font color="green">Ok</font><br>');
  2131. // docroot-command
  2132. if ($talk)
  2133. sendLine('Backup of Docroot <em>'.tfb_htmlencodekeepspaces($cfg["docroot"]).'</em> ...');
  2134. shell_exec($commands['docroot']);
  2135. if ($talk)
  2136. sendLine(' <font color="green">Ok</font><br>');
  2137. // transfers-command
  2138. if ($exec['transfers'] === true) {
  2139. if ($talk)
  2140. sendLine('Backup of transfers <em>'.tfb_htmlencodekeepspaces($cfg["transfer_file_path"]).'</em> ...');
  2141. shell_exec($commands['transfers']);
  2142. if ($talk)
  2143. sendLine(' <font color="green">Ok</font><br>');
  2144. }
  2145. // fluxd-command
  2146. if ($exec['fluxd'] === true) {
  2147. if ($talk)
  2148. sendLine('Backup of fluxd <em>'.tfb_htmlencodekeepspaces($cfg["path"].'.fluxd').'</em> ...');
  2149. shell_exec($commands['fluxd']);
  2150. if ($talk)
  2151. sendLine(' <font color="green">Ok</font><br>');
  2152. }
  2153. // mrtg-command
  2154. if ($exec['mrtg'] === true) {
  2155. if ($talk)
  2156. sendLine('Backup of mrtg <em>'.tfb_htmlencodekeepspaces($cfg["path"].'.mrtg').'</em> ...');
  2157. shell_exec($commands['mrtg']);
  2158. if ($talk)
  2159. sendLine(' <font color="green">Ok</font><br>');
  2160. }
  2161. // create the archive
  2162. if ($talk)
  2163. sendLine('Creating Archive <em>'.$fileArchiveName.'</em> ...');
  2164. shell_exec($commands['archive']);
  2165. if ($talk)
  2166. sendLine(' <font color="green">Ok</font><br>');
  2167. // delete temp-file(s)
  2168. if ($talk)
  2169. sendLine('Deleting temp-files ...');
  2170. if ($commands['db'] != "")
  2171. @unlink($files['db']);
  2172. @unlink($files['docroot']);
  2173. @unlink($files['transfers']);
  2174. @unlink($files['fluxd']);
  2175. @unlink($files['mrtg']);
  2176. if ($talk)
  2177. sendLine(' <font color="green">Ok</font><br>');
  2178. // log
  2179. if ($talk)
  2180. sendLine('<font color="green">Backup Complete.</font><br>');
  2181. AuditAction($cfg["constants"]["admin"], "Backup Created: ".$fileArchiveName);
  2182. return $fileArchiveName;
  2183. }
  2184. /**
  2185. * validate Local Files
  2186. */
  2187. function validateLocalFiles() {
  2188. sendLine('<h3>Validate Files</h3>');
  2189. sendLine('<strong>Getting Checksum-list</strong>');
  2190. // download list
  2191. $checksumsString = "";
  2192. @ini_set("allow_url_fopen", "1");
  2193. @ini_set("user_agent", "torrentflux-b4rt/". _VERSION);
  2194. if ($urlHandle = @fopen(_SUPERADMIN_URLBASE._FILE_CHECKSUMS_PRE._VERSION._FILE_CHECKSUMS_SUF, 'r')) {
  2195. stream_set_timeout($urlHandle, 15);
  2196. $info = stream_get_meta_data($urlHandle);
  2197. while ((!feof($urlHandle)) && (!$info['timed_out'])) {
  2198. $checksumsString .= @fgets($urlHandle, 8192);
  2199. $info = stream_get_meta_data($urlHandle);
  2200. sendLine('.');
  2201. }
  2202. @fclose($urlHandle);
  2203. }
  2204. if (empty($checksumsString))
  2205. exit('error getting checksum-list from '._SUPERADMIN_URLBASE);
  2206. sendLine('<font color="green">done</font><br>');
  2207. sendLine('<br><strong>Processing list</strong>');
  2208. // remote Checksums
  2209. $remoteChecksums = array();
  2210. $remoteSums = explode("\n", $checksumsString);
  2211. $remoteSums = array_map('trim', $remoteSums);
  2212. foreach ($remoteSums as $remSum) {
  2213. $tempAry = explode(";", $remSum);
  2214. if ((!empty($tempAry[0])) && (!empty($tempAry[1]))) {
  2215. $remoteChecksums[$tempAry[0]] = $tempAry[1];
  2216. sendLine('.');
  2217. }
  2218. }
  2219. $remoteChecksumsCount = count($remoteChecksums);
  2220. sendLine('<font color="green">done</font> ('.$remoteChecksumsCount.')<br>');
  2221. // local Checksums
  2222. sendLine('<br><strong>Getting local checksums</strong>');
  2223. $localChecksums = getFileChecksums(true);
  2224. $localChecksumsCount = count($localChecksums);
  2225. sendLine('<font color="green">done</font> ('.$localChecksumsCount.')<br>');
  2226. // init some arrays
  2227. $filesMissing = array();
  2228. $filesNew = array();
  2229. $filesOk = array();
  2230. $filesChanged = array();
  2231. // validate
  2232. sendLine('<br><strong>Validating...</strong><br>');
  2233. // validate pass 1
  2234. foreach ($remoteChecksums as $file => $md5) {
  2235. $line = tfb_htmlencodekeepspaces($file);
  2236. if (isset($localChecksums[$file])) {
  2237. if ($md5 == $localChecksums[$file]) {
  2238. array_push($filesOk, $file);
  2239. $line .= ' <font color="green"> Ok</font>';
  2240. } else {
  2241. array_push($filesChanged, $file);
  2242. $line .= ' <font color="red"> Changed</font>';
  2243. }
  2244. } else {
  2245. array_push($filesMissing, $file);
  2246. $line .= ' <font color="red"> Missing</font>';
  2247. }
  2248. sendLine($line."<br>");
  2249. }
  2250. // validate pass 2
  2251. foreach ($localChecksums as $file => $md5)
  2252. if (!isset($remoteChecksums[$file]))
  2253. array_push($filesNew, $file);
  2254. // summary
  2255. sendLine('<h3>Done.</h3>');
  2256. // files Total
  2257. sendLine('<strong>'._VERSION.': </strong>'.$remoteChecksumsCount.'<br>');
  2258. sendLine('<strong>Local: </strong>'.$localChecksumsCount.'<br>');
  2259. // files Ok
  2260. sendLine('<strong>Unchanged: </strong>'.count($filesOk).'<br>');
  2261. // files Missing
  2262. sendLine('<strong>Missing: </strong>'.count($filesMissing).'<br>');
  2263. // files Changed
  2264. sendLine('<strong>Changed: </strong>'.count($filesChanged).'<br>');
  2265. // files New
  2266. sendLine('<strong>New: </strong>'.count($filesNew).'<br>');
  2267. if (count($filesNew) > 0) {
  2268. sendLine('<br><strong>New Files: </strong><br>');
  2269. foreach ($filesNew as $newFile)
  2270. sendLine(tfb_htmlencodekeepspaces($newFile).'<br>');
  2271. }
  2272. }
  2273. /**
  2274. * phpCheckWeb
  2275. *
  2276. * @return string
  2277. */
  2278. function phpCheckWeb() {
  2279. $retVal = "<br>";
  2280. $errors = 0;
  2281. $warnings = 0;
  2282. $dbsupported = 0;
  2283. $errorsMessages = array();
  2284. $warningsMessages = array();
  2285. // PHP-Version
  2286. $retVal .= '<p><strong>1. PHP-Version</strong></p>';
  2287. $phpVersion = 'PHP-Version: <em>'.PHP_VERSION.'</em> ';
  2288. if (PHP_VERSION < 4.3) {
  2289. $phpVersion .= '<font color="red">Failed</font>';
  2290. $errors++;
  2291. array_push($errorsMessages, "PHP-Version: 4.3 or higher required.");
  2292. } else {
  2293. $phpVersion .= '<font color="green">Passed</font>';
  2294. }
  2295. $retVal .= $phpVersion;
  2296. // PHP-Extensions
  2297. $retVal .= '<p><strong>2. PHP-Extensions</strong></p>';
  2298. $retVal .= "<ul>";
  2299. $loadedExtensions = get_loaded_extensions();
  2300. // session
  2301. $session = '<li>session ';
  2302. if (in_array("session", $loadedExtensions)) {
  2303. $session .= '<font color="green">Passed</font>';
  2304. } else {
  2305. $session .= '<font color="red">Failed</font>';
  2306. $errors++;
  2307. array_push($errorsMessages, "PHP-Extensions: session required.");
  2308. }
  2309. $retVal .= $session.'</li>';
  2310. // pcre
  2311. $pcre = '<li>pcre ';
  2312. if (in_array("pcre", $loadedExtensions)) {
  2313. $pcre .= '<font color="green">Passed</font>';
  2314. } else {
  2315. $pcre .= '<font color="red">Failed</font>';
  2316. $errors++;
  2317. array_push($errorsMessages, "PHP-Extensions: pcre required.");
  2318. }
  2319. $retVal .= $pcre.'</li>';
  2320. // sockets
  2321. $sockets = '<li>sockets ';
  2322. if (in_array("sockets", $loadedExtensions)) {
  2323. $sockets .= '<font color="green">Passed</font>';
  2324. } else {
  2325. $sockets .= '<font color="red">Failed</font>';
  2326. $warnings++;
  2327. array_push($warningsMessages, "PHP-Extensions: sockets required for communication with fluxd. fluxd cannot work without sockets.");
  2328. }
  2329. $retVal .= $sockets.'</li>';
  2330. //
  2331. $retVal .= "</ul>";
  2332. // PHP-Configuration
  2333. $retVal .= '<p><strong>3. PHP-Configuration</strong></p>';
  2334. $retVal .= "<ul>";
  2335. // safe_mode
  2336. $safe_mode = '<li>safe_mode ';
  2337. if ((ini_get("safe_mode")) == 0) {
  2338. $safe_mode .= '<font color="green">Passed</font>';
  2339. } else {
  2340. $safe_mode .= '<font color="red">Failed</font>';
  2341. $errors++;
  2342. array_push($errorsMessages, "PHP-Configuration: safe_mode must be turned off.");
  2343. }
  2344. $retVal .= $safe_mode.'</li>';
  2345. // allow_url_fopen
  2346. $allow_url_fopen = '<li>allow_url_fopen ';
  2347. if ((ini_get("allow_url_fopen")) == 1) {
  2348. $allow_url_fopen .= '<font color="green">Passed</font>';
  2349. } else {
  2350. $allow_url_fopen .= '<font color="red">Failed</font>';
  2351. array_push($warningsMessages, "PHP-Configuration: allow_url_fopen must be turned on. some features wont work if it is turned off.");
  2352. $warnings++;
  2353. }
  2354. $retVal .= $allow_url_fopen.'</li>';
  2355. // register_globals
  2356. $register_globals = '<li>register_globals ';
  2357. if ((ini_get("register_globals")) == 0) {
  2358. $register_globals .= '<font color="green">Passed</font>';
  2359. } else {
  2360. $register_globals .= '<font color="red">Failed</font>';
  2361. $errors++;
  2362. array_push($errorsMessages, "PHP-Configuration: register_globals must be turned off.");
  2363. }
  2364. $retVal .= $register_globals.'</li>';
  2365. //
  2366. $retVal .= "</ul>";
  2367. // PHP-Database-Support
  2368. $retVal .= '<p><strong>4. PHP-Database-Support</strong></p>';
  2369. $retVal .= "<ul>";
  2370. // define valid db-types
  2371. $databaseTypes = array();
  2372. $databaseTypes['mysql'] = 'mysql_connect';
  2373. $databaseTypes['mysqli'] = 'mysqli_connect';
  2374. $databaseTypes['sqlite'] = 'sqlite_open';
  2375. $databaseTypes['postgres'] = 'pg_connect';
  2376. // test db-types
  2377. foreach ($databaseTypes as $databaseTypeName => $databaseTypeFunction) {
  2378. $dbtest = '<li>'.$databaseTypeName.' ';
  2379. if (function_exists($databaseTypeFunction)) {
  2380. $dbtest .= '<font color="green">Passed</font>';
  2381. $dbsupported++;
  2382. } else {
  2383. $dbtest .= '<font color="red">Failed</font>';
  2384. }
  2385. $retVal .= $dbtest.'</li>';
  2386. }
  2387. $retVal .= "</ul>";
  2388. // db-state
  2389. if ($dbsupported == 0) {
  2390. $errors++;
  2391. array_push($errorsMessages, "PHP-Database-Support: no supported database-type found.");
  2392. }
  2393. // OS-Specific
  2394. // get os
  2395. $osString = php_uname('s');
  2396. if (isset($osString)) {
  2397. if (!(stristr($osString, 'linux') === false)) /* linux */
  2398. define('_OS', 1);
  2399. else if (!(stristr($osString, 'bsd') === false)) /* bsd */
  2400. define('_OS', 2);
  2401. else
  2402. define('_OS', 0);
  2403. } else {
  2404. define('_OS', 0);
  2405. }
  2406. $retVal .= '<p><strong>5. OS-Specific ('.$osString.' '.php_uname('r').')</strong></p>';
  2407. switch (_OS) {
  2408. case 1: // linux
  2409. $retVal .= 'No Special Requirements on Linux-OS. <font color="green">Passed</font>';
  2410. break;
  2411. case 2: // bsd
  2412. $retVal .= "<ul>";
  2413. // posix
  2414. $posix = '<li>posix ';
  2415. if ((function_exists('posix_geteuid')) && (function_exists('posix_getpwuid'))) {
  2416. $posix .= '<font color="green">Passed</font>';
  2417. } else {
  2418. $posix .= '<font color="red">Failed</font>';
  2419. $warnings++;
  2420. array_push($warningsMessages, "OS-Specific: PHP-extension posix missing. some netstat-features wont work without.");
  2421. }
  2422. $retVal .= $posix.'</li>';
  2423. $retVal .= "</ul>";
  2424. break;
  2425. case 0: // unknown
  2426. default:
  2427. $retVal .= "OS not supported.<br>";
  2428. $errors++;
  2429. array_push($errorsMessages, "OS-Specific: ".$osString." not supported.");
  2430. break;
  2431. }
  2432. // summary
  2433. $retVal .= '<p><strong>Summary</strong></p>';
  2434. // state
  2435. $state = "<strong>State: ";
  2436. if (($warnings + $errors) == 0) {
  2437. // good
  2438. $state .= '<font color="green">Ok</font>';
  2439. $state .= "</strong><br>";
  2440. $retVal .= $state;
  2441. $retVal .= "torrentflux-b4rt should run on this system.";
  2442. } else {
  2443. if (($errors == 0) && ($warnings > 0)) {
  2444. // may run with flaws
  2445. $state .= '<font color="orange">Warning</font>';
  2446. $state .= "</strong><br>";
  2447. $retVal .= $state;
  2448. $retVal .= "torrentflux-b4rt may run on this system, but there may be problems.";
  2449. } else {
  2450. // not ok
  2451. $state .= '<font color="red">Failed</font>';
  2452. $state .= "</strong><br>";
  2453. $retVal .= $state;
  2454. $retVal .= "torrentflux-b4rt cannot run on this system.";
  2455. }
  2456. }
  2457. // errors
  2458. if (count($errorsMessages) > 0) {
  2459. $retVal .= '<p><strong><font color="red">Errors: </font></strong><br>';
  2460. $retVal .= "<ul>";
  2461. foreach ($errorsMessages as $errorsMessage) {
  2462. $retVal .= "<li>".$errorsMessage."</li>";
  2463. }
  2464. $retVal .= "</ul>";
  2465. }
  2466. // warnings
  2467. if (count($warningsMessages) > 0) {
  2468. $retVal .= '<p><strong><font color="orange">Warnings: </font></strong><br>';
  2469. $retVal .= "<ul>";
  2470. foreach ($warningsMessages as $warningsMessage) {
  2471. $retVal .= "<li>".$warningsMessage."</li>";
  2472. }
  2473. $retVal .= "</ul>";
  2474. }
  2475. // return
  2476. return $retVal;
  2477. }
  2478. ?>