更新 main.go

This commit is contained in:
XOF
2025-12-31 14:37:35 +08:00
parent e2da4ebea7
commit b6ad3dcbb8

71
main.go
View File

@@ -520,79 +520,79 @@ func handleRoot(w http.ResponseWriter, r *http.Request) {
<h2>📥 下载地址</h2>
<div class="download-link">
<strong>IPv4 路由列表</strong>
<a href="%s/chnroute.rsc" download>%s/chnroute.rsc</a>
<a href="%[1]s/chnroute.rsc" download>%[1]s/chnroute.rsc</a>
</div>
<div class="download-link">
<strong>IPv6 路由列表</strong>
<a href="%s/chnroute_v6.rsc" download>%s/chnroute_v6.rsc</a>
<a href="%[1]s/chnroute_v6.rsc" download>%[1]s/chnroute_v6.rsc</a>
</div>
</div>
<!-- 使用方法 -->
<div class="card">
<h2>🔧 RouterOS 使用方法%s</h2>
<h2>🔧 RouterOS 使用方法%[2]s</h2>
<div class="protocol-note">
%s
%[3]s
</div>
<h3>一键导入脚本</h3>
<div class="code-container">
<button class="copy-btn" onclick="copyCode('code1')">📋 复制</button>
<pre id="code1"># SSH 登录 RouterOS 后执行
/tool fetch url="%s/chnroute.rsc" mode=%s
<pre id="code1"># SSH login to RouterOS and execute
/tool fetch url="%[1]s/chnroute.rsc" mode=%[4]s
/import chnroute.rsc
# 验证导入
# Verify import
/ip firewall address-list print count-only where list=chnroute</pre>
</div>
<h3 style="margin-top: 30px;">自动更新脚本(推荐)</h3>
<div class="code-container">
<button class="copy-btn" onclick="copyCode('code2')">📋 复制</button>
<pre id="code2"># 创建更新脚本
<pre id="code2"># Create update script
/system script add name=update-chnroute source={
:log info "开始更新 CHNRoute"
:log info "Start updating CHNRoute"
/file remove [find name="chnroute.rsc"]
/tool fetch url="%s/chnroute.rsc" mode=%s
/tool fetch url="%[1]s/chnroute.rsc" mode=%[4]s
:delay 3s
/ip firewall address-list remove [find list=chnroute]
/import chnroute.rsc
:local count [/ip firewall address-list print count-only where list=chnroute]
:log info ("CHNRoute 更新完成,共 " . $count . " ")
:log info ("CHNRoute updated: " . \$count . " entries")
}
# 设置每周自动执行每周日凌晨3点
# Set weekly auto-run (every Sunday at 3:00 AM)
/system scheduler add name=auto-update-chnroute interval=7d00:00:00 on-event="/system script run update-chnroute" start-time=03:00:00</pre>
</div>
<h3 style="margin-top: 30px;">IPv6 导入脚本</h3>
<div class="code-container">
<button class="copy-btn" onclick="copyCode('code3')">📋 复制</button>
<pre id="code3"># IPv6 路由列表导入
/tool fetch url="%s/chnroute_v6.rsc" mode=%s
<pre id="code3"># Import IPv6 route list
/tool fetch url="%[1]s/chnroute_v6.rsc" mode=%[4]s
/import chnroute_v6.rsc
# 验证导入
# Verify import
/ipv6 firewall address-list print count-only where list=chnroute6</pre>
</div>
<h3 style="margin-top: 30px;">IPv6 自动更新脚本</h3>
<div class="code-container">
<button class="copy-btn" onclick="copyCode('code4')">📋 复制</button>
<pre id="code4"># 创建 IPv6 更新脚本
<h3 style="margin-top: 30px;">IPv6 自动更新脚本</h3>
<div class="code-container">
<button class="copy-btn" onclick="copyCode('code4')">📋 复制</button>
<pre id="code4"># Create IPv6 update script
/system script add name=update-chnroute-v6 source={
:log info "开始更新 CHNRoute IPv6"
:log info "Start updating CHNRoute IPv6"
/file remove [find name="chnroute_v6.rsc"]
/tool fetch url="%s/chnroute_v6.rsc" mode=%s
/tool fetch url="%[1]s/chnroute_v6.rsc" mode=%[4]s
:delay 3s
/ipv6 firewall address-list remove [find list=chnroute6]
/import chnroute_v6.rsc
:local count [/ipv6 firewall address-list print count-only where list=chnroute6]
:log info ("CHNRoute IPv6 更新完成,共 " . $count . " ")
:log info ("CHNRoute IPv6 updated: " . \$count . " entries")
}
# 设置每周日凌晨3点自动执行
# Set weekly auto-run (every Sunday at 3:00 AM)
/system scheduler add name=auto-update-chnroute-v6 interval=7d00:00:00 on-event="/system script run update-chnroute-v6" start-time=03:00:00</pre>
</div>
</div>
@@ -602,14 +602,14 @@ func handleRoot(w http.ResponseWriter, r *http.Request) {
<h2>📊 服务状态<span class="badge badge-success">运行中</span></h2>
<div class="status-grid">
<div class="status-item">
<div class="status-icon">%s</div>
<div class="status-icon">%[5]s</div>
<div class="status-label">IPv4 缓存</div>
<div class="status-time">已缓存 %v</div>
<div class="status-time">已缓存 %[6]v</div>
</div>
<div class="status-item">
<div class="status-icon">%s</div>
<div class="status-icon">%[7]s</div>
<div class="status-label">IPv6 缓存</div>
<div class="status-time">已缓存 %v</div>
<div class="status-time">已缓存 %[8]v</div>
</div>
</div>
</div>
@@ -650,15 +650,14 @@ func handleRoot(w http.ResponseWriter, r *http.Request) {
</script>
</body>
</html>`,
baseURL, baseURL, // 1-2: 下载地址 IPv4 (href + 显示文本)
baseURL, baseURL, // 3-4: 下载地址 IPv6 (href + 显示文本)
protocolBadge, // 5: 协议徽章
protocolNote, // 6: 协议提示
baseURL, fetchMode, // 7-8: 一键导入 (url + mode)
baseURL, fetchMode, // 9-10: 自动更新 (url + mode)
baseURL, fetchMode, // 11-12: IPv6 导入 (url + mode)
statusIPv4, cacheAgeIPv4, // 13-14: IPv4 状态图标 + 缓存时间
statusIPv6, cacheAgeIPv6) // 15-16: IPv6 状态图标 + 缓存时间
baseURL, // %[1]s - 重复使用多次
protocolBadge, // %[2]s - 协议徽章
protocolNote, // %[3]s - 协议提示
fetchMode, // %[4]s - 重复使用多次
statusIPv4, // %[5]s - IPv4 状态
cacheAgeIPv4, // %[6]v - IPv4 缓存时间
statusIPv6, // %[7]s - IPv6 状态
cacheAgeIPv6) // %[8]v - IPv6 缓存时间
w.Header().Set("Content-Type", "text/html; charset=utf-8")
w.Write([]byte(html))