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 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 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 smbtree(){ $unix=new unix(); $timefile="/etc/artica-postfix/smbtree.cache"; $smbtree=$unix->find_program("smbtree"); if(!is_file($smbtree)){return;} $time=file_time_min($timefile); if($time>5){ exec("$smbtree -N 2>&1",$results); @file_put_contents($timefile,serialize($results)); } $results=unserialize(@file_get_contents($timefile)); $final=array(); while (list ($index, $ligne) = each ($results)){ $ligne=trim($ligne); if($GLOBALS["VERBOSE"]){echo "check \"$ligne\"\n";} if(preg_match("#^([A-Za-z0-9\_\-]+)$#",$ligne,$re)){ if($GLOBALS["VERBOSE"]){echo "Found DOMAIN {$re[1]}\n";} $DOMAIN=$re[1]; continue; } $tr=explode('\\',$ligne); if(count($tr)>0){ unset($tr[0]); unset($tr[1]); if(count($tr)>1){ $final[$DOMAIN][$tr[2]]["IP"]=nmblookup($tr[2],null); $final[$DOMAIN][$tr[2]]["SHARES"][]=$tr[3]; } } } @file_put_contents("/usr/share/artica-postfix/ressources/logs/smbtree.array",serialize($final)); shell_exec("/bin/chmod 777 /usr/share/artica-postfix/ressources/logs/smbtree.array"); }