Project

General

Profile

Download (6.4 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
	getserviceproviders.php
4
*/
5
/* ====================================================================
6
 *  Copyright (c)  2004-2015  Electric Sheep Fencing, LLC. All rights reserved.
7
 *  Copyright (c) 2010 Vinicius Coque <vinicius.coque@bluepex.com>
8
 *
9
 *  Redistribution and use in source and binary forms, with or without modification,
10
 *  are permitted provided that the following conditions are met:
11
 *
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
 *      distribution.
19
 *
20
 *  3. All advertising materials mentioning features or use of this software
21
 *      must display the following acknowledgment:
22
 *      "This product includes software developed by the pfSense Project
23
 *       for use in the pfSense software distribution. (http://www.pfsense.org/).
24
 *
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
/*
57
	pfSense_MODULE:	ajax
58
*/
59

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

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

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

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

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

    
97
function providers_list($country) {
98
	$serviceproviders = get_country_providers($country);
99
	foreach ($serviceproviders as $sp) {
100
		echo $sp['name']['value'] . "\n";
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
?>
(70-70/228)