Project

General

Profile

Download (5.16 KB) Statistics
| Branch: | Tag: | Revision:
1 f1a7a397 Vinicius Coque
<?php
2
/*
3
    getserviceproviders.php
4
    Copyright (C) 2010 Vinicius Coque <vinicius.coque@bluepex.com>
5 ed2d1343 Renato Botelho
    Copyright (C) 2013-2015 Electric Sheep Fencing, LP
6 f1a7a397 Vinicius Coque
    All rights reserved.
7
8
    Redistribution and use in source and binary forms, with or without
9
    modification, are permitted provided that the following conditions are met:
10
11
    1. Redistributions of source code must retain the above copyright notice,
12
       this list of conditions and the following disclaimer.
13
14
    2. Redistributions in binary form must reproduce the above copyright
15
       notice, this list of conditions and the following disclaimer in the
16
       documentation and/or other materials provided with the distribution.
17
18
    THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
19
    INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
20
    AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
21
    AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
22
    OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23
    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24
    INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25
    CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26
    ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27
    POSSIBILITY OF SUCH DAMAGE.
28
*/
29
/*
30
	pfSense_MODULE:	ajax
31
*/
32
33
##|+PRIV
34
##|*IDENT=page-getserviceproviders
35
##|*NAME=AJAX: Get Service Providers
36
##|*DESCR=Allow access to the 'AJAX: Service Providers' page.
37
##|*MATCH=getserviceproviders.php*
38
##|-PRIV
39 84c07e65 Scott Ullrich
require_once("guiconfig.inc");
40 f1a7a397 Vinicius Coque
require_once("pfsense-utils.inc");
41
42
$serviceproviders_xml = "/usr/local/share/mobile-broadband-provider-info/serviceproviders.xml";
43
$serviceproviders_contents = file_get_contents($serviceproviders_xml);
44
$serviceproviders_attr = xml2array($serviceproviders_contents,1,"attr");
45
46
$serviceproviders = &$serviceproviders_attr['serviceproviders']['country'];
47
48
function get_country_providers($country) {
49
	global $serviceproviders;
50
	foreach($serviceproviders as $sp) {
51
		if($sp['attr']['code'] == strtolower($country)) {
52
			return is_array($sp['provider'][0]) ? $sp['provider'] : array($sp['provider']);
53
		}
54
	}
55
	return $provider_list;
56
}
57
58
function country_list() {
59
	global $serviceproviders;
60
	$country_list = get_country_name("ALL");
61
	foreach($serviceproviders as $sp) {
62
		foreach($country_list as $country) {
63
			if(strtoupper($sp['attr']['code']) == $country['code']) {
64
				echo $country['name'] . ":" . $country['code'] . "\n";
65
			}
66
		}
67
	}
68
}
69
70
function providers_list($country) {
71
	$serviceproviders = get_country_providers($country);
72
	foreach($serviceproviders as $sp) {
73
		echo $sp['name']['value'] . "\n";
74
	}
75
}
76
77
function provider_plan_data($country,$provider,$connection) {
78 6f3d2063 Renato Botelho
	header("Content-type: application/xml;");
79 87aa8215 technical50
	echo "<?xml version=\"1.0\" ?>\n";
80 f1a7a397 Vinicius Coque
	echo "<connection>\n";
81
	$serviceproviders = get_country_providers($country);
82
	foreach($serviceproviders as $sp) {
83
		if(strtolower($sp['name']['value']) == strtolower($provider)) {
84
			if(strtoupper($connection) == "CDMA") {
85
				$conndata = $sp['cdma'];
86
			} else {
87
				if(!is_array($sp['gsm']['apn'][0])) {
88
					$conndata = $sp['gsm']['apn'];
89
				} else {
90
					foreach($sp['gsm']['apn'] as $apn) {
91
						if($apn['attr']['value'] == $connection) {
92
							$conndata = $apn;
93
							break;
94
						}
95
					}
96
				}
97
			}
98
			if(is_array($conndata)) {
99
				echo "<apn>" . $connection . "</apn>\n";
100
				echo "<username>" . $conndata['username']['value'] . "</username>\n";
101
				echo "<password>" . $conndata['password']['value'] . "</password>\n";
102
103
				$dns_arr = is_array($conndata['dns'][0]) ? $conndata['dns'] : array( $conndata['dns'] );
104
				foreach($dns_arr as $dns) {
105
					echo '<dns>' . $dns['value'] . "</dns>\n";
106
				}
107
			}
108
			break;
109
		}
110
	}
111
	echo "</connection>";
112
}
113
114
function provider_plans_list($country,$provider) {
115
	$serviceproviders = get_country_providers($country);
116
	foreach($serviceproviders as $sp) {
117
		if(strtolower($sp['name']['value']) == strtolower($provider)) {
118
			if(array_key_exists('gsm',$sp)) {
119
				if(array_key_exists('attr',$sp['gsm']['apn'])) {
120
					$name = ($sp['gsm']['apn']['name'] ? $sp['gsm']['apn']['name'] : $sp['name']['value']);
121
					echo $name . ":" . $sp['gsm']['apn']['attr']['value'];
122
				} else {
123
					foreach($sp['gsm']['apn'] as $apn_info) {
124
						$name = ($apn_info['name']['value'] ? $apn_info['name']['value'] : $apn_info['gsm']['apn']['name']);
125
						echo $name . ":" . $apn_info['attr']['value'] . "\n";
126
					}
127
				}
128
			}
129
			if(array_key_exists('cdma',$sp)) {
130
				$name = $sp['cdma']['name']['value'] ? $sp['cdma']['name']['value']:$sp['name']['value'];
131
				echo $name . ":" . "CDMA";
132
			}
133
		}
134
	}
135
}
136
137 219d9eb9 Darren Embry
$_GET_OR_POST = ($_SERVER['REQUEST_METHOD'] === 'POST') ? $_POST : $_GET;
138
139
if(isset($_GET_OR_POST['country']) && !isset($_GET_OR_POST['provider'])) {
140
	providers_list($_GET_OR_POST['country']);
141
} elseif(isset($_GET_OR_POST['country']) && isset($_GET_OR_POST['provider'])) {
142
	if(isset($_GET_OR_POST['plan']))
143
		provider_plan_data($_GET_OR_POST['country'],$_GET_OR_POST['provider'],$_GET_OR_POST['plan']);
144 f1a7a397 Vinicius Coque
	else
145 219d9eb9 Darren Embry
		provider_plans_list($_GET_OR_POST['country'],$_GET_OR_POST['provider']);
146 f1a7a397 Vinicius Coque
} else {
147
	country_list();
148
}
149
?>