<?php
/**
* Librarys
* class.php
*/
error_reporting(E_ALL^E_NOTICE);
date_default_timezone_set('PRC');
//初始化检测
if (!is_dir($savedir)) mkdir($savedir);
if (!is_file($savelog)) file_put_contents($savelog,'');
if (strpos($_SERVER['SCRIPT_NAME'],'api')!==FALSE) header('Content-type:text/html; charset=GBK');
function checkmobile() {
$ua=$_SERVER['HTTP_USER_AGENT'];
$mobilelist=array('iphone','android','phone','mobile','wap','netfront','java','opera mobi','opera mini','ucweb','windows ce','symbian','series','webos','sony','blackberry','dopod','nokia','samsung','palmsource','xda','pieplus','meizu','midp','cldc','motorola','foma','docomo','up.browser','up.link','blazer','helio','hosin','huawei','novarra','coolpad','webos','techfaith','palmsource','alcatel','amoi','ktouch','nexian','ericsson','philips','sagem','wellcom','bunjalloo','maui','smartphone','iemobile','spice','bird','zte-','longcos','pantech','gionee','portalmmm','jig browser','hiptop','benq','haier','^lct','320x320','240x320','176x220');
$padlist=array('pad','gt-p1000');
$useragent=strtolower($ua);
if(dstrpos($useragent,$padlist)) {
return true;
}
if((dstrpos($useragent,$mobilelist,true))) {
return false;
}
$brower=array('mozilla','chrome','safari','opera','m3gate','winwap','openwave','myop');
if(dstrpos($useragent,$brower)) return true;
}
function dstrpos($string,&$arr,$returnvalue=false) { //checkmobile需要
if(empty($string)) return false;
foreach((array)$arr as $v) {
if(strpos($string,$v) !== false) {
$return=$returnvalue ? $v : true;
return $return;
}
}
return false;
}
class sydl {
var $is_pc; //手机or电脑
var $adminpwd; //管理员密码
var $savedir; //保存目录
var $savelog; //记录文件
var $downway; //用fopen还是curl
var $adminmail; //用户邮箱
var $head;
var $mhead;
var $menu;
var $mmenu;
var $bottom;
var $mbottom;
var $adminfile;
var $out;
function sydl() {
$this->adminfile=$_SERVER['SCRIPT_NAME'];
$this->head='<!DOCTYPE html><html lang="zh-CN"><head><meta http-equiv="Content-Type" content="text/html; charset=GBK"><meta charset="GBK"><title>泷涯离线下载</title><link style="text/css" rel="stylesheet" href="style.css" /></head><body>';
$this->mhead='<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=GBK"><title>泷涯离线下载</title><link style="text/css" rel="stylesheet" href="m.css" /></head><body screen_capture_injected="true"><div class="hd"><a href="http://bbs.sylingd.com">泷涯离线下载</a></div><div class="wp">';
$this->menu=str_replace('#adminfile#',$_SERVER['SCRIPT_NAME'],'<div id="menu"><h3 id="menu_title"><a href="http://bbs.sylingd.com" target="_blank">泷涯离线下载</a></h3><ul><li><a href="#adminfile#">首页</a></li><li><a href="#adminfile#?op=manage">任务</a></li><li><a href="#adminfile#?op=add_a">新建</a></li><li><a href="#adminfile#?op=config">设置</a></li><li><a href="#adminfile#?op=about">关于</a></li><li><a href="#adminfile#?op=login_out">退出</a></li></ul><div class="clear"></div></div>');
$this->mmenu=str_replace('#adminfile#',$_SERVER['SCRIPT_NAME'],'<div class="pd2"><a href="#adminfile#">首页</a><span class="pipe">|</span><a href="#adminfile#?op=manage">任务</a><span class="pipe">|</span><a href="#adminfile#?op=add_a">新建</a><span class="pipe">|</span><a href="#adminfile#?op=config">设置</a><span class="pipe">|</span><a href="#adminfile#?op=about">关于</a><span class="pipe">|</span><a href="#adminfile#?op=login_out">退出</a></div>');
$this->bottom='<div id="footer"><div id="footer_box"><span>Powered by <a href="http://bbs.sylingd.com" target="_blank">泷涯离线下载</a></span></div></div></body></html>';
$this->mbottom='</div></div><p>Powered by <strong><a href="http://bbs.sylingd.com" target="_blank">泷涯离线下载</a></strong></p></div></body></html>';
$this->is_pc=checkmobile();
$this->downway=$GLOBALS['downway'];
$this->savedir=$GLOBALS['savedir'];
$this->adminpwd=$GLOBALS['adminpwd'];
$this->adminmail=$GLOBALS['adminmail'];
$this->savelog=$GLOBALS['savelog'];
}
private function tz_show($varName) { //探针函数一
switch($result=get_cfg_var($varName)) {
case 0:
return '<font color="red">×</font>';
break;
case 1:
return '<font color="green">√</font>';
break;
default:
return $result;
break;
}
}
private function tz_fun($funName='') { //探针函数二
if (!$funName || trim($funName) == '' || preg_match('~[^a-z0-9\_]+~i', $funName, $tmp)) return '获取失败';
return (false !== function_exists($funName)) ? '<font color="green">√</font>' : '<font color="red">×</font>';
}
private function tz_disfuns() { //探针函数三
$disFuns=get_cfg_var("disable_functions");
if(empty($disFuns))
{
$result='<font color=red>×</font>';
}
else
{
$disFuns_array=explode(',',$disFuns);
foreach ($disFuns_array as $key=>$value) {
if ($key!=0 && $key%5==0) {
$result.='<br/>';
}
$result.="$value ";
}
}
return $result;
}
private function getstr($num) { //随机名称
$str='abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ';
return substr(str_shuffle($str),0,$num);
}
public function getfilesize($url) {
if ($this->downway=='Curl') {
$ch=curl_init();
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_HEADER,1);
curl_setopt($ch,CURLOPT_NOBODY,1);
curl_setopt($ch,CURLOPT_FOLLOWLOCATION,1);
$result=curl_exec($ch);
@curl_close($ch);
$regex="/Content-Length: \d+/";
preg_match($regex,$result,$matches);
preg_match("/\d+/",$matches[0],$rrr);
} else {
$matches=get_headers($url);
preg_match("/\d+/",$matches[4],$rrr);
}
if (isset($rrr[0])) $size=$rrr[0];
else $size='0';
return $size;
}
private function func_down($url,$name,$type,$size,$mor='没有备注') { //下载内容
@ignore_user_abort(TRUE);
@set_time_limit(0);
do {
$tmp_name=$this->getstr(15).'.sy';
}
while (is_file($this->savedir.'/'.$tmp_name)); //文件不存在
$log=file_get_contents($this->savelog);
$name=str_replace(',',',',$name);
$mor=str_replace(',',',',$mor);
$tmp_add=$tmp_name.','.$name.','.$mor.','.$type.','.$size."\n";
file_put_contents($this->savelog,$log.$tmp_add); //写入记录
if ($this->downway=='Curl') { //用Curl
$fp=fopen($this->savedir.'/'.$tmp_name,"wb");
$ch=curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_FOLLOWLOCATION,1);
curl_setopt($ch,CURLOPT_HEADER,0);
curl_setopt($ch,CURLOPT_FILE,$fp);
curl_exec($ch);
@curl_close($ch);
@fclose($fp);
} else { //用fopen下载
$d=fopen($url,"rb");
if ($d) {
$b=fopen('./'.$this->savedir.'/'.$tmp_name,"wb");
if ($b) {
while (!feof($d)) {
fwrite($b,fread($d,1024*8),1024*8);
}
}
}
if ($d) @fclose($d);
if ($b) @fclose($b);
}
$mail='亲,你的下载任务'.$name.'已经完成了哦!';
@mail($this->adminmail,'下载完成!',$mail);
}
private function add_mor($text) { //批量任务
$lines=explode("\n",$text);
foreach ($lines as $line) {
$keys=explode('|',$line);
foreach ($keys as $key=>$value) {
switch ($key) {
case 0:
$url=$value;
break;
case 1:
$name=$value;
break;
case 2:
$this->func_down($url,$name,'','',$value);
break;
default:
break;
}
}
}
$this->show('add_ok');
}
private function del_all() { //删除所有任务
$file=file_get_contents($this->savelog);
$lines=explode("\n",$file);
foreach ($lines as $line) {
$keys=explode(',',$line);
foreach ($keys as $key) {
$this->func_del($key);
break;
}
}
$this->show('del_ok');
}
private function func_del($filename) { //删除任务
$file=file_get_contents($this->savelog);
@unlink($this->savedir.'/'.$filename);
$lines=explode("\n