import subprocess def _cmd(cmd: str) -> str: """ Safe shell command runner """ try: return subprocess.getoutput(cmd) except Exception as e: return f"ERROR: {e}" # ---------- SECURITY ---------- def security() -> str: out = _cmd("sshd -T | grep -i '^permitrootlogin'") if not out or "ERROR:" in out: return "šŸ” Security\n\nāš ļø permitrootlogin not found" if "no" in out.lower(): return "šŸ” Security\n\n🟢 Root login disabled" return "šŸ” Security\n\nšŸ”“ Root login ENABLED" # ---------- DISKS ---------- def list_disks() -> list[str]: out = _cmd("lsblk -dn -o NAME,TYPE") disks = [] for line in out.splitlines(): parts = line.split() if len(parts) != 2: continue name, typ = parts if typ == "disk": disks.append(f"/dev/{name}") return disks def smart_health(dev: str) -> str: out = _cmd(f"smartctl -H {dev}") if not out or "ERROR:" in out: return "āš ļø ERROR" if "PASSED" in out: return "🟢 PASSED" if "FAILED" in out: return "šŸ”“ FAILED" return "āš ļø UNKNOWN" def disk_temperature(dev: str) -> str: out = _cmd(f"smartctl -A {dev}") if not out or "ERROR:" in out: return "n/a" # NVMe for line in out.splitlines(): if "Temperature:" in line and "Celsius" in line: try: temp = int("".join(filter(str.isdigit, line))) return f"{temp}°C" except Exception: pass # SATA attributes for line in out.splitlines(): if line.strip().startswith(("194", "190")): parts = line.split() for p in parts[::-1]: if p.isdigit(): return f"{p}°C" return "n/a" def disks() -> str: disks = list_disks() if not disks: return "šŸ’½ Disks\n\nāŒ No disks found" lines = ["šŸ’½ Disks (SMART)\n"] for d in disks: health = smart_health(d) temp = disk_temperature(d) icon = "🟢" if temp != "n/a": t = int(temp.replace("°C", "")) if t > 50: icon = "šŸ”“" elif t > 40: icon = "🟔" lines.append(f"{icon} {d} — {health}, 🌔 {temp}") return "\n".join(lines)