Heray-Was-Here
Server : Apache
System : Linux vps103298.mylogin.co 4.18.0-513.11.1.el8_9.x86_64 #1 SMP Wed Jan 17 02:00:40 EST 2024 x86_64
User : calvet ( 273824)
PHP Version : 7.4.33
Disable Function : NONE
Directory :  /usr/share/fusioninventory/lib/FusionInventory/Agent/Task/Inventory/MacOS/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //usr/share/fusioninventory/lib/FusionInventory/Agent/Task/Inventory/MacOS/Firewall.pm
package FusionInventory::Agent::Task::Inventory::MacOS::Firewall;

use strict;
use warnings;

use parent 'FusionInventory::Agent::Task::Inventory::Module';

use FusionInventory::Agent::Tools;
use FusionInventory::Agent::Tools::Constants;

sub isEnabled {
    my (%params) = @_;
    return 0 if $params{no_category}->{firewall};
    return canRun('defaults') && canRun('launchctl');
}

sub doInventory {
    my (%params) = @_;

    my $inventory = $params{inventory};
    my $logger = $params{logger};

    my $firewallStatus = _getFirewallStatus(
        logger => $logger
    );
    $inventory->addEntry(
        section => 'FIREWALL',
        entry   => {
            STATUS => $firewallStatus
        }
    );

}

sub _getFirewallStatus {
    my (%params) = @_;

    return STATUS_OFF unless _checkFirewallService(%params);

    my $status = getFirstMatch(
        command => 'defaults read /Library/Preferences/com.apple.alf globalstate',
        pattern => qr/^(\d)$/,
        %params
    );
    if ($status && $status eq '1') {
        $status = STATUS_ON;
    } else {
        $status = STATUS_OFF;
    }

    return $status;
}

sub _checkFirewallService {
    my (%params) = @_;

    my $pid = _getFirewallServicePID(
        file => $params{pidFile} || undef
    );
    return unless $pid;

    return _checkRunning(
        pid => $pid,
        file => $params{runningFile} || undef
    );
}

sub _getFirewallServicePID {
    my (%params) = @_;

    return getFirstMatch(
        command => 'launchctl list',
        pattern => qr/^(\d+)\s+\S+\s+com\.apple\.alf$/,
        %params
    );
}

sub _checkRunning {
    my (%params) = @_;
    return unless $params{pid};

    return getFirstMatch(
            command => 'sudo launchctl procinfo ' . $params{pid},
            pattern => qr/^\s*state = running\s*$/,
            %params
        ) ?
        1 :
        0;
}

1;

Hry