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 Save() { $comp = new computers(); $comp->uid = $_POST["computername"] . "\$"; $comp->ComputerRealName = $_POST["computername"]; $comp->ComputerIP = $_POST["ipaddr"]; $comp->ComputerMacAddress = $_POST["MAC"]; $comp->Add(); }
function DeleteComputer() { $computer = new computers($_POST["DeleteComputer"]); if ($computer->ComputerMacAddress != null) { $ocs = new ocs($computer->ComputerMacAddress); $ocs->DeleteComputer(); return; } $computer->DeleteComputer(); }
function save() { $uid = $_GET["uid"]; if (strpos($uid, '$') == 0) { $uid = $uid . '$'; } $computer = new computers($uid); $ini = new Bs_IniHandler(); $ini->loadString($computer->ComputerCryptedInfos); $ini->_params["ACCOUNT"]["USERNAME"] = $_GET["username"]; $ini->_params["ACCOUNT"]["PASSWORD"] = $_GET["password"]; $computer->ComputerCryptedInfos = $ini->toString(); $computer->SaveCryptedInfos(); }
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 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 SimpleShareAddComputerLDAP() { $tpl = new templates(); $computer = $_GET["computername_add"]; $ip = $_GET["computerip_add"]; if ($computer == null) { echo $tpl->_ENGINE_parse_body("{computer_name} = NULL"); exit; } if ($ip == null) { echo $tpl->_ENGINE_parse_body("{ip_address} = NULL"); exit; } $uid = "{$computer}\$"; $comp = new computers($uid); $comp->ComputerIP = $ip; $comp->ComputerRealName = $computer; if (!$comp->Add()) { echo @implode("\n", $GLOBALS["INJECT_COMPUTER_TOLDAP"]); return; } }
function importcomputersFromList(){ cpulimit(20); $sock=new sockets(); $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;} $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)"); 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 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 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 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 SaveSchedule() { $computer = new computers($_GET["uid"] . '$'); $ini = new Bs_IniHandler(); $ini->loadString($computer->ComputerCryptedInfos); $ini->_params["SCHEDULE"]["cron"] = $_GET["SaveSchedule"]; $computer->ComputerCryptedInfos = $ini->toString(); $computer->SaveCryptedInfos(); }
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 computers_delete() { $filter_search = "(&(objectClass=ArticaComputerInfos)(|(cn=*)(ComputerIP=*)(uid=*))(gecos=computer))"; $ldap = new clladp(); $attrs = array("uid", "dn", "ComputerOS"); $dn = "{$ldap->suffix}"; $hash = $ldap->Ldap_search($dn, $filter_search, $attrs); for ($i = 0; $i < $hash["count"]; $i++) { if ($hash["{$i}"]["uid"][0] == null) { continue; } $count = $count + 1; $computer = new computers($hash["{$i}"]["uid"][0]); $computer->DeleteComputer(); } $tpl = new templates(); echo $tpl->javascript_parse_text("{success}: {$count} {computers}"); }
function main_add_computer() { $computer = $_POST["add_computer"]; if (trim($computer) != null) { $comp = new computers(); $comp->uid = $computer; if (!$comp->Add()) { echo $comp->ldap_error; } } }
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 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); }
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 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 computer_list() { $tofindorg = $_POST["query"]; $tpl = new templates(); $_GET["tofind"] = $_POST["query"]; $MyPage = CurrentPageName(); if ($_GET["tofind"] == '*') { $_GET["tofind"] = null; } if ($_GET["tofind"] == null) { $tofind = "*"; } else { $tofind = "*{$_GET["tofind"]}*"; } $tofind = str_replace("**", "*", $tofind); $filter_search = "(&(objectClass=ArticaComputerInfos)(|(cn={$tofind})(ComputerIP={$tofind})(uid={$tofind}))(gecos=computer))"; $ldap = new clladp(); $attrs = array("uid", "ComputerIP", "ComputerOS", "ComputerMachineType", "ComputerMacAddress"); $dn = "{$ldap->suffix}"; $hash = $ldap->Ldap_search($dn, $filter_search, $attrs, $_POST["rp"]); if (IsPhysicalAddress($tofindorg)) { $tofind = strtolower($tofindorg); $tofind = str_replace('-', ":", $tofind); $patternMac = "(&(objectclass=posixAccount)(ComputerMacAddress={$tofind}))"; $hash2 = $ldap->Ldap_search($dn, $patternMac, $attrs, $_POST["rp"]); } $spanStyle = "<span style='font-size:14px;font-weight:bold'>"; $data['page'] = 1; $data['total'] = $hash["count"]; $data['rows'] = array(); $c = 0; $unknown = $tpl->_ENGINE_parse_body("{unknown}"); for ($i = 0; $i < $hash["count"]; $i++) { $realuid = $hash[$i]["uid"][0]; $hash[$i]["uid"][0] = str_replace('$', '', $hash[$i]["uid"][0]); $js = MEMBER_JS($realuid, 1); $Alreadyrealuid[$realuid] = true; if ($_GET["mode"] == "dansguardian-ip-group") { $js_add = "<td width=1%>" . imgtootltip('add-18.png', "{add_computer}", "AddComputerToDansGuardian('{$realuid}','{$_GET["value"]}')") . "</td>"; } if ($_GET["mode"] == "selection") { $js = "{$_GET["callback"]}('{$realuid}');"; } $ip = $hash[$i][strtolower("ComputerIP")][0]; $os = $hash[$i][strtolower("ComputerOS")][0]; $type = $hash[$i][strtolower("ComputerMachineType")][0]; $name = $hash[$i]["uid"][0]; if ($os == "Unknown") { if ($type != "Unknown") { $os = $type; } } $js = str_replace("javascript:", '', $js); $md5S = md5(serialize($hash[$i])); if (!preg_match("#^[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+\$#", $ip)) { $ip = gethostbyname($hash[$i]["uid"][0]); if (!preg_match("#^[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+\$#", $ip)) { $ip = $unknown; } else { $computer = new computers($realuid); $computer->update_ipaddr($ip); } } if ($os == "UnKnown") { $os = $unknown; } $c++; $delete = imgsimple("delete-24.png", null, "Loadjs('{$MyPage}?computer-delete-js=yes&uid={$realuid}&id={$md5S}')"); $data['rows'][] = array('id' => $md5S, 'cell' => array("<img src='img/computer-32.png'>", "<a href='#' OnClick=\"javascript:{$js}\" style='font-size:14px;text-decoration:underline;font-weight:bold'>{$name}</a>", "{$spanStyle}{$ip}</span>", "{$spanStyle}{$os}</span>", $delete)); } if (is_array($hash2)) { for ($i = 0; $i < $hash2["count"]; $i++) { $realuid = $hash2[$i]["uid"][0]; if (isset($Alreadyrealuid[$realuid])) { continue; } $hash2[$i]["uid"][0] = str_replace('$', '', $hash2[$i]["uid"][0]); $js = MEMBER_JS($realuid, 1); $Alreadyrealuid[$realuid] = true; if ($_GET["mode"] == "dansguardian-ip-group") { $js_add = "<td width=1%>" . imgtootltip('add-18.png', "{add_computer}", "AddComputerToDansGuardian('{$realuid}','{$_GET["value"]}')") . "</td>"; } if ($_GET["mode"] == "selection") { $js = "{$_GET["callback"]}('{$realuid}');"; } $ip = $hash2[$i][strtolower("ComputerIP")][0]; $os = $hash2[$i][strtolower("ComputerOS")][0]; $type = $hash2[$i][strtolower("ComputerMachineType")][0]; $name = $hash2[$i]["uid"][0]; if (strlen($name) > 25) { $name = substr($name, 0, 23) . "..."; } if ($os == "Unknown") { if ($type != "Unknown") { $os = $type; } } if (strlen($os) > 20) { $os = texttooltip(substr($os, 0, 17) . '...', $os, null, null, 1); } if (strlen($ip) > 20) { $ip = texttooltip(substr($ip, 0, 17) . '...', $ip, null, null, 1); } $js = str_replace("javascript:", '', $js); $md5S = md5(serialize($hash2[$i])); $delete = imgsimple("delete-24.png", null, "Loadjs('{$MyPage}?computer-delete-js=yes&uid={$realuid}&id={$md5S}');"); $c++; $data['rows'][] = array('id' => $md5S, 'cell' => array("<img src='img/computer-32.png'>", "<a href='#' OnClick=\"javascript:{$js}\" style='font-size:13px;text-decoration:underline'>{$name}</a>", "{$spanStyle}{$ip}</span>", "{$spanStyle}{$os}</span>", $delete)); } } $data['total'] = $c; if ($c == 0) { json_error_show("no item"); } echo json_encode($data); }
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 COMPUTER_DELETE_ALIAS() { writelogs("delete aliase for to group {$_GET["userid"]}", __FUNCTION__, __FILE__, __LINE__); $comp = new computers($_GET["userid"]); $comp->ComputerDelAlias($_GET["DeletComputerAliases"]); }
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 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 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 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 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 SMBCHANGECOMPUTERS() { $ldap = new clladp(); $filter_search = "(&(objectClass=ArticaComputerInfos)(|(cn=*)(ComputerIP=*)(uid=*))(gecos=computer))"; $attrs = array("uid", "ComputerIP", "ComputerOS"); $dn = "{$ldap->suffix}"; $hash = $ldap->Ldap_search($dn, $filter_search, $attrs); for ($i = 0; $i < $hash["count"]; $i++) { $realuid = $hash[$i]["uid"][0]; if (preg_match("#[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+#", $realuid)) { continue; } $cp = new computers($realuid); $cp->UpdateComputerSID(); if (posix_getuid() != 0) { echo "<hr>"; } } }