PageRenderTime 46ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/01.Source/01.CORE/includes/core/admin_login.php

http://creative-portal.googlecode.com/
PHP | 220 lines | 194 code | 19 blank | 7 comment | 30 complexity | 0852b65969c380d062ea7140270cd0a6 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. <?php
  2. /**
  3. * @Project NUKEVIET 3.0
  4. * @Author VINADES.,JSC (contact@vinades.vn)
  5. * @copyright 2009
  6. * @createdate 12/30/2009 1:31
  7. */
  8. if ( ! defined( 'NV_MAINFILE' ) ) die( 'Stop!!!' );
  9. if ( ! nv_admin_checkip() )
  10. {
  11. nv_info_die( $global_config['site_description'], $lang_global['site_info'], sprintf( $lang_global['admin_ipincorrect'], $client_info['ip'] ) . "<META HTTP-EQUIV=\"refresh\" content=\"5;URL=" . $global_config['site_url'] . "\" />" );
  12. }
  13. if ( ! nv_admin_checkfirewall() )
  14. {
  15. // remove non US-ASCII to respect RFC2616
  16. $server_message = preg_replace( '/[^\x20-\x7e]/i', '', $lang_global['firewallsystem'] );
  17. if ( empty( $server_message ) )
  18. {
  19. $server_message = "Administrators Section";
  20. }
  21. header( 'WWW-Authenticate: Basic realm="' . $server_message . '"' );
  22. header( NV_HEADERSTATUS . ' 401 Unauthorized' );
  23. if ( php_sapi_name() !== 'cgi-fcgi' )
  24. {
  25. header( 'status: 401 Unauthorized' );
  26. }
  27. nv_info_die( $global_config['site_description'], $lang_global['site_info'], $lang_global['firewallincorrect'] . "<META HTTP-EQUIV=\"refresh\" content=\"5;URL=" . $global_config['site_url'] . "\" />" );
  28. }
  29. $error = "";
  30. $login = "";
  31. $array_gfx_chk = array(
  32. 1, 5, 6, 7
  33. );
  34. if ( in_array( $global_config['gfx_chk'], $array_gfx_chk ) )
  35. {
  36. $global_config['gfx_chk'] = 1;
  37. }
  38. else
  39. {
  40. $global_config['gfx_chk'] = 0;
  41. }
  42. $admin_login_redirect = $nv_Request->get_string( 'admin_login_redirect', 'session', '' );
  43. if ( $nv_Request->isset_request( 'nv_login,nv_password', 'post' ) )
  44. {
  45. $nv_username = filter_text_input( 'nv_login', 'post', '', '', 100 );
  46. $nv_password = filter_text_input( 'nv_password', 'post', '', '', 50 );
  47. if ( $global_config['gfx_chk'] == 1 )
  48. {
  49. $nv_seccode = filter_text_input( 'nv_seccode', 'post', '' );
  50. }
  51. if ( empty( $nv_username ) )
  52. {
  53. $error = $lang_global['nickname_empty'];
  54. }
  55. elseif ( empty( $nv_password ) )
  56. {
  57. $error = $lang_global['password_empty'];
  58. }
  59. elseif ( $global_config['gfx_chk'] == 1 and ! nv_capcha_txt( $nv_seccode ) )
  60. {
  61. $error = $lang_global['securitycodeincorrect'];
  62. }
  63. else
  64. {
  65. if ( defined( 'NV_IS_USER_FORUM' ) )
  66. {
  67. define( 'NV_IS_MOD_USER', true );
  68. require_once ( NV_ROOTDIR . '/' . DIR_FORUM . '/nukeviet/login.php' );
  69. }
  70. $userid = 0;
  71. $sql = "SELECT userid, username, password FROM `" . NV_USERS_GLOBALTABLE . "` WHERE md5username ='" . md5( $nv_username ) . "'";
  72. $result = $db->sql_query( $sql );
  73. if ( $db->sql_numrows( $result ) == 1 )
  74. {
  75. $row = $db->sql_fetchrow( $result );
  76. if ( $row['username'] == $nv_username and $crypt->validate( $nv_password, $row['password'] ) )
  77. {
  78. $userid = $row['userid'];
  79. }
  80. }
  81. $error = $lang_global['loginincorrect'];
  82. if ( $userid > 0 )
  83. {
  84. $query = "SELECT t1.admin_id as admin_id, t1.lev as admin_lev, t1.last_agent as admin_last_agent, t1.last_ip as admin_last_ip, t1.last_login as admin_last_login, t2.password as admin_pass FROM `" . NV_AUTHORS_GLOBALTABLE . "` AS t1 INNER JOIN `" . NV_USERS_GLOBALTABLE . "` AS t2 ON t1.admin_id = t2.userid WHERE t1.admin_id = " . $userid . " AND t1.lev!=0 AND t1.is_suspend=0 AND t2.active=1";
  85. $result = $db->sql_query( $query );
  86. $numrows = $db->sql_numrows( $result );
  87. if ( $numrows == 1 )
  88. {
  89. $row = $db->sql_fetchrow( $result );
  90. $db->sql_freeresult( $result );
  91. $current_login = NV_CURRENTTIME;
  92. $admin_id = intval( $row['admin_id'] );
  93. $admin_lev = intval( $row['admin_lev'] );
  94. $agent = substr( NV_USER_AGENT, 0, 254 );
  95. $checknum = nv_genpass( 10 );
  96. $checknum = $crypt->hash( $checknum );
  97. $array_admin = array(
  98. 'admin_id' => $admin_id, 'checknum' => $checknum, 'current_agent' => $agent, 'last_agent' => $row['admin_last_agent'], 'current_ip' => $client_info['ip'], 'last_ip' => $row['admin_last_ip'], 'current_login' => $current_login, 'last_login' => intval( $row['admin_last_login'] )
  99. );
  100. $admin_serialize = serialize( $array_admin );
  101. $query = $db->constructQuery( "UPDATE `" . NV_AUTHORS_GLOBALTABLE . "` SET `check_num` = [s], `last_login` = [d], `last_ip` = [s], `last_agent` = [s] WHERE `admin_id`=[d]", $checknum, $current_login, $client_info['ip'], $agent, $admin_id );
  102. $db->sql_query( $query );
  103. $nv_Request->set_Session( 'admin', $admin_serialize );
  104. $nv_Request->set_Session( 'online', '1|' . NV_CURRENTTIME . '|' . NV_CURRENTTIME . '|0' );
  105. define( 'NV_IS_ADMIN', true );
  106. $redirect = NV_BASE_SITEURL . NV_ADMINDIR;
  107. if ( ! empty( $admin_login_redirect ) )
  108. {
  109. $redirect = $admin_login_redirect;
  110. $nv_Request->unset_request( 'admin_login_redirect', 'session' );
  111. }
  112. $error = "";
  113. nv_info_die( $global_config['site_description'], $lang_global['site_info'], $lang_global['admin_loginsuccessfully'] . "<META HTTP-EQUIV=\"refresh\" content=\"3;URL=" . $redirect . "\" />" );
  114. die();
  115. }
  116. }
  117. }
  118. }
  119. else
  120. {
  121. if ( empty( $admin_login_redirect ) )
  122. {
  123. $nv_Request->set_Session( 'admin_login_redirect', $nv_Request->request_uri );
  124. }
  125. $nv_username = "";
  126. }
  127. if ( file_exists( NV_ROOTDIR . "/language/" . NV_LANG_INTERFACE . "/admin_global.php" ) )
  128. {
  129. require_once ( NV_ROOTDIR . "/language/" . NV_LANG_INTERFACE . "/admin_global.php" );
  130. }
  131. elseif ( file_exists( NV_ROOTDIR . "/language/en/admin_global.php" ) )
  132. {
  133. require_once ( NV_ROOTDIR . "/language/en/admin_global.php" );
  134. }
  135. $info = ( ! empty( $error ) ) ? '<div class="error">' . $error . '</div>' : '<div class="normal">' . $lang_global['logininfo'] . '</div>';
  136. $size = @getimagesize( NV_ROOTDIR . '/images/' . $global_config['site_logo'] );
  137. $dir_template = "";
  138. if ( file_exists( NV_ROOTDIR . "/themes/" . $global_config['admin_theme'] . "/system/login.tpl" ) )
  139. {
  140. $dir_template = NV_ROOTDIR . "/themes/" . $global_config['admin_theme'] . "/system";
  141. }
  142. else
  143. {
  144. $dir_template = NV_ROOTDIR . "/themes/admin_default/system";
  145. $global_config['admin_theme'] = "admin_default";
  146. }
  147. $xtpl = new XTemplate( "login.tpl", $dir_template );
  148. $xtpl->assign( 'CHARSET', $global_config['site_charset'] );
  149. $xtpl->assign( 'SITE_NAME', $global_config['site_name'] );
  150. $xtpl->assign( 'PAGE_TITLE', $lang_global['admin_page'] );
  151. $xtpl->assign( 'ADMIN_THEME', $global_config['admin_theme'] );
  152. $xtpl->assign( 'SITELANG', NV_LANG_INTERFACE );
  153. $xtpl->assign( 'NV_BASE_SITEURL', NV_BASE_SITEURL );
  154. $xtpl->assign( 'NV_BASE_ADMINURL', NV_BASE_ADMINURL );
  155. $xtpl->assign( 'CHECK_SC', ( $global_config['gfx_chk'] == 1 ) ? 1 : 0 );
  156. $xtpl->assign( 'LOGIN_TITLE', $lang_global['adminlogin'] );
  157. $xtpl->assign( 'LOGIN_INFO', $info );
  158. $xtpl->assign( 'N_LOGIN', $lang_global['nickname'] );
  159. $xtpl->assign( 'N_PASSWORD', $lang_global['password'] );
  160. $xtpl->assign( 'SITEURL', $global_config['site_url'] );
  161. $xtpl->assign( 'N_SUBMIT', $lang_global['loginsubmit'] );
  162. $xtpl->assign( 'LOGIN_ERROR_SECURITY', addslashes( sprintf( $lang_global['login_error_security'], NV_GFX_NUM ) ) );
  163. $xtpl->assign( 'V_LOGIN', $nv_username );
  164. $xtpl->assign( 'LANGINTERFACE', $lang_global['langinterface'] );
  165. $xtpl->assign( 'LOGO_SRC', NV_BASE_SITEURL . "images/" . $global_config['site_logo'] );
  166. $xtpl->assign( 'LOGO_WIDTH', $size[0] );
  167. $xtpl->assign( 'LOGO_HEIGHT', $size[1] );
  168. $xtpl->assign( 'LANGLOSTPASS', $lang_global['lostpass'] );
  169. $xtpl->assign( 'LINKLOSTPASS', NV_BASE_SITEURL . "index.php?" . NV_LANG_VARIABLE . "=" . $global_config['site_lang'] . "&amp;" . NV_NAME_VARIABLE . "=users&amp;" . NV_OP_VARIABLE . "=lostpass" );
  170. if ( $global_config['gfx_chk'] == 1 )
  171. {
  172. $xtpl->parse( 'main.jscaptcha' );
  173. $xtpl->assign( 'CAPTCHA_REFRESH', $lang_global['captcharefresh'] );
  174. $xtpl->assign( 'CAPTCHA_REFR_SRC', NV_BASE_SITEURL . "images/refresh.png" );
  175. $xtpl->assign( 'N_CAPTCHA', $lang_global['securitycode'] );
  176. $xtpl->assign( 'GFX_NUM', NV_GFX_NUM );
  177. $xtpl->assign( 'GFX_WIDTH', NV_GFX_WIDTH );
  178. $xtpl->assign( 'GFX_HEIGHT', NV_GFX_HEIGHT );
  179. $xtpl->parse( 'main.captcha' );
  180. }
  181. if ( $global_config['lang_multi'] == 1 )
  182. {
  183. foreach ( $global_config['allow_adminlangs'] as $lang_i )
  184. {
  185. if ( file_exists( NV_ROOTDIR . "/language/" . $lang_i . "/global.php" ) and file_exists( NV_ROOTDIR . "/language/" . $lang_i . "/admin_global.php" ) )
  186. {
  187. $xtpl->assign( 'LANGOP', NV_BASE_ADMINURL . "index.php?langinterface=" . $lang_i );
  188. $xtpl->assign( 'LANGTITLE', $lang_global['langinterface'] );
  189. $xtpl->assign( 'SELECTED', ( $lang_i == NV_LANG_INTERFACE ) ? "selected='selected'" : "" );
  190. $xtpl->assign( 'LANGVALUE', $language_array[$lang_i]['name'] );
  191. $xtpl->parse( 'main.lang_multi.option' );
  192. }
  193. }
  194. $xtpl->parse( 'main.lang_multi' );
  195. }
  196. $xtpl->parse( 'main' );
  197. include ( NV_ROOTDIR . "/includes/header.php" );
  198. $xtpl->out( 'main' );
  199. include ( NV_ROOTDIR . "/includes/footer.php" );
  200. die();
  201. ?>