class MediaSessions { /* connect to a mediaproxy dispatcher get media sessions and display them */ var $dispatcher_port = 25061; var $sessions = array(); var $relays = array(); var $timeout = 3; function MediaSessions ($dispatcher='',$allowedDomains=array(),$filters=array()) { if (!strlen($dispatcher)) return false; global $userAgentImages; global $userAgentImagesFile; if (!isset($userAgentImagesFile)) { $userAgentImagesFile="phone_images.php"; } require_once($userAgentImagesFile); $this->userAgentImages = $userAgentImages; $this->filters = $filters; $this->allowedDomains = $allowedDomains; list($ip,$port) = explode(":",$dispatcher); $this->dispatcher_ip = $ip; if ($port) $this->dispatcher_port = $port; return $this->getSessions(); } function getSessions () { if (!$this->dispatcher_ip) return false; if (!$this->dispatcher_port) return false; if ($fp = fsockopen ($this->dispatcher_ip, $this->dispatcher_port, $errno, $errstr, $this->timeout)) { printf ("
Connected to MediaProxy2 dispatcher %s:%s",$this->dispatcher_ip, $this->dispatcher_port); if (!count($this->allowedDomains)) { fputs($fp, "summary\r\n"); $line = fgets($fp); $this->relays = json_decode($line); } fputs($fp, "sessions\r\n"); $line = fgets($fp); $_sessions=json_decode($line); if (count($this->allowedDomains)) { foreach ($_sessions as $_session) { list($user1,$domain1)=explode("@",$_session->from_uri); list($user2,$domain2)=explode("@",$_session->to_uri); if (!in_array($domain1,$this->allowedDomains) && !in_array($domain2,$this->allowedDomains)) { continue; } if (strlen($this->filters['user'])) { $user=$this->filters['user']; if (preg_match("/$user/",$_session->from_uri) || preg_match("/$user/",$_session->to_uri) ) { $this->sessions[] = $_session; } } } } else { $this->sessions = $_sessions; } fclose($fp); return true; } else { printf ("
Error connecting to %s:%s: %s (%s) \n",$this->dispatcher_ip,$this->dispatcher_port,$errstr,$errno); return false; } } function showSearch() { if (!count($this->sessions)) return; printf ("