$ssh->exec('ping 127.0.0.1'); on a Linux host will never return and will run indefinitely. setTimeout() makes it so it'll timeout.
Setting $timeout to false or 0 will mean there is no timeout.
public setTimeout ( mixed $timeout ) | ||
$timeout | mixed |
/** * Logs in to a SSH server with the specified credentials, * and returns the Net_SSH2 instance. * * @return Net_SSH2 $ssh * @author Ronald Rey **/ public static final function getSSH($host, $user, $pass, $timeout) { $ssh = new Net_SSH2($host); if (!$ssh->login($user, $pass)) { exit('Login to failed.'); } $ssh->setTimeout($timeout); $ssh->write(" "); return $ssh; }
public function Exec($command, $stdin = '') { $database = $this->session->getDatabase(); $name = $database['name']; $engine = $this->session->getSpoolerByName($name, 'waae'); if (!isset($engine[0]['shell'])) { print "?!"; exit; } set_include_path('../vendor/phpseclib' . PATH_SEPARATOR . get_include_path()); include 'Net/SSH2.php'; include 'Crypt/RSA.php'; $shell = $engine[0]['shell']; $host = $shell['host']; $user = $shell['user']; $ssh = new \Net_SSH2($host); if (isset($shell['key'])) { $key = new \Crypt_RSA(); $ret = $key->loadKey($shell['key']); if (!$ret) { echo "loadKey failed\n"; print "<pre>" . $ssh->getLog() . '</pre>'; exit; } } elseif (isset($shell['password'])) { $key = $shell['password']; } else { $key = ''; // ?! possible ? } if (!$ssh->login('autosys', $key)) { print 'Login Failed'; print "<pre>" . $ssh->getLog() . '</pre>'; exit; } if ($stdin == '') { return $ssh->exec(". ~/.bash_profile;{$command}"); } // Test STDIN $ssh->enablePTY(); print "profile" . $ssh->exec(". ~/.bash_profile"); print "sort" . ($exec = $ssh->exec('sort')); $ssh->write(<<<EOF echo "update_job: SE.ERIC.JOB.JobType_UNIX" echo "description: 'ok!!' EOF ); $ssh->reset(true); $ssh->setTimeout(2); print $ssh->read(); return; return $ssh->read(); // outputs the echo above }
/** * ??? * * @param string[][] $data Die Serverdaten * @return ??? */ public static function Verbinden($data) { $ssh = null; if ($data['ZV']['zv_ssh_auth_type'] == 'passwd') { $ssh = new Net_SSH2($data['ZV']['zv_ssh_address']); $res = @$ssh->login($data['ZV']['zv_ssh_login'], $data['ZV']['zv_ssh_password']); if (!$res) { return null; } $ssh->setTimeout(0); } else { if ($data['ZV']['zv_ssh_auth_type'] == 'keyFile') { $ssh = new Net_SSH2($data['ZV']['zv_ssh_address']); $key = new Crypt_RSA(); $key->loadKey(file_get_contents($data['ZV']['zv_ssh_key_file'])); if (!$ssh->login($data['ZV']['zv_ssh_login'], $key)) { return null; } $ssh->setTimeout(0); } } return $ssh; }
echo "."; @ob_flush(); flush(); } $result = mysqli_query($con, "SELECT name,coind,gitsrc,cd_gitsrc,port_p2p,port_rpc FROM coind_templates WHERE id='" . $_POST['templateid'] . "'"); $coindinfo = mysqli_fetch_row($result); $coindinfo['name'] = $coindinfo[0]; $coindinfo['coind'] = $coindinfo[1]; $coindinfo['gitsrc'] = $coindinfo[2]; $coindinfo['cd_gitsrc'] = $coindinfo[3]; $coindinfo['port_p2p'] = $coindinfo[4]; $coindinfo['port_rpc'] = $coindinfo[5]; $result2 = mysqli_query($con, "SELECT ip FROM servers WHERE id='" . $_POST['serverid'] . "'"); $serverinfo = mysqli_fetch_row($result2); $serverinfo['ip'] = $serverinfo[0]; //log into server., $ssh = new Net_SSH2($serverinfo['ip']); $key = new Crypt_RSA(); $key->loadKey(file_get_contents($sshkey_location)); if (!$ssh->login('root', $key)) { $debug[] = "SSH Login Failed!"; } else { $ssh->setTimeout(25); $debug['exec_fixutf8bug'] = $ssh->exec('su -c "export LC_ALL=\\"en_US.UTF-8\\"" -s /bin/sh ' . $_POST['username'], 'packet_handler'); $cmd = "cd /home/" . $_POST['username'] . "/sauce/" . $coindinfo['cd_gitsrc'] . "/;"; $cmd .= "./" . $coindinfo['coind'] . " -daemon &"; $debug['exec_service'] = $ssh->exec('su -c "' . $cmd . '" -s /bin/sh ' . $_POST['username'], 'packet_handler'); $debug['step'] = "Daemon Started! <a href=coinds.php>Enjoy your service.</a>"; } mysqli_close($con); print_r($debug);
$path = getcwd(); set_include_path($path); @($query = mysqli_query($connect, "SELECT * FROM configureddb where dbuid='{$option}'")); while ($query_row = mysqli_fetch_assoc($query)) { $hostname = $query_row['server']; $sslusername = $query_row['sslusername']; $sslpassword = $query_row['sslpassword']; } set_include_path(get_include_path() . '/' . 'phpsec'); include 'Net/SSH2.php'; include 'File/ANSI.php'; $ssh = new Net_SSH2(@$hostname); if (@$ssh->login(@$sslusername, @$sslpassword)) { $ssh->enablePTY(); $ssh->exec('ps axo pid,ppid,%cpu,pmem,user,group,args --sort %cpu'); $ssh->setTimeout(2); $hello = $ssh->read(); $ps = explode("\n", $hello); $proc = array(); foreach ($ps as $process) { $processes[] = preg_split('@\\s+@', trim($process), 7); } unset($processes[0]); foreach ($processes as $pro) { $proc[] = @array('pid' => $pro[0], 'ppid' => $pro[1], 'cpu' => $pro[2], 'pmem' => $pro[3], 'user' => $pro[4], 'group' => $pro[5], 'cmd' => $pro[6]); } echo json_encode($proc); } else { echo "[]"; } } else {
function create_client_config_and_send($cert_name, $config_dir, $config_file, $remote_value, $send_type, $key_dir_name) { //will need phpseclib later.... so... if (!isset($_SESSION['password'])) { start_session('certs.php?action=send_cert&type=$send_type&cert_name=$cert_name'); } $password = stripslashes(trim($_SESSION['password'])); $username = stripslashes(trim($_SESSION['username'])); if ($username == "") { $username = "******"; } $ssh = new Net_SSH2('localhost'); if (!$ssh->login($username, $password)) { exit('Login Failed'); } //Creating a default client config file //TODO have a check to make sure /etc/openvpn.conf exists.... //If none exists... then you should prolly do some checks when the webui is first launched.... duh if (!file_exists("openvpn-client-default.conf")) { create_default_client_config(); } $vpn_config = read_openvpn_config($config_dir . $config_file); extract($vpn_config); echo "Default client file exists... <br />"; echo "Now copying to new config {$cert_name}.conf<br />"; copy("openvpn-client-default.conf", "{$cert_name}.conf"); //New Conf file should exist.... Now edit specifics... if (file_exists("{$cert_name}.conf")) { $client_config = "{$cert_name}.conf"; file_put_contents($client_config, "cert " . $cert_name . ".crt" . PHP_EOL, FILE_APPEND | LOCK_EX); file_put_contents($client_config, "key " . $cert_name . ".key" . PHP_EOL, FILE_APPEND | LOCK_EX); } else { echo "Error... client config file not found?<br />"; exit; } //Finding what dir $curr_work_dir = getcwd(); echo "Copying needed files...<br />"; //Now copying all the necc. sh!t to the root folder... then zip it? tar it? idk.. prolly zip $ssh->read('/.*@.*[$|#]/', NET_SSH2_READ_REGEX); $ssh->write("cd {$key_dir_name};cp {$cert_name}.key {$ca_values['1']} {$cert_name}.crt {$curr_work_dir}\n"); $result = $ssh->read('/.*@.*[$|#]/', NET_SSH2_READ_REGEX); echo "<pre>{$result}</pre>"; //HAVE to change the permissions on *.key... or php can't touch it echo "Have to change permissions on the *.key file.. or php can't touch..<br />"; $ssh->write("cd {$curr_work_dir};chmod 555 {$cert_name}.key\n"); $result = $ssh->read('/.*@.*[$|#]/', NET_SSH2_READ_REGEX); echo "<pre>{$result}</pre>"; echo str_repeat(' ', 1024 * 64); //create array of files to zip $files_to_zip = array("{$cert_name}.crt", "{$cert_name}.key", "{$ca_values['1']}", "{$cert_name}.conf"); echo "Creating zip file <b>{$cert_name}.zip</b><br />"; echo str_repeat(' ', 1024 * 64); $result = create_zip($files_to_zip, "{$cert_name}.zip", $cert_name); // unlink every other file... unlink("{$cert_name}.crt"); unlink("{$cert_name}.key"); unlink("{$ca_values['1']}"); unlink("{$cert_name}.conf"); if ($send_type == "download") { echo "<br /> Download transfer type selected!"; echo "<br />"; echo "Result:{$result}"; echo str_repeat(' ', 1024 * 64); sleep(5); // return name of zip file, will use that to generate download link return $result; exit; } if ($send_type == "scp") { if (!isset($_SESSION['password'])) { start_session('certs.php?action=send_cert&type=$send_type&cert_name=$cert_name'); } $password = stripslashes(trim($_SESSION['password'])); $username = stripslashes(trim($_SESSION['username'])); if ($username == "") { $username = "******"; } $ssh = new Net_SSH2('localhost'); if (!$ssh->login($username, $password)) { exit('Login Failed'); } echo "SCP transfer type selected!"; echo "TYPE TOO"; echo str_repeat(' ', 1024 * 64); $ssh->read('/.*@.*[$|#]/', NET_SSH2_READ_REGEX); $ssh->write("cd {$curr_work_dir};scp {$cert_name}.zip {$username}@{$remote_host}:{$remote_dir}\n"); $ssh->setTimeout(10); sleep(5); $result = $ssh->read('/.*@.*[$|#]/', NET_SSH2_READ_REGEX); echo "<pre>{$result}</pre>"; echo str_repeat(' ', 1024 * 64); exit; } }
//remote path variables to files $remoteInputFile = "/code/spopt-stable/tests/" . $session . "/input.txt"; $remoteOutputFile = "/code/spopt-stable/tests/" . $session . "/input.txt.out"; $remoteSolutionsFile = "/code/spopt-stable/tests/" . $session . "/input.txt.solutions"; $remoteDiscardedFile = "/code/spopt-stable/tests/" . $session . "/input.txt.discarded"; //ssh2 and sftp used to remotely connect set_include_path(get_include_path() . PATH_SEPARATOR . 'phpseclib'); include 'Net/SSH2.php'; include 'Net/SFTP.php'; //ssh connect to cr2g server $ssh = new Net_SSH2('cr2g01.cs.utep.edu', 22); if (!$ssh->login('rlgruver', 'utep$2015')) { exit('ssh Login Failed'); } //attempted to set an ssh timeout, not allowed on UTEP server $ssh->setTimeout(7200); //sftp connect to cr2g server $sftp = new Net_SFTP('cr2g01.cs.utep.edu', 22); if (!$sftp->login('rlgruver', 'utep$2015')) { exit('sftp Login Failed'); } //send input file to cr2g server $sftp->mkdir('/code/spopt-stable/tests/' . $session); $sftp->put($remoteInputFile, $localInputFile, NET_SFTP_LOCAL_FILE); $sftp->chmod(0777, $remoteInputFile); //execute python script in this order to run the Solver: //1. change to directory where solver script is located $ssh->write("cd /code/spopt-stable\n"); //2. 'read' command to ensure script is called from the proper directory $ssh->read('rlgruver@cr2g01:/code/spopt-stable$'); //3. run the solver script with the test from the current session
public static function server_connect($sServer, $sAPI = 0) { $sSSH = new Net_SSH2($sServer->sIPAddress); if ($sServer->sPassword == 0) { $sKey = new Crypt_RSA(); $sKey->loadKey(file_get_contents('/var/feathur/data/keys/' . $sServer->sKey)); } else { $sKey = file_get_contents('/var/feathur/data/keys' . $sServer->sKey); } try { if (!$sSSH->login($sServer->sUser, $sKey)) { if (!empty($sAPI)) { return $sResult = array("result" => 'Unable to connect to the host node, please contact customer service.'); } echo json_encode(array("result" => 'Unable to connect to the host node, please contact customer service.')); die; } else { $sSSH->setTimeout(30); return $sSSH; } } catch (Exception $e) { if (!empty($sAPI)) { return $sResult = array("result" => 'Unable to connect to the host node, please contact customer service.'); } echo json_encode(array("result" => 'Unable to connect to the host node, please contact customer service.')); die; } }
$host_connected = false; $sql = "UPDATE sshManagerQueue\n\t\t\t\tSET cmdOutput = 'Auth failed!',\n\t\t\t\t\tcmdTimestamp = UNIX_TIMESTAMP()\n\t\t\t\tWHERE memberID = '" . $connection["memberID"] . "'\n\t\t\t\t AND jobTemplateID = '" . $connection["jobTemplateID"] . "'\n\t\t\t\t AND deviceID = '" . $connection["deviceID"] . "'\n\t\t\t\t AND cmdID = '" . $connection["cmdID"] . "'"; //echo "Running sql auth error cmdID: ".$connection["cmdID"]."\n$sql"; if ($db_CS->query($sql)) { } } else { // WE GOT A CONNECTION ! //$ansi->appendString($ssh->read('username@username:~$')); $ansi = new File_ANSI(); $sql = "UPDATE sshManagerQueue\n\t\t\t\tSET cmdOutput = 'Connected!',\n\t\t\t\t\tcmdTimestamp = UNIX_TIMESTAMP()\n\t\t\t\tWHERE memberID = '" . $connection["memberID"] . "'\n\t\t\t\t AND jobTemplateID = '" . $connection["jobTemplateID"] . "'\n\t\t\t\t AND cmdID = '" . $connection["cmdID"] . "'\n\t\t\t\t AND deviceID = '" . $connection["deviceID"] . "'"; if ($db_CS->query($sql)) { if (strstr($cmdText, 'top')) { $ssh->enablePTY(); //echo "found TOP in command list\n"; $ssh->exec($cmdText); $ssh->setTimeout(5); //$ansi->appendString($ssh->read('username@username:~$')); $ansi->appendString($ssh->read()); $response["cmdOutput"] = $ansi->getHistory(); } else { $ssh->enablePTY(); //echo "not found TOP in command list\nExecuting $cmdText \n"; $ssh->exec($cmdText . "\n"); //$ssh->setTimeout(5); $ansi->appendString($ssh->read()); $response["cmdOutput"] = $ansi->getHistory(); //$response["cmdOutput"] = $ssh->exec($cmdText); } //echo "Response: \n".$response["cmdOutput"]; $sql = "UPDATE sshManagerQueue\n\t\t\t\t\tSET cmdOutput = '" . addslashes($response["cmdOutput"]) . "',\n\t\t\t\t\t\tcmdTimestamp = UNIX_TIMESTAMP()\n\t\t\t\t\tWHERE memberID = '" . $connection["memberID"] . "'\n\t\t\t\t\t AND jobTemplateID = '" . $connection["jobTemplateID"] . "'\n\t\t\t\t\t AND cmdID = '" . $connection["cmdID"] . "'\n\t\t\t\t\t AND deviceID = '" . $connection["deviceID"] . "'"; //echo "Running sql success cmdID: ".$connection["cmdID"]."\n$sql";
$vsftpd .= "write_enable=YES\n"; $vsftpd .= "local_enable=YES\n"; $vsftpd .= "allow_writeable_chroot=YES\n"; //SSL $vsftpd .= "rsa_cert_file=/etc/ssl/private/vsftpd.pem\n"; $vsftpd .= "rsa_private_key_file=/etc/ssl/private/vsftpd.pem\n"; $vsftpd .= "ssl_enable=YES\n"; $vsftpd .= "allow_anon_ssl=NO\n"; $vsftpd .= "ssl_tlsv1=YES\n"; $vsftpd .= "ssl_sslv2=NO\n"; $vsftpd .= "ssl_sslv3=NO\n"; $vsftpd .= "require_ssl_reuse=NO\n"; $vsftpd .= "ssl_ciphers=HIGH\n"; $vsftpd .= "################\n"; if ($os == "Debian 8 32bit") { $ssh->setTimeout(45); $ssh->exec('apt-get update'); $ssh->exec('apt-get -y install sudo'); $ssh->exec('apt-get -y install screen'); $ssh->exec('apt-get -y install libtinfo5 libncurses5'); $ssh->exec('apt-get -y install lib32stdc++6'); $ssh->exec('apt-get -y install vsftpd'); $ssh->exec('apt-get -y install unzip'); $ssh->exec('apt-get -y install gawk'); $ssh->exec("apt-get -y install openssl"); $os_version = "Debian 8"; $os_bit = "32"; } elseif ($os == "Debian 8 64bit") { $ssh->exec('dpkg --add-architecture i386'); $ssh->setTimeout(45); $ssh->exec('apt-get update');
function NewOrderPatient($drug, $dose, $Regimen_Dose_Unit, $Description, $match, $NumberofDoses) { if ($Description === 'old') { } else { $orderday = date('m_d_Y'); //Set Variables $host = '54.83.44.110'; $username = '******'; $password = ''; $login = '******'; $loginpass = '******'; $csession = 'csession cache355'; $cdUnix = 'D ^%CD'; $instance = 'CPM355'; $cprsLogin = '******'; $tmatch = trim($match); $patientSearch = $tmatch; $patientLocation = 'GEN MED'; $actingProvider = 'v107'; $doseorder = "" . $dose . " " . $Regimen_Dose_Unit . ""; $schedule = 'QDAY'; $routine = 'ROUTINE'; $drug = '5-FU FLUOROURACIL INJ,SOLN'; $tdrug = trim($drug); $AC = '1radiologist'; $VC = 'radiologist1'; $Description = 'OutPatient'; $ssh = new Net_SSH2($host); if (!$ssh->login($username, $password)) { exit('Login Failed'); } $ssh->write("{$login}\r"); $ssh->write("{$loginpass}\r"); sleep(3); $ssh->write("{$AC}\r"); $ssh->write("{$VC}\r"); sleep(3); $ssh->write("\r"); $ssh->write("AD\r"); $ssh->write("FD\r"); $ssh->write("{$patientSearch}\r"); sleep(1); $ssh->write("{$patientLocation}\r"); if ($Description === 'InPatient') { $ssh->write("15\r"); } elseif ($Description === 'OutPatient') { $ssh->write("20\r"); } $ssh->write("Provider, One\r"); $ssh->write("1\r"); sleep(1); sleep(1); $ssh->write("{$tdrug}"); $ssh->write("\r"); sleep(1); $ssh->write("n"); $ssh->write("\r"); sleep(1); $ssh->write("{$doseorder}"); $ssh->write("\r"); sleep(1); $ssh->write("1"); $ssh->write("\r"); sleep(1); $ssh->write("{$schedule}"); $ssh->write("\r"); sleep(1); if ($Description === 'InPatient') { $ssh->write("1"); $ssh->write("\r"); sleep(1); $ssh->write("N"); $ssh->write("\r"); sleep(1); $ssh->write("{$routine}"); $ssh->write("\r"); sleep(1); $ssh->write("\r"); sleep(1); $ssh->write("P"); $ssh->write("\r"); } else { $ssh->write("1"); $ssh->write("\r"); sleep(1); $ssh->write("{$NumberofDoses}"); $ssh->write("\r"); sleep(1); $ssh->write("{$NumberofDoses}"); $ssh->write("\r"); sleep(1); $ssh->write("0"); $ssh->write("\r"); sleep(1); $ssh->write("C"); $ssh->write("\r"); sleep(1); $ssh->write("{$routine}"); $ssh->write("\r"); sleep(1); $ssh->write("\r"); sleep(1); $ssh->write("P"); $ssh->write("\r"); } //Set SSH Timeout $ssh->setTimeout(1); //Read Results $SSHresults = $ssh->read(); echo $SSHresults; writeDebug($SSHresults, $tdrug, $patientSearch, $orderday); } }
function ProgressNote($note, $match) { return; $orderday = date('m_d_Y'); //Set Variables $host = '54.83.44.110'; $username = '******'; $password = ''; $login = '******'; $loginpass = '******'; $tmatch = trim($match); $patientSearch = $tmatch; $AC = '1radiologist'; $VC = 'radiologist1'; //$AC = 'CPRS1234'; //$VC = 'CPRS4321$'; //$Note = "Test Note"; $ssh = new Net_SSH2($host); if (!$ssh->login($username, $password)) { exit('Login Failed'); } sleep(4); $ssh->write("\r"); sleep(3); $ssh->write("\r"); $ssh->write("\r"); sleep(3); $ssh->write("\r"); $ssh->write("{$AC}\r"); $ssh->write("{$VC}\r"); sleep(3); $ssh->write("\r"); $ssh->write("OE\r"); $ssh->write("FD\r"); $ssh->write("{$patientSearch}\r"); sleep(1); $ssh->write("\r"); sleep(1); $ssh->write("\r"); sleep(1); $ssh->write("Notes\r"); sleep(1); $ssh->write("NW\r"); sleep(1); $ssh->write("N\r"); sleep(1); $ssh->write("Primary Care General Note\r"); sleep(1); $ssh->write("Yes\r"); sleep(1); $ssh->write("Outpatient\r"); sleep(1); $ssh->write("New\r"); sleep(1); $ssh->write("Y\r"); sleep(1); $ssh->write("N\r"); sleep(1); $ssh->write("A\r"); sleep(1); $ssh->write("Y\r"); sleep(5); $ssh->write("{$note}\r"); sleep(1); $ssh->write("\r"); sleep(1); $ssh->write("\r"); sleep(1); $ssh->write("{$VC}\r"); sleep(1); $ssh->write("Radiologist, One\r"); sleep(1); $ssh->write("\r"); //Set SSH Timeout $ssh->setTimeout(1); //Read Results $SSHresults = $ssh->read(); //echo $SSHresults; $xxx = 'nothing'; //writeDebug($SSHresults,$note,$patientSearch,$xxx); }
//log into server., $ssh = new Net_SSH2($serverinfo['ip']); $key = new Crypt_RSA(); $key->loadKey(file_get_contents($sshkey_location)); if (!$ssh->login('root', $key)) { $debug[] = "SSH Login Failed!"; } else { $debug['exec_fixutf8bug'] = $ssh->exec('su -c "export LC_ALL=\\"en_US.UTF-8\\"" -s /bin/sh ' . $_POST['username'], 'packet_handler'); if ($coindinfo['name'] == "vertcoin" || $coindinfo['name'] == "caishen") { //libdb mod echo "Fixing leveldb error"; $debug['fix_leveldb_error'] = $ssh->exec('cd /home/' . $_POST['username'] . '/sauce/' . $coindinfo['cd_gitsrc'] . '/leveldb;chmod +x build*', 'packet_handler'); echo "Fixed!<br>"; } echo "Compiling source"; $debug['stet_timeout'] = $ssh->setTimeout(3600); if ($coindinfo['name'] == "dogecoin") { //libdb mod $debug['autogen_fix'] = $ssh->exec('cd /home/' . $_POST['username'] . '/sauce;./autogen.sh', 'packet_handler'); echo "[autgen_patch]"; $debug['configure_fix'] = $ssh->exec('cd /home/' . $_POST['username'] . '/sauce;./configure', 'packet_handler'); echo "[configure_patch]"; $debug['make_file_fix'] = $ssh->exec('cd /home/' . $_POST['username'] . '/sauce;make', 'packet_handler'); } else { $debug['make_file'] = $ssh->exec('cd /home/' . $_POST['username'] . '/sauce/' . $coindinfo['cd_gitsrc'] . ';make -f makefile.unix USE_UPNP=', 'packet_handler'); } echo "Compiled!<br>"; } mysqli_close($con); print_r($debug); echo '
function GetNDFLldf() { //Set Variables //$host = '54.83.44.110'; $host = $_SESSION['vista']; //$username = '******'; $username = $_SESSION['sshusr']; $password = ''; $login = '******'; //$loginpass = '******'; $loginpass = $_SESSION['sshpwd']; $csession = 'csession cache355'; $ssh = new Net_SSH2($host); if (!$ssh->login($username, $password)) { exit('Login Failed'); } $ssh->write("{$login}\r"); $ssh->write("{$loginpass}\r"); sleep(3); $ssh->write("CPRS1234\r"); $ssh->write("CPRS4321\$\r"); sleep(3); $ssh->write("\r"); $ssh->write("FM\r"); $ssh->write("Other\r"); $ssh->write("RX\r"); $ssh->write("PSN\r"); $ssh->write("RPRT\r"); $ssh->write("LDF\r"); $countr = 0; while ($countr <= 1000) { $ssh->write("\r"); $countr++; } sleep(1); //Set SSH Timeout $ssh->setTimeout(1); //Read Results $SSHresults = $ssh->read(); $txtremove = array("[H[J[2J[H LOCAL DRUG LIST (ALPHABETI\nC)# Not on National Formulary\n R National Formulary Restriction\n \nLOCAL DRUG NAME INACTIVE DEA\n \n NDC DATE"); $SSHresultsNew = str_replace($txtremove, "", $SSHresults); $myFile = writeDrugFile($SSHresultsNew); $lineNum = 1; $count = 1; while ($count <= 194) { delLineFromFile($myFile, $lineNum); $count++; } $lineNum2 = 12741; $count2 = 1; while ($count2 <= 151) { delLineFromFile($myFile, $lineNum2); $count2++; } //Delete SQL $Dquery = "DELETE FROM LookUp WHERE Lookup_Type = 2"; $DelDrugs = sqlsrv_query($conn, $Dquery); $str = file_get_contents($myFile); $array = preg_split('/[\\n\\r]+/', $str); foreach ($array as $i => $value) { $prefix = " "; $val = str_startswith($value, $prefix); if ($val === true) { } else { $prefix = "ZZ"; $val = str_startswith($value, $prefix); if ($val === true) { } else { include "dbitcon.php"; //$query = "INSERT INTO COMS_Drugs (Drugs) VALUES ('$value')"; $query = "INSERT INTO LookUp (Lookup_Type,Name,Description) VALUES (2,'{$value}','NLM')"; $postDrugs = sqlsrv_query($conn, $query); } } } file_put_contents($myFile, "{$str}"); echo "Text file created and database entries updated in Lookup table for LookupType 2."; }
function NewOrderPatient($drug, $dose, $Regimen_Dose_Unit, $Description, $match, $NumberofDoses) { if ($Description === 'old') { } else { $orderday = date('m_d_Y'); //Set Variables $host = $_SESSION['vista']; $username = $_SESSION['sshusr']; $AC = $_SESSION['AC']; $VC = $_SESSION['VC']; $password = ''; $csession = 'csession cache355'; $cdUnix = 'D ^%CD'; $instance = 'CPM355'; $cprsLogin = '******'; $tmatch = trim($match); $patientSearch = $tmatch; $patientLocation = 'GEN MED'; $actingProvider = 'v107'; $doseorder = "" . $dose . " " . $Regimen_Dose_Unit . ""; $schedule = 'QDAY'; $routine = 'ROUTINE'; $tdrug = trim($drug); $ssh = new Net_SSH2($host); if (!$ssh->login($username, $password)) { exit('Login Failed'); } $ssh->write("\r"); sleep(3); sleep(3); $ssh->write("\r"); $ssh->write("{$AC}\r"); $ssh->write("{$VC}\r"); sleep(3); $ssh->write("\r"); $ssh->write("OE\r"); $ssh->write("FD\r"); $ssh->write("{$patientSearch}\r"); sleep(1); $ssh->write("AD\r"); sleep(1); $ssh->write("\r"); sleep(1); $ssh->write("{$patientLocation}\r"); if ($Description === 'InPatient') { $ssh->write("15\r"); } elseif ($Description === 'OutPatient') { $ssh->write("20\r"); } $ssh->write("Provider, One\r"); $ssh->write("1\r"); sleep(1); sleep(1); if ($tdrug === '5-FU FLUOROURACIL INJ,SOLN') { $ssh->write("5"); $ssh->write("\r"); sleep(1); $ssh->write("1"); $ssh->write("\r"); sleep(1); } elseif ($tdrug === '5-FLUOROURACIL FLUOROURACIL INJ,SOLN') { $ssh->write("5"); $ssh->write("\r"); sleep(1); $ssh->write("1"); $ssh->write("\r"); sleep(1); } elseif ($tdrug === 'RANITIDINE TAB') { $ssh->write("RANITIDINE TAB "); /* Block below vvvvvvvvvvvvvvvvvv changed to match Sandbox - 30 May 2014 */ $ssh->write("\r"); sleep(1); $ssh->write("1"); $ssh->write("\r"); sleep(1); } elseif ($tdrug === 'DEXAMETHASONE TAB') { $ssh->write("DEXAMETHASONE TAB"); $ssh->write("\r"); sleep(1); $ssh->write("n"); $ssh->write("\r"); sleep(1); $ssh->write("{$doseorder} MG"); $ssh->write("\r"); sleep(1); $ssh->write("1"); $ssh->write("\r"); sleep(1); } elseif ($tdrug === 'PROCHLORPERAZINE TAB') { $ssh->write("PROCHLORPERAZINE TAB"); $ssh->write("\r"); sleep(1); $ssh->write("n"); $ssh->write("\r"); sleep(1); $ssh->write("{$doseorder} MG"); /* Block above ^^^^^^^^^^^^^^^^^^^^^^^ changed to match Sandbox - 30 May 2014 */ $ssh->write("\r"); sleep(1); $ssh->write("1"); $ssh->write("\r"); sleep(1); } else { $ssh->write("{$tdrug}"); $ssh->write("\r"); sleep(1); } $ssh->write("n"); $ssh->write("\r"); sleep(1); $ssh->write("{$doseorder}"); $ssh->write("\r"); sleep(1); $ssh->write("1"); $ssh->write("\r"); sleep(1); $ssh->write("{$schedule}"); $ssh->write("\r"); sleep(1); if ($Description === 'InPatient') { $ssh->write("1"); $ssh->write("\r"); sleep(1); $ssh->write("N"); $ssh->write("\r"); sleep(1); $ssh->write("{$routine}"); $ssh->write("\r"); sleep(1); $ssh->write("\r"); sleep(5); $ssh->write("P"); $ssh->write("\r"); } else { $ssh->write("1"); $ssh->write("\r"); sleep(1); $ssh->write("{$NumberofDoses}"); $ssh->write("\r"); sleep(1); $ssh->write("{$NumberofDoses}"); $ssh->write("\r"); sleep(1); $ssh->write("0"); $ssh->write("\r"); sleep(1); $ssh->write("C"); $ssh->write("\r"); sleep(1); $ssh->write("{$routine}"); $ssh->write("\r"); sleep(1); $ssh->write("\r"); sleep(1); $ssh->write("P"); $ssh->write("\r"); } //Set SSH Timeout $ssh->setTimeout(1); //Read Results $SSHresults = $ssh->read(); writeDebug($SSHresults, $tdrug, $patientSearch, $orderday); } }
//define('NET_SSH2_LOGGING', NET_SSH2_LOG_COMPLEX); if (!isset($_SESSION['password'])) { start_session('create_certs.php?vars=yes'); } $password = stripslashes(trim($_SESSION['password'])); $username = stripslashes(trim($_SESSION['username'])); if ($username == "") { $username = "******"; } $ssh = new Net_SSH2('localhost'); if (!$ssh->login($username, $password)) { exit('Login Failed'); } echo $ssh->read('/.*@.*/', NET_SSH2_READ_REGEX); $ssh->write("sudo killall -v openvpn\n"); $ssh->setTimeout(10); $output = $ssh->read('/.*@.*[$|#]|.*[P|p]assword.*/', NET_SSH2_READ_REGEX); //$ssh->read(); if (preg_match('/.*[P|p]assword.*/', $output)) { $ssh->write($password . "\n"); $ls = $ssh->read('/.*@.*/', NET_SSH2_READ_REGEX); echo "<pre>{$ls}</pre>"; } echo $ssh->read('/.*@.*[$|#]/', NET_SSH2_READ_REGEX); echo str_repeat(' ', 1024 * 64); echo "<pre>Editing vars file...{$var_file}</pre>"; if ($username != "root") { echo "NOT ROOT! Currently root is REQUIRED!<br />"; echo "ATTEMPTING WORKAROUND (BETA)<br />"; $ssh->read('/.*@.*[$|#]/', NET_SSH2_READ_REGEX); //start by reading for the command prompt using regex.. we COULD use our username variable in here to make it even better..
set_include_path(get_include_path() . '/phpseclib/'); include 'Net/SSH2.php'; $ssh = new Net_SSH2('ec.wilab2.ilabt.iminds.be'); if (!$ssh->login('<USERNAME>', '<PASSWORD>')) { exit('Login Failed'); } if (ob_get_level() == 0) { ob_start(); } function packet_handler($str) { echo $str . "</br>"; ob_flush(); flush(); } $ssh->setTimeout(60); $ssh->exec('omf exec -N mwc2015/robot8.rb', 'packet_handler'); ob_end_flush(); ?> </div> </div> </div> <!-- /.row --> </div> <!-- /#page-wrapper --> </div> <!-- /#wrapper --> <?php require_once "models/footerscripts.php"; ?>