BtRepositories.php
3.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
<?php
/**
* Created by PhpStorm.
* User: zhl
* Date: 2022/11/1
* Time: 11:56
*/
namespace App\Repositories;
use App\Models\BtSites;
use App\Repositories\Bt\Bt;
/**
* Class BtRepositories
* @package App\Repositories
*/
class BtRepositories
{
public $instance = [];
/**
* @param $domain
* @param $ssl_open
* @param $ssl_auto
* @param $ssl_auto_day
* @return array|bool
*/
public function createBtSite($domain, $ssl_open, $ssl_auto, $ssl_auto_day)
{
$domain_array = parse_url($domain);
$host = $domain_array['host'];
$host_array = explode('.', $host);
if (empty($host_array[0]) && $host_array[0] == 'www')
unset($host_array[0]);
$domain_top = implode('.', $host_array);
$web_name = ['domain' => $host, 'domainlist' => [$domain_top], 'count' => 0];
$array = [
'webname' => json_encode($web_name),
'path' => env('PROJECT_PATH') ? env('PROJECT_PATH') : dirname(dirname(app_path())) . DIRECTORY_SEPARATOR . $domain,
'type_id' => 0,
'type' => 'PHP',
'version' => '73',
'port' => '80',
'ps' => $host,
'ftp' => false,
'ftp_username' => '',
'ftp_password' => '',
'sql' => false,
'codeing' => '',
'datauser' => '',
'datapassword' => '',
];
$bt = $this->getBtObject();
$result = $bt->AddSite($array);
if (empty($result) || empty($result['id']))
return false;
$ssl_status = 0;
$result = BtSites::createBtSite($host, $result['id'], $ssl_open, $ssl_status, $ssl_auto, $ssl_auto_day);
return $result->toArray();
}
/**
* 删除站点
* @param $domain
* @return bool
*/
public function deleteBtSite($domain)
{
$domain = parse_url($domain);
$domain_array = parse_url($domain);
$host = $domain_array['host'];
$bt = $this->getBtObject();
$site = BtSites::getSiteByDomain($host);
// $id = $site->site_id;
// 获取bt数据 可能要可靠一些
$result = $bt->Websites($host);
if (empty($result['data']))
return false;
$id = 0;
foreach ($result['data'] as $v) {
if ($v['name'] == $domain) {
$id = $v['id'];
break;
}
}
if (empty($id))
return false;
$result = $bt->WebDeleteSite($id,$domain,false,false,false);
$site->is_del = BtSites::IS_DEL_TRUE;
$site->save();
return true;
}
/**
* 获取bt对象
* @param string $key
* @param string $panel
* @return Bt
*/
public function getBtObject($key = '', $panel = '')
{
$key = $key ?: env('BT_KEY');
$panel = $panel ?: env('BT_PANEL');
$object_key = md5($key . $panel);
if (empty($this->instance[$object_key])) {
$bt = new Bt($panel, $key);
$this->instance[$object_key] = $bt;
}
return $this->instance[$object_key];
}
}