Ejemplo n.º 1
0
}
if (!is_file($GLOBALS["DBPATH"])) {
    try {
        WLOG("Creating {$GLOBALS["DBPATH"]} database");
        $db_desttmp = dba_open($GLOBALS["DBPATH"], "c", "db4");
    } catch (Exception $e) {
        $error = $e->getMessage();
        WLOG("TIME_QUOTA::FATAL ERROR {$error}");
    }
    if (!$db_desttmp) {
        WLOG("TIME_QUOTA::FATAL ERROR, unable to create database {$GLOBALS["DBPATH"]}");
    }
    dba_close($db_desttmp);
}
@chmod($GLOBALS["DBPATH"], 0777);
LOADING_RULES();
WLOG("Quota Database : Starting Group id:{$GLOBALS["MYPID"]}");
$DCOUNT = 0;
while (!feof(STDIN)) {
    $url = trim(fgets(STDIN));
    if ($url == null) {
        if ($GLOBALS["DEBUG"]) {
            WLOG("{$DCOUNT}] TIME_QUOTA::URL is null [" . __LINE__ . "]");
        }
        continue;
    }
    $DCOUNT++;
    try {
        $result = TIME_QUOTA($url);
    } catch (Exception $e) {
        $error = $e->getMessage();
Ejemplo n.º 2
0
function SIZE_QUOTA($url)
{
    if (trim($url) == null) {
        if ($GLOBALS["DEBUG"]) {
            WLOG("SIZE_QUOTA::URL is null [" . __LINE__ . "]");
            return false;
        }
    }
    //- Group75 administrateur 192.168.1.9 00:26:b9:78:8f:0a - ttvpsy.psychologies.com ttvpsy.psychologies.com 75
    $MAIN = explode(" ", $url);
    $EXT_LOG = $MAIN[0];
    $MYGROUP = $MAIN[1];
    $USERNAME = $MAIN[2];
    $IPADDR = $MAIN[3];
    $MAC = $MAIN[4];
    $XFORWARD = trim($MAIN[5]);
    $WWW = $MAIN[6];
    $WWW_SRC = $WWW;
    $gpid = $MAIN[7];
    if ($IPADDR == "127.0.0.1") {
        return false;
    }
    if ($XFORWARD == "-") {
        $XFORWARD = null;
    }
    if (strpos($USERNAME, '$') > 0) {
        if (substr($USERNAME, strlen($USERNAME) - 1, 1) == "\$") {
            $USERNAME = null;
        }
    }
    $USERNAME = str_replace("%20", " ", $USERNAME);
    $USERNAME = str_replace("%25", "-", $USERNAME);
    $IPADDR = str_replace("%25", "-", $IPADDR);
    $MAC = str_replace("%25", "-", $MAC);
    $XFORWARD = str_replace("%25", "-", $XFORWARD);
    if ($XFORWARD == "-") {
        $XFORWARD = null;
    }
    if ($MAC == "00:00:00:00:00:00") {
        $MAC = null;
    }
    if ($MAC == "-") {
        $MAC = null;
    }
    if ($USERNAME == "-") {
        $USERNAME = null;
    }
    $IPCalls = new IP();
    if ($IPCalls->isIPAddress($XFORWARD)) {
        $IPADDR = $XFORWARD;
    }
    if (preg_match("#(.+?):[0-9]+#", $WWW, $re)) {
        $WWW = $re[1];
    }
    if (preg_match("#^www\\.(.+)#", $WWW, $re)) {
        $WWW = $re[1];
    }
    if (!class_exists("squid_familysite")) {
        include_once dirname(__FILE__) . "/ressources/class.squid.familysites.inc";
    }
    $fam = new squid_familysite();
    $WWW = $fam->GetFamilySites($WWW);
    $LOG_PREFIX = "{$WWW}";
    if ($GLOBALS["DEBUG"]) {
        WLOG("{$LOG_PREFIX}: {$WWW_SRC}::GROUPID:{$gpid}; USERNAME:{$USERNAME};MAC:{$MAC}; IPADDR:{$IPADDR} [" . __LINE__ . "]");
    }
    LOADING_RULES($gpid);
    if (!isset($GLOBALS["ACL_RULES"][$gpid]["WEEK"])) {
        $GLOBALS["ACL_RULES"][$gpid]["WEEK"] = 0;
    }
    if (!isset($GLOBALS["ACL_RULES"][$gpid]["HOUR"])) {
        $GLOBALS["ACL_RULES"][$gpid]["HOUR"] = 0;
    }
    if (!isset($GLOBALS["ACL_RULES"][$gpid]["DAY"])) {
        $GLOBALS["ACL_RULES"][$gpid]["DAY"] = 0;
    }
    if (!isset($GLOBALS["ACL_RULES"][$gpid]["MEMBER_HOUR"])) {
        $GLOBALS["ACL_RULES"][$gpid]["MEMBER_HOUR"] = 0;
    }
    if (!isset($GLOBALS["ACL_RULES"][$gpid]["MEMBER_WEEK"])) {
        $GLOBALS["ACL_RULES"][$gpid]["MEMBER_WEEK"] = 0;
    }
    if (!isset($GLOBALS["ACL_RULES"][$gpid]["MEMBER_DAY"])) {
        $GLOBALS["ACL_RULES"][$gpid]["MEMBER_DAY"] = 0;
    }
    if (!isset($GLOBALS["ACL_RULES"][$gpid]["WEBSITE_HOUR"])) {
        $GLOBALS["ACL_RULES"][$gpid]["WEBSITE_HOUR"] = 0;
    }
    if (!isset($GLOBALS["ACL_RULES"][$gpid]["WEBSITE_WEEK"])) {
        $GLOBALS["ACL_RULES"][$gpid]["WEBSITE_WEEK"] = 0;
    }
    if (!isset($GLOBALS["ACL_RULES"][$gpid]["WEBSITE_HOUR"])) {
        $GLOBALS["ACL_RULES"][$gpid]["WEBSITE_HOUR"] = 0;
    }
    $MaxPerDay = intval($GLOBALS["ACL_RULES"][$gpid]["DAY"]);
    $MaxPerHour = intval($GLOBALS["ACL_RULES"][$gpid]["HOUR"]);
    $MaxPerWeek = intval($GLOBALS["ACL_RULES"][$gpid]["WEEK"]);
    $MEMBER_HOUR = intval($GLOBALS["ACL_RULES"][$gpid]["MEMBER_HOUR"]);
    $MEMBER_DAY = intval($GLOBALS["ACL_RULES"][$gpid]["MEMBER_DAY"]);
    $MEMBER_WEEK = intval($GLOBALS["ACL_RULES"][$gpid]["MEMBER_WEEK"]);
    $WEBSITE_HOUR = intval($GLOBALS["ACL_RULES"][$gpid]["WEBSITE_HOUR"]);
    $WEBSITE_DAY = intval($GLOBALS["ACL_RULES"][$gpid]["WEBSITE_DAY"]);
    $WEBSITE_WEEK = intval($GLOBALS["ACL_RULES"][$gpid]["WEBSITE_WEEK"]);
    if (CHECK_WEBSITE($WWW, $WEBSITE_HOUR, $WEBSITE_DAY, $WEBSITE_WEEK)) {
        WLOG("{$LOG_PREFIX}: {$WWW} match size");
        return true;
    }
    if (isset($GLOBALS["ACL_RULES"][$gpid]["CATEGORIES_HOUR"])) {
        if (CHECK_CATEGORY_HOUR($WWW_SRC, $gpid)) {
            WLOG("{$LOG_PREFIX}: {$WWW} Hourly Category match size");
            return true;
        }
    } else {
        WLOG("{$LOG_PREFIX}: {$gpid} CATEGORIES_HOUR not set");
    }
    if (isset($GLOBALS["ACL_RULES"][$gpid]["CATEGORIES_DAY"])) {
        if (CHECK_CATEGORY_DAY($WWW_SRC, $gpid)) {
            WLOG("{$LOG_PREFIX}: {$WWW} Daily Category match size");
            return true;
        }
    }
    if (isset($GLOBALS["ACL_RULES"][$gpid]["CATEGORIES_WEEK"])) {
        if (CHECK_CATEGORY_WEEK($WWW_SRC, $gpid)) {
            WLOG("{$LOG_PREFIX}: {$WWW} Weekly Category match size");
            return true;
        }
    }
    if ($USERNAME != null) {
        $CHECK_USER = true;
        if (CHECK_UID($WWW, "UID/{$USERNAME}", $MaxPerHour, $MaxPerDay, $MaxPerWeek)) {
            WLOG("{$LOG_PREFIX}: {$USERNAME} {$WWW} match size");
            return true;
        }
        if (CHECK_MEMBER("UID/{$USERNAME}", $MEMBER_HOUR, $MEMBER_DAY, $MEMBER_WEEK)) {
            WLOG("{$LOG_PREFIX}: {$USERNAME} match size");
            return true;
        }
    }
    if (!$CHECK_USER) {
        if ($MAC != null) {
            $CHECK_USER = true;
            if (CHECK_UID($WWW, "MAC/{$MAC}", $MaxPerHour, $MaxPerDay, $MaxPerWeek)) {
                WLOG("{$LOG_PREFIX}: {$MAC} {$WWW} match size");
                return true;
            }
            if (CHECK_MEMBER("UID/{$MAC}", $MEMBER_HOUR, $MEMBER_DAY, $MEMBER_WEEK)) {
                WLOG("{$LOG_PREFIX}: {$USERNAME} match size");
                return true;
            }
        }
    }
    if (!$CHECK_USER) {
        if ($IPADDR != null) {
            if (CHECK_UID($WWW, "IPADDR/{$IPADDR}", $MaxPerHour, $MaxPerDay, $MaxPerWeek)) {
                WLOG("{$LOG_PREFIX}: {$IPADDR} {$WWW} match size");
                return true;
            }
            if (CHECK_MEMBER("UID/{$IPADDR}", $MEMBER_HOUR, $MEMBER_DAY, $MEMBER_WEEK)) {
                WLOG("{$LOG_PREFIX}: {$USERNAME} match size");
                return true;
            }
        }
    }
    return false;
}