コード例 #1
0
ファイル: amazon.php プロジェクト: myvirtualteams/samplecode
 /**
  * @param  [type] $first_arr  see run_everything_amazon function in 'ssh' custom class
  * @return [type]             [description]
  */
 function send_ssh_request($Net_SSH2Ob, $first_arr, $type, $other = array())
 {
     $sshOb = new ssh($Net_SSH2Ob);
     if ($Net_SSH2Ob->isConnected()) {
         $ssh_result = $sshOb->run_everything_amazon($first_arr, $type, $other);
         if ($ssh_result == 1) {
             return 1;
         } else {
             return 0;
         }
     }
 }
コード例 #2
0
ファイル: auth.php プロジェクト: sgchris/grunssh
 /**
  * check connection
  */
 public function test()
 {
     // check POST
     if ($this->input->server('REQUEST_METHOD', false) != 'POST') {
         echo json_encode(array('result' => 'error', 'error' => 'the action requires POST request'));
         return;
     }
     // check parameters
     $params = $this->input->post();
     if (empty($params) || !isset($params['host']) || !isset($params['login']) || !isset($params['password'])) {
         echo json_encode(array('result' => 'error', 'error' => 'no `host`, `login` or `password` parameter'));
     } elseif ($params['host'] && $params['login'] && $params['password']) {
         // create the connection
         $ssh = new ssh($params['host'], $params['login'], $params['password']);
         if ($ssh->connect() === false) {
             echo json_encode(array('result' => 'error', 'error' => 'cannot connect'));
         } else {
             echo json_encode(array('result' => 'success'));
         }
     }
 }
コード例 #3
0
ファイル: server.php プロジェクト: kyroskoh/rokket
 protected function control($type)
 {
     $id = $this->id;
     $SSH = rp::get('SSH');
     $host = $SSH['ip'];
     $user = $SSH['user'];
     $pass = $SSH['password'];
     unset($SSH);
     $ssh = new ssh($host, $user, $pass);
     $sql = new sql();
     $sql->setTable('server');
     $sql->setWhere('id=' . $id);
     #$ssh->read('[prompt]');
     switch ($type) {
         case 'install':
             $ssh->exec("cd {$id}; ./control.sh auto-install  > /dev/null &");
             $sql->addPost('status', 0);
             break;
         case 'start':
             $ssh->exec("cd {$id}; ./control.sh start >> /dev/null 2>&1 & /n");
             $sql->addPost('status', 1);
             break;
         case 'stop':
             $ssh->exec("cd {$id}; ./control.sh stop >> /dev/null 2>&1 & /n");
             $sql->addPost('status', 0);
             break;
         case 'restart':
             $ssh->exec("cd {$id}; ./control.sh restart >> /dev/null 2>&1 & /n");
             $sql->addPost('status', 1);
             break;
     }
     $sql->update();
 }
コード例 #4
0
ファイル: console.php プロジェクト: DINKIN/rokket
<div class="panel">
	<div class="content">
        <div id="terminal">
            <?php 
$SSH = rp::get('SSH');
$host = $SSH['ip'];
$user = $SSH['user'];
$pass = $SSH['password'];
unset($SSH);
$ssh = new ssh($host, $user, $pass);
if (ajax::is()) {
    $test = 1;
} else {
    echo nl2br($ssh->read('/.*@.*[$|#]/', NET_SSH2_READ_REGEX));
    $ssh->write("screen -r test123 \n\r");
    $ssh->setTimeout(4);
    $ssh->write("ping google.de \n\r");
}
if (ajax::is()) {
    #$ssh->setTimeout(1);
    #$ssh->write("ping google.de \n\r");
    $ssh->setTimeout(4);
    $ssh->exec("screen -r test123");
    #$return = nl2br($ssh->read('/.*@.*[$|#]/', NET_SSH2_READ_REGEX));
    ajax::addReturn($return);
}
?>
        </div>
    </div>
</div>
コード例 #5
0
ファイル: files.php プロジェクト: sgchris/grunssh
 /**
  * @brief create new folder
  * @method POST
  * 	 * grep -r -i -B 2 -A 1 "n Search" --include \*php /var/www/grunssh
  * @return  
  */
 public function search()
 {
     $params = $this->input->post();
     if (empty($params) || !isset($params['id']) || empty($params['id']) || !isset($params['term']) || empty($params['term']) || !isset($params['host']) || empty($params['host']) || !isset($params['login']) || empty($params['login']) || !isset($params['password']) || empty($params['password'])) {
         echo json_encode(array('result' => 'error', 'error' => 'missing parameters'));
         return;
     }
     $fileNamesOnly = isset($params['onlyFiles']) && $params['onlyFiles'] == 1;
     // connect to remote host
     $ssh = new ssh($params['host'], $params['login'], $params['password']);
     $folderPath = str_replace('_SEP_', '/', $params['id']);
     $term = $params['term'];
     $commandParams = '';
     if ($fileNamesOnly) {
         $commandParams .= ' -l ';
     }
     $result = $ssh->exec('grep -r ' . $commandParams . ' ' . escapeshellarg($term) . ' ' . escapeshellarg($folderPath));
     $totalResults = substr_count($result, "\n");
     if ($result === false) {
         echo json_encode(array('result' => 'error', 'error' => 'cannot create folder'));
         return;
     }
     // get list of results
     $results = explode("\n", $result);
     // clear empty lines
     $results = array_filter($results, 'strlen');
     // keep files with path (starting with "/")
     $results = array_filter($results, function ($el) {
         return preg_match('%^/%', $el);
     });
     // rearrange the array
     $results = array_values($results);
     echo json_encode(array('result' => 'success', 'occurrences' => $results));
 }
コード例 #6
0
ファイル: example.php プロジェクト: sgchris/ssh
<?php

/**
 * Simple script for backup MySQL database on remote server
 */
include "ssh.class.php";
$server_host = "ssh.example.com";
$server_login = "******";
$server_password = "******";
// Didn't use simple passwords
$mysql_user = "******";
$mysql_password = "******";
// Didn't use simple passwords
$mysql_database = "base";
// Connect:
$ssh = new ssh($server_host, $server_login, $server_password);
// Make backup:
$ssh("mysqldump -u {$mysql_user} -p{$mysql_password} {$mysql_database} > /tmp/bases", "gzip -9 /tmp/bases");
// Download backup:
$ssh->download("/tmp/bases.gz", "/my/backups/dir/bases.gz");
// Delete backup on server
$ssh("rm /tmp/bases.gz");
コード例 #7
0
function doUpload()
{
    global $upload_settings_file, $datenow, $total_pids_taken_per_run, $class_ju, $class_jc, $jng_sp_id, $jng_sp_name, $image_uploaded_file, $xml_filepath, $xml_filename, $xml_filename_marker, $xml_filename_temp, $zip_final, $zip_filename, $zip_filename_marker, $start, $pid_file_processed, $timestamp, $process_runned;
    $success = false;
    $messages_success = 'CAT XML File is created on "temp"<br/>';
    //INITIALIZE FTP SETTINGS AND PATHS
    use_class('ssh');
    $ftp_server = SP_NECKERMANN_CAT_FTP_HOST;
    $ftp_user_name = SP_NECKERMANN_CAT_FTP_USER;
    $ftp_user_pass = SP_NECKERMANN_CAT_FTP_PASSWORD;
    $ftp_file_path = 'out/';
    $ssh = new ssh($ftp_server, $ftp_user_name, $ftp_user_pass);
    if ($ssh->sftp !== false) {
        //    if(true) { ##XXX  (FOR TESTING)
        if (file_exists($image_uploaded_file)) {
            $handle = fopen($image_uploaded_file, "r+");
            $im_contents = fread($handle, filesize($image_uploaded_file));
            $upload_image_log = $im_contents != '' ? explode(',', $im_contents) : array();
            fclose($handle);
        }
        $upload_img_zip = count($upload_image_log) > 0;
        //MOVE XML MEDIA FILE FROM TEMP TO UPLOAD FOLDER ON SERVER
        if (file_exists($xml_filename_temp)) {
            //CREATE BACKUP CAT XML
            $zip_xml_backup = "{$datenow}-{$xml_filename}.zip";
            $zip_xml_backup_filepath = SP_NECKERMANN_PATH . "cat-backup/{$zip_xml_backup}";
            $shell[] = 'cd ' . SP_NECKERMANN_TEMP_FOLDER;
            $shell[] = "zip  {$zip_xml_backup_filepath} {$xml_filename}";
            //add image file directly to single zip
            $output = shell_exec(implode("\n", $shell));
            /* FOR TESTING ON LOCAL
               $shell = '"C:\Program Files\WinRAR\WinRAR.exe" a '."$zip_xml_backup_filepath $xml_filename_temp";
               $output = exec($shell);
                */
            //PUT CAT XML FROM TEMP TO "products/out"
            $success = rename($xml_filename_temp, $xml_filepath);
            $messages_success .= 'CAT XML File is moved from "temp" to "products/out"<br/>';
        } else {
            sendMessageToAdmin("Function doUpload -> The CAT file is not found on {$xml_filename_temp}, please contact administrator.", true, true);
        }
        //        $success = true; ##XXX (FOR TESTING)
        if ($success) {
            $contents = $ssh->ssh2ListDirectory($ftp_file_path);
            if (is_array($contents) && count($contents) > 0) {
                if (in_array($xml_filename, $contents)) {
                    $ssh->ssh2Unlink($xml_filename);
                }
            }
            echo '. ';
            //templine
            if ($upload_img_zip) {
                $success_upload = $ssh->ssh2FileUpload($zip_final, $ftp_file_path . $zip_filename);
                echo '. ';
                //templine
                if ($success_upload) {
                    $uploaded_size = $ssh->ssh2FileSize($ftp_file_path . $zip_filename);
                    $local_size = filesize($zip_final);
                    if ($uploaded_size == $local_size) {
                        $messages_success .= 'Media (Image) File is uploaded to NM.DE<br/>';
                        $success_upload = $ssh->ssh2FileCreate($ftp_file_path . $zip_filename_marker);
                    } else {
                        $messages_error .= 'Media (Image) File Upload Failed<br/>';
                        $success_upload = false;
                    }
                }
                if (!$success_upload) {
                    $messages_error .= 'Function doUpload -> Image file Upload failed<br/>';
                }
            } else {
                $success_upload = true;
            }
            //$success_upload = $ssh->ssh2FileCreate($ftp_file_path.$xml_filename, $xml_content);
            echo '. ';
            //templine
            if ($success_upload) {
                $success_upload = $ssh->ssh2FileUpload($xml_filepath, $ftp_file_path . $xml_filename);
                if ($success_upload) {
                    $uploaded_size = $ssh->ssh2FileSize($ftp_file_path . $xml_filename);
                    $local_size = filesize($xml_filepath);
                    //var_dump('Local: '.$local_size); echo '<br />';
                    //var_dump('Remote: '.$uploaded_size);
                    if ($uploaded_size == $local_size) {
                        $messages_success .= 'CAT XML File is uploaded to NM.DE<br/>';
                        $success_upload = $ssh->ssh2FileCreate($ftp_file_path . $xml_filename_marker);
                    } else {
                        $messages_error .= 'Function doUpload -> CAT XML File Upload failed<br/>';
                        $success_upload = false;
                    }
                }
            }
            $success = $success_upload;
        } else {
            sendMessageToAdmin('Function doUpload -> Could not move CAT XML from "temp" to "products/out".', true, true);
        }
    } else {
        sendMessageToAdmin('Function doUpload -> ' . $jng_sp_name . ': Failed connecting to SFTP server', true, true);
    }
    if ($success) {
        $class_jc->updateLastActiveStatus($jng_sp_id);
        $class_jc->updateLastReportedStock($jng_sp_id);
        $upload_id = $class_ju->newUpload($jng_sp_id, 'CAT', $zip_xml_backup, 'auto');
        echo "<h1>UPLOAD ID {$upload_id}</h1>";
        if ($upload_img_zip) {
            $class_ju->addUploadType($upload_id, 'MEDIA', $zip_filename);
            foreach ($upload_image_log as $jcid) {
                $class_ju->addUploadImage($upload_id, $jcid);
            }
        }
        $products = array();
        $handle = fopen($pid_file_processed, 'r+');
        $fp_contents = fread($handle, filesize($pid_file_processed));
        $fp_temp = explode("\n", $fp_contents);
        if (is_array($fp_temp) && count($fp_temp) > 0) {
            $products = explode(',', $fp_temp[0]);
            fwrite($handle, $fp_temp[0] . "\nUPLOADED SUCCESSFULLY ON {$timestamp}");
        }
        fclose($handle);
        $messages_success .= "CAT UPLOAD DONE >> upload_id : {$upload_id}<br/>";
        $handle = fopen($upload_settings_file, 'r+');
        fwrite($handle, "{$total_pids_taken_per_run}\nDONE\n{$process_runned}");
        fclose($handle);
    }
    $time = microtime();
    $time = explode(' ', $time);
    $time = $time[1] + $time[0];
    $finish = $time;
    $total_time = round($finish - $start, 4);
    $messages_time = "<p style=\"color:#000;\">Processing time : {$total_time} seconds</p>";
    if ($messages_error != '') {
        $messages_error .= $messages_time;
        sendMessageToAdmin($messages_error, true, true);
    }
    if ($messages_success != '') {
        //SET UPLOAD STATUS TO SUCCESS 'S' ALSO SET IMAGE UPLOADED TO '1'
        if ($upload_id > 0) {
            $class_ju->updateStatus($upload_id, 'S', 'auto');
        }
        $messages_success .= $messages_time;
        $messages_success .= '<br/>Total Products Processed : ' . count($products) . ' Products';
        sendMessageToAdmin($messages_success, false);
    }
}
コード例 #8
0
     exit;
 }
 //XML CLOSER
 $xml_content .= writeXMLclose('NVAG_CATALOG', 0);
 //FINISH XML FILE CREATION
 $success = fwrite($file, $xml_content) !== false;
 fclose($file);
 if ($success) {
     $success = false;
     //initialize ftp settings and paths
     use_class('ssh');
     $ftp_server = SP_NECKERMANN_CAT_FTP_HOST;
     $ftp_user_name = SP_NECKERMANN_CAT_FTP_USER;
     $ftp_user_pass = SP_NECKERMANN_CAT_FTP_PASSWORD;
     $ftp_file_path = 'out/';
     $ssh = new ssh($ftp_server, $ftp_user_name, $ftp_user_pass);
     if ($ssh->sftp !== false) {
         $contents = $ssh->ssh2ListDirectory($ftp_file_path);
         if (is_array($contents) && count($contents) > 0) {
             if (in_array($xml_filename, $contents)) {
                 $ssh->ssh2Unlink($xml_filename);
             }
         }
         //echo '. ';  //templine
         $success_upload = $ssh->ssh2FileUpload($xml_filepath, $ftp_file_path . $xml_filename);
         if ($success_upload) {
             $uploaded_size = $ssh->ssh2FileSize($ftp_file_path . $xml_filename);
             $local_size = filesize($xml_filepath);
             //var_dump('Local: '.$local_size); echo '<br />';
             //var_dump('Remote: '.$uploaded_size);
             if ($uploaded_size == $local_size) {