|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* ***************************************************************************** |
|
5
|
|
|
* Contributions to this work were made on behalf of the GÉANT project, a |
|
6
|
|
|
* project that has received funding from the European Union’s Framework |
|
7
|
|
|
* Programme 7 under Grant Agreements No. 238875 (GN3) and No. 605243 (GN3plus), |
|
8
|
|
|
* Horizon 2020 research and innovation programme under Grant Agreements No. |
|
9
|
|
|
* 691567 (GN4-1) and No. 731122 (GN4-2). |
|
10
|
|
|
* On behalf of the aforementioned projects, GEANT Association is the sole owner |
|
11
|
|
|
* of the copyright in all material which was developed by a member of the GÉANT |
|
12
|
|
|
* project. GÉANT Vereniging (Association) is registered with the Chamber of |
|
13
|
|
|
* Commerce in Amsterdam with registration number 40535155 and operates in the |
|
14
|
|
|
* UK as a branch of GÉANT Vereniging. |
|
15
|
|
|
* |
|
16
|
|
|
* Registered office: Hoekenrode 3, 1102BR Amsterdam, The Netherlands. |
|
17
|
|
|
* UK branch address: City House, 126-130 Hills Road, Cambridge CB2 1PQ, UK |
|
18
|
|
|
* |
|
19
|
|
|
* License: see the web/copyright.inc.php file in the file structure or |
|
20
|
|
|
* <base_url>/copyright.php after deploying the software |
|
21
|
|
|
*/ |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* This file contains the AbstractProfile class. It contains common methods for |
|
25
|
|
|
* both RADIUS/EAP profiles and SilverBullet profiles |
|
26
|
|
|
* |
|
27
|
|
|
* @author Stefan Winter <[email protected]> |
|
28
|
|
|
* @author Tomasz Wolniewicz <[email protected]> |
|
29
|
|
|
* |
|
30
|
|
|
* @package Developer |
|
31
|
|
|
* |
|
32
|
|
|
*/ |
|
33
|
|
|
|
|
34
|
|
|
namespace core; |
|
35
|
|
|
|
|
36
|
|
|
use \Exception; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* This class interacts with the external DB to fetch operational data for |
|
40
|
|
|
* read-only purposes. |
|
41
|
|
|
* |
|
42
|
|
|
* @author Stefan Winter <[email protected]> |
|
43
|
|
|
* |
|
44
|
|
|
* @license see LICENSE file in root directory |
|
45
|
|
|
* |
|
46
|
|
|
* @package Developer |
|
47
|
|
|
*/ |
|
48
|
|
|
class ExternalEduroamDBData extends EntityWithDBProperties { |
|
49
|
|
|
|
|
50
|
|
|
private $SPList = []; |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* constructor, gives us access to the DB handle we need for queries |
|
54
|
|
|
*/ |
|
55
|
|
|
public function __construct() { |
|
56
|
|
|
$this->databaseType = "EXTERNAL"; |
|
57
|
|
|
parent::__construct(); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* we don't write anything to the external DB, so no need to track update |
|
62
|
|
|
* timestamps |
|
63
|
|
|
* |
|
64
|
|
|
* @return void |
|
65
|
|
|
*/ |
|
66
|
|
|
public function updateFreshness() { |
|
67
|
|
|
|
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* eduroam DB delivers a string with all name variants mangled in one. Pry |
|
72
|
|
|
* it apart. |
|
73
|
|
|
* |
|
74
|
|
|
* @param string $nameRaw the string with all name variants coerced into one |
|
75
|
|
|
* @return array language/name pair |
|
76
|
|
|
*/ |
|
77
|
|
|
private function splitNames($nameRaw) { |
|
78
|
|
|
// the delimiter used by eduroam DB is ; but that is ALSO an allowed |
|
79
|
|
|
// character in payload, and in active use. We need to try and find out |
|
80
|
|
|
// which semicolon should NOT be considered a language delimiter... |
|
81
|
|
|
$cleanName = preg_replace('/;\[/', '##DBLIMIT##[', $nameRaw); |
|
82
|
|
|
$variants = explode('##DBLIMIT##', $cleanName); |
|
83
|
|
|
$submatches = []; |
|
84
|
|
|
$returnArray = []; |
|
85
|
|
|
foreach ($variants as $oneVariant) { |
|
86
|
|
|
if ($oneVariant == NULL) { |
|
87
|
|
|
return []; |
|
88
|
|
|
} |
|
89
|
|
|
if (!preg_match('/^\[(.*)\]\ (.*)/', $oneVariant, $submatches) || !isset($submatches[2])) { |
|
90
|
|
|
throw new Exception("We expect '[CC] bla but found '$oneVariant'."); |
|
91
|
|
|
} |
|
92
|
|
|
$returnArray[$submatches[1]] = $submatches[2]; |
|
93
|
|
|
} |
|
94
|
|
|
return $returnArray; |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
public function allServiceProviders() { |
|
|
|
|
|
|
98
|
|
|
if (count($this->SPList) == 0) { |
|
99
|
|
|
$query = $this->databaseHandle->exec("SELECT country, inst_name, sp_location FROM view_active_SP_location_eduroamdb"); |
|
100
|
|
|
while ($iterator = mysqli_fetch_object($query)) { |
|
|
|
|
|
|
101
|
|
|
$this->SPList[] = ["country" => $iterator->country, "instnames" => $this->splitNames($iterator->inst_name), "locnames" => $this->splitNames($iterator->sp_location)]; |
|
102
|
|
|
} |
|
103
|
|
|
} |
|
104
|
|
|
return $this->SPList; |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
} |
|
108
|
|
|
|