Advertisement
Guest User

Untitled

a guest
May 11th, 2016
271
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.16 KB | None | 0 0
  1. <?php
  2. session_start();
  3. $ROOT = realpath(__DIR__);
  4. include $ROOT.'/../core/config.php';
  5. include 'log.php';
  6. set_include_path($ROOT.'/../SSH2');
  7. include 'Net/SSH2.php';
  8. set_include_path('');
  9. $PagePermision = '2';
  10. include 'session.php';
  11.  
  12. try {
  13. $SQL = 'SELECT * FROM Users ORDER BY ID DESC';
  14. $SQL = $CONN->prepare($SQL);
  15. $SQL->execute();
  16. $Clients = $SQL->fetchAll();
  17. } catch(PDOException $e) {
  18. echo "Error: " . $e->getMessage();
  19. }
  20.  
  21. try {
  22. $SQL = 'SELECT * FROM Games';
  23. $SQL = $CONN->prepare($SQL);
  24. $SQL->execute();
  25. $Games = $SQL->fetchAll();
  26. } catch(PDOException $e) {
  27. echo "Error: " . $e->getMessage();
  28. }
  29.  
  30. try {
  31. $SQL = 'SELECT * FROM Boxes';
  32. $SQL = $CONN->prepare($SQL);
  33. $SQL->execute();
  34. $Boxes = $SQL->fetchAll();
  35. } catch(PDOException $e) {
  36. echo "Error: " . $e->getMessage();
  37. }
  38.  
  39. if(isset($_GET['GameID'])) {
  40. $GameID = $_GET['GameID'];
  41. } else {
  42. $GameID = NULL;
  43. }
  44.  
  45. try {
  46. $SQL = 'SELECT * FROM Templates WHERE GameID = :GameID ORDER BY ID ASC';
  47. $SQL = $CONN->prepare($SQL);
  48. $SQL->execute(array('GameID' => $GameID));
  49. $Mods = $SQL->fetchAll();
  50. } catch(PDOException $e) {
  51. echo "Error: " . $e->getMessage();
  52. }
  53.  
  54. if($_SERVER['REQUEST_METHOD'] === 'POST') {
  55. $UserID = $_POST['UserID'];
  56. $BoxID = $_POST['BoxID'];
  57. $TemplateID = $_POST['TemplateID'];
  58. $Hostname = $_POST['Hostname'];
  59. $SlotNumber = $_POST['SlotNumber'];
  60. $Expires = $_POST['Expires'];
  61. $Price = $_POST['Price'];
  62.  
  63. try {
  64. $SQL = 'SELECT * FROM Boxes WHERE ID = :ID';
  65. $SQL = $CONN->prepare($SQL);
  66. $SQL->execute(array('ID' => $BoxID));
  67. $BoxData = $SQL->fetch(PDO::FETCH_ASSOC);
  68. } catch(PDOException $e) {
  69. echo "Error: " . $e->getMessage();
  70. }
  71.  
  72. try {
  73. $SQL = 'SELECT * FROM Templates WHERE ID = :ID';
  74. $SQL = $CONN->prepare($SQL);
  75. $SQL->execute(array('ID' => $TemplateID));
  76. $TemplateData = $SQL->fetch(PDO::FETCH_ASSOC);
  77. } catch(PDOException $e) {
  78. echo "Error: " . $e->getMessage();
  79. }
  80.  
  81. try {
  82. $SQL = 'SELECT ServerPort FROM Servers INNER JOIN Templates ON Templates.ID = Servers.TemplateID WHERE Templates.BoxID = :BoxID AND Templates.GameID = :GameID ORDER BY Servers.ServerPort DESC LIMIT 1';
  83. $SQL = $CONN->prepare($SQL);
  84. $SQL->execute(array('BoxID' => $BoxID, 'GameID' => $TemplateData['GameID']));
  85. $ServerData = $SQL->fetch(PDO::FETCH_ASSOC);
  86. $ServerPort = $ServerData['ServerPort'];
  87. } catch(PDOException $e) {
  88. echo "Error: " . $e->getMessage();
  89. }
  90.  
  91. $ServerPort = $ServerPort + 1;
  92.  
  93. try {
  94. $SQL = 'SELECT Username FROM Servers WHERE BoxID = :BoxID ORDER BY Username DESC LIMIT 1';
  95. $SQL = $CONN->prepare($SQL);
  96. $SQL->execute(array('BoxID' => $BoxID));
  97. $ServerData = $SQL->fetch(PDO::FETCH_ASSOC);
  98. $Username = $ServerData['Username'];
  99. } catch(PDOException $e) {
  100. echo "Error: " . $e->getMessage();
  101. }
  102.  
  103. $Username = filter_var($Username, FILTER_SANITIZE_NUMBER_INT) + 10;
  104. $Username = 'SRV'.$Username;
  105.  
  106. function RandomPassword() {
  107. $Alphabet = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890';
  108. $Pass = array();
  109. $AlphaLength = strlen($Alphabet) - 1;
  110. for ($I = 0; $I < 10; $I++) {
  111. $N = rand(0, $AlphaLength);
  112. $Pass[] = $Alphabet[$N];
  113. }
  114. return implode($Pass);
  115. }
  116.  
  117. $Password = RandomPassword();
  118.  
  119. try {
  120. $SQL = 'INSERT INTO Servers (UserID, BoxID, TemplateID, Type, Status, Hostname, ServerIP, ServerPort, SlotNumber, Expires, Price, Username, Password) VALUES (:UserID, :BoxID, :TemplateID, :Type, :Status, :Hostname, :ServerIP, :ServerPort, :SlotNumber, :Expires, :Price, :Username, :Password)';
  121. $SQL = $CONN->prepare($SQL);
  122. $SQL->execute(array('UserID' => $UserID, 'BoxID' => $BoxID, 'TemplateID' => $TemplateID, 'Type' => '1', 'Status' => '0', 'Hostname' => $Hostname, 'ServerIP' => $BoxData['BoxIP'], 'ServerPort' => $ServerPort, 'SlotNumber' => $SlotNumber, 'Expires' => $Expires, 'Price' => $Price, 'Username' => $Username, 'Password' => $Password));
  123. } catch(PDOException $e) {
  124. echo "Error: " . $e->getMessage();
  125. }
  126.  
  127. $SSH2_Host = $BoxData['BoxIP'];
  128. $SSH2_Username = $BoxData['Username'];
  129. $SSH2_Password = $BoxData['Password'];
  130.  
  131. $SSH2 = new Net_SSH2($SSH2_Host);
  132. if (!$SSH2->login($SSH2_Username, $SSH2_Password)) {
  133. echo 'SSH2 Login Error!';
  134. }
  135. $SSH2->enablePTY();
  136.  
  137. $SSH2->exec('screen -S "'.$Username.'"');
  138. $SSH2->setTimeout(1);
  139. $SSH2->write("useradd -s /usr/sbin/nologin -m ".$Username."\n");
  140. $SSH2->setTimeout(1);
  141. $SSH2->write("echo ".$Username.":".$Password." | chpasswd\n");
  142. $SSH2->setTimeout(1);
  143. $SSH2->write("cp -R ".$TemplateData['FilesPath']."* /home/".$Username."\n");
  144. $SSH2->setTimeout(1);
  145. $SSH2->write("chown -R ".$Username.":".$Username." /home/".$Username." && exit\n");
  146. $SSH2->read();
  147.  
  148. LogMessage('Server Addet! User: '.$UserID.'.', $CONN);
  149.  
  150. header("location: servers.php");
  151. exit();
  152. }
  153.  
  154. include 'layout/header.php';
  155. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement