Project

General

Profile

Download (6.22 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 Electric Sheep Fencing, LLC
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
	return $provider_list;
78
}
79

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

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

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

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

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

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

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