Project

General

Profile

Download (6.38 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
 * getserviceproviders.php
4
 *
5
 * part of pfSense (https://www.pfsense.org)
6
 * Copyright (c) 2004-2016 Rubicon Communications, LLC (Netgate)
7
 * Copyright (c) 2010 Vinicius Coque <vinicius.coque@bluepex.com>
8
 * All rights reserved.
9
 *
10
 * Redistribution and use in source and binary forms, with or without
11
 * modification, are permitted provided that the following conditions are met:
12
 *
13
 * 1. Redistributions of source code must retain the above copyright notice,
14
 *    this list of conditions and the following disclaimer.
15
 *
16
 * 2. Redistributions in binary form must reproduce the above copyright
17
 *    notice, this list of conditions and the following disclaimer in
18
 *    the documentation and/or other materials provided with the
19
 *    distribution.
20
 *
21
 * 3. All advertising materials mentioning features or use of this software
22
 *    must display the following acknowledgment:
23
 *    "This product includes software developed by the pfSense Project
24
 *    for use in the pfSense® software distribution. (http://www.pfsense.org/).
25
 *
26
 * 4. The names "pfSense" and "pfSense Project" must not be used to
27
 *    endorse or promote products derived from this software without
28
 *    prior written permission. For written permission, please contact
29
 *    coreteam@pfsense.org.
30
 *
31
 * 5. Products derived from this software may not be called "pfSense"
32
 *    nor may "pfSense" appear in their names without prior written
33
 *    permission of the Electric Sheep Fencing, LLC.
34
 *
35
 * 6. Redistributions of any form whatsoever must retain the following
36
 *    acknowledgment:
37
 *
38
 * "This product includes software developed by the pfSense Project
39
 * for use in the pfSense software distribution (http://www.pfsense.org/).
40
 *
41
 * THIS SOFTWARE IS PROVIDED BY THE pfSense PROJECT ``AS IS'' AND ANY
42
 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
44
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE pfSense PROJECT OR
45
 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
46
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
47
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
48
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
49
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
50
 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
51
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
52
 * OF THE POSSIBILITY OF SUCH DAMAGE.
53
 */
54

    
55
##|+PRIV
56
##|*IDENT=page-getserviceproviders
57
##|*NAME=AJAX: Get Service Providers
58
##|*DESCR=Allow access to the 'AJAX: Service Providers' page.
59
##|*MATCH=getserviceproviders.php*
60
##|-PRIV
61
require_once("guiconfig.inc");
62
require_once("pfsense-utils.inc");
63

    
64
$serviceproviders_xml = "/usr/local/share/mobile-broadband-provider-info/serviceproviders.xml";
65
$serviceproviders_contents = file_get_contents($serviceproviders_xml);
66
$serviceproviders_attr = xml2array($serviceproviders_contents, 1, "attr");
67

    
68
$serviceproviders = &$serviceproviders_attr['serviceproviders']['country'];
69

    
70
function get_country_providers($country) {
71
	global $serviceproviders;
72
	foreach ($serviceproviders as $sp) {
73
		if ($sp['attr']['code'] == strtolower($country)) {
74
			return is_array($sp['provider'][0]) ? $sp['provider'] : array($sp['provider']);
75
		}
76
	}
77
	$provider_list = (is_array($provider_list)) ? $provider_list : array();
78
	return $provider_list;
79
}
80

    
81
function country_list() {
82
	global $serviceproviders;
83
	$country_list = get_country_name("ALL");
84
	foreach ($serviceproviders as $sp) {
85
		foreach ($country_list as $country) {
86
			if (strtoupper($sp['attr']['code']) == $country['code']) {
87
				echo $country['name'] . ":" . $country['code'] . "\n";
88
			}
89
		}
90
	}
91
}
92

    
93
function providers_list($country) {
94
	$serviceproviders = get_country_providers($country);
95
	if (is_array($serviceproviders)) {
96
		foreach ($serviceproviders as $sp) {
97
			echo $sp['name']['value'] . "\n";
98
		}
99
	} else {
100
		$serviceproviders = array();
101
	}
102
}
103

    
104
function provider_plan_data($country, $provider, $connection) {
105
	header("Content-type: application/xml;");
106
	echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
107
	echo "<connection>\n";
108
	$serviceproviders = get_country_providers($country);
109
	foreach ($serviceproviders as $sp) {
110
		if (strtolower($sp['name']['value']) == strtolower($provider)) {
111
			if (strtoupper($connection) == "CDMA") {
112
				$conndata = $sp['cdma'];
113
			} else {
114
				if (!is_array($sp['gsm']['apn'][0])) {
115
					$conndata = $sp['gsm']['apn'];
116
				} else {
117
					foreach ($sp['gsm']['apn'] as $apn) {
118
						if ($apn['attr']['value'] == $connection) {
119
							$conndata = $apn;
120
							break;
121
						}
122
					}
123
				}
124
			}
125
			if (is_array($conndata)) {
126
				echo "<apn>" . $connection . "</apn>\n";
127
				echo "<username>" . $conndata['username']['value'] . "</username>\n";
128
				echo "<password>" . $conndata['password']['value'] . "</password>\n";
129

    
130
				$dns_arr = is_array($conndata['dns'][0]) ? $conndata['dns'] : array($conndata['dns']);
131
				foreach ($dns_arr as $dns) {
132
					echo '<dns>' . $dns['value'] . "</dns>\n";
133
				}
134
			}
135
			break;
136
		}
137
	}
138
	echo "</connection>";
139
}
140

    
141
function provider_plans_list($country, $provider) {
142
	$serviceproviders = get_country_providers($country);
143
	foreach ($serviceproviders as $sp) {
144
		if (strtolower($sp['name']['value']) == strtolower($provider)) {
145
			if (array_key_exists('gsm', $sp)) {
146
				if (array_key_exists('attr', $sp['gsm']['apn'])) {
147
					$name = ($sp['gsm']['apn']['name'] ? $sp['gsm']['apn']['name'] : $sp['name']['value']);
148
					echo $name . ":" . $sp['gsm']['apn']['attr']['value'];
149
				} else {
150
					foreach ($sp['gsm']['apn'] as $apn_info) {
151
						$name = ($apn_info['name']['value'] ? $apn_info['name']['value'] : $apn_info['gsm']['apn']['name']);
152
						echo $name . ":" . $apn_info['attr']['value'] . "\n";
153
					}
154
				}
155
			}
156
			if (array_key_exists('cdma', $sp)) {
157
				$name = $sp['cdma']['name']['value'] ? $sp['cdma']['name']['value']:$sp['name']['value'];
158
				echo $name . ":" . "CDMA";
159
			}
160
		}
161
	}
162
}
163

    
164
$_GET_OR_POST = ($_SERVER['REQUEST_METHOD'] === 'POST') ? $_POST : $_GET;
165

    
166
if (isset($_GET_OR_POST['country']) && !isset($_GET_OR_POST['provider'])) {
167
	providers_list($_GET_OR_POST['country']);
168
} elseif (isset($_GET_OR_POST['country']) && isset($_GET_OR_POST['provider'])) {
169
	if (isset($_GET_OR_POST['plan'])) {
170
		provider_plan_data($_GET_OR_POST['country'], $_GET_OR_POST['provider'], $_GET_OR_POST['plan']);
171
	} else {
172
		provider_plans_list($_GET_OR_POST['country'], $_GET_OR_POST['provider']);
173
	}
174
} else {
175
	country_list();
176
}
177
?>
(62-62/230)