Project

General

Profile

Download (4.71 KB) Statistics
| Branch: | Tag: | Revision:
1 f1a7a397 Vinicius Coque
<?php
2
/*
3 c5d81585 Renato Botelho
 * getserviceproviders.php
4 fd9ebcd5 Stephen Beaver
 *
5 c5d81585 Renato Botelho
 * part of pfSense (https://www.pfsense.org)
6 b8f91b7c Luiz Souza
 * Copyright (c) 2004-2018 Rubicon Communications, LLC (Netgate)
7 c5d81585 Renato Botelho
 * Copyright (c) 2010 Vinicius Coque <vinicius.coque@bluepex.com>
8
 * All rights reserved.
9 fd9ebcd5 Stephen Beaver
 *
10 b12ea3fb Renato Botelho
 * Licensed under the Apache License, Version 2.0 (the "License");
11
 * you may not use this file except in compliance with the License.
12
 * You may obtain a copy of the License at
13 fd9ebcd5 Stephen Beaver
 *
14 b12ea3fb Renato Botelho
 * http://www.apache.org/licenses/LICENSE-2.0
15 fd9ebcd5 Stephen Beaver
 *
16 b12ea3fb Renato Botelho
 * Unless required by applicable law or agreed to in writing, software
17
 * distributed under the License is distributed on an "AS IS" BASIS,
18
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19
 * See the License for the specific language governing permissions and
20
 * limitations under the License.
21 fd9ebcd5 Stephen Beaver
 */
22 f1a7a397 Vinicius Coque
23
##|+PRIV
24
##|*IDENT=page-getserviceproviders
25
##|*NAME=AJAX: Get Service Providers
26
##|*DESCR=Allow access to the 'AJAX: Service Providers' page.
27
##|*MATCH=getserviceproviders.php*
28
##|-PRIV
29 84c07e65 Scott Ullrich
require_once("guiconfig.inc");
30 f1a7a397 Vinicius Coque
require_once("pfsense-utils.inc");
31
32
$serviceproviders_xml = "/usr/local/share/mobile-broadband-provider-info/serviceproviders.xml";
33
$serviceproviders_contents = file_get_contents($serviceproviders_xml);
34 6c07db48 Phil Davis
$serviceproviders_attr = xml2array($serviceproviders_contents, 1, "attr");
35 f1a7a397 Vinicius Coque
36
$serviceproviders = &$serviceproviders_attr['serviceproviders']['country'];
37
38
function get_country_providers($country) {
39
	global $serviceproviders;
40 45b4ffc6 Phil Davis
	foreach ($serviceproviders as $sp) {
41
		if ($sp['attr']['code'] == strtolower($country)) {
42 f1a7a397 Vinicius Coque
			return is_array($sp['provider'][0]) ? $sp['provider'] : array($sp['provider']);
43
		}
44
	}
45 ce348731 doktornotor
	$provider_list = (is_array($provider_list)) ? $provider_list : array();
46 f1a7a397 Vinicius Coque
	return $provider_list;
47
}
48
49
function country_list() {
50
	global $serviceproviders;
51 988640d3 Renato Botelho
	$country_list = get_country_name();
52 45b4ffc6 Phil Davis
	foreach ($serviceproviders as $sp) {
53
		foreach ($country_list as $country) {
54
			if (strtoupper($sp['attr']['code']) == $country['code']) {
55 f1a7a397 Vinicius Coque
				echo $country['name'] . ":" . $country['code'] . "\n";
56
			}
57
		}
58
	}
59
}
60
61
function providers_list($country) {
62
	$serviceproviders = get_country_providers($country);
63 ce348731 doktornotor
	if (is_array($serviceproviders)) {
64
		foreach ($serviceproviders as $sp) {
65
			echo $sp['name']['value'] . "\n";
66
		}
67
	} else {
68
		$serviceproviders = array();
69 f1a7a397 Vinicius Coque
	}
70
}
71
72 6c07db48 Phil Davis
function provider_plan_data($country, $provider, $connection) {
73 6f3d2063 Renato Botelho
	header("Content-type: application/xml;");
74 cd94a9a8 Renato Botelho
	echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
75 f1a7a397 Vinicius Coque
	echo "<connection>\n";
76
	$serviceproviders = get_country_providers($country);
77 45b4ffc6 Phil Davis
	foreach ($serviceproviders as $sp) {
78
		if (strtolower($sp['name']['value']) == strtolower($provider)) {
79
			if (strtoupper($connection) == "CDMA") {
80 f1a7a397 Vinicius Coque
				$conndata = $sp['cdma'];
81
			} else {
82 45b4ffc6 Phil Davis
				if (!is_array($sp['gsm']['apn'][0])) {
83 f1a7a397 Vinicius Coque
					$conndata = $sp['gsm']['apn'];
84
				} else {
85 45b4ffc6 Phil Davis
					foreach ($sp['gsm']['apn'] as $apn) {
86
						if ($apn['attr']['value'] == $connection) {
87 f1a7a397 Vinicius Coque
							$conndata = $apn;
88
							break;
89
						}
90
					}
91
				}
92
			}
93 45b4ffc6 Phil Davis
			if (is_array($conndata)) {
94 f1a7a397 Vinicius Coque
				echo "<apn>" . $connection . "</apn>\n";
95
				echo "<username>" . $conndata['username']['value'] . "</username>\n";
96
				echo "<password>" . $conndata['password']['value'] . "</password>\n";
97
98 6c07db48 Phil Davis
				$dns_arr = is_array($conndata['dns'][0]) ? $conndata['dns'] : array($conndata['dns']);
99 45b4ffc6 Phil Davis
				foreach ($dns_arr as $dns) {
100 f1a7a397 Vinicius Coque
					echo '<dns>' . $dns['value'] . "</dns>\n";
101
				}
102
			}
103
			break;
104
		}
105
	}
106
	echo "</connection>";
107
}
108
109 6c07db48 Phil Davis
function provider_plans_list($country, $provider) {
110 f1a7a397 Vinicius Coque
	$serviceproviders = get_country_providers($country);
111 45b4ffc6 Phil Davis
	foreach ($serviceproviders as $sp) {
112
		if (strtolower($sp['name']['value']) == strtolower($provider)) {
113 6c07db48 Phil Davis
			if (array_key_exists('gsm', $sp)) {
114
				if (array_key_exists('attr', $sp['gsm']['apn'])) {
115 f1a7a397 Vinicius Coque
					$name = ($sp['gsm']['apn']['name'] ? $sp['gsm']['apn']['name'] : $sp['name']['value']);
116
					echo $name . ":" . $sp['gsm']['apn']['attr']['value'];
117
				} else {
118 45b4ffc6 Phil Davis
					foreach ($sp['gsm']['apn'] as $apn_info) {
119 f1a7a397 Vinicius Coque
						$name = ($apn_info['name']['value'] ? $apn_info['name']['value'] : $apn_info['gsm']['apn']['name']);
120
						echo $name . ":" . $apn_info['attr']['value'] . "\n";
121
					}
122
				}
123
			}
124 6c07db48 Phil Davis
			if (array_key_exists('cdma', $sp)) {
125 f1a7a397 Vinicius Coque
				$name = $sp['cdma']['name']['value'] ? $sp['cdma']['name']['value']:$sp['name']['value'];
126
				echo $name . ":" . "CDMA";
127
			}
128
		}
129
	}
130
}
131
132 cbb82e6b Steve Beaver
$_REQ_OR_POST = ($_SERVER['REQUEST_METHOD'] === 'POST') ? $_POST : $_REQUEST;
133 219d9eb9 Darren Embry
134 cbb82e6b Steve Beaver
if (isset($_REQ_OR_POST['country']) && !isset($_REQ_OR_POST['provider'])) {
135
	providers_list($_REQ_OR_POST['country']);
136
} elseif (isset($_REQ_OR_POST['country']) && isset($_REQ_OR_POST['provider'])) {
137
	if (isset($_REQ_OR_POST['plan'])) {
138
		provider_plan_data($_REQ_OR_POST['country'], $_REQ_OR_POST['provider'], $_REQ_OR_POST['plan']);
139 45b4ffc6 Phil Davis
	} else {
140 cbb82e6b Steve Beaver
		provider_plans_list($_REQ_OR_POST['country'], $_REQ_OR_POST['provider']);
141 45b4ffc6 Phil Davis
	}
142 f1a7a397 Vinicius Coque
} else {
143
	country_list();
144
}
145
?>