PageRenderTime 45ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/administrator/components/com_patch/patch/administrator/index.php

https://github.com/viollarr/alab
PHP | 248 lines | 167 code | 34 blank | 47 comment | 46 complexity | 404b894cc405e7e8d42639642be5c7ac MD5 | raw file
Possible License(s): LGPL-2.1, GPL-2.0, AGPL-3.0, Apache-2.0, BSD-3-Clause, GPL-3.0
  1. <?php
  2. /**
  3. * This file has been modified by Vincent Cheah, ByOS Technologies 2008-02-27 12:07
  4. * for integration with JACLPlus Component
  5. */
  6. /**
  7. * @version $Id: index.php 10041 2008-02-15 21:48:13Z eddieajau $
  8. * @package Joomla
  9. * @copyright Copyright (C) 2005 Open Source Matters. All rights reserved.
  10. * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
  11. * Joomla! is free software. This version may have been modified pursuant
  12. * to the GNU General Public License, and as distributed it includes or
  13. * is derivative of works licensed under the GNU General Public License or
  14. * other free or open source software licenses.
  15. * See COPYRIGHT.php for copyright notices and details.
  16. */
  17. // Set flag that this is a parent file
  18. define( '_VALID_MOS', 1 );
  19. if (!file_exists( '../configuration.php' )) {
  20. header( 'Location: ../installation/index.php' );
  21. exit();
  22. }
  23. require( '../globals.php' );
  24. require( '../configuration.php' );
  25. // SSL check - $http_host returns <live site url>:<port number if it is 443>
  26. $http_host = explode(':', $_SERVER['HTTP_HOST'] );
  27. if( (!empty( $_SERVER['HTTPS'] ) && strtolower( $_SERVER['HTTPS'] ) != 'off' || isset( $http_host[1] ) && $http_host[1] == 443) && substr( $mosConfig_live_site, 0, 8 ) != 'https://' ) {
  28. $mosConfig_live_site = 'https://'.substr( $mosConfig_live_site, 7 );
  29. }
  30. require_once( '../includes/joomla.php' );
  31. include_once ( $mosConfig_absolute_path . '/language/'. $mosConfig_lang .'.php' );
  32. //Installation sub folder check, removed for work with SVN
  33. if (file_exists( '../installation/index.php' ) && $_VERSION->SVN == 0) {
  34. define( '_INSTALL_CHECK', 1 );
  35. include ($mosConfig_absolute_path .'/offline.php');
  36. exit();
  37. }
  38. $option = strtolower( strval( mosGetParam( $_REQUEST, 'option', NULL ) ) );
  39. // mainframe is an API workhorse, lots of 'core' interaction routines
  40. $mainframe = new mosMainFrame( $database, $option, '..', true );
  41. if (isset( $_POST['submit'] )) {
  42. $usrname = stripslashes( mosGetParam( $_POST, 'usrname', NULL ) );
  43. $pass = stripslashes( mosGetParam( $_POST, 'pass', NULL ) );
  44. if($pass == NULL) {
  45. echo "<script>alert('Please enter a password'); document.location.href='index.php?mosmsg=Please enter a password'</script>\n";
  46. exit();
  47. }
  48. $query = "SELECT COUNT(*)"
  49. . "\n FROM #__users"
  50. . "\n WHERE ("
  51. // Administrators
  52. . "\n gid = 24"
  53. // Super Administrators
  54. . "\n OR gid = 25"
  55. . "\n )"
  56. ;
  57. $database->setQuery( $query );
  58. $count = intval( $database->loadResult() );
  59. if ($count < 1) {
  60. mosErrorAlert( _LOGIN_NOADMINS );
  61. }
  62. $my = null;
  63. $query = "SELECT u.*, m.*"
  64. . "\n FROM #__users AS u"
  65. . "\n LEFT JOIN #__messages_cfg AS m ON u.id = m.user_id AND m.cfg_name = 'auto_purge'"
  66. . "\n WHERE u.username = " . $database->Quote( $usrname )
  67. . "\n AND u.block = 0"
  68. ;
  69. $database->setQuery( $query );
  70. $database->loadObject( $my );
  71. /** find the user group (or groups in the future) */
  72. if (@$my->id) {
  73. $grp = $acl->getAroGroup( $my->id );
  74. $my->gid = $grp->group_id;
  75. $my->usertype = $grp->name;
  76. if(isset($grp->jaclplus) && class_exists('JACLPlus')) $my->jaclplus = $grp->jaclplus;
  77. // Conversion to new type
  78. if ((strpos($my->password, ':') === false) && $my->password == md5($pass)) {
  79. // Old password hash storage but authentic ... lets convert it
  80. $salt = mosMakePassword(16);
  81. $crypt = md5($pass.$salt);
  82. $my->password = $crypt.':'.$salt;
  83. // Now lets store it in the database
  84. $query = 'UPDATE #__users ' .
  85. 'SET password = '.$database->Quote($my->password) .
  86. 'WHERE id = '.(int)$my->id;
  87. $database->setQuery($query);
  88. if (!$database->query()) {
  89. // This is an error but not sure what to do with it ... we'll still work for now
  90. }
  91. }
  92. list($hash, $salt) = explode(':', $my->password);
  93. $cryptpass = md5($pass.$salt);
  94. if ( strcmp( $hash, $cryptpass ) || !$acl->acl_check( 'administration', 'login', 'users', $my->usertype ) ) {
  95. mosErrorAlert("Incorrect Username, Password, or Access Level. Please try again", "document.location.href='index.php'");
  96. }
  97. // construct Session ID
  98. $logintime = time();
  99. $session_id = md5( $my->id . $my->username . $my->usertype . $logintime );
  100. session_name( md5( $mosConfig_live_site ) );
  101. session_id( $session_id );
  102. session_start();
  103. // add Session ID entry to DB
  104. $query = "INSERT INTO #__session"
  105. . "\n SET time = " . $database->Quote( $logintime ) . ", session_id = " . $database->Quote( $session_id ) . ", userid = " . (int) $my->id . ", usertype = " . $database->Quote( $my->usertype) . ", username = " . $database->Quote( $my->username )
  106. . ( isset($my->jaclplus) ? ", gid = " . (int) $my->gid . ", jaclplus = " . $database->Quote( $my->jaclplus ) : "" )
  107. ;
  108. $database->setQuery( $query );
  109. if (!$database->query()) {
  110. echo $database->stderr();
  111. }
  112. // check if site designated as a production site
  113. // for a demo site allow multiple logins with same user account
  114. if ( $_VERSION->SITE == 1 ) {
  115. // delete other open admin sessions for same account
  116. $query = "DELETE FROM #__session"
  117. . "\n WHERE userid = " . (int) $my->id
  118. . "\n AND username = " . $database->Quote( $my->username )
  119. . "\n AND usertype = " . $database->Quote( $my->usertype )
  120. . "\n AND session_id != " . $database->Quote( $session_id )
  121. // this ensures that frontend sessions are not purged
  122. . "\n AND guest = 1"
  123. . ( isset($my->jaclplus) ? "\n AND gid = " . (int) $my->gid : "\n AND gid = 0" )
  124. ;
  125. $database->setQuery( $query );
  126. if (!$database->query()) {
  127. echo $database->stderr();
  128. }
  129. }
  130. $_SESSION['session_id'] = $session_id;
  131. $_SESSION['session_user_id'] = $my->id;
  132. $_SESSION['session_username'] = $my->username;
  133. $_SESSION['session_usertype'] = $my->usertype;
  134. $_SESSION['session_gid'] = $my->gid;
  135. $_SESSION['session_logintime'] = $logintime;
  136. $_SESSION['session_user_params'] = $my->params;
  137. $_SESSION['session_userstate'] = array();
  138. if(isset($my->jaclplus)) $_SESSION['session_jaclplus'] = $my->jaclplus;
  139. session_write_close();
  140. $expired = 'index2.php';
  141. // check if site designated as a production site
  142. // for a demo site disallow expired page functionality
  143. if ( $_VERSION->SITE == 1 && @$mosConfig_admin_expired === '1' ) {
  144. $file = $mainframe->getPath( 'com_xml', 'com_users' );
  145. $params =& new mosParameters( $my->params, $file, 'component' );
  146. $now = time();
  147. // expired page functionality handling
  148. $expired = $params->def( 'expired', '' );
  149. $expired_time = $params->def( 'expired_time', '' );
  150. // if now expired link set or expired time is more than half the admin session life set, simply load normal admin homepage
  151. $checktime = ( $mosConfig_session_life_admin ? $mosConfig_session_life_admin : 1800 ) / 2;
  152. if (!$expired || ( ( $now - $expired_time ) > $checktime ) ) {
  153. $expired = 'index2.php';
  154. }
  155. // link must also be a Joomla link to stop malicious redirection
  156. if ( strpos( $expired, 'index2.php?option=com_' ) !== 0 ) {
  157. $expired = 'index2.php';
  158. }
  159. // clear any existing expired page data
  160. $params->set( 'expired', '' );
  161. $params->set( 'expired_time', '' );
  162. // param handling
  163. if (is_array( $params->toArray() )) {
  164. $txt = array();
  165. foreach ( $params->toArray() as $k=>$v) {
  166. $txt[] = "$k=$v";
  167. }
  168. $saveparams = implode( "\n", $txt );
  169. }
  170. // save cleared expired page info to user data
  171. $query = "UPDATE #__users"
  172. . "\n SET params = " . $database->Quote( $saveparams )
  173. . "\n WHERE id = " . (int) $my->id
  174. . "\n AND username = " . $database->Quote( $my->username )
  175. . "\n AND usertype = " . $database->Quote( $my->usertype )
  176. ;
  177. $database->setQuery( $query );
  178. $database->query();
  179. }
  180. // check if auto_purge value set
  181. if ( $my->cfg_name == 'auto_purge' ) {
  182. $purge = $my->cfg_value;
  183. } else {
  184. // if no value set, default is 7 days
  185. $purge = 7;
  186. }
  187. // calculation of past date
  188. $past = date( 'Y-m-d H:i:s', time() - $purge * 60 * 60 * 24 );
  189. // if purge value is not 0, then allow purging of old messages
  190. if ($purge != 0) {
  191. // purge old messages at day set in message configuration
  192. $query = "DELETE FROM #__messages"
  193. . "\n WHERE date_time < " . $database->Quote( $past )
  194. . "\n AND user_id_to = " . (int) $my->id
  195. ;
  196. $database->setQuery( $query );
  197. if (!$database->query()) {
  198. echo $database->stderr();
  199. }
  200. }
  201. /** cannot using mosredirect as this stuffs up the cookie in IIS */
  202. // redirects page to admin homepage by default or expired page
  203. echo "<script>document.location.href='$expired';</script>\n";
  204. exit();
  205. } else {
  206. mosErrorAlert("Incorrect Username, Password, or Access Level. Please try again", "document.location.href='index.php?mosmsg=Incorrect Username, Password, or Access Level. Please try again'");
  207. }
  208. } else {
  209. initGzip();
  210. $path = $mosConfig_absolute_path . '/administrator/templates/' . $mainframe->getTemplate() . '/login.php';
  211. require_once( $path );
  212. doGzip();
  213. }
  214. ?>