TSDNS.php 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. /**
  3. * @file
  4. * TeamSpeak 3 PHP Framework
  5. *
  6. * $Id: TSDNS.php 06/06/2016 22:27:13 scp@Svens-iMac $
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. * @package TeamSpeak3
  22. * @version 1.1.24
  23. * @author Sven 'ScP' Paulsen
  24. * @copyright Copyright (c) 2010 by Planet TeamSpeak. All rights reserved.
  25. */
  26. /**
  27. * @class TeamSpeak3_Adapter_TSDNS
  28. * @brief Provides methods to query a TSDNS server.
  29. */
  30. class TeamSpeak3_Adapter_TSDNS extends TeamSpeak3_Adapter_Abstract
  31. {
  32. /**
  33. * The TCP port number used by any TSDNS server.
  34. *
  35. * @var integer
  36. */
  37. protected $default_port = 41144;
  38. /**
  39. * Connects the TeamSpeak3_Transport_Abstract object and performs initial actions on the remote
  40. * server.
  41. *
  42. * @throws TeamSpeak3_Adapter_Exception
  43. * @return void
  44. */
  45. public function syn()
  46. {
  47. if(!isset($this->options["port"]) || empty($this->options["port"])) $this->options["port"] = $this->default_port;
  48. $this->initTransport($this->options);
  49. $this->transport->setAdapter($this);
  50. TeamSpeak3_Helper_Profiler::init(spl_object_hash($this));
  51. TeamSpeak3_Helper_Signal::getInstance()->emit("tsdnsConnected", $this);
  52. }
  53. /**
  54. * The TeamSpeak3_Adapter_FileTransfer destructor.
  55. *
  56. * @return void
  57. */
  58. public function __destruct()
  59. {
  60. if($this->getTransport() instanceof TeamSpeak3_Transport_Abstract && $this->getTransport()->isConnected())
  61. {
  62. $this->getTransport()->disconnect();
  63. }
  64. }
  65. /**
  66. * Queries the TSDNS server for a specified virtual hostname and returns the result.
  67. *
  68. * @param string $tsdns
  69. * @throws TeamSpeak3_Adapter_TSDNS_Exception
  70. * @return TeamSpeak3_Helper_String
  71. */
  72. public function resolve($tsdns)
  73. {
  74. $this->getTransport()->sendLine($tsdns);
  75. $repl = $this->getTransport()->readLine();
  76. $this->getTransport()->disconnect();
  77. if($repl->section(":", 0)->toInt() == 404)
  78. {
  79. throw new TeamSpeak3_Adapter_TSDNS_Exception("unable to resolve TSDNS hostname (" . $tsdns . ")");
  80. }
  81. TeamSpeak3_Helper_Signal::getInstance()->emit("tsdnsResolved", $tsdns, $repl);
  82. return $repl;
  83. }
  84. }