作者 刘锟

update

<?php
namespace App\Console\Commands;
use App\Repositories\BtRepository;
use Illuminate\Console\Command;
class SelfSiteSsl extends Command
{
protected $signature = 'self_site_ssl';
protected $description = '自建站项目自动更新证书';
protected $bt_repository;
protected $bt;
public function __construct()
{
parent::__construct();
$this->bt_repository = new BtRepository();
$this->bt = $this->bt_repository->getBtObject();
}
public function handle()
{
try {
$this->checkDomainSsl();
} catch (\Exception $e) {
$this->output($e->getMessage());
}
}
public function checkDomainSsl()
{
$end_day = date('Y-m-d H:i:s', time() + 3 * 24 * 3600);//3天后到期
$site_domain = env('DOMAIN', '');
$site_ip = env('SITE_IP', '');
if (!$site_domain) {
throw new \Exception('项目主站域名未配置');
}
if (!$site_ip) {
throw new \Exception('项目主站IP未配置');
}
$ssl_time = $this->getDomainSslTime($site_domain);
if ($ssl_time['to'] < $end_day) {
//主站证书即将到期
$site_list = $this->bt->WebSiteList($site_domain);
if (isset($site_list['data']) && $site_list['data'] && $site_list['data'][0]['status'] == 1) {
$site_id = $site_list['data'][0]['id'];
$host = $site_list['data'][0]['name'];
//获取站点可用于设置证书的域名
$site_domain = $this->bt->WebDoaminList($site_id);
$apply_ssl_domain_list = [];
foreach ($site_domain as $val) {
if (strpos($val['name'], '*') === false && $this->check_domain_record($val['name'], ['ip' => $site_ip])) {
$apply_ssl_domain_list[] = $val['name'];
}
}
if (empty($apply_ssl_domain_list)) {
throw new \Exception('主站所有域名都未解析在当前服务器');
}
//申请证书之前,还原主站配置
$config_before = file_get_contents(public_path('main_site_default.txt'));
$re_config_before = $this->bt->SaveFileBody('/www/server/panel/vhost/nginx/' . $host . '.conf', $config_before, 'utf-8', 1);
if (!($re_config_before['status'] ?? false)) {
throw new \Exception($re_config_before['msg'] ?? '还原主站nginx配置失败');
}
//设置站点证书
$this->setDomainSsl($site_id, $host, $apply_ssl_domain_list);
//申请证书之后,更新主站配置
$config_after = file_get_contents(public_path('main_site_config.txt'));
$re_config_after = $this->bt->SaveFileBody('/www/server/panel/vhost/nginx/' . $host . '.conf', $config_after, 'utf-8', 1);
if (!($re_config_after['status'] ?? false)) {
throw new \Exception($re_config_after['msg'] ?? '更新主站nginx配置失败');
}
$this->output('主站证书更新成功');
}
}
$amp_domain = env('AMP_DOMAIN', '');
if ($amp_domain) {
$amp_ssl_time = $this->getDomainSslTime($amp_domain);
if ($amp_ssl_time['to'] < $end_day) {
//AMP证书即将到期
$amp_site_list = $this->bt->WebSiteList($amp_domain);
if (isset($amp_site_list['data']) && $amp_site_list['data'] && $amp_site_list['data'][0]['status'] == 1) {
$amp_site_id = $amp_site_list['data'][0]['id'];
$amp_host = $amp_site_list['data'][0]['name'];
//设置站点证书
$this->setDomainSsl($amp_site_id, $amp_host, [$amp_host]);
$this->output('AMP站证书更新成功');
}
}
}
}
/**
* 检查域名解析师是否正确
* @param $domain
* @param $server_info
* @return bool
* @author Akun
* @date 2025/01/13 14:53
*/
public function check_domain_record($domain, $server_info)
{
try {
$records = dns_get_record($domain, DNS_A);
if (count($records) != 1) {
return false;
}
$record = $records[0];
if ($record['host'] == $server_info['domain'] || $record['ip'] == $server_info['ip']) {
return $domain;
} else {
return false;
}
} catch (\Exception $e) {
return false;
}
}
/**
* 设置域名证书
* @param $site_id
* @param $host
* @param $domain_list
* @param string $key
* @param string $cer
* @throws \Exception
* @author Akun
* @date 2025/01/13 14:53
*/
public function setDomainSsl($site_id, $host, $domain_list, $key = '', $cer = '')
{
if (empty($key) || empty($cer)) {
$ssl = $this->bt->GetSSL($host);
if (isset($ssl['cert_data']['notAfter']) && strtotime($ssl['cert_data']['notAfter']) - time() > 259200) {
// 如果已经申请了ssl证书, 并且证书有效期超过3天, 那么就使用已经申请好的证书
$key = $ssl['key'];
$cer = $ssl['csr'];
$is_set_status = !$ssl['status'];
} else {
$re_apply_cert = $this->bt->ApplyCert(json_encode($domain_list), $site_id);
if (!($re_apply_cert['status'] ?? false)) {
$apply_error_msg = '申请免费证书失败';
if (isset($re_apply_cert['msg'])) {
if (is_array($re_apply_cert['msg'])) {
$apply_error_msg = json_encode($re_apply_cert['msg']);
} else {
$apply_error_msg = $re_apply_cert['msg'];
}
}
throw new \Exception($apply_error_msg);
}
$key = $re_apply_cert['private_key'];
$cer = $re_apply_cert['cert'];
$is_set_status = true;
}
} else {
$is_set_status = true;
}
if ($key && $cer && $is_set_status) {
$re_set_ssl = $this->bt->SetSSL(1, $host, $key, $cer);
if (!($re_set_ssl['status'] ?? false)) {
throw new \Exception($re_set_ssl['msg'] ?? '设置证书失败');
}
}
}
/**
* 获取域名证书有效时间
* @param $domain
* @return string[]
* @author Akun
* @date 2024/08/29 9:59
*/
public function getDomainSslTime($domain)
{
$valid_from = '';
$valid_to = '';
try {
$context = stream_context_create([
'ssl' => [
'capture_peer_cert' => true,
'capture_peer_cert_chain' => false,
'verify_peer' => false,
'verify_peer_name' => false
],
]);
$stream = stream_socket_client('ssl://' . $domain . ':443', $errno, $errstr, 30, STREAM_CLIENT_CONNECT, $context);
if ($stream) {
$remote_cert = stream_context_get_params($stream)['options']['ssl']['peer_certificate'];
if ($remote_cert) {
$valid_from = date('Y-m-d H:i:s', openssl_x509_parse($remote_cert)['validFrom_time_t']);
$valid_to = date('Y-m-d H:i:s', openssl_x509_parse($remote_cert)['validTo_time_t']);
}
}
fclose($stream);
} catch (\Exception $e) {
$valid_from = '';
$valid_to = '';
}
return ['from' => $valid_from, 'to' => $valid_to];
}
/**
* 输出处理日志
* @param $message
*/
public function output($message)
{
echo date('Y-m-d H:i:s') . ' | ' . $message . PHP_EOL;
}
}
... ...
<?php
namespace App\Repositories\Bt;
/**
* 宝塔面板站点操作类库
* @author 阿良 or Youngxj(二次开发)
* @link https://www.bt.cn/api-doc.pdf
* @link https://gitee.com/youngxj0/Bty1.0
* @version 1.0
* @example
* $bt = new Bt('http://127.0.0.1/8888','xxxxxxxxxxxxxxxx');
* echo $bt->GetSystemTotal();//获取系统基础统计
* @return Array
*/
class Bt
{
private $BT_KEY = ""; //接口密钥
private $BT_PANEL = "http://127.0.0.1/8888"; //面板地址
/**
* 初始化
* @param [type] $bt_panel 宝塔接口地址
* @param [type] $bt_key 宝塔Api密钥
*/
public function __construct($bt_panel = null,$bt_key = null){
if($bt_panel) $this->BT_PANEL = $bt_panel;
if($bt_key) $this->BT_KEY = $bt_key;
}
/**
* 获取系统基础统计
*/
public function GetSystemTotal(){
$url = $this->BT_PANEL.$this->config("GetSystemTotal");
$p_data = $this->GetKeyData();
$result = $this->HttpPostCookie($url,$p_data);
$data = json_decode($result,true);
return $data;
}
/**
* 获取磁盘分区信息
*/
public function GetDiskInfo(){
$url = $this->BT_PANEL.$this->config("GetDiskInfo");
$p_data = $this->GetKeyData();
$result = $this->HttpPostCookie($url,$p_data);
$data = json_decode($result,true);
return $data;
}
/**
* 获取实时状态信息
* (CPU、内存、网络、负载)
*/
public function GetNetWork(){
$url = $this->BT_PANEL.$this->config("GetNetWork");
$p_data = $this->GetKeyData();
$result = $this->HttpPostCookie($url,$p_data);
$data = json_decode($result,true);
return $data;
}
/**
* 检查是否有安装任务
*/
public function GetTaskCount(){
$url = $this->BT_PANEL.$this->config("GetTaskCount");
$p_data = $this->GetKeyData();
$result = $this->HttpPostCookie($url,$p_data);
$data = json_decode($result,true);
return $data;
}
/**
* 检查面板更新
*/
public function UpdatePanel($check=false,$force=false){
$url = $this->BT_PANEL.$this->config("UpdatePanel");
$p_data = $this->GetKeyData();
$p_data['check'] = $check;
$p_data['force'] = $force;
$result = $this->HttpPostCookie($url,$p_data);
$data = json_decode($result,true);
return $data;
}
/**
* 申请ssl
*/
public function ApplyCert($domains,$id){
$url = $this->BT_PANEL.$this->config("ApplyCert");
$p_data = $this->GetKeyData();
$p_data['domains'] = $domains;
$p_data['auth_type'] = "http";
$p_data['auth_to'] = $id;
$p_data['auto_wildcard'] = 0;
$p_data['id'] = $id;
$result = $this->HttpPostCookie($url,$p_data);
$data = json_decode($result,true);
return $data;
}
/**
* 续签ssl
*/
public function RenewCert($index){
$url = $this->BT_PANEL.$this->config("RenewCert");
$p_data = $this->GetKeyData();
$p_data['index'] = $index;
$result = $this->HttpPostCookie($url,$p_data);
$data = json_decode($result,true);
return $data;
}
/**
* 获取网站列表
* @param string $page 当前分页
* @param string $limit 取出的数据行数
* @param string $type 分类标识 -1: 分部分类 0: 默认分类
* @param string $order 排序规则 使用 id 降序:id desc 使用名称升序:name desc
* @param string $tojs 分页 JS 回调,若不传则构造 URI 分页连接
* @param string $search 搜索内容
* @return mixed
*/
public function Websites($search='',$page='1',$limit='15',$type='-1',$order='id desc',$tojs=''){
$url = $this->BT_PANEL.$this->config("Websites");
$p_data = $this->GetKeyData();
$p_data['p'] = $page;
$p_data['limit'] = $limit;
$p_data['type'] = $type;
$p_data['order'] = $order;
$p_data['tojs'] = $tojs;
$p_data['search'] = $search;
$result = $this->HttpPostCookie($url,$p_data);
return json_decode($result,true);
}
/**
* 获取网站FTP列表
* @param string $page 当前分页
* @param string $limit 取出的数据行数
* @param string $type 分类标识 -1: 分部分类 0: 默认分类
* @param string $order 排序规则 使用 id 降序:id desc 使用名称升序:name desc
* @param string $tojs 分页 JS 回调,若不传则构造 URI 分页连接
* @param string $search 搜索内容
* @return mixed
*/
public function WebFtpList($search='',$page='1',$limit='15',$type='-1',$order='id desc',$tojs=''){
$url = $this->BT_PANEL.$this->config("WebFtpList");
$p_data = $this->GetKeyData();
$p_data['p'] = $page;
$p_data['limit'] = $limit;
$p_data['type'] = $type;
$p_data['order'] = $order;
$p_data['tojs'] = $tojs;
$p_data['search'] = $search;
$result = $this->HttpPostCookie($url,$p_data);
$data = json_decode($result,true);
return $data;
}
/**
* 获取网站SQL列表
* @param string $page 当前分页
* @param string $limit 取出的数据行数
* @param string $type 分类标识 -1: 分部分类 0: 默认分类
* @param string $order 排序规则 使用 id 降序:id desc 使用名称升序:name desc
* @param string $tojs 分页 JS 回调,若不传则构造 URI 分页连接
* @param string $search 搜索内容
*/
public function WebSqlList($search='',$page='1',$limit='15',$type='-1',$order='id desc',$tojs=''){
$url = $this->BT_PANEL.$this->config("WebSqlList");
$p_data = $this->GetKeyData();
$p_data['p'] = $page;
$p_data['limit'] = $limit;
$p_data['type'] = $type;
$p_data['order'] = $order;
$p_data['tojs'] = $tojs;
$p_data['search'] = $search;
$result = $this->HttpPostCookie($url,$p_data);
$data = json_decode($result,true);
return $data;
}
/**
* 获取所有网站分类
*/
public function Webtypes(){
$url = $this->BT_PANEL.$this->config("Webtypes");
$p_data = $this->GetKeyData();
$result = $this->HttpPostCookie($url,$p_data);
$data = json_decode($result,true);
return $data;
}
/**
* 获取已安装的 PHP 版本列表
*/
public function GetPHPVersion(){
//拼接URL地址
$url = $this->BT_PANEL.$this->config("GetPHPVersion");
//准备POST数据
$p_data = $this->GetKeyData(); //取签名
//请求面板接口
$result = $this->HttpPostCookie($url,$p_data);
//解析JSON数据
$data = json_decode($result,true);
return $data;
}
/**
* 修改指定网站的PHP版本
* @param [type] $site 网站名
* @param [type] $php PHP版本
*/
public function SetPHPVersion($site,$php){
$url = $this->BT_PANEL.$this->config("SetPHPVersion");
$p_data = $this->GetKeyData();
$p_data['siteName'] = $site;
$p_data['version'] = $php;
$result = $this->HttpPostCookie($url,$p_data);
$data = json_decode($result,true);
return $data;
}
/**
* 获取指定网站运行的PHP版本
* @param [type] $site 网站名
*/
public function GetSitePHPVersion($site){
$url = $this->BT_PANEL.$this->config("GetSitePHPVersion");
$p_data = $this->GetKeyData();
$p_data['siteName'] = $site;
$result = $this->HttpPostCookie($url,$p_data);
$data = json_decode($result,true);
return $data;
}
/**
* 新增网站
* @param [type] $webname 网站域名 json格式
* @param [type] $path 网站路径
* @param [type] $type_id 网站分类ID
* @param string $type 网站类型
* @param [type] $version PHP版本
* @param [type] $port 网站端口
* @param [type] $ps 网站备注
* @param [type] $ftp 网站是否开通FTP
* @param [type] $ftp_username FTP用户名
* @param [type] $ftp_password FTP密码
* @param [type] $sql 网站是否开通数据库
* @param [type] $codeing 数据库编码类型 utf8|utf8mb4|gbk|big5
* @param [type] $datauser 数据库账号
* @param [type] $datapassword 数据库密码
*/
public function AddSite($infoArr=[]){
$url = $this->BT_PANEL.$this->config("WebAddSite");
//准备POST数据
$p_data = $this->GetKeyData(); //取签名
$p_data['webname'] = $infoArr['webname'];
$p_data['path'] = $infoArr['path'];
$p_data['type_id'] = $infoArr['type_id'];
$p_data['type'] = $infoArr['type'];
$p_data['version'] = $infoArr['version'];
$p_data['port'] = $infoArr['port'];
$p_data['ps'] = $infoArr['ps'];
$p_data['ftp'] = $infoArr['ftp'];
$p_data['ftp_username'] = $infoArr['ftp_username'];
$p_data['ftp_password'] = $infoArr['ftp_password'];
$p_data['sql'] = $infoArr['sql'];
$p_data['codeing'] = $infoArr['codeing'];
$p_data['datauser'] = $infoArr['datauser'];
$p_data['datapassword'] = $infoArr['datapassword'];
//请求面板接口
$result = $this->HttpPostCookie($url,$p_data);
//var_dump($result);
//解析JSON数据
$data = json_decode($result,true);
return $data;
}
/**
* 删除网站
* @param [type] $id 网站ID
* @param [type] $webname 网站名称
* @param [type] $ftp 是否删除关联FTP
* @param [type] $database 是否删除关联数据库
* @param [type] $path 是否删除关联网站根目录
*
*/
public function WebDeleteSite($id,$webname,$ftp,$database,$path){
$url = $this->BT_PANEL.$this->config("WebDeleteSite");
$p_data = $this->GetKeyData();
$p_data['id'] = $id;
$p_data['webname'] = $webname;
$ftp && $p_data['ftp'] = $ftp;
$database && $p_data['database'] = $database;
$path && $p_data['path'] = $path;
$result = $this->HttpPostCookie($url,$p_data);
$data = json_decode($result,true);
return $data;
}
/**
* 停用站点
* @param [type] $id 网站ID
* @param [type] $name 网站域名
* @return mixed
*/
public function WebSiteStop($id,$name){
$url = $this->BT_PANEL.$this->config("WebSiteStop");
$p_data = $this->GetKeyData();
$p_data['id'] = $id;
$p_data['name'] = $name;
$result = $this->HttpPostCookie($url,$p_data);
$data = json_decode($result,true);
return $data;
}
/**
* 启用网站
* @param [type] $id 网站ID
* @param [type] $name 网站域名
* @return mixed
*/
public function WebSiteStart($id,$name){
$url = $this->BT_PANEL.$this->config("WebSiteStart");
$p_data = $this->GetKeyData();
$p_data['id'] = $id;
$p_data['name'] = $name;
$result = $this->HttpPostCookie($url,$p_data);
$data = json_decode($result,true);
return $data;
}
/**
* 设置网站到期时间
* @param [type] $id 网站ID
* @param [type] $edate 网站到期时间 格式:2019-01-01,永久:0000-00-00
* @return mixed
*/
public function WebSetEdate($id,$edate){
$url = $this->BT_PANEL.$this->config("WebSetEdate");
$p_data = $this->GetKeyData();
$p_data['id'] = $id;
$p_data['edate'] = $edate;
$result = $this->HttpPostCookie($url,$p_data);
$data = json_decode($result,true);
return $data;
}
/**
* 修改网站备注
* @param [type] $id 网站ID
* @param [type] $ps 网站备注
*/
public function WebSetPs($id,$ps){
$url = $this->BT_PANEL.$this->config("WebSetPs");
$p_data = $this->GetKeyData();
$p_data['id'] = $id;
$p_data['ps'] = $ps;
$result = $this->HttpPostCookie($url,$p_data);
$data = json_decode($result,true);
return $data;
}
/**
* 获取网站备份列表
* @param [type] $id 网站ID
* @param string $page 当前分页
* @param string $limit 每页取出的数据行数
* @param string $type 备份类型 目前固定为0
* @param string $tojs 分页js回调若不传则构造 URI 分页连接 get_site_backup
*/
public function WebBackupList($id,$page='1',$limit='5',$type='0',$tojs=''){
$url = $this->BT_PANEL.$this->config("WebBackupList");
$p_data = $this->GetKeyData();
$p_data['p'] = $page;
$p_data['limit'] = $limit;
$p_data['type'] = $type;
$p_data['tojs'] = $tojs;
$p_data['search'] = $id;
$result = $this->HttpPostCookie($url,$p_data);
$data = json_decode($result,true);
return $data;
}
/**
* 创建网站备份
* @param [type] $id 网站ID
*/
public function WebToBackup($id){
$url = $this->BT_PANEL.$this->config("WebToBackup");
$p_data = $this->GetKeyData();
$p_data['id'] = $id;
$result = $this->HttpPostCookie($url,$p_data);
$data = json_decode($result,true);
return $data;
}
/**
* 删除网站备份
* @param [type] $id 网站备份ID
*/
public function WebDelBackup($id){
$url = $this->BT_PANEL.$this->config("WebDelBackup");
$p_data = $this->GetKeyData();
$p_data['id'] = $id;
$result = $this->HttpPostCookie($url,$p_data);
$data = json_decode($result,true);
return $data;
}
/**
* 删除数据库备份
* @param [type] $id 数据库备份ID
*/
public function SQLDelBackup($id){
$url = $this->BT_PANEL.$this->config("SQLDelBackup");
$p_data = $this->GetKeyData();
$p_data['id'] = $id;
$result = $this->HttpPostCookie($url,$p_data);
$data = json_decode($result,true);
return $data;
}
/**
* 备份数据库
* @param [type] $id 数据库列表ID
*/
public function SQLToBackup($id){
$url = $this->BT_PANEL.$this->config("SQLToBackup");
$p_data = $this->GetKeyData();
$p_data['id'] = $id;
$result = $this->HttpPostCookie($url,$p_data);
$data = json_decode($result,true);
return $data;
}
/**
* 获取网站域名列表
* @param [type] $id 网站ID
* @param boolean $list 固定传true
*/
public function WebDoaminList($id,$list=true){
$url = $this->BT_PANEL.$this->config("WebDoaminList");
$p_data = $this->GetKeyData();
$p_data['search'] = $id;
$p_data['list'] = $list;
$result = $this->HttpPostCookie($url,$p_data);
$data = json_decode($result,true);
return $data;
}
/**
* 获取网站列表
* @param string $search
* @param int $p
* @param int $limit
* @param int $type
* @return mixed
*/
public function WebSiteList($search = '', $p = 1, $limit = 20, $type = 0){
$url = $this->BT_PANEL.$this->config("WebSiteList");
$p_data = $this->GetKeyData();
$p_data['search'] = $search;
$p_data['p'] = $p;
$p_data['limit'] = $limit;
$p_data['type'] = $type;
$result = $this->HttpPostCookie($url,$p_data);
$data = json_decode($result,true);
return $data;
}
/**
* 添加域名
* @param [type] $id 网站ID
* @param [type] $webname 网站名称
* @param [type] $domain 要添加的域名:端口 80 端品不必构造端口,多个域名用换行符隔开
*/
public function WebAddDomain($id,$webname,$domain){
$url = $this->BT_PANEL.$this->config("WebAddDomain");
$p_data = $this->GetKeyData();
$p_data['id'] = $id;
$p_data['webname'] = $webname;
$p_data['domain'] = $domain;
$result = $this->HttpPostCookie($url,$p_data);
$data = json_decode($result,true);
return $data;
}
/**
* 删除网站域名
* @param [type] $id 网站ID
* @param [type] $webname 网站名
* @param [type] $domain 网站域名
* @param [type] $port 网站域名端口
*/
public function WebDelDomain($id,$webname,$domain,$port){
$url = $this->BT_PANEL.$this->config("WebDelDomain");
$p_data = $this->GetKeyData();
$p_data['id'] = $id;
$p_data['webname'] = $webname;
$p_data['domain'] = $domain;
$p_data['port'] = $port;
$result = $this->HttpPostCookie($url,$p_data);
$data = json_decode($result,true);
return $data;
}
/**
* 获取可选的预定义伪静态列表
* @param [type] $siteName 网站名
*/
public function GetRewriteList($siteName){
$url = $this->BT_PANEL.$this->config("GetRewriteList");
$p_data = $this->GetKeyData();
$p_data['siteName'] = $siteName;
$result = $this->HttpPostCookie($url,$p_data);
$data = json_decode($result,true);
return $data;
}
/**
* 获取预置伪静态规则内容(文件内容)
* @param [type] $path 规则名
* @param [type] $type 0->获取内置伪静态规则;1->获取当前站点伪静态规则
*/
public function GetFileBody($path,$type=0){
$url = $this->BT_PANEL.$this->config("GetFileBody");
$p_data = $this->GetKeyData();
// $path_dir = $type?'vhost/rewrite':'rewrite/nginx';
if ($type == 2) {
$path_dir = 'vhost/nginx';
} elseif ($type == 1) {
$path_dir = 'vhost/rewrite';
} else {
$path_dir = 'rewrite/nginx';
}
//获取当前站点伪静态规则
///www/server/panel/vhost/rewrite/user_hvVBT_1.test.com.conf
//获取内置伪静态规则
///www/server/panel/rewrite/nginx/EmpireCMS.conf
//保存伪静态规则到站点
///www/server/panel/vhost/rewrite/user_hvVBT_1.test.com.conf
///www/server/panel/rewrite/nginx/typecho.conf
$p_data['path'] = '/www/server/panel/'.$path_dir.'/'.$path.'.conf';
//var_dump($p_data['path']);
$result = $this->HttpPostCookie($url,$p_data);
$data = json_decode($result,true);
return $data;
}
/**
* 保存伪静态规则内容(保存文件内容)
* @param [type] $path 规则名
* @param [type] $data 规则内容
* @param string $encoding 规则编码强转utf-8
* @param number $type 0->系统默认路径;1->自定义全路径
*/
public function SaveFileBody($path,$data,$encoding='utf-8',$type=0){
$url = $this->BT_PANEL.$this->config("SaveFileBody");
if($type){
$path_dir = $path;
}else{
$path_dir = '/www/server/panel/vhost/rewrite/'.$path.'.conf';
}
$p_data = $this->GetKeyData();
$p_data['path'] = $path_dir;
$p_data['data'] = $data;
$p_data['encoding'] = $encoding;
$result = $this->HttpPostCookie($url,$p_data);
$data = json_decode($result,true);
return $data;
}
/**
* 设置密码访问网站
* @param [type] $id 网站ID
* @param [type] $username 用户名
* @param [type] $password 密码
*/
public function SetHasPwd($id,$username,$password){
$url = $this->BT_PANEL.$this->config("SetHasPwd");
$p_data = $this->GetKeyData();
$p_data['id'] = $id;
$p_data['username'] = $username;
$p_data['password'] = $password;
$result = $this->HttpPostCookie($url,$p_data);
$data = json_decode($result,true);
return $data;
}
/**
* 关闭密码访问网站
* @param [type] $id 网站ID
*/
public function CloseHasPwd($id){
$url = $this->BT_PANEL.$this->config("CloseHasPwd");
$p_data = $this->GetKeyData();
$p_data['id'] = $id;
$result = $this->HttpPostCookie($url,$p_data);
$data = json_decode($result,true);
return $data;
}
/**
* 获取网站日志
* @param [type] $site 网站名
*/
public function GetSiteLogs($site){
$url = $this->BT_PANEL.$this->config("GetSiteLogs");
$p_data = $this->GetKeyData();
$p_data['siteName'] = $site;
$result = $this->HttpPostCookie($url,$p_data);
$data = json_decode($result,true);
return $data;
}
/**
* 获取网站盗链状态及规则信息
* @param [type] $id 网站ID
* @param [type] $site 网站名
*/
public function GetSecurity($id,$site){
$url = $this->BT_PANEL.$this->config("GetSecurity");
$p_data = $this->GetKeyData();
$p_data['id'] = $id;
$p_data['name'] = $site;
$result = $this->HttpPostCookie($url,$p_data);
$data = json_decode($result,true);
return $data;
}
/**
* 设置网站盗链状态及规则信息
* @param [type] $id 网站ID
* @param [type] $site 网站名
* @param [type] $fix URL后缀
* @param [type] $domains 许可域名
* @param [type] $status 状态
*/
public function SetSecurity($id,$site,$fix,$domains,$status){
$url = $this->BT_PANEL.$this->config("SetSecurity");
$p_data = $this->GetKeyData();
$p_data['id'] = $id;
$p_data['name'] = $site;
$p_data['fix'] = $fix;
$p_data['domains'] = $domains;
$p_data['status'] = $status;
$result = $this->HttpPostCookie($url,$p_data);
$data = json_decode($result,true);
return $data;
}
/**
* 获取网站三项配置开关(防跨站、日志、密码访问)
* @param [type] $id 网站ID
* @param [type] $path 网站运行目录
*/
public function GetDirUserINI($id,$path){
$url = $this->BT_PANEL.$this->config("GetDirUserINI");
$p_data = $this->GetKeyData();
$p_data['id'] = $id;
$p_data['path'] = $path;
$result = $this->HttpPostCookie($url,$p_data);
$data = json_decode($result,true);
return $data;
}
/**
* 开启强制HTTPS
* @param [type] $site 网站域名(纯域名)
*/
public function HttpToHttps($site){
$url = $this->BT_PANEL.$this->config("HttpToHttps");
$p_data = $this->GetKeyData();
$p_data['siteName'] = $site;
$result = $this->HttpPostCookie($url,$p_data);
$data = json_decode($result,true);
return $data;
}
/**
* 关闭强制HTTPS
* @param [type] $site 域名(纯域名)
*/
public function CloseToHttps($site){
$url = $this->BT_PANEL.$this->config("CloseToHttps");
$p_data = $this->GetKeyData();
$p_data['siteName'] = $site;
$result = $this->HttpPostCookie($url,$p_data);
$data = json_decode($result,true);
return $data;
}
/**
* 设置SSL域名证书
* @param [type] $type 类型
* @param [type] $site 网站名
* @param [type] $key 证书key
* @param [type] $csr 证书PEM
* @return mixed
*/
public function SetSSL($type,$site,$key,$csr){
$url = $this->BT_PANEL.$this->config("SetSSL");
$p_data = $this->GetKeyData();
$p_data['type'] = $type;
$p_data['siteName'] = $site;
$p_data['key'] = $key;
$p_data['csr'] = $csr;
$result = $this->HttpPostCookie($url,$p_data);
return json_decode($result,true);
}
/*
* 关闭宝塔日志
*/
public function CloseLogsHandle(){
$url = $this->BT_PANEL.$this->config("CloseLogs");
$p_data = $this->GetKeyData();
$result = $this->HttpPostCookie($url,$p_data);
return json_decode($result,true);
}
/**
* 关闭SSL
* @param [type] $updateOf 修改状态码
* @param [type] $site 域名(纯域名)
*/
public function CloseSSLConf($updateOf,$site){
$url = $this->BT_PANEL.$this->config("CloseSSLConf");
$p_data = $this->GetKeyData();
$p_data['updateOf'] = $updateOf;
$p_data['siteName'] = $site;
$result = $this->HttpPostCookie($url,$p_data);
$data = json_decode($result,true);
return $data;
}
/**
* 获取SSL状态及证书信息
* @param [type] $site 域名(纯域名)
*/
public function GetSSL($site){
$url = $this->BT_PANEL.$this->config("GetSSL");
$p_data = $this->GetKeyData();
$p_data['siteName'] = $site;
$result = $this->HttpPostCookie($url,$p_data);
$data = json_decode($result,true);
return $data;
}
/**
* 获取网站默认文件
* @param [type] $id 网站ID
*/
public function WebGetIndex($id){
$url = $this->BT_PANEL.$this->config("WebGetIndex");
$p_data = $this->GetKeyData();
$p_data['id'] = $id;
$result = $this->HttpPostCookie($url,$p_data);
$data = json_decode($result,true);
return $data;
}
/**
* 设置网站默认文件
* @param [type] $id 网站ID
* @param [type] $index 内容
*/
public function WebSetIndex($id,$index){
$url = $this->BT_PANEL.$this->config("WebSetIndex");
$p_data = $this->GetKeyData();
$p_data['id'] = $id;
$p_data['Index'] = $index;
$result = $this->HttpPostCookie($url,$p_data);
$data = json_decode($result,true);
return $data;
}
/**
* 获取网站流量限制信息
* @param [type] $id [description]
*/
public function GetLimitNet($id){
$url = $this->BT_PANEL.$this->config("GetLimitNet");
$p_data = $this->GetKeyData();
$p_data['id'] = $id;
$result = $this->HttpPostCookie($url,$p_data);
$data = json_decode($result,true);
return $data;
}
/**
* 设置网站流量限制信息
* @param [type] $id 网站ID
* @param [type] $perserver 并发限制
* @param [type] $perip 单IP限制
* @param [type] $limit_rate 流量限制
*/
public function SetLimitNet($id,$perserver,$perip,$limit_rate){
$url = $this->BT_PANEL.$this->config("SetLimitNet");
$p_data = $this->GetKeyData();
$p_data['id'] = $id;
$p_data['perserver'] = $perserver;
$p_data['perip'] = $perip;
$p_data['limit_rate'] = $limit_rate;
$result = $this->HttpPostCookie($url,$p_data);
$data = json_decode($result,true);
return $data;
}
/**
* 关闭网站流量限制
* @param [type] $id 网站ID
*/
public function CloseLimitNet($id){
$url = $this->BT_PANEL.$this->config("CloseLimitNet");
$p_data = $this->GetKeyData();
$p_data['id'] = $id;
$result = $this->HttpPostCookie($url,$p_data);
$data = json_decode($result,true);
return $data;
}
/**
* 获取网站301重定向信息
* @param [type] $site 网站名
*/
public function Get301Status($site){
$url = $this->BT_PANEL.$this->config("Get301Status");
$p_data = $this->GetKeyData();
$p_data['siteName'] = $site;
$result = $this->HttpPostCookie($url,$p_data);
$data = json_decode($result,true);
return $data;
}
/**
* 设置网站301重定向信息
* @param [type] $site 网站名
* @param [type] $toDomain 目标Url
* @param [type] $srcDomain 来自Url
* @param [type] $type 类型
*/
public function Set301Status($site,$toDomain,$srcDomain,$type){
$url = $this->BT_PANEL.$this->config("Set301Status");
$p_data = $this->GetKeyData();
$p_data['siteName'] = $site;
$p_data['toDomain'] = $toDomain;
$p_data['srcDomain'] = $srcDomain;
$p_data['type'] = $type;
$result = $this->HttpPostCookie($url,$p_data);
$data = json_decode($result,true);
return $data;
}
/**
* 获取网站反代信息及状态
* @param [type] $site [description]
*/
public function GetProxyList($site){
$url = $this->BT_PANEL.$this->config("GetProxyList");
$p_data = $this->GetKeyData();
$p_data['sitename'] = $site;
$result = $this->HttpPostCookie($url,$p_data);
$data = json_decode($result,true);
return $data;
}
/**
* 添加网站反代信息
* @param [type] $cache 是否缓存
* @param [type] $proxyname 代理名称
* @param [type] $cachetime 缓存时长 /小时
* @param [type] $proxydir 代理目录
* @param [type] $proxysite 反代URL
* @param [type] $todomain 目标域名
* @param [type] $advanced 高级功能:开启代理目录
* @param [type] $sitename 网站名
* @param [type] $subfilter 文本替换json格式[{"sub1":"百度","sub2":"白底"},{"sub1":"","sub2":""}]
* @param [type] $type 开启或关闭 0关;1开
*/
public function CreateProxy($cache,$proxyname,$cachetime,$proxydir,$proxysite,$todomain,$advanced,$sitename,$subfilter,$type){
$url = $this->BT_PANEL.$this->config("CreateProxy");
$p_data = $this->GetKeyData();
$p_data['cache'] = $cache;
$p_data['proxyname'] = $proxyname;
$p_data['cachetime'] = $cachetime;
$p_data['proxydir'] = $proxydir;
$p_data['proxysite'] = $proxysite;
$p_data['todomain'] = $todomain;
$p_data['advanced'] = $advanced;
$p_data['sitename'] = $sitename;
$p_data['subfilter'] = $subfilter;
$p_data['type'] = $type;
$result = $this->HttpPostCookie($url,$p_data);
$data = json_decode($result,true);
return $data;
}
/**
* 添加网站反代信息
* @param [type] $cache 是否缓存
* @param [type] $proxyname 代理名称
* @param [type] $cachetime 缓存时长 /小时
* @param [type] $proxydir 代理目录
* @param [type] $proxysite 反代URL
* @param [type] $todomain 目标域名
* @param [type] $advanced 高级功能:开启代理目录
* @param [type] $sitename 网站名
* @param [type] $subfilter 文本替换json格式[{"sub1":"百度","sub2":"白底"},{"sub1":"","sub2":""}]
* @param [type] $type 开启或关闭 0关;1开
*/
public function ModifyProxy($cache,$proxyname,$cachetime,$proxydir,$proxysite,$todomain,$advanced,$sitename,$subfilter,$type){
$url = $this->BT_PANEL.$this->config("ModifyProxy");
$p_data = $this->GetKeyData();
$p_data['cache'] = $cache;
$p_data['proxyname'] = $proxyname;
$p_data['cachetime'] = $cachetime;
$p_data['proxydir'] = $proxydir;
$p_data['proxysite'] = $proxysite;
$p_data['todomain'] = $todomain;
$p_data['advanced'] = $advanced;
$p_data['sitename'] = $sitename;
$p_data['subfilter'] = $subfilter;
$p_data['type'] = $type;
$result = $this->HttpPostCookie($url,$p_data);
$data = json_decode($result,true);
return $data;
}
/**
* 获取网站域名绑定二级目录信息
* @param [type] $id 网站ID
*/
public function GetDirBinding($id){
$url = $this->BT_PANEL.$this->config("GetDirBinding");
$p_data = $this->GetKeyData();
$p_data['id'] = $id;
$result = $this->HttpPostCookie($url,$p_data);
$data = json_decode($result,true);
return $data;
}
/**
* 设置网站域名绑定二级目录
* @param [type] $id 网站ID
* @param [type] $domain 域名
* @param [type] $dirName 目录
*/
public function AddDirBinding($id,$domain,$dirName){
$url = $this->BT_PANEL.$this->config("AddDirBinding");
$p_data = $this->GetKeyData();
$p_data['id'] = $id;
$p_data['domain'] = $domain;
$p_data['dirName'] = $dirName;
$result = $this->HttpPostCookie($url,$p_data);
$data = json_decode($result,true);
return $data;
}
/**
* 删除网站域名绑定二级目录
* @param [type] $dirid 子目录ID
*/
public function DelDirBinding($dirid){
$url = $this->BT_PANEL.$this->config("DelDirBinding");
$p_data = $this->GetKeyData();
$p_data['id'] = $dirid;
$result = $this->HttpPostCookie($url,$p_data);
$data = json_decode($result,true);
return $data;
}
/**
* 获取网站子目录绑定伪静态信息
* @param [type] $dirid 子目录绑定ID
*/
public function GetDirRewrite($dirid,$type=0){
$url = $this->BT_PANEL.$this->config("GetDirRewrite");
$p_data = $this->GetKeyData();
$p_data['id'] = $dirid;
if($type){
$p_data['add'] = 1;
}
$result = $this->HttpPostCookie($url,$p_data);
$data = json_decode($result,true);
return $data;
}
/**
* 修改FTP账号密码
* @param [type] $id FTPID
* @param [type] $ftp_username 用户名
* @param [type] $new_password 密码
*/
public function SetUserPassword($id,$ftp_username,$new_password){
$url = $this->BT_PANEL.$this->config("SetUserPassword");
$p_data = $this->GetKeyData();
$p_data['id'] = $id;
$p_data['ftp_username'] = $ftp_username;
$p_data['new_password'] = $new_password;
$result = $this->HttpPostCookie($url,$p_data);
$data = json_decode($result,true);
return $data;
}
/**
* 修改SQL账号密码
* @param [type] $id SQLID
* @param [type] $ftp_username 用户名
* @param [type] $new_password 密码
*/
public function ResDatabasePass($id,$name,$password){
$url = $this->BT_PANEL.$this->config("ResDatabasePass");
$p_data = $this->GetKeyData();
$p_data['id'] = $id;
$p_data['name'] = $name;
$p_data['password'] = $password;
$result = $this->HttpPostCookie($url,$p_data);
$data = json_decode($result,true);
return $data;
}
/**
* 启用/禁用FTP
* @param [type] $id FTPID
* @param [type] $username 用户名
* @param [type] $status 状态 0->关闭;1->开启
*/
public function SetStatus($id,$username,$status){
$url = $this->BT_PANEL.$this->config("SetStatus");
$p_data = $this->GetKeyData();
$p_data['id'] = $id;
$p_data['username'] = $username;
$p_data['status'] = $status;
$result = $this->HttpPostCookie($url,$p_data);
$data = json_decode($result,true);
return $data;
}
/**
* 宝塔一键部署列表
* @param string $search 搜索关键词
* @return [type] [description]
*/
public function deployment($search=''){
if($search){
$url = $this->BT_PANEL.$this->config("deployment").'&search='.$search;
}else{
$url = $this->BT_PANEL.$this->config("deployment");
}
$p_data = $this->GetKeyData();
$result = $this->HttpPostCookie($url,$p_data);
$data = json_decode($result,true);
return $data;
}
/**
* 宝塔一键部署执行
* @param [type] $dname 部署程序名
* @param [type] $site_name 部署到网站名
* @param [type] $php_version PHP版本
*/
public function SetupPackage($dname,$site_name,$php_version){
$url = $this->BT_PANEL.$this->config("SetupPackage");
$p_data = $this->GetKeyData();
$p_data['dname'] = $dname;
$p_data['site_name'] = $site_name;
$p_data['php_version'] = $php_version;
$result = $this->HttpPostCookie($url,$p_data);
$data = json_decode($result,true);
return $data;
}
/**
* 设置文件权限
* @param $path
* @param $user
* @param $access
* @param $all
* @return mixed
*/
public function setFileAccess($path, $user, $access, $all) {
$url = $this->BT_PANEL.$this->config("SetFileAccess");
$p_data = $this->GetKeyData();
$p_data['user'] = $user;
$p_data['access'] = $access;
$p_data['all'] = $all;
$p_data['filename'] = $path;
$result = $this->HttpPostCookie($url,$p_data);
$data = json_decode($result,true);
return $data;
}
/**
* 获取队列
* @return mixed
*/
public function getProcessList()
{
$url = $this->BT_PANEL.$this->config("GetProcessList");
$p_data = $this->GetKeyData();
$result = $this->HttpPostCookie($url,$p_data);
$data = json_decode($result,true);
return $data;
}
/**
* 停止队列
* @param $program
* @param int $numprocs
* @return mixed
*/
public function stopProcess($program, $numprocs = 1)
{
$url = $this->BT_PANEL.$this->config("StopProcess");
$p_data = $this->GetKeyData();
$p_data['program'] = $program;
$p_data['numprocs'] = $numprocs;
$result = $this->HttpPostCookie($url,$p_data);
$data = json_decode($result,true);
return $data;
}
/**
* 修改队列
* @param $pjname
* @param $level
* @param $user
* @param $command
* @param $numprocs
* @param $ps
* @param $path
* @return mixed
* @author Akun
* @date 2024/08/01 17:55
*/
public function updateProcess($pjname,$level,$user,$command,$numprocs,$ps,$path)
{
$url = $this->BT_PANEL.$this->config("UpdateProcess");
$p_data = $this->GetKeyData();
$p_data['pjname'] = $pjname;
$p_data['level'] = $level;
$p_data['user'] = $user;
$p_data['command'] = $command;
$p_data['numprocs'] = $numprocs;
$p_data['ps'] = $ps;
$p_data['path'] = $path;
$result = $this->HttpPostCookie($url,$p_data);
$data = json_decode($result,true);
return $data;
}
/**
* 启动队列
* @param $program
* @param int $numprocs
* @return mixed
*/
public function startProcess($program, $numprocs = 1)
{
$url = $this->BT_PANEL.$this->config("StartProcess");
$p_data = $this->GetKeyData();
$p_data['program'] = $program;
$p_data['numprocs'] = $numprocs;
$result = $this->HttpPostCookie($url,$p_data);
$data = json_decode($result,true);
return $data;
}
/**
* 设置文件权限
* @param $path
* @return mixed
*/
public function DeleteFile($path) {
$url = $this->BT_PANEL.$this->config("DeleteFile");
$p_data = $this->GetKeyData();
$p_data['path'] = $path;
$result = $this->HttpPostCookie($url,$p_data);
$data = json_decode($result,true);
return $data;
}
/**
* 更新网站目录
* @param $site_id
* @param $path
* @return mixed
*/
public function SetPath($site_id, $path)
{
$url = $this->BT_PANEL.$this->config("SetPath");
$p_data = $this->GetKeyData();
$p_data['id'] = $site_id;
$p_data['path'] = $path;
$result = $this->HttpPostCookie($url,$p_data);
$data = json_decode($result,true);
return $data;
}
/**
* 更新运行目录
* @param $site_id
* @param $path
* @return mixed
*/
public function SetSiteRunPath($site_id, $path)
{
$url = $this->BT_PANEL.$this->config("SetSiteRunPath");
$p_data = $this->GetKeyData();
$p_data['id'] = $site_id;
$p_data['runPath'] = $path;
$result = $this->HttpPostCookie($url,$p_data);
$data = json_decode($result,true);
return $data;
}
/**
* 构造带有签名的关联数组
*/
public function GetKeyData(){
$now_time = time();
$p_data = array(
'request_token' => md5($now_time.''.md5($this->BT_KEY)),
'request_time' => $now_time
);
return $p_data;
}
/**
* 发起POST请求
* @param String $url 目标网填,带http://
* @param Array|String $data 欲提交的数据
* @return string
*/
private function HttpPostCookie($url, $data,$timeout = 300)
{
//定义cookie保存位置
$cookie_file='./'.md5($this->BT_PANEL).'.cookie';
if(!file_exists($cookie_file)){
$fp = fopen($cookie_file,'w+');
fclose($fp);
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$output = curl_exec($ch);
curl_close($ch);
return $output;
}
/**
* 加载宝塔数据接口
* @param [type] $str [description]
* @return [type] [description]
*/
private function config($str){
$config = config("bt");
//var_dump($config);
return $config[$str];
}
}
... ...
<?php
/**
* Created by PhpStorm.
* User: zhl
* Date: 2023/09/18
* Time: 20:56
*/
namespace App\Repositories;
use App\Repositories\Bt\Bt;
/**
* Class BtRepository
* @package App\Repositories
*/
class BtRepository
{
public $instance = [];
/**
* 获取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];
}
/**
* 获取配置前的文件内容
* @param $domain
* @return string|string[]
*/
public function getBeforeNginxConfStr($domain)
{
$bt = $this->getBtObject();
$conf = $bt->GetFileBody($domain, 2);
//如果有变量标识,去掉变量标识
if (FALSE !== strpos($conf['data'], 'map $domain_prefix')) {
$conf['data'] = str_replace($this->domainPrefixConf(), '', $conf['data']);
//去掉自定义配置
$conf['data'] = str_replace($this->customConf($domain), 'root ' . public_path() . ';', $conf['data']);
}
return $conf['data'];
}
/**
* 获取配置后的文件内容
* @param $domain
* @return mixed
*/
public function getAfterNginxConfStr($domain)
{
$bt = $this->getBtObject();
$conf = $bt->GetFileBody($domain, 2);
// 如果没有变量, 添加变量识别
if (FALSE === strpos($conf['data'], 'map $domain_prefix')) {
$conf['data'] = $this->domainPrefixConf() . $conf['data'];
// 替换自定义配置
$conf['data'] = str_replace('root ' . public_path() . ';', $this->customConf($domain), $conf['data']);
}
return $conf['data'];
}
/**
* 需要定制修改的配置
* @param $domain string
* @return string
*/
public function customConf($domain): string
{
$domain_arr = explode('.', $domain);
if ($domain_arr[0] == 'www') {
$string = ' root ' . public_path() . '; # 设置根目录
set $domain_prefix "";
if ($host ~* "^(?<domain_prefix>[^.]+)\.") {
set $domain_prefix $1;
}
location / {
root ' . public_path() . '/' . $domain . '; # 设置根目录
if ($is_prefix_in_string = 1) {
root ' . public_path() . '/' . $domain . '/$domain_prefix;
}
try_files $uri $uri/ /404/index.html =404;
}
location ~ ^/(api|search) {
root ' . public_path() . '; # 设置/api /search /.well-known的根目录
try_files $uri $uri/ /index.php?$query_string;
}
location ~ ^/(well-known) {
root ' . public_path() . ';
try_files $uri $uri/ /404/index.html =404;
}
error_page 403 /404/index.html;';
} else {
$string = ' root ' . public_path() . '; # 设置根目录
set $domain_prefix "";
if ($host ~* "^(?<domain_prefix>[^.]+)\.") {
set $domain_prefix $1;
}
if ($domain_prefix = ' . $domain_arr[0] . '){
set $is_prefix_in_string 0;
}
location / {
root ' . public_path() . '/' . $domain . '; # 设置根目录
if ($is_prefix_in_string = 1) {
root ' . public_path() . '/' . $domain . '/$domain_prefix;
}
try_files $uri $uri/ /404/index.html =404;
}
location ~ ^/(api|search) {
root ' . public_path() . '; # 设置/api /search /.well-known的根目录
try_files $uri $uri/ /index.php?$query_string;
}
location ~ ^/(well-known) {
root ' . public_path() . ';
try_files $uri $uri/ /404/index.html =404;
}
error_page 403 /404/index.html;';
}
return $string;
}
/**
* 配置变量
* @return string
*/
public function domainPrefixConf()
{
return 'map $domain_prefix $is_prefix_in_string {
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;
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;
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;
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;
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;
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;
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;
tk 1; uk 1; ur 1; ug 1; uz 1; vi 1; cy 1; xh 1; yi 1; yo 1; zu 1;
}';
}
}
... ...