|
|
@@ -34,38 +34,37 @@ class ProtectorGUI(tk.Tk):
|
|
|
def __init__(self, protector_runner=None):
|
|
|
super().__init__()
|
|
|
self.title("Protector GUI")
|
|
|
- self.geometry("700x500")
|
|
|
+ self.geometry("700x710")
|
|
|
|
|
|
self.cfg = load_cfg()
|
|
|
-
|
|
|
- # Config frame
|
|
|
- cf = tk.LabelFrame(self, text="Config")
|
|
|
+ # 配置区域
|
|
|
+ cf = tk.LabelFrame(self, text="配置")
|
|
|
cf.pack(fill="x", padx=8, pady=6)
|
|
|
|
|
|
- tk.Label(cf, text="base_url:").grid(row=0, column=0, sticky="w")
|
|
|
+ tk.Label(cf, text="设备地址 (base_url):").grid(row=0, column=0, sticky="w")
|
|
|
self.base_entry = tk.Entry(cf, width=60)
|
|
|
self.base_entry.grid(row=0, column=1, padx=4, pady=2)
|
|
|
|
|
|
- tk.Label(cf, text="conn_threshold:").grid(row=1, column=0, sticky="w")
|
|
|
+ tk.Label(cf, text="连接阈值:").grid(row=1, column=0, sticky="w")
|
|
|
self.th_entry = tk.Entry(cf, width=10)
|
|
|
self.th_entry.grid(row=1, column=1, sticky="w", padx=4, pady=2)
|
|
|
|
|
|
- tk.Label(cf, text="test_prefix:").grid(row=1, column=2, sticky="w", padx=(12,0))
|
|
|
+ tk.Label(cf, text="测试前缀:").grid(row=1, column=2, sticky="w", padx=(12,0))
|
|
|
self.test_prefix_entry = tk.Entry(cf, width=15)
|
|
|
self.test_prefix_entry.grid(row=1, column=3, sticky="w", padx=4, pady=2)
|
|
|
|
|
|
- tk.Label(cf, text="rule_ip_limit:").grid(row=2, column=2, sticky="w", padx=(12,0))
|
|
|
+ tk.Label(cf, text="规则 IP 上限:").grid(row=2, column=2, sticky="w", padx=(12,0))
|
|
|
self.rule_limit_entry = tk.Entry(cf, width=15)
|
|
|
self.rule_limit_entry.grid(row=2, column=3, sticky="w", padx=4, pady=2)
|
|
|
|
|
|
- tk.Label(cf, text="scan_interval (s):").grid(row=2, column=0, sticky="w")
|
|
|
+ tk.Label(cf, text="检测间隔 (秒):").grid(row=2, column=0, sticky="w")
|
|
|
self.interval_entry = tk.Entry(cf, width=10)
|
|
|
self.interval_entry.grid(row=2, column=1, sticky="w", padx=4, pady=2)
|
|
|
|
|
|
- tk.Button(cf, text="Save Config", command=self.save_config).grid(row=3, column=1, sticky="w", pady=6)
|
|
|
+ tk.Button(cf, text="保存配置", command=self.save_config).grid(row=3, column=1, sticky="w", pady=6)
|
|
|
|
|
|
- # Protector list frame
|
|
|
- lf = tk.LabelFrame(self, text="Protector List")
|
|
|
+ # 监控目标列表
|
|
|
+ lf = tk.LabelFrame(self, text="监控目标列表")
|
|
|
lf.pack(fill="both", expand=True, padx=8, pady=6)
|
|
|
|
|
|
self.listbox = tk.Listbox(lf)
|
|
|
@@ -75,19 +74,19 @@ class ProtectorGUI(tk.Tk):
|
|
|
right = tk.Frame(lf)
|
|
|
right.pack(side="right", fill="y", padx=4)
|
|
|
|
|
|
- tk.Label(right, text="target_ip:").pack(anchor="w")
|
|
|
+ tk.Label(right, text="目标 IP:").pack(anchor="w")
|
|
|
self.ip_entry = tk.Entry(right)
|
|
|
self.ip_entry.pack(fill="x")
|
|
|
- tk.Label(right, text="src_port:").pack(anchor="w")
|
|
|
+ tk.Label(right, text="源端口:").pack(anchor="w")
|
|
|
self.port_entry = tk.Entry(right)
|
|
|
self.port_entry.pack(fill="x")
|
|
|
- tk.Label(right, text="threshold (optional):").pack(anchor="w")
|
|
|
+ tk.Label(right, text="阈值(可选):").pack(anchor="w")
|
|
|
self.entry_threshold = tk.Entry(right)
|
|
|
self.entry_threshold.pack(fill="x")
|
|
|
|
|
|
- tk.Button(right, text="Add", command=self.add_entry).pack(fill="x", pady=4)
|
|
|
- tk.Button(right, text="Update", command=self.update_entry).pack(fill="x", pady=4)
|
|
|
- tk.Button(right, text="Remove", command=self.remove_entry).pack(fill="x", pady=4)
|
|
|
+ tk.Button(right, text="添加", command=self.add_entry).pack(fill="x", pady=4)
|
|
|
+ tk.Button(right, text="更新", command=self.update_entry).pack(fill="x", pady=4)
|
|
|
+ tk.Button(right, text="删除", command=self.remove_entry).pack(fill="x", pady=4)
|
|
|
|
|
|
self.load_values()
|
|
|
|
|
|
@@ -110,19 +109,19 @@ class ProtectorGUI(tk.Tk):
|
|
|
|
|
|
# Protector runner instance (optional) for countdown and triggering runs
|
|
|
self.protector_runner = protector_runner
|
|
|
- # countdown label
|
|
|
- self.countdown_var = tk.StringVar(value="Protector: idle")
|
|
|
+ # 倒计时标签
|
|
|
+ self.countdown_var = tk.StringVar(value="保护器:空闲")
|
|
|
self.countdown_label = tk.Label(self, textvariable=self.countdown_var)
|
|
|
self.countdown_label.pack(anchor="ne", padx=8, pady=4)
|
|
|
|
|
|
# Pause/Resume button
|
|
|
self.pause_btn = None
|
|
|
if self.protector_runner is not None:
|
|
|
- self.pause_btn = tk.Button(self, text="Pause", command=self._toggle_pause)
|
|
|
+ self.pause_btn = tk.Button(self, text="暂停", command=self._toggle_pause)
|
|
|
self.pause_btn.pack(anchor="ne", padx=8)
|
|
|
|
|
|
# Blocked IPs frame (uses advanced_acl to query current Test_ prefixed rules)
|
|
|
- bf = tk.LabelFrame(self, text="Blocked IPs (来自高级 ACL)")
|
|
|
+ bf = tk.LabelFrame(self, text="已阻断的 IP(来自高级 ACL)")
|
|
|
bf.pack(fill="both", expand=False, padx=8, pady=6)
|
|
|
|
|
|
self.block_listbox = tk.Listbox(bf, height=8)
|
|
|
@@ -132,11 +131,11 @@ class ProtectorGUI(tk.Tk):
|
|
|
block_right.pack(side="right", fill="y", padx=4)
|
|
|
|
|
|
tk.Button(block_right, text="刷新阻断列表", command=self.refresh_blocked_ips).pack(fill="x", pady=2)
|
|
|
- tk.Label(block_right, text="手动加入 IP:").pack(anchor="w", pady=(8,0))
|
|
|
+ tk.Label(block_right, text="手动加入 IP:").pack(anchor="w", pady=(8,0))
|
|
|
self.manual_ip_entry = tk.Entry(block_right)
|
|
|
self.manual_ip_entry.pack(fill="x")
|
|
|
tk.Button(block_right, text="加入阻断", command=self.manual_add_ip).pack(fill="x", pady=2)
|
|
|
- tk.Button(block_right, text="从列表删除选中", command=self.manual_remove_selected).pack(fill="x", pady=2)
|
|
|
+ tk.Button(block_right, text="从阻断列表删除选中项", command=self.manual_remove_selected).pack(fill="x", pady=2)
|
|
|
|
|
|
# Register on_run_complete callback only after GUI widgets exist
|
|
|
if self.protector_runner is not None:
|
|
|
@@ -358,11 +357,11 @@ class ProtectorGUI(tk.Tk):
|
|
|
try:
|
|
|
if not self.protector_runner:
|
|
|
return
|
|
|
- # Update label
|
|
|
- # compute seconds until next run based on protector_runner's schedule
|
|
|
+
|
|
|
+ # Update label: compute seconds until next run based on protector_runner's schedule
|
|
|
try:
|
|
|
if self.protector_runner.is_paused():
|
|
|
- self.countdown_var.set("Protector: paused")
|
|
|
+ self.countdown_var.set("保护器:已暂停")
|
|
|
else:
|
|
|
next_ts = self.protector_runner.get_next_run_time()
|
|
|
if next_ts is None:
|
|
|
@@ -372,7 +371,7 @@ class ProtectorGUI(tk.Tk):
|
|
|
secs = max(0, int(round(next_ts - time.time())))
|
|
|
self.countdown_var.set(f"下一次检测:{secs}s")
|
|
|
except Exception:
|
|
|
- self.countdown_var.set("Protector: running")
|
|
|
+ self.countdown_var.set("保护器:运行中")
|
|
|
|
|
|
# if protector hasn't been started yet, use internal countdown
|
|
|
try:
|
|
|
@@ -403,11 +402,6 @@ class ProtectorGUI(tk.Tk):
|
|
|
# ProtectorRunner.start() will perform an initial run, so do not
|
|
|
# explicitly call run_once() here to avoid double execution.
|
|
|
# reset internal countdown to interval after start
|
|
|
- try:
|
|
|
- self._countdown_seconds = int(self.protector_runner.get_interval())
|
|
|
- except Exception:
|
|
|
- self._countdown_seconds = self._initial_delay
|
|
|
- # reset countdown to configured interval
|
|
|
try:
|
|
|
self._countdown_seconds = int(self.protector_runner.get_interval())
|
|
|
except Exception:
|
|
|
@@ -415,12 +409,11 @@ class ProtectorGUI(tk.Tk):
|
|
|
# update pause button text
|
|
|
try:
|
|
|
if self.pause_btn:
|
|
|
- self.pause_btn.config(text=("Resume" if self.protector_runner.is_paused() else "Pause"))
|
|
|
+ self.pause_btn.config(text=("恢复" if self.protector_runner.is_paused() else "暂停"))
|
|
|
except Exception:
|
|
|
pass
|
|
|
else:
|
|
|
- # when protector already started, we won't decrement internal counter
|
|
|
- # keep internal counter but keep ticking for display purposes
|
|
|
+ # when protector not started, decrement the internal counter for display
|
|
|
if not started:
|
|
|
self._countdown_seconds -= 1
|
|
|
|
|
|
@@ -441,11 +434,11 @@ class ProtectorGUI(tk.Tk):
|
|
|
if self.protector_runner.is_paused():
|
|
|
self.protector_runner.resume()
|
|
|
if self.pause_btn:
|
|
|
- self.pause_btn.config(text="Pause")
|
|
|
+ self.pause_btn.config(text="暂停")
|
|
|
else:
|
|
|
self.protector_runner.pause()
|
|
|
if self.pause_btn:
|
|
|
- self.pause_btn.config(text="Resume")
|
|
|
+ self.pause_btn.config(text="恢复")
|
|
|
except Exception as e:
|
|
|
messagebox.showerror("错误", f"切换暂停/恢复失败: {e}")
|
|
|
|