本文整理汇总了PHP中Net_SSH2::read方法的典型用法代码示例。如果您正苦于以下问题:PHP Net_SSH2::read方法的具体用法?PHP Net_SSH2::read怎么用?PHP Net_SSH2::read使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Net_SSH2
的用法示例。
在下文中一共展示了Net_SSH2::read方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: Exec
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
}
示例2: while
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 {
echo "[]";
示例3: create_client_config_and_send
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 = "root";
}
$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 = "root";
}
$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;
}
}
示例4: exit
//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);
$sftp->get($remoteDiscardedFile, $localDiscardedFile);
//function to provide discarded solutions during session
示例5: chdir
chdir('..');
chdir('..');
$path = getcwd();
chdir('php/pear');
$path = getcwd();
set_include_path($path);
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)) {
$ansi = new File_ANSI();
$ssh->enablePTY();
$ssh->exec(' sar 1 1 | tail -1');
$ssh->setTimeout(2);
$var = $ssh->read();
$stripped = preg_replace(array('/\\s{2,}/', '/[\\t\\n]/'), ' ', $var);
$result = explode(' ', $stripped);
$idlecpu = $result[7];
$result = array(array("Free", $idlecpu), array('Used', 100 - $idlecpu));
$rows = array();
$table = array();
$table['cols'] = array(array('label' => 'BLKSIZE', 'type' => 'string'), array('label' => 'total blks', 'type' => 'number'));
foreach ($result as $r) {
$temp = array();
$temp[] = array('v' => (string) $r[0]);
$temp[] = array('v' => (double) $r[1]);
$rows[] = array('c' => $temp);
}
$table['rows'] = $rows;
echo $jsonTable = json_encode($table);
示例6: trim
if (!$ssh->login($connection["USER"], $connection["PASS"])) {
$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)) {
$ssh->enablePTY();
$fwCMD = "cat /http/default/_version.php | grep 'define' | grep 'PRODUCT_VERSION' | awk -F ',' '{print \$2}' | sed 's/[^[:alnum:]\\.[:space:]]\\+//g'";
$ssh->exec($fwCMD);
$ansi->appendString($ssh->read());
$response["cmdOutput"] = trim(htmlspecialchars_decode(strip_tags($ansi->getHistory())));
//echo "Running sql success cmdID: ".$connection["cmdID"]."\n$sql";
if ($db_CS->query($sql)) {
if ($connection["tDeviceFirmware"] != $response["cmdOutput"]) {
$sql = "UPDATE sshManagerQueue\n\t\t\t\t\t\t\tSET cmdOutput = 'FW updated from " . $connection["tDeviceFirmware"] . " to " . $response["cmdOutput"] . "',\n\t\t\t\t\t\t\t\tcmdTimestamp = UNIX_TIMESTAMP()\n\t\t\t\t\t\t\tWHERE memberID = '" . $connection["memberID"] . "'\n\t\t\t\t\t\t\t AND jobTemplateID = '" . $connection["jobTemplateID"] . "'\n\t\t\t\t\t\t\t AND cmdID = '" . $connection["cmdID"] . "'\n\t\t\t\t\t\t\t AND deviceID = '" . $connection["deviceID"] . "'";
$db_CS->query($sql);
$sql = "UPDATE DeviceList\n\t\t\t\t\t\t\tSET tDeviceFirmware = '" . $response["cmdOutput"] . "'\n\t\t\t\t\t\t\tWHERE id = '" . $connection["deviceID"] . "'";
if ($db_CS->query($sql) && $db_CS->affected_rows > 0) {
if (updateDeviceHistoryMember($connection["deviceID"], 'tDeviceFirmware', $connection["memberID"])) {
$db_CS->commit();
} else {
$db_CS->rollback();
}
}
} else {
示例7: ProgressNote
function ProgressNote($note, $match)
{
return;
$orderday = date('m_d_Y');
//Set Variables
$host = '54.83.44.110';
$username = 'vista';
$password = '';
$login = '1radiologist';
$loginpass = 'radiologist1';
$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);
}
示例8: stripslashes
//need to use bash commands to do this... permission issues.
//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 = "root";
}
$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 />";
示例9: elseif
$ssh->exec('apt-get -y install lib32gcc1');
$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:');
$ssh->write($password . "\n");
$ssh->read('Retype new UNIX password:');
$ssh->write($password . "\n");
$ssh->read('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');
示例10: fire
public function fire($job, $data)
{
$output = new Symfony\Component\Console\Output\ConsoleOutput();
$node = Node::find($data['message']['node_id']);
$s3 = \Aws\S3\S3Client::factory(array('key' => 'AKIAIUCV4E2L4HDCDOUA', 'secret' => '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', 'region' => 'us-east-1'));
$all_keys = Key::where('integration_id', '=', $data['message']['integration_id'])->get();
foreach ($all_keys as $pem_key_reference) {
if ($pem_key_reference->remote_url) {
$unique_key_name = rand(0, 9999) . $pem_key_reference->remote_url;
$key_bucket = App::isLocal() ? 'devkeys.nosprawl.software' : 'keys.nosprawl.software';
$s3->getObject(array('Bucket' => $key_bucket, 'Key' => $pem_key_reference->remote_url, 'SaveAs' => '/tmp/' . $unique_key_name));
// Shouldn't need these two lines at all.
exec('chmod 400 /tmp/' . $unique_key_name);
$empty = null;
$s3_resource_root = App::isLocal() ? 'http://agent.nosprawl.software/dev/' : 'http://agent.nosprawl.software/';
$latest_version = exec("curl -s " . $s3_resource_root . "latest", $empty);
$latest_version_url = $s3_resource_root . $latest_version;
$ssh = new Net_SSH2($node->public_dns_name);
$ssh->enableQuietMode();
$ssh->enablePTY();
$key = new Crypt_RSA();
$key->loadKey(file_get_contents('/tmp/' . $unique_key_name));
exec('rm -rf /tmp/' . $unique_key_name);
if (!$ssh->login($pem_key_reference->username, $key)) {
continue;
} else {
$possible_installers = ["yum", "apt-get"];
foreach ($possible_installers as $possible_installer) {
$installer_check_result = false;
$found = false;
$ssh->exec("sudo " . $possible_installer . " -y install ruby");
$install_result = $ssh->read();
$output->writeln($install_result);
$install_exit_status = $ssh->getExitStatus();
if ($install_exit_status == 0) {
Queue::push('DeployAgentToNode', array('message' => array('node_id' => $node->id, 'integration_id' => $node->integration->id)));
return $job->delete();
}
}
}
} else {
$output->writeln("This is what we do if all we have is a password.");
continue;
}
}
// If we got to this point we were unable to install Curl automatically.
$problem = new Problem();
$problem->description = "Couldn't install Curl.";
$problem->reason = "Unable to automatically install Curl. Please install it manually.";
$problem->node_id = $node->id;
$problem->save();
$remediation = new Remediation();
$remediation->name = "Retry Deployment";
$remediation->queue_name = "DeployAgentToNode";
$remediation->problem_id = $problem->id;
$remediation->save();
$remediation = new Remediation();
$remediation->name = "Cancel";
$remediation->queue_name = "CancelDeployAgentToNode";
$remediation->problem_id = $problem->id;
$remediation->save();
return $job->delete();
}
示例11: NewOrderPatient
//.........这里部分代码省略.........
$instance = 'CPM355';
$cprsLogin = 'S DUZ=1';
$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);
}
}
示例12: checkDeviceFW
public function checkDeviceFW($deviceID = false)
{
global $db_CS;
global $access;
global $allowedParams;
global $allowedGroupsDeviceList;
global $allowedGroupsArray;
$deviceID = isset($_REQUEST['deviceID']) ? htmlspecialchars($_REQUEST['deviceID']) : $deviceID;
$sql = "SELECT tLastAliveIP,tDeviceVPNName,tDeviceFirmware,tRootPwd FROM DeviceList WHERE id = '{$deviceID}'";
$db_CS->autocommit(FALSE);
$data["rstatus"] = false;
if ($rs = $db_CS->query($sql)) {
if ($connection = $rs->fetch_assoc()) {
set_include_path(get_include_path() . PATH_SEPARATOR . '/var/www/html/sacp/includes/phpseclib');
include 'Net/SSH2.php';
include 'File/ANSI.php';
$data["tDeviceVPNName"] = $connection["tDeviceVPNName"];
if (filter_var($connection["tLastAliveIP"], FILTER_VALIDATE_IP)) {
$ssh = new Net_SSH2($connection["tLastAliveIP"], '22');
if (!$ssh->login('root', $connection["tRootPwd"])) {
$host_connected = false;
$data["result"] = "Auth failed!";
$data["alert_type"] = "danger alert";
} else {
// WE GOT A CONNECTION !
$ansi = new File_ANSI();
$ssh->enablePTY();
$fwCMD = "cat /http/default/_version.php | grep 'define' | grep 'PRODUCT_VERSION' | awk -F ',' '{print \$2}' | sed 's/[^[:alnum:]\\.[:space:]]\\+//g'";
$ssh->exec($fwCMD);
$ansi->appendString($ssh->read());
$response["cmdOutput"] = htmlspecialchars_decode(strip_tags($ansi->getHistory()));
if ($connection["tDeviceFirmware"] != $response["cmdOutput"]) {
$sql = "UPDATE DeviceList\n\t\t\t\t\t\t\t\t\tSET tDeviceFirmware = '" . $response["cmdOutput"] . "'\n\t\t\t\t\t\t\t\t\tWHERE id = '{$deviceID}'";
if ($db_CS->query($sql) && $db_CS->affected_rows > 0) {
if ($this->updateDeviceHistoryMember($deviceID, 'tDeviceFirmware')) {
$db_CS->commit();
$data["rstatus"] = true;
$data["alert_type"] = "success alert";
$data["result"] = "FW updated from " . $connection["tDeviceFirmware"] . " to " . $response["cmdOutput"] . "";
} else {
$data["rstatus"] = true;
//$data["sql"] = $sql;
$data["alert_type"] = "danger alert";
$data["result"] = 'Ошибка сохранения или такого устройства не существует';
}
}
} else {
$data["rstatus"] = true;
$data["alert_type"] = "success alert";
$data["result"] = "FW is up to date! (Answer: " . addslashes($response["cmdOutput"]) . ")";
}
}
} else {
$data["result"] = "Wrong IP! (" . $connection["tLastAliveIP"] . ")";
}
header('Content-Type: application/json');
echo json_encode($data);
}
}
}
示例13: array
set_include_path(get_include_path() . '/' . 'phpsec');
include 'Net/SSH2.php';
include 'File/ANSI.php';
$rows = array();
$table = array();
$query = mysqli_query($connect, "SELECT distinct server ,sslusername,sslpassword FROM configureddb");
while ($query_row = mysqli_fetch_assoc($query)) {
$hostname = $query_row['server'];
$sslusername = $query_row['sslusername'];
$sslpassword = $query_row['sslpassword'];
$ssh = new Net_SSH2($hostname);
if (@$ssh->login($sslusername, $sslpassword)) {
$ansi = new File_ANSI();
$ssh->enablePTY();
$ssh->exec('free|grep -i "Mem" |tail -1');
$mem = $ssh->read();
$memstrip = preg_replace(array('/\\s{2,}/', '/[\\t\\n]/'), ' ', $mem);
$resultmem = explode(' ', $memstrip);
$totalmem = $resultmem[1];
$freemem = $resultmem[3];
$mem = $freemem / $totalmem * 100;
$result = array(array($hostname, $mem));
$table['cols'] = array(array('label' => 'MEMORY', 'type' => 'string'), array('label' => '% Free', 'type' => 'number'));
foreach ($result as $r) {
$temp = array();
$temp[] = array('v' => (string) $r[0]);
$temp[] = array('v' => (double) $r[1]);
$rows[] = array('c' => $temp);
}
}
}
示例14: writeSnippetSSH
/**
* 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;
}
示例15: NewOrderPatient
//.........这里部分代码省略.........
$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);
}
}