Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?
- class SSH {
- var $hostname;
- var $port;
- var $username;
- var $password;
- var $_socket;
- public function __construct($hostname, $port, $username, $password) {
- $this->hostname = $hostname;
- $this->port = $port;
- $this->username = $username;
- $this->password = $password;
- if(!function_exists('ssh2_connect')) throw new Exception("Error(ssh.class.php): ssh2_connect function was not found.");
- if(!($this->_socket = ssh2_connect($this->hostname, $this->port))) throw new Exception("Error(ssh.class.php): Connection refused.");
- if(!ssh2_auth_password($this->_socket, $this->username, $this->password)) throw new Exception("Error(ssh.class.php): Invalid username and/or password.");
- }
- public function SendCommand($command) {
- $stream = ssh2_exec($this->_socket, $command);
- stream_set_blocking($stream, true);
- return stream_get_contents($stream);
- }
- public function RestartServer($type, $screen) {
- $screen = db::escape($screen);
- if($type == 0) {
- $query = db::q("SELECT * FROM cs_servers WHERE screen = '$screen'");
- $vps_query = db::q("SELECT * FROM servers WHERE id = '". db::result($query, 0, 'sid') ."'");
- $pid = $this->SendCommand("ps aux|grep -w ".$screen."|grep -v grep|awk '{print $2}'");
- $this->SendCommand("kill -9 ". $pid);
- $this->SendCommand("cd ". db::result($query, 0, 'dir') ." && screen -A -m -d -S ".$screen." ./hlds_run -game cstrike +ip ". db::result($query, 0, 'ip') ." -port ". db::result($query, 0, 'port') ." +maxplayers 11 +map de_inferno +servercfgfile " . db::result($query, 0, 'servercfg'));
- } elseif($type == 1) {
- $query = db::q("SELECT * FROM css_servers WHERE screen = '$screen'");
- $vps_query = db::q("SELECT * FROM servers WHERE id = '". db::result($query, 0, 'sid') ."'");
- $pid = $this->SendCommand("ps aux|grep -w ".$screen."|grep -v grep|awk '{print $2}'");
- $this->SendCommand("kill -9 ". $pid);
- $this->SendCommand("cd ". db::result($query, 0, 'dir') ." && screen -A -m -d -S ".$screen." ./srcds_run -game cstrike +ip ". db::result($query, 0, 'ip') ." -tickrate 1000 -insecure +mp_dynamicpricing 0 -port ". db::result($query, 0, 'port') ." +maxplayers 11 +map de_inferno +servercfgfile " . db::result($query, 0, 'servercfg'));
- }
- }
- public function __destruct() {
- @fclose($this->_socket);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement