root/modules/branches/2.8/sipstation/edittrunk.html.php

Revision 8417, 4.2 kB (checked in by p_lindheimer, 4 years ago)

new sipstation module to auto-configure and monitor FreePBX.com SIP trunks and service

  • Property svn:executable set to *
Line 
1 <?php
2 /* $Id:$ */
3
4 /* Copyright (c) 2009 Bandwidth.com
5    Licensed for use by active FreePBX.com SIP Trunking Customers (SIPSTATION(tm)). Not licensed to be modified or redistributed in any fashion.
6    No guarantees or warranties provided, use at your own risk. See license included with module for more details.
7 */
8
9 // TODO: set this in production
10 error_reporting(0);
11
12 include_once('sipstation.utility.php');
13
14 if (! @include_once("common/json.inc.php")) {
15   $quietmode=1;
16   include_once("/var/www/html/admin/common/json.inc.php");
17   include_once("/var/www/html/admin/functions.inc.php");
18   $amp_conf = parse_amportal_conf("/etc/amportal.conf");
19   include_once("/var/www/html/admin/common/db_connect.php");
20   include_once("/var/www/html/admin/modules/core/functions.inc.php");
21   if (!isset($active_modules)) {
22     $active_modules = array();
23   }
24 }
25 /* For testing:
26 *//*
27 include_once("common/json.inc.php");
28 */
29
30 /* We can use the cached config data as we were just told that
31    trunk params have changed and chose to update
32  */
33
34 $filter = array(
35   'sip_username' => true,
36   'sip_password' => true,
37   'gateways' => true,
38   'asterisk_settings' => true,
39 );
40 $current_config = sipstation_get_config("xxx", false, $filter);
41
42 $need_reload = false;
43
44 $sip_user = $current_config['sip_username'];
45 $sip_pass = $current_config['sip_password'];
46
47 $tlist       = core_trunks_list(true);
48 $tech        = 'sip';
49
50 $peer_array = array();
51 foreach ($current_config['asterisk_settings']['peer'] as $param) {
52   $peerdetails .= trim($param)."\n";
53   $parts = explode('=',$param,2);
54   $peer_array[$parts[0]] = $parts[1];
55 }
56 $peerdetails .= "username=$sip_user\nsecret=$sip_pass\nhost=";
57 $register    = "$sip_user:$sip_pass@";
58
59 for ($i=1;$i<3;$i++) {
60   $gidx = "gw$i";
61   $channelid   = "fpbx-$i-$sip_user";
62   $gw          = $current_config['gateways'][$gidx];
63   if (isset($tlist["SIP/$channelid"])) {
64     $json_array['status'] = 'success';
65     if (!isset($_POST[$gidx]) || $_POST[$gidx] != 'yes') {
66       continue;
67     }
68     $globalvar = $tlist["SIP/$channelid"]['globalvar'];
69     $trunknum  = ltrim($globalvar,'OUT_');
70     $trunk_details = core_trunks_getDetails($trunknum);
71     $userconfig = core_trunks_getTrunkUserConfig($trunknum);
72     $old_peerdetails = explode("\n",core_trunks_getTrunkPeerDetails($trunknum));
73     foreach ($old_peerdetails as $param) {
74       $parts = explode('=',$param,2);
75       switch (strtolower(trim($parts[0]))) {
76         case 'allow':
77           $allow = "allow=".$parts[1]."\n";
78         break;
79         case 'disallow':
80           $disallow = "disallow=".$parts[1]."\n";
81         break;
82       }
83     }
84     $peer_stuff = $peerdetails.$gw."\n".$disallow.$allow;
85     $reg = $register.$gw;
86
87     /* Extract the allow/disallow now
88     */
89     $tech = $trunk_details['tech'];
90     $outcid = $trunk_details['outcid'];
91     $maxchans = $trunk_details['maxchans'];
92     $dialoutprefix = $trunk_details['dialoutprefix'];
93     $keepcid = $trunk_details['keepcid'];
94     $failtrunk = $trunk_details['failscript'];
95     $disabletrunk = $trunk_details['disabled'];
96
97     // TODO: trunk_name, provider with 2.6
98     /*
99     $provider = $trunk_details['provider'];
100     $trunk_name = $trunk_details['name'];
101     */
102       core_trunks_edit($trunknum, $channelid, $dialoutprefix, $maxchans, $outcid, $peer_stuff, $usercontext, $userconfig, $reg, $keepcid, $failtrunk, $disabletrunk);
103     $need_reload = true;
104     $json_array['status'] = 'success';
105     $json_array['trunk_updated'][$gidx] = $trunknum;
106   }
107 }
108
109 /*
110   if we made changes then we have to set the needsreload status and send back the reload bar to be inserted
111 */
112 if ($need_reload) {
113   needreload();
114   if ($_POST['send_reload'] == 'yes') {
115     ob_start();
116     if (!@include ('views/freepbx_reloadbar.php')) {
117       @include ('../../views/freepbx_reloadbar.php'); //TODO for debugging
118     }
119     $json_array['reload_bar'] = ob_get_clean();
120     ob_start();
121     if (!@include ('views/freepbx_reload.php')) {
122       @include ('../../views/freepbx_reload.php'); //TODO for debugging
123     }
124     $json_array['reload_header'] = ob_get_clean();
125   }
126   $json_array['show_reload'] = 'yes';
127 } else {
128   $json_array['show_reload'] = 'no';
129 }
130
131 $json = new Services_JSON();
132 $value = $json->decode($_POST);
133
134 header("Content-type: application/json");
135 echo $json->encode($json_array);
136
Note: See TracBrowser for help on using the browser.