Project

General

Profile

Download (6.37 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
##|+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
require_once("guiconfig.inc");
64
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
$serviceproviders_attr = xml2array($serviceproviders_contents, 1, "attr");
69

    
70
$serviceproviders = &$serviceproviders_attr['serviceproviders']['country'];
71

    
72
function get_country_providers($country) {
73
	global $serviceproviders;
74
	foreach ($serviceproviders as $sp) {
75
		if ($sp['attr']['code'] == strtolower($country)) {
76
			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
	foreach ($serviceproviders as $sp) {
86
		foreach ($country_list as $country) {
87
			if (strtoupper($sp['attr']['code']) == $country['code']) {
88
				echo $country['name'] . ":" . $country['code'] . "\n";
89
			}
90
		}
91
	}
92
}
93

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

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

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

    
138
function provider_plans_list($country, $provider) {
139
	$serviceproviders = get_country_providers($country);
140
	foreach ($serviceproviders as $sp) {
141
		if (strtolower($sp['name']['value']) == strtolower($provider)) {
142
			if (array_key_exists('gsm', $sp)) {
143
				if (array_key_exists('attr', $sp['gsm']['apn'])) {
144
					$name = ($sp['gsm']['apn']['name'] ? $sp['gsm']['apn']['name'] : $sp['name']['value']);
145
					echo $name . ":" . $sp['gsm']['apn']['attr']['value'];
146
				} else {
147
					foreach ($sp['gsm']['apn'] as $apn_info) {
148
						$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
			if (array_key_exists('cdma', $sp)) {
154
				$name = $sp['cdma']['name']['value'] ? $sp['cdma']['name']['value']:$sp['name']['value'];
155
				echo $name . ":" . "CDMA";
156
			}
157
		}
158
	}
159
}
160

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

    
163
if (isset($_GET_OR_POST['country']) && !isset($_GET_OR_POST['provider'])) {
164
	providers_list($_GET_OR_POST['country']);
165
} elseif (isset($_GET_OR_POST['country']) && isset($_GET_OR_POST['provider'])) {
166
	if (isset($_GET_OR_POST['plan'])) {
167
		provider_plan_data($_GET_OR_POST['country'], $_GET_OR_POST['provider'], $_GET_OR_POST['plan']);
168
	} else {
169
		provider_plans_list($_GET_OR_POST['country'], $_GET_OR_POST['provider']);
170
	}
171
} else {
172
	country_list();
173
}
174
?>
(60-60/229)