Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace bc_utils;
- class ssh {
- protected $conn;
- // constructor
- public function __construct($host, authentication $auth, $port = 22) {
- $this -> conn = ssh2_connect($host, $port);
- switch(get_class($auth)) {
- case "password":
- $username = $auth -> get_username();
- $password = $auth -> get_password();
- if (ssh2_auth_password($this -> conn, $username, $password) === false) {
- throw new Exception("SSH2 login is invalid");
- }
- break;
- case "key":
- $username = $auth -> get_username();
- $public_key = $auth -> get_public_key();
- $private_key = $auth -> get_private_key();
- if (ssh2_auth_pubkey_file($this -> conn, $username, $public_key, $private_key) === false) {
- throw new Exception("SSH2 login is invalid");
- }
- break;
- default:
- throw new Exception("Unknown SSH2 login type");
- break;
- }
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement