Ticket #1950: autoconf.php

File autoconf.php, 2.9 kB (added by thisboyiscrazy, 1 year ago)

autoconfig update from phone

Line 
1 #!/usr/bin/php -q
2 <?php 
3
4 // Copyright (C) 2003 Zac Sprackett <zsprackett-asterisk@sprackett.com>
5 //
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
10 //
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 // GNU General Public License for more details.
15 //
16 // Amended by Coalescent Systems Inc. Sept, 2004
17 // to include support for DND, Call Waiting, and CF to external trunk
18 // info@coalescentsystems.ca
19 //
20 // This script has been ported to PHP by
21 // Diego Iastrubni <diego.iastrubni@xorcom.com> and the freePBX community
22
23 //Change to freepbx dir
24 chdir("/var/www/localhost/htdocs/admin");
25
26 include("functions.inc.php");
27 include("modules/core/functions.inc.php");
28 include("modules/autoprovision/functions.inc.php");
29
30 $amp_conf = parse_amportal_conf( "/etc/amportal.conf" );
31 include("common/db_connect.php");
32
33 include("/var/lib/asterisk/agi-bin/phpagi.php");
34
35
36 $AGI = new AGI();
37
38 //Get the SIPURI this contains the temp extension and IP address
39 $sipuri = get_var( $AGI, "SIPURI" );
40 if (($sipuri = get_var( $AGI, "SIPURI" )) == '') {
41         debug("Unable to get SIPURI");
42         exit(1);
43 }
44
45 //Parse out the IP address
46 $parts = explode("@",$sipuri);
47 if (count($parts) != 2) {
48         debug("Unable to split SIPURI: $sipuri");
49         exit(1);
50 } else {
51         $ip = $parts[1];
52         debug( "IP $ip", 1 );
53 }
54
55 //Get the EXTEN we are setting the phone to
56 $exten = get_var($AGI,"EXTEN");
57 debug( "EXTEN $exten",1);
58
59 //Retrive the device infotmation from the database
60 $device = core_devices_get($exten);
61
62 if(!$device) {
63         $AGI->stream_file("that-number");
64         $AGI->stream_file("is-curntly-unavail");
65         debug("Doesnot exisit",1);
66         $AGI->hangup();
67         die (1);
68 }
69
70 //Translate the IP address into a MAC address
71 exec("arp -n | grep ^$ip ", $output);
72 foreach($output as $line) {
73         if (preg_match("/([0-9a-fA-F][0-9a-fA-F]:){5}([0-9a-fA-F][0-9a-fA-F])/", $line, $matches))
74                 $mac = strtolower( str_replace(":","",$matches[0]));
75 }
76
77 //Update database and config files
78 $device = $device['id'];
79 debug("DEVICE: $device MAC: $mac",1);
80 autoprovision_device_del($device,$mac);
81 autoprovision_mac_del($device,$mac);
82 autoprovision_device_add($device, $mac);
83
84 //Signal the phone is active and reboot
85 $AGI->stream_file("activated");
86 $AGI->hangup();
87 exec("/usr/sbin/asterisk -rx \"sip notify polycom-check-cfg $ip\"", $output);
88
89
90 // helper functions
91 function get_var( $agi, $value)
92 {
93         $r = $agi->get_variable( $value );
94        
95         if ($r['result'] == 1)
96         {
97                 $result = $r['data'];
98                 return $result;
99         }
100         else
101                 return '';
102 }
103
104 function debug($string, $level=1)
105 {
106         global $AGI;
107         $AGI->verbose($string, $level);
108 }
Donate



Support
Download
Develop
Forums
News
Documentation
Paid Support
About

Paid Ads