1 |
f1a7a397
|
Vinicius Coque
|
<?php
|
2 |
|
|
/*
|
3 |
|
|
getserviceproviders.php
|
4 |
|
|
Copyright (C) 2010 Vinicius Coque <vinicius.coque@bluepex.com>
|
5 |
|
|
All rights reserved.
|
6 |
|
|
|
7 |
|
|
Redistribution and use in source and binary forms, with or without
|
8 |
|
|
modification, are permitted provided that the following conditions are met:
|
9 |
|
|
|
10 |
|
|
1. Redistributions of source code must retain the above copyright notice,
|
11 |
|
|
this list of conditions and the following disclaimer.
|
12 |
|
|
|
13 |
|
|
2. Redistributions in binary form must reproduce the above copyright
|
14 |
|
|
notice, this list of conditions and the following disclaimer in the
|
15 |
|
|
documentation and/or other materials provided with the distribution.
|
16 |
|
|
|
17 |
|
|
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
18 |
|
|
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
19 |
|
|
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
20 |
|
|
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
21 |
|
|
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
22 |
|
|
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
23 |
|
|
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
24 |
|
|
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
25 |
|
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
26 |
|
|
POSSIBILITY OF SUCH DAMAGE.
|
27 |
|
|
*/
|
28 |
|
|
/*
|
29 |
|
|
pfSense_MODULE: ajax
|
30 |
|
|
*/
|
31 |
|
|
|
32 |
|
|
##|+PRIV
|
33 |
|
|
##|*IDENT=page-getserviceproviders
|
34 |
|
|
##|*NAME=AJAX: Get Service Providers
|
35 |
|
|
##|*DESCR=Allow access to the 'AJAX: Service Providers' page.
|
36 |
|
|
##|*MATCH=getserviceproviders.php*
|
37 |
|
|
##|-PRIV
|
38 |
84c07e65
|
Scott Ullrich
|
require_once("guiconfig.inc");
|
39 |
f1a7a397
|
Vinicius Coque
|
require_once("pfsense-utils.inc");
|
40 |
|
|
|
41 |
|
|
$serviceproviders_xml = "/usr/local/share/mobile-broadband-provider-info/serviceproviders.xml";
|
42 |
|
|
$serviceproviders_contents = file_get_contents($serviceproviders_xml);
|
43 |
|
|
$serviceproviders_attr = xml2array($serviceproviders_contents,1,"attr");
|
44 |
|
|
|
45 |
|
|
$serviceproviders = &$serviceproviders_attr['serviceproviders']['country'];
|
46 |
|
|
|
47 |
|
|
function get_country_providers($country) {
|
48 |
|
|
global $serviceproviders;
|
49 |
|
|
foreach($serviceproviders as $sp) {
|
50 |
|
|
if($sp['attr']['code'] == strtolower($country)) {
|
51 |
|
|
return is_array($sp['provider'][0]) ? $sp['provider'] : array($sp['provider']);
|
52 |
|
|
}
|
53 |
|
|
}
|
54 |
|
|
return $provider_list;
|
55 |
|
|
}
|
56 |
|
|
|
57 |
|
|
function country_list() {
|
58 |
|
|
global $serviceproviders;
|
59 |
|
|
$country_list = get_country_name("ALL");
|
60 |
|
|
foreach($serviceproviders as $sp) {
|
61 |
|
|
foreach($country_list as $country) {
|
62 |
|
|
if(strtoupper($sp['attr']['code']) == $country['code']) {
|
63 |
|
|
echo $country['name'] . ":" . $country['code'] . "\n";
|
64 |
|
|
}
|
65 |
|
|
}
|
66 |
|
|
}
|
67 |
|
|
}
|
68 |
|
|
|
69 |
|
|
function providers_list($country) {
|
70 |
|
|
$serviceproviders = get_country_providers($country);
|
71 |
|
|
foreach($serviceproviders as $sp) {
|
72 |
|
|
echo $sp['name']['value'] . "\n";
|
73 |
|
|
}
|
74 |
|
|
}
|
75 |
|
|
|
76 |
|
|
function provider_plan_data($country,$provider,$connection) {
|
77 |
6f3d2063
|
Renato Botelho
|
header("Content-type: application/xml;");
|
78 |
87aa8215
|
technical50
|
echo "<?xml version=\"1.0\" ?>\n";
|
79 |
f1a7a397
|
Vinicius Coque
|
echo "<connection>\n";
|
80 |
|
|
$serviceproviders = get_country_providers($country);
|
81 |
|
|
foreach($serviceproviders as $sp) {
|
82 |
|
|
if(strtolower($sp['name']['value']) == strtolower($provider)) {
|
83 |
|
|
if(strtoupper($connection) == "CDMA") {
|
84 |
|
|
$conndata = $sp['cdma'];
|
85 |
|
|
} else {
|
86 |
|
|
if(!is_array($sp['gsm']['apn'][0])) {
|
87 |
|
|
$conndata = $sp['gsm']['apn'];
|
88 |
|
|
} else {
|
89 |
|
|
foreach($sp['gsm']['apn'] as $apn) {
|
90 |
|
|
if($apn['attr']['value'] == $connection) {
|
91 |
|
|
$conndata = $apn;
|
92 |
|
|
break;
|
93 |
|
|
}
|
94 |
|
|
}
|
95 |
|
|
}
|
96 |
|
|
}
|
97 |
|
|
if(is_array($conndata)) {
|
98 |
|
|
echo "<apn>" . $connection . "</apn>\n";
|
99 |
|
|
echo "<username>" . $conndata['username']['value'] . "</username>\n";
|
100 |
|
|
echo "<password>" . $conndata['password']['value'] . "</password>\n";
|
101 |
|
|
|
102 |
|
|
$dns_arr = is_array($conndata['dns'][0]) ? $conndata['dns'] : array( $conndata['dns'] );
|
103 |
|
|
foreach($dns_arr as $dns) {
|
104 |
|
|
echo '<dns>' . $dns['value'] . "</dns>\n";
|
105 |
|
|
}
|
106 |
|
|
}
|
107 |
|
|
break;
|
108 |
|
|
}
|
109 |
|
|
}
|
110 |
|
|
echo "</connection>";
|
111 |
|
|
}
|
112 |
|
|
|
113 |
|
|
function provider_plans_list($country,$provider) {
|
114 |
|
|
$serviceproviders = get_country_providers($country);
|
115 |
|
|
foreach($serviceproviders as $sp) {
|
116 |
|
|
if(strtolower($sp['name']['value']) == strtolower($provider)) {
|
117 |
|
|
if(array_key_exists('gsm',$sp)) {
|
118 |
|
|
if(array_key_exists('attr',$sp['gsm']['apn'])) {
|
119 |
|
|
$name = ($sp['gsm']['apn']['name'] ? $sp['gsm']['apn']['name'] : $sp['name']['value']);
|
120 |
|
|
echo $name . ":" . $sp['gsm']['apn']['attr']['value'];
|
121 |
|
|
} else {
|
122 |
|
|
foreach($sp['gsm']['apn'] as $apn_info) {
|
123 |
|
|
$name = ($apn_info['name']['value'] ? $apn_info['name']['value'] : $apn_info['gsm']['apn']['name']);
|
124 |
|
|
echo $name . ":" . $apn_info['attr']['value'] . "\n";
|
125 |
|
|
}
|
126 |
|
|
}
|
127 |
|
|
}
|
128 |
|
|
if(array_key_exists('cdma',$sp)) {
|
129 |
|
|
$name = $sp['cdma']['name']['value'] ? $sp['cdma']['name']['value']:$sp['name']['value'];
|
130 |
|
|
echo $name . ":" . "CDMA";
|
131 |
|
|
}
|
132 |
|
|
}
|
133 |
|
|
}
|
134 |
|
|
}
|
135 |
|
|
|
136 |
219d9eb9
|
Darren Embry
|
$_GET_OR_POST = ($_SERVER['REQUEST_METHOD'] === 'POST') ? $_POST : $_GET;
|
137 |
|
|
|
138 |
|
|
if(isset($_GET_OR_POST['country']) && !isset($_GET_OR_POST['provider'])) {
|
139 |
|
|
providers_list($_GET_OR_POST['country']);
|
140 |
|
|
} elseif(isset($_GET_OR_POST['country']) && isset($_GET_OR_POST['provider'])) {
|
141 |
|
|
if(isset($_GET_OR_POST['plan']))
|
142 |
|
|
provider_plan_data($_GET_OR_POST['country'],$_GET_OR_POST['provider'],$_GET_OR_POST['plan']);
|
143 |
f1a7a397
|
Vinicius Coque
|
else
|
144 |
219d9eb9
|
Darren Embry
|
provider_plans_list($_GET_OR_POST['country'],$_GET_OR_POST['provider']);
|
145 |
f1a7a397
|
Vinicius Coque
|
} else {
|
146 |
|
|
country_list();
|
147 |
|
|
}
|
148 |
|
|
?>
|