Przeglądaj źródła

Merge pull request #589 from M-itch/master

TeamSpeak 3 PHP Framework updated
DieFeM 3 lat temu
rodzic
commit
0abed8f986

+ 4 - 4
protocol/TeamSpeak3/Helper/Char.php

@@ -179,7 +179,7 @@ class TeamSpeak3_Helper_Char
    */
   public function toUnicode()
   {
-    $h = ord($this->char{0});
+    $h = ord($this->char[0]);
 
     if($h <= 0x7F)
     {
@@ -191,15 +191,15 @@ class TeamSpeak3_Helper_Char
     }
     else if($h <= 0xDF)
     {
-      return ($h & 0x1F) << 6 | (ord($this->char{1}) & 0x3F);
+      return ($h & 0x1F) << 6 | (ord($this->char[1]) & 0x3F);
     }
     else if($h <= 0xEF)
     {
-      return ($h & 0x0F) << 12 | (ord($this->char{1}) & 0x3F) << 6 | (ord($this->char{2}) & 0x3F);
+      return ($h & 0x0F) << 12 | (ord($this->char[1]) & 0x3F) << 6 | (ord($this->char[2]) & 0x3F);
     }
     else if($h <= 0xF4)
     {
-      return ($h & 0x0F) << 18 | (ord($this->char{1}) & 0x3F) << 12 | (ord($this->char{2}) & 0x3F) << 6 | (ord($this->char{3}) & 0x3F);
+      return ($h & 0x0F) << 18 | (ord($this->char[1]) & 0x3F) << 12 | (ord($this->char[2]) & 0x3F) << 6 | (ord($this->char[3]) & 0x3F);
     }
     else
     {

+ 1 - 1
protocol/TeamSpeak3/Helper/Crypt.php

@@ -174,7 +174,7 @@ class TeamSpeak3_Helper_Crypt
       $data = 0;
       for($j = 4; $j > 0; $j--)
       {
-        $data = $data << 8 | ord($passphrase{$k});
+        $data = $data << 8 | ord($passphrase[$k]);
         $k = ($k+1) % $length;
       }
       $this->p[$i] ^= $data;

+ 4 - 4
protocol/TeamSpeak3/Helper/String.php

@@ -186,7 +186,7 @@ class TeamSpeak3_Helper_String implements ArrayAccess, Iterator, Countable, Json
 
     if($regexp)
     {
-      return (preg_match("/" . $pattern . "/i", $this->string)) ? TRUE : FALSE;
+      return (preg_match("/" . preg_quote($pattern, '/') . "/i", $this->string)) ? TRUE : FALSE;
     }
     else
     {
@@ -897,7 +897,7 @@ class TeamSpeak3_Helper_String implements ArrayAccess, Iterator, Countable, Json
    */
   public function current()
   {
-    return new TeamSpeak3_Helper_Char($this->string{$this->position});
+    return new TeamSpeak3_Helper_Char($this->string[$this->position]);
   }
 
   /**
@@ -921,7 +921,7 @@ class TeamSpeak3_Helper_String implements ArrayAccess, Iterator, Countable, Json
    */
   public function offsetGet($offset)
   {
-    return ($this->offsetExists($offset)) ? new TeamSpeak3_Helper_Char($this->string{$offset}) : null;
+    return ($this->offsetExists($offset)) ? new TeamSpeak3_Helper_Char($this->string[$offset]) : null;
   }
 
   /**
@@ -931,7 +931,7 @@ class TeamSpeak3_Helper_String implements ArrayAccess, Iterator, Countable, Json
   {
     if(!$this->offsetExists($offset)) return;
 
-    $this->string{$offset} = strval($value);
+    $this->string[$offset] = strval($value);
   }
 
   /**

+ 0 - 1
protocol/TeamSpeak3/Node/Channel.php

@@ -580,4 +580,3 @@ class TeamSpeak3_Node_Channel extends TeamSpeak3_Node_Abstract
     return (string) $this["channel_name"];
   }
 }
-

+ 111 - 1
protocol/TeamSpeak3/Node/Host.php

@@ -457,6 +457,61 @@ class TeamSpeak3_Node_Host extends TeamSpeak3_Node_Abstract
     return $this->execute("bindinglist", array("subsystem" => $subsystem))->toArray();
   }
 
+  /**
+   * Returns the number of WebQuery API keys known by the virtual server.
+   *
+   * @return integer
+   */
+  public function apiKeyCount()
+  {
+    return current($this->execute("apikeylist -count", array("duration" => 1))->toList("count"));
+  }
+
+  /**
+   * Returns a list of WebQuery API keys known by the virtual server. By default, the server spits out 25 entries
+   * at once. When no $cldbid is specified, API keys for the invoker are returned. In addition, using '*' as $cldbid
+   * will return all known API keys.
+   *
+   * @param  integer $offset
+   * @param  integer $limit
+   * @param  mixed   $cldbid
+   * @return array
+   */
+  public function apiKeyList($offset = null, $limit = null, $cldbid = null)
+  {
+    return $this->execute("apikeylist -count", array("start" => $offset, "duration" => $limit, "cldbid" => $cldbid))->toAssocArray("id");
+  }
+
+  /**
+   * Creates a new WebQuery API key and returns an assoc array containing its details. Use $lifetime to specify the API
+   * key lifetime in days. Setting $lifetime to 0 means the key will be valid forever. $cldbid defaults to the invoker
+   * database ID.
+   *
+   * @param  string  $scope
+   * @param  integer $lifetime
+   * @param  integer $cldbid
+   * @return array
+   */
+  public function apiKeyCreate($scope = TeamSpeak3::APIKEY_READ, $lifetime = 14, $cldbid = null)
+  {
+    $detail = $this->execute("apikeyadd", array("scope" => $scope, "lifetime" => $lifetime, "cldbid" => $cldbid))->toList();
+
+    TeamSpeak3_Helper_Signal::getInstance()->emit("notifyApikeycreated", $this, $detail["apikey"]);
+
+    return $detail;
+  }
+
+  /**
+   * Deletes an API key specified by $id.
+   *
+   * @param  integer $id
+   * @return void
+   */
+  public function apiKeyDelete($id)
+  {
+    $this->execute("apikeydel", array("id" => $id));
+  }
+
   /**
    * Returns a list of permissions available on the server instance.
    *
@@ -539,7 +594,7 @@ class TeamSpeak3_Node_Host extends TeamSpeak3_Node_Abstract
       $permtree[$val]["permcatid"]      = $val;
       $permtree[$val]["permcathex"]     = "0x" . dechex($val);
       $permtree[$val]["permcatname"]    = TeamSpeak3_Helper_String::factory(TeamSpeak3_Helper_Convert::permissionCategory($val));
-      $permtree[$val]["permcatparent"]  = $permtree[$val]["permcathex"]{3} == 0 ? 0 : hexdec($permtree[$val]["permcathex"]{2} . 0);
+      $permtree[$val]["permcatparent"]  = $permtree[$val]["permcathex"][3] == 0 ? 0 : hexdec($permtree[$val]["permcathex"][2] . 0);
       $permtree[$val]["permcatchilren"] = 0;
       $permtree[$val]["permcatcount"]   = 0;
 
@@ -848,6 +903,61 @@ class TeamSpeak3_Node_Host extends TeamSpeak3_Node_Abstract
     TeamSpeak3_Helper_Signal::getInstance()->emit("notifyLogout", $this);
   }
 
+  /**
+   * Returns the number of ServerQuery logins on the selected virtual server.
+   *
+   * @return integer
+   */
+  public function queryCountLogin($pattern = null)
+  {
+    return current($this->execute("queryloginlist -count", array("duration" => 1, "pattern" => $pattern))->toList("count"));
+  }
+
+  /**
+   * Returns a list of ServerQuery logins on the selected virtual server. By default, the server spits out 25 entries
+   * at once.
+   *
+   * @param  integer $offset
+   * @param  integer $limit
+   * @return array
+   */
+  public function queryListLogin($offset = null, $limit = null, $pattern = null)
+  {
+    return $this->execute("queryloginlist -count", array("start" => $offset, "duration" => $limit, "pattern" => $pattern))->toAssocArray("cldbid");
+  }
+
+  /**
+   * Creates a new ServerQuery login, or enables ServerQuery logins for an existing client. When no virtual server is
+   * selected, the command will create global ServerQuery login. Otherwise a ServerQuery login will be added for an
+   * existing client (cldbid must be specified).
+   *
+   * @param  string  $username
+   * @param  integer $cldbid
+   * @return array
+   */
+  public function queryLoginCreate($username, $cldbid = 0)
+  {
+    if($this->serverSelectedId())
+    {
+      return $this->execute("queryloginadd", array("client_login_name" => $username, "cldbid" => $cldbid))->toList();
+    }
+    else
+    {
+      return $this->execute("queryloginadd", array("client_login_name" => $username))->toList();
+    }
+  }
+
+  /**
+   * Deletes an existing ServerQuery login.
+   *
+   * @param  integer $cldbid
+   * @return void
+   */
+  public function queryLoginDelete($cldbid)
+  {
+    $this->execute("querylogindel", array("cldbid" => $cldbid));
+  }
+
   /**
    * Returns information about your current ServerQuery connection.
    *

+ 24 - 14
protocol/TeamSpeak3/Node/Server.php

@@ -97,7 +97,7 @@ class TeamSpeak3_Node_Server extends TeamSpeak3_Node_Abstract
   {
     if($this->channelList === null)
     {
-      $channels = $this->request("channellist -topic -flags -voice -limits -icon")->toAssocArray("cid");
+      $channels = $this->request("channellist -topic -flags -voice -limits -icon -banners")->toAssocArray("cid");
 
       $this->channelList = array();
 
@@ -1008,7 +1008,7 @@ class TeamSpeak3_Node_Server extends TeamSpeak3_Node_Abstract
       $permident = (is_numeric(current($permid))) ? "permid" : "permsid";
     }
 
-    $this->execute("clientaddperm", array("cldbid" => $cldbid, $permident => $permid, "permvalue" => $permvalue, "permskip" => $permskip));
+    $this->execute("clientaddperm -continueonerror", array("cldbid" => $cldbid, $permident => $permid, "permvalue" => $permvalue, "permskip" => $permskip));
   }
 
   /**
@@ -1624,28 +1624,28 @@ class TeamSpeak3_Node_Server extends TeamSpeak3_Node_Abstract
     {
       switch($assignment["t"])
       {
-      	case TeamSpeak3::PERM_TYPE_SERVERGROUP:
-      		$this->serverGroupPermRemove($assignment["id1"], $assignment["p"]);
-      		break;
+        case TeamSpeak3::PERM_TYPE_SERVERGROUP:
+          $this->serverGroupPermRemove($assignment["id1"], $assignment["p"]);
+          break;
 
         case TeamSpeak3::PERM_TYPE_CLIENT:
-          $this->clientPermRemove($assignment["id2"], $assignment["p"]);
+          $this->clientPermRemove($assignment["id1"], $assignment["p"]);
           break;
 
         case TeamSpeak3::PERM_TYPE_CHANNEL:
-          $this->channelPermRemove($assignment["id2"], $assignment["p"]);
+          $this->channelPermRemove($assignment["id1"], $assignment["p"]);
           break;
 
         case TeamSpeak3::PERM_TYPE_CHANNELGROUP:
-          $this->channelGroupPermRemove($assignment["id1"], $assignment["p"]);
+          $this->channelGroupPermRemove($assignment["id2"], $assignment["p"]);
           break;
 
         case TeamSpeak3::PERM_TYPE_CHANNELCLIENT:
-          $this->channelClientPermRemove($assignment["id2"], $assignment["id1"], $assignment["p"]);
+          $this->channelClientPermRemove($assignment["id1"], $assignment["id2"], $assignment["p"]);
           break;
 
-      	default:
-      	  throw new TeamSpeak3_Adapter_ServerQuery_Exception("convert error", 0x604);
+        default:
+          throw new TeamSpeak3_Adapter_ServerQuery_Exception("convert error", 0x604);
       }
     }
 
@@ -1917,7 +1917,7 @@ class TeamSpeak3_Node_Server extends TeamSpeak3_Node_Abstract
         break;
     }
 
-    $detail = $this->request("serversnapshotdeploy -mapping " . $data)->toList();
+    $detail = $this->request("serversnapshotdeploy -mapping -keepfiles " . $data)->toList();
 
     if(isset($detail[0]["sid"]))
     {
@@ -2138,9 +2138,19 @@ class TeamSpeak3_Node_Server extends TeamSpeak3_Node_Abstract
    *
    * @return array
    */
-  public function banList()
+  public function banList($offset = null, $limit = null)
+  {
+    return $this->execute("banlist -count", array("start" => $offset, "duration" => $limit))->toAssocArray("banid");
+  }
+
+  /**
+   * Returns the number of bans on the selected virtual server.
+   *
+   * @return integer
+   */
+  public function banCount()
   {
-    return $this->request("banlist")->toAssocArray("banid");
+    return current($this->execute("banlist -count", array("duration" => 1))->toList("count"));
   }
 
   /**

+ 80 - 67
protocol/TeamSpeak3/TeamSpeak3.php

@@ -66,7 +66,7 @@ class TeamSpeak3
   /**
    * TeamSpeak 3 PHP Framework version.
    */
-  const LIB_VERSION = "1.1.34";
+  const LIB_VERSION = "1.1.35";
 
   /*@
    * TeamSpeak 3 protocol separators.
@@ -76,6 +76,13 @@ class TeamSpeak3
   const SEPARATOR_CELL = " ";  //!< protocol cell separator
   const SEPARATOR_PAIR = "=";  //!< protocol pair separator
 
+  /*@
+   * TeamSpeak 3 API key scopes.
+   */
+  const APIKEY_MANAGE = "manage";  //!< allow access to administrative calls
+  const APIKEY_WRITE  = "write";   //!< allow access to read and write calls
+  const APIKEY_READ   = "read";    //!< allow access to read-only calls
+
   /*@
    * TeamSpeak 3 log levels.
    */
@@ -337,90 +344,96 @@ class TeamSpeak3
 
     $object = new $adapter($options);
 
-    if($object instanceof TeamSpeak3_Adapter_ServerQuery)
-    {
-      $node = $object->getHost();
-
-      if($uri->hasUser() && $uri->hasPass())
+    try {
+      if($object instanceof TeamSpeak3_Adapter_ServerQuery)
       {
-        $node->login($uri->getUser(), $uri->getPass());
-      }
+        $node = $object->getHost();
 
-      if($uri->hasQueryVar("nickname"))
-      {
-        $node->setPredefinedQueryName($uri->getQueryVar("nickname"));
-      }
-
-      if($uri->getFragment() == "use_offline_as_virtual")
-      {
-        $node->setUseOfflineAsVirtual(TRUE);
-      }
-      elseif($uri->hasQueryVar("use_offline_as_virtual"))
-      {
-        $node->setUseOfflineAsVirtual($uri->getQueryVar("use_offline_as_virtual") ? TRUE : FALSE);
-      }
+        if($uri->hasUser() && $uri->hasPass())
+        {
+          $node->login($uri->getUser(), $uri->getPass());
+        }
 
-      if($uri->getFragment() == "clients_before_channels")
-      {
-        $node->setLoadClientlistFirst(TRUE);
-      }
-      elseif($uri->hasQueryVar("clients_before_channels"))
-      {
-        $node->setLoadClientlistFirst($uri->getQueryVar("clients_before_channels") ? TRUE : FALSE);
-      }
+        if($uri->hasQueryVar("nickname"))
+        {
+          $node->setPredefinedQueryName($uri->getQueryVar("nickname"));
+        }
 
-      if($uri->getFragment() == "no_query_clients")
-      {
-        $node->setExcludeQueryClients(TRUE);
-      }
-      elseif($uri->hasQueryVar("no_query_clients"))
-      {
-        $node->setExcludeQueryClients($uri->getQueryVar("no_query_clients") ? TRUE : FALSE);
-      }
+        if($uri->getFragment() == "use_offline_as_virtual")
+        {
+          $node->setUseOfflineAsVirtual(TRUE);
+        }
+        elseif($uri->hasQueryVar("use_offline_as_virtual"))
+        {
+          $node->setUseOfflineAsVirtual($uri->getQueryVar("use_offline_as_virtual") ? TRUE : FALSE);
+        }
 
-      if($uri->hasQueryVar("server_id"))
-      {
-        $node = $node->serverGetById($uri->getQueryVar("server_id"));
-      }
-      elseif($uri->hasQueryVar("server_uid"))
-      {
-        $node = $node->serverGetByUid($uri->getQueryVar("server_uid"));
-      }
-      elseif($uri->hasQueryVar("server_port"))
-      {
-        $node = $node->serverGetByPort($uri->getQueryVar("server_port"));
-      }
-      elseif($uri->hasQueryVar("server_name"))
-      {
-        $node = $node->serverGetByName($uri->getQueryVar("server_name"));
-      }
+        if($uri->getFragment() == "clients_before_channels")
+        {
+          $node->setLoadClientlistFirst(TRUE);
+        }
+        elseif($uri->hasQueryVar("clients_before_channels"))
+        {
+          $node->setLoadClientlistFirst($uri->getQueryVar("clients_before_channels") ? TRUE : FALSE);
+        }
 
-      if($node instanceof TeamSpeak3_Node_Server)
-      {
-        if($uri->hasQueryVar("channel_id"))
+        if($uri->getFragment() == "no_query_clients")
         {
-          $node = $node->channelGetById($uri->getQueryVar("channel_id"));
+          $node->setExcludeQueryClients(TRUE);
         }
-        elseif($uri->hasQueryVar("channel_name"))
+        elseif($uri->hasQueryVar("no_query_clients"))
         {
-          $node = $node->channelGetByName($uri->getQueryVar("channel_name"));
+          $node->setExcludeQueryClients($uri->getQueryVar("no_query_clients") ? TRUE : FALSE);
         }
 
-        if($uri->hasQueryVar("client_id"))
+        if($uri->hasQueryVar("server_id"))
         {
-          $node = $node->clientGetById($uri->getQueryVar("client_id"));
+          $node = $node->serverGetById($uri->getQueryVar("server_id"));
         }
-        if($uri->hasQueryVar("client_uid"))
+        elseif($uri->hasQueryVar("server_uid"))
         {
-          $node = $node->clientGetByUid($uri->getQueryVar("client_uid"));
+          $node = $node->serverGetByUid($uri->getQueryVar("server_uid"));
         }
-        elseif($uri->hasQueryVar("client_name"))
+        elseif($uri->hasQueryVar("server_port"))
         {
-          $node = $node->clientGetByName($uri->getQueryVar("client_name"));
+          $node = $node->serverGetByPort($uri->getQueryVar("server_port"));
+        }
+        elseif($uri->hasQueryVar("server_name"))
+        {
+          $node = $node->serverGetByName($uri->getQueryVar("server_name"));
+        }
+
+        if($node instanceof TeamSpeak3_Node_Server)
+        {
+          if($uri->hasQueryVar("channel_id"))
+          {
+            $node = $node->channelGetById($uri->getQueryVar("channel_id"));
+          }
+          elseif($uri->hasQueryVar("channel_name"))
+          {
+            $node = $node->channelGetByName($uri->getQueryVar("channel_name"));
+          }
+
+          if($uri->hasQueryVar("client_id"))
+          {
+            $node = $node->clientGetById($uri->getQueryVar("client_id"));
+          }
+          if($uri->hasQueryVar("client_uid"))
+          {
+            $node = $node->clientGetByUid($uri->getQueryVar("client_uid"));
+          }
+          elseif($uri->hasQueryVar("client_name"))
+          {
+            $node = $node->clientGetByName($uri->getQueryVar("client_name"));
+          }
         }
-      }
 
-      return $node;
+        return $node;
+      }
+    }
+    catch (Exception $e) {
+      $object->__destruct();
+      throw $e;
     }
 
     return $object;

+ 1 - 1
protocol/TeamSpeak3/Viewer/Html.php

@@ -337,7 +337,7 @@ class TeamSpeak3_Viewer_Html implements TeamSpeak3_Viewer_Interface
 
       if($this->currObj->spacerGetAlign() == TeamSpeak3::SPACER_ALIGN_REPEAT)
       {
-        $string->resize(30, $string);
+        if($string->count()) $string->resize(30, $string);
       }
 
       return htmlspecialchars($string);

+ 1 - 1
protocol/TeamSpeak3/Viewer/Json.php

@@ -386,7 +386,7 @@ class TeamSpeak3_Viewer_Json implements TeamSpeak3_Viewer_Interface
     elseif($this->currObj instanceof TeamSpeak3_Node_Channel)
     {
       $props->id       = $this->currObj->getId();
-      $props->icon     = $this->currObj->isSpacer() ? 0 : $this->currObj->channel_icon_id < 0 ? pow(2, 32)-($this->currObj->channel_icon_id*-1) : $this->currObj->channel_icon_id;
+      $props->icon     = ($this->currObj->isSpacer() ? 0 : $this->currObj->channel_icon_id < 0) ? pow(2, 32)-($this->currObj->channel_icon_id*-1) : $this->currObj->channel_icon_id;
       $props->path     = trim($this->currObj->getPathway());
       $props->topic    = strlen($this->currObj->channel_topic) ? trim($this->currObj->channel_topic) : null;
       $props->codec    = $this->currObj->channel_codec;