Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get Module Firewall in sideright.js #1029

Open
haoireal opened this issue Dec 29, 2024 · 1 comment
Open

Get Module Firewall in sideright.js #1029

haoireal opened this issue Dec 29, 2024 · 1 comment
Labels
FEATURE Feature advice/request

Comments

@haoireal
Copy link

I am trying to write a module about firewalld toggle in quicktoggles.js
when I import it in sideright.js it makes ags error. I need help.

// cCustom moduel for firewalld
export const ModuleFirewall = (props = {}) =>
  Widget.Button({
    className: "txt-small sidebar-iconbutton",
    tooltipText: "FirewallD | Right-click to configure",
    onClicked: () => {
      execAsync("systemctl is-active firewalld")
        .then((status) => {
          if (status.trim() === "active") {
            exec("sudo systemctl stop firewalld").catch(print);
          } else {
            exec("sudo systemctl start firewalld").catch(print);
          }
        })
        .catch((error) => {
          print(`Error checking firewalld status: ${error}`);
        });
    },
    onSecondaryClickRelease: () => {
      execAsync(["bash", "-c", "firewalld-config-tool"]).catch(print);
      closeEverything();
    },
    child: FirewallIndicator(),
    setup: (self) => {
      setupCursorHover(self);

      // Cập nhật trạng thái của firewalld
      const updateFirewallStatus = () => {
        execAsync("systemctl is-active firewalld")
          .then((status) => {
            const isActive = status.trim() === "active";
            self.toggleClassName("sidebar-button-active", isActive);
            self.tooltipText = isActive
              ? "FirewallD Active"
              : "FirewallD Inactive";
          })
          .catch((error) => {
            print(`Error updating firewalld status: ${error}`);
          });
      };

      updateFirewallStatus();
      setInterval(updateFirewallStatus, 5000);
    },
    ...props,
  });
@haoireal
Copy link
Author

I just tweaked the source code a bit and it works. But only when the firewall is turned off. If you want to turn it on, you can't

// cCustom moduel for firewalld
export const ModuleFirewall = (props = {}) =>
  Widget.Button({
    className: "txt-small sidebar-iconbutton",
    tooltipText: "Firewalld",
    onClicked: (self) => {
      execAsync("systemctl is-active firewalld")
        .then((status) => {
          const isActive = status.trim() === "active";
          const command = isActive
            ? "pkexec systemctl stop firewalld"
            : "sudo systemctl start firewalld";
          execAsync(command)
            .then(() => {
              self.toggleClassName("sidebar-button-active", !isActive);
            })
            .catch(print);
        })
        .catch(print);
    },
    child: MaterialIcon("security", "norm"),
    setup: (self) => {
      execAsync("systemctl is-active firewalld")
        .then((status) => {
          const isActive = status.trim() === "active";
          self.toggleClassName("sidebar-button-active", isActive);
        })
        .catch(print);
    },
    ...props,
  });
// End

@clsty clsty added the FEATURE Feature advice/request label Feb 9, 2025
@clsty clsty changed the title [Feature] Get Module Firewall in sideright.js Get Module Firewall in sideright.js Feb 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
FEATURE Feature advice/request
Projects
None yet
Development

No branches or pull requests

2 participants