better-staridc-MNBT
1<?php
2if($egn=='phpxg') {
3 $php=daddslashes($_POST['php'] ?? '');
4 include("../class.php");
5 $apie = new bt_api_set($btipe,$btkeye);
6 $r_data = $apie->btapi_setphp($yhc['sqldz'],$php);
7 $ok = isset($r_data['status']) && ($r_data['status'] === true || $r_data['status'] === 'true');
8 logjl($yhc['user'],'PHP版本','修改PHP版本为'.$php, $ok?'修改成功':'修改失败:'.($r_data['msg']??'未知错误'), $DB);
9 if($ok) {
10 exit(json_encode(['code'=>'修改成功', 'phpversion'=>$php], JSON_UNESCAPED_UNICODE));
11 } else {
12 exit(json_encode(['code'=>'修改失败:'.($r_data['msg']??'未知错误')], JSON_UNESCAPED_UNICODE));
13 }
14}
15if($egn=='sqldr') {
16 //导入SQL文件
17 $ml=daddslashes($_POST['path'] ?? '');
18 $name=daddslashes($_POST['filename'] ?? '');
19 if(substr($ml,0,1)!='/')exit('{"code":"目录格式错误!"}');
20 if(strpos($name,'/')!==false)exit('{"code":"文件名格式错误!"}');
21 if(substr(strtolower($name),'-4' , 4)!='.sql')exit('{"code":"错误!您导入的文件不是SQL文件!"}');
22 $path = $os_xt.$yhc['sqldz'].$ml;
23 include("../class.php");
24 $api = new bt_api($btipe,$btkeye);
25 $list=dirfiles(($api->GetLogshqwjlo($path) ?: [])['FILES'] ?? [],'file')['file'];
26 $file=false;
27 foreach($list as $val) {
28 if($val['name']==$name) {
29 $file=$val;
30 break;
31 }
32 }
33 if(!$file)exit('{"code":"错误!文件不存在!"}');
34 $sqlsize=json_decode($yhc['hxb'],true);
35 $mbsize=round($file['size']/1048576);
36 if($mbsize>$sqlsize['max'])exit('{"code":"错误!导入的文件大于您的最大可用数据库空间!"}');
37 if($sqlsize['max']<=$sqlsize['dq'])exit('{"code":"错误!您的数据库空间已满!"}');
38 if($mbsize>$sqlsize['max']-$sqlsize['dq'])exit('{"code":"错误!导入的文件大于您现在可用的数据库空间大小!请清除数据库空间至剩余'.$mbsize.'MB为止!"}');
39 $r_datr = $api->drsql(array($path.$name,$yhc['sqluser']));
40 $r_datr = $r_datr ?: [];
41 logjl($yhc['user'],'导入SQL','导入SQL文件'.$name,'导入成功',$DB);
42 json_exit($r_datr['msg']??'');
43 return;
44}
45if($egn=='scmmfw') {
46 //删除密码访问
47 $setname=$_POST['mb'] ?? '';
48 include("../class.php");
49 $api = new bt_api($btipe,$btkeye);
50 $r_data = $api->GetLogsr($zjid,$setname) ?: [];
51 logjl($yhc['user'],'密码访问','删除了密码访问目录'.$setname,'删除成功',$DB);
52 json_exit($r_data['msg']??'');
53 return;
54}
55if($egn=='tjmmfw') {
56 //添加密码访问
57 $name=$_POST['name'] ?? '';
58 $ml=$_POST['mbml'] ?? '';
59 $zh=$_POST['user'] ?? '';
60 $mm=$_POST['pass'] ?? '';
61 if(substr($ml,0,1)!='/')exit('{"code":"目录格式错误!"}');
62 include("../class.php");
63 $api = new bt_api($btipe,$btkeye);
64 $r_data = $api->GetLogst($zjid,$name,$ml,$zh,$mm) ?: [];
65 logjl($yhc['user'],'密码访问','添加了密码访问目录'.$ml,'添加成功',$DB);
66 json_exit($r_data['msg']??'');
67 return;
68}
69if($egn=='xgmrwd') {
70 //修改默认文档
71 $index=$_POST['ml'] ?? '';
72 include("../class.php");
73 $api = new bt_api($btipe,$btkeye);
74 $r_data = $api->GetLogsea($zjid,$index) ?: [];
75 logjl($yhc['user'],'默认文档','修改默认文档为'.$index,'修改成功',$DB);
76 json_exit($r_data['msg']??'');
77 return;
78}
79if($egn=='hqjt') {
80 //获取伪静态
81 $tdxz=($_POST['xz']??'')!='0.当前'?'rewrite/nginx/'.($_POST['xz']??''):'vhost/rewrite/'.$yhc['sqldz'];
82 $jt='/www/server/panel/'.$tdxz.'.conf';
83 if($cert['btos']=='1') {
84 $jt='/www/server/panel/'.$tdxz.'.conf';
85 } else {
86 $jt='D:/BtSoft/panel/'.$tdxz.'.conf';
87 }
88 include("../class.php");
89 $api = new bt_api($btipe,$btkeye);
90 $r_data = $api->GetLogswt($jt) ?: [];
91 exit($r_data['data']??'');
92 return;
93}
94if($egn=='setwjt') {
95 //设置伪静态
96 include("../class.php");
97 if($cert['btos']=='1') {
98 //$jt='/www/server/panel/'.$tdxz.'.conf';
99 $api = new bt_api($btipe,$btkeye);
100 $r_data = $api->setwjt([$_POST['wb']??'','/www/server/panel/vhost/rewrite/'.$yhc['sqldz'].'.conf']) ?: [];
101 json_exit($r_data['msg']??'');
102 } else {
103 //$jt='/www/server/panel/'.$tdxz.'.conf';
104 $api = new win_bt_api($btipe,$btkeye);
105 $r_data = $api->setwjt([$yhc['sqldz'],$_POST['wb']??'']) ?: [];
106 json_exit($r_data['msg']??'');
107 }
108 return;
109}
110if($egn=='ftpjy') {
111 //解压文件
112 $ywj=$_POST['jywj'] ?? '';
113 $jyd=$_POST['jyd'] ?? '';
114 $jypass=$_POST['jymm'] ?? '';
115 $jybm=$_POST['wjbm'] ?? '';
116 if(substr($jyd,0,1)!='/')exit('{"code":"解压到的目录格式错误!"}');
117 include("../class.php");
118 $api = new bt_api($btipe,$btkeye);
119 $r_data = $api->GetLogsjywj($os_xt.$yhc['sqldz'].$ywj,$os_xt.$yhc['sqldz'].$jyd,$jybm,$jypass);
120 json_exit('解压成功');
121 return;
122}
123if($egn=='xgpass') {
124 //修改密码
125 $ftpmm=daddslashes($_POST['ftp'] ?? '');
126 $sqlmm=daddslashes($_POST['sql'] ?? '');
127 if(mb_strlen($ftpmm)<6 && mb_strlen($ftpmm)!=0 || mb_strlen($sqlmm)<6 && mb_strlen($sqlmm)!=0 )exit('{"code":"错误!FTP密码和数据库密码都不能小于6位!"}');
128 $user=$yhc['user'];
129 if(empty($ftpmm) && empty($sqlmm))exit('{"code":"错误!FTP密码和SQL密码不能全为空!"}');
130 include("../class.php");
131 $api = new bt_api($btipe,$btkeye);
132 if(empty($ftpmm)) {
133 $pass=$yhc['pass'];
134 } else {
135 $api->GetLogsftp($yhc['ftpid'],$yhc['user'],$ftpmm);
136 $pass=$ftpmm;
137 }
138 if(empty($sqlmm)) {
139 $gpwd=$yhc['sqlpass'];
140 } else {
141 $api->GetLogsworld($yhc['hxd'],$yhc['sqluser'],$sqlmm);
142 $gpwd=$sqlmm;
143 }
144 logjl($yhc['user'],'密码修改','修改了FTP和数据库密码','修改成功',$DB);
145 if($DB->query_prepare("update `MN_zj` set `sqlpass` =?, `pass` =? where `user`=?", [$gpwd, $pass, $user])) json_exit('修改成功'); else json_exit('修改失败');
146 return;
147}
148if($egn=='setyxml') {
149 //设置运行目录
150 $szh=daddslashes($_POST['wb'] ?? '');
151 if(substr($szh,0,1)!='/')exit('{"code":"目录格式错误!"}');
152 include("../class.php");
153 $api = new bt_api($btipe,$btkeye);
154 $abc=$api->setyxml([$yhc['btid'],$szh,$os_xt.$yhc['sqldz']]);
155 $abc = $abc ?: [];
156 logjl($yhc['user'],'运行目录','设置运行目录为'.$szh,'设置成功',$DB);
157 json_exit($abc['msg']??'');
158 return;
159}
160if($egn=='sxsyxx') {
161 //刷新网页空间,数据库空间,流量使用情况
162 // 与其它接口一致用 ../class.php(旧 ../../class.php 在 CWD=user 时会越界失败 → 500)
163 include("../class.php");
164 $sql_kjr = json_decode($yhc['hxb'] ?? '', true) ?: [];
165 $web_kjr = json_decode($yhc['hxa'] ?? '', true) ?: [];
166 $ll_kjr = json_decode($yhc['llmax'] ?? '', true) ?: [];
167 $r_js_web = $web_kjr;
168 $r_js_sql = $sql_kjr;
169 $api = new bt_api($btipe, $btkeye);
170$t_id = $yhc['id'] ?? 0;
171
172$r_data = $api->webkjjs($os_xt . $yhc['sqldz']) ?: [];
173$webkj = ($r_data['size'] ?? 0) / (1024 * 1000);
174$r_js_web = $web_kjr;
175$r_js_web['dq'] = sprintf('%.2f', $webkj);
176$r_sy = json_encode($r_js_web, 256);
177$DB->query_prepare('update `MN_zj` set `hxa` =? where `id`=?', [$r_sy, $t_id]);
178
179$r_datb = $api->sqlkjhq($yhc['sqluser'] ?? '') ?: [];
180$r_datb_data_size = (string)($r_datb['data_size'] ?? '0');
181if (substr($r_datb_data_size, -2) == 'kb' || substr($r_datb_data_size, -2) == 'KB' || substr($r_datb_data_size, -2) == 'kB' || substr($r_datb_data_size, -2) == 'Kb') {
182 $sqlkj = str_ireplace(substr($r_datb_data_size, -2), '', $r_datb_data_size);
183} elseif (substr($r_datb_data_size, -2) == 'MB' || substr($r_datb_data_size, -2) == 'mb' || substr($r_datb_data_size, -2) == 'Mb' || substr($r_datb_data_size, -2) == 'mB') {
184 $sqlkj = str_ireplace(substr($r_datb_data_size, -2), '', $r_datb_data_size) * 1000;
185} elseif (substr($r_datb_data_size, -1) == 'b' || substr($r_datb_data_size, -1) == 'B') {
186 $sqlkj = (float)preg_replace('/[^0-9.]/', '', $r_datb_data_size) / 1000;
187} else {
188 $sqlkj = '0';
189}
190$adft = ((float)$sqlkj) / 1024;
191$r_js_sql = $sql_kjr;
192$r_js_sql['dq'] = sprintf('%.2f', $adft);
193$r_sy = json_encode($r_js_sql, 256);
194$DB->query_prepare('update `MN_zj` set `hxb` =? where `id`=?', [$r_sy, $t_id]);
195
196 $s_data = $api->getlog($yhc['sqldz'] ?? '') ?: [];
197 $g_size = 0;
198 if (($s_data['status'] ?? false) && ($s_data['msg'] ?? '') != '') {
199 $sfyr = explode(' - - ', $s_data['msg']);
200 unset($sfyr[0]);
201 $latest_ts = '';
202 foreach ($sfyr as $vfm) {
203 preg_match('/\[(.*?)\]/', $vfm, $tm);
204 if (!($tm[1] ?? '')) continue;
205 if (isset($ll_kjr['statistics']) && $ll_kjr['statistics'] !== '' && $tm[1] <= $ll_kjr['statistics']) continue;
206 $e_size = explode(' ', $vfm);
207 if (!isset($e_size[6]) || !is_numeric($e_size[6])) continue;
208 $g_size += $e_size[6];
209 if ($tm[1] > $latest_ts) $latest_ts = $tm[1];
210 }
211 if ($latest_ts !== '') $ll_kjr['statistics'] = $latest_ts;
212 }
213 $ll_kjr['dq'] = ($ll_kjr['dq'] ?? 0) + $g_size;
214 $r_sy = json_encode($ll_kjr, 256);
215 $DB->query_prepare('update `MN_zj` set `llmax` =? where `id`=?', [$r_sy, $t_id]);
216
217 // 未定义 max/dq 时按 0,避免 PHP8 Warning→Exception 导致 500
218 $ll_ok = (float)($ll_kjr['dq'] ?? 0) <= (float)($ll_kjr['max'] ?? 0) * 1024 * 1024 * 1024;
219 $web_ok = (float)($r_js_web['dq'] ?? 0) <= (float)($r_js_web['max'] ?? 0);
220 $sql_ok = (float)($r_js_sql['dq'] ?? 0) <= (float)($r_js_sql['max'] ?? 0);
221 if ($ll_ok && $web_ok && $sql_ok) {
222 $api->qdweb($yhc['btid'] ?? '', $yhc['sqldz'] ?? '');
223 $api->ftpxg($yhc['ftpid'] ?? '', $yhc['user'] ?? '', '1');
224 } else {
225 $api->ztweb($yhc['btid'] ?? '', $yhc['sqldz'] ?? '');
226 $api->ftpxg($yhc['ftpid'] ?? '', $yhc['user'] ?? '', '0');
227 }
228 json_exit('刷新成功!');
229 return;
230}
231
232if($egn=='setgzip' || $egn=='gzip') {
233 $action = $_POST['action'] ?? ($_POST['status'] ?? '');
234 include("../class.php");
235 $api = new bt_api($btipe,$btkeye);
236 if ($action === 'off' || $action === '0' || $action === 0 || $action === false) {
237 $result = $api->remove_gzip_status($yhc['sqldz']);
238 } else {
239 $level = intval($_POST['level'] ?? 6);
240 if ($level < 1 || $level > 9) $level = 6;
241 $min_len = trim($_POST['min_len'] ?? '1k');
242 if ($min_len === '') $min_len = '1k';
243 $types = trim($_POST['types'] ?? 'text/plain application/javascript application/x-javascript text/javascript text/css application/xml application/json image/jpeg image/gif image/png font/ttf font/otf image/svg+xml application/xml+rss text/x-js');
244 $result = $api->set_gzip($yhc['sqldz'], $types, (string)$level, $min_len);
245 }
246 if (isset($result['status']) && ($result['status'] === true || $result['status'] === 'true')) {
247 logjl($yhc['user'], 'Gzip配置', '修改Gzip压缩为: '.$action, '修改成功', $DB);
248 json_exit('修改成功');
249 } else {
250 logjl($yhc['user'], 'Gzip配置', '修改Gzip压缩为: '.$action, '修改失败:'.($result['msg'] ?? '未知错误'), $DB);
251 json_exit('操作失败:'.($result['msg'] ?? '未知错误'));
252 }
253 return;
254}