<?php
/*
'**************************************************************************************************
' 软件名称: 搜一次 Content Management System
' 版本编号: Version 1.X
' 官方网站: http://www.syccms.com
' 官方论坛：http://bbs.syccms.com
' 版权所有: 搜一次运营团队
' 法律顾问: 杭州市元茂律师事务所 严飞律师
' 郑重声明:
'    1、任何个人或组织不得在未经授权的情况下删除、修改、拷贝本软件及其他副本上一切关于版权的信息；
'    2、搜一次网络事业部保留此软件的法律追究权利
'**************************************************************************************************
*/
if(!is_writable(session_save_path())){
	$cache_path = dirname(dirname(__FILE__)).'/cache/';
	if(!is_writable($cache_path)){
		exit('session缓存目录'.session_save_path().'不可写，请联系主机服务商解决');
	} 
	session_save_path($cache_path);
}
session_start();
if (isset($_SESSION['S_AdminID']) && $_SESSION['S_ExpireTS']<time()) {
	exit("<script type='text/javascript'>window.location.href='index.php';</script>");
}
include "../include/conn.php";
include "../include/function.php";
include "admin_version.php";

$action=SafeRequest("action");
if($action=="log"){
	$S_Name=SafeRequest("S_AdminUserName","post");
	$S_Pass=md5(SafeRequest("S_AdminPassWord","post"));
	$S_Code=SafeRequest("Codes","post");
	$logtime=date("Y-m-d");
	$UIP=httpxaddr();
	if($S_Code!=S_CheckCode){
		die("<script>alert('对不起,你输入的认证码错误！');history.back();</script>");
		}
	$sql= "Select * from s_admin where S_AdminUserName='".$S_Name."' and S_AdminPassWord='".$S_Pass."' and S_IsLock=0 GROUP BY S_ID";
	$row = $db->getrow($sql);
	if ($row) {
		$S_ID = $row['S_ID'];
		$s_preip=$row["S_LoginIP"];
		$sql="update s_admin set S_LoginNum =S_LoginNum +1,S_PreIP='".$s_preip."',S_LoginIP='".$UIP."',S_LastLogin ='".$logtime."' where S_ID='".$S_ID."'";
		$db->query($sql);
		 $_SESSION['S_SessionID'] = session_id();
		 $_SESSION['S_ExpireTS'] = time()+3600;
		 $_SESSION['S_AdminID'] = $row['S_ID'];
		 $_SESSION['S_AdminUserName'] = $row['S_AdminUserName'];
		 $_SESSION['S_Permission'] = $row['S_Permission'];
		 $_SESSION['S_UIP'] = $UIP;
		 $_SESSION['S_PreIP'] = $row['S_PreIP'];
		 exit("<script>window.location.href='index.php';</script>");		
	} else {
		die("<script>alert('登录失败请确认输入的是正确信息以及帐号是否开启!');history.back();</script>");
	}
}
elseif($action=="logout"){
	unset($_SESSION);session_destroy();
    die("<script>window.parent.window.location.href='admin_login.php'</script>");
	}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<link  href="images/style.css" rel="stylesheet" type="text/css" />
<title>搜一次后台管理</title>
<script type="text/javascript" language="javascript">var tentpath='<?php echo S_SitePath?>';</script>
<script src="js/jquery.js"></script>
<script language="javascript" src="js/alerts.js"></script>
<link type="text/css" href="images/alerts.css" rel="stylesheet" media="screen">
<script language="javascript">
  function CheckLogin(){
	  if (this.form1.S_AdminUserName.value==""){
		  document.getElementById("infos").innerHTML="对不起，用户名不能为空！";
		  return false;
		  }
	 else if(this.form1.S_AdminPassWord.value==""){
          document.getElementById("infos").innerHTML="对不起，密码不能为空！";
		  return false;
		 }	
	 else if(this.form1.Codes.value==""){
		  document.getElementById("infos").innerHTML="对不起，认证码不能为空！";
		  return false;
		}
   else{
	   return true;
	   }
	  
	  }
</script>
</head>
<body bgcolor="#00389A" scroll=no>
<form method="post" name="form1" action="?action=log">
  <div id="login_index">
    <div id="login_main">
       <div id="login_1"></div>
       <div id="login_2">
          <div id="login_2_1"></div>
          <div id="login_2_2">
             <div id="login_2_2_1"></div>
             <div id="login_2_2_2">
               <input type="text" name="S_AdminUserName" id="login_input1" size="24">
             </div>
             <div id="login_2_2_3">
               <input type="PassWord" name="S_AdminPassWord" id="login_input2" size="24" >
             </div>
             <div id="login_2_2_4">
               <input type="PassWord" name="Codes" id="login_input3" size="24" >
             </div>
             <div id="login_2_2_5"><div id="infos"></div></div>
          </div>
          <div id="login_2_3">
            <input type="image" src="images/login_img/login_bt.jpg" id="lo_btn" onClick="return CheckLogin()">
          </div>
          <div id="login_2_4"></div>
       </div>
      <div id="login_3"></div>
      </div>
  </div></form> 
</body>
<?php 
function httpxaddr() {
	$onlineip = '';
	if(getenv('HTTP_CLIENT_IP') && strcasecmp(getenv('HTTP_CLIENT_IP'), 'unknown')) {
		$onlineip = getenv('HTTP_CLIENT_IP');
	}elseif(getenv('HTTP_X_FORWARDED_FOR') && strcasecmp(getenv('HTTP_X_FORWARDED_FOR'), 'unknown')) {
		$onlineip = getenv('HTTP_X_FORWARDED_FOR');
	} elseif(getenv('REMOTE_ADDR') && strcasecmp(getenv('REMOTE_ADDR'), 'unknown')) {
		$onlineip = getenv('REMOTE_ADDR');
	} elseif(isset($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] && strcasecmp($_SERVER['REMOTE_ADDR'], 'unknown')) {
		$onlineip = $_SERVER['REMOTE_ADDR'];
	}
	return $onlineip;
} 
?>
</html>