diff --git a/system/ATool.php b/system/ATool.php index fe64930..a1ba369 100644 --- a/system/ATool.php +++ b/system/ATool.php @@ -119,7 +119,54 @@ if(!empty($_GET['type'])){ opcache_reset(); //清理PHP缓存 } msgA(['code'=>1,'msg'=>'操作成功']); + //改账号 + }elseif($_GET['type'] == 'set_user_name'){ + //新用户名是否合规 + if(empty($_POST['new_user_name'])){ + msgA(['code'=>-1,'msg'=>'用户名不能为空']); + }elseif(empty($_POST['ID'])){ + msgA(['code'=>-1,'msg'=>'ID不能为空']); + }elseif(!preg_match('/^[A-Za-z0-9]{4,13}$/',$_POST['new_user_name'])){ + msg(-1,'账号只能是4到13位的数字和字母!'); + } + + //检测是否冲突 + if(file_exists(DIR."/data/user/".$_POST['new_user_name'])){ + msgA(['code'=>-1,'msg'=>'data/user/存在同名文件夹']); + } + if(file_exists(DIR."/data/backup/".$_POST['new_user_name'])){ + msgA(['code'=>-1,'msg'=>'data/backup/存在同名文件夹']); + } + //读取用户信息 + $USER = get_db("global_user", "*", ["ID" => $_POST['ID']]); + if(empty($USER)){ + msgA(['code'=>-1,'msg'=>'用户ID不存在']); + }elseif($USER['User'] == $_POST['new_user_name']){ + msgA(['code'=>-1,'msg'=>'新用户名不能和旧的一样']); + }elseif(has_db('global_user',['User'=>$_POST['new_user_name']])){ + msgA(['code'=>-1,'msg'=>'新账号已存在,请核对后再试!']); + } + //移动数据目录 + $Path = DIR.'/data/user/'.$USER['User']; + if(is_dir($Path)){ + $New_Path = DIR.'/data/user/'.$_POST['new_user_name']; + if(!rename($Path,$New_Path)){ + msgA(['code'=>-1,'msg'=>'移动数据目录失败']); + } + } + //移动备份目录 + $Path = DIR.'/data/backup/'.$USER['User']; + if(is_dir($Path)){ + $New_Path = DIR.'/data/backup/'.$_POST['new_user_name']; + if(!rename($Path,$New_Path)){ + msgA(['code'=>-1,'msg'=>'移动备份目录失败']); + } + } + update_db("user_login_info", ["user" => $_POST['new_user_name']], ["user" => $USER['User']]); + update_db("user_log", ["user" => $_POST['new_user_name']], ["user" => $USER['User']]); + update_db("global_user", ["User" => $_POST['new_user_name']], ["ID" => $_POST['ID']],[1,'操作成功']); } + msgA(['code'=>-1,'msg'=>'请求类型错误']); }else{ //判断是否已验证 @@ -174,7 +221,7 @@ function echo_Atool(){ @@ -219,6 +266,7 @@ function echo_Atool(){
改密码 设站长 + 改账号
@@ -232,7 +280,7 @@ function echo_Atool(){ var table = layui.table; var cols = [[ {field:'ID',title:'ID',width:60,sort:true} - ,{title:'操作',toolbar:'#tablebar',width:130} + ,{title:'操作',toolbar:'#tablebar',width:175} ,{field:'User',title:'账号',minWidth:120,templet:function(d){ return ''+d.User+'' }} @@ -299,6 +347,18 @@ function echo_Atool(){ layer.msg(data.msg, {icon: 5}); } }); + }else if(obj.event == 'set_user_name'){ + layer.prompt({formType: 3,value: '',title:'请输入新账号 (原账号:'+data.User+')'}, function(value, index, elem){ + $.post('./ATool.php?type=set_user_name',{ID:data.ID,new_user_name:value},function(data,status){ + if(data.code == 1) { + layer.close(index); + table.reload('table'); + layer.msg(data.msg, {icon: 1}); + }else{ + layer.msg(data.msg, {icon: 5}); + } + }); + }); } }); $('.set').click(function () { diff --git a/system/Register.php b/system/Register.php index 6f55057..581e8f8 100644 --- a/system/Register.php +++ b/system/Register.php @@ -68,6 +68,49 @@ if(!preg_match('/^[A-Za-z0-9]{4,13}$/', $user)){ msg(-1,'该账号已被站长保留!'); } +//读取邮件配置 +$mail_config = get_db("global_config","v",["k"=>"mail_config"]); +if(!empty($mail_config)){ + $mail_config = unserialize($mail_config); + if($mail_config['verify_email'] == 1 && $_GET['type'] == 'getcode'){ + //判断是否频繁发送 + $send_interval = intval($mail_config['send_interval']); + if($send_interval > 0 && has_db('user_log',['type'=>'send_email','ip'=>$IP,'time[>]'=>time() - $send_interval])){ + msg(-1,'请勿频繁获取验证码'); + } + $mail_config['addressee'] = $_POST['Email']; + $mail_config['Subject'] = '验证码'; + $code = mt_rand(100000,999999); + + if(!strstr($mail_config['verify_template'],'$code')){ + $mail_config['verify_template'] = '您的验证:$code'; + } + $mail_config['Body'] = empty($mail_config['verify_template']) ? '您的验证:'.$code:str_replace('$code', $code, $mail_config['verify_template']); + $mail_config['return']='bool'; + if(send_email($mail_config)){ + session_start(); + $_SESSION["{$_POST['Email']}"]['code'] = "$code"; + $_SESSION["{$_POST['Email']}"]['time'] = time(); + insert_db("user_log", ["uid" => 0,"user"=>$user,"ip"=>$IP,"time"=>time(),"type" => 'send_email',"content"=>Get_Request_Content(),"description"=>"发送注册验证码:".$code.', 接收邮箱: '.$_POST['Email']]); + msg(1,'发送成功'); + }else{ + msg(-1,'发送失败'); + } + exit; + } +} +//验证码效验 +if(!empty($mail_config['verify_email']) && $mail_config['verify_email'] == 1){ + session_start(); + if(empty($_POST['code'])){ + msg(-1,'请输入验证码'); + }elseif ($_POST['code'] != $_SESSION["{$_POST['Email']}"]['code']) { + msg(-1,'验证码错误'.$_SESSION["{$_POST['Email']}"]['code']); + }elseif($_SESSION["{$_POST['Email']}"]['time'] + 300 < time()){ + msg(-1,'验证码已过期'); + } + unset($_SESSION["{$_POST['Email']}"]); +} //插入用户表和创建初始数据库 $RegTime = time(); $PassMD5 = Get_MD5_Password($pass,$RegTime); @@ -155,28 +198,28 @@ insert_db("user_config", ["uid" => $USER_DB['ID'],"k"=>"s_templates","v"=>$globa $time = time(); if($blueprint){ $categorys = select_db('user_categorys','*',['uid'=>$Group['uid']]); - $inks = select_db('user_links','*',['uid'=>$Group['uid']]); + $links = select_db('user_links','*',['uid'=>$Group['uid']]); }else{ $categorys = select_db('user_categorys','*',['uid'=>0]); - $inks = select_db('user_links','*',['uid'=>0]); + $links = select_db('user_links','*',['uid'=>0]); } foreach ($categorys as $key => $data){ - $categorys[$key]['uid'] = $USER_DB['ID']; - $categorys[$key]['add_time'] = $time; - $categorys[$key]['up_time'] = $time; - unset($categorys[$key]['id']); + $data['uid'] = $USER_DB['ID']; + $data['add_time'] = $time; + $data['up_time'] = $time; + unset($data['id']); + insert_db('user_categorys',$data); } -insert_db('user_categorys',$categorys); - -foreach ($inks as $key => $data){ - $inks[$key]['uid'] = $USER_DB['ID']; - $inks[$key]['add_time'] = $time; - $inks[$key]['up_time'] = $time; - unset($inks[$key]['id']); +foreach ($links as $key => $data){ + $data['uid'] = $USER_DB['ID']; + $data['add_time'] = $time; + $data['up_time'] = $time; + unset($data['id']); + insert_db('user_links',$data); } -insert_db('user_links',$inks); + //写初始ID $link_id = intval(max_db('user_links','lid',['uid'=>$USER_DB['ID']])) +1; insert_db("user_config", ["uid"=>$USER_DB['ID'],"k"=>"link_id","v"=>$link_id,"t"=>"max_id","d"=>'链接ID']); diff --git a/system/api.php b/system/api.php index 6d91139..2bb4cfd 100644 --- a/system/api.php +++ b/system/api.php @@ -44,8 +44,10 @@ if(!is_login()){ }else{ msg(-1,'请先验证二级密码!'); } - - +//是否加载扩展API +if($global_config['api_extend'] == 1 && is_file('./system/api_extend.php')){ + require './system/api_extend.php'; +} //站长相关方法名 $root = ['write_subscribe','write_sys_settings','write_default_settings','read_user_list','write_user_info','read_purview_list','read_users_list','write_users','read_regcode_list','write_regcode','other_upsys','read_log','other_root']; @@ -1098,6 +1100,9 @@ function other_testing_link(){ global $global_config; if ( $global_config['offline'] == '1'){ msg(-1,"离线模式无法使用此功能"); } $code = get_http_code($_POST['url']); + if($code != 200 && $code != 302 && $code != 301){ + $code = ccurl($_POST['url'])['code']; + } msgA(['code' => 0 ,'StatusCode'=> $code]); } diff --git a/system/api_root.php b/system/api_root.php index 03263cb..5c8472c 100644 --- a/system/api_root.php +++ b/system/api_root.php @@ -321,10 +321,25 @@ function write_user_info(){ //删除 case "Del": $uids = json_decode($_POST['ID']); + $USER_S = select_db('global_user','User',['ID'=>$uids]); + foreach($USER_S as $USER){ + if(is_dir(DIR.'/data/user/'.$USER)){ + deldir(DIR.'/data/user/'.$USER); + if(is_dir(DIR.'/data/user/'.$USER)){ + msg(1,'删除用户数据目录失败,用户名:'.$USER); + } + } + if(is_dir(DIR.'/data/backup/'.$USER)){ + deldir(DIR.'/data/backup/'.$USER); + if(is_dir(DIR.'/data/backup/'.$USER)){ + msg(1,'删除用户备份目录失败,用户名:'.$USER); + } + } + } foreach (['regcode_list','user_categorys','user_config','user_count','user_links','user_log','user_login_info'] as $table){ delete_db($table,[ "uid" => $uids ]); } - delete_db('global_user',["ID" => json_decode($_POST['ID']) ]); + delete_db('global_user',["ID" => $uids]); msg(1,'删除成功'); break; //设用户组 @@ -504,6 +519,7 @@ function write_sys_settings(){ 'copyright'=>['empty'=>true], 'global_header'=>['empty'=>true], 'global_footer'=>['empty'=>true], + 'api_extend'=>['empty'=>true], //扩展功能-(全局开关) 'apply'=>['int'=>true,'min'=>0,'max'=>1,'msg'=>'收录管理参数错误'], 'guestbook'=>['int'=>true,'min'=>0,'max'=>1,'msg'=>'留言管理参数错误'], @@ -609,6 +625,7 @@ function read_log(){ $count = count_db('user_log',$where); //分页 $where['LIMIT'] = [$offset,$limit]; + $where['ORDER']['id'] = 'DESC'; //查询 $datas = select_db('user_log','*',$where); //返回 @@ -651,6 +668,38 @@ function other_root(){ } write_global_config('username_retain',$_POST['username_retain'],'账号保留'); msg(1,'保存成功'); + }elseif($_GET['type'] == 'write_mail_config'){ + if($GLOBALS['global_config']['offline'] == '1'){msg(-1,"离线模式无法使用此功能");} + if(!is_subscribe('bool')){msg(-1,"未检测到有效授权,无法使用该功能!");} + //检测PHPMailer是否存在 + clearstatcache(); + if(!is_file(DIR.'/system/PHPMailer/PHPMailer.php')){ + $filePath = "./data/temp/PHPMailer_6.8.0.tar.gz"; + if(downFile('https://update.lm21.top/TwoNav/updata/PHPMailer_6.8.0.tar.gz','PHPMailer_6.8.0.tar.gz','./data/temp/')){ + $file_md5 = md5_file($filePath); + if($file_md5 != "07251997fb7ebf3bf2d296d4214ccf0a"){ + unlink($filePath); + msg(-1,'效验PHPMailer失败
!'); + } + }else{ + msg(-1,'下载PHPMailer失败,请重试!
如需手动安装可联系技术支持!'); + } + try { + $phar = new PharData($filePath); + $phar->extractTo('./system/', null, true); + unlink($filePath); + clearstatcache(); + } catch (Exception $e) { + msg(-1,'安装PHPMailer失败'); + } + } + write_global_config('mail_config',$_POST,'账号保留'); + msg(1,'保存成功'); + }elseif($_GET['type'] == 'write_mail_test'){ + $_POST['Subject'] = 'TwoNav 测试邮件' . time(); + $_POST['Body'] = '

TwoNav 测试邮件

' . date('Y-m-d H:i:s'); + send_email($_POST); } - } + + diff --git a/system/install.php b/system/install.php index 909be1b..341b66e 100644 --- a/system/install.php +++ b/system/install.php @@ -7,7 +7,7 @@ session_start(); //判断请求类型 if($_SERVER['REQUEST_METHOD'] === 'POST'){ - if( !$_SESSION['initial'] ){ msg(-1,'当前环境无法满足程序运行条件!'); } + if(empty($_SESSION['initial'])){ msg(-1,'当前环境无法满足程序运行条件!'); } define('Debug',TRUE); $db = null; $USER_DB =null; @@ -51,7 +51,7 @@ function diagnosis() { $log=''; $log .= "服务器时间:" . date("Y-m-d H:i:s") ."
"; $log .= "系统信息:" . php_uname('s').','.php_uname('r') ."
"; - $log .= "当前版本:" . SysVer . "
"; + $log .= "当前版本:" . file_get_contents('./system/version.txt') . "
"; //检查PHP版本,需要大于5.6小于8.0 $php_version = floatval(PHP_VERSION); @@ -76,7 +76,7 @@ function diagnosis() { if(function_exists("opcache_reset")){ $log = $log ."opcache: 已安装
"; } - $log .= "脚本权限:" . get_current_user()."/".substr(sprintf("%o",fileperms("index.php")),-4)."\n"; + $log .= "脚本权限:" . get_current_user()."/".substr(sprintf("%o",fileperms("index.php")),-4)."
"; $log .= in_array("pdo_sqlite",$ext) ? "PDO_Sqlite:支持
" : "PDO_Sqlite:不支持 (导入db3)
"; $log .= in_array("curl",$ext) ? "curl:支持
" : "curl:不支持 (链接识别/在线更新/主题下载/订阅等)
"; $log .= in_array("mbstring",$ext) ? "mbstring:支持
" : "mbstring:不支持 (链接识别)
"; diff --git a/system/public.php b/system/public.php index ccd3ee9..68f3070 100644 --- a/system/public.php +++ b/system/public.php @@ -480,6 +480,7 @@ function get_http_code($url) { curl_setopt($curl, CURLOPT_NOBODY, true); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_TIMEOUT, 10); + curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36'); $data = curl_exec($curl); $return = curl_getinfo($curl, CURLINFO_HTTP_CODE); curl_close($curl); @@ -495,6 +496,7 @@ function ccurl($url,$overtime = 3){ curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); + curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36'); $Res["content"] = curl_exec ( $curl ) ; $Res["code"] = curl_getinfo($curl, CURLINFO_HTTP_CODE); curl_close ( $curl ) ; @@ -636,3 +638,51 @@ function Get_Rand_Str( $length = 8 ,$extend = false){ } return $str; } +//发送邮件 +function send_email($config){ + if(!is_file(DIR.'/system/PHPMailer/PHPMailer.php')){ + msg(-1,'未安装PHPMailer!'); + } + + require DIR.'/system/PHPMailer/Exception.php'; + require DIR.'/system/PHPMailer/PHPMailer.php'; + require DIR.'/system/PHPMailer/SMTP.php'; + $mail = new PHPMailer\PHPMailer\PHPMailer(true); + try { + $mail->CharSet ="UTF-8"; + $mail->SMTPDebug = 0; + $mail->isSMTP(); + $mail->Host = $config['host']; + $mail->SMTPAuth = true; + $mail->Username = $config['user']; + $mail->Password = $config['pwd']; + $mail->SMTPSecure = $config['secure']; + $mail->Port = intval($config['port']); + + if(preg_match('/(.+)<(.+)>/', $config['sender'], $match)){ + $mail->setFrom($match[2],$match[1]); + }else{ + $mail->setFrom($config['sender']); + } + + $mail->addAddress($config['addressee']); //收件人 + + $mail->isHTML(true); + $mail->Subject = $config['Subject']; + $mail->Body = $config['Body']; + $mail->send(); + if(!empty($config['return']) && $config['return'] == 'bool'){ + return true; + } + msg(1,'邮件发送成功'); + } catch (Exception $e) { + if(!empty($config['return']) && $config['return'] == 'bool'){ + return false; + } + if(Debug){ + msgA(['code'=>-1,'msg'=>'发送失败:'.$mail->ErrorInfo]); + }else{ + msg(-1,'发送失败'); + } + } +} \ No newline at end of file diff --git a/system/templates.php b/system/templates.php index 735febe..daf0b2e 100644 --- a/system/templates.php +++ b/system/templates.php @@ -69,7 +69,10 @@ if(empty($c) || in_array($c,['index','click'])){ }//如果参数错误则使用本地服务器 } //取分类图标(六零系主题在用) - function get_category($content){ + function get_category($content){ //抽风的命名..过度几个版本后删除 + return get_category_icon($content); + } + function get_category_icon($content){ if(empty($content)){ return ''; } diff --git a/system/version.txt b/system/version.txt index e9ae985..62f2079 100644 --- a/system/version.txt +++ b/system/version.txt @@ -1 +1 @@ -v2.0.16-20230425 \ No newline at end of file +v2.0.17-20230428 \ No newline at end of file diff --git a/templates/admin/page/root/mail_set.php b/templates/admin/page/root/mail_set.php new file mode 100644 index 0000000..9fa11f7 --- /dev/null +++ b/templates/admin/page/root/mail_set.php @@ -0,0 +1,144 @@ + + +
+
+
+
+
+ 1.此功能授权用户专享 +
+ +
SMTP 配置
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+ +
注册参数
+
+ +
+ +
+
+
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+
+ + +
+
+
+
+
+
+ + + + + \ No newline at end of file diff --git a/templates/admin/page/root/sys_log.php b/templates/admin/page/root/sys_log.php index 5163da0..27acad2 100644 --- a/templates/admin/page/root/sys_log.php +++ b/templates/admin/page/root/sys_log.php @@ -13,6 +13,7 @@ require(dirname(__DIR__).'/header.php'); + @@ -57,6 +58,9 @@ layui.use(['table','layer','form'], function () { //{type:'checkbox'} //开启复选框 {field:'id',title:'ID',width:60} ,{field:'user',title:'账号',width:120,templet:function(d){ + if(d.type == 'send_email'){ + return d.user; + } return ''+d.user+'' }} ,{field:'ip',title:'请求IP',width:140,templet:function(d){ diff --git a/templates/admin/page/root/sys_setting.php b/templates/admin/page/root/sys_setting.php index 4a3f4a4..b50ce83 100644 --- a/templates/admin/page/root/sys_setting.php +++ b/templates/admin/page/root/sys_setting.php @@ -179,6 +179,16 @@ $title='系统设置';require(dirname(__DIR__).'/header.php'); + +
扩展功能
注:开关后请刷新整个页面
@@ -244,6 +254,18 @@ layui.use(['jquery','form'], function () { }); return false; }); + + //开启隐藏功能 + $('.layui-elem-field').click(function () { + if(Number( $(this).attr('click')) >= 6){ + $("#api_extend").show(); + }else{ + let click = $(this).attr('click') ? Number($(this).attr('click')) + 1 : 0; + $(this).attr('click',click) + } + + }); + }); diff --git a/templates/admin/page/root/tool.php b/templates/admin/page/root/tool.php index 5341aa5..5adedd8 100644 --- a/templates/admin/page/root/tool.php +++ b/templates/admin/page/root/tool.php @@ -27,7 +27,7 @@ require(dirname(__DIR__).'/header.php'); - +
 1.功能都集中在上方的按钮了,需要那个就点击那个!
diff --git a/templates/admin/page/updatelog.php b/templates/admin/page/updatelog.php
index 96acc23..aa7e9ed 100644
--- a/templates/admin/page/updatelog.php
+++ b/templates/admin/page/updatelog.php
@@ -2,6 +2,20 @@
 
 
+
  • + +
    +

    v2.0.17-20230428

    +
      +
    • [优化] 删除用户时支持同时删除用户文件夹 ( 图标/留言等数据 ) 和备份数据
    • +
    • [优化] 链接列表 > 检测功能的准确性
    • +
    • [优化] 系统日志按新旧排序,支持记录邮件发送日志
    • +
    • [修复] 用户注册初始数据可能复制失败
    • +
    • [新增] ATool工具箱支持修改用户名 ( 建议修改前先备份数据 )
    • +
    • [新增] 网站管理 > 站长工具 > 邮件配置 ( 用于配置注册时发送验证码 )
    • +
    +
    +
  • diff --git a/templates/home/default/index.php b/templates/home/default/index.php index 4280b96..4e95fc9 100644 --- a/templates/home/default/index.php +++ b/templates/home/default/index.php @@ -36,7 +36,7 @@ if ($DescrRowNumber <= 0 ){ - +