// Dangerous Pi polkit rules
// Allows the dangerous-pi user to manage NetworkManager and specific systemd services
// without requiring sudo

polkit.addRule(function(action, subject) {
    // Allow NetworkManager control for dangerous-pi user
    if (action.id.indexOf("org.freedesktop.NetworkManager") === 0 &&
        subject.user === "__DANGEROUS_PI_USER__") {
        return polkit.Result.YES;
    }

    // Allow managing specific systemd services
    if (action.id === "org.freedesktop.systemd1.manage-units" &&
        subject.user === "__DANGEROUS_PI_USER__") {
        // Check if the unit is one of our allowed services
        var unit = action.lookup("unit");
        if (unit === "hostapd.service" ||
            unit === "dnsmasq.service" ||
            unit === "NetworkManager.service") {
            return polkit.Result.YES;
        }
    }
});
