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; }