PageRenderTime 23ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/modules/admin/actions/firstrun.act.php

http://awarenet.googlecode.com/
PHP | 202 lines | 124 code | 41 blank | 37 comment | 29 complexity | 5393a88d198e007050989f7e1654ca1e MD5 | raw file
Possible License(s): GPL-3.0
  1. <?
  2. require_once($kapenta->installPath . 'core/dbdriver/mysqladmin.dbd.php');
  3. //-------------------------------------------------------------------------------------------------
  4. //* configure awareNet from Windows Installer
  5. //-------------------------------------------------------------------------------------------------
  6. //---------------------------------------------------------------------------------------------
  7. // check that this is not already complete
  8. //---------------------------------------------------------------------------------------------
  9. if ('yes' == $registry->get('firstrun.complete')) {
  10. $session->msg('awareNet initialized.');
  11. $page->do302('');
  12. }
  13. // override default max execution time in case Apache has not been restarted.
  14. ini_set('max_execution_time', 900);
  15. //---------------------------------------------------------------------------------------------
  16. // set some registry defaults
  17. //---------------------------------------------------------------------------------------------
  18. $dbrDefault = array(
  19. 'firstrun.dbr.created' => 'no',
  20. 'firstrun.dbr.granted' => 'no',
  21. 'firstrun.dbr.installed' => 'no',
  22. 'firstrun.dbr.name' => 'awarenet',
  23. 'firstrun.dbr.host' => 'localhost',
  24. 'firstrun.dbr.user' => 'root',
  25. 'firstrun.dbr.password' => '',
  26. 'firstrun.db.user' => 'awarenet',
  27. 'firstrun.db.password' => $kapenta->createUID(),
  28. 'firstrun.adminuid' => $kapenta->createUID()
  29. );
  30. foreach($dbrDefault as $key => $value) {
  31. if ('' == $registry->get($key)) { $registry->set($key, $value); }
  32. }
  33. //---------------------------------------------------------------------------------------------
  34. // run as admin
  35. //---------------------------------------------------------------------------------------------
  36. $user->role = 'admin';
  37. echo $theme->expandBlocks("[[:theme::ifscrollheader:]]", '');
  38. echo "<h1>Configuring awareNet</h1>";
  39. $dba = new KDBAdminDriver();
  40. //---------------------------------------------------------------------------------------------
  41. // handle POSTs
  42. //---------------------------------------------------------------------------------------------
  43. if (true == array_key_exists('action', $_POST)) {
  44. //-----------------------------------------------------------------------------------------
  45. // set MySQL root user and password
  46. //-----------------------------------------------------------------------------------------
  47. if ('set_dbr' == $_POST['action']) {
  48. $registry->set('firstrun.dbr.user', $_POST['firstrun_dbr_user']);
  49. $registry->set('firstrun.dbr.password', $_POST['firstrun_dbr_password']);
  50. }
  51. }
  52. //---------------------------------------------------------------------------------------------
  53. // define some forms
  54. //---------------------------------------------------------------------------------------------
  55. $frmMySQLRoot = ''
  56. . "Please enter your MySQL root user and password to create `awarenet` database:<br/>\n"
  57. . "<br/>"
  58. . "<form name='frmSetDbr' method='POST'>\n"
  59. . "<input type='hidden' name='action' value='set_dbr' />"
  60. . "<b>Username:</b> <input type='text' name='firstrun_dbr_user' "
  61. . "value='" . $registry->get('firstrun.dbr.user') . "'/>&nbsp; "
  62. . "<b>Password:</b> <input type='text' name='firstrun_dbr_password' "
  63. . "value='" . $registry->get('firstrun.dbr.password') . "'/>&nbsp; "
  64. . "<input type='submit' value='Retry &gt;&gt;' />"
  65. . "</form><br/>\n"
  66. . "<small>Default values for XAMPP are 'root' and no password.</small>";
  67. $frmMySQLDetail = ''
  68. . "<p>Alternatively, if you already have a database set up, please set the details:"
  69. . "<form name='frmSetMySQL' method='POST'>"
  70. . "<input type='hidden' name='action' value='set_mysql' />"
  71. . "<table noborder width='100%'>"
  72. . " <tr>\n"
  73. . " <td><b>Database name:</b></td>"
  74. . " <td><input type='text' name='kapenta.db.name'></td>"
  75. . " </tr>"
  76. . "</table>"
  77. . "</form>";
  78. //---------------------------------------------------------------------------------------------
  79. // install database (xampp settings)
  80. //---------------------------------------------------------------------------------------------
  81. if ('yes' !== $registry->get('firstrun.dbr.installed')) {
  82. $db->host = $registry->get('firstrun.dbr.host');
  83. $db->user = $registry->get('firstrun.dbr.user');;
  84. $db->pass = $registry->get('firstrun.dbr.password');;
  85. $db->name = $registry->get('firstrun.dbr.name');
  86. //-----------------------------------------------------------------------------------------
  87. // create the database itself
  88. //-----------------------------------------------------------------------------------------
  89. if ('yes' !== $registry->get('firstrun.dbr.created')) {
  90. $check = $dba->create($db->name);
  91. $msg = "Creating database `awareNet` using default XAMPP root user... ";
  92. if (true == $check) {
  93. $msg .= "<b>OK</b>";
  94. $registry->set('firstrun.dbr.created', 'yes');
  95. echo "<div class='chatmessagegreen'>$msg</div>";
  96. if (true == $dba->dbExists($db->name)) {
  97. $registry->set('firstrun.dbr.created', 'yes');
  98. }
  99. } else {
  100. $msg .= "<b>FAIL</b>.";
  101. echo "<div class='chatmessagered'>$msg</div>";
  102. echo "<div class='chatmessageblack'>$frmMySQLRoot</div>";
  103. die();
  104. }
  105. }
  106. //-----------------------------------------------------------------------------------------
  107. // create database user
  108. //-----------------------------------------------------------------------------------------
  109. if ('yes' !== $registry->get('firstrun.dbr.granted')) {
  110. $newUser = $registry->get('firstrun.db.user');
  111. $newPass = $registry->get('firstrun.db.password');
  112. $sql = ''
  113. . "GRANT ALL ON " . $db->name . ".* "
  114. . "TO '$newUser'@'localhost' IDENTIFIED BY '$newPass' ";
  115. $msg = "Creating new database user for use by awareNet... ";
  116. $check = $db->query($sql);
  117. if (true == $check) {
  118. $msg .= "<b>OK</b>.";
  119. $registry->set('firstrun.dbr.granted', 'yes');
  120. $registry->set('kapenta.db.user', $newUser);
  121. $registry->set('kapenta.db.password', $newPass);
  122. $registry->set('kapenta.db.host', 'localhost');
  123. $registry->set('kapenta.db.name', $db->name);
  124. echo "<div class='chatmessagegreen'>$msg</div>";
  125. } else {
  126. $msg .= "<b>FAIL</b>.";
  127. echo "<div class='chatmessagered'>$msg</div>";
  128. echo "<div class='chatmessageblack'>$sql</div>";
  129. die();
  130. }
  131. }
  132. }
  133. //---------------------------------------------------------------------------------------------
  134. // run all module install scripts
  135. //---------------------------------------------------------------------------------------------
  136. echo "<h2>Installing Modules</h2>";
  137. $mods = $kapenta->listModules();
  138. foreach($mods as $moduleName) {
  139. $msg = "<b>Installing module: $moduleName </b><br/>";
  140. $installScript = 'modules/' . $moduleName . '/inc/install.inc.php';
  141. if (true == $kapenta->fileExists($installScript)) {
  142. $msg .= "Install script: $installScript<br/>";
  143. $installFn = $moduleName . "_install_module";
  144. require_once($kapenta->installPath . $installScript);
  145. if (true == function_exists($installFn)) {
  146. $msg .= "Call: $installFn<br/>";
  147. $report = $installFn();
  148. $msg .= "<hr/><br/><div class='chatmessageblack'>$report</div><br/>";
  149. } else {
  150. $msg .= "Missing install function, please install manually.<br/>";
  151. }
  152. } else {
  153. $msg .= "No install script for this module.<br/>";
  154. }
  155. echo "<div class='chatmessageblack'>$msg</div><br/>\n";
  156. }
  157. //---------------------------------------------------------------------------------------------
  158. // done
  159. //---------------------------------------------------------------------------------------------
  160. echo $theme->expandBlocks("[[:theme::ifscrollfooter:]]", '');
  161. ?>