|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
* ***************************************************************************** |
|
4
|
|
|
* Contributions to this work were made on behalf of the GÉANT project, a |
|
5
|
|
|
* project that has received funding from the European Union’s Framework |
|
6
|
|
|
* Programme 7 under Grant Agreements No. 238875 (GN3) and No. 605243 (GN3plus), |
|
7
|
|
|
* Horizon 2020 research and innovation programme under Grant Agreements No. |
|
8
|
|
|
* 691567 (GN4-1) and No. 731122 (GN4-2). |
|
9
|
|
|
* On behalf of the aforementioned projects, GEANT Association is the sole owner |
|
10
|
|
|
* of the copyright in all material which was developed by a member of the GÉANT |
|
11
|
|
|
* project. GÉANT Vereniging (Association) is registered with the Chamber of |
|
12
|
|
|
* Commerce in Amsterdam with registration number 40535155 and operates in the |
|
13
|
|
|
* UK as a branch of GÉANT Vereniging. |
|
14
|
|
|
* |
|
15
|
|
|
* Registered office: Hoekenrode 3, 1102BR Amsterdam, The Netherlands. |
|
16
|
|
|
* UK branch address: City House, 126-130 Hills Road, Cambridge CB2 1PQ, UK |
|
17
|
|
|
* |
|
18
|
|
|
* License: see the web/copyright.inc.php file in the file structure or |
|
19
|
|
|
* <base_url>/copyright.php after deploying the software |
|
20
|
|
|
*/ |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* This file contains the TestModule class |
|
24
|
|
|
* |
|
25
|
|
|
* This is a very basic example of using the CAT API. |
|
26
|
|
|
* |
|
27
|
|
|
* The module contains two files |
|
28
|
|
|
* in the Files directory. They will illustrate the use of the {@link DeviceConfig::copyFile()} method. |
|
29
|
|
|
* One fille will be coppied without the name change, for the second we will provide a new name. |
|
30
|
|
|
* The API also contains a similar {@link DeviceConfig::translateFile()} method, which is special to Windows installers and not used in this example. |
|
31
|
|
|
* |
|
32
|
|
|
* This module will collect all certificate files stored in the database for a given profile and will copy them to the working directory. |
|
33
|
|
|
* |
|
34
|
|
|
* If, for the given profile, an information file is available, this will also be copied to the working directory. |
|
35
|
|
|
* |
|
36
|
|
|
* The installer will collect all available configuration attributes and save them to a file in the form of the PHP print_r output. |
|
37
|
|
|
* |
|
38
|
|
|
* Finally, the installer will create a zip archive containing all above files and this file |
|
39
|
|
|
* will be sent to the user as the configurator file. |
|
40
|
|
|
* |
|
41
|
|
|
* Go to the {@link Device_TestModule} and {@link DeviceConfig} class definitions to learn more. |
|
42
|
|
|
* |
|
43
|
|
|
* @package ModuleWriting |
|
44
|
|
|
*/ |
|
45
|
|
|
|
|
46
|
|
|
namespace devices\test_module; |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* This is the main implementation class of the module |
|
50
|
|
|
* |
|
51
|
|
|
* The name of the class must the the 'Device_' followed by the name of the module file |
|
52
|
|
|
* (without the '.php' extension), so in this case the file is "TestModule.php" and |
|
53
|
|
|
* the class is Device_TestModule. |
|
54
|
|
|
* |
|
55
|
|
|
* The class MUST define the constructor method and one additional |
|
56
|
|
|
* public method: {@link writeInstaller()}. |
|
57
|
|
|
* |
|
58
|
|
|
* All other methods and properties should be private. This example sets zipInstaller method to protected, so that it can be seen in the documentation. |
|
59
|
|
|
* |
|
60
|
|
|
* It is important to understand how the device module fits into the whole picture, so here is s short descrption. |
|
61
|
|
|
* An external caller (for instance {@link GUI::generateInstaller()}) creates the module device instance and prepares |
|
62
|
|
|
* its environment for a given user profile by calling {@link DeviceConfig::setup()} method. |
|
63
|
|
|
* this will: |
|
64
|
|
|
* - create the temporary directory and save its path as $this->FPATH |
|
65
|
|
|
* - process the CA certificates and store results in $this->attributes['internal:CAs'][0] |
|
66
|
|
|
* $this->attributes['internal:CAs'][0] is an array of processed CA certificates |
|
67
|
|
|
* a processed certifincate is an array |
|
68
|
|
|
* 'pem' points to pem feromat certificate |
|
69
|
|
|
* 'der' points to der format certificate |
|
70
|
|
|
* 'md5' points to md5 fingerprint |
|
71
|
|
|
* 'sha1' points to sha1 fingerprint |
|
72
|
|
|
* 'name' points to the certificate subject |
|
73
|
|
|
* 'root' can be 1 for self-signed certificate or 0 otherwise |
|
74
|
|
|
* - save the info_file (if exists) and put the name in $this->attributes['internal:info_file_name'][0] |
|
75
|
|
|
* Finally, the module {@link DeviceConfig::writeInstaller ()} is called and the returned path name is used for user download. |
|
76
|
|
|
* |
|
77
|
|
|
* @package ModuleWriting |
|
78
|
|
|
*/ |
|
79
|
|
|
class DeviceTestModule extends \core\DeviceConfig { |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* Constructs a Device object. |
|
83
|
|
|
* |
|
84
|
|
|
* It is CRUCIAL that the constructor sets $this->supportedEapMethods to an array of methods |
|
85
|
|
|
* available for the particular device. |
|
86
|
|
|
* |
|
87
|
|
|
* @final not to be redefined |
|
88
|
|
|
*/ |
|
89
|
|
|
final public function __construct() { |
|
90
|
|
|
parent::__construct(); |
|
91
|
|
|
$this->setSupportedEapMethods(\core\common\EAP::EAPTYPES_CONVERSION); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* prepare a zip archive containing files and settings which normally would be used inside the module to produce an installer |
|
96
|
|
|
* |
|
97
|
|
|
* @return string installer path name |
|
98
|
|
|
*/ |
|
99
|
|
|
public function writeInstaller() { |
|
100
|
|
|
$this->loggerInstance->debug(4, "Test Module Installer start\n"); |
|
101
|
|
|
// create certificate files and save their names in $cAfiles arrary |
|
102
|
|
|
$cAfiles = $this->saveCertificateFiles('der'); |
|
103
|
|
|
if ($cAfiles === []) { |
|
104
|
|
|
$this->loggerInstance->debug(2, "copying of certificates failed\n"); |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
// copy a fixed file from the module Files directory |
|
108
|
|
|
if (!$this->copyFile('Module.howto')) { |
|
109
|
|
|
$this->loggerInstance->debug(2, "copying of Module.howto failed\n"); |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
// copy a fixed file from the module Files directory and saveunde a different name |
|
113
|
|
|
if (!$this->copyFile('test_file', 'copied_test_file')) { |
|
114
|
|
|
$this->loggerInstance->debug(2, "copying of Module.howto to copied_test_file failed\n"); |
|
115
|
|
|
} |
|
116
|
|
|
$this->dumpAttibutes('profile_attributes'); |
|
117
|
|
|
return $this->zipInstaller(); |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
/** |
|
121
|
|
|
* prepare module desctiption and usage information |
|
122
|
|
|
* |
|
123
|
|
|
* @return string HTML text to be displayed in the information window |
|
124
|
|
|
*/ |
|
125
|
|
|
public function writeDeviceInfo() { |
|
126
|
|
|
\core\common\Entity::intoThePotatoes(); |
|
127
|
|
|
$ssidCount = count($this->attributes['internal:SSID']); |
|
128
|
|
|
$out = "<p>"; |
|
129
|
|
|
$out .= sprintf(_("This installer is an example only. It produces a zip file containig the IdP certificates, info and logo files (if such have been defined by the IdP administrator) and a dump of all available attributes. The installer is called with %d SSIDs to configure."), $ssidCount); |
|
130
|
|
|
\core\common\Entity::outOfThePotatoes(); |
|
131
|
|
|
return $out; |
|
132
|
|
|
} |
|
133
|
|
|
|
|
134
|
|
|
/** |
|
135
|
|
|
* zip files and return the archive name |
|
136
|
|
|
* |
|
137
|
|
|
* @return string |
|
138
|
|
|
*/ |
|
139
|
|
|
private function zipInstaller() { |
|
140
|
|
|
// one can always access $this->attributes to check things |
|
141
|
|
|
$fileName = $this->installerBasename . '.zip'; |
|
142
|
|
|
$output = system('zip -q ' . $fileName . ' *'); |
|
143
|
|
|
if ($output === FALSE) { |
|
144
|
|
|
$this->loggerInstance->debug(2, "unable to zip the installer\n"); |
|
145
|
|
|
} |
|
146
|
|
|
return $fileName; |
|
147
|
|
|
} |
|
148
|
|
|
} |
|
149
|
|
|
|