function popup_search()
{
    $icon = "win7groups-32.png";
    $ldap = new ldap_extern();
    if ($_POST["query"] == null) {
        $_POST["query"] = "*";
    }
    if (strpos(" {$_POST["query"]}", "*") == 0) {
        $_POST["query"] = "*{$_POST["query"]}*";
    }
    $_POST["query"] = str_replace("**", "*", $_POST["query"]);
    $_POST["query"] = str_replace("**", "*", $_POST["query"]);
    if (!is_numeric($_POST["rp"])) {
        $_POST["rp"] = 50;
    }
    $Array = $ldap->SearchGroups($_POST["query"], $_POST["rp"]);
    if (!$ldap->ok) {
        json_error_show($ldap->ldap_error, 1);
    }
    if (count($Array) == 0) {
        json_error_show("No item", 1);
    }
    $data = array();
    $data['page'] = 1;
    $data['total'] = count($Array);
    $data['rows'] = array();
    while (list($dn, $itemname) = each($Array)) {
        $GroupxSourceName = $itemname;
        $GroupxName = $itemname;
        $GroupxName = replace_accents($GroupxName);
        $GroupxName = str_replace("'", "`", $itemname);
        $addtitile = null;
        $select = null;
        $dn_enc = base64_encode($dn);
        $DN_base64 = base64_encode($dn);
        $itemnameenc = base64_encode($itemname);
        $CountDeUsers = $ldap->CountDeUsersByGroupDN($dn);
        $js = "EditField{$_GET["t"]}('{$DN_base64}','{$GroupxSourceName}');";
        if ($_GET["MainFunction"] != null) {
            $js = "{$_GET["MainFunction"]}('{$dn}');YahooWinBrowseHide();";
        }
        $image = imgsimple($icon, null, $js);
        $select = imgsimple("arrow-right-32.png", null, $js);
        $md5 = md5($dn);
        $data['rows'][] = array('id' => $md5, 'cell' => array("<center>{$image}</center>", "<span style='font-size:20px;'>{$GroupxName}</a></span>", "<center style='font-size:20px;'>{$CountDeUsers}</center>", "<center>{$select}</center>"));
    }
    echo json_encode($data);
}
Example #2
0
function parseTemplate_unlock_checkcred()
{
    include_once dirname(__FILE__) . "/ressources/class.sockets.inc";
    include_once dirname(__FILE__) . "/ressources/class.mysql.squid.builder.php";
    include_once dirname(__FILE__) . "/ressources/class.tcpip.inc";
    include_once dirname(__FILE__) . "/ressources/class.user.inc";
    include_once dirname(__FILE__) . "/ressources/class.templates.inc";
    include_once dirname(__FILE__) . "/ressources/class.users.menus.inc";
    include_once dirname(__FILE__) . "/ressources/class.external.ad.inc";
    include_once dirname(__FILE__) . "/ressources/class.ldap-extern.inc";
    include "ressources/settings.inc";
    $sock = new sockets();
    $UfdbGuardHTTPAllowNoCreds = intval($sock->GET_INFO("UfdbGuardHTTPAllowNoCreds"));
    if ($UfdbGuardHTTPAllowNoCreds == 1) {
        return true;
    }
    if ($_POST["nocreds"] == 1) {
        return true;
    }
    $username = $_POST["username"];
    $password = trim($_POST["password"]);
    if ($sock->SQUID_IS_EXTERNAL_LDAP()) {
        $ldap_extern = new ldap_extern();
        if ($ldap_extern->checkcredentials($username, $password)) {
            return true;
        }
    }
    if (trim(strtolower($username)) == trim(strtolower($_GLOBAL["ldap_admin"]))) {
        if ($password == trim($_GLOBAL["ldap_password"])) {
            return true;
        }
    }
    $ldap = new clladp();
    if ($ldap->IsKerbAuth()) {
        $external_ad_search = new external_ad_search();
        if ($external_ad_search->CheckUserAuth($username, $password)) {
            return true;
        }
    }
    $q = new mysql();
    $sql = "SELECT `username`,`value`,id FROM radcheck WHERE `username`='{$username}' AND `attribute`='Cleartext-Password' LIMIT 0,1";
    $ligne = mysql_fetch_array($q->QUERY_SQL($sql, "artica_backup"));
    if (!is_numeric($ligne["id"])) {
        $ligne["id"] = 0;
    }
    if (!$q->ok) {
        writelogs("{$username}:: {$q->mysql_error}", __FUNCTION__, __FILE__, __LINE__);
    }
    if ($ligne["id"] > 0) {
        if ($ligne["value"] == $password) {
            return true;
        }
    }
    $u = new user($username);
    if (trim($u->uidNumber) != null) {
        if (trim($password) == trim($u->password)) {
            return true;
        }
    }
    return false;
}
function ufdbguard_checks($id)
{
    LoadSettings();
    if ($GLOBALS["VERBOSE"]) {
        $GLOBALS["output"] = true;
        echo "OPEN: /etc/squid3/ufdb.groups.{$id}.db\n";
    }
    if (!is_file("/etc/squid3/ufdb.groups.{$id}.db")) {
        if ($GLOBALS["output"]) {
            echo "Cannot perform this operation\nYou have to create correctly a Web filtering rule\nIncluding blacklists and whitelists\nAnd compile your Web filtering rules in order to dump groups\n";
        }
        return null;
    }
    $arrayGROUPS = unserialize(@file_get_contents("/etc/squid3/ufdb.groups.{$id}.db"));
    $FINAL = array();
    $Hash = array();
    if ($GLOBALS["VERBOSE"]) {
        echo "DUMP: ARRAY ***********************\n";
    }
    if ($GLOBALS["VERBOSE"]) {
        print_r($arrayGROUPS);
    }
    if ($GLOBALS["VERBOSE"]) {
        echo "***********************************\n";
    }
    if (isset($arrayGROUPS["EXT-LDAP"])) {
        if ($GLOBALS["VERBOSE"]) {
            echo "Found:EXT-LDAP\n";
        }
        $extn_ldap = new ldap_extern();
        while (list($index, $DNS) = each($arrayGROUPS["EXT-LDAP"])) {
            if ($GLOBALS["VERBOSE"]) {
                echo "DN:{$DNS}\n";
            }
            $rr = $extn_ldap->HashUsersFromGroupDN($DNS);
            if ($GLOBALS["output"]) {
                echo "{$DNS} return " . count($rr) . " users\n";
            }
            while (list($a, $b) = each($rr)) {
                $b = trim($b);
                if ($b == null) {
                    continue;
                }
                echo "USER= {$b}\n";
                $MemberArray[$a] = $a;
            }
            while (list($a, $b) = each($MemberArray)) {
                $FINAL[] = $a;
            }
        }
    }
    if (isset($arrayGROUPS["EXTLDAP"])) {
        while (list($index, $CONFS) = each($arrayGROUPS["EXTLDAP"])) {
            $rr = external_ldap_members($CONFS["DN"], $CONFS["CONF"]);
            if ($GLOBALS["output"]) {
                echo "{$CONFS["DN"]} return " . count($rr) . " users\n";
            }
            while (list($a, $b) = each($rr)) {
                echo "USER= {$b}\n";
                $MemberArray[$a] = $a;
            }
        }
        while (list($a, $b) = each($MemberArray)) {
            $FINAL[] = $a;
        }
    }
    if (isset($arrayGROUPS["AD"])) {
        while (list($index, $DNenc) = each($arrayGROUPS["AD"])) {
            $DN = base64_decode($DNenc);
            if ($GLOBALS["output"]) {
                echo "Loading Active Directory groups...\n";
            }
            if ($GLOBALS["output"]) {
                echo "Branch {$DN}\n";
            }
            if ($GLOBALS["VERBOSE"]) {
                echo "DN, {$DN}\n";
            }
            $ldapExt = new external_acl_squid_ldap();
            $members = $ldapExt->AdLDAP_MembersFromGroup($DN);
            if ($GLOBALS["VERBOSE"]) {
                echo "DN, {$DN} -> " . count($members) . "\n";
            }
            while (list($a, $b) = each($members)) {
                $Hash[$b] = $b;
            }
        }
        while (list($a, $b) = each($Hash)) {
            if ($GLOBALS["VERBOSE"]) {
                echo "USER= {$b}\n";
            }
            $FINAL[] = $b;
        }
    }
    if (isset($arrayGROUPS["LDAP"])) {
        while (list($index, $gpid) = each($arrayGROUPS["LDAP"])) {
            $Hash = HashUsersFromGPID($gpid);
            if (count($Hash) == 0) {
                WLOG("[QUERY]: ufdbguard_checks({$id}) GPID:{$gpid} store no user...");
                continue;
            }
            while (list($a, $b) = each($Hash)) {
                if ($GLOBALS["VERBOSE"]) {
                    echo "USER= {$b}\n";
                }
                $FINAL[] = $b;
            }
        }
    }
    if ($GLOBALS["output"]) {
        echo "\nResults\n**********************************\n# # # # # # # # # # # # # # # # # # # # # #\n" . count($FINAL) . " item(s)\n# # # # # # # # # # # # # # # # # # # # # #\n";
    }
    if (count($FINAL) == 0) {
        WLOG("[QUERY]: ufdbguard_checks({$id}) no user...");
        return;
    }
    while (list($a, $Member) = each($FINAL)) {
        $Member = trim($Member);
        if ($Member == null) {
            continue;
        }
        $Member = str_replace(" ", "%20", $Member);
        $FINAL2[] = $Member;
    }
    echo @implode($FINAL2, "\n") . "\n";
}
function rules_list()
{
    $tpl = new templates();
    $MyPage = CurrentPageName();
    $table = "ufdb_page_rules";
    $q = new mysql_squid_builder();
    $FORCE = 1;
    $t = $_GET["t"];
    if ($_POST["query"] != null) {
        $search = str_replace("*", ".*?", $_POST["query"]);
    }
    $total = 0;
    if ($q->COUNT_ROWS($table, "artica_backup") == 0) {
        json_error_show("no data [" . __LINE__ . "]", 0);
    }
    if (isset($_POST["sortname"])) {
        if ($_POST["sortname"] != null) {
            $ORDER = "ORDER BY {$_POST["sortname"]} {$_POST["sortorder"]}";
        }
    }
    if (isset($_POST['page'])) {
        $page = $_POST['page'];
    }
    if (!is_numeric($page)) {
        $page = 1;
    }
    $searchstring = string_to_flexquery();
    if ($searchstring != null) {
        $sql = "SELECT COUNT(*) as TCOUNT FROM `{$table}` WHERE {$FORCE} {$searchstring}";
        $ligne = mysql_fetch_array($q->QUERY_SQL($sql, "artica_events"));
        $total = $ligne["TCOUNT"];
    } else {
        $total = $q->COUNT_ROWS($table, "artica_events");
    }
    if (isset($_POST['rp'])) {
        $rp = $_POST['rp'];
    }
    if (!is_numeric($rp)) {
        $rp = 50;
    }
    $pageStart = ($page - 1) * $rp;
    $limitSql = "LIMIT {$pageStart}, {$rp}";
    $sql = "SELECT *  FROM `{$table}` WHERE {$FORCE} {$searchstring} {$ORDER} {$limitSql}";
    writelogs($sql, __FUNCTION__, __FILE__, __LINE__);
    $results = $q->QUERY_SQL($sql, "artica_events");
    if (!$q->ok) {
        json_error_show($q->mysql_error . "<br>{$sql}", 0);
    }
    $data = array();
    $data['page'] = $page;
    $data['total'] = $total;
    $data['rows'] = array();
    $CurrentPage = CurrentPageName();
    if (mysql_num_rows($results) == 0) {
        json_error_show("no data");
    }
    $searchstring = string_to_flexquery();
    $automatically_add_to = $tpl->javascript_parse_text("{automatically_add_to}");
    $unlock_during = $tpl->javascript_parse_text("{unlock_during}");
    $results = $q->QUERY_SQL($sql, 'artica_backup');
    if (!$q->ok) {
        json_error_show($q->mysql_error . "<br>{$sql}");
    }
    $q1 = new mysql();
    $t = time();
    $fontsize = 22;
    $span = "<span style='font-size:{$fontsize}px'>";
    $everyone = $tpl->javascript_parse_text("{everyone}");
    $all_categories = $tpl->javascript_parse_text("{all_categories}");
    while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) {
        $red = "32-red.png";
        $ok = "ok-32.png";
        $warn = "warning32.png";
        $zmd5 = $ligne["zmd5"];
        $category = $ligne["category"];
        $webruleid = intval($ligne["webruleid"]);
        $deny = $ligne["deny"];
        $adgroup = $ligne["adgroup"];
        $noauth = $ligne["noauth"];
        $infinite = $ligne["infinite"];
        $addTocat = $ligne["addTocat"];
        $username = $ligne["username"];
        $maxtime = $ligne["maxtime"];
        $allow = $ligne["allow"];
        $automatically_add_to_text = null;
        $unlock_during = null;
        $icon = "ok32-grey.png";
        $icon_allow = "ok32-grey.png";
        $icon_ticket = "ok32-grey.png";
        $groupname = null;
        if ($allow == 1) {
            $icon_allow = $ok;
            $icon = "ok32-grey.png";
        }
        if ($deny == 1) {
            $icon = $red;
            $icon_allow = "ok32-grey.png";
        }
        if ($username != null) {
            $adgroup = $username;
        }
        if ($addTocat != null) {
            $automatically_add_to_text = "<br><i>{$automatically_add_to} {$addTocat}</i>";
        }
        if ($noauth == 1) {
            $icon_allow = $warn;
        }
        if ($ligne["ticket"] == 1) {
            $icon_ticket = $ok;
            $icon_allow = "ok32-grey.png";
        }
        if ($adgroup == "*") {
            $adgroup = "{$everyone}";
        }
        if (preg_match("#EXTLDAP:(.+)#", $adgroup, $re)) {
            $ldap = new ldap_extern();
            $hash = $ldap->DNInfos($re[1]);
            $DNENC = urlencode($re[1]);
            if (isset($hash[0]["cn"])) {
                $adgroup = $hash[0]["cn"][0];
                if (isset($hash[0][$ldap->ldap_filter_group_attribute]["count"])) {
                    $CountOfUsers = " (<a href=\"javascript:blur();\" OnClick=\"javascript:Loadjs('browse-extldap-users.php?DN={$DNENC}');\" style='text-decoration:underline'>" . intval($hash[0][$ldap->ldap_filter_group_attribute]["count"]) . " {members}</a>)";
                }
                if (isset($hash[0]["description"])) {
                    $description = "<br><i>{$hash[0]["description"][0]}</i>";
                }
                $adgroup = $tpl->_ENGINE_parse_body("{ldap_group}: {$adgroup} {$CountOfUsers}{$description}");
            }
        }
        $delete = imgsimple("delete-42.png", null, "Loadjs('{$MyPage}?delete-js={$zmd5}')");
        $link = "Loadjs('{$MyPage}?rule-js={$zmd5}')";
        $href = "<a href=\"javascript:blur();\" OnClick=\"javascript:{$link}\"\n\t\tstyle='text-decoration:underline;font-size:{$fontsize}px'>";
        if ($maxtime > 0) {
            $automatically_add_to_text = $automatically_add_to_text . "<br><i>{$unlock_during} {$maxtime} minutes</i>";
        }
        if ($category == null) {
            $category = $all_categories;
        }
        if ($webruleid > 0) {
            $ligne = mysql_fetch_array($q->QUERY_SQL("SELECT groupname FROM webfilter_rules WHERE ID={$webruleid}"));
            $groupname = "<br>{$href}<i style='font-size:18px'>" . utf8_encode($ligne["groupname"]) . "</i></a>";
        }
        $data['rows'][] = array('id' => $zmd5, 'cell' => array("{$href}{$category}</a>{$groupname}{$automatically_add_to_text}", "<center><img src='img/{$icon}'></center>", "<center><img src='img/{$icon_allow}'></center>", "<center><img src='img/{$icon_ticket}'></center>", "{$span}{$adgroup}</span>", "<center>{$delete}</center>"));
    }
    echo json_encode($data);
}
function ufdbguard_checks($id)
{
    LoadSettings();
    if ($GLOBALS["VERBOSE"]) {
        $GLOBALS["output"] = true;
        echo "OPEN: /etc/squid3/ufdb.groups.{$id}.db\n";
    }
    $arrayGROUPS = unserialize(@file_get_contents("/etc/squid3/ufdb.groups.{$id}.db"));
    $FINAL = array();
    $Hash = array();
    if (isset($arrayGROUPS["EXT-LDAP"])) {
        if ($GLOBALS["VERBOSE"]) {
            echo "Found:EXT-LDAP\n";
        }
        $extn_ldap = new ldap_extern();
        while (list($index, $DNS) = each($arrayGROUPS["EXT-LDAP"])) {
            if ($GLOBALS["VERBOSE"]) {
                echo "DN:{$DNS}\n";
            }
            $rr = $extn_ldap->HashUsersFromGroupDN($DNS);
            if ($GLOBALS["output"]) {
                echo "{$DNS} return " . count($rr) . " users\n";
            }
            while (list($a, $b) = each($rr)) {
                $b = trim($b);
                if ($b == null) {
                    continue;
                }
                echo "USER= {$b}\n";
                $MemberArray[$a] = $a;
            }
            while (list($a, $b) = each($MemberArray)) {
                $FINAL[] = $a;
            }
        }
    }
    if (isset($arrayGROUPS["EXTLDAP"])) {
        while (list($index, $CONFS) = each($arrayGROUPS["EXTLDAP"])) {
            $rr = external_ldap_members($CONFS["DN"], $CONFS["CONF"]);
            if ($GLOBALS["output"]) {
                echo "{$CONFS["DN"]} return " . count($rr) . " users\n";
            }
            while (list($a, $b) = each($rr)) {
                echo "USER= {$b}\n";
                $MemberArray[$a] = $a;
            }
        }
        while (list($a, $b) = each($MemberArray)) {
            $FINAL[] = $a;
        }
    }
    if (isset($arrayGROUPS["AD"])) {
        while (list($index, $DNenc) = each($arrayGROUPS["AD"])) {
            $DN = base64_decode($DNenc);
            if ($GLOBALS["VERBOSE"]) {
                echo "DN, {$DN}\n";
            }
            $ldapExt = new external_acl_squid_ldap();
            $members = $ldapExt->AdLDAP_MembersFromGroup($DN);
            if ($GLOBALS["VERBOSE"]) {
                echo "DN, {$DN} -> " . count($members) . "\n";
            }
            while (list($a, $b) = each($members)) {
                $Hash[$b] = $b;
            }
        }
        while (list($a, $b) = each($Hash)) {
            if ($GLOBALS["VERBOSE"]) {
                echo "USER= {$b}\n";
            }
            $FINAL[] = $b;
        }
    }
    if (isset($arrayGROUPS["LDAP"])) {
        while (list($index, $gpid) = each($arrayGROUPS["LDAP"])) {
            $Hash = HashUsersFromGPID($gpid);
            if (count($Hash) == 0) {
                WLOG("[QUERY]: ufdbguard_checks({$id}) GPID:{$gpid} store no user...");
                continue;
            }
            while (list($a, $b) = each($Hash)) {
                if ($GLOBALS["VERBOSE"]) {
                    echo "USER= {$b}\n";
                }
                $FINAL[] = $b;
            }
        }
    }
    if ($GLOBALS["output"]) {
        echo "\nResults\n**********************************\n# # # # # # # # # # # # # # # # # # # # # #\n" . count($FINAL) . " item(s)\n# # # # # # # # # # # # # # # # # # # # # #\n";
    }
    if (count($FINAL) == 0) {
        WLOG("[QUERY]: ufdbguard_checks({$id}) no user...");
        return;
    }
    while (list($a, $Member) = each($FINAL)) {
        $Member = trim($Member);
        if ($Member == null) {
            continue;
        }
        $Member = str_replace(" ", "%20", $Member);
        $FINAL2[] = $Member;
    }
    echo @implode($FINAL2, "\n") . "\n";
}
Example #6
0
function groups_list()
{
    $tpl = new templates();
    $MyPage = CurrentPageName();
    $q = new mysql_squid_builder();
    $tpl = new templates();
    $dump_group_text = $tpl->_ENGINE_parse_body("{dump_group}");
    $page = 1;
    $t = $_GET["t"];
    $table = "(SELECT webfilter_assoc_groups.ID,webfilter_assoc_groups.webfilter_id,\n\twebfilter_group.groupname,\n\twebfilter_group.description,\n\twebfilter_group.gpid,\n\twebfilter_group.localldap,\n\twebfilter_group.ID as webfilter_group_ID,\n\twebfilter_group.dn as webfilter_group_dn,\n\twebfilter_group.enabled\n\tFROM webfilter_group,webfilter_assoc_groups \n\tWHERE webfilter_assoc_groups.webfilter_id={$_GET["rule-id"]}\n\tAND webfilter_assoc_groups.group_id=webfilter_group.ID\n\tORDER BY webfilter_group.groupname) as t";
    if ($_GET["QuotaID"] > 0) {
        if (!$q->TABLE_EXISTS("webfilter_assoc_quota_groups")) {
            $q->CheckTables(null, true);
        }
        $table = "(SELECT webfilter_assoc_quota_groups.ID,webfilter_assoc_quota_groups.webfilter_id,\n\t\twebfilter_group.groupname,\n\t\twebfilter_group.description,\n\t\twebfilter_group.gpid,\n\t\twebfilter_group.localldap,\n\t\twebfilter_group.ID as webfilter_group_ID,\n\t\twebfilter_group.dn as webfilter_group_dn,\n\t\twebfilter_group.enabled\n\t\tFROM webfilter_group,webfilter_assoc_quota_groups\n\t\tWHERE webfilter_assoc_quota_groups.webfilter_id={$_GET["QuotaID"]}\n\t\tAND webfilter_assoc_quota_groups.group_id=webfilter_group.ID\n\t\tORDER BY webfilter_group.groupname) as t";
    }
    $searchstring = string_to_flexquery();
    if ($searchstring != null) {
        $sql = "SELECT COUNT(*) as TCOUNT FROM {$table} WHERE 1 {$searchstring}";
        $ligne = mysql_fetch_array($q->QUERY_SQL($sql));
        if (!$q->ok) {
            json_error_show($q->mysql_error, 1);
        }
        $total = $ligne["TCOUNT"];
    } else {
        $sql = "SELECT COUNT(*) as TCOUNT FROM {$table}";
        $ligne = mysql_fetch_array($q->QUERY_SQL($sql));
        if (!$q->ok) {
            json_error_show($q->mysql_error, 1);
        }
        $total = $ligne["TCOUNT"];
    }
    if (isset($_POST["sortname"])) {
        if ($_POST["sortname"] != null) {
            $ORDER = "ORDER BY {$_POST["sortname"]} {$_POST["sortorder"]}";
        }
    }
    $localldap[0] = "{ldap_group}";
    $localldap[1] = "{virtual_group}";
    $localldap[2] = "{active_directory_group}";
    $localldap[3] = "{remote_ladp_group}";
    $isDynamic = isDynamic($_GET["rule-id"]);
    if (isset($_POST['page'])) {
        $page = $_POST['page'];
    }
    if (isset($_POST['rp'])) {
        $rp = $_POST['rp'];
    }
    $pageStart = ($page - 1) * $rp;
    if (!is_numeric($rp)) {
        $rp = 50;
    }
    $limitSql = "LIMIT {$pageStart}, {$rp}";
    $results = $q->QUERY_SQL($sql);
    if (!$q->ok) {
        json_error_show($q->mysql_error, 1);
    }
    $data = array();
    $data['page'] = $page;
    $data['total'] = $total;
    $data['rows'] = array();
    if (isset($_POST['rp'])) {
        $rp = $_POST['rp'];
    }
    $pageStart = ($page - 1) * $rp;
    $limitSql = "LIMIT {$pageStart}, {$rp}";
    $sql = "SELECT *  FROM {$table} WHERE 1 {$searchstring} {$ORDER} {$limitSql}";
    $results = $q->QUERY_SQL($sql);
    if ($GLOBALS["VERBOSE"]) {
        echo "<strong>" . __LINE__ . " </strong><br>\n";
    }
    if (mysql_num_rows($results) == 0) {
        json_error_show("no data", 1);
    }
    while ($ligne = mysql_fetch_array($results, MYSQL_ASSOC)) {
        $textExplainGroup = null;
        $KEY_ID_GROUP = $ligne["webfilter_group_ID"];
        $delete = "<a href=\"javascript:blur();\" \n\t\tOnClick=\"javascript:UnlinkFilterGroup('{$ligne["ID"]}')\"><img src='img/delete-32.png' style='border:0px'></a>";
        $color = "black";
        $CountDeMembers = "??";
        $Textdynamic = null;
        if ($GLOBALS["VERBOSE"]) {
            echo "<strong>" . __LINE__ . " localldap:{$ligne["localldap"]}</strong><br>\n";
        }
        if ($ligne["localldap"] == 0) {
            $gp = new groups($ligne["gpid"]);
            $groupadd_text = "(" . $gp->groupName . ")";
            $CountDeMembers = count($gp->members);
        }
        if ($ligne["localldap"] == 1) {
            $sql = "SELECT COUNT(ID) as tcount FROM webfilter_members WHERE `groupid`='{$KEY_ID_GROUP}'";
            $COUNLIGNE = mysql_fetch_array($q->QUERY_SQL($sql));
            $CountDeMembers = $COUNLIGNE["tcount"];
            if ($isDynamic) {
                $color = "#9A9A9A";
                $Textdynamic = $tpl->_ENGINE_parse_body("<div style='font-weight:bold;color:#E40F0F'>{ufdb_no_dynamic_group}</div>");
            }
        }
        if ($GLOBALS["VERBOSE"]) {
            print_r($ligne);
        }
        if ($ligne["enabled"] == 0) {
            $color = "#9A9A9A";
        }
        if ($ligne["localldap"] == 2) {
            if (preg_match("#AD:(.*?):(.+)#", $ligne["webfilter_group_dn"], $re)) {
                $dnEnc = $re[2];
                $LDAPID = $re[1];
                $ad = new ActiveDirectory($LDAPID);
                if ($ad->UseDynamicGroupsAcls == 1) {
                    if (preg_match("#^CN=(.+?),.*#i", base64_decode($dnEnc), $re)) {
                        $groupname = _ActiveDirectoryToName($re[1]);
                        $CountDeMembers = '-';
                        $Debug = "&nbsp;<a href=\"javascript:Loadjs('dansguardian2.explodeadgroup.php?rule-id={$_GET["rule-id"]}&groupid={$KEY_ID_GROUP}');\"\n\t\t\t\t\t\tstyle=\"text-decoration:underline\">{$dump_group_text}</a>";
                    }
                } else {
                    $tty = $ad->ObjectProperty(base64_decode($dnEnc));
                    $CountDeMembers = $tty["MEMBERS"];
                }
                $description = htmlentities($tty["description"]);
                $description = str_replace("'", "`", $description);
                if (trim($ligne["description"]) == null) {
                    $ligne["description"] = $description;
                }
            }
        }
        if ($ligne["localldap"] == 0) {
            if (preg_match("#^ExtLdap:(.+)#", $ligne["webfilter_group_dn"], $re)) {
                $CountDeMembers = '-';
                $groupadd_text = "&nbsp;{$re[1]}";
            }
        }
        if ($ligne["localldap"] == 3) {
            if (preg_match("#ExtLDAP:(.+?):(.+)#", $ligne["groupname"], $re)) {
                $ligne["groupname"] = $re[1];
            }
            $DN = base64_decode($re[2]);
            $ldap_ext = new ldap_extern();
            $CountDeMembers = $ldap_ext->CountDeUsersByGroupDN($DN);
        }
        $imgGP = "win7groups-32.png";
        if ($ligne["localldap"] < 2) {
            $imgGP = "group-32.png";
        }
        if ($Textdynamic != null) {
            $imgGP = "warning-panneau-32.png";
        }
        $TextGroupType = $tpl->_ENGINE_parse_body($localldap[$ligne["localldap"]]);
        $jsSelect = "Loadjs('dansguardian2.edit.group.php?ID-js={$KEY_ID_GROUP}&t={$t}&YahooWin=4');";
        $data['rows'][] = array('id' => "group{$ligne["ID"]}", 'cell' => array("<a href=\"javascript:blur();\" \n\t\t\t\tOnClick=\"javascript:{$jsSelect}\" \n\t\t\t\tstyle='font-size:22px;text-decoration:underline;color:{$color}'>{$ligne['groupname']}</span></a>\n\t\t\t\t<span style='font-size:22px'>{$groupadd_text}{$Textdynamic}</span><br>\n\t\t\t\t<span style='font-size:18px'>{$textExplainGroup}<i>&laquo;{$ligne["description"]} <i>{$TextGroupType}</i>&raquo;</i>{$Debug}</span>", "<span style='font-size:22px;color:{$color}'>{$CountDeMembers}</span>", "<center>{$delete}</center>"));
    }
    echo json_encode($data);
}
Example #7
0
function group_list()
{
    //ini_set('html_errors',0);ini_set('display_errors', 1);ini_set('error_reporting', E_ALL);ini_set('error_prepend_string','');ini_set('error_append_string','');
    $tpl = new templates();
    $MyPage = CurrentPageName();
    $q = new mysql_squid_builder();
    $RULEID = $_GET["RULEID"];
    $FORCE_FILTER = null;
    $search = '%';
    $table = "webfilters_sqgroups";
    $page = 1;
    if ($q->COUNT_ROWS($table) == 0) {
        json_error_show("No data");
    }
    if (isset($_POST["sortname"])) {
        if ($_POST["sortname"] != null) {
            $ORDER = "ORDER BY {$_POST["sortname"]} {$_POST["sortorder"]}";
        }
    }
    if (isset($_POST['page'])) {
        $page = $_POST['page'];
    }
    if ($_POST["query"] != null) {
        $_POST["query"] = str_replace("*", "%", $_POST["query"]);
        $search = $_POST["query"];
        $searchstring = "AND (`{$_POST["qtype"]}` LIKE '{$search}')";
        $sql = "SELECT COUNT(*) as TCOUNT FROM `{$table}` WHERE 1 {$FORCE_FILTER} {$searchstring}";
        $ligne = mysql_fetch_array($q->QUERY_SQL($sql));
        $total = $ligne["TCOUNT"];
    } else {
        $sql = "SELECT COUNT(*) as TCOUNT FROM `{$table}` WHERE 1 {$FORCE_FILTER}";
        $ligne = mysql_fetch_array($q->QUERY_SQL($sql));
        $total = $ligne["TCOUNT"];
    }
    if (isset($_POST['rp'])) {
        $rp = $_POST['rp'];
    }
    $pageStart = ($page - 1) * $rp;
    $limitSql = "LIMIT {$pageStart}, {$rp}";
    $sql = "SELECT *  FROM `{$table}` WHERE 1 {$searchstring} {$FORCE_FILTER} {$ORDER} {$limitSql}";
    $results = $q->QUERY_SQL($sql);
    if (!$q->ok) {
        json_error_show($q->mysql_error);
    }
    if (mysql_num_rows($results) == 0) {
        json_error_show("no data");
    }
    $data = array();
    $data['page'] = $page;
    $data['total'] = $total;
    $data['rows'] = array();
    $GroupType = $q->acl_GroupType;
    $GroupType["src"] = "{addr}";
    $GroupType["arp"] = "{ComputerMacAddress}";
    $GroupType["dstdomain"] = "{dstdomain}";
    $GroupType["proxy_auth"] = "{members}";
    $GroupType["port"] = "{remote_ports}";
    $GroupType["maxconn"] = "{max_connections}";
    $font_size = "15px";
    $delet_img = "delete-24.png";
    if (isset($_GET["as-big"])) {
        $font_size = "26px;";
        $delet_img = "delete-42.png";
    }
    while ($ligne = mysql_fetch_assoc($results)) {
        $val = 0;
        $ligne2['tcount'] = 0;
        $disable = Field_checkbox("groupid_{$ligne['ID']}", 1, $ligne["enabled"], "EnableDisableGroup('{$ligne['ID']}')");
        $ligne['GroupName'] = utf8_encode($ligne['GroupName']);
        $GroupTypeText = $tpl->_ENGINE_parse_body($GroupType[$ligne["GroupType"]]);
        $delete = imgsimple($delet_img, null, "DeleteSquidAclGroup('{$ligne['ID']}')");
        if ($ligne["GroupType"] == "proxy_auth_ads") {
            $p = new external_ad_search();
            $ligne2['tcount'] = $p->CountDeUsersByGroupName($ligne['GroupName']);
        }
        if ($ligne["GroupType"] == "proxy_auth_statad") {
            $p = new external_ad_search();
            $ligne2['tcount'] = $p->CountDeUsersByGroupName($ligne['GroupName']);
        }
        if ($ligne["GroupType"] == "proxy_auth_ldap") {
            $p = new ldap_extern();
            preg_match("#^ExtLDAP:(.+?):(.+)#", $ligne['GroupName'], $re);
            $ligne['GroupName'] = $re[1];
            $DN = base64_decode($re[2]);
            $ligne2['tcount'] = $p->CountDeUsersByGroupDN($DN);
        }
        if ($ligne2['tcount'] == 0) {
            $ligne2 = mysql_fetch_array($q->QUERY_SQL("SELECT COUNT(ID) as tcount FROM webfilters_sqitems WHERE gpid='{$ligne['ID']}'"));
        }
        if ($ligne["GroupType"] == "all") {
            $ligne2['tcount'] = "*";
        }
        $CountOfRules = 0;
        $ligne3 = mysql_fetch_array($q->QUERY_SQL("SELECT COUNT(webfilters_sqacls.ID) as tcount FROM  webfilters_sqacllinks,webfilters_sqacls WHERE webfilters_sqacllinks.gpid='{$ligne['ID']}' AND webfilters_sqacllinks.aclid=webfilters_sqacls.ID"));
        $CountOfRules = $ligne3["tcount"];
        if ($CountOfRules > 0) {
            $CountOfRules = "<a href=\"javascript:blur();\"  OnClick=\"javascript:Loadjs('squid.acls.groups.rules.php?ID={$ligne['ID']}');\" style='font-size:{$font_size};text-decoration:underline'>{$CountOfRules}</a>";
        }
        $data['rows'][] = array('id' => "group{$ligne['ID']}", 'cell' => array("<a href=\"javascript:blur();\" \n\t\tOnClick=\"javascript:Loadjs('{$MyPage}?AddGroup-js=yes&ID={$ligne['ID']}');\" \n\t\tstyle='font-size:{$font_size};text-decoration:underline'>{$ligne['GroupName']}</span>", "<span style='font-size:{$font_size};'>{$GroupTypeText}</span>", "<center style='font-size:{$font_size};'>{$ligne2['tcount']}</center>", "<center style='font-size:{$font_size};'>{$CountOfRules}</center>", "<center>{$disable}</center>", "<center>{$delete}</center>"));
    }
    echo json_encode($data);
}
$GLOBALS["MACTUIDONLY"] = false;
$GLOBALS["uriToHost"] = array();
$GLOBALS["SESSION_TIME"] = array();
$GLOBALS["LDAP_TIME_LIMIT"] = 10;
$GLOBALS["BASENAME"] = basename(__FILE__);
if (!isset($GLOBALS["DEBUG_GROUPS"])) {
    $GLOBALS["DEBUG_GROUPS"] = intval(@file_get_contents("/etc/artica-postfix/settings/Daemons/SquidExternalLDAPDebug"));
    if (!is_numeric($GLOBALS["DEBUG_GROUPS"])) {
        WLOG("[START]: DEBUG_GROUP not a numeric, define it to 0");
        $GLOBALS["DEBUG_GROUPS"] = 0;
    }
}
$GLOBALS["TIMELOG"] = 0;
$GLOBALS["QUERIES_NUMBER"] = 0;
$GLOBALS["TIMELOG_TIME"] = time();
$ldapext = new ldap_extern();
while (!feof(STDIN)) {
    $content = trim(fgets(STDIN));
    if ($content != null) {
        if ($GLOBALS["DEBUG_GROUPS"] > 0) {
            WLOG("receive content...\"{$content}\"");
        }
        $array = explode(" ", $content);
        $member = trim($array[0]);
        $member = str_replace("%20", " ", $member);
        $groupDN = $array[1];
        if (!preg_match("#ExtLDAP:(.+?):(.+)#", $groupDN, $re)) {
            WLOG("Wrong ACL pattern {$groupDN}");
            fwrite(STDOUT, "OK\n");
            continue;
        }
function popup_search()
{
    $icon = "user-32.png";
    $ldap = new ldap_extern();
    if (strpos(" {$_POST["query"]}", "*") == 0) {
        $_POST["query"] = "*{$_POST["query"]}*";
    }
    $_POST["query"] = str_replace("**", "*", $_POST["query"]);
    $_POST["query"] = str_replace("**", "*", $_POST["query"]);
    if (!is_numeric($_POST["rp"])) {
        $_POST["rp"] = 50;
    }
    $hash = $ldap->DNInfos($_GET["DN"]);
    if (!$ldap->ok) {
        json_error_show($ldap->ldap_error, 1);
    }
    if ($hash[0][$ldap->ldap_filter_group_attribute]["count"] == 0) {
        json_error_show("No item", 1);
    }
    $data = array();
    $data['page'] = 1;
    $data['total'] = $hash[0][$ldap->ldap_filter_group_attribute]["count"];
    $data['rows'] = array();
    if ($_POST["rp"] > $hash[0][$ldap->ldap_filter_group_attribute]["count"]) {
        $_POST["rp"] = $hash[0][$ldap->ldap_filter_group_attribute]["count"];
    }
    $attr = $ldap->ldap_filter_group_attribute;
    $searchstring = string_to_flexregex();
    $tz = 0;
    for ($i = 0; $i < $_POST["rp"]; $i++) {
        $member = $hash[0][$attr][$i];
        if (preg_match("#^uid=(.+?),#", $member, $re)) {
            $member = $re[1];
        }
        if ($searchstring != null) {
            if (!preg_match("#{$searchstring}#", $member)) {
                continue;
            }
        }
        $tz++;
        $js = "EditField{$_GET["t"]}('{$DN_base64}','{$GroupxSourceName}');";
        if ($_GET["MainFunction"] != null) {
            $js = "{$_GET["MainFunction"]}('{$dn}');YahooWinBrowseHide();";
        }
        $image = imgsimple($icon, null, $js);
        $select = imgsimple("arrow-right-32.png", null, $js);
        $md5 = md5($dn);
        $data['rows'][] = array('id' => $md5, 'cell' => array("<center>{$image}</center>", "<span style='font-size:20px;'>{$member}</a></span>", "<center></center>"));
    }
    $data['total'] = $tz;
    echo json_encode($data);
}