Advertisement
Guest User

Untitled

a guest
Sep 27th, 2017
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.50 KB | None | 0 0
  1. <?
  2. class SSH {
  3. var $hostname;
  4. var $port;
  5. var $username;
  6. var $password;
  7.  
  8. var $_socket;
  9.  
  10. public function __construct($hostname, $port, $username, $password) {
  11. $this->hostname = $hostname;
  12. $this->port = $port;
  13. $this->username = $username;
  14. $this->password = $password;
  15.  
  16. if(!function_exists('ssh2_connect')) throw new Exception("Error(ssh.class.php): ssh2_connect function was not found.");
  17. if(!($this->_socket = ssh2_connect($this->hostname, $this->port))) throw new Exception("Error(ssh.class.php): Connection refused.");
  18. if(!ssh2_auth_password($this->_socket, $this->username, $this->password)) throw new Exception("Error(ssh.class.php): Invalid username and/or password.");
  19. }
  20.  
  21. public function SendCommand($command) {
  22. $stream = ssh2_exec($this->_socket, $command);
  23. stream_set_blocking($stream, true);
  24. return stream_get_contents($stream);
  25. }
  26.  
  27. public function RestartServer($type, $screen) {
  28. $screen = db::escape($screen);
  29. if($type == 0) {
  30. $query = db::q("SELECT * FROM cs_servers WHERE screen = '$screen'");
  31. $vps_query = db::q("SELECT * FROM servers WHERE id = '". db::result($query, 0, 'sid') ."'");
  32. $pid = $this->SendCommand("ps aux|grep -w ".$screen."|grep -v grep|awk '{print $2}'");
  33. $this->SendCommand("kill -9 ". $pid);
  34. $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'));
  35. } elseif($type == 1) {
  36. $query = db::q("SELECT * FROM css_servers WHERE screen = '$screen'");
  37. $vps_query = db::q("SELECT * FROM servers WHERE id = '". db::result($query, 0, 'sid') ."'");
  38. $pid = $this->SendCommand("ps aux|grep -w ".$screen."|grep -v grep|awk '{print $2}'");
  39. $this->SendCommand("kill -9 ". $pid);
  40. $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'));
  41. }
  42. }
  43.  
  44. public function __destruct() {
  45. @fclose($this->_socket);
  46. }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement