Turn the rows that only reported things into controls
Autostart entries showed "Enabled" or "Disabled" as plain text. The row did toggle on click the whole time, so this is an affordance rather than a missing capability -- but a control that reads as static text is one nobody knows they have. It is a switch now, with removal alongside it behind a confirmation: disabling writes Hidden=true and can be undone, deleting the file cannot. remove-autostart is confined to files the autostart directory owns. It resolves the path and compares the parent, so a name like "../../.bashrc" cannot escape, and it refuses symlinks rather than following them -- deleting through one would remove whatever it points at, which is somewhere else and not ours. Each refusal was tested against a fixture directory, including a symlink aimed at /etc/hostname, which survived. Sharing says who is signed in from another machine: user, origin and since when. An empty list on this machine proves nothing, so the parser was checked against sample `who` output -- it picks out remote sessions and leaves out local seats and the :0 display, which would otherwise report the person at the keyboard as a remote login. Media sharing was "Available" and nothing else: rygel installed, rygel.service disabled, no way to change that from here. It is a switch now, and it says what it does before you touch it rather than afterwards -- turning it on publishes media folders to every device on the network with no password in front of them. Per-application camera and microphone permissions come from the portal's permission store, which is where an application that asked through the portal has its answer recorded. The page states the limit plainly instead of implying a protection that does not exist: a program installed outside the portal opens the device directly and nothing here stands in its way. Anything that is not an explicit "yes" is treated as withheld, because guessing generously about a camera is the wrong way to be wrong. The first version of the write silently did nothing -- SetPermission takes an array of strings and was being handed one string -- and the test did not notice, because it discarded the helper's output and only checked that state was unchanged afterwards, which was trivially true. The contract now requires the value to move, and was proven to fail by putting that exact bug back. Claude-Session: https://claude.ai/code/session_01BRvzt4H8XXLPVH5MyYdk9L
This commit is contained in:
@@ -98,6 +98,62 @@ def remote_desktop() -> dict:
|
||||
return state
|
||||
|
||||
|
||||
def active_logins() -> list[dict[str, str]]:
|
||||
"""Who is signed in from another machine right now.
|
||||
|
||||
Read from `who`, which names the user, when they arrived, and where from.
|
||||
Only sessions with an origin are reported: a local seat has none, and
|
||||
listing the person sitting at the keyboard as a remote login would be
|
||||
alarming and wrong.
|
||||
"""
|
||||
result = run(["who"])
|
||||
if result.returncode != 0:
|
||||
return []
|
||||
|
||||
sessions: list[dict[str, str]] = []
|
||||
for line in result.stdout.splitlines():
|
||||
match = re.match(r"^(\S+)\s+(\S+)\s+(.+?)\s+\((.+)\)\s*$", line)
|
||||
if not match:
|
||||
continue
|
||||
user, line_name, when, origin = match.groups()
|
||||
# X displays appear in the same parenthesised field as a hostname.
|
||||
if origin.startswith(":") or origin in ("localhost", ""):
|
||||
continue
|
||||
sessions.append({
|
||||
"user": user,
|
||||
"line": line_name,
|
||||
"since": when.strip(),
|
||||
"from": origin,
|
||||
})
|
||||
return sessions
|
||||
|
||||
|
||||
def media_sharing() -> dict:
|
||||
"""Rygel, which serves media to devices on the network over DLNA.
|
||||
|
||||
Reported as a running state rather than just "installed", because installed
|
||||
and off is the normal case and is not the same thing as sharing. Turning it
|
||||
on publishes media directories to every device on the network, which is why
|
||||
the page says so next to the switch.
|
||||
"""
|
||||
if not shutil.which("rygel"):
|
||||
return {"installed": False, "active": False, "enabled": False, "package": "rygel"}
|
||||
state = unit_state("rygel.service", user=True)
|
||||
state["installed"] = True
|
||||
state["package"] = "rygel"
|
||||
return state
|
||||
|
||||
|
||||
def set_media_sharing(enabled: bool) -> None:
|
||||
if not shutil.which("rygel"):
|
||||
raise BoundaryError("Rygel is not installed.")
|
||||
verb = "enable" if enabled else "disable"
|
||||
result = run(["systemctl", "--user", verb, "--now", "rygel.service"])
|
||||
if result.returncode != 0:
|
||||
detail = (result.stderr or "").strip().splitlines()
|
||||
raise BoundaryError(detail[-1] if detail else "Media sharing could not be changed.")
|
||||
|
||||
|
||||
def snapshot() -> dict:
|
||||
static_name = run(["hostnamectl", "--static"]).stdout.strip()
|
||||
pretty_name = run(["hostnamectl", "--pretty"]).stdout.strip()
|
||||
@@ -106,6 +162,7 @@ def snapshot() -> dict:
|
||||
login["port"] = ssh_setting("Port") or "22"
|
||||
login["passwordAuthentication"] = ssh_setting("PasswordAuthentication")
|
||||
login["rootLogin"] = ssh_setting("PermitRootLogin")
|
||||
login["sessions"] = active_logins()
|
||||
|
||||
return {
|
||||
"hostname": static_name,
|
||||
@@ -115,7 +172,7 @@ def snapshot() -> dict:
|
||||
# Reported as absent rather than offered as a switch that would do
|
||||
# nothing. Installing software is not this page's job.
|
||||
"fileSharing": {"installed": bool(shutil.which("smbd")), "package": "samba"},
|
||||
"mediaSharing": {"installed": bool(shutil.which("rygel")), "package": "rygel"},
|
||||
"mediaSharing": media_sharing(),
|
||||
"error": "",
|
||||
}
|
||||
|
||||
@@ -187,7 +244,9 @@ def main(arguments: list[str]) -> int:
|
||||
if arguments == ["snapshot"]:
|
||||
print(json.dumps(snapshot(), separators=(",", ":")))
|
||||
return 0
|
||||
if len(arguments) == 2 and arguments[0] == "set-remote-login":
|
||||
if len(arguments) == 2 and arguments[0] == "set-media-sharing":
|
||||
set_media_sharing(arguments[1] == "true")
|
||||
elif len(arguments) == 2 and arguments[0] == "set-remote-login":
|
||||
set_remote_login(arguments[1] == "true")
|
||||
elif len(arguments) == 2 and arguments[0] == "set-remote-desktop":
|
||||
set_remote_desktop(arguments[1] == "true")
|
||||
|
||||
Reference in New Issue
Block a user