<?
include('../../config.inc.php');
$sql="select t_pass,t_name from admin_infos";
$query=mysql_query($sql);
$row=mysql_fetch_array($query);
$t_name=$row['t_name'];
$t_pass=$row['t_pass'];
if($_COOKIE['tj_pass']!=$t_pass){echo "<script>alert('密码过期，请重新登陆！');location.href='../index.php';</script>"; exit;}

//修改管理员密码
if($_GET['type']=='change_pass')
{
	if($_POST['pass']==''){echo "<script>alert('原密码不能为空');history.back();</script>";exit;}
	if($_POST['new_pass']==''){echo "<script>alert('新密码不能为空！');history.back();</script>";exit;}
	if($_POST['new_pass']!=$_POST['re_new_pass']){echo "<script>alert('两次输入的新密码不相同！');history.back();</script>";exit;}
	
	$old_pass=md5(md5($_POST['pass']).'tueur');
	if($old_pass==$t_pass)
	{
		$new_pass=$_POST['new_pass'];
		$new_pass=md5(md5($new_pass).'tueur');
		$sql="update admin_infos set t_pass='$new_pass' where t_name='$t_name'";
		mysql_query($sql);
		echo "<script>alert('修改密码成功，请重新登陆！');location.href='../index.php';</script>";
	}else{echo "<script>alert('原密码错误！');history.back();</script>";}

}

//修改网站LOGO
if($_GET['type']=='change_logo')
{
	if($_POST['logo']==''){echo "<script>alert('LOGO地址不能为空');location.href='../index.php';</script>";exit;}
	$t_logo=$_POST['logo'];
	if(!get_magic_quotes_gpc())
	{
		$t_logo=addslashes($t_logo);
	}
	$sql="update admin_infos set t_logo='$t_logo' where t_name='$t_name'";
	mysql_query($sql);
	echo "<script>alert('LOGO修改成功！');location.href='../index.php';</script>";
}

//修改网站标题和SEO关键词
if($_GET['type']=='change_title')
{
	if($_POST['title']==''){echo "<script>alert('网站标题不能为空');location.href='../index.php';</script>";exit;}
	$t_title=$_POST['title'];
	$t_seo=$_POST['seo'];
	if(!get_magic_quotes_gpc())
	{
		$t_title=addslashes($t_title);
		$t_seo=addslashes($t_seo);
	}
	$sql="update admin_infos set t_title='$t_title',t_seo='$t_seo' where t_name='$t_name'";
	mysql_query($sql);
	echo "<script>alert('修改成功！');location.href='../index.php';</script>";
}

//添加友情链接
if($_GET['type']=='add_link')
{
	if(!$_POST['link_name']||!$_POST['link_url'])
	{echo "<script>alert('链接名称或者地址不能为空！');location.href='../index.php?t=links';</script>";exit;}
	$rank=is_numeric($_POST['rank'])?$_POST['rank']:0;
	$link_name=$_POST['link_name'];
	$link_url=$_POST['link_url'];
	if(!get_magic_quotes_gpc())
	{
		$link_name=addslashes($link_name);
		$link_url=addslashes($link_url);
	}
	$sql="insert into friend_links (id,rank,link_name,link_url) values(NULL,'$rank','$link_name','$link_url')";
	mysql_query($sql);
	echo "<script>alert('添加成功！');location.href='../index.php?t=links';</script>";
}

//修改或删除友情链接
if($_GET['type']=='change_link')
{
	if($_POST['del'])
	{
		$id=$_POST['del'];
		$sql="delete from friend_links where id='$id'";
		mysql_query($sql);
		echo "<script>alert('删除成功！');location.href='../index.php?t=links';</script>";
		exit;
	}
	$id=$_POST['id'];
	$rank=is_numeric($_POST['rank'])?$_POST['rank']:0;
	$link_name=$_POST['link_name'];
	$link_url=$_POST['link_url'];
	if(!get_magic_quotes_gpc())
	{
		$link_name=addslashes($link_name);
		$link_url=addslashes($link_url);
	}
	$sql="update friend_links set rank='$rank',link_name='$link_name',link_url='$link_url' where id='$id'";
	mysql_query($sql);
	echo "<script>alert('修改成功！');location.href='../index.php?t=links';</script>";
}

//修改页头导航条信息
if($_GET['type']=='head_nav')
{
	$t_head_nav=$_POST['t_head_nav'];
	if(!get_magic_quotes_gpc())
	{
		$t_head_nav=addslashes($t_head_nav);
	}
	$sql="update admin_infos set t_head_nav='$t_head_nav' where t_name='$t_name'";
	mysql_query($sql);
	echo "<script>alert('页头信息修改成功！');location.href='../index.php?t=header';</script>";
}

//修改页头广告信息
if($_GET['type']=='change_ad')
{
	$t_ad=$_POST['t_ad'];
	if(!get_magic_quotes_gpc())
	{
		$t_ad=addslashes($t_ad);
	}
	$sql="update admin_infos set t_ad='$t_ad' where t_name='$t_name'";
	mysql_query($sql);
	echo "<script>alert('广告信息修改成功！');location.href='../index.php?t=header';</script>";
}

//修改页底说明信息
if($_GET['type']=='footer_info')
{
	if(!$_POST['footer_info']){echo "<script>alert('页底说明信息不能为空');location.href='../index.php?t=footer';</script>";exit;}
	$t_footer_info=$_POST['footer_info'];
	if(!get_magic_quotes_gpc())
	{
		$t_footer_info=addslashes($t_footer_info);
	}
	$sql="update admin_infos set t_footer_info='$t_footer_info' where t_name='$t_name'";
	mysql_query($sql);
	echo "<script>alert('页底信息修改成功！');location.href='../index.php?t=footer';</script>";
}

//修改站长统计代码
if($_GET['type']=='statistics')
{
	$t_statistics=$_POST['statistics'];
	if(!get_magic_quotes_gpc())
	{
		$t_statistics=addslashes($t_statistics);
	}
	$sql="update admin_infos set t_statistics='$t_statistics' where t_name='$t_name'";
	mysql_query($sql);
	echo "<script>alert('站长统计代码修改成功！');location.href='../index.php?t=footer';</script>";
}

//更新三个月前的黑页信息
if($_GET['type']=='update')
{
	$dateline=60*60*24*80;
	$dateline=time()-$dateline;
	$sql="update hacked_pages set tj_domain='' where tj_date<$dateline";
	mysql_query($sql);
	echo "<script>alert('数据更新成功！');location.href='../index.php?t=update';</script>";
}

//更新三个月前的黑页信息
if($_GET['type']=='ip_del')
{
	if(!$_POST['ip'])
	{echo "<script>alert('IP地址不能为空！');location.href='../index.php?t=ip_del';</script>";exit;}
	echo "如果黑页数量过多，处理速度可能会比较慢，请稍等一会......";
	$ip=$_POST['ip'];
	if(!get_magic_quotes_gpc())
	{
		$ip=addslashes($ip);
	}
	$sql="select id from hacked_page where tj_ip='$ip'";
	@$query=mysql_query($sql);
    while(@$row=mysql_fetch_array($query))
	{
		$id=$row['id'];
		$path='../../hacked_pages/'.md5($id).'.html';
		@unlink($path);
	}
	$sql="delete from hacked_pages where tj_ip=$ip";
	@mysql_query($sql);
	echo "<script>alert('此ip提交的黑页已全部删除！');location.href='../index.php?t=ip_del';</script>";
}
?>