Completed
Branch master (03ec64)
by Brook
14:43
created
core/DeviceConfig.php 1 patch
Indentation   +421 added lines, -421 removed lines patch added patch discarded remove patch
@@ -6,10 +6,10 @@  discard block
 block discarded – undo
6 6
 ?>
7 7
 <?php
8 8
 /**
9
-  * This file defines the abstract Device class
10
-  *
11
-  * @package ModuleWriting
12
-  */
9
+ * This file defines the abstract Device class
10
+ *
11
+ * @package ModuleWriting
12
+ */
13 13
 
14 14
 /**
15 15
  * 
@@ -46,10 +46,10 @@  discard block
 block discarded – undo
46 46
  */
47 47
 
48 48
 abstract class DeviceConfig {
49
-   /**
50
-    * stores the path to the temporary working directory for a module instance
51
-    * @var string $FPATH
52
-    */
49
+    /**
50
+     * stores the path to the temporary working directory for a module instance
51
+     * @var string $FPATH
52
+     */
53 53
     public $FPATH;
54 54
 
55 55
     /**
@@ -58,390 +58,390 @@  discard block
 block discarded – undo
58 58
      */
59 59
     public $specialities;
60 60
 
61
-   /**
61
+    /**
62 62
      * device module constructor should be defined by each module, but if it is not, then here is a default one
63 63
      */
64 64
 
65
-      public function __construct() {
66
-      $this->supportedEapMethods  = [EAP::$TLS, EAP::$PEAP_MSCHAP2, EAP::$TTLS_PAP];
67
-      debug(4,"This device supports the following EAP methods: ");
68
-      debug(4,$this->supportedEapMethods);
65
+        public function __construct() {
66
+        $this->supportedEapMethods  = [EAP::$TLS, EAP::$PEAP_MSCHAP2, EAP::$TTLS_PAP];
67
+        debug(4,"This device supports the following EAP methods: ");
68
+        debug(4,$this->supportedEapMethods);
69 69
     }
70 70
 
71 71
 
72
-   /**
73
-    * Set up working environment for a device module
74
-    *
75
-    * Sets up the device module environment taking into account the actual profile
76
-    * selected by the user in the GUI. The selected profile is passed as the
77
-    * Profile $profile argumant.
78
-    *
79
-    * This method needs to be called after the device instance has been created (the GUI class does that)
80
-    *
81
-    * setup performs the following tasks:
82
-    * - collect profile attributes and pass them as the attributes property;
83
-    * - create the temporary working directory
84
-    * - process CA certificates and store them as 'internal:CAs' attribute
85
-    * - process and save optional info files and store references to them in
86
-    *   'internal:info_file' attribute
87
-    * @param Profile $profile the profile object which will be passed by the caller
88
-    * @final not to be redefined
89
-    */
72
+    /**
73
+     * Set up working environment for a device module
74
+     *
75
+     * Sets up the device module environment taking into account the actual profile
76
+     * selected by the user in the GUI. The selected profile is passed as the
77
+     * Profile $profile argumant.
78
+     *
79
+     * This method needs to be called after the device instance has been created (the GUI class does that)
80
+     *
81
+     * setup performs the following tasks:
82
+     * - collect profile attributes and pass them as the attributes property;
83
+     * - create the temporary working directory
84
+     * - process CA certificates and store them as 'internal:CAs' attribute
85
+     * - process and save optional info files and store references to them in
86
+     *   'internal:info_file' attribute
87
+     * @param Profile $profile the profile object which will be passed by the caller
88
+     * @final not to be redefined
89
+     */
90 90
     final public function setup(Profile $profile) {
91
-       debug(4,"module setup start\n");
92
-       if(! $profile instanceof Profile) {
93
-          debug(2,"No profile has been set\n");
94
-          error("No profile has been set");
95
-          exit;
96
-       }
97
-       $this->attributes = $this->getProfileAttributes($profile);
98
-       if(! $this->selected_eap) {
99
-          error("No EAP type specified.");
100
-          exit;
101
-       }
102
-       // create temporary directory, its full path will be saved in $this->FPATH;
103
-       $T = createTemporaryDirectory('installer');
104
-       $this->FPATH = $T['dir'];
105
-       mkdir($T['dir'].'/tmp');
106
-       chdir($T['dir'].'/tmp');
107
-       $CAs = [];
108
-       if(isset($this->attributes['eap:ca_file'])) {
109
-       foreach ($this->attributes['eap:ca_file'] as $ca) {
110
-          if($c = X509::processCertificate($ca))
111
-             $CAs[] = $c;
112
-          }
113
-          $this->attributes['internal:CAs'][0]=$CAs;
114
-       }
115
-       if(isset($this->attributes['support:info_file'])) {
116
-          $this->attributes['internal:info_file'][0] = 
117
-             $this->saveInfoFile($this->attributes['support:info_file'][0]);
118
-       }
119
-       if(isset($this->attributes['general:logo_file']))
120
-          $this->attributes['internal:logo_file'] = 
121
-             $this->saveLogoFile($this->attributes['general:logo_file']);
122
-       $this->attributes['internal:SSID'] = $this->getSSIDs()['add'];;
123
-       $this->attributes['internal:remove_SSID'] = $this->getSSIDs()['del'];;
124
-       $this->attributes['internal:consortia'] = $this->getConsortia();
125
-       $this->lang_index = CAT::get_lang();
126
-       // phpMD says the below is not needed. Wow.
127
-       // $idp = new IdP($profile->institution);
128
-       $olddomain = CAT::set_locale("core");
129
-       $this->support_email_substitute = sprintf(_("your local %s support"),Config::$CONSORTIUM['name']);
130
-       $this->support_url_substitute = sprintf(_("your local %s support page"),Config::$CONSORTIUM['name']);
131
-       CAT::set_locale($olddomain);
132
-
133
-       if($this->signer && $this->options['sign'])
134
-         $this->sign = CAT::$root . '/signer/'. $this->signer;
135
-       $this->installerBasename = $this->getInstallerBasename();
91
+        debug(4,"module setup start\n");
92
+        if(! $profile instanceof Profile) {
93
+            debug(2,"No profile has been set\n");
94
+            error("No profile has been set");
95
+            exit;
96
+        }
97
+        $this->attributes = $this->getProfileAttributes($profile);
98
+        if(! $this->selected_eap) {
99
+            error("No EAP type specified.");
100
+            exit;
101
+        }
102
+        // create temporary directory, its full path will be saved in $this->FPATH;
103
+        $T = createTemporaryDirectory('installer');
104
+        $this->FPATH = $T['dir'];
105
+        mkdir($T['dir'].'/tmp');
106
+        chdir($T['dir'].'/tmp');
107
+        $CAs = [];
108
+        if(isset($this->attributes['eap:ca_file'])) {
109
+        foreach ($this->attributes['eap:ca_file'] as $ca) {
110
+            if($c = X509::processCertificate($ca))
111
+                $CAs[] = $c;
112
+            }
113
+            $this->attributes['internal:CAs'][0]=$CAs;
114
+        }
115
+        if(isset($this->attributes['support:info_file'])) {
116
+            $this->attributes['internal:info_file'][0] = 
117
+                $this->saveInfoFile($this->attributes['support:info_file'][0]);
118
+        }
119
+        if(isset($this->attributes['general:logo_file']))
120
+            $this->attributes['internal:logo_file'] = 
121
+                $this->saveLogoFile($this->attributes['general:logo_file']);
122
+        $this->attributes['internal:SSID'] = $this->getSSIDs()['add'];;
123
+        $this->attributes['internal:remove_SSID'] = $this->getSSIDs()['del'];;
124
+        $this->attributes['internal:consortia'] = $this->getConsortia();
125
+        $this->lang_index = CAT::get_lang();
126
+        // phpMD says the below is not needed. Wow.
127
+        // $idp = new IdP($profile->institution);
128
+        $olddomain = CAT::set_locale("core");
129
+        $this->support_email_substitute = sprintf(_("your local %s support"),Config::$CONSORTIUM['name']);
130
+        $this->support_url_substitute = sprintf(_("your local %s support page"),Config::$CONSORTIUM['name']);
131
+        CAT::set_locale($olddomain);
132
+
133
+        if($this->signer && $this->options['sign'])
134
+            $this->sign = CAT::$root . '/signer/'. $this->signer;
135
+        $this->installerBasename = $this->getInstallerBasename();
136 136
     }
137 137
 
138
-  /**
139
-    * Selects the preferred eap method based on profile EAP configuration and device EAP capabilities
140
-    *
141
-    * @param array eap_array an array of eap methods supported by a given device
142
-    * @return the best matching EAP type for the profile; or 0 if no match was found
143
-    */   
144
-   public function getPreferredEapType($eap_array) {
145
-     foreach ($eap_array as $eap) {
146
-         if(in_array($eap,$this->supportedEapMethods)) {
138
+    /**
139
+     * Selects the preferred eap method based on profile EAP configuration and device EAP capabilities
140
+     *
141
+     * @param array eap_array an array of eap methods supported by a given device
142
+     * @return the best matching EAP type for the profile; or 0 if no match was found
143
+     */   
144
+    public function getPreferredEapType($eap_array) {
145
+        foreach ($eap_array as $eap) {
146
+            if(in_array($eap,$this->supportedEapMethods)) {
147 147
             $this->selected_eap = $eap;
148 148
             debug(4,"Selected EAP:");
149 149
             debug(4,$eap);
150 150
             return($eap);
151
-         }
152
-     }
153
-     return(0);
154
-   }
155
-  /**
156
-    * prepare usage information for the installer
157
-    * every device module should override this method
158
-    *
159
-    * @return String HTML text to be displayed
160
-    */ 
161
-   public function writeDeviceInfo() {
162
-     return _("Sorry, this should not happen - no additional information is available");
163
-   }
164
-
165
-  /**
166
-    *  Copy a file from the module location to the temporary directory.
167
-    *
168
-    * If the second argument is provided then the file will be saved under the name 
169
-    * taken form this argument. If only one parameter is given, source and destination
170
-    * filenames are the same
171
-    * Source file can be located either in the Files subdirectory or in the sibdirectory of Files
172
-    * named the same as device_id. The second option takes precedence.
173
-    *
174
-    * @param string $source_name The source file name
175
-    * @param string $output_name The destination file name
176
-    *
177
-    * @return bool result of the copy operation
178
-    * @final not to be redefined
179
-    */
180
-   final protected function copyFile($source_name, $output_name = 0) {
181
-      if  ( $output_name === 0)
151
+            }
152
+        }
153
+        return(0);
154
+    }
155
+    /**
156
+     * prepare usage information for the installer
157
+     * every device module should override this method
158
+     *
159
+     * @return String HTML text to be displayed
160
+     */ 
161
+    public function writeDeviceInfo() {
162
+        return _("Sorry, this should not happen - no additional information is available");
163
+    }
164
+
165
+    /**
166
+     *  Copy a file from the module location to the temporary directory.
167
+     *
168
+     * If the second argument is provided then the file will be saved under the name 
169
+     * taken form this argument. If only one parameter is given, source and destination
170
+     * filenames are the same
171
+     * Source file can be located either in the Files subdirectory or in the sibdirectory of Files
172
+     * named the same as device_id. The second option takes precedence.
173
+     *
174
+     * @param string $source_name The source file name
175
+     * @param string $output_name The destination file name
176
+     *
177
+     * @return bool result of the copy operation
178
+     * @final not to be redefined
179
+     */
180
+    final protected function copyFile($source_name, $output_name = 0) {
181
+        if  ( $output_name === 0)
182 182
         $output_name = $source_name;
183 183
 
184
-      debug(4,"fileCopy($source_name, $output_name)\n");
185
-      if(is_file($this->module_path.'/Files/'.$this->device_id.'/'.$source_name))
186
-         $source = $this->module_path.'/Files/'.$this->device_id.'/'.$source_name;
187
-      elseif(is_file($this->module_path.'/Files/'.$source_name))
188
-         $source = $this->module_path.'/Files/'.$source_name;
189
-      else {
184
+        debug(4,"fileCopy($source_name, $output_name)\n");
185
+        if(is_file($this->module_path.'/Files/'.$this->device_id.'/'.$source_name))
186
+            $source = $this->module_path.'/Files/'.$this->device_id.'/'.$source_name;
187
+        elseif(is_file($this->module_path.'/Files/'.$source_name))
188
+            $source = $this->module_path.'/Files/'.$source_name;
189
+        else {
190 190
         debug(2,"fileCopy:reqested file $source_name does not exist\n");
191 191
         return(FALSE);
192
-      }
193
-      debug(4,"Copying $source to $output_name\n");
194
-      $result = copy($source,"$output_name");
195
-      if(! $result )
192
+        }
193
+        debug(4,"Copying $source to $output_name\n");
194
+        $result = copy($source,"$output_name");
195
+        if(! $result )
196 196
         debug(2,"fileCopy($source_name, $output_name) failed\n");
197
-      return($result); 
198
-   }
199
-
200
-
201
-  /**
202
-    *  Copy a file from the module location to the temporary directory aplying transcoding.
203
-    *
204
-    * Transcoding is only required for Windows installers, and no Unicode support
205
-    * in NSIS (NSIS version below 3)
206
-    * Trancoding is only applied if the third optional parameter is set and nonzero
207
-    * If Config::$NSIS_VERSION is set to 3 or more, no transcoding will be applied
208
-    * regardless of the third parameter value.
209
-    * If the second argument is provided and is not equal to 0, then the file will be
210
-    * saved under the name taken from this argument.
211
-    * If only one parameter is given or the second is equal to 0, source and destination
212
-    * filenames are the same.
213
-    * The third optional parameter, if nonzero, should be the character set understood by iconv
214
-    * This is required by the Windows installer and is expected to go away in the future.
215
-    * Source file can be located either in the Files subdirectory or in the sibdirectory of Files
216
-    * named the same as device_id. The second option takes precedence.
217
-    *
218
-    * @param string $source_name The source file name
219
-    * @param string $output_name The destination file name
220
-    * @param int $use_win_cp Set Windows charset if non-zero
221
-    *
222
-    * @final not to be redefined
223
-    */
224
-
225
-   final protected function translateFile($source_name, $output_name = 0, $encoding = 0) {
226
-      if(Config::$NSIS_VERSION >= 3)
197
+        return($result); 
198
+    }
199
+
200
+
201
+    /**
202
+     *  Copy a file from the module location to the temporary directory aplying transcoding.
203
+     *
204
+     * Transcoding is only required for Windows installers, and no Unicode support
205
+     * in NSIS (NSIS version below 3)
206
+     * Trancoding is only applied if the third optional parameter is set and nonzero
207
+     * If Config::$NSIS_VERSION is set to 3 or more, no transcoding will be applied
208
+     * regardless of the third parameter value.
209
+     * If the second argument is provided and is not equal to 0, then the file will be
210
+     * saved under the name taken from this argument.
211
+     * If only one parameter is given or the second is equal to 0, source and destination
212
+     * filenames are the same.
213
+     * The third optional parameter, if nonzero, should be the character set understood by iconv
214
+     * This is required by the Windows installer and is expected to go away in the future.
215
+     * Source file can be located either in the Files subdirectory or in the sibdirectory of Files
216
+     * named the same as device_id. The second option takes precedence.
217
+     *
218
+     * @param string $source_name The source file name
219
+     * @param string $output_name The destination file name
220
+     * @param int $use_win_cp Set Windows charset if non-zero
221
+     *
222
+     * @final not to be redefined
223
+     */
224
+
225
+    final protected function translateFile($source_name, $output_name = 0, $encoding = 0) {
226
+        if(Config::$NSIS_VERSION >= 3)
227 227
         $encoding = 0;
228
-      if  ( $output_name === 0)
228
+        if  ( $output_name === 0)
229 229
         $output_name = $source_name;
230 230
 
231
-      debug(4,"translateFile($source_name, $output_name, $encoding)\n");
232
-      ob_start();
233
-      debug(4,$this->module_path.'/Files/'.$this->device_id.'/'.$source_name."\n");
234
-      if(is_file($this->module_path.'/Files/'.$this->device_id.'/'.$source_name))
235
-         $source = $this->module_path.'/Files/'.$this->device_id.'/'.$source_name;
236
-      elseif(is_file($this->module_path.'/Files/'.$source_name))
237
-         $source = $this->module_path.'/Files/'.$source_name;
238
-      include($source);
239
-      $output = ob_get_clean();
240
-      if($encoding) {
231
+        debug(4,"translateFile($source_name, $output_name, $encoding)\n");
232
+        ob_start();
233
+        debug(4,$this->module_path.'/Files/'.$this->device_id.'/'.$source_name."\n");
234
+        if(is_file($this->module_path.'/Files/'.$this->device_id.'/'.$source_name))
235
+            $source = $this->module_path.'/Files/'.$this->device_id.'/'.$source_name;
236
+        elseif(is_file($this->module_path.'/Files/'.$source_name))
237
+            $source = $this->module_path.'/Files/'.$source_name;
238
+        include($source);
239
+        $output = ob_get_clean();
240
+        if($encoding) {
241 241
         $output_c = iconv('UTF-8',$encoding.'//TRANSLIT',$output);
242 242
         if($output_c)
243
-           $output = $output_c;
244
-      }
245
-      $f = fopen("$output_name","w");
246
-      if(! $f)
247
-         debug(2,"translateFile($source, $output_name, $encoding) failed\n");
248
-      fwrite($f,$output);
249
-      fclose($f);
250
-      debug(4,"translateFile($source, $output_name, $encoding) end\n");
251
-   }
252
-
253
-
254
-  /**
255
-    * Transcode a string adding double quotes escaping
256
-    *
257
-    * Transcoding is only required for Windows installers, and no Unicode support
258
-    * in NSIS (NSIS version below 3)
259
-    * Trancoding is only applied if the third optional parameter is set and nonzero
260
-    * If Config::$NSIS_VERSION is set to 3 or more, no transcoding will be applied
261
-    * regardless of the second parameter value.
262
-    * The second optional parameter, if nonzero, should be the character set understood by iconv
263
-    * This is required by the Windows installer and is expected to go away in the future.
264
-    *
265
-    * @param string $source_name The source file name
266
-    * @param int $use_win_cp Set Windows charset if non-zero
267
-    *
268
-    * @final not to be redefined
269
-    */
270
-
271
-   final protected function translateString($source_string,$encoding = 0) {
272
-      if(Config::$NSIS_VERSION >= 3)
243
+            $output = $output_c;
244
+        }
245
+        $f = fopen("$output_name","w");
246
+        if(! $f)
247
+            debug(2,"translateFile($source, $output_name, $encoding) failed\n");
248
+        fwrite($f,$output);
249
+        fclose($f);
250
+        debug(4,"translateFile($source, $output_name, $encoding) end\n");
251
+    }
252
+
253
+
254
+    /**
255
+     * Transcode a string adding double quotes escaping
256
+     *
257
+     * Transcoding is only required for Windows installers, and no Unicode support
258
+     * in NSIS (NSIS version below 3)
259
+     * Trancoding is only applied if the third optional parameter is set and nonzero
260
+     * If Config::$NSIS_VERSION is set to 3 or more, no transcoding will be applied
261
+     * regardless of the second parameter value.
262
+     * The second optional parameter, if nonzero, should be the character set understood by iconv
263
+     * This is required by the Windows installer and is expected to go away in the future.
264
+     *
265
+     * @param string $source_name The source file name
266
+     * @param int $use_win_cp Set Windows charset if non-zero
267
+     *
268
+     * @final not to be redefined
269
+     */
270
+
271
+    final protected function translateString($source_string,$encoding = 0) {
272
+        if(Config::$NSIS_VERSION >= 3)
273 273
         $encoding = 0;
274
-      if($encoding)
274
+        if($encoding)
275 275
         $output_c = iconv('UTF-8',$encoding.'//TRANSLIT',$source_string);
276
-      else
276
+        else
277 277
         $output_c = $source_string;
278
-      if($output_c) 
279
-         $source_string  = str_replace('"','$\\"',$output_c);
280
-      else
281
-         debug(2,"Failed to convert string $source_string\n");
282
-      return $source_string;
283
-   }
284
-
285
-
286
-  /**
287
-   * Save certificate files in either DER or PEM format
288
-   *
289
-   * Certificate files will be saved in the module working directory.
290
-   * @param string $format  only "der" and "pem" are currently allowed
291
-   * @return array an array of arrays or FALSE on error
292
-   * saved certificate file names are avalable under the 'file' index
293
-   * additional array entries are indexed as 'sha1', 'md5', and 'root'.
294
-   * sha1 and md5 are correcponding certificate hashes
295
-   * root is set to 1 for the CA roor certicicate and 0 otherwise
296
-  */ 
297
-   final protected function saveCertificateFiles($format) {
298
-     if($format == 'der' || $format == 'pam') {
299
-       $i = 0;
300
-       $CA_files = [];
301
-       $ca_array = $this->attributes['internal:CAs'][0];
302
-       if(! $ca_array)
303
-         return(FALSE);
304
-       foreach ($ca_array as $CA) {
305
-         $f = fopen("cert-$i.crt","w");
306
-         if(! $f) die("problem opening the file\n");
307
-         if($format == "pem")
278
+        if($output_c) 
279
+            $source_string  = str_replace('"','$\\"',$output_c);
280
+        else
281
+            debug(2,"Failed to convert string $source_string\n");
282
+        return $source_string;
283
+    }
284
+
285
+
286
+    /**
287
+     * Save certificate files in either DER or PEM format
288
+     *
289
+     * Certificate files will be saved in the module working directory.
290
+     * @param string $format  only "der" and "pem" are currently allowed
291
+     * @return array an array of arrays or FALSE on error
292
+     * saved certificate file names are avalable under the 'file' index
293
+     * additional array entries are indexed as 'sha1', 'md5', and 'root'.
294
+     * sha1 and md5 are correcponding certificate hashes
295
+     * root is set to 1 for the CA roor certicicate and 0 otherwise
296
+     */ 
297
+    final protected function saveCertificateFiles($format) {
298
+        if($format == 'der' || $format == 'pam') {
299
+        $i = 0;
300
+        $CA_files = [];
301
+        $ca_array = $this->attributes['internal:CAs'][0];
302
+        if(! $ca_array)
303
+            return(FALSE);
304
+        foreach ($ca_array as $CA) {
305
+            $f = fopen("cert-$i.crt","w");
306
+            if(! $f) die("problem opening the file\n");
307
+            if($format == "pem")
308 308
             fwrite($f,$CA['pem']);
309
-         else
309
+            else
310 310
             fwrite($f,$CA['der']);
311
-         fclose($f);
312
-         $C = [];
313
-         $C['file'] = "cert-$i.crt";
314
-         $C['sha1'] = $CA['sha1'];
315
-         $C['md5'] = $CA['md5'];
316
-         $C['root'] = $CA['root'];
317
-         $CA_files[] = $C;
318
-         $i++;
319
-       }
320
-       return($CA_files);
321
-     } else {
322
-       debug(2, 'incorrect format value specified');
323
-       return(FALSE);
324
-     }
311
+            fclose($f);
312
+            $C = [];
313
+            $C['file'] = "cert-$i.crt";
314
+            $C['sha1'] = $CA['sha1'];
315
+            $C['md5'] = $CA['md5'];
316
+            $C['root'] = $CA['root'];
317
+            $CA_files[] = $C;
318
+            $i++;
319
+        }
320
+        return($CA_files);
321
+        } else {
322
+        debug(2, 'incorrect format value specified');
323
+        return(FALSE);
324
+        }
325 325
       
326
-   }
327
-
328
-   /**
329
-    * Generate installer filename base.
330
-    * Device module should use this name adding an extension.
331
-    * Normally the device identifier follows the Consortium name.
332
-    * The sting taken for the device identifier equals (by default) to the index in the listDevices array,
333
-    * but can be overriden with the 'device_id' device option.
334
-    */
335
-   private function getInstallerBasename() {
336
-      $replace_pattern = '/[ ()\/\'"]+/';
337
-      debug(4,"getInstallerBasename1:".$this->attributes['general:instname'][0]."\n");
338
-      $inst = iconv("UTF-8", "US-ASCII//TRANSLIT", preg_replace($replace_pattern, '_', $this->attributes['general:instname'][0]));
339
-      debug(4,"getInstallerBasename2:$inst\n");
340
-      $Inst_a = explode('_',$inst);
341
-      if(count($Inst_a) > 2) {
342
-         $inst = '';
343
-         foreach($Inst_a as $i)
344
-           $inst .= $i[0];
345
-      }   
346
-      $c_name = iconv("UTF-8", "US-ASCII//TRANSLIT", preg_replace($replace_pattern, '_', Config::$CONSORTIUM['name']));
347
-      if($this->attributes['internal:profile_count'][0] > 1) {
348
-         if(!empty($this->attributes['profile:name']) && ! empty($this->attributes['profile:name'][0])) {
349
-             $prof = iconv("UTF-8", "US-ASCII//TRANSLIT", preg_replace($replace_pattern, '_', $this->attributes['profile:name'][0]));
350
-             $prof = preg_replace('/_+$/','',$prof);
351
-             return $c_name. '-'. $this->getDeviceId() . $inst .'-'. $prof;
352
-         }
353
-      }
354
-      return $c_name. '-'. $this->getDeviceId() . $inst;
355
-  }
356
-
357
-  private function getDeviceId() {
326
+    }
327
+
328
+    /**
329
+     * Generate installer filename base.
330
+     * Device module should use this name adding an extension.
331
+     * Normally the device identifier follows the Consortium name.
332
+     * The sting taken for the device identifier equals (by default) to the index in the listDevices array,
333
+     * but can be overriden with the 'device_id' device option.
334
+     */
335
+    private function getInstallerBasename() {
336
+        $replace_pattern = '/[ ()\/\'"]+/';
337
+        debug(4,"getInstallerBasename1:".$this->attributes['general:instname'][0]."\n");
338
+        $inst = iconv("UTF-8", "US-ASCII//TRANSLIT", preg_replace($replace_pattern, '_', $this->attributes['general:instname'][0]));
339
+        debug(4,"getInstallerBasename2:$inst\n");
340
+        $Inst_a = explode('_',$inst);
341
+        if(count($Inst_a) > 2) {
342
+            $inst = '';
343
+            foreach($Inst_a as $i)
344
+            $inst .= $i[0];
345
+        }   
346
+        $c_name = iconv("UTF-8", "US-ASCII//TRANSLIT", preg_replace($replace_pattern, '_', Config::$CONSORTIUM['name']));
347
+        if($this->attributes['internal:profile_count'][0] > 1) {
348
+            if(!empty($this->attributes['profile:name']) && ! empty($this->attributes['profile:name'][0])) {
349
+                $prof = iconv("UTF-8", "US-ASCII//TRANSLIT", preg_replace($replace_pattern, '_', $this->attributes['profile:name'][0]));
350
+                $prof = preg_replace('/_+$/','',$prof);
351
+                return $c_name. '-'. $this->getDeviceId() . $inst .'-'. $prof;
352
+            }
353
+        }
354
+        return $c_name. '-'. $this->getDeviceId() . $inst;
355
+    }
356
+
357
+    private function getDeviceId() {
358 358
     $d_id = $this->device_id;
359 359
     if(isset($this->options['device_id'])) 
360
-      $d_id = $this->options['device_id'];
360
+        $d_id = $this->options['device_id'];
361 361
     if($d_id !== '')
362
-      $d_id .= '-';
362
+        $d_id .= '-';
363 363
     return $d_id;
364
-  }
364
+    }
365 365
 
366 366
 
367
-  private function getSSIDs() {
367
+    private function getSSIDs() {
368 368
     $S['add']=[];
369 369
     $S['del']=[];
370 370
     if (isset(Config::$CONSORTIUM['ssid'])) {
371
-       foreach (Config::$CONSORTIUM['ssid'] as $ssid) {
371
+        foreach (Config::$CONSORTIUM['ssid'] as $ssid) {
372 372
         if(isset(Config::$CONSORTIUM['tkipsupport']) && Config::$CONSORTIUM['tkipsupport'] == TRUE)
373
-          $S['add'][$ssid] = 'TKIP';
373
+            $S['add'][$ssid] = 'TKIP';
374 374
         else {
375
-          $S['add'][$ssid] = 'AES';
376
-          $S['del'][$ssid] = 'TKIP';
375
+            $S['add'][$ssid] = 'AES';
376
+            $S['del'][$ssid] = 'TKIP';
377
+        }
377 378
         }
378
-       }
379 379
     }
380 380
     if(isset($this->attributes['media:SSID'])) {
381
-      $SSID = $this->attributes['media:SSID'];
381
+        $SSID = $this->attributes['media:SSID'];
382 382
 
383
-      foreach($SSID as $ssid)
384
-         $S['add'][$ssid] = 'AES';
385
-      }
383
+        foreach($SSID as $ssid)
384
+            $S['add'][$ssid] = 'AES';
385
+        }
386 386
     if(isset($this->attributes['media:SSID_with_legacy'])) {
387
-      $SSID = $this->attributes['media:SSID_with_legacy'];
388
-      foreach($SSID as $ssid)
389
-         $S['add'][$ssid] = 'TKIP';
387
+        $SSID = $this->attributes['media:SSID_with_legacy'];
388
+        foreach($SSID as $ssid)
389
+            $S['add'][$ssid] = 'TKIP';
390 390
     }
391 391
     if(isset($this->attributes['media:remove_SSID'])) {
392
-      $SSID = $this->attributes['media:remove_SSID'];
393
-      foreach($SSID as $ssid)
394
-         $S['del'][$ssid] = 'DEL';
392
+        $SSID = $this->attributes['media:remove_SSID'];
393
+        foreach($SSID as $ssid)
394
+            $S['del'][$ssid] = 'DEL';
395 395
     }
396 396
     return $S;
397
-  }
397
+    }
398 398
 
399
-  private function getConsortia() {
400
-      $OIs = [];
401
-      $OIs = array_merge($OIs, Config::$CONSORTIUM['interworking-consortium-oi']);
402
-      if (isset($this->attributes['media:consortium_OI']))
403
-          foreach ($this->attributes['media:consortium_OI'] as $new_oi)
399
+    private function getConsortia() {
400
+        $OIs = [];
401
+        $OIs = array_merge($OIs, Config::$CONSORTIUM['interworking-consortium-oi']);
402
+        if (isset($this->attributes['media:consortium_OI']))
403
+            foreach ($this->attributes['media:consortium_OI'] as $new_oi)
404 404
             $OIs[] = $new_oi;
405
-      return $OIs;
406
-  }
405
+        return $OIs;
406
+    }
407 407
   
408
-  /**
409
-   * An array with shorthand definitions for MIME types
410
-   * @var array
411
-   */
412
-  private $mime_extensions = [
413
-     'text/plain' => 'txt',
414
-     'text/rtf' => 'rtf',
415
-     'application/pdf' =>'pdf',
416
-  ];
417
-
418
-  private function saveLogoFile($Logos) {
408
+    /**
409
+     * An array with shorthand definitions for MIME types
410
+     * @var array
411
+     */
412
+    private $mime_extensions = [
413
+        'text/plain' => 'txt',
414
+        'text/rtf' => 'rtf',
415
+        'application/pdf' =>'pdf',
416
+    ];
417
+
418
+    private function saveLogoFile($Logos) {
419 419
     $i=0;
420 420
     $returnarray= [];
421 421
     foreach ($Logos as $blob) {
422
-      $finfo = new finfo(FILEINFO_MIME_TYPE);
423
-      $mime = $finfo->buffer($blob);
424
-      if(preg_match('/^image\/(.*)/',$mime,$m))
422
+        $finfo = new finfo(FILEINFO_MIME_TYPE);
423
+        $mime = $finfo->buffer($blob);
424
+        if(preg_match('/^image\/(.*)/',$mime,$m))
425 425
         $ext = $m[1];
426
-      else
426
+        else
427 427
         $ext = 'unsupported';
428
-      debug(4,"saveLogoFile: $mime : $ext\n");
429
-      $f_name = 'logo-'.$i.'.'.$ext;
430
-      $f = fopen($f_name,"w");
431
-      if(! $f) {
432
-          debug(2,"saveLogoFile failed for: $f_name\n");
433
-          die("problem opening the file\n");
434
-      }
435
-      fwrite($f,$blob);
436
-      fclose($f);
437
-      $returnarray[]= ['name'=>$f_name,'mime'=>$ext];
438
-      $i++;
428
+        debug(4,"saveLogoFile: $mime : $ext\n");
429
+        $f_name = 'logo-'.$i.'.'.$ext;
430
+        $f = fopen($f_name,"w");
431
+        if(! $f) {
432
+            debug(2,"saveLogoFile failed for: $f_name\n");
433
+            die("problem opening the file\n");
434
+        }
435
+        fwrite($f,$blob);
436
+        fclose($f);
437
+        $returnarray[]= ['name'=>$f_name,'mime'=>$ext];
438
+        $i++;
439 439
     }
440 440
     return($returnarray);
441
-  }
441
+    }
442 442
 
443 443
 
444
-  private function saveInfoFile($blob) {
444
+    private function saveInfoFile($blob) {
445 445
     $finfo = new finfo(FILEINFO_MIME_TYPE);
446 446
     $mime = $finfo->buffer($blob);
447 447
     $ext = isset($this->mime_extensions[$mime]) ? $this->mime_extensions[$mime] : 'usupported';
@@ -451,43 +451,43 @@  discard block
 block discarded – undo
451 451
     fwrite($f,$blob);
452 452
     fclose($f);
453 453
     return(['name'=>'local-info.'.$ext,'mime'=>$ext]);
454
-  }
455
-
456
-  private function getProfileAttributes(Profile $profile) {
457
-     $eaps = $profile->getEapMethodsinOrderOfPreference(1);
458
-     if($eap = $this->getPreferredEapType($eaps)) {
459
-          $a = $profile->getCollapsedAttributes($eap);
460
-          $a['eap'] = $eap;
461
-          $a['all_eaps'] = $eaps;
462
-          return($a);
463
-     } else {
464
-       error("No supported eap types found for this profile.");
465
-       return(FALSE);
466
-  }
467
-  }
454
+    }
455
+
456
+    private function getProfileAttributes(Profile $profile) {
457
+        $eaps = $profile->getEapMethodsinOrderOfPreference(1);
458
+        if($eap = $this->getPreferredEapType($eaps)) {
459
+            $a = $profile->getCollapsedAttributes($eap);
460
+            $a['eap'] = $eap;
461
+            $a['all_eaps'] = $eaps;
462
+            return($a);
463
+        } else {
464
+        error("No supported eap types found for this profile.");
465
+        return(FALSE);
466
+    }
467
+    }
468 468
 /**
469
-  * dumps attributes for debugging purposes
470
-  *
471
-  * dumpAttibutes method is supplied for debuging purposes, it simply dumps the attribute array
472
-  * to a file with name passed in the attribute.
473
-  * @param string $file the output file name
474
-  */
475
-  protected function dumpAttibutes($file) {
469
+     * dumps attributes for debugging purposes
470
+     *
471
+     * dumpAttibutes method is supplied for debuging purposes, it simply dumps the attribute array
472
+     * to a file with name passed in the attribute.
473
+     * @param string $file the output file name
474
+     */
475
+    protected function dumpAttibutes($file) {
476 476
         ob_start();
477 477
         print_r($this->attributes);
478 478
         $output = ob_get_clean();
479 479
         $f = fopen($file,"w");
480 480
         fwrite($f,$output);
481 481
         fclose($f);
482
-  }
482
+    }
483 483
 /** 
484
- * placeholder for the main device method
485
- *
486
- */
484
+     * placeholder for the main device method
485
+     *
486
+     */
487 487
 
488
-  protected function writeInstaller() {
489
-     return("download path");
490
-  }
488
+    protected function writeInstaller() {
489
+        return("download path");
490
+    }
491 491
 
492 492
 /**
493 493
  * Array passing all options to the device module.
@@ -521,76 +521,76 @@  discard block
 block discarded – undo
521 521
  * @see X509::processCertificate()
522 522
  * @var array $attributes
523 523
  */
524
-  public $attributes;
524
+    public $attributes;
525 525
 /**
526
-  * stores the path to the module source location and is used 
527
-  * by copyFile and translateFile
528
-  * the only reason for it to be a public variable ies that it is set by the DeviceFactory class
529
-  * module_path should not be used by module drivers.
530
-  * @var string 
531
-  */
532
-  public $module_path;
526
+     * stores the path to the module source location and is used 
527
+     * by copyFile and translateFile
528
+     * the only reason for it to be a public variable ies that it is set by the DeviceFactory class
529
+     * module_path should not be used by module drivers.
530
+     * @var string 
531
+     */
532
+    public $module_path;
533 533
 
534 534
 /**
535 535
  * The optimal EAP type
536 536
  *
537 537
  */ 
538 538
 /**
539
-  * optimal EAP method selected given profile and device
540
-  * @var EAP::constant
541
-  */
542
-  public $selected_eap;
539
+ * optimal EAP method selected given profile and device
540
+ * @var EAP::constant
541
+ */
542
+    public $selected_eap;
543 543
 /**
544
-  * the path to the profile signing program
545
-  * device modules which require signing should use this property to exec the signer
546
-  * the signer program must accept two arguments - input and output file names
547
-  * the signer program mus operate in the local directory and filenames are relative to this
548
-  * directory
549
-  *
550
-  *@var string
551
-  */
552
-  public $sign;
553
-  public $signer;
544
+     * the path to the profile signing program
545
+     * device modules which require signing should use this property to exec the signer
546
+     * the signer program must accept two arguments - input and output file names
547
+     * the signer program mus operate in the local directory and filenames are relative to this
548
+     * directory
549
+     *
550
+     *@var string
551
+     */
552
+    public $sign;
553
+    public $signer;
554 554
 /**
555
- * the string referencing the language (index ot the Config::$LANGUAGES array).
556
- * It is set to the current language and may be used by the device module to
557
- * set its language
558
- *
559
- *@var string
560
- */
561
-  public $lang_index;
562
-  /**
563
-   * The string identifier of the device (don't show this to users)
564
-   * @var string
565
-   */
566
-  public $device_id;
567
-
568
-  /**
569
-   * See devices-template.php for a list of available options
570
-   * @var array
571
-   */
572
-  public $options;
573
-
574
-  /**
575
-   * This string will be shown if no support email was configured by the admin
576
-   * 
577
-   * @var string 
578
-   */
579
-  public static $support_email_substitute;
580
-
581
-  /**
582
-   * This string will be shown if no support URL was configured by the admin
583
-   * 
584
-   * @var string 
585
-   */
586
-  public static $support_url_substitute;
587
-
588
-  /**
589
-   * This string should be used by all installer modules to set the 
590
-   * installer file basename.
591
-   *
592
-   * @var string 
593
-   */
594
-  public static $installerBasename;
555
+     * the string referencing the language (index ot the Config::$LANGUAGES array).
556
+     * It is set to the current language and may be used by the device module to
557
+     * set its language
558
+     *
559
+     *@var string
560
+     */
561
+    public $lang_index;
562
+    /**
563
+     * The string identifier of the device (don't show this to users)
564
+     * @var string
565
+     */
566
+    public $device_id;
567
+
568
+    /**
569
+     * See devices-template.php for a list of available options
570
+     * @var array
571
+     */
572
+    public $options;
573
+
574
+    /**
575
+     * This string will be shown if no support email was configured by the admin
576
+     * 
577
+     * @var string 
578
+     */
579
+    public static $support_email_substitute;
580
+
581
+    /**
582
+     * This string will be shown if no support URL was configured by the admin
583
+     * 
584
+     * @var string 
585
+     */
586
+    public static $support_url_substitute;
587
+
588
+    /**
589
+     * This string should be used by all installer modules to set the 
590
+     * installer file basename.
591
+     *
592
+     * @var string 
593
+     */
594
+    public static $installerBasename;
595 595
 }
596 596
 ?>
Please login to merge, or discard this patch.
core/DeviceFactory.php 1 patch
Indentation   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -46,7 +46,7 @@  discard block
 block discarded – undo
46 46
      */
47 47
     public function __construct($blueprint) {
48 48
 
49
-      $Dev = Devices::listDevices();
49
+        $Dev = Devices::listDevices();
50 50
         if(isset($Dev[$blueprint])) {
51 51
             if($Dev[$blueprint]['directory'] && $Dev[$blueprint]['module'])
52 52
                 require_once("devices/".$Dev[$blueprint]['directory']."/".$Dev[$blueprint]['module'].".php");
@@ -60,16 +60,16 @@  discard block
 block discarded – undo
60 60
         } else {
61 61
             error("unknown devicename:$blueprint");
62 62
         }
63
-       $this->device->module_path = CAT::$root.'/devices/'.$Dev[$blueprint]['directory'];
64
-       $this->device->signer = isset($Dev[$blueprint]['signer']) ? $Dev[$blueprint]['signer'] : 0; 
65
-       $this->device->device_id = $blueprint;
66
-       $options = Devices::$Options;
67
-       if(isset($Dev[$blueprint]['options'])) {
68
-          $Opt = $Dev[$blueprint]['options'];
69
-          foreach ($Opt as $option => $value)
63
+        $this->device->module_path = CAT::$root.'/devices/'.$Dev[$blueprint]['directory'];
64
+        $this->device->signer = isset($Dev[$blueprint]['signer']) ? $Dev[$blueprint]['signer'] : 0; 
65
+        $this->device->device_id = $blueprint;
66
+        $options = Devices::$Options;
67
+        if(isset($Dev[$blueprint]['options'])) {
68
+            $Opt = $Dev[$blueprint]['options'];
69
+            foreach ($Opt as $option => $value)
70 70
             $options[$option] = $value;
71
-       }
72
-       $this->device->options = $options;
71
+        }
72
+        $this->device->options = $options;
73 73
     }
74 74
 }
75 75
 ?>
Please login to merge, or discard this patch.
core/phpqrcode.php 1 patch
Indentation   +40 added lines, -40 removed lines patch added patch discarded remove patch
@@ -74,32 +74,32 @@  discard block
 block discarded – undo
74 74
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
75 75
  */
76 76
  
77
-	// Encoding modes
77
+    // Encoding modes
78 78
 	 
79
-	define('QR_MODE_NUL', -1);
80
-	define('QR_MODE_NUM', 0);
81
-	define('QR_MODE_AN', 1);
82
-	define('QR_MODE_8', 2);
83
-	define('QR_MODE_KANJI', 3);
84
-	define('QR_MODE_STRUCTURE', 4);
85
-
86
-	// Levels of error correction.
87
-
88
-	define('QR_ECLEVEL_L', 0);
89
-	define('QR_ECLEVEL_M', 1);
90
-	define('QR_ECLEVEL_Q', 2);
91
-	define('QR_ECLEVEL_H', 3);
79
+    define('QR_MODE_NUL', -1);
80
+    define('QR_MODE_NUM', 0);
81
+    define('QR_MODE_AN', 1);
82
+    define('QR_MODE_8', 2);
83
+    define('QR_MODE_KANJI', 3);
84
+    define('QR_MODE_STRUCTURE', 4);
85
+
86
+    // Levels of error correction.
87
+
88
+    define('QR_ECLEVEL_L', 0);
89
+    define('QR_ECLEVEL_M', 1);
90
+    define('QR_ECLEVEL_Q', 2);
91
+    define('QR_ECLEVEL_H', 3);
92 92
 	
93
-	// Supported output formats
93
+    // Supported output formats
94 94
 	
95
-	define('QR_FORMAT_TEXT', 0);
96
-	define('QR_FORMAT_PNG',  1);
95
+    define('QR_FORMAT_TEXT', 0);
96
+    define('QR_FORMAT_PNG',  1);
97 97
 	
98
-	class qrstr {
99
-		public static function set(&$srctab, $x, $y, $repl, $replLen = false) {
100
-			$srctab[$y] = substr_replace($srctab[$y], ($replLen !== false)?substr($repl,0,$replLen):$repl, $x, ($replLen !== false)?$replLen:strlen($repl));
101
-		}
102
-	}	
98
+    class qrstr {
99
+        public static function set(&$srctab, $x, $y, $repl, $replLen = false) {
100
+            $srctab[$y] = substr_replace($srctab[$y], ($replLen !== false)?substr($repl,0,$replLen):$repl, $x, ($replLen !== false)?$replLen:strlen($repl));
101
+        }
102
+    }	
103 103
 
104 104
 
105 105
 
@@ -211,9 +211,9 @@  discard block
 block discarded – undo
211 211
         //----------------------------------------------------------------------
212 212
         public static function buildCache()
213 213
         {
214
-			QRtools::markTime('before_build_cache');
214
+            QRtools::markTime('before_build_cache');
215 215
 			
216
-			$mask = new QRmask();
216
+            $mask = new QRmask();
217 217
             for ($a=1; $a <= QRSPEC_VERSION_MAX; $a++) {
218 218
                 $frame = QRspec::newFrame($a);
219 219
                 if (QR_IMAGE) {
@@ -221,13 +221,13 @@  discard block
 block discarded – undo
221 221
                     QRimage::png(self::binarize($frame), $fileName, 1, 0);
222 222
                 }
223 223
 				
224
-				$width = count($frame);
225
-				$bitMask = array_fill(0, $width, array_fill(0, $width, 0));
226
-				for ($maskNo=0; $maskNo<8; $maskNo++)
227
-					$mask->makeMaskNo($maskNo, $width, $frame, $bitMask, true);
224
+                $width = count($frame);
225
+                $bitMask = array_fill(0, $width, array_fill(0, $width, 0));
226
+                for ($maskNo=0; $maskNo<8; $maskNo++)
227
+                    $mask->makeMaskNo($maskNo, $width, $frame, $bitMask, true);
228 228
             }
229 229
 			
230
-			QRtools::markTime('after_build_cache');
230
+            QRtools::markTime('after_build_cache');
231 231
         }
232 232
 
233 233
         //----------------------------------------------------------------------
@@ -647,10 +647,10 @@  discard block
 block discarded – undo
647 647
 
648 648
         // Version information pattern -----------------------------------------
649 649
 
650
-		// Version information pattern (BCH coded).
650
+        // Version information pattern (BCH coded).
651 651
         // See Table 1 in Appendix D (pp.68) of JIS X0510:2004.
652 652
         
653
-		// size: [QRSPEC_VERSION_MAX - 6]
653
+        // size: [QRSPEC_VERSION_MAX - 6]
654 654
 		
655 655
         public static $versionPattern = [
656 656
             0x07c94, 0x085bc, 0x09a99, 0x0a4d3, 0x0bbf6, 0x0c762, 0x0d847, 0x0e60d,
@@ -1438,7 +1438,7 @@  discard block
 block discarded – undo
1438 1438
             -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
1439 1439
             -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
1440 1440
             36, -1, -1, -1, 37, 38, -1, -1, -1, -1, 39, 40, -1, 41, 42, 43,
1441
-             0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 44, -1, -1, -1, -1, -1,
1441
+                0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 44, -1, -1, -1, -1, -1,
1442 1442
             -1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
1443 1443
             25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, -1, -1, -1, -1, -1,
1444 1444
             -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
@@ -2500,17 +2500,17 @@  discard block
 block discarded – undo
2500 2500
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2501 2501
  */
2502 2502
  
2503
-	define('N1', 3);
2504
-	define('N2', 3);
2505
-	define('N3', 40);
2506
-	define('N4', 10);
2503
+    define('N1', 3);
2504
+    define('N2', 3);
2505
+    define('N3', 40);
2506
+    define('N4', 10);
2507 2507
 
2508
-	class QRmask {
2508
+    class QRmask {
2509 2509
 	
2510
-		public $runLength = [];
2510
+        public $runLength = [];
2511 2511
 		
2512
-		//----------------------------------------------------------------------
2513
-		public function __construct() 
2512
+        //----------------------------------------------------------------------
2513
+        public function __construct() 
2514 2514
         {
2515 2515
             $this->runLength = array_fill(0, QRSPEC_WIDTH_MAX + 1, 0);
2516 2516
         }
Please login to merge, or discard this patch.
core/IdP.php 1 patch
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -118,10 +118,10 @@
 block discarded – undo
118 118
             }
119 119
         }
120 120
         $this->priv_attributes[] = ["name" => "internal:country", 
121
-                                         "value" => $this->federation, 
122
-                                         "level" => "IdP", 
123
-                                         "row" => 0, 
124
-                                         "flag" => NULL];
121
+                                            "value" => $this->federation, 
122
+                                            "level" => "IdP", 
123
+                                            "row" => 0, 
124
+                                            "flag" => NULL];
125 125
 
126 126
         $this->name = getLocalisedValue($this->getAttributes('general:instname', 0, 0), CAT::get_lang());
127 127
         debug(3, "--- END Constructing new IdP object ... ---\n");
Please login to merge, or discard this patch.
core/RADIUSTests.php 1 patch
Indentation   -1 removed lines patch added patch discarded remove patch
@@ -328,7 +328,6 @@
 block discarded – undo
328 328
      * - RETVAL_NOT_CONFIGURED; needs Config::$RADIUSTESTS['TLS-discoverytag']
329 329
      * - RETVAL_INVALID (at least one format error)
330 330
      * - RETVAL_OK (all fine)
331
-
332 331
      * @return int one of two RETVALs above
333 332
      */
334 333
     public function NAPTR_compliance() {
Please login to merge, or discard this patch.
core/Options.php 1 patch
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -29,7 +29,7 @@
 block discarded – undo
29 29
  */
30 30
 class Options {
31 31
     
32
-   /**
32
+    /**
33 33
      * database which this class queries by default
34 34
      * 
35 35
      * @var string
Please login to merge, or discard this patch.
core/Profile.php 1 patch
Indentation   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -680,27 +680,27 @@
 block discarded – undo
680 680
             $redirect_url = getLocalisedValue($this->getAttributes("device-specific:redirect", 0, $d), $locale);
681 681
             $dev_status = AVAILABLE;
682 682
             if(isset($D['options']) && isset($D['options']['message']) && $D['options']['message']) 
683
-               $message = $D['options']['message'];
683
+                $message = $D['options']['message'];
684 684
             else
685
-               $message = 0;
685
+                $message = 0;
686 686
 
687 687
             if ($redirect_url === 0) {
688 688
                 if(isset($D['options']) && isset($D['options']['redirect']) && $D['options']['redirect']) {
689
-                   $dev_status = HIDDEN;
689
+                    $dev_status = HIDDEN;
690 690
                 }  else {
691
-                   $eap = $dev->getPreferredEapType($preferred_eap);
692
-                   if ($eap) {
693
-                       if (isset($EAP_options["eap-specific:customtext"][serialize($eap)]))
694
-                           $eap_customtext = $EAP_options["eap-specific:customtext"][serialize($eap)];
695
-                       else {
696
-                           $eap_customtext = getLocalisedValue($this->getAttributes("eap-specific:customtext", $eap, 0), $locale);
697
-                           $EAP_options["eap-specific:customtext"][serialize($eap)] = $eap_customtext;
698
-                       }
699
-                       $device_customtext = getLocalisedValue($this->getAttributes("device-specific:customtext", 0, $d), $locale);
700
-                   } else {
691
+                    $eap = $dev->getPreferredEapType($preferred_eap);
692
+                    if ($eap) {
693
+                        if (isset($EAP_options["eap-specific:customtext"][serialize($eap)]))
694
+                            $eap_customtext = $EAP_options["eap-specific:customtext"][serialize($eap)];
695
+                        else {
696
+                            $eap_customtext = getLocalisedValue($this->getAttributes("eap-specific:customtext", $eap, 0), $locale);
697
+                            $EAP_options["eap-specific:customtext"][serialize($eap)] = $eap_customtext;
698
+                        }
699
+                        $device_customtext = getLocalisedValue($this->getAttributes("device-specific:customtext", 0, $d), $locale);
700
+                    } else {
701 701
                     $dev_status = UNAVAILABLE;
702
-                   }
703
-               }
702
+                    }
703
+                }
704 704
             }
705 705
             $returnarray[] = ['id' => $d, 'display' => $D['display'], 'status' => $dev_status, 'redirect' => $redirect_url, 'eap_customtext' => $eap_customtext, 'device_customtext' => $device_customtext, 'message' => $message, 'options'=>$D['options']];
706 706
         }
Please login to merge, or discard this patch.
core/X509.php 1 patch
Indentation   +61 added lines, -61 removed lines patch added patch discarded remove patch
@@ -33,42 +33,42 @@  discard block
 block discarded – undo
33 33
  *  @author http://php.net/manual/en/ref.openssl.php (comment from 29-Mar-2007)
34 34
  */
35 35
 public function pem2der($pem_data) {
36
-   $begin = "CERTIFICATE-----";
37
-   $end   = "-----END";
38
-   $pem_data = substr($pem_data, strpos($pem_data, $begin)+strlen($begin));
39
-   $pem_data = substr($pem_data, 0, strpos($pem_data, $end));
40
-   $der = base64_decode($pem_data);
41
-   return $der;
36
+    $begin = "CERTIFICATE-----";
37
+    $end   = "-----END";
38
+    $pem_data = substr($pem_data, strpos($pem_data, $begin)+strlen($begin));
39
+    $pem_data = substr($pem_data, 0, strpos($pem_data, $end));
40
+    $der = base64_decode($pem_data);
41
+    return $der;
42 42
 }
43 43
 
44 44
 public function der2pem($der_data) {
45
-   $pem = chunk_split(base64_encode($der_data), 64, "\n");
46
-   $pem = "-----BEGIN CERTIFICATE-----\n".$pem."-----END CERTIFICATE-----\n";
47
-   return $pem;
45
+    $pem = chunk_split(base64_encode($der_data), 64, "\n");
46
+    $pem = "-----BEGIN CERTIFICATE-----\n".$pem."-----END CERTIFICATE-----\n";
47
+    return $pem;
48 48
 }
49 49
 /**
50
-  * prepare PEM and DER formats, MD5 and SHA1 fingerprints and subject of the certificate
51
-  *
52
-  * returns an array with the following fields:
53
-  * <pre> uuid
54
-  * pem	certificate in PEM format
55
-  * der	certificate in DER format
56
-  * md5	MD5 fingerprint
57
-  * sha1	SHA1 fingerprint
58
-  * name	certificate subject
59
-  * root value 1 if root certificate 0 otherwise
60
-  * ca   value 1 if CA certificate 0 otherwise
61
-  *
62
-  * </pre>
63
-  * @param blob $cadata certificate in ether PEM or DER format
64
-  * @return array
65
-  */
50
+ * prepare PEM and DER formats, MD5 and SHA1 fingerprints and subject of the certificate
51
+ *
52
+ * returns an array with the following fields:
53
+ * <pre> uuid
54
+ * pem	certificate in PEM format
55
+ * der	certificate in DER format
56
+ * md5	MD5 fingerprint
57
+ * sha1	SHA1 fingerprint
58
+ * name	certificate subject
59
+ * root value 1 if root certificate 0 otherwise
60
+ * ca   value 1 if CA certificate 0 otherwise
61
+ *
62
+ * </pre>
63
+ * @param blob $cadata certificate in ether PEM or DER format
64
+ * @return array
65
+ */
66 66
 public function processCertificate ($cadata) {
67 67
     $begin_pem = strpos($cadata,"-----BEGIN CERTIFICATE-----");
68
-   if($begin_pem !== FALSE) {
68
+    if($begin_pem !== FALSE) {
69 69
         $end_c = strpos($cadata,"-----END CERTIFICATE-----") + 25;
70 70
         if($end_c !== FALSE) {
71
-           $cadata = substr($cadata,$begin_pem,$end_c - $begin_pem);
71
+            $cadata = substr($cadata,$begin_pem,$end_c - $begin_pem);
72 72
         }
73 73
         $ca_der = X509::pem2der($cadata);
74 74
         $ca_pem = X509::der2pem($ca_der);
@@ -91,25 +91,25 @@  discard block
 block discarded – undo
91 91
     $out =  ["uuid" => uuid(), "pem" => $ca_pem, "der" => $ca_der, "md5"=>$md5, "sha1"=>$sha1, "name"=>$mydetails['name']];
92 92
     $diff_a = array_diff($mydetails['issuer'], $mydetails['subject']);
93 93
     if(count($diff_a) == 0 ) {
94
-     $out['root'] = 1;
95
-     $mydetails['type'] = 'root';
94
+        $out['root'] = 1;
95
+        $mydetails['type'] = 'root';
96 96
     } else {
97
-     $out['root'] = 0;
97
+        $out['root'] = 0;
98 98
     }
99 99
     // if no basicContraints are set at all, this is a problem in itself
100 100
     // is this a CA? or not? Treat as server, but add a warning...
101 101
     if (isset($mydetails['extensions']['basicConstraints'])) {
102
-       $out['ca'] = preg_match('/^CA:TRUE/',$mydetails['extensions']['basicConstraints']);
103
-       $out['basicconstraints_set'] = 1;
102
+        $out['ca'] = preg_match('/^CA:TRUE/',$mydetails['extensions']['basicConstraints']);
103
+        $out['basicconstraints_set'] = 1;
104 104
     } else {
105
-       $out['ca'] = 0; // we need to resolve this ambiguity
106
-       $out['basicconstraints_set'] = 0;
105
+        $out['ca'] = 0; // we need to resolve this ambiguity
106
+        $out['basicconstraints_set'] = 0;
107 107
     }
108 108
     
109 109
     if( $out['ca'] > 0 && $out['root'] == 0 )
110
-     $mydetails['type'] = 'interm_ca';
110
+        $mydetails['type'] = 'interm_ca';
111 111
     if( $out['ca'] == 0 && $out['root'] == 0 )
112
-     $mydetails['type'] = 'server';
112
+        $mydetails['type'] = 'server';
113 113
     $mydetails['sha1'] = $sha1;
114 114
     $out['full_details'] = $mydetails;
115 115
     
@@ -119,51 +119,51 @@  discard block
 block discarded – undo
119 119
     
120 120
     openssl_x509_export($myca, $output, FALSE);
121 121
     if(preg_match('/^\s+Signature Algorithm:\s*(.*)\s*$/m', $output, $match)) 
122
-      $out['full_details']['signature_algorithm'] = $match[1];
122
+        $out['full_details']['signature_algorithm'] = $match[1];
123 123
     else
124
-      $out['full_details']['signature_algorithm'] = $output;
124
+        $out['full_details']['signature_algorithm'] = $output;
125 125
  
126 126
     if((preg_match('/^\s+Public-Key:\s*\((.*) bit\)\s*$/m', $output, $match)) && is_numeric($match[1])) 
127
-      $out['full_details']['public_key_length'] = $match[1];
127
+        $out['full_details']['public_key_length'] = $match[1];
128 128
     else
129
-      $out['full_details']['public_key_length'] = $output;
129
+        $out['full_details']['public_key_length'] = $output;
130 130
     
131 131
     return $out;
132 132
 }
133 133
 
134 134
 /**
135
-  * split a certificate file into components 
136
-  *
137
-  * returns an array containing the PEM format of the certificate (s)
138
-  * if the file contains multiple certificates it gets split into components
139
-  *
140
-  * @param blob $cadata certificate in ether PEM or DER format
141
-  * @return array
142
-  */
135
+ * split a certificate file into components 
136
+ *
137
+ * returns an array containing the PEM format of the certificate (s)
138
+ * if the file contains multiple certificates it gets split into components
139
+ *
140
+ * @param blob $cadata certificate in ether PEM or DER format
141
+ * @return array
142
+ */
143 143
 
144 144
 public function splitCertificate($cadata) {
145
-  $returnarray = [];
146
-  // maybe we got no real cert data at all? The code is hardened, but will
147
-  // produce ugly WARNING level output in the logfiles, so let's avoid at least
148
-  // the trivial case: if the file is empty, there's no cert in it
149
-  if ($cadata == "")
150
-      return $returnarray;
151
-  $start_c = strpos($cadata,"-----BEGIN CERTIFICATE-----" );
152
-  if( $start_c !== FALSE) {
145
+    $returnarray = [];
146
+    // maybe we got no real cert data at all? The code is hardened, but will
147
+    // produce ugly WARNING level output in the logfiles, so let's avoid at least
148
+    // the trivial case: if the file is empty, there's no cert in it
149
+    if ($cadata == "")
150
+        return $returnarray;
151
+    $start_c = strpos($cadata,"-----BEGIN CERTIFICATE-----" );
152
+    if( $start_c !== FALSE) {
153 153
         $cadata = substr($cadata,$start_c);
154 154
         $end_c = strpos($cadata,"-----END CERTIFICATE-----") + 25;
155 155
         $next_c = strpos($cadata,"-----BEGIN CERTIFICATE-----",30);
156 156
         while ( $next_c !== FALSE) {
157
-          $returnarray[] = substr($cadata,0,$end_c);
158
-          $cadata = substr($cadata,$next_c);
159
-          $end_c = strpos($cadata,"-----END CERTIFICATE-----") + 25;
160
-          $next_c = strpos($cadata,"-----BEGIN CERTIFICATE-----",30);
157
+            $returnarray[] = substr($cadata,0,$end_c);
158
+            $cadata = substr($cadata,$next_c);
159
+            $end_c = strpos($cadata,"-----END CERTIFICATE-----") + 25;
160
+            $next_c = strpos($cadata,"-----BEGIN CERTIFICATE-----",30);
161 161
         }
162 162
         $returnarray[] = substr($cadata,0,$end_c);
163 163
     } else {
164 164
         // TODO: before we blindly hand it over to der2pem - is this valid DER
165 165
         // data at all?
166
-      $returnarray[] = X509::der2pem($cadata);
166
+        $returnarray[] = X509::der2pem($cadata);
167 167
     }
168 168
     // print_r($returnarray);
169 169
     
Please login to merge, or discard this patch.
core/EAP.php 1 patch
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -77,7 +77,7 @@
 block discarded – undo
77 77
      */
78 78
     public static $TLS = ["OUTER" => TLS, "INNER" => NONE];
79 79
 
80
-   /**
80
+    /**
81 81
      * EAP-TLS: Outer EAP Type = 13, no inner EAP
82 82
      *
83 83
      * @var array of EAP type IDs that describe EAP-TLS
Please login to merge, or discard this patch.