Ticket #2589: devstate.agi

File devstate.agi, 1.7 kB (added by naftali5, 1 year ago)
Line 
1 #!/usr/bin/env php
2 <?php
3
4 $config = parse_amportal_conf( "/etc/amportal.conf" );
5
6 require_once "phpagi.php";
7 require_once "phpagi-asmanager.php";
8
9 $debug = 4;
10
11 $rc             = "";           // Catch return code
12
13 $AGI = new AGI();
14 debug("Starting New devstate.agi", 1);
15
16 $priority = get_var( $AGI, "priority" ) + 1;
17 debug( "priority is $priority", 1 );
18
19 $extnum         = get_var( $AGI, "ARG1" );
20
21 if (empty($extnum))     $extnum         = 0;
22
23 debug("Devstate Check extnum:   '$extnum'", 4);
24
25 $extstate = is_ext_avail($extnum);
26 // get ExtensionState: 0-idle; 1-busy; 4-unavail; 8-ringing <--- these are unconfirmed
27 debug("Extension $extnum has ExtensionState: $extstate",1);
28 $AGI->set_variable('PEERDEVSTATE',$extstate);
29
30
31 // EOF devstate.agi
32 exit( 0 );
33
34 // helper functions
35 function get_var( $agi, $value)
36 {
37         $r = $agi->get_variable( $value );
38        
39         if ($r['result'] == 1)
40         {
41                 $result = $r['data'];
42                 return $result;
43         }
44         else
45                 return '';
46 }
47
48
49 function debug($string, $level=3)
50 {
51         global $AGI;
52         $AGI->verbose($string, $level);
53 }
54
55 function mycallback( $rc )
56 {
57         debug("User hung up. (rc=" . $rc . ")", 1);
58         exit ($rc);
59 }
60
61 function is_ext_avail( $extnum )
62 {
63         global $config;
64                
65         $astman = new AGI_AsteriskManager( );   
66         if (!$astman->connect("127.0.0.1", $config["AMPMGRUSER"] , $config["AMPMGRPASS"]))
67         {
68                 return false;
69         }
70        
71         $status = $astman->ExtensionState( $extnum, 'from-internal' );
72         $astman->disconnect();
73                
74         $status = $status['Status'];
75         debug("ExtensionState: $status", 4);
76         return $status;
77        
78 }
79
80 function parse_amportal_conf($filename)
81 {
82         $file = file($filename);
83         $matches = array();
84         $matchpattern = '/^\s*([a-zA-Z0-9]+)\s*=\s*(.*)\s*([;#].*)?/';
85         foreach ($file as $line)
86         {
87                 if (preg_match($matchpattern, $line, $matches))
88                 {
89                         $conf[ $matches[1] ] = $matches[2];
90                 }
91         }
92         return $conf;
93 }
94
95 ?>
Donate



Support
Download
Develop
Forums
News
Documentation
Paid Support
About

Paid Ads