1 |
f1a7a397
|
Vinicius Coque
|
<?php
|
2 |
|
|
/*
|
3 |
45b4ffc6
|
Phil Davis
|
getserviceproviders.php
|
4 |
f1a7a397
|
Vinicius Coque
|
*/
|
5 |
fd9ebcd5
|
Stephen Beaver
|
/* ====================================================================
|
6 |
919d91f9
|
Phil Davis
|
* Copyright (c) 2004-2015 Electric Sheep Fencing, LLC. All rights reserved.
|
7 |
fd9ebcd5
|
Stephen Beaver
|
* Copyright (c) 2010 Vinicius Coque <vinicius.coque@bluepex.com>
|
8 |
|
|
*
|
9 |
919d91f9
|
Phil Davis
|
* Redistribution and use in source and binary forms, with or without modification,
|
10 |
|
|
* are permitted provided that the following conditions are met:
|
11 |
fd9ebcd5
|
Stephen Beaver
|
*
|
12 |
|
|
* 1. Redistributions of source code must retain the above copyright notice,
|
13 |
|
|
* this list of conditions and the following disclaimer.
|
14 |
|
|
*
|
15 |
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
16 |
|
|
* notice, this list of conditions and the following disclaimer in
|
17 |
|
|
* the documentation and/or other materials provided with the
|
18 |
919d91f9
|
Phil Davis
|
* distribution.
|
19 |
fd9ebcd5
|
Stephen Beaver
|
*
|
20 |
919d91f9
|
Phil Davis
|
* 3. All advertising materials mentioning features or use of this software
|
21 |
fd9ebcd5
|
Stephen Beaver
|
* must display the following acknowledgment:
|
22 |
|
|
* "This product includes software developed by the pfSense Project
|
23 |
919d91f9
|
Phil Davis
|
* for use in the pfSense software distribution. (http://www.pfsense.org/).
|
24 |
fd9ebcd5
|
Stephen Beaver
|
*
|
25 |
|
|
* 4. The names "pfSense" and "pfSense Project" must not be used to
|
26 |
|
|
* endorse or promote products derived from this software without
|
27 |
|
|
* prior written permission. For written permission, please contact
|
28 |
|
|
* coreteam@pfsense.org.
|
29 |
|
|
*
|
30 |
|
|
* 5. Products derived from this software may not be called "pfSense"
|
31 |
|
|
* nor may "pfSense" appear in their names without prior written
|
32 |
|
|
* permission of the Electric Sheep Fencing, LLC.
|
33 |
|
|
*
|
34 |
|
|
* 6. Redistributions of any form whatsoever must retain the following
|
35 |
|
|
* acknowledgment:
|
36 |
|
|
*
|
37 |
|
|
* "This product includes software developed by the pfSense Project
|
38 |
|
|
* for use in the pfSense software distribution (http://www.pfsense.org/).
|
39 |
|
|
*
|
40 |
|
|
* THIS SOFTWARE IS PROVIDED BY THE pfSense PROJECT ``AS IS'' AND ANY
|
41 |
|
|
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
42 |
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
43 |
|
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE pfSense PROJECT OR
|
44 |
|
|
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
45 |
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
46 |
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
47 |
|
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
48 |
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
49 |
|
|
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
50 |
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
51 |
|
|
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
52 |
|
|
*
|
53 |
|
|
* ====================================================================
|
54 |
|
|
*
|
55 |
|
|
*/
|
56 |
f1a7a397
|
Vinicius Coque
|
|
57 |
|
|
##|+PRIV
|
58 |
|
|
##|*IDENT=page-getserviceproviders
|
59 |
|
|
##|*NAME=AJAX: Get Service Providers
|
60 |
|
|
##|*DESCR=Allow access to the 'AJAX: Service Providers' page.
|
61 |
|
|
##|*MATCH=getserviceproviders.php*
|
62 |
|
|
##|-PRIV
|
63 |
84c07e65
|
Scott Ullrich
|
require_once("guiconfig.inc");
|
64 |
f1a7a397
|
Vinicius Coque
|
require_once("pfsense-utils.inc");
|
65 |
|
|
|
66 |
|
|
$serviceproviders_xml = "/usr/local/share/mobile-broadband-provider-info/serviceproviders.xml";
|
67 |
|
|
$serviceproviders_contents = file_get_contents($serviceproviders_xml);
|
68 |
6c07db48
|
Phil Davis
|
$serviceproviders_attr = xml2array($serviceproviders_contents, 1, "attr");
|
69 |
f1a7a397
|
Vinicius Coque
|
|
70 |
|
|
$serviceproviders = &$serviceproviders_attr['serviceproviders']['country'];
|
71 |
|
|
|
72 |
|
|
function get_country_providers($country) {
|
73 |
|
|
global $serviceproviders;
|
74 |
45b4ffc6
|
Phil Davis
|
foreach ($serviceproviders as $sp) {
|
75 |
|
|
if ($sp['attr']['code'] == strtolower($country)) {
|
76 |
f1a7a397
|
Vinicius Coque
|
return is_array($sp['provider'][0]) ? $sp['provider'] : array($sp['provider']);
|
77 |
|
|
}
|
78 |
|
|
}
|
79 |
|
|
return $provider_list;
|
80 |
|
|
}
|
81 |
|
|
|
82 |
|
|
function country_list() {
|
83 |
|
|
global $serviceproviders;
|
84 |
|
|
$country_list = get_country_name("ALL");
|
85 |
45b4ffc6
|
Phil Davis
|
foreach ($serviceproviders as $sp) {
|
86 |
|
|
foreach ($country_list as $country) {
|
87 |
|
|
if (strtoupper($sp['attr']['code']) == $country['code']) {
|
88 |
f1a7a397
|
Vinicius Coque
|
echo $country['name'] . ":" . $country['code'] . "\n";
|
89 |
|
|
}
|
90 |
|
|
}
|
91 |
|
|
}
|
92 |
|
|
}
|
93 |
|
|
|
94 |
|
|
function providers_list($country) {
|
95 |
|
|
$serviceproviders = get_country_providers($country);
|
96 |
45b4ffc6
|
Phil Davis
|
foreach ($serviceproviders as $sp) {
|
97 |
f1a7a397
|
Vinicius Coque
|
echo $sp['name']['value'] . "\n";
|
98 |
|
|
}
|
99 |
|
|
}
|
100 |
|
|
|
101 |
6c07db48
|
Phil Davis
|
function provider_plan_data($country, $provider, $connection) {
|
102 |
6f3d2063
|
Renato Botelho
|
header("Content-type: application/xml;");
|
103 |
cd94a9a8
|
Renato Botelho
|
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
|
104 |
f1a7a397
|
Vinicius Coque
|
echo "<connection>\n";
|
105 |
|
|
$serviceproviders = get_country_providers($country);
|
106 |
45b4ffc6
|
Phil Davis
|
foreach ($serviceproviders as $sp) {
|
107 |
|
|
if (strtolower($sp['name']['value']) == strtolower($provider)) {
|
108 |
|
|
if (strtoupper($connection) == "CDMA") {
|
109 |
f1a7a397
|
Vinicius Coque
|
$conndata = $sp['cdma'];
|
110 |
|
|
} else {
|
111 |
45b4ffc6
|
Phil Davis
|
if (!is_array($sp['gsm']['apn'][0])) {
|
112 |
f1a7a397
|
Vinicius Coque
|
$conndata = $sp['gsm']['apn'];
|
113 |
|
|
} else {
|
114 |
45b4ffc6
|
Phil Davis
|
foreach ($sp['gsm']['apn'] as $apn) {
|
115 |
|
|
if ($apn['attr']['value'] == $connection) {
|
116 |
f1a7a397
|
Vinicius Coque
|
$conndata = $apn;
|
117 |
|
|
break;
|
118 |
|
|
}
|
119 |
|
|
}
|
120 |
|
|
}
|
121 |
|
|
}
|
122 |
45b4ffc6
|
Phil Davis
|
if (is_array($conndata)) {
|
123 |
f1a7a397
|
Vinicius Coque
|
echo "<apn>" . $connection . "</apn>\n";
|
124 |
|
|
echo "<username>" . $conndata['username']['value'] . "</username>\n";
|
125 |
|
|
echo "<password>" . $conndata['password']['value'] . "</password>\n";
|
126 |
|
|
|
127 |
6c07db48
|
Phil Davis
|
$dns_arr = is_array($conndata['dns'][0]) ? $conndata['dns'] : array($conndata['dns']);
|
128 |
45b4ffc6
|
Phil Davis
|
foreach ($dns_arr as $dns) {
|
129 |
f1a7a397
|
Vinicius Coque
|
echo '<dns>' . $dns['value'] . "</dns>\n";
|
130 |
|
|
}
|
131 |
|
|
}
|
132 |
|
|
break;
|
133 |
|
|
}
|
134 |
|
|
}
|
135 |
|
|
echo "</connection>";
|
136 |
|
|
}
|
137 |
|
|
|
138 |
6c07db48
|
Phil Davis
|
function provider_plans_list($country, $provider) {
|
139 |
f1a7a397
|
Vinicius Coque
|
$serviceproviders = get_country_providers($country);
|
140 |
45b4ffc6
|
Phil Davis
|
foreach ($serviceproviders as $sp) {
|
141 |
|
|
if (strtolower($sp['name']['value']) == strtolower($provider)) {
|
142 |
6c07db48
|
Phil Davis
|
if (array_key_exists('gsm', $sp)) {
|
143 |
|
|
if (array_key_exists('attr', $sp['gsm']['apn'])) {
|
144 |
f1a7a397
|
Vinicius Coque
|
$name = ($sp['gsm']['apn']['name'] ? $sp['gsm']['apn']['name'] : $sp['name']['value']);
|
145 |
|
|
echo $name . ":" . $sp['gsm']['apn']['attr']['value'];
|
146 |
|
|
} else {
|
147 |
45b4ffc6
|
Phil Davis
|
foreach ($sp['gsm']['apn'] as $apn_info) {
|
148 |
f1a7a397
|
Vinicius Coque
|
$name = ($apn_info['name']['value'] ? $apn_info['name']['value'] : $apn_info['gsm']['apn']['name']);
|
149 |
|
|
echo $name . ":" . $apn_info['attr']['value'] . "\n";
|
150 |
|
|
}
|
151 |
|
|
}
|
152 |
|
|
}
|
153 |
6c07db48
|
Phil Davis
|
if (array_key_exists('cdma', $sp)) {
|
154 |
f1a7a397
|
Vinicius Coque
|
$name = $sp['cdma']['name']['value'] ? $sp['cdma']['name']['value']:$sp['name']['value'];
|
155 |
|
|
echo $name . ":" . "CDMA";
|
156 |
|
|
}
|
157 |
|
|
}
|
158 |
|
|
}
|
159 |
|
|
}
|
160 |
|
|
|
161 |
219d9eb9
|
Darren Embry
|
$_GET_OR_POST = ($_SERVER['REQUEST_METHOD'] === 'POST') ? $_POST : $_GET;
|
162 |
|
|
|
163 |
45b4ffc6
|
Phil Davis
|
if (isset($_GET_OR_POST['country']) && !isset($_GET_OR_POST['provider'])) {
|
164 |
219d9eb9
|
Darren Embry
|
providers_list($_GET_OR_POST['country']);
|
165 |
45b4ffc6
|
Phil Davis
|
} elseif (isset($_GET_OR_POST['country']) && isset($_GET_OR_POST['provider'])) {
|
166 |
|
|
if (isset($_GET_OR_POST['plan'])) {
|
167 |
6c07db48
|
Phil Davis
|
provider_plan_data($_GET_OR_POST['country'], $_GET_OR_POST['provider'], $_GET_OR_POST['plan']);
|
168 |
45b4ffc6
|
Phil Davis
|
} else {
|
169 |
6c07db48
|
Phil Davis
|
provider_plans_list($_GET_OR_POST['country'], $_GET_OR_POST['provider']);
|
170 |
45b4ffc6
|
Phil Davis
|
}
|
171 |
f1a7a397
|
Vinicius Coque
|
} else {
|
172 |
|
|
country_list();
|
173 |
|
|
}
|
174 |
|
|
?>
|