<?php


$timestamp=time();

if (empty($username)) $username=$HTTP_COOKIE_VARS['liuxingid'];

if (empty($password)) $password=$HTTP_COOKIE_VARS['liuxingpwd'];


if(!checkpass($username,$password)) {
admintitle();

adminlogin();

	exit;
}
if(checkpass($username,$password)) 
{$login_status=1;
$lxpwd=md5($password);}
$checkpower=checkpower($username,$password);



setcookie("liuxingid",$username,"0");

setcookie("liuxingpwd",$password,"0");

if ($out=="quit") {
setcookie("liuxingid","");
setcookie("liuxingpwd","");
}

//-------------------------------------------



$tab_top="<table width=92% align=center cellspacing=0 cellpadding=0 bgcolor=333333>

	    <tr><td>

	    <table width=100% cellspacing=1 cellpadding=3>

	    <tr><td bgcolor=EEEEE8>

	<font face=verdana>";

$tab_bottom="</font>

	</td></tr></table>

	</td></tr></table>";



admintitle();



//+-----------------------------------------------------------------------

//-----------------functions-------------------------

function checkpass($username,$password){
	global $checkpower;

	   if (!$username) return 0;
	   if (!$password) return 0;

	if (!file_exists("user/$username.php") || strpos($username,"..")!==false) return 0;

	$useinfo=explode("|",readfrom("user/$username.php"));

	$userpwd=$useinfo[2];

	if ($password==$userpwd) return 1; else return 0;
	   $checkpower=$useinfo[3];


}
function checkpower($username,$password){
	   if (!$username) return 0;
	   if (!$password) return 0;

	if (!file_exists("user/$username.php") || strpos($username,"..")!==false) return 0;

	$useri=explode("|",readfrom("user/$username.php"));	
	 if ($password==$useri[2])  return $useri[3]; else return 0; 

}

function adminlogin() {

global $thisprog;

print <<<EOT

    <tr><td bgcolor=#80809b colspan=2><font color=#FFFFFF>

    <b>欢迎来到流星のstudy信息发布超级管理程式</b>

    </td></tr>

    <tr>

    <td bgcolor=#EEEEEE valign=middle colspan=2 align=center><font color=#333333><b>请输入您的用户名、密码登陆</b></font></td></tr>

    <form action="$thisprog" method="post">

    <tr><td>

<br>

   <table width=300 align=center cellspacing=1 cellpadding=0 bgcolor=333333>

    <tr><td>

    <table width=100% cellspacing=0 cellpadding=3>

    <tr bgcolor=EEEEE8>

    <font face=verdana>

    <td valign=middle width=40% align=right><font color=#555555>请输入管理员ID</font></td>

    <td valign=middle><input type=text name="username" ></td></tr>

    <tr bgcolor=EEEEE8>

    <td valign=middle width=40% align=right><font color=#555555>请输入管理员密码</font></td>

    <td valign=middle><input type=password name="password"></td></tr>

 </font>

    </tr></table>

    </td></tr></table>



</td></tr>

    <tr bgcolor=FFFFFF>

    <td valign=middle colspan=2 align=center><input type=submit name="submit" value="登 陆"></td></tr></form>

    <tr>

    <td bgcolor=#FFFFFF valign=middle align=left colspan=2><font color=#555555>

    <blockquote><b>请注意</b><p>在进入管理，请确定你的浏览器打开了 Cookie 选项。<br> Cookie 只会存在于当前的浏览器进程中。为了安全起见，当你关闭了浏览器后，Cookie 会失效并被自动删除。<p><p><hr><b>程式： <a href="mailto:wxjhope@163.com">快乐的流星</a> <a href="http://www.liuxing.40it.com" target=_blank>信息发布管理程式</a></b>

    </blockquote>

    </td></tr>

    </table></td></tr></table>

    </td></tr></table></body></html>

EOT;

}

function admintitle() {
global $checkpower,$login_status,$lxpwd;

print <<<EOT

    <html>

    <head>

    <title>流星流言本管理程式</title>

    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">

    <style type="text/css">

    BODY { COLOR: #3F3849; FONT-FAMILY: Verdana,Arial; FONT-SIZE: 9pt;

	SCROLLBAR-BASE-COLOR:  #666688;

	SCROLLBAR-ARROW-COLOR: #D3D3FF;

	SCROLLBAR-HIGHLIGHT-COLOR: #444466;

}

A:LINK		{COLOR: #3F3849; TEXT-DECORATION: none}

A:VISITED	{COLOR: #3F3849; TEXT-DECORATION: none}

/* hover color for links (Internet Explorer only) */

A:HOVER		{COLOR: #F5D300; BACKGROUND-COLOR: #40364d}

A:ACTIVE	{COLOR: #F5D300; BACKGROUND-COLOR: #40364d}

		

		.t     {	LINE-HEIGHT: 1.4}

		TD,SELECT,TEXTAREA,DIV,FORM,OPTION,P{COLOR:333333; FONT-FAMILY: 宋体; FONT-SIZE: 9pt}

		INPUT  {	FONT-FAMILY: 宋体; FONT-SIZE: 9pt; height:22px;	}

    </style>

    </head>

    <body bgcolor=#555570 topmargin=5 leftmargin=5>


    <table width=85% cellpadding=0 cellspacing=1 border=0 bgcolor=#222244 align=center>

    <tr><td>

    <table width=100% cellpadding=0 cellspacing=1 border=0>

    <tr><td width=25% valign=top bgcolor=#FFFFFF>

    <table width=100% cellpadding=6 cellspacing=0 border=0>

    <tr><td bgcolor=#80809b><font color=#FFFFFF>

    <b>管理选项</b>

    </td></tr>

    <tr>

    <td bgcolor=#FFFFFF> <br><br>
※ <a href="admin.php">管理首页</a><br><br>
※ <a href="setoptions.php">基本设置</a><br> <br>
※ <a href=adduser.php>用户管理</a> <br><br>
※ <a href=editmypwd.php>密码修改</a> <br><br>
※ <a href="?out=quit">退出系统</a><br><br>
※ <a href="index.php?admin=$login_status&pwd=$lxpwd" target=_blank>首页消息管理</a><br><br>
<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
   </td></tr>
    <td bgcolor=#FFFFFF>

    <table width=95% align=left cellspacing=0 cellpadding=0 bgcolor=333333>

    <tr><td>

    <table width=100% cellspacing=1 cellpadding=1>

    <tr><td bgcolor=EEEEE8>

版本:流星のstudy<br>
开发:<a href="http://liuxing.40it.com">快乐的流星</a><br>

所有:<a href="http://www.ofstar.com">流星动网</a>

    </td></tr></table>

    </td></tr></table>

    

    </td></tr></table>

    </td><td width=85% valign=top bgcolor=#FFFFFF>

    <table width=100% cellpadding=6 cellspacing=0 border=0>

EOT;

}



///////////////read & write////////////////////



function readfrom($file_name) {
	$filenum=@fopen($file_name,"r");
	@flock($filenum,LOCK_SH);
	$file_data=@fread($filenum,filesize($file_name));
	@fclose($filenum);
	return $file_data;
}
function writeto($file_name,$infoata,$method="w") {
	$filenum=@fopen($file_name,$method);
	flock($filenum,LOCK_EX);
	$file_data=fwrite($filenum,$infoata);
	fclose($filenum);
	return $file_data;
}

////////////find out the next available post file name///////////

/////////////////kick out the dangerous Char-/////////



function kick_out($info) {

  $info = str_replace("\t","",$info);

  $info = str_replace("<","&lt;",$info);

  $info = str_replace(">","&gt;",$info);

  $info = str_replace("\r","<br>",$info);

  $info = str_replace("\n","",$info);

  $info = str_replace("|","│",$info);

  $info = str_replace("  "," &nbsp;",$info);

  return $info;

}
