upgrade.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729
  1. <?php
  2. /* $Id: upgrade.php 2292 2007-01-20 18:22:34Z b4rt $ */
  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. // version
  16. if (is_file('version.php'))
  17. require_once('version.php');
  18. else
  19. die("Fatal Error. version.php is missing.");
  20. // install-functions
  21. if ((@is_file('inc/install/functions.install.php')) === true)
  22. require_once('inc/install/functions.install.php');
  23. else
  24. die("Fatal Error. inc/install/functions.install.php is missing.");
  25. // defines
  26. define('_NAME', 'torrentflux-b4rt');
  27. define('_UPGRADE_FROM', 'v94');
  28. define('_UPGRADE_TO', '1.0');
  29. define('_DEFAULT_PATH', '/usr/local/torrent/');
  30. define('_TITLE', _NAME.' '._VERSION.' - Upgrade '._UPGRADE_FROM.' to '._UPGRADE_TO);
  31. define('_DIR', dirname($_SERVER["SCRIPT_FILENAME"])."/");
  32. define('_FILE_DBCONF', 'inc/config/config.db.php');
  33. define('_FILE_THIS', $_SERVER['SCRIPT_NAME']);
  34. // Database-Types
  35. $databaseTypes = array();
  36. $databaseTypes['mysql'] = 'mysql_connect';
  37. $databaseTypes['sqlite'] = 'sqlite_open';
  38. // init queries
  39. initQueries("upgrade", _UPGRADE_FROM);
  40. // -----------------------------------------------------------------------------
  41. // Main
  42. // -----------------------------------------------------------------------------
  43. // ob-start
  44. if (@ob_get_level() == 0)
  45. @ob_start();
  46. if (isset($_REQUEST["1"])) { // 1 - Database
  47. sendHead(" - Database");
  48. send("<h1>"._TITLE."</h1>");
  49. send("<h2>Database</h2>");
  50. sendButton(11);
  51. } elseif (isset($_REQUEST["11"])) { // 11 - Database - type
  52. sendHead(" - Database");
  53. send("<h1>"._TITLE."</h1>");
  54. send("<h2>Database - Type</h2>");
  55. send('<form name="setup" action="' . _FILE_THIS . '" method="post">');
  56. send('<select name="db_type">');
  57. foreach ($databaseTypes as $databaseTypeName => $databaseTypeFunction) {
  58. $option = '<option value="'.$databaseTypeName.'"';
  59. if ((isset($_REQUEST["db_type"])) && ($_REQUEST["db_type"] == $databaseTypeName))
  60. $option .= ' selected';
  61. $option .= '>'.$databaseTypeName.'</option>';
  62. $option .= '</option>';
  63. send($option);
  64. }
  65. send('</select>');
  66. send('<input type="Hidden" name="12" value="">');
  67. send('<input type="submit" value="Continue">');
  68. send('</form>');
  69. } elseif (isset($_REQUEST["12"])) { // 12 - Database - type check
  70. if ((isset($_REQUEST["db_type"])) && ($databaseTypes[$_REQUEST["db_type"]] != "")) {
  71. $type = $_REQUEST["db_type"];
  72. sendHead(" - Database");
  73. send("<h1>"._TITLE."</h1>");
  74. send("<h2>Database - Type Check</h2>");
  75. if (function_exists($databaseTypes[$type])) {
  76. send('<font color="green"><strong>Ok</strong></font><br>');
  77. send('This PHP does support <em>'.$type.'</em>.<p>');
  78. send('<form name="setup" action="' . _FILE_THIS . '" method="post">');
  79. send('<input type="Hidden" name="db_type" value="'.$type.'">');
  80. send('<input type="Hidden" name="13" value="">');
  81. send('<input type="submit" value="Continue">');
  82. send('</form>');
  83. } else {
  84. send('<font color="red"><strong>Error</strong></font><br>');
  85. send('This PHP does not support <em>'.$type.'</em>.<p>');
  86. send('<form name="setup" action="' . _FILE_THIS . '" method="post">');
  87. send('<input type="Hidden" name="11" value="">');
  88. send('<input type="submit" value="Back">');
  89. send('</form>');
  90. }
  91. } else {
  92. header("location: setup.php?11");
  93. exit();
  94. }
  95. } elseif (isset($_REQUEST["13"])) { // 13 - Database - config
  96. $type = $_REQUEST["db_type"];
  97. sendHead(" - Database");
  98. send("<h1>"._TITLE."</h1>");
  99. send("<h2>Database - Config - ".$type."</h2>");
  100. send('<form name="setup" action="' . _FILE_THIS . '" method="post">');
  101. send('<table border="0">');
  102. // settings
  103. send('<tr><td colspan="2"><strong>Database Settings : </strong></td></tr>');
  104. switch ($type) {
  105. case "mysql":
  106. // host
  107. $line = '<tr><td>Host : </td>';
  108. $line .= '<td><input name="db_host" type="Text" maxlength="254" size="40" value="';
  109. if (isset($_REQUEST["db_host"]))
  110. $line .= $_REQUEST["db_host"];
  111. else
  112. $line .= 'localhost';
  113. $line .= '"></td></tr>';
  114. send($line);
  115. // name
  116. $line = '<tr><td>Name : </td>';
  117. $line .= '<td><input name="db_name" type="Text" maxlength="254" size="40" value="';
  118. if (isset($_REQUEST["db_name"]))
  119. $line .= $_REQUEST["db_name"];
  120. else
  121. $line .= 'torrentflux';
  122. $line .= '"></td></tr>';
  123. send($line);
  124. // user
  125. $line = '<tr><td>Username : </td>';
  126. $line .= '<td><input name="db_user" type="Text" maxlength="254" size="40" value="';
  127. if (isset($_REQUEST["db_user"]))
  128. $line .= $_REQUEST["db_user"];
  129. else
  130. $line .= 'root';
  131. $line .= '"></td></tr>';
  132. send($line);
  133. // pass
  134. $line = '<tr><td>Password : </td>';
  135. $line .= '<td><input name="db_pass" type="Password" maxlength="254" size="40"';
  136. if (isset($_REQUEST["db_pass"]))
  137. $line .= ' value="'.$_REQUEST["db_pass"].'">';
  138. else
  139. $line .= '>';
  140. $line .= '</td></tr>';
  141. send($line);
  142. //
  143. break;
  144. case "sqlite":
  145. // file
  146. $line = '<tr><td>Database-File : </td>';
  147. $line .= '<td><input name="db_host" type="Text" maxlength="254" size="40" value="';
  148. if (isset($_REQUEST["db_host"]))
  149. $line .= $_REQUEST["db_host"];
  150. $line .= '"></td></tr>';
  151. send($line);
  152. }
  153. // pcon
  154. $line = '<tr><td colspan="2">Persistent Connection :';
  155. $line .= '<input name="db_pcon" type="Checkbox" value="true"';
  156. if (isset($_REQUEST["db_pcon"]))
  157. $line .= ' checked">';
  158. else
  159. $line .= '>';
  160. $line .= '</td></tr>';
  161. send($line);
  162. send('</table>');
  163. send('<input type="Hidden" name="db_type" value="'.$type.'">');
  164. send('<input type="Hidden" name="14" value="">');
  165. send('<input type="submit" value="Continue">');
  166. send('</form>');
  167. } elseif (isset($_REQUEST["14"])) { // 14 - Database - test
  168. $type = $_REQUEST["db_type"];
  169. sendHead(" - Database");
  170. send("<h1>"._TITLE."</h1>");
  171. send("<h2>Database - Test - ".$type."</h2>");
  172. $paramsOk = true;
  173. if (isset($_REQUEST["db_host"]))
  174. $host = $_REQUEST["db_host"];
  175. else
  176. $paramsOk = false;
  177. if (isset($_REQUEST["db_pcon"]))
  178. $pcon = "true";
  179. else
  180. $pcon = "false";
  181. switch ($type) {
  182. case "mysql":
  183. if (isset($_REQUEST["db_name"]))
  184. $name = $_REQUEST["db_name"];
  185. else
  186. $paramsOk = false;
  187. if (isset($_REQUEST["db_user"]))
  188. $user = $_REQUEST["db_user"];
  189. else
  190. $paramsOk = false;
  191. if (isset($_REQUEST["db_pass"]))
  192. $pass = $_REQUEST["db_pass"];
  193. else
  194. $paramsOk = false;
  195. break;
  196. case "sqlite":
  197. $name = "";
  198. $user = "";
  199. $pass = "";
  200. }
  201. $databaseTestOk = false;
  202. $databaseError = "";
  203. // test
  204. if ($paramsOk) {
  205. $dbCon = getAdoConnection($type, $host, $user, $pass, $name);
  206. if (!$dbCon) {
  207. $databaseTestOk = false;
  208. $databaseError = "cannot connect to database.";
  209. } else {
  210. send('<ul>');
  211. $databaseTestCount = 0;
  212. foreach ($queries['test'][$type] as $databaseTypeName => $databaseQuery) {
  213. send('<li><em>'.$databaseQuery.'</em> : ');
  214. $dbCon->Execute($databaseQuery);
  215. if ($dbCon->ErrorNo() == 0) {
  216. send('<font color="green">Ok</font></li>');
  217. $databaseTestCount++;
  218. } else { // damn there was an error
  219. send('<font color="red">Error</font></li>');
  220. // close ado-connection
  221. $dbCon->Close();
  222. break;
  223. }
  224. }
  225. if ($databaseTestCount == count($queries['test'][$type])) {
  226. $databaseTestOk = true;
  227. } else {
  228. $databaseTestOk = false;
  229. }
  230. send('</ul>');
  231. }
  232. } else {
  233. $databaseTestOk = false;
  234. $databaseError = "config error.";
  235. }
  236. // output
  237. if ($databaseTestOk) {
  238. // load path
  239. $tf_settings = loadSettings("tf_settings");
  240. if ($tf_settings !== false) {
  241. $oldpath = $tf_settings["path"];
  242. if (((strlen($oldpath) > 0)) && (substr($oldpath, -1 ) != "/"))
  243. $oldpath .= "/";
  244. } else {
  245. $oldpath = _DEFAULT_PATH;
  246. }
  247. // close ado-connection
  248. $dbCon->Close();
  249. send('<font color="green"><strong>Ok</strong></font><br>');
  250. send("<h2>Next : Write Config File</h2>");
  251. send("Please ensure this script can write to the dir <em>"._DIR."inc/config/</em><p>");
  252. send('<form name="setup" action="' . _FILE_THIS . '" method="post">');
  253. send('<input type="Hidden" name="oldpath" value="'.$oldpath.'">');
  254. send('<input type="Hidden" name="db_type" value="'.$type.'">');
  255. send('<input type="Hidden" name="db_host" value="'.$host.'">');
  256. send('<input type="Hidden" name="db_name" value="'.$name.'">');
  257. send('<input type="Hidden" name="db_user" value="'.$user.'">');
  258. send('<input type="Hidden" name="db_pass" value="'.$pass.'">');
  259. send('<input type="Hidden" name="db_pcon" value="'.$pcon.'">');
  260. send('<input type="Hidden" name="15" value="">');
  261. send('<input type="submit" value="Continue">');
  262. } else {
  263. send('<font color="red"><strong>Error</strong></font><br>');
  264. send($databaseError."<p>");
  265. send('<form name="setup" action="' . _FILE_THIS . '" method="post">');
  266. send('<input type="Hidden" name="db_type" value="'.$type.'">');
  267. send('<input type="Hidden" name="13" value="">');
  268. if (isset($_REQUEST["db_name"]))
  269. send('<input type="Hidden" name="db_host" value="'.$_REQUEST["db_host"].'">');
  270. if (isset($_REQUEST["db_name"]))
  271. send('<input type="Hidden" name="db_name" value="'.$_REQUEST["db_name"].'">');
  272. if (isset($_REQUEST["db_user"]))
  273. send('<input type="Hidden" name="db_user" value="'.$_REQUEST["db_user"].'">');
  274. if (isset($_REQUEST["db_pass"]))
  275. send('<input type="Hidden" name="db_pass" value="'.$_REQUEST["db_pass"].'">');
  276. if (isset($_REQUEST["db_pcon"]))
  277. send('<input type="Hidden" name="db_pcon" value="'.$_REQUEST["db_pcon"].'">');
  278. send('<input type="submit" value="Back">');
  279. }
  280. send('</form>');
  281. } elseif (isset($_REQUEST["15"])) { // 15 - Database - config-file
  282. sendHead(" - Database");
  283. send("<h1>"._TITLE."</h1>");
  284. send("<h2>Database - Config-File</h2>");
  285. $oldpath = $_REQUEST["oldpath"];
  286. $type = $_REQUEST["db_type"];
  287. $host = $_REQUEST["db_host"];
  288. $name = $_REQUEST["db_name"];
  289. $user = $_REQUEST["db_user"];
  290. $pass = $_REQUEST["db_pass"];
  291. $pcon = $_REQUEST["db_pcon"];
  292. // write file
  293. $databaseConfWriteOk = false;
  294. $databaseConfWriteError = "";
  295. $databaseConfContent = "";
  296. writeDatabaseConfig($type, $host, $user, $pass, $name, $pcon);
  297. // output
  298. if ($databaseConfWriteOk) {
  299. send('<font color="green"><strong>Ok</strong></font><br>');
  300. send('database-config-file <em>'._DIR._FILE_DBCONF.'</em> written.');
  301. } else {
  302. send('<font color="red"><strong>Error</strong></font><br>');
  303. send($databaseConfWriteError."<p>");
  304. send('to perform this step manual paste the following content to the database-config-file <em>'._DIR._FILE_DBCONF.'</em> : <p>');
  305. send('<textarea cols="81" rows="33">'.$databaseConfContent.'</textarea>');
  306. send("<p>Note : You must write this file before you can continue !");
  307. }
  308. send("<h2>Next : Create/Alter Tables</h2>");
  309. send('<form name="setup" action="' . _FILE_THIS . '" method="post">');
  310. send('<input type="Hidden" name="oldpath" value="'.$oldpath.'">');
  311. send('<input type="Hidden" name="16" value="">');
  312. send('<input type="submit" value="Continue">');
  313. send('</form>');
  314. } elseif (isset($_REQUEST["16"])) { // 16 - Database - table-creation
  315. sendHead(" - Database");
  316. send("<h1>"._TITLE."</h1>");
  317. send("<h2>Database - Create/Alter Tables</h2>");
  318. $oldpath = $_REQUEST["oldpath"];
  319. if (is_file(_FILE_DBCONF)) {
  320. require_once(_FILE_DBCONF);
  321. $databaseTableCreationCount = 0;
  322. $databaseTableCreation = false;
  323. $databaseError = "";
  324. $dbCon = getAdoConnection($cfg["db_type"], $cfg["db_host"], $cfg["db_user"], $cfg["db_pass"], $cfg["db_name"]);
  325. if (!$dbCon) {
  326. $databaseTableCreation = false;
  327. $databaseError = "cannot connect to database.";
  328. } else {
  329. send('<ul>');
  330. foreach ($queries['create'][$cfg["db_type"]] as $databaseTypeName => $databaseQuery) {
  331. send('<li><em>'.$databaseQuery.'</em> : ');
  332. $dbCon->Execute($databaseQuery);
  333. if ($dbCon->ErrorNo() == 0) {
  334. send('<font color="green">Ok</font></li>');
  335. $databaseTableCreationCount++;
  336. } else { // damn there was an error
  337. send('<font color="red">Error</font></li>');
  338. $databaseError = "error creating tables.";
  339. // close ado-connection
  340. $dbCon->Close();
  341. break;
  342. }
  343. }
  344. if ($databaseTableCreationCount == count($queries['create'][$cfg["db_type"]])) {
  345. // close ado-connection
  346. $dbCon->Close();
  347. $databaseTableCreation = true;
  348. } else {
  349. $databaseTableCreation = false;
  350. }
  351. send('</ul>');
  352. }
  353. if ($databaseTableCreation) {
  354. send('<font color="green"><strong>Ok</strong></font><br>');
  355. send($databaseTableCreationCount.' queries executed.');
  356. send("<h2>Next : Data</h2>");
  357. send('<form name="setup" action="' . _FILE_THIS . '" method="post">');
  358. send('<input type="Hidden" name="oldpath" value="'.$oldpath.'">');
  359. send('<input type="Hidden" name="17" value="">');
  360. send('<input type="submit" value="Continue">');
  361. send('</form>');
  362. } else {
  363. send('<font color="red"><strong>Error</strong></font><br>');
  364. send($databaseError."<p>");
  365. }
  366. } else {
  367. send('<font color="red"><strong>Error</strong></font><br>');
  368. send('database-config-file <em>'._DIR._FILE_DBCONF.'</em> missing. setup cannot continue.');
  369. }
  370. } elseif (isset($_REQUEST["17"])) { // 17 - Database - data
  371. sendHead(" - Database");
  372. send("<h1>"._TITLE."</h1>");
  373. send("<h2>Database - Data</h2>");
  374. $oldpath = $_REQUEST["oldpath"];
  375. if (is_file(_FILE_DBCONF)) {
  376. require_once(_FILE_DBCONF);
  377. $databaseDataCount = 0;
  378. $databaseData = false;
  379. $databaseError = "";
  380. $dbCon = getAdoConnection($cfg["db_type"], $cfg["db_host"], $cfg["db_user"], $cfg["db_pass"], $cfg["db_name"]);
  381. if (!$dbCon) {
  382. $databaseData = false;
  383. $databaseError = "cannot connect to database.";
  384. } else {
  385. send('<ul>');
  386. // add path
  387. array_unshift($queries['data'][$cfg["db_type"]], "INSERT INTO tf_settings VALUES ('path','".$oldpath."')");
  388. // add delete-state
  389. array_unshift($queries['data'][$cfg["db_type"]], "DELETE FROM tf_settings");
  390. // exec
  391. foreach ($queries['data'][$cfg["db_type"]] as $databaseTypeName => $databaseQuery) {
  392. send('<li><em>'.$databaseQuery.'</em> : ');
  393. $dbCon->Execute($databaseQuery);
  394. if ($dbCon->ErrorNo() == 0) {
  395. send('<font color="green">Ok</font></li>');
  396. $databaseDataCount++;
  397. } else { // damn there was an error
  398. send('<font color="red">Error</font></li>');
  399. $databaseError = "error importing data.";
  400. // close ado-connection
  401. $dbCon->Close();
  402. break;
  403. }
  404. }
  405. if ($databaseDataCount == count($queries['data'][$cfg["db_type"]])) {
  406. // close ado-connection
  407. $dbCon->Close();
  408. $databaseData = true;
  409. } else {
  410. $databaseData = false;
  411. }
  412. send('</ul>');
  413. }
  414. if ($databaseData) {
  415. send('<font color="green"><strong>Ok</strong></font><br>');
  416. send($databaseDataCount.' queries executed.');
  417. send("<h2>Next : Configuration</h2>");
  418. sendButton(2);
  419. } else {
  420. send('<font color="red"><strong>Error</strong></font><br>');
  421. send($databaseError."<p>");
  422. }
  423. } else {
  424. send('<font color="red"><strong>Error</strong></font><br>');
  425. send('database-config-file <em>'._DIR._FILE_DBCONF.'</em> missing. setup cannot continue.');
  426. }
  427. } elseif (isset($_REQUEST["2"])) { // 2 - Configuration
  428. sendHead(" - Configuration");
  429. send("<h1>"._TITLE."</h1>");
  430. send("<h2>Configuration</h2>");
  431. send("<h2>Next : Server Settings</h2>");
  432. sendButton(21);
  433. send('</form>');
  434. } elseif (isset($_REQUEST["21"])) { // 21 - Configuration - Server Settings input
  435. sendHead(" - Configuration");
  436. send("<h1>"._TITLE."</h1>");
  437. send("<h2>Configuration - Server Settings</h2>");
  438. if (is_file(_FILE_DBCONF)) {
  439. require_once(_FILE_DBCONF);
  440. $dbCon = getAdoConnection($cfg["db_type"], $cfg["db_host"], $cfg["db_user"], $cfg["db_pass"], $cfg["db_name"]);
  441. if (!$dbCon) {
  442. send('<font color="red"><strong>Error</strong></font><br>');
  443. send("cannot connect to database.<p>");
  444. } else {
  445. $tf_settings = loadSettings("tf_settings");
  446. // close ado-connection
  447. $dbCon->Close();
  448. if ($tf_settings !== false) {
  449. send('<form name="setup" action="' . _FILE_THIS . '" method="post">');
  450. send('<table border="0">');
  451. // docroot
  452. /*
  453. $line = '<tr><td>docroot : </td>';
  454. $line .= '<td><input name="docroot" type="Text" maxlength="254" size="40" value="';
  455. if (isset($_REQUEST["docroot"]))
  456. $line .= $_REQUEST["docroot"];
  457. else
  458. $line .= _DIR;
  459. $line .= '"></td></tr>';
  460. send($line);
  461. */
  462. send('</table>');
  463. // docroot
  464. if (isset($_REQUEST["docroot"]))
  465. send('<input type="Hidden" name="docroot" value="'.$_REQUEST["docroot"].'">');
  466. else
  467. send('<input type="Hidden" name="docroot" value="'.getcwd().'">');
  468. send('<input type="Hidden" name="22" value="">');
  469. send('<input type="submit" value="Continue">');
  470. send('</form>');
  471. } else {
  472. send('<font color="red"><strong>Error</strong></font><br>');
  473. send("error loading settings.<p>");
  474. }
  475. }
  476. } else {
  477. send('<font color="red"><strong>Error</strong></font><br>');
  478. send('database-config-file <em>'._DIR._FILE_DBCONF.'</em> missing. setup cannot continue.');
  479. }
  480. } elseif (isset($_REQUEST["22"])) { // 22 - Configuration - Server Settings validate
  481. sendHead(" - Configuration");
  482. send("<h1>"._TITLE."</h1>");
  483. send("<h2>Configuration - Server Settings Validation</h2>");
  484. $docroot = $_REQUEST["docroot"];
  485. if (((strlen($docroot) > 0)) && (substr($docroot, -1 ) != "/"))
  486. $docroot .= "/";
  487. $serverSettingsTestCtr = 0;
  488. $serverSettingsTestError = "";
  489. // docroot
  490. if (is_file($docroot."version.php"))
  491. $serverSettingsTestCtr++;
  492. else
  493. $serverSettingsTestError .= "docroot <em>".$docroot."</em> is not valid.";
  494. // output
  495. if ($serverSettingsTestCtr == 1) {
  496. send('<font color="green"><strong>Ok</strong></font><br>');
  497. send("docroot : <em>".$docroot."</em><br>");
  498. send("<h2>Next : Save Server Settings</h2>");
  499. send('<form name="setup" action="' . _FILE_THIS . '" method="post">');
  500. send('<input type="Hidden" name="docroot" value="'.$docroot.'">');
  501. send('<input type="Hidden" name="23" value="">');
  502. send('<input type="submit" value="Continue">');
  503. } else {
  504. send('<font color="red"><strong>Error</strong></font><br>');
  505. send($serverSettingsTestError."<p>");
  506. send('<form name="setup" action="' . _FILE_THIS . '" method="post">');
  507. send('<input type="Hidden" name="docroot" value="'.$docroot.'">');
  508. send('<input type="Hidden" name="21" value="">');
  509. send('<input type="submit" value="Back">');
  510. }
  511. send('</form>');
  512. } elseif (isset($_REQUEST["23"])) { // 23 - Configuration - Server Settings save
  513. sendHead(" - Configuration");
  514. send("<h1>"._TITLE."</h1>");
  515. send("<h2>Configuration - Server Settings Save</h2>");
  516. $docroot = $_REQUEST["docroot"];
  517. if (is_file(_FILE_DBCONF)) {
  518. require_once(_FILE_DBCONF);
  519. $dbCon = getAdoConnection($cfg["db_type"], $cfg["db_host"], $cfg["db_user"], $cfg["db_pass"], $cfg["db_name"]);
  520. if (!$dbCon) {
  521. send('<font color="red"><strong>Error</strong></font><br>');
  522. send("cannot connect to database.<p>");
  523. } else {
  524. $settingsSaveCtr = 0;
  525. if (updateSetting("tf_settings", "docroot", $docroot) === true)
  526. $settingsSaveCtr++;
  527. if ($settingsSaveCtr == 1) {
  528. send('<font color="green"><strong>Ok</strong></font><br>');
  529. send('Server Settings saved.');
  530. send("<h2>Next : Rename Files and Dirs</h2>");
  531. sendButton(3);
  532. } else {
  533. send('<font color="red"><strong>Error</strong></font><br>');
  534. send('could not save Server Settings.');
  535. send('<form name="setup" action="' . _FILE_THIS . '" method="post">');
  536. send('<input type="Hidden" name="docroot" value="'.$docroot.'">');
  537. send('<input type="Hidden" name="21" value="">');
  538. send('<input type="submit" value="Back">');
  539. send('</form>');
  540. }
  541. // close ado-connection
  542. $dbCon->Close();
  543. }
  544. } else {
  545. send('<font color="red"><strong>Error</strong></font><br>');
  546. send('database-config-file <em>'._DIR._FILE_DBCONF.'</em> missing. setup cannot continue.');
  547. }
  548. } elseif (isset($_REQUEST["3"])) { // 3 - rename files and dirs
  549. sendHead(" - Rename Files and Dirs");
  550. send("<h1>"._TITLE."</h1>");
  551. send("<h2>Rename Files and Dirs</h2>");
  552. if (is_file(_FILE_DBCONF)) {
  553. require_once(_FILE_DBCONF);
  554. $dbCon = getAdoConnection($cfg["db_type"], $cfg["db_host"], $cfg["db_user"], $cfg["db_pass"], $cfg["db_name"]);
  555. if (!$dbCon) {
  556. send('<font color="red"><strong>Error</strong></font><br>');
  557. send("cannot connect to database.<p>");
  558. } else {
  559. $tf_settings = loadSettings("tf_settings");
  560. // close ado-connection
  561. $dbCon->Close();
  562. if ($tf_settings !== false) {
  563. $path = $tf_settings["path"];
  564. $pathExists = false;
  565. $renameOk = false;
  566. $allDone = true;
  567. if ((@is_dir($path) === true) && (@is_dir($path.".torrents") === true)) {
  568. $pathExists = true;
  569. send('<ul>');
  570. // transfers-dir
  571. send('<li><em>'.$path.".torrents -> ".$path.".transfers".'</em> : ');
  572. $renameOk = rename($path.".torrents", $path.".transfers");
  573. if ($renameOk === true) {
  574. send('<font color="green">Ok</font></li>');
  575. } else {
  576. $allDone = false;
  577. send('<font color="red">Error</font></li>');
  578. }
  579. // old queue-dir
  580. if ($renameOk) {
  581. if (@is_dir($path.".transfers/queue")) {
  582. $files = array();
  583. if ($dirHandle = opendir($path.".transfers/queue")) {
  584. while (false !== ($file = readdir($dirHandle))) {
  585. if ((strlen($file) > 4) && ((substr($file, -4)) == "stat"))
  586. array_push($files, $file);
  587. }
  588. closedir($dirHandle);
  589. }
  590. $filesCount = count($files);
  591. $filesCtr = 0;
  592. if ($filesCount > 0) {
  593. foreach ($files as $file) {
  594. $fileSource = $path.".transfers/queue/".$file;
  595. send('<li>delete : <em>'.$fileSource.'</em> : ');
  596. $fileUnlinkOk = @unlink($fileSource);
  597. if ($fileUnlinkOk === true) {
  598. $filesCtr++;
  599. send('<font color="green">Ok</font></li>');
  600. } else {
  601. send('<font color="red">Error</font></li>');
  602. }
  603. }
  604. if ($filesCount != $filesCtr)
  605. $allDone = false;
  606. }
  607. send('<li>delete : <em>'.$path.".transfers/queue".'</em> : ');
  608. $rmdirOk = @rmdir($path.".transfers/queue");
  609. if ($rmdirOk === true) {
  610. send('<font color="green">Ok</font></li>');
  611. } else {
  612. $allDone = false;
  613. send('<font color="red">Error</font></li>');
  614. }
  615. }
  616. }
  617. // transfer-files (should not be here anymore if transfers
  618. // were deleted like required and written in the docu)
  619. if ($renameOk) {
  620. $fileTypes = array(".torrent", ".stat", ".pid", ".prio", ".url");
  621. $files = array();
  622. if ($dirHandle = opendir($path.".transfers")) {
  623. while (false !== ($file = readdir($dirHandle))) {
  624. $stringLength = strlen($file);
  625. foreach ($fileTypes as $ftype) {
  626. $extLength = strlen($ftype);
  627. $extIndex = 0 - $extLength;
  628. if (($stringLength > $extLength) && (strtolower(substr($file, $extIndex)) === ($ftype)))
  629. array_push($files, $file);
  630. }
  631. }
  632. closedir($dirHandle);
  633. }
  634. $filesCount = count($files);
  635. $filesCtr = 0;
  636. if ($filesCount > 0) {
  637. foreach ($files as $file) {
  638. $fileSource = $path.".transfers/".$file;
  639. send('<li>delete : <em>'.$fileSource.'</em> : ');
  640. $fileUnlinkOk = @unlink($fileSource);
  641. if ($fileUnlinkOk === true) {
  642. $filesCtr++;
  643. send('<font color="green">Ok</font></li>');
  644. } else {
  645. send('<font color="red">Error</font></li>');
  646. }
  647. }
  648. if ($filesCount != $filesCtr)
  649. $allDone = false;
  650. }
  651. }
  652. send('</ul>');
  653. if ($allDone) {
  654. send('<font color="green"><strong>Ok</strong></font><br>');
  655. send('Files and Dirs renamed.');
  656. send("<h2>Next : End</h2>");
  657. sendButton(4);
  658. } else { // damn there was an error
  659. send('<font color="red">Error</font></li>');
  660. send("error renaming Files and Dirs. you have to re-inject all torrents.<p>");
  661. }
  662. } else {
  663. send('<font color="red">Error</font></li>');
  664. send("path <em>".$path.".torrents</em> does not exist. you have to re-inject all torrents.<p>");
  665. }
  666. } else {
  667. send('<font color="red"><strong>Error</strong></font><br>');
  668. send("error loading settings.<p>");
  669. }
  670. }
  671. } else {
  672. send('<font color="red"><strong>Error</strong></font><br>');
  673. send('database-config-file <em>'._DIR._FILE_DBCONF.'</em> missing. setup cannot continue.');
  674. }
  675. } elseif (isset($_REQUEST["4"])) { // 4 - End
  676. sendHead(" - End");
  677. send("<h1>"._TITLE."</h1>");
  678. send("<h2>End</h2>");
  679. send("<p>Upgrade completed.</p>");
  680. if ((substr(_VERSION, 0, 3)) != "svn") {
  681. $result = @unlink(__FILE__);
  682. if ($result !== true)
  683. send('<p><font color="red">Could not delete '.__FILE__.'</font><br>Please delete the file manual.</p>');
  684. else
  685. send('<p><font color="green">Deleted '.__FILE__.'</font></p>');
  686. } else {
  687. send('<p><font color="blue">This is a svn-version. '.__FILE__.' is untouched.</font></p>');
  688. }
  689. send("<h2>Next : Login</h2>");
  690. send('<form name="setup" action="login.php" method="post">');
  691. send('<input type="submit" value="Continue">');
  692. send('</form>');
  693. } else { // default
  694. sendHead();
  695. if (is_file(_FILE_DBCONF))
  696. send('<p><br><font color="red"><h1>db-config already exists ('._FILE_DBCONF.')</h1></font>Delete upgrade.php if you came here after finishing upgrade to proceed to login.</p><hr>');
  697. send("<h1>"._TITLE."</h1>");
  698. send("<p>This script will upgrade "._NAME." from "._UPGRADE_FROM." to "._UPGRADE_TO."</p>");
  699. send("<h2>Next : Database</h2>");
  700. sendButton(1);
  701. }
  702. // foot
  703. sendFoot();
  704. // ob-end + exit
  705. @ob_end_flush();
  706. exit();
  707. ?>