better-staridc-MNBT
1<?php
2if($egn=='yjbs') {
3 //一键部署
4 $id=daddslashes($_POST['id'] ?? 0);
5 $zxwc_ms_h='3';
6 //每次远程操作执行完成后等待的秒数
7 $res=$DB->get_row_prepare("SELECT * FROM MN_bs WHERE id=? limit 1", [$id]);
8 if(!in_array((string)($res['qk'] ?? ''), ['true','1','TRUE','True'], true))exit('{"code":"禁止部署已经下架的程序"}');
9 $pz_jx_json=json_decode($res['sxpz'],true) ?: [0, 0];
10 $pz_web_a=$pz_jx_json[0] ?? 0;
11 $pz_sql_a=$pz_jx_json[1] ?? 0;
12 $hxa = json_decode($yhc['hxa'],true) ?: [];
13 $hxb = json_decode($yhc['hxb'],true) ?: [];
14 if($pz_web_a>($hxa['max']??0) || $pz_sql_a>($hxb['max']??0))exit('{"code":"您的配置未达到要求!"}');
15 if(!in_array($yhc['user'],json_decode($res['tj'],true) ?: []) && $res['jg']!=0)exit('{"code":"您未购买该程序"}');
16 include("../fn.php");
17 //引入代码执行库
18 include("../class.php");
19 //引入数据处理库
20 $api = new bt_api($btipe,$btkeye);
21 //实例化类
22 $cxform = json_decode($res['inp'], true) ?: [];
23 $bds = [];
24 foreach ($cxform as $va => $val) {
25 $cz = $val['cz'] ?? '';
26 if ($cz !== '' && isset($_POST[$cz])) {
27 $bds[$va][$cz] = $_POST[$cz];
28 }
29 }
30 $userform=formcl($res['inp'], $bds);
31 //获取变量与用户提交数据的的对应数组
32 if($userform['code']=='0')exit(json_encode(['qk'=>4,"code"=>$userform['msg']]));
33 $file=$res['cxwz'];
34 $type='application/zip';
35 $name=basename($file);
36 //获取文件名称
37 $wj=$api->GetLogshqwjlo($os_xt.$yhc['sqldz']);
38 //网站目录下所有文件
39 $nameh=array();
40 $sl=0;
41 foreach (($wj['DIR'] ?? []) as $val) {
42 $nameb=explode(";",$val);
43 array_push($nameh,$nameb[0]);
44 }
45 foreach (($wj['FILES'] ?? []) as $val) {
46 $nameb=explode(";",$val);
47 if($nameb[0]!='.user.ini') {
48 array_push($nameh,$nameb[0]);
49 }
50 //不删除防跨站配置文件
51 }
52 $json=json_encode($nameh);
53 $c1=$api->xzdelwj('/',$json,[$yhc['btid'],$os_xt.$yhc['sqldz']]);
54 //删除该站点所有文件
55 sleep($zxwc_ms_h);
56 $c2=$api->zswjsc(array('tmp_name'=>$file,'type'=>$type,'name'=>$name),$os_xt.$yhc['sqldz']);
57 //上传源码
58 sleep($zxwc_ms_h);
59 $c3=$api->GetLogsjywj($os_xt.$yhc['sqldz'].'/'.$name,$os_xt.$yhc['sqldz'],'UTF-8','');
60 //解压文件
61 sleep($zxwc_ms_h);
62 $c4=$api->delwj($os_xt.$yhc['sqldz'].'/'.$name);
63 //删除源码
64 $c5=$api->setyxml([$yhc['btid'],'/',$os_xt.$yhc['sqldz']]);
65 //将运行目录设置为根目录
66 $c6 = $api->setwjt(['','/www/server/panel/vhost/rewrite/'.$yhc['sqldz'].'.conf']);
67 //将伪静态设置为空
68 $bs=1;
69 if($res['pz']!='null' && !empty($res['pz'])) {
70 foreach (json_decode($res['pz'],true) ?: [] as $val) {
71 $funcz=$val['cz'];
72 //获取该执行哪个函数
73 $ab=$funcz($val,$yhc,$os_xt,$userform);
74 //对数据进行处理
75 if($funcz!='gettj') {
76 $abc=$api->$funcz($ab);
77 //执行操作
78 if($abc['status']==false) {
79 exit(json_encode(['code'=>"部署失败:第{$bs}步出错,错误提示:{$abc['msg']}"]));
80 break;
81 }
82 }
83 $bs++;
84 sleep('0.5');
85 //此处只用等待0.5秒即可
86 }
87 }
88 $bs_tj=json_decode($res['tj'],true) ?: [];
89 if(!in_array($yhc['user'],$bs_tj)) {
90 $bs_tj[]=$yhc['user'];
91 }
92 $tj=json_encode($bs_tj,256);
93 $DB->query_prepare("update `MN_bs` set `tj` =? where `id`=?", [$tj, $id]);
94 if($res['alet']!=null) {
95 exit(json_encode(['qk'=>1,"code"=>tihs($res['alet'],$userform,$yhc)]));
96 } else {
97 exit(json_encode(['qk'=>1,"code"=>'程序部署成功!']));
98 }
99 return;
100}
101if($egn=='yjbsform') {
102 //一键部署-表单获取
103 $id=$_POST['id'] ?? 0;
104 $res=$DB->get_row_prepare("SELECT * FROM MN_bs WHERE id=? limit 1", [$id]);
105 if(!in_array((string)($res['qk'] ?? ''), ['true','1','TRUE','True'], true))exit(json_encode(["qk"=>4,'code'=>"无法部署已经下架从程序!"],256));
106 $pz_jx_json=json_decode($res['sxpz'],true) ?: [0, 0];
107 $pz_web_a=$pz_jx_json[0] ?? 0;
108 $pz_sql_a=$pz_jx_json[1] ?? 0;
109 $hxa = json_decode($yhc['hxa'],true) ?: [];
110 $hxb = json_decode($yhc['hxb'],true) ?: [];
111 if($pz_web_a>($hxa['max']??0) || $pz_sql_a>($hxb['max']??0))exit(json_encode(["qk"=>4,'code'=>"您的配置未达到要求"],256));
112 if(!in_array($yhc['user'],json_decode($res['tj'],true) ?: []) && $res['jg']!=0)exit(json_encode(["qk"=>4,'code'=>"您未购买该程序!"],256));
113 exit(json_encode(["qk"=>1,'code'=>"获取成功!",'form'=>$res['inp']],256));
114 return;
115}