upgrade.php 26 KB

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