function save() { $_POST["mac"] = str_replace("-", ":", $_POST["mac"]); $_POST["mac"] = strtolower($_POST["mac"]); $ipClass = new IP(); if (!$ipClass->IsvalidMAC($_POST["mac"])) { echo "MAC: {$_POST["mac"]} Invalid!\n"; return; } if (!$ipClass->isValid($_POST["ipaddr"])) { echo "MAC: {$_POST["ipaddr"]} Invalid!\n"; return; } $cmp = new computers(); $uid = $cmp->ComputerIDFromMAC($_POST["mac"]); if ($uid != null) { $cmp = new computers($uid); } if ($uid == null) { $uid = "{$_POST["hostname"]}\$"; } $cmp->uid = $uid; $cmp->ComputerIP = $_POST["ipaddr"]; $cmp->ComputerMacAddress = $_POST["mac"]; $cmp->ComputerRealName = $_POST["hostname"]; if ($cmp->Add()) { echo $cmp->ldap_error; } }
function delete_computer_js() { $page = CurrentPageName(); $t = time(); if (!is_numeric($_GET["t"])) { $_GET["t"] = 0; } header("content-type: application/x-javascript"); $MAC = $_GET["MAC"]; $tpl = new templates(); $IpClass = new IP(); if (!$IpClass->IsvalidMAC($MAC)) { $error = $tpl->javascript_parse_text("{invalid_mac_address}"); echo "alert('{$error} \"{$MAC}\"');"; return; } $delete = $tpl->javascript_parse_text("{delete}"); $html = "\nvar xSave{$t}= function (obj) {\n\tvar t={$_GET["t"]};\n\tvar results=obj.responseText;\n\tif(results.length>3){alert(results);return;}\n\tif(t>0){\n\t\t\$('#flexRT{$_GET["t"]}').flexReload();\n\t}\n}\n\t\nfunction Save{$t}(){\n\tif(!confirm('{$delete} {$MAC} ?')){return;}\n\tvar XHR = new XHRConnection();\n\tXHR.appendData('delete-computer','{$MAC}');\n\tXHR.sendAndLoad('{$page}', 'POST',xSave{$t});\n}\nSave{$t}();\n"; echo $html; }
function list1() { $page = 1; $tpl = new templates(); $influx = new influx(); $q = new postgres_sql(); $USER_FIELD = $_GET["user"]; $search = $_GET["search"]; if ($search == null) { $search = "*"; } $table = "access_log"; if (!isset($_POST["rp"])) { $_POST["rp"] = 100; } $from = date("Y-m-d H:i:s", strtotime("-2 hour")); if (isset($_POST["sortname"])) { if ($_POST["sortname"] != null) { $ORDER = "ORDER BY {$_POST["sortname"]} {$_POST["sortorder"]}"; } } if ($GLOBALS["VERBOSE"]) { echo "string_to_flexPostGresquery\n"; } $searchstring = string_to_flexPostGresquery(); $searchstringORG = $searchstring; if ($searchstring != null) { $sql = "SELECT COUNT(*) as tcount FROM {$table} WHERE {$searchstring}"; if ($GLOBALS["VERBOSE"]) { echo "{$sql}\n"; } $ligne = @pg_fetch_assoc($q->QUERY_SQL($sql)); if (!$q->ok) { json_error_show($q->mysql_error); } $total = $ligne["tcount"]; } else { $sql = "SELECT COUNT(*) as tcount FROM {$table}"; if ($GLOBALS["VERBOSE"]) { echo "{$sql}\n"; } $ligne = @pg_fetch_assoc($q->QUERY_SQL($sql)); $total = $ligne["tcount"]; if (!$q->ok) { json_error_show($q->mysql_error); } if ($GLOBALS["VERBOSE"]) { echo "COUNT: {$total}\n"; } } if (isset($_POST['rp'])) { $rp = $_POST['rp']; } $pageStart = ($page - 1) * $rp; if (is_numeric($rp)) { $limitSql = "LIMIT {$rp} OFFSET {$pageStart} "; } if ($searchstring != null) { $searchstring = " AND {$searchstring}"; } $sql = "SELECT * FROM access_log WHERE zdate > '{$from}' {$searchstring} {$ORDER} {$limitSql}"; if ($GLOBALS["VERBOSE"]) { echo "{$sql}\n"; } $data = array(); $data['page'] = $page; $data['total'] = $total; $data['rows'] = array(); $results = $q->QUERY_SQL($sql); if (!$q->ok) { json_error_show($q->mysql_error); } $SumoF = @pg_num_rows($results); if ($SumoF == 0) { json_error_show("no data {$sql}"); } $c = 0; $fontsize = "18px"; $color = null; $curday = date("Y-m-d"); $ipClass = new IP(); while ($ligne = pg_fetch_assoc($results)) { $USER = trim($ligne["userid"]); $size = intval($ligne["size"]); if ($size == 0) { continue; } $time = $ligne["zdate"]; $CATEGORY = $ligne["category"]; $SITE = $ligne["familysite"]; $RQS = $ligne["rqs"]; $MAC_link = null; $MAC = $ligne["mac"]; $IPADDR = $ligne["ipaddr"]; $size = FormatBytes($size / 1024); $RQS = FormatNumber($RQS); if ($ipClass->IsvalidMAC($MAC)) { $MAC_link = "<a href=\"javascript:blur();\"\n\t\t\tOnClick=\"javascript:Loadjs('squid.nodes.php?node-infos-js=yes&MAC=" . urlencode($MAC) . "');\"\n\t\t\t\t\tstyle='font-size:{$fontsize};text-decoration:underline'>\n\t\t\t\t\t"; } $time = str_replace($curday, "", $time); if ($ipClass->isValid($SITE)) { $SITE = "<a href=\"https://db-ip.com/{$SITE}\" style='text-decoration:underline;color:black' target=_new>{$SITE}</a>"; } $data['rows'][] = array('id' => $c, 'cell' => array("<span style='font-size:{$fontsize}'>{$time}</a></span>", "<span style='font-size:{$fontsize}'>{$SITE}</a></span>", "<span style='font-size:{$fontsize}'>{$CATEGORY}</a></span>", "<span style='font-size:{$fontsize}'>{$MAC_link}{$MAC}</a></span>", "<span style='font-size:{$fontsize}'>{$IPADDR}</a></span>", "<span style='font-size:{$fontsize}'>{$USER}</a></span>", "<span style='font-size:{$fontsize}'>{$RQS}</a></span>", "<span style='font-size:{$fontsize}'>{$size}</a></span>")); } echo json_encode($data); return; }
function remove_MAC_sessions($mac) { $ipClass = new IP(); if (!$ipClass->IsvalidMAC($mac)) { if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} invalid mac address: {$mac}\n"; } return; } $unix = new unix(); $tmp = $unix->TEMP_DIR(); $iptables_save = $unix->find_program("iptables-save"); $iptables_restore = $unix->find_program("iptables-restore"); if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} {$GLOBALS["CACHE_FILE"]}\n"; } shell_exec("{$iptables_save} > {$GLOBALS["CACHE_FILE"]}"); $data = file_get_contents($GLOBALS["CACHE_FILE"]); $datas = explode("\n", $data); $pattern = "#{$mac}#i"; $c = 0; $MAIN = array(); while (list($num, $ligne) = each($datas)) { if ($ligne == null) { continue; } if (preg_match($pattern, $ligne)) { $c++; continue; } $MAIN[] = $ligne; } $t = time(); file_put_contents("{$tmp}/{$t}.conf", @implode("\n", $MAIN)); system("{$iptables_restore} < {$tmp}/{$t}.conf"); @unlink("{$tmp}/{$t}.conf"); shell_exec("{$iptables_save} > {$GLOBALS["CACHE_FILE"]}"); }
function MAC_TO_NAME($MAC = null) { if ($MAC == "00:00:00:00:00:00") { return null; } if ($MAC == null) { return null; } include_once dirname(__FILE__) . "/class.tcpip.inc"; $ip = new IP(); $tt = array(); if (!$ip->IsvalidMAC($MAC)) { return null; } $ligne = mysql_fetch_array($this->QUERY_SQL("SELECT uid FROM `webfilters_nodes` WHERE `MAC`='{$MAC}'")); if ($ligne["uid"] != null) { return $ligne["uid"]; } $results = $this->QUERY_SQL("SELECT hostname FROM `UserAutDB` WHERE `MAC`='{$MAC}' AND LENGTH(hostname)>0"); while ($ligne = mysql_fetch_assoc($results)) { $tt[$ligne["hostname"]] = $ligne["hostname"]; } if (count($tt) > 0) { return @implode(",", $tt); } }
function wifidog_login($error = null) { header('Content-Type: text/html; charset=iso-8859-1'); $REMOTE_ADDR = $_SERVER["REMOTE_ADDR"]; session_start(); $ipClass = new IP(); $USE_TERMS_ACCEPTED = false; $gateway_addr = $_REQUEST["gw_address"]; $gw_port = $_REQUEST["gw_port"]; $gw_id = $_REQUEST["gw_id"]; $ARP = $_REQUEST["mac"]; $url = $_REQUEST["url"]; $cachefile = "{$GLOBALS["CACHEDIR"]}/{$ARP}." . md5($error . serialize($_REQUEST)) . "." . __FUNCTION__ . ".html"; if (isset($_POST["wifidog-terms"])) { $_SESSION["USE_TERMS_ACCEPTED"] = true; $USE_TERMS_ACCEPTED = true; } if (isset($_SESSION["USE_TERMS_ACCEPTED"])) { $USE_TERMS_ACCEPTED = true; } if (isset($_GET["clear"])) { unset($_SESSION["WIFIDOG_RULES"]); } if (!$ipClass->IsvalidMAC($ARP)) { $CacheError1 = "{$GLOBALS["CACHEDIR"]}/hostspot_network_incompatible.html"; if (!is_file($CacheError1)) { $tpl = new templates(); $text_form = $tpl->_ENGINE_parse_body(FATAL_ERROR_SHOW_128("{hostspot_network_incompatible}")); @file_put_contents($CacheError1, $text_form); } else { $text_form = @file_get_contents($CacheError1); } } if (!isset($_REQUEST["token"])) { $_REQUEST["token"] = generateToken($ARP); } $wifidog_build_uri = wifidog_build_uri(); $uriext = $wifidog_build_uri[0]; $HiddenFields = $wifidog_build_uri[1]; $wifidog_templates = new wifidog_rules(); $_SESSION["WIFIDOG_RULES"] = $wifidog_templates->ruleid; if ($GLOBALS["HOTSPOT_DEBUG"]) { wifidog_logs("Rule number {$_SESSION["WIFIDOG_RULES"]}", __FUNCTION__, __LINE__); } $wifidog_rule = new wifidog_settings($_SESSION["WIFIDOG_RULES"]); $ArticaHotSpotNowPassword = intval($wifidog_rule->GET_INFO("ArticaHotSpotNowPassword")); $ENABLED_REDIRECT_LOGIN = intval($wifidog_rule->GET_INFO("ENABLED_REDIRECT_LOGIN")); $ENABLED_SMTP = intval($wifidog_rule->GET_INFO("ENABLED_SMTP")); $ENABLED_AUTO_LOGIN = intval($wifidog_rule->GET_INFO("ENABLED_AUTO_LOGIN")); $USE_TERMS = intval($wifidog_rule->GET_INFO("USE_TERMS")); $ALLOW_RECOVER_PASS = intval($wifidog_rule->GET_INFO("ALLOW_RECOVER_PASS")); $DO_NOT_AUTENTICATE = intval($wifidog_rule->GET_INFO("DO_NOT_AUTENTICATE")); $SMS_REGISTER = intval($wifidog_rule->GET_INFO("SMS_REGISTER")); $BOUNCE_AUTH = intval($wifidog_rule->GET_INFO("BOUNCE_AUTH")); if ($BOUNCE_AUTH == 1) { if ($ARP != null) { $CacheARP = "{$GLOBALS["CACHEDIR"]}/{$ARP}"; $ligne["uid"] = null; if (is_file($CacheARP)) { if (file_time_min_Web($CacheARP) > 15) { @unlink($CacheARP); } } if (!is_file($CacheARP)) { $q = new mysql_hotspot(); $sql = "SELECT * FROM hotspot_members WHERE MAC='{$ARP}'"; $ligne = mysql_fetch_array($q->QUERY_SQL($sql)); $uid = $ligne["uid"]; } else { $ligne["uid"] = @file_get_contents($CacheARP); } if ($ligne["uid"] != null) { $array["LOGIN"] = $ligne["uid"]; $array["IPADDR"] = null; $array["MAC"] = $ARP; $array["ARP"] = $ARP; $array["token"] = $_REQUEST["token"]; $array["ruleid"] = $_SESSION["WIFIDOG_RULES"]; if (UnLock($array)) { wifidog_redirect_after_login(); return; } } } } if ($USE_TERMS == 1) { if (!$USE_TERMS_ACCEPTED) { if ($GLOBALS["HOTSPOT_DEBUG"]) { wifidog_logs("->wifidog_terms()", __FUNCTION__, __LINE__); } return wifidog_terms($ARP); } } $wifidog_templates = new wifidog_templates($_SESSION["WIFIDOG_RULES"]); if ($SMS_REGISTER == 1) { if ($GLOBALS["HOTSPOT_DEBUG"]) { wifidog_logs("->wifidog_register_sms()", __FUNCTION__, __LINE__); } wifidog_register_sms(); return; } if ($ENABLED_SMTP == 1) { if ($ENABLED_REDIRECT_LOGIN == 1) { wifidog_register(); return; } } if (is_file($cachefile)) { echo @file_get_contents($cachefile); return; } $page = CurrentPageName(); $tpl = new templates(); $username = $wifidog_templates->LabelUsername; $password = $wifidog_templates->LabelPassword; $lost_password_text = $wifidog_templates->LostPasswordLink; $please_sign_in = $tpl->_ENGINE_parse_body("{please_sign_in}"); $page = CurrentPageName(); $t = time(); unset($_SESSION["HOTSPOT_AUTO_RECOVER"]); $_SESSION["HOTSPOT_REDIRECT_URL"] = $url; $url_encoded = urlencode($url); if ($DO_NOT_AUTENTICATE == 1) { $ArticaHotSpotNowPassword = 1; } $f[] = "<p>{$wifidog_templates->WelcomeMessage}</p>"; $f[] = "<div id='content'>"; $f[] = ""; $f[] = "<form id='wifidogform' action=\"{$page}\" method=\"post\">"; $f[] = "<input type=\"hidden\" name=\"ruleid\" id=\"ruleid\" value='{$_SESSION["WIFIDOG_RULES"]}'>"; $f[] = "{$HiddenFields}"; if ($wifidog_templates->FORM_HEAD != null) { $f[] = "<p>{$wifidog_templates->FORM_HEAD}</p>"; } $f[] = "<table style='width:100%'>"; $f[] = "<tr>"; $f[] = "<td class=legend>{$username}:</td>"; $f[] = "<td>\n\t<input type=\"text\" \n\t\tname=\"username\" \n\t\tid=\"username\"\n\t\tvalue=\"{$_REQUEST["username"]}\" \n\t\tonfocus=\"this.setAttribute('class','active');RemoveLogonCSS();\" \n\t\tonblur=\"this.removeAttribute('class');\" \n\t\tOnKeyPress=\"javascript:SendLogon{$t}(event)\">"; $f[] = "</td>"; $f[] = "</tr>"; if ($ArticaHotSpotNowPassword == 0) { $f[] = "<tr>"; $f[] = "<td class=legend>{$password}:</td>"; $f[] = "<td><input type=\"password\" name=\"password\" \n\t\t\t\tvalue=\"{$_REQUEST["password"]}\"\n\t\t\t\tid=\"password\" onfocus=\"this.setAttribute('class','active');RemoveLogonCSS();\" \n\t\t\t\tonblur=\"this.removeAttribute('class');\" OnKeyPress=\"javascript:SendLogon{$t}(event)\">"; $f[] = "</td>"; $f[] = "</tr>"; } else { $f[] = "<input type=\"hidden\" name=\"password\" id=\"password\" value=''>"; } $f[] = "<tr><td colspan=2> </td></tr>"; $f[] = "<tr><td colspan=2 align='right' class=ButtonCell>"; if ($ENABLED_AUTO_LOGIN == 1) { $f[] = "<a data-loading-text=\"Chargement...\"\n\t\tstyle=\"text-transform:capitalize\"\n\t\tclass=\"Button2014 Button2014-success Button2014-lg\"\n\t\tid=\"fb92ae5e1f7bbea3b5044cbcdd40f088\"\n\t\thref=\"{$page}?wifidog-register=yes&{$uriext}\">« {$wifidog_templates->RegisterTitle} »</a>"; } $f[] = "<a data-loading-text=\"Chargement...\" \n\t\t\tstyle=\"text-transform:capitalize\" \n\t\t\tclass=\"Button2014 Button2014-success Button2014-lg\" \n\t\t\tid=\"fb92ae5e1f7bbea3b5044cbcdd40f088\" \n\t\t\tonclick=\"javascript:document.forms['wifidogform'].submit();\" \n\t\t\thref=\"javascript:Blurz()\">« " . $wifidog_templates->char($wifidog_templates->ConnectionButton) . " »</a>"; $f[] = "</td>\n\t</tr>"; if ($ENABLED_SMTP == 1) { if ($ALLOW_RECOVER_PASS == 1) { if ($ArticaHotSpotNowPassword == 0) { $f[] = "<tr><td class=legend colspan=2>"; $f[] = "<a href=\"{$page}?wifidog-recover=yes&email={$_REQUEST["username"]}&{$uriext}\">{$lost_password_text}</a></div>"; $f[] = "</td></tr>"; } } } $f[] = "</table>"; $f[] = "\t\t\t</form>\t"; $f[] = "</div>\n\t<script>\n\t\tfunction SendLogon{$t}(e){\n\t\t\tif(!checkEnter(e)){return;}\n\t\t\tdocument.forms['wifidogform'].submit();\n\t\t}\n\t</script>\n\t\n"; $text_form = @implode("\n", $f); $page = BuildFullPage($text_form, $error); @file_put_contents($cachefile, $page); echo $page; }
function list1() { $page = CurrentPageName(); $tpl = new templates(); $influx = new influx(); $q = new mysql_squid_builder(); $USER_FIELD = $_GET["user"]; $search = $_GET["search"]; if ($search == null) { $search = "*"; } $from = strtotime("{$_GET["date1"]} {$_GET["time1"]}"); if (!isset($_GET["date1"])) { $from = strtotime("-1 hour"); } if (isset($_POST["qtype"])) { if ($_POST["query"] != null) { $search = str_replace("*", ".*", $_POST["query"]); $search_query = "AND {$_POST["qtype"]} =~ /{$search}/"; } } $to = strtotime("{$_GET["date2"]} {$_GET["time2"]}"); $md5_table = md5("{$from}{$to}{$USER_FIELD}"); $_SESSION["SQUID_STATS_MEMBER_SEARCH"] = $search; $Maxlines = $_GET["Maxlines"]; $_SESSION["SQUID_STATS_MAX_LINES"] = $Maxlines; if ($search != "*") { //$search_query="AND (SITE =~ /$search/ or $USER_FIELD =~ /$search/)"; } $totext = "and time < {$to}s"; if (!isset($_POST["rp"])) { $_POST["rp"] = 100; } if ($from == $to) { $totext = null; } $totext = null; $sql = "SELECT * from access_log WHERE time > {$from}s {$totext} {$search_query} ORDER BY ASC LIMIT {$_POST["rp"]}"; $main = $influx->QUERY_SQL($sql); $data = array(); $data['page'] = 1; $data['total'] = 0; $data['rows'] = array(); $c = 0; $fontsize = "18px"; $color = null; $ipClass = new IP(); foreach ($main as $row) { $USER = trim($row->USERID); if ($row->SIZE == 0) { continue; } $time = date("H:i:00", InfluxToTime($row->time)); $CURTIME = strtotime($time); $CATEGORY = $row->CATEGORY; $SITE = $row->SITE; $RQS = $row->RQS; $MAC_link = null; $MAC = $row->MAC; $IPADDR = $row->IPADDR; $USER = trim($row->USERID); $SIZE = $row->SIZE; $MD5 = md5("{$time}{$MAC}{$IPADDR}{$USER}{$SITE}"); if (!isset($MAIN[$CURTIME][$MD5])) { $MAIN[$CURTIME][$MD5]["TIME"] = $time; $MAIN[$CURTIME][$MD5]["RQS"] = $RQS; $MAIN[$CURTIME][$MD5]["MAC"] = $MAC; $MAIN[$CURTIME][$MD5]["IPADDR"] = $IPADDR; $MAIN[$CURTIME][$MD5]["USER"] = $USER; $MAIN[$CURTIME][$MD5]["SIZE"] = $SIZE; $MAIN[$CURTIME][$MD5]["SITE"] = $SITE; $MAIN[$CURTIME][$MD5]["CATEGORY"] = $CATEGORY; } else { $MAIN[$CURTIME][$MD5]["RQS"] = $MAIN[$MD5]["RQS"] + $RQS; $MAIN[$CURTIME][$MD5]["SIZE"] = $MAIN[$MD5]["SIZE"] + $SIZE; $MAIN[$CURTIME][$MD5]["CATEGORY"] = $CATEGORY; } } krsort($MAIN); while (list($curtime, $array0) = each($MAIN)) { while (list($MDKey, $array) = each($array0)) { $USER = trim($array["USER"]); if ($color == null) { $color = "#F2F0F1"; } else { $color = null; } $time = $array["TIME"]; $RQS = $array["RQS"]; $MAC_link = null; $SIZE = $array["SIZE"]; if ($SIZE > 1024) { $size = FormatBytes($SIZE / 1024); } else { $size = "{$SIZE} Bytes"; } $MAC = $array["MAC"]; $IPADDR = $array["IPADDR"]; $CATEGORY = $array["CATEGORY"]; $SITE = $array["SITE"]; $RQS = FormatNumber($RQS); $c++; if ($ipClass->IsvalidMAC($MAC)) { $MAC_link = "<a href=\"javascript:blur();\"\n\t\t\tOnClick=\"javascript:Loadjs('squid.nodes.php?node-infos-js=yes&MAC=" . urlencode($MAC) . "');\"\n\t\t\tstyle='font-size:{$fontsize};text-decoration:underline'>\t\t\n\t\t\t"; } if ($ipClass->isValid($SITE)) { $SITE = "<a href=\"https://db-ip.com/{$SITE}\" style='text-decoration:underline;color:black' target=_new>{$SITE}</a>"; } if ($c > $_POST["rp"]) { break; } $data['rows'][] = array('id' => $c, 'cell' => array("<span style='font-size:{$fontsize}'>{$time}</a></span>", "<span style='font-size:{$fontsize}'>{$SITE}</a></span>", "<span style='font-size:{$fontsize}'>{$CATEGORY}</a></span>", "<span style='font-size:{$fontsize}'>{$MAC_link}{$MAC}</a></span>", "<span style='font-size:{$fontsize}'>{$IPADDR}</a></span>", "<span style='font-size:{$fontsize}'>{$USER}</a></span>", "<span style='font-size:{$fontsize}'>{$RQS}</a></span>", "<span style='font-size:{$fontsize}'>{$size}</a></span>")); } } $data['total'] = $c; echo json_encode($data); return; }
function items(){ $tpl=new templates(); $MyPage=CurrentPageName(); $q=new mysql_squid_builder(); $t=$_GET["t"]; $search='%'; $table="UserAuthDaysGrouped"; $page=1; $FORCE_FILTER=null; $total=0; if(isset($_POST["sortname"])){if($_POST["sortname"]<>null){$ORDER="ORDER BY {$_POST["sortname"]} {$_POST["sortorder"]}";}} if(isset($_POST['page'])) {$page = $_POST['page'];} $searchstring=string_to_flexquery(); if($searchstring<>null){ $sql="SELECT COUNT(*) as TCOUNT FROM $table WHERE 1 $FORCE_FILTER $searchstring"; $ligne=mysql_fetch_array($q->QUERY_SQL($sql)); $total = $ligne["TCOUNT"]; }else{ $total = $q->COUNT_ROWS("UserAuthDaysGrouped"); } if (isset($_POST['rp'])) {$rp = $_POST['rp'];} $pageStart = ($page-1)*$rp; if(is_numeric($rp)){$limitSql = "LIMIT $pageStart, $rp";} $sql="SELECT * FROM $table WHERE 1 $searchstring $FORCE_FILTER $ORDER $limitSql"; $results = $q->QUERY_SQL($sql); $data = array(); $data['page'] = $page; $data['total'] = $total; $data['rows'] = array(); if(!$q->ok){json_error_show($q->mysql_error."<br>$sql");} if(mysql_num_rows($results)==0){json_error_show("no data");} $fontsize="16"; //ipaddr | hostname | uid | MAC | account | QuerySize | hits $IpClass=new IP(); while ($ligne = mysql_fetch_assoc($results)) { $color="black"; $md=md5(serialize($ligne)); $ligne["QuerySize"]=FormatBytes($ligne["QuerySize"]/1024); $ligne["hits"]=FormatNumber($ligne["hits"]); $uiduri="<a href=\"javascript:Loadjs('squid.members.zoom.php?field=uid&value=".urlencode($ligne["uid"])."')\" style='font-size:{$fontsize}px;color:$color;text-decoration:underline'>"; $macencode=urlencode($ligne["MAC"]); $MACUri="<a href=\"javascript:Loadjs('squid.nodes.php?node-infos-js=yes&MAC=$macencode',true);\" style='font-size:{$fontsize}px;color:$color;text-decoration:underline'>"; if(!$IpClass->IsvalidMAC($ligne["MAC"])){$MACUri=null;} $data['rows'][] = array( 'id' => $ligne['ID'], 'cell' => array( "<span style='font-size:{$fontsize}px;color:$color'>{$ligne["ipaddr"]}</span>", "<span style='font-size:{$fontsize}px;color:$color'>{$ligne["hostname"]}</span>", "<span style='font-size:{$fontsize}px;color:$color'>$uiduri{$ligne["uid"]}</a></span>", "<span style='font-size:{$fontsize}px;color:$color'>$MACUri{$ligne["MAC"]}</a></span>", "<span style='font-size:{$fontsize}px;color:$color'>{$ligne["QuerySize"]}</span>", "<span style='font-size:{$fontsize}px;color:$color'>{$ligne["hits"]}</span>", ) ); } echo json_encode($data); }
function xqueries() { $page = CurrentPageName(); $tpl = new templates(); $influx = new influx(); $sql = "SELECT MAX(ZDATE) AS MAX FROM access_log"; $main = $influx->QUERY_SQL($sql); $MAX = $main[0]->MAX; $LastEntry = $tpl->time_to_date($MAX, true); if ($GLOBALS["VERBOSE"]) { echo "<p style='color:blue'>{$MAX} -> {$LastEntry}</p>"; } $from_gmt = $tpl->time_to_date($MAX - 300, true); $from = QueryToUTC($MAX - 300); $fromTime = date("Y-m-d H:i:s", $from); $ToTime = date("Y-m-d H:i:s", QueryToUTC($MAX)); $sql = "SELECT * from access_log WHERE time > '{$fromTime}' AND time < '{$ToTime}'"; //echo "<hr>$sql</HR>"; $main = null; $influx2 = new influx(); $QUERY2 = $influx2->QUERY_SQL($sql); $color = null; $ipClass = new IP(); $q = new mysql_squid_builder(); $c = 0; $D = 0; foreach ($QUERY2 as $row) { $USER = trim($row->USERID); $IPADDR = trim($row->IPADDR); $MAC = trim($row->MAC); if ($row->SIZE == 0) { continue; } if (is_numeric($USER)) { continue; } $RQS = $row->RQS; $time = InfluxToTime($row->time); $DATEKEY = date("H:00", $time); $KEYMD5 = md5("{$USER}{$IPADDR}{$MAC}"); $c = $c + $RQS; $D = $D + $row->SIZE; if (!isset($MAIN[$DATEKEY][$KEYMD5])) { $MAIN[$DATEKEY][$KEYMD5]["USER"] = $USER; $MAIN[$DATEKEY][$KEYMD5]["IPADDR"] = $IPADDR; $MAIN[$DATEKEY][$KEYMD5]["MAC"] = $MAC; $MAIN[$DATEKEY][$KEYMD5]["SIZE"] = $row->SIZE; $MAIN[$DATEKEY][$KEYMD5]["RQS"] = $RQS; } else { $MAIN[$DATEKEY][$KEYMD5]["SIZE"] = $MAIN[$DATEKEY][$KEYMD5]["SIZE"] + $row->SIZE; $MAIN[$DATEKEY][$KEYMD5]["RQS"] = $MAIN[$DATEKEY][$KEYMD5]["RQS"] + $RQS; } } $D = FormatBytes($D / 1024); $requests = $tpl->javascript_parse_text("{requests}"); $last_entry_on = $tpl->javascript_parse_text("{last_entry_on}"); $since = $tpl->_ENGINE_parse_body("{since}"); $html[] = "\n\t\n\t<div style='width:98%' class=form>\n\t<div style='margin-top:5px;font-size:16px;text-align:right;margin-bottom:15px;font-weight:bold'>\n\t\t{$since} 5mn ({$c} {$requests} / {$D}) UTC:" . $tpl->time_to_date($from, true) . " - GMT {$from_gmt} / {$last_entry_on}: {$LastEntry}</div>"; $html[] = "\n\t\t\n\t<table style='width:100%'>"; $html[] = $tpl->_ENGINE_parse_body("<tr>\n\t\t\t<th style='font-size:18px'>{time}</th>\n\t\t\t<th style='font-size:18px'>{MAC}</th>\n\t\t\t<th style='font-size:18px'>{ipaddr}</th>\n\t\t\t<th style='font-size:18px'>{uid}</th>\n\t\t\t<th style='font-size:18px'>{requests}</th>\n\t\t\t<th style='font-size:18px'>{size}</th>\n\t\t\t</tr>\n\t\t\t"); while (list($time, $SUBARRAY) = each($MAIN)) { while (list($KEYMD5, $BIGARRAY) = each($SUBARRAY)) { if ($color == null) { $color = "#F2F0F1"; } else { $color = null; } $MAC = $BIGARRAY["MAC"]; $RQS = $BIGARRAY["RQS"]; $SIZE = $BIGARRAY["SIZE"]; $USER = $BIGARRAY["USER"]; $IPADDR = $BIGARRAY["IPADDR"]; $MAC_link = null; if ($SIZE > 1024) { $size = FormatBytes($SIZE / 1024); } else { $size = "{$SIZE}Bytes"; } $RQS = FormatNumber($RQS); if ($ipClass->IsvalidMAC($MAC)) { $MAC_link = "<a href=\"javascript:blur();\"\n\t\t\tOnClick=\"javascript:Loadjs('squid.nodes.php?node-infos-js=yes&MAC=" . urlencode($MAC) . "');\"\n\t\t\tstyle='font-size:16px;text-decoration:underline;font-weight:bold'>\t\t\n\t\t\t"; if (trim($USER) == null) { $USER = $q->MacToUid($MAC); } } $html[] = "<tr style='background-color:{$color}'>"; $html[] = "<td style='font-size:16px;width:50px;padding:10px;font-weight:bold'>{$time}</td>"; $html[] = "<td style='font-size:16px;width:50px;padding:10px;font-weight:bold'>{$MAC_link}{$MAC}</a></td>"; $html[] = "<td style='font-size:16px;width:50px;padding:10px;font-weight:bold'>{$IPADDR}</td>"; $html[] = "<td style='font-size:16px;width:50px;padding:10px;font-weight:bold'>{$USER}</td>"; $html[] = "<td style='font-size:16px;width:50px;text-align:right;padding:10px' nowrap>{$RQS}</td>"; $html[] = "<td style='font-size:16px;width:50px;text-align:right;padding:10px' nowrap>{$size}</td>"; $html[] = "</tr>"; } } $html[] = "</table>"; $html[] = "</div>"; $html[] = "\n\t<script>\n\t\tfunction FollowerRefresh(){\n\t\t\tif(!document.getElementById('ZRTRQUESTS_COMPTER')){ return;}\n\t\t\tvar compter=parseInt(document.getElementById('ZRTRQUESTS_COMPTER').value);\n\t\t\tif(compter<10){\n\t\t\t\tcompter=compter+1;\n\t\t\t\tdocument.getElementById('ZRTRQUESTS_COMPTER').value=compter;\n\t\t\t\tsetTimeout(\"FollowerRefresh()\",1000);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t\n\t\t\tdocument.getElementById('ZRTRQUESTS_COMPTER').value=0;\n\t\t\tif(!document.getElementById('proxy-follower-table')){ return;}\n\t\t\tLoadAjaxSilent('proxy-follower-table','{$page}?follow=yes&t={$_GET["t"]}');\n\t\t}\n\t\t\t\n\t\t\t\n\tsetTimeout(\"FollowerRefresh()\",1000);\n\t</script>"; echo @implode("\n", $html); }
function group_popup() { $page = CurrentPageName(); $q = new mysql_squid_builder(); $tpl = new templates(); $table = $_GET["table"]; $IP = trim($_GET["IP"]); $MAC = trim($_GET["MAC"]); $t = time(); $GROUPS[null] = "{select}"; $IPclass = new IP(); if ($MAC != null) { if ($IPclass->IsvalidMAC($MAC)) { $ligne = mysql_fetch_array($q->QUERY_SQL("SELECT * FROM webfilters_nodes WHERE MAC='{$MAC}'")); $member = $ligne["uid"]; $group = $ligne["group"]; $sql = "SELECT `group` FROM webfilters_nodes GROUP BY `group` ORDER BY `group`"; $results = $q->QUERY_SQL($sql, "artica_backup"); if (!$q->ok) { echo $q->mysql_error_html(); } while ($ligne2 = mysql_fetch_assoc($results)) { if (trim($ligne2["group"]) == null) { continue; } $GROUPS[$ligne2["group"]] = $ligne2["group"]; } $field = "\n\t\t\t<tr>\n\t\t\t\t<td class=legend style='font-size:26px'>{MAC}:</td>\n\t\t\t\t<td>" . Field_text("{$t}-ITEM", $MAC, "font-size:26px;width:260px", $MAC, null, null, false, "LinkUserStatsDBcHeck{$t}(event)") . "</td>\n\t\t\t</tr>\n\t\t\t"; } } if ($IP != null) { if ($member == null) { if ($IPclass->isValid($_GET["ipaddr"])) { $ligne = mysql_fetch_array($q->QUERY_SQL("SELECT * FROM webfilters_ipaddr WHERE ipaddr='{$IP}'")); $member = $ligne["uid"]; $group = $ligne["group"]; $sql = "SELECT `group` FROM webfilters_ipaddr GROUP BY `group` ORDER BY `group`"; $results = $q->QUERY_SQL($sql, "artica_backup"); if (!$q->ok) { echo $q->mysql_error_html(); } while ($ligne2 = mysql_fetch_assoc($results)) { if (trim($ligne2["group"]) == null) { continue; } $GROUPS[$ligne2["group"]] = $ligne2["group"]; } } } $field = "<tr>\n\t\t\t\t<td class=legend style='font-size:26px'>{ipaddr}:</td>\n\t\t\t\t<td>" . field_ipv4("{$t}-ITEM", $IP, "font-size:26px;width:250px", null, null, null, false, "LinkUserStatsDBcHeck{$t}(event)") . "</td>\n\t\t\t</tr>"; } $html = "<div id='div-{$t}' style='width:98%' class=form>\n<div style='font-size:30px;margin-bottom:20px'>{proxy_alias}: {$_GET["MAC"]} / {$_GET["ipaddr"]}</div>\n\t<table style='width:100%'>\n\t\t{$field}\n\t\t<tr>\n\t\t\t<td class=legend style='font-size:26px'>{alias}:</td>\n\t\t\t<td>" . Field_text("{$t}-uid", $member, "font-size:26px;width:550px", null, null, null, false, "LinkUserStatsDBcHeck{$t}(event)") . "</td>\n\t\t</tr>\n\t\t<tr>\n\t\t\t<td class=legend style='font-size:26px'>{group}:</td>\n\t\t\t<td>" . Field_array_Hash($GROUPS, "{$t}-group", $group, "style:font-size:26px;", null, null, null, false, "LinkUserStatsDBcHeck{$t}(event)") . "</td>\n\t\t</tr>\n\t\t<tr>\n\t\t\t<td class=legend style='font-size:26px'>{group} ({new}):</td>\n\t\t\t<td>" . Field_text("{$t}-group2", null, "font-size:26px;width:550px", null, null, null, false, "LinkUserStatsDBcHeck{$t}(event)") . "</td>\n\t\t</tr>\t\t\t\t\t\t\t\t\t\t\n\t\t<tr>\n\t\t\t<td colspan=2 align='right'><hr>" . button("{apply}", "LinkUserStatsDB{$t}()", 32) . "</td>\n\t\t</tr>\n\t</table>\n</div>\n<script>\nvar x_LinkUserStatsDB{$t}=function(obj){\n\tvar tempvalue=obj.responseText;\n\tif(tempvalue.length>3){alert(tempvalue);return;}\n\tYahooWinHide();\n\tif(document.getElementById('main_node_infos_tab')){RefreshTab('main_node_infos_tab');}\n\t\t\n\tif(document.getElementById('OCS_SEARCH_TABLE')){\n\t\tvar id=document.getElementById('OCS_SEARCH_TABLE').value;\n\t\t\$('#'+id).flexReload();\n\t}\n\tif(document.getElementById('PROXY_ALIASES_TABLE')){\n\t\t\$('#PROXY_ALIASES_TABLE').flexReload();\n\t}\n\t\t\n\tif(IsFunctionExists('RefreshNodesSquidTbl')){ RefreshNodesSquidTbl();}\n\tLoadjs('squid.macToUid.progress.php');\n}\n\t\t\nfunction LinkUserStatsDBcHeck{$t}(e){\n\tif(checkEnter(e)){LinkUserStatsDB{$t}();}\n}\n\t\t\nfunction LinkUserStatsDB{$t}(){\n\tvar XHR = new XHRConnection();\n\tXHR.appendData('uid',document.getElementById('{$t}-uid').value);\n\tXHR.appendData('group',document.getElementById('{$t}-group').value);\n\tXHR.appendData('group2',document.getElementById('{$t}-group2').value);\n\tXHR.appendData('item',document.getElementById('{$t}-ITEM').value);\n\tXHR.appendData('table','{$table}');\n\tXHR.sendAndLoad('{$page}', 'POST',x_LinkUserStatsDB{$t});\n}\n</script>\n\t\t\n\t\t"; echo $tpl->_ENGINE_parse_body($html); }
function node_infos_realtime_list() { $page = CurrentPageName(); $tpl = new templates(); $sock = new sockets(); $influx = new influx(); $from = strtotime('-1 hour'); if (isset($_POST['page'])) { $page = $_POST['page']; } if (isset($_POST['rp'])) { $rp = $_POST['rp']; } $ip = new IP(); if ($ip->isIPAddress($_GET["ipaddr"])) { $Select = "IPADDR"; $FORCE_FILTER = " IPADDR='{$_GET["ipaddr"]}'"; } if ($ip->IsvalidMAC($_GET["MAC"])) { $Select = "MAC"; $FORCE_FILTER = " MAC='{$_GET["MAC"]}'"; } $sql = "SELECT * FROM access_log where time >{$from}s and {$FORCE_FILTER} ORDER BY time DESC LIMIT {$rp}"; $data = array(); $data['page'] = $page; $data['total'] = 0; $data['rows'] = array(); $today = date("Y-m-d"); $tcp = new IP(); $main = $influx->QUERY_SQL($sql); $c = 0; foreach ($main as $row) { $color = "black"; $return_code_text = null; $ff = array(); $color = "black"; $uri = $row->SITE; $xtimelog = null; $date = date("H:i:s", InfluxToTime($row->time)); $mac = $row->MAC; $ip = $row->IPADDR; $user = $row->uid; $size = $row->SIZE; $rqs = $row->RQS; $ident = array(); $md = md5(serialize($row)); $c++; $spanON = "<span style='color:{$color};font-size:16px'>"; $spanOFF = "</span>"; $cached_text = null; $size = FormatBytes($size / 1024); $data['rows'][] = array('id' => $md, 'cell' => array("{$spanON}{$date}{$spanOFF}", "{$spanON}{$uri}{$spanOFF}", "{$spanON}{$rqs}{$spanOFF}", "{$spanON}{$size}{$spanOFF}")); } $data['total'] = $c; echo json_encode($data); }
function BANDWIDTH_MONITOR() { $sock = new sockets(); $SquidPerformance = intval($sock->GET_INFO("SquidPerformance")); if ($SquidPerformance > 1) { return; } $watchdog = new squid_watchdog(); $MonitConfig = $watchdog->MonitConfig; if ($MonitConfig["CHECK_BANDWITDH"] == 0) { return; } $CHECK_BANDWITDH_INTERVAL = $MonitConfig["CHECK_BANDWITDH_INTERVAL"]; $influx = new influx(); if (!is_numeric($CHECK_BANDWITDH_INTERVAL)) { $CHECK_BANDWITDH_INTERVAL = 5; } $olddate = strtotime("-{$CHECK_BANDWITDH_INTERVAL} minutes", time()); $CHECK_BANDWITDH_SIZE = intval($MonitConfig["CHECK_BANDWITDH_INTERVAL"]); $query_date = date("Y-m-d H:i:s", $olddate); $postgres = new postgres_sql(); $sql = "select sum(SIZE) as size from access_log where zdate > '{$olddate}'"; $ligne = @pg_fetch_assoc($postgres->QUERY_SQL($sql)); $size = $ligne["size"] / 1024; $size = round($size / 1024, 2); if ($GLOBALS["VERBOSE"]) { echo "Since " . date("Y-m-d H:i:s", $olddate) . "- Size: {$size}MB\n"; } if ($GLOBALS["VERBOSE"]) { echo "{$size}MB must be higher than {$CHECK_BANDWITDH_SIZE}MB\n"; } if ($size < $CHECK_BANDWITDH_SIZE) { return; } $EXCEED_SIZE = $size; $REPORT[] = "Report bandwidth usage since: " . date("{l} {F} d H:i:s", $olddate); $ipclass = new IP(); $sql = "select sum(size) as size,ipaddr,mac,userid from access_log where zdate > '{$olddate}' group by IPADDR,MAC,USERID order by size desc"; $results = $postgres->QUERY_SQL($sql); while ($ligne = @pg_fetch_assoc($results)) { $users2 = array(); $size = $ligne["size"] / 1024; $size = round($size / 1024, 2); if ($size == 0) { continue; } if ($size < 1) { continue; } if ($CHECK_BANDWITDH_SIZE > 1) { if ($size < 2) { continue; } } $IPADDR = $ligne["ipaddr"]; $users2[] = $IPADDR; $MAC = trim($ligne["mac"]); $USERID = $ligne["userid"]; if ($USERID != null) { $users2[] = $USERID; } if ($ipclass->IsvalidMAC($MAC)) { $users2[] = $MAC; } $REPORT[] = "User: "******", ", $users2) . " {$size}MB used"; if ($GLOBALS["VERBOSE"]) { echo "Since " . date("Y-m-d H:i:s", $olddate) . "- {$IPADDR},{$MAC},{$USERID} Size: {$size}MB\n"; } } $catz = new mysql_catz(); $sql = "select sum(SIZE) as size,familysite from access_log group by familysite where zdate > '{$olddate}' ORDER by size desc"; $results = $postgres->QUERY_SQL($sql); while ($ligne = @pg_fetch_assoc($results)) { $size = $ligne["size"] / 1024; $size = round($size / 1024, 2); if ($size == 0) { continue; } if ($size < 1) { continue; } $FAMILYSITE = $ligne["familysite"]; $category = $catz->GET_CATEGORIES($FAMILYSITE); if ($category != null) { $category_text = " (category:{$category})"; } $REPORT[] = "Web site: {$FAMILYSITE} {$size}MB used{$category_text}"; } squid_admin_mysql(0, "Bandwidth usage {$EXCEED_SIZE}MB exceed {$CHECK_BANDWITDH_SIZE}MB", @implode("\n", $REPORT), __FILE__, __LINE__); }
function node_infos_realtime_list(){ $page=CurrentPageName(); $tpl=new templates(); $sock=new sockets(); $q=new mysql_squid_builder(); $GLOBALS["Q"]=$q; $table="squidhour_".date("YmdH"); if(isset($_POST['page'])) {$page = $_POST['page'];} if(isset($_POST['rp'])) {$rp = $_POST['rp'];} $ip=new IP(); if($ip->isIPAddress($_GET["ipaddr"])){ $Select="ipaddr"; $FORCE_FILTER=" ipaddr='{$_GET["ipaddr"]}'"; } if($ip->IsvalidMAC($_GET["MAC"])){ $Select="MAC"; $FORCE_FILTER=" MAC='{$_GET["MAC"]}'"; } $searchstring=string_to_flexquery(); if($searchstring<>null){ $sql="SELECT COUNT(*) as TCOUNT FROM `$table` WHERE $FORCE_FILTER $searchstring"; $ligne=mysql_fetch_array($q->QUERY_SQL($sql)); $total = $ligne["TCOUNT"]; }else{ $sql="SELECT COUNT(*) as TCOUNT FROM `$table` WHERE $FORCE_FILTER"; $ligne=mysql_fetch_array($q->QUERY_SQL($sql)); $total = $ligne["TCOUNT"]; } if(!is_numeric($rp)){$rp=50;} $pageStart = ($page-1)*$rp; $limitSql = "LIMIT $pageStart, $rp"; if(isset($_POST["sortname"])){if($_POST["sortname"]<>null){$ORDER="ORDER BY {$_POST["sortname"]} {$_POST["sortorder"]}";}} $sql="SELECT * FROM `$table` WHERE $FORCE_FILTER $searchstring $ORDER $limitSql"; $results = $q->QUERY_SQL($sql); if(!$q->ok){json_error_show($q->mysql_error."\n$sql");} $data = array(); $data['page'] = $page; $data['total'] = $total; $data['rows'] = array(); $today=date("Y-m-d"); $tcp=new IP(); $cachedT=$tpl->_ENGINE_parse_body("{cached}"); $c=0; while ($ligne = mysql_fetch_assoc($results)) { $color="black"; $return_code_text=null; $ff=array(); $color="black"; $uri=$ligne["uri"]; $date=$ligne["zDate"]; $mac=$ligne["MAC"]; $ip=$ligne["CLIENT"]; $user=$ligne["uid"]; $dom=$ligne["sitename"]; $cached=$ligne["cached"]; $return_code=$ligne["TYPE"]; $size=$ligne["QuerySize"]; $ident=array(); $md=md5(serialize($ligne)); $today=date("Y-m-d"); $date=str_replace($today, "", $date); $spanON="<span style='color:$color'>"; $spanOFF="</span>"; $cached_text=null; if($cached==1){$cached_text=" - $cachedT";} $size=FormatBytes($size/1024); if($return_code=="Service Unavailable"){$color="#BA0000";} if($return_code=="Bad Gateway"){$color="#BA0000";} $return_code_text="<div style='color:$color;font-size:11px'><i>«$return_code»$cached_text - $size</i></div>"; $data['rows'][] = array( 'id' => $md, 'cell' => array( "$spanON$date$spanOFF", "$spanON$uri.$return_code_text$spanOFF", ) ); } echo json_encode($data); }
function BANDWIDTH_MONITOR() { $sock = new sockets(); $SquidPerformance = intval($sock->GET_INFO("SquidPerformance")); if ($SquidPerformance > 1) { return; } $watchdog = new squid_watchdog(); $MonitConfig = $watchdog->MonitConfig; if ($MonitConfig["CHECK_BANDWITDH"] == 0) { return; } $CHECK_BANDWITDH_INTERVAL = $MonitConfig["CHECK_BANDWITDH_INTERVAL"]; $influx = new influx(); if (!is_numeric($CHECK_BANDWITDH_INTERVAL)) { $CHECK_BANDWITDH_INTERVAL = 5; } $olddate = strtotime("-{$CHECK_BANDWITDH_INTERVAL} minutes", time()); $CHECK_BANDWITDH_SIZE = intval($MonitConfig["CHECK_BANDWITDH_INTERVAL"]); $sql = "select sum(SIZE) as size from access_log where time > {$olddate}s"; $main = $influx->QUERY_SQL($sql); foreach ($main as $row) { $size = $row->size / 1024; $size = round($size / 1024, 2); if ($GLOBALS["VERBOSE"]) { echo "Since " . date("Y-m-d H:i:s", $olddate) . "- Size: {$size}MB\n"; } } if ($GLOBALS["VERBOSE"]) { echo "{$size}MB must be higher than {$CHECK_BANDWITDH_SIZE}MB\n"; } if ($size < $CHECK_BANDWITDH_SIZE) { return; } $EXCEED_SIZE = $size; $REPORT[] = "Report bandwidth usage since: " . date("{l} {F} d H:i:s", $olddate); $ipclass = new IP(); $sql = "select sum(SIZE) as size,IPADDR,MAC,USERID from access_log group by IPADDR,MAC,USERID where time > {$olddate}s"; $main = $influx->QUERY_SQL($sql); foreach ($main as $row) { $users2 = array(); $size = $row->size / 1024; $size = round($size / 1024, 2); if ($size == 0) { continue; } if ($size < 1) { continue; } if ($CHECK_BANDWITDH_SIZE > 1) { if ($size < 2) { continue; } } $IPADDR = $row->IPADDR; $users2[] = $IPADDR; $MAC = trim($row->MAC); $USERID = trim($row->USERID); if ($USERID != null) { $users2[] = $USERID; } if ($ipclass->IsvalidMAC($MAC)) { $users2[] = $MAC; } $REPORT[] = "User: "******", ", $users2) . " {$size}MB used"; if ($GLOBALS["VERBOSE"]) { echo "Since " . date("Y-m-d H:i:s", $olddate) . "- {$IPADDR},{$MAC},{$USERID} Size: {$size}MB\n"; } } $catz = new mysql_catz(); $sql = "select sum(SIZE) as size,FAMILYSITE from access_log group by FAMILYSITE where time > {$olddate}s"; $main = $influx->QUERY_SQL($sql); foreach ($main as $row) { $size = $row->size / 1024; $size = round($size / 1024, 2); if ($size == 0) { continue; } if ($size < 1) { continue; } $FAMILYSITE = $row->FAMILYSITE; $category = $catz->GET_CATEGORIES($FAMILYSITE); if ($category != null) { $category_text = " (category:{$category})"; } $REPORT[] = "Web site: {$FAMILYSITE} {$size}MB used{$category_text}"; } squid_admin_mysql(0, "Bandwidth usage {$EXCEED_SIZE}MB exceed {$CHECK_BANDWITDH_SIZE}MB", @implode("\n", $REPORT), __FILE__, __LINE__); }
function mQuotaWebFilter() { $unix = new unix(); $pidfile = "/etc/artica-postfix/pids/exec.squid.stats.hours.php.mQuotaWebFilter.pid"; $timefile = "/etc/artica-postfix/pids/exec.squid.stats.hours.php.mQuotaWebFilter.time"; $sock = new sockets(); $SquidPerformance = intval($sock->GET_INFO("SquidPerformance")); if ($SquidPerformance > 1) { die; } $pid = $unix->get_pid_from_file($pidfile); if (!$GLOBALS["FORCE"]) { if ($pid < 100) { $pid = null; } $unix = new unix(); if ($unix->process_exists($pid, basename(__FILE__))) { $rpcessTime = $unix->PROCCESS_TIME_MIN($pid); if ($GLOBALS["VERBOSE"]) { echo "Already executed pid {$pid} since {$rpcessTime}Mn\n"; } if ($rpcessTime < 10) { return; } $unix->KILL_PROCESS($pid, 9); } $timeexec = $unix->file_time_min($timefile); if ($timeexec < 30) { return; } $mypid = getmypid(); @file_put_contents($pidfile, $mypid); } build_last_hour(); $ipClass = new IP(); if ($GLOBALS["VERBOSE"]) { echo "Time File: {$timefile}\n"; } $ARRAY["TIME_BUILD"] = time(); $q = new mysql_squid_builder(); $influx = new influx(); $date_from = InfluxQueryFromUTC(strtotime("-1 hour")); $sql = "SELECT SUM(SIZE) as size,USERID,IPADDR,MAC,CATEGORY FROM access_log GROUP BY time(1h) ,USERID,IPADDR,MAC,CATEGORY WHERE time > {$date_from}s"; if ($GLOBALS["VERBOSE"]) { echo "{$sql}\n"; } $main = $influx->QUERY_SQL($sql); foreach ($main as $row) { $CATEGORY = $row->CATEGORY; $USERID = strtolower($row->USERID); $IPADDR = $row->IPADDR; $MAC = $row->MAC; $size = intval($row->size); if ($size == 0) { continue; } if ($CATEGORY != null) { if (!isset($ARRAY["categories"][$CATEGORY]["HOUR"][$USERID])) { $ARRAY["categories"][$CATEGORY]["HOUR"][$USERID] = $size; } else { $size_old = intval($ARRAY["categories"][$CATEGORY]["HOUR"][$USERID]); $size_old = $size_old + $size; $ARRAY["categories"][$CATEGORY]["HOUR"][$USERID] = $size_old; } if (!isset($ARRAY["categories"][$CATEGORY]["HOUR"][$IPADDR])) { $ARRAY["categories"][$CATEGORY]["HOUR"][$IPADDR] = $size; } else { $size_old = $ARRAY["categories"][$CATEGORY]["HOUR"][$IPADDR]; $size_old = $size_old + $size; if ($size_old == 0) { echo "Warning {$CATEGORY}/{$IPADDR} {$ARRAY["categories"][$CATEGORY]["HOUR"][$IPADDR]} + {$size} = 0\n"; } $ARRAY["categories"][$CATEGORY]["HOUR"][$IPADDR] = $size_old; } if (!isset($ARRAY["categories"][$CATEGORY]["HOUR"][$MAC])) { $ARRAY["categories"][$CATEGORY]["HOUR"][$MAC] = $size; } else { $size_old = $ARRAY["categories"][$CATEGORY]["HOUR"][$MAC]; $size_old = $size_old + $size; $ARRAY["categories"][$CATEGORY]["HOUR"][$MAC] = $size_old; } } if (!isset($ARRAY["UID"][$USERID]["HOUR"])) { $ARRAY["UID"][$USERID]["HOUR"] = $size; } else { $size_old = $ARRAY["UID"][$USERID]["HOUR"]; $size_old = $size_old + $size; $ARRAY["UID"][$USERID]["HOUR"] = $size_old; } if (!isset($ARRAY["IPADDR"][$IPADDR]["HOUR"])) { $ARRAY["IPADDR"][$IPADDR]["HOUR"] = $size; } else { $size_old = $ARRAY["IPADDR"][$IPADDR]["HOUR"]; $size_old = $size_old + $size; $ARRAY["IPADDR"][$IPADDR]["HOUR"] = $size_old; } if ($ipClass->IsvalidMAC($MAC)) { if (!isset($ARRAY["MAC"][$MAC]["HOUR"])) { $ARRAY["MAC"][$MAC]["HOUR"] = $size; } else { $size_old = $ARRAY["MAC"][$MAC]["HOUR"]; $size_old = $size_old + $size; $ARRAY["MAC"][$MAC]["HOUR"] = $size_old; } } } //----------------------------------------------------------------------------------------------- $date_from = InfluxQueryFromUTC(strtotime("-1 day")); $sql = "SELECT SUM(SIZE) as size,USERID,IPADDR,MAC,CATEGORY FROM access_hour GROUP BY time(1d) ,USERID,IPADDR,MAC,CATEGORY WHERE time > {$date_from}s"; if ($GLOBALS["VERBOSE"]) { echo "{$sql}\n"; } $main = $influx->QUERY_SQL($sql); foreach ($main as $row) { $CATEGORY = $row->CATEGORY; $USERID = strtolower($row->USERID); $IPADDR = $row->IPADDR; $MAC = $row->MAC; $size = intval($row->size); if ($size == 0) { continue; } if ($CATEGORY != null) { if (!isset($ARRAY["categories"][$CATEGORY]["DAY"][$USERID])) { $ARRAY["categories"][$CATEGORY]["DAY"][$USERID] = $size; } else { $size_old = intval($ARRAY["categories"][$CATEGORY]["DAY"][$USERID]); $size_old = $size_old + $size; $ARRAY["categories"][$CATEGORY]["DAY"][$USERID] = $size_old; } if (!isset($ARRAY["categories"][$CATEGORY]["DAY"][$IPADDR])) { $ARRAY["categories"][$CATEGORY]["DAY"][$IPADDR] = $size; } else { $size_old = $ARRAY["categories"][$CATEGORY]["DAY"][$IPADDR]; $size_old = $size_old + $size; $ARRAY["categories"][$CATEGORY]["DAY"][$IPADDR] = $size_old; } if (!isset($ARRAY["categories"][$CATEGORY]["DAY"][$MAC])) { $ARRAY["categories"][$CATEGORY]["DAY"][$MAC] = $size; } else { $size_old = $ARRAY["categories"][$CATEGORY]["DAY"][$MAC]; $size_old = $size_old + $size; $ARRAY["categories"][$CATEGORY]["DAY"][$MAC] = $size_old; } } if (!isset($ARRAY["UID"][$USERID]["DAY"])) { $ARRAY["UID"][$USERID]["DAY"] = $size; } else { $size_old = $ARRAY["UID"][$USERID]["DAY"]; $size_old = $size_old + $size; $ARRAY["UID"][$USERID]["DAY"] = $size_old; } if (!isset($ARRAY["IPADDR"][$IPADDR]["DAY"])) { $ARRAY["IPADDR"][$IPADDR]["DAY"] = $size; } else { $size_old = $ARRAY["IPADDR"][$IPADDR]["DAY"]; $size_old = $size_old + $size; $ARRAY["IPADDR"][$IPADDR]["DAY"] = $size_old; } if ($ipClass->IsvalidMAC($MAC)) { if (!isset($ARRAY["MAC"][$MAC]["DAY"])) { $ARRAY["MAC"][$MAC]["DAY"] = $size; } else { $size_old = $ARRAY["MAC"][$MAC]["DAY"]; $size_old = $size_old + $size; $ARRAY["MAC"][$MAC]["DAY"] = $size_old; } } } //----------------------------------------------------------------------------------------------- $influx = new influx(); $date_from = strtotime("-1 week"); $sql = "SELECT SUM(SIZE) as size,USERID,IPADDR,MAC,CATEGORY FROM access_hour GROUP BY time(1w) ,USERID,IPADDR,MAC,CATEGORY WHERE time > {$date_from}s"; $main = $influx->QUERY_SQL($sql); foreach ($main as $row) { $CATEGORY = $row->CATEGORY; $USERID = strtolower($row->USERID); $IPADDR = $row->IPADDR; $MAC = $row->MAC; $size = intval($row->size); if ($size == 0) { continue; } if ($CATEGORY != null) { if (!isset($ARRAY["categories"][$CATEGORY]["WEEK"][$USERID])) { $ARRAY["categories"][$CATEGORY]["WEEK"][$USERID] = $size; } else { $size_old = $ARRAY["categories"][$CATEGORY]["WEEK"][$USERID]; $size_old = $size_old + $size; $ARRAY["categories"][$CATEGORY]["WEEK"][$USERID] = $size_old; } if (!isset($ARRAY["categories"][$CATEGORY]["WEEK"][$IPADDR])) { $ARRAY["categories"][$CATEGORY]["WEEK"][$IPADDR] = $size; } else { $size_old = $ARRAY["categories"][$CATEGORY]["WEEK"][$IPADDR]; $size_old = $size_old + $size; $ARRAY["categories"][$CATEGORY]["WEEK"][$IPADDR] = $size_old; } if (!isset($ARRAY["categories"][$CATEGORY]["WEEK"][$MAC])) { $ARRAY["categories"][$CATEGORY]["WEEK"][$MAC] = $size; } else { $size_old = $ARRAY["categories"][$CATEGORY]["WEEK"][$MAC]; $size_old = $size_old + $size; $ARRAY["categories"][$CATEGORY]["WEEK"][$MAC] = $size_old; } } if ($USERID != null) { if (!isset($ARRAY["UID"][$USERID]["WEEK"])) { $ARRAY["UID"][$USERID]["WEEK"] = $size; } else { $size_old = $ARRAY["UID"][$USERID]["WEEK"]; $size_old = $size_old + $size; $ARRAY["UID"][$USERID]["WEEK"] = $size_old; } } if ($ipClass->isValid($IPADDR)) { if (!isset($ARRAY["IPADDR"][$IPADDR]["WEEK"])) { $ARRAY["IPADDR"][$IPADDR]["IPADDR"] = $size; } else { $size_old = $ARRAY["IPADDR"][$IPADDR]["WEEK"]; $size_old = $size_old + $size; $ARRAY["IPADDR"][$IPADDR]["WEEK"] = $size_old; } } if ($ipClass->IsvalidMAC($MAC)) { if (!isset($ARRAY["MAC"][$MAC]["WEEK"])) { $ARRAY["MAC"][$MAC]["WEEK"] = $size; } else { $size_old = $ARRAY["MAC"][$MAC]["WEEK"]; $size_old = $size_old + $size; $ARRAY["MAC"][$MAC]["WEEK"] = $size_old; } } } //----------------------------------------------------------------------------------------------- if ($GLOBALS["VERBOSE"]) { print_r($ARRAY); } @unlink("/usr/share/squid3/CurrentSizesUsers.db"); @file_put_contents("/usr/share/squid3/CurrentSizesUsers.db", serialize($ARRAY)); @file_put_contents("/usr/share/artica-postfix/ressources/logs/web/CurrentSizesUsers.db", serialize($ARRAY)); @chmod("/usr/share/artica-postfix/ressources/logs/web/CurrentSizesUsers.db", 0755); }
function wifidog_login($error = null) { $sock = new sockets(); $page = CurrentPageName(); session_start(); $ipClass = new IP(); $tpl = new templates(); $USE_TERMS_ACCEPTED = false; header('Content-Type: text/html; charset=iso-8859-1'); $gateway_addr = $_REQUEST["gw_address"]; $gw_port = $_REQUEST["gw_port"]; $gw_id = $_REQUEST["gw_id"]; $ARP = $_REQUEST["mac"]; $url = $_REQUEST["url"]; if (isset($_POST["wifidog-terms"])) { $_SESSION["USE_TERMS_ACCEPTED"] = true; $USE_TERMS_ACCEPTED = true; } if (isset($_SESSION["USE_TERMS_ACCEPTED"])) { $USE_TERMS_ACCEPTED = true; } if (!$ipClass->IsvalidMAC($ARP)) { $text_form = $tpl->_ENGINE_parse_body(FATAL_ERROR_SHOW_128("{hostspot_network_incompatible}")); } if (!isset($_REQUEST["token"])) { $_REQUEST["token"] = generateToken($ARP); } $wifidog_build_uri = wifidog_build_uri(); $uriext = $wifidog_build_uri[0]; $HiddenFields = $wifidog_build_uri[1]; if (!isset($_SESSION["WIFIDOG_RULES"])) { $wifidog_templates = new wifidog_rules(); $_SESSION["WIFIDOG_RULES"] = $wifidog_templates->ruleid; } $wifidog_rule = new wifidog_settings($_SESSION["WIFIDOG_RULES"]); $ArticaHotSpotNowPassword = intval($wifidog_rule->GET_INFO("ArticaHotSpotNowPassword")); $ENABLED_REDIRECT_LOGIN = intval($wifidog_rule->GET_INFO("ENABLED_REDIRECT_LOGIN")); $ENABLED_SMTP = intval($wifidog_rule->GET_INFO("ENABLED_SMTP")); $ENABLED_AUTO_LOGIN = intval($wifidog_rule->GET_INFO("ENABLED_AUTO_LOGIN")); $USE_TERMS = intval($wifidog_rule->GET_INFO("USE_TERMS")); $ALLOW_RECOVER_PASS = intval($wifidog_rule->GET_INFO("ALLOW_RECOVER_PASS")); $DO_NOT_AUTENTICATE = intval($wifidog_rule->GET_INFO("DO_NOT_AUTENTICATE")); if ($USE_TERMS == 1) { if (!$USE_TERMS_ACCEPTED) { return wifidog_terms(); } } $wifidog_templates = new wifidog_templates($_SESSION["WIFIDOG_RULES"]); $ArticaSplashHotSpotTitle = $wifidog_templates->MainTitle; if ($ENABLED_SMTP == 1) { if ($ENABLED_REDIRECT_LOGIN == 1) { wifidog_register(); return; } } $tpl = new templates(); $username = $wifidog_templates->LabelUsername; $password = $wifidog_templates->LabelPassword; $lost_password_text = $wifidog_templates->LostPasswordLink; $please_sign_in = $tpl->_ENGINE_parse_body("{please_sign_in}"); $page = CurrentPageName(); $t = time(); unset($_SESSION["HOTSPOT_AUTO_RECOVER"]); $_SESSION["HOTSPOT_REDIRECT_URL"] = $url; $url_encoded = urlencode($url); if ($DO_NOT_AUTENTICATE == 1) { $ArticaHotSpotNowPassword = 1; } $f[] = "<p>{$wifidog_templates->WelcomeMessage}</p>"; $f[] = " <div id='content'>"; $f[] = " "; $f[] = "\t\t\t<form id='wifidogform' action=\"{$page}\" method=\"post\">"; $f[] = "\t\t\t<input type=\"hidden\" name=\"ruleid\" id=\"ruleid\" value='{$_SESSION["WIFIDOG_RULES"]}'>"; $f[] = "{$HiddenFields}"; $f[] = "<table style='width:100%'>"; $f[] = "<tr>"; $f[] = "<td class=legend>{$username}:</td>"; $f[] = "<td>\n\t<input type=\"text\" \n\t\tname=\"username\" \n\t\tid=\"username\"\n\t\tvalue=\"{$_REQUEST["username"]}\" \n\t\tonfocus=\"this.setAttribute('class','active');RemoveLogonCSS();\" \n\t\tonblur=\"this.removeAttribute('class');\" \n\t\tOnKeyPress=\"javascript:SendLogon{$t}(event)\">"; $f[] = "</td>"; $f[] = "</tr>"; if ($ArticaHotSpotNowPassword == 0) { $f[] = "<tr>"; $f[] = "<td class=legend>{$password}:</td>"; $f[] = "<td><input type=\"password\" name=\"password\" \n\t\t\t\tvalue=\"{$_REQUEST["password"]}\"\n\t\t\t\tid=\"password\" onfocus=\"this.setAttribute('class','active');RemoveLogonCSS();\" \n\t\t\t\tonblur=\"this.removeAttribute('class');\" OnKeyPress=\"javascript:SendLogon{$t}(event)\">"; $f[] = "</td>"; $f[] = "</tr>"; } else { $f[] = "<input type=\"hidden\" name=\"password\" id=\"password\" value=''>"; } $f[] = "<tr><td colspan=2> </td></tr>"; $f[] = "<tr><td colspan=2 align='right' class=ButtonCell>"; if ($ENABLED_AUTO_LOGIN == 1) { $f[] = "\t\t\t\t\t\t<a data-loading-text=\"Chargement...\"\n\t\tstyle=\"text-transform:capitalize\"\n\t\tclass=\"Button2014 Button2014-success Button2014-lg\"\n\t\tid=\"fb92ae5e1f7bbea3b5044cbcdd40f088\"\n\t\thref=\"{$page}?wifidog-register=yes&{$uriext}\">« {$wifidog_templates->RegisterTitle} »</a>"; } $f[] = "<a data-loading-text=\"Chargement...\" \n\t\t\tstyle=\"text-transform:capitalize\" \n\t\t\tclass=\"Button2014 Button2014-success Button2014-lg\" \n\t\t\tid=\"fb92ae5e1f7bbea3b5044cbcdd40f088\" \n\t\t\tonclick=\"javascript:document.forms['wifidogform'].submit();\" \n\t\t\thref=\"javascript:Blurz()\">« {$wifidog_templates->ConnectionButton} »</a>"; $f[] = "</td>\n\t</tr>"; if ($ENABLED_SMTP == 1) { if ($ALLOW_RECOVER_PASS == 1) { if ($ArticaHotSpotNowPassword == 0) { $f[] = "<tr><td class=legend colspan=2>"; $f[] = "<a href=\"{$page}?wifidog-recover=yes&email={$_REQUEST["username"]}&{$uriext}\">{$lost_password_text}</a></div>"; $f[] = "</td></tr>"; } } } $f[] = "</table>"; $f[] = "\t\t\t</form>\t"; $f[] = "</div>\n\t<script>\n\t\tfunction SendLogon{$t}(e){\n\t\t\tif(!checkEnter(e)){return;}\n\t\t\tdocument.forms['wifidogform'].submit();\n\t\t}\n\t</script>\n\t\n"; $text_form = @implode("\n", $f); echo BuildFullPage($text_form, $error); }
function importcomputersFromList() { $sock = new sockets(); $ipClass = new IP(); $tbl = explode("\n", $sock->GET_INFO("ComputerListToImport")); writelogs("ComputerListToImport=" . count($tbl) . " values", __FUNCTION__, __FILE__, __LINE__); $i = 0; $max = count($tbl); while (list($num, $computername) = each($tbl)) { $z = $z + 1; $computername = trim($computername); $ip = null; $mac = null; if ($computername == null) { continue; } if (strpos($computername, " ") > 0) { $TRB = explode(" ", $computername); $computername = $TRB[0]; unset($TRB[0]); while (list($a, $b) = each($TRB)) { if ($b == null) { continue; } if ($ipClass->isValid($b)) { $ip = $b; continue; } if ($ipClass->IsvalidMAC($b)) { $mac = $b; continue; } } } if (isset($_GET["arp-ip"])) { $ip_arp = unserialize(base64_decode($sock->getFrameWork("cmd.php?arp-ip=" . $_GET["arp-ip"]))); if (is_array($ip_arp)) { $ip = $ip_arp[0]; $mac = $ip_arp[1]; unset($ip_arp); } } $pourc = round($z / $max * 100); writelogs("{$pourc}) {$computername}", __FUNCTION__, __FILE__, __LINE__); WriteCOmputerBrowseProgress($pourc, "{import}: {$computername} ({$ip}/{$mac})"); $cmp = new computers(); if ($mac != null) { $uid = $cmp->ComputerIDFromMAC($mac); } else { $uid = "{$computername}\$"; } if ($uid == null) { $uid = "{$computername}\$"; } $cmp = new computers($uid); if ($ip != null) { $cmp->ComputerIP = $ip; } if ($mac != null) { $cmp->ComputerMacAddress = $mac; } $cmp->ComputerRealName = $computername; $cmp->Add(); $i = $i + 1; } WriteCOmputerBrowseProgress(0, "{waiting}"); }
function search() { $tpl = new templates(); $MyPage = CurrentPageName(); $q = new mysql_squid_builder(); $t = $_GET["t"]; $q->QUERY_SQL("CREATE TABLE IF NOT EXISTS `FULL_USERS_DAY` (\n\t\t\t`user` varchar(128) NOT NULL,\n\t\t\t`hits` BIGINT UNSIGNED NOT NULL,\n\t\t\t`size` BIGINT UNSIGNED NOT NULL,\n\t\t\tPRIMARY KEY `user` (`user`),\n\t\t\tKEY `hits` (`hits`),\n\t\t\tKEY `size` (`size`)\n\t) ENGINE=MYISAM;"); $data = array(); if ($q->COUNT_ROWS("FULL_USERS_DAY", "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']; } $table = "FULL_USERS_DAY"; $searchstring = string_to_flexquery(); if (isset($_POST['rp'])) { $rp = $_POST['rp']; } if (!is_numeric($rp)) { $rp = 100; } $data['page'] = $page; $pageStart = ($page - 1) * $rp; if ($pageStart < 0) { $pageStart = 0; } $limitSql = "LIMIT {$pageStart}, {$rp}"; if ($searchstring == null) { $data['total'] = $q->COUNT_ROWS("FULL_USERS_DAY"); } else { $sql = "SELECT COUNT(*) as tcount FROM FULL_USERS_DAY WHERE 1 {$searchstring}"; $ligne = mysql_fetch_array($q->QUERY_SQL($sql)); $data['total'] = $ligne["tcount"]; } $data['rows'] = array(); $CurrentPage = CurrentPageName(); $sql = "SELECT * FROM {$table} WHERE 1 {$searchstring} {$ORDER} {$limitSql}"; $results = $q->QUERY_SQL($sql, 'artica_backup'); if (mysql_num_rows($results) == 0) { json_error_show("no data"); } 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'>"; $IPTCP = new IP(); while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) { $zmd5 = $ligne["zmd5"]; $member_value = trim($ligne["user"]); $hits = FormatNumber($ligne["hits"]); $size = FormatBytes($ligne["size"] / 1024); $ahref = null; $member_assoc = null; $graph = imgtootltip("graph2-48.png", "{statistics}", "Loadjs('{$MyPage}?graph-js=yes&uid=" . urlencode($member_value) . "')"); $graph2 = imgtootltip("graphs-48.png", "{statistics}", "Loadjs('{$MyPage}?graph2-js=yes&uid=" . urlencode($member_value) . "')"); if ($IPTCP->IsvalidMAC($member_value)) { $mac_encoded = urlencode($member_value); $uid = $q->MacToUid($member_value); if ($uid != null) { $member_assoc = " ({$uid})"; } $ahref = "<a href=\"javascript:blur();\"\n\t\t\t\t\tOnClick=\"javascript:Loadjs('squid.nodes.php?node-infos-js=yes&MAC={$mac_encoded}');\"\n\t\t\t\t\tstyle='font-size:{$fontsize};text-decoration:underline'>"; } $data['rows'][] = array('id' => $member_value, 'cell' => array("{$span}{$ahref}{$member_value}</a>{$member_assoc}</span>", "{$span}{$hits}</a></span>", "{$span}{$size}</a></span>", "<center>{$graph}</center>", "<center>{$graph2}</center>")); } echo json_encode($data); }
function IpToMac($ipaddr) { if ($GLOBALS["EnableMacAddressFilter"] == 0) { if ($GLOBALS["VERBOSE"]) { events("IpToMac({$ipaddr}): EnableMacAddressFilter set to disabled, aborting"); } return null; } if ($GLOBALS["MacResolvFrfomIP"] == null) { if ($GLOBALS["VERBOSE"]) { events("IpToMac({$ipaddr}): MacResolvInterface/MacResolvFrfomIP Not set, aborting"); } return null; } if (!is_file("/usr/bin/arping")) { $GLOBALS["MacResolvFrfomIP"] = null; return; } $ipaddr = trim($ipaddr); $ttl = date('YmdH'); if (isset($GLOBALS["CACHEARP"][$ttl][$ipaddr])) { return $GLOBALS["CACHEARP"][$ttl][$ipaddr]; } $IpClass = new IP(); $unix = new unix(); if (count($GLOBALS["CACHEARP"]) > 3) { unset($GLOBALS["CACHEARP"]); } if (isset($GLOBALS["CACHEARP"][$ttl][$ipaddr])) { return $GLOBALS["CACHEARP"][$ttl][$ipaddr]; } $mac = $unix->IpToMac($ipaddr); if ($IpClass->IsvalidMAC($mac)) { if ($GLOBALS["VERBOSE"]) { events("IpToMac -> {$ipaddr} -> {$mac} OK"); } $GLOBALS["CACHEARP"][$ttl][$ipaddr] = $mac; } else { if ($GLOBALS["VERBOSE"]) { events("IpToMac -> {$ipaddr} -> {$mac} FAILED"); } $GLOBALS["CACHEARP"][$ttl][$ipaddr] = null; return null; } }
function ACCESS_BACKUP_SCAN($filename) { $unix = new unix(); $BaseName = basename($filename); $tempfile = $unix->FILE_TEMP(); if (preg_match("#\\.gz\$#", $BaseName)) { $zcat = $unix->find_program("zcat"); shell_exec("{$zcat} {$filename} >{$tempfile}"); } else { @copy($filename, $tempfile); } $handle = @fopen($tempfile, "r"); if (!$handle) { echo "Failed to open file\n"; return; } $prefix = "INSERT INTO access_log (zdate,category,ipaddr,mac,sitename,familysite,proxyname,userid,size,rqs) VALUES "; $MASTER_C = 0; $MAIN = array(); $MASTER_G = 0; while (!feof($handle)) { $pattern = trim(fgets($handle)); if ($pattern == null) { continue; } $ARRAY = LineToArray($pattern); if (count($ARRAY) < 5) { echo "{$pattern} no match\n"; continue; } if (!isset($ARRAY["MAC"])) { $ARRAY["MAC"] = "00:00:00:00:00:00"; } if ($ARRAY["MAC"] === null) { $ARRAY["MAC"] = "00:00:00:00:00:00"; } $IP = new IP(); if (!$IP->isValid($ARRAY["IPADDR"])) { continue; } if (!$IP->IsvalidMAC($ARRAY["MAC"])) { $ARRAY["MAC"] = "00:00:00:00:00:00"; } if (!isset($ARRAY["USERID"])) { $ARRAY["USERID"] = null; } if (!isset($ARRAY["CATEGORY"])) { $ARRAY["CATEGORY"] = null; } if (strlen($ARRAY["SITE"]) > 128) { $ARRAY["SITE"] = substr(0, 127, $ARRAY["SITE"]); } if (strlen($ARRAY["FAMILYSITE"]) > 128) { $ARRAY["FAMILYSITE"] = substr(0, 127, $ARRAY["FAMILYSITE"]); } if (strlen($ARRAY["PROXYNAME"]) > 128) { $ARRAY["PROXYNAME"] = substr(0, 127, $ARRAY["PROXYNAME"]); } $date = $ARRAY["ZDATE"]; $MAIN[] = "('{$date}','{$ARRAY["CATEGORY"]}','{$ARRAY["IPADDR"]}','{$ARRAY["MAC"]}','{$ARRAY["SITE"]}','{$ARRAY["FAMILYSITE"]}','{$ARRAY["PROXYNAME"]}','{$ARRAY["USERID"]}','{$ARRAY["SIZE"]}','{$ARRAY["RQS"]}')"; $MASTER_C++; $CountOfMain = count($MAIN); if ($CountOfMain > 1000) { $MASTER_G++; squid_admin_mysql(1, "{$MASTER_G}]: Injecting {$CountOfMain} events from {$BaseName}", null, __FILE__, __LINE__); $q = new postgres_sql(); $q->QUERY_SQL($prefix . @implode(",", $MAIN)); if (!$q->ok) { $MAIN = array(); squid_admin_mysql(0, "Failed Injecting {$CountOfMain} events from {$BaseName}", $q->mysql_error, __FILE__, __LINE__); echo $q->mysql_error; return false; } $MAIN = array(); } } $CountOfMain = count($MAIN); if (count($MAIN) > 0) { $q = new postgres_sql(); squid_admin_mysql(1, "(FINAL) Injecting {$CountOfMain} events from {$BaseName}", null, __FILE__, __LINE__); $q->QUERY_SQL($prefix . @implode(",", $MAIN)); if (!$q->ok) { squid_admin_mysql(0, "(FINAL) SQL error: {$q->mysql_error}", null, __FILE__, __LINE__); echo $q->mysql_error; return false; } } echo "{$filename}, Injected {$MASTER_C} items\n"; echo "Vaccum....\n"; squid_admin_mysql(1, basename($filename) . ": running vacuumdb...", null, __FILE__, __LINE__); shell_exec("/usr/local/ArticaStats/bin/vacuumdb -h /var/run/ArticaStats --dbname=proxydb --username=ArticaStats"); squid_admin_mysql(1, basename($filename) . ": Injected {$MASTER_C} items ", null, __FILE__, __LINE__); InfluxDbSize(); return true; }
function pattern_item($destination, $eth = null, $port = 0, $destinationProto = 0) { $nic = new system_nic(); $trace = @debug_backtrace(); $interface = null; $portText = null; if (isset($trace[1])) { $called = "in " . basename($trace[1]["file"]) . " function {$trace[1]["function"]}() line {$trace[1]["line"]}"; } if ($GLOBALS["VERBOSE"]) { echo "[" . __LINE__ . "]: Destination: {$destination} eth={$eth} port={$port} destinationProto={$destinationProto} - {$called}\n"; } if (is_numeric($eth)) { $eth = null; } if ($port > 0) { $portText = "--srcport {$port}"; if ($destinationProto == 1) { $portText = " --dport {$port}"; } } $pdest = "-s "; if ($eth != null) { if ($destinationProto == 0) { $interface = " -m physdev --physdev-in {$eth} "; } } if ($destinationProto == 1) { $pdest = "-d "; } if ($destination == "*") { $destination = "0.0.0.0/0"; } if (trim($destination) == null) { if ($GLOBALS["VERBOSE"]) { echo "[" . __LINE__ . "]: Destination: return *** {$interface}{$portText} ***\n"; } return "{$interface}{$portText}"; } if (preg_match("#[0-9\\.]+-[0-9\\.]+#", $destination)) { if ($destinationProto == 1) { if ($GLOBALS["VERBOSE"]) { echo "[" . __LINE__ . "]: Destination: return *** {$interface}-m iprange --dst-range '{$destination}'{$portText} ***\n"; } return "{$interface}-m iprange --dst-range '{$destination}'{$portText} "; } if ($GLOBALS["VERBOSE"]) { echo "[" . __LINE__ . "]: Destination: return *** {$interface}-m iprange --src-range '{$destination}'{$portText} ***\n"; } return "{$interface}-m iprange --src-range '{$destination}'{$portText} "; } $ipClass = new IP(); if ($ipClass->IsvalidMAC($destination)) { if ($GLOBALS["VERBOSE"]) { echo "[" . __LINE__ . "]: Destination: return *** {$interface}-m mac --mac-source {$destination}{$portText} ***\n"; } return "{$interface}-m mac --mac-source {$destination}{$portText} "; } if ($ipClass->isIPAddressOrRange($destination)) { return "{$interface}{$pdest}{$destination}{$portText} "; } }
function search() { $base = "/home/squid/rttsize"; $YEAR = date("Y"); $MONTH = date("m"); $DAY = date("d"); $HOUR = date("H"); $WEEK = date("W"); if (!isset($_GET["SUBDIR"])) { $_GET["SUBDIR"] = "UID"; } if (isset($_POST["sortname"])) { if ($_POST["sortname"] != null) { $ORDER = "ORDER BY {$_POST["sortname"]} {$_POST["sortorder"]}"; } } if (isset($_POST['page'])) { $page = $_POST['page']; } $TIMES_SLOT["hour"] = "/home/squid/rttsize/{$YEAR}/{$MONTH}/{$WEEK}/{$DAY}/{$HOUR}/{$_GET["SUBDIR"]}"; $TIMES_SLOT["day"] = "/home/squid/rttsize/{$YEAR}/{$MONTH}/{$WEEK}/{$DAY}/{$_GET["SUBDIR"]}"; $TIMES_SLOT["week"] = "/home/squid/rttsize/{$YEAR}/{$MONTH}/{$WEEK}/{$_GET["SUBDIR"]}"; $TIMES_SLOT["month"] = "/home/squid/rttsize/{$YEAR}/{$MONTH}/{$_GET["SUBDIR"]}"; $baseWeek = "/home/squid/rttsize/{$YEAR}/{$MONTH}/{$WEEK}/{$_GET["SUBDIR"]}"; $baseMonth = "/home/squid/rttsize/{$YEAR}/{$MONTH}/{$_GET["SUBDIR"]}"; $directory_path = $TIMES_SLOT[$_GET["timeslot"]]; if (!is_dir($directory_path)) { json_error_show("{$directory_path} no such dir"); } if ($GLOBALS["VERBOSE"]) { echo "{$directory_path}\n"; } $directory = opendir($directory_path); $DATAS = array(); while ($file = readdir($directory)) { if ($file == ".") { continue; } if ($file == "..") { continue; } $dirpath = "{$directory_path}/{$file}"; if ($GLOBALS["VERBOSE"]) { echo "{$dirpath}\n"; } if ($_GET["SUBDIR"] == "WEBS") { $TOT = intval(@file_get_contents("{$dirpath}")); if ($TOT == 0) { continue; } $DATAS[] = "('{$file}','{$TOT}')"; continue; } if ($_GET["SUBDIR"] == "CATS") { $TOT = intval(@file_get_contents("{$dirpath}")); if ($TOT == 0) { continue; } $DATAS[] = "('{$file}','{$TOT}')"; continue; } if (!is_dir($dirpath)) { if ($GLOBALS["VERBOSE"]) { echo "{$dirpath} not a dir\n"; } continue; } if ($GLOBALS["VERBOSE"]) { if (!is_file("{$dirpath}/TOT")) { echo "{$dirpath}/TOT not a file\n"; } } $TOT = intval(@file_get_contents("{$dirpath}/TOT")); if ($TOT == 0) { continue; } $DATAS[] = "('{$file}','{$TOT}')"; } closedir($directory); if (count($DATAS) == 0) { json_error_show("no data"); } $q = new mysql_squid_builder(); if (!$q->TABLE_EXISTS("TMP_RTTSIZE")) { $q->QUERY_SQL("CREATE TABLE IF NOT EXISTS `TMP_RTTSIZE` (\n\t\t\t `SIZE` BIGINT UNSIGNED NOT NULL,\n\t\t\t `pattern` varchar(128) NOT NULL PRIMARY KEY,\n\t\t\t KEY `SIZE` (`SIZE`)\n\t\t\t ) ENGINE=MYISAM;"); if (!$q->ok) { json_error_show("CREATE TABLE:{$q->mysql_error}"); } } $q->QUERY_SQL("TRUNCATE TABLE TMP_RTTSIZE"); $sql = "INSERT IGNORE INTO TMP_RTTSIZE (pattern,SIZE) VALUES " . @implode(",", $DATAS); $q->QUERY_SQL($sql); if (!$q->ok) { json_error_show("INSERT: {$q->mysql_error}<br>{$sql}"); } $table = "TMP_RTTSIZE"; $searchstring = string_to_flexquery(); if (isset($_POST['rp'])) { $rp = $_POST['rp']; } if (!is_numeric($rp)) { $rp = 100; } $page = 1; $data['page'] = $page; $pageStart = ($page - 1) * $rp; if ($pageStart < 0) { $pageStart = 0; } $limitSql = "LIMIT {$pageStart}, {$rp}"; if ($searchstring == null) { $data['total'] = $q->COUNT_ROWS("FULL_USERS_DAY"); } else { $sql = "SELECT COUNT(*) as tcount FROM FULL_USERS_DAY WHERE 1 {$searchstring}"; $ligne = mysql_fetch_array($q->QUERY_SQL($sql)); $data['total'] = $ligne["tcount"]; } $data['rows'] = array(); $CurrentPage = CurrentPageName(); $sql = "SELECT * FROM {$table} WHERE 1 {$searchstring} {$ORDER} {$limitSql}"; $results = $q->QUERY_SQL($sql, 'artica_backup'); if (mysql_num_rows($results) == 0) { json_error_show("no data"); } 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'>"; $IPTCP = new IP(); $c = 0; while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) { $zmd5 = $ligne["zmd5"]; $member_value = trim($ligne["pattern"]); $size = FormatBytes($ligne["SIZE"] / 1024); $ahref = null; $member_assoc = null; if ($IPTCP->IsvalidMAC($member_value)) { $mac_encoded = urlencode($member_value); $uid = $q->MacToUid($member_value); if ($uid != null) { $member_assoc = " ({$uid})"; } $ahref = "<a href=\"javascript:blur();\"\n\t\t\tOnClick=\"javascript:Loadjs('squid.nodes.php?node-infos-js=yes&MAC={$mac_encoded}');\"\n\t\t\tstyle='font-size:{$fontsize};text-decoration:underline'>"; } $c++; $data['rows'][] = array('id' => $member_value, 'cell' => array("{$span}{$ahref}{$member_value}</a>{$member_assoc}</span>", "{$span}{$size}</a></span>")); } $data['total'] = $c; echo json_encode($data); }
function ACCESS_LOG_HOURLY_DUMP($MEM) { if (count($MEM) == 0) { return true; } $q = new influx(); $AS_POSTGRES = false; $suffix = "influx"; if (is_file("/usr/local/ArticaStats/bin/postgres")) { $AS_POSTGRES = true; $suffix = "postgres"; } $IPClass = new IP(); while (list($KEYMD5, $subarray) = each($MEM)) { $CATEGORY = $subarray["CATEGORY"]; $USERID = $subarray["USERID"]; $IPADDR = $subarray["IPADDR"]; $MAC = $subarray["MAC"]; $SIZE = intval($subarray["SIZE"]); $SITE = $subarray["SITE"]; $FAM = $subarray["FAM"]; $RQS = $subarray["RQS"]; $PROXYNAME = $subarray["PROXYNAME"]; if ($MAC == null) { $MAC = "00:00:00:00:00:00"; } if (!$IPClass->isValid($IPADDR)) { continue; } if (!$IPClass->IsvalidMAC($MAC)) { $MAC = "00:00:00:00:00:00"; } if ($USERID == null) { $USERID = "none"; } if (strlen($FAM) > 128) { $FAM = substr(0, 127, $FAM); } if (strlen($SITE) > 128) { $SITE = substr(0, 127, $SITE); } if (strlen($PROXYNAME) > 128) { $PROXYNAME = substr(0, 127, $PROXYNAME); } if ($AS_POSTGRES) { $zDate = date("Y-m-d H:i:s", $subarray["ZDATE"]); $FINAL[] = "('{$zDate}','{$MAC}','{$IPADDR}','{$CATEGORY}','{$FAM}','{$USERID}','{$SIZE}','{$RQS}','{$FAM}','{$PROXYNAME}')"; continue; } $zArray["precision"] = "s"; $zArray["time"] = $subarray["TIME"]; $zArray["tags"]["CATEGORY"] = $CATEGORY; $zArray["tags"]["USERID"] = $USERID; $zArray["tags"]["IPADDR"] = $IPADDR; $zArray["tags"]["MAC"] = $MAC; $zArray["fields"]["SIZE"] = $SIZE; $zArray["tags"]["SITE"] = $SITE; $zArray["tags"]["FAMILYSITE"] = $FAM; $zArray["fields"]["ZDATE"] = $subarray["ZDATE"]; $zArray["fields"]["RQS"] = $RQS; $zArray["tags"]["proxyname"] = $PROXYNAME; $line = $q->prepare("access_log", $zArray); $FINAL[] = $line; } if (count($FINAL) > 0) { $backupdir = "{$GLOBALS["LogFileDeamonLogDir"]}/access-backup"; $failedPath = "{$GLOBALS["LogFileDeamonLogDir"]}/access-failed"; @mkdir($failedPath, 0755, true); @mkdir($backupdir, 0755, true); $backupfile = "{$GLOBALS["LogFileDeamonLogDir"]}/access-backup/" . time() . ".{$suffix}.log"; $failedPath = "{$GLOBALS["LogFileDeamonLogDir"]}/access-failed/" . time() . ".{$suffix}.log"; if ($AS_POSTGRES) { $sql = "INSERT INTO access_log (zDate,MAC,IPADDR,CATEGORY,SITENAME,USERID,SIZE,RQS,familysite,PROXYNAME) VALUES " . @implode(",", $FINAL); $q = new postgres_sql(); $q->QUERY_SQL($sql); if (!$q->ok) { events("INJECTION Failed: backup to {$failedPath} ({$q->curl_error})"); @file_put_contents($failedPath, @implode("\n", $sql)); return false; } } if (!$AS_POSTGRES) { if (!$q->bulk_inject($FINAL)) { events("INJECTION Failed: backup to {$failedPath} ({$q->curl_error})"); @file_put_contents($failedPath, @implode("\n", $FINAL)); return false; } } events("INJECTION Success: backup to {$backupfile}"); @file_put_contents($backupfile, @implode("\n", $FINAL)); $FINAL = array(); } return true; }
function proxy_alias_add($IPADDR = null, $MAC = null, $UID = null) { if ($IPADDR == null) { if ($MAC == null) { return; } } $ipClass = new IP(); if (!$ipClass->IsvalidMAC($MAC)) { $MAC = null; } if (!$ipClass->isValid($IPADDR)) { $IPADDR = null; } if (!class_exists("mysql_squid_builder")) { include_once dirname(__FILE__) . "/ressources/class.mysql.squid.builder.php"; } $q = new mysql_squid_builder(); if (!$q->FIELD_EXISTS("webfilters_ipaddr", "ip")) { $q->QUERY_SQL("ALTER TABLE `webfilters_ipaddr` ADD `ip` int(10) unsigned NOT NULL default '0',ADD INDEX ( `ip` )"); } $UID = mysql_escape_string2($UID); if ($MAC != null) { $sql = "UPDATE webfilters_nodes SET uid='{$UID}' WHERE MAC='{$MAC}'"; $q = new mysql_squid_builder(); $ligne = mysql_fetch_array($q->QUERY_SQL("SELECT MAC FROM webfilters_nodes WHERE MAC='{$MAC}'")); if ($ligne["MAC"] == null) { $sql = "INSERT INTO webfilters_nodes (MAC,uid,hostname,nmapreport,nmap)\n\t\t\tVALUES ('{$MAC}','{$UID}','','',0)"; } $q->QUERY_SQL($sql); if (!$q->ok) { echo "Fatal:" . $q->mysql_error . "\n"; return; } return; } if ($IPADDR != null) { $ip2Long2 = ip2Long2($IPADDR); $sql = "UPDATE webfilters_ipaddr SET uid='{$UID}',`ip`='{$ip2Long2}' WHERE ipaddr='{$IPADDR}'"; $q = new mysql_squid_builder(); $ligne = mysql_fetch_array($q->QUERY_SQL("SELECT ipaddr FROM webfilters_ipaddr WHERE ipaddr='{$IPADDR}'")); if ($ligne["ipaddr"] == null) { $sql = "INSERT INTO webfilters_ipaddr (ipaddr,uid,ip,hostname) VALUES ('{$IPADDR}','{$UID}','{$ip2Long2}','')"; } $q->QUERY_SQL($sql); if (!$q->ok) { echo "Fatal:" . $q->mysql_error . "\n"; return; } return; } }
function GroupInArray($ID = 0, $IsArray = false) { if ($ID == 0) { return array(); } $q = new mysql_squid_builder(); $sql = "SELECT GroupType FROM webfilters_sqgroups WHERE ID={$ID}"; $ligne = mysql_fetch_array($q->QUERY_SQL($sql)); if (!$q->ok) { echo "[" . __LINE__ . "]: {$q->mysql_error}\n"; } $GroupType = $ligne["GroupType"]; if ($GLOBALS["VERBOSE"]) { echo "[" . __LINE__ . "]: src_items:{$ID} -> {$GroupType} Get items.\n"; } if ($GroupType == "teamviewer") { include_once dirname(__FILE__) . "/ressources/class.products-ip-ranges.inc"; $products_ip_ranges = new products_ip_ranges(); $array = $products_ip_ranges->teamviewer_networks(); if ($GLOBALS["VERBOSE"]) { echo "teamviewer_networks ->" . count($array) . " items [" . __LINE__ . "]\n"; } while (list($a, $b) = each($array)) { if (preg_match("#([0-9]+)-([0-9]+)#", $b)) { $f["-m iprange --dst-range {$b}"] = true; continue; } $f["--dst {$b}"] = true; } if ($GLOBALS["VERBOSE"]) { echo "[" . __LINE__ . "]: teamviewer::{$ID} -> " . count($f) . " item(s).\n"; } return $f; } if ($GroupType == "office365") { include_once dirname(__FILE__) . "/ressources/class.products-ip-ranges.inc"; $products_ip_ranges = new products_ip_ranges(); $array = $products_ip_ranges->office365_networks(); if ($GLOBALS["VERBOSE"]) { echo "office365 ->" . count($array) . " items [" . __LINE__ . "]\n"; } while (list($a, $b) = each($array)) { if (preg_match("#([0-9]+)-([0-9]+)#", $b)) { $f["-m iprange --dst-range {$b}"] = true; continue; } $f["--dst {$b}"] = true; } if ($GLOBALS["VERBOSE"]) { echo "[" . __LINE__ . "]: teamviewer::{$ID} -> " . count($f) . " item(s).\n"; } return $f; } if ($GroupType == "skype") { include_once dirname(__FILE__) . "/ressources/class.products-ip-ranges.inc"; $products_ip_ranges = new products_ip_ranges(); $array = $products_ip_ranges->skype_networks(); if ($GLOBALS["VERBOSE"]) { echo "skype_networks ->" . count($array) . " items [" . __LINE__ . "]\n"; } while (list($a, $b) = each($array)) { if (preg_match("#([0-9]+)-([0-9]+)#", $b)) { $f["-m iprange --dst-range {$b}"] = true; continue; } $f["--dst {$b}"] = true; } if ($GLOBALS["VERBOSE"]) { echo "[" . __LINE__ . "]: teamviewer::{$ID} -> " . count($f) . " item(s).\n"; } return $f; } if ($GroupType == "google") { include_once dirname(__FILE__) . "/ressources/class.products-ip-ranges.inc"; $products_ip_ranges = new products_ip_ranges(); $array = $products_ip_ranges->google_networks(); if ($GLOBALS["VERBOSE"]) { echo "google_networks ->" . count($array) . " items [" . __LINE__ . "]\n"; } while (list($a, $b) = each($array)) { if (preg_match("#([0-9]+)-([0-9]+)#", $b)) { $f["-m iprange --dst-range {$b}"] = true; continue; } $f["--dst {$b}"] = true; } if ($GLOBALS["VERBOSE"]) { echo "[" . __LINE__ . "]: teamviewer::{$ID} -> " . count($f) . " item(s).\n"; } return $f; } if ($GroupType == "google_ssl") { include_once dirname(__FILE__) . "/ressources/class.products-ip-ranges.inc"; $products_ip_ranges = new products_ip_ranges(); $array = $products_ip_ranges->google_ssl(); if ($GLOBALS["VERBOSE"]) { echo "google_networks ->" . count($array) . " items [" . __LINE__ . "]\n"; } while (list($a, $b) = each($array)) { if (preg_match("#([0-9]+)-([0-9]+)#", $b)) { $f["-m iprange --dst-range {$b}"] = true; continue; } $f["--dst {$b}"] = true; } if ($GLOBALS["VERBOSE"]) { echo "[" . __LINE__ . "]: teamviewer::{$ID} -> " . count($f) . " item(s).\n"; } return $f; } if ($GroupType == "dropbox") { include_once dirname(__FILE__) . "/ressources/class.products-ip-ranges.inc"; $products_ip_ranges = new products_ip_ranges(); $array = $products_ip_ranges->dropbox_networks(); if ($GLOBALS["VERBOSE"]) { echo "google_networks ->" . count($array) . " items [" . __LINE__ . "]\n"; } while (list($a, $b) = each($array)) { if (preg_match("#([0-9]+)-([0-9]+)#", $b)) { $f["-m iprange --dst-range {$b}"] = true; continue; } $f["--dst {$b}"] = true; } if ($GLOBALS["VERBOSE"]) { echo "[" . __LINE__ . "]: dropbox::{$ID} -> " . count($f) . " item(s).\n"; } return $f; } $IpClass = new IP(); $sql = "SELECT pattern FROM webfilters_sqitems WHERE gpid={$ID} AND enabled=1"; $f = array(); $results = $q->QUERY_SQL($sql); if (!$q->ok) { echo "[" . __LINE__ . "]: {$q->mysql_error}\n"; } while ($ligne = mysql_fetch_assoc($results)) { $pattern = trim($ligne["pattern"]); if ($pattern == null) { continue; } if ($GLOBALS["VERBOSE"]) { echo "[" . __LINE__ . "]: src_items:{$ID} -> {$pattern} item.\n"; } if ($GroupType == "arp") { if (!$IpClass->IsvalidMAC($pattern)) { if ($GLOBALS["VERBOSE"]) { echo "[" . __LINE__ . "]: src_items:{$ID} -> {$pattern} INVALID.\n"; } continue; } if ($GLOBALS["VERBOSE"]) { echo "[" . __LINE__ . "]: src_items:{$ID} -> ADD -m mac --mac-source {$pattern}.\n"; } $f["-m mac --mac-source {$pattern}"] = true; continue; } if ($GroupType == "src") { if (preg_match("#[0-9\\.]+-[0-9\\.]+#", $pattern)) { $f["-m iprange --src-range {$pattern}"] = true; continue; } $f["--source {$pattern}"] = true; continue; } if ($GroupType == "dst") { if (preg_match("#[0-9\\.]+-[0-9\\.]+#", $pattern)) { $f["-m iprange --dst-range {$pattern}"] = true; continue; } $f["--dst {$pattern}"] = true; continue; } if ($GroupType == "port") { $f[$pattern] = true; } } if ($GroupType == "port") { $T = array(); if ($IsArray) { $T[] = 0; } while (list($a, $b) = each($f)) { $T[] = $a; } if ($IsArray) { return $T; } if (count($T) == 0) { return null; } if (count($T) == 1) { return "--destination-port " . @implode("", $T); } return "--destination-ports " . @implode(",", $T); } if ($GLOBALS["VERBOSE"]) { echo "[" . __LINE__ . "]: src_items:{$ID} -> " . count($f) . " item(s).\n"; } return $f; }
function trusted_macs() { $Ipclass = new IP(); $q = new mysql_squid_builder(); $f = array(); $results = $q->QUERY_SQL("SELECT * FROM hotspot_whitemacs WHERE enabled=1"); $Count = mysql_num_rows($results); if ($GLOBALS["OUTPUT"]) { echo "Configuring...: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]}: Checking {$Count} trusted MAC(s)\n"; } if ($Count == 0) { return null; } while ($ligne = mysql_fetch_assoc($results)) { $MAC = $ligne["MAC"]; if (!$Ipclass->IsvalidMAC($MAC)) { continue; } $f[] = $MAC; } if (count($f) > 0) { return @implode(",", $f); } }
function wifidog_login($error = null) { $sock = new sockets(); session_start(); $ipClass = new IP(); $tpl = new templates(); $USE_TERMS_ACCEPTED = false; header('Content-Type: text/html; charset=iso-8859-1'); $gateway_addr = $_REQUEST["gw_address"]; $gw_port = $_REQUEST["gw_port"]; $gw_id = $_REQUEST["gw_id"]; $ARP = $_REQUEST["mac"]; $url = $_REQUEST["url"]; if (isset($_POST["wifidog-terms"])) { $_SESSION["USE_TERMS_ACCEPTED"] = true; $USE_TERMS_ACCEPTED = true; } if (isset($_SESSION["USE_TERMS_ACCEPTED"])) { $USE_TERMS_ACCEPTED = true; } if (!$ipClass->IsvalidMAC($ARP)) { $text_form = $tpl->_ENGINE_parse_body(FATAL_ERROR_SHOW_128("{hostspot_network_incompatible}")); } if (!isset($_REQUEST["token"])) { $_REQUEST["token"] = generateToken($ARP); } $wifidog_build_uri = wifidog_build_uri(); $uriext = $wifidog_build_uri[0]; $HiddenFields = $wifidog_build_uri[1]; $ArticaHotSpotSMTP = SMTP_SETTINGS(); if ($ArticaHotSpotSMTP["USE_TERMS"] == 1) { if (!$USE_TERMS_ACCEPTED) { return wifidog_terms(); } } $fontsize = $ArticaHotSpotSMTP["SKIN_FONT_SIZE"]; $ArticaSplashHotSpotTitle = $sock->GET_INFO("ArticaSplashHotSpotTitle"); if ($ArticaSplashHotSpotTitle == null) { $ArticaSplashHotSpotTitle = "HotSpot system"; } $tpl = new templates(); $username = $tpl->_ENGINE_parse_body("{username}"); $password = $tpl->_ENGINE_parse_body("{password}"); $please_sign_in = $tpl->_ENGINE_parse_body("{please_sign_in}"); $page = CurrentPageName(); $ArticaSplashHotSpotTitle = $sock->GET_INFO("ArticaSplashHotSpotTitle"); if ($ArticaSplashHotSpotTitle == null) { $ArticaSplashHotSpotTitle = "HotSpot system"; } $lost_password_text = $tpl->_ENGINE_parse_body("{lost_password}"); if (!isset($ArticaHotSpotSMTP["ENABLED_AUTO_LOGIN"])) { $ArticaHotSpotSMTP["ENABLED_AUTO_LOGIN"] = 0; } if (!isset($ArticaHotSpotSMTP["ENABLED_SMTP"])) { $ArticaHotSpotSMTP["ENABLED_SMTP"] = 0; } $t = time(); unset($_SESSION["HOTSPOT_AUTO_RECOVER"]); $_SESSION["HOTSPOT_REDIRECT_URL"] = $url; $url_encoded = urlencode($url); $Connexion = $tpl->_ENGINE_parse_body("{connection}"); $page = CurrentPageName(); $f[] = ""; $f[] = " <div id='content'>"; $f[] = " "; $f[] = "\t\t\t<form id='wifidogform' action=\"{$page}\" method=\"post\">"; $f[] = "{$HiddenFields}"; $f[] = "\t\t\t\t<div class=\"f\">"; $f[] = "\t\t\t\t\t<div class=\"field\">"; $f[] = "\t\t\t\t\t\t<label for=\"username\" style='font-size:{$ArticaHotSpotSMTP["SKIN_LABEL_FONT_SIZE"]}'>{$username}:</label> <input type=\"text\" \n\t\tname=\"username\" \n\t\tid=\"username\"\n\t\tvalue=\"{$_REQUEST["username"]}\" \n\t\tonfocus=\"this.setAttribute('class','active');RemoveLogonCSS();\" \n\t\tonblur=\"this.removeAttribute('class');\" \n\t\tOnKeyPress=\"javascript:SendLogon{$t}(event)\">"; $f[] = "\t\t"; $f[] = "</div>"; $f[] = "\t<div class=\"field\">"; $f[] = "\t\t<label for=\"password\" style='font-size:{$ArticaHotSpotSMTP["SKIN_LABEL_FONT_SIZE"]}'>{$password}:</label> <input type=\"password\" name=\"password\" \n\t\t\t\tvalue=\"{$_REQUEST["password"]}\"\n\t\t\t\tid=\"password\" onfocus=\"this.setAttribute('class','active');RemoveLogonCSS();\" \n\t\t\t\tonblur=\"this.removeAttribute('class');\" OnKeyPress=\"javascript:SendLogon{$t}(event)\">"; if ($ArticaHotSpotSMTP["ENABLED_SMTP"] == 1) { $f[] = "<div style='text-align:right'><a href=\"{$page}?wifidog-recover=yes&email={$_REQUEST["username"]}&{$uriext}\">{$lost_password_text}</a></div>"; } $f[] = "\t\t\t\t\t</div>"; $f[] = "\t\t\t\t\t<div class=\"field button\">"; if ($ArticaHotSpotSMTP["ENABLED_AUTO_LOGIN"] == 1) { $register = $tpl->_ENGINE_parse_body("{register}"); $f[] = "\t\t\t\t\t\t<a data-loading-text=\"Chargement...\"\n\t\tstyle=\"font-size:{$fontsize};text-transform:capitalize\"\n\t\tclass=\"Button2014 Button2014-success Button2014-lg\"\n\t\tid=\"fb92ae5e1f7bbea3b5044cbcdd40f088\"\n\t\thref=\"{$page}?wifidog-register=yes&{$uriext}\">« {$register} »</a>"; } $f[] = "<a data-loading-text=\"Chargement...\" \n\t\t\tstyle=\"font-size:{$fontsize};text-transform:capitalize\" \n\t\t\tclass=\"Button2014 Button2014-success Button2014-lg\" \n\t\t\tid=\"fb92ae5e1f7bbea3b5044cbcdd40f088\" \n\t\t\tonclick=\"javascript:document.forms['wifidogform'].submit();\" \n\t\t\thref=\"javascript:Blurz()\">« {$Connexion} »</a>"; $f[] = "\t\t\t\t\t</div>"; if ($ArticaHotSpotSMTP["SKIN_TEXT_LOGON"] != null) { $f[] = "<p style='font-size:{$ArticaHotSpotSMTP["SKIN_FONT_SIZE"]};padding:8px'>{$ArticaHotSpotSMTP["SKIN_TEXT_LOGON"]}</p>"; } $f[] = "\t\t\t\t</div>"; $f[] = "\t\t"; $f[] = "\t\t\t</form>\t"; $f[] = "</div>\n\t<script>\n\t\tfunction SendLogon{$t}(e){\n\t\t\tif(!checkEnter(e)){return;}\n\t\t\tdocument.forms['wifidogform'].submit();\n\t\t}\n\t</script>\n\t\n"; $text_form = @implode("\n", $f); echo BuildFullPage($text_form, $error); }
function search() { $Mypage = CurrentPageName(); $tpl = new templates(); $q = new mysql_squid_builder(); $t = time(); $fontsize = 13; $type = $_GET["type"]; $field_query = "size"; $field_query2 = "SUM(size)"; $table_field = "{size}"; $category = $tpl->_ENGINE_parse_body("{category}"); $table = "WEEK_RTTH"; $member = $tpl->_ENGINE_parse_body("{member}"); $sitename = $tpl->_ENGINE_parse_body("{website}"); $search = '%'; $page = 1; $ORDER = "ORDER BY ID DESC"; $ip = new IP(); $Select = "MAC"; $FORCE_FILTER = " AND `MAC`='{$_GET["MAC"]}'"; if ($ip->isIPAddress($_GET["ipaddr"])) { $Select = "ipaddr"; $FORCE_FILTER = "ipaddr='{$_GET["ipaddr"]}'"; } if ($ip->IsvalidMAC($_GET["MAC"])) { $Select = "MAC"; $FORCE_FILTER = "MAC='{$_GET["MAC"]}'"; } $table = "(SELECT `day`,SUM(size) as size,{$Select} FROM WEEK_RTTH GROUP BY `day`,{$Select} HAVING {$FORCE_FILTER}) as t"; if (isset($_POST["sortname"])) { if ($_POST["sortname"] != null) { $ORDER = "ORDER BY {$_POST["sortname"]} {$_POST["sortorder"]}"; } } if (isset($_POST['page'])) { $page = $_POST['page']; } if (isset($_POST['rp'])) { $rp = $_POST['rp']; } $search = string_to_flexquery(); if ($search != null) { $sql = "SELECT COUNT(*) as TCOUNT FROM {$table}"; $ligne = mysql_fetch_array($q->QUERY_SQL($sql)); $total = $ligne["TCOUNT"]; } else { $sql = "SELECT COUNT(*) as TCOUNT FROM {$table}"; $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 {$search} {$ORDER} {$limitSql}"; $results = $q->QUERY_SQL($sql); $data = array(); $data['page'] = 0; $data['total'] = $total; $data['rows'] = array(); if (!$q->ok) { json_error_show($q->mysql_error); } if (mysql_num_rows($results) == 0) { json_error_show("no data"); } $data['total'] = mysql_num_rows($results); $style = "style='font-size:22px'"; while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) { $ligne["size"] = FormatBytes($ligne["size"] / 1024); $categorize = "Loadjs('squid.categorize.php?www={$ligne["sitename"]}')"; if (trim($ligne["category"]) == null) { $ligne["category"] = "<span style='color:#D70707'>{categorize_this_website}</span>"; } $id = md5(@implode("", $ligne)); if (trim($ligne["uid"]) == "-") { $ligne["uid"] = null; } if (trim($ligne["uid"]) == null) { $ligne["uid"] = $q->UID_FROM_MAC($ligne["MAC"]); } if (trim($ligne["uid"]) == null) { $ligne["uid"] = $q->UID_FROM_IP($ligne["CLIENT"]); } $categorize = "<a href=\"javascript:blur()\" \n\t\tOnClick=\"javascript:{$categorize}\" \n\t\tstyle='font-size:{$fontsize}px;text-decoration:underline'>"; $familysite = $q->GetFamilySites($ligne["sitename"]); $TrafficHour = "<a href=\"javascript:blur()\" \n\t\tOnClick=\"javascript:Loadjs('squid.traffic.statistics.hours.php?familysite={$ligne["sitename"]}&day={$_GET["day"]}')\" \n\t\tstyle='font-size:{$fontsize}px;text-decoration:underline'>"; $dd = date("Y-m"); $D = $q->time_to_date(strtotime("{$dd}-{$ligne["day"]} 00:00:00")); $data['rows'][] = array('id' => $id, 'cell' => array("<span {$style}>{$D}</span>", "<span {$style}>{$ligne["size"]}</a></span>")); } echo json_encode($data); }
function search() { $tpl = new templates(); $MyPage = CurrentPageName(); $q = new mysql_squid_builder(); $t = $_GET["t"]; $total = 0; if ($q->COUNT_ROWS("dashboard_user_day", "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']; } $table = "(SELECT SUM(RQS) as RQS, SUM(SIZE) as SIZE,USER FROM dashboard_user_day GROUP BY USER ) as t"; $searchstring = string_to_flexquery(); if (isset($_POST['rp'])) { $rp = $_POST['rp']; } if (!is_numeric($rp)) { $rp = 100; } $pageStart = ($page - 1) * $rp; if ($pageStart < 0) { $pageStart = 0; } $limitSql = "LIMIT {$pageStart}, {$rp}"; $sql = "SELECT * FROM {$table} WHERE 1 {$searchstring} {$ORDER} {$limitSql}"; writelogs($sql, __FUNCTION__, __FILE__, __LINE__); $results = $q->QUERY_SQL($sql, "artica_events"); $total = mysql_num_rows($results); 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(); $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'>"; $IPTCP = new IP(); while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) { $zmd5 = $ligne["zmd5"]; $member_value = trim($ligne["USER"]); $hits = FormatNumber($ligne["RQS"]); $size = FormatBytes($ligne["SIZE"] / 1024); $ahref = null; $member_assoc = null; $graph = imgtootltip("graph2-48.png", "{statistics}", "Loadjs('{$MyPage}?graph-js=yes&uid=" . urlencode($member_value) . "')"); $graph2 = imgtootltip("graphs-48.png", "{statistics}", "Loadjs('{$MyPage}?graph2-js=yes&uid=" . urlencode($member_value) . "')"); if ($IPTCP->IsvalidMAC($member_value)) { $mac_encoded = urlencode($member_value); $uid = $q->MacToUid($member_value); if ($uid != null) { $member_assoc = " ({$uid})"; } $ahref = "<a href=\"javascript:blur();\"\n\t\t\t\t\tOnClick=\"javascript:Loadjs('squid.nodes.php?node-infos-js=yes&MAC={$mac_encoded}');\"\n\t\t\t\t\tstyle='font-size:{$fontsize};text-decoration:underline'>"; } $data['rows'][] = array('id' => $member_value, 'cell' => array("{$span}{$ahref}{$member_value}</a>{$member_assoc}</span>", "{$span}{$hits}</a></span>", "{$span}{$size}</a></span>", "<center>{$graph}</center>", "<center>{$graph2}</center>")); } echo json_encode($data); }
function nodes_list() { $tpl = new templates(); $MyPage = CurrentPageName(); $q = new mysql_squid_builder(); $defaultday = $q->HIER(); $TableActive = date('Ymd', strtotime($defaultday . " 00:00:00")) . "_hour"; $t = $_GET["t"]; $filterby = $_GET["filterby"]; $search = '%'; $table = "UserAutDB"; $page = 1; $FORCE_FILTER = null; $total = 0; if ($q->COUNT_ROWS($table) == 0) { json_error_show("No data"); } $table = "(SELECT {$filterby} FROM {$table} GROUP BY {$filterby} HAVING LENGTH({$filterby})>0) as t"; if (isset($_POST["sortname"])) { if ($_POST["sortname"] != null) { $ORDER = "ORDER BY {$_POST["sortname"]} {$_POST["sortorder"]}"; } } if (isset($_POST['page'])) { $page = $_POST['page']; } $searchstring = string_to_flexquery(); if ($searchstring != null) { $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); $data = array(); $data['page'] = $page; $data['total'] = $total; $data['rows'] = array(); if (!$q->ok) { json_error_show("{$q->mysql_error}"); } $ipClass = new IP(); while ($ligne = mysql_fetch_assoc($results)) { $js = null; $Link = null; $TextDeco = "none"; $value = utf8_encode($ligne[$filterby]); $md5 = md5($value); $valueEnc = urlencode($ligne[$filterby]); $member = $q->UID_FROM_ALL($ligne[$filterby]); if ($filterby == "MAC") { if (!$ipClass->IsvalidMAC($ligne[$filterby])) { continue; } $js = "Loadjs('squid.nodes.php?node-infos-js=yes&MAC={$ligne[$filterby]}',true);"; } if ($js != null) { $Link = "OnClick=\"javascript:{$js}\""; $TextDeco = "underline"; } $data['rows'][] = array('id' => $md5, 'cell' => array("<a href=\"javascript:blur();\" {$Link} style='font-size:16px;text-decoration:{$TextDeco}'>{$value}</a></span>", "<a href=\"javascript:blur();\" {$Link} style='font-size:16px;text-decoration:{$TextDeco}'>{$member}</a></span>")); } echo json_encode($data); }