<?php
/*
乘风下载管理系统
作者QQ：178575
作者Email：yliangcf@163.com
作者网站：http://www.qqcf.com
详细简介：http://www.qqcf.com/cfdown.htm
上面有程序在线演示，安装演示，使用疑难解答，最新版本下载等内容
因为这些内容可能时常更新，就没有放在程序里，请自己上网站查看
*/
?>
<?php
header("content-Type: text/html; charset=utf-8");

require '../conn.php';
require '../config.php';
require '../include/myfunction.php';
require '../include/getcookie.php';

$action = isset($_GET["action"]) ? chkstr($_GET["action"],1) : "";
$idstr = isset($_GET["idstr"]) ? chkstr($_GET["idstr"],1) : AlertUrl('缩短网址不能为空',"../");

//密码验证
if($action=="downloginsave"){
	$pwd=ChkStr(trim($_POST["pwd"]),1);
	$ly=ChkStr($_POST["ly"],1);

	$Sql="Select * From cfdown_info where idstr='$idstr' and pwd='$pwd'";
	$Result=mysql_query($Sql);
	if(!$Rs=mysql_fetch_assoc($Result)) AlertRef("提取码错误!");
	
	//此文件输入提取码成功以后,此提取码保留一天状态,加系统安全码加密防止猜解其它文件
	setcookie("CFDownIDStr_".$idstr, md5($idstr.$syscode), time()+86400,"/");
	
	$downurl="./$idstr";
	header("Location: $downurl");
	exit;
}


$ip=empty($_SERVER["HTTP_X_FORWARDED_FOR"])?ChkStr($_SERVER["REMOTE_ADDR"],1):ChkStr($_SERVER["HTTP_X_FORWARDED_FOR"],1);

if($_COOKIE["CFDownIDStr_Ly_".$idstr]==""){
 $ly=ChkStr($_SERVER["HTTP_REFERER"],1);
 setcookie("CFDownIDStr_Ly_".$idstr, $ly, time()+86400,"/");
}else{
 $ly=$_COOKIE["CFDownIDStr_Ly_".$idstr];
}

$Sql="Select * From cfdown_info where idstr='$idstr'";
$Result=mysql_query($Sql);
if(!$Rs=mysql_fetch_assoc($Result)) exit('记录不存在<meta http-equiv=refresh content=3;url=http://www.qqcf.com/>');
$id=$Rs['id'];
$pwd=$Rs['pwd'];
$downurl=$Rs['downurl'];

if($Rs['infokeyword']=="")
	$infokeyword=$Rs['title'];
else
	$infokeyword=$Rs['infokeyword'];

if($Rs['infodesc']=="")
	$infodesc=$Rs['title'];
else
	$infodesc=$Rs['infodesc'];
?>

<!DOCTYPE html>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<meta name="keywords" content="<?php echo $infokeyword?>" />
	<meta name="description" content="<?php echo $infodesc?>" />
	<meta charset="utf-8">
	<title><?php echo $Rs['title']?></title>
	<link rel="stylesheet" href="../images/style2.css" />
	<script src="../js/jquery.min.js"></script>
</head>
<body>

<div class="navbar">
	<div class="navbar-inner">
		<div class="container">
			<div class="nav">
				<li><a href="../">首页</a></li>

			</div>
			<div class="navr">

			<?php if ($_COOKIE['cfdownadmin']!="") echo '<a href="../admin/">登录</a>';?>
			</div>
		</div>
	</div>
</div>
<style>
#common_content_main{background:#fff;position:relative;}
.common_content_main .yanshi_xiazai{margin-top:18px;margin-bottom:8px;}
.common_content_main .yanshi_xiazai a{font-size:16px;padding:10px 20px;margin-right:20px;background:#2DBFBE;color:#fff;}
.common_content_main .yanshi_xiazai a:hover{background:#FF6263;}
</style>

<div class="container">       
	<div class="hero-unit">

<?php 
//不需要内部提取码或已经用提取码登录了时
if($pwd==""||$_COOKIE["CFDownIDStr_".$idstr]==md5($idstr.$syscode)){


//打开了下载页时才进行统计,如果是搜索引擎统计也统计
$agentstr=$_SERVER['HTTP_USER_AGENT'];
if(preg_match("/(Googlebot|Msnbot|YodaoBot|Sosospider|baiduspider|google|baidu|yahoo|sogou|bing|coodir|soso|youdao|zhongsou|slurp|ia_archiver|scooter|spider|webcrawler|OutfoxBot)/i", $agentstr)){
	$searchbot=1;
	
	$Sql="update cfdown_info set searchbotnum=searchbotnum+1,lasttime=NOW() where id=$id";
	mysql_query($Sql);

    $Sql="update cfdown_count_day set searchbotnum=searchbotnum+1 where infoid=$id and TO_DAYS(NOW())-TO_DAYS(adddate)=0";
	mysql_query($Sql);
	if(mysql_affected_rows()==0){
		$Sql="insert into cfdown_count_day (infoid,searchbotnum,adddate) values ($id,1,DATE_FORMAT(NOW(),'%Y-%m-%d'))";
		mysql_query($Sql);
	}
}else{
	$searchbot=0;
	
    $Sql="update cfdown_info set viewnum=viewnum+1,lasttime=NOW() where id=$id";
	mysql_query($Sql);

	$Sql="update cfdown_count_day set viewnum=viewnum+1 where infoid=$id and TO_DAYS(NOW())-TO_DAYS(adddate)=0";
	mysql_query($Sql);
	if(mysql_affected_rows()==0){
		$Sql="insert into cfdown_count_day (infoid,viewnum,adddate) values ($id,1,DATE_FORMAT(NOW(),'%Y-%m-%d'))";
		mysql_query($Sql);
	}
}



$Sql="Select ifnull(max(myid),0) myid From cfdown_visit_last";
$Result=mysql_query($Sql);
$Rs2=mysql_fetch_assoc($Result);
$myid=$Rs2['myid'];


$Sql="update cfdown_visit_last set myid=".($myid+ 1).",numtype=1,ip='$ip',ly='$ly',infoid=$id,searchbot=$searchbot,agentstr='$agentstr',addtime='".date("Y-m-d H:i:s")."' where myid = ".($myid - 10000 + 1);

mysql_query($Sql);
if(mysql_affected_rows()==0){
	$Sql="insert into cfdown_visit_last (myid,numtype,ip,ly,infoid,searchbot,agentstr,addtime) values (".($myid+1).",1,'$ip','$ly',$id,$searchbot,'$agentstr','".date("Y-m-d H:i:s")."')";
	mysql_query($Sql);
}
?>
<center><b><?php echo $Rs['title']?></b>
<div class="common_content_main">
	<p class="yanshi_xiazai">

<a href="down.php?idstr=<?php echo $idstr?>&downurl=<?php echo $downurl;//加文件名是防止迅雷类的工具下载时文件为down.php?>" target="_black">下载资源</a>
<?php if($Rs["downsite"]==0&&$Rs["outpwd"]!="") echo "<br>提取码:".$Rs["outpwd"];?>
	</p>
</div>
</center><br />


文件名称：<?php echo $Rs['title']?><br />
资源大小：<?php echo $Rs['filesize']?><br />
文件标签：<?php echo $Rs['infolabel']?><br />
发布日期：<?php echo date('Y-m-d',strtotime($Rs['addtime']))?><br />
资源介绍：<br /><?php echo $Rs['content']?><br />
<?php }?>


<?php if($pwd!=""&&$_COOKIE["CFDownIDStr_".$idstr]!=md5($idstr.$syscode)){?>
<script>
$(function(){
	
$("#down").click(function(){

if($("#pwd").val()==""){
 alert('请输入提取码');
 return false;
}

});

});
</script>

<center><b><?php echo $Rs['title']?></b>
<div class="common_content_main">
	<p class="yanshi_xiazai">

<form id="downlogin" name="downlogin" method="post" action="<?php echo HttpPath(6)?>?action=downloginsave&idstr=<?php echo $idstr;?>">
请输入提取码：
<input name="pwd" type="text" id="pwd" size="20">
<?php
if($_COOKIE["CFDownIDStr_Ly_".$idstr]=="")
$ly=$_SERVER["HTTP_REFERER"];
setcookie("CFDownIDStr_Ly_".$idstr, $ly, time()+86400,"/");
?>
<input name="ly" type="hidden" value="<?php echo $ly;?>"> 
<input type="submit" name="Submit3322" value="提取文件" class="btn" id="down" />
</form>
	
	</p>
</div>
</center><br />
</form>
<?php }?>


</div>
</div>


	</div>
</div>
<div class="scf-footer">
<ul class="scf-link-list">合作网站：
<li class="last"><a href="http://www.qqcf.com/" target="_blank">乘风原创程序</a></li>
</ul><p>Copyright <?php echo strftime("%Y",time());?> <a href="http://www.qqcf.com/" target="_blank">乘风下载系统</a>. All Rights Reserved. <a href="http://www.qqcf.com/" target="_blank">乘风</a> 版权所有</div>

</body>
</html>