write() public method

Inputs a command into an interactive shell.
See also: self::read()
public write ( string $cmd ) : boolean
$cmd string
return boolean
示例#1
1
 /**
  * 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;
 }
示例#2
0
    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
    }
示例#3
0
文件: VCFDrugs.php 项目: bciv/COMS
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("                                                      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.";
}
示例#4
0
 /**
  *  Write a config snippet to to a device using SSH
  */
 public function writeSnippetSSH($snippetArr, $prompt)
 {
     $log = ADLog::getInstance();
     if (!($ssh = new Net_SSH2($this->_hostname, 22, $this->_timeout))) {
         $output = "Failure: Unable to connect to {$this->_hostname}\n";
         $log->Conn("Failure: Unable to connect to " . $this->_hostname . " - (File: " . $_SERVER['PHP_SELF'] . ")");
         return false;
     }
     if (!$ssh->login($this->_username, $this->_password)) {
         $output = "Error: Authentication Failed for {$this->_hostname}\n";
         $log->Conn("Error: Authentication Failed for {$this->_hostname} (File: " . $_SERVER['PHP_SELF'] . ")");
         return false;
     }
     $output = '';
     if ($this->_enableMode === 'on') {
         // $ssh->write("\n"); // 1st linebreak after above prompt check
         $ssh->read('/.*>/', NET_SSH2_READ_REGEX);
         // read out to '>'
         $ssh->write("enable\n");
         $ssh->read('/.*:/', NET_SSH2_READ_REGEX);
         $ssh->write($this->_enableModePassword . "\n");
         $ssh->read('/' . $prompt . '/', NET_SSH2_READ_REGEX);
         foreach ($snippetArr as $key => $command) {
             $ssh->write($command . "\n");
             $output .= $ssh->read('/.*#/', NET_SSH2_READ_REGEX);
             // read out to '#'
         }
         $ssh->write("\n");
         // to line break after command output
         $ssh->read('/' . $prompt . '/', NET_SSH2_READ_REGEX);
     } else {
         // $ssh->write("\n"); // 1st linebreak after above prompt check
         $ssh->read('/' . $prompt . '/', NET_SSH2_READ_REGEX);
         foreach ($snippetArr as $key => $command) {
             $ssh->write($command . "\n");
             $output .= $ssh->read('/.*#/', NET_SSH2_READ_REGEX);
             // read out to '#' because the prompt will change depending on the deployed config
         }
         $ssh->write("\n");
         // to line break after command output
         $ssh->read('/' . $prompt . '/', NET_SSH2_READ_REGEX);
     }
     $ssh->disconnect();
     return $output;
 }
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;
    }
}
示例#6
0
    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
$ssh->write("python SpOpt.py tests/" . $session . "/input.txt\n");
//start timerin case anything gets stuck, will break within 120 minutes (7200 sec)
$starttime = time();
//ssh will break within 120 minutes (7200 sec) regardless of execution status
while ($ssh->isConnected()) {
    $now = time() - $starttime;
    if ($now > 7200) {
        break;
    }
    sleep(3);
    //retrieve all solutions/discarded from cr2g and store in local
    $sftp->get($remoteSolutionsFile, $localSolutionsFile);
 $username = stripslashes(trim($_SESSION['username']));
 if ($username == "") {
     $username = "******";
 }
 $ssh = new Net_SSH2('localhost');
 if (!$ssh->login($username, $password)) {
     exit('Login Failed');
 }
 echo "<font color='B22222'>Error!</font> OPENSSL.CNF not found... required, should have been copied in with PKITOOL, searching... <br /><br />";
 //Checking SSl version to see which one is installed, then try and match that to a CNF file (usually they have 1.0.1 or something in the cnf filename)
 echo "<pre>Running openssl version</pre>";
 echo str_repeat(' ', 1024 * 64);
 //purge buffer
 $ssh->read('/.*@.*[$|#]/', NET_SSH2_READ_REGEX);
 //Finding installed openssl version
 $ssh->write("openssl version\n");
 $ssh->setTimeout(10);
 $output = $ssh->read('/.*@.*[$|#]/', NET_SSH2_READ_REGEX);
 echo $output;
 echo "<br />";
 echo str_repeat(' ', 1024 * 64);
 //purge buffer
 //Looking for openssl version files
 $pattern = "/([0-9]+\\.+[0-9]+\\.+[0-9]+)/";
 if ($c = preg_match($pattern, $output, $matches)) {
     echo "<pre> Version Found: {$matches['0']} </pre><br />";
 } else {
     echo "No openssl version found? May need openssl installed!<br />";
 }
 echo str_repeat(' ', 1024 * 64);
 //now find the cnf file to match the version
示例#8
0
    $server = $users[$userNumber]['server'];
    $password = $userInput;
    $ssh = new Net_SSH2($server);
    if (!$ssh->login($username, $userInput)) {
        $users[$userNumber]['status'] == 2;
        echo 'Login failed.  Please reply with username.';
        exit;
    } else {
        //echo($ssh->read($username . '@' . $server . ':~$'));
        echo 'Connection successful.  Reply with command.';
        exit;
    }
} elseif ($users[$userNumber]['status'] == 4) {
    $username = $users[$userNumber]['username'];
    $server = $users[$userNumber]['server'];
    $password = $userInput;
    $ssh = new Net_SSH2($server);
    if (!$ssh->login($username, $userInput)) {
        $users[$userNumber]['status'] == 2;
        echo 'Login failed.  Please reply with username.';
        exit;
    }
    $ssh->write($userInput . "\n");
} else {
    echo 'You have not yet initiated your SSH connection.  Reply \'ssh\' to begin.';
    exit;
}
?>
        </Message>
    </Response>
示例#9
0
文件: VCFOrder.php 项目: bciv/COMS
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);
    }
}
示例#10
0
     $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 = "Ubuntu 15.04";
     $os_bit = "64";
 } else {
     msg_error('Something went wrong, Invalid OS');
     exit;
 }
 $ssh->exec('sudo useradd -m -d /home/' . $user . ' -s /bin/bash ' . $user);
 $ssh->enablePTY();
 $ssh->exec('sudo passwd ' . $user);
 if ($language == "English") {
     $ssh->read('Enter new UNIX password:'******'Retype new UNIX password:'******'passwd: password updated successfully');
 } elseif ($language == "Deutsch") {
     $ssh->read('Geben Sie ein neues UNIX-Passwort ein:');
     $ssh->write($password . "\n");
     $ssh->read('Geben Sie das neue UNIX-Passwort erneut ein:');
     $ssh->write($password . "\n");
     $ssh->read('passwd: Passwort erfolgreich geändert');
 }
 $ssh->disablePTY();
 $ssh->read('[prompt]');
 $ssh->exec("usermod -a -G sudo " . $user);
 $ssh->exec('echo "%sudo ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers');
 $ssh->exec('echo "' . $vsftpd . '" >> /etc/vsftpd.conf');
<?php

include 'phpsec/Net/SSH2.php';
set_include_path(implode(PATH_SEPARATOR, array(get_include_path(), \PFC\Editor\LIBRARY_PATH . '/phpsec')));
$ssh = new Net_SSH2('www.kena23.cz');
if (!$ssh->login('', '')) {
    exit('Login Failed');
}
//echo $ssh->exec('mkdir test');
$ssh->write("mkdir test\n");
$ssh->write("ls -la\n");
echo $ssh->read('username@username:~$');
echo '<hr>';
$ssh->write("rm -r -i test\n");
echo $ssh->read('username@username:~$');
echo '<hr>';
$ssh->write("y\n");
echo $ssh->read('username@username:~$');
echo '<hr>';
echo $ssh->exec('ls -la');
//echo $ssh->exec('pwd');
//echo $ssh->exec('ls -la');
//echo $ssh->exec('pwd'); // outputs /home/username
//$ssh->exec('cd /var/www');
//echo $ssh->exec('pwd'); // (despite the previous command) outputs /home/username
//$ssh->write("ls -la\n");
//$ssh->write("clear\n"); // note the "\n"
//$ssh->write("ls -la\n"); // note the "\n"
//$ssh->write("clear\n"); // note the "\n"
//$ssh->reset();
//echo $ssh->read('username@username:~$');
示例#12
0
</head>
<?php 
$var_file = "/etc/openvpn/easy-rsa/2.0/vars";
$key_dir = "/etc/openvpn/easy-rsa/2.0/keys";
$key_country = "EN";
$key_province = "TEST2";
$var_dir = "/etc/openvpn/easy-rsa/2.0/";
$password = "******";
$ssh = new Net_SSH2('localhost');
if (!$ssh->login('root', 'RHB12+ADMIN')) {
    exit('Login Failed');
}
echo "<h2>Check for errors, then continue to <a href='index.php'>Home</a></h2>";
$num_keys = 0;
//need to export list of files so we can extract key names.
$ssh->write("ls {$key_dir} > key_list.txt\n");
$ssh->read('/.*@.*[$|#]/', NET_SSH2_READ_REGEX);
//list should now be stored in curr_work_dir, php will read, extract key names.
$key_filename = "key_list.txt";
//$contents = file($key_filename);
//$string = implode($contents);
//echo $string;
echo "<br />";
echo "<br />";
echo "<br />";
echo "<br />";
echo "<br />";
echo "<br />";
echo "<br />";
$key_dir_files = file($key_filename, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
//Counting the keys in the keydir
示例#13
0
文件: WPN.php 项目: bciv/COMS
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);
}
 //editing var file using sed
 //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);
示例#15
0
文件: NWPatient.php 项目: bciv/COMS
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);
    }
}
示例#16
0
<?php

$output = shell_exec('sh PATCH_SUPEE-6788_CE_1.9.1.0_v1-2015-10-27-09-06-11.sh');
echo "<pre>{$output}</pre>";
exit;
include 'Crypt/RSA.php';
include 'Net/SSH2.php';
try {
    $key = new Crypt_RSA();
    //$key->setPassword('whatever');
    $key->loadKey(file_get_contents('id_rsa.ppk'));
    $ssh = new Net_SSH2('ftp.narayansoft.com');
    if (!$ssh->login('username', $key)) {
        exit('Login Failed');
    }
} catch (Exception $e) {
    echo 'Caught exception: ', $e->getMessage(), "\n";
}
exit;
echo $ssh->read('username@username:~$');
$ssh->write("ls -la\n");
echo $ssh->read('username@username:~$');
示例#17
0
 $stmt->bind_result($user_name, $user_u_count);
 $stmt->fetch();
 $stmt->close();
 $gs_login = $user_name . "-" . $user_u_count;
 $gs_password = generatePassword();
 $ssh = new Net_SSH2($dedi_ip, $dedi_port);
 if (!$ssh->login($dedi_login, $dedi_password)) {
     msg_error("Login failed");
     exit;
 } else {
     $ssh->exec('sudo useradd -m -d /home/' . $gs_login . ' -s /bin/bash ' . $gs_login);
     $ssh->enablePTY();
     $ssh->exec('sudo passwd ' . $gs_login);
     if ($dedi_language == "Deutsch") {
         $ssh->read('Geben Sie ein neues UNIX-Passwort ein:');
         $ssh->write($gs_password . "\n");
         $ssh->read('Geben Sie das neue UNIX-Passwort erneut ein:');
         $ssh->write($gs_password . "\n");
         $ssh->read('passwd: Passwort erfolgreich geändert');
     } elseif ($dedi_language == "Englisch") {
         $ssh->read('Enter new UNIX password:'******'Retype new UNIX password:'******'passwd: password updated successfully');
     }
     $ssh->disablePTY();
     $ssh->read('[prompt]');
     $copy = "screen -amds cp" . $gs_login . " bash -c 'sudo cp -R /home/" . $dedi_login . "/templates/" . $type . "/* /home/" . $gs_login . ";sudo cp -R /home/" . $dedi_login . "/templates/" . $type . "/linux32/libstdc++.so.6 /home/" . $gs_login . "/game/bin;sudo chown -R " . $gs_login . ":" . $gs_login . " /home/" . $gs_login . ";chmod a-w /home/" . $gs_login . ";sudo rm /home/" . $gs_login . "/screenlog.0;'";
     $ssh->exec($copy);
     $version = 0;