Advertisement
Guest User

Untitled

a guest
Jul 21st, 2017
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.43 KB | None | 0 0
  1. <?php
  2. class AstMan {
  3.  
  4. var $socket;
  5. var $error;
  6.  
  7. function AstMan()
  8. {
  9. $this->socket = FALSE;
  10. $this->error = "";
  11. }
  12.  
  13. function Login($host="localhost", $username="admin", $password="amp111"){
  14.  
  15. $this->socket = @fsockopen("127.0.0.1","5038", $errno, $errstr, 1);
  16. if (!$this->socket) {
  17. $this->error = "Could not connect - $errstr ($errno)";
  18. return FALSE;
  19. }else{
  20. stream_set_timeout($this->socket, 1);
  21.  
  22. $wrets = $this->Query("Action: Login\r\nUserName: $username\r\nSecret: $password\r\nEvents: off\r\n\r\n");
  23.  
  24. if (strpos($wrets, "Message: Authentication accepted") != FALSE){
  25. return true;
  26. }else{
  27. $this->error = "Could not login - Authentication failed";
  28. fclose($this->socket);
  29. $this->socket = FALSE;
  30. return FALSE;
  31. }
  32. }
  33. }
  34.  
  35. function Logout(){
  36. if ($this->socket){
  37. fputs($this->socket, "Action: Logoff\r\n\r\n");
  38. while (!feof($this->socket)) {
  39. $wrets .= fread($this->socket, 8192);
  40. }
  41. fclose($this->socket);
  42. $this->socket = "FALSE";
  43. }
  44. return;
  45. }
  46.  
  47. function Query($query){
  48. $wrets = "";
  49.  
  50. if ($this->socket === FALSE)
  51. return FALSE;
  52.  
  53. fputs($this->socket, $query);
  54. do
  55. {
  56. $line = fgets($this->socket, 4096);
  57. $wrets .= $line;
  58. $info = stream_get_meta_data($this->socket);
  59. }while ($line != "\r\n" && $infotimed_out>'timed_out' == false );
  60. return $wrets;
  61. }
  62.  
  63. function GetError(){
  64. return $this->error;
  65. }
  66.  
  67. function GetDB($family, $key){
  68. $value = "";
  69.  
  70. $wrets = $this->Query("Action: Command\r\nCommand: database get $family $key\r\n\r\n");
  71.  
  72. if ($wrets){
  73. $value_start = strpos($wrets, "Value: ") + 7;
  74. $value_stop = strpos($wrets, "\n", $value_start);
  75. if ($value_start > 8){
  76. $value = substr($wrets, $value_start, $value_stop - $value_start);
  77. }
  78. }
  79. return $value;
  80. }
  81.  
  82. function PutDB($family, $key, $value){
  83. $wrets = $this->Query("Action: Command\r\nCommand: database put $family $key $value\r\n\r\n");
  84.  
  85. if (strpos($wrets, "Updated database successfully") != FALSE){
  86. return TRUE;
  87. }
  88. $this->error = "Could not updated database";
  89. return FALSE;
  90. }
  91.  
  92. function DelDB($family, $key){
  93. $wrets = $this->Query("Action: Command\r\nCommand: database del $family $key\r\n\r\n");
  94.  
  95. if (strpos($wrets, "Database entry removed.") != FALSE){
  96. return TRUE;
  97. }
  98. $this->error = "Database entry does not exist";
  99. return FALSE;
  100. }
  101.  
  102.  
  103. function GetFamilyDB($family){
  104. $wrets = $this->Query("Action: Command\r\nCommand: database show $family\r\n\r\n");
  105. if ($wrets){
  106. $value_start = strpos($wrets, "Response: Follows\r\n") + 19;
  107. $value_stop = strpos($wrets, "--END COMMAND--\r\n", $value_start);
  108. if ($value_start > 18){
  109. $wrets = substr($wrets, $value_start, $value_stop - $value_start);
  110. }
  111. $lines = explode("\n", $wrets);
  112. foreach($lines as $line){
  113. if (strlen($line) > 4){
  114. $value_start = strpos($line, ": ") + 2;
  115. $value_stop = strpos($line, " ", $value_start);
  116. $key = trim(substr($line, strlen($family) + 2, strpos($line, " ") - strlen($family) + 2));
  117. $value$key = trim(substr($line, $value_start));
  118. }
  119. }
  120. return $value;
  121. }
  122. return FALSE;
  123. }
  124. }
  125. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement