<?php |
$user = 'admin' ; |
$pwd = 'admin' ; |
$savedir = 'down' ; |
$savetxt = 'index.php#sy.txt' ; |
$adminfile = $SCRIPT_NAME ; |
$act =htmlspecialchars(trim( $_GET [ 'act' ])); |
session_start(); |
$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>' ; |
$menu = '<div id="menu"><h3 id="menu_title"><a href="http://code.worldedit.org" target="_blank">泷涯离线下载</a></h3><ul><li><a href="' . $adminfile . '">管理首页</a></li><li><a href="' . $adminfile . '?act=manage">任务管理</a></li><li><a href="' . $adminfile . '?act=add">新建下载</a></li><li><a href="' . $adminfile . '?act=about">关于</a></li></ul><div class="clear"></div></div>' ; |
$bottom = '<div id="footer"><div id="footer_box"><span>Powered by <a href="http://code.worldedit.org" target="_blank">泷涯离线下载</a></span></div></div></body></html>' ; |
if (! is_dir ( $savedir )) mkdir ( $savedir ); |
if (! file_exists ( $savetxt )) { |
$fp = fopen ( $savetxt , 'wb' ); |
fwrite( $fp , '' ); |
@fclose( $fp ); |
} |
function tips( $bodyi , $etype = 'n' ) { |
global $head , $menu , $bottom ; |
if ( $etype == 'y' ) { |
echo $head . $menu . '<div id="content"><div id="content_box"><div class="admin_page_name">提示</div><div class="table_list post_list">' . $bodyi . '</div></div></div>' . $bottom ; |
} else { |
echo $head . '<div id="content"><div id="content_box"><div class="admin_page_name">提示</div><div class="table_list post_list">' . $bodyi . '</div></div></div>' . $bottom ; |
} |
} |
function show( $name ) { |
switch ( $result =get_cfg_var( $name )) { |
case 0: |
$result = '<font color="red">×</font>' ; |
break ; |
case 1: |
$result = '<font color="green">√</font>' ; |
break ; |
default : |
break ; |
} |
return $result ; |
} |
function isfun( $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>' ; |
} |
if ( $_SESSION [ 'login' ]== 'ok' ) { |
if ( $act == 'manage' ) { //任务管理 |
$body = '<div id="content"><div id="content_box"><div class="admin_page_name">任务管理</div><div class="table_list post_list"><table colspan="0" rowspan="0" cellpadding="0" cellspacing="0" id="list"><thead><tr><td>名称</td><td style="width:15%">动作</td></tr></thead><tbody>' ; |
if ( filesize ( $savetxt )==0) { |
$body .= '<td colspan="4"><center><h3>没有记录,<a href="' . $adminfile . '?act=add">新建一个</a></h3></center></td>' ; |
} else { |
$url = str_replace ( "\\" , '/' ,dirname( __FILE__ )); |
$file = file_get_contents ( $savetxt ); |
$lines = explode ( "\n" , $file ); |
foreach ( $lines as $line ) { |
$body .= '<tr class="alt">' ; |
$i =1; |
$keys = explode ( ',' , $line ); |
foreach ( $keys as $key ) { |
if ( $i ==1) $id = $key ; |
elseif ( $i ==2) $name = $key ; |
elseif ( $i ==3) { |
$filename = $key ; |
$i =0; |
$body .= "<td>$name</td><td><a href=\"$adminfile?act=del&id=$id&name=$name&filename=$filename\" class=\"link_button\">删除</a><a href=\"$savedir/$filename\" class=\"link_button\">下载</a>" ; |
} |
$i ++; |
} |
$body .= '</tr>' ; |
} |
} |
$body .= '<tbody></table></div></div></div></div>' ; |
$menu = str_replace ( "<li><a href=\"$adminfile?act=manage\">任务管理</a></li>" , "<li class=\"current\"><a href=\"$adminfile?act=manage\">任务管理</a></li>" , $menu ); |
$show =TRUE; |
} elseif ( $act == 'add' ) { //新建下载 |
$body = '<div id="content"><div id="content_box"><div class="admin_page_name">新建下载</div><div class="table_list post_list"><form action="' . $adminfile . '?act=adda" method="post"><center><p><h5>地址:<input type="text" name="iurl" value="http://"/></h5></p><p><h5>名称:<input type="text" name="iname" /></h5></p><p><input type="submit" name="Submit" value="添加" /></p></center></form></div></div></div>' ; |
$menu = str_replace ( "<li><a href=\"$adminfile?act=add\">新建下载</a></li>" , "<li class=\"current\"><a href=\"$adminfile?act=add\">新建下载</a></li>" , $menu ); |
$show =TRUE; |
} elseif ( $act == 'del' ) { //删除 |
$id =htmlspecialchars(trim( $_GET [ 'id' ])); |
$name =htmlspecialchars(trim( $_GET [ 'name' ])); |
$filename =htmlspecialchars(trim( $_GET [ 'filename' ])); |
$str = $id . ',' . $name . ',' . $filename . "\n" ; |
$file = file_get_contents ( $savetxt ); |
$file = str_replace ( $str , '' , $file ); |
$fp = fopen ( $savetxt , 'wb' ); |
fwrite( $fp , $file ); |
if ( $fp ) @fclose( $fp ); |
@unlink( "$savedir/$filename" ); |
tips( '<h5>删除成功</h5>' , 'y' ); |
$show =FALSE; |
} elseif ( $act == 'adda' ) { //下载 |
$url =htmlspecialchars(trim( $_POST [ 'iurl' ])); |
$name =htmlspecialchars(trim( $_POST [ 'iname' ])); |
if ( empty ( $url )) { |
tips( '<p><center><h5>没有输入地址,点击<a href="javascript:history.back(-1)">这里</a>返回</h5></center></p>' ); |
} elseif ( empty ( $name )) { |
tips( '<p><center><h5>没有输入名称,点击<a href="javascript:history.back(-1)">这里</a>返回</h5></center></p>' ); |
} else { |
$dt = '.sy' ; |
do { |
$tmp_name = substr ( str_shuffle ( 'abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ' ),0,20). $dt ; |
} |
while ( file_exists ( $savedir . '/' . $tmp_name )); |
$file = file_get_contents ( $savetxt ); |
$lines = explode ( "\n" , $file ); |
foreach ( $lines as $line ) { |
$body .= '<tr class="alt">' ; |
$i =1; |
$keys = explode ( ',' , $line ); |
foreach ( $keys as $key ) { |
if ( $i ==1) $id = $key ; |
} |
$i ++; |
} |
if ( empty ( $id )) $id =1; else $id = $id ++; |
$file = $file . $id . ',' . $name . ',' . $tmp_name . "\n" ; |
$fp = fopen ( $savetxt , 'wb' ); |
fwrite( $fp , $file ); |
@fclose( $fp ); |
$d = fopen ( $url , 'rb' ); |
if ( $d ) { |
$b = fopen ( $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 ); |
} |
tips( '<h5>成功添加任务</h5>' , 'y' ); |
$show =FALSE; |
} elseif ( $act == 'delall' ) { //删除所有 |
$file = file_get_contents ( $savetxt ); |
$lines = explode ( "\n" , $file ); |
foreach ( $lines as $line ) { |
$i =1; |
$keys = explode ( ',' , $line ); |
foreach ( $keys as $key ) { |
if ( $i ==3) { |
@unlink( "$savedir/$filename" ); |
} |
} |
} |
$body .= '<tbody></table></div></div></div></div>' ; |
$fp = fopen ( $savetxt , 'wb' ); |
fwrite( $fp , '' ); |
@fclose( $fp ); |
tips( '<h5>删除成功</h5>' , 'y' ); |
$show =FALSE; |
} elseif ( $act == 'about' ) { //关于 |
$body = '<div id="content"><div id="content_box"><div class="admin_page_name">关于</div><div class="table_list post_list"><p>这个程序完全开源,大家可以免费使用、学习</p><p>但是,禁止在没有经过作者允许下,篡改、去除版权,如果需要基于此程序开发,需要先联系作者</p><p>泷涯离线下载 ver 1.0 <a href="http://code.worldedit.org">查看最新版</a></p></div></div></div>' ; |
$menu = str_replace ( "<li><a href=\"$adminfile?act=about\">关于</a></li>" , "<li class=\"current\"><a href=\"$adminfile?act=about\">关于</a></li>" , $menu ); |
$show =TRUE; |
} else { //首页 |
$body = '<div id="content"><div id="content_box"><div class="admin_page_name">管理首页</div><div class="table_list post_list"><center><p><h5>允许URL打开文件:' .show(allow_url_fopen). '</h5></p><p><h5>Curl支持:' .isfun( "curl_init" ). '</h5></p></center></div></div></div>' ; |
$menu = str_replace ( "<li><a href=\"$adminfile\">管理首页</a></li>" , "<li class=\"current\"><a href=\"$adminfile\">管理首页</a></li>" , $menu ); |
$show =TRUE; |
} |
if ( $show ) echo $head . $menu . $body . $bottom ; |
} else { |
if ( $_GET [ 'act' ]== 'logincheck' ) { |
$inputpwd =md5(trim( $_POST [ 'ipwd' ])); |
$inputuser =md5(trim( $_POST [ 'iuser' ])); |
if ( $inputpwd ==md5( $pwd ) && $inputuser ==md5( $user )) { |
$_SESSION [ 'login' ]= 'ok' ; |
header( 'Location:' . $adminfile ); |
} else { |
tips( '<p><h5>啊哦,错了哦</h5></p><p><h6>点击<a href="' . $adminfile . '">这里</a>返回</h6></p>' , '0' ); |
} |
} else { |
echo '<!DOCTYPE html><html><head><meta http-equiv="Content-Type" content="text/html; charset=GBK"><meta charset="GBK"><title>后台管理</title><style type="text/css">* { font-family:"Microsoft YaHei",Arial; }body { background:#f9f9f9; font-size:14px; }#login_title { text-align:center; width:360px; margin:120px auto; margin-bottom:0px; font-size:32px; color:#333; text-shadow: 0 2px 0 #FFFFFF;}#login_form { width:360px; margin:0 auto; margin-top:20px; border:solid 1px #e0e0e0; background:#fff; border-radius:3px 3px 3px 3px;}#login_form_box { padding:16px; }#login_form .label { font-weight:bold; padding-bottom:6px; color:#333; }#login_form .textbox input { border:none; padding:0; font-size:24px; width:312px; color:#333; }#login_form .textbox { border:1px solid #e0e0e0; padding:6px; margin-bottom:20px; border-radius:3px 3px 3px 3px; }#login_form .bottom { text-align:right; }#login_form .button { padding:8px 16px; font-size:14px; }</style></head><body><form action="' . $adminfile . '?act=logincheck" method="post"> <div id="login_title">泷涯离线下载</div><div id="login_form"><div id="login_form_box"><div class="label">用户名</div><div class="textbox"><input name="iuser" type="text"></div><div class="label">密码</div><div class="textbox"><input name="ipwd" type="password"></div><div class="bottom"><input name="login" type="submit" value="登录" class="button"></div></div></div></form></body></html>' ; |
} |
} |
?> |