DownSysFun.php 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383
  1. <?php
  2. $DownSys_CheckIp=0; //下载验证码检测用户IP,0为不开启,1为开启
  3. //返回检测IP
  4. function ReturnDownSysCheckIp(){
  5. global $DownSys_CheckIp;
  6. $ip=$DownSys_CheckIp?egetip():'127.0.0.1';
  7. return $ip;
  8. }
  9. //下载软件
  10. function DownSoft($classid,$id,$pathid,$p,$pass){
  11. global $empire,$dbtbpre,$public_r,$level_r,$class_r,$emod_r,$ecms_config;
  12. //验证IP
  13. eCheckAccessDoIp('downinfo');
  14. $id=(int)$id;
  15. $classid=(int)$classid;
  16. $pathid=(int)$pathid;
  17. if(empty($id)||empty($p)||empty($classid))
  18. {
  19. printerror("ErrorUrl","history.go(-1)",1);
  20. }
  21. $p=RepPostVar($p);
  22. $p_r=explode(":::",$p);
  23. $userid=$p_r[0];
  24. $rnd=$p_r[1];
  25. $nockpass=$p_r[2];
  26. //验证码
  27. $cpass=md5(md5($classid."-!ecms!".$id."-!ecms!".$pathid).ReturnDownSysCheckIp()."wm_chief".$public_r[downpass].$userid);
  28. if('dg'.$cpass<>'dg'.$pass)
  29. {
  30. printerror("FailDownpass","history.go(-1)",1);
  31. }
  32. //表不存在
  33. if(empty($class_r[$classid][tbname]))
  34. {
  35. printerror("ExiestSoftid","history.go(-1)",1);
  36. }
  37. $mid=$class_r[$classid][modid];
  38. $tbname=$class_r[$classid][tbname];
  39. $ok=1;
  40. $r=$empire->fetch1("select * from {$dbtbpre}ecms_".$tbname." where id='$id' limit 1");
  41. if(empty($r['id'])||$r['classid']!=$classid)
  42. {
  43. printerror("ExiestSoftid","history.go(-1)",1);
  44. }
  45. //副表
  46. $finfor=$empire->fetch1("select ".ReturnSqlFtextF($mid)." from {$dbtbpre}ecms_".$tbname."_data_".$r[stb]." where id='$r[id]' limit 1");
  47. $r=array_merge($r,$finfor);
  48. //区分下载地址
  49. $path_r=explode("\r\n",$r[downpath]);
  50. if(!$path_r[$pathid])
  51. {
  52. printerror("ExiestSoftid","history.go(-1)",1);
  53. }
  54. $showdown_r=explode("::::::",$path_r[$pathid]);
  55. $downgroup=$showdown_r[2];
  56. //下载权限
  57. if($downgroup)
  58. {
  59. $userid=(int)$userid;
  60. $rnd=RepPostVar($rnd);
  61. $nockpass=RepPostVar($nockpass);
  62. if(!$nockpass)
  63. {
  64. printerror("MustSingleUser","history.go(-1)",1);
  65. }
  66. $cknockpass=qReturnLoginPassNoCK($userid,'',$rnd,0);
  67. if('dg'.$nockpass<>'dg'.$cknockpass)
  68. {
  69. printerror("MustSingleUser","history.go(-1)",1);
  70. }
  71. //取得会员资料
  72. $u=$empire->fetch1("select ".eReturnSelectMemberF('*')." from ".eReturnMemberTable()." where ".egetmf('userid')."='$userid' and ".egetmf('rnd')."='$rnd' limit 1");
  73. if(empty($u['userid']))
  74. {printerror("MustSingleUser","history.go(-1)",1);}
  75. //下载次数限制
  76. $setuserday="";
  77. if($level_r[$u['groupid']]['daydown'])
  78. {
  79. $setuserday=DoCheckMDownNum($userid,$u['groupid']);
  80. }
  81. if($downgroup>0)//会员组
  82. {
  83. if($level_r[$downgroup][level]>$level_r[$u[groupid]][level])
  84. {
  85. printerror("NotDownLevel","history.go(-1)",1);
  86. }
  87. }
  88. else//访问组
  89. {
  90. $vgroupid=0-$downgroup;
  91. $ckvgresult=eMember_ReturnCheckViewGroup($u,$vgroupid);
  92. if($ckvgresult<>'empire.cms')
  93. {
  94. printerror("NotDownLevel","history.go(-1)",1);
  95. }
  96. }
  97. //点数是否足够
  98. $showdown_r[3]=intval($showdown_r[3]);
  99. if($showdown_r[3])
  100. {
  101. //---------是否有历史记录
  102. $bakr=$empire->fetch1("select id,truetime from {$dbtbpre}enewsdownrecord where id='$id' and classid='$classid' and userid='$userid' and pathid='$pathid' and online=0 order by truetime desc limit 1");
  103. if($bakr[id]&&(time()-$bakr[truetime]<=$public_r[redodown]*3600))
  104. {}
  105. else
  106. {
  107. //包月卡
  108. if($u['userdate']-time()>0)
  109. {}
  110. //点数
  111. else
  112. {
  113. if($showdown_r[3]>$u['userfen'])
  114. {
  115. printerror("NotEnoughFen","history.go(-1)",1);
  116. }
  117. //去除点数
  118. $usql=$empire->query("update ".eReturnMemberTable()." set ".egetmf('userfen')."=".egetmf('userfen')."-".$showdown_r[3]." where ".egetmf('userid')."='$userid'");
  119. }
  120. //备份下载记录
  121. $utfusername=$u['username'];
  122. BakDown($classid,$id,$pathid,$userid,$utfusername,$r[title],$showdown_r[3],0);
  123. }
  124. }
  125. //更新用户下载次数
  126. if($setuserday)
  127. {
  128. $usql=$empire->query($setuserday);
  129. }
  130. }
  131. //总下载数据增一
  132. $usql=$empire->query("update {$dbtbpre}ecms_".$class_r[$classid][tbname]." set totaldown=totaldown+1 where id='$id'");
  133. $downurl=stripSlashes($showdown_r[1]);
  134. $downurlr=ReturnDownQzPath($downurl,$showdown_r[4]);
  135. $downurl=$downurlr['repath'];
  136. //防盗链
  137. @include(ECMS_PATH."e/DownSys/class/enpath.php");
  138. $downurl=DoEnDownpath($downurl);
  139. db_close();
  140. $empire=null;
  141. DoTypeForDownurl($downurl,$downurlr['downtype']);
  142. }
  143. //下载操作
  144. function DoTypeForDownurl($downurl,$type=0){
  145. global $public_r;
  146. if($type==1)//meta
  147. {
  148. echo"<META HTTP-EQUIV=\"refresh\" CONTENT=\"0;url=$downurl\">";
  149. }
  150. elseif($type==2)//read
  151. {
  152. QDownLoadFile($downurl);
  153. }
  154. else//header
  155. {
  156. Header("Location:$downurl");
  157. }
  158. exit();
  159. }
  160. //下载
  161. function QDownLoadFile($file){
  162. global $public_r;
  163. if(strstr($file,"\\"))
  164. {
  165. $exp="\\";
  166. }
  167. elseif(strstr($file,"/"))
  168. {
  169. $exp="/";
  170. }
  171. else
  172. {
  173. Header("Location:$file");
  174. exit();
  175. }
  176. if(strstr($file,$exp."e".$exp)||strstr($file,"..")||strstr($file,"?")||strstr($file,"#"))
  177. {
  178. Header("Location:$file");
  179. exit();
  180. }
  181. $efileurl=eReturnFileUrl();
  182. if(strstr($file,$efileurl))
  183. {
  184. $file=str_replace($efileurl,'/d/file/',$file);
  185. }
  186. if(!strstr($file,"://"))
  187. {
  188. if(!file_exists($file))
  189. {
  190. $file=eReturnEcmsMainPortPath().substr($file,1);
  191. }
  192. }
  193. $filename=GetDownurlFilename($file,$exp);
  194. if(empty($filename))
  195. {
  196. Header("Location:$file");
  197. exit();
  198. }
  199. //下载
  200. Header("Content-type: application/octet-stream");
  201. //Header("Accept-Ranges: bytes");
  202. //Header("Accept-Length: ".$filesize);
  203. Header("Content-Disposition: attachment; filename=".$filename);
  204. echo ReadFiletext($file);
  205. }
  206. //取得下载文件名
  207. function GetDownurlFilename($file,$expstr){
  208. $r=explode($expstr,$file);
  209. $count=count($r)-1;
  210. $filename=$r[$count];
  211. return $filename;
  212. }
  213. //----------------------在线电影模型
  214. //取得验证码
  215. function GetOnlinePass(){
  216. global $public_r;
  217. $onlinep=$public_r[downpass]."qweirtydui4opttt.,mvcfvxzzf3dsfm,.dsa";
  218. $r[0]=time();
  219. $r[1]=md5($onlinep.$r[0]);
  220. return $r;
  221. }
  222. //验证验证码
  223. function CheckOnlinePass($onlinetime,$onlinepass){
  224. global $movtime,$public_r;
  225. if($onlinetime+$movtime<time()||$onlinetime>time())
  226. {
  227. exit();
  228. }
  229. $onlinep=$public_r[downpass]."qweirtydui4opttt.,mvcfvxzzf3dsfm,.dsa";
  230. $cpass=md5($onlinep.$onlinetime);
  231. if('dg'.$onlinepass<>'dg'.$cpass)
  232. {
  233. exit();
  234. }
  235. }
  236. //--------取得软件地址
  237. function GetSofturl($classid,$id,$pathid,$p,$pass,$onlinetime,$onlinepass){
  238. global $empire,$dbtbpre,$public_r,$class_r,$emod_r,$level_r,$ecms_config;
  239. //验证IP
  240. eCheckAccessDoIp('onlineinfo');
  241. $classid=(int)$classid;
  242. $id=(int)$id;
  243. $pathid=(int)$pathid;
  244. $onlinetime=(int)$onlinetime;
  245. $p=RepPostVar($p);
  246. if(!$classid||empty($id)||empty($p))
  247. {exit();}
  248. $p_r=explode(":::",$p);
  249. $userid=$p_r[0];
  250. $rnd=$p_r[1];
  251. $nockpass=$p_r[2];
  252. //验证码
  253. $cpass=md5(md5($classid."-!ecms!".$id."-!ecms!".$pathid).ReturnDownSysCheckIp()."wm_chief".$public_r[downpass].$userid);
  254. if('dg'.$cpass<>'dg'.$pass)
  255. {exit();}
  256. //验证验证码
  257. CheckOnlinePass($onlinetime,$onlinepass);
  258. //表不存在
  259. if(empty($class_r[$classid][tbname]))
  260. {exit();}
  261. $mid=$class_r[$classid][modid];
  262. $tbname=$class_r[$classid][tbname];
  263. $r=$empire->fetch1("select * from {$dbtbpre}ecms_".$tbname." where id='$id' limit 1");
  264. if(empty($r['id'])||$r['classid']!=$classid)
  265. {exit();}
  266. //副表
  267. $finfor=$empire->fetch1("select ".ReturnSqlFtextF($mid)." from {$dbtbpre}ecms_".$tbname."_data_".$r[stb]." where id='$r[id]' limit 1");
  268. $r=array_merge($r,$finfor);
  269. //区分下载地址
  270. $path_r=explode("\r\n",$r[onlinepath]);
  271. if(!$path_r[$pathid])
  272. {
  273. exit();
  274. }
  275. $showdown_r=explode("::::::",$path_r[$pathid]);
  276. $downgroup=$showdown_r[2];
  277. //下载权限
  278. if($downgroup)
  279. {
  280. $userid=(int)$userid;
  281. $rnd=RepPostVar($rnd);
  282. $nockpass=RepPostVar($nockpass);
  283. if(!$nockpass)
  284. {
  285. exit();
  286. }
  287. $cknockpass=qReturnLoginPassNoCK($userid,'',$rnd,0);
  288. if('dg'.$nockpass<>'dg'.$cknockpass)
  289. {
  290. exit();
  291. }
  292. //取得会员资料
  293. $u=$empire->fetch1("select ".eReturnSelectMemberF('*')." from ".eReturnMemberTable()." where ".egetmf('userid')."='$userid' and ".egetmf('rnd')."='$rnd' limit 1");
  294. if(empty($u['userid']))
  295. {exit();}
  296. //下载次数限制
  297. $setuserday="";
  298. if($level_r[$u['groupid']]['daydown'])
  299. {
  300. $setuserday=DoCheckMDownNum($userid,$u['groupid'],1);
  301. }
  302. if($downgroup>0)//会员组
  303. {
  304. if($level_r[$downgroup][level]>$level_r[$u[groupid]][level])
  305. {
  306. exit();
  307. }
  308. }
  309. else//访问组
  310. {
  311. $vgroupid=0-$downgroup;
  312. $ckvgresult=eMember_ReturnCheckViewGroup($u,$vgroupid);
  313. if($ckvgresult<>'empire.cms')
  314. {
  315. exit();
  316. }
  317. }
  318. //点数是否足够
  319. $showdown_r[3]=intval($showdown_r[3]);
  320. if($showdown_r[3])
  321. {
  322. //---------是否有历史记录
  323. $bakr=$empire->fetch1("select id,truetime from {$dbtbpre}enewsdownrecord where id='$id' and classid='$classid' and userid='$userid' and pathid='$pathid' and online=1 order by truetime desc limit 1");
  324. if($bakr[id]&&(time()-$bakr[truetime]<=$public_r[redodown]*3600))
  325. {}
  326. else
  327. {
  328. //包月卡
  329. if($u['userdate']-time()>0)
  330. {}
  331. //点数
  332. else
  333. {
  334. if($showdown_r[3]>$u['userfen'])
  335. {
  336. exit();
  337. }
  338. //去除点数
  339. $usql=$empire->query("update ".eReturnMemberTable()." set ".egetmf('userfen')."=".egetmf('userfen')."-".$showdown_r[3]." where ".egetmf('userid')."='$userid'");
  340. }
  341. //备份下载记录
  342. $utfusername=$u['username'];
  343. BakDown($classid,$id,$pathid,$userid,$utfusername,$r[title],$showdown_r[3],1);
  344. }
  345. }
  346. //更新用户下载次数
  347. if($setuserday)
  348. {
  349. $usql=$empire->query($setuserday);
  350. }
  351. }
  352. //总下载数据增一
  353. $usql=$empire->query("update {$dbtbpre}ecms_".$class_r[$classid][tbname]." set totaldown=totaldown+1 where id='$id'");
  354. //选择播放器
  355. $ftype=GetFiletype($showdown_r[1]);
  356. if(strstr($ecms_config['sets']['realplayertype'],','.$ftype.','))
  357. {
  358. Header("Content-Type: audio/x-pn-realaudio");
  359. }
  360. else
  361. {
  362. Header("Content-Type: video/x-ms-asf");
  363. }
  364. $downurl=stripSlashes($showdown_r[1]);
  365. $downurlr=ReturnDownQzPath($downurl,$showdown_r[4]);
  366. $downurl=$downurlr['repath'];
  367. //防盗链
  368. @include(ECMS_PATH."e/DownSys/class/enpath.php");
  369. $downurl=DoEnOnlinepath($downurl);
  370. db_close();
  371. $empire=null;
  372. echo $downurl;
  373. exit();
  374. }
  375. ?>