| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- <?php
- if (! defined('IS_INITPHP'))
- exit('Access Denied!');
- include 'ssh/Net/SSH2.php';
- /**
- * SSH登陆服务器操作
- *
- * @author Chen Deben
- * @copyright Meitu
- */
- class sshInit {
- public $ssh;
- /**
- * 登陆
- *
- * @param string $server
- * 服务器地址
- * @param string $username
- * 用户名
- * @param string $password
- * 密码,如果$cer=true,则此处为证书的地址
- * @param string $cer
- */
- public function login($server,$port=22, $username = "root", $password="", $cer = FALSE) {
- $this->ssh = new Net_SSH2($server,$port);
- if ($cer) {
- include ('Crypt/RSA.php');
- $key = new Crypt_RSA();
- $key->loadKey(file_get_contents($password));
- } else {
- $key = $password;
- }
- if (!$this->ssh->login($username, $key)) {
- return false; // Login Failed
- }else {
- return true;
- }
- }
- /**
- * 执行SSH命令
- */
- public function exec($com){
- return $this->ssh->exec($com);
- }
- /**
- * 关闭SSH连接
- */
- public function close(){
- return $this->ssh->disconnect();
- }
- }
|