install.php

  1. 7.x install.php
  2. 6.x install.php
  3. 4.x install.php
  4. 5.x install.php

This is the initial installation file for FlightPath.

This script will handle the initial installation of FlightPath, which entails creating its database tables and settings.php file.

File

install.php
View source
  1. <?php
  2. /**
  3. * @file
  4. * This is the initial installation file for FlightPath.
  5. *
  6. * This script will handle the initial installation of FlightPath, which
  7. * entails creating its database tables and settings.php file.
  8. */
  9. // Set the PHP error reporting level for FlightPath. In this case,
  10. // only show us errors and warnings. (Hide "notice" and "strict" messages)
  11. error_reporting(E_ERROR | E_CORE_ERROR | E_COMPILE_ERROR | E_WARNING);
  12. session_start();
  13. header("Cache-control: private");
  14. // Load our bootstrap (skipping over loads we don't need)
  15. $skip_flightpath_settings = TRUE;
  16. $skip_flightpath_modules = TRUE;
  17. require("bootstrap.inc");
  18. // Load needed modules
  19. require_once("modules/system/system.module");
  20. // Check here to see if FlightPath has already been installed.
  21. // We will do this by simply looking for the settings.php file.
  22. if (file_exists("custom/settings.php")) {
  23. die("FlightPath has already been installed. If you wish to re-install FlightPath,
  24. DELETE the custom/settings.php file, and drop all of the tables in FlightPath's
  25. database.");
  26. }
  27. /*
  28. * To begin setting up FlightPath, the user must have completed
  29. * two other steps-- select language, and pass the requirements
  30. * check.
  31. */
  32. $lang = $_REQUEST["lang"];
  33. if ($lang == "") {
  34. install_display_lang_selection();
  35. die;
  36. }
  37. // If we made it here, the language must have been set. So,
  38. // now check the requirements, and display the results if there
  39. // are any.
  40. if ($req_array = install_check_requirements()) {
  41. install_display_requirements($req_array);
  42. die;
  43. }
  44. if ($_REQUEST["perform_action"] != "install") {
  45. // If we made it this far, it means we have no unfulfilled requirements.
  46. // Let's go ahead and ask the user for their database information.
  47. install_display_db_form();
  48. die;
  49. }
  50. else {
  51. // We ARE trying to install. Let's give it a go!
  52. install_perform_install();
  53. die;
  54. }
  55. die;
  56. /**
  57. * Actually performs the installation of FlightPath
  58. */
  59. function install_perform_install() {
  60. global $user;
  61. if (!isset($user)) {
  62. $user = new stdClass();
  63. }
  64. $user->id = 1; // set to admin during install
  65. $db_name = trim($_POST["db_name"]);
  66. $db_host = trim($_POST["db_host"]);
  67. $db_port = trim($_POST["db_port"]);
  68. $db_user = trim($_POST["db_user"]);
  69. $db_pass = trim($_POST["db_pass"]);
  70. $admin_pass = trim($_POST["admin_pass"]);
  71. $admin_pass2 = trim($_POST["admin_pass2"]);
  72. $admin_name = trim($_POST["admin_name"]);
  73. if (strlen($admin_name) < 3) {
  74. return install_display_db_form("<font color='red'>" . st("Please select another
  75. username for Admin (ex: admin)
  76. which is at least 3 characters long.") . "</font>");
  77. }
  78. if (strlen($admin_pass) < 5) {
  79. return install_display_db_form("<font color='red'>" . st("Admin password must be at least 5 characters long.") . "</font>");
  80. }
  81. if ($admin_pass != $admin_pass2) {
  82. return install_display_db_form("<font color='red'>" . st("You must enter the same Admin password for both the
  83. 'Admin Password' field and the 'Re-enter Password'
  84. field.") . "</font>");
  85. }
  86. // Place into settings so our installation procedures will work.
  87. $GLOBALS["fp_system_settings"]["db_host"] = $db_host . ':' . $db_port;
  88. $GLOBALS["fp_system_settings"]["db_user"] = $db_user;
  89. $GLOBALS["fp_system_settings"]["db_pass"] = $db_pass;
  90. $GLOBALS["fp_system_settings"]["db_name"] = $db_name;
  91. // Make sure admin information is OK.
  92. // We will attempt to connect to this database. If we have any problems, we will go back to
  93. // the form and inform the user.
  94. if (!@mysql_connect ($db_host . ':' . $db_port, $db_user, $db_pass)) {
  95. return install_display_db_form("<font color='red'>" . st("Could not connect. Please check that you have
  96. created the database already, and given the user all of the permissions
  97. (except Grant). Then, make sure you typed the username and
  98. password correctly.") . "</font>");
  99. }
  100. if (!@mysql_select_db ($db_name)) {
  101. return install_display_db_form("<font color='red'>" . st("Could not connect to the database name you specified.
  102. Please check that you have
  103. created the database already, and given the user all of the permissions
  104. (except Grant). Possibly check that the database name is correct.") . "</font>");
  105. }
  106. ///////////////////////////////
  107. // If we have made it here, then we have been provided valid database credentials.
  108. // Let's write out our settings.php file.
  109. $settings_template = trim(install_get_settings_file_template());
  110. // Add in our replacements
  111. $settings_template = str_replace("%DB_HOST%", $db_host, $settings_template);
  112. $settings_template = str_replace("%DB_PORT%", $db_port, $settings_template);
  113. $settings_template = str_replace("%DB_NAME%", $db_name, $settings_template);
  114. $settings_template = str_replace("%DB_USER%", $db_user, $settings_template);
  115. $settings_template = str_replace("%DB_PASS%", $db_pass, $settings_template);
  116. $settings_template = str_replace("%CRON_SECURITY_TOKEN%", md5(time()), $settings_template);
  117. // Attempt to figure out the file_system_path based on __FILE__
  118. $file_system_path = str_replace("install.php", "", __FILE__);
  119. // Convert \ to / in the file system path.
  120. $file_system_path = str_replace("\\", "/", $file_system_path);
  121. // Get rid of the last character, which should be a / at this point.
  122. $file_system_path = substr($file_system_path, 0, -1);
  123. $settings_template = str_replace("%FILE_SYSTEM_PATH%", $file_system_path, $settings_template);
  124. // Attempt to figure out the base URL.
  125. $protocol = strpos(strtolower($_SERVER['SERVER_PROTOCOL']),'https') === FALSE ? 'http' : 'https';
  126. $host = $_SERVER['HTTP_HOST'];
  127. $script = $_SERVER['SCRIPT_NAME'];
  128. $base_url = $protocol . "://" . $host . $script;
  129. $base_url = str_replace("/install.php", "", $base_url);
  130. $settings_template = str_replace("%BASE_URL%", $base_url, $settings_template);
  131. // Figure out the base_path and add it in.
  132. $base_path = str_replace($protocol . "://" . $host, "", $base_url);
  133. $settings_template = str_replace("%BASE_PATH%", $base_path, $settings_template);
  134. // Okay, we have completed all the changes to the settings template string, we can
  135. // write it out to a file now.
  136. if (!file_put_contents("custom/settings.php", $settings_template)) {
  137. die("There was an error trying to write out the /custom/settings.php file. Please
  138. make sure the /custom directory is writable to the webserver.");
  139. }
  140. ///////////////////////////////////
  141. // Okay, we have just written out our settings.php file.
  142. // We now need to install our database. We will do this by
  143. // running the system module's hook_install, as it contains all
  144. // of our various tables needed to run FlightPath.
  145. include_once("modules/system/system.install");
  146. $GLOBALS["fp_die_mysql_errors"] = TRUE;
  147. // call system_install() to perform our numerous DB table creations.
  148. system_install();
  149. // With db tables created, let's include our settings file so we can get some
  150. // important GLOBAL variables set up.
  151. include("custom/settings.php");
  152. // Re-establish DatabaseHandler object connection since we just re-loaded the settings file.
  153. $temp_db = new DatabaseHandler();
  154. // Add the admin user to the newly-created users table and the "faculty" table.
  155. db_query("INSERT INTO users (user_id, user_name, cwid, password, is_faculty, f_name, l_name)
  156. VALUES ('1', '?', '1', '?', '1', 'Admin', 'User') ", $admin_name, md5($admin_pass));
  157. db_query("INSERT INTO faculty (cwid) VALUES ('1') ");
  158. // Having made it here, we now need to call system_enable,
  159. // which will in turn enable all of the other modules which
  160. // we will need to have, as well as other database changes.
  161. system_enable();
  162. // Now that we have enabled all of the modules (and made other database changes)
  163. // let's re-include the bootstrap file, which will re-init our GLOBAL settings,
  164. // as well as load all of our new modules.
  165. $skip_flightpath_settings = FALSE;
  166. $skip_flightpath_modules = FALSE;
  167. include("bootstrap.inc");
  168. // Re-establish DatabaseHandler object connection since we just re-loaded the settings file.
  169. $temp_db = new DatabaseHandler();
  170. /////////////////////////
  171. // Now, we need to clear our caches and re-build the menu router.
  172. fp_clear_cache();
  173. // wipe out the SESSION to remove any extraneous messages.
  174. session_destroy();
  175. // Okay, now we are done!
  176. // let's re-direct to a new page.
  177. fp_goto("install-finished");
  178. }
  179. /**
  180. * Returns a template for a new settings file.
  181. *
  182. * The only role of this function is to provide a settings
  183. * template, with replacement patterns which we will use to create
  184. * a new settings.php file.
  185. */
  186. function install_get_settings_file_template() {
  187. return '
  188. <?php
  189. /**
  190. * @file
  191. * The settings file for FlightPath, containing database and other settings.
  192. *
  193. * Once you have made changes to this file, it would be best to change
  194. * the permissions to "read-only" to prevent unauthorized users
  195. * from altering it.
  196. */
  197. // Set the PHP error reporting level for FlightPath. In this case,
  198. // only show us errors and warnings. (Hide "notice" and "strict" messages)
  199. error_reporting(E_ERROR | E_CORE_ERROR | E_COMPILE_ERROR | E_WARNING);
  200. // Set the PHP max time limit which any one page is allowed to take up while
  201. // running. The default is 30 seconds. Change this value (or remove it)
  202. // as needed.
  203. set_time_limit(300); // 300 seconds = 5 minutes.
  204. /**
  205. * All system settings will be placed (at the end of this script)
  206. * into a $GLOBALS variable, but for now will be placed into an
  207. * array.
  208. */
  209. $system_settings = array();
  210. ////////////////////////////////////
  211. // !!! *** IMPORTANT !!! *** //
  212. ////////////////////////////////////
  213. // If this variable is set to TRUE, then anyone who attempts to log in
  214. // will have full, admin access.
  215. // Only set this to TRUE when you are first installing FlightPath.
  216. // Otherwise, leave it set to FALSE!
  217. $system_settings["GRANT_FULL_ACCESS"] = FALSE;
  218. ////////////////////////////////////
  219. // This should be the actual filesystem path to the directory
  220. // where FlightPath is installed. Do NOT include a trailing slash!
  221. // Ex: /var/www/public_html/flightpath or, for Windows: C:/htdocs/flightpath
  222. // ** Depending on your webserver, you may be required to use forward-slashes! **
  223. // use the following line to help you figure out the fileSystemPath, by seeing
  224. // what the path is to this file:
  225. // print "<br>System path to settings.php: " . __FILE__ . "<br><br>";
  226. $system_settings["file_system_path"] = "%FILE_SYSTEM_PATH%";
  227. // The base URL is the actual URL a user would type to visit your site.
  228. // Do NOT enter a trailing slash!
  229. // Ex: http://localhost/flightpath
  230. $system_settings["base_url"] = "%BASE_URL%";
  231. // The basePath is related to the baseURL. It is the part of the URL which comes after
  232. // your domain name.
  233. // It MUST begin with a preceeding slash.
  234. // Ex: If your site is example.com/dev/flightpath, then you should
  235. // enter "/dev/flightpath"
  236. $system_settings["base_path"] = "%BASE_PATH%";
  237. ////////////////////////////////////
  238. // *** Database-related settings ***
  239. ////////////////////////////////////
  240. $system_settings["db_host"] = "%DB_HOST%:%DB_PORT%"; // domain/ip address of the mysql host. ex: localhost or mysite.com:32145
  241. $system_settings["db_user"] = "%DB_USER%";
  242. $system_settings["db_pass"] = "%DB_PASS%";
  243. $system_settings["db_name"] = "%DB_NAME%"; // Name of the actual database where
  244. // flightpath\'s tables are located.
  245. // Usually just "flightpath"
  246. /////////////////////////////////////
  247. // *** Defaults *** //
  248. /////////////////////////////////////
  249. // These default settings are for installation reasons only.
  250. // They will be overwritten in memory
  251. // once the flightpath_system_settings table is read in at the end of the file.
  252. // Do not alter them.
  253. $system_settings["display_mysql_errors"] = TRUE;
  254. $system_settings["theme"] = "themes/classic";
  255. ////////////////////////////////////
  256. // *** Misc Settings ***
  257. ////////////////////////////////////
  258. // To cut down on load times when the user loads a large elective group
  259. // containing many courses, FlightPath can load some of the course inventory
  260. // upon login. Set the number of courses to load here.
  261. $system_settings["load_course_inventory_on_login_number"] = 2000;
  262. ////////////////////////////////////
  263. // *** Cron-related ***
  264. ////////////////////////////////////
  265. // If you wish to use cron.php (which will call every module\'s
  266. // hook_cron() function), you may set up a cron job like this:
  267. // php cron.php security_token_string
  268. // SecurityToken: This is something which
  269. // must be the first argument passed to cron.php. It can be any continuous
  270. // string of *alpha-numeric* characters.
  271. // This is a security measure to prevent unauthorized users (or web-users) from
  272. // running cron.php, and is REQUIRED!
  273. // For example, if the token is "qwss34frwquu" then to run the script you would need
  274. // to use: http://url/cron.php?t=CRON_TOKEN (use wget to access from a system cron job.)
  275. $system_settings["cron_security_token"] = "%CRON_SECURITY_TOKEN%";
  276. /////////////////////////////////////
  277. /////////////////////////////////////
  278. //
  279. // The end of the settings file!
  280. /////////////////////////////////////
  281. /////////////////////////////////////
  282. /////////////////////////////////////
  283. // Do not alter or remove!!
  284. // This will load the contents of the flightpath_system_settings
  285. // table into the $system_settings variable. These are extra settings
  286. // which were set via the web using the system module.
  287. $db_host = $system_settings["db_host"];
  288. $db_user = $system_settings["db_user"];
  289. $db_pass = $system_settings["db_pass"];
  290. $db_name = $system_settings["db_name"];
  291. $dbc = mysql_connect ($db_host, $db_user, $db_pass) or die("Could not connect to database: " . mysql_error());
  292. mysql_select_db ($db_name);
  293. $res = mysql_query("SELECT * FROM variables");
  294. while ($cur = mysql_fetch_array($res)) {
  295. if ($val = unserialize($cur["value"])) {
  296. $system_settings[$cur["name"]] = $val;
  297. }
  298. }
  299. $res = mysql_query("SELECT * FROM modules WHERE enabled = 1
  300. ORDER BY weight, name");
  301. while ($cur = mysql_fetch_array($res)) {
  302. $system_settings["modules"][$cur["name"]] = $cur;
  303. }
  304. mysql_close($dbc);
  305. // We want to make sure the "system" module is enabled, so we will hard-code
  306. // its values.
  307. if ($system_settings["modules"]["system"]["enabled"] != 1) {
  308. $system_settings["modules"]["system"]["path"] = "modules/system";
  309. $system_settings["modules"]["system"]["enabled"] = 1;
  310. }
  311. ////////////////////////////////////////////
  312. ////////////////////////////////////////////
  313. // This must appear at the VERY end! Nothing should come after it....
  314. //
  315. // Assign our systemSettings to the GLOBALS array so we can access it anywhere.
  316. $GLOBALS["fp_system_settings"] = $system_settings;
  317. //////////////////////////////////////////////
  318. //////////////////////////////////////////////
  319. // PUT NOTHING BELOW THIS LINE!!!!
  320. ';
  321. }
  322. /**
  323. * Displays the form to let a user set up a new database
  324. */
  325. function install_display_db_form($msg = "") {
  326. global $lang;
  327. $db_name = $_POST["db_name"];
  328. $db_host = $_POST["db_host"];
  329. $db_port = $_POST["db_port"];
  330. $db_user = $_POST["db_user"];
  331. $db_pass = $_POST["db_pass"];
  332. $admin_pass = $_POST["admin_pass"];
  333. $admin_pass2 = $_POST["admin_pass2"];
  334. $admin_name = $_POST["admin_name"];
  335. $pC = "";
  336. $pC .= "<h2 class='title'>" . st("Setup Database and Admin") . "</h2>$msg
  337. <p>" . st("You should have already set up a database and database user
  338. (with all privileges except Grant) for FlightPath. Please
  339. enter that information below.") . "</p>
  340. <hr>
  341. <form action='install.php?lang=$lang' method='POST'>
  342. <input type='hidden' name='perform_action' value='install'>
  343. <table border='0' cellpadding='3' style='margin-left: 20px;'>
  344. <tr>
  345. <td colspan='2'><b>" . st("FlightPath administrator information") . "</b></td>
  346. </tr>
  347. <tr>
  348. <td valign='top'>" . st("Admin Username:") . "</td>
  349. <td valign='top'><input type='text' name='admin_name' value='$admin_name' size='15' maxlength='50'> Ex: admin</td>
  350. </tr>
  351. <tr>
  352. <td valign='top'>" . st("Admin Password:") . "</td>
  353. <td valign='top'><input type='password' name='admin_pass' value='$admin_pass' size='20'></td>
  354. </tr>
  355. <tr>
  356. <td valign='top'>" . st("Re-enter Password:") . "</td>
  357. <td valign='top'><input type='password' name='admin_pass2' value='$admin_pass2' size='20'></td>
  358. </tr>
  359. <tr>
  360. <td colspan='2'><hr>
  361. <b>" . st("Database information") . "</b></td>
  362. </tr>
  363. <tr>
  364. <td valign='top'>" . st("Database Name:") . "</td>
  365. <td valign='top'><input type='text' name='db_name' value='$db_name' size='50'></td>
  366. </tr>
  367. <tr>
  368. <td valign='top'>" . st("Database Host/IP:") . "</td>
  369. <td valign='top'><input type='text' name='db_host' value='$db_host' size='50'></td>
  370. </tr>
  371. <tr>
  372. <td valign='top'>" . st("Database Port:") . "</td>
  373. <td valign='top'><input type='text' name='db_port' value='$db_port' size='10'> Ex: 3306</td>
  374. </tr>
  375. <tr>
  376. <td valign='top'>" . st("Database Username:") . "</td>
  377. <td valign='top'><input type='text' name='db_user' value='$db_user' size='50'></td>
  378. </tr>
  379. <tr>
  380. <td valign='top'>" . st("Database Password:") . "</td>
  381. <td valign='top'><input type='password' name='db_pass' value='$db_pass' size='50'></td>
  382. </tr>
  383. </table>
  384. <br><br>
  385. <input type='submit' value='" . st("Install") . "'>
  386. <br>
  387. <b>" . st("Please click only once. May take several seconds to install.") . "
  388. </form>";
  389. // Display the screen
  390. $page_content = $pC;
  391. $page_title = "Install FlightPath";
  392. $page_hide_report_error = TRUE;
  393. include("themes/classic/fp_template.php");
  394. }
  395. /**
  396. * Check for missing requirements of the system.
  397. *
  398. * Returns an array of missing requirements which the user must fix before
  399. * installation can continue.
  400. *
  401. */
  402. function install_check_requirements() {
  403. $rtn = array();
  404. // Is the /custom directory writable?
  405. if (!is_writable("custom")) {
  406. $rtn[] = st("Please make sure the <em>/custom</em> directory is writable to the web server.
  407. <br>Ex: chmod 777 custom");
  408. }
  409. if (count($rtn) == 0) return FALSE;
  410. return $rtn;
  411. }
  412. /**
  413. * Displays the requirements on screen for the user.
  414. */
  415. function install_display_requirements($req_array) {
  416. global $lang;
  417. $pC = "";
  418. $pC .= "<h2 class='title'>" . st("Check Requirements") . "</h2>
  419. <p>" . st("The following requirements must be fixed before installation of FlightPath
  420. can continue.") . "</p>";
  421. foreach ($req_array as $req) {
  422. $pC .= "<div style='padding: 5px; margin: 10px; border: 1px solid red;
  423. font-family: Courier New, serif; font-size:0.9em'>$req</div>";
  424. }
  425. $pC .= "<p>" . st("Please fix the problems listed, then reload to try again:") . "
  426. <br><a href='install.php?lang=$lang'>" . st("Click here to try again") . "</a>";
  427. // Display the screen
  428. $page_content = $pC;
  429. $page_title = "Install FlightPath";
  430. $page_hide_report_error = TRUE;
  431. include("themes/classic/fp_template.php");
  432. }
  433. function install_display_lang_selection() {
  434. $pC = "";
  435. $pC .= "<h2 class='title'>Install FlightPath</h2>
  436. Please follow the instructions on the following pages to complete
  437. your installation of FlightPath.
  438. <h3 class='title'>Select language</h3>
  439. Please begin by selecting an installation language.
  440. <ul>
  441. <li><a href='install.php?lang=en'>English</a></li>
  442. </ul>
  443. <br><br><br>
  444. <b>Please note:</b> By proceeding with this installation, you affirm that you
  445. have read, understand, and agree with the LICENSE.txt file and the COPYRIGHT.txt file
  446. included with this software package.
  447. Specifically, that you accept and agree with the GNU GPL license, and with the statement
  448. that this software is provided to you without warranty. If you have any questions,
  449. please visit http://getflightpath.com/contact before proceeding with installation.";
  450. // Display the screen
  451. $page_content = $pC;
  452. $page_title = "Install FlightPath";
  453. $page_hide_report_error = TRUE;
  454. include("themes/classic/fp_template.php");
  455. }

Functions

Namesort descending Description
install_check_requirements Check for missing requirements of the system.
install_display_db_form Displays the form to let a user set up a new database
install_display_lang_selection
install_display_requirements Displays the requirements on screen for the user.
install_get_settings_file_template Returns a template for a new settings file.
install_perform_install Actually performs the installation of FlightPath