正在显示
3 个修改的文件
包含
1817 行增加
和
0 行删除
app/Console/Commands/SelfSiteSsl.php
0 → 100644
| 1 | +<?php | ||
| 2 | + | ||
| 3 | +namespace App\Console\Commands; | ||
| 4 | + | ||
| 5 | +use App\Repositories\BtRepository; | ||
| 6 | +use Illuminate\Console\Command; | ||
| 7 | + | ||
| 8 | +class SelfSiteSsl extends Command | ||
| 9 | +{ | ||
| 10 | + protected $signature = 'self_site_ssl'; | ||
| 11 | + protected $description = '自建站项目自动更新证书'; | ||
| 12 | + | ||
| 13 | + protected $bt_repository; | ||
| 14 | + protected $bt; | ||
| 15 | + | ||
| 16 | + public function __construct() | ||
| 17 | + { | ||
| 18 | + parent::__construct(); | ||
| 19 | + | ||
| 20 | + $this->bt_repository = new BtRepository(); | ||
| 21 | + $this->bt = $this->bt_repository->getBtObject(); | ||
| 22 | + } | ||
| 23 | + | ||
| 24 | + public function handle() | ||
| 25 | + { | ||
| 26 | + try { | ||
| 27 | + $this->checkDomainSsl(); | ||
| 28 | + } catch (\Exception $e) { | ||
| 29 | + $this->output($e->getMessage()); | ||
| 30 | + } | ||
| 31 | + } | ||
| 32 | + | ||
| 33 | + public function checkDomainSsl() | ||
| 34 | + { | ||
| 35 | + $end_day = date('Y-m-d H:i:s', time() + 3 * 24 * 3600);//3天后到期 | ||
| 36 | + | ||
| 37 | + $site_domain = env('DOMAIN', ''); | ||
| 38 | + $site_ip = env('SITE_IP', ''); | ||
| 39 | + | ||
| 40 | + if (!$site_domain) { | ||
| 41 | + throw new \Exception('项目主站域名未配置'); | ||
| 42 | + } | ||
| 43 | + | ||
| 44 | + if (!$site_ip) { | ||
| 45 | + throw new \Exception('项目主站IP未配置'); | ||
| 46 | + } | ||
| 47 | + | ||
| 48 | + $ssl_time = $this->getDomainSslTime($site_domain); | ||
| 49 | + if ($ssl_time['to'] < $end_day) { | ||
| 50 | + //主站证书即将到期 | ||
| 51 | + $site_list = $this->bt->WebSiteList($site_domain); | ||
| 52 | + if (isset($site_list['data']) && $site_list['data'] && $site_list['data'][0]['status'] == 1) { | ||
| 53 | + $site_id = $site_list['data'][0]['id']; | ||
| 54 | + $host = $site_list['data'][0]['name']; | ||
| 55 | + | ||
| 56 | + //获取站点可用于设置证书的域名 | ||
| 57 | + $site_domain = $this->bt->WebDoaminList($site_id); | ||
| 58 | + $apply_ssl_domain_list = []; | ||
| 59 | + foreach ($site_domain as $val) { | ||
| 60 | + if (strpos($val['name'], '*') === false && $this->check_domain_record($val['name'], ['ip' => $site_ip])) { | ||
| 61 | + $apply_ssl_domain_list[] = $val['name']; | ||
| 62 | + } | ||
| 63 | + } | ||
| 64 | + if (empty($apply_ssl_domain_list)) { | ||
| 65 | + throw new \Exception('主站所有域名都未解析在当前服务器'); | ||
| 66 | + } | ||
| 67 | + | ||
| 68 | + //申请证书之前,还原主站配置 | ||
| 69 | + $config_before = file_get_contents(public_path('main_site_default.txt')); | ||
| 70 | + $re_config_before = $this->bt->SaveFileBody('/www/server/panel/vhost/nginx/' . $host . '.conf', $config_before, 'utf-8', 1); | ||
| 71 | + if (!($re_config_before['status'] ?? false)) { | ||
| 72 | + throw new \Exception($re_config_before['msg'] ?? '还原主站nginx配置失败'); | ||
| 73 | + } | ||
| 74 | + | ||
| 75 | + //设置站点证书 | ||
| 76 | + $this->setDomainSsl($site_id, $host, $apply_ssl_domain_list); | ||
| 77 | + | ||
| 78 | + //申请证书之后,更新主站配置 | ||
| 79 | + $config_after = file_get_contents(public_path('main_site_config.txt')); | ||
| 80 | + $re_config_after = $this->bt->SaveFileBody('/www/server/panel/vhost/nginx/' . $host . '.conf', $config_after, 'utf-8', 1); | ||
| 81 | + if (!($re_config_after['status'] ?? false)) { | ||
| 82 | + throw new \Exception($re_config_after['msg'] ?? '更新主站nginx配置失败'); | ||
| 83 | + } | ||
| 84 | + | ||
| 85 | + $this->output('主站证书更新成功'); | ||
| 86 | + } | ||
| 87 | + } | ||
| 88 | + | ||
| 89 | + $amp_domain = env('AMP_DOMAIN', ''); | ||
| 90 | + if ($amp_domain) { | ||
| 91 | + $amp_ssl_time = $this->getDomainSslTime($amp_domain); | ||
| 92 | + if ($amp_ssl_time['to'] < $end_day) { | ||
| 93 | + //AMP证书即将到期 | ||
| 94 | + $amp_site_list = $this->bt->WebSiteList($amp_domain); | ||
| 95 | + if (isset($amp_site_list['data']) && $amp_site_list['data'] && $amp_site_list['data'][0]['status'] == 1) { | ||
| 96 | + $amp_site_id = $amp_site_list['data'][0]['id']; | ||
| 97 | + $amp_host = $amp_site_list['data'][0]['name']; | ||
| 98 | + | ||
| 99 | + //设置站点证书 | ||
| 100 | + $this->setDomainSsl($amp_site_id, $amp_host, [$amp_host]); | ||
| 101 | + | ||
| 102 | + $this->output('AMP站证书更新成功'); | ||
| 103 | + } | ||
| 104 | + } | ||
| 105 | + } | ||
| 106 | + } | ||
| 107 | + | ||
| 108 | + /** | ||
| 109 | + * 检查域名解析师是否正确 | ||
| 110 | + * @param $domain | ||
| 111 | + * @param $server_info | ||
| 112 | + * @return bool | ||
| 113 | + * @author Akun | ||
| 114 | + * @date 2025/01/13 14:53 | ||
| 115 | + */ | ||
| 116 | + public function check_domain_record($domain, $server_info) | ||
| 117 | + { | ||
| 118 | + try { | ||
| 119 | + $records = dns_get_record($domain, DNS_A); | ||
| 120 | + if (count($records) != 1) { | ||
| 121 | + return false; | ||
| 122 | + } | ||
| 123 | + | ||
| 124 | + $record = $records[0]; | ||
| 125 | + if ($record['host'] == $server_info['domain'] || $record['ip'] == $server_info['ip']) { | ||
| 126 | + return $domain; | ||
| 127 | + } else { | ||
| 128 | + return false; | ||
| 129 | + } | ||
| 130 | + } catch (\Exception $e) { | ||
| 131 | + return false; | ||
| 132 | + } | ||
| 133 | + } | ||
| 134 | + | ||
| 135 | + /** | ||
| 136 | + * 设置域名证书 | ||
| 137 | + * @param $site_id | ||
| 138 | + * @param $host | ||
| 139 | + * @param $domain_list | ||
| 140 | + * @param string $key | ||
| 141 | + * @param string $cer | ||
| 142 | + * @throws \Exception | ||
| 143 | + * @author Akun | ||
| 144 | + * @date 2025/01/13 14:53 | ||
| 145 | + */ | ||
| 146 | + public function setDomainSsl($site_id, $host, $domain_list, $key = '', $cer = '') | ||
| 147 | + { | ||
| 148 | + if (empty($key) || empty($cer)) { | ||
| 149 | + $ssl = $this->bt->GetSSL($host); | ||
| 150 | + if (isset($ssl['cert_data']['notAfter']) && strtotime($ssl['cert_data']['notAfter']) - time() > 259200) { | ||
| 151 | + // 如果已经申请了ssl证书, 并且证书有效期超过3天, 那么就使用已经申请好的证书 | ||
| 152 | + $key = $ssl['key']; | ||
| 153 | + $cer = $ssl['csr']; | ||
| 154 | + $is_set_status = !$ssl['status']; | ||
| 155 | + } else { | ||
| 156 | + $re_apply_cert = $this->bt->ApplyCert(json_encode($domain_list), $site_id); | ||
| 157 | + if (!($re_apply_cert['status'] ?? false)) { | ||
| 158 | + $apply_error_msg = '申请免费证书失败'; | ||
| 159 | + if (isset($re_apply_cert['msg'])) { | ||
| 160 | + if (is_array($re_apply_cert['msg'])) { | ||
| 161 | + $apply_error_msg = json_encode($re_apply_cert['msg']); | ||
| 162 | + } else { | ||
| 163 | + $apply_error_msg = $re_apply_cert['msg']; | ||
| 164 | + } | ||
| 165 | + } | ||
| 166 | + throw new \Exception($apply_error_msg); | ||
| 167 | + } | ||
| 168 | + | ||
| 169 | + $key = $re_apply_cert['private_key']; | ||
| 170 | + $cer = $re_apply_cert['cert']; | ||
| 171 | + $is_set_status = true; | ||
| 172 | + } | ||
| 173 | + } else { | ||
| 174 | + $is_set_status = true; | ||
| 175 | + } | ||
| 176 | + | ||
| 177 | + if ($key && $cer && $is_set_status) { | ||
| 178 | + $re_set_ssl = $this->bt->SetSSL(1, $host, $key, $cer); | ||
| 179 | + if (!($re_set_ssl['status'] ?? false)) { | ||
| 180 | + throw new \Exception($re_set_ssl['msg'] ?? '设置证书失败'); | ||
| 181 | + } | ||
| 182 | + } | ||
| 183 | + } | ||
| 184 | + | ||
| 185 | + /** | ||
| 186 | + * 获取域名证书有效时间 | ||
| 187 | + * @param $domain | ||
| 188 | + * @return string[] | ||
| 189 | + * @author Akun | ||
| 190 | + * @date 2024/08/29 9:59 | ||
| 191 | + */ | ||
| 192 | + public function getDomainSslTime($domain) | ||
| 193 | + { | ||
| 194 | + $valid_from = ''; | ||
| 195 | + $valid_to = ''; | ||
| 196 | + try { | ||
| 197 | + $context = stream_context_create([ | ||
| 198 | + 'ssl' => [ | ||
| 199 | + 'capture_peer_cert' => true, | ||
| 200 | + 'capture_peer_cert_chain' => false, | ||
| 201 | + 'verify_peer' => false, | ||
| 202 | + 'verify_peer_name' => false | ||
| 203 | + ], | ||
| 204 | + ]); | ||
| 205 | + $stream = stream_socket_client('ssl://' . $domain . ':443', $errno, $errstr, 30, STREAM_CLIENT_CONNECT, $context); | ||
| 206 | + if ($stream) { | ||
| 207 | + $remote_cert = stream_context_get_params($stream)['options']['ssl']['peer_certificate']; | ||
| 208 | + if ($remote_cert) { | ||
| 209 | + $valid_from = date('Y-m-d H:i:s', openssl_x509_parse($remote_cert)['validFrom_time_t']); | ||
| 210 | + $valid_to = date('Y-m-d H:i:s', openssl_x509_parse($remote_cert)['validTo_time_t']); | ||
| 211 | + } | ||
| 212 | + } | ||
| 213 | + fclose($stream); | ||
| 214 | + } catch (\Exception $e) { | ||
| 215 | + $valid_from = ''; | ||
| 216 | + $valid_to = ''; | ||
| 217 | + } | ||
| 218 | + return ['from' => $valid_from, 'to' => $valid_to]; | ||
| 219 | + } | ||
| 220 | + | ||
| 221 | + /** | ||
| 222 | + * 输出处理日志 | ||
| 223 | + * @param $message | ||
| 224 | + */ | ||
| 225 | + public function output($message) | ||
| 226 | + { | ||
| 227 | + echo date('Y-m-d H:i:s') . ' | ' . $message . PHP_EOL; | ||
| 228 | + } | ||
| 229 | +} | 
app/Repositories/Bt/Bt.php
0 → 100644
| 1 | +<?php | ||
| 2 | +namespace App\Repositories\Bt; | ||
| 3 | +/** | ||
| 4 | + * 宝塔面板站点操作类库 | ||
| 5 | + * @author 阿良 or Youngxj(二次开发) | ||
| 6 | + * @link https://www.bt.cn/api-doc.pdf | ||
| 7 | + * @link https://gitee.com/youngxj0/Bty1.0 | ||
| 8 | + * @version 1.0 | ||
| 9 | + * @example | ||
| 10 | + * $bt = new Bt('http://127.0.0.1/8888','xxxxxxxxxxxxxxxx'); | ||
| 11 | + * echo $bt->GetSystemTotal();//获取系统基础统计 | ||
| 12 | + * @return Array | ||
| 13 | + */ | ||
| 14 | +class Bt | ||
| 15 | +{ | ||
| 16 | + private $BT_KEY = ""; //接口密钥 | ||
| 17 | + private $BT_PANEL = "http://127.0.0.1/8888"; //面板地址 | ||
| 18 | + | ||
| 19 | + /** | ||
| 20 | + * 初始化 | ||
| 21 | + * @param [type] $bt_panel 宝塔接口地址 | ||
| 22 | + * @param [type] $bt_key 宝塔Api密钥 | ||
| 23 | + */ | ||
| 24 | + public function __construct($bt_panel = null,$bt_key = null){ | ||
| 25 | + if($bt_panel) $this->BT_PANEL = $bt_panel; | ||
| 26 | + if($bt_key) $this->BT_KEY = $bt_key; | ||
| 27 | + } | ||
| 28 | + | ||
| 29 | + /** | ||
| 30 | + * 获取系统基础统计 | ||
| 31 | + */ | ||
| 32 | + public function GetSystemTotal(){ | ||
| 33 | + $url = $this->BT_PANEL.$this->config("GetSystemTotal"); | ||
| 34 | + | ||
| 35 | + $p_data = $this->GetKeyData(); | ||
| 36 | + | ||
| 37 | + $result = $this->HttpPostCookie($url,$p_data); | ||
| 38 | + | ||
| 39 | + $data = json_decode($result,true); | ||
| 40 | + return $data; | ||
| 41 | + } | ||
| 42 | + | ||
| 43 | + /** | ||
| 44 | + * 获取磁盘分区信息 | ||
| 45 | + */ | ||
| 46 | + public function GetDiskInfo(){ | ||
| 47 | + $url = $this->BT_PANEL.$this->config("GetDiskInfo"); | ||
| 48 | + | ||
| 49 | + $p_data = $this->GetKeyData(); | ||
| 50 | + | ||
| 51 | + $result = $this->HttpPostCookie($url,$p_data); | ||
| 52 | + | ||
| 53 | + $data = json_decode($result,true); | ||
| 54 | + return $data; | ||
| 55 | + } | ||
| 56 | + | ||
| 57 | + /** | ||
| 58 | + * 获取实时状态信息 | ||
| 59 | + * (CPU、内存、网络、负载) | ||
| 60 | + */ | ||
| 61 | + public function GetNetWork(){ | ||
| 62 | + $url = $this->BT_PANEL.$this->config("GetNetWork"); | ||
| 63 | + | ||
| 64 | + $p_data = $this->GetKeyData(); | ||
| 65 | + | ||
| 66 | + $result = $this->HttpPostCookie($url,$p_data); | ||
| 67 | + | ||
| 68 | + $data = json_decode($result,true); | ||
| 69 | + return $data; | ||
| 70 | + } | ||
| 71 | + | ||
| 72 | + /** | ||
| 73 | + * 检查是否有安装任务 | ||
| 74 | + */ | ||
| 75 | + public function GetTaskCount(){ | ||
| 76 | + $url = $this->BT_PANEL.$this->config("GetTaskCount"); | ||
| 77 | + | ||
| 78 | + $p_data = $this->GetKeyData(); | ||
| 79 | + | ||
| 80 | + $result = $this->HttpPostCookie($url,$p_data); | ||
| 81 | + | ||
| 82 | + $data = json_decode($result,true); | ||
| 83 | + return $data; | ||
| 84 | + } | ||
| 85 | + | ||
| 86 | + /** | ||
| 87 | + * 检查面板更新 | ||
| 88 | + */ | ||
| 89 | + public function UpdatePanel($check=false,$force=false){ | ||
| 90 | + $url = $this->BT_PANEL.$this->config("UpdatePanel"); | ||
| 91 | + | ||
| 92 | + $p_data = $this->GetKeyData(); | ||
| 93 | + $p_data['check'] = $check; | ||
| 94 | + $p_data['force'] = $force; | ||
| 95 | + | ||
| 96 | + $result = $this->HttpPostCookie($url,$p_data); | ||
| 97 | + | ||
| 98 | + $data = json_decode($result,true); | ||
| 99 | + return $data; | ||
| 100 | + } | ||
| 101 | + /** | ||
| 102 | + * 申请ssl | ||
| 103 | + */ | ||
| 104 | + public function ApplyCert($domains,$id){ | ||
| 105 | + $url = $this->BT_PANEL.$this->config("ApplyCert"); | ||
| 106 | + $p_data = $this->GetKeyData(); | ||
| 107 | + $p_data['domains'] = $domains; | ||
| 108 | + $p_data['auth_type'] = "http"; | ||
| 109 | + $p_data['auth_to'] = $id; | ||
| 110 | + $p_data['auto_wildcard'] = 0; | ||
| 111 | + $p_data['id'] = $id; | ||
| 112 | + $result = $this->HttpPostCookie($url,$p_data); | ||
| 113 | + | ||
| 114 | + $data = json_decode($result,true); | ||
| 115 | + return $data; | ||
| 116 | + } | ||
| 117 | + /** | ||
| 118 | + * 续签ssl | ||
| 119 | + */ | ||
| 120 | + public function RenewCert($index){ | ||
| 121 | + $url = $this->BT_PANEL.$this->config("RenewCert"); | ||
| 122 | + $p_data = $this->GetKeyData(); | ||
| 123 | + | ||
| 124 | + $p_data['index'] = $index; | ||
| 125 | + | ||
| 126 | + $result = $this->HttpPostCookie($url,$p_data); | ||
| 127 | + $data = json_decode($result,true); | ||
| 128 | + return $data; | ||
| 129 | + } | ||
| 130 | + | ||
| 131 | + | ||
| 132 | + /** | ||
| 133 | + * 获取网站列表 | ||
| 134 | + * @param string $page 当前分页 | ||
| 135 | + * @param string $limit 取出的数据行数 | ||
| 136 | + * @param string $type 分类标识 -1: 分部分类 0: 默认分类 | ||
| 137 | + * @param string $order 排序规则 使用 id 降序:id desc 使用名称升序:name desc | ||
| 138 | + * @param string $tojs 分页 JS 回调,若不传则构造 URI 分页连接 | ||
| 139 | + * @param string $search 搜索内容 | ||
| 140 | + * @return mixed | ||
| 141 | + */ | ||
| 142 | + public function Websites($search='',$page='1',$limit='15',$type='-1',$order='id desc',$tojs=''){ | ||
| 143 | + $url = $this->BT_PANEL.$this->config("Websites"); | ||
| 144 | + | ||
| 145 | + $p_data = $this->GetKeyData(); | ||
| 146 | + $p_data['p'] = $page; | ||
| 147 | + $p_data['limit'] = $limit; | ||
| 148 | + $p_data['type'] = $type; | ||
| 149 | + $p_data['order'] = $order; | ||
| 150 | + $p_data['tojs'] = $tojs; | ||
| 151 | + $p_data['search'] = $search; | ||
| 152 | + | ||
| 153 | + $result = $this->HttpPostCookie($url,$p_data); | ||
| 154 | + | ||
| 155 | + return json_decode($result,true); | ||
| 156 | + } | ||
| 157 | + | ||
| 158 | + /** | ||
| 159 | + * 获取网站FTP列表 | ||
| 160 | + * @param string $page 当前分页 | ||
| 161 | + * @param string $limit 取出的数据行数 | ||
| 162 | + * @param string $type 分类标识 -1: 分部分类 0: 默认分类 | ||
| 163 | + * @param string $order 排序规则 使用 id 降序:id desc 使用名称升序:name desc | ||
| 164 | + * @param string $tojs 分页 JS 回调,若不传则构造 URI 分页连接 | ||
| 165 | + * @param string $search 搜索内容 | ||
| 166 | + * @return mixed | ||
| 167 | + */ | ||
| 168 | + public function WebFtpList($search='',$page='1',$limit='15',$type='-1',$order='id desc',$tojs=''){ | ||
| 169 | + $url = $this->BT_PANEL.$this->config("WebFtpList"); | ||
| 170 | + | ||
| 171 | + $p_data = $this->GetKeyData(); | ||
| 172 | + $p_data['p'] = $page; | ||
| 173 | + $p_data['limit'] = $limit; | ||
| 174 | + $p_data['type'] = $type; | ||
| 175 | + $p_data['order'] = $order; | ||
| 176 | + $p_data['tojs'] = $tojs; | ||
| 177 | + $p_data['search'] = $search; | ||
| 178 | + | ||
| 179 | + $result = $this->HttpPostCookie($url,$p_data); | ||
| 180 | + | ||
| 181 | + $data = json_decode($result,true); | ||
| 182 | + return $data; | ||
| 183 | + } | ||
| 184 | + | ||
| 185 | + /** | ||
| 186 | + * 获取网站SQL列表 | ||
| 187 | + * @param string $page 当前分页 | ||
| 188 | + * @param string $limit 取出的数据行数 | ||
| 189 | + * @param string $type 分类标识 -1: 分部分类 0: 默认分类 | ||
| 190 | + * @param string $order 排序规则 使用 id 降序:id desc 使用名称升序:name desc | ||
| 191 | + * @param string $tojs 分页 JS 回调,若不传则构造 URI 分页连接 | ||
| 192 | + * @param string $search 搜索内容 | ||
| 193 | + */ | ||
| 194 | + public function WebSqlList($search='',$page='1',$limit='15',$type='-1',$order='id desc',$tojs=''){ | ||
| 195 | + $url = $this->BT_PANEL.$this->config("WebSqlList"); | ||
| 196 | + | ||
| 197 | + $p_data = $this->GetKeyData(); | ||
| 198 | + $p_data['p'] = $page; | ||
| 199 | + $p_data['limit'] = $limit; | ||
| 200 | + $p_data['type'] = $type; | ||
| 201 | + $p_data['order'] = $order; | ||
| 202 | + $p_data['tojs'] = $tojs; | ||
| 203 | + $p_data['search'] = $search; | ||
| 204 | + | ||
| 205 | + $result = $this->HttpPostCookie($url,$p_data); | ||
| 206 | + | ||
| 207 | + $data = json_decode($result,true); | ||
| 208 | + return $data; | ||
| 209 | + } | ||
| 210 | + | ||
| 211 | + /** | ||
| 212 | + * 获取所有网站分类 | ||
| 213 | + */ | ||
| 214 | + public function Webtypes(){ | ||
| 215 | + $url = $this->BT_PANEL.$this->config("Webtypes"); | ||
| 216 | + | ||
| 217 | + $p_data = $this->GetKeyData(); | ||
| 218 | + | ||
| 219 | + $result = $this->HttpPostCookie($url,$p_data); | ||
| 220 | + | ||
| 221 | + $data = json_decode($result,true); | ||
| 222 | + return $data; | ||
| 223 | + } | ||
| 224 | + | ||
| 225 | + /** | ||
| 226 | + * 获取已安装的 PHP 版本列表 | ||
| 227 | + */ | ||
| 228 | + public function GetPHPVersion(){ | ||
| 229 | + //拼接URL地址 | ||
| 230 | + $url = $this->BT_PANEL.$this->config("GetPHPVersion"); | ||
| 231 | + | ||
| 232 | + //准备POST数据 | ||
| 233 | + $p_data = $this->GetKeyData(); //取签名 | ||
| 234 | + | ||
| 235 | + //请求面板接口 | ||
| 236 | + $result = $this->HttpPostCookie($url,$p_data); | ||
| 237 | + | ||
| 238 | + //解析JSON数据 | ||
| 239 | + $data = json_decode($result,true); | ||
| 240 | + | ||
| 241 | + return $data; | ||
| 242 | + } | ||
| 243 | + | ||
| 244 | + /** | ||
| 245 | + * 修改指定网站的PHP版本 | ||
| 246 | + * @param [type] $site 网站名 | ||
| 247 | + * @param [type] $php PHP版本 | ||
| 248 | + */ | ||
| 249 | + public function SetPHPVersion($site,$php){ | ||
| 250 | + | ||
| 251 | + $url = $this->BT_PANEL.$this->config("SetPHPVersion"); | ||
| 252 | + | ||
| 253 | + $p_data = $this->GetKeyData(); | ||
| 254 | + $p_data['siteName'] = $site; | ||
| 255 | + $p_data['version'] = $php; | ||
| 256 | + $result = $this->HttpPostCookie($url,$p_data); | ||
| 257 | + | ||
| 258 | + $data = json_decode($result,true); | ||
| 259 | + return $data; | ||
| 260 | + } | ||
| 261 | + | ||
| 262 | + /** | ||
| 263 | + * 获取指定网站运行的PHP版本 | ||
| 264 | + * @param [type] $site 网站名 | ||
| 265 | + */ | ||
| 266 | + public function GetSitePHPVersion($site){ | ||
| 267 | + $url = $this->BT_PANEL.$this->config("GetSitePHPVersion"); | ||
| 268 | + | ||
| 269 | + $p_data = $this->GetKeyData(); | ||
| 270 | + $p_data['siteName'] = $site; | ||
| 271 | + $result = $this->HttpPostCookie($url,$p_data); | ||
| 272 | + | ||
| 273 | + $data = json_decode($result,true); | ||
| 274 | + return $data; | ||
| 275 | + } | ||
| 276 | + | ||
| 277 | + | ||
| 278 | + /** | ||
| 279 | + * 新增网站 | ||
| 280 | + * @param [type] $webname 网站域名 json格式 | ||
| 281 | + * @param [type] $path 网站路径 | ||
| 282 | + * @param [type] $type_id 网站分类ID | ||
| 283 | + * @param string $type 网站类型 | ||
| 284 | + * @param [type] $version PHP版本 | ||
| 285 | + * @param [type] $port 网站端口 | ||
| 286 | + * @param [type] $ps 网站备注 | ||
| 287 | + * @param [type] $ftp 网站是否开通FTP | ||
| 288 | + * @param [type] $ftp_username FTP用户名 | ||
| 289 | + * @param [type] $ftp_password FTP密码 | ||
| 290 | + * @param [type] $sql 网站是否开通数据库 | ||
| 291 | + * @param [type] $codeing 数据库编码类型 utf8|utf8mb4|gbk|big5 | ||
| 292 | + * @param [type] $datauser 数据库账号 | ||
| 293 | + * @param [type] $datapassword 数据库密码 | ||
| 294 | + */ | ||
| 295 | + public function AddSite($infoArr=[]){ | ||
| 296 | + $url = $this->BT_PANEL.$this->config("WebAddSite"); | ||
| 297 | + //准备POST数据 | ||
| 298 | + $p_data = $this->GetKeyData(); //取签名 | ||
| 299 | + $p_data['webname'] = $infoArr['webname']; | ||
| 300 | + $p_data['path'] = $infoArr['path']; | ||
| 301 | + $p_data['type_id'] = $infoArr['type_id']; | ||
| 302 | + $p_data['type'] = $infoArr['type']; | ||
| 303 | + $p_data['version'] = $infoArr['version']; | ||
| 304 | + $p_data['port'] = $infoArr['port']; | ||
| 305 | + $p_data['ps'] = $infoArr['ps']; | ||
| 306 | + $p_data['ftp'] = $infoArr['ftp']; | ||
| 307 | + $p_data['ftp_username'] = $infoArr['ftp_username']; | ||
| 308 | + $p_data['ftp_password'] = $infoArr['ftp_password']; | ||
| 309 | + $p_data['sql'] = $infoArr['sql']; | ||
| 310 | + $p_data['codeing'] = $infoArr['codeing']; | ||
| 311 | + $p_data['datauser'] = $infoArr['datauser']; | ||
| 312 | + $p_data['datapassword'] = $infoArr['datapassword']; | ||
| 313 | + | ||
| 314 | + | ||
| 315 | + | ||
| 316 | + //请求面板接口 | ||
| 317 | + $result = $this->HttpPostCookie($url,$p_data); | ||
| 318 | + //var_dump($result); | ||
| 319 | + //解析JSON数据 | ||
| 320 | + $data = json_decode($result,true); | ||
| 321 | + return $data; | ||
| 322 | + } | ||
| 323 | + | ||
| 324 | + /** | ||
| 325 | + * 删除网站 | ||
| 326 | + * @param [type] $id 网站ID | ||
| 327 | + * @param [type] $webname 网站名称 | ||
| 328 | + * @param [type] $ftp 是否删除关联FTP | ||
| 329 | + * @param [type] $database 是否删除关联数据库 | ||
| 330 | + * @param [type] $path 是否删除关联网站根目录 | ||
| 331 | + * | ||
| 332 | + */ | ||
| 333 | + public function WebDeleteSite($id,$webname,$ftp,$database,$path){ | ||
| 334 | + $url = $this->BT_PANEL.$this->config("WebDeleteSite"); | ||
| 335 | + | ||
| 336 | + $p_data = $this->GetKeyData(); | ||
| 337 | + $p_data['id'] = $id; | ||
| 338 | + $p_data['webname'] = $webname; | ||
| 339 | + $ftp && $p_data['ftp'] = $ftp; | ||
| 340 | + $database && $p_data['database'] = $database; | ||
| 341 | + $path && $p_data['path'] = $path; | ||
| 342 | + | ||
| 343 | + $result = $this->HttpPostCookie($url,$p_data); | ||
| 344 | + | ||
| 345 | + $data = json_decode($result,true); | ||
| 346 | + return $data; | ||
| 347 | + } | ||
| 348 | + | ||
| 349 | + /** | ||
| 350 | + * 停用站点 | ||
| 351 | + * @param [type] $id 网站ID | ||
| 352 | + * @param [type] $name 网站域名 | ||
| 353 | + * @return mixed | ||
| 354 | + */ | ||
| 355 | + public function WebSiteStop($id,$name){ | ||
| 356 | + $url = $this->BT_PANEL.$this->config("WebSiteStop"); | ||
| 357 | + | ||
| 358 | + $p_data = $this->GetKeyData(); | ||
| 359 | + $p_data['id'] = $id; | ||
| 360 | + $p_data['name'] = $name; | ||
| 361 | + $result = $this->HttpPostCookie($url,$p_data); | ||
| 362 | + | ||
| 363 | + $data = json_decode($result,true); | ||
| 364 | + return $data; | ||
| 365 | + } | ||
| 366 | + | ||
| 367 | + /** | ||
| 368 | + * 启用网站 | ||
| 369 | + * @param [type] $id 网站ID | ||
| 370 | + * @param [type] $name 网站域名 | ||
| 371 | + * @return mixed | ||
| 372 | + */ | ||
| 373 | + public function WebSiteStart($id,$name){ | ||
| 374 | + $url = $this->BT_PANEL.$this->config("WebSiteStart"); | ||
| 375 | + | ||
| 376 | + $p_data = $this->GetKeyData(); | ||
| 377 | + $p_data['id'] = $id; | ||
| 378 | + $p_data['name'] = $name; | ||
| 379 | + $result = $this->HttpPostCookie($url,$p_data); | ||
| 380 | + | ||
| 381 | + $data = json_decode($result,true); | ||
| 382 | + return $data; | ||
| 383 | + } | ||
| 384 | + | ||
| 385 | + /** | ||
| 386 | + * 设置网站到期时间 | ||
| 387 | + * @param [type] $id 网站ID | ||
| 388 | + * @param [type] $edate 网站到期时间 格式:2019-01-01,永久:0000-00-00 | ||
| 389 | + * @return mixed | ||
| 390 | + */ | ||
| 391 | + public function WebSetEdate($id,$edate){ | ||
| 392 | + $url = $this->BT_PANEL.$this->config("WebSetEdate"); | ||
| 393 | + | ||
| 394 | + $p_data = $this->GetKeyData(); | ||
| 395 | + $p_data['id'] = $id; | ||
| 396 | + $p_data['edate'] = $edate; | ||
| 397 | + $result = $this->HttpPostCookie($url,$p_data); | ||
| 398 | + | ||
| 399 | + $data = json_decode($result,true); | ||
| 400 | + return $data; | ||
| 401 | + } | ||
| 402 | + | ||
| 403 | + /** | ||
| 404 | + * 修改网站备注 | ||
| 405 | + * @param [type] $id 网站ID | ||
| 406 | + * @param [type] $ps 网站备注 | ||
| 407 | + */ | ||
| 408 | + public function WebSetPs($id,$ps){ | ||
| 409 | + $url = $this->BT_PANEL.$this->config("WebSetPs"); | ||
| 410 | + | ||
| 411 | + $p_data = $this->GetKeyData(); | ||
| 412 | + $p_data['id'] = $id; | ||
| 413 | + $p_data['ps'] = $ps; | ||
| 414 | + $result = $this->HttpPostCookie($url,$p_data); | ||
| 415 | + | ||
| 416 | + $data = json_decode($result,true); | ||
| 417 | + return $data; | ||
| 418 | + } | ||
| 419 | + | ||
| 420 | + /** | ||
| 421 | + * 获取网站备份列表 | ||
| 422 | + * @param [type] $id 网站ID | ||
| 423 | + * @param string $page 当前分页 | ||
| 424 | + * @param string $limit 每页取出的数据行数 | ||
| 425 | + * @param string $type 备份类型 目前固定为0 | ||
| 426 | + * @param string $tojs 分页js回调若不传则构造 URI 分页连接 get_site_backup | ||
| 427 | + */ | ||
| 428 | + public function WebBackupList($id,$page='1',$limit='5',$type='0',$tojs=''){ | ||
| 429 | + $url = $this->BT_PANEL.$this->config("WebBackupList"); | ||
| 430 | + | ||
| 431 | + $p_data = $this->GetKeyData(); | ||
| 432 | + $p_data['p'] = $page; | ||
| 433 | + $p_data['limit'] = $limit; | ||
| 434 | + $p_data['type'] = $type; | ||
| 435 | + $p_data['tojs'] = $tojs; | ||
| 436 | + $p_data['search'] = $id; | ||
| 437 | + $result = $this->HttpPostCookie($url,$p_data); | ||
| 438 | + | ||
| 439 | + $data = json_decode($result,true); | ||
| 440 | + return $data; | ||
| 441 | + } | ||
| 442 | + | ||
| 443 | + /** | ||
| 444 | + * 创建网站备份 | ||
| 445 | + * @param [type] $id 网站ID | ||
| 446 | + */ | ||
| 447 | + public function WebToBackup($id){ | ||
| 448 | + $url = $this->BT_PANEL.$this->config("WebToBackup"); | ||
| 449 | + | ||
| 450 | + $p_data = $this->GetKeyData(); | ||
| 451 | + $p_data['id'] = $id; | ||
| 452 | + $result = $this->HttpPostCookie($url,$p_data); | ||
| 453 | + | ||
| 454 | + $data = json_decode($result,true); | ||
| 455 | + return $data; | ||
| 456 | + } | ||
| 457 | + | ||
| 458 | + /** | ||
| 459 | + * 删除网站备份 | ||
| 460 | + * @param [type] $id 网站备份ID | ||
| 461 | + */ | ||
| 462 | + public function WebDelBackup($id){ | ||
| 463 | + $url = $this->BT_PANEL.$this->config("WebDelBackup"); | ||
| 464 | + | ||
| 465 | + $p_data = $this->GetKeyData(); | ||
| 466 | + $p_data['id'] = $id; | ||
| 467 | + $result = $this->HttpPostCookie($url,$p_data); | ||
| 468 | + | ||
| 469 | + $data = json_decode($result,true); | ||
| 470 | + return $data; | ||
| 471 | + } | ||
| 472 | + | ||
| 473 | + /** | ||
| 474 | + * 删除数据库备份 | ||
| 475 | + * @param [type] $id 数据库备份ID | ||
| 476 | + */ | ||
| 477 | + public function SQLDelBackup($id){ | ||
| 478 | + $url = $this->BT_PANEL.$this->config("SQLDelBackup"); | ||
| 479 | + | ||
| 480 | + $p_data = $this->GetKeyData(); | ||
| 481 | + $p_data['id'] = $id; | ||
| 482 | + $result = $this->HttpPostCookie($url,$p_data); | ||
| 483 | + | ||
| 484 | + $data = json_decode($result,true); | ||
| 485 | + return $data; | ||
| 486 | + } | ||
| 487 | + | ||
| 488 | + /** | ||
| 489 | + * 备份数据库 | ||
| 490 | + * @param [type] $id 数据库列表ID | ||
| 491 | + */ | ||
| 492 | + public function SQLToBackup($id){ | ||
| 493 | + $url = $this->BT_PANEL.$this->config("SQLToBackup"); | ||
| 494 | + | ||
| 495 | + $p_data = $this->GetKeyData(); | ||
| 496 | + $p_data['id'] = $id; | ||
| 497 | + $result = $this->HttpPostCookie($url,$p_data); | ||
| 498 | + | ||
| 499 | + $data = json_decode($result,true); | ||
| 500 | + return $data; | ||
| 501 | + } | ||
| 502 | + | ||
| 503 | + /** | ||
| 504 | + * 获取网站域名列表 | ||
| 505 | + * @param [type] $id 网站ID | ||
| 506 | + * @param boolean $list 固定传true | ||
| 507 | + */ | ||
| 508 | + public function WebDoaminList($id,$list=true){ | ||
| 509 | + $url = $this->BT_PANEL.$this->config("WebDoaminList"); | ||
| 510 | + | ||
| 511 | + $p_data = $this->GetKeyData(); | ||
| 512 | + $p_data['search'] = $id; | ||
| 513 | + $p_data['list'] = $list; | ||
| 514 | + $result = $this->HttpPostCookie($url,$p_data); | ||
| 515 | + | ||
| 516 | + $data = json_decode($result,true); | ||
| 517 | + return $data; | ||
| 518 | + } | ||
| 519 | + | ||
| 520 | + /** | ||
| 521 | + * 获取网站列表 | ||
| 522 | + * @param string $search | ||
| 523 | + * @param int $p | ||
| 524 | + * @param int $limit | ||
| 525 | + * @param int $type | ||
| 526 | + * @return mixed | ||
| 527 | + */ | ||
| 528 | + public function WebSiteList($search = '', $p = 1, $limit = 20, $type = 0){ | ||
| 529 | + $url = $this->BT_PANEL.$this->config("WebSiteList"); | ||
| 530 | + | ||
| 531 | + $p_data = $this->GetKeyData(); | ||
| 532 | + $p_data['search'] = $search; | ||
| 533 | + $p_data['p'] = $p; | ||
| 534 | + $p_data['limit'] = $limit; | ||
| 535 | + $p_data['type'] = $type; | ||
| 536 | + $result = $this->HttpPostCookie($url,$p_data); | ||
| 537 | + | ||
| 538 | + $data = json_decode($result,true); | ||
| 539 | + return $data; | ||
| 540 | + } | ||
| 541 | + | ||
| 542 | + /** | ||
| 543 | + * 添加域名 | ||
| 544 | + * @param [type] $id 网站ID | ||
| 545 | + * @param [type] $webname 网站名称 | ||
| 546 | + * @param [type] $domain 要添加的域名:端口 80 端品不必构造端口,多个域名用换行符隔开 | ||
| 547 | + */ | ||
| 548 | + public function WebAddDomain($id,$webname,$domain){ | ||
| 549 | + $url = $this->BT_PANEL.$this->config("WebAddDomain"); | ||
| 550 | + | ||
| 551 | + $p_data = $this->GetKeyData(); | ||
| 552 | + $p_data['id'] = $id; | ||
| 553 | + $p_data['webname'] = $webname; | ||
| 554 | + $p_data['domain'] = $domain; | ||
| 555 | + $result = $this->HttpPostCookie($url,$p_data); | ||
| 556 | + | ||
| 557 | + $data = json_decode($result,true); | ||
| 558 | + return $data; | ||
| 559 | + } | ||
| 560 | + | ||
| 561 | + /** | ||
| 562 | + * 删除网站域名 | ||
| 563 | + * @param [type] $id 网站ID | ||
| 564 | + * @param [type] $webname 网站名 | ||
| 565 | + * @param [type] $domain 网站域名 | ||
| 566 | + * @param [type] $port 网站域名端口 | ||
| 567 | + */ | ||
| 568 | + public function WebDelDomain($id,$webname,$domain,$port){ | ||
| 569 | + $url = $this->BT_PANEL.$this->config("WebDelDomain"); | ||
| 570 | + | ||
| 571 | + $p_data = $this->GetKeyData(); | ||
| 572 | + $p_data['id'] = $id; | ||
| 573 | + $p_data['webname'] = $webname; | ||
| 574 | + $p_data['domain'] = $domain; | ||
| 575 | + $p_data['port'] = $port; | ||
| 576 | + $result = $this->HttpPostCookie($url,$p_data); | ||
| 577 | + | ||
| 578 | + $data = json_decode($result,true); | ||
| 579 | + return $data; | ||
| 580 | + } | ||
| 581 | + | ||
| 582 | + /** | ||
| 583 | + * 获取可选的预定义伪静态列表 | ||
| 584 | + * @param [type] $siteName 网站名 | ||
| 585 | + */ | ||
| 586 | + public function GetRewriteList($siteName){ | ||
| 587 | + $url = $this->BT_PANEL.$this->config("GetRewriteList"); | ||
| 588 | + | ||
| 589 | + $p_data = $this->GetKeyData(); | ||
| 590 | + $p_data['siteName'] = $siteName; | ||
| 591 | + $result = $this->HttpPostCookie($url,$p_data); | ||
| 592 | + | ||
| 593 | + $data = json_decode($result,true); | ||
| 594 | + return $data; | ||
| 595 | + } | ||
| 596 | + | ||
| 597 | + /** | ||
| 598 | + * 获取预置伪静态规则内容(文件内容) | ||
| 599 | + * @param [type] $path 规则名 | ||
| 600 | + * @param [type] $type 0->获取内置伪静态规则;1->获取当前站点伪静态规则 | ||
| 601 | + */ | ||
| 602 | + public function GetFileBody($path,$type=0){ | ||
| 603 | + $url = $this->BT_PANEL.$this->config("GetFileBody"); | ||
| 604 | + $p_data = $this->GetKeyData(); | ||
| 605 | +// $path_dir = $type?'vhost/rewrite':'rewrite/nginx'; | ||
| 606 | + if ($type == 2) { | ||
| 607 | + $path_dir = 'vhost/nginx'; | ||
| 608 | + } elseif ($type == 1) { | ||
| 609 | + $path_dir = 'vhost/rewrite'; | ||
| 610 | + } else { | ||
| 611 | + $path_dir = 'rewrite/nginx'; | ||
| 612 | + } | ||
| 613 | + | ||
| 614 | + //获取当前站点伪静态规则 | ||
| 615 | + ///www/server/panel/vhost/rewrite/user_hvVBT_1.test.com.conf | ||
| 616 | + //获取内置伪静态规则 | ||
| 617 | + ///www/server/panel/rewrite/nginx/EmpireCMS.conf | ||
| 618 | + //保存伪静态规则到站点 | ||
| 619 | + ///www/server/panel/vhost/rewrite/user_hvVBT_1.test.com.conf | ||
| 620 | + ///www/server/panel/rewrite/nginx/typecho.conf | ||
| 621 | + $p_data['path'] = '/www/server/panel/'.$path_dir.'/'.$path.'.conf'; | ||
| 622 | + //var_dump($p_data['path']); | ||
| 623 | + $result = $this->HttpPostCookie($url,$p_data); | ||
| 624 | + | ||
| 625 | + $data = json_decode($result,true); | ||
| 626 | + return $data; | ||
| 627 | + } | ||
| 628 | + | ||
| 629 | + /** | ||
| 630 | + * 保存伪静态规则内容(保存文件内容) | ||
| 631 | + * @param [type] $path 规则名 | ||
| 632 | + * @param [type] $data 规则内容 | ||
| 633 | + * @param string $encoding 规则编码强转utf-8 | ||
| 634 | + * @param number $type 0->系统默认路径;1->自定义全路径 | ||
| 635 | + */ | ||
| 636 | + public function SaveFileBody($path,$data,$encoding='utf-8',$type=0){ | ||
| 637 | + $url = $this->BT_PANEL.$this->config("SaveFileBody"); | ||
| 638 | + if($type){ | ||
| 639 | + $path_dir = $path; | ||
| 640 | + }else{ | ||
| 641 | + $path_dir = '/www/server/panel/vhost/rewrite/'.$path.'.conf'; | ||
| 642 | + } | ||
| 643 | + $p_data = $this->GetKeyData(); | ||
| 644 | + $p_data['path'] = $path_dir; | ||
| 645 | + $p_data['data'] = $data; | ||
| 646 | + $p_data['encoding'] = $encoding; | ||
| 647 | + $result = $this->HttpPostCookie($url,$p_data); | ||
| 648 | + | ||
| 649 | + $data = json_decode($result,true); | ||
| 650 | + return $data; | ||
| 651 | + } | ||
| 652 | + | ||
| 653 | + | ||
| 654 | + | ||
| 655 | + /** | ||
| 656 | + * 设置密码访问网站 | ||
| 657 | + * @param [type] $id 网站ID | ||
| 658 | + * @param [type] $username 用户名 | ||
| 659 | + * @param [type] $password 密码 | ||
| 660 | + */ | ||
| 661 | + public function SetHasPwd($id,$username,$password){ | ||
| 662 | + $url = $this->BT_PANEL.$this->config("SetHasPwd"); | ||
| 663 | + | ||
| 664 | + $p_data = $this->GetKeyData(); | ||
| 665 | + $p_data['id'] = $id; | ||
| 666 | + $p_data['username'] = $username; | ||
| 667 | + $p_data['password'] = $password; | ||
| 668 | + $result = $this->HttpPostCookie($url,$p_data); | ||
| 669 | + | ||
| 670 | + $data = json_decode($result,true); | ||
| 671 | + return $data; | ||
| 672 | + } | ||
| 673 | + | ||
| 674 | + /** | ||
| 675 | + * 关闭密码访问网站 | ||
| 676 | + * @param [type] $id 网站ID | ||
| 677 | + */ | ||
| 678 | + public function CloseHasPwd($id){ | ||
| 679 | + $url = $this->BT_PANEL.$this->config("CloseHasPwd"); | ||
| 680 | + | ||
| 681 | + $p_data = $this->GetKeyData(); | ||
| 682 | + $p_data['id'] = $id; | ||
| 683 | + $result = $this->HttpPostCookie($url,$p_data); | ||
| 684 | + | ||
| 685 | + $data = json_decode($result,true); | ||
| 686 | + return $data; | ||
| 687 | + } | ||
| 688 | + | ||
| 689 | + /** | ||
| 690 | + * 获取网站日志 | ||
| 691 | + * @param [type] $site 网站名 | ||
| 692 | + */ | ||
| 693 | + public function GetSiteLogs($site){ | ||
| 694 | + $url = $this->BT_PANEL.$this->config("GetSiteLogs"); | ||
| 695 | + | ||
| 696 | + $p_data = $this->GetKeyData(); | ||
| 697 | + $p_data['siteName'] = $site; | ||
| 698 | + $result = $this->HttpPostCookie($url,$p_data); | ||
| 699 | + | ||
| 700 | + $data = json_decode($result,true); | ||
| 701 | + return $data; | ||
| 702 | + } | ||
| 703 | + | ||
| 704 | + /** | ||
| 705 | + * 获取网站盗链状态及规则信息 | ||
| 706 | + * @param [type] $id 网站ID | ||
| 707 | + * @param [type] $site 网站名 | ||
| 708 | + */ | ||
| 709 | + public function GetSecurity($id,$site){ | ||
| 710 | + $url = $this->BT_PANEL.$this->config("GetSecurity"); | ||
| 711 | + | ||
| 712 | + $p_data = $this->GetKeyData(); | ||
| 713 | + $p_data['id'] = $id; | ||
| 714 | + $p_data['name'] = $site; | ||
| 715 | + $result = $this->HttpPostCookie($url,$p_data); | ||
| 716 | + | ||
| 717 | + $data = json_decode($result,true); | ||
| 718 | + return $data; | ||
| 719 | + } | ||
| 720 | + | ||
| 721 | + /** | ||
| 722 | + * 设置网站盗链状态及规则信息 | ||
| 723 | + * @param [type] $id 网站ID | ||
| 724 | + * @param [type] $site 网站名 | ||
| 725 | + * @param [type] $fix URL后缀 | ||
| 726 | + * @param [type] $domains 许可域名 | ||
| 727 | + * @param [type] $status 状态 | ||
| 728 | + */ | ||
| 729 | + public function SetSecurity($id,$site,$fix,$domains,$status){ | ||
| 730 | + $url = $this->BT_PANEL.$this->config("SetSecurity"); | ||
| 731 | + | ||
| 732 | + $p_data = $this->GetKeyData(); | ||
| 733 | + $p_data['id'] = $id; | ||
| 734 | + $p_data['name'] = $site; | ||
| 735 | + $p_data['fix'] = $fix; | ||
| 736 | + $p_data['domains'] = $domains; | ||
| 737 | + $p_data['status'] = $status; | ||
| 738 | + $result = $this->HttpPostCookie($url,$p_data); | ||
| 739 | + | ||
| 740 | + $data = json_decode($result,true); | ||
| 741 | + return $data; | ||
| 742 | + } | ||
| 743 | + | ||
| 744 | + /** | ||
| 745 | + * 获取网站三项配置开关(防跨站、日志、密码访问) | ||
| 746 | + * @param [type] $id 网站ID | ||
| 747 | + * @param [type] $path 网站运行目录 | ||
| 748 | + */ | ||
| 749 | + public function GetDirUserINI($id,$path){ | ||
| 750 | + $url = $this->BT_PANEL.$this->config("GetDirUserINI"); | ||
| 751 | + | ||
| 752 | + $p_data = $this->GetKeyData(); | ||
| 753 | + $p_data['id'] = $id; | ||
| 754 | + $p_data['path'] = $path; | ||
| 755 | + $result = $this->HttpPostCookie($url,$p_data); | ||
| 756 | + | ||
| 757 | + $data = json_decode($result,true); | ||
| 758 | + return $data; | ||
| 759 | + } | ||
| 760 | + | ||
| 761 | + /** | ||
| 762 | + * 开启强制HTTPS | ||
| 763 | + * @param [type] $site 网站域名(纯域名) | ||
| 764 | + */ | ||
| 765 | + public function HttpToHttps($site){ | ||
| 766 | + $url = $this->BT_PANEL.$this->config("HttpToHttps"); | ||
| 767 | + | ||
| 768 | + $p_data = $this->GetKeyData(); | ||
| 769 | + $p_data['siteName'] = $site; | ||
| 770 | + $result = $this->HttpPostCookie($url,$p_data); | ||
| 771 | + | ||
| 772 | + $data = json_decode($result,true); | ||
| 773 | + return $data; | ||
| 774 | + } | ||
| 775 | + | ||
| 776 | + /** | ||
| 777 | + * 关闭强制HTTPS | ||
| 778 | + * @param [type] $site 域名(纯域名) | ||
| 779 | + */ | ||
| 780 | + public function CloseToHttps($site){ | ||
| 781 | + $url = $this->BT_PANEL.$this->config("CloseToHttps"); | ||
| 782 | + | ||
| 783 | + $p_data = $this->GetKeyData(); | ||
| 784 | + $p_data['siteName'] = $site; | ||
| 785 | + $result = $this->HttpPostCookie($url,$p_data); | ||
| 786 | + | ||
| 787 | + $data = json_decode($result,true); | ||
| 788 | + return $data; | ||
| 789 | + } | ||
| 790 | + | ||
| 791 | + /** | ||
| 792 | + * 设置SSL域名证书 | ||
| 793 | + * @param [type] $type 类型 | ||
| 794 | + * @param [type] $site 网站名 | ||
| 795 | + * @param [type] $key 证书key | ||
| 796 | + * @param [type] $csr 证书PEM | ||
| 797 | + * @return mixed | ||
| 798 | + */ | ||
| 799 | + public function SetSSL($type,$site,$key,$csr){ | ||
| 800 | + $url = $this->BT_PANEL.$this->config("SetSSL"); | ||
| 801 | + $p_data = $this->GetKeyData(); | ||
| 802 | + $p_data['type'] = $type; | ||
| 803 | + $p_data['siteName'] = $site; | ||
| 804 | + $p_data['key'] = $key; | ||
| 805 | + $p_data['csr'] = $csr; | ||
| 806 | + $result = $this->HttpPostCookie($url,$p_data); | ||
| 807 | + return json_decode($result,true); | ||
| 808 | + } | ||
| 809 | + | ||
| 810 | + /* | ||
| 811 | + * 关闭宝塔日志 | ||
| 812 | + */ | ||
| 813 | + public function CloseLogsHandle(){ | ||
| 814 | + $url = $this->BT_PANEL.$this->config("CloseLogs"); | ||
| 815 | + $p_data = $this->GetKeyData(); | ||
| 816 | + $result = $this->HttpPostCookie($url,$p_data); | ||
| 817 | + return json_decode($result,true); | ||
| 818 | + } | ||
| 819 | + | ||
| 820 | + /** | ||
| 821 | + * 关闭SSL | ||
| 822 | + * @param [type] $updateOf 修改状态码 | ||
| 823 | + * @param [type] $site 域名(纯域名) | ||
| 824 | + */ | ||
| 825 | + public function CloseSSLConf($updateOf,$site){ | ||
| 826 | + $url = $this->BT_PANEL.$this->config("CloseSSLConf"); | ||
| 827 | + | ||
| 828 | + $p_data = $this->GetKeyData(); | ||
| 829 | + $p_data['updateOf'] = $updateOf; | ||
| 830 | + $p_data['siteName'] = $site; | ||
| 831 | + $result = $this->HttpPostCookie($url,$p_data); | ||
| 832 | + | ||
| 833 | + $data = json_decode($result,true); | ||
| 834 | + return $data; | ||
| 835 | + } | ||
| 836 | + | ||
| 837 | + /** | ||
| 838 | + * 获取SSL状态及证书信息 | ||
| 839 | + * @param [type] $site 域名(纯域名) | ||
| 840 | + */ | ||
| 841 | + public function GetSSL($site){ | ||
| 842 | + $url = $this->BT_PANEL.$this->config("GetSSL"); | ||
| 843 | + | ||
| 844 | + $p_data = $this->GetKeyData(); | ||
| 845 | + $p_data['siteName'] = $site; | ||
| 846 | + $result = $this->HttpPostCookie($url,$p_data); | ||
| 847 | + | ||
| 848 | + $data = json_decode($result,true); | ||
| 849 | + return $data; | ||
| 850 | + } | ||
| 851 | + | ||
| 852 | + /** | ||
| 853 | + * 获取网站默认文件 | ||
| 854 | + * @param [type] $id 网站ID | ||
| 855 | + */ | ||
| 856 | + public function WebGetIndex($id){ | ||
| 857 | + $url = $this->BT_PANEL.$this->config("WebGetIndex"); | ||
| 858 | + | ||
| 859 | + $p_data = $this->GetKeyData(); | ||
| 860 | + $p_data['id'] = $id; | ||
| 861 | + $result = $this->HttpPostCookie($url,$p_data); | ||
| 862 | + | ||
| 863 | + $data = json_decode($result,true); | ||
| 864 | + return $data; | ||
| 865 | + } | ||
| 866 | + | ||
| 867 | + /** | ||
| 868 | + * 设置网站默认文件 | ||
| 869 | + * @param [type] $id 网站ID | ||
| 870 | + * @param [type] $index 内容 | ||
| 871 | + */ | ||
| 872 | + public function WebSetIndex($id,$index){ | ||
| 873 | + $url = $this->BT_PANEL.$this->config("WebSetIndex"); | ||
| 874 | + | ||
| 875 | + $p_data = $this->GetKeyData(); | ||
| 876 | + $p_data['id'] = $id; | ||
| 877 | + $p_data['Index'] = $index; | ||
| 878 | + $result = $this->HttpPostCookie($url,$p_data); | ||
| 879 | + | ||
| 880 | + $data = json_decode($result,true); | ||
| 881 | + return $data; | ||
| 882 | + } | ||
| 883 | + | ||
| 884 | + /** | ||
| 885 | + * 获取网站流量限制信息 | ||
| 886 | + * @param [type] $id [description] | ||
| 887 | + */ | ||
| 888 | + public function GetLimitNet($id){ | ||
| 889 | + $url = $this->BT_PANEL.$this->config("GetLimitNet"); | ||
| 890 | + | ||
| 891 | + $p_data = $this->GetKeyData(); | ||
| 892 | + $p_data['id'] = $id; | ||
| 893 | + $result = $this->HttpPostCookie($url,$p_data); | ||
| 894 | + | ||
| 895 | + $data = json_decode($result,true); | ||
| 896 | + return $data; | ||
| 897 | + } | ||
| 898 | + | ||
| 899 | + /** | ||
| 900 | + * 设置网站流量限制信息 | ||
| 901 | + * @param [type] $id 网站ID | ||
| 902 | + * @param [type] $perserver 并发限制 | ||
| 903 | + * @param [type] $perip 单IP限制 | ||
| 904 | + * @param [type] $limit_rate 流量限制 | ||
| 905 | + */ | ||
| 906 | + public function SetLimitNet($id,$perserver,$perip,$limit_rate){ | ||
| 907 | + $url = $this->BT_PANEL.$this->config("SetLimitNet"); | ||
| 908 | + | ||
| 909 | + $p_data = $this->GetKeyData(); | ||
| 910 | + $p_data['id'] = $id; | ||
| 911 | + $p_data['perserver'] = $perserver; | ||
| 912 | + $p_data['perip'] = $perip; | ||
| 913 | + $p_data['limit_rate'] = $limit_rate; | ||
| 914 | + $result = $this->HttpPostCookie($url,$p_data); | ||
| 915 | + | ||
| 916 | + $data = json_decode($result,true); | ||
| 917 | + return $data; | ||
| 918 | + } | ||
| 919 | + | ||
| 920 | + /** | ||
| 921 | + * 关闭网站流量限制 | ||
| 922 | + * @param [type] $id 网站ID | ||
| 923 | + */ | ||
| 924 | + public function CloseLimitNet($id){ | ||
| 925 | + $url = $this->BT_PANEL.$this->config("CloseLimitNet"); | ||
| 926 | + | ||
| 927 | + $p_data = $this->GetKeyData(); | ||
| 928 | + $p_data['id'] = $id; | ||
| 929 | + $result = $this->HttpPostCookie($url,$p_data); | ||
| 930 | + | ||
| 931 | + $data = json_decode($result,true); | ||
| 932 | + return $data; | ||
| 933 | + } | ||
| 934 | + | ||
| 935 | + /** | ||
| 936 | + * 获取网站301重定向信息 | ||
| 937 | + * @param [type] $site 网站名 | ||
| 938 | + */ | ||
| 939 | + public function Get301Status($site){ | ||
| 940 | + $url = $this->BT_PANEL.$this->config("Get301Status"); | ||
| 941 | + | ||
| 942 | + $p_data = $this->GetKeyData(); | ||
| 943 | + $p_data['siteName'] = $site; | ||
| 944 | + $result = $this->HttpPostCookie($url,$p_data); | ||
| 945 | + | ||
| 946 | + $data = json_decode($result,true); | ||
| 947 | + return $data; | ||
| 948 | + } | ||
| 949 | + | ||
| 950 | + /** | ||
| 951 | + * 设置网站301重定向信息 | ||
| 952 | + * @param [type] $site 网站名 | ||
| 953 | + * @param [type] $toDomain 目标Url | ||
| 954 | + * @param [type] $srcDomain 来自Url | ||
| 955 | + * @param [type] $type 类型 | ||
| 956 | + */ | ||
| 957 | + public function Set301Status($site,$toDomain,$srcDomain,$type){ | ||
| 958 | + $url = $this->BT_PANEL.$this->config("Set301Status"); | ||
| 959 | + | ||
| 960 | + $p_data = $this->GetKeyData(); | ||
| 961 | + $p_data['siteName'] = $site; | ||
| 962 | + $p_data['toDomain'] = $toDomain; | ||
| 963 | + $p_data['srcDomain'] = $srcDomain; | ||
| 964 | + $p_data['type'] = $type; | ||
| 965 | + $result = $this->HttpPostCookie($url,$p_data); | ||
| 966 | + | ||
| 967 | + $data = json_decode($result,true); | ||
| 968 | + return $data; | ||
| 969 | + } | ||
| 970 | + | ||
| 971 | + /** | ||
| 972 | + * 获取网站反代信息及状态 | ||
| 973 | + * @param [type] $site [description] | ||
| 974 | + */ | ||
| 975 | + public function GetProxyList($site){ | ||
| 976 | + $url = $this->BT_PANEL.$this->config("GetProxyList"); | ||
| 977 | + | ||
| 978 | + $p_data = $this->GetKeyData(); | ||
| 979 | + $p_data['sitename'] = $site; | ||
| 980 | + $result = $this->HttpPostCookie($url,$p_data); | ||
| 981 | + | ||
| 982 | + $data = json_decode($result,true); | ||
| 983 | + return $data; | ||
| 984 | + } | ||
| 985 | + | ||
| 986 | + /** | ||
| 987 | + * 添加网站反代信息 | ||
| 988 | + * @param [type] $cache 是否缓存 | ||
| 989 | + * @param [type] $proxyname 代理名称 | ||
| 990 | + * @param [type] $cachetime 缓存时长 /小时 | ||
| 991 | + * @param [type] $proxydir 代理目录 | ||
| 992 | + * @param [type] $proxysite 反代URL | ||
| 993 | + * @param [type] $todomain 目标域名 | ||
| 994 | + * @param [type] $advanced 高级功能:开启代理目录 | ||
| 995 | + * @param [type] $sitename 网站名 | ||
| 996 | + * @param [type] $subfilter 文本替换json格式[{"sub1":"百度","sub2":"白底"},{"sub1":"","sub2":""}] | ||
| 997 | + * @param [type] $type 开启或关闭 0关;1开 | ||
| 998 | + */ | ||
| 999 | + public function CreateProxy($cache,$proxyname,$cachetime,$proxydir,$proxysite,$todomain,$advanced,$sitename,$subfilter,$type){ | ||
| 1000 | + $url = $this->BT_PANEL.$this->config("CreateProxy"); | ||
| 1001 | + | ||
| 1002 | + $p_data = $this->GetKeyData(); | ||
| 1003 | + $p_data['cache'] = $cache; | ||
| 1004 | + $p_data['proxyname'] = $proxyname; | ||
| 1005 | + $p_data['cachetime'] = $cachetime; | ||
| 1006 | + $p_data['proxydir'] = $proxydir; | ||
| 1007 | + $p_data['proxysite'] = $proxysite; | ||
| 1008 | + $p_data['todomain'] = $todomain; | ||
| 1009 | + $p_data['advanced'] = $advanced; | ||
| 1010 | + $p_data['sitename'] = $sitename; | ||
| 1011 | + $p_data['subfilter'] = $subfilter; | ||
| 1012 | + $p_data['type'] = $type; | ||
| 1013 | + $result = $this->HttpPostCookie($url,$p_data); | ||
| 1014 | + | ||
| 1015 | + $data = json_decode($result,true); | ||
| 1016 | + return $data; | ||
| 1017 | + } | ||
| 1018 | + | ||
| 1019 | + /** | ||
| 1020 | + * 添加网站反代信息 | ||
| 1021 | + * @param [type] $cache 是否缓存 | ||
| 1022 | + * @param [type] $proxyname 代理名称 | ||
| 1023 | + * @param [type] $cachetime 缓存时长 /小时 | ||
| 1024 | + * @param [type] $proxydir 代理目录 | ||
| 1025 | + * @param [type] $proxysite 反代URL | ||
| 1026 | + * @param [type] $todomain 目标域名 | ||
| 1027 | + * @param [type] $advanced 高级功能:开启代理目录 | ||
| 1028 | + * @param [type] $sitename 网站名 | ||
| 1029 | + * @param [type] $subfilter 文本替换json格式[{"sub1":"百度","sub2":"白底"},{"sub1":"","sub2":""}] | ||
| 1030 | + * @param [type] $type 开启或关闭 0关;1开 | ||
| 1031 | + */ | ||
| 1032 | + public function ModifyProxy($cache,$proxyname,$cachetime,$proxydir,$proxysite,$todomain,$advanced,$sitename,$subfilter,$type){ | ||
| 1033 | + $url = $this->BT_PANEL.$this->config("ModifyProxy"); | ||
| 1034 | + | ||
| 1035 | + $p_data = $this->GetKeyData(); | ||
| 1036 | + $p_data['cache'] = $cache; | ||
| 1037 | + $p_data['proxyname'] = $proxyname; | ||
| 1038 | + $p_data['cachetime'] = $cachetime; | ||
| 1039 | + $p_data['proxydir'] = $proxydir; | ||
| 1040 | + $p_data['proxysite'] = $proxysite; | ||
| 1041 | + $p_data['todomain'] = $todomain; | ||
| 1042 | + $p_data['advanced'] = $advanced; | ||
| 1043 | + $p_data['sitename'] = $sitename; | ||
| 1044 | + $p_data['subfilter'] = $subfilter; | ||
| 1045 | + $p_data['type'] = $type; | ||
| 1046 | + $result = $this->HttpPostCookie($url,$p_data); | ||
| 1047 | + | ||
| 1048 | + $data = json_decode($result,true); | ||
| 1049 | + return $data; | ||
| 1050 | + } | ||
| 1051 | + | ||
| 1052 | + /** | ||
| 1053 | + * 获取网站域名绑定二级目录信息 | ||
| 1054 | + * @param [type] $id 网站ID | ||
| 1055 | + */ | ||
| 1056 | + public function GetDirBinding($id){ | ||
| 1057 | + $url = $this->BT_PANEL.$this->config("GetDirBinding"); | ||
| 1058 | + | ||
| 1059 | + $p_data = $this->GetKeyData(); | ||
| 1060 | + $p_data['id'] = $id; | ||
| 1061 | + $result = $this->HttpPostCookie($url,$p_data); | ||
| 1062 | + | ||
| 1063 | + $data = json_decode($result,true); | ||
| 1064 | + return $data; | ||
| 1065 | + } | ||
| 1066 | + | ||
| 1067 | + /** | ||
| 1068 | + * 设置网站域名绑定二级目录 | ||
| 1069 | + * @param [type] $id 网站ID | ||
| 1070 | + * @param [type] $domain 域名 | ||
| 1071 | + * @param [type] $dirName 目录 | ||
| 1072 | + */ | ||
| 1073 | + public function AddDirBinding($id,$domain,$dirName){ | ||
| 1074 | + $url = $this->BT_PANEL.$this->config("AddDirBinding"); | ||
| 1075 | + | ||
| 1076 | + $p_data = $this->GetKeyData(); | ||
| 1077 | + $p_data['id'] = $id; | ||
| 1078 | + $p_data['domain'] = $domain; | ||
| 1079 | + $p_data['dirName'] = $dirName; | ||
| 1080 | + $result = $this->HttpPostCookie($url,$p_data); | ||
| 1081 | + | ||
| 1082 | + $data = json_decode($result,true); | ||
| 1083 | + return $data; | ||
| 1084 | + } | ||
| 1085 | + | ||
| 1086 | + /** | ||
| 1087 | + * 删除网站域名绑定二级目录 | ||
| 1088 | + * @param [type] $dirid 子目录ID | ||
| 1089 | + */ | ||
| 1090 | + public function DelDirBinding($dirid){ | ||
| 1091 | + $url = $this->BT_PANEL.$this->config("DelDirBinding"); | ||
| 1092 | + | ||
| 1093 | + $p_data = $this->GetKeyData(); | ||
| 1094 | + $p_data['id'] = $dirid; | ||
| 1095 | + $result = $this->HttpPostCookie($url,$p_data); | ||
| 1096 | + | ||
| 1097 | + $data = json_decode($result,true); | ||
| 1098 | + return $data; | ||
| 1099 | + } | ||
| 1100 | + | ||
| 1101 | + /** | ||
| 1102 | + * 获取网站子目录绑定伪静态信息 | ||
| 1103 | + * @param [type] $dirid 子目录绑定ID | ||
| 1104 | + */ | ||
| 1105 | + public function GetDirRewrite($dirid,$type=0){ | ||
| 1106 | + $url = $this->BT_PANEL.$this->config("GetDirRewrite"); | ||
| 1107 | + | ||
| 1108 | + $p_data = $this->GetKeyData(); | ||
| 1109 | + $p_data['id'] = $dirid; | ||
| 1110 | + if($type){ | ||
| 1111 | + $p_data['add'] = 1; | ||
| 1112 | + } | ||
| 1113 | + $result = $this->HttpPostCookie($url,$p_data); | ||
| 1114 | + | ||
| 1115 | + $data = json_decode($result,true); | ||
| 1116 | + return $data; | ||
| 1117 | + } | ||
| 1118 | + | ||
| 1119 | + /** | ||
| 1120 | + * 修改FTP账号密码 | ||
| 1121 | + * @param [type] $id FTPID | ||
| 1122 | + * @param [type] $ftp_username 用户名 | ||
| 1123 | + * @param [type] $new_password 密码 | ||
| 1124 | + */ | ||
| 1125 | + public function SetUserPassword($id,$ftp_username,$new_password){ | ||
| 1126 | + $url = $this->BT_PANEL.$this->config("SetUserPassword"); | ||
| 1127 | + | ||
| 1128 | + $p_data = $this->GetKeyData(); | ||
| 1129 | + $p_data['id'] = $id; | ||
| 1130 | + $p_data['ftp_username'] = $ftp_username; | ||
| 1131 | + $p_data['new_password'] = $new_password; | ||
| 1132 | + $result = $this->HttpPostCookie($url,$p_data); | ||
| 1133 | + | ||
| 1134 | + $data = json_decode($result,true); | ||
| 1135 | + return $data; | ||
| 1136 | + } | ||
| 1137 | + | ||
| 1138 | + /** | ||
| 1139 | + * 修改SQL账号密码 | ||
| 1140 | + * @param [type] $id SQLID | ||
| 1141 | + * @param [type] $ftp_username 用户名 | ||
| 1142 | + * @param [type] $new_password 密码 | ||
| 1143 | + */ | ||
| 1144 | + public function ResDatabasePass($id,$name,$password){ | ||
| 1145 | + $url = $this->BT_PANEL.$this->config("ResDatabasePass"); | ||
| 1146 | + | ||
| 1147 | + $p_data = $this->GetKeyData(); | ||
| 1148 | + $p_data['id'] = $id; | ||
| 1149 | + $p_data['name'] = $name; | ||
| 1150 | + $p_data['password'] = $password; | ||
| 1151 | + $result = $this->HttpPostCookie($url,$p_data); | ||
| 1152 | + | ||
| 1153 | + $data = json_decode($result,true); | ||
| 1154 | + return $data; | ||
| 1155 | + } | ||
| 1156 | + | ||
| 1157 | + /** | ||
| 1158 | + * 启用/禁用FTP | ||
| 1159 | + * @param [type] $id FTPID | ||
| 1160 | + * @param [type] $username 用户名 | ||
| 1161 | + * @param [type] $status 状态 0->关闭;1->开启 | ||
| 1162 | + */ | ||
| 1163 | + public function SetStatus($id,$username,$status){ | ||
| 1164 | + $url = $this->BT_PANEL.$this->config("SetStatus"); | ||
| 1165 | + | ||
| 1166 | + $p_data = $this->GetKeyData(); | ||
| 1167 | + $p_data['id'] = $id; | ||
| 1168 | + $p_data['username'] = $username; | ||
| 1169 | + $p_data['status'] = $status; | ||
| 1170 | + $result = $this->HttpPostCookie($url,$p_data); | ||
| 1171 | + | ||
| 1172 | + $data = json_decode($result,true); | ||
| 1173 | + return $data; | ||
| 1174 | + } | ||
| 1175 | + | ||
| 1176 | + /** | ||
| 1177 | + * 宝塔一键部署列表 | ||
| 1178 | + * @param string $search 搜索关键词 | ||
| 1179 | + * @return [type] [description] | ||
| 1180 | + */ | ||
| 1181 | + public function deployment($search=''){ | ||
| 1182 | + if($search){ | ||
| 1183 | + $url = $this->BT_PANEL.$this->config("deployment").'&search='.$search; | ||
| 1184 | + }else{ | ||
| 1185 | + $url = $this->BT_PANEL.$this->config("deployment"); | ||
| 1186 | + } | ||
| 1187 | + | ||
| 1188 | + $p_data = $this->GetKeyData(); | ||
| 1189 | + $result = $this->HttpPostCookie($url,$p_data); | ||
| 1190 | + | ||
| 1191 | + $data = json_decode($result,true); | ||
| 1192 | + return $data; | ||
| 1193 | + } | ||
| 1194 | + | ||
| 1195 | + /** | ||
| 1196 | + * 宝塔一键部署执行 | ||
| 1197 | + * @param [type] $dname 部署程序名 | ||
| 1198 | + * @param [type] $site_name 部署到网站名 | ||
| 1199 | + * @param [type] $php_version PHP版本 | ||
| 1200 | + */ | ||
| 1201 | + public function SetupPackage($dname,$site_name,$php_version){ | ||
| 1202 | + $url = $this->BT_PANEL.$this->config("SetupPackage"); | ||
| 1203 | + | ||
| 1204 | + $p_data = $this->GetKeyData(); | ||
| 1205 | + $p_data['dname'] = $dname; | ||
| 1206 | + $p_data['site_name'] = $site_name; | ||
| 1207 | + $p_data['php_version'] = $php_version; | ||
| 1208 | + $result = $this->HttpPostCookie($url,$p_data); | ||
| 1209 | + | ||
| 1210 | + $data = json_decode($result,true); | ||
| 1211 | + return $data; | ||
| 1212 | + } | ||
| 1213 | + | ||
| 1214 | + /** | ||
| 1215 | + * 设置文件权限 | ||
| 1216 | + * @param $path | ||
| 1217 | + * @param $user | ||
| 1218 | + * @param $access | ||
| 1219 | + * @param $all | ||
| 1220 | + * @return mixed | ||
| 1221 | + */ | ||
| 1222 | + public function setFileAccess($path, $user, $access, $all) { | ||
| 1223 | + $url = $this->BT_PANEL.$this->config("SetFileAccess"); | ||
| 1224 | + $p_data = $this->GetKeyData(); | ||
| 1225 | + $p_data['user'] = $user; | ||
| 1226 | + $p_data['access'] = $access; | ||
| 1227 | + $p_data['all'] = $all; | ||
| 1228 | + $p_data['filename'] = $path; | ||
| 1229 | + $result = $this->HttpPostCookie($url,$p_data); | ||
| 1230 | + | ||
| 1231 | + $data = json_decode($result,true); | ||
| 1232 | + return $data; | ||
| 1233 | + } | ||
| 1234 | + | ||
| 1235 | + /** | ||
| 1236 | + * 获取队列 | ||
| 1237 | + * @return mixed | ||
| 1238 | + */ | ||
| 1239 | + public function getProcessList() | ||
| 1240 | + { | ||
| 1241 | + $url = $this->BT_PANEL.$this->config("GetProcessList"); | ||
| 1242 | + $p_data = $this->GetKeyData(); | ||
| 1243 | + $result = $this->HttpPostCookie($url,$p_data); | ||
| 1244 | + | ||
| 1245 | + $data = json_decode($result,true); | ||
| 1246 | + return $data; | ||
| 1247 | + } | ||
| 1248 | + | ||
| 1249 | + /** | ||
| 1250 | + * 停止队列 | ||
| 1251 | + * @param $program | ||
| 1252 | + * @param int $numprocs | ||
| 1253 | + * @return mixed | ||
| 1254 | + */ | ||
| 1255 | + public function stopProcess($program, $numprocs = 1) | ||
| 1256 | + { | ||
| 1257 | + $url = $this->BT_PANEL.$this->config("StopProcess"); | ||
| 1258 | + $p_data = $this->GetKeyData(); | ||
| 1259 | + $p_data['program'] = $program; | ||
| 1260 | + $p_data['numprocs'] = $numprocs; | ||
| 1261 | + $result = $this->HttpPostCookie($url,$p_data); | ||
| 1262 | + | ||
| 1263 | + $data = json_decode($result,true); | ||
| 1264 | + return $data; | ||
| 1265 | + } | ||
| 1266 | + | ||
| 1267 | + /** | ||
| 1268 | + * 修改队列 | ||
| 1269 | + * @param $pjname | ||
| 1270 | + * @param $level | ||
| 1271 | + * @param $user | ||
| 1272 | + * @param $command | ||
| 1273 | + * @param $numprocs | ||
| 1274 | + * @param $ps | ||
| 1275 | + * @param $path | ||
| 1276 | + * @return mixed | ||
| 1277 | + * @author Akun | ||
| 1278 | + * @date 2024/08/01 17:55 | ||
| 1279 | + */ | ||
| 1280 | + public function updateProcess($pjname,$level,$user,$command,$numprocs,$ps,$path) | ||
| 1281 | + { | ||
| 1282 | + $url = $this->BT_PANEL.$this->config("UpdateProcess"); | ||
| 1283 | + $p_data = $this->GetKeyData(); | ||
| 1284 | + $p_data['pjname'] = $pjname; | ||
| 1285 | + $p_data['level'] = $level; | ||
| 1286 | + $p_data['user'] = $user; | ||
| 1287 | + $p_data['command'] = $command; | ||
| 1288 | + $p_data['numprocs'] = $numprocs; | ||
| 1289 | + $p_data['ps'] = $ps; | ||
| 1290 | + $p_data['path'] = $path; | ||
| 1291 | + $result = $this->HttpPostCookie($url,$p_data); | ||
| 1292 | + | ||
| 1293 | + $data = json_decode($result,true); | ||
| 1294 | + return $data; | ||
| 1295 | + } | ||
| 1296 | + | ||
| 1297 | + /** | ||
| 1298 | + * 启动队列 | ||
| 1299 | + * @param $program | ||
| 1300 | + * @param int $numprocs | ||
| 1301 | + * @return mixed | ||
| 1302 | + */ | ||
| 1303 | + public function startProcess($program, $numprocs = 1) | ||
| 1304 | + { | ||
| 1305 | + $url = $this->BT_PANEL.$this->config("StartProcess"); | ||
| 1306 | + $p_data = $this->GetKeyData(); | ||
| 1307 | + $p_data['program'] = $program; | ||
| 1308 | + $p_data['numprocs'] = $numprocs; | ||
| 1309 | + $result = $this->HttpPostCookie($url,$p_data); | ||
| 1310 | + | ||
| 1311 | + $data = json_decode($result,true); | ||
| 1312 | + return $data; | ||
| 1313 | + } | ||
| 1314 | + | ||
| 1315 | + /** | ||
| 1316 | + * 设置文件权限 | ||
| 1317 | + * @param $path | ||
| 1318 | + * @return mixed | ||
| 1319 | + */ | ||
| 1320 | + public function DeleteFile($path) { | ||
| 1321 | + $url = $this->BT_PANEL.$this->config("DeleteFile"); | ||
| 1322 | + $p_data = $this->GetKeyData(); | ||
| 1323 | + $p_data['path'] = $path; | ||
| 1324 | + $result = $this->HttpPostCookie($url,$p_data); | ||
| 1325 | + | ||
| 1326 | + $data = json_decode($result,true); | ||
| 1327 | + return $data; | ||
| 1328 | + } | ||
| 1329 | + | ||
| 1330 | + /** | ||
| 1331 | + * 更新网站目录 | ||
| 1332 | + * @param $site_id | ||
| 1333 | + * @param $path | ||
| 1334 | + * @return mixed | ||
| 1335 | + */ | ||
| 1336 | + public function SetPath($site_id, $path) | ||
| 1337 | + { | ||
| 1338 | + $url = $this->BT_PANEL.$this->config("SetPath"); | ||
| 1339 | + $p_data = $this->GetKeyData(); | ||
| 1340 | + $p_data['id'] = $site_id; | ||
| 1341 | + $p_data['path'] = $path; | ||
| 1342 | + $result = $this->HttpPostCookie($url,$p_data); | ||
| 1343 | + $data = json_decode($result,true); | ||
| 1344 | + return $data; | ||
| 1345 | + } | ||
| 1346 | + | ||
| 1347 | + | ||
| 1348 | + /** | ||
| 1349 | + * 更新运行目录 | ||
| 1350 | + * @param $site_id | ||
| 1351 | + * @param $path | ||
| 1352 | + * @return mixed | ||
| 1353 | + */ | ||
| 1354 | + public function SetSiteRunPath($site_id, $path) | ||
| 1355 | + { | ||
| 1356 | + $url = $this->BT_PANEL.$this->config("SetSiteRunPath"); | ||
| 1357 | + $p_data = $this->GetKeyData(); | ||
| 1358 | + $p_data['id'] = $site_id; | ||
| 1359 | + $p_data['runPath'] = $path; | ||
| 1360 | + $result = $this->HttpPostCookie($url,$p_data); | ||
| 1361 | + $data = json_decode($result,true); | ||
| 1362 | + return $data; | ||
| 1363 | + } | ||
| 1364 | + | ||
| 1365 | + | ||
| 1366 | + /** | ||
| 1367 | + * 构造带有签名的关联数组 | ||
| 1368 | + */ | ||
| 1369 | + public function GetKeyData(){ | ||
| 1370 | + $now_time = time(); | ||
| 1371 | + $p_data = array( | ||
| 1372 | + 'request_token' => md5($now_time.''.md5($this->BT_KEY)), | ||
| 1373 | + 'request_time' => $now_time | ||
| 1374 | + ); | ||
| 1375 | + return $p_data; | ||
| 1376 | + } | ||
| 1377 | + | ||
| 1378 | + /** | ||
| 1379 | + * 发起POST请求 | ||
| 1380 | + * @param String $url 目标网填,带http:// | ||
| 1381 | + * @param Array|String $data 欲提交的数据 | ||
| 1382 | + * @return string | ||
| 1383 | + */ | ||
| 1384 | + private function HttpPostCookie($url, $data,$timeout = 300) | ||
| 1385 | + { | ||
| 1386 | + //定义cookie保存位置 | ||
| 1387 | + $cookie_file='./'.md5($this->BT_PANEL).'.cookie'; | ||
| 1388 | + if(!file_exists($cookie_file)){ | ||
| 1389 | + $fp = fopen($cookie_file,'w+'); | ||
| 1390 | + fclose($fp); | ||
| 1391 | + } | ||
| 1392 | + | ||
| 1393 | + $ch = curl_init(); | ||
| 1394 | + curl_setopt($ch, CURLOPT_URL, $url); | ||
| 1395 | + curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); | ||
| 1396 | + curl_setopt($ch, CURLOPT_POST, 1); | ||
| 1397 | + curl_setopt($ch, CURLOPT_POSTFIELDS, $data); | ||
| 1398 | + curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file); | ||
| 1399 | + curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file); | ||
| 1400 | + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | ||
| 1401 | + curl_setopt($ch, CURLOPT_HEADER, 0); | ||
| 1402 | + curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); | ||
| 1403 | + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); | ||
| 1404 | + $output = curl_exec($ch); | ||
| 1405 | + curl_close($ch); | ||
| 1406 | + return $output; | ||
| 1407 | + } | ||
| 1408 | + | ||
| 1409 | + /** | ||
| 1410 | + * 加载宝塔数据接口 | ||
| 1411 | + * @param [type] $str [description] | ||
| 1412 | + * @return [type] [description] | ||
| 1413 | + */ | ||
| 1414 | + private function config($str){ | ||
| 1415 | + $config = config("bt"); | ||
| 1416 | + //var_dump($config); | ||
| 1417 | + return $config[$str]; | ||
| 1418 | + } | ||
| 1419 | +} | ||
| 1420 | + | ||
| 1421 | + | ||
| 1422 | + | 
app/Repositories/BtRepository.php
0 → 100644
| 1 | +<?php | ||
| 2 | +/** | ||
| 3 | + * Created by PhpStorm. | ||
| 4 | + * User: zhl | ||
| 5 | + * Date: 2023/09/18 | ||
| 6 | + * Time: 20:56 | ||
| 7 | + */ | ||
| 8 | + | ||
| 9 | +namespace App\Repositories; | ||
| 10 | + | ||
| 11 | +use App\Repositories\Bt\Bt; | ||
| 12 | + | ||
| 13 | +/** | ||
| 14 | + * Class BtRepository | ||
| 15 | + * @package App\Repositories | ||
| 16 | + */ | ||
| 17 | +class BtRepository | ||
| 18 | +{ | ||
| 19 | + public $instance = []; | ||
| 20 | + | ||
| 21 | + /** | ||
| 22 | + * 获取bt对象 | ||
| 23 | + * @param string $key | ||
| 24 | + * @param string $panel | ||
| 25 | + * @return Bt | ||
| 26 | + */ | ||
| 27 | + public function getBtObject($key = '', $panel = '') | ||
| 28 | + { | ||
| 29 | + $key = $key ?: env('BT_KEY'); | ||
| 30 | + $panel = $panel ?: env('BT_PANEL'); | ||
| 31 | + $object_key = md5($key . $panel); | ||
| 32 | + if (empty($this->instance[$object_key])) { | ||
| 33 | + $bt = new Bt($panel, $key); | ||
| 34 | + $this->instance[$object_key] = $bt; | ||
| 35 | + } | ||
| 36 | + return $this->instance[$object_key]; | ||
| 37 | + } | ||
| 38 | + | ||
| 39 | + /** | ||
| 40 | + * 获取配置前的文件内容 | ||
| 41 | + * @param $domain | ||
| 42 | + * @return string|string[] | ||
| 43 | + */ | ||
| 44 | + public function getBeforeNginxConfStr($domain) | ||
| 45 | + { | ||
| 46 | + $bt = $this->getBtObject(); | ||
| 47 | + $conf = $bt->GetFileBody($domain, 2); | ||
| 48 | + | ||
| 49 | + //如果有变量标识,去掉变量标识 | ||
| 50 | + if (FALSE !== strpos($conf['data'], 'map $domain_prefix')) { | ||
| 51 | + $conf['data'] = str_replace($this->domainPrefixConf(), '', $conf['data']); | ||
| 52 | + //去掉自定义配置 | ||
| 53 | + $conf['data'] = str_replace($this->customConf($domain), 'root ' . public_path() . ';', $conf['data']); | ||
| 54 | + } | ||
| 55 | + return $conf['data']; | ||
| 56 | + } | ||
| 57 | + | ||
| 58 | + /** | ||
| 59 | + * 获取配置后的文件内容 | ||
| 60 | + * @param $domain | ||
| 61 | + * @return mixed | ||
| 62 | + */ | ||
| 63 | + public function getAfterNginxConfStr($domain) | ||
| 64 | + { | ||
| 65 | + $bt = $this->getBtObject(); | ||
| 66 | + $conf = $bt->GetFileBody($domain, 2); | ||
| 67 | + // 如果没有变量, 添加变量识别 | ||
| 68 | + if (FALSE === strpos($conf['data'], 'map $domain_prefix')) { | ||
| 69 | + $conf['data'] = $this->domainPrefixConf() . $conf['data']; | ||
| 70 | + // 替换自定义配置 | ||
| 71 | + $conf['data'] = str_replace('root ' . public_path() . ';', $this->customConf($domain), $conf['data']); | ||
| 72 | + } | ||
| 73 | + | ||
| 74 | + return $conf['data']; | ||
| 75 | + } | ||
| 76 | + | ||
| 77 | + | ||
| 78 | + /** | ||
| 79 | + * 需要定制修改的配置 | ||
| 80 | + * @param $domain string | ||
| 81 | + * @return string | ||
| 82 | + */ | ||
| 83 | + public function customConf($domain): string | ||
| 84 | + { | ||
| 85 | + $domain_arr = explode('.', $domain); | ||
| 86 | + if ($domain_arr[0] == 'www') { | ||
| 87 | + $string = ' root ' . public_path() . '; # 设置根目录 | ||
| 88 | + | ||
| 89 | + set $domain_prefix ""; | ||
| 90 | + if ($host ~* "^(?<domain_prefix>[^.]+)\.") { | ||
| 91 | + set $domain_prefix $1; | ||
| 92 | + } | ||
| 93 | + | ||
| 94 | + location / { | ||
| 95 | + root ' . public_path() . '/' . $domain . '; # 设置根目录 | ||
| 96 | + if ($is_prefix_in_string = 1) { | ||
| 97 | + root ' . public_path() . '/' . $domain . '/$domain_prefix; | ||
| 98 | + } | ||
| 99 | + try_files $uri $uri/ /404/index.html =404; | ||
| 100 | + } | ||
| 101 | + | ||
| 102 | + location ~ ^/(api|search) { | ||
| 103 | + root ' . public_path() . '; # 设置/api /search /.well-known的根目录 | ||
| 104 | + try_files $uri $uri/ /index.php?$query_string; | ||
| 105 | + } | ||
| 106 | + | ||
| 107 | + location ~ ^/(well-known) { | ||
| 108 | + root ' . public_path() . '; | ||
| 109 | + try_files $uri $uri/ /404/index.html =404; | ||
| 110 | + } | ||
| 111 | + error_page 403 /404/index.html;'; | ||
| 112 | + | ||
| 113 | + } else { | ||
| 114 | + $string = ' root ' . public_path() . '; # 设置根目录 | ||
| 115 | + | ||
| 116 | + set $domain_prefix ""; | ||
| 117 | + if ($host ~* "^(?<domain_prefix>[^.]+)\.") { | ||
| 118 | + set $domain_prefix $1; | ||
| 119 | + } | ||
| 120 | + | ||
| 121 | + if ($domain_prefix = ' . $domain_arr[0] . '){ | ||
| 122 | + set $is_prefix_in_string 0; | ||
| 123 | + } | ||
| 124 | + | ||
| 125 | + location / { | ||
| 126 | + root ' . public_path() . '/' . $domain . '; # 设置根目录 | ||
| 127 | + if ($is_prefix_in_string = 1) { | ||
| 128 | + root ' . public_path() . '/' . $domain . '/$domain_prefix; | ||
| 129 | + } | ||
| 130 | + try_files $uri $uri/ /404/index.html =404; | ||
| 131 | + } | ||
| 132 | + | ||
| 133 | + location ~ ^/(api|search) { | ||
| 134 | + root ' . public_path() . '; # 设置/api /search /.well-known的根目录 | ||
| 135 | + try_files $uri $uri/ /index.php?$query_string; | ||
| 136 | + } | ||
| 137 | + | ||
| 138 | + location ~ ^/(well-known) { | ||
| 139 | + root ' . public_path() . '; | ||
| 140 | + try_files $uri $uri/ /404/index.html =404; | ||
| 141 | + } | ||
| 142 | + error_page 403 /404/index.html;'; | ||
| 143 | + | ||
| 144 | + } | ||
| 145 | + | ||
| 146 | + return $string; | ||
| 147 | + } | ||
| 148 | + | ||
| 149 | + /** | ||
| 150 | + * 配置变量 | ||
| 151 | + * @return string | ||
| 152 | + */ | ||
| 153 | + public function domainPrefixConf() | ||
| 154 | + { | ||
| 155 | + return 'map $domain_prefix $is_prefix_in_string { | ||
| 156 | + default 0; en 1; zh 1; fr 1; de 1; ko 1; ja 1; es 1; ar 1; pt 1; ru 1; af 1; sq 1; | ||
| 157 | + am 1; hy 1; az 1; eu 1; be 1; bn 1; bs 1; bg 1; ca 1; ceb 1; zh-CN 1; zh-TW 1; co 1; | ||
| 158 | + hr 1; cs 1; da 1; nl 1; eo 1; et 1; fi 1; fy 1; gl 1; ka 1; el 1; gu 1; ht 1; ha 1; haw 1; | ||
| 159 | + iw 1; hi 1; hmn 1; hu 1; is 1; ig 1; id 1; ga 1; it 1; jw 1; kn 1; kk 1; km 1; rw 1; | ||
| 160 | + ku 1; ky 1; lo 1; la 1; lv 1; lt 1; lb 1; mk 1; mg 1; ms 1; ml 1; mt 1; mi 1; mr 1; mn 1; | ||
| 161 | + my 1; ne 1; no 1; ny 1; or 1; ps 1; fa 1; pl 1; pa 1; ro 1; sm 1; gd 1; sr 1; st 1; sn 1; | ||
| 162 | + sd 1; si 1; sk 1; sl 1; so 1; su 1; sw 1; sv 1; tl 1; tg 1; ta 1; tt 1; te 1; th 1; tr 1; | ||
| 163 | + tk 1; uk 1; ur 1; ug 1; uz 1; vi 1; cy 1; xh 1; yi 1; yo 1; zu 1; | ||
| 164 | +}'; | ||
| 165 | + } | ||
| 166 | +} | 
- 
请 注册 或 登录 后发表评论