Advertisement
craftyoyo

ssh button

Jun 1st, 2019
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.14 KB | None | 0 0
  1. if(isset($_GET['action'])){
  2.  
  3.     if($_GET['action'] == 'stop'){
  4.         $connection = ssh2_connect('localhost', 22);
  5.         if ($connection === false) {
  6.             $error = error_get_last();
  7.             throw new Exception("Impossible de s'identifier en SSH au serveur distant : <br/><br/>
  8.             Type d'erreur : ".$error["type"]."<br/>
  9.             Message : ".$error["message"]."<br/>
  10.             Fichier : ".$error["file"]."<br/>
  11.             Ligne : ".$error["line"]."<br/>");
  12.         }
  13.         ssh2_auth_password($connection, 'user', 'pass');
  14.         $stdio_stream = ssh2_shell($connection);
  15.         ssh2_exec($connection, 'screen -S ftb -p 0 -X stuff "stop^M"');
  16.         echo "<script type='text/javascript'>document.location.replace('index.php');</script>";
  17.     }
  18.     if($_GET['action'] == 'boot'){
  19.         $connection = ssh2_connect('localhost', 22);
  20.         if ($connection === false) {
  21.             $error = error_get_last();
  22.             throw new Exception("Impossible de s'identifier en SSH au serveur distant : <br/><br/>
  23.             Type d'erreur : ".$error["type"]."<br/>
  24.             Message : ".$error["message"]."<br/>
  25.             Fichier : ".$error["file"]."<br/>
  26.             Ligne : ".$error["line"]."<br/>");
  27.         }
  28.         ssh2_auth_password($connection, 'user', 'pass');
  29.         $stdio_stream = ssh2_shell($connection);
  30.         ssh2_exec($connection, 'cd ftb/ && ./ServerStart.sh');
  31.         echo "<script type='text/javascript'>document.location.replace('index.php');</script>";
  32.     }
  33.     if($_GET['action'] == 'restart'){
  34.         $connection = ssh2_connect('localhost', 22);
  35.         if ($connection === false) {
  36.             $error = error_get_last();
  37.             throw new Exception("Impossible de s'identifier en SSH au serveur distant : <br/><br/>
  38.             Type d'erreur : ".$error["type"]."<br/>
  39.             Message : ".$error["message"]."<br/>
  40.             Fichier : ".$error["file"]."<br/>
  41.             Ligne : ".$error["line"]."<br/>");
  42.         }
  43.         ssh2_auth_password($connection, 'user', 'pass');
  44.         $stdio_stream = ssh2_shell($connection);
  45.         ssh2_exec($connection, 'screen -S ftb -p 0 -X stuff "broadcast Server Reboot in 1Min^M"');
  46.         sleep(60);
  47.         ssh2_exec($connection, 'screen -S ftb -p 0 -X stuff "stop^M"');
  48.         sleep(4);
  49.         ssh2_exec($connection, 'cd ftb/ && ./ServerStart.sh');
  50.         echo "<script type='text/javascript'>document.location.replace('index.php');</script>";
  51.     }
  52.  
  53. }
  54.  
  55. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement