feat: add downstream domain fix plugin
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
namespace addons\downstream_domain_fix;
|
||||
|
||||
use app\admin\lib\Plugin;
|
||||
|
||||
class DownstreamDomainFixPlugin extends Plugin
|
||||
{
|
||||
public $info = [
|
||||
'name' => 'DownstreamDomainFix',
|
||||
'title' => '下游推送域名修复',
|
||||
'description' => '批量修改指定客户名下服务器的下游推送域名',
|
||||
'status' => 1,
|
||||
'author' => '<a href=\"https://www.munianyun.com/\">沐念云</a>',
|
||||
'version' => '1.0',
|
||||
'module' => 'addons',
|
||||
'lang' => [
|
||||
'chinese' => '下游推送域名修复',
|
||||
'chinese_tw' => '下游推送域名修復',
|
||||
'english' => 'Downstream Domain Fix',
|
||||
],
|
||||
];
|
||||
|
||||
public function install()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function uninstall()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
namespace addons\downstream_domain_fix\controller;
|
||||
|
||||
class AdminIndexController extends \app\admin\controller\PluginAdminBaseController
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
$result = null;
|
||||
$uid = input('post.uid', 0, 'intval');
|
||||
$domain = input('post.domain', '', 'trim');
|
||||
|
||||
if ($this->request->isPost()) {
|
||||
$result = $this->fixDomain($uid, $domain);
|
||||
}
|
||||
|
||||
$this->assign('Title', '下游推送域名修复');
|
||||
$this->assign('uid', $uid ?: '');
|
||||
$this->assign('domain', $domain);
|
||||
$this->assign('result', $result);
|
||||
return $this->fetch('/index');
|
||||
}
|
||||
|
||||
private function fixDomain($uid, $domain)
|
||||
{
|
||||
$domain = rtrim($domain, '/');
|
||||
if ($uid <= 0) {
|
||||
return ['status' => 400, 'msg' => '客户ID不能为空', 'total' => 0, 'updated' => 0, 'skipped' => 0, 'list' => []];
|
||||
}
|
||||
if (!$this->isValidDomain($domain)) {
|
||||
return ['status' => 400, 'msg' => '推送域名必须以 http:// 或 https:// 开头', 'total' => 0, 'updated' => 0, 'skipped' => 0, 'list' => []];
|
||||
}
|
||||
|
||||
$hosts = \think\Db::name('host')
|
||||
->field('id,uid,domain,dedicatedip,domainstatus,stream_info')
|
||||
->where('uid', $uid)
|
||||
->where('stream_info', '<>', '')
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
$result = ['status' => 200, 'msg' => '处理完成', 'total' => count($hosts), 'updated' => 0, 'skipped' => 0, 'list' => []];
|
||||
|
||||
foreach ($hosts as $host) {
|
||||
$streamInfo = json_decode($host['stream_info'], true) ?: [];
|
||||
if (empty($streamInfo['downstream_url']) || empty($streamInfo['downstream_token']) || empty($streamInfo['downstream_id'])) {
|
||||
$result['skipped']++;
|
||||
$result['list'][] = $this->buildRow($host, '', $domain, '跳过:没有完整下游推送信息');
|
||||
continue;
|
||||
}
|
||||
|
||||
$oldDomain = rtrim($streamInfo['downstream_url'], '/');
|
||||
if ($oldDomain === $domain) {
|
||||
$result['skipped']++;
|
||||
$result['list'][] = $this->buildRow($host, $oldDomain, $domain, '跳过:域名未变化');
|
||||
continue;
|
||||
}
|
||||
|
||||
$streamInfo['downstream_url'] = $domain;
|
||||
\think\Db::name('host')->where('id', $host['id'])->update([
|
||||
'stream_info' => json_encode($streamInfo, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE),
|
||||
]);
|
||||
|
||||
$result['updated']++;
|
||||
$result['list'][] = $this->buildRow($host, $oldDomain, $domain, '已更新');
|
||||
}
|
||||
|
||||
if (function_exists('active_log')) {
|
||||
active_log(sprintf('插件批量修复下游推送域名,客户ID:%d,目标域名:%s,更新:%d,跳过:%d', $uid, $domain, $result['updated'], $result['skipped']));
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
private function isValidDomain($domain)
|
||||
{
|
||||
return strpos($domain, 'https://') === 0 || strpos($domain, 'http://') === 0;
|
||||
}
|
||||
|
||||
private function buildRow($host, $oldDomain, $newDomain, $status)
|
||||
{
|
||||
return [
|
||||
'id' => $host['id'],
|
||||
'domain' => $host['domain'],
|
||||
'dedicatedip' => $host['dedicatedip'],
|
||||
'domainstatus' => $host['domainstatus'],
|
||||
'old_domain' => $oldDomain,
|
||||
'new_domain' => $newDomain,
|
||||
'status' => $status,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
<?php
|
||||
return [];
|
||||
@@ -0,0 +1,2 @@
|
||||
<?php
|
||||
return [];
|
||||
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
return [
|
||||
[
|
||||
'name' => '修复推送域名',
|
||||
'url' => 'DownstreamDomainFix://AdminIndex/index',
|
||||
'custom' => 0,
|
||||
'lang' => [
|
||||
'chinese' => '修复推送域名',
|
||||
'chinese_tw' => '修復推送域名',
|
||||
'english' => 'Fix Domain',
|
||||
],
|
||||
],
|
||||
];
|
||||
@@ -0,0 +1,2 @@
|
||||
<?php
|
||||
return [];
|
||||
@@ -0,0 +1,219 @@
|
||||
<style>
|
||||
.ddf-page {
|
||||
background: linear-gradient(135deg, #f7fbff 0%, #eef5ff 100%);
|
||||
border-radius: 14px;
|
||||
padding: 22px;
|
||||
}
|
||||
.ddf-hero {
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
border-radius: 16px;
|
||||
padding: 28px 32px;
|
||||
color: #fff;
|
||||
background: linear-gradient(135deg, #1d4ed8 0%, #0f766e 100%);
|
||||
box-shadow: 0 14px 34px rgba(20, 82, 160, .18);
|
||||
margin-bottom: 22px;
|
||||
}
|
||||
.ddf-hero:after {
|
||||
content: "";
|
||||
position: absolute;
|
||||
width: 220px;
|
||||
height: 220px;
|
||||
right: -70px;
|
||||
top: -70px;
|
||||
border-radius: 50%;
|
||||
background: rgba(255, 255, 255, .14);
|
||||
}
|
||||
.ddf-hero h3 {
|
||||
margin: 0 0 10px;
|
||||
font-size: 24px;
|
||||
font-weight: 700;
|
||||
letter-spacing: .5px;
|
||||
}
|
||||
.ddf-hero p {
|
||||
margin: 0;
|
||||
max-width: 760px;
|
||||
line-height: 1.8;
|
||||
color: rgba(255, 255, 255, .9);
|
||||
}
|
||||
.ddf-form-card,
|
||||
.ddf-result-card {
|
||||
border: 1px solid #e6eef8;
|
||||
border-radius: 16px;
|
||||
background: #fff;
|
||||
box-shadow: 0 10px 28px rgba(15, 52, 96, .08);
|
||||
}
|
||||
.ddf-form-card {
|
||||
padding: 26px 28px;
|
||||
}
|
||||
.ddf-field label {
|
||||
color: #26384d;
|
||||
font-weight: 600;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
.ddf-field .form-control {
|
||||
height: 42px;
|
||||
border-color: #d9e4f2;
|
||||
border-radius: 10px;
|
||||
box-shadow: none;
|
||||
}
|
||||
.ddf-field .form-control:focus {
|
||||
border-color: #2563eb;
|
||||
box-shadow: 0 0 0 3px rgba(37, 99, 235, .12);
|
||||
}
|
||||
.ddf-submit {
|
||||
min-width: 150px;
|
||||
height: 42px;
|
||||
border: 0;
|
||||
border-radius: 10px;
|
||||
background: linear-gradient(135deg, #2563eb 0%, #0f766e 100%);
|
||||
box-shadow: 0 10px 20px rgba(37, 99, 235, .2);
|
||||
font-weight: 600;
|
||||
}
|
||||
.ddf-result-card {
|
||||
margin-top: 22px;
|
||||
padding: 18px;
|
||||
}
|
||||
.ddf-summary {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 12px;
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
.ddf-summary-item {
|
||||
min-width: 150px;
|
||||
border-radius: 12px;
|
||||
padding: 14px 16px;
|
||||
background: #f5f8fc;
|
||||
}
|
||||
.ddf-summary-item strong {
|
||||
display: block;
|
||||
font-size: 20px;
|
||||
color: #12304f;
|
||||
}
|
||||
.ddf-summary-item span {
|
||||
color: #6b7a90;
|
||||
}
|
||||
.ddf-table {
|
||||
margin-bottom: 0;
|
||||
border-radius: 12px;
|
||||
overflow: hidden;
|
||||
}
|
||||
.ddf-table thead th {
|
||||
border-bottom: 0;
|
||||
background: #f1f6fd;
|
||||
color: #34506c;
|
||||
font-weight: 700;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.ddf-table tbody td {
|
||||
vertical-align: middle;
|
||||
color: #34495e;
|
||||
}
|
||||
.ddf-badge {
|
||||
display: inline-block;
|
||||
border-radius: 999px;
|
||||
padding: 4px 10px;
|
||||
background: #e8f5ee;
|
||||
color: #17834f;
|
||||
font-size: 12px;
|
||||
font-weight: 600;
|
||||
}
|
||||
</style>
|
||||
|
||||
<section class="admin-main">
|
||||
<div class="container-fluid">
|
||||
<div class="page-container">
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<div class="card-title row align-items-center mb-3">
|
||||
<div style="padding:0 15px;font-size:20px;font-weight:700;">{$Title}</div>
|
||||
<div class="col-lg-8 col-md-12 col-sm-12">
|
||||
{foreach $PluginsAdminMenu as $v}
|
||||
{if $v['custom']}
|
||||
<span class="ml-2"><a class="h5" href="{$v.url}" target="_blank">{$v.name}</a></span>
|
||||
{else/}
|
||||
<span class="ml-2"><a class="h5" href="{$v.url}">{$v.name}</a></span>
|
||||
{/if}
|
||||
{/foreach}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="ddf-page">
|
||||
<div class="ddf-hero">
|
||||
<h3>代理推送地址批量修复</h3>
|
||||
<p>用于你站点名下代理用户的地址变更后,可通过本插件直接批量更换推送代理新地址。</p>
|
||||
</div>
|
||||
|
||||
<form method="post" action="{:shd_addon_url('DownstreamDomainFix://AdminIndex/index')}" onsubmit="return confirm('确认批量修改该客户名下服务器的下游推送域名?');">
|
||||
<div class="ddf-form-card">
|
||||
<div class="row align-items-end">
|
||||
<div class="col-lg-4 col-md-5 col-12">
|
||||
<div class="form-group ddf-field mb-lg-0">
|
||||
<label class="require">客户ID</label>
|
||||
<input type="number" class="form-control" name="uid" value="{$uid}" placeholder="例如:810" required>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-lg-6 col-md-7 col-12">
|
||||
<div class="form-group ddf-field mb-lg-0">
|
||||
<label class="require">指定推送域名</label>
|
||||
<input type="text" class="form-control" name="domain" value="{$domain}" placeholder="例如:https://www.ysyplat.cn" required>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-lg-2 col-12 mt-3 mt-lg-0">
|
||||
<button type="submit" class="btn btn-primary ddf-submit">开始修复</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
{if $result}
|
||||
<div class="ddf-result-card">
|
||||
<div class="alert {if $result.status == 200}alert-success{else/}alert-danger{/if}">
|
||||
{$result.msg};匹配 {$result.total} 台,更新 {$result.updated} 台,跳过 {$result.skipped} 台。
|
||||
</div>
|
||||
|
||||
<div class="ddf-summary">
|
||||
<div class="ddf-summary-item"><strong>{$result.total}</strong><span>匹配服务器</span></div>
|
||||
<div class="ddf-summary-item"><strong>{$result.updated}</strong><span>成功更新</span></div>
|
||||
<div class="ddf-summary-item"><strong>{$result.skipped}</strong><span>跳过数量</span></div>
|
||||
</div>
|
||||
|
||||
{if $result.list}
|
||||
<div class="table-body table-responsive">
|
||||
<table class="table table-bordered table-hover ddf-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Host ID</th>
|
||||
<th>主机名</th>
|
||||
<th>主IP</th>
|
||||
<th>状态</th>
|
||||
<th>原推送域名</th>
|
||||
<th>新推送域名</th>
|
||||
<th>处理结果</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{foreach $result.list as $row}
|
||||
<tr>
|
||||
<td>{$row.id}</td>
|
||||
<td>{$row.domain}</td>
|
||||
<td>{$row.dedicatedip}</td>
|
||||
<td>{$row.domainstatus}</td>
|
||||
<td>{$row.old_domain}</td>
|
||||
<td>{$row.new_domain}</td>
|
||||
<td><span class="ddf-badge">{$row.status}</span></td>
|
||||
</tr>
|
||||
{/foreach}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
Reference in New Issue
Block a user