PageRenderTime 43ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/administrator/components/com_joomlapack/temp/installation/includes/CConfig.php

https://bitbucket.org/dgough/annamaria-daneswood-25102012
PHP | 331 lines | 245 code | 50 blank | 36 comment | 24 complexity | cd5d8bf3faa059caba00445e73b719d2 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1
  1. <?php
  2. /**
  3. * @package JoomlaPackInstaller
  4. * @copyright Copyright (C) 2008 JoomlaPack Developers. All rights reserved.
  5. * @version 2.0
  6. * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
  7. *
  8. * This file contains the final configuration page
  9. *
  10. * For bugs regarding this part of JoomlaPack, contact Nicholas K. Dionysopoulos
  11. * (JoomlaPack Support Forum user: nicholas, email: nikosdion@gmail.com)
  12. *
  13. * JoomlaPack is free software. This version may have been modified pursuant
  14. * to the GNU General Public License, and as distributed it includes or
  15. * is derivative of works licensed under the GNU General Public License or
  16. * other free or open source software licenses.
  17. */
  18. class CConfig
  19. {
  20. var $dberror = "";
  21. function getFullHTML()
  22. {
  23. return getPageHTML( $this->getStepBarHTML(), $this->getMainHTML() );
  24. }
  25. function getBodyHTML()
  26. {
  27. return getBodyHTML( $this->getStepBarHTML(), $this->getMainHTML() );
  28. }
  29. function getStepBarHTML()
  30. {
  31. return getStepBar('config');
  32. }
  33. function getMainHTML()
  34. {
  35. global $lang, $ConfigManager;
  36. $mainHTML = "";
  37. $mainHTML .= getPageHeader( $lang['global']['step4'], $this->_getButtonsHTML() );
  38. $mainHTML .= '<div id="error">&nbsp;</div>' . "\n";
  39. $mainHTML .= "<h2>" . $lang['config']['basic_title'] . "</h2>\n";
  40. $mainHTML .= getLayoutTable( $lang['config']['basic_desc'], $this->_getMainOptionsHTML());
  41. $mainHTML .= "<h2>" . $lang['config']['chmod_title'] . "</h2>\n";
  42. $mainHTML .= getLayoutTable( $lang['config']['chmod_desc'], $this->_getPermsHTML());
  43. if( $ConfigManager->JoomlaVersion != "1.0.x" ) {
  44. $mainHTML .= "<h2>" . $lang['config']['ftp_title'] . "</h2>\n";
  45. $mainHTML .= getLayoutTable( $lang['config']['ftp_desc'], $this->_getFTPHTML());
  46. }
  47. return $mainHTML;
  48. }
  49. function SaveConfig($sitename, $mailfrom, $adminpass, $dirperms = "", $fileperms = "", $ftp_enable = false, $ftp_host = '', $ftp_port = '21', $ftp_user = '', $ftp_pass = '', $ftp_root = '')
  50. {
  51. /*
  52. * 1. Basic configuration:
  53. * sitename, mailfrom, {admin password}
  54. * 2. FTP Layer configuration - 1.5.x:
  55. * ftp_enable, ftp_host, ftp_port, ftp_user, ftp_pass, ftp_root
  56. * 3. Automatically calculated - 1.0.x:
  57. * absolute_path, live_site
  58. */
  59. global $lang, $ConfigManager;
  60. // First, we check for required parameters
  61. $errors = "";
  62. $errors .= $sitename ? "" : $lang['config']['error1'] . '<br />';
  63. $errors .= $mailfrom ? "" : $lang['config']['error2'] . '<br />';
  64. if( ($ConfigManager->JoomlaVersion != "1.0.x") && ($ftp_enable == "on") ) {
  65. $errors .= $ftp_host ? "" : $lang['config']['error3'] . '<br />';
  66. $errors .= $ftp_port ? "" : $lang['config']['error4'] . '<br />';
  67. $errors .= $ftp_user ? "" : $lang['config']['error5'] . '<br />';
  68. $errors .= $ftp_pass ? "" : $lang['config']['error6'] . '<br />';
  69. $errors .= $ftp_root ? "" : $lang['config']['error7'] . '<br />';
  70. }
  71. if( $errors ) return $errors; // If errors occured, inform the user about them
  72. // No errors. Good. Update basic parameters.
  73. $ConfigManager->config['sitename'] = $sitename;
  74. $ConfigManager->config['mailfrom'] = $mailfrom;
  75. if( $ConfigManager->JoomlaVersion != "1.0.x" )
  76. {
  77. $ConfigManager->config['ftp_enable'] = ($ftp_enable == "on") ? true : false;
  78. $ConfigManager->config['ftp_host'] = $ftp_host;
  79. $ConfigManager->config['ftp_port'] = $ftp_port;
  80. $ConfigManager->config['ftp_user'] = $ftp_user;
  81. $ConfigManager->config['ftp_pass'] = $ftp_pass;
  82. $ConfigManager->config['ftp_root'] = $ftp_root;
  83. }
  84. // Request admin password change if requested
  85. if( $adminpass != "" ) {
  86. if( !$this->_changeAdminPass( $adminpass ) ) $errors .= $lang['config']['error8'] . '<br />';
  87. }
  88. // Change permissions if requested
  89. $dirperms = $dirperms == "" ? null : $dirperms;
  90. $fileperms = $fileperms == "" ? null : $fileperms;
  91. if( (!is_null($dirperms)) || (!is_null($fileperms)) ) mosChmodRecursive( realpath( JPIDIR . '/../' ), octdec($fileperms), octdec($dirperms) );
  92. // Test connect to FTP
  93. if( !$this->_testFTP($ftp_host, $ftp_port, $ftp_user, $ftp_pass, $ftp_root) ) $errors .= $lang['config']['error9'] . '<br />';
  94. // Joomla! 1.0.x parameters
  95. if( $ConfigManager->JoomlaVersion == "1.0.x" )
  96. {
  97. $port = ( $_SERVER['SERVER_PORT'] == 80 ) ? '' : ":".$_SERVER['SERVER_PORT'];
  98. $root = $_SERVER['SERVER_NAME'] . $port . $_SERVER['PHP_SELF'];
  99. $upto = strpos( $root, "/installation" );
  100. $root = substr( $root, 0, $upto );
  101. $url = "http://".$root;
  102. $ConfigManager->config['absolute_path'] = realpath( JPIDIR . '/../' );
  103. $ConfigManager->config['live_site'] = $url;
  104. }
  105. // Database parameters which must be saved in configuration.php
  106. require_once( JPIDIR . '/includes/CDatabase.php' );
  107. global $JPDBFunc;
  108. $myDB = $JPDBFunc->databases[0];
  109. $ConfigManager->config['host'] = $myDB['Host'];
  110. $ConfigManager->config['user'] = $myDB['Username'];
  111. $ConfigManager->config['password'] = $myDB['Password'];
  112. $ConfigManager->config['db'] = $myDB['DBName'];
  113. $ConfigManager->config['dbprefix'] = $myDB['Prefix'];
  114. $ConfigManager->save();
  115. // Return - if we had errors a non-empty string will be returned
  116. return $errors;
  117. }
  118. // Change the administrator's password to $pass. Returns true on success
  119. function _changeAdminPass( $pass )
  120. {
  121. require_once( JPIDIR . '/includes/CDatabase.php' );
  122. require_once( JPIDIR . '/../includes/database.php' );
  123. global $JPDBFunc, $lang;
  124. $myDB = $JPDBFunc->databases[0];
  125. $database = new database( $myDB['Host'], $myDB['Username'], $myDB['Password'], $myDB['DBName'], $myDB['Prefix'] );
  126. $cryptpass = md5( $pass );
  127. $sql = "UPDATE `#__users` SET `password` = '$cryptpass' WHERE id=62";
  128. $database->setQuery( $sql );
  129. $test = $database->getErrorNum();
  130. if ($test != 0) {
  131. $this->dberror = $database->getErrorMsg();
  132. return false;
  133. } else {
  134. return true;
  135. }
  136. }
  137. // Tries to connect to FTP. Returns true on success
  138. function _testFTP($ftp_host, $ftp_port, $ftp_user, $ftp_pass, $ftp_root)
  139. {
  140. // TODO
  141. return true;
  142. }
  143. function _getButtonsHTML()
  144. {
  145. global $lang;
  146. return '<input name="ButtonNext" type="submit" class="button" value="' . $lang['global']['btnNext'] . '" onclick="applyConfig();" />';
  147. }
  148. function _getMainOptionsHTML()
  149. {
  150. // sitename, mailfrom, {admin password}
  151. global $lang, $ConfigManager;
  152. $out = "";
  153. $out .= <<<ENDOFDATAMARK
  154. <table class="config">
  155. <tr>
  156. <td colspan="2">{$lang['config']['sitename']}</td>
  157. </tr>
  158. <tr>
  159. <td colspan="2"><input id="sitename" type="text" value="{$ConfigManager->config['sitename']}" class="text" /></td>
  160. </tr>
  161. <tr>
  162. <td colspan="2">{$lang['config']['mailfrom']}</td>
  163. </tr>
  164. <tr>
  165. <td colspan="2"><input id="mailfrom" type="text" value="{$ConfigManager->config['mailfrom']}" class="text" /></td>
  166. </tr>
  167. <tr>
  168. <td colspan="2">
  169. {$lang['config']['adminpass']}<br />
  170. <span style="font-weight: normal; font-size: smaller;">{$lang['config']['adminpassinfo']}</span>
  171. </td>
  172. </tr>
  173. <tr>
  174. <td><input id="adminpass" type="text" class="text" /></td>
  175. <td width="10%"><input type="button" id="mkrand" value="{$lang['config']['getrandom']}" onclick="getRandomPassword();" /></td>
  176. </tr>
  177. </table>
  178. ENDOFDATAMARK;
  179. return $out;
  180. }
  181. function _getPermsHTML()
  182. {
  183. global $lang;
  184. return <<<ENDOFDATAMARK
  185. <table>
  186. <tr>
  187. <td valign="top">
  188. <input type="checkbox" id="chmoddir" />
  189. <span style="font-weight: bold;">{$lang['config']['chmod_directory']}</span>
  190. </td>
  191. <td>
  192. <table>
  193. <thead>
  194. <tr>
  195. <th width="110px">&nbsp;</th>
  196. <th width="50px">{$lang['config']['chmod_user']}</th>
  197. <th width="50px">{$lang['config']['chmod_group']}</th>
  198. <th>{$lang['config']['chmod_others']}</th>
  199. </tr>
  200. </thead>
  201. <tr>
  202. <td>{$lang['config']['chmod_r']}</td>
  203. <td><input type="checkbox" id="dur" value="4" checked /></td>
  204. <td><input type="checkbox" id="dgr" value="4" checked /></td>
  205. <td><input type="checkbox" id="dor" value="4" checked /></td>
  206. </tr>
  207. <tr>
  208. <td>{$lang['config']['chmod_w']}</td>
  209. <td><input type="checkbox" id="duw" value="2" checked /></td>
  210. <td><input type="checkbox" id="dgw" value="2" checked /></td>
  211. <td><input type="checkbox" id="dow" value="2" /></td>
  212. </tr>
  213. <tr>
  214. <td>{$lang['config']['chmod_xd']}</td>
  215. <td><input type="checkbox" id="dux" value="1" checked /></td>
  216. <td><input type="checkbox" id="dgx" value="1" checked /></td>
  217. <td><input type="checkbox" id="dox" value="1" checked /></td>
  218. </tr>
  219. </table>
  220. </td>
  221. </tr>
  222. <tr>
  223. <td valign="top">
  224. <input type="checkbox" id="chmodfiles" />
  225. <span style="font-weight: bold;">{$lang['config']['chmod_files']}</span>
  226. </td>
  227. <td>
  228. <table>
  229. <thead>
  230. <tr>
  231. <th width="110px">&nbsp;</th>
  232. <th width="50px">{$lang['config']['chmod_user']}</th>
  233. <th width="50px">{$lang['config']['chmod_group']}</th>
  234. <th>{$lang['config']['chmod_others']}</th>
  235. </tr>
  236. </thead>
  237. <tr>
  238. <td>{$lang['config']['chmod_r']}</td>
  239. <td><input type="checkbox" id="fur" value="4" checked /></td>
  240. <td><input type="checkbox" id="fgr" value="4" checked /></td>
  241. <td><input type="checkbox" id="for" value="4" checked /></td>
  242. </tr>
  243. <tr>
  244. <td>{$lang['config']['chmod_w']}</td>
  245. <td><input type="checkbox" id="fuw" value="2" checked /></td>
  246. <td><input type="checkbox" id="fgw" value="2" checked /></td>
  247. <td><input type="checkbox" id="fow" value="2" /></td>
  248. </tr>
  249. <tr>
  250. <td>{$lang['config']['chmod_x']}</td>
  251. <td><input type="checkbox" id="fux" value="1" checked /></td>
  252. <td><input type="checkbox" id="fgx" value="1" checked /></td>
  253. <td><input type="checkbox" id="fox" value="1" checked /></td>
  254. </tr>
  255. </table>
  256. </td>
  257. </tr>
  258. </table>
  259. ENDOFDATAMARK;
  260. }
  261. function _getFTPHTML()
  262. {
  263. global $lang, $ConfigManager;
  264. $checked = $ConfigManager->config['ftp_enable'] ? "checked" : "";
  265. return <<<ENDOFDATAMARK
  266. <input type="checkbox" id="ftp_enable" {$checked} />
  267. <span style="font-weight: bold;">{$lang['config']['ftp_enable']}</span>
  268. <label for="ftp_host">{$lang['config']['ftp_host']}</label>
  269. <input type="text" id="ftp_host" value="{$ConfigManager->config['ftp_host']}" class="text" />
  270. <label for="ftp_port">{$lang['config']['ftp_port']}</label>
  271. <input type="text" id="ftp_port" value="{$ConfigManager->config['ftp_port']}" class="text" />
  272. <label for="ftp_user">{$lang['config']['ftp_user']}</label>
  273. <input type="text" id="ftp_user" value="{$ConfigManager->config['ftp_user']}" class="text" />
  274. <label for="ftp_pass">{$lang['config']['ftp_pass']}</label>
  275. <input type="text" id="ftp_pass" value="{$ConfigManager->config['ftp_pass']}" class="text" />
  276. <label for="ftp_root">{$lang['config']['ftp_root']}</label>
  277. <input type="text" id="ftp_root" value="{$ConfigManager->config['ftp_root']}" class="text" />
  278. ENDOFDATAMARK;
  279. }
  280. }
  281. ?>