Completed
Push — master ( 03ec64...ee79b5 )
by
unknown
07:25
created
core/DBConnection.php 2 patches
Doc Comments   +3 added lines patch added patch discarded remove patch
@@ -134,6 +134,8 @@  discard block
 block discarded – undo
134 134
     /**
135 135
      * Checks if a raw data pointer is public data (return value FALSE) or if 
136 136
      * yes who the authorised admins to view it are (return array of user IDs)
137
+     * @param string $table
138
+     * @param string $row
137 139
      */
138 140
     public static function isDataRestricted($table, $row) {
139 141
         if ($table != "institution_option" && $table != "profile_option" && $table != "federation_option")
@@ -175,6 +177,7 @@  discard block
 block discarded – undo
175 177
 
176 178
     /**
177 179
      * Retrieves the last auto-id of an INSERT. Needs to be called immediately after the corresponding exec() call
180
+     * @param string $db
178 181
      * @return int the last autoincrement-ID
179 182
      */
180 183
     public static function lastID($db) {
Please login to merge, or discard this patch.
Braces   +25 added lines, -14 removed lines patch added patch discarded remove patch
@@ -106,8 +106,9 @@  discard block
 block discarded – undo
106 106
         }
107 107
 
108 108
         // log exact query to audit log, if it's not a SELECT
109
-        if (preg_match("/^SELECT/i", $querystring) == 0)
110
-            CAT::writeSQLAudit("[DB: " . strtoupper($db) . "] " . $querystring);
109
+        if (preg_match("/^SELECT/i", $querystring) == 0) {
110
+                    CAT::writeSQLAudit("[DB: " . strtoupper($db) . "] " . $querystring);
111
+        }
111 112
         return $result;
112 113
     }
113 114
 
@@ -120,14 +121,17 @@  discard block
 block discarded – undo
120 121
      */
121 122
     public static function fetchRawDataByIndex($table, $row) {
122 123
         // only for select tables!
123
-        if ($table != "institution_option" && $table != "profile_option" && $table != "federation_option")
124
-            return FALSE;
124
+        if ($table != "institution_option" && $table != "profile_option" && $table != "federation_option") {
125
+                    return FALSE;
126
+        }
125 127
         $blob_query = DBConnection::exec("INST", "SELECT option_value from $table WHERE row = $row");
126
-        while ($a = mysqli_fetch_object($blob_query))
127
-            $blob = $a->option_value;
128
+        while ($a = mysqli_fetch_object($blob_query)) {
129
+                    $blob = $a->option_value;
130
+        }
128 131
 
129
-        if (!isset($blob))
130
-            return FALSE;
132
+        if (!isset($blob)) {
133
+                    return FALSE;
134
+        }
131 135
         return $blob;
132 136
     }
133 137
 
@@ -136,13 +140,17 @@  discard block
 block discarded – undo
136 140
      * yes who the authorised admins to view it are (return array of user IDs)
137 141
      */
138 142
     public static function isDataRestricted($table, $row) {
139
-        if ($table != "institution_option" && $table != "profile_option" && $table != "federation_option")
140
-            return []; // better safe than sorry: that's an error, so assume nobody is authorised to act on that data
143
+        if ($table != "institution_option" && $table != "profile_option" && $table != "federation_option") {
144
+                    return [];
145
+        }
146
+        // better safe than sorry: that's an error, so assume nobody is authorised to act on that data
141 147
         switch ($table) {
142 148
             case "profile_option":
143 149
                 $blob_query = DBConnection::exec("INST", "SELECT profile_id from $table WHERE row = $row");
144
-                while ($a = mysqli_fetch_object($blob_query)) // only one row
150
+                while ($a = mysqli_fetch_object($blob_query)) {
151
+                    // only one row
145 152
                     $blobprofile = $a->profile_id;
153
+                }
146 154
                 // is the profile in question public?
147 155
                 $profile = new Profile($blobprofile);
148 156
                 if ($profile->getShowtime() == TRUE) { // public data
@@ -154,8 +162,10 @@  discard block
 block discarded – undo
154 162
                 break;
155 163
             case "institution_option":
156 164
                 $blob_query = DBConnection::exec("INST", "SELECT institution_id from $table WHERE row = $row");
157
-                while ($a = mysqli_fetch_object($blob_query)) // only one row
165
+                while ($a = mysqli_fetch_object($blob_query)) {
166
+                    // only one row
158 167
                     $blobinst = $a->institution_id;
168
+                }
159 169
                 $inst = new IdP($blobinst);
160 170
                 // if at least one of the profiles belonging to the inst is public, the data is public
161 171
                 if ($inst->isOneProfileShowtime()) { // public data
@@ -209,8 +219,9 @@  discard block
 block discarded – undo
209 219
             exit(1);
210 220
         }
211 221
 
212
-        if ($db == "EXTERNAL" && Config::$CONSORTIUM['name'] == "eduroam" && isset(Config::$CONSORTIUM['deployment-voodoo']) && Config::$CONSORTIUM['deployment-voodoo'] == "Operations Team")
213
-            mysqli_query($this->connection, "SET NAMES 'latin1'");
222
+        if ($db == "EXTERNAL" && Config::$CONSORTIUM['name'] == "eduroam" && isset(Config::$CONSORTIUM['deployment-voodoo']) && Config::$CONSORTIUM['deployment-voodoo'] == "Operations Team") {
223
+                    mysqli_query($this->connection, "SET NAMES 'latin1'");
224
+        }
214 225
     }
215 226
 
216 227
 }
217 228
\ No newline at end of file
Please login to merge, or discard this patch.
core/IdP.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -224,7 +224,7 @@
 block discarded – undo
224 224
      * Adds a new profile to this IdP.
225 225
      * Only creates the DB entry for the Profile. If you want to add attributes later, see Profile::addAttribute().
226 226
      *
227
-     * @return object new Profile object if successful, or FALSE if an error occured
227
+     * @return Profile|null new Profile object if successful, or FALSE if an error occured
228 228
      */
229 229
     public function newProfile() {
230 230
         DBConnection::exec($this->databaseType, "INSERT INTO profile (inst_id) VALUES($this->identifier)");
Please login to merge, or discard this patch.
Indentation   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -48,7 +48,7 @@  discard block
 block discarded – undo
48 48
      */
49 49
     private $external_db_syncstate;
50 50
     
51
-   /**
51
+    /**
52 52
      * The shortname of this IdP's federation
53 53
      * @var string 
54 54
      */
@@ -110,10 +110,10 @@  discard block
 block discarded – undo
110 110
             }
111 111
         }
112 112
         $this->attributes[] = ["name" => "internal:country", 
113
-                                         "value" => $this->federation, 
114
-                                         "level" => "IdP", 
115
-                                         "row" => 0, 
116
-                                         "flag" => NULL];
113
+                                            "value" => $this->federation, 
114
+                                            "level" => "IdP", 
115
+                                            "row" => 0, 
116
+                                            "flag" => NULL];
117 117
 
118 118
         $this->name = getLocalisedValue($this->getAttributes('general:instname'), CAT::get_lang());
119 119
         debug(3, "--- END Constructing new IdP object ... ---\n");
Please login to merge, or discard this patch.
Braces   +65 added lines, -46 removed lines patch added patch discarded remove patch
@@ -128,8 +128,9 @@  discard block
 block discarded – undo
128 128
      */
129 129
     public function listProfiles($active_only = 0) {
130 130
         $query = "SELECT profile_id FROM profile WHERE inst_id = $this->identifier";
131
-        if ($active_only)
132
-            $query .= " AND showtime = 1";
131
+        if ($active_only) {
132
+                    $query .= " AND showtime = 1";
133
+        }
133 134
         $allProfiles = DBConnection::exec($this->databaseType, $query);
134 135
         $returnarray = [];
135 136
         while ($a = mysqli_fetch_object($allProfiles)) {
@@ -144,24 +145,27 @@  discard block
 block discarded – undo
144 145
         // migration phase: are there NULLs in the profile list sufficient_config column?
145 146
         // if so, run prepShowtime on all profiles
146 147
         $needTreatment = DBConnection::exec($this->databaseType, "SELECT profile_id FROM profile WHERE inst_id = $this->identifier AND sufficient_config IS NULL");
147
-        if (mysqli_num_rows($needTreatment) > 0)
148
-            foreach ($this->listProfiles() as $prof)
148
+        if (mysqli_num_rows($needTreatment) > 0) {
149
+                    foreach ($this->listProfiles() as $prof)
149 150
                 $prof->prepShowtime();
151
+        }
150 152
        
151 153
         // now, just look in the DB
152 154
         $allProfiles = DBConnection::exec($this->databaseType, "SELECT profile_id FROM profile WHERE inst_id = $this->identifier AND sufficient_config = 1");
153
-        if (mysqli_num_rows($allProfiles) > 0)
154
-            return TRUE;
155
-        else
156
-            return FALSE;
155
+        if (mysqli_num_rows($allProfiles) > 0) {
156
+                    return TRUE;
157
+        } else {
158
+                    return FALSE;
159
+        }
157 160
     }
158 161
 
159 162
     public function isOneProfileShowtime() {
160 163
         $allProfiles = DBConnection::exec($this->databaseType, "SELECT profile_id FROM profile WHERE inst_id = $this->identifier AND showtime = 1");
161
-        if (mysqli_num_rows($allProfiles) > 0)
162
-            return TRUE;
163
-        else
164
-            return FALSE;
164
+        if (mysqli_num_rows($allProfiles) > 0) {
165
+                    return TRUE;
166
+        } else {
167
+                    return FALSE;
168
+        }
165 169
         
166 170
     }
167 171
     
@@ -169,16 +173,21 @@  discard block
 block discarded – undo
169 173
         $allProfiles = DBConnection::exec($this->databaseType, "SELECT status_dns, status_cert, status_reachability, status_TLS, last_status_check FROM profile WHERE inst_id = $this->identifier AND sufficient_config = 1");
170 174
         $returnarray = ['dns' => RETVAL_SKIPPED, 'cert' => L_OK, 'reachability' => RETVAL_SKIPPED, 'TLS' => RETVAL_SKIPPED, 'checktime' => NULL];
171 175
         while ($a = mysqli_fetch_object($allProfiles)) {
172
-            if ($a->status_dns < $returnarray['dns'])
173
-                $returnarray['dns'] = $a->status_dns;
174
-            if ($a->status_reachability < $returnarray['reachability'])
175
-                $returnarray['reachability'] = $a->status_reachability;
176
-            if ($a->status_TLS < $returnarray['TLS'])
177
-                $returnarray['TLS'] = $a->status_TLS;
178
-            if ($a->status_cert < $returnarray['cert'])
179
-                $returnarray['cert'] = $a->status_cert;
180
-            if ($a->last_status_check > $returnarray['checktime'])
181
-                $returnarray['checktime'] = $a->last_status_check;
176
+            if ($a->status_dns < $returnarray['dns']) {
177
+                            $returnarray['dns'] = $a->status_dns;
178
+            }
179
+            if ($a->status_reachability < $returnarray['reachability']) {
180
+                            $returnarray['reachability'] = $a->status_reachability;
181
+            }
182
+            if ($a->status_TLS < $returnarray['TLS']) {
183
+                            $returnarray['TLS'] = $a->status_TLS;
184
+            }
185
+            if ($a->status_cert < $returnarray['cert']) {
186
+                            $returnarray['cert'] = $a->status_cert;
187
+            }
188
+            if ($a->last_status_check > $returnarray['checktime']) {
189
+                            $returnarray['checktime'] = $a->last_status_check;
190
+            }
182 191
         }
183 192
         return $returnarray;
184 193
     }
@@ -191,8 +200,9 @@  discard block
 block discarded – undo
191 200
     public function owner() {
192 201
         $returnarray = [];
193 202
         $admins = DBConnection::exec($this->databaseType, "SELECT user_id, orig_mail, blesslevel FROM ownership WHERE institution_id = $this->identifier ORDER BY user_id");
194
-        while ($a = mysqli_fetch_object($admins))
195
-            $returnarray[] = ['ID' => $a->user_id, 'MAIL' => $a->orig_mail, 'LEVEL' => $a->blesslevel];
203
+        while ($a = mysqli_fetch_object($admins)) {
204
+                    $returnarray[] = ['ID' => $a->user_id, 'MAIL' => $a->orig_mail, 'LEVEL' => $a->blesslevel];
205
+        }
196 206
         return $returnarray;
197 207
     }
198 208
 
@@ -230,10 +240,11 @@  discard block
 block discarded – undo
230 240
         DBConnection::exec($this->databaseType, "INSERT INTO profile (inst_id) VALUES($this->identifier)");
231 241
         $identifier = DBConnection::lastID($this->databaseType);
232 242
 
233
-        if ($identifier > 0)
234
-            return new Profile($identifier, $this);
235
-        else
236
-            return NULL;
243
+        if ($identifier > 0) {
244
+                    return new Profile($identifier, $this);
245
+        } else {
246
+                    return NULL;
247
+        }
237 248
     }
238 249
 
239 250
     /**
@@ -241,13 +252,15 @@  discard block
 block discarded – undo
241 252
      */
242 253
     public function destroy() {
243 254
         /* delete all profiles */
244
-        foreach ($this->listProfiles() as $profile)
245
-            $profile->destroy();
255
+        foreach ($this->listProfiles() as $profile) {
256
+                    $profile->destroy();
257
+        }
246 258
         /* double-check that all profiles are gone */
247 259
         $profiles = $this->listProfiles();
248 260
 
249
-        if (count($profiles) > 0)
250
-            die("This IdP shouldn't have any profiles any more!");
261
+        if (count($profiles) > 0) {
262
+                    die("This IdP shouldn't have any profiles any more!");
263
+        }
251 264
 
252 265
         DBConnection::exec($this->databaseType, "DELETE FROM ownership WHERE institution_id = $this->identifier");
253 266
         DBConnection::exec($this->databaseType, "DELETE FROM institution_option WHERE institution_id = $this->identifier");
@@ -286,13 +299,15 @@  discard block
 block discarded – undo
286 299
             $candidate_list = DBConnection::exec("EXTERNAL", "SELECT id_institution AS id, name AS collapsed_name FROM view_active_idp_institution WHERE country = '" . strtolower($this->federation) . "'");
287 300
 
288 301
             $already_used = DBConnection::exec($this->databaseType, "SELECT DISTINCT external_db_id FROM institution WHERE external_db_id IS NOT NULL AND external_db_syncstate = " . EXTERNAL_DB_SYNCSTATE_SYNCED);
289
-            while ($a = mysqli_fetch_object($already_used))
290
-                $usedarray[] = $a->external_db_id;
302
+            while ($a = mysqli_fetch_object($already_used)) {
303
+                            $usedarray[] = $a->external_db_id;
304
+            }
291 305
 
292 306
             // and split them into ID, LANG, NAME pairs
293 307
             while ($a = mysqli_fetch_object($candidate_list)) {
294
-                if (in_array($a->id, $usedarray))
295
-                    continue;
308
+                if (in_array($a->id, $usedarray)) {
309
+                                    continue;
310
+                }
296 311
                 $names = explode('#', $a->collapsed_name);
297 312
                 foreach ($names as $name) {
298 313
                     $perlang = explode(': ', $name, 2);
@@ -302,12 +317,14 @@  discard block
 block discarded – undo
302 317
             // now see if any of the languages in CAT match any of those in the external DB
303 318
             $mynames = $this->getAttributes("general:instname");
304 319
             $matching_candidates = [];
305
-            foreach ($mynames as $onename)
306
-                foreach ($list as $listentry) {
320
+            foreach ($mynames as $onename) {
321
+                            foreach ($list as $listentry) {
307 322
                     $unserialised = unserialize($onename['value']);
308
-                    if (($unserialised['lang'] == $listentry['lang'] || $unserialised['lang'] == "C") && $unserialised['content'] == $listentry['name'])
309
-                        if (array_search($listentry['ID'], $matching_candidates) === FALSE)
323
+            }
324
+                    if (($unserialised['lang'] == $listentry['lang'] || $unserialised['lang'] == "C") && $unserialised['content'] == $listentry['name']) {
325
+                                            if (array_search($listentry['ID'], $matching_candidates) === FALSE)
310 326
                             $matching_candidates[] = $listentry['ID'];
327
+                    }
311 328
                 }
312 329
 
313 330
             return $matching_candidates;
@@ -347,10 +364,11 @@  discard block
 block discarded – undo
347 364
      */
348 365
     public function getExternalDBEntityDetails() {
349 366
         $external_id = $this->getExternalDBId();
350
-        if ($external_id !== FALSE)
351
-            return Federation::getExternalDBEntityDetails($external_id);
352
-        else
353
-            return [];
367
+        if ($external_id !== FALSE) {
368
+                    return Federation::getExternalDBEntityDetails($external_id);
369
+        } else {
370
+                    return [];
371
+        }
354 372
     }
355 373
 
356 374
     public function setExternalDBId($identifier) {
@@ -358,8 +376,9 @@  discard block
 block discarded – undo
358 376
         if (Config::$CONSORTIUM['name'] == "eduroam" && isset(Config::$CONSORTIUM['deployment-voodoo']) && Config::$CONSORTIUM['deployment-voodoo'] == "Operations Team") { // SW: APPROVED
359 377
             $already_used = DBConnection::exec($this->databaseType, "SELECT DISTINCT external_db_id FROM institution WHERE external_db_id = '$identifier' AND external_db_syncstate = " . EXTERNAL_DB_SYNCSTATE_SYNCED);
360 378
 
361
-            if (mysqli_num_rows($already_used) == 0)
362
-                DBConnection::exec($this->databaseType, "UPDATE institution SET external_db_id = '$identifier', external_db_syncstate = " . EXTERNAL_DB_SYNCSTATE_SYNCED . " WHERE inst_id = $this->identifier");
379
+            if (mysqli_num_rows($already_used) == 0) {
380
+                            DBConnection::exec($this->databaseType, "UPDATE institution SET external_db_id = '$identifier', external_db_syncstate = " . EXTERNAL_DB_SYNCSTATE_SYNCED . " WHERE inst_id = $this->identifier");
381
+            }
363 382
         }
364 383
     }
365 384
 }
366 385
\ No newline at end of file
Please login to merge, or discard this patch.
core/Profile.php 3 patches
Doc Comments   +14 added lines, -12 removed lines patch added patch discarded remove patch
@@ -59,7 +59,7 @@  discard block
 block discarded – undo
59 59
      * supported EAP types from the DB and stores them in the priv_ arrays.
60 60
      * 
61 61
      * @param int $p_id identifier of the profile in the DB
62
-     * @param IdP $idp_object optionally, the institution to which this Profile belongs. Saves the construction of the IdP instance. If omitted, an extra query and instantiation is executed to find out.
62
+     * @param integer $idp_object optionally, the institution to which this Profile belongs. Saves the construction of the IdP instance. If omitted, an extra query and instantiation is executed to find out.
63 63
      */
64 64
     public function __construct($p_id, $idp_object = 0) {
65 65
         debug(3, "--- BEGIN Constructing new Profile object ... ---\n");
@@ -358,6 +358,8 @@  discard block
 block discarded – undo
358 358
      * 
359 359
      * @param string device the device identifier string
360 360
      * @param string path the path where the new installer can be found
361
+     * @param string $device
362
+     * @param string $path
361 363
      */
362 364
     public function updateCache($device, $path,$mime) {
363 365
         $escapedDevice = DBConnection::escape_value($this->databaseType, $device);
@@ -370,9 +372,9 @@  discard block
 block discarded – undo
370 372
     /**
371 373
      * Log a new download for our stats
372 374
      * 
373
-     * @param device the device id string
374
-     * @param area either admin or user
375
-     * @return TRUE if incrementing worked, FALSE if not
375
+     * @param device string device id string
376
+     * @param area string admin or user
377
+     * @return boolean if incrementing worked, FALSE if not
376 378
      */
377 379
     public function incrementDownloadStats($device, $area) {
378 380
         $device = DBConnection::escape_value($this->databaseType, $device);
@@ -385,7 +387,7 @@  discard block
 block discarded – undo
385 387
 
386 388
     /**
387 389
      * Retrieve current download stats from database, either for one specific device or for all devices
388
-     * @param string $device the device id string
390
+     * @param integer $device the device id string
389 391
      * @return mixed user downloads of this profile; if device is given, returns the counter as int, otherwise an array with devicename => counter
390 392
      */
391 393
     public function getUserDownloadStats($device = 0) {
@@ -412,10 +414,10 @@  discard block
 block discarded – undo
412 414
      * adds an attribute to this profile; not the usual function from EntityWithDBProperties
413 415
      * because this class also has per-EAP-type and per-device sub-settings
414 416
      *
415
-     * @param string $attr_name name of the attribute to set
416
-     * @param string $attr_value value of the attribute to set
417
-     * @param int $eap_type identifier of the EAP type in the database. 0 if the attribute is valid for all EAP types.
418
-     * @param string $device identifier of the device in the databse. Omit the argument if attribute is valid for all devices.
417
+     * @param string $attrName name of the attribute to set
418
+     * @param string $attrValue value of the attribute to set
419
+     * @param integer $eapType identifier of the EAP type in the database. 0 if the attribute is valid for all EAP types.
420
+     * @param integer $device identifier of the device in the databse. Omit the argument if attribute is valid for all devices.
419 421
      */
420 422
     public function addAttribute($attrName, $attrValue, $eapType, $device = 0) {
421 423
         $escapedAttrName = DBConnection::escape_value(Profile::$DB_TYPE, $attrName);
@@ -525,7 +527,7 @@  discard block
 block discarded – undo
525 527
     /** Returns an array of the profile's attributes.
526 528
      * 
527 529
      * @param string option_name the name of a specific option. If set, only returns option values for this option name
528
-     * @param eapmethod the EAP type, in array ("OUTER/INNER") notation. If set, returns only attributes which are specific to that EAP type
530
+     * @param eapmethod integer EAP type, in array ("OUTER/INNER") notation. If set, returns only attributes which are specific to that EAP type
529 531
      * @param string device the device ID string. If set, returns only attributes which are specific to that device
530 532
      * @return array attributes of the profile
531 533
      */
@@ -609,7 +611,7 @@  discard block
 block discarded – undo
609 611
     /**
610 612
      * list all devices marking their availabiblity and possible redirects
611 613
      *
612
-     * @param string $locale for text-based attributes, either returns values for the default value, or if specified here, in the locale specified
614
+     * @param integer $locale for text-based attributes, either returns values for the default value, or if specified here, in the locale specified
613 615
      * @return array of device ids display names and their status
614 616
      */
615 617
     public function listDevices($locale = 0) {
@@ -664,7 +666,7 @@  discard block
 block discarded – undo
664 666
      * as wel as the chosen language.
665 667
      * can be called with an optional $eap argument
666 668
      * 
667
-     * @param array $eap if specified, retrieves attributes specific to the given EAP type
669
+     * @param integer $eap if specified, retrieves attributes specific to the given EAP type
668 670
      * @return array list of attributes in collapsed style (index is the attrib name, value is an array of different values)
669 671
      */
670 672
     public function getCollapsedAttributes($eap = 0) {
Please login to merge, or discard this patch.
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -112,7 +112,7 @@  discard block
 block discarded – undo
112 112
                 $temparray[] = [
113 113
                     "name" => $a->option_name,
114 114
                     "value" => $a->option_value,
115
-                    "level" => ($a->device_id == NULL && $a->method == 0 ? "Profile" : "Method" ),
115
+                    "level" => ($a->device_id == NULL && $a->method == 0 ? "Profile" : "Method"),
116 116
                     "row" => $a->row,
117 117
                     "device" => $a->device_id,
118 118
                     "flag" => $optinfo['flag'],
@@ -133,8 +133,8 @@  discard block
 block discarded – undo
133 133
 
134 134
                 $temparray[] = [
135 135
                     "name" => $a->option_name,
136
-                    "value" => ( $lang == "" ? $content : serialize(['lang' => $lang, 'content' => $content])),
137
-                    "level" => ($a->device_id == NULL && $a->method == 0 ? "Profile" : "Method" ),
136
+                    "value" => ($lang == "" ? $content : serialize(['lang' => $lang, 'content' => $content])),
137
+                    "level" => ($a->device_id == NULL && $a->method == 0 ? "Profile" : "Method"),
138 138
                     "row" => $a->row,
139 139
                     "flag" => $optinfo['flag'],
140 140
                     "device" => $a->device_id,
@@ -346,7 +346,7 @@  discard block
 block discarded – undo
346 346
             if ($lc = mysqli_fetch_object($exec_update)->last_change) {
347 347
                 if ($lc < $cache->tm) {
348 348
                     debug(4, "Installer cached:$cache->download_path\n");
349
-                    $returnValue = ['cache'=>$cache->download_path,'mime'=>$cache->mime];
349
+                    $returnValue = ['cache'=>$cache->download_path, 'mime'=>$cache->mime];
350 350
                 }
351 351
             }
352 352
         }
@@ -359,7 +359,7 @@  discard block
 block discarded – undo
359 359
      * @param string device the device identifier string
360 360
      * @param string path the path where the new installer can be found
361 361
      */
362
-    public function updateCache($device, $path,$mime) {
362
+    public function updateCache($device, $path, $mime) {
363 363
         $escapedDevice = DBConnection::escape_value($this->databaseType, $device);
364 364
         $escapedPath   = DBConnection::escape_value($this->databaseType, $path);
365 365
         DBConnection::exec($this->databaseType, "INSERT INTO downloads (profile_id,device_id,download_path,mime,lang,installer_time) 
@@ -422,7 +422,7 @@  discard block
 block discarded – undo
422 422
         $escapedAttrValue = DBConnection::escape_value(Profile::$DB_TYPE, $attrValue);
423 423
         
424 424
         DBConnection::exec($this->databaseType, "INSERT INTO $this->entityOptionTable ($this->entityIdColumn, option_name, option_value, eap_method_id" . ($device !== 0 ? ",device_id" : "") . ") 
425
-                          VALUES(". $this->identifier . ", '$escapedAttrName', '$escapedAttrValue', $eapType" . ($device !== 0 ? ",'". DBConnection::escape_value($this->databaseType, $device) . "'" : "" ) . ")");
425
+                          VALUES(". $this->identifier . ", '$escapedAttrName', '$escapedAttrValue', $eapType" . ($device !== 0 ? ",'" . DBConnection::escape_value($this->databaseType, $device) . "'" : "") . ")");
426 426
         $this->updateFreshness();
427 427
     }
428 428
 
@@ -475,20 +475,20 @@  discard block
 block discarded – undo
475 475
      * @param string $localpart the username
476 476
      *
477 477
      */
478
-    public function setRealmCheckUser($shallwe,$localpart = NULL) {
478
+    public function setRealmCheckUser($shallwe, $localpart = NULL) {
479 479
         DBConnection::exec($this->databaseType, 
480 480
                 "UPDATE profile SET checkuser_outer = " . ($shallwe == true ? "1" : "0") . 
481
-                ( $localpart !== NULL ? ", checkuser_value = '$localpart' " : "") .
481
+                ($localpart !== NULL ? ", checkuser_value = '$localpart' " : "") .
482 482
                 " WHERE profile_id = $this->identifier");
483 483
     }
484 484
 
485 485
     /** should username be verified or even prefilled?
486 486
      * 
487 487
      */
488
-    public function setInputVerificationPreference($verify,$hint) {
488
+    public function setInputVerificationPreference($verify, $hint) {
489 489
         DBConnection::exec($this->databaseType, 
490 490
                 "UPDATE profile SET verify_userinput_suffix = " . ($verify == true ? "1" : "0") . 
491
-                ", hint_userinput_suffix = ". ($hint == true ? "1" : "0") .
491
+                ", hint_userinput_suffix = " . ($hint == true ? "1" : "0") .
492 492
                 " WHERE profile_id = $this->identifier");
493 493
     }
494 494
     
@@ -630,15 +630,15 @@  discard block
 block discarded – undo
630 630
             $dev = $factory->device;
631 631
             $redirect_url = getLocalisedValue($this->getAttributes("device-specific:redirect", 0, $d), $locale);
632 632
             $dev_status = AVAILABLE;
633
-            if(isset($D['options']) && isset($D['options']['message']) && $D['options']['message']) 
633
+            if (isset($D['options']) && isset($D['options']['message']) && $D['options']['message']) 
634 634
                $message = $D['options']['message'];
635 635
             else
636 636
                $message = 0;
637 637
 
638 638
             if ($redirect_url === 0) {
639
-                if(isset($D['options']) && isset($D['options']['redirect']) && $D['options']['redirect']) {
639
+                if (isset($D['options']) && isset($D['options']['redirect']) && $D['options']['redirect']) {
640 640
                    $dev_status = HIDDEN;
641
-                }  else {
641
+                } else {
642 642
                    $eap = $dev->getPreferredEapType($preferred_eap);
643 643
                    if ($eap) {
644 644
                        if (isset($EAP_options["eap-specific:customtext"][serialize($eap)]))
Please login to merge, or discard this patch.
Braces   +109 added lines, -78 removed lines patch added patch discarded remove patch
@@ -232,8 +232,8 @@  discard block
 block discarded – undo
232 232
 
233 233
         $idpoptions = $idp->getAttributes();
234 234
 
235
-        foreach ($idpoptions as $the_attr)
236
-            $temparray[] = [
235
+        foreach ($idpoptions as $the_attr) {
236
+                    $temparray[] = [
237 237
                 "name" => $the_attr["name"],
238 238
                 "value" => $the_attr["value"],
239 239
                 "level" => $the_attr["level"],
@@ -242,28 +242,33 @@  discard block
 block discarded – undo
242 242
                 "device" => NULL,
243 243
                 "eapmethod" => NULL,
244 244
             ];
245
+        }
245 246
 
246 247
         // check sanity (device and eapmethod are mutually exclusive) and first batch of adding (method level)
247 248
 
248 249
         foreach ($temparray as $attrib) {
249
-            if ($attrib["device"] != NULL && $attrib["eapmethod"] != NULL)
250
-                debug(2, "Sanity check failed - device and eapmethod are set!\n");
250
+            if ($attrib["device"] != NULL && $attrib["eapmethod"] != NULL) {
251
+                            debug(2, "Sanity check failed - device and eapmethod are set!\n");
252
+            }
251 253
         }
252 254
 
253 255
         foreach ($temparray as $attrib) {
254
-            if ($attrib["device"] != NULL || $attrib["eapmethod"] != NULL)
255
-                $this->attributes[] = $attrib;
256
+            if ($attrib["device"] != NULL || $attrib["eapmethod"] != NULL) {
257
+                            $this->attributes[] = $attrib;
258
+            }
256 259
         }
257 260
         // pick all attributes which are profile specific and place into final array if no eap/device-specific exists
258 261
 
259 262
         foreach ($temparray as $attrib) {
260 263
             if ($attrib["level"] == "Profile") {
261 264
                 $ignore = "";
262
-                foreach ($this->attributes as $approved_attrib)
263
-                    if ($attrib["name"] == $approved_attrib["name"] && $approved_attrib["level"] != "IdP" && $approved_attrib["level"] != "Profile")
265
+                foreach ($this->attributes as $approved_attrib) {
266
+                                    if ($attrib["name"] == $approved_attrib["name"] && $approved_attrib["level"] != "IdP" && $approved_attrib["level"] != "Profile")
264 267
                         $ignore = "YES";
265
-                if ($ignore != "YES")
266
-                    $this->attributes[] = $attrib;
268
+                }
269
+                if ($ignore != "YES") {
270
+                                    $this->attributes[] = $attrib;
271
+                }
267 272
             }
268 273
         }
269 274
 
@@ -272,11 +277,13 @@  discard block
 block discarded – undo
272 277
         foreach ($temparray as $attrib) {
273 278
             if ($attrib["level"] == "IdP") {
274 279
                 $ignore = "";
275
-                foreach ($this->attributes as $approved_attrib)
276
-                    if ($attrib["name"] == $approved_attrib["name"] && $approved_attrib["level"] != "IdP")
280
+                foreach ($this->attributes as $approved_attrib) {
281
+                                    if ($attrib["name"] == $approved_attrib["name"] && $approved_attrib["level"] != "IdP")
277 282
                         $ignore = "YES";
278
-                if ($ignore != "YES")
279
-                    $this->attributes[] = $attrib;
283
+                }
284
+                if ($ignore != "YES") {
285
+                                    $this->attributes[] = $attrib;
286
+                }
280 287
             }
281 288
         }
282 289
 
@@ -305,8 +312,9 @@  discard block
 block discarded – undo
305 312
         $exec_query = DBConnection::exec($this->databaseType, "SELECT profile_id FROM profile WHERE realm LIKE '%@$realm'");
306 313
         if ($a = mysqli_fetch_object($exec_query)) {
307 314
             return $a->profile_id;
308
-        } else
309
-            return FALSE;
315
+        } else {
316
+                    return FALSE;
317
+        }
310 318
     }
311 319
     
312 320
     /**
@@ -391,20 +399,23 @@  discard block
 block discarded – undo
391 399
     public function getUserDownloadStats($device = 0) {
392 400
         $returnarray = [];
393 401
         $numbers_q = DBConnection::exec($this->databaseType, "SELECT device_id, SUM(downloads_user) AS downloads_user FROM downloads WHERE profile_id = $this->identifier GROUP BY device_id");
394
-        while ($a = mysqli_fetch_object($numbers_q))
395
-            $returnarray[$a->device_id] = $a->downloads_user;
402
+        while ($a = mysqli_fetch_object($numbers_q)) {
403
+                    $returnarray[$a->device_id] = $a->downloads_user;
404
+        }
396 405
         if ($device !== 0) {
397
-            if (isset($returnarray[$device]))
398
-                return $returnarray[$device];
399
-            else
400
-                return 0;
406
+            if (isset($returnarray[$device])) {
407
+                            return $returnarray[$device];
408
+            } else {
409
+                            return 0;
410
+            }
401 411
         }
402 412
         // we should pretty-print the device names
403 413
         $finalarray = [];
404 414
         $devlist = Devices::listDevices();
405
-        foreach ($returnarray as $dev_id => $count)
406
-            if (isset($devlist[$dev_id]))
415
+        foreach ($returnarray as $dev_id => $count) {
416
+                    if (isset($devlist[$dev_id]))
407 417
                     $finalarray[$devlist[$dev_id]['display']] = $count;
418
+        }
408 419
         return $finalarray;
409 420
     }
410 421
 
@@ -515,9 +526,10 @@  discard block
 block discarded – undo
515 526
         if ($complete_only == 0) {
516 527
             return $this->priv_eaptypes;
517 528
         } else {
518
-            foreach ($this->priv_eaptypes as $type)
519
-                if ($this->isEapTypeDefinitionComplete($type) === true)
529
+            foreach ($this->priv_eaptypes as $type) {
530
+                            if ($this->isEapTypeDefinitionComplete($type) === true)
520 531
                     $temparray[] = $type;
532
+            }
521 533
             return($temparray);
522 534
         }
523 535
     }
@@ -534,27 +546,31 @@  discard block
 block discarded – undo
534 546
         $outarray = [];
535 547
         $temparray = [];
536 548
         if ($eapmethod) {
537
-            foreach ($this->attributes as $the_attr) 
538
-                if ($the_attr["eapmethod"] == $eapmethod)
549
+            foreach ($this->attributes as $the_attr) {
550
+                            if ($the_attr["eapmethod"] == $eapmethod)
539 551
                     $temparray[] = $the_attr;
552
+            }
540 553
         } else
541 554
         if ($device) {
542
-            foreach ($this->attributes as $the_attr)
543
-                if ($the_attr["device"] == $device)
555
+            foreach ($this->attributes as $the_attr) {
556
+                            if ($the_attr["device"] == $device)
544 557
                     $temparray[] = $the_attr;
558
+            }
545 559
         };
546 560
 
547
-        foreach ($this->attributes as $the_attr)
548
-            if ($the_attr["device"] == NULL && $the_attr["eapmethod"] == NULL)
561
+        foreach ($this->attributes as $the_attr) {
562
+                    if ($the_attr["device"] == NULL && $the_attr["eapmethod"] == NULL)
549 563
                 $temparray[] = $the_attr;
564
+        }
550 565
 
551 566
 
552 567
         // return only options by one name, if asked for
553 568
 
554 569
         if ($option_name) {
555
-            foreach ($temparray as $the_attr)
556
-                if ($the_attr["name"] == $option_name)
570
+            foreach ($temparray as $the_attr) {
571
+                            if ($the_attr["name"] == $option_name)
557 572
                     $outarray[] = $the_attr;
573
+            }
558 574
         } else {
559 575
             $outarray = $temparray;
560 576
         }
@@ -582,15 +598,18 @@  discard block
 block discarded – undo
582 598
                 foreach ($ca_option as $one_ca) {
583 599
                     $x509 = new X509();
584 600
                     $ca_parsed = $x509->processCertificate($one_ca['value']);
585
-                    if ($ca_parsed['root'] == 1)
586
-                        return true;
601
+                    if ($ca_parsed['root'] == 1) {
602
+                                            return true;
603
+                    }
587 604
                 }
588 605
                 $missing[] = "eap:ca_file";
589 606
             }
590
-            if (count($ca_option) == 0)
591
-                $missing[] = "eap:ca_file";
592
-            if (count($cn_option) == 0)
593
-                $missing[] = "eap:server_name";
607
+            if (count($ca_option) == 0) {
608
+                            $missing[] = "eap:ca_file";
609
+            }
610
+            if (count($cn_option) == 0) {
611
+                            $missing[] = "eap:server_name";
612
+            }
594 613
             return $missing;
595 614
         } elseif ($eaptype["OUTER"] == PWD || $eaptype["INNER"] == NE_SILVERBULLET) {
596 615
             /*
@@ -613,8 +632,9 @@  discard block
 block discarded – undo
613 632
      * @return array of device ids display names and their status
614 633
      */
615 634
     public function listDevices($locale = 0) {
616
-        if ($locale == 0)
617
-            $locale = $this->lang_index;
635
+        if ($locale == 0) {
636
+                    $locale = $this->lang_index;
637
+        }
618 638
         $redirect_url = 0;
619 639
         $message = 0;
620 640
         $returnarray = [];
@@ -630,20 +650,21 @@  discard block
 block discarded – undo
630 650
             $dev = $factory->device;
631 651
             $redirect_url = getLocalisedValue($this->getAttributes("device-specific:redirect", 0, $d), $locale);
632 652
             $dev_status = AVAILABLE;
633
-            if(isset($D['options']) && isset($D['options']['message']) && $D['options']['message']) 
634
-               $message = $D['options']['message'];
635
-            else
636
-               $message = 0;
653
+            if(isset($D['options']) && isset($D['options']['message']) && $D['options']['message']) {
654
+                           $message = $D['options']['message'];
655
+            } else {
656
+                           $message = 0;
657
+            }
637 658
 
638 659
             if ($redirect_url === 0) {
639 660
                 if(isset($D['options']) && isset($D['options']['redirect']) && $D['options']['redirect']) {
640 661
                    $dev_status = HIDDEN;
641
-                }  else {
662
+                } else {
642 663
                    $eap = $dev->getPreferredEapType($preferred_eap);
643 664
                    if ($eap) {
644
-                       if (isset($EAP_options["eap-specific:customtext"][serialize($eap)]))
645
-                           $eap_customtext = $EAP_options["eap-specific:customtext"][serialize($eap)];
646
-                       else {
665
+                       if (isset($EAP_options["eap-specific:customtext"][serialize($eap)])) {
666
+                                                  $eap_customtext = $EAP_options["eap-specific:customtext"][serialize($eap)];
667
+                       } else {
647 668
                            $eap_customtext = getLocalisedValue($this->getAttributes("eap-specific:customtext", $eap, 0), $locale);
648 669
                            $EAP_options["eap-specific:customtext"][serialize($eap)] = $eap_customtext;
649 670
                        }
@@ -676,8 +697,9 @@  discard block
 block discarded – undo
676 697
             $level = $b['level'];
677 698
 //            $S[$l] = $z[$l];
678 699
             $value = $b['value'];
679
-            if (!isset($temp[$name][$level]))
680
-                $temp[$name][$level] = [];
700
+            if (!isset($temp[$name][$level])) {
701
+                            $temp[$name][$level] = [];
702
+            }
681 703
             if ($b['flag'] == 'ML') {
682 704
                 $v = unserialize($value);
683 705
                 $value = [$v['lang'] => $v['content']];
@@ -689,25 +711,29 @@  discard block
 block discarded – undo
689 711
             if ($flags[$name] == 'ML') {
690 712
                 $S = [];
691 713
                 if (isset($temp[$name]['Profile'])) {
692
-                    foreach ($temp[$name]['Profile'] as $z)
693
-                        foreach ($z as $l => $w)
714
+                    foreach ($temp[$name]['Profile'] as $z) {
715
+                                            foreach ($z as $l => $w)
694 716
                             $S[$l] = $w;
717
+                    }
695 718
                 }
696 719
                 if (!$S && isset($temp[$name]['IdP'])) {
697
-                    foreach ($temp[$name]['IdP'] as $z)
698
-                        foreach ($z as $l => $w)
720
+                    foreach ($temp[$name]['IdP'] as $z) {
721
+                                            foreach ($z as $l => $w)
699 722
                             $S[$l] = $w;
723
+                    }
700 724
                 }
701 725
                 $out[$name]['langs'] = $S;
702
-                if (isset($S[$this->lang_index]) || isset($S['C']))
703
-                    $out[$name][0] = (isset($S[$this->lang_index])) ? $S[$this->lang_index] : $S['C'];
726
+                if (isset($S[$this->lang_index]) || isset($S['C'])) {
727
+                                    $out[$name][0] = (isset($S[$this->lang_index])) ? $S[$this->lang_index] : $S['C'];
728
+                }
704 729
             } else {
705
-                if (isset($temp[$name]['Method']))
706
-                    $out[$name] = $temp[$name]['Method'];
707
-                elseif (isset($temp[$name]['Profile']))
708
-                    $out[$name] = $temp[$name]['Profile'];
709
-                else
710
-                    $out[$name] = $temp[$name]['IdP'];
730
+                if (isset($temp[$name]['Method'])) {
731
+                                    $out[$name] = $temp[$name]['Method'];
732
+                } elseif (isset($temp[$name]['Profile'])) {
733
+                                    $out[$name] = $temp[$name]['Profile'];
734
+                } else {
735
+                                    $out[$name] = $temp[$name]['IdP'];
736
+                }
711 737
             }
712 738
         }
713 739
         return($out);
@@ -745,20 +771,23 @@  discard block
 block discarded – undo
745 771
         $proper_config = FALSE;
746 772
         $attribs = $this->getCollapsedAttributes();
747 773
         // do we have enough to go live? Check if any of the configured EAP methods is completely configured ...
748
-        if (sizeof($this->getEapMethodsinOrderOfPreference(1)) > 0)
749
-            $proper_config = TRUE;
774
+        if (sizeof($this->getEapMethodsinOrderOfPreference(1)) > 0) {
775
+                    $proper_config = TRUE;
776
+        }
750 777
         // if not, it could still be that general redirect has been set
751 778
         if (!$proper_config) {
752
-            if (isset($attribs['device-specific:redirect']))
753
-                $proper_config = TRUE;
779
+            if (isset($attribs['device-specific:redirect'])) {
780
+                            $proper_config = TRUE;
781
+            }
754 782
             // TODO: or maybe just a per-device redirect? would be good enough...
755 783
         }
756 784
         // do we know at least one SSID to configure, or work with wired? If not, it's not ready...
757 785
         if (!isset($attribs['media:SSID']) &&
758 786
                 !isset($attribs['media:SSID_with_legacy']) &&
759 787
                 (!isset(Config::$CONSORTIUM['ssid']) || count(Config::$CONSORTIUM['ssid']) == 0) &&
760
-                !isset($attribs['media:wired']))
761
-            $proper_config = FALSE;
788
+                !isset($attribs['media:wired'])) {
789
+                    $proper_config = FALSE;
790
+        }
762 791
         return $proper_config;
763 792
     }
764 793
 
@@ -767,10 +796,11 @@  discard block
 block discarded – undo
767 796
      */
768 797
     public function prepShowtime() {
769 798
         $proper_config = $this->readyForShowtime();
770
-        if ($proper_config)
771
-            DBConnection::exec($this->databaseType, "UPDATE profile SET sufficient_config = TRUE WHERE profile_id = " . $this->identifier);
772
-        else
773
-            DBConnection::exec($this->databaseType, "UPDATE profile SET sufficient_config = FALSE WHERE profile_id = " . $this->identifier);
799
+        if ($proper_config) {
800
+                    DBConnection::exec($this->databaseType, "UPDATE profile SET sufficient_config = TRUE WHERE profile_id = " . $this->identifier);
801
+        } else {
802
+                    DBConnection::exec($this->databaseType, "UPDATE profile SET sufficient_config = FALSE WHERE profile_id = " . $this->identifier);
803
+        }
774 804
         $attribs = $this->getCollapsedAttributes();
775 805
         // if not enough info to go live, set FALSE
776 806
         // even if enough info is there, admin has the ultimate say: 
@@ -794,10 +824,11 @@  discard block
 block discarded – undo
794 824
         /* echo "<pre>";
795 825
           print_r($r);
796 826
           echo "</pre>"; */
797
-        if ($r[0] == "0")
798
-            return FALSE;
799
-        else
800
-            return TRUE;
827
+        if ($r[0] == "0") {
828
+                    return FALSE;
829
+        } else {
830
+                    return TRUE;
831
+        }
801 832
     }
802 833
 
803 834
     /**
Please login to merge, or discard this patch.
core/User.php 1 patch
Braces   +17 added lines, -11 removed lines patch added patch discarded remove patch
@@ -109,14 +109,16 @@  discard block
 block discarded – undo
109 109
     public function isFederationAdmin($federation = 0) {
110 110
         $feds = $this->getAttributes("user:fedadmin");
111 111
         if ($federation === 0) {
112
-            if (count($feds) == 0)
113
-                return FALSE;
114
-            else
115
-                return TRUE;
112
+            if (count($feds) == 0) {
113
+                            return FALSE;
114
+            } else {
115
+                            return TRUE;
116
+            }
116 117
         } else {
117 118
             foreach ($feds as $fed) {
118
-                if (strtoupper($fed['value']) == strtoupper($federation))
119
-                    return TRUE;
119
+                if (strtoupper($fed['value']) == strtoupper($federation)) {
120
+                                    return TRUE;
121
+                }
120 122
             }
121 123
             return FALSE;
122 124
         }
@@ -139,9 +141,10 @@  discard block
 block discarded – undo
139 141
     */
140 142
     public function isIdPOwner($idp) {
141 143
        $temp = new IdP($idp);
142
-       foreach ($temp->owner() as $oneowner)
143
-            if ($oneowner['ID'] == $this->identifier)
144
+       foreach ($temp->owner() as $oneowner) {
145
+                   if ($oneowner['ID'] == $this->identifier)
144 146
                 return TRUE;
147
+       }
145 148
        return FALSE;
146 149
     }
147 150
 
@@ -165,16 +168,19 @@  discard block
 block discarded – undo
165 168
         $mail->addReplyTo(Config::$APPEARANCE['support-contact']['mail'], Config::$APPEARANCE['productname'] . " " ._("Feedback"));
166 169
         
167 170
         $mailaddr = $this->getAttributes("user:email");
168
-        if (count($mailaddr) == 0) // we don't know his mail address
171
+        if (count($mailaddr) == 0) {
172
+            // we don't know his mail address
169 173
             return FALSE;
174
+        }
170 175
         
171 176
         $mail->addAddress($mailaddr[0]["value"]);
172 177
         
173 178
         // what do we want to say?
174 179
         $mail->Subject = $subject;
175 180
         $mail->Body = $content;
176
-        if (isset(Config::$CONSORTIUM['certfilename'], Config::$CONSORTIUM['keyfilename'], Config::$CONSORTIUM['keypass']))
177
-            $mail->sign(Config::$CONSORTIUM['certfilename'], Config::$CONSORTIUM['keyfilename'], Config::$CONSORTIUM['keypass']);
181
+        if (isset(Config::$CONSORTIUM['certfilename'], Config::$CONSORTIUM['keyfilename'], Config::$CONSORTIUM['keypass'])) {
182
+                    $mail->sign(Config::$CONSORTIUM['certfilename'], Config::$CONSORTIUM['keyfilename'], Config::$CONSORTIUM['keypass']);
183
+        }
178 184
 
179 185
 
180 186
         $sent = $mail->send();
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,15 +60,15 @@  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
\ No newline at end of file
Please login to merge, or discard this patch.
core/Federation.php 1 patch
Braces   +69 added lines, -47 removed lines patch added patch discarded remove patch
@@ -58,8 +58,9 @@  discard block
 block discarded – undo
58 58
         $timestamp = date("Y-m-d") . "T" . date("H:i:s");
59 59
         
60 60
         $retstring = "";
61
-        if (!$astablerows)
62
-            $retstring .= "<federation id='" . ( $federationid == NULL ? "ALL" : $federationid ) . "' ts='$timestamp'>\n";
61
+        if (!$astablerows) {
62
+                    $retstring .= "<federation id='" . ( $federationid == NULL ? "ALL" : $federationid ) . "' ts='$timestamp'>\n";
63
+        }
63 64
 
64 65
         foreach (Devices::listDevices() as $index => $device_array) {
65 66
             $query = "SELECT SUM(downloads_admin) AS admin, SUM(downloads_user) AS user FROM downloads, profile, institution WHERE device_id = '$index' AND downloads.profile_id = profile.profile_id AND profile.inst_id = institution.inst_id ";
@@ -69,8 +70,9 @@  discard block
 block discarded – undo
69 70
             $retstring .= ($astablerows ? "<tr>" : "  <device name='" . $device_array['display'] . "'>\n");
70 71
             $admin_query = DBConnection::exec($this->databaseType, $query);
71 72
             while ($a = mysqli_fetch_object($admin_query)) {
72
-                if ($astablerows)
73
-                    $retstring .= "<td>" . $device_array['display'] . "</td>";
73
+                if ($astablerows) {
74
+                                    $retstring .= "<td>" . $device_array['display'] . "</td>";
75
+                }
74 76
                 $retstring .= ($astablerows ? "<td>" : "    <downloads group='admin'>");
75 77
                 $retstring .= ( $a->admin === NULL ? "0" : $a->admin);
76 78
                 $retstring .= ($astablerows ? "</td><td>" : "</downloads>\n    <downloads group='user'>");
@@ -82,16 +84,18 @@  discard block
 block discarded – undo
82 84
             $retstring .= ($astablerows ? "</tr>" : "  </device>\n");
83 85
         }
84 86
         $retstring .= ($astablerows ? "<tr>" : "  <total>\n");
85
-        if ($astablerows)
86
-            $retstring .= "<td><strong>TOTAL</ts>";
87
+        if ($astablerows) {
88
+                    $retstring .= "<td><strong>TOTAL</ts>";
89
+        }
87 90
         $retstring .= ($astablerows ? "<td><strong>" : "    <downloads group='admin'>");
88 91
         $retstring .= $gross_admin;
89 92
         $retstring .= ($astablerows ? "</strong></td><td><strong>" : "</downloads>\n    <downloads group='user'>");
90 93
         $retstring .= $gross_user;
91 94
         $retstring .= ($astablerows ? "</strong></td>" : "</downloads>\n");
92 95
         $retstring .= ($astablerows ? "</tr>" : "  </total>\n");
93
-        if (!$astablerows)
94
-            $retstring .= "</federation>\n";
96
+        if (!$astablerows) {
97
+                    $retstring .= "</federation>\n";
98
+        }
95 99
 
96 100
         return $retstring;
97 101
     }
@@ -431,8 +435,9 @@  discard block
 block discarded – undo
431 435
         $escapedLevel = DBConnection::escape_value($this->databaseType, $level);
432 436
         $escapedMail = DBConnection::escape_value($this->databaseType, $mail);
433 437
 
434
-        if ($escapedOwnerId != "PENDING")
435
-            DBConnection::exec($this->databaseType, "INSERT INTO ownership (user_id,institution_id, blesslevel, orig_mail) VALUES('$escapedOwnerId', $identifier, '$escapedLevel', '$escapedMail')");
438
+        if ($escapedOwnerId != "PENDING") {
439
+                    DBConnection::exec($this->databaseType, "INSERT INTO ownership (user_id,institution_id, blesslevel, orig_mail) VALUES('$escapedOwnerId', $identifier, '$escapedLevel', '$escapedMail')");
440
+        }
436 441
         return $identifier;
437 442
     }
438 443
 
@@ -471,13 +476,16 @@  discard block
 block discarded – undo
471 476
 
472 477
     public function listFederationAdmins() {
473 478
         $returnarray = [];
474
-        if (Config::$CONSORTIUM['name'] == "eduroam" && isset(Config::$CONSORTIUM['deployment-voodoo']) && Config::$CONSORTIUM['deployment-voodoo'] == "Operations Team") // SW: APPROVED
479
+        if (Config::$CONSORTIUM['name'] == "eduroam" && isset(Config::$CONSORTIUM['deployment-voodoo']) && Config::$CONSORTIUM['deployment-voodoo'] == "Operations Team") {
480
+            // SW: APPROVED
475 481
             $admins = DBConnection::exec("USER", "SELECT eptid as user_id FROM view_admin WHERE role = 'fedadmin' AND realm = '" . strtolower($this->name) . "'");
476
-        else
477
-            $admins = DBConnection::exec("USER", "SELECT user_id FROM user_options WHERE option_name = 'user:fedadmin' AND option_value = '" . strtoupper($this->name) . "'");
482
+        } else {
483
+                    $admins = DBConnection::exec("USER", "SELECT user_id FROM user_options WHERE option_name = 'user:fedadmin' AND option_value = '" . strtoupper($this->name) . "'");
484
+        }
478 485
 
479
-        while ($a = mysqli_fetch_object($admins))
480
-            $returnarray[] = $a->user_id;
486
+        while ($a = mysqli_fetch_object($admins)) {
487
+                    $returnarray[] = $a->user_id;
488
+        }
481 489
         return $returnarray;
482 490
     }
483 491
 
@@ -485,10 +493,11 @@  discard block
 block discarded – undo
485 493
         $returnarray = [];
486 494
         $countrysuffix = "";
487 495
         
488
-        if ($this->name != "")
489
-            $countrysuffix = " WHERE country = '" . strtolower($this->name) . "'";
490
-        else
491
-            $countrysuffix = "";
496
+        if ($this->name != "") {
497
+                    $countrysuffix = " WHERE country = '" . strtolower($this->name) . "'";
498
+        } else {
499
+                    $countrysuffix = "";
500
+        }
492 501
         
493 502
         if (Config::$CONSORTIUM['name'] == "eduroam" && isset(Config::$CONSORTIUM['deployment-voodoo']) && Config::$CONSORTIUM['deployment-voodoo'] == "Operations Team") { // SW: APPROVED
494 503
             $usedarray = [];
@@ -501,15 +510,18 @@  discard block
 block discarded – undo
501 510
                                                                                                       WHERE external_db_uniquehandle IS NOT NULL 
502 511
                                                                                                       AND invite_created >= TIMESTAMPADD(DAY, -1, NOW()) 
503 512
                                                                                                       AND used = 0");
504
-            while ($a = mysqli_fetch_object($already_used))
505
-                $usedarray[] = $a->external_db_id;
506
-            while ($a = mysqli_fetch_object($pending_invite))
507
-                if (!in_array($a->external_db_uniquehandle, $usedarray))
513
+            while ($a = mysqli_fetch_object($already_used)) {
514
+                            $usedarray[] = $a->external_db_id;
515
+            }
516
+            while ($a = mysqli_fetch_object($pending_invite)) {
517
+                            if (!in_array($a->external_db_uniquehandle, $usedarray))
508 518
                     $usedarray[] = $a->external_db_uniquehandle;
519
+            }
509 520
             while ($a = mysqli_fetch_object($externals)) {
510 521
                 if ($unmapped_only === TRUE) {
511
-                    if (in_array($a->id, $usedarray))
512
-                        continue;
522
+                    if (in_array($a->id, $usedarray)) {
523
+                                            continue;
524
+                    }
513 525
                 }
514 526
                 $names = explode('#', $a->collapsed_name);
515 527
                 // trim name list to current best language match
@@ -533,8 +545,9 @@  discard block
 block discarded – undo
533 545
                     $matches = [];
534 546
                     preg_match("/^n: (.*), e: (.*), p: .*$/", $contact, $matches);
535 547
                     if ($matches[2] != "") {
536
-                        if ($mailnames != "")
537
-                            $mailnames .= ", ";
548
+                        if ($mailnames != "") {
549
+                                                    $mailnames .= ", ";
550
+                        }
538 551
                         // extracting real names is nice, but the <> notation
539 552
                         // really gets screwed up on POSTs and HTML safety
540 553
                         // so better not do this; use only mail addresses
@@ -553,10 +566,11 @@  discard block
 block discarded – undo
553 566
     public static function getExternalDBEntityDetails($external_id, $realm = NULL) {
554 567
         $list = [];
555 568
         if (Config::$CONSORTIUM['name'] == "eduroam" && isset(Config::$CONSORTIUM['deployment-voodoo']) && Config::$CONSORTIUM['deployment-voodoo'] == "Operations Team") { // SW: APPROVED
556
-            if ($realm !== NULL)
557
-                $scanforrealm = "OR inst_realm LIKE '%$realm%'";
558
-            else
559
-                $scanforrealm = "";
569
+            if ($realm !== NULL) {
570
+                            $scanforrealm = "OR inst_realm LIKE '%$realm%'";
571
+            } else {
572
+                            $scanforrealm = "";
573
+            }
560 574
             $info_list = DBConnection::exec("EXTERNAL", "SELECT name AS collapsed_name, inst_realm as realmlist, contact AS collapsed_contact, country FROM view_active_idp_institution WHERE id_institution = $external_id $scanforrealm");
561 575
             // split names and contacts into proper pairs
562 576
             while ($a = mysqli_fetch_object($info_list)) {
@@ -590,14 +604,16 @@  discard block
 block discarded – undo
590 604
         $query = "SELECT distinct institution.inst_id AS inst_id, institution.country AS country,
591 605
                      group_concat(concat_ws('===',institution_option.option_name,LEFT(institution_option.option_value,200)) separator '---') AS options
592 606
                      FROM institution ";
593
-        if ($active_only == 1)
594
-            $query .= "JOIN profile ON institution.inst_id = profile.inst_id ";
607
+        if ($active_only == 1) {
608
+                    $query .= "JOIN profile ON institution.inst_id = profile.inst_id ";
609
+        }
595 610
         $query .= "JOIN institution_option ON institution.inst_id = institution_option.institution_id ";
596 611
         $query .= "WHERE (institution_option.option_name = 'general:instname' 
597 612
                           OR institution_option.option_name = 'general:geo_coordinates'
598 613
                           OR institution_option.option_name = 'general:logo_file') ";
599
-        if ($active_only == 1)
600
-            $query .= "AND profile.showtime = 1 ";
614
+        if ($active_only == 1) {
615
+                    $query .= "AND profile.showtime = 1 ";
616
+        }
601 617
 
602 618
         if ($country) {
603 619
             // escape the parameter
@@ -610,25 +626,30 @@  discard block
 block discarded – undo
610 626
         while ($a = mysqli_fetch_object($allIDPs)) {
611 627
             $O = explode('---', $a->options);
612 628
             $A = [];
613
-            if (isset($geo))
614
-                unset($geo);
615
-            if (isset($names))
616
-                $names = [];
629
+            if (isset($geo)) {
630
+                            unset($geo);
631
+            }
632
+            if (isset($names)) {
633
+                            $names = [];
634
+            }
617 635
             $A['entityID'] = $a->inst_id;
618 636
             $A['country'] = strtoupper($a->country);
619 637
             foreach ($O as $o) {
620 638
                 $opt = explode('===', $o);
621
-                if ($opt[0] == 'general:logo_file')
622
-                    $A['icon'] = $a->inst_id;
639
+                if ($opt[0] == 'general:logo_file') {
640
+                                    $A['icon'] = $a->inst_id;
641
+                }
623 642
                 if ($opt[0] == 'general:geo_coordinates') {
624 643
                     $at1 = unserialize($opt[1]);
625
-                    if (!isset($geo))
626
-                        $geo = [];
644
+                    if (!isset($geo)) {
645
+                                            $geo = [];
646
+                    }
627 647
                     $geo[] = $at1;
628 648
                 }
629 649
                 if ($opt[0] == 'general:instname') {
630
-                    if (!isset($names))
631
-                        $names = [];
650
+                    if (!isset($names)) {
651
+                                            $names = [];
652
+                    }
632 653
                     $names[] = ['value' => $opt[1]];
633 654
                 }
634 655
             }
@@ -638,8 +659,9 @@  discard block
 block discarded – undo
638 659
                 $name = getLocalisedValue($names, CAT::get_lang());
639 660
             }
640 661
             $A['title'] = $name;
641
-            if (isset($geo))
642
-                $A['geo'] = $geo;
662
+            if (isset($geo)) {
663
+                            $A['geo'] = $geo;
664
+            }
643 665
             $returnarray[] = $A;
644 666
         }
645 667
         return $returnarray;
Please login to merge, or discard this patch.
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,75 +521,75 @@  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
\ No newline at end of file
Please login to merge, or discard this patch.
core/UserAPI.php 2 patches
Indentation   +391 added lines, -391 removed lines patch added patch discarded remove patch
@@ -52,7 +52,7 @@  discard block
 block discarded – undo
52 52
  *  link - the path name of the resulting installer
53 53
  *  mime - the mimetype of the installer
54 54
  */
55
-  public function generateInstaller($device,$prof_id, $generated_for = "user") {
55
+    public function generateInstaller($device,$prof_id, $generated_for = "user") {
56 56
     $this->set_locale("devices");
57 57
     $Dev = Devices::listDevices();
58 58
     $Config = $Dev[$device];
@@ -61,93 +61,93 @@  discard block
 block discarded – undo
61 61
     $attribs = $profile->getCollapsedAttributes();
62 62
     // test if the profile is production-ready and if not if the authenticated user is an owner
63 63
     if (!isset($attribs['profile:production']) || (isset($attribs['profile:production']) && $attribs['profile:production'][0] != "on")) {
64
-       debug(4,"Attempt to download a non-production ready installer fir profile: $prof_id\n");
65
-       require_once(Config::$AUTHENTICATION['ssp-path-to-autoloader']);
66
-       $as = new SimpleSAML_Auth_Simple(Config::$AUTHENTICATION['ssp-authsource']);
67
-       if($as->isAuthenticated()) {
68
-          $user_object = new User($_SESSION['user']);
69
-          if($user_object->isIdPOwner($profile->institution)) {
70
-              debug(4, "User is the owner - allowing access\n");
71
-          } else {
72
-             debug(2, "User not an owner of a non-production profile - access forbidden\n");
73
-       header("HTTP/1.0 403 Not Authorized");
74
-             return;
75
-          }
76
-       } else {
77
-          debug(2, "User NOT authenticated, rejecting request for a non-production installer\n");
78
-          header("HTTP/1.0 403 Not Authorized");
79
-          return;
80
-       }
64
+        debug(4,"Attempt to download a non-production ready installer fir profile: $prof_id\n");
65
+        require_once(Config::$AUTHENTICATION['ssp-path-to-autoloader']);
66
+        $as = new SimpleSAML_Auth_Simple(Config::$AUTHENTICATION['ssp-authsource']);
67
+        if($as->isAuthenticated()) {
68
+            $user_object = new User($_SESSION['user']);
69
+            if($user_object->isIdPOwner($profile->institution)) {
70
+                debug(4, "User is the owner - allowing access\n");
71
+            } else {
72
+                debug(2, "User not an owner of a non-production profile - access forbidden\n");
73
+        header("HTTP/1.0 403 Not Authorized");
74
+                return;
75
+            }
76
+        } else {
77
+            debug(2, "User NOT authenticated, rejecting request for a non-production installer\n");
78
+            header("HTTP/1.0 403 Not Authorized");
79
+            return;
80
+        }
81 81
     }
82 82
     $a = [];
83 83
     $a['profile'] = $prof_id;
84 84
     $a['device'] = $device;
85 85
     if( (isset(Devices::$Options['no_cache']) && Devices::$Options['no_cache'] ) || ( isset($Config['options']['no_cache']) && $Config['options']['no_cache'] ))
86
-      $this->i_path = FALSE;
86
+        $this->i_path = FALSE;
87 87
     else {
88
-      $cache = $profile->testCache($device);
89
-      $this->i_path = $cache['cache'];
88
+        $cache = $profile->testCache($device);
89
+        $this->i_path = $cache['cache'];
90 90
     }
91 91
     if($this->i_path && is_file($this->i_path)) { 
92
-      debug(4,"Using cached installer for: $device\n");
93
-      $a['link'] = "API.php?api_version=$version&action=downloadInstaller&lang=".CAT::get_lang()."&profile=$prof_id&device=$device&generatedfor=$generated_for";
94
-      $a['mime'] = $cache['mime'];
92
+        debug(4,"Using cached installer for: $device\n");
93
+        $a['link'] = "API.php?api_version=$version&action=downloadInstaller&lang=".CAT::get_lang()."&profile=$prof_id&device=$device&generatedfor=$generated_for";
94
+        $a['mime'] = $cache['mime'];
95 95
     } else {
96
-      $factory = new DeviceFactory($device);
97
-      $dev = $factory->device;
98
-      if(isset($dev)) {
99
-         $dev->setup($profile);
100
-         $installer = $dev->writeInstaller();
101
-         $i_path = $dev->FPATH.'/tmp/'.$installer;
102
-         if($i_path && is_file($i_path)) {
103
-         if(isset($dev->options['mime']))
104
-               $a['mime'] = $dev->options['mime'];
105
-         else {
106
-           $info = new finfo();
107
-           $a['mime'] = $info->file($i_path, FILEINFO_MIME_TYPE);
108
-         }
109
-         $this->i_path = $dev->FPATH.'/'.$installer;
110
-         rename($i_path, $this->i_path);
111
-         $profile->updateCache($device,$this->i_path,$a['mime']);
96
+        $factory = new DeviceFactory($device);
97
+        $dev = $factory->device;
98
+        if(isset($dev)) {
99
+            $dev->setup($profile);
100
+            $installer = $dev->writeInstaller();
101
+            $i_path = $dev->FPATH.'/tmp/'.$installer;
102
+            if($i_path && is_file($i_path)) {
103
+            if(isset($dev->options['mime']))
104
+                $a['mime'] = $dev->options['mime'];
105
+            else {
106
+            $info = new finfo();
107
+            $a['mime'] = $info->file($i_path, FILEINFO_MIME_TYPE);
108
+            }
109
+            $this->i_path = $dev->FPATH.'/'.$installer;
110
+            rename($i_path, $this->i_path);
111
+            $profile->updateCache($device,$this->i_path,$a['mime']);
112 112
 //         rrmdir($dev->FPATH.'/tmp');
113
-         debug(4,"Generated installer: ".$this->i_path.": for: $device\n");
114
-         $a['link'] = "API.php?api_version=$version&action=downloadInstaller&lang=".CAT::get_lang()."&profile=$prof_id&device=$device&generatedfor=$generated_for";
115
-         } else {
116
-         debug(2,"Installer generation failed for: $prof_id:$device:".CAT::get_lang()."\n");
117
-         $a['link'] = 0;
118
-         }
119
-      } 
113
+            debug(4,"Generated installer: ".$this->i_path.": for: $device\n");
114
+            $a['link'] = "API.php?api_version=$version&action=downloadInstaller&lang=".CAT::get_lang()."&profile=$prof_id&device=$device&generatedfor=$generated_for";
115
+            } else {
116
+            debug(2,"Installer generation failed for: $prof_id:$device:".CAT::get_lang()."\n");
117
+            $a['link'] = 0;
118
+            }
119
+        } 
120 120
     }
121 121
     $this->set_locale("web_user");
122 122
     return($a);
123
- }
123
+    }
124 124
 
125
- /**
126
-  * interface to Devices::listDevices() 
127
-  */
128
- public function listDevices($show_hidden = 0) {
125
+    /**
126
+     * interface to Devices::listDevices() 
127
+     */
128
+    public function listDevices($show_hidden = 0) {
129 129
     $Dev = Devices::listDevices();
130 130
     $R = [];
131 131
     $ct = 0;
132 132
     if($show_hidden !== 0 && $show_hidden != 1)
133
-      return;
133
+        return;
134 134
     foreach ($Dev as $device => $D) {
135
-      if(isset($D['options']['hidden']) && $D['options']['hidden'] && $show_hidden == 0)
136
-         continue;
137
-      $ct ++;
138
-      if($this->version == 1)
139
-         $D['device'] = $device;
140
-      else
141
-         $D['device'] = $device;
142
-      $group = isset($D['group']) ? $D['group'] : 'other';
143
-      if (! isset($R[$group]))
144
-         $R[$group] = [];
145
-      $R[$group][$device] = $D;
146
-    }
147
-   return $R;
148
- }
149
-
150
- public function deviceInfo($device,$prof_id) {
135
+        if(isset($D['options']['hidden']) && $D['options']['hidden'] && $show_hidden == 0)
136
+            continue;
137
+        $ct ++;
138
+        if($this->version == 1)
139
+            $D['device'] = $device;
140
+        else
141
+            $D['device'] = $device;
142
+        $group = isset($D['group']) ? $D['group'] : 'other';
143
+        if (! isset($R[$group]))
144
+            $R[$group] = [];
145
+        $R[$group][$device] = $D;
146
+    }
147
+    return $R;
148
+    }
149
+
150
+    public function deviceInfo($device,$prof_id) {
151 151
     $this->set_locale("devices");
152 152
     $out = 0;
153 153
     $profile = new Profile($prof_id);
@@ -155,11 +155,11 @@  discard block
 block discarded – undo
155 155
     $dev = $factory->device;
156 156
     if(isset($dev)) {
157 157
 //       $dev->setup($profile);
158
-       $out = $dev->writeDeviceInfo();
159
-   }
158
+        $out = $dev->writeDeviceInfo();
159
+    }
160 160
     $this->set_locale("web_user");
161 161
     echo $out;
162
- }
162
+    }
163 163
 
164 164
 /**
165 165
  * Prepare the support data for a given profile
@@ -173,23 +173,23 @@  discard block
 block discarded – undo
173 173
  * - description
174 174
  * - devices - an array of device names and their statuses (for a given profile)
175 175
  */
176
- public function profileAttributes($prof_id) {
176
+    public function profileAttributes($prof_id) {
177 177
     $this->set_locale("devices");
178
-      $profile = new Profile($prof_id);
179
-      $attr = $profile->getCollapsedAttributes();
180
-      $a = [];
181
-      if(isset($attr['support:email']))
182
-         $a['local_email'] = $attr['support:email'][0];
183
-      if(isset($attr['support:phone']))
184
-         $a['local_phone'] = $attr['support:phone'][0];
185
-      if(isset($attr['support:url']))
186
-         $a['local_url'] = $attr['support:url'][0];
187
-      if(isset($attr['profile:description']))
188
-         $a['description'] = $attr['profile:description'][0];
189
-      $a['devices'] = $profile->listDevices();
190
-      $this->set_locale("web_user");
191
-      return($a);
192
- }
178
+        $profile = new Profile($prof_id);
179
+        $attr = $profile->getCollapsedAttributes();
180
+        $a = [];
181
+        if(isset($attr['support:email']))
182
+            $a['local_email'] = $attr['support:email'][0];
183
+        if(isset($attr['support:phone']))
184
+            $a['local_phone'] = $attr['support:phone'][0];
185
+        if(isset($attr['support:url']))
186
+            $a['local_url'] = $attr['support:url'][0];
187
+        if(isset($attr['profile:description']))
188
+            $a['description'] = $attr['profile:description'][0];
189
+        $a['devices'] = $profile->listDevices();
190
+        $this->set_locale("web_user");
191
+        return($a);
192
+    }
193 193
 
194 194
 /*
195 195
    this method needs to be used with care, it could give wrong results in some
@@ -201,13 +201,13 @@  discard block
 block discarded – undo
201 201
     $file= $F['file'];
202 202
     $file = substr($file,strlen(dirname(__DIR__)));
203 203
     while(substr($file,0,1) == '/')
204
-       $file = substr($file,1);
204
+        $file = substr($file,1);
205 205
     $n = count(explode('/',$file));
206 206
     $out = $_SERVER['SCRIPT_NAME'];
207 207
     for ($i= 0; $i < $n; $i++)
208
-      $out = dirname($out);
208
+        $out = dirname($out);
209 209
     if ($out == '/')
210
-      $out = '';
210
+        $out = '';
211 211
     $s = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] ? 'https' : 'http';
212 212
     $s .= '://'.$_SERVER['HTTP_HOST'] . $out;
213 213
     return $s;
@@ -215,29 +215,29 @@  discard block
 block discarded – undo
215 215
 
216 216
 /* JSON functions */
217 217
 
218
-  public function return_json($data,$status=1) {
219
-     $return_array = [];
220
-     $return_array['status'] = $status;
221
-     $return_array['data'] = $data;
222
-     $return_array['tou'] =  "Please consult Terms of Use at: ".$this->GetRootURL()."/tou.php";
223
-     return(json_encode($return_array));
224
-  }
218
+    public function return_json($data,$status=1) {
219
+        $return_array = [];
220
+        $return_array['status'] = $status;
221
+        $return_array['data'] = $data;
222
+        $return_array['tou'] =  "Please consult Terms of Use at: ".$this->GetRootURL()."/tou.php";
223
+        return(json_encode($return_array));
224
+    }
225 225
 
226 226
 /**
227
-  * Return the list of supported languages.
228
-  *
229
-  * 
230
-  */
231
-  public function JSON_listLanguages() {
232
-     $return_array = [];
233
-     foreach(Config::$LANGUAGES as $id => $val){
234
-       if($this->version == 1)
235
-          $return_array[] = ['id'=>$id,'display'=>$val['display'],'locale'=>$val['locale']];
236
-       else
237
-          $return_array[] = ['lang'=>$id,'display'=>$val['display'],'locale'=>$val['locale']];
238
-     }
239
-     echo $this->return_json($return_array);
240
-  }
227
+ * Return the list of supported languages.
228
+ *
229
+ * 
230
+ */
231
+    public function JSON_listLanguages() {
232
+        $return_array = [];
233
+        foreach(Config::$LANGUAGES as $id => $val){
234
+        if($this->version == 1)
235
+            $return_array[] = ['id'=>$id,'display'=>$val['display'],'locale'=>$val['locale']];
236
+        else
237
+            $return_array[] = ['lang'=>$id,'display'=>$val['display'],'locale'=>$val['locale']];
238
+        }
239
+        echo $this->return_json($return_array);
240
+    }
241 241
 
242 242
 /**
243 243
  * Return the list of countiers with configured IdPs
@@ -245,17 +245,17 @@  discard block
 block discarded – undo
245 245
  * @return string JSON encoded data
246 246
  */
247 247
 
248
-  public function JSON_listCountries() {
249
-     $FED = $this->printCountryList(1);
250
-     $return_array = [];
251
-     foreach ($FED as $id => $val) {
252
-       if($this->version == 1)
253
-          $return_array[] = ['id'=>$id,'display'=>$val];
254
-       else
255
-          $return_array[] = ['federation'=>$id,'display'=>$val];
256
-     }
257
-     echo $this->return_json($return_array);
258
-  }
248
+    public function JSON_listCountries() {
249
+        $FED = $this->printCountryList(1);
250
+        $return_array = [];
251
+        foreach ($FED as $id => $val) {
252
+        if($this->version == 1)
253
+            $return_array[] = ['id'=>$id,'display'=>$val];
254
+        else
255
+            $return_array[] = ['federation'=>$id,'display'=>$val];
256
+        }
257
+        echo $this->return_json($return_array);
258
+    }
259 259
 
260 260
 /**
261 261
  * Return the list of IdPs in a given country
@@ -264,17 +264,17 @@  discard block
 block discarded – undo
264 264
  * @return string JSON encoded data
265 265
  */
266 266
 
267
-  public function JSON_listIdentityProviders($country) {
268
-     $idps = Federation::listAllIdentityProviders(1,$country);
269
-     $return_array = [];
270
-     foreach ($idps as $idp) {
267
+    public function JSON_listIdentityProviders($country) {
268
+        $idps = Federation::listAllIdentityProviders(1,$country);
269
+        $return_array = [];
270
+        foreach ($idps as $idp) {
271 271
         if($this->version == 1)
272
-           $return_array[] = ['id'=>$idp['entityID'],'display'=>$idp['title']];
272
+            $return_array[] = ['id'=>$idp['entityID'],'display'=>$idp['title']];
273 273
         else
274
-           $return_array[] = ['idp'=>$idp['entityID'],'display'=>$idp['title']];
275
-     }
276
-     echo $this->return_json($return_array);
277
-  }
274
+            $return_array[] = ['idp'=>$idp['entityID'],'display'=>$idp['title']];
275
+        }
276
+        echo $this->return_json($return_array);
277
+    }
278 278
 
279 279
 /**
280 280
  * return the list of all active IdPs
@@ -283,18 +283,18 @@  discard block
 block discarded – undo
283 283
  * @return string JSON encoded data
284 284
  */
285 285
 
286
-  public function JSON_listIdentityProvidersForDisco() {
287
-     $idps = Federation::listAllIdentityProviders(1);
288
-     $return_array = [];
289
-     foreach ($idps as $idp) {
286
+    public function JSON_listIdentityProvidersForDisco() {
287
+        $idps = Federation::listAllIdentityProviders(1);
288
+        $return_array = [];
289
+        foreach ($idps as $idp) {
290 290
         if($this->version == 1)
291
-           $idp['id'] = $idp['entityID'];
292
-         else
293
-           $idp['idp'] = $idp['entityID'];
291
+            $idp['id'] = $idp['entityID'];
292
+            else
293
+            $idp['idp'] = $idp['entityID'];
294 294
         $return_array[] = $idp;
295
-      }
296
-     echo json_encode($return_array);
297
-  }
295
+        }
296
+        echo json_encode($return_array);
297
+    }
298 298
 
299 299
 
300 300
 
@@ -306,17 +306,17 @@  discard block
 block discarded – undo
306 306
  */
307 307
 
308 308
 
309
-  public function JSON_orderIdentityProviders($country,$L=NULL) {
310
-     $idps = $this->orderIdentityProviders($country,$L);
311
-     $return_array = [];
312
-     foreach ($idps as $idp) {
309
+    public function JSON_orderIdentityProviders($country,$L=NULL) {
310
+        $idps = $this->orderIdentityProviders($country,$L);
311
+        $return_array = [];
312
+        foreach ($idps as $idp) {
313 313
         if($this->version == 1)
314
-           $return_array[] = ['id'=>$idp['id'],'display'=>$idp['title']];
314
+            $return_array[] = ['id'=>$idp['id'],'display'=>$idp['title']];
315 315
         else
316
-           $return_array[] = ['idp'=>$idp['id'],'display'=>$idp['title']];
317
-     }
318
-     echo $this->return_json($return_array);
319
-  }
316
+            $return_array[] = ['idp'=>$idp['id'],'display'=>$idp['title']];
317
+        }
318
+        echo $this->return_json($return_array);
319
+    }
320 320
 
321 321
 /**
322 322
  * Produce a list of profiles available for a given IdP
@@ -324,31 +324,31 @@  discard block
 block discarded – undo
324 324
  * @param int $idp_id the IdP identifier
325 325
  * @return string JSON encoded data
326 326
  */
327
-  public function JSON_listProfiles($idp_id,$sort = 0) {
328
-     $this->set_locale("web_user");
329
-     $return_array = [];
330
-     try {     
331
-         $idp = new IdP($idp_id);
332
-     }
333
-     catch (Exception $fail) {
327
+    public function JSON_listProfiles($idp_id,$sort = 0) {
328
+        $this->set_locale("web_user");
329
+        $return_array = [];
330
+        try {     
331
+            $idp = new IdP($idp_id);
332
+        }
333
+        catch (Exception $fail) {
334 334
         echo $this->return_json($return_array,0);
335 335
         return;
336
-     }
337
-     $l = 0;
338
-     $logo = $idp->getAttributes('general:logo_file');
339
-     if($logo)
340
-       $l = 1;
341
-     $profiles = $idp->listProfiles(1);
342
-     if($sort == 1)
336
+        }
337
+        $l = 0;
338
+        $logo = $idp->getAttributes('general:logo_file');
339
+        if($logo)
340
+        $l = 1;
341
+        $profiles = $idp->listProfiles(1);
342
+        if($sort == 1)
343 343
         usort($profiles,"profile_sort");
344
-     foreach ($profiles as $P) {
345
-       if($this->version == 1)
346
-          $return_array[] = ['id'=>$P->identifier,'display'=>$P->name, 'idp_name'=>$P->inst_name,'logo'=>$l]; 
347
-       else
348
-          $return_array[] = ['profile'=>$P->identifier,'display'=>$P->name, 'idp_name'=>$P->inst_name,'logo'=>$l]; 
349
-     }
350
-     echo $this->return_json($return_array);
351
-  }
344
+        foreach ($profiles as $P) {
345
+        if($this->version == 1)
346
+            $return_array[] = ['id'=>$P->identifier,'display'=>$P->name, 'idp_name'=>$P->inst_name,'logo'=>$l]; 
347
+        else
348
+            $return_array[] = ['profile'=>$P->identifier,'display'=>$P->name, 'idp_name'=>$P->inst_name,'logo'=>$l]; 
349
+        }
350
+        echo $this->return_json($return_array);
351
+    }
352 352
 
353 353
 /**
354 354
  * Return the list of devices available for the given profile
@@ -356,34 +356,34 @@  discard block
 block discarded – undo
356 356
  * @param int $profile_id the Profile identifier
357 357
  * @return string JSON encoded data
358 358
  */
359
-  public function JSON_listDevices($profile_id) {
360
-     $this->set_locale("web_user");
361
-     $return_array = [];
362
-     $a = $this->profileAttributes($profile_id);
363
-     $thedevices = $a['devices'];
364
-     if(!isset($profile_redirect) || ! $profile_redirect) {
365
-         $profile_redirect = 0;
366
-         foreach ($thedevices as $D) {
367
-              if(isset($D['options']) && isset($D['options']['hidden']) &&  $D['options']['hidden'])
368
-                   continue;
369
-              $disp = $D['display'];
370
-              if($this->version == 1) {
371
-                 if($D['id'] === '0') {
372
-                     $profile_redirect = 1;
373
-                     $disp = $c;
374
-                 }
359
+    public function JSON_listDevices($profile_id) {
360
+        $this->set_locale("web_user");
361
+        $return_array = [];
362
+        $a = $this->profileAttributes($profile_id);
363
+        $thedevices = $a['devices'];
364
+        if(!isset($profile_redirect) || ! $profile_redirect) {
365
+            $profile_redirect = 0;
366
+            foreach ($thedevices as $D) {
367
+                if(isset($D['options']) && isset($D['options']['hidden']) &&  $D['options']['hidden'])
368
+                    continue;
369
+                $disp = $D['display'];
370
+                if($this->version == 1) {
371
+                    if($D['id'] === '0') {
372
+                        $profile_redirect = 1;
373
+                        $disp = $c;
374
+                    }
375 375
                 $return_array[] = ['id'=>$D['id'], 'display'=>$disp, 'status'=>$D['status'], 'redirect'=>$D['redirect']];
376
-             } else {
377
-                 if($D['device'] === '0') {
378
-                     $profile_redirect = 1;
379
-                     $disp = $c;
380
-                 }
376
+                } else {
377
+                    if($D['device'] === '0') {
378
+                        $profile_redirect = 1;
379
+                        $disp = $c;
380
+                    }
381 381
                 $return_array[] = ['device'=>$D['id'], 'display'=>$disp, 'status'=>$D['status'], 'redirect'=>$D['redirect']];
382
-             }
383
-         }
382
+                }
383
+            }
384 384
 
385
-  }
386
-  echo $this->return_json($return_array);
385
+    }
386
+    echo $this->return_json($return_array);
387 387
 }
388 388
   
389 389
 /**
@@ -393,7 +393,7 @@  discard block
 block discarded – undo
393 393
  * @param int $prof_id profile identifier
394 394
  * @return string JSON encoded data
395 395
  */
396
-  public function JSON_generateInstaller($device,$prof_id) {
396
+    public function JSON_generateInstaller($device,$prof_id) {
397 397
     debug(4,"JSON::generateInstaller arguments: $device,$prof_id\n");
398 398
     $o = $this->generateInstaller($device,$prof_id);
399 399
     debug(4,"output from GUI::generateInstaller:");
@@ -401,7 +401,7 @@  discard block
 block discarded – undo
401 401
     debug(4,json_encode($o));
402 402
 //    header('Content-type: application/json; utf-8');
403 403
     echo $this->return_json($o);
404
- }
404
+    }
405 405
 
406 406
 /**
407 407
  * Generate and send the installer
@@ -411,14 +411,14 @@  discard block
 block discarded – undo
411 411
  * @return binary installerFile
412 412
  */
413 413
 
414
- public function downloadInstaller($device,$prof_id,$generated_for='user') {
414
+    public function downloadInstaller($device,$prof_id,$generated_for='user') {
415 415
     debug(4,"downloadInstaller arguments: $device,$prof_id,$generated_for\n");
416 416
     $o = $this->generateInstaller($device,$prof_id);
417 417
     debug(4,"output from GUI::generateInstaller:");
418 418
     debug(4,$o);
419 419
     if(! $o['link']) {
420
-       header("HTTP/1.0 404 Not Found");
421
-       return;
420
+        header("HTTP/1.0 404 Not Found");
421
+        return;
422 422
     }
423 423
     $profile = new Profile($prof_id);
424 424
     $profile->incrementDownloadStats($device, $generated_for);
@@ -431,242 +431,242 @@  discard block
 block discarded – undo
431 431
     ob_clean();
432 432
     flush();
433 433
     readfile($file);
434
- }
434
+    }
435 435
 /**
436
- * Get and prepare logo file 
437
- *
438
- * When called for DiscoJuice, first check if file cache exists
439
- * If not then generate the file and save it in the cache
440
- * @param int $idp_id IdP identifier
441
- * @param int $disco flag turning on image generation for DiscoJuice
442
- * @param int $width, $height  maximum width and height of the generated image 
443
- * if one of these is 0 then it is treated as no upper bound
444
- *
445
- */
436
+     * Get and prepare logo file 
437
+     *
438
+     * When called for DiscoJuice, first check if file cache exists
439
+     * If not then generate the file and save it in the cache
440
+     * @param int $idp_id IdP identifier
441
+     * @param int $disco flag turning on image generation for DiscoJuice
442
+     * @param int $width, $height  maximum width and height of the generated image 
443
+     * if one of these is 0 then it is treated as no upper bound
444
+     *
445
+     */
446
+
447
+    public function sendLogo($idp_id, $disco=FALSE, $width=0, $height=0) {
448
+    $ExpStr = '';
449
+    $resize = 0;
450
+    if(($width || $height) && is_numeric($width) && is_numeric($height)) {
451
+        $resize = 1;
452
+        if($height == 0)
453
+            $height = 10000;
454
+        if($width == 0)
455
+            $width = 10000;
456
+        $logo_file = CAT::$root.'/web/downloads/logos/'.$idp_id.'_'.$width.'_'.$height.'.png';
457
+    } elseif($disco == 1) {
458
+        $width = 120;
459
+        $height = 40;
460
+        $resize = 1;
461
+        $logo_file = CAT::$root.'/web/downloads/logos/'.$idp_id.'_'.$width.'_'.$height.'.png';
462
+    }
446 463
 
447
- public function sendLogo($idp_id, $disco=FALSE, $width=0, $height=0) {
448
-   $ExpStr = '';
449
-   $resize = 0;
450
-   if(($width || $height) && is_numeric($width) && is_numeric($height)) {
451
-       $resize = 1;
452
-       if($height == 0)
453
-          $height = 10000;
454
-       if($width == 0)
455
-          $width = 10000;
456
-       $logo_file = CAT::$root.'/web/downloads/logos/'.$idp_id.'_'.$width.'_'.$height.'.png';
457
-   } elseif($disco == 1) {
458
-       $width = 120;
459
-       $height = 40;
460
-       $resize = 1;
461
-       $logo_file = CAT::$root.'/web/downloads/logos/'.$idp_id.'_'.$width.'_'.$height.'.png';
462
-   }
463
-
464
-   if($resize && is_file($logo_file)){
465
-      debug(4,"Using cached logo $logo_file for: $idp_id\n");
466
-      $blob = file_get_contents($logo_file);
467
-      $filetype = 'image/png';
468
-   }
469
-   else {
470
-      $idp = new IdP($idp_id);
471
-      $at = $idp->getAttributes('general:logo_file');
472
-      $blob =  $at[0]['value'];
473
-      $info = new finfo();
474
-      $filetype = $info->buffer($blob, FILEINFO_MIME_TYPE);
475
-      $offset = 60 * 60 * 24 * 30;
476
-      $ExpStr = "Expires: " . gmdate( "D, d M Y H:i:s", time() + $offset ) . " GMT";
477
-      if($resize) {
478
-         $filetype = 'image/png';
479
-         $image = new Imagick();
480
-         $image->readImageBlob($blob);
481
-         if( $image->setImageFormat('PNG')) {
482
-           $image->thumbnailImage($width,$height,1);
483
-           $blob = $image->getImageBlob();
484
-           debug(4,"Writing cached logo $logo_file for: $idp_id\n");
485
-           file_put_contents($logo_file,$blob);
486
-         }
487
-         else
488
-           $blob = "XXXXXX";
489
-      }
490
-   }
491
-   header( "Content-type: ".$filetype );
492
-   header( "Cache-Control:max-age=36000, must-revalidate" );
493
-   header( $ExpStr );
494
-   echo $blob;
495
- }
496
-
497
- public function locateUser() {
498
-   $host = $_SERVER['REMOTE_ADDR'];
499
-   $record = geoip_record_by_name($host);
500
-   if($record) {
501
-     $result = ['status' => 'ok'];
502
-     $result['country'] = $record['country_code'];
464
+    if($resize && is_file($logo_file)){
465
+        debug(4,"Using cached logo $logo_file for: $idp_id\n");
466
+        $blob = file_get_contents($logo_file);
467
+        $filetype = 'image/png';
468
+    }
469
+    else {
470
+        $idp = new IdP($idp_id);
471
+        $at = $idp->getAttributes('general:logo_file');
472
+        $blob =  $at[0]['value'];
473
+        $info = new finfo();
474
+        $filetype = $info->buffer($blob, FILEINFO_MIME_TYPE);
475
+        $offset = 60 * 60 * 24 * 30;
476
+        $ExpStr = "Expires: " . gmdate( "D, d M Y H:i:s", time() + $offset ) . " GMT";
477
+        if($resize) {
478
+            $filetype = 'image/png';
479
+            $image = new Imagick();
480
+            $image->readImageBlob($blob);
481
+            if( $image->setImageFormat('PNG')) {
482
+            $image->thumbnailImage($width,$height,1);
483
+            $blob = $image->getImageBlob();
484
+            debug(4,"Writing cached logo $logo_file for: $idp_id\n");
485
+            file_put_contents($logo_file,$blob);
486
+            }
487
+            else
488
+            $blob = "XXXXXX";
489
+        }
490
+    }
491
+    header( "Content-type: ".$filetype );
492
+    header( "Cache-Control:max-age=36000, must-revalidate" );
493
+    header( $ExpStr );
494
+    echo $blob;
495
+    }
496
+
497
+    public function locateUser() {
498
+    $host = $_SERVER['REMOTE_ADDR'];
499
+    $record = geoip_record_by_name($host);
500
+    if($record) {
501
+        $result = ['status' => 'ok'];
502
+        $result['country'] = $record['country_code'];
503 503
 //  the two lines below are a dirty hack to take of the error in naming the UK federation
504
-     if($result['country'] == 'GB')
505
-         $result['country'] = 'UK';
506
-     $result['region'] = $record['region'];
507
-     $result['geo'] = ['lat' => (float)$record['latitude'] , 'lon' => (float)$record['longitude']];
508
-   } else {
509
-     $result = ['status' => 'error', 'error' =>'Problem listing countries']; 
510
-   }
511
-   return($result);
512
- }
513
-
514
-
515
- public function locateUser2() {
516
-   require_once Config::$GEOIP['geoip2-path-to-autoloader'];
517
-   $reader = new Reader(Config::$GEOIP['geoip2-path-to-db']);
518
-   $host = $_SERVER['REMOTE_ADDR'];
519
-   try {
520
-      $record = $reader->city($host);
521
-   } catch (Exception $e) {
522
-      $result = ['status' => 'error', 'error' =>'Problem listing countries']; 
523
-      return($result);
524
-   }
525
-   $result = ['status' => 'ok'];
526
-   $result['country'] = $record->country->isoCode;
504
+        if($result['country'] == 'GB')
505
+            $result['country'] = 'UK';
506
+        $result['region'] = $record['region'];
507
+        $result['geo'] = ['lat' => (float)$record['latitude'] , 'lon' => (float)$record['longitude']];
508
+    } else {
509
+        $result = ['status' => 'error', 'error' =>'Problem listing countries']; 
510
+    }
511
+    return($result);
512
+    }
513
+
514
+
515
+    public function locateUser2() {
516
+    require_once Config::$GEOIP['geoip2-path-to-autoloader'];
517
+    $reader = new Reader(Config::$GEOIP['geoip2-path-to-db']);
518
+    $host = $_SERVER['REMOTE_ADDR'];
519
+    try {
520
+        $record = $reader->city($host);
521
+    } catch (Exception $e) {
522
+        $result = ['status' => 'error', 'error' =>'Problem listing countries']; 
523
+        return($result);
524
+    }
525
+    $result = ['status' => 'ok'];
526
+    $result['country'] = $record->country->isoCode;
527 527
 //  the two lines below are a dirty hack to take of the error in naming the UK federation
528
-   if($result['country'] == 'GB')
529
-       $result['country'] = 'UK';
530
-   $result['region'] = $record->continent->name;
528
+    if($result['country'] == 'GB')
529
+        $result['country'] = 'UK';
530
+    $result['region'] = $record->continent->name;
531 531
 
532
-   $result['geo'] = ['lat' => (float)$record->location->latitude , 'lon' => (float)$record->location->longitude];
533
-   return($result);
534
- }
532
+    $result['geo'] = ['lat' => (float)$record->location->latitude , 'lon' => (float)$record->location->longitude];
533
+    return($result);
534
+    }
535 535
 
536 536
 public function JSON_locateUser() {
537 537
     header('Content-type: application/json; utf-8');
538 538
    
539 539
     if(empty(Config::$GEOIP['version']) || Config::$GEOIP['version'] == 0)
540
-      echo json_encode(['status' => 'error', 'error' =>'Geolocation not supported']);
540
+        echo json_encode(['status' => 'error', 'error' =>'Geolocation not supported']);
541 541
     if(Config::$GEOIP['version'] == 1)
542
-      echo json_encode($this->locateUser());
542
+        echo json_encode($this->locateUser());
543 543
     if(Config::$GEOIP['version'] == 2)
544
-      echo json_encode($this->locateUser2());
544
+        echo json_encode($this->locateUser2());
545 545
 }
546 546
 
547 547
 /**
548 548
  * Produce support data prepared within {@link GUI::profileAttributes()}
549 549
  * @return string JSON encoded data
550 550
  */
551
-  public function JSON_profileAttributes($prof_id) {
551
+    public function JSON_profileAttributes($prof_id) {
552 552
 //    header('Content-type: application/json; utf-8');
553 553
     echo $this->return_json($this->profileAttributes($prof_id));
554
-  }
554
+    }
555 555
 
556 556
 /**
557
-  * Calculate the distence in km between two points given their
558
-  * geo coordinates.
559
-  * @param array $P1 - first point as an 'lat', 'lon' array 
560
-  * @param array $P2 - second point as an 'lat', 'lon' array 
561
-  * @return float distance in km
562
-  */
557
+ * Calculate the distence in km between two points given their
558
+ * geo coordinates.
559
+ * @param array $P1 - first point as an 'lat', 'lon' array 
560
+ * @param array $P2 - second point as an 'lat', 'lon' array 
561
+ * @return float distance in km
562
+ */
563 563
 private function geoDistance($P1,$P2) {
564 564
 
565
-  $dist = sin(deg2rad($P1['lat'])) * sin(deg2rad($P2['lat'])) +  
565
+    $dist = sin(deg2rad($P1['lat'])) * sin(deg2rad($P2['lat'])) +  
566 566
          cos(deg2rad($P1['lat'])) * cos(deg2rad($P2['lat'])) * cos(deg2rad($P1['lon'] - $P2['lon']));
567
-  $dist = rad2deg(acos($dist)) * 60 * 1.1852 ;
568
-  return(round($dist));
567
+    $dist = rad2deg(acos($dist)) * 60 * 1.1852 ;
568
+    return(round($dist));
569 569
 }
570 570
 
571 571
 /**
572
-  * Order active identity providers according to their distance and name
573
-  * @param array $L - current location
574
-  * @return array $IdPs -  list of arrays ('id', 'name');
575
-  */
572
+ * Order active identity providers according to their distance and name
573
+ * @param array $L - current location
574
+ * @return array $IdPs -  list of arrays ('id', 'name');
575
+ */
576 576
 
577 577
 public function orderIdentityProviders($country,$L=NULL) {
578
-     $idps = Federation::listAllIdentityProviders(1,$country);
579
-
580
-  if(is_null($L)) {
581
-     $U = $this->locateUser();
582
-     if($U['status'] == 'ok') {
583
-     $L = $U['geo'];
584
-     } else {
585
-       $L = ['lat'=>"90",'lon'=>"0"];
586
-     }
587
-  }
588
-  $T=[];
589
-  $R=[];
590
-     foreach ($idps as $idp) {
578
+        $idps = Federation::listAllIdentityProviders(1,$country);
579
+
580
+    if(is_null($L)) {
581
+        $U = $this->locateUser();
582
+        if($U['status'] == 'ok') {
583
+        $L = $U['geo'];
584
+        } else {
585
+        $L = ['lat'=>"90",'lon'=>"0"];
586
+        }
587
+    }
588
+    $T=[];
589
+    $R=[];
590
+        foreach ($idps as $idp) {
591 591
         $T[$idp['entityID']] = $idp['title'];
592 592
         $dist = 10000;
593 593
         if(isset($idp['geo'])) {
594
-          $G=$idp['geo'];
595
-          if(isset($G['lon'])) {
596
-             $d1 = $this->geoDistance($L,$G); 
597
-             if( $d1 < $dist)
594
+            $G=$idp['geo'];
595
+            if(isset($G['lon'])) {
596
+                $d1 = $this->geoDistance($L,$G); 
597
+                if( $d1 < $dist)
598 598
                 $dist = $d1;
599
-          } else {
599
+            } else {
600 600
             foreach ($G as $g) {
601
-             $d1 = $this->geoDistance($L,$g); 
602
-             if( $d1 < $dist)
601
+                $d1 = $this->geoDistance($L,$g); 
602
+                if( $d1 < $dist)
603 603
                 $dist = $d1;
604 604
             }
605
-          }
605
+            }
606 606
         }
607
-       if($dist > 100)
608
-         $dist=10000;
609
-      $d = sprintf("%06d",$dist);
610
-      $R[$idp['entityID']] = $d." ".$idp['title'];
611
-     }
612
-     asort($R);
613
-     foreach (array_keys($R) as $r) {
614
-      if($this->version == 1)
615
-         $outarray[] = ['id'=>$r, 'title'=>$T[$r]];
616
-      else
617
-         $outarray[] = ['idp'=>$r, 'title'=>$T[$r]];
618
-      }
619
-     return($outarray);
607
+        if($dist > 100)
608
+            $dist=10000;
609
+        $d = sprintf("%06d",$dist);
610
+        $R[$idp['entityID']] = $d." ".$idp['title'];
611
+        }
612
+        asort($R);
613
+        foreach (array_keys($R) as $r) {
614
+        if($this->version == 1)
615
+            $outarray[] = ['id'=>$r, 'title'=>$T[$r]];
616
+        else
617
+            $outarray[] = ['idp'=>$r, 'title'=>$T[$r]];
618
+        }
619
+        return($outarray);
620 620
 }
621 621
 
622 622
 /**
623
-  * Detect the best device driver form the browser
624
-  *
625
-  * Detects the operating system and returns its id 
626
-  * display name and group membership (as in devices.php)
627
-  * @return array indexed by 'id', 'display', 'group'
628
-  */
623
+ * Detect the best device driver form the browser
624
+ *
625
+ * Detects the operating system and returns its id 
626
+ * display name and group membership (as in devices.php)
627
+ * @return array indexed by 'id', 'display', 'group'
628
+ */
629 629
 
630 630
 public function detectOS() {
631
-   $Dev = Devices::listDevices();
632
-   if( isset($_REQUEST['device']) && isset($Dev[$_REQUEST['device']]) && (!isset($device['options']['hidden']) || $device['options']['hidden'] == 0)) {
633
-      $dev_id = $_REQUEST['device'];
634
-      $device = $Dev[$dev_id];
635
-      if($this->version == 1)
636
-         return(['id'=>$dev_id,'display'=>$device['display'], 'group'=>$device['group']]);
637
-      else
638
-         return(['device'=>$dev_id,'display'=>$device['display'], 'group'=>$device['group']]);
639
-   }
640
-   $browser = $_SERVER['HTTP_USER_AGENT'];
641
-   debug(4,"HTTP_USER_AGENT=$browser\n");
642
-   foreach ($Dev as $dev_id => $device) {
643
-     if(!isset($device['match']))
631
+    $Dev = Devices::listDevices();
632
+    if( isset($_REQUEST['device']) && isset($Dev[$_REQUEST['device']]) && (!isset($device['options']['hidden']) || $device['options']['hidden'] == 0)) {
633
+        $dev_id = $_REQUEST['device'];
634
+        $device = $Dev[$dev_id];
635
+        if($this->version == 1)
636
+            return(['id'=>$dev_id,'display'=>$device['display'], 'group'=>$device['group']]);
637
+        else
638
+            return(['device'=>$dev_id,'display'=>$device['display'], 'group'=>$device['group']]);
639
+    }
640
+    $browser = $_SERVER['HTTP_USER_AGENT'];
641
+    debug(4,"HTTP_USER_AGENT=$browser\n");
642
+    foreach ($Dev as $dev_id => $device) {
643
+        if(!isset($device['match']))
644 644
         continue;
645
-     if(preg_match('/'.$device['match'].'/',$browser)) {
646
-       if(!isset($device['options']['hidden']) || $device['options']['hidden'] == 0) {
647
-          debug(4,"Browser_id: $dev_id\n");
648
-          if($this->version == 1)
649
-             return(['id'=>$dev_id,'display'=>$device['display'], 'group'=>$device['group']]);
650
-          else
651
-             return(['device'=>$dev_id,'display'=>$device['display'], 'group'=>$device['group']]);
652
-       }
653
-       else {
654
-         debug(2, "Unrecognised system: ".$_SERVER['HTTP_USER_AGENT']."\n");
655
-         return(false);
656
-       }
657
-     }
658
-   }
659
-   debug(2, "Unrecognised system: ".$_SERVER['HTTP_USER_AGENT']."\n");
660
-   return(false);
645
+        if(preg_match('/'.$device['match'].'/',$browser)) {
646
+        if(!isset($device['options']['hidden']) || $device['options']['hidden'] == 0) {
647
+            debug(4,"Browser_id: $dev_id\n");
648
+            if($this->version == 1)
649
+                return(['id'=>$dev_id,'display'=>$device['display'], 'group'=>$device['group']]);
650
+            else
651
+                return(['device'=>$dev_id,'display'=>$device['display'], 'group'=>$device['group']]);
652
+        }
653
+        else {
654
+            debug(2, "Unrecognised system: ".$_SERVER['HTTP_USER_AGENT']."\n");
655
+            return(false);
656
+        }
657
+        }
658
+    }
659
+    debug(2, "Unrecognised system: ".$_SERVER['HTTP_USER_AGENT']."\n");
660
+    return(false);
661 661
 }
662 662
 
663 663
 public function JSON_detectOS() {
664
-     $return_array=$this->detectOS();
665
-     if($return_array)
664
+        $return_array=$this->detectOS();
665
+        if($return_array)
666 666
         $status = 1;
667
-     else
667
+        else
668 668
         $status = 0;
669
-     echo $this->return_json($return_array,$status);
669
+        echo $this->return_json($return_array,$status);
670 670
 }
671 671
 
672 672
 
@@ -676,5 +676,5 @@  discard block
 block discarded – undo
676 676
   
677 677
 }
678 678
 function profile_sort($P1,$P2) {
679
-   return strcasecmp($P1->name, $P2->name);
679
+    return strcasecmp($P1->name, $P2->name);
680 680
 } 
681 681
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +150 added lines, -150 removed lines patch added patch discarded remove patch
@@ -52,21 +52,21 @@  discard block
 block discarded – undo
52 52
  *  link - the path name of the resulting installer
53 53
  *  mime - the mimetype of the installer
54 54
  */
55
-  public function generateInstaller($device,$prof_id, $generated_for = "user") {
55
+  public function generateInstaller($device, $prof_id, $generated_for = "user") {
56 56
     $this->set_locale("devices");
57 57
     $Dev = Devices::listDevices();
58 58
     $Config = $Dev[$device];
59
-    debug(4,"installer:$device:$prof_id\n");
59
+    debug(4, "installer:$device:$prof_id\n");
60 60
     $profile = new Profile($prof_id);
61 61
     $attribs = $profile->getCollapsedAttributes();
62 62
     // test if the profile is production-ready and if not if the authenticated user is an owner
63 63
     if (!isset($attribs['profile:production']) || (isset($attribs['profile:production']) && $attribs['profile:production'][0] != "on")) {
64
-       debug(4,"Attempt to download a non-production ready installer fir profile: $prof_id\n");
64
+       debug(4, "Attempt to download a non-production ready installer fir profile: $prof_id\n");
65 65
        require_once(Config::$AUTHENTICATION['ssp-path-to-autoloader']);
66 66
        $as = new SimpleSAML_Auth_Simple(Config::$AUTHENTICATION['ssp-authsource']);
67
-       if($as->isAuthenticated()) {
67
+       if ($as->isAuthenticated()) {
68 68
           $user_object = new User($_SESSION['user']);
69
-          if($user_object->isIdPOwner($profile->institution)) {
69
+          if ($user_object->isIdPOwner($profile->institution)) {
70 70
               debug(4, "User is the owner - allowing access\n");
71 71
           } else {
72 72
              debug(2, "User not an owner of a non-production profile - access forbidden\n");
@@ -82,38 +82,38 @@  discard block
 block discarded – undo
82 82
     $a = [];
83 83
     $a['profile'] = $prof_id;
84 84
     $a['device'] = $device;
85
-    if( (isset(Devices::$Options['no_cache']) && Devices::$Options['no_cache'] ) || ( isset($Config['options']['no_cache']) && $Config['options']['no_cache'] ))
85
+    if ((isset(Devices::$Options['no_cache']) && Devices::$Options['no_cache']) || (isset($Config['options']['no_cache']) && $Config['options']['no_cache']))
86 86
       $this->i_path = FALSE;
87 87
     else {
88 88
       $cache = $profile->testCache($device);
89 89
       $this->i_path = $cache['cache'];
90 90
     }
91
-    if($this->i_path && is_file($this->i_path)) { 
92
-      debug(4,"Using cached installer for: $device\n");
93
-      $a['link'] = "API.php?api_version=$version&action=downloadInstaller&lang=".CAT::get_lang()."&profile=$prof_id&device=$device&generatedfor=$generated_for";
91
+    if ($this->i_path && is_file($this->i_path)) { 
92
+      debug(4, "Using cached installer for: $device\n");
93
+      $a['link'] = "API.php?api_version=$version&action=downloadInstaller&lang=" . CAT::get_lang() . "&profile=$prof_id&device=$device&generatedfor=$generated_for";
94 94
       $a['mime'] = $cache['mime'];
95 95
     } else {
96 96
       $factory = new DeviceFactory($device);
97 97
       $dev = $factory->device;
98
-      if(isset($dev)) {
98
+      if (isset($dev)) {
99 99
          $dev->setup($profile);
100 100
          $installer = $dev->writeInstaller();
101
-         $i_path = $dev->FPATH.'/tmp/'.$installer;
102
-         if($i_path && is_file($i_path)) {
103
-         if(isset($dev->options['mime']))
101
+         $i_path = $dev->FPATH . '/tmp/' . $installer;
102
+         if ($i_path && is_file($i_path)) {
103
+         if (isset($dev->options['mime']))
104 104
                $a['mime'] = $dev->options['mime'];
105 105
          else {
106 106
            $info = new finfo();
107 107
            $a['mime'] = $info->file($i_path, FILEINFO_MIME_TYPE);
108 108
          }
109
-         $this->i_path = $dev->FPATH.'/'.$installer;
109
+         $this->i_path = $dev->FPATH . '/' . $installer;
110 110
          rename($i_path, $this->i_path);
111
-         $profile->updateCache($device,$this->i_path,$a['mime']);
111
+         $profile->updateCache($device, $this->i_path, $a['mime']);
112 112
 //         rrmdir($dev->FPATH.'/tmp');
113
-         debug(4,"Generated installer: ".$this->i_path.": for: $device\n");
114
-         $a['link'] = "API.php?api_version=$version&action=downloadInstaller&lang=".CAT::get_lang()."&profile=$prof_id&device=$device&generatedfor=$generated_for";
113
+         debug(4, "Generated installer: " . $this->i_path . ": for: $device\n");
114
+         $a['link'] = "API.php?api_version=$version&action=downloadInstaller&lang=" . CAT::get_lang() . "&profile=$prof_id&device=$device&generatedfor=$generated_for";
115 115
          } else {
116
-         debug(2,"Installer generation failed for: $prof_id:$device:".CAT::get_lang()."\n");
116
+         debug(2, "Installer generation failed for: $prof_id:$device:" . CAT::get_lang() . "\n");
117 117
          $a['link'] = 0;
118 118
          }
119 119
       } 
@@ -129,31 +129,31 @@  discard block
 block discarded – undo
129 129
     $Dev = Devices::listDevices();
130 130
     $R = [];
131 131
     $ct = 0;
132
-    if($show_hidden !== 0 && $show_hidden != 1)
132
+    if ($show_hidden !== 0 && $show_hidden != 1)
133 133
       return;
134 134
     foreach ($Dev as $device => $D) {
135
-      if(isset($D['options']['hidden']) && $D['options']['hidden'] && $show_hidden == 0)
135
+      if (isset($D['options']['hidden']) && $D['options']['hidden'] && $show_hidden == 0)
136 136
          continue;
137
-      $ct ++;
138
-      if($this->version == 1)
137
+      $ct++;
138
+      if ($this->version == 1)
139 139
          $D['device'] = $device;
140 140
       else
141 141
          $D['device'] = $device;
142 142
       $group = isset($D['group']) ? $D['group'] : 'other';
143
-      if (! isset($R[$group]))
143
+      if (!isset($R[$group]))
144 144
          $R[$group] = [];
145 145
       $R[$group][$device] = $D;
146 146
     }
147 147
    return $R;
148 148
  }
149 149
 
150
- public function deviceInfo($device,$prof_id) {
150
+ public function deviceInfo($device, $prof_id) {
151 151
     $this->set_locale("devices");
152 152
     $out = 0;
153 153
     $profile = new Profile($prof_id);
154 154
     $factory = new DeviceFactory($device);
155 155
     $dev = $factory->device;
156
-    if(isset($dev)) {
156
+    if (isset($dev)) {
157 157
 //       $dev->setup($profile);
158 158
        $out = $dev->writeDeviceInfo();
159 159
    }
@@ -178,13 +178,13 @@  discard block
 block discarded – undo
178 178
       $profile = new Profile($prof_id);
179 179
       $attr = $profile->getCollapsedAttributes();
180 180
       $a = [];
181
-      if(isset($attr['support:email']))
181
+      if (isset($attr['support:email']))
182 182
          $a['local_email'] = $attr['support:email'][0];
183
-      if(isset($attr['support:phone']))
183
+      if (isset($attr['support:phone']))
184 184
          $a['local_phone'] = $attr['support:phone'][0];
185
-      if(isset($attr['support:url']))
185
+      if (isset($attr['support:url']))
186 186
          $a['local_url'] = $attr['support:url'][0];
187
-      if(isset($attr['profile:description']))
187
+      if (isset($attr['profile:description']))
188 188
          $a['description'] = $attr['profile:description'][0];
189 189
       $a['devices'] = $profile->listDevices();
190 190
       $this->set_locale("web_user");
@@ -196,30 +196,30 @@  discard block
 block discarded – undo
196 196
    cicumstances
197 197
 */
198 198
 private function GetRootURL() {
199
-    $backtrace =  debug_backtrace();
199
+    $backtrace = debug_backtrace();
200 200
     $F = array_pop($backtrace);
201
-    $file= $F['file'];
202
-    $file = substr($file,strlen(dirname(__DIR__)));
203
-    while(substr($file,0,1) == '/')
204
-       $file = substr($file,1);
205
-    $n = count(explode('/',$file));
201
+    $file = $F['file'];
202
+    $file = substr($file, strlen(dirname(__DIR__)));
203
+    while (substr($file, 0, 1) == '/')
204
+       $file = substr($file, 1);
205
+    $n = count(explode('/', $file));
206 206
     $out = $_SERVER['SCRIPT_NAME'];
207
-    for ($i= 0; $i < $n; $i++)
207
+    for ($i = 0; $i < $n; $i++)
208 208
       $out = dirname($out);
209 209
     if ($out == '/')
210 210
       $out = '';
211 211
     $s = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] ? 'https' : 'http';
212
-    $s .= '://'.$_SERVER['HTTP_HOST'] . $out;
212
+    $s .= '://' . $_SERVER['HTTP_HOST'] . $out;
213 213
     return $s;
214 214
 }
215 215
 
216 216
 /* JSON functions */
217 217
 
218
-  public function return_json($data,$status=1) {
218
+  public function return_json($data, $status = 1) {
219 219
      $return_array = [];
220 220
      $return_array['status'] = $status;
221 221
      $return_array['data'] = $data;
222
-     $return_array['tou'] =  "Please consult Terms of Use at: ".$this->GetRootURL()."/tou.php";
222
+     $return_array['tou'] = "Please consult Terms of Use at: " . $this->GetRootURL() . "/tou.php";
223 223
      return(json_encode($return_array));
224 224
   }
225 225
 
@@ -230,11 +230,11 @@  discard block
 block discarded – undo
230 230
   */
231 231
   public function JSON_listLanguages() {
232 232
      $return_array = [];
233
-     foreach(Config::$LANGUAGES as $id => $val){
234
-       if($this->version == 1)
235
-          $return_array[] = ['id'=>$id,'display'=>$val['display'],'locale'=>$val['locale']];
233
+     foreach (Config::$LANGUAGES as $id => $val) {
234
+       if ($this->version == 1)
235
+          $return_array[] = ['id'=>$id, 'display'=>$val['display'], 'locale'=>$val['locale']];
236 236
        else
237
-          $return_array[] = ['lang'=>$id,'display'=>$val['display'],'locale'=>$val['locale']];
237
+          $return_array[] = ['lang'=>$id, 'display'=>$val['display'], 'locale'=>$val['locale']];
238 238
      }
239 239
      echo $this->return_json($return_array);
240 240
   }
@@ -249,10 +249,10 @@  discard block
 block discarded – undo
249 249
      $FED = $this->printCountryList(1);
250 250
      $return_array = [];
251 251
      foreach ($FED as $id => $val) {
252
-       if($this->version == 1)
253
-          $return_array[] = ['id'=>$id,'display'=>$val];
252
+       if ($this->version == 1)
253
+          $return_array[] = ['id'=>$id, 'display'=>$val];
254 254
        else
255
-          $return_array[] = ['federation'=>$id,'display'=>$val];
255
+          $return_array[] = ['federation'=>$id, 'display'=>$val];
256 256
      }
257 257
      echo $this->return_json($return_array);
258 258
   }
@@ -265,13 +265,13 @@  discard block
 block discarded – undo
265 265
  */
266 266
 
267 267
   public function JSON_listIdentityProviders($country) {
268
-     $idps = Federation::listAllIdentityProviders(1,$country);
268
+     $idps = Federation::listAllIdentityProviders(1, $country);
269 269
      $return_array = [];
270 270
      foreach ($idps as $idp) {
271
-        if($this->version == 1)
272
-           $return_array[] = ['id'=>$idp['entityID'],'display'=>$idp['title']];
271
+        if ($this->version == 1)
272
+           $return_array[] = ['id'=>$idp['entityID'], 'display'=>$idp['title']];
273 273
         else
274
-           $return_array[] = ['idp'=>$idp['entityID'],'display'=>$idp['title']];
274
+           $return_array[] = ['idp'=>$idp['entityID'], 'display'=>$idp['title']];
275 275
      }
276 276
      echo $this->return_json($return_array);
277 277
   }
@@ -287,7 +287,7 @@  discard block
 block discarded – undo
287 287
      $idps = Federation::listAllIdentityProviders(1);
288 288
      $return_array = [];
289 289
      foreach ($idps as $idp) {
290
-        if($this->version == 1)
290
+        if ($this->version == 1)
291 291
            $idp['id'] = $idp['entityID'];
292 292
          else
293 293
            $idp['idp'] = $idp['entityID'];
@@ -306,14 +306,14 @@  discard block
 block discarded – undo
306 306
  */
307 307
 
308 308
 
309
-  public function JSON_orderIdentityProviders($country,$L=NULL) {
310
-     $idps = $this->orderIdentityProviders($country,$L);
309
+  public function JSON_orderIdentityProviders($country, $L = NULL) {
310
+     $idps = $this->orderIdentityProviders($country, $L);
311 311
      $return_array = [];
312 312
      foreach ($idps as $idp) {
313
-        if($this->version == 1)
314
-           $return_array[] = ['id'=>$idp['id'],'display'=>$idp['title']];
313
+        if ($this->version == 1)
314
+           $return_array[] = ['id'=>$idp['id'], 'display'=>$idp['title']];
315 315
         else
316
-           $return_array[] = ['idp'=>$idp['id'],'display'=>$idp['title']];
316
+           $return_array[] = ['idp'=>$idp['id'], 'display'=>$idp['title']];
317 317
      }
318 318
      echo $this->return_json($return_array);
319 319
   }
@@ -324,28 +324,28 @@  discard block
 block discarded – undo
324 324
  * @param int $idp_id the IdP identifier
325 325
  * @return string JSON encoded data
326 326
  */
327
-  public function JSON_listProfiles($idp_id,$sort = 0) {
327
+  public function JSON_listProfiles($idp_id, $sort = 0) {
328 328
      $this->set_locale("web_user");
329 329
      $return_array = [];
330 330
      try {     
331 331
          $idp = new IdP($idp_id);
332 332
      }
333 333
      catch (Exception $fail) {
334
-        echo $this->return_json($return_array,0);
334
+        echo $this->return_json($return_array, 0);
335 335
         return;
336 336
      }
337 337
      $l = 0;
338 338
      $logo = $idp->getAttributes('general:logo_file');
339
-     if($logo)
339
+     if ($logo)
340 340
        $l = 1;
341 341
      $profiles = $idp->listProfiles(1);
342
-     if($sort == 1)
343
-        usort($profiles,"profile_sort");
342
+     if ($sort == 1)
343
+        usort($profiles, "profile_sort");
344 344
      foreach ($profiles as $P) {
345
-       if($this->version == 1)
346
-          $return_array[] = ['id'=>$P->identifier,'display'=>$P->name, 'idp_name'=>$P->inst_name,'logo'=>$l]; 
345
+       if ($this->version == 1)
346
+          $return_array[] = ['id'=>$P->identifier, 'display'=>$P->name, 'idp_name'=>$P->inst_name, 'logo'=>$l]; 
347 347
        else
348
-          $return_array[] = ['profile'=>$P->identifier,'display'=>$P->name, 'idp_name'=>$P->inst_name,'logo'=>$l]; 
348
+          $return_array[] = ['profile'=>$P->identifier, 'display'=>$P->name, 'idp_name'=>$P->inst_name, 'logo'=>$l]; 
349 349
      }
350 350
      echo $this->return_json($return_array);
351 351
   }
@@ -361,20 +361,20 @@  discard block
 block discarded – undo
361 361
      $return_array = [];
362 362
      $a = $this->profileAttributes($profile_id);
363 363
      $thedevices = $a['devices'];
364
-     if(!isset($profile_redirect) || ! $profile_redirect) {
364
+     if (!isset($profile_redirect) || !$profile_redirect) {
365 365
          $profile_redirect = 0;
366 366
          foreach ($thedevices as $D) {
367
-              if(isset($D['options']) && isset($D['options']['hidden']) &&  $D['options']['hidden'])
367
+              if (isset($D['options']) && isset($D['options']['hidden']) && $D['options']['hidden'])
368 368
                    continue;
369 369
               $disp = $D['display'];
370
-              if($this->version == 1) {
371
-                 if($D['id'] === '0') {
370
+              if ($this->version == 1) {
371
+                 if ($D['id'] === '0') {
372 372
                      $profile_redirect = 1;
373 373
                      $disp = $c;
374 374
                  }
375 375
                 $return_array[] = ['id'=>$D['id'], 'display'=>$disp, 'status'=>$D['status'], 'redirect'=>$D['redirect']];
376 376
              } else {
377
-                 if($D['device'] === '0') {
377
+                 if ($D['device'] === '0') {
378 378
                      $profile_redirect = 1;
379 379
                      $disp = $c;
380 380
                  }
@@ -393,12 +393,12 @@  discard block
 block discarded – undo
393 393
  * @param int $prof_id profile identifier
394 394
  * @return string JSON encoded data
395 395
  */
396
-  public function JSON_generateInstaller($device,$prof_id) {
397
-    debug(4,"JSON::generateInstaller arguments: $device,$prof_id\n");
398
-    $o = $this->generateInstaller($device,$prof_id);
399
-    debug(4,"output from GUI::generateInstaller:");
400
-    debug(4,$o);
401
-    debug(4,json_encode($o));
396
+  public function JSON_generateInstaller($device, $prof_id) {
397
+    debug(4, "JSON::generateInstaller arguments: $device,$prof_id\n");
398
+    $o = $this->generateInstaller($device, $prof_id);
399
+    debug(4, "output from GUI::generateInstaller:");
400
+    debug(4, $o);
401
+    debug(4, json_encode($o));
402 402
 //    header('Content-type: application/json; utf-8');
403 403
     echo $this->return_json($o);
404 404
  }
@@ -411,12 +411,12 @@  discard block
 block discarded – undo
411 411
  * @return binary installerFile
412 412
  */
413 413
 
414
- public function downloadInstaller($device,$prof_id,$generated_for='user') {
415
-    debug(4,"downloadInstaller arguments: $device,$prof_id,$generated_for\n");
416
-    $o = $this->generateInstaller($device,$prof_id);
417
-    debug(4,"output from GUI::generateInstaller:");
418
-    debug(4,$o);
419
-    if(! $o['link']) {
414
+ public function downloadInstaller($device, $prof_id, $generated_for = 'user') {
415
+    debug(4, "downloadInstaller arguments: $device,$prof_id,$generated_for\n");
416
+    $o = $this->generateInstaller($device, $prof_id);
417
+    debug(4, "output from GUI::generateInstaller:");
418
+    debug(4, $o);
419
+    if (!$o['link']) {
420 420
        header("HTTP/1.0 404 Not Found");
421 421
        return;
422 422
     }
@@ -424,9 +424,9 @@  discard block
 block discarded – undo
424 424
     $profile->incrementDownloadStats($device, $generated_for);
425 425
     $file = $this->i_path;
426 426
     $filetype = $o['mime'];
427
-    debug(4,"installer MIME type:$filetype\n");
428
-    header("Content-type: ".$filetype);
429
-    header('Content-Disposition: inline; filename="'.basename($file).'"');
427
+    debug(4, "installer MIME type:$filetype\n");
428
+    header("Content-type: " . $filetype);
429
+    header('Content-Disposition: inline; filename="' . basename($file) . '"');
430 430
     header('Content-Length: ' . filesize($file));
431 431
     ob_clean();
432 432
     flush();
@@ -444,67 +444,67 @@  discard block
 block discarded – undo
444 444
  *
445 445
  */
446 446
 
447
- public function sendLogo($idp_id, $disco=FALSE, $width=0, $height=0) {
447
+ public function sendLogo($idp_id, $disco = FALSE, $width = 0, $height = 0) {
448 448
    $ExpStr = '';
449 449
    $resize = 0;
450
-   if(($width || $height) && is_numeric($width) && is_numeric($height)) {
450
+   if (($width || $height) && is_numeric($width) && is_numeric($height)) {
451 451
        $resize = 1;
452
-       if($height == 0)
452
+       if ($height == 0)
453 453
           $height = 10000;
454
-       if($width == 0)
454
+       if ($width == 0)
455 455
           $width = 10000;
456
-       $logo_file = CAT::$root.'/web/downloads/logos/'.$idp_id.'_'.$width.'_'.$height.'.png';
457
-   } elseif($disco == 1) {
456
+       $logo_file = CAT::$root . '/web/downloads/logos/' . $idp_id . '_' . $width . '_' . $height . '.png';
457
+   } elseif ($disco == 1) {
458 458
        $width = 120;
459 459
        $height = 40;
460 460
        $resize = 1;
461
-       $logo_file = CAT::$root.'/web/downloads/logos/'.$idp_id.'_'.$width.'_'.$height.'.png';
461
+       $logo_file = CAT::$root . '/web/downloads/logos/' . $idp_id . '_' . $width . '_' . $height . '.png';
462 462
    }
463 463
 
464
-   if($resize && is_file($logo_file)){
465
-      debug(4,"Using cached logo $logo_file for: $idp_id\n");
464
+   if ($resize && is_file($logo_file)) {
465
+      debug(4, "Using cached logo $logo_file for: $idp_id\n");
466 466
       $blob = file_get_contents($logo_file);
467 467
       $filetype = 'image/png';
468 468
    }
469 469
    else {
470 470
       $idp = new IdP($idp_id);
471 471
       $at = $idp->getAttributes('general:logo_file');
472
-      $blob =  $at[0]['value'];
472
+      $blob = $at[0]['value'];
473 473
       $info = new finfo();
474 474
       $filetype = $info->buffer($blob, FILEINFO_MIME_TYPE);
475 475
       $offset = 60 * 60 * 24 * 30;
476
-      $ExpStr = "Expires: " . gmdate( "D, d M Y H:i:s", time() + $offset ) . " GMT";
477
-      if($resize) {
476
+      $ExpStr = "Expires: " . gmdate("D, d M Y H:i:s", time() + $offset) . " GMT";
477
+      if ($resize) {
478 478
          $filetype = 'image/png';
479 479
          $image = new Imagick();
480 480
          $image->readImageBlob($blob);
481
-         if( $image->setImageFormat('PNG')) {
482
-           $image->thumbnailImage($width,$height,1);
481
+         if ($image->setImageFormat('PNG')) {
482
+           $image->thumbnailImage($width, $height, 1);
483 483
            $blob = $image->getImageBlob();
484
-           debug(4,"Writing cached logo $logo_file for: $idp_id\n");
485
-           file_put_contents($logo_file,$blob);
484
+           debug(4, "Writing cached logo $logo_file for: $idp_id\n");
485
+           file_put_contents($logo_file, $blob);
486 486
          }
487 487
          else
488 488
            $blob = "XXXXXX";
489 489
       }
490 490
    }
491
-   header( "Content-type: ".$filetype );
492
-   header( "Cache-Control:max-age=36000, must-revalidate" );
493
-   header( $ExpStr );
491
+   header("Content-type: " . $filetype);
492
+   header("Cache-Control:max-age=36000, must-revalidate");
493
+   header($ExpStr);
494 494
    echo $blob;
495 495
  }
496 496
 
497 497
  public function locateUser() {
498 498
    $host = $_SERVER['REMOTE_ADDR'];
499 499
    $record = geoip_record_by_name($host);
500
-   if($record) {
500
+   if ($record) {
501 501
      $result = ['status' => 'ok'];
502 502
      $result['country'] = $record['country_code'];
503 503
 //  the two lines below are a dirty hack to take of the error in naming the UK federation
504
-     if($result['country'] == 'GB')
504
+     if ($result['country'] == 'GB')
505 505
          $result['country'] = 'UK';
506 506
      $result['region'] = $record['region'];
507
-     $result['geo'] = ['lat' => (float)$record['latitude'] , 'lon' => (float)$record['longitude']];
507
+     $result['geo'] = ['lat' => (float) $record['latitude'], 'lon' => (float) $record['longitude']];
508 508
    } else {
509 509
      $result = ['status' => 'error', 'error' =>'Problem listing countries']; 
510 510
    }
@@ -525,22 +525,22 @@  discard block
 block discarded – undo
525 525
    $result = ['status' => 'ok'];
526 526
    $result['country'] = $record->country->isoCode;
527 527
 //  the two lines below are a dirty hack to take of the error in naming the UK federation
528
-   if($result['country'] == 'GB')
528
+   if ($result['country'] == 'GB')
529 529
        $result['country'] = 'UK';
530 530
    $result['region'] = $record->continent->name;
531 531
 
532
-   $result['geo'] = ['lat' => (float)$record->location->latitude , 'lon' => (float)$record->location->longitude];
532
+   $result['geo'] = ['lat' => (float) $record->location->latitude, 'lon' => (float) $record->location->longitude];
533 533
    return($result);
534 534
  }
535 535
 
536 536
 public function JSON_locateUser() {
537 537
     header('Content-type: application/json; utf-8');
538 538
    
539
-    if(empty(Config::$GEOIP['version']) || Config::$GEOIP['version'] == 0)
539
+    if (empty(Config::$GEOIP['version']) || Config::$GEOIP['version'] == 0)
540 540
       echo json_encode(['status' => 'error', 'error' =>'Geolocation not supported']);
541
-    if(Config::$GEOIP['version'] == 1)
541
+    if (Config::$GEOIP['version'] == 1)
542 542
       echo json_encode($this->locateUser());
543
-    if(Config::$GEOIP['version'] == 2)
543
+    if (Config::$GEOIP['version'] == 2)
544 544
       echo json_encode($this->locateUser2());
545 545
 }
546 546
 
@@ -560,11 +560,11 @@  discard block
 block discarded – undo
560 560
   * @param array $P2 - second point as an 'lat', 'lon' array 
561 561
   * @return float distance in km
562 562
   */
563
-private function geoDistance($P1,$P2) {
563
+private function geoDistance($P1, $P2) {
564 564
 
565 565
   $dist = sin(deg2rad($P1['lat'])) * sin(deg2rad($P2['lat'])) +  
566 566
          cos(deg2rad($P1['lat'])) * cos(deg2rad($P2['lat'])) * cos(deg2rad($P1['lon'] - $P2['lon']));
567
-  $dist = rad2deg(acos($dist)) * 60 * 1.1852 ;
567
+  $dist = rad2deg(acos($dist)) * 60 * 1.1852;
568 568
   return(round($dist));
569 569
 }
570 570
 
@@ -574,44 +574,44 @@  discard block
 block discarded – undo
574 574
   * @return array $IdPs -  list of arrays ('id', 'name');
575 575
   */
576 576
 
577
-public function orderIdentityProviders($country,$L=NULL) {
578
-     $idps = Federation::listAllIdentityProviders(1,$country);
577
+public function orderIdentityProviders($country, $L = NULL) {
578
+     $idps = Federation::listAllIdentityProviders(1, $country);
579 579
 
580
-  if(is_null($L)) {
580
+  if (is_null($L)) {
581 581
      $U = $this->locateUser();
582
-     if($U['status'] == 'ok') {
582
+     if ($U['status'] == 'ok') {
583 583
      $L = $U['geo'];
584 584
      } else {
585
-       $L = ['lat'=>"90",'lon'=>"0"];
585
+       $L = ['lat'=>"90", 'lon'=>"0"];
586 586
      }
587 587
   }
588
-  $T=[];
589
-  $R=[];
588
+  $T = [];
589
+  $R = [];
590 590
      foreach ($idps as $idp) {
591 591
         $T[$idp['entityID']] = $idp['title'];
592 592
         $dist = 10000;
593
-        if(isset($idp['geo'])) {
594
-          $G=$idp['geo'];
595
-          if(isset($G['lon'])) {
596
-             $d1 = $this->geoDistance($L,$G); 
597
-             if( $d1 < $dist)
593
+        if (isset($idp['geo'])) {
594
+          $G = $idp['geo'];
595
+          if (isset($G['lon'])) {
596
+             $d1 = $this->geoDistance($L, $G); 
597
+             if ($d1 < $dist)
598 598
                 $dist = $d1;
599 599
           } else {
600 600
             foreach ($G as $g) {
601
-             $d1 = $this->geoDistance($L,$g); 
602
-             if( $d1 < $dist)
601
+             $d1 = $this->geoDistance($L, $g); 
602
+             if ($d1 < $dist)
603 603
                 $dist = $d1;
604 604
             }
605 605
           }
606 606
         }
607
-       if($dist > 100)
608
-         $dist=10000;
609
-      $d = sprintf("%06d",$dist);
610
-      $R[$idp['entityID']] = $d." ".$idp['title'];
607
+       if ($dist > 100)
608
+         $dist = 10000;
609
+      $d = sprintf("%06d", $dist);
610
+      $R[$idp['entityID']] = $d . " " . $idp['title'];
611 611
      }
612 612
      asort($R);
613 613
      foreach (array_keys($R) as $r) {
614
-      if($this->version == 1)
614
+      if ($this->version == 1)
615 615
          $outarray[] = ['id'=>$r, 'title'=>$T[$r]];
616 616
       else
617 617
          $outarray[] = ['idp'=>$r, 'title'=>$T[$r]];
@@ -629,44 +629,44 @@  discard block
 block discarded – undo
629 629
 
630 630
 public function detectOS() {
631 631
    $Dev = Devices::listDevices();
632
-   if( isset($_REQUEST['device']) && isset($Dev[$_REQUEST['device']]) && (!isset($device['options']['hidden']) || $device['options']['hidden'] == 0)) {
632
+   if (isset($_REQUEST['device']) && isset($Dev[$_REQUEST['device']]) && (!isset($device['options']['hidden']) || $device['options']['hidden'] == 0)) {
633 633
       $dev_id = $_REQUEST['device'];
634 634
       $device = $Dev[$dev_id];
635
-      if($this->version == 1)
636
-         return(['id'=>$dev_id,'display'=>$device['display'], 'group'=>$device['group']]);
635
+      if ($this->version == 1)
636
+         return(['id'=>$dev_id, 'display'=>$device['display'], 'group'=>$device['group']]);
637 637
       else
638
-         return(['device'=>$dev_id,'display'=>$device['display'], 'group'=>$device['group']]);
638
+         return(['device'=>$dev_id, 'display'=>$device['display'], 'group'=>$device['group']]);
639 639
    }
640 640
    $browser = $_SERVER['HTTP_USER_AGENT'];
641
-   debug(4,"HTTP_USER_AGENT=$browser\n");
641
+   debug(4, "HTTP_USER_AGENT=$browser\n");
642 642
    foreach ($Dev as $dev_id => $device) {
643
-     if(!isset($device['match']))
643
+     if (!isset($device['match']))
644 644
         continue;
645
-     if(preg_match('/'.$device['match'].'/',$browser)) {
646
-       if(!isset($device['options']['hidden']) || $device['options']['hidden'] == 0) {
647
-          debug(4,"Browser_id: $dev_id\n");
648
-          if($this->version == 1)
649
-             return(['id'=>$dev_id,'display'=>$device['display'], 'group'=>$device['group']]);
645
+     if (preg_match('/' . $device['match'] . '/', $browser)) {
646
+       if (!isset($device['options']['hidden']) || $device['options']['hidden'] == 0) {
647
+          debug(4, "Browser_id: $dev_id\n");
648
+          if ($this->version == 1)
649
+             return(['id'=>$dev_id, 'display'=>$device['display'], 'group'=>$device['group']]);
650 650
           else
651
-             return(['device'=>$dev_id,'display'=>$device['display'], 'group'=>$device['group']]);
651
+             return(['device'=>$dev_id, 'display'=>$device['display'], 'group'=>$device['group']]);
652 652
        }
653 653
        else {
654
-         debug(2, "Unrecognised system: ".$_SERVER['HTTP_USER_AGENT']."\n");
654
+         debug(2, "Unrecognised system: " . $_SERVER['HTTP_USER_AGENT'] . "\n");
655 655
          return(false);
656 656
        }
657 657
      }
658 658
    }
659
-   debug(2, "Unrecognised system: ".$_SERVER['HTTP_USER_AGENT']."\n");
659
+   debug(2, "Unrecognised system: " . $_SERVER['HTTP_USER_AGENT'] . "\n");
660 660
    return(false);
661 661
 }
662 662
 
663 663
 public function JSON_detectOS() {
664
-     $return_array=$this->detectOS();
665
-     if($return_array)
664
+     $return_array = $this->detectOS();
665
+     if ($return_array)
666 666
         $status = 1;
667 667
      else
668 668
         $status = 0;
669
-     echo $this->return_json($return_array,$status);
669
+     echo $this->return_json($return_array, $status);
670 670
 }
671 671
 
672 672
 
@@ -675,6 +675,6 @@  discard block
 block discarded – undo
675 675
 private $i_path;
676 676
   
677 677
 }
678
-function profile_sort($P1,$P2) {
678
+function profile_sort($P1, $P2) {
679 679
    return strcasecmp($P1->name, $P2->name);
680 680
 } 
681 681
\ No newline at end of file
Please login to merge, or discard this patch.
devices/ms/Vista7.php 1 patch
Indentation   +135 added lines, -135 removed lines patch added patch discarded remove patch
@@ -26,66 +26,66 @@  discard block
 block discarded – undo
26 26
  */
27 27
 class Device_Vista7 extends WindowsCommon {
28 28
     final public function __construct() {
29
-      $this->supportedEapMethods = [EAP::$TLS, EAP::$PEAP_MSCHAP2, EAP::$PWD];
30
-      debug(4,"This device supports the following EAP methods: ");
31
-      debug(4,$this->supportedEapMethods);
32
-      $this->specialities['anon_id'][serialize(EAP::$PEAP_MSCHAP2)] = _("Anonymous identities do not use the realm as specified in the profile - it is derived from the suffix of the user's username input instead.");
29
+        $this->supportedEapMethods = [EAP::$TLS, EAP::$PEAP_MSCHAP2, EAP::$PWD];
30
+        debug(4,"This device supports the following EAP methods: ");
31
+        debug(4,$this->supportedEapMethods);
32
+        $this->specialities['anon_id'][serialize(EAP::$PEAP_MSCHAP2)] = _("Anonymous identities do not use the realm as specified in the profile - it is derived from the suffix of the user's username input instead.");
33 33
     }
34 34
 
35
-  public function writeInstaller() {
36
-      $dom = textdomain(NULL);
37
-      textdomain("devices");
38
-   // create certificate files and save their names in $CA_files arrary
39
-     $CA_files = $this->saveCertificateFiles('der');
35
+    public function writeInstaller() {
36
+        $dom = textdomain(NULL);
37
+        textdomain("devices");
38
+    // create certificate files and save their names in $CA_files arrary
39
+        $CA_files = $this->saveCertificateFiles('der');
40 40
 
41
-     $SSIDs = $this->attributes['internal:SSID'];
42
-     $delSSIDs = $this->attributes['internal:remove_SSID'];
43
-     $this->prepareInstallerLang();
44
-     $set_wired = isset($this->attributes['media:wired'][0]) && $this->attributes['media:wired'][0] == 'on' ? 1 : 0;
41
+        $SSIDs = $this->attributes['internal:SSID'];
42
+        $delSSIDs = $this->attributes['internal:remove_SSID'];
43
+        $this->prepareInstallerLang();
44
+        $set_wired = isset($this->attributes['media:wired'][0]) && $this->attributes['media:wired'][0] == 'on' ? 1 : 0;
45 45
 //   create a list of profiles to be deleted after installation
46
-     $delProfiles = [];
47
-     foreach ($delSSIDs as $ssid => $cipher) {
48
-         if($cipher == 'DEL') 
49
-          $delProfiles[] = $ssid;
50
-         if($cipher == 'TKIP') 
51
-          $delProfiles[] = $ssid.' (TKIP)';
52
-     }
53
-
54
-     if ($this->selected_eap == EAP::$TLS || $this->selected_eap == EAP::$PEAP_MSCHAP2 || $this->selected_eap == EAP::$PWD || $this->selected_eap == EAP::$TTLS_PAP) {
55
-       $WindowsProfile = [];
56
-       $eap_config = $this->prepareEapConfig($this->attributes);
57
-       $i = 0;
58
-       foreach ($SSIDs as $ssid => $cipher) {
59
-          if($cipher == 'TKIP') {
60
-             $WindowsProfile[$i] = $this->writeWLANprofile ($ssid.' (TKIP)',$ssid,'WPA','TKIP',$eap_config,$i);
61
-             $i++;
62
-          }
63
-          $WindowsProfile[$i] = $this->writeWLANprofile ($ssid,$ssid,'WPA2','AES',$eap_config,$i);
64
-          $i++;
65
-       }
66
-       if($set_wired) {
67
-         $this->writeLANprofile($eap_config);
68
-       }
69
-     } else {
70
-       error("  this EAP type is not handled yet");
71
-       return;
72
-     }
46
+        $delProfiles = [];
47
+        foreach ($delSSIDs as $ssid => $cipher) {
48
+            if($cipher == 'DEL') 
49
+            $delProfiles[] = $ssid;
50
+            if($cipher == 'TKIP') 
51
+            $delProfiles[] = $ssid.' (TKIP)';
52
+        }
53
+
54
+        if ($this->selected_eap == EAP::$TLS || $this->selected_eap == EAP::$PEAP_MSCHAP2 || $this->selected_eap == EAP::$PWD || $this->selected_eap == EAP::$TTLS_PAP) {
55
+        $WindowsProfile = [];
56
+        $eap_config = $this->prepareEapConfig($this->attributes);
57
+        $i = 0;
58
+        foreach ($SSIDs as $ssid => $cipher) {
59
+            if($cipher == 'TKIP') {
60
+                $WindowsProfile[$i] = $this->writeWLANprofile ($ssid.' (TKIP)',$ssid,'WPA','TKIP',$eap_config,$i);
61
+                $i++;
62
+            }
63
+            $WindowsProfile[$i] = $this->writeWLANprofile ($ssid,$ssid,'WPA2','AES',$eap_config,$i);
64
+            $i++;
65
+        }
66
+        if($set_wired) {
67
+            $this->writeLANprofile($eap_config);
68
+        }
69
+        } else {
70
+        error("  this EAP type is not handled yet");
71
+        return;
72
+        }
73 73
     debug(4,"WindowsProfile"); debug(4,$WindowsProfile);
74 74
     
75 75
     $this->writeProfilesNSH($WindowsProfile, $CA_files,$set_wired);
76 76
     $this->writeAdditionalDeletes($delProfiles);
77 77
     $this->copyFiles($this->selected_eap);
78 78
     if(isset($this->attributes['internal:logo_file']))
79
-       $this->combineLogo($this->attributes['internal:logo_file']);
79
+        $this->combineLogo($this->attributes['internal:logo_file']);
80 80
     $this->writeMainNSH($this->selected_eap,$this->attributes);
81 81
     $this->compileNSIS();
82 82
     $installer_path = $this->signInstaller($this->attributes); 
83 83
 
84 84
     textdomain($dom);
85 85
     return($installer_path);  
86
-  }
86
+    }
87 87
 
88
-  public function writeDeviceInfo() {
88
+    public function writeDeviceInfo() {
89 89
     $ssid_ct=count($this->attributes['internal:SSID']);
90 90
     $out = "<p>";
91 91
     $out .= sprintf(_("%s installer will be in the form of an EXE file. It will configure %s on your device, by creating wireless network profiles.<p>When you click the download button, the installer will be saved by your browser. Copy it to the machine you want to configure and execute."),Config::$CONSORTIUM['name'],Config::$CONSORTIUM['name']);
@@ -97,12 +97,12 @@  discard block
 block discarded – undo
97 97
             $out .= sprintf(_("In addition to <strong>%s</strong> the installer will also configure access to:"),implode(', ',Config::$CONSORTIUM['ssid']))." ";
98 98
         $i = 0;
99 99
         foreach ($this->attributes['internal:SSID'] as $ssid=>$v) {
100
-           if(! in_array($ssid, Config::$CONSORTIUM['ssid'])) {
101
-             if($i > 0)
102
-           $out .= ", ";
103
-         $i++;
104
-         $out .= "<strong>$ssid</strong>";
105
-       }
100
+            if(! in_array($ssid, Config::$CONSORTIUM['ssid'])) {
101
+                if($i > 0)
102
+            $out .= ", ";
103
+            $i++;
104
+            $out .= "<strong>$ssid</strong>";
105
+        }
106 106
     }
107 107
     $out .= "<p>";
108 108
     }
@@ -115,21 +115,21 @@  discard block
 block discarded – undo
115 115
         $out .= "<p>";
116 116
         $out .= _("When you are connecting to the network for the first time, Windows will pop up a login box, where you should enter your user name and password. This information will be saved so that you will reconnect to the network automatically each time you are in the range.");
117 117
         if($ssid_ct > 1) {
118
-             $out .= "<p>";
119
-             $out .= _("You will be required to enter the same credentials for each of the configured notworks:")." ";
120
-             $i = 0;
118
+                $out .= "<p>";
119
+                $out .= _("You will be required to enter the same credentials for each of the configured notworks:")." ";
120
+                $i = 0;
121 121
             foreach ($this->attributes['internal:SSID'] as $ssid=>$v) {
122
-                 if($i > 0)
123
-                   $out .= ", ";
124
-                 $i++;
125
-                 $out .= "<strong>$ssid</strong>";
122
+                    if($i > 0)
123
+                    $out .= ", ";
124
+                    $i++;
125
+                    $out .= "<strong>$ssid</strong>";
126 126
             }
127 127
     }
128 128
 
129
-   }
129
+    }
130 130
 
131
-   }
132
-  return($out);
131
+    }
132
+    return($out);
133 133
 }
134 134
 
135 135
 private function prepareEapConfig($attr) {
@@ -137,25 +137,25 @@  discard block
 block discarded – undo
137 137
     $w7_ext = '';
138 138
     $eap = $this->selected_eap;
139 139
     if ($eap != EAP::$TLS && $eap != EAP::$PEAP_MSCHAP2 && $eap != EAP::$PWD && $eap != EAP::$TTLS_PAP) {
140
-      debug(2,"this method only allows TLS, PEAP, TTLS-PAP or EAP-pwd");
141
-      error("this method only allows TLS, PEAP, TTLS-PAP or EAP-pwd");
142
-     return;
140
+        debug(2,"this method only allows TLS, PEAP, TTLS-PAP or EAP-pwd");
141
+        error("this method only allows TLS, PEAP, TTLS-PAP or EAP-pwd");
142
+        return;
143
+    }
144
+    $use_anon = $attr['internal:use_anon_outer'] [0];
145
+    $realm = $attr['internal:realm'] [0];
146
+    if ($use_anon) {
147
+        $outer_user = $attr['internal:anon_local_value'][0];
143 148
     }
144
-   $use_anon = $attr['internal:use_anon_outer'] [0];
145
-   $realm = $attr['internal:realm'] [0];
146
-   if ($use_anon) {
147
-     $outer_user = $attr['internal:anon_local_value'][0];
148
-   }
149 149
 //   $servers = preg_quote(implode(';',$attr['eap:server_name']));
150
-   $servers = implode(';',$attr['eap:server_name']);
151
-   $ca_array = $attr['internal:CAs'][0];
152
-   $author_id = "0";
153
-   if( $eap == EAP::$TTLS_PAP) {
154
-      $author_id = "17236";
155
-      $servers = implode('</ServerName><ServerName>',$attr['eap:server_name']);
156
-   }
157
-
158
-  $profile_file_contents = '<EAPConfig><EapHostConfig xmlns="http://www.microsoft.com/provisioning/EapHostConfig">
150
+    $servers = implode(';',$attr['eap:server_name']);
151
+    $ca_array = $attr['internal:CAs'][0];
152
+    $author_id = "0";
153
+    if( $eap == EAP::$TTLS_PAP) {
154
+        $author_id = "17236";
155
+        $servers = implode('</ServerName><ServerName>',$attr['eap:server_name']);
156
+    }
157
+
158
+    $profile_file_contents = '<EAPConfig><EapHostConfig xmlns="http://www.microsoft.com/provisioning/EapHostConfig">
159 159
 <EapMethod>
160 160
 <Type xmlns="http://www.microsoft.com/provisioning/EapCommon">'.
161 161
     $this->selected_eap["OUTER"] .'</Type>
@@ -166,7 +166,7 @@  discard block
 block discarded – undo
166 166
 ';
167 167
 
168 168
 
169
-   if( $eap == EAP::$TTLS_PAP) {
169
+    if( $eap == EAP::$TTLS_PAP) {
170 170
 $profile_file_contents .= '
171 171
 <Config xmlns="http://www.microsoft.com/provisioning/EapHostConfig">
172 172
 <EAPIdentityProviderList xmlns="urn:ietf:params:xml:ns:yang:ietf-eap-metadata">
@@ -201,14 +201,14 @@  discard block
 block discarded – undo
201 201
 $profile_file_contents .= '<ServerSideCredential>
202 202
 ';
203 203
 
204
-   foreach ($ca_array as $ca) {
204
+    foreach ($ca_array as $ca) {
205 205
       
206
-      $profile_file_contents .= '<CA><format>PEM</format><cert-data>';
207
-      $profile_file_contents .= base64_encode($ca['der']);
208
-      $profile_file_contents .= '</cert-data></CA>
206
+        $profile_file_contents .= '<CA><format>PEM</format><cert-data>';
207
+        $profile_file_contents .= base64_encode($ca['der']);
208
+        $profile_file_contents .= '</cert-data></CA>
209 209
 ';
210
-   }
211
-   $profile_file_contents .= "<ServerName>$servers</ServerName>\n";
210
+    }
211
+    $profile_file_contents .= "<ServerName>$servers</ServerName>\n";
212 212
 
213 213
 $profile_file_contents .= '
214 214
 </ServerSideCredential>
@@ -228,7 +228,7 @@  discard block
 block discarded – undo
228 228
 }
229 229
 
230 230
 elseif( $eap == EAP::$TLS) {
231
-  $profile_file_contents .= '
231
+    $profile_file_contents .= '
232 232
 
233 233
 <Config xmlns:baseEap="http://www.microsoft.com/provisioning/BaseEapConnectionPropertiesV1" 
234 234
   xmlns:eapTls="http://www.microsoft.com/provisioning/EapTlsConnectionPropertiesV1">
@@ -244,14 +244,14 @@  discard block
 block discarded – undo
244 244
 if($ca_array) {
245 245
 foreach ($ca_array as $CA)
246 246
     if($CA['root'])
247
-       $profile_file_contents .= "<eapTls:TrustedRootCA>".$CA['sha1']."</eapTls:TrustedRootCA>\n";
247
+        $profile_file_contents .= "<eapTls:TrustedRootCA>".$CA['sha1']."</eapTls:TrustedRootCA>\n";
248 248
 }
249 249
 $profile_file_contents .= '</eapTls:ServerValidation>
250 250
 ';
251 251
 if(isset($attr['eap-specific:tls_use_other_id']) && $attr['eap-specific:tls_use_other_id'][0] == 'on')
252
-   $profile_file_contents .= '<eapTls:DifferentUsername>true</eapTls:DifferentUsername>';
252
+    $profile_file_contents .= '<eapTls:DifferentUsername>true</eapTls:DifferentUsername>';
253 253
 else
254
-   $profile_file_contents .= '<eapTls:DifferentUsername>false</eapTls:DifferentUsername>';
254
+    $profile_file_contents .= '<eapTls:DifferentUsername>false</eapTls:DifferentUsername>';
255 255
 $profile_file_contents .= '
256 256
 </eapTls:EapType>
257 257
 </baseEap:Eap>
@@ -259,9 +259,9 @@  discard block
 block discarded – undo
259 259
 ';
260 260
 } elseif ( $eap == EAP::$PEAP_MSCHAP2) {
261 261
 if(isset($attr['eap:enable_nea']) && $attr['eap:enable_nea'][0] == 'on')
262
-   $nea = 'true';
262
+    $nea = 'true';
263 263
 else
264
-   $nea = 'false';
264
+    $nea = 'false';
265 265
 $vista_ext = '<Config xmlns:eapUser="http://www.microsoft.com/provisioning/EapUserPropertiesV1" 
266 266
 xmlns:baseEap="http://www.microsoft.com/provisioning/BaseEapConnectionPropertiesV1" 
267 267
   xmlns:msPeap="http://www.microsoft.com/provisioning/MsPeapConnectionPropertiesV1" 
@@ -275,7 +275,7 @@  discard block
 block discarded – undo
275 275
 if($ca_array) {
276 276
 foreach ($ca_array as $CA)
277 277
     if($CA['root'])
278
-       $vista_ext .= "<msPeap:TrustedRootCA>".$CA['sha1']."</msPeap:TrustedRootCA>\n";
278
+        $vista_ext .= "<msPeap:TrustedRootCA>".$CA['sha1']."</msPeap:TrustedRootCA>\n";
279 279
 }
280 280
 $vista_ext .= '</msPeap:ServerValidation>
281 281
 <msPeap:FastReconnect>true</msPeap:FastReconnect> 
@@ -329,7 +329,7 @@  discard block
 block discarded – undo
329 329
 </Config>
330 330
 ';
331 331
 } elseif ( $eap == EAP::$PWD) {
332
-   $profile_file_contents .= '<ConfigBlob></ConfigBlob>';
332
+    $profile_file_contents .= '<ConfigBlob></ConfigBlob>';
333 333
 } 
334 334
 
335 335
 
@@ -351,7 +351,7 @@  discard block
 block discarded – undo
351 351
 /**
352 352
  * produce PEAP and TLS configuration files for Vista and Windows 7
353 353
  */
354
-  private function writeWLANprofile($wlan_profile_name,$ssid,$auth,$encryption,$eap_config,$i) {
354
+    private function writeWLANprofile($wlan_profile_name,$ssid,$auth,$encryption,$eap_config,$i) {
355 355
 $profile_file_contents = '<?xml version="1.0"?>
356 356
 <WLANProfile xmlns="http://www.microsoft.com/networking/WLAN/profile/v1">
357 357
 <name>'.$wlan_profile_name.'</name>
@@ -391,9 +391,9 @@  discard block
 block discarded – undo
391 391
 ';
392 392
 
393 393
 if(! is_dir('w7'))
394
-  mkdir('w7');
394
+    mkdir('w7');
395 395
 if(! is_dir('vista'))
396
-  mkdir('vista');
396
+    mkdir('vista');
397 397
 $xml_f_name = "vista/wlan_prof-$i.xml";
398 398
 $xml_f = fopen($xml_f_name,'w');
399 399
 fwrite($xml_f,$profile_file_contents. $eap_config['vista']. $closing) ;
@@ -423,9 +423,9 @@  discard block
 block discarded – undo
423 423
 </LANProfile>
424 424
 ';
425 425
 if(! is_dir('w7'))
426
-  mkdir('w7');
426
+    mkdir('w7');
427 427
 if(! is_dir('vista'))
428
-  mkdir('vista');
428
+    mkdir('vista');
429 429
 $xml_f_name = "vista/lan_prof.xml";
430 430
 $xml_f = fopen($xml_f_name,'w');
431 431
 fwrite($xml_f,$profile_file_contents. $eap_config['vista']. $closing) ;
@@ -438,16 +438,16 @@  discard block
 block discarded – undo
438 438
 
439 439
 private function glueServerNames($server_list) {
440 440
 //print_r($server_list);
441
- $A0 =  array_reverse(explode('.',array_shift($server_list)));
442
- $B = $A0;
443
- if($server_list) {
444
-   foreach($server_list as $a) {
445
-   $A= array_reverse(explode('.',$a));
446
-   $B = array_intersect_assoc($A0,$A);
447
-   $A0 = $B;
448
-   }
449
-  }
450
-  return(implode('.',array_reverse($B)));
441
+    $A0 =  array_reverse(explode('.',array_shift($server_list)));
442
+    $B = $A0;
443
+    if($server_list) {
444
+    foreach($server_list as $a) {
445
+    $A= array_reverse(explode('.',$a));
446
+    $B = array_intersect_assoc($A0,$A);
447
+    $A0 = $B;
448
+    }
449
+    }
450
+    return(implode('.',array_reverse($B)));
451 451
 }
452 452
 
453 453
 
@@ -502,7 +502,7 @@  discard block
 block discarded – undo
502 502
 ';
503 503
 
504 504
 if(isset($this->attributes['media:wired'][0]) && $attr['media:wired'][0] == 'on')
505
-  $fcontents .= '!define WIRED
505
+    $fcontents .= '!define WIRED
506 506
 ';
507 507
 
508 508
 $f = fopen('main.nsh','w');
@@ -514,8 +514,8 @@  discard block
 block discarded – undo
514 514
 private function writeProfilesNSH($P,$ca_array,$wired=0) {
515 515
 debug(4,"writeProfilesNSH");
516 516
 debug(4,$P);
517
-  $fcontents = '';
518
-  foreach($P as $p) 
517
+    $fcontents = '';
518
+    foreach($P as $p) 
519 519
     $fcontents .= "!insertmacro define_wlan_profile $p\n";
520 520
   
521 521
 $f = fopen('profiles.nsh','w');
@@ -526,8 +526,8 @@  discard block
 block discarded – undo
526 526
 $f = fopen('certs.nsh','w');
527 527
 if($ca_array) {
528 528
 foreach ($ca_array as $CA) {
529
-      $store = $CA['root'] ? "root" : "ca";
530
-      $fcontents .= '!insertmacro install_ca_cert "'.$CA['file'].'" "'.$CA['sha1'].'" "'.$store."\"\n";
529
+        $store = $CA['root'] ? "root" : "ca";
530
+        $fcontents .= '!insertmacro install_ca_cert "'.$CA['file'].'" "'.$CA['sha1'].'" "'.$store."\"\n";
531 531
     }
532 532
 fwrite($f, $fcontents);
533 533
 }
@@ -537,33 +537,33 @@  discard block
 block discarded – undo
537 537
 private function copyFiles ($eap) {
538 538
 debug(4,"copyFiles start\n");
539 539
 debug(4,"code_page=".$this->code_page."\n");
540
-   $result;
541
-   $result = $this->copyFile('wlan_test.exe');
542
-   $result = $this->copyFile('check_wired.cmd');
543
-   $result = $this->copyFile('install_wired.cmd');
544
-   $result = $this->copyFile('setEAPCred.exe');
545
-   $result = $this->copyFile('base64.nsh');
546
-   $result = $this->copyFile('cat_bg.bmp');
547
-   $result = $result && $this->copyFile('cat32.ico');
548
-   $result = $result && $this->copyFile('cat_150.bmp');
549
-   $this->translateFile('common.inc','common.nsh',$this->code_page);
550
-   if( $eap["OUTER"] == TTLS)  {
551
-     $result = $this->copyFile('GPL3.rtf');
552
-     $result = $result && $this->copyFile('ArnesLinkEn32.msi');
553
-     $result = $result && $this->copyFile('ArnesLinkEn64.msi');
554
-     $result = $result && $this->copyFile('dump_arneslink_profile.cmd');
555
-     $result = $result && $this->copyFile('install_arneslink_profile.cmd');
556
-     $this->translateFile('arnes_link.inc','cat.NSI',$this->code_page);
557
-   } elseif($eap["OUTER"] == PWD) {
558
-     $this->translateFile('pwd.inc','cat.NSI',$this->code_page);
559
-     $result = $result && $this->copyFile('Aruba_Networks_EAP-pwd_x32.msi');
560
-     $result = $result && $this->copyFile('Aruba_Networks_EAP-pwd_x64.msi');
540
+    $result;
541
+    $result = $this->copyFile('wlan_test.exe');
542
+    $result = $this->copyFile('check_wired.cmd');
543
+    $result = $this->copyFile('install_wired.cmd');
544
+    $result = $this->copyFile('setEAPCred.exe');
545
+    $result = $this->copyFile('base64.nsh');
546
+    $result = $this->copyFile('cat_bg.bmp');
547
+    $result = $result && $this->copyFile('cat32.ico');
548
+    $result = $result && $this->copyFile('cat_150.bmp');
549
+    $this->translateFile('common.inc','common.nsh',$this->code_page);
550
+    if( $eap["OUTER"] == TTLS)  {
551
+        $result = $this->copyFile('GPL3.rtf');
552
+        $result = $result && $this->copyFile('ArnesLinkEn32.msi');
553
+        $result = $result && $this->copyFile('ArnesLinkEn64.msi');
554
+        $result = $result && $this->copyFile('dump_arneslink_profile.cmd');
555
+        $result = $result && $this->copyFile('install_arneslink_profile.cmd');
556
+        $this->translateFile('arnes_link.inc','cat.NSI',$this->code_page);
557
+    } elseif($eap["OUTER"] == PWD) {
558
+        $this->translateFile('pwd.inc','cat.NSI',$this->code_page);
559
+        $result = $result && $this->copyFile('Aruba_Networks_EAP-pwd_x32.msi');
560
+        $result = $result && $this->copyFile('Aruba_Networks_EAP-pwd_x64.msi');
561 561
     } else {
562
-     $this->translateFile('peap_tls.inc','cat.NSI',$this->code_page);
563
-     $result = 1;
562
+        $this->translateFile('peap_tls.inc','cat.NSI',$this->code_page);
563
+        $result = 1;
564 564
     }
565 565
 debug(4,"copyFiles end\n");
566
-   return($result);
566
+    return($result);
567 567
 }
568 568
 
569 569
 }
570 570
\ No newline at end of file
Please login to merge, or discard this patch.