Skip to content

Commit dab2c4a

Browse files
committed
Commit remaining workspace changes: update menus, docs, systemd units, and scripts
Include: updates to azctl menus and core, docs (en/ja), deploy config files (opencanary/vector), updated installers and sanity check, systemd unit adjustments, and removal of tmp/events.json. This commit stages previously unstaged edits so the branch fully reflects on-host changes.
1 parent f1b1050 commit dab2c4a

21 files changed

+375
-166
lines changed

azazel_pi/core/display/status_collector.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,12 +493,28 @@ def _count_alerts(self, recent_window_seconds: int = 300) -> tuple[int, int]:
493493

494494
def _is_service_active(self, service_name: str) -> bool:
495495
"""Check if a systemd service is active."""
496+
if service_name == "opencanary":
497+
return self._is_container_running("azazel_opencanary")
496498
try:
497499
result = run_cmd(["systemctl", "is-active", f"{service_name}.service"], capture_output=True, text=True, timeout=2, check=False)
498500
return (result.stdout or "").strip() == "active"
499501
except Exception:
500502
return False
501503

504+
def _is_container_running(self, container_name: str) -> bool:
505+
"""Check if a Docker container is running."""
506+
try:
507+
result = run_cmd(
508+
["docker", "inspect", "-f", "{{.State.Running}}", container_name],
509+
capture_output=True,
510+
text=True,
511+
timeout=2,
512+
check=False,
513+
)
514+
return result.returncode == 0 and (result.stdout or "").strip().lower() == "true"
515+
except Exception:
516+
return False
517+
502518
def _get_uptime(self) -> int:
503519
"""Get system uptime in seconds."""
504520
try:

azctl/menu/core.py

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -449,9 +449,9 @@ def _get_current_status(self) -> Dict[str, Any]:
449449
mode_display = mode.upper() if mode else "UNKNOWN"
450450

451451
# Count active services (simplified)
452-
services = ["suricata", "opencanary", "vector", "azctl"]
452+
systemd_services = ["suricata", "vector", "azctl"]
453453
services_active = 0
454-
for service in services:
454+
for service in systemd_services:
455455
try:
456456
result = run_cmd(
457457
["systemctl", "is-active", service],
@@ -462,11 +462,15 @@ def _get_current_status(self) -> Dict[str, Any]:
462462
except Exception:
463463
pass
464464

465+
services_total = len(systemd_services) + 1 # include OpenCanary container
466+
if self._is_container_running("azazel_opencanary"):
467+
services_active += 1
468+
465469
return {
466470
"mode": mode,
467471
"mode_display": mode_display if 'mode_display' in locals() else (mode.upper() if mode else "UNKNOWN"),
468472
"services_active": services_active,
469-
"services_total": len(services),
473+
"services_total": services_total,
470474
}
471475

472476
def _get_enhanced_status(self) -> Dict[str, Any]:
@@ -487,4 +491,18 @@ def _get_enhanced_status(self) -> Dict[str, Any]:
487491
"profile": profile,
488492
"wlan0_info": wlan0_info,
489493
"wlan1_info": wlan1_info,
490-
}
494+
}
495+
496+
def _is_container_running(self, container_name: str) -> bool:
497+
"""Check whether a Docker container is running."""
498+
try:
499+
result = run_cmd(
500+
["docker", "inspect", "-f", "{{.State.Running}}", container_name],
501+
capture_output=True,
502+
text=True,
503+
timeout=5,
504+
check=False,
505+
)
506+
return result.returncode == 0 and (result.stdout or "").strip().lower() == "true"
507+
except Exception:
508+
return False

azctl/menu/defense.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -214,12 +214,11 @@ def _view_status(self) -> None:
214214

215215
# Add services status if available
216216
try:
217-
import subprocess
218217
suricata_status = run_cmd(['systemctl', 'is-active', 'suricata'], capture_output=True, text=True).stdout.strip()
219-
canary_status = run_cmd(['systemctl', 'is-active', 'opencanary'], capture_output=True, text=True).stdout.strip()
218+
canary_running = self._is_container_running("azazel_opencanary")
220219

221-
services_info = f"Suricata: {'✅' if suricata_status == 'active' else '❌'} | Canary: {'✅' if canary_status == 'active' else '❌'}"
222-
except:
220+
services_info = f"Suricata: {'✅' if suricata_status == 'active' else '❌'} | Canary: {'✅' if canary_running else '❌'}"
221+
except Exception:
223222
services_info = "Status unknown"
224223

225224
info_table.add_row(
@@ -552,6 +551,20 @@ def _get_memory_usage(self) -> str:
552551
except Exception:
553552
return "N/A"
554553

554+
def _is_container_running(self, container_name: str) -> bool:
555+
"""Check whether a Docker container is running."""
556+
try:
557+
result = run_cmd(
558+
["docker", "inspect", "-f", "{{.State.Running}}", container_name],
559+
capture_output=True,
560+
text=True,
561+
timeout=5,
562+
check=False,
563+
)
564+
return result.returncode == 0 and (result.stdout or "").strip().lower() == "true"
565+
except Exception:
566+
return False
567+
555568
def _pause(self) -> None:
556569
"""Pause for user input."""
557-
Prompt.ask("\n[dim]Press Enter to continue[/dim]", default="", show_default=False)
570+
Prompt.ask("\n[dim]Press Enter to continue[/dim]", default="", show_default=False)

azctl/menu/emergency.py

Lines changed: 37 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -121,13 +121,18 @@ def _emergency_lockdown(self) -> None:
121121

122122
# Step 4: Stop services
123123
self.console.print("[blue]4. Stopping non-essential services...[/blue]")
124-
services_to_stop = ["vector", "opencanary"]
124+
services_to_stop = ["vector"]
125125
for service in services_to_stop:
126126
try:
127127
run_cmd(["sudo", "systemctl", "stop", f"{service}.service"], timeout=15)
128128
self.console.print(f"[green]✓ {service} stopped[/green]")
129129
except Exception:
130130
self.console.print(f"[yellow]! {service} stop failed[/yellow]")
131+
try:
132+
run_cmd(["sudo", "docker", "stop", "azazel_opencanary"], timeout=30)
133+
self.console.print("[green]✓ azazel_opencanary stopped[/green]")
134+
except Exception:
135+
self.console.print("[yellow]! azazel_opencanary stop failed[/yellow]")
131136

132137
self.console.print("\n[bold red]EMERGENCY LOCKDOWN COMPLETED[/bold red]")
133138
self.console.print("[yellow]System is now in maximum security lockdown mode.[/yellow]")
@@ -163,10 +168,10 @@ def _reset_network(self) -> None:
163168
run_cmd(["sudo", "systemctl", "stop", "wpa_supplicant"], timeout=10)
164169

165170
# Backup and reset wpa_supplicant.conf
166-
run_cmd([
167-
"sudo", "cp", "/etc/wpa_supplicant/wpa_supplicant.conf",
168-
f"/etc/wpa_supplicant/wpa_supplicant.conf.backup.{datetime.now().strftime('%Y%m%d_%H%M%S')}"
169-
], timeout=5)
171+
run_cmd([
172+
"sudo", "cp", "/etc/wpa_supplicant/wpa_supplicant.conf",
173+
f"/etc/wpa_supplicant/wpa_supplicant.conf.backup.{datetime.now().strftime('%Y%m%d_%H%M%S')}"
174+
], timeout=5)
170175

171176
# Create minimal wpa_supplicant.conf
172177
minimal_config = """ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
@@ -190,23 +195,23 @@ def _reset_network(self) -> None:
190195
# Reset network interfaces
191196
self.console.print("[blue]2. Resetting network interfaces...[/blue]")
192197
try:
193-
run_cmd(["sudo", "ip", "link", "set", self.wan_if, "down"], timeout=5)
194-
run_cmd(["sudo", "ip", "link", "set", self.wan_if, "up"], timeout=5)
195-
run_cmd(["sudo", "ip", "link", "set", self.lan_if, "down"], timeout=5)
196-
run_cmd(["sudo", "ip", "link", "set", self.lan_if, "up"], timeout=5)
198+
run_cmd(["sudo", "ip", "link", "set", self.wan_if, "down"], timeout=5)
199+
run_cmd(["sudo", "ip", "link", "set", self.wan_if, "up"], timeout=5)
200+
run_cmd(["sudo", "ip", "link", "set", self.lan_if, "down"], timeout=5)
201+
run_cmd(["sudo", "ip", "link", "set", self.lan_if, "up"], timeout=5)
197202
self.console.print("[green]✓ Network interfaces reset[/green]")
198203
except Exception as e:
199204
self.console.print(f"[red]✗ Interface reset failed: {e}[/red]")
200205

201206
# Restart network services
202207
self.console.print("[blue]3. Restarting network services...[/blue]")
203208
services = ["dhcpcd", "hostapd"]
204-
for service in services:
205-
try:
206-
run_cmd(["sudo", "systemctl", "restart", service], timeout=15)
207-
self.console.print(f"[green]✓ {service} restarted[/green]")
208-
except Exception:
209-
self.console.print(f"[yellow]! {service} restart failed[/yellow]")
209+
for service in services:
210+
try:
211+
run_cmd(["sudo", "systemctl", "restart", service], timeout=15)
212+
self.console.print(f"[green]✓ {service} restarted[/green]")
213+
except Exception:
214+
self.console.print(f"[yellow]! {service} restart failed[/yellow]")
210215

211216
self.console.print("\n[bold green]Network configuration reset completed[/bold green]")
212217

@@ -292,7 +297,7 @@ def _system_report(self) -> None:
292297
# Service status
293298
report.write("SERVICE STATUS\n")
294299
report.write("-" * 15 + "\n")
295-
services = ["azctl", "azctl-serve", "suricata", "opencanary", "vector"]
300+
services = ["azctl", "azctl-serve", "suricata", "vector"]
296301
for service in services:
297302
try:
298303
result = run_cmd(
@@ -303,6 +308,7 @@ def _system_report(self) -> None:
303308
report.write(f"{service}: {status}\n")
304309
except Exception:
305310
report.write(f"{service}: UNKNOWN\n")
311+
report.write(f"azazel_opencanary (Docker): {'ACTIVE' if self._is_container_running('azazel_opencanary') else 'INACTIVE'}\n")
306312

307313
report.write("\n")
308314

@@ -402,4 +408,18 @@ def _factory_reset(self) -> None:
402408

403409
def _pause(self) -> None:
404410
"""Pause for user input."""
405-
Prompt.ask("\n[dim]Press Enter to continue[/dim]", default="", show_default=False)
411+
Prompt.ask("\n[dim]Press Enter to continue[/dim]", default="", show_default=False)
412+
413+
def _is_container_running(self, container_name: str) -> bool:
414+
"""Check whether a Docker container is running."""
415+
try:
416+
result = run_cmd(
417+
["docker", "inspect", "-f", "{{.State.Running}}", container_name],
418+
capture_output=True,
419+
text=True,
420+
timeout=5,
421+
check=False,
422+
)
423+
return result.returncode == 0 and (result.stdout or "").strip().lower() == "true"
424+
except Exception:
425+
return False

0 commit comments

Comments
 (0)