Advertisement
Guest User

Untitled

a guest
Jul 18th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.13 KB | None | 0 0
  1. <?php
  2.  
  3. class m_mysql extends Module
  4. {
  5.  
  6. private $m_sNick;
  7.  
  8. private $conn;
  9.  
  10. private $sqlInfo = array(
  11.  
  12. 'host' => 'localhost',
  13. 'user' => 'VIKI',
  14. 'pass' => 'a5dde8bbe9bdba75f11ae9e60cdbc4',
  15. 'db' => 'eXXe'
  16.  
  17. );
  18.  
  19.  
  20. public function __construct($sNick)
  21. {
  22. $this -> m_sNick = $sNick;
  23.  
  24. $this->conn = new mysqli($this->sqlInfo['host'], $this->sqlInfo['user'], $this->sqlInfo['pass'], $this->sqlInfo['db']) or die('There was a problem connecting to the database.');
  25. }
  26.  
  27. public function __destruct( )
  28. {
  29. }
  30.  
  31. public function onPrivMsg( $sFrom, $sMsg )
  32. {
  33. }
  34.  
  35. public function onPrivNotice( $sFrom, $sMsg )
  36. {
  37. // echo $sFrom . '<=N ' . $sMsg . chr( 10 );
  38. }
  39.  
  40. public function onMsg( $sFrom, $sTo, $sMsg, $sSpecial = null )
  41. {
  42. $sNick = $this->m_sNick;
  43. $oBot = Bots::obj()->getBot($sNick);
  44.  
  45. $aMsg = explode(' ', $sMsg);
  46.  
  47. $sCmd = strtolower($aMsg[0]);
  48.  
  49. if($sCmd == '@#testcon') {
  50. $query = 'SELECT id, name, password FROM users WHERE id = 1';
  51.  
  52. if($stmt = $this->conn->prepare($query)) {
  53. $stmt->execute();
  54. $stmt->bind_result($id, $name, $password);
  55.  
  56. $users = array();
  57.  
  58. while($row = $stmt->fetch()) {
  59. $users['id'] = $id;
  60. $users['name'] = $name;
  61. $users['password'] = $password;
  62. }
  63.  
  64. $stmt->close();
  65.  
  66. $oBot->msg($oBot['in']->Channel, $users['id'] .'|'. $users['name'] .'|'. $users['password']);
  67. }
  68. }
  69. else if($sCmd == '@#listusers') {
  70. $query = 'SELECT id, name, password FROM users ORDER BY id ASC';
  71.  
  72. if($stmt = $this->conn->prepare($query)) {
  73. $stmt->execute();
  74. $stmt->bind_result($id, $name, $password);
  75.  
  76. $users = array();
  77.  
  78. while($row = $stmt->fetch()) {
  79. $users[$id]['id'] = $id;
  80. $users[$id]['name'] = $name;
  81. $users[$id]['password'] = $password;
  82. }
  83.  
  84. $stmt->close();
  85.  
  86. $oBot->msg($oBot['in']->Channel, '----| User List |----');
  87. foreach($users as $user) {
  88. $oBot->msg($oBot['in']->Channel, $user['id'] .'|'. $user['name'] .'|'. $user['password']);
  89. }
  90. }
  91. }
  92. else if($sCmd == '@#adduser') {
  93. if(!isset($aMsg[1]) || !isset($aMsg[2])) {
  94. return $oBot->msg($oBot['in']->Channel, CMD_ERROR.' USAGE: @#adduser [username] [password]');
  95. } else {
  96.  
  97. $username = $aMsg[1];
  98. $password = hash('whirlpool', $aMsg[2]);
  99.  
  100. $query = 'INSERT INTO users VALUES (NULL, ?, ?)';
  101.  
  102. if($stmt = $this->conn->prepare($query)) {
  103. $stmt->bind_param('ss', $username, $password);
  104. if($stmt->execute()) {
  105. $oBot->msg($oBot['in']->Channel, CMD_SUCCESS.' User added successfully!');
  106. $stmt->close();
  107. } else {
  108. $oBot->msg($oBot['in']->Channel, CMD_ERROR.' User not added successfully.');
  109. $stmt->close();
  110. }
  111. }
  112. }
  113. }
  114. else if($sCmd == '@#remuser') {
  115. if($aMsg[1] == NULL) {
  116. return $oBot->msg($oBot['in']->Channel, CMD_ERROR.' USAGE: @#remuser [username]');
  117. } else {
  118. $username = $aMsg[1];
  119.  
  120. if(!$this->isValidUser($username)) {
  121. return $oBot->msg($oBot['in']->Channel, CMD_ERROR.' Invalid Username.');
  122. } else {
  123.  
  124. $query = "DELETE FROM users WHERE name = ?";
  125.  
  126. if($stmt = $this->conn->prepare($query)) {
  127. $stmt->bind_param('s', $username);
  128. if($stmt->execute()) {
  129. $oBot->msg($oBot['in']->Channel, CMD_SUCCESS.' User removed successfully!');
  130. $stmt->close();
  131. } else {
  132. $oBot->msg($oBot['in']->Channel, CMD_ERROR.' User not removed successfully.');
  133. $stmt->close();
  134. }
  135. }
  136. }
  137. }
  138. }
  139. }
  140. public function isValidUser($username) {
  141.  
  142. $query = "SELECT id FROM users WHERE name = ?";
  143.  
  144. if($stmt = $this->conn->prepare($query)) {
  145. $stmt->bind_param('s', $username);
  146. $stmt->execute();
  147. $stmt->store_result();
  148.  
  149. if($stmt->num_rows <= 0) {
  150. $stmt->close();
  151. return false;
  152. } else {
  153. $stmt->close();
  154. return true;
  155. }
  156. } else {
  157. return false;
  158. }
  159. }
  160.  
  161. public function __toString( )
  162. {
  163. return 'MySQL Test Module';
  164. }
  165. }
  166.  
  167. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement