root/freepbx/branches/experimental/amp_conf/htdocs/panel/managerproxy.php

Revision 2140, 1.4 kB (checked in by gregmac, 2 years ago)

Initial work on DhtmlOperatorPanel

  • Property svn:mime-type set to text/plain
  • Property svn:eol-style set to native
  • Property svn:executable set to *
Line 
1 <?php
2 /** $Id$
3  * FreePBX DHTML Operator Panel
4  *
5  * @package     FreePBX
6  * @author      Greg MacLellan
7  * @copyright   Copyright (c) 2006, Greg MacLellan
8  * @license     GPL
9  * @link        http://www.freepbx.org/trac/wiki/DhtmlOperatorPanel
10 */
11
12 class ManagerProxy {
13         var $server;
14         var $port;
15         var $socket;
16
17         var $handlers;
18        
19         var $buf = "";
20        
21         function ManagerProxy($server,$port) {
22                 $this->server = $server;
23                 $this->port = $port;
24         }
25
26         function connect() {
27                 if (!$this->socket = fsockopen($this->server, $this->port, $errno, $errstr, 10)) {
28                         return false;
29                 }
30                
31         }
32
33         function set_handler($callback) {
34                 $this->handler = $callback;
35         }
36
37         function wait_read($timeout = 10) {
38                 socket_set_timeout($this->socket, $timeout);
39        
40                 // read up to \n , or error
41                 $read = @ fgets($this->socket, 4096);
42                 if ($read === false) {
43                         return false;
44                 } else if ($read === "") {
45                         // timeout
46                         return true;
47                 } else {
48                         $this->buf .= $read;
49                         if (($read[strlen($read)-1] == "\n") || ($read[strlen($read)-1] == "\r")) {
50                                 // handle it
51                                 $this->handle_data(trim($this->buf));
52                                 $this->buf = '';
53                         }
54                         return true;
55                 }
56         }
57
58         function handle_data($data) {
59                 if ($arr = unserialize($data)) {
60                         if (!isset($arr['Event'])) {
61                                 return false;
62                         }
63                        
64                         if (isset($this->handler) && function_exists($this->handler)) {
65                                 // have a callback
66                                 $handler = $this->handler;
67                                 // run callback
68                                 $handler($arr['Event'], $arr);
69                         }
70                 }
71                 return false;
72                
73         }
74 }
75
76
77 ?>
Note: See TracBrowser for help on using the browser.
Donate



Support
Download
Develop
Forums
News
Documentation
Paid Support
About

Paid Ads