Exemplo n.º 1
0
function xrun()
{
    $unix = new unix();
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__);
    $pid = $unix->get_pid_from_file($pidfile);
    if ($unix->process_exists($pid, basename(__FILE__))) {
        echo "Starting......: " . date("H:i:s") . " [META]: Already executed {$pid}\n";
        return;
    }
    if ($unix->SQUID_ENABLED() == 0) {
        echo "Starting......: " . date("H:i:s") . " [META]: Squid Not installed or disabled\n";
        return;
    }
    $myuuid = $unix->GetUniqueID();
    echo "Starting......: " . date("H:i:s") . " [META]: My UUID = {$myuuid}\n";
    $md5_org = md5_file("/etc/squid3/acls_center_meta.conf");
    $q = new mysql();
    $results = $q->QUERY_SQL("SELECT gpid FROM metagroups_link WHERE uuid='{$myuuid}'", "metaclient");
    $acls = new squid_acls();
    $acls->Build_Acls(false, true);
    if (count($acls->acls_array) == 0) {
        @file_put_contents("/etc/squid3/acls_center_meta.conf", "\n");
        @chown("/etc/squid3/acls_center_meta.conf", "squid");
        @chgrp("/etc/squid3/acls_center_meta.conf", "squid");
        $md5_new = md5_file("/etc/squid3/acls_center_meta.conf");
        if ($md5_new != $md5_org) {
            $squidbin = $unix->LOCATE_SQUID_BIN();
            squid_admin_mysql(1, "Reload proxy service for Meta acls", null, __FILE__, __LINE__);
            shell_exec("{$squidbin} -f /etc/squid3/squid.conf -k reconfigure");
        }
        return;
    }
    $all_acls = @implode("\n", $acls->acls_array);
    $php = $unix->LOCATE_PHP5_BIN();
    $ACLS = array();
    while ($ligne = mysql_fetch_assoc($results)) {
        echo "{$myuuid} is a member of group id {$ligne["gpid"]}\n";
        $ACLS = buildacls_fromgroup($ligne["gpid"], $ACLS);
    }
    $q = new mysql();
    $results = $q->QUERY_SQL("SELECT * FROM meta_webfilters_acls WHERE metauuid='{$myuuid}'", "metaclient");
    $aclsGroups = new squid_acls_groups();
    $aclsGroups->AsMeta = true;
    while ($ligne = mysql_fetch_assoc($results)) {
        $aclname = $ligne["aclname"];
        $httpaccess = $ligne["httpaccess"];
        $httpaccess_data = $ligne["httpaccess_data"];
        $reverse = false;
        $ID = $ligne["ID"];
        $valueToAdd = null;
        if ($httpaccess == "deny_access_except") {
            $reverse = true;
        }
        echo "Starting......: " . date("H:i:s") . " [META]: aclname[{$ID}]: {$aclname}/{$httpaccess}\n";
        if (isset($GLOBALS["ACLRULEXEC"][$ID])) {
            echo "Starting......: " . date("H:i:s") . " [META]: aclname[{$ID}]: Already executed, skip\n";
            continue;
        }
        $Groups = $aclsGroups->buildacls_bytype_items($ID, $reverse);
        if (count($Groups) == 0) {
            echo "Starting......: " . date("H:i:s") . " [META]: aclname[{$ID}]: no group, skip...\n";
            continue;
        }
        $GLOBALS["ACLRULEXEC"][$ID] = true;
        $firstToken = getFirstToken($httpaccess, $httpaccess_data, $ID);
        $ACLS[] = "{$firstToken} {$valueToAdd}" . @implode(" ", $Groups);
    }
    @file_put_contents("/etc/squid3/acls_center_meta.conf", "{$all_acls}\n" . @implode("\n", $ACLS) . "\n");
    @chown("/etc/squid3/acls_center_meta.conf", "squid");
    @chgrp("/etc/squid3/acls_center_meta.conf", "squid");
    if (count($ACLS) == 0) {
        $md5_new = md5_file("/etc/squid3/acls_center_meta.conf");
        if ($md5_new != $md5_org) {
            $squidbin = $unix->LOCATE_SQUID_BIN();
            squid_admin_mysql(1, "Reload proxy service for Meta acls", null, __FILE__, __LINE__);
            shell_exec("{$squidbin} -f /etc/squid3/squid.conf -k reconfigure");
        }
        return;
    }
    if (!$GLOBALS["NOCHECK"]) {
        if (!isInSquidConf()) {
            squid_admin_mysql(1, "Reconfigure proxy service for Meta acls", null, __FILE__, __LINE__);
            system("{$php} /usr/share/artica-postfix/exec.squid.php --build --force --for-meta");
            return;
        }
    }
    $md5_new = md5_file("/etc/squid3/acls_center_meta.conf");
    if ($md5_new != $md5_org) {
        $squidbin = $unix->LOCATE_SQUID_BIN();
        squid_admin_mysql(1, "Reload proxy service for Meta acls", null, __FILE__, __LINE__);
        shell_exec("{$squidbin} -f /etc/squid3/squid.conf -k reconfigure");
    }
}
Exemplo n.º 2
0
function output_acls()
{
    $q = new squidbee();
    $acls = new squid_acls_groups();
    $squid = new squidbee();
    echo "\nexternal_acl_helper_categories\n-----------------\n";
    echo $squid->external_acl_helper_categories();
    echo "\n-----------------\n";
    $sock = new sockets();
    $refreshpattern = $squid->refresh_pattern_list();
    $SquidBubbleMode = $sock->GET_INFO("SquidBubbleMode");
    if (!is_numeric($SquidBubbleMode)) {
        $SquidBubbleMode = 0;
    }
    $acl = new squid_acls_quotas_time();
    $squid_acls_quotas_time = $acl->build() . "\n";
    $acls = new squid_acls();
    $acls->Build_Acls();
    $aclgroups = new squid_acls_groups();
    if (count($acls->acls_array) > 0) {
        $ACLS_TO_ADD = @implode("\n", $acls->acls_array);
    }
    echo "\nAcls\n-----------------\n" . $ACLS_TO_ADD . "\n-----------------\n\n";
    echo "\nQuotas Time\n-----------------\n" . $squid_acls_quotas_time . "\n-----------------\n\n";
    echo "\n\n-----------------\n" . $aclgroups->buildacls_order(0) . "\n-----------------\n\n";
    echo "######\n";
    $tcp_outgoing_address = $aclgroups->buildacls_bytype("tcp_outgoing_address");
    echo "\n\ntcp_outgoing_address -----------------\n";
    if (count($tcp_outgoing_address) > 0) {
        echo "Starting......: " . date("H:i:s") . " [ACLS]: Engine tcp_outgoing_address " . count($tcp_outgoing_address) . " rules..\n";
        while (list($index, $line) = each($tcp_outgoing_address)) {
            echo "tcp_outgoing_address {$line}\n";
        }
    } else {
        echo "Starting......: " . date("H:i:s") . " [ACLS]: ACL Engine tcp_outgoing_address No rules..\n";
    }
    echo "\n-----------------\n\n";
    echo "######\n";
    $q = new mysql_squid_builder();
    if ($SquidBubbleMode == 1) {
        $sql = "SELECT * FROM webfilters_sqaclsports ORDER BY aclport";
        $results = $q->QUERY_SQL($sql);
        while ($ligne = mysql_fetch_assoc($results)) {
            echo "\n\n#--------- ACLS {$ligne["portname"]}\n\n";
            echo "\n\n" . $aclgroups->buildacls_order($ligne["aclport"]) . "\n\n";
        }
    }
    $bandwith = new squid_bandwith_builder();
    echo "\n-----------------\n\n";
    echo $bandwith->compile() . "\n";
    $acls_rules = $acls->build_http_access(0);
    echo "\n\n# Builded acls from engine [" . count($acls_rules) . "] items.\n";
    if (count($acls_rules) > 0) {
        echo "\n\n" . @implode("\n", $acls_rules) . "\n";
    }
    if ($SquidBubbleMode == 1) {
        $sql = "SELECT * FROM webfilters_sqaclsports ORDER BY aclport";
        $results = $q->QUERY_SQL($sql);
        while ($ligne = mysql_fetch_assoc($results)) {
            $acls_rules = $acls->build_http_access($ligne["aclport"]);
            echo "\n\n# Builded acls from engine {$ligne["portname"]} [" . count($acls_rules) . "] items.\n";
            if (count($acls_rules) > 0) {
                echo "\n\n" . @implode("\n", $acls_rules) . "\n";
            }
        }
    }
    echo "\n\n-----------------\n" . $refreshpattern . "\n-----------------\n\n";
    $acls = new squid_acls_groups();
    $acls_deny = $acls->buildacls_bytype("url_rewrite_access_deny");
    if (count($acls_deny) > 0) {
        while (list($index, $line) = each($acls_deny)) {
            $MyStandPort = "MyStandPort";
            echo "url_rewrite_access deny {$line}\n";
        }
    }
    echo "######\n";
    echo "######\n";
    echo "######\n";
}