function MEMBER_JS_JS() { header("content-type: application/x-javascript"); $comp = new computers(); $uid = $comp->ComputerIDFromMAC($_GET["MEMBER_JS"]); echo MEMBER_JS($uid, 1, 1); }
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 parsefile($filename, $uid) { $datas = file_get_contents($filename); $tbl = explode("\n", $datas); if (!is_array($tbl)) { return null; } while (list($num, $ligne) = each($tbl)) { if (preg_match("#([0-9]+).+?open\\s+(.+)#", $ligne, $re)) { $array[] = $re[1] . ":" . $re[2]; continue; } if (preg_match("#^Running:(.+)#", $ligne, $re)) { $ComputerRunning = $re[1]; continue; } if (preg_match("#^OS details:(.+)#", $ligne, $re)) { $ComputerOS = $re[1]; continue; } if (preg_match("#^MAC Address:(.+).+?\\((.+?)\\)#", $ligne, $re)) { $ComputerMacAddress = $re[1]; $ComputerMachineType = $re[2]; continue; } if (preg_match("#^MAC Address:(.+)#", $ligne, $re)) { $ComputerMacAddress = $re[1]; continue; } } if ($ComputerMacAddress != null) { $computer = new computers(); $cpid = $computer->ComputerIDFromMAC($ComputerMacAddress); } if ($cpid == null) { $cpid = $uid; } echo "Save infos for {$cpid}\n"; echo "ComputerMacAddress: {$ComputerMacAddress}\n"; echo "ComputerOS: {$ComputerOS}\n"; $computer = new computers($cpid . "\$"); if ($ComputerMacAddress != null) { $computer->ComputerMacAddress = $ComputerMacAddress; } if ($ComputerOS != null) { $computer->ComputerOS = $ComputerOS; } if ($ComputerRunning != null) { $computer->ComputerRunning = $ComputerRunning; } if ($ComputerMachineType != null) { $computer->ComputerMachineType = $ComputerMachineType; } if (is_array($array)) { $computer->ComputerOpenPorts = implode("\n", $array); } $computer->Edit(); echo $datas; }
function search() { $search = $_GET["search"]; $search = "*{$search}*"; $search = str_replace("**", "*", $search); $search = str_replace("**", "*", $search); $search = str_replace("*", "%", $search); if (CACHE_SESSION_GET(__FUNCTION__ . $search, __FILE__, 15)) { return; } $page = CurrentPageName(); $tpl = new templates(); $sock = new sockets(); $q = new mysql(); $computers = new computers(); $sql = "SELECT * FROM dhcpd_logs WHERE description LIKE '{$search}' ORDER BY zDate DESC LIMIT 0,100"; $results = $q->QUERY_SQL($sql, "artica_events"); while ($ligne = mysql_fetch_array($results, MYSQL_ASSOC)) { $color = "black"; if ($classtr == "oddRow") { $classtr = null; } else { $classtr = "oddRow"; } $uid = null; $mac = null; if (preg_match("#to\\s+([0-9a-z:]+)\\s+via#", $ligne["description"], $re)) { $mac = $re[1]; } if (preg_match("#from\\s+([0-9a-z:]+)\\s+via#", $ligne["description"], $re)) { $mac = $re[1]; } if ($mac != null) { $uid = $computers->ComputerIDFromMAC($mac); if ($uid != null) { $uri = "<a href=\"javascript:blur();\" OnClick=\"javascript:YahooUser(870,'domains.edit.user.php?userid={$uid}&ajaxmode=yes&dn=','{$uid}');\" style='font-size:14px;font-weight:bold;color:{$color};text-decoration:underline'>{$mac}</a> <span style='font-size:11px'>({$uid})</span>"; $ligne["description"] = str_replace($mac, $uri, $ligne["description"]); } } $html = $html . "\n\t\t<tr class={$classtr}>\n\t\t\t\n\t\t\t<td style='font-size:14px;font-weight:bold;color:{$color}' width=1% nowrap>{$ligne["zDate"]}</div></td>\n\t\t\t<td style='font-size:14px;font-weight:bold;color:{$color}' width=99% >{$ligne["description"]}</div></td>\n\t\t</tr>\n\t\t"; } $header = "<center>\n<table cellspacing='0' cellpadding='0' border='0' class='tableView' style='width:100%'>\n<thead class='thead'>\n\t<tr>\n\t\t<th width=99% colspan=2>{events}</th>\n\t</tr>\n</thead>\n<tbody class='tbody'>"; $html = $header . $html . "</table>\n\t</center>\n\t\n\t<script>\n\n\t</script>\n\t"; CACHE_SESSION_SET(__FUNCTION__ . $search, __FILE__, $tpl->_ENGINE_parse_body($html)); }
function computers_search() { $tpl = new templates(); $MyPage = CurrentPageName(); $boot = new boostrap_form(); $q = new mysql(); $sock = new sockets(); $fontsize = "14px"; $page = 1; if (!$q->DATABASE_EXISTS("ocsweb")) { $sock->getFrameWork("services.php?mysql-ocs=yes"); } if (!$q->TABLE_EXISTS("hardware", "ocsweb")) { $sock->getFrameWork("services.php?mysql-ocs=yes"); } if (!$q->TABLE_EXISTS("networks", "ocsweb", true)) { $sock->getFrameWork("services.php?mysql-ocs=yes"); } $EnableScanComputersNet = $sock->GET_INFO("EnableScanComputersNet"); if (!is_numeric($EnableScanComputersNet)) { $EnableScanComputersNet = 0; } if (!$q->FIELD_EXISTS("networks", "isActive", "ocsweb")) { $q->QUERY_SQL("ALTER TABLE `networks` ADD `isActive` SMALLINT( 1 ) NOT NULL DEFAULT '0',ADD INDEX ( `isActive` ) ", "ocsweb"); } $ORDER = $boot->TableOrder(array("NAME" => "ASC")); $searchstring = string_to_flexquery("computer-search"); $table = "(SELECT networks.MACADDR,networks.IPADDRESS,\n\t\t\thardware.OSNAME,\n\t\t\thardware.LASTDATE,\n\t\t\thardware.NAME,\n\t\t\thardware.IPADDR,\n\t\t\thardware.IPSRC\n\t\t\tFROM networks,hardware WHERE networks.HARDWARE_ID=hardware.ID) as t"; $sql = "SELECT * FROM {$table} WHERE 1 {$searchstring} ORDER BY {$ORDER} LIMIT 0,250"; $results = $q->QUERY_SQL($sql, "ocsweb"); if (!$q->ok) { echo $q->mysql_error . "<br>{$sql}\n"; } $computer = new computers(); while ($ligne = mysql_fetch_array($results, MYSQL_ASSOC)) { if ($ligne["MACADDR"] == "unknown") { continue; } $uid = null; $OSNAME = null; if ($ligne["OSNAME"] == "Unknown") { $ligne["OSNAME"] = null; } $color = "#7D7D7D"; $md = md5($ligne["MACADDR"]); $uri = strtolower($ligne["NAME"]); $uid = $computer->ComputerIDFromMAC($ligne["MACADDR"]); $view = " "; $jsfiche = MEMBER_JS($uid, 1, 1); $js = null; if ($uid != null) { $js = $boot->trswitch($jsfiche); } if ($ligne["OSNAME"] != null) { $OSNAME = "<div style='font-size:9px'><i>{$ligne["OSNAME"]}</i></div>"; } $isActive = "img/unknown24.png"; if ($EnableScanComputersNet == 1) { if ($ligne["isActive"] == 1) { $isActive = "img/ok24.png"; } else { $isActive = "img/danger24.png"; } } if (!IsPhysicalAddress($ligne["MACADDR"])) { if ($_GET["CorrectMac"] == 1) { continue; } } $AlreadyMAC[$ligne["MACADDR"]] = true; $zdate = null; if (isset($ligne["zDate"])) { $zdate = "<div style='font-size:11px;color:#7D7D7D'>{$ligne["zDate"]}</div>"; } $tr[] = "\n\t\t<tr>\n\t\t\t<td style='font-size:18px' nowrap width=1% {$js}>{$ligne["LASTDATE"]}</td>\n\t\t\t<td style='font-size:18px' nowrap {$js}>{$ligne["NAME"]}</td>\n\t\t\t<td style='font-size:18px' nowrap width=1% {$js}>{$ligne["IPADDRESS"]}</td>\n\t\t\t<td style='font-size:18px' nowrap width=1% {$js}>{$ligne["MACADDR"]}</td>\n\t\t\t<td style='font-size:18px' nowrap width=1% {$js}><img src='{$isActive}'></td>\t\t\t\n\t\t\t\t\n\t\t</tr>"; } echo $boot->TableCompile(array("LASTDATE" => "{date}", "NAME" => "{hostname}", "IPADDRESS" => "{ipaddr}", "MACADDR" => "{MAC}"), $tr); }
function popup_connected_search() { $ocs = new ocs(); $sql = $ocs->COMPUTER_SEARCH_QUERY($_GET["connected-search"]); $CONFIG = $ocs->GET_SERVER_SETTINGS(); $PROLOG_FREQ = $CONFIG["PROLOG_FREQ"] * 60; $q = new mysql(); $results = $q->QUERY_SQL($sql, "ocsweb"); if (!$q->ok) { echo "<p> </p><p style='font-size:15px'>{$q->mysql_error}<hr>{$sql}</p>"; return; } $html = "\n\t<table style='width:100%;'>\n\t<tr>\n\t\t<th colspan=2>{computer}</th>\n\t\t<th>{status}</th>\n\t\t<th>{ComputerMacAddress}</th>\n\t\t<th>{ip_address}</th>\n\t</tr>"; while ($ligne = mysql_fetch_array($results, MYSQL_ASSOC)) { if ($ligne["IPADDRESS"] == "0.0.0.0") { continue; } if ($ligne["MACADDR"] == "00:00:00:00:00:00") { continue; } if ($already[$ligne["MACADDR"]]) { continue; } if ($already[$ligne["NAME"] . $ligne["IPSRC"]]) { continue; } $status = null; $already[$ligne["MACADDR"]] = true; $already[$ligne["NAME"] . $ligne["IPADDRESS"]] = true; $f = new computers(); $uid = $f->ComputerIDFromMAC($ligne["MACADDR"]); if (trim($uid) != null) { $already[$ligne["NAME"] . $ligne["IPSRC"]] = true; } $js = MEMBER_JS($uid, 1, 1); $last = distanceOfTimeInWords(strtotime($ligne["LASTCOME"]), time()); $mins = distanceMinStrings($ligne["LASTCOME"]); $js_text = "{$ligne["NAME"]}<hr>{last_com}:{$last}<hr>{$ligne["IPADDRESS"]}"; if ($mins > $PROLOG_FREQ) { $status = imgtootltip('status_service_removed.png', $last); $js_text = "{$ligne["NAME"]}<hr><span color:red>{last_com}:{$last}</span>"; } else { $status = imgtootltip('status_service_run.png', $last); } if ($uid == null) { $js = null; $status = imgtootltip("status_warning.gif", "{ocs_computer_is_not_in_ldap}", "AddComputerFromOCS('{$ligne["MACADDR"]}')", null, md5($ligne["MACADDR"]) . time()); $js_text = "{ocs_computer_is_not_in_ldap}"; } else { } if (trim($ligne["IPADDRESS"]) != null) { if (trim($ligne["IPSRC"]) != trim($ligne["IPADDRESS"])) { $ligne["IPSRC"] = $ligne["IPSRC"] . "/" . $ligne["IPADDRESS"]; } } $html = $html . "\n\t\t<tr " . CellRollOver($js, $js_text) . ">\n\t\t\t<td width=1%><img src='img/laptop-32.png'></td>\n\t\t\t<td style='font-size:13px'>{$ligne["NAME"]}</td>\n\t\t\t<td width=1% align='center' valign='middle'>{$status}</td>\n\t\t\t<td style='font-size:13px'>{$ligne["MACADDR"]}</td>\n\t\t\t<td style='font-size:12px'>{$ligne["IPSRC"]}</td>\n\t\t</tr>\n\t\t\n\t\t"; } $html = $html . "</table>\n\t\n\t"; $tpl = new templates(); echo $tpl->_ENGINE_parse_body($html); }
function update_computer($ip, $mac, $name) { $sock = new sockets(); $ComputersAllowDHCPLeases = $sock->GET_INFO("ComputersAllowDHCPLeases"); if ($ComputersAllowDHCPLeases == null) { $ComputersAllowDHCPLeases = 1; } if ($ComputersAllowDHCPLeases == 0) { localsyslog("`ComputersAllowDHCPLeases` Aborting updating the LDAP database"); return; } $mac = trim($mac); $name = trim(strtolower($name)); $ip = trim($ip); if ($ip == null) { return; } if ($mac == null) { return; } if ($name == null) { return; } $mac = strtolower(str_replace("-", ":", $mac)); $ipClass = new IP(); if ($ipClass->isIPAddress($name)) { localsyslog("`{$name}` is a TCP IP address, aborting updating the LDAP database"); return; } $ip = nmblookup($name, $ip); $dhcp = new dhcpd(); $GLOBALS["domain"] = $dhcp->ddns_domainname; $comp = new computers(); $uid = $comp->ComputerIDFromMAC($mac); if (strpos($name, ".") > 0) { $NAMETR = explode(".", $name); $name = $NAMETR[0]; unset($NAMETR[0]); $GLOBALS["domain"] = @implode(".", $NAMETR); } if ($ipClass->isIPAddress($uid)) { $comp = new computers($uid); localsyslog("Removing computer ({$uid}) {$mac}"); $comp->DeleteComputer(); $uid = null; $uid = $comp->ComputerIDFromMAC($mac); } localsyslog("{$mac} -> uid:`{$uid}`"); if ($uid == null) { $add = true; $uid = "{$name}\$"; $comp = new computers(); $comp->ComputerRealName = $name; $comp->ComputerMacAddress = $mac; $comp->ComputerIP = $ip; $comp->DnsZoneName = $GLOBALS["domain"]; $comp->uid = $uid; $ComputerRealName = $name; localsyslog("Create new computer {$name[$ip]} ({$uid}) {$mac} in domain {$comp->DnsZoneName}"); $comp->Add(); } else { $comp = new computers($uid); if (strpos($comp->ComputerRealName, ".") > 0) { $NAMETR = explode(".", $name); $comp->ComputerRealName = $NAMETR[0]; } if ($comp->ComputerRealName == null) { $comp->ComputerRealName = $name; } if ($ipClass->isIPAddress($comp->ComputerRealName)) { $comp->ComputerRealName = $name; } $comp->ComputerIP = $ip; $comp->DnsZoneName = $GLOBALS["domain"]; localsyslog("Update computer {$comp->ComputerRealName}[{$ip}] ({$uid}) {$mac} in domain {$comp->DnsZoneName}"); $comp->Edit(); } $dns = new pdns($GLOBALS["domain"]); $dns->EditIPName(strtolower($name), $ip, 'A', $mac); }
function AutomaticInjectionAdd($MAC) { echo "add {$MAC}\n"; $cs = new ocs(); if ($cs->INJECT_COMPUTER_TOLDAP($MAC)) { unset($GLOBALS["INJECT_COMPUTER_TOLDAP"]); $f = new computers(); $uid = $f->ComputerIDFromMAC($ligne["MACADDR"]); $f = new computers($uid); $text[] = "uid\t:{$uid}"; $text[] = "Computer\t:{$f->ComputerRealName}"; $text[] = "IP\t:{$f->ComputerIP}"; $text[] = "MAC\t:{$MAC}"; send_email_events("New computer {$f->ComputerRealName} added into Database", @implode("\n", $text), "system"); } else { $infos = @implode("\n", $GLOBALS["INJECT_COMPUTER_TOLDAP"]) . "\n\n" . @implode("\n", $text); send_email_events("Failed to inject computer {$f->ComputerRealName} ({$MAC})", $infos, "system"); } }
function update_computer($ip, $mac, $name) { $sock = new sockets(); $ComputersAllowDHCPLeases = $sock->GET_INFO("ComputersAllowDHCPLeases"); if ($ComputersAllowDHCPLeases == null) { $ComputersAllowDHCPLeases = 1; } if ($ComputersAllowDHCPLeases == 0) { writelogs("ComputersAllowDHCPLeases is disabled, aborting...", "update_computer", __FILE__, __LINE__); die; } $mac = trim($mac); $name = trim(strtolower($name)); $ip = trim($ip); if ($ip == null) { return; } if ($mac == null) { return; } if ($name == null) { return; } $ip = nmblookup($name, $ip); $unix = new unix(); $unix->add_EtcHosts($name, $ip); $dhcp = new dhcpd(); $GLOBALS["domain"] = $dhcp->ddns_domainname; $comp = new computers(); $uid = $comp->ComputerIDFromMAC($mac); if ($uid == null) { $add = true; $uid = "{$name}\$"; $comp = new computers(); $comp->ComputerRealName = $name; $comp->ComputerMacAddress = $mac; $comp->ComputerIP = $ip; $comp->DnsZoneName = $GLOBALS["domain"]; $comp->uid = $uid; $ComputerRealName = $HOST; $comp->Add(); } else { $comp = new computers($uid); if ($comp->ComputerRealName == null) { $ComputerRealName = $name; } if (preg_match("#[0-9]+\\.[0-9]+\\.#", $comp->ComputerRealName)) { $comp->ComputerRealName = $name; } $comp->ComputerIP = $ip; $comp->DnsZoneName = $GLOBALS["domain"]; $comp->Edit(); } $dns = new pdns($GLOBALS["domain"]); $dns->EditIPName(strtolower($name), $ip, 'A', $mac); }
function SearchComputers() { $tpl = new templates(); $page = CurrentPageName(); $q = new mysql(); $search = "*" . $_GET["SearchComputers"] . "*"; $search = str_replace("**", "*", $search); $search = str_replace("**", "*", $search); $search = str_replace("*", "%", $search); $order = "ORDER BY hardware.LASTDATE DESC"; if (trim($_GET["orderBydate"]) != null) { $order = "ORDER BY hardware.LASTDATE {$_GET["orderBydate"]} "; } $add_computer_js = "YahooUser(780,'domains.edit.user.php?userid=newcomputer\$&ajaxmode=yes','New computer');"; $add = imgtootltip("plus-24.png", "{add}", $add_computer_js); $sql = "SELECT networks.*,hardware.* FROM networks,hardware WHERE\n\tnetworks.HARDWARE_ID=hardware.ID\n\tAND ( (hardware.NAME LIKE '{$search}') OR (networks.MACADDR LIKE '{$search}') OR (networks.IPADDRESS LIKE '{$search}') OR (hardware.OSNAME LIKE '{$search}'))\n\t{$order} LIMIT 0,30\n\t"; $html = "<center>\n<table cellspacing='0' cellpadding='0' border='0' class='tableView' style='width:100%'>\n<thead class='thead'>\n\t<tr>\n\t\t<th width=1%>{$add}</th>\n\t\t<th><a href=\"javascript:blur();\" OnClick=\"OcsFilterBYDate()\" style='font-weight:bold;text-decoration:underline'>{date}</a></th>\n\t\t<th>{hostname}</th>\n\t\t<th>{ipaddr}</th>\n\t\t<th>MAC</th>\n\t\t<th> </th>\n\t</tr>\n</thead>\n<tbody class='tbody'>"; $results = $q->QUERY_SQL($sql, "ocsweb"); $computer = new computers(); if (!$q->ok) { if (preg_match("#Unknown database#", $q->mysql_error)) { $sock = new sockets(); $sock->getFrameWork("services.php?mysql-ocs=yes"); $results = $q->QUERY_SQL($sql, "ocsweb"); } if (!$q->ok) { echo "<H2>{$q->mysql_error}</H2>"; } } $cs = 0; while ($ligne = mysql_fetch_array($results, MYSQL_ASSOC)) { if ($ligne["MACADDR"] == "unknown") { continue; } $color = "black"; $uid = null; $OSNAME = null; if ($ligne["OSNAME"] == "Unknown") { $ligne["OSNAME"] = null; } //$delete=imgtootltip("delete-32.png","{delete}","CgroupProcessDel('{$ligne["process_name"]}')"); if ($classtr == "oddRow") { $classtr = null; } else { $classtr = "oddRow"; } $md = md5($ligne["MACADDR"]); $uid = $computer->ComputerIDFromMAC($ligne["MACADDR"]); $view = " "; $jsfiche = MEMBER_JS($uid, 1, 1); $uri = $ligne["NAME"]; if ($uid != null) { $view = imgtootltip("computer-32.png", "{view}", $jsfiche); } $js[] = "LoadAjaxTiny('cmp-{$md}','{$page}?compt-status={$ligne["IPADDRESS"]}');"; if ($ligne["OSNAME"] != null) { $OSNAME = "<div style='font-size:9px'><i>{$ligne["OSNAME"]}</i></div>"; } if ($_GET["callback"] != null) { $view = imgtootltip("arrow-down-32.png", "{select}", "{$_GET["callback"]}('{$uid}')"); $uri = texttooltip($ligne["NAME"], "{view}", $jsfiche, null, 0, "font-size:12px;text-decoration:underline"); } $cs++; $html = $html . "\n\t\t<tr class={$classtr}>\n\t\t\t<td style='font-size:12px;font-weight:normal;color:{$color}' width=1% nowrap>{$view}</td>\n\t\t\t<td style='font-size:12px;font-weight:normal;color:{$color}' width=1% nowrap>{$link}{$ligne["LASTDATE"]}</a></td>\n\t\t\t<td style='font-size:12px;font-weight:bold;color:{$color}' width=99%>{$link}{$uri}</a>{$OSNAME}</td>\n\t\t\t<td style='font-size:12px;font-weight:bold;color:{$color}' width=1%>{$link}{$ligne["IPADDRESS"]}</a></td>\n\t\t\t<td style='font-size:12px;font-weight:bold;color:{$color}' width=1%>{$link}{$ligne["MACADDR"]}</a></td>\n\t\t\t<td width=1%><input type=hidden id='ipaddr-{$cs}' value='{$ligne["IPADDRESS"]}'><div id='cmp-{$cs}'><img src='img/unknown24.png'></div></td>\n\t\t</tr>\n\t\t"; } $html = $html . "</tbody></table>\n\t'\n\t<script>\n\t\n\t\n\tfunction CheckIpConfig2(i){\n\t\tif(document.getElementById('ipaddr-'+i)){\n\t\t\tvar ipaddr=document.getElementById('ipaddr-'+i).value;\n\t\t\tLoadAjaxPreload('cmp-'+i,'{$page}?compt-status='+ipaddr);\n\t\t\ti=i+1;\n\t\t\tsetTimeout('CheckIpConfig2('+i+')',800);\t\n\t\t}\n\t}\n\t\n\t\n\n\t\n\tCheckIpConfig2(1);\n\t</script>\n\t\n\t"; echo $tpl->_ENGINE_parse_body($html); }
function changecomputername() { if (substr($_POST["userid"], strlen($_POST["userid"]) - 1, 1) != "\$") { $_POST["userid"] = $_POST["userid"] . "\$"; } $comp = new computers($_POST["userid"]); $MAC = $comp->ComputerMacAddress; $_POST["NewHostname"] = trim(strtolower($_POST["NewHostname"])); $_POST["NewHostname"] = str_replace('$', '', $_POST["NewHostname"]); $actualdn = $comp->dn; $newrdn = "cn={$_POST["NewHostname"]}\$"; $ldap = new clladp(); if (!preg_match("#^cn=(.+?),[a-zA-Z\\s]+#", $actualdn, $re)) { echo "Unable to preg_match {$actualdn}\n"; return; } $newDN = str_replace($re[1], $_POST["NewHostname"] . '$', $actualdn); if ($newDN == null) { echo "Unable to preg_match {$actualdn} -> {$re[1]}\n"; return; } if ($ldap->ExistsDN("{$newrdn},ou=Computer,dc=samba,dc=organizations,{$ldap->suffix}")) { $ldap->ldap_delete("{$newrdn},ou=Computer,dc=samba,dc=organizations,{$ldap->suffix}"); } $newParent = "ou=Computer,dc=samba,dc=organizations,{$ldap->suffix}"; if (!$ldap->Ldap_rename_dn($newrdn, $actualdn, $newParent)) { echo "Rename failed {$ldap->ldap_last_error}\nFunction:" . __FUNCTION__ . "\nFile:" . __FILE__ . "\nLine" . __LINE__ . "\n\nActual DN:{$actualdn}\nExpected DN:{$newrdn}"; return; } $upd["uid"][0] = $_POST["NewHostname"] . '$'; if (!$ldap->Ldap_modify($newDN, $upd)) { echo "Update UID {$upd["uid"][0]} failed:\n{$ldap->ldap_last_error}\nFunction:" . __FUNCTION__ . "\nFile:" . __FILE__ . "\nLine" . __LINE__ . "\nExpected DN:{$newDN}\nExpected value:{$_POST["NewHostname"]}"; return; } $ocs = new ocs($MAC); $ocs->ComputerName = $_POST["NewHostname"]; $ocs->ComputerIP = $comp->ComputerIP; $ocs->EditComputer(); if (IsPhysicalAddress($comp->ComputerMacAddress)) { include_once dirname(__FILE__) . "/ressources/class.mysql.inc"; $uid = $comp->ComputerIDFromMAC($comp->ComputerMacAddress); $comp = new computers($uid); $sql = "UPDATE dhcpd_fixed SET `hostname`='{$comp->ComputerRealName}' WHERE `mac`='{$comp->ComputerMacAddress}'"; $q = new mysql(); $q->QUERY_SQL($sql, "artica_backup"); } }
function hosts_list() { $tpl = new templates(); $MyPage = CurrentPageName(); $sock = new sockets(); $Importold = $sock->GET_INFO("DHCPDOlFixedImported"); if (!is_numeric($Importold)) { $Importold = 0; } if ($Importold == 0) { hosts_import(); } $q = new mysql(); $tt = $_GET["t"]; $search = '%'; $table = "dhcpd_fixed"; $page = 1; $_POST["query"] = trim($_POST["query"]); if ($q->COUNT_ROWS($table, "artica_backup") == 0) { json_error_show("no data"); return; } 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 {$searchstring}"; $ligne = mysql_fetch_array($q->QUERY_SQL($sql, "artica_backup")); if (!$q->ok) { json_error_show($q->mysql_error . "<hr>{$sql}"); } $total = $ligne["TCOUNT"]; } else { $sql = "SELECT COUNT(*) as TCOUNT FROM `{$table}` WHERE 1"; $ligne = mysql_fetch_array($q->QUERY_SQL($sql, "artica_backup")); if (!$q->ok) { json_error_show($q->mysql_error . "<hr>{$sql}"); } $total = $ligne["TCOUNT"]; } if (isset($_POST['rp'])) { $rp = $_POST['rp']; } if (isset($_POST["sortname"])) { if ($_POST["sortname"] != null) { $ORDER = "ORDER BY {$_POST["sortname"]} {$_POST["sortorder"]}"; } } if (isset($_POST['page'])) { $page = $_POST['page']; } $pageStart = ($page - 1) * $rp; $limitSql = "LIMIT {$pageStart}, {$rp}"; $sql = "SELECT * FROM `{$table}` WHERE 1 {$searchstring} {$ORDER} {$limitSql}"; writelogs($sql, __FUNCTION__, __FILE__, __LINE__); $results = $q->QUERY_SQL($sql, "artica_backup"); if (!$q->ok) { json_error_show($q->mysql_error . "<hr>{$sql}"); } $data = array(); $data['page'] = $page; $data['total'] = $total; $data['rows'] = array(); if (mysql_num_rows($results) == 0) { json_error_show("No item<hr>{$sql}"); } while ($ligne = mysql_fetch_assoc($results)) { $jsfiche = null; $herf = null; $md5 = md5($ligne["mac"]); $cmp = new computers(); $uid = $cmp->ComputerIDFromMAC($ligne["mac"]); $routers = $ligne["routers"]; $domain_name_servers = $ligne["domain-name-servers"]; $fiche = imgsimple("computer-32-grey.png", null, null); if ($uid != null) { $jsfiche = MEMBER_JS($uid, 1, 1); $fiche = imgsimple("computer-32.png", null, $jsfiche); } if (strpos($ligne["hostname"], ".") > 0) { $ff = explode(".", $ligne["hostname"]); $ligne["hostname"] = $ff[0]; } $delete = imgtootltip("delete-32.png", "{delete} {$ligne["mac"]}", "DHCPFixedDelete('{$ligne["mac"]}','{$md5}')"); $Modify = "<a href=\"javascript:blur();\" \n\t\tOnClick=\"javascript:Loadjs('{$MyPage}?modify-dhcpd-settings-js=yes&mac={$ligne["mac"]}&t={$tt}');\" \n\t\tstyle='font-size:16px;text-decoration:underline;font-weight:bold'>"; $ligne["hostname"] = strtolower(str_replace("\$", "", $ligne["hostname"])); $ligne["mac"] = strtoupper($ligne["mac"]); $data['rows'][] = array('id' => $md5, 'cell' => array($fiche, "<span style='font-size:16px'>{$Modify}{$ligne["hostname"]}</a></span>", "<span style='font-size:16px'>{$Modify}{$ligne["mac"]}</a></span>", "<span style='font-size:16px'>{$Modify}{$ligne["ipaddr"]}</a></span>", "<span style='font-size:16px'>{$Modify}{$ligne["routers"]}</a></span>", "<span style='font-size:16px'>{$Modify}{$domain_name_servers}</a></span>", "<span style='font-size:16px'>{$ligne["domain"]}</a></span>", $delete)); } if (count($data['rows']) == 0) { json_error_show("no data"); } echo json_encode($data); }
function importcomputersFromList() { $unix = new unix(); if (!is_file("/usr/bin/arp-scan")) { $unix->DEBIAN_INSTALL_PACKAGE("arp-scan"); } $sock = new sockets(); $ipClass = new IP(); $tbl = explode("\n", $sock->GET_INFO("ComputerListToImport")); $CountOfLines = count($tbl); build_progress("{$CountOfLines} {computers}", 10); echo "[" . __LINE__ . "] {$CountOfLines} lines\n"; $i = 0; $z = 0; $max = $CountOfLines; $FAILED = 0; $SUCCESS = 0; while (list($num, $line) = each($tbl)) { $z++; $prc = $z / $CountOfLines * 100; $prc = round($prc); if ($prc < 10) { $prc = 10; } if ($prc > 90) { $prc = 90; } $proxy_alias = null; $computername = null; $IPADDR = null; $MAC = null; //pc001,192.168.1.5,d8:9e:3f:34:2d:8d,jhon_pc[br] $EXPLODED = explode(",", $line); $computername = $EXPLODED[0]; $IPADDR = $EXPLODED[1]; $MAC = $EXPLODED[2]; $MAC = str_replace("-", ":", $MAC); $MAC = strtolower($MAC); if (isset($EXPLODED[3])) { $proxy_alias = trim(strtolower($EXPLODED[3])); } if ($proxy_alias != null) { proxy_alias_add($IPADDR, $MAC, $proxy_alias); } $computername = trim($computername); if ($MAC == null) { $MAC = arp_scan_IpToMac($IPADDR); } if ($computername == null) { echo "[" . __LINE__ . "] Computer Name is null, aborting\n"; $FAILED++; continue; } if (!$ipClass->isValid($IPADDR)) { $IPADDR = null; } if (!$ipClass->IsvalidMAC($MAC)) { $MAC = null; } build_progress("{$computername} {$IPADDR}/{$MAC}/{$proxy_alias}", $prc); $cmp = new computers(); if ($MAC != null) { $uid = $cmp->ComputerIDFromMAC($MAC); } else { $uid = "{$computername}\$"; } if ($uid == null) { $uid = "{$computername}\$"; } if ($IPADDR == null) { echo "Try to resolve {$computername}\n"; $IPADDR = @gethostbyname($computername); if (!$ipClass->isValid($IPADDR)) { $IPADDR = null; } } $cmp = new computers($uid); if ($IPADDR != null) { $cmp->ComputerIP = $IPADDR; } if ($MAC != null) { $cmp->ComputerMacAddress = $MAC; } $cmp->ComputerRealName = $computername; if (!$cmp->Add()) { echo "{$computername}: {$cmp->ldap_error}\n"; $FAILED++; } else { $SUCCESS++; } $i = $i + 1; } echo "Success: {$SUCCESS}\n"; echo "Failed : {$FAILED}\n"; build_progress("{$SUCCESS} {added_computers}", 95); sleep(10); build_progress("{done}", 100); }
function list_nets() { $tpl = new templates(); $MyPage = CurrentPageName(); $q = new mysql(); $t = $_GET["t"]; $search = '%'; $table = "dhcpd_leases"; $database = 'artica_backup'; $page = 1; $FORCE_FILTER = ""; $ORDER = "ORDER BY hostname"; if (!$q->TABLE_EXISTS($table, $database)) { throw new Exception("{$table}, No such table...", 500); } if ($q->COUNT_ROWS($table, 'artica_backup') == 0) { throw new Exception("No data...", 500); } 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("search-records"); $sql = "SELECT * FROM `{$table}` WHERE 1 {$searchstring} {$FORCE_FILTER} {$ORDER} {$limitSql}"; $results = $q->QUERY_SQL($sql, 'artica_backup'); if (!$q->ok) { senderror($q->mysql_error); } if (mysql_num_rows($results) == 0) { senderror("no data"); } $sock = new sockets(); $cmp = new computers(); $boot = new boostrap_form(); while ($ligne = mysql_fetch_assoc($results)) { $id = md5(serialize($ligne)); $ligne["hostname"] = trim($ligne["hostname"]); if ($ligne["mac"] == null) { continue; } $ligne["starts"] = time_to_date(strtotime($ligne["starts"]), true); $ligne["ends"] = time_to_date(strtotime($ligne["ends"]), true); $ligne["cltt"] = time_to_date(strtotime($ligne["cltt"]), true); $ligne["tstp"] = time_to_date(strtotime($ligne["tstp"]), true); $tooltip = "<ul style=font-size:11px><li>start {$ligne["starts"]}</li>\n\t\t<li>cltt:{$ligne["cltt"]}</li> \n\t\t<li>tstp:{$ligne["tstp"]}</li></ul>"; $js = "zBlur();"; $href = null; $uid = null; $uid = $cmp->ComputerIDFromMAC($ligne["mac"]); if ($uid != null) { $js = MEMBER_JS($uid, 1, 1); $href = "<a href=\"javascript:blur()\" OnClick=\"javascript:{$js}\" style='font-size:12px;text-decoration:underline'>"; $uid = "<div style='font-size:12px'><i>({$uid})</i></div>"; } if ($ligne["hostname"] == null) { $ligne["hostname"] = " "; } if ($ligne["ipaddr"] == null) { $ligne["ipaddr"] = " "; } if ($ligne["mac"] == null) { $ligne["mac"] = " "; } $link = $boot->trswitch($js); $tr[] = "\n\t\t<tr id='{$id}'>\n\t\t<td {$link}><i class='icon-globe'></i> {$ligne["hostname"]}</a>{$uid}{$tooltip}</td>\n\t\t<td {$link} nowrap><i class='icon-info-sign'></i> {$ligne["ipaddr"]}</td>\n\t\t<td {$link} nowrap><i class='icon-star'></i> {$ligne["mac"]}</td>\n\t\t<td {$link} nowrap><i class='icon-time'></i> {$ligne["starts"]}</td>\n\t\t<td {$link} nowrap><i class='icon-time'></i> {$ligne["ends"]}</td>\n\t\t\n\t\t</tr>"; } echo $tpl->_ENGINE_parse_body("\n\t\n\t\t<table class='table table-bordered table-hover'>\n\t\n\t\t\t<thead>\n\t\t\t\t<tr>\n\t\t\t\t\t<th>{hostname}</th>\n\t\t\t\t\t<th>{ipaddr}</th>\n\t\t\t\t\t<th>{ComputerMacAddress}</th>\n\t\t\t\t\t<th>Starts</th>\n\t\t\t\t\t<th>END</th>\n\t\t\t\t</tr>\n\t\t\t</thead>\n\t\t\t <tbody>\n\t\t\t") . @implode("\n", $tr) . " </tbody>\n\t\t\t\t</table>\n\t\t\t\t"; }
function host_add() { $dhcp = new dhcpd(0, 1); $ip = new IP(); $tpl = new templates(); $cmp = new computers(); if (!$dhcp->IsPhysicalAddress($_POST["mac"])) { echo "Wrong value {$_POST["mac"]}\n"; return; } $_POST["uid"] = str_replace("\$", "", $_POST["uid"]); $_POST["ipaddr"] = str_replace("\$", "", $_POST["ipaddr"]); if (!$ip->isIPAddress($_POST["ipaddr"])) { echo $tpl->javascript_parse_text("{invalid_ipaddr}: {$_POST["ipaddr"]}"); return; } $q = new mysql(); $sql = "SELECT hostname FROM dhcpd_fixed WHERE mac='{$_POST["mac"]}'"; $ligneCK = mysql_fetch_array($q->QUERY_SQL($sql, "artica_backup")); if ($ligneCK["hostname"] != null) { echo $tpl->javascript_parse_text("{this_computer_already_exists}\n{hostname}:{$ligneCK["hostname"]} ({$_POST["mac"]})", 1); return; } if (!preg_match("#[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+#", $_POST["ipaddr"])) { echo "Wrong value {$_POST["ipaddr"]}\n"; return; } $uid = $cmp->ComputerIDFromMAC($_POST["mac"]); if ($uid != null) { $cmp = new computers($uid); $domain = $cmp->DnsZoneName; if ($cmp->ComputerRealName != null) { $_POST["hostname"] = $cmp->ComputerRealName; } } if ($domain != null) { $domain = $dhcp->ddns_domainname; } if ($domain == null) { echo "DNS domain is null"; } $sql = "INSERT INTO dhcpd_fixed (mac,ipaddr,hostname,domain) VALUES\n\t('{$_POST["mac"]}','{$_POST["ipaddr"]}','{$_POST["hostname"]}','{$domain}')"; $q = new mysql(); $q->QUERY_SQL($sql, "artica_backup"); if (!$q->ok) { echo $q->mysql_error; return; } $sock = new sockets(); $sock->getFrameWork("cmd.php?apply-dhcpd=yes"); }
function nmap_scan_results() { if (!is_file("/etc/artica-postfix/nmap.map")) { return; } $f = explode("\n", @file_get_contents("/etc/artica-postfix/nmap.map")); while (list($index, $ligne) = each($f)) { if (preg_match("#Nmap scan report for\\s+(.+?)\\s+\\(([0-9\\.]+)#", $ligne, $re)) { $ipaddr = $re[2]; $computer[$ipaddr]["IPADDR"] = $re[2]; $computer[$ipaddr]["HOSTNAME"] = trim($re[1]); $LOGS[] = "Found {$ipaddr} hostname= {$re[1]}"; continue; } if (preg_match("#Nmap scan report for ([0-9\\.]+)\$#", trim($ligne), $re)) { $ipaddr = $re[1]; $computer[$ipaddr]["IPADDR"] = $re[1]; $LOGS[] = "Found {$ipaddr} without computername "; continue; } if (preg_match("#^MAC Address:\\s+([0-9A-Z:]+)\$#", trim($ligne), $re)) { if (isset($MACSSCAN[trim($re[1])])) { continue; } $computer[$ipaddr]["MAC"] = trim($re[1]); $LOGS[] = "Found {$ipaddr} with mac {$re[1]} "; $MACSSCAN[trim($re[1])] = true; continue; } if (preg_match("#^MAC Address:(.+).+?\\((.+?)\\)#", $ligne, $re)) { if (isset($MACSSCAN[trim($re[1])])) { continue; } $MACSSCAN[trim($re[1])] = true; $computer[$ipaddr]["MAC"] = trim($re[1]); $computer[$ipaddr]["MACHINE_TYPE"] = trim($re[2]); $LOGS[] = "Found {$ipaddr} with mac {$re[1]} and machine type {$re[2]}"; continue; } if (preg_match("#^Running:(.+)#", $ligne, $re)) { $computer[$ipaddr]["RUNNING"] = trim($re[1]); continue; } if (preg_match("#^OS details:(.+)#", $ligne, $re)) { $LOGS[] = "Found {$ipaddr} with OS {$re[1]}"; $computer[$ipaddr]["OS"] = trim($re[1]); continue; } } nmap_logs(count($f) . " analyzed lines", @implode("\n", $LOGS)); $c = 0; while (list($ipaddr, $array) = each($computer)) { if (isset($already[$mac])) { continue; } $mac = trim($array["MAC"]); if ($mac == null) { continue; } $c++; $already[$mac] = true; $ldap_ipaddr = null; $ComputerRealName = null; $uid = null; $RAISON = array(); if (!isset($array["HOSTNAME"])) { $array["HOSTNAME"] = null; } if (!isset($array["OS"])) { $array["OS"] = null; } if (!isset($array["RUNNING"])) { $array["RUNNING"] = null; } if (!isset($array["MACHINE_TYPE"])) { $array["MACHINE_TYPE"] = null; } $cmp = new computers(null); $uid = $cmp->ComputerIDFromMAC($mac); if ($uid != null) { if ($GLOBALS["VERBOSE"]) { echo "{$mac} = {$uid}\n"; } $cmp = new computers($uid); $ldap_ipaddr = $cmp->ComputerIP; $ComputerRealName = $cmp->ComputerRealName; if ($GLOBALS["VERBOSE"]) { echo "{$mac} = {$uid}\nLDAP:{$ldap_ipaddr}<>NMAP:{$ipaddr}\nLDAP CMP:{$ComputerRealName}<>NMAP:{$array["HOSTNAME"]}"; } if ($array["HOSTNAME"] != null) { $EXPECTED_UID = strtoupper($array["HOSTNAME"]) . "\$"; if ($EXPECTED_UID != $uid) { $RAISON[] = "UID: {$uid} is different from {$EXPECTED_UID}"; nmap_logs("EDIT UID: {$mac}:[{$array["HOSTNAME"]}] ({$ipaddr})", @implode("\n", $array) . "\n" . @implode("\n", $RAISON), $uid); $cmp->update_uid($EXPECTED_UID); } } if ($ldap_ipaddr != $ipaddr) { writelogs("Change {$ldap_ipaddr} -> to {$ipaddr} for {$cmp->uid}", __FUNCTION__, __FILE__, __LINE__); $RAISON[] = "LDAP IP ADDR: {$ldap_ipaddr} is different from {$ipaddr}"; $RAISON[] = "DN: {$cmp->dn}"; $RAISON[] = "UID: {$cmp->uid}"; $RAISON[] = "MAC: {$cmp->ComputerMacAddress}"; if (!$cmp->update_ipaddr($ipaddr)) { $RAISON[] = "ERROR:{$cmp->ldap_last_error}"; } nmap_logs("EDIT IP: {$mac}:[{$array["HOSTNAME"]}] ({$ipaddr})", @implode("\n", $array) . "\n" . @implode("\n", $RAISON), $uid); } if ($array["OS"] != null) { if (strtolower($cmp->ComputerOS == "Unknown")) { $cmp->ComputerOS = null; } if ($cmp->ComputerOS == null) { $RAISON[] = "LDAP OS: {$cmp->ComputerOS} is different from {$array["OS"]}"; nmap_logs("EDIT OS: {$mac}:[{$array["HOSTNAME"]}] ({$ipaddr})", @implode("\n", $array) . "\n" . @implode("\n", $RAISON), $uid); $cmp->update_OS($array["OS"]); } } } else { if ($array["HOSTNAME"] != null) { $uid = "{$array["HOSTNAME"]}\$"; } else { $uid = "{$ipaddr}\$"; } nmap_logs("ADD NEW: {$mac}:[{$array["HOSTNAME"]}] ({$ipaddr})", @implode("\n", $array) . "\n" . @implode("\n", $RAISON), "{$uid}"); $cmp = new computers(); $cmp->ComputerIP = $ipaddr; $cmp->ComputerMacAddress = $mac; $cmp->uid = "{$uid}"; $cmp->ComputerOS = $array["OS"]; $cmp->ComputerRunning = $array["RUNNING"]; $cmp->ComputerMachineType = $array["MACHINE_TYPE"]; $cmp->Add(); } } nmap_logs("{$c} hosts analyzed in databases"); @unlink("/etc/artica-postfix/nmap.map"); //print_r($computer); }
function list_nets() { $tpl = new templates(); $page = CurrentPageName(); $search = $_GET["search"]; $q = new mysql(); if ($search != null) { $search = "*{$search}*"; $search = str_replace("**", "*", $search); $search = str_replace("*", "%", $search); $search_sql = " WHERE (mac LIKE '{$search}') OR (ipaddr LIKE '{$search}') OR (hostname LIKE '{$search}')"; } $sql = "SELECT * FROM dhcpd_leases {$search_sql} ORDER BY `dhcpd_leases`.`cltt` DESC LIMIT 0,100"; $results = $q->QUERY_SQL($sql, "artica_backup"); if (!$q->ok) { echo "<H2>{$q->mysql_error}</H2>"; } $html = "\n<table cellspacing='0' cellpadding='0' border='0' class='tableView' style='width:100%'>\n<thead class='thead'>\n\t<th width=1%> </th>\n\t<th>{hostname}</th>\n\t<th>{ipaddr}</th>\n\t<th>{ComputerMacAddress}</th>\n\t<th>{end}</th>\n</thead>\n<tbody class='tbody'>"; $cmp = new computers(); while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) { $ligne["hostname"] = trim($ligne["hostname"]); if ($classtr == "oddRow") { $classtr = null; } else { $classtr = "oddRow"; } if ($ligne["mac"] == null) { continue; } $tooltip = "\n\t\t<table class=form>\n\t\t<tr>\n\t\t\t<td class=legend>start:</td>\n\t\t\t<td><strong style=font-size:13px>{$ligne["starts"]}</td>\n\t\t</tr>\n\t\t<tr>\n\t\t\t<td class=legend>cltt:</td>\n\t\t\t<td><strong style=font-size:13px>{$ligne["cltt"]}</td>\n\t\t</tr>\n\t\t<tr>\n\t\t\t<td class=legend>tstp:</td>\n\t\t\t<td><strong style=font-size:13px>{$ligne["tstp"]}</td>\n\t\t</tr>\n\t\t</table>\n\t\t"; $js = null; $uid = $cmp->ComputerIDFromMAC($ligne["mac"]); if ($uid != null) { $img = "30-computer.png"; $js = MEMBER_JS($uid, 1, 1); $tooltip = $tooltip . "<br>{view}"; } else { $img = "30-computer-grey.png"; } if ($ligne["hostname"] == null) { $ligne["hostname"] = " "; } if ($ligne["ipaddr"] == null) { $ligne["ipaddr"] = " "; } if ($ligne["mac"] == null) { $ligne["mac"] = " "; } $html = $html . "\n\t\t<tr class={$classtr}>\n\t\t<td width=1% style='font-size:14px' align='center'>" . imgtootltip("30-computer.png", "{$tooltip}", $js) . "</td>\n\t\t<td style='font-size:13px'>{$href}{$ligne["hostname"]}</a></td>\n\t\t<td style='font-size:13px' nowrap>{$href}{$ligne["ipaddr"]}</a></td>\n\t\t<td style='font-size:13px'>{$href}{$ligne["mac"]}</a></td>\n\t\t<td style='font-size:13px' nowrap>{$href}{$ligne["ends"]}</td>\n\t</tr>\n\t\t"; } $html = $html . "</table>\n\n\n"; echo $tpl->_ENGINE_parse_body($html); }
function list_nets() { $tpl = new templates(); $MyPage = CurrentPageName(); $q = new mysql(); $t = $_GET["t"]; $search = '%'; $table = "dhcpd_logs"; $database = 'artica_events'; $page = 1; $FORCE_FILTER = ""; $ORDER = "ORDER BY zDate DESC"; if (!$q->TABLE_EXISTS($table, $database)) { throw new Exception("{$table}, No such table...", 500); } if ($q->COUNT_ROWS($table, $database) == 0) { throw new Exception("No data...", 500); } 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("search-records"); $sql = "SELECT * FROM `{$table}` WHERE 1 {$searchstring} {$FORCE_FILTER} {$ORDER} limit 0,250"; $results = $q->QUERY_SQL($sql, $database); if (!$q->ok) { senderror($q->mysql_error, 1); } if (mysql_num_rows($results) == 0) { senderror("no data"); } $sock = new sockets(); $cmp = new computers(); $boot = new boostrap_form(); $computers = new computers(); while ($ligne = mysql_fetch_assoc($results)) { $color = "black"; $uid = null; $mac = null; if (preg_match("#to\\s+([0-9a-z:]+)\\s+via#", $ligne["description"], $re)) { $mac = $re[1]; } if (preg_match("#from\\s+([0-9a-z:]+)\\s+via#", $ligne["description"], $re)) { $mac = $re[1]; } $js = "zBlur();"; if ($mac != null) { $uid = $computers->ComputerIDFromMAC($mac); if ($uid != null) { $js = MEMBER_JS($uid, 1, 1); $ligne["description"] = str_replace($mac, "<strong><i class='icon-info-sign'></i> {$mac}</strong></strong>", $ligne["description"]); } } $link = $boot->trswitch($js); $tr[] = "\n\t\t<tr id='{$id}'>\n\t\t<td nowrap {$link}><i class='icon-time'></i> {$ligne["zDate"]}</td>\n\t\t<td {$link} ><i class='icon-info-sign'></i> {$ligne["description"]}</td>\n\t\t</tr>"; } echo $tpl->_ENGINE_parse_body("\n\t\n\t\t<table class='table table-bordered table-hover'>\n\t\n\t\t\t<thead>\n\t\t\t\t<tr>\n\t\t\t\t\t<th>{zDate}</th>\n\t\t\t\t\t<th>{events}</th>\n\t\t\t\t</tr>\n\t\t\t</thead>\n\t\t\t <tbody>\n\t\t\t") . @implode("\n", $tr) . " </tbody>\n\t\t\t\t</table>\n\t\t\t\t"; }
function search() { $t = $_GET["t"]; $tpl = new templates(); $MyPage = CurrentPageName(); $q = new mysql(); $sock = new sockets(); $search = '%'; $table = "dhcpd_logs"; $database = "artica_events"; $page = 1; $FORCE_FILTER = ""; 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, $database)); $total = $ligne["TCOUNT"]; } else { $sql = "SELECT COUNT(*) as TCOUNT FROM {$table} WHERE 1 {$FORCE_FILTER}"; $ligne = mysql_fetch_array($q->QUERY_SQL($sql, $database)); $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}"; writelogs($sql, __FUNCTION__, __FILE__, __LINE__); $results = $q->QUERY_SQL($sql, $database); $data = array(); $data['page'] = $page; $data['total'] = $total; $data['rows'] = array(); if (!$q->ok) { json_error_show($q->mysql_error); } $computers = new computers(); while ($ligne = mysql_fetch_assoc($results)) { $color = "black"; $uid = null; $mac = null; $js = "zblur()"; if (preg_match("#to\\s+([0-9a-z:]+)\\s+via#", $ligne["description"], $re)) { $mac = $re[1]; } if (preg_match("#from\\s+([0-9a-z:]+)\\s+via#", $ligne["description"], $re)) { $mac = $re[1]; } if ($mac != null) { $uid = $computers->ComputerIDFromMAC($mac); if ($uid != null) { $js = MEMBER_JS($uid, 1, 1); $uri = "<a href=\"javascript:blur();\" OnClick=\"{$js}\" style='font-size:14px;font-weight:bold;color:{$color};text-decoration:underline'>{$mac}</a> <span style='font-size:11px'>({$uid})</span>"; $ligne["description"] = str_replace($mac, $uri, $ligne["description"]); } } $data['rows'][] = array('id' => "{$ID}", 'cell' => array("<span style='font-size:14px;color:{$color}'>{$urljs}{$ligne["zDate"]}</a></span>", "<span style='font-size:14px;color:{$color}'>{$ligne["description"]}</a></span>")); } echo json_encode($data); }
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 update_computer($ip, $mac, $name) { $mac = trim($mac); $name = trim(strtolower($name)); $ip = trim($ip); if ($ip == null) { return; } if ($mac == null) { return; } if ($name == null) { return; } $ip = nmblookup($name, $ip); $unix = new unix(); $unix->add_EtcHosts($name, $ip); $dhcp = new dhcpd(); $GLOBALS["domain"] = $dhcp->ddns_domainname; $comp = new computers(); $uid = $comp->ComputerIDFromMAC($mac); if ($uid == null) { $add = true; $uid = "{$name}\$"; $comp = new computers(); $comp->ComputerRealName = $name; $comp->ComputerMacAddress = $mac; $comp->ComputerIP = $ip; $comp->DnsZoneName = $GLOBALS["domain"]; $comp->uid = $uid; $ComputerRealName = $HOST; $comp->Add(); } else { $comp = new computers($uid); if ($comp->ComputerRealName == null) { $ComputerRealName = $name; } if (preg_match("#[0-9]+\\.[0-9]+\\.#", $comp->ComputerRealName)) { $comp->ComputerRealName = $name; } $comp->ComputerIP = $ip; $comp->DnsZoneName = $GLOBALS["domain"]; $comp->Edit(); } $dns = new pdns($GLOBALS["domain"]); $dns->EditIPName(strtolower($name), $ip, 'A', $mac); }
function SearchComputers() { $tpl = new templates(); $MyPage = CurrentPageName(); $sock = new sockets(); $EnableIntelCeleron = intval($sock->GET_INFO("EnableIntelCeleron")); $q = new mysql(); $sock = new sockets(); $fontsize = "14px"; $cs = 0; $page = 1; if (!$q->DATABASE_EXISTS("ocsweb")) { $sock->getFrameWork("services.php?mysql-ocs=yes"); } if (!$q->TABLE_EXISTS("hardware", "ocsweb")) { $sock->getFrameWork("services.php?mysql-ocs=yes"); } if (!$q->TABLE_EXISTS("networks", "ocsweb", true)) { $sock->getFrameWork("services.php?mysql-ocs=yes"); } if (!$q->FIELD_EXISTS("networks", "isActive", "ocsweb")) { $q->QUERY_SQL("ALTER TABLE `networks` ADD `isActive` SMALLINT( 1 ) NOT NULL DEFAULT '0',ADD INDEX ( `isActive` ) ", "ocsweb"); } if (isset($_POST['rp'])) { $rp = $_POST['rp']; } $pageStart = ($page - 1) * $rp; $limitSql = "LIMIT {$pageStart}, {$rp}"; $table = "(SELECT networks.HARDWARE_ID,networks.MACADDR,networks.STATUS,networks.IPADDRESS,networks.isActive,\n\t\t\thardware.* FROM networks,hardware WHERE networks.HARDWARE_ID=hardware.ID) 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, "ocsweb")); if (!$q->ok) { json_error_show($q->mysql_error . "<br>{$sql}"); } $total = $ligne["TCOUNT"]; } else { $sql = "SELECT COUNT(*) as TCOUNT FROM {$table} WHERE 1"; $ligne = mysql_fetch_array($q->QUERY_SQL($sql, "ocsweb")); if (!$q->ok) { json_error_show($q->mysql_error . "<br>{$sql}"); } $total = $ligne["TCOUNT"]; } if (isset($_POST['rp'])) { $rp = $_POST['rp']; } if (isset($_POST["sortname"])) { if ($_POST["sortname"] != null) { $ORDER = "ORDER BY {$_POST["sortname"]} {$_POST["sortorder"]}"; } } if (isset($_POST['page'])) { $page = $_POST['page']; } $data = array(); $data['page'] = $page; $data['total'] = $total; $data['rows'] = array(); $sql = "SELECT * FROM {$table} WHERE 1 {$searchstring} {$ORDER} {$limitSql}"; writelogs($sql, __FUNCTION__, __FILE__, __LINE__); $results = $q->QUERY_SQL($sql, "ocsweb"); if (!$q->ok) { json_error_show($q->mysql_error . "<hr>{$sql}"); } if (mysql_num_rows($results) == 0) { json_error_show("no data"); } $users = new usersMenus(); $DHC_MAIN = false; if ($users->dhcp_installed) { $EnableDHCPServer = intval($sock->GET_INFO('EnableDHCPServer')); if ($EnableDHCPServer == 1) { $DHC_MAIN = true; } } $SQUID_MAIN = false; if ($users->SQUID_INSTALLED) { $SQUID_MAIN = true; } $fontsize = "22px"; $computer = new computers(); $q2 = new mysql_squid_builder(); while ($ligne = mysql_fetch_array($results, MYSQL_ASSOC)) { if ($ligne["MACADDR"] == "unknown") { continue; } $ligne["MACADDR"] = strtolower($ligne["MACADDR"]); $HARDWARE_ID = $ligne["HARDWARE_ID"]; $uid = null; $OSNAME = null; if ($ligne["OSNAME"] == "Unknown") { $ligne["OSNAME"] = null; } $color = "#7D7D7D"; $md = md5($ligne["MACADDR"]); $uri = strtolower($ligne["NAME"]); if ($EnableIntelCeleron == 0) { $uid = $computer->ComputerIDFromMAC($ligne["MACADDR"]); } $view = " "; $jslink = null; $jsfiche = null; $ISDB = "ok32-grey.png"; $DHCP = "ok32-none.png"; $SQUID = "ok32-none.png"; if ($DHC_MAIN) { $DHCP = "ok32-grey.png"; if ($computer->dhcpfixedFromMac($ligne["MACADDR"])) { $DHCP = "ok32.png"; } } if ($SQUID_MAIN) { $ligne2 = mysql_fetch_array($q2->QUERY_SQL("SELECT enabled FROM computers_time WHERE `MAC`='{$ligne["MACADDR"]}'", "artica_backup")); if (intval($ligne2["enabled"]) != 0) { $SQUID = "warning24.png"; } } if ($uid != null) { $ISDB = "ok32.png"; $jsfiche = MEMBER_JS($uid, 1, 1); $view = "<a href=\"javascript:blur();\" \n\t\t\tOnClick=\"javascript:{$jsfiche}\" \n\t\t\tstyle='font-size:{$fontsize};text-decoration:underline'>" . str_replace("\$", "", strtolower($uid)) . "</a>"; $jslink = "<a href=\"javascript:blur();\" \n\t\t\tOnClick=\"javascript:{$jsfiche}\" \n\t\t\tstyle='font-size:{$fontsize};text-decoration:underline'>"; } else { $uid = $ligne["NAME"]; if (preg_match("#^[0-9]+\\.[0-9]+\\.[0-9]+#", $uid)) { $q = new mysql_squid_builder(); $NAME2 = $q->UID_FROM_MAC($ligne["MACADDR"]); if ($NAME2 != null) { $uid = $NAME2; } } if ($uid == null) { $uid = "Unknown"; } $jsfiche = "Loadjs('domains.computer.autoadd.php?mac=" . urlencode($ligne["MACADDR"]) . "&ipaddr=" . urlencode($ligne["IPADDRESS"]) . "&computername=" . urlencode($uid) . "&t={$_GET["t"]}')"; if ($EnableIntelCeleron == 1) { $jsfiche = "Loadjs('domains.computer.mysql.php?HARDWARE_ID={$HARDWARE_ID}&t={$_GET["t"]}')"; } $jslink = "<a href=\"javascript:blur();\"\n\t\t\tOnClick=\"javascript:{$jsfiche}\"\n\t\t\tstyle='font-size:{$fontsize};text-decoration:underline'>"; $view = "<a href=\"javascript:blur();\"\n\t\t\tOnClick=\"javascript:{$jsfiche}\"\n\t\t\tstyle='font-size:{$fontsize};text-decoration:underline'>{$uid}</a>"; } $js[] = "LoadAjaxTiny('cmp-{$md}','{$page}?compt-status={$ligne["IPADDRESS"]}');"; $icon = "<img src='img/{$ISDB}'>"; if ($ligne["OSNAME"] != null) { $OSNAME = "<div style='font-size:9px'><i>{$ligne["OSNAME"]}</i></div>"; } if ($_GET["callback"] != null) { $color = "black"; if ($_GET["fullvalues"] == 1) { $viewjs = "{$_GET["callback"]}('{$uid}','{$ligne["IPADDRESS"]}','{$ligne["MACADDR"]}')"; } else { $viewjs = "{$_GET["callback"]}('{$uid}')"; } $view = "<a href=\"javascript:blur();\" \n\t\t\t\t\t\tOnClick=\"javascript:{$viewjs}\" \n\t\t\t\t\t\tstyle='font-size:{$fontsize};text-decoration:underline'>" . str_replace("\$", "", strtolower($uid)) . "</a>"; $icon = imgtootltip("arrow-blue-left-32.png", null, $viewjs); } if (!IsPhysicalAddress($ligne["MACADDR"])) { if ($_GET["CorrectMac"] == 1) { continue; } } $AlreadyMAC[$ligne["MACADDR"]] = true; $zdate = null; if (isset($ligne["zDate"])) { $zdate = "<div style='font-size:11px;color:#7D7D7D'>{$ligne["zDate"]}</div>"; } $macenc = urlencode($ligne["MACADDR"]); $ipenc = urlencode($ligne["IPADDRESS"]); $jsDelete = "Loadjs('{$MyPage}?delete-computer-js=yes&MAC={$macenc}&t={$_GET["t"]}');"; $alias = $q2->UID_FROM_MAC($ligne["MACADDR"]); if ($alias != null) { $alias_uri = "Loadjs('squid.nodes.php?node-infos-js=yes&MAC={$macenc}');"; } if ($alias == null) { $alias = $q2->UID_FROM_IP($ligne["IPADDRESS"]); if ($alias != null) { $alias_uri = "Loadjs('squid.nodes.php?node-infos-js=yes&ipaddr={$ipenc}');"; } } if ($alias == null) { $alias = "<center><img src='img/32-plus.png'></center>"; $alias_uri = "Loadjs('squid.nodes.php?link-user-js=yes&MAC={$macenc}&ipaddr={$ipenc}',true)"; } if ($EnableIntelCeleron == 1) { $jsfiche = "Loadjs('domains.computer.mysql.php?HARDWARE_ID={$HARDWARE_ID}&t={$_GET["t"]}')"; } $cs++; $data['rows'][] = array('id' => md5(serialize($ligne)), 'cell' => array($view . $zdate, "<span style='font-size:{$fontsize}'>{$jslink}{$ligne["IPADDRESS"]}</a></span>", "<span style='font-size:{$fontsize}'>{$jslink}{$ligne["MACADDR"]}</a></span>", "<span style='font-size:{$fontsize}'><a href=\"javascript:blur();\" \n\t\t\tOnClick=\"javascript:{$alias_uri}\" style='text-decoration:underline'>{$alias}</a></span>", "<center><a href=\"javascript:blur();\" OnClick=\"javascript:{$jsfiche}\">{$icon}</a></center>", "<center><a href=\"javascript:blur();\" OnClick=\"javascript:{$jsfiche}\"><img src='img/{$DHCP}'></center></a>", "<center><a href=\"javascript:blur();\" OnClick=\"javascript:{$jsfiche}\"><img src='img/{$SQUID}'></center></a>", "<center><a href=\"javascript:blur();\" OnClick=\"javascript:{$jsDelete}\"><img src='img/delete-32.png'></center></a>")); } if ($cs > $_POST["rp"]) { $data['total'] = $cs; echo json_encode($data); return; } if ($cs == 0) { json_error_show("no item"); } $data['total'] = $cs; echo json_encode($data); }
function ImportDatas($datas) { $import = unserialize(base64_decode($datas)); $hash = $import["COMPUTERS"]; for ($i = 0; $i < $hash["count"]; $i++) { $comp = new computers(); $uidorg = $hash[$i]["uid"][0]; $dnszonename = $hash[$i]["dnszonename"][0]; $dnstype = $hash[$i]["dnstype"][0]; $computermachinetype = $hash[$i]["computermachinetype"][0]; $computerip = $hash[$i]["computerip"][0]; $computermacaddress = $hash[$i]["computermacaddress"][0]; $ComputerRealName = $hash[$i][strtolower("ComputerRealName")][0]; if ($ComputerRealName == null) { $ComputerRealName = str_replace('$', '', $uidorg); } writelogs("Importing computer: {$uid} {$computerip} {$computermacaddress}", __FUNCTION__, __FILE__, __LINE__); $uid = $comp->ComputerIDFromMAC($computermacaddress); if ($uid == null) { $uid = $uidorg; $comp = new computers(); $comp->ComputerRealName = $ComputerRealName; $comp->ComputerMacAddress = $computermacaddress; $comp->ComputerIP = $computerip; $comp->DnsZoneName = $dnszonename; $comp->ComputerMachineType = $computermachinetype; $comp->uid = $uid; $comp->Add(); } else { $comp = new computers($uid); $comp->ComputerIP = $computerip; $comp->DnsZoneName = $dnszonename; $comp->ComputerMachineType = $computermachinetype; $comp->Edit(); } $dns = new pdns($dnszonename); $dns->EditIPName(strtolower($ComputerRealName), $computerip, $dnstype, $computermacaddress); } }
function items(){ $tpl=new templates(); $MyPage=CurrentPageName(); $q=new mysql_squid_builder(); $RULEID=$_GET["RULEID"]; $search='%'; $table="computers_time"; $page=1; $FORCE=1; 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 $FORCE $searchstring"; $ligne=mysql_fetch_array($q->QUERY_SQL($sql)); $total = $ligne["TCOUNT"]; if(!$q->ok){json_error_show("$q->mysql_error");} }else{ $sql="SELECT COUNT(*) as TCOUNT FROM $table WHERE $FORCE"; $ligne=mysql_fetch_array($q->QUERY_SQL($sql)); $total = $ligne["TCOUNT"]; if(!$q->ok){json_error_show("$q->mysql_error");} } if (isset($_POST['rp'])) {$rp = $_POST['rp'];} $pageStart = ($page-1)*$rp; $limitSql = "LIMIT $pageStart, $rp"; $sql="SELECT * FROM $table WHERE $FORCE $searchstring $ORDER $limitSql"; if($GLOBALS["VERBOSE"]){echo "<p style='color:red'>$sql</p>";} $results = $q->QUERY_SQL($sql); if(!$q->ok){json_error_show("$q->mysql_error");} $data = array(); $data['page'] = $page; $data['total'] = $total; $data['rows'] = array(); if(mysql_num_rows($results)==0){json_error_show("no rule $sql");} $fontsize=18; $computer=new computers(); while ($ligne = mysql_fetch_assoc($results)) { $id=md5(serialize($ligne["pattern"])); $mac=$ligne["MAC"]; $macec=urlencode($mac); $uid=$computer->ComputerIDFromMAC($mac); $color="black"; if($ligne["enabled"]==0){$color="#8a8a8a";} $view_mac=$mac; $view_hostname=null; if($uid<>null){ $jsfiche=MEMBER_JS($uid,1,1); $view_hostname="<a href=\"javascript:blur();\" OnClick=\"javascript:$jsfiche\" style='font-size:$fontsize;color:$color;text-decoration:underline'>". str_replace("$", "", strtolower($uid))."</a>"; $view_mac="<a href=\"javascript:blur();\" OnClick=\"javascript:$jsfiche\" style='font-size:$fontsize;;color:$color;text-decoration:underline'>$mac</a>"; } $description=explainThis($ligne); $delete=imgsimple("delete-48.png","{delete} {$ligne["pattern"]}","Loadjs('$MyPage?delete-pattern=yes&MAC=$macec&t={$_GET["t"]}')"); $enable=Field_checkbox($id,1,$ligne["enabled"],"RtResProxyEnable('$mac','$id')"); $data['rows'][] = array( 'id' => $ligne['mac'], 'cell' => array("<span style='font-size:18px;color:$color;'>$view_mac</span>" ,"<span style='font-size:18px;color:$color;'>$view_hostname</span>", "<span style='font-size:16px;color:$color;'>$description</span>", "<center>$enable</center>", "<center>$delete</center>" ) ); } echo json_encode($data); }
function popup_connected_search() { $ocs = new ocs(); $sql = $ocs->COMPUTER_SEARCH_QUERY($_GET["connected-search"]); $CONFIG = $ocs->GET_SERVER_SETTINGS(); $PROLOG_FREQ = $CONFIG["PROLOG_FREQ"] * 60; $q = new mysql(); $results = $q->QUERY_SQL($sql, "ocsweb"); if (!$q->ok) { echo "<p> </p><p style='font-size:15px'>{$q->mysql_error}<hr>{$sql}</p>"; return; } $html = "\n<table cellspacing='0' cellpadding='0' border='0' class='tableView' style='width:99%'>\n<thead class='thead'>\n<tr>\n\t\t<th colspan=2>{computer}</th>\n\t\t<th>{status}</th>\n\t\t<th>{ComputerMacAddress}</th>\n\t\t<th>{ip_address}</th>\n\t</tr>\n</thead>\n<tbody class='tbody'>\t"; while ($ligne = mysql_fetch_array($results, MYSQL_ASSOC)) { if ($ligne["IPADDRESS"] == "0.0.0.0") { continue; } if ($ligne["MACADDR"] == "00:00:00:00:00:00") { continue; } if ($already[$ligne["MACADDR"]]) { continue; } if ($already[$ligne["NAME"] . $ligne["IPSRC"]]) { continue; } $status = null; $already[$ligne["MACADDR"]] = true; $already[$ligne["NAME"] . $ligne["IPADDRESS"]] = true; $f = new computers(); $uid = $f->ComputerIDFromMAC($ligne["MACADDR"]); if (trim($uid) != null) { $already[$ligne["NAME"] . $ligne["IPSRC"]] = true; } $js = MEMBER_JS($uid, 1, 1); $last = distanceOfTimeInWords(strtotime($ligne["LASTCOME"]), time()); $mins = distanceMinStrings($ligne["LASTCOME"]); $js_text = "{$ligne["NAME"]}<hr>{last_com}:{$last}<hr>{$ligne["IPADDRESS"]}/{$ligne["MACADDR"]}"; if ($mins > $PROLOG_FREQ) { $js_text = "{$ligne["NAME"]}<hr><span color:#d32d2d>{last_com}:{$last}</span>"; $status = imgtootltip('ok32-grey.png', $js_text); } else { $status = imgtootltip('ok32.png', "{$ligne["IPADDRESS"]}/{$ligne["MACADDR"]}<br>{$last}"); } if ($uid == null) { $js = null; $status = imgtootltip("warning-panneau-32.png", "{ocs_computer_is_not_in_ldap}", "AddComputerFromOCS('{$ligne["MACADDR"]}')", null, md5($ligne["MACADDR"]) . time()); $js_text = "{ocs_computer_is_not_in_ldap}"; } else { } if (trim($ligne["IPADDRESS"]) != null) { if (trim($ligne["IPSRC"]) != null) { if (trim($ligne["IPSRC"]) != trim($ligne["IPADDRESS"])) { $ligne["IPSRC"] = $ligne["IPSRC"] . "/" . $ligne["IPADDRESS"]; } } else { $ligne["IPSRC"] = $ligne["IPADDRESS"]; } } if ($classtr == "oddRow") { $classtr = null; } else { $classtr = "oddRow"; } $html = $html . "\n\t\t<tr class={$classtr}>\n\t\t\t<td width=1%>" . imgtootltip("laptop-32.png", $js_text, $js) . "</td>\n\t\t\t<td style='font-size:14px'><code style='font-size:14px'>{$ligne["NAME"]}</code></td>\n\t\t\t<td width=1% align='center' valign='middle'>{$status}</td>\n\t\t\t<td style='font-size:14px'><code style='font-size:14px'>{$ligne["MACADDR"]}</code></td>\n\t\t\t<td style='font-size:14px'><code style='font-size:14px'>{$ligne["IPSRC"]}</code></td>\n\t\t</tr>\n\t\t\n\t\t"; } $html = $html . "</table>\n\t\n\t"; $tpl = new templates(); echo $tpl->_ENGINE_parse_body($html); }
function receive_noop_connection() { $datas = base64_decode($_GET["noop"]); // 00-0C-29-09-BB-77|192.168.1.248|GRAPHICS|Windows XP SP3|Windows XP|SP3|=Intel;Intel(R) Core(TM)2 Quad CPU Q6600 @ 2.40GHz;2400;MMX|C:;34949382144 $datas = explode("|", $datas); @file_put_contents("/tmp/datas.txt", implode("\n", $datas)); while (list($num, $ligne) = each($datas)) { writelogs("=>{$num}): {$ligne}", __FUNCTION__, __FILE__, __LINE__); } $MAC = $datas[0]; $MAC = str_replace("-", ":", $MAC); $LOCAL_IP = $datas[1]; $COMPUTER_NAME = $datas[2]; $OS_VER = $datas[3]; $CPUAR = explode(";", $datas[6]); $CPU_INFO = $CPUAR[1]; $CPU_INFO = str_replace(" ", " ", $CPU_INFO); $domain = strtolower($datas[9]); $uptime = strtolower($datas[13]); if (!preg_match("#(.+?)\\.(.+)#", $domain)) { $domain = null; } $computer = new computers(); $uid = $computer->ComputerIDFromMAC($MAC); writelogs("[{$uid}] ({$COMPUTER_NAME}):: mac={$MAC}, ip={$LOCAL_IP}, system {$OS_VER} ({$CPU_INFO}) uptime={$uptime}", __FUNCTION__, __LINE__); if ($uid == null) { $computer->uid = "{$COMPUTER_NAME}\$"; $computer->ComputerMacAddress = $MAC; $computer->ComputerIP = $LOCAL_IP; if ($domain != null) { $computer->DnsZoneName = $domain; } $computer->ComputerRealName = $COMPUTER_NAME; $computer->ComputerCPU = $CPU_INFO; $computer->ComputerOS = $OS_VER; if ($uptime != null) { $computer->ComputerUpTime = $uptime; } $computer->Add(); } else { $computer = new computers($uid); $computer->ComputerIP = $LOCAL_IP; $computer->ComputerRealName = $COMPUTER_NAME; $computer->ComputerCPU = $CPU_INFO; $computer->ComputerOS = $OS_VER; $computer->ComputerMacAddress = $MAC; if ($domain != null) { $computer->DnsZoneName = $domain; } if ($uptime != null) { $computer->ComputerUpTime = $uptime; } $computer->Edit(); } $MAC = str_replace("-", ':', $MAC); $sql = "INSERT INTO computers_events (MAC,zDate,events_type,events) VALUES('{$MAC}',NOW(),'communication','{success_artica_agent_updateinfo}')"; $q = new mysql(); $q->QUERY_SQL($sql, 'artica_backup'); $sql = "SELECT * FROM computers_tasks WHERE MAC='{$MAC}' AND task_enabled=1 ORDER BY ID DESC"; $results = $q->QUERY_SQL($sql, "artica_backup"); while ($ligne = mysql_fetch_array($results, MYSQL_ASSOC)) { echo "<task>{$ligne["ID"]}</task><task_type>{$ligne["task_type"]}</task_type><schedule>{$ligne["schedule"]}</schedule><path>{$ligne["path"]}</path>\n"; } $sql = "SELECT * FROM computers_orders WHERE MAC='{$MAC}' ORDER BY ID DESC"; $results = $q->QUERY_SQL($sql, "artica_backup"); while ($ligne = mysql_fetch_array($results, MYSQL_ASSOC)) { $ligne["parameters"] = base64_encode($ligne["parameters"]); echo "<order>{$ligne["ID"]}</order><task_type>{$ligne["task_type"]}</task_type><parameters>{$ligne["parameters"]}</parameters><taskid>{$ligne["taskid"]}</taskid>\n"; } }
function COMPUTER_CHECK_MAC() { $tpl = new templates(); $mac = $_GET["ComputerMacAddressFindUid"]; $comp = new computers(); $uid = trim($comp->ComputerIDFromMAC($mac)); if ($uid != null) { if ($uid != $_GET["userid"]) { echo $tpl->_ENGINE_parse_body(imgtootltip("status_warning.png", "{this_mac_address_is_already_used_by}:{$uid}")); return; } } if (!IsPhysicalAddress($_GET["ComputerMacAddressFindUid"])) { echo $tpl->_ENGINE_parse_body(imgtootltip("status_warning.png", "{WARNING_MAC_ADDRESS_CORRUPT}")); return; } echo "<img src='img/ok16.png'>"; }
function computer_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(); $userid = $_GET["userid"]; $search = '%'; $table = "hostsusers"; $page = 1; $FORCE_FILTER = 1; if (trim($userid != null)) { $FORCE_FILTER = "`uid`='{$userid}'"; } if ($q->COUNT_ROWS($table, "artica_backup") == 0) { $data['page'] = $page; $data['total'] = $total; $data['rows'] = array(); echo json_encode($data); return; } 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 {$FORCE_FILTER} {$searchstring}"; $ligne = mysql_fetch_array($q->QUERY_SQL($sql, "artica_backup")); $total = $ligne["TCOUNT"]; } else { $sql = "SELECT COUNT(*) as TCOUNT FROM `{$table}` WHERE {$FORCE_FILTER}"; $ligne = mysql_fetch_array($q->QUERY_SQL($sql, "artica_backup")); $total = $ligne["TCOUNT"]; } if (isset($_POST['rp'])) { $rp = $_POST['rp']; } $pageStart = ($page - 1) * $rp; $limitSql = "LIMIT {$pageStart}, {$rp}"; $sql = "SELECT * FROM `{$table}` WHERE {$FORCE_FILTER} {$searchstring} {$ORDER} {$limitSql}"; writelogs($sql, __FUNCTION__, __FILE__, __LINE__); $results = $q->QUERY_SQL($sql, "artica_backup"); $data = array(); $data['page'] = $page; $data['total'] = $total; $data['rows'] = array(); if (mysql_num_rows($results) == 0) { $data['rows'][] = array('id' => $ligne[time()], 'cell' => array($sql, "", "", "")); } while ($ligne = mysql_fetch_assoc($results)) { $color = "black"; $also = null; $f = substr($ligne["computerid"], strlen($ligne["computerid"]) - 1, 1); $js = null; if ($f == "\$") { $comp = new computers($ligne["computerid"]); $ipaddr = $comp->ComputerIP; $ligne["computerid"] = substr($ligne["computerid"], 0, strlen($ligne["computerid"]) - 1) . " ({$ipaddr})"; $js = "<a href=\"javascript:blur();\" " . COMPUTER_JS($comp->uid) . "\n\t\t\tstyle='font-size:16px;color:{$color};text-decoration:underline'>"; } else { $comp = new computers(); $uid = $comp->ComputerIDFromMAC($ligne["MacAddress"]); if ($uid != null) { $comp = new computers($uid); $also = $tpl->_ENGINE_parse_body("{also_known_as}") . ": {$comp->ComputerRealName} - {$comp->ComputerIP}"; $js = "<a href=\"javascript:blur();\" " . COMPUTER_JS($comp->uid) . "\n\t\t\t\tstyle='font-size:16px;color:{$color};text-decoration:underline'>"; } } $delete = imgtootltip("delete-24.png", "{delete}", "DeletedComputerLink('{$ligne["zmd5"]}')"); $filename = basename($ligne["filename"]); $data['rows'][] = array('id' => $ligne['zmd5'], 'cell' => array("<img src='img/30-computer.png'>", "<span style='font-size:16px;color:{$color}'>{$js}{$ligne["computerid"]}</a></span><div style='font-size:10px;font-style:italic'>{$also}</div>", "<span style='font-size:16px;color:{$color}'>{$ligne["uid"]}</span>", "<span style='font-size:16px;color:{$color}'>{$ligne["MacAddress"]}</a></span>", $delete)); } echo json_encode($data); }
function scanarp() { $GLOBALS["CLASS_USERS"] = new usersMenus(); $GLOBALS["CLASS_SOCKETS"] = new sockets(); if (!$GLOBALS["CLASS_USERS"]->ARPD_INSTALLED) { if ($GLOBALS["VERBOSE"]) { echo __FUNCTION__ . " ARPD_INSTALLED = FALSE\n"; } return; } $EnableArpDaemon = $GLOBALS["CLASS_SOCKETS"]->GET_INFO("EnableArpDaemon"); if (!is_numeric($EnableArpDaemon)) { $EnableArpDaemon = 1; } if ($EnableArpDaemon == 0) { if ($GLOBALS["VERBOSE"]) { echo __FUNCTION__ . " EnableArpDaemon = {$EnableArpDaemon}\n"; } return; } $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . ".pid"; $unix = new unix(); $me = basename(__FILE__); $pid = $unix->get_pid_from_file($pidfile); if ($unix->process_exists($pid, $me)) { if ($GLOBALS["VERBOSE"]) { echo " {$pid} --> Already executed.. aborting the process\n"; } $time = $unix->PROCCESS_TIME_MIN($pid); system_admin_events("Already executed pid {$pid} since {$time}Mn.. aborting the process", __FUNCTION__, __FILE__, __LINE__, "system"); die; } @file_put_contents($pidfile, getmypid()); if (!is_file("/var/lib/arpd/arpd.db")) { die; } $GLOBALS["CLASS_UNIX"] = $unix; $GLOBALS["nmblookup"] = $unix->find_program("nmblookup"); $GLOBALS["arpd"] = $unix->find_program("arpd"); $GLOBALS["arp"] = $unix->find_program("arp"); $GLOBALS["ARP_DB"] = "/var/lib/arpd/arpd.db"; $GLOBALS["CACHE_DB"] = "/etc/artica-postfix/arpd.cache"; $GLOBALS["EnableMacAddressFilter"] = trim(@file_get_contents("/etc/artica-postfix/settings/Daemons/EnableMacAddressFilter")); if (!is_numeric($GLOBALS["EnableMacAddressFilter"])) { $GLOBALS["EnableMacAddressFilter"] = 1; } $squidbin = $unix->LOCATE_SQUID_BIN(); if (is_file($squidbin)) { if ($GLOBALS["EnableMacAddressFilter"] == 0) { return; } } $ArpdArray = unserialize(base64_decode(@file_get_contents($GLOBALS["CACHE_DB"]))); if ($GLOBALS["FLUSH"]) { $ArpdArray = array(); } if (!is_array($ArpdArray)) { $ArpdArray = array(); } if (!isset($ArpdArray["LAST"])) { $ArpdArray["LAST"] = 0; } $last_modified = filemtime($GLOBALS["ARP_DB"]); $TimeArpd = $ArpdArray["LAST"]; if ($TimeArpd == $last_modified) { events("{$TimeArpd} -> {$last_modified} No modification time", __FUNCTION__, __LINE__); return; } events("Scanning ARP table....", __FUNCTION__, __LINE__); $ArpdArray["LAST"] = $last_modified; exec("{$GLOBALS["arpd"]} -l 2>&1", $results); events("{$GLOBALS["arpd"]} -l return " . count($results) . " element(s)", __FUNCTION__, __LINE__); while (list($num, $ligne) = each($results)) { if (preg_match("#unexpected file type or format#", $ligne)) { @unlink($GLOBALS["ARP_DB"]); @unlink($GLOBALS["CACHE_DB"]); shell_exec("/etc/init.d/arpd restart"); die; } if (!preg_match("#^[0-9]+\\s+\\s+(.+?)\\s+(.+)#", $ligne, $re)) { if ($GLOBALS["VERBOSE"]) { echo "line: {$num}, unexpected line..\n"; } continue; } if (preg_match("#FAILED:#", $re[2])) { continue; } $mac = $re[2]; $ipaddr = $re[1]; if ($GLOBALS["VERBOSE"]) { echo "line: {$num}, MAC:{$mac} -> {$ipaddr}\n"; } if (isset($ArpdArray["MACS"][$mac])) { if ($GLOBALS["VERBOSE"]) { echo "MAC:{$mac} Already cached, aborting....\n"; } continue; } $ArpdArray["MACS"][$mac] = true; $cmp = new computers(); $uid = $cmp->ComputerIDFromMAC($mac); if ($GLOBALS["VERBOSE"]) { echo "line: {$num}, MAC:{$mac} -> {$uid}\n"; } if ($uid == null) { $res2 = array(); $computer_name = null; events("It is time to add {$mac}/{$ipaddr} in database", __FUNCTION__, __LINE__); exec("{$GLOBALS["arp"]} -a {$ipaddr} 2>&1", $res2); if (preg_match("#^(.+?)\\s+\\(#", trim(@implode("", $res2)), $rz)) { $computer_name = $rz[1]; } if (strlen($computer_name) < 3) { $computer_name = $ipaddr; } $cmp->uid = "{$computer_name}\$"; $cmp->ComputerIP = $ipaddr; $cmp->ComputerMacAddress = $mac; system_admin_events("adding/editing {$computer_name} with MAC:{$mac}", __FUNCTION__, __FILE__, __LINE__, "network"); $cmp->Add(); } else { if ($GLOBALS["FLUSH"]) { $res2 = array(); $cmp = new computers($uid); $computer_name = null; events("It is time to edit {$uid}/{$mac}/{$ipaddr} in database", __FUNCTION__, __LINE__); exec("{$GLOBALS["arp"]} -a {$ipaddr} 2>&1", $res2); if ($GLOBALS["VERBOSE"]) { echo "{$GLOBALS["arp"]} -a {$ipaddr} 2>&1 = >" . trim(@implode("", $res2)); } if (preg_match("#^(.+?)\\s+\\(#", trim(@implode("", $res2)), $rz)) { $computer_name = $rz[1]; } else { if ($GLOBALS["VERBOSE"]) { echo "Unable to find computer name\n"; } } if (strlen($computer_name) < 3) { $computer_name = $ipaddr; } if ($GLOBALS["VERBOSE"]) { echo "line: {$num}, UID:{$mac} -> {$uid}\n"; } if ($GLOBALS["VERBOSE"]) { echo "line: {$num}, NAME:{$computer_name} -> {$uid}\n"; } system_admin_events("adding/editing {$computer_name} with MAC:{$mac}", __FUNCTION__, __FILE__, __LINE__, "network"); $cmp->ComputerIP = $ipaddr; $cmp->ComputerMacAddress = $mac; $cmp->Add(); } } if (system_is_overloaded(basename(__FILE__))) { @file_put_contents($GLOBALS["CACHE_DB"], base64_encode(serialize($ArpdArray))); system_admin_events("Overloaded system, aborting the task...", __FUNCTION__, __FILE__, __LINE__, "network"); return; } @file_put_contents($GLOBALS["CACHE_DB"], base64_encode(serialize($ArpdArray))); $nice = EXEC_NICE(); $unix = new unix(); $nohup = $unix->find_program("nohup"); $php5 = $unix->LOCATE_PHP5_BIN(); shell_exec("{$nohup} {$nice} {$php5} " . __FILE__ . " --tomysql schedule-id={$GLOBALS["SCHEDULE_ID"]} >/dev/null 2>&1 &"); } }
function items() { $page = 1; $q = new mysql(); $table = "nmap_scannet"; if (isset($_POST["sortname"])) { if ($_POST["sortname"] != null) { $ORDER = "ORDER BY {$_POST["sortname"]} {$_POST["sortorder"]}"; } } if (isset($_POST['page'])) { $page = $_POST['page']; } if (!$q->TABLE_EXISTS("nmap_scannet", "artica_backup")) { $sql = "CREATE TABLE IF NOT EXISTS `nmap_scannet` (\n\t\t`MAC` varchar(90) NOT NULL,\n\t\t`ipaddr` varchar(90) NOT NULL,\n\t\t`vendor` varchar(90) NOT NULL DEFAULT '',\n\t\t`zDate` datetime NOT NULL,\n\t\tPRIMARY KEY (`MAC`),\n\t\tKEY `ipaddr` (`ipaddr`),\n\t\tKEY `vendor` (`vendor`)\n\t\t) ENGINE=MYISAM;"; $q->QUERY_SQL($sql, "artica_backup"); } $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, "artica_backup")); $total = $ligne["TCOUNT"]; } else { $sql = "SELECT COUNT(*) as TCOUNT FROM {$table}"; $ligne = mysql_fetch_array($q->QUERY_SQL($sql, "artica_backup")); $total = $ligne["TCOUNT"]; } 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 1 {$searchstring} {$ORDER} {$limitSql}"; if (isset($_GET["verbose"])) { echo "<hr><code>{$sql}</code></hr>"; } $results = $q->QUERY_SQL($sql, "artica_backup"); if (!$q->ok) { json_error_show($q->mysql_error, 1); } if (mysql_num_rows($results) == 0) { json_error_show("{$table} no data", 1); } $fontsize = "26px"; $data = array(); $data['page'] = 1; $data['total'] = mysql_num_rows($results); $data['rows'] = array(); //if(mysql_num_rows($results)==0){$data['rows'][] = array('id' => $ligne[time()],'cell' => array($sql,"", "",""));} $computer = new computers(); $tpl = new templates(); $dhcpfixed = $tpl->_ENGINE_parse_body("{dhcpfixed}"); $q2 = new mysql_squid_builder(); while ($ligne = mysql_fetch_assoc($results)) { $ipaddr = $ligne["ipaddr"]; $infoZ = array(); $mac = strtolower($ligne["MAC"]); $vendor = $ligne["vendor"]; $uid = null; $uid = $computer->ComputerIDFromMAC($mac); $view = " "; $jslink = null; $jsfiche = null; $infos = null; $macenc = urlencode($ligne["MAC"]); if ($uid != null) { $jslink = "<a href=\"javascript:blur();\"\n\t\t\t\tOnClick=\"javascript:" . MEMBER_JS($uid, 1, 1) . "\"\n\t\t\t\tstyle='font-size:{$fontsize};text-decoration:underline'>"; $computer = new computers($uid); if ($computer->dhcpfixed == 1) { $infoZ[] = "<a href=\"javascript:blur();\"\n\t\t\t\t\t\t\tOnClick=\"javascript:Loadjs('dhcpd.fixed.hosts.php?modify-dhcpd-settings-js=yes&mac={$macenc}');\"\n\t\t\t\t\t\t\tstyle='text-decoration:underline'>{$dhcpfixed}</a> - "; } if (trim($computer->DisplayName) != null) { $infoZ[] = $computer->DisplayName; } if (trim($computer->ComputerMachineType) != null) { $infoZ[] = $computer->ComputerMachineType; } if (trim($computer->ComputerOS) != null) { $infoZ[] = $computer->ComputerOS; } $infos = @implode(" - ", $infoZ); } else { $ocs = new ocs($mac); if (trim($ocs->HARDWARE_ID > 0)) { if ($ocs->dhcpfixed == 1) { $infos = "<a href=\"javascript:blur();\"\n\t\t\t\t\t\tOnClick=\"javascript:Loadjs('dhcpd.fixed.hosts.php?modify-dhcpd-settings-js=yes&mac={$macenc}');\n\t\t\t\t\t\tstyle='text-decoration:underline'>{$dhcpfixed}</a> - "; } $infos = $infos . $ocs->ComputerName . " - " . $computer->ComputerOS; } } $macenc = urlencode($mac); $proxy_alias = $q2->UID_FROM_MAC($mac); if ($proxy_alias != null) { $proxy_alias = "\n\t\t\t\t<a href=\"javascript:blur();\"\n\t\t\t\tstyle=\"text-decoration:underline\"\n\t\t\t\tOnClick=\"javascript:Loadjs('squid.nodes.php?node-infos-js=yes&MAC={$macenc}');\"\n\t\t\t\t>{$proxy_alias}</a>"; } if ($proxy_alias == null) { $proxy_alias = $q2->UID_FROM_IP($ipaddr); } if ($proxy_alias == null) { $proxy_alias = "<center>\n\t\t\t\t\t<a href=\"javascript:blur();\" \n\t\t\t\t\tOnClick=\"javascript:Loadjs('squid.nodes.php?link-user-js=yes&MAC={$macenc}&ipaddr={$ipaddr}',true)\"\n\t\t\t\t\t><img src='img/32-plus.png'></a></center>"; } $data['rows'][] = array('id' => md5(serialize($ligne)), 'cell' => array("<span style='font-size:26px'>{$ipaddr}</span>", "<span style='font-size:26px'>{$jslink}{$mac}</a></span>", "<span style='font-size:26px'>{$vendor}</span>", "<span style='font-size:18px'>{$infos}</span>", "<span style='font-size:26px'>{$proxy_alias}</span>")); } echo json_encode($data); }