Project

General

Profile

Download (6.41 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
	getserviceproviders.php
4
*/
5

    
6
/* ====================================================================
7
 *  Copyright (c)  2004-2015  Electric Sheep Fencing, LLC. All rights reserved. 
8
 *  Copyright (c) 2010 Vinicius Coque <vinicius.coque@bluepex.com>
9
 *
10
 *  Redistribution and use in source and binary forms, with or without modification, 
11
 *  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
 *
56
 */
57
/*
58
	pfSense_MODULE:	ajax
59
*/
60

    
61
##|+PRIV
62
##|*IDENT=page-getserviceproviders
63
##|*NAME=AJAX: Get Service Providers
64
##|*DESCR=Allow access to the 'AJAX: Service Providers' page.
65
##|*MATCH=getserviceproviders.php*
66
##|-PRIV
67
require_once("guiconfig.inc");
68
require_once("pfsense-utils.inc");
69

    
70
$serviceproviders_xml = "/usr/local/share/mobile-broadband-provider-info/serviceproviders.xml";
71
$serviceproviders_contents = file_get_contents($serviceproviders_xml);
72
$serviceproviders_attr = xml2array($serviceproviders_contents, 1, "attr");
73

    
74
$serviceproviders = &$serviceproviders_attr['serviceproviders']['country'];
75

    
76
function get_country_providers($country) {
77
	global $serviceproviders;
78
	foreach ($serviceproviders as $sp) {
79
		if ($sp['attr']['code'] == strtolower($country)) {
80
			return is_array($sp['provider'][0]) ? $sp['provider'] : array($sp['provider']);
81
		}
82
	}
83
	return $provider_list;
84
}
85

    
86
function country_list() {
87
	global $serviceproviders;
88
	$country_list = get_country_name("ALL");
89
	foreach ($serviceproviders as $sp) {
90
		foreach ($country_list as $country) {
91
			if (strtoupper($sp['attr']['code']) == $country['code']) {
92
				echo $country['name'] . ":" . $country['code'] . "\n";
93
			}
94
		}
95
	}
96
}
97

    
98
function providers_list($country) {
99
	$serviceproviders = get_country_providers($country);
100
	foreach ($serviceproviders as $sp) {
101
		echo $sp['name']['value'] . "\n";
102
	}
103
}
104

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

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

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

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

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