setup.php 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873
  1. <?php
  2. /* $Id: setup.php 3221 2007-09-17 18:16:32Z munk $ */
  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('_TITLE', _NAME.' '._VERSION.' - Setup');
  28. define('_DIR', dirname($_SERVER["SCRIPT_FILENAME"])."/");
  29. define('_FILE_DBCONF', 'inc/config/config.db.php');
  30. define('_FILE_THIS', $_SERVER['SCRIPT_NAME']);
  31. define('_FORUM_URL', "http://tf-b4rt.berlios.de/forum/");
  32. // Database-Types
  33. $databaseTypes = array();
  34. $databaseTypes['MySQL'] = 'mysql_connect';
  35. $databaseTypes['SQLite'] = 'sqlite_open';
  36. $databaseTypes['Postgres'] = 'pg_connect';
  37. // generic msg about db config missing:
  38. $msgDbConfigMissing = 'Database configuration file <em>'._DIR._FILE_DBCONF.'</em> missing. ';
  39. $msgDbConfigMissing .= 'Setup cannot continue. Please check the file exists and is readable by the webserver before continuing.';
  40. // init queries
  41. initQueries("install");
  42. // -----------------------------------------------------------------------------
  43. // Main
  44. // -----------------------------------------------------------------------------
  45. // ob-start
  46. if (@ob_get_level() == 0)
  47. @ob_start();
  48. if (isset($_REQUEST["1"])) { // 1 - Database
  49. sendHead(" - Database");
  50. send("<h1>"._TITLE."</h1>");
  51. send("<h2>Database</h2>");
  52. send("<p>In this section you will choose the type of database you wish to use with "._NAME.". You will then be prompted to provide the hostname, database name, username and password that "._NAME." will use to store information.</p>");
  53. send("<p>Finally "._NAME." will run some tests to check everything works OK and write the database and server configuration.</p>");
  54. send("<p>For more information and support with this installation, please feel free to visit <a href='"._FORUM_URL."'>the "._NAME." forum</a>.</p><br/>");
  55. send("<br/>");
  56. sendButton(11);
  57. } elseif (isset($_REQUEST["11"])) { // 11 - Database - type
  58. sendHead(" - Database");
  59. send("<h1>"._TITLE."</h1>");
  60. send("<h2>Database - Select Type of Database</h2>");
  61. send("<p>Please select the type of database you wish to use with your "._NAME." installation below:</p>");
  62. send('<form name="setup" action="' . _FILE_THIS . '" method="post">');
  63. send('<select name="db_type">');
  64. foreach ($databaseTypes as $databaseTypeName => $databaseTypeFunction) {
  65. $option = '<option value="'.$databaseTypeName.'"';
  66. if ((isset($_REQUEST["db_type"])) && ($_REQUEST["db_type"] == $databaseTypeName))
  67. $option .= ' selected';
  68. $option .= '>'.$databaseTypeName.'</option>';
  69. $option .= '</option>';
  70. send($option);
  71. }
  72. send('</select>');
  73. send('<p><strong>Note:</strong> if you do not see the type of database you wish to use, please visit <a href="'._FORUM_URL.'">the '._NAME.' forum</a> to find out about getting your database type added to '._NAME.'.</p>');
  74. send('<input type="Hidden" name="12" value="">');
  75. send('<input type="submit" value="Continue">');
  76. send('</form></p>');
  77. } elseif (isset($_REQUEST["12"])) { // 12 - Database - type check
  78. if ((isset($_REQUEST["db_type"])) && ($databaseTypes[$_REQUEST["db_type"]] != "")) {
  79. $type = $_REQUEST["db_type"];
  80. sendHead(" - Database");
  81. send("<h1>"._TITLE."</h1>");
  82. send("<h2>Database - Type Check</h2>");
  83. if (function_exists($databaseTypes[$type])) {
  84. $msg = "Your PHP installation supports ".$type;
  85. displaySetupMessage($msg, true);
  86. send("<br/>");
  87. send('<form name="setup" action="' . _FILE_THIS . '" method="post">');
  88. send('<input type="Hidden" name="db_type" value="'.$type.'">');
  89. send('<input type="Hidden" name="13" value="">');
  90. send('<input type="submit" value="Continue">');
  91. send('</form>');
  92. } else {
  93. $err='Your PHP installation does not have support for '.$type.' built into it. Please reinstall PHP and ensure support for your database is built in.</p>';
  94. displaySetupMessage($err, false);
  95. send("<br/>");
  96. send('<form name="setup" action="' . _FILE_THIS . '" method="post">');
  97. send('<input type="Hidden" name="11" value="">');
  98. send('<input type="submit" value="Back">');
  99. send('</form>');
  100. }
  101. } else {
  102. @header("location: setup.php?11");
  103. exit();
  104. }
  105. } elseif (isset($_REQUEST["13"])) { // 13 - Database - config
  106. $type = $_REQUEST["db_type"];
  107. sendHead(" - Database");
  108. send("<h1>"._TITLE."</h1>");
  109. send("<h2>Database - Config - ".$type."</h2>");
  110. send("<p>The installation will now configure and test your database settings.</p><br/>");
  111. send('<form name="setup" action="' . _FILE_THIS . '" method="post">');
  112. send('<table border="0">');
  113. // settings
  114. send('<tr><td colspan="2"><strong>Database Settings</strong></td></tr>');
  115. send('<tr><td colspan="2">Please enter your '.$type.' database settings below:</td></tr>');
  116. switch (strtolower($type)) {
  117. case "sqlite":
  118. // file
  119. $line = '<tr><td>Database-File : </td>';
  120. $line .= '<td><input name="db_host" type="Text" maxlength="254" size="40" value="';
  121. if (isset($_REQUEST["db_host"]))
  122. $line .= $_REQUEST["db_host"];
  123. $line .= '"></td></tr>';
  124. send($line);
  125. break;
  126. // MySQL and PostgreSQL have same data reqs, make it default case:
  127. case "mysql":
  128. case "postgres":
  129. default:
  130. // host
  131. $line = '<tr><td>Host : </td>';
  132. $line .= '<td><input name="db_host" type="Text" maxlength="254" size="40" value="';
  133. if (isset($_REQUEST["db_host"]))
  134. $line .= $_REQUEST["db_host"];
  135. else
  136. $line .= 'localhost';
  137. $line .= '"></td></tr>';
  138. send($line);
  139. // name
  140. $line = '<tr><td>Name : </td>';
  141. $line .= '<td><input name="db_name" type="Text" maxlength="254" size="40" value="';
  142. if (isset($_REQUEST["db_name"]))
  143. $line .= $_REQUEST["db_name"];
  144. else
  145. $line .= "torrentfluxb4rt";
  146. $line .= '"></td></tr>';
  147. send($line);
  148. // user
  149. $line = '<tr><td>Username : </td>';
  150. $line .= '<td><input name="db_user" type="Text" maxlength="254" size="40" value="';
  151. if (isset($_REQUEST["db_user"]))
  152. $line .= $_REQUEST["db_user"];
  153. else
  154. $line .= "torrentfluxb4rt";
  155. $line .= '"></td></tr>';
  156. send($line);
  157. // pass
  158. $line = '<tr><td>Password : </td>';
  159. $line .= '<td><input name="db_pass" type="Password" maxlength="254" size="40"';
  160. if (isset($_REQUEST["db_pass"]))
  161. $line .= ' value="'.$_REQUEST["db_pass"].'">';
  162. else
  163. $line .= '>';
  164. $line .= '</td></tr>';
  165. send($line);
  166. //
  167. break;
  168. }
  169. // create
  170. $line = '<tr><td>Create Database:</td>';
  171. $line .= '<td><input name="db_create" type="Checkbox" value="true" checked> <strong>Note:</strong> the next step will fail if the database already exists.';
  172. $line .= '</td></tr>';
  173. send($line);
  174. // pcon
  175. $line = '<tr><td>Use Persistent Connection:';
  176. $line .= '<td><input name="db_pcon" type="Checkbox" value="true"';
  177. if (isset($_REQUEST["db_pcon"]))
  178. $line .= ' checked">';
  179. else
  180. $line .= '>';
  181. $line .= ' <strong>Note:</strong> enabling persistent connections may help reduce the load on your database.</td></tr>';
  182. send($line);
  183. send('</table>');
  184. send("<br/>");
  185. send('<input type="Hidden" name="db_type" value="'.$type.'">');
  186. send('<input type="Hidden" name="14" value="">');
  187. send('<input type="submit" value="Continue">');
  188. send('</form>');
  189. } elseif (isset($_REQUEST["14"])) { // 14 - Database - creation + test
  190. $type = $_REQUEST["db_type"];
  191. sendHead(" - Database");
  192. send("<h1>"._TITLE."</h1>");
  193. send("<h2>Database - Creation + Test - ".$type."</h2>");
  194. $paramsOk = true;
  195. if (isset($_REQUEST["db_host"]))
  196. $host = $_REQUEST["db_host"];
  197. else
  198. $paramsOk = false;
  199. if (isset($_REQUEST["db_create"]))
  200. $create = true;
  201. else
  202. $create = false;
  203. if (isset($_REQUEST["db_pcon"]))
  204. $pcon = "true";
  205. else
  206. $pcon = "false";
  207. switch (strtolower($type)) {
  208. case "sqlite":
  209. $name = "";
  210. $user = "";
  211. $pass = "";
  212. break;
  213. case "mysql":
  214. case "postgres":
  215. default:
  216. if (!empty($_REQUEST["db_name"]))
  217. $name = stripslashes($_REQUEST["db_name"]);
  218. else
  219. $paramsOk = false;
  220. if (!empty($_REQUEST["db_user"]))
  221. $user = $_REQUEST["db_user"];
  222. else
  223. $paramsOk = false;
  224. if (!empty($_REQUEST["db_pass"]))
  225. $pass = $_REQUEST["db_pass"];
  226. else
  227. $paramsOk = false;
  228. }
  229. $databaseTestOk = false;
  230. $databaseError = "";
  231. // create + test
  232. if ($paramsOk) {
  233. send("<p>The installation will now try to connect to the database server, create a new database if applicable and run some tests to check we can create tables in the database.</p>");
  234. $databaseExists = true;
  235. if (($create) && (strtolower($type) != "sqlite")) {
  236. $dbCon = getAdoConnection($type, $host, $user, $pass);
  237. if (!$dbCon) {
  238. $databaseExists = false;
  239. $databaseTestOk = false;
  240. $databaseError = "Cannot connect to database. Check username, hostname and password?";
  241. } else {
  242. $sqlState = "CREATE DATABASE ";
  243. if ($type == "mysql")
  244. $sqlState .= "`".$name."`";
  245. else
  246. $sqlState .= $name;
  247. $dbCon->Execute($sqlState);
  248. send('<ul>');
  249. if ($dbCon->ErrorNo() == 0) {
  250. send('<li/><font color="green">Ok:</font> Created database <em>'.$name.'</em>');
  251. $databaseExists = true;
  252. } else { // damn there was an error
  253. send('<li/><font color="red">Error:</font> Could not create database <em>'.$name.'</em>');
  254. $databaseExists = false;
  255. $databaseTestOk = false;
  256. $databaseError = "Check the database <strong>$name</strong> does not exist already to perform this step.";
  257. }
  258. send('</ul>');
  259. // close ado-connection
  260. $dbCon->Close();
  261. }
  262. unset($dbCon);
  263. }
  264. if ($databaseExists) {
  265. $dbCon = getAdoConnection($type, $host, $user, $pass, $name);
  266. if (!$dbCon) {
  267. $databaseTestOk = false;
  268. $databaseError = "Cannot connect to database to perform query tests.";
  269. } else {
  270. $databaseTestCount = 0;
  271. send('<ul>');
  272. foreach ($queries['test'][strtolower($type)] as $databaseTypeName => $databaseQuery) {
  273. send('<li/>');
  274. $dbCon->Execute($databaseQuery);
  275. if ($dbCon->ErrorNo() == 0) {
  276. send('<font color="green">Query Ok:</font> '.$databaseQuery);
  277. $databaseTestCount++;
  278. } else { // damn there was an error
  279. send('<font color="red">Query Error:</font> '.$databaseQuery);
  280. // close ado-connection
  281. $dbCon->Close();
  282. break;
  283. }
  284. }
  285. if ($databaseTestCount == count($queries['test'][strtolower($type)])) {
  286. // close ado-connection
  287. $dbCon->Close();
  288. $databaseTestOk = true;
  289. } else {
  290. $databaseTestOk = false;
  291. }
  292. send('</ul>');
  293. }
  294. }
  295. } else {
  296. $databaseTestOk = false;
  297. $databaseError = "Problem found in configuration details supplied - please supply hostname, database name, username and password to continue.";
  298. }
  299. // output
  300. if ($databaseTestOk) {
  301. $msg = "Database creation and tests succeeded";
  302. displaySetupMessage($msg, true);
  303. send("<br/>");
  304. send("<h2>Next: Write Database Configuration File</h2>");
  305. send("Please ensure this script can write to the directory <em>"._DIR."inc/config/</em> before continuing.<p>");
  306. send('<form name="setup" action="' . _FILE_THIS . '" method="post">');
  307. send('<input type="Hidden" name="db_type" value="'.$type.'">');
  308. send('<input type="Hidden" name="db_host" value="'.$host.'">');
  309. send('<input type="Hidden" name="db_name" value="'.$name.'">');
  310. send('<input type="Hidden" name="db_user" value="'.$user.'">');
  311. send('<input type="Hidden" name="db_pass" value="'.$pass.'">');
  312. send('<input type="Hidden" name="db_pcon" value="'.$pcon.'">');
  313. send('<input type="Hidden" name="15" value="">');
  314. send('<input type="submit" value="Continue">');
  315. } else {
  316. displaySetupMessage($databaseError, false);
  317. send('<form name="setup" action="' . _FILE_THIS . '" method="post">');
  318. send('<input type="Hidden" name="db_type" value="'.$type.'">');
  319. send('<input type="Hidden" name="13" value="">');
  320. if (isset($_REQUEST["db_name"]))
  321. send('<input type="Hidden" name="db_host" value="'.$_REQUEST["db_host"].'">');
  322. if (isset($_REQUEST["db_name"]))
  323. send('<input type="Hidden" name="db_name" value="'.$_REQUEST["db_name"].'">');
  324. if (isset($_REQUEST["db_user"]))
  325. send('<input type="Hidden" name="db_user" value="'.$_REQUEST["db_user"].'">');
  326. if (isset($_REQUEST["db_pass"]))
  327. send('<input type="Hidden" name="db_pass" value="'.$_REQUEST["db_pass"].'">');
  328. if (isset($_REQUEST["db_pcon"]))
  329. send('<input type="Hidden" name="db_pcon" value="'.$_REQUEST["db_pcon"].'">');
  330. if (isset($_REQUEST["db_create"]))
  331. send('<input type="Hidden" name="db_create" value="'.$_REQUEST["db_create"].'">');
  332. send('<input type="submit" value="Back">');
  333. }
  334. send('</form>');
  335. } elseif (isset($_REQUEST["15"])) { // 15 - Database - config-file
  336. sendHead(" - Database");
  337. send("<h1>"._TITLE."</h1>");
  338. send("<h2>Database - Config-File</h2>");
  339. send("<p>The installation will now attempt to write the database configuration file to "._DIR._FILE_DBCONF.".</p>");
  340. $type = $_REQUEST["db_type"];
  341. $host = $_REQUEST["db_host"];
  342. $name = $_REQUEST["db_name"];
  343. $user = $_REQUEST["db_user"];
  344. $pass = $_REQUEST["db_pass"];
  345. $pcon = $_REQUEST["db_pcon"];
  346. // write file
  347. $databaseConfWriteOk = false;
  348. $databaseConfWriteError = "";
  349. $databaseConfContent = "";
  350. writeDatabaseConfig($type, $host, $user, $pass, $name, $pcon);
  351. // output
  352. if ($databaseConfWriteOk) {
  353. $msg = 'Database configuration file <em>'._DIR._FILE_DBCONF.'</em> written.';
  354. displaySetupMessage($msg, true);
  355. } else {
  356. displaySetupMessage($databaseConfWriteError, false);
  357. send("<br/>");
  358. send('<p>To perform this step manually please paste the following content to the database configuration file <em>'._DIR._FILE_DBCONF.'</em> and ensure the file is readable by the user the webserver runs as:</p>');
  359. send('<textarea cols="81" rows="33">'.$databaseConfContent.'</textarea>');
  360. send("<p><strong>Note:</strong> You must write this file before you can continue!</p>");
  361. }
  362. send("<br/>");
  363. send("<h2>Next : Create Tables</h2>");
  364. sendButton(16);
  365. } elseif (isset($_REQUEST["16"])) { // 16 - Database - table-creation
  366. sendHead(" - Database");
  367. send("<h1>"._TITLE."</h1>");
  368. send("<h2>Database - Create Tables</h2>");
  369. send("<p>The installation will now attempt to create the database tables required for running "._NAME.".</p>");
  370. if (is_file(_FILE_DBCONF)) {
  371. require_once(_FILE_DBCONF);
  372. $databaseTableCreationCount = 0;
  373. $databaseTableCreation = false;
  374. $databaseError = "";
  375. $dbCon = getAdoConnection($cfg["db_type"], $cfg["db_host"], $cfg["db_user"], $cfg["db_pass"], $cfg["db_name"]);
  376. if (!$dbCon) {
  377. $databaseTableCreation = false;
  378. $databaseError = "Cannot connect to database.";
  379. } else {
  380. send('<ul>');
  381. foreach ($queries['create'][$cfg["db_type"]] as $databaseTypeName => $databaseQuery) {
  382. send('<li/>');
  383. $dbCon->Execute($databaseQuery);
  384. if ($dbCon->ErrorNo() == 0) {
  385. send('<font color="green">Query Ok:</font> <em>'.$databaseQuery.'</em>');
  386. $databaseTableCreationCount++;
  387. } else { // damn there was an error
  388. send('<font color="red">Query Error:</font> <em>'.$databaseQuery.'</em>');
  389. $databaseError = "Could not create tables. Note that the database must be empty to perform this step.";
  390. // close ado-connection
  391. $dbCon->Close();
  392. break;
  393. }
  394. }
  395. if ($databaseTableCreationCount == count($queries['create'][$cfg["db_type"]])) {
  396. // close ado-connection
  397. $dbCon->Close();
  398. $databaseTableCreation = true;
  399. } else {
  400. $databaseTableCreation = false;
  401. }
  402. send('</ul>');
  403. }
  404. if ($databaseTableCreation) {
  405. $msg = $databaseTableCreationCount.' tables created';
  406. displaySetupMessage($msg, true);
  407. send("<br/>");
  408. send("<h2>Next: Insert Data Into Database</h2>");
  409. sendButton(17);
  410. } else {
  411. displaySetupMessage($databaseError, false);
  412. }
  413. } else {
  414. displaySetupMessage($msgDbConfigMissing, false);
  415. }
  416. } elseif (isset($_REQUEST["17"])) { // 17 - Database - data
  417. sendHead(" - Database");
  418. send("<h1>"._TITLE."</h1>");
  419. send("<h2>Database - Insert Data Into Database</h2>");
  420. send("<p>The installation will now attempt to insert all the data required for the system into the database.</p>");
  421. if (is_file(_FILE_DBCONF)) {
  422. require_once(_FILE_DBCONF);
  423. $databaseDataCount = 0;
  424. $databaseData = false;
  425. $databaseError = "";
  426. $dbCon = getAdoConnection($cfg["db_type"], $cfg["db_host"], $cfg["db_user"], $cfg["db_pass"], $cfg["db_name"]);
  427. if (!$dbCon) {
  428. $databaseData = false;
  429. $databaseError = "cannot connect to database.";
  430. } else {
  431. send('<ul>');
  432. foreach ($queries['data'][$cfg["db_type"]] as $databaseTypeName => $databaseQuery) {
  433. send('<li/>');
  434. $dbCon->Execute($databaseQuery);
  435. if ($dbCon->ErrorNo() == 0) {
  436. send('<font color="green">Query Ok:</font> '.$databaseQuery);
  437. $databaseDataCount++;
  438. } else { // damn there was an error
  439. send('<font color="red">Query Error:</font> '.$databaseQuery);
  440. $databaseError = "Could not import data into database. Database tables must be empty before performing this step.";
  441. // close ado-connection
  442. $dbCon->Close();
  443. break;
  444. }
  445. }
  446. if ($databaseDataCount == count($queries['data'][$cfg["db_type"]])) {
  447. // close ado-connection
  448. $dbCon->Close();
  449. $databaseData = true;
  450. } else {
  451. $databaseData = false;
  452. }
  453. send('</ul>');
  454. }
  455. if ($databaseData) {
  456. $msg = $databaseDataCount.' queries executed.';
  457. displaySetupMessage($msg, true);
  458. send("<br/>");
  459. send("<h2>Next: Server Configuration</h2>");
  460. sendButton(2);
  461. } else {
  462. displaySetupMessage($databaseError, false);
  463. }
  464. } else {
  465. displaySetupMessage($err, false);
  466. }
  467. } elseif (isset($_REQUEST["2"])) { // 2 - Configuration
  468. sendHead(" - Configuration");
  469. send("<h1>"._TITLE."</h1>");
  470. send("<h2>Server Configuration</h2>");
  471. send("<p>The installation will now continue to prompt you for some basic settings required to get "._NAME." running.</p>");
  472. send("<br/>");
  473. send("<h2>Next : Server Settings</h2>");
  474. sendButton(21);
  475. } elseif (isset($_REQUEST["21"])) { // 21 - Configuration - Server Settings input
  476. sendHead(" - Configuration");
  477. send("<h1>"._TITLE."</h1>");
  478. send("<h2>Configuration - Server Settings</h2>");
  479. if (is_file(_FILE_DBCONF)) {
  480. require_once(_FILE_DBCONF);
  481. $dbCon = getAdoConnection($cfg["db_type"], $cfg["db_host"], $cfg["db_user"], $cfg["db_pass"], $cfg["db_name"]);
  482. if (!$dbCon) {
  483. $err = "cannot connect to database.";
  484. } else {
  485. $tf_settings = loadSettings("tf_settings");
  486. // close ado-connection
  487. $dbCon->Close();
  488. if ($tf_settings !== false) {
  489. send("<p>Please enter the path to the directory you want "._NAME." to save your user downloads into below.</p>");
  490. send("<p><strong>Important:</strong> this path <b>must</b> be writable by the webserver user</p>");
  491. send('<form name="setup" action="' . _FILE_THIS . '" method="post">');
  492. send('<table border="0">');
  493. // path
  494. $line = '<tr><td width="200"><strong>User Download Path:</strong></td>';
  495. $line .= '<td><input name="path" type="Text" maxlength="254" size="40" value="';
  496. if (!empty($_REQUEST["path"]))
  497. $line .= $_REQUEST["path"];
  498. else
  499. $line .= $tf_settings["path"];
  500. $line .= '"></td></tr>';
  501. $line .= '<tr><td>&nbsp;</td><td width="400"><strong>Note:</strong> this is what you may know as "path" (or "downloads") ';
  502. $line .= 'from TF 2.1 and TF 2.1-b4rt - the parent directory where home directories will ';
  503. $line .= 'be created and transfers will be downloaded to.</td></tr>';
  504. send($line);
  505. send('</table>');
  506. // docroot
  507. if (isset($_REQUEST["docroot"]))
  508. send('<input type="Hidden" name="docroot" value="'.$_REQUEST["docroot"].'">');
  509. else
  510. send('<input type="Hidden" name="docroot" value="'.getcwd().'">');
  511. send('<input type="Hidden" name="22" value="">');
  512. send('<input type="submit" value="Continue">');
  513. send('</form>');
  514. } else {
  515. $err = "error loading settings.";
  516. displaySetupMessage($err, false);
  517. }
  518. }
  519. } else {
  520. displaySetupMessage($msgDbConfigMissing, false);
  521. }
  522. } elseif (isset($_REQUEST["22"])) { // 22 - Configuration - Server Settings validate
  523. sendHead(" - Configuration");
  524. send("<h1>"._TITLE."</h1>");
  525. send("<h2>Configuration - Server Settings Validation</h2>");
  526. $serverSettingsTestCtr = 0;
  527. $serverSettingsTestError = "";
  528. $pathExists = false;
  529. $path = $_REQUEST["path"];
  530. if(empty($path)){
  531. $serverSettingsTestError = "user download path cannot be empty, please supply the full path to the directory.";
  532. } elseif (((strlen($path) > 0)) && (substr($path, -1 ) != "/")){
  533. $path .= "/";
  534. }
  535. $docroot = $_REQUEST["docroot"];
  536. if (((strlen($docroot) > 0)) && (substr($docroot, -1 ) != "/"))
  537. $docroot .= "/";
  538. // Only go here if no error already:
  539. if(empty($serverSettingsTestEror)){
  540. // path
  541. if (!(@is_dir($path) === true)) {
  542. // dir doesn't exist, try to create
  543. if (!((@mkdir($path, 0777)) === true))
  544. $serverSettingsTestError .= "path <em>".$path."</em> does not exist and cannot be created. Check that the path is writable by the webserver user.";
  545. else
  546. $pathExists = true;
  547. } else {
  548. $pathExists = true;
  549. }
  550. if ($pathExists) {
  551. if (!(@is_writable($path) === true))
  552. $serverSettingsTestError .= "path <em>".$path."</em> is not writable. Check that the path is writable by the webserver user.";
  553. else
  554. $serverSettingsTestCtr++;
  555. }
  556. // docroot
  557. if (is_file($docroot."version.php"))
  558. $serverSettingsTestCtr++;
  559. else
  560. $serverSettingsTestError .= "docroot <em>".$docroot."</em> is not valid.";
  561. }
  562. // output
  563. if ($serverSettingsTestCtr == 2) {
  564. $msg = "User download directory set to: <em>".$path."</em>";
  565. displaySetupMessage($msg, true);
  566. $msg = "Document root directory set to: <em>".$docroot."</em>";
  567. displaySetupMessage($msg, true);
  568. send("<br/>");
  569. send("<h2>Next: Check For Third Party Utilities</h2>");
  570. send('<form name="setup" action="' . _FILE_THIS . '" method="post">');
  571. send('<input type="Hidden" name="path" value="'.$path.'">');
  572. send('<input type="Hidden" name="docroot" value="'.$docroot.'">');
  573. send('<input type="Hidden" name="221" value="">');
  574. send('<input type="submit" value="Continue">');
  575. } else {
  576. displaySetupMessage($serverSettingsTestError, false);
  577. send("<br/>");
  578. send('<form name="setup" action="' . _FILE_THIS . '" method="post">');
  579. send('<input type="Hidden" name="path" value="'.$path.'">');
  580. send('<input type="Hidden" name="docroot" value="'.$docroot.'">');
  581. send('<input type="Hidden" name="21" value="">');
  582. send('<input type="submit" value="Back">');
  583. }
  584. send('</form>');
  585. } elseif (isset($_REQUEST["221"])) {
  586. $OS = strtolower(exec("uname"));
  587. // Check for system tools like grep, awk, netstat, rar, etc:
  588. sendHead(" - Configuration");
  589. send("<h1>"._TITLE."</h1>");
  590. send("<h2>Configuration - Check System Tools</h2>");
  591. send("<p>The installation will now check to locate the system tools required for operating "._NAME." smoothly.</p><br/>");
  592. $line = '<table border="1" cellspacing="0">';
  593. $line .= '<tr style="font-weight:bold"><td>Tool Name</td><td>Path</td><td width="400">Info</td></td></tr>';
  594. if (is_file(_FILE_DBCONF)) {
  595. require_once(_FILE_DBCONF);
  596. $databaseError = "";
  597. $dbCon = getAdoConnection($cfg["db_type"], $cfg["db_host"], $cfg["db_user"], $cfg["db_pass"], $cfg["db_name"]);
  598. if (!$dbCon) {
  599. $databaseError = "cannot connect to database.";
  600. // stop:
  601. displaySetupMessage($databaseError, false);
  602. } else {
  603. // extra non-standard binary paths to check installed binaries:
  604. $binPaths = array(
  605. // FreeBSD:
  606. '/usr/local/bin',
  607. '/usr/local/sbin',
  608. // NetBSD:
  609. '/usr/pkgsrc/bin',
  610. '/usr/pkgsrc/sbin',
  611. // OpenBSD (same as fbsd?):
  612. // Solaris (unsure):
  613. // AN other:
  614. );
  615. // Array of binaries => default binary paths:
  616. $bins = array(
  617. 'grep' => '/bin/grep',
  618. 'netstat' => '/bin/netstat',
  619. 'php' => '/usr/bin/php',
  620. 'awk' => '/usr/bin/awk',
  621. 'du' => '/usr/bin/du',
  622. 'wget' => '/usr/bin/wget',
  623. 'unrar' => '/usr/bin/unrar',
  624. 'unzip' => '/usr/bin/unzip',
  625. 'cksfv' => '/usr/bin/cksfv',
  626. 'sockstat' => '/usr/bin/sockstat',
  627. 'vlc' => '/usr/local/bin/vlc',
  628. 'uudeview' => '/usr/local/bin/uudeview'
  629. );
  630. $pathErrCount = 0;
  631. foreach ($bins as $bin => $path){
  632. if($OS == "linux" && $bin == "sockstat"){
  633. continue;
  634. }
  635. $foundPath = "";
  636. $isExe = false;
  637. $line .= '<tr valign="top"><td>'.$bin.'</td><td>';
  638. // see if which finds this binary:
  639. $foundPath = trim(exec(escapeshellcmd("which $bin")));
  640. if(empty($foundPath)){
  641. // OK no bin found, let's check the non-standard paths:
  642. foreach ($binPaths as $extraPath){
  643. $thisBin = $extraPath."/".$bin;
  644. if( is_file($thisBin) ){
  645. // Yay, found the file:
  646. $foundPath = $thisBin;
  647. // Check executable bit:
  648. if ( is_executable($foundPath) ){
  649. $isExe = true;
  650. // Done with this exe, move onto next:
  651. break;
  652. }
  653. }
  654. }
  655. } else {
  656. // Check is exe:
  657. if(is_executable($foundPath)){
  658. $isExe = true;
  659. }
  660. }
  661. if(!empty($foundPath)){
  662. $line .= $foundPath.'</td><td>Path found Ok. ';
  663. if(!$isExe){
  664. $line .= '<font color="red">Error: binary '.$foundPath.' is NOT executable. Ensure webserver user can execute this binary before continuing.</font>';
  665. } else {
  666. $line .= $foundPath.' is executable.';
  667. }
  668. // Update path for this binary:
  669. $databaseQuery = "UPDATE tf_settings SET tf_value='$foundPath' WHERE tf_key='bin_$bin'";
  670. $dbCon->Execute($databaseQuery);
  671. if ($dbCon->ErrorNo() != 0) {
  672. // Problem with query:
  673. $line .= "<br/><br/>Error executing query:<br/><strong>$databaseQuery</strong>";
  674. }
  675. } else {
  676. // Didn't find this binary, let the user know:
  677. $line .= '<font color="red">NOT FOUND</font></td>';
  678. $line .= '<td><font color="orange">Warning: could not find <strong>'.$bin.'</strong> on your system. Default path <strong>'.$path.'</strong> used.</font>';
  679. $pathErrCount++;
  680. }
  681. $line .= "</td></tr>";
  682. }
  683. $line .="</table>";
  684. if($pathErrCount > 0){
  685. $line .= "<br/><p><strong>Important:</strong><br/>There were problems locating the paths to some tools on your server. ";
  686. $line .= "Depending on which tools they were, some features may not work as expected.</p><p>After installation, check that the tools reported as <font color=\"red\">NOT FOUND</font> above are installed correctly and modify your installation settings to reflect the path of the problematic tools. You can do this by clicking on the 'Admin' link at the top right of the "._NAME." page and then selecting the 'Server Settings' tab.</p>";
  687. }
  688. send($line);
  689. send("<br/>");
  690. send('<form name="setup" action="' . _FILE_THIS . '" method="post">');
  691. send('<input type="Hidden" name="path" value="'.$_REQUEST["path"].'">');
  692. send('<input type="Hidden" name="docroot" value="'.$_REQUEST["docroot"].'">');
  693. send('<input type="Hidden" name="23" value="">');
  694. send("<br/>");
  695. send("<h2>Next: Server Settings Save</h2>");
  696. send('<input type="submit" value="Continue">');
  697. send('</form>');
  698. }
  699. } else {
  700. // stop:
  701. displaySetupMessage($msgDbConfigMissing, false);
  702. }
  703. } elseif (isset($_REQUEST["23"])) { // 23 - Configuration - Server Settings save
  704. sendHead(" - Configuration");
  705. send("<h1>"._TITLE."</h1>");
  706. send("<h2>Configuration - Server Settings Save</h2>");
  707. $path = $_REQUEST["path"];
  708. $docroot = $_REQUEST["docroot"];
  709. if (is_file(_FILE_DBCONF)) {
  710. require_once(_FILE_DBCONF);
  711. $dbCon = getAdoConnection($cfg["db_type"], $cfg["db_host"], $cfg["db_user"], $cfg["db_pass"], $cfg["db_name"]);
  712. if (!$dbCon) {
  713. $err = "cannot connect to database. Check database settings in "._FILE_DBCONF;
  714. displaySetupMessage($err);
  715. } else {
  716. $settingsSaveCtr = 0;
  717. if (updateSetting("tf_settings", "path", $path) === true)
  718. $settingsSaveCtr++;
  719. if (updateSetting("tf_settings", "docroot", $docroot) === true)
  720. $settingsSaveCtr++;
  721. if ($settingsSaveCtr == 2) {
  722. $msg = 'Server settings saved to database.';
  723. displaySetupMessage($msg, true);
  724. send("<br/>");
  725. send("<h2>Next: Installation End</h2>");
  726. sendButton(3);
  727. } else {
  728. $err = 'could not save path and docroot server settings to database.';
  729. displaySetupMessage($err, false);
  730. send("<br/>");
  731. send('<form name="setup" action="' . _FILE_THIS . '" method="post">');
  732. send('<input type="Hidden" name="path" value="'.$path.'">');
  733. send('<input type="Hidden" name="docroot" value="'.$docroot.'">');
  734. send('<input type="Hidden" name="21" value="">');
  735. send('<input type="submit" value="Back">');
  736. send('</form>');
  737. }
  738. // close ado-connection
  739. $dbCon->Close();
  740. }
  741. } else {
  742. displaySetupMessage($msgDbConfigMissing, false);
  743. }
  744. } elseif (isset($_REQUEST["3"])) { // 3 - End
  745. sendHead(" - End");
  746. send("<h1>"._TITLE."</h1>");
  747. send("<h2>Setup Completed</h2>");
  748. send("<p>Congratulations! "._NAME." has successfully been installed.</p>");
  749. if ((substr(_VERSION, 0, 3)) != "svn") {
  750. $result = @unlink(__FILE__);
  751. if ($result !== true) {
  752. $err = 'Could not delete '.__FILE__.'. Please delete the file manually.';
  753. $err .= '<strong>Important:</strong> '._NAME.' will not run until this file is deleted for security reasons!';
  754. displaySetupMessage($err, false);
  755. } else {
  756. $msg = 'Deleted '.__FILE__.' successfully.';
  757. displaySetupMessage($msg, true);
  758. send("<br/>");
  759. send("<h2>Next: Login</h2>");
  760. send("<p>To continue on to the "._NAME." login screen, click the button below:</p>");
  761. send('<form name="setup" action="login.php" method="post">');
  762. send('<input type="submit" value="Continue">');
  763. send('</form>');
  764. }
  765. } else {
  766. $msg = '<font color="blue">This is an svn-version. '.__FILE__.' is untouched. Please remove the file manually to login to your '._NAME.' installation.</font>';
  767. displaySetupMessage($msg, true);
  768. }
  769. send("<p><strong>Important:</strong><br/>When logging in for the first time <strong>the login username and password you supply there will create the default superadmin user for your "._NAME." installation.</strong> For this reason it is important you do this immediately and remember the username and password!!!</p>");
  770. } else { // default
  771. sendHead();
  772. if (is_file(_FILE_DBCONF))
  773. send('<p><br><font color="red"><h1>db-config already exists ('._FILE_DBCONF.')</h1></font>Delete setup.php if you came here after finishing setup to proceed to login.</p><hr>');
  774. send("<h1>"._TITLE."</h1>");
  775. send("<p>Welcome to the installation script for ". _NAME.". In the following pages you will be guided through the steps necessary to get your installation of "._NAME." up and running, including database configuration and initial "._NAME." system configuration file creation.</p>");
  776. send("<br/>");
  777. send("<h2>Next: Database</h2>");
  778. sendButton(1);
  779. }
  780. // foot
  781. sendFoot();
  782. // ob-end + exit
  783. @ob_end_flush();
  784. exit();
  785. ?>