Project

General

Profile

Download (4.96 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
    getserviceproviders.php
4
    Copyright (C) 2010 Vinicius Coque <vinicius.coque@bluepex.com>
5
    All rights reserved.
6

    
7
    Redistribution and use in source and binary forms, with or without
8
    modification, are permitted provided that the following conditions are met:
9

    
10
    1. Redistributions of source code must retain the above copyright notice,
11
       this list of conditions and the following disclaimer.
12

    
13
    2. Redistributions in binary form must reproduce the above copyright
14
       notice, this list of conditions and the following disclaimer in the
15
       documentation and/or other materials provided with the distribution.
16

    
17
    THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
18
    INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
19
    AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
20
    AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
21
    OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22
    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23
    INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24
    CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25
    ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26
    POSSIBILITY OF SUCH DAMAGE.
27
*/
28
/*
29
	pfSense_MODULE:	ajax
30
*/
31

    
32
##|+PRIV
33
##|*IDENT=page-getserviceproviders
34
##|*NAME=AJAX: Get Service Providers
35
##|*DESCR=Allow access to the 'AJAX: Service Providers' page.
36
##|*MATCH=getserviceproviders.php*
37
##|-PRIV
38
require_once("pfsense-utils.inc");
39

    
40
$serviceproviders_xml = "/usr/local/share/mobile-broadband-provider-info/serviceproviders.xml";
41
$serviceproviders_contents = file_get_contents($serviceproviders_xml);
42
$serviceproviders_attr = xml2array($serviceproviders_contents,1,"attr");
43

    
44
$serviceproviders = &$serviceproviders_attr['serviceproviders']['country'];
45

    
46
function get_country_providers($country) {
47
	global $serviceproviders;
48
	foreach($serviceproviders as $sp) {
49
		if($sp['attr']['code'] == strtolower($country)) {
50
			return is_array($sp['provider'][0]) ? $sp['provider'] : array($sp['provider']);
51
		}
52
	}
53
	return $provider_list;
54
}
55

    
56
function country_list() {
57
	global $serviceproviders;
58
	$country_list = get_country_name("ALL");
59
	foreach($serviceproviders as $sp) {
60
		foreach($country_list as $country) {
61
			if(strtoupper($sp['attr']['code']) == $country['code']) {
62
				echo $country['name'] . ":" . $country['code'] . "\n";
63
			}
64
		}
65
	}
66
}
67

    
68
function providers_list($country) {
69
	$serviceproviders = get_country_providers($country);
70
	foreach($serviceproviders as $sp) {
71
		echo $sp['name']['value'] . "\n";
72
	}
73
}
74

    
75
function provider_plan_data($country,$provider,$connection) {
76
	Header("Content-type: application/xml; charset=iso-8859-1");
77
	echo "<?xml version=\"1.0\" encoding=\"ISO-8859-1\" ?>\n";
78
	echo "<connection>\n";
79
	$serviceproviders = get_country_providers($country);
80
	foreach($serviceproviders as $sp) {
81
		if(strtolower($sp['name']['value']) == strtolower($provider)) {
82
			if(strtoupper($connection) == "CDMA") {
83
				$conndata = $sp['cdma'];
84
			} else {
85
				if(!is_array($sp['gsm']['apn'][0])) {
86
					$conndata = $sp['gsm']['apn'];
87
				} else {
88
					foreach($sp['gsm']['apn'] as $apn) {
89
						if($apn['attr']['value'] == $connection) {
90
							$conndata = $apn;
91
							break;
92
						}
93
					}
94
				}
95
			}
96
			if(is_array($conndata)) {
97
				echo "<apn>" . $connection . "</apn>\n";
98
				echo "<username>" . $conndata['username']['value'] . "</username>\n";
99
				echo "<password>" . $conndata['password']['value'] . "</password>\n";
100

    
101
				$dns_arr = is_array($conndata['dns'][0]) ? $conndata['dns'] : array( $conndata['dns'] );
102
				foreach($dns_arr as $dns) {
103
					echo '<dns>' . $dns['value'] . "</dns>\n";
104
				}
105
			}
106
			break;
107
		}
108
	}
109
	echo "</connection>";
110
}
111

    
112
function provider_plans_list($country,$provider) {
113
	$serviceproviders = get_country_providers($country);
114
	foreach($serviceproviders as $sp) {
115
		if(strtolower($sp['name']['value']) == strtolower($provider)) {
116
			if(array_key_exists('gsm',$sp)) {
117
				if(array_key_exists('attr',$sp['gsm']['apn'])) {
118
					$name = ($sp['gsm']['apn']['name'] ? $sp['gsm']['apn']['name'] : $sp['name']['value']);
119
					echo $name . ":" . $sp['gsm']['apn']['attr']['value'];
120
				} else {
121
					foreach($sp['gsm']['apn'] as $apn_info) {
122
						$name = ($apn_info['name']['value'] ? $apn_info['name']['value'] : $apn_info['gsm']['apn']['name']);
123
						echo $name . ":" . $apn_info['attr']['value'] . "\n";
124
					}
125
				}
126
			}
127
			if(array_key_exists('cdma',$sp)) {
128
				$name = $sp['cdma']['name']['value'] ? $sp['cdma']['name']['value']:$sp['name']['value'];
129
				echo $name . ":" . "CDMA";
130
			}
131
		}
132
	}
133
}
134

    
135
if(isset($_POST['country']) && !isset($_POST['provider'])) {
136
	providers_list($_POST['country']);
137
} elseif(isset($_POST['country']) && isset($_POST['provider'])) {
138
	if(isset($_POST['plan']))
139
		provider_plan_data($_POST['country'],$_POST['provider'],$_POST['plan']);
140
	else
141
		provider_plans_list($_POST['country'],$_POST['provider']);
142
} else {
143
	country_list();
144
}
145
?>
(67-67/220)