yjys_open.js 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. <?php
  2. //管理员应急工具箱
  3. error_reporting(E_ALL^E_NOTICE^E_WARNING^E_DEPRECATED);
  4. define('DIR',dirname(__DIR__));
  5. define('config_path', DIR . '/data/ATool_config.php'); ;
  6. //判断配置文件是否存在
  7. if(is_file(config_path)){
  8. require config_path;
  9. if(empty($config['key'])){
  10. exit('未读取到Key');
  11. }
  12. require DIR."/system/Msg.php";
  13. }else{
  14. require DIR.'/system/public.php';
  15. Reset_Config();
  16. }
  17. //switch状态
  18. if($config['switch'] === 1){
  19. }else{
  20. $msg['title'] = 'ATool未开启';
  21. $msg['methodTitle'] = '开启方式:';
  22. $msg['content'] = '1. 登录您的云服务器或虚拟主机<br /> 2. 进入TwoNav的程序目录<br /> 3. 编辑 data/ATool_config.php 将"switch" => 0 改为 "switch" => 1 <br /> 4. 复制Key的内容,保存后刷新此页面,使用Key验证即可进入ATool';
  23. require DIR.'/templates/admin/other/error.php';
  24. exit;
  25. }
  26. session_name('ATool_SSID');
  27. session_start();
  28. if(!empty($_GET['type'])){
  29. if($_GET['type'] == 'verify'){
  30. if(isset($_SESSION['verify']) && $_SESSION['verify'] === true){
  31. msg(-1,'您已经验证过了,无需重复验证!');
  32. }else{
  33. if(!empty($_POST['Key']) && $_POST['Key'] === md5($config['key'])){
  34. $_SESSION['verify'] = true;
  35. msg(1,'验证成功');
  36. }else{
  37. msg(-1,'Key错误');
  38. }
  39. }
  40. }
  41. //判断是否已验证
  42. if(isset($_SESSION['verify']) && $_SESSION['verify'] === true){
  43. $db = Load_db();
  44. $global_config = unserialize( get_db("global_config", "v", ["k" => "o_config"]) );
  45. }else{
  46. msg(-1,'鉴权失败');
  47. }
  48. if($_GET['type'] == 'logout'){
  49. $_SESSION['verify'] = false;
  50. Reset_Config();
  51. msg(1,'退出成功');
  52. }elseif($_GET['type'] == 'user_list'){
  53. $query = $_POST['query'];
  54. $UserGroup = @$_POST['UserGroup'];
  55. $page = empty(intval($_REQUEST['page'])) ? 1 : intval($_REQUEST['page']);
  56. $limit = empty(intval($_REQUEST['limit'])) ? 50 : intval($_REQUEST['limit']);
  57. $offset = ($page - 1) * $limit; //起始行号
  58. //用户组筛选
  59. if(!empty($UserGroup)){
  60. $where['AND']['UserGroup'] = $UserGroup;
  61. }
  62. //关键字筛选
  63. if(!empty($query)){
  64. $where['AND']['OR'] = ["User[~]" => $query,"Email[~]" => $query,"RegIP[~]" => $query];
  65. }
  66. //统计条数
  67. $count = count_db('global_user',$where);
  68. //权重排序(数字小的排前面)
  69. $where['ORDER']['RegTime'] = 'DESC';
  70. //分页
  71. $where['LIMIT'] = [$offset,$limit];
  72. //查询
  73. $datas = select_db('global_user',['ID','User','UserGroup','Email','RegIP','RegTime','Login'],$where);
  74. if(!empty($datas)){
  75. $user_group = select_db('user_group',['name','code'],'');//读用户组
  76. $user_group = array_column($user_group, 'name', 'code');//以代号为键
  77. $user_group['root'] = '站长';
  78. $user_group['default'] = '默认';
  79. foreach ($datas as $key => $data){
  80. $datas[$key]['UserGroupName'] = $user_group[$data['UserGroup']]??'Null';
  81. }
  82. }
  83. msgA(['code'=>1,'msg'=>'获取成功','count'=>$count,'data'=>$datas]);
  84. }elseif($_GET['type'] == 'set_pwd'){
  85. if(!has_db('global_user',['ID'=>$_POST['ID']])){
  86. msg(-1,'用户不存在!');
  87. }
  88. //空字符串md5 防止意外出现空密码
  89. if( $_POST['new_pwd']== 'd41d8cd98f00b204e9800998ecf8427e'){
  90. msg(-1,'密码不能为空');
  91. }
  92. $RegTime = get_db('global_user','RegTime',['ID'=>$_POST['ID']]);
  93. update_db('global_user',['Password'=>Get_MD5_Password($_POST['new_pwd'],$RegTime)],["ID" => $_POST['ID'] ],[1,'修改成功']);
  94. }elseif($_GET['type'] == 'set_root'){
  95. update_db('global_user',['UserGroup'=>'root'],["ID" => $_POST['ID'] ],[1,'修改成功']);
  96. //设为允许注册
  97. }elseif($_GET['type'] == 'set_allow_register'){
  98. $global_config['RegOption'] = 1;
  99. update_db("global_config", ["v" => $global_config], ["k" => "o_config"],[1,'设置成功']);
  100. //关闭维护模式
  101. }elseif($_GET['type'] == 'set_close_Maintenance'){
  102. $global_config['Maintenance'] = 0;
  103. update_db("global_config", ["v" => $global_config], ["k" => "o_config"],[1,'设置成功']);
  104. //重置静态路径
  105. }elseif($_GET['type'] == 'Set_Libs'){
  106. $global_config['Libs'] = "./static";
  107. update_db("global_config", ["v" => $global_config], ["k" => "o_config"],[1,'设置成功']);
  108. //清理缓存
  109. }elseif($_GET['type'] == 'Set_clear_cache'){
  110. clearstatcache();
  111. if(function_exists("opcache_reset")){
  112. opcache_reset(); //清理PHP缓存
  113. }
  114. msgA(['code'=>1,'msg'=>'操作成功']);
  115. //改账号
  116. }elseif($_GET['type'] == 'set_user_name'){
  117. //新用户名是否合规
  118. if(empty($_POST['new_user_name'])){
  119. msgA(['code'=>-1,'msg'=>'用户名不能为空']);
  120. }elseif(empty($_POST['ID'])){
  121. msgA(['code'=>-1,'msg'=>'ID不能为空']);
  122. }elseif(!preg_match('/^[A-Za-z0-9]{4,13}$/',$_POST['new_user_name'])){
  123. msg(-1,'账号只能是4到13位的数字和字母!');
  124. }
  125. //检测是否冲突
  126. if(file_exists(DIR."/data/user/".$_POST['new_user_name'])){
  127. msgA(['code'=>-1,'msg'=>'data/user/存在同名文件夹']);
  128. }
  129. if(file_exists(DIR."/data/backup/".$_POST['new_user_name'])){
  130. msgA(['code'=>-1,'msg'=>'data/backup/存在同名文件夹']);
  131. }
  132. //读取用户信息
  133. $USER = get_db("global_user", "*", ["ID" => $_POST['ID']]);
  134. if(empty($USER)){
  135. msgA(['code'=>-1,'msg'=>'用户ID不存在']);
  136. }elseif($USER['User'] == $_POST['new_user_name']){
  137. msgA(['code'=>-1,'msg'=>'新用户名不能和旧的一样']);
  138. }elseif(has_db('global_user',['User'=>$_POST['new_user_name']])){
  139. msgA(['code'=>-1,'msg'=>'新账号已存在,请核对后再试!']);
  140. }
  141. //移动数据目录
  142. $Path = DIR.'/data/user/'.$USER['User'];
  143. if(is_dir($Path)){
  144. $New_Path = DIR.'/data/user/'.$_POST['new_user_name'];
  145. if(!rename($Path,$New_Path)){
  146. msgA(['code'=>-1,'msg'=>'移动数据目录失败']);
  147. }
  148. }
  149. //移动备份目录
  150. $Path = DIR.'/data/backup/'.$USER['User'];
  151. if(is_dir($Path)){
  152. $New_Path = DIR.'/data/backup/'.$_POST['new_user_name'];
  153. if(!rename($Path,$New_Path)){
  154. msgA(['code'=>-1,'msg'=>'移动备份目录失败']);
  155. }
  156. }
  157. update_db("user_login_info", ["user" => $_POST['new_user_name']], ["user" => $USER['User']]);
  158. update_db("user_log", ["user" => $_POST['new_user_name']], ["user" => $USER['User']]);
  159. update_db("global_user", ["User" => $_POST['new_user_name']], ["ID" => $_POST['ID']],[1,'操作成功']);
  160. }elseif($_GET['type'] == 'del_otp'){
  161. $user_data = get_db('global_user','*',['ID'=>$_POST['ID']]);
  162. $LoginConfig = unserialize($user_data['LoginConfig']);
  163. if(empty($LoginConfig['totp_key'])){
  164. msgA(['code'=>-1,'msg'=>'当前账号未开启OTP双重验证']);
  165. }
  166. $LoginConfig['totp_key'] = '';
  167. update_db("global_user", ["LoginConfig" => $LoginConfig], ["ID" => $_POST['ID']],[1,'操作成功']);
  168. }
  169. msgA(['code'=>-1,'msg'=>'请求类型错误']);
  170. }else{
  171. //判断是否已验证
  172. if(isset($_SESSION['verify']) && $_SESSION['verify'] === true){
  173. $db = Load_db();
  174. $global_config = unserialize( get_db("global_config", "v", ["k" => "o_config"]) );
  175. echo_Atool();
  176. }else{
  177. echo_verify();
  178. }
  179. }
  180. //载入数据库
  181. function Load_db(){
  182. require DIR."/data/config.php";
  183. require DIR.'/system/Medoo.php';
  184. if($db_config['type'] == 'sqlite'){
  185. try {
  186. $db_config['path'] = DIR."/data/".$db_config['file'];
  187. $db = new Medoo\Medoo(['type'=>'sqlite','database'=>$db_config['path']]);
  188. }catch (Exception $e) {
  189. Amsg(-1,'载入数据库失败'.$db_config['path']);
  190. }
  191. }elseif($db_config['type'] == 'mysql'){
  192. try {
  193. $db = new Medoo\Medoo(['type' => 'mysql',
  194. 'host' => $db_config['host'],
  195. 'port' => $db_config['port'],
  196. 'database' => $db_config['name'],
  197. 'username' => $db_config['user'],
  198. 'password' => $db_config['password']
  199. ]);
  200. }catch (Exception $e) {
  201. Amsg(-1,'链接数据库失败!');
  202. }
  203. }
  204. require DIR.'/system/public.php';
  205. return $db;
  206. }
  207. function echo_Atool(){
  208. global $global_config;
  209. ?>
  210. <!DOCTYPE html>
  211. <html lang="en">
  212. <head>
  213. <meta charset="UTF-8">
  214. <title>ATool 工具箱</title>
  215. <link rel="stylesheet" href="../static/Layui/v2.8.17/css/layui.css">
  216. <style>
  217. html, body {min-width: 1200px;background-color: #fff;position: relative;}
  218. .page-wrapper {width: 1200px;margin: 0 auto;padding: 0 15px;}
  219. </style>
  220. </head>
  221. <body>
  222. <div class="page-wrapper">
  223. <fieldset class="layui-elem-field layui-field-title">
  224. <legend> ATool 工具箱 </legend>
  225. </fieldset>
  226. <div class="layui-btn-container" style="display: inline-block;">
  227. <button id="logout" class="layui-btn layui-btn-sm layui-btn-primary"><i class="layui-icon layui-icon-snowflake"></i>安全退出</button>
  228. <a class="layui-btn layui-btn-sm layui-btn-primary" href="../index.php?c=<?php echo $global_config['Login'];?>" target="_blank"><i class="layui-icon layui-icon-username"></i>打开登录页</a>
  229. <a class="layui-btn layui-btn-sm layui-btn-primary" href="../index.php?c=<?php ec