TeamSpeak 3 PHP Framework
1.1.12
|
00001 <?php 00002 00003 /** 00004 * @file 00005 * TeamSpeak 3 PHP Framework 00006 * 00007 * $Id: Blacklist.php 2/18/2012 12:42:45 scp@orilla $ 00008 * 00009 * This program is free software: you can redistribute it and/or modify 00010 * it under the terms of the GNU General Public License as published by 00011 * the Free Software Foundation, either version 3 of the License, or 00012 * (at your option) any later version. 00013 * 00014 * This program is distributed in the hope that it will be useful, 00015 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00017 * GNU General Public License for more details. 00018 * 00019 * You should have received a copy of the GNU General Public License 00020 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00021 * 00022 * @package TeamSpeak3 00023 * @version 1.1.12 00024 * @author Sven 'ScP' Paulsen 00025 * @copyright Copyright (c) 2010 by Planet TeamSpeak. All rights reserved. 00026 */ 00027 00028 /** 00029 * @class TeamSpeak3_Adapter_Blacklist 00030 * @brief Provides methods to check if an IP address is currently blacklisted. 00031 */ 00032 class TeamSpeak3_Adapter_Blacklist extends TeamSpeak3_Adapter_Abstract 00033 { 00034 /** 00035 * The IPv4 address or FQDN of the TeamSpeak Systems update server. 00036 * 00037 * @var string 00038 */ 00039 protected $default_host = "blacklist.teamspeak.com"; 00040 00041 /** 00042 * The UDP port number of the TeamSpeak Systems update server. 00043 * 00044 * @var integer 00045 */ 00046 protected $default_port = 17385; 00047 00048 /** 00049 * Stores an array containing the latest build numbers. 00050 * 00051 * @var array 00052 */ 00053 protected $build_numbers = null; 00054 00055 /** 00056 * Connects the TeamSpeak3_Transport_Abstract object and performs initial actions on the remote 00057 * server. 00058 * 00059 * @return void 00060 */ 00061 public function syn() 00062 { 00063 if(!isset($this->options["host"]) || empty($this->options["host"])) $this->options["host"] = $this->default_host; 00064 if(!isset($this->options["port"]) || empty($this->options["port"])) $this->options["port"] = $this->default_port; 00065 00066 $this->initTransport($this->options, "TeamSpeak3_Transport_UDP"); 00067 $this->transport->setAdapter($this); 00068 00069 TeamSpeak3_Helper_Profiler::init(spl_object_hash($this)); 00070 00071 TeamSpeak3_Helper_Signal::getInstance()->emit("blacklistConnected", $this); 00072 } 00073 00074 /** 00075 * The TeamSpeak3_Adapter_Blacklist destructor. 00076 * 00077 * @return void 00078 */ 00079 public function __destruct() 00080 { 00081 if($this->getTransport() instanceof TeamSpeak3_Transport_Abstract && $this->getTransport()->isConnected()) 00082 { 00083 $this->getTransport()->disconnect(); 00084 } 00085 } 00086 00087 /** 00088 * Returns TRUE if a specified $host IP address is currently blacklisted. 00089 * 00090 * @param string $host 00091 * @throws TeamSpeak3_Adapter_Blacklist_Exception 00092 * @return boolean 00093 */ 00094 public function isBlacklisted($host) 00095 { 00096 if(ip2long($host) === FALSE) 00097 { 00098 $addr = gethostbyname($host); 00099 00100 if($addr == $host) 00101 { 00102 throw new TeamSpeak3_Adapter_Blacklist_Exception("unable to resolve IPv4 address (" . $host . ")"); 00103 } 00104 00105 $host = $addr; 00106 } 00107 00108 $this->getTransport()->send("ip4:" . $host); 00109 $repl = $this->getTransport()->read(1); 00110 $this->getTransport()->disconnect(); 00111 00112 if(!count($repl)) 00113 { 00114 return FALSE; 00115 } 00116 00117 return ($repl->toInt()) ? FALSE : TRUE; 00118 } 00119 }