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->Ldap_rename_dn($newrdn, $actualdn, null)) { echo "Rename failed {$ldap->ldap_last_error}\nFunction:" . __FUNCTION__ . "\nFile:" . __FILE__ . "\nLine" . __LINE__ . "\nExpected DN:{$newDN}"; 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(); }
function Save() { $ocs = new ocs(); $ocs->HARDWARE_ID = $_POST["HARDWARE_ID"]; $ocs->LoadParams(); $ocs->ComputerName = $_POST["computername"]; $ocs->ComputerIP = $_POST["ipaddr"]; $ocs->mac = $_POST["MAC"]; $ocs->UpdateDirect(); }
function DeleteComputer() { $computer = new computers($_POST["DeleteComputer"]); if ($computer->ComputerMacAddress != null) { $ocs = new ocs($computer->ComputerMacAddress); $ocs->DeleteComputer(); return; } $computer->DeleteComputer(); }
function ENABLE_PACKAGE() { $HARDWARE_ID = $_GET["HARDWARE_ID"]; $FILEID = $_GET["FILEID"]; $enabled = $_GET["AffectPackageToValue"]; $ocs = new ocs(); if ($enabled == 1) { $ocs->PACKAGE_AFFECT($FILEID, $HARDWARE_ID); } else { $ocs->PACKAGE_DESAFFECT($FILEID, $HARDWARE_ID); } }
function softwares_search() { $page = CurrentPageName(); $tpl = new templates(); $cmp = new computers($_GET["uid"]); $ocs = new ocs($cmp->ComputerMacAddress); $ocs->LoadParams(); $q = new mysql(); $search = $_GET["search"]; $search = "*{$search}*"; $search = str_replace("**", "*", $search); $search = str_replace("**", "*", $search); $search = str_replace("*", "%", $search); $group_text = $tpl->_ENGINE_parse_body("{group}"); $sql = "SELECT * FROM softwares WHERE HARDWARE_ID={$ocs->HARDWARE_ID} AND ((PUBLISHER LIKE '{$search}') OR (NAME LIKE '{$search}') OR (COMMENTS LIKE '{$search}')) ORDER BY NAME LIMIT 0,50"; $results = $q->QUERY_SQL($sql, "ocsweb"); if (!$q->ok) { echo "<H2>{$q->mysql_error}</H2><code style='font-size:11px'>{$sql}</code>"; } $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% nowrap colspan=2>{PUBLISHER}</th>\n\t\t<th width=99%>{software}</th>\n\t\t<th width=1% align='center'>{version}</th>\n\t</tr>\n</thead>\n<tbody class='tbody'>"; while ($ligne = mysql_fetch_array($results, MYSQL_ASSOC)) { if (trim($ligne["PUBLISHER"]) == null) { $ligne["PUBLISHER"] = " "; } if ($classtr == "oddRow") { $classtr = null; } else { $classtr = "oddRow"; } $color = "black"; $html = $html . "\n\t\t<tr class={$classtr}>\n\t\t\t<td width=1%><img src='img/software-task-32.png'></td>\n\t\t\t<td style='font-size:14px;font-weight:normal;color:{$color}' nowrap>{$ligne["PUBLISHER"]}</td>\n\t\t\t<td style='font-size:14px;font-weight:normal;color:{$color}'>{$ligne["NAME"]}<div style='font-size:10px'><i>{$ligne["COMMENTS"]}</i></td>\n\t\t\t<td style='font-size:14px;font-weight:normal;color:{$color}' align='center'>{$ligne["VERSION"]}</td>\n\t\t</tr>\n\t\t"; } $html = $html . "</table>\n\t</center>\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 popup_network_save() { $ocs = new ocs(); $ocs->SET_SERVER_SETTINGS("PROLOG_FREQ", $_GET["PROLOG_FREQ"]); }
function AJAX_COMPUTER_OCS() { $uidend = urlencode($_GET["userid"]); $time = time(); $html = "<div id='{$time}'></div>\n\t<script>\n\t\tLoadAjax('{$time}','computers.ocs.single.php?uid={$uidend}');\n\t</script>\n\t\n\t"; $tpl = new templates(); return $tpl->_ENGINE_parse_body($html); $install = Paragraphe("software-deploy-64.png", "{OCS_DEPLOY_WINDOWS}", "{OCS_DEPLOY_WINDOWS_TEXT}", "javascript:Loadjs('ocs.ng.php?deploy-js={$_GET["userid"]}')"); $cmp = new computers($_GET["userid"]); $ocs = new ocs($cmp->ComputerMacAddress); $ocsinfos = $ocs->BuildFirstInfos(); if ($ocsinfos != null) { $install = null; } $html = "\n\t<table style='width:100%'>\n\t<tr>\n\t\t<td valign='top' style='vertical-align:top' width=1%>{$install}\n\t\t</td>\n\t\t<td valign='top' style='vertical-align:top' width=99%><div style='width:99%;height:350px;overflow:auto'>{$ocsinfos}</div></td>\n\t</tr>\n\t</table>\n \t\n\t"; $tpl = new templates(); return $tpl->_ENGINE_parse_body($html); }
function runtask($uid, $ID) { Levents("Starting deploy remote agent on {$uid}, task id {$ID}", $ID, 5, "executing", __FUNCTION__, __LINE__); $sock = new sockets(); $unix = new unix(); $winexe = $unix->find_program('winexe'); $winexe_no_errors["smb_raw_read_recv"] = true; $winexe_no_errors["on_ctrl_pipe_error"] = true; $ocs = new ocs(); if ($winexe == null) { Levents("unable to stat winexe program", $ID, 110, "failed", __FUNCTION__, __LINE__); return false; } $ocsInventoryagntWinVer = $sock->getFrameWork("cmd.php?ocsInventoryagntWinVer=yes"); Levents("Remote agent version {$ocsInventoryagntWinVer}", $ID, 6, "executing", __FUNCTION__, __LINE__); if ($ocsInventoryagntWinVer == null) { Levents("unable to stat OCS agent windows version", $ID, 110, "failed", __FUNCTION__, __LINE__); return false; } $package_source = "/opt/artica/install/sources/fusioninventory/fusioninventory-agent_windows-i386-{$ocsInventoryagntWinVer}.exe"; Levents("Remote agent package fusioninventory-agent_windows-i386-{$ocsInventoryagntWinVer}.exe", $ID, 7, "executing", __FUNCTION__, __LINE__); $cmp = new computers($uid); Levents("runtask:: Execute remote task for {$cmp->ComputerRealName} ({$cmp->ComputerIP})", $ID, 7, "executing", __FUNCTION__, __LINE__); //if(!PREG_BACKTRACK_LIMIT_ERROR) if (!preg_match("#^[0-9]+\\.[0-9]+\\.[0-9]+#", $cmp->ComputerIP)) { $cmp->ComputerIP = null; } $ipsrc = $cmp->ComputerIP; $cmp->ComputerIP = $unix->HostToIp($cmp->ComputerRealName); if ($cmp->ComputerIP == null) { $cmp->ComputerIP = $ipsrc; } if ($cmp->ComputerIP == null) { Levents("Failed to resolve computer name {$cmp->ComputerRealName} aborting process.", $ID, 110, "failed", __FUNCTION__, __LINE__); return false; } $pp = new ping($cmp->ComputerIP); if (!$pp->Isping()) { Levents("Failed to ping {$cmp->ComputerRealName} ({$cmp->ComputerIP}), aborting process.", $ID, 110, "failed", __FUNCTION__, __LINE__); return false; } Levents("pinging {$cmp->ComputerIP} OK", $ID, 15, "starting", __FUNCTION__, __LINE__); $hash = unserialize(base64_decode($sock->GET_INFO("GlobalNetAdmin"))); $page = CurrentPageName(); $global_user = $hash["GLOBAL"]["username"]; $global_password = $hash["GLOBAL"]["password"]; $ini = new Bs_IniHandler(); $ini->loadString($cmp->ComputerCryptedInfos); $username_standard = $ini->_params["ACCOUNT"]["USERNAME"]; $password_standard = $ini->_params["ACCOUNT"]["PASSWORD"]; $MountComputerRemote = false; if ($global_user != null) { Levents("mounting using {$global_user}", $ID, 20, "connect", __FUNCTION__, __LINE__); $MountComputerRemote = MountComputerRemote($cmp->uid, $cmp->ComputerIP, $global_user, $global_password, $package_source); if (!$MountComputerRemote) { if ($username_standard != null) { $global_user = $username_standard; $global_password = $password_standard; } } } if (!$MountComputerRemote) { if ($username_standard != null) { Levents("mounting using {$username_standard}", $ID, 20, "connect", __FUNCTION__, __LINE__); $MountComputerRemote = MountComputerRemote($cmp->uid, $cmp->ComputerIP, $username_standard, $password_standard, $package_source); } } while (list($index, $line) = each($GLOBALS[$cmp->uid]["EVENTS"])) { if (trim($line) == null) { continue; } Levents($line, $ID, 50, "connecting", __FUNCTION__, __LINE__); } if (!$MountComputerRemote) { Levents("MountComputerRemote() -> failed", $ID, 50, "failed", __FUNCTION__, __LINE__); return false; } unset($GLOBALS[$cmp->uid]["EVENTS"]); $uri = $ocs->GET_OCSSERVER_URI(); Levents("OCS servers is set has {$uri}, working path={$GLOBALS["LOCAL_FILE_PATH"]}", $ID, 50, "installing", __FUNCTION__, __LINE__); $execute_path = $GLOBALS["LOCAL_FILE_PATH"] . " /S /server={$uri} /no-ssl-check /rpc-trust-localhost /runnow"; Levents("{$execute_path} on target computer", $ID, 80, "remote_install", __FUNCTION__, __LINE__); $logfile = "/tmp/" . md5($cmp->ComputerIP); $cmd = "{$winexe} -d 2 --user={$global_user} --password={$global_password} --interactive=0 --runas={$global_user}%{$global_password} --uninstall //{$cmp->ComputerIP} \"{$execute_path}\" >{$logfile} &"; writelogs("{$cmd}", __FUNCTION__, __FILE__, __LINE__); system($cmd); if (!WaitWinexeForSecondes(5, $cmp->ComputerIP)) { Levents("Execute time-out after 5 minutes on target computer", $ID, 110, "failed", __FUNCTION__, __LINE__); return false; } $results = @explode("\n", @file_get_contents($logfile)); $type = "installed"; $mypourc = 100; while (list($index, $line) = each($results)) { if (trim($line) == null) { continue; } if (preg_match("#Sending command: set runas#", $line)) { continue; } if (preg_match("#ERROR:\\s+(.+?)\\s+#", $line, $re)) { if (!$winexe_no_errors[trim($re[1])]) { $type = failed; $mypourc = 110; } } Levents($line, $ID, $mypourc, $type, __FUNCTION__, __LINE__); } @unlink($logfile); unset($results); exec("umount -l {$GLOBALS["MOUNT_POINT"]}", $results); while (list($index, $line) = each($results)) { if (trim($line) == null) { continue; } Levents($line, $ID, $mypourc, $type, __FUNCTION__, __LINE__); } return true; }
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 AJAX_COMPUTER_OCS() { $install = Paragraphe("software-deploy-64.png", "{OCS_DEPLOY_WINDOWS}", "{OCS_DEPLOY_WINDOWS_TEXT}", "javascript:Loadjs('ocs.ng.php?deploy-js={$_GET["userid"]}')"); $cmp = new computers($_GET["userid"]); $ocs = new ocs($cmp->ComputerMacAddress); $ocsinfos = $ocs->BuildFirstInfos(); $html = "\n\t<table style='width:100%'>\n\t<tr>\n\t\t<td valign='top' width=1%>{$install}\n\t\t</td>\n\t\t<td valign='top' width=99%><div style='width:99%;height:350px;overflow:auto'>{$ocsinfos}</div></td>\n\t</tr>\n\t</table>\n \t\n\t"; $tpl = new templates(); return $tpl->_ENGINE_parse_body($html); }
function ParseComputersOCS() { $Dir = "/var/log/squid/mysql-computers"; if (!($handle = opendir($Dir))) { events("Unable to open {$Dir}"); return; } $f = array(); events("ParseComputersOCS()::Scanning {$Dir}"); $ocs = new ocs(); while (false !== ($filename = readdir($handle))) { if ($filename == ".") { continue; } if ($filename == "..") { continue; } $filepath = "{$Dir}/{$filename}"; events("ParseComputersOCS():: Scanning {$filepath}"); $array = unserialize(@file_get_contents($filepath)); if (!is_array($array)) { events("ParseUsersAgents:: {$filepath} Not an array"); continue; } $mac = $array["MAC"]; $ipaddr = $array["IP"]; $ocs->ADD_HARDWARE($ipaddr, $mac); } }
function delete_computer() { $ocs = new ocs($_POST["delete-computer"]); $ocs->DeleteComputer(); }
function popup_ocs_softs_list() { $uid = $_GET["uid"]; $page = CurrentPageName(); $ocs = new ocs(); $tpl = new templates(); $PUBLISHER = $_GET["PUBLISHER"]; $HARDWARE_ID = $_GET["HARDWARE_ID"]; if ($HARDWARE_ID < 1) { $comp = new computers($uid); $HARDWARE_ID = $ocs->GET_HARDWARE_ID_FROM_MAC($comp->ComputerMacAddress); } $sql = "SELECT NAME,VERSION FROM softwares WHERE HARDWARE_ID={$HARDWARE_ID} AND PUBLISHER='{$PUBLISHER}'"; if ($PUBLISHER == null) { $sql = "SELECT NAME,VERSION FROM softwares WHERE HARDWARE_ID={$HARDWARE_ID} LIMIT 0,50"; } $html = "\n\t<table class=tableView style='width:95%'>\n\t\t<thead class=thead>\n\t\t\t<tr>\n\t\t\t\t<th width=1% nowrap colspan=2>{software}:</td>\n\t\t\t\t<th width=1% nowrap>{version}:</td>\n\t\t\t</tr>\n\t\t</thead>"; $q = new mysql(); $results = $q->QUERY_SQL($sql, "ocsweb"); if (!$q->ok) { $html = "<code style='color:#d32d2d'>{$q->mysql_error}<br>{$sql}</code>"; } while ($ligne = mysql_fetch_array($results, MYSQL_ASSOC)) { if ($cl == "oddRow") { $cl = null; } else { $cl = "oddRow"; } $ligne["NAME"] = utf8_encode($ligne["NAME"]); $html = $html . "\n\t\t<tr class={$cl}> \n\t\t\t<td valign='middle' width=1%><img src='img/fw_bold.gif'></td>\n\t\t\t<td><strong style='font-size:12px'>{$ligne["NAME"]}</td>\n\t\t\t<td valign='middle' width=1% nowrap><strong>{$ligne["VERSION"]}</td>\n\t\t</tr>"; } $html = $html . "</table>"; echo $tpl->_ENGINE_parse_body($html); }