TeamSpeak 3 PHP Framework  1.1.16
Copyright © Planet TeamSpeak. All rights reserved.
All Classes Namespaces Files Functions Variables Pages
Blacklist.php
Go to the documentation of this file.
1 <?php
2 
3 /**
4  * @file
5  * TeamSpeak 3 PHP Framework
6  *
7  * $Id: Blacklist.php 8/31/2012 11:06:09 scp@orilla $
8  *
9  * This program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program. If not, see <http://www.gnu.org/licenses/>.
21  *
22  * @package TeamSpeak3
23  * @version 1.1.16
24  * @author Sven 'ScP' Paulsen
25  * @copyright Copyright (c) 2010 by Planet TeamSpeak. All rights reserved.
26  */
27 
28 /**
29  * @class TeamSpeak3_Adapter_Blacklist
30  * @brief Provides methods to check if an IP address is currently blacklisted.
31  */
33 {
34  /**
35  * The IPv4 address or FQDN of the TeamSpeak Systems update server.
36  *
37  * @var string
38  */
39  protected $default_host = "blacklist.teamspeak.com";
40 
41  /**
42  * The UDP port number of the TeamSpeak Systems update server.
43  *
44  * @var integer
45  */
46  protected $default_port = 17385;
47 
48  /**
49  * Stores an array containing the latest build numbers.
50  *
51  * @var array
52  */
53  protected $build_numbers = null;
54 
55  /**
56  * Connects the TeamSpeak3_Transport_Abstract object and performs initial actions on the remote
57  * server.
58  *
59  * @return void
60  */
61  public function syn()
62  {
63  if(!isset($this->options["host"]) || empty($this->options["host"])) $this->options["host"] = $this->default_host;
64  if(!isset($this->options["port"]) || empty($this->options["port"])) $this->options["port"] = $this->default_port;
65 
66  $this->initTransport($this->options, "TeamSpeak3_Transport_UDP");
67  $this->transport->setAdapter($this);
68 
69  TeamSpeak3_Helper_Profiler::init(spl_object_hash($this));
70 
71  TeamSpeak3_Helper_Signal::getInstance()->emit("blacklistConnected", $this);
72  }
73 
74  /**
75  * The TeamSpeak3_Adapter_Blacklist destructor.
76  *
77  * @return void
78  */
79  public function __destruct()
80  {
81  if($this->getTransport() instanceof TeamSpeak3_Transport_Abstract && $this->getTransport()->isConnected())
82  {
83  $this->getTransport()->disconnect();
84  }
85  }
86 
87  /**
88  * Returns TRUE if a specified $host IP address is currently blacklisted.
89  *
90  * @param string $host
91  * @throws TeamSpeak3_Adapter_Blacklist_Exception
92  * @return boolean
93  */
94  public function isBlacklisted($host)
95  {
96  if(ip2long($host) === FALSE)
97  {
98  $addr = gethostbyname($host);
99 
100  if($addr == $host)
101  {
102  throw new TeamSpeak3_Adapter_Blacklist_Exception("unable to resolve IPv4 address (" . $host . ")");
103  }
104 
105  $host = $addr;
106  }
107 
108  $this->getTransport()->send("ip4:" . $host);
109  $repl = $this->getTransport()->read(1);
110  $this->getTransport()->disconnect();
111 
112  if(!count($repl))
113  {
114  return FALSE;
115  }
116 
117  return ($repl->toInt()) ? FALSE : TRUE;
118  }
119 }