<?php
/**
<ul>
<li>Mumble</li>
<li></li>
<li>LICENSE</li>
<li></li>
<li>This source file is owned by LessThinking and may NOT be modified,</li>
<li>resold, rehosted etc. without written permission from LessThinking.</li>
<li>If you brought this from someone other than the LessThinking company,</li>
<li>please email legal@lessthinking.com, thank you.</li>
<li></li>
<li>Prof of concept</li>
<li></li>
<li>@author Mads Madsen</li>
<li>@package Mumble</li>
<li>@copyright 2008, 2009</li>
</ul>
*/
class Mumble
{
protected $_address = null;
protected $_port = 0;
protected $_glacierAddress = null;
protected $_glacierPort = 0;
protected $_glacierUsername = null;
protected $_glacierPassword = null;
protected $_useGlacier = false;
protected $_glacierRouter = null;
protected $_connection = null;
protected $_meta = null;
protected $_server = null;
protected $_player = null;
protected $ice;
public $lastError = '';
public function __construct($address = null, $port = null,
$glacierAddress = null, $glacierPort = null,
$glacierUsername = null, $glacierPassword = null)
{
if (!empty($address))
{
$this->setAddress($address);
}
if (!empty($port))
{
$this->setPort($port);
}
if (!empty($glacierAddress))
{
$this->setGlacierAddress($glacierAddress);
}
if (!empty($glacierPort))
{
$this->setGlacierPort($glacierPort);
}
if (!empty($glacierUsername))
{
$this->setGlacierUsername($glacierUsername);
}
if (!empty($glacierPassword))
{
$this->setGlacierPassword($glacierPassword);
}
Ice_loadProfile();
global $ICE;
$this->ice = $ICE;
}
public function setAddress($address)
{
$this->_address = $address;
return $this;
}
public function setPort($port = null) {
$this->_port = $port;
return $this;
}
public function setGlacierAddress($glacierAddress = null)
{
$this->_glacierAddress = $glacierAddress;
return $this;
}
public function setGlacierPort($glacierPort = null)
{
$this->_glacierPort = $glacierPort;
return $this;
}
public function setGlacierUsername($glacierUsername = null)
{
$this->_glacierUsername = $glacierUsername;
return $this;
}
public function setGlacierPassword($glacierPassword = null)
{
$this->_glacierPassword = $glacierPassword;
return $this;
}
private function error($ex)
{
;
}
public function connect()
{
if(empty($this->_address))
{
return false;
}
if (empty($this->_port))
{
return false;
}
if (!empty($this->_glacierAddress) && !empty($this->_glacierPort) && !empty($this->_glacierPassword))
{
$this->_useGlacier = true;
}
$return = null;
$this->_useGlacier == true ? $return = $this->glacierConnect() : $return = $this->directConnect();
return $return;
}
private function glacierConnect()
{
try
{
$router = $this->ice->stringToProxy("Glacier2/router:tcp -p ".$this->_glacierPort . " -h ".$this->_glacierAddress);
$this->_glacierRouter = $router->ice_uncheckedCast("::Glacier2::Router")->ice_router(null);
unset($router);
try
{
$this->_glacierRouter->createSession($this->_glacierUsername, $this->_glacierPassword);
}
catch (Ice_UnknownLocalException $ex)
{
$this->lastError = $ex->unknown;
return false;
}
catch (Glacier2_PermissionDeniedException $ex)
{
$this->lastError = "Wrong combination of Glacier username and password.";
return false;
}
$this->_connection = $this->ice->stringToProxy("Meta:tcp -h ".$this->_address." -p ".$this->_port)->ice_router($this->_glacierRouter);
$this->_meta = $this->_connection->ice_checkedCast("::Murmur::Meta")->ice_router($this->_glacierRouter);
return true;
}
catch (Ice_Exception $ex)
{
$this->error($ex);
}
}
private function directConnect()
{
try
{
$this->_connection = $this->ice->stringToProxy("Meta:tcp -h ".$this->_address." -p ".$this->_port);
try
{
$this->_meta = $this->_connection->ice_checkedCast("::Murmur::Meta");
return true;
}
catch (Ice_UnknownLocalException $ex)
{
$this->lastError = $ex->unknown;
return false;
}
}
catch (Ice_Exception $ex)
{
$this->error($ex);
}
}
public function newServer()
{
try
{
$serverData = $this->_meta->newServer();
$result = explode(" ", $serverData);
$result = explode("/", $result[0]);
$result = $result[1];
return $result;
}
catch (Ice_Exception $ex)
{
$this->error($ex);
}
return false;
}
public function getAllServers()
{
try
{
$_servers = $this->_meta->getAllServers();
$servers = array();
if($this->_useGlacier === true)
{
$i = 0;
foreach ($_servers as $s)
{
$servers[$i]['id'] = $s->ice_router($this->_glacierRouter)->id();
$servers[$i]['running'] = $s->ice_router($this->_glacierRouter)->isRunning();
$i++;
}
}
else
{
$i = 0;
foreach ($_servers as $s)
{
$servers[$i]['id'] = $s->id();
$servers[$i]['running'] = $s->isRunning();
$i++;
}
}
return $servers;
}
catch (Ice_Exception $ex)
{
$this->error($ex);
}
return false;
}
public function setServer($id)
{
try
{
$this->_server = $this->_meta->getServer($id);
return true;
}
catch (Ice_UnknownLocalException $ex)
{
$this->error($ex);
}
return $this;
}
public function getDefaultConf()
{
try
{
return $this->_meta->getDefaultConf();
}
catch (Ice_Exception $ex)
{
$this->error($ex);
}
return false;
}
public function isRunning()
{
try
{
if ($this->_useGlacier === true)
{
return $this->_server->ice_router($this->_glacierRouter)->isRunning();
}
else
{
return $this->_server->isRunning();
}
}
catch (Ice_Exception $ex)
{
$this->error($ex);
}
return false;
}
public function startServer()
{
if($this->isRunning() === false)
{
if($this->_useGlacier === true)
{
return $this->_server->ice_router($this->_glacierRouter)->start();
}
else
{
return $this->_server->start();
}
}
return false;
}
public function stopServer()
{
if($this->isRunning() === true)
{
if($this->_useGlacier === true)
{
return $this->_server->ice_router($this->_glacierRouter)->stop();
}
else
{
return $this->_server->stop();
}
}
return false;
}
public function deleteServer()
{
if($this->isRunning() === true)
{
$this->stopServer();
}
if($this->_useGlacier === true)
{
return $this->_server->ice_router($this->_glacierRouter)->delete();
}
else
{
return $this->_server->delete();
}
}
public function getConf($conf)
{
try
{
if($this->_useGlacier === true)
{
return $this->_server->ice_router($this->_glacierRouter)->getConf($conf);
}
else
{
return $this->_server->getConf($conf);
}
}
catch (Ice_Exception $ex)
{
$this->error($ex);
}
return false;
}
public function getAllConf()
{
$conf = array(
'bandwidth' => null,
'password' => null,
'port' => null,
'users' => null,
'welcometext' => null
);
$confitems = array('bandwidth', 'password', 'port', 'users', 'welcometext');
$defaultConf = $this->getDefaultConf();
foreach ($confitems as $value) {
$conf[$value] = $this->getConf($value);
if(empty($conf[$value])) $conf[$value] = $defaultConf[$value];
}
return $conf;
}
public function setConf($key, $value)
{
try
{
$value = stripslashes($value);
if($this->_useGlacier === true)
{
return $this->_server->ice_router($this->_glacierRouter)->setConf($key, $value);
}
else
{
return $this->_server->setConf($key, $value);
}
}
catch (Ice_Exception $ex)
{
$this->error($ex);
}
return false;
}
public function setSuperuserPassword($pw)
{
try
{
if ($this->_useGlacier === true)
{
return $this->_server->ice_router($this->_glacierRouter)->setSuperuserPassword($pw);
}
else
{
return $this->_server->setSuperuserPassword($pw);
}
}
catch (Ice_Exception $ex)
{
$this->error($ex);
}
return false;
}
public function getPlayers()
{
try
{
$players = array();
$playerMap = null;
if($this->_useGlacier === true)
{
$playerMap = $this->_server->ice_router($this->_glacierRouter)->getPlayers();
}
else
{
$playerMap = $this->_server->getPlayers();
}
$i = 0;
foreach ($playerMap as $player)
{
foreach ($player as $key => $value)
{
$players[$i][$key] = $value;
}
$i++;
}
return $players;
}
catch (Ice_Exception $ex)
{
$this->error($ex);
}
return false;
}
public function getChannels()
{
try
{
$channels = array();
$channelMap = null;
if($this->_useGlacier === true)
{
$channelMap = $this->_server->ice_router($this->_glacierRouter)->getChannels();
}
else
{
$channelMap = $this->_server->getChannels();
}
$i = 0;
foreach ($channelMap as $channel)
{
foreach ($channel as $key => $value)
{
$channels[$i][$key] = $value;
}
$i++;
}
return $channels;
}
catch (Ice_Exception $ex)
{
$this->error($ex);
}
return false;
}
public function getBans()
{
try
{
$bans = array();
$banList = null;
if ($this->_useGlacier === true)
{
$banList = $this->_server->ice_router($this->_glacierRouter)->getBans();
}
else
{
$banList = $this->_server->getBans();
}
$i = 0;
foreach ($banList as $ban)
{
foreach ($ban as $key => $value)
{
$bans[$i][$key] = $value;
}
$i++;
}
return $bans;
}
catch (Ice_Exception $ex)
{
$this->error($ex);
}
return false;
}
public function newPlayer($name, $pw, $email = null)
{
try
{
$_id = null;
$user = null;
if ($this->_useGlacier === true)
{
$_id = $this->_server->ice_router($this->_glacierRouter)->registerPlayer($name);
$user = $this->_server->ice_router($this->_glacierRouter)->getRegistration($_id);
}
else
{
$_id = $this->_server->registerPlayer($name);
$user = $this->_server->getRegistration($_id);
}
$user->pw = $pw;
$user->email = $email;
if ($this->_useGlacier === true)
{
$this->_server->ice_router($this->_glacierRouter)->updateRegistration($user);
}
else
{
$this->_server->updateRegistration($user);
}
return $_id;
}
catch (Ice_Exception $ex)
{
$this->error($ex);
}
return false;
}
public function getRegisteredPlayers()
{
try
{
$playerIds = array();
if ($this->_useGlacier === true)
{
$idMap = $this->_server->ice_router($this->_glacierRouter)->getRegisteredPlayers("");
}
else
{
$idMap = $this->_server->getRegisteredPlayers("");
}
foreach ($idMap as $id)
{
$_tmpData = array();
foreach ($id as $_key => $_value)
{
$_tmpData[$_key] = $_value;
}
$playerIds[] = $_tmpData;
}
return $playerIds;
}
catch (Ice_Exception $ex)
{
$this->error($ex);
}
return false;
}
public function getRegisteredPlayer($name)
{
try
{
$player = array();
if ($this->_useGlacier === true)
{
$idMap = $this->_server->ice_router($this->_glacierRouter)->getRegisteredPlayers($name);
}
else
{
$idMap = $this->_server->getRegisteredPlayers($name);
}
foreach ($idMap as $id)
{
$_tmpData = array();
foreach ($id as $_key => $_value)
{
$_tmpData[$_key] = $_value;
}
$player = $_tmpData;
}
return $player;
}
catch (Ice_Exception $ex)
{
$this->error($ex);
}
return false;
}
public function updatePlayer($name, $pw = null, $email = '')
{
try
{
$playerData = $this->getRegisteredPlayer($name);
if(count($playerData) === 0) return false;
$_id = $playerData['playerid'];
if($this->_useGlacier === true)
{
$user = $this->_server->ice_router($this->_glacierRouter)->getRegistration($_id);
}
else
{
$user = $this->_server->getRegistration($_id);
}
if(!empty($pw)) $user->pw = $pw;
$user->email = $email;
if($this->_useGlacier === true)
{
return $this->_server->ice_router($this->_glacierRouter)->updateRegistration($user);
}
else
{
return $this->_server->updateRegistration($user);
}
}
catch (Ice_Exception $ex)
{
$this->error($ex);
}
return false;
}
public function deletePlayer($name)
{
try
{
$playerData = $this->getRegisteredPlayer($name);
if(count($playerData) === 0) return false;
$_id = $playerData['playerid'];
if($this->_useGlacier === true)
{
return $this->_server->ice_router($this->_glacierRouter)->unregisterPlayer($_id);
}
else
{
return $this->_server->unregisterPlayer($_id);
}
}
catch (Ice_Exception $ex)
{
$this->error($ex);
}
return false;
}
public function getAcl($channelId = 0)
{
try
{
$acls = array('acls' => array(), 'groups' => array(), 'inherit' => false);
$_acls = null;
$_groups = null;
$_inherit = null;
if ($this->_useGlacier === true)
{
$this->_server->ice_router($this->_glacierRouter)->getACL($channelId, $_acls, $_groups, $_inherit);
}
else
{
$this->_server->getACL($channelId, $_acls, $_groups, $_inherit);
}
if(!empty($_acls)) {
foreach ($_acls as $acl)
{
$_tmpData = array();
foreach ($acl as $_key => $_value)
{
$_tmpData[$_key] = $_value;
}
$acls['acls'][] = $_tmpData;
}
}
if(!empty($_groups)) {
foreach ($_groups as $group)
{
$_tmpData = array();
foreach ($group as $_key => $_value)
{
$_tmpData[$_key] = $_value;
}
$acls['groups'][] = $_tmpData;
}
}
$acls['inherit'] = $_inherit;
return $acls;
}
catch (Ice_Exception $ex)
{
$this->error($ex);
}
return false;
}
public function setAcl($channelId, $acl)
{
try
{
$acls = null;
foreach ($acl['acls'] as $aclPart)
{
$part = new Murmur_ACL();
foreach ($aclPart as $key => $val)
{
$part->$key = $val;
}
$acls[] = $part;
unset($part);
}
$groups = null;
foreach ($acl['groups'] as $groupPart)
{
$part = new Murmur_Group();
foreach ($groupPart as $key => $val)
{
$part->$key = $val;
}
$groups[] = $part;
unset($part);
}
if ($this->_useGlacier === true)
{
$this->_server->ice_router($this->_glacierRouter)->setACL($channelId, $acls, $groups, $acl['inherit']);
}
else
{
$this->_server->setACL($channelId, $acls, $groups, $acl['inherit']);
}
}
catch (Ice_Exception $ex)
{
$this->error($ex);
}
return false;
}
}
Reply