function CopyFile($source, $dest) { // Check for symlinks if (is_link($source)) { return symlink(readlink($source), $dest); } // Simple copy for a file if (is_file($source)) { return copy($source, $dest); } // Make destination directory if (!is_dir($dest)) { mkdir($dest); } // Loop through the folder $dir = dir($source); while (false !== ($entry = $dir->read())) { // Skip pointers if ($entry == '.' || $entry == '..') { continue; } // Deep copy directories CopyFile("{$source}/{$entry}", "{$dest}/{$entry}"); } // Clean up $dir->close(); return true; }
function runtask($id) { $sql = "SELECT files_id,computer_id,commandline,username,password,debug_mode FROM deploy_tasks WHERE ID={$id}"; $q = new mysql(); $ligne = @mysql_fetch_array($q->QUERY_SQL($sql, 'artica_backup')); $ldap = new clladp(); $commandline = trim($ligne["commandline"]); $username = $ligne["username"]; $password = $ligne["password"]; $computerid = $ligne["computer_id"]; $files_id = $ligne["files_id"]; $debug_mode = $ligne["debug_mode"]; if (strpos($computerid, '$') == 0) { $computerid = "{$computerid}\$"; } $cmp = new computers($computerid); events("runtask:: debug mode={$debug_mode} computerid={$computerid} {$cmp->ComputerRealName}"); $sql = "SELECT * FROM files_storage WHERE id_files='{$files_id}'"; $q = new mysql(); $ligne = @mysql_fetch_array($q->QUERY_SQL($sql, 'artica_backup')); $filename = $ligne["filename"]; $bin_data = $ligne["bin_data"]; $OCS_PACKAGE = $ligne["OCS_PACKAGE"]; $MinutesToWait = $ligne["MinutesToWait"]; if ($MinutesToWait == 0) { $MinutesToWait = 5; } $package_commandline = $ligne["commandline"]; if ($commandline == null) { $commandline = $package_commandline; } $file_dir = str_replace(" ", "", $filename); $file_dir = str_replace(".", "", $file_dir); $ExecuteAfter = $ligne["ExecuteAfter"]; $_GET["logcomputer"] = OS_FILE_TEMP(); if ($debug_mode == 1) { events("runtask:: Debug mode enabled"); $_GET["DEBUG"] = true; $_GET["FILE_DEBUG"][] = $_GET["logcomputer"]; $_GET["FILE_DEBUG"][] = "/var/log/artica-postfix/remote-install.debug"; } if (trim($username) == null) { $ini = new Bs_IniHandler(); $ini->loadString($cmp->ComputerCryptedInfos); $username = $ini->_params["ACCOUNT"]["USERNAME"]; $password = $ini->_params["ACCOUNT"]["PASSWORD"]; } if ($OCS_PACKAGE == 1) { $commandline = OCS_COMMANDLINE(); } if (!is_file("/usr/bin/winexe")) { events("unable to stat /usr/bin/winexe"); return false; } if ($filename == null) { events("runtask:: Execute remote task for {$cmp->ComputerRealName} ({$cmp->ComputerIP}) failed to get file name for {$files_id} ({$filename})"); return false; } if ($bin_data == null) { events("runtask:: failed to get binary data on the server for package number {$files_id}"); return false; } $cmp = new computers($computerid); events("runtask:: Execute remote task for {$cmp->ComputerRealName} ({$cmp->ComputerIP})"); $pp = new ping($cmp->ComputerIP); if (!$pp->Isping()) { events("runtask:: Failed to ping {$cmp->ComputerRealName} ({$cmp->ComputerIP}), aborting process."); return false; } events("runtask:: pinging {$cmp->ComputerIP} OK"); $mount = new mount("/var/log/artica-postfix/remote-install.debug"); if (!$mount->ismounted("/opt/artica/mounts/remote-install")) { @mkdir("/opt/artica/mounts/remote-install", 0755, true); events("runtask:: mounting c\$ on remote computer..."); $cmd = "/bin/mount -t smbfs -o username={$username},password={$password} //{$cmp->ComputerIP}/c\$ /opt/artica/mounts/remote-install"; $cmd_logs = str_replace($password, "[password]", $cmd); events($cmd_logs); system("/bin/mount -t smbfs -o username={$username},password={$password} //{$cmp->ComputerIP}/c\$ /opt/artica/mounts/remote-install >{$_GET["logcomputer"]}.mount 2>&1"); events("runtask:: mount logs {$_GET["logcomputer"]}.mount :" . filesize("{$_GET["logcomputer"]}.mount") . " bytes"); $tbl = explode("\n", @file_get_contents("{$_GET["logcomputer"]}.mount")); @unlink("{$_GET["logcomputer"]}.mount"); if (is_array($tbl)) { while (list($index, $line) = each($tbl)) { if (trim($line) == null) { continue; } events("{$line}"); } } } else { events("runtask:: Already mounted"); } if (!$mount->ismounted("/opt/artica/mounts/remote-install")) { events("runtask:: mount class report unmounted... Unable to mount on target computer"); return false; } $workingDirectory = "/opt/artica/mounts/remote-install/tmp/{$file_dir}"; if (preg_match("#\\.zip\$#", $filename)) { $zipped = true; events("runtask:: Zipped compressed, extract file and execute {$commandline}"); $file_dir = ExtractFile($bin_data, $workingDirectory, $filename, $file_dir); if ($file_dir == null) { events("runtask:: Extracting failed..."); return false; } } else { events("runtask:: Copy file..."); if (!CopyFile($workingDirectory, $filename, $bin_data)) { events("runtask:: Unable to save //{$cmp->ComputerIP}/c\$/tmp/{$file_dir}/{$filename} on target computer "); return false; } } if ($zipped) { $execute_path = "C:\\tmp\\{$file_dir}\\{$commandline}"; } else { $execute_path = "C:\\tmp\\{$file_dir}\\{$filename} {$commandline}"; } events("runtask:: execute {$execute_path} on target computer"); $logfile = "/tmp/" . md5($cmp->ComputerIP); $cmd = "/usr/bin/winexe -d 2 --user={$username} --password={$password} --interactive=1 --runas={$username}%{$password} --uninstall //{$cmp->ComputerIP} \"{$execute_path}\" >{$logfile} &"; exec($cmd); if (!WaitWinexeForSecondes($MinutesToWait, $cmp->ComputerIP)) { events("runtask:: Time-out !!"); winexe_umount($workingDirectory); return false; } if ($ExecuteAfter != null) { events("runtask:: execute {$ExecuteAfter} on target computer"); $cmd = "/usr/bin/winexe -d 2 --user={$username} --password={$password} --interactive=1 --runas={$username}%{$password} --uninstall //{$cmp->ComputerIP} {$ExecuteAfter} >{$logfile} &"; exec($cmd); if (!WaitWinexeForSecondes($MinutesToWait, $cmp->ComputerIP)) { events("runtask:: execute {$ExecuteAfter} time-out on target computer"); } } winexe_umount($workingDirectory); events("runtask:: Done..."); return true; }
function ProcessImageDirectory($mode) { echo "<h4>Processing Images</h4>\n<blockquote>\n"; CreateDir(TARGET_IMAGE_DIR); if ($mode == "docs" || $mode == 'print') { CopyFile(NUNIT_IMAGE_DIR, TARGET_IMAGE_DIR, "logo.gif"); CopyFile(NUNIT_IMAGE_DIR, TARGET_IMAGE_DIR, "langfilter.gif"); CopyFile(NUNIT_IMAGE_DIR, TARGET_IMAGE_DIR, "bulletOn.gif"); CopyFile(NUNIT_IMAGE_DIR, TARGET_IMAGE_DIR, "bulletOff.gif"); } else { CopyDirectory(NUNIT_IMAGE_DIR, TARGET_IMAGE_DIR); } echo "</blockquote>\n"; }
function cmdCopyFile($data) { global $aStat; $sDscFile = DIR_SERVER_ROOT . '/' . $data['destination']; $sDscFile = str_replace('/templates/skin/default/', '/templates/skin/' . SITE_SKIN . '/', $sDscFile); if (substr($sDscFile, -1) != '/') { $sDscFile .= '/'; } $sDscFile .= basename($data['name']); $sSrcFile = DIR_INSTALL . '/' . $data['name']; if (!CopyFile($sSrcFile, $sDscFile)) { MsgError('Cannot copy file to <b>' . $sDscFile . '</b>.<br/> Please check permissions.'); } $aStat['copied'] += 1; }