- <?php
- /**
- * 後臺登陸
- *
- * @version $Id: login.php 1 8:48 2010年7月13日Z tianya $
- * @package DedeCMS.Administrator
- * @copyright Copyright (c) 2007 - 2010, DesDev, Inc.
- * @license http://help.dedecms.com/usersguide/license.html
- * @link http://www.dedecms.com
- */
- //引入公共的顯示文件 目錄路徑 域名/include/common.inc.php
- require_once(dirname(__FILE__).'/../include/common.inc.php');
- //引入管理員登陸類 目錄路徑 域名/include/userlogin.class.php
- require_once(DEDEINC.'/userlogin.class.php');
- //判斷$dopost是否爲空 $dopost是點擊提交的發送變量
- if(emptyempty($dopost)) $dopost = '';
- //檢測安裝目錄安全性
- //判斷是否安裝dedecms
- //判斷安裝目錄是否存在
- if( is_dir(dirname(__FILE__).'/../install') )
- {
- //如果安裝之後的install_lock.txt文件不存在
- if(!file_exists(dirname(__FILE__).'/../install/install_lock.txt') )
- {
- //以寫的方式打開install_lock.txt
- //如果無法寫入則執行後面那一句
- $fp = fopen(dirname(__FILE__).'/../install/install_lock.txt', 'w') or die('安裝目錄無寫入權限,無法進行寫入鎖定文件,請安裝完畢刪除安裝目錄!');
- //寫入ok
- fwrite($fp,'ok');
- //關閉文件
- fclose($fp);
- }
- //爲了防止未知安全性問題,強制禁用安裝程序的文件
- //判斷安裝的index.php存在 目錄路徑 域名/install/index.php
- if( file_exists("../install/index.php") ) {
- //rename() 函數重命名文件或目錄。
- /**
- * 若成功,則該函數返回 true。若失敗,則返回 false。
- * 語法
- * rename(oldname,newname,context)
- * 參數 描述
- * oldname 必需。規定要重命名的文件或目錄。
- * newname 必需。規定文件或目錄的新名稱。
- * context 可選。規定文件句柄的環境。context 是可修改流的行爲的一套選項。
- */
- //重命名 目錄路徑 域名/install/index.php 備份文件 域名/install/index.php.bak
- @rename("../install/index.php", "../install/index.php.bak");
- }
- //判斷安裝的module-install.php存在 目錄路徑 域名/install/index.php
- if( file_exists("../install/module-install.php") ) {
- //重命名 目錄路徑 域名/install/module-install.php 備份文件 域名/install/module-install.php.ba
- @rename("../install/module-install.php", "../install/module-install.php.bak");
- }
- //定義文件路徑 目錄路徑 域名/install/index.html
- $fileindex = "../install/index.html";
- //判斷 文件路徑文件是否存在
- if( !file_exists($fileindex) ) {
- //用可寫的方式打開文件
- $fp = @fopen($fileindex,'w');
- //寫入dir
- fwrite($fp,'dir');
- //關閉
- fclose($fp);
- }
- }
- //更新服務器文件 目錄路徑 域名/data/admin/config_update.php
- require_once (DEDEDATA.'/admin/config_update.php');
- //如果 $dopost=='showad'
- if ($dopost=='showad')
- { //引入登陸界面的廣告
- include('templets/login_ad.htm');
- exit;
- }
- //檢測後臺目錄是否更名 GetCurUrl() 獲得當前的腳本網址
- $cururl = GetCurUrl();
- //匹配正則 進行正則表達式匹配。並且只匹配一次
- /**
- * int preg_match( string pattern, string subject [, array matches [, int flags]] )
- * 在 subject 字符串中搜索與pattern給出的正則表達式相匹配的內容。
- * 如果提供了 matches,則其會被搜索的結果所填充。$matches[0] 將包含與整個模式匹配的文本,$matches[1] 將包含與第一個捕獲的括號中的子模式所匹配的文本,以此類推。
- * flags 可以是下列標記:
- * PREG_OFFSET_CAPTURE如果設定本標記,對每個出現的匹配結果也同時返回其附屬的字符串偏移量。注意這改變了返回的數組的值,使其中的每個單元也是一個數組,其中第一項爲匹配字符串,第二項爲其偏移量。本標記自PHP 4.3.0 起可用。
- * flags 參數來自 PHP 4.3.0 起可用。
- * preg_match() 返回 pattern 所匹配的次數。要麼是 0 次(沒有匹配)或 1 次,因爲 preg_match() 在第一次匹配之後將停止搜索。如果出錯 preg_match() 返回FALSE。
- */
- if(preg_match('/dede\/login/i',$cururl))
- {
- $redmsg = '<div class=\'safe-tips\'>您的管理目錄的名稱中包含默認名稱dede,建議在FTP裏把它修改爲其它名稱,那樣會更安全!</div>';
- }
- else
- {
- $redmsg = '';
- }
- //登錄檢測
- $admindirs = explode('/',str_replace("\\",'/',dirname(__FILE__)));
- $admindir = $admindirs[count($admindirs)-1];
- //以下是點擊登陸按鈕的時候執行的
- if($dopost=='login')
- {
- $validate = emptyempty($validate) ? '' : strtolower(trim($validate));
- //獲取驗證碼的session值 GetCkVdValue()
- $svali = strtolower(GetCkVdValue());
- if(($validate=='' || $validate != $svali) && preg_match("/6/",$safe_gdopen)){
- //php版本有bug時候執行
- ResetVdValue();
- ShowMsg('驗證碼不正確!','login.php',0,1000);
- exit;
- } else {
- //new一個登陸的對象
- $cuserLogin = new userLogin($admindir);
- //判斷userid和pwd不爲空
- if(!emptyempty($userid) && !emptyempty($pwd))
- { //checkUser 檢驗用戶是否正確
- $res = $cuserLogin->checkUser($userid,$pwd);
- //success
- if($res==1)
- { // keepUser保持用戶的會話狀態
- $cuserLogin->keepUser();
- if(!emptyempty($gotopage))
- {
- ShowMsg('成功登錄,正在轉向管理管理主頁!',$gotopage);
- exit();
- }
- else
- {
- ShowMsg('成功登錄,正在轉向管理管理主頁!',"index.php");
- exit();
- }
- }
- //error
- else if($res==-1)
- {
- ShowMsg('你的用戶名不存在!',-1,0,1000);
- exit;
- }
- else
- {
- ShowMsg('你的密碼錯誤!',-1,0,1000);
- exit;
- }
- }
- //password empty
- else
- {
- ShowMsg('用戶和密碼沒填寫完整!',-1,0,1000);
- exit;
- }
- }
- }
- //引入登陸模板 目錄路徑 域名/dede/templets/login.htm
- include('templets/login.htm');