function server_command($serverip, $cmd, $noremove = false, $copy_file_to_dest = False) { # not used yet. # execute a shell command in local or remote server. if (is_array($serverip)) { $serverip = $serverip['ip']; } # accept both until all code is standard. if (!$noremove) { $cmd = removeDoubleSlash($cmd); } $escapedcmd = escapeshellcmd($cmd); $accessip = $this->get_server_access_ip($serverip); #echo "\nexecuting command: $cmd \n(escaped cmd:$escapedcmd)\n"; if ($accessip == 'localhost') { echo "\nexecuting command: {$cmd} \n(escapedcmd: {$escapedcmd})\n"; return shell_exec($escapedcmd); } else { if ($copy_file_to_dest) { # in this case, the command is a file (probably that has many commands inside) that needs to be transfered to dest server before executing. shell_exec("scp {$cmd} {$accessip}:/etc/ehcp/"); $cmd = "/etc/ehcp/{$cmd}"; } echo "\nexecuting command: ssh {$accessip} \"{$cmd}\" \n(escapedcmd: ssh {$accessip} \"{$escapedcmd}\")\n"; return shell_exec("ssh {$accessip} \"{$escapedcmd}\""); } }
function passthru3($cmd, $source = '') { $cmd = removeDoubleSlash($cmd); # Echoes command and execute, does not escapeshellcmd echo "\n{$source}:Executing command: ({$cmd}) \n"; passthru($cmd); }