@@ -230,7 +230,7 @@ |
||
| 230 | 230 | * @param string $user persistent identifier of the user who triggered the action |
| 231 | 231 | * @param string $category type of modification, from the fixed vocabulary: "NEW", "OWN", "MOD", "DEL" |
| 232 | 232 | * @param string $message message to log into the audit log |
| 233 | - * @return boolean TRUE if successful. Will terminate script execution on failure. |
|
| 233 | + * @return boolean|null TRUE if successful. Will terminate script execution on failure. |
|
| 234 | 234 | */ |
| 235 | 235 | public static function writeAudit($user, $category, $message) { |
| 236 | 236 | switch ($category) { |
@@ -191,9 +191,9 @@ |
||
| 191 | 191 | * gets the language setting in CAT |
| 192 | 192 | */ |
| 193 | 193 | static public function get_lang() { |
| 194 | - if(self::$LANG === '') |
|
| 195 | - list(self::$LANG, $xx) = self::set_lang(); |
|
| 196 | - return self::$LANG; |
|
| 194 | + if(self::$LANG === '') |
|
| 195 | + list(self::$LANG, $xx) = self::set_lang(); |
|
| 196 | + return self::$LANG; |
|
| 197 | 197 | } |
| 198 | 198 | |
| 199 | 199 | /** |
@@ -73,12 +73,12 @@ discard block |
||
| 73 | 73 | |
| 74 | 74 | |
| 75 | 75 | if (CAT::$RELEASE_VERSION) { |
| 76 | - $temp_version = "CAT-".CAT::$VERSION_MAJOR.".".CAT::$VERSION_MINOR; |
|
| 76 | + $temp_version = "CAT-" . CAT::$VERSION_MAJOR . "." . CAT::$VERSION_MINOR; |
|
| 77 | 77 | if (CAT::$VERSION_PATCH != 0) |
| 78 | - $temp_version .= ".".CAT::$VERSION_PATCH; |
|
| 78 | + $temp_version .= "." . CAT::$VERSION_PATCH; |
|
| 79 | 79 | if (CAT::$VERSION_EXTRA != "") |
| 80 | - $temp_version .= "-".CAT::$VERSION_EXTRA; |
|
| 81 | - CAT::$VERSION = sprintf(_("Release %s"), $temp_version ); |
|
| 80 | + $temp_version .= "-" . CAT::$VERSION_EXTRA; |
|
| 81 | + CAT::$VERSION = sprintf(_("Release %s"), $temp_version); |
|
| 82 | 82 | } |
| 83 | 83 | else |
| 84 | 84 | CAT::$VERSION = _("Unreleased SVN Revision"); |
@@ -191,7 +191,7 @@ discard block |
||
| 191 | 191 | * gets the language setting in CAT |
| 192 | 192 | */ |
| 193 | 193 | static public function get_lang() { |
| 194 | - if(self::$LANG === '') |
|
| 194 | + if (self::$LANG === '') |
|
| 195 | 195 | list(self::$LANG, $xx) = self::set_lang(); |
| 196 | 196 | return self::$LANG; |
| 197 | 197 | } |
@@ -239,9 +239,9 @@ discard block |
||
| 239 | 239 | case "MOD": // modified existing object |
| 240 | 240 | case "DEL": // deleted an object |
| 241 | 241 | ob_start(); |
| 242 | - printf("%-015s",microtime(TRUE)); |
|
| 242 | + printf("%-015s", microtime(TRUE)); |
|
| 243 | 243 | print " ($category) "; |
| 244 | - print_r(" ".$user.": ".$message."\n"); |
|
| 244 | + print_r(" " . $user . ": " . $message . "\n"); |
|
| 245 | 245 | $output = ob_get_clean(); |
| 246 | 246 | if (Config::$PATHS['logdir']) { |
| 247 | 247 | $f = fopen(Config::$PATHS['logdir'] . "/audit-activity.log", "a"); |
@@ -268,8 +268,8 @@ discard block |
||
| 268 | 268 | $logtext1 = preg_replace("/[\n\r]/", "", $query); |
| 269 | 269 | $logtext = preg_replace("/ +/", " ", $logtext1); |
| 270 | 270 | ob_start(); |
| 271 | - printf("%-015s",microtime(TRUE)); |
|
| 272 | - print(" ".$logtext."\n"); |
|
| 271 | + printf("%-015s", microtime(TRUE)); |
|
| 272 | + print(" " . $logtext . "\n"); |
|
| 273 | 273 | $output = ob_get_clean(); |
| 274 | 274 | if (Config::$PATHS['logdir']) { |
| 275 | 275 | $f = fopen(Config::$PATHS['logdir'] . "/audit-SQL.log", "a"); |
@@ -74,14 +74,16 @@ discard block |
||
| 74 | 74 | |
| 75 | 75 | if (CAT::$RELEASE_VERSION) { |
| 76 | 76 | $temp_version = "CAT-".CAT::$VERSION_MAJOR.".".CAT::$VERSION_MINOR; |
| 77 | - if (CAT::$VERSION_PATCH != 0) |
|
| 78 | - $temp_version .= ".".CAT::$VERSION_PATCH; |
|
| 79 | - if (CAT::$VERSION_EXTRA != "") |
|
| 80 | - $temp_version .= "-".CAT::$VERSION_EXTRA; |
|
| 77 | + if (CAT::$VERSION_PATCH != 0) { |
|
| 78 | + $temp_version .= ".".CAT::$VERSION_PATCH; |
|
| 79 | + } |
|
| 80 | + if (CAT::$VERSION_EXTRA != "") { |
|
| 81 | + $temp_version .= "-".CAT::$VERSION_EXTRA; |
|
| 82 | + } |
|
| 81 | 83 | CAT::$VERSION = sprintf(_("Release %s"), $temp_version ); |
| 84 | + } else { |
|
| 85 | + CAT::$VERSION = _("Unreleased SVN Revision"); |
|
| 82 | 86 | } |
| 83 | - else |
|
| 84 | - CAT::$VERSION = _("Unreleased SVN Revision"); |
|
| 85 | 87 | } |
| 86 | 88 | |
| 87 | 89 | /** |
@@ -170,16 +172,18 @@ discard block |
||
| 170 | 172 | // we need to map stuff manually |
| 171 | 173 | $thelang = $try_lang; |
| 172 | 174 | |
| 173 | - foreach (Config::$LANGUAGES as $language => $value) |
|
| 174 | - if (preg_match("/^" . $language . ".*/", $try_lang)) { |
|
| 175 | + foreach (Config::$LANGUAGES as $language => $value) { |
|
| 176 | + if (preg_match("/^" . $language . ".*/", $try_lang)) { |
|
| 175 | 177 | $thelang = $value['locale']; |
| 178 | + } |
|
| 176 | 179 | $lang_index = $language; |
| 177 | 180 | } |
| 178 | 181 | |
| 179 | 182 | // echo "Trying to set language to $thelang..."; |
| 180 | 183 | // putenv("LC_ALL=$thelang"); |
| 181 | - if (setlocale(LC_ALL, $thelang)) |
|
| 182 | - break; |
|
| 184 | + if (setlocale(LC_ALL, $thelang)) { |
|
| 185 | + break; |
|
| 186 | + } |
|
| 183 | 187 | } |
| 184 | 188 | putenv("LC_ALL=" . $thelang); |
| 185 | 189 | debug(4, "selected lang:$lang_index:$thelang\n"); |
@@ -191,8 +195,9 @@ discard block |
||
| 191 | 195 | * gets the language setting in CAT |
| 192 | 196 | */ |
| 193 | 197 | static public function get_lang() { |
| 194 | - if(self::$LANG === '') |
|
| 195 | - list(self::$LANG, $xx) = self::set_lang(); |
|
| 198 | + if(self::$LANG === '') { |
|
| 199 | + list(self::$LANG, $xx) = self::set_lang(); |
|
| 200 | + } |
|
| 196 | 201 | return self::$LANG; |
| 197 | 202 | } |
| 198 | 203 | |
@@ -172,7 +172,7 @@ discard block |
||
| 172 | 172 | * named the same as device_id. The second option takes precedence. |
| 173 | 173 | * |
| 174 | 174 | * @param string $source_name The source file name |
| 175 | - * @param string $output_name The destination file name |
|
| 175 | + * @param integer $output_name The destination file name |
|
| 176 | 176 | * |
| 177 | 177 | * @return bool result of the copy operation |
| 178 | 178 | * @final not to be redefined |
@@ -216,8 +216,7 @@ discard block |
||
| 216 | 216 | * named the same as device_id. The second option takes precedence. |
| 217 | 217 | * |
| 218 | 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 |
|
| 219 | + * @param integer $output_name The destination file name |
|
| 221 | 220 | * |
| 222 | 221 | * @final not to be redefined |
| 223 | 222 | */ |
@@ -262,8 +261,6 @@ discard block |
||
| 262 | 261 | * The second optional parameter, if nonzero, should be the character set understood by iconv |
| 263 | 262 | * This is required by the Windows installer and is expected to go away in the future. |
| 264 | 263 | * |
| 265 | - * @param string $source_name The source file name |
|
| 266 | - * @param int $use_win_cp Set Windows charset if non-zero |
|
| 267 | 264 | * |
| 268 | 265 | * @final not to be redefined |
| 269 | 266 | */ |
@@ -107,8 +107,9 @@ discard block |
||
| 107 | 107 | $CAs = []; |
| 108 | 108 | if(isset($this->attributes['eap:ca_file'])) { |
| 109 | 109 | foreach ($this->attributes['eap:ca_file'] as $ca) { |
| 110 | - if($c = X509::processCertificate($ca)) |
|
| 111 | - $CAs[] = $c; |
|
| 110 | + if($c = X509::processCertificate($ca)) { |
|
| 111 | + $CAs[] = $c; |
|
| 112 | + } |
|
| 112 | 113 | } |
| 113 | 114 | $this->attributes['internal:CAs'][0]=$CAs; |
| 114 | 115 | } |
@@ -116,9 +117,10 @@ discard block |
||
| 116 | 117 | $this->attributes['internal:info_file'][0] = |
| 117 | 118 | $this->saveInfoFile($this->attributes['support:info_file'][0]); |
| 118 | 119 | } |
| 119 | - if(isset($this->attributes['general:logo_file'])) |
|
| 120 | - $this->attributes['internal:logo_file'] = |
|
| 120 | + if(isset($this->attributes['general:logo_file'])) { |
|
| 121 | + $this->attributes['internal:logo_file'] = |
|
| 121 | 122 | $this->saveLogoFile($this->attributes['general:logo_file']); |
| 123 | + } |
|
| 122 | 124 | $this->attributes['internal:SSID'] = $this->getSSIDs()['add'];; |
| 123 | 125 | $this->attributes['internal:remove_SSID'] = $this->getSSIDs()['del'];; |
| 124 | 126 | $this->attributes['internal:consortia'] = $this->getConsortia(); |
@@ -130,8 +132,9 @@ discard block |
||
| 130 | 132 | $this->support_url_substitute = sprintf(_("your local %s support page"),Config::$CONSORTIUM['name']); |
| 131 | 133 | CAT::set_locale($olddomain); |
| 132 | 134 | |
| 133 | - if($this->signer && $this->options['sign']) |
|
| 134 | - $this->sign = CAT::$root . '/signer/'. $this->signer; |
|
| 135 | + if($this->signer && $this->options['sign']) { |
|
| 136 | + $this->sign = CAT::$root . '/signer/'. $this->signer; |
|
| 137 | + } |
|
| 135 | 138 | $this->installerBasename = $this->getInstallerBasename(); |
| 136 | 139 | } |
| 137 | 140 | |
@@ -178,22 +181,24 @@ discard block |
||
| 178 | 181 | * @final not to be redefined |
| 179 | 182 | */ |
| 180 | 183 | final protected function copyFile($source_name, $output_name = 0) { |
| 181 | - if ( $output_name === 0) |
|
| 182 | - $output_name = $source_name; |
|
| 184 | + if ( $output_name === 0) { |
|
| 185 | + $output_name = $source_name; |
|
| 186 | + } |
|
| 183 | 187 | |
| 184 | 188 | 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 { |
|
| 189 | + if(is_file($this->module_path.'/Files/'.$this->device_id.'/'.$source_name)) { |
|
| 190 | + $source = $this->module_path.'/Files/'.$this->device_id.'/'.$source_name; |
|
| 191 | + } elseif(is_file($this->module_path.'/Files/'.$source_name)) { |
|
| 192 | + $source = $this->module_path.'/Files/'.$source_name; |
|
| 193 | + } else { |
|
| 190 | 194 | debug(2,"fileCopy:reqested file $source_name does not exist\n"); |
| 191 | 195 | return(FALSE); |
| 192 | 196 | } |
| 193 | 197 | debug(4,"Copying $source to $output_name\n"); |
| 194 | 198 | $result = copy($source,"$output_name"); |
| 195 | - if(! $result ) |
|
| 196 | - debug(2,"fileCopy($source_name, $output_name) failed\n"); |
|
| 199 | + if(! $result ) { |
|
| 200 | + debug(2,"fileCopy($source_name, $output_name) failed\n"); |
|
| 201 | + } |
|
| 197 | 202 | return($result); |
| 198 | 203 | } |
| 199 | 204 | |
@@ -223,28 +228,33 @@ discard block |
||
| 223 | 228 | */ |
| 224 | 229 | |
| 225 | 230 | final protected function translateFile($source_name, $output_name = 0, $encoding = 0) { |
| 226 | - if(Config::$NSIS_VERSION >= 3) |
|
| 227 | - $encoding = 0; |
|
| 228 | - if ( $output_name === 0) |
|
| 229 | - $output_name = $source_name; |
|
| 231 | + if(Config::$NSIS_VERSION >= 3) { |
|
| 232 | + $encoding = 0; |
|
| 233 | + } |
|
| 234 | + if ( $output_name === 0) { |
|
| 235 | + $output_name = $source_name; |
|
| 236 | + } |
|
| 230 | 237 | |
| 231 | 238 | debug(4,"translateFile($source_name, $output_name, $encoding)\n"); |
| 232 | 239 | ob_start(); |
| 233 | 240 | 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; |
|
| 241 | + if(is_file($this->module_path.'/Files/'.$this->device_id.'/'.$source_name)) { |
|
| 242 | + $source = $this->module_path.'/Files/'.$this->device_id.'/'.$source_name; |
|
| 243 | + } elseif(is_file($this->module_path.'/Files/'.$source_name)) { |
|
| 244 | + $source = $this->module_path.'/Files/'.$source_name; |
|
| 245 | + } |
|
| 238 | 246 | include($source); |
| 239 | 247 | $output = ob_get_clean(); |
| 240 | 248 | if($encoding) { |
| 241 | 249 | $output_c = iconv('UTF-8',$encoding.'//TRANSLIT',$output); |
| 242 | - if($output_c) |
|
| 243 | - $output = $output_c; |
|
| 250 | + if($output_c) { |
|
| 251 | + $output = $output_c; |
|
| 252 | + } |
|
| 244 | 253 | } |
| 245 | 254 | $f = fopen("$output_name","w"); |
| 246 | - if(! $f) |
|
| 247 | - debug(2,"translateFile($source, $output_name, $encoding) failed\n"); |
|
| 255 | + if(! $f) { |
|
| 256 | + debug(2,"translateFile($source, $output_name, $encoding) failed\n"); |
|
| 257 | + } |
|
| 248 | 258 | fwrite($f,$output); |
| 249 | 259 | fclose($f); |
| 250 | 260 | debug(4,"translateFile($source, $output_name, $encoding) end\n"); |
@@ -269,16 +279,19 @@ discard block |
||
| 269 | 279 | */ |
| 270 | 280 | |
| 271 | 281 | final protected function translateString($source_string,$encoding = 0) { |
| 272 | - if(Config::$NSIS_VERSION >= 3) |
|
| 273 | - $encoding = 0; |
|
| 274 | - if($encoding) |
|
| 275 | - $output_c = iconv('UTF-8',$encoding.'//TRANSLIT',$source_string); |
|
| 276 | - else |
|
| 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 | + if(Config::$NSIS_VERSION >= 3) { |
|
| 283 | + $encoding = 0; |
|
| 284 | + } |
|
| 285 | + if($encoding) { |
|
| 286 | + $output_c = iconv('UTF-8',$encoding.'//TRANSLIT',$source_string); |
|
| 287 | + } else { |
|
| 288 | + $output_c = $source_string; |
|
| 289 | + } |
|
| 290 | + if($output_c) { |
|
| 291 | + $source_string = str_replace('"','$\\"',$output_c); |
|
| 292 | + } else { |
|
| 293 | + debug(2,"Failed to convert string $source_string\n"); |
|
| 294 | + } |
|
| 282 | 295 | return $source_string; |
| 283 | 296 | } |
| 284 | 297 | |
@@ -299,15 +312,19 @@ discard block |
||
| 299 | 312 | $i = 0; |
| 300 | 313 | $CA_files = []; |
| 301 | 314 | $ca_array = $this->attributes['internal:CAs'][0]; |
| 302 | - if(! $ca_array) |
|
| 303 | - return(FALSE); |
|
| 315 | + if(! $ca_array) { |
|
| 316 | + return(FALSE); |
|
| 317 | + } |
|
| 304 | 318 | foreach ($ca_array as $CA) { |
| 305 | 319 | $f = fopen("cert-$i.crt","w"); |
| 306 | - if(! $f) die("problem opening the file\n"); |
|
| 307 | - if($format == "pem") |
|
| 308 | - fwrite($f,$CA['pem']); |
|
| 309 | - else |
|
| 310 | - fwrite($f,$CA['der']); |
|
| 320 | + if(! $f) { |
|
| 321 | + die("problem opening the file\n"); |
|
| 322 | + } |
|
| 323 | + if($format == "pem") { |
|
| 324 | + fwrite($f,$CA['pem']); |
|
| 325 | + } else { |
|
| 326 | + fwrite($f,$CA['der']); |
|
| 327 | + } |
|
| 311 | 328 | fclose($f); |
| 312 | 329 | $C = []; |
| 313 | 330 | $C['file'] = "cert-$i.crt"; |
@@ -340,8 +357,9 @@ discard block |
||
| 340 | 357 | $Inst_a = explode('_',$inst); |
| 341 | 358 | if(count($Inst_a) > 2) { |
| 342 | 359 | $inst = ''; |
| 343 | - foreach($Inst_a as $i) |
|
| 344 | - $inst .= $i[0]; |
|
| 360 | + foreach($Inst_a as $i) { |
|
| 361 | + $inst .= $i[0]; |
|
| 362 | + } |
|
| 345 | 363 | } |
| 346 | 364 | $c_name = iconv("UTF-8", "US-ASCII//TRANSLIT", preg_replace($replace_pattern, '_', Config::$CONSORTIUM['name'])); |
| 347 | 365 | if($this->attributes['internal:profile_count'][0] > 1) { |
@@ -356,10 +374,12 @@ discard block |
||
| 356 | 374 | |
| 357 | 375 | private function getDeviceId() { |
| 358 | 376 | $d_id = $this->device_id; |
| 359 | - if(isset($this->options['device_id'])) |
|
| 360 | - $d_id = $this->options['device_id']; |
|
| 361 | - if($d_id !== '') |
|
| 362 | - $d_id .= '-'; |
|
| 377 | + if(isset($this->options['device_id'])) { |
|
| 378 | + $d_id = $this->options['device_id']; |
|
| 379 | + } |
|
| 380 | + if($d_id !== '') { |
|
| 381 | + $d_id .= '-'; |
|
| 382 | + } |
|
| 363 | 383 | return $d_id; |
| 364 | 384 | } |
| 365 | 385 | |
@@ -369,9 +389,9 @@ discard block |
||
| 369 | 389 | $S['del']=[]; |
| 370 | 390 | if (isset(Config::$CONSORTIUM['ssid'])) { |
| 371 | 391 | foreach (Config::$CONSORTIUM['ssid'] as $ssid) { |
| 372 | - if(isset(Config::$CONSORTIUM['tkipsupport']) && Config::$CONSORTIUM['tkipsupport'] == TRUE) |
|
| 373 | - $S['add'][$ssid] = 'TKIP'; |
|
| 374 | - else { |
|
| 392 | + if(isset(Config::$CONSORTIUM['tkipsupport']) && Config::$CONSORTIUM['tkipsupport'] == TRUE) { |
|
| 393 | + $S['add'][$ssid] = 'TKIP'; |
|
| 394 | + } else { |
|
| 375 | 395 | $S['add'][$ssid] = 'AES'; |
| 376 | 396 | $S['del'][$ssid] = 'TKIP'; |
| 377 | 397 | } |
@@ -380,18 +400,21 @@ discard block |
||
| 380 | 400 | if(isset($this->attributes['media:SSID'])) { |
| 381 | 401 | $SSID = $this->attributes['media:SSID']; |
| 382 | 402 | |
| 383 | - foreach($SSID as $ssid) |
|
| 384 | - $S['add'][$ssid] = 'AES'; |
|
| 403 | + foreach($SSID as $ssid) { |
|
| 404 | + $S['add'][$ssid] = 'AES'; |
|
| 405 | + } |
|
| 385 | 406 | } |
| 386 | 407 | if(isset($this->attributes['media:SSID_with_legacy'])) { |
| 387 | 408 | $SSID = $this->attributes['media:SSID_with_legacy']; |
| 388 | - foreach($SSID as $ssid) |
|
| 389 | - $S['add'][$ssid] = 'TKIP'; |
|
| 409 | + foreach($SSID as $ssid) { |
|
| 410 | + $S['add'][$ssid] = 'TKIP'; |
|
| 411 | + } |
|
| 390 | 412 | } |
| 391 | 413 | if(isset($this->attributes['media:remove_SSID'])) { |
| 392 | 414 | $SSID = $this->attributes['media:remove_SSID']; |
| 393 | - foreach($SSID as $ssid) |
|
| 394 | - $S['del'][$ssid] = 'DEL'; |
|
| 415 | + foreach($SSID as $ssid) { |
|
| 416 | + $S['del'][$ssid] = 'DEL'; |
|
| 417 | + } |
|
| 395 | 418 | } |
| 396 | 419 | return $S; |
| 397 | 420 | } |
@@ -399,9 +422,10 @@ discard block |
||
| 399 | 422 | private function getConsortia() { |
| 400 | 423 | $OIs = []; |
| 401 | 424 | $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) |
|
| 425 | + if (isset($this->attributes['media:consortium_OI'])) { |
|
| 426 | + foreach ($this->attributes['media:consortium_OI'] as $new_oi) |
|
| 404 | 427 | $OIs[] = $new_oi; |
| 428 | + } |
|
| 405 | 429 | return $OIs; |
| 406 | 430 | } |
| 407 | 431 | |
@@ -421,10 +445,11 @@ discard block |
||
| 421 | 445 | foreach ($Logos as $blob) { |
| 422 | 446 | $finfo = new finfo(FILEINFO_MIME_TYPE); |
| 423 | 447 | $mime = $finfo->buffer($blob); |
| 424 | - if(preg_match('/^image\/(.*)/',$mime,$m)) |
|
| 425 | - $ext = $m[1]; |
|
| 426 | - else |
|
| 427 | - $ext = 'unsupported'; |
|
| 448 | + if(preg_match('/^image\/(.*)/',$mime,$m)) { |
|
| 449 | + $ext = $m[1]; |
|
| 450 | + } else { |
|
| 451 | + $ext = 'unsupported'; |
|
| 452 | + } |
|
| 428 | 453 | debug(4,"saveLogoFile: $mime : $ext\n"); |
| 429 | 454 | $f_name = 'logo-'.$i.'.'.$ext; |
| 430 | 455 | $f = fopen($f_name,"w"); |
@@ -447,7 +472,9 @@ discard block |
||
| 447 | 472 | $ext = isset($this->mime_extensions[$mime]) ? $this->mime_extensions[$mime] : 'usupported'; |
| 448 | 473 | debug(4,"saveInfoFile: $mime : $ext\n"); |
| 449 | 474 | $f = fopen('local-info.'.$ext,"w"); |
| 450 | - if(! $f) die("problem opening the file\n"); |
|
| 475 | + if(! $f) { |
|
| 476 | + die("problem opening the file\n"); |
|
| 477 | + } |
|
| 451 | 478 | fwrite($f,$blob); |
| 452 | 479 | fclose($f); |
| 453 | 480 | return(['name'=>'local-info.'.$ext,'mime'=>$ext]); |
@@ -6,10 +6,10 @@ discard block |
||
| 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 |
||
| 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,391 +58,391 @@ discard block |
||
| 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 | - $lang_pointer = Config::$LANGUAGES[$this->lang_index]['latin_based'] == TRUE ? 0 : 1; |
|
| 338 | - debug(4,"getInstallerBasename1:".$this->attributes['general:instname'][$lang_pointer]."\n"); |
|
| 339 | - $inst = iconv("UTF-8", "US-ASCII//TRANSLIT", preg_replace($replace_pattern, '_', $this->attributes['general:instname'][$lang_pointer])); |
|
| 340 | - debug(4,"getInstallerBasename2:$inst\n"); |
|
| 341 | - $Inst_a = explode('_',$inst); |
|
| 342 | - if(count($Inst_a) > 2) { |
|
| 343 | - $inst = ''; |
|
| 344 | - foreach($Inst_a as $i) |
|
| 345 | - $inst .= $i[0]; |
|
| 346 | - } |
|
| 347 | - $c_name = iconv("UTF-8", "US-ASCII//TRANSLIT", preg_replace($replace_pattern, '_', Config::$CONSORTIUM['name'])); |
|
| 348 | - if($this->attributes['internal:profile_count'][0] > 1) { |
|
| 349 | - if(!empty($this->attributes['profile:name']) && ! empty($this->attributes['profile:name'][$lang_pointer])) { |
|
| 350 | - $prof = iconv("UTF-8", "US-ASCII//TRANSLIT", preg_replace($replace_pattern, '_', $this->attributes['profile:name'][$lang_pointer])); |
|
| 351 | - $prof = preg_replace('/_+$/','',$prof); |
|
| 352 | - return $c_name. '-'. $this->getDeviceId() . $inst .'-'. $prof; |
|
| 353 | - } |
|
| 354 | - } |
|
| 355 | - return $c_name. '-'. $this->getDeviceId() . $inst; |
|
| 356 | - } |
|
| 357 | - |
|
| 358 | - 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 | + $lang_pointer = Config::$LANGUAGES[$this->lang_index]['latin_based'] == TRUE ? 0 : 1; |
|
| 338 | + debug(4,"getInstallerBasename1:".$this->attributes['general:instname'][$lang_pointer]."\n"); |
|
| 339 | + $inst = iconv("UTF-8", "US-ASCII//TRANSLIT", preg_replace($replace_pattern, '_', $this->attributes['general:instname'][$lang_pointer])); |
|
| 340 | + debug(4,"getInstallerBasename2:$inst\n"); |
|
| 341 | + $Inst_a = explode('_',$inst); |
|
| 342 | + if(count($Inst_a) > 2) { |
|
| 343 | + $inst = ''; |
|
| 344 | + foreach($Inst_a as $i) |
|
| 345 | + $inst .= $i[0]; |
|
| 346 | + } |
|
| 347 | + $c_name = iconv("UTF-8", "US-ASCII//TRANSLIT", preg_replace($replace_pattern, '_', Config::$CONSORTIUM['name'])); |
|
| 348 | + if($this->attributes['internal:profile_count'][0] > 1) { |
|
| 349 | + if(!empty($this->attributes['profile:name']) && ! empty($this->attributes['profile:name'][$lang_pointer])) { |
|
| 350 | + $prof = iconv("UTF-8", "US-ASCII//TRANSLIT", preg_replace($replace_pattern, '_', $this->attributes['profile:name'][$lang_pointer])); |
|
| 351 | + $prof = preg_replace('/_+$/','',$prof); |
|
| 352 | + return $c_name. '-'. $this->getDeviceId() . $inst .'-'. $prof; |
|
| 353 | + } |
|
| 354 | + } |
|
| 355 | + return $c_name. '-'. $this->getDeviceId() . $inst; |
|
| 356 | + } |
|
| 357 | + |
|
| 358 | + private function getDeviceId() { |
|
| 359 | 359 | $d_id = $this->device_id; |
| 360 | 360 | if(isset($this->options['device_id'])) |
| 361 | - $d_id = $this->options['device_id']; |
|
| 361 | + $d_id = $this->options['device_id']; |
|
| 362 | 362 | if($d_id !== '') |
| 363 | - $d_id .= '-'; |
|
| 363 | + $d_id .= '-'; |
|
| 364 | 364 | return $d_id; |
| 365 | - } |
|
| 365 | + } |
|
| 366 | 366 | |
| 367 | 367 | |
| 368 | - private function getSSIDs() { |
|
| 368 | + private function getSSIDs() { |
|
| 369 | 369 | $S['add']=[]; |
| 370 | 370 | $S['del']=[]; |
| 371 | 371 | if (isset(Config::$CONSORTIUM['ssid'])) { |
| 372 | - foreach (Config::$CONSORTIUM['ssid'] as $ssid) { |
|
| 372 | + foreach (Config::$CONSORTIUM['ssid'] as $ssid) { |
|
| 373 | 373 | if(isset(Config::$CONSORTIUM['tkipsupport']) && Config::$CONSORTIUM['tkipsupport'] == TRUE) |
| 374 | - $S['add'][$ssid] = 'TKIP'; |
|
| 374 | + $S['add'][$ssid] = 'TKIP'; |
|
| 375 | 375 | else { |
| 376 | - $S['add'][$ssid] = 'AES'; |
|
| 377 | - $S['del'][$ssid] = 'TKIP'; |
|
| 376 | + $S['add'][$ssid] = 'AES'; |
|
| 377 | + $S['del'][$ssid] = 'TKIP'; |
|
| 378 | + } |
|
| 378 | 379 | } |
| 379 | - } |
|
| 380 | 380 | } |
| 381 | 381 | if(isset($this->attributes['media:SSID'])) { |
| 382 | - $SSID = $this->attributes['media:SSID']; |
|
| 382 | + $SSID = $this->attributes['media:SSID']; |
|
| 383 | 383 | |
| 384 | - foreach($SSID as $ssid) |
|
| 385 | - $S['add'][$ssid] = 'AES'; |
|
| 386 | - } |
|
| 384 | + foreach($SSID as $ssid) |
|
| 385 | + $S['add'][$ssid] = 'AES'; |
|
| 386 | + } |
|
| 387 | 387 | if(isset($this->attributes['media:SSID_with_legacy'])) { |
| 388 | - $SSID = $this->attributes['media:SSID_with_legacy']; |
|
| 389 | - foreach($SSID as $ssid) |
|
| 390 | - $S['add'][$ssid] = 'TKIP'; |
|
| 388 | + $SSID = $this->attributes['media:SSID_with_legacy']; |
|
| 389 | + foreach($SSID as $ssid) |
|
| 390 | + $S['add'][$ssid] = 'TKIP'; |
|
| 391 | 391 | } |
| 392 | 392 | if(isset($this->attributes['media:remove_SSID'])) { |
| 393 | - $SSID = $this->attributes['media:remove_SSID']; |
|
| 394 | - foreach($SSID as $ssid) |
|
| 395 | - $S['del'][$ssid] = 'DEL'; |
|
| 393 | + $SSID = $this->attributes['media:remove_SSID']; |
|
| 394 | + foreach($SSID as $ssid) |
|
| 395 | + $S['del'][$ssid] = 'DEL'; |
|
| 396 | 396 | } |
| 397 | 397 | return $S; |
| 398 | - } |
|
| 398 | + } |
|
| 399 | 399 | |
| 400 | - private function getConsortia() { |
|
| 401 | - $OIs = []; |
|
| 402 | - $OIs = array_merge($OIs, Config::$CONSORTIUM['interworking-consortium-oi']); |
|
| 403 | - if (isset($this->attributes['media:consortium_OI'])) |
|
| 404 | - foreach ($this->attributes['media:consortium_OI'] as $new_oi) |
|
| 400 | + private function getConsortia() { |
|
| 401 | + $OIs = []; |
|
| 402 | + $OIs = array_merge($OIs, Config::$CONSORTIUM['interworking-consortium-oi']); |
|
| 403 | + if (isset($this->attributes['media:consortium_OI'])) |
|
| 404 | + foreach ($this->attributes['media:consortium_OI'] as $new_oi) |
|
| 405 | 405 | $OIs[] = $new_oi; |
| 406 | - return $OIs; |
|
| 407 | - } |
|
| 406 | + return $OIs; |
|
| 407 | + } |
|
| 408 | 408 | |
| 409 | - /** |
|
| 410 | - * An array with shorthand definitions for MIME types |
|
| 411 | - * @var array |
|
| 412 | - */ |
|
| 413 | - private $mime_extensions = [ |
|
| 414 | - 'text/plain' => 'txt', |
|
| 415 | - 'text/rtf' => 'rtf', |
|
| 416 | - 'application/pdf' =>'pdf', |
|
| 417 | - ]; |
|
| 418 | - |
|
| 419 | - private function saveLogoFile($Logos) { |
|
| 409 | + /** |
|
| 410 | + * An array with shorthand definitions for MIME types |
|
| 411 | + * @var array |
|
| 412 | + */ |
|
| 413 | + private $mime_extensions = [ |
|
| 414 | + 'text/plain' => 'txt', |
|
| 415 | + 'text/rtf' => 'rtf', |
|
| 416 | + 'application/pdf' =>'pdf', |
|
| 417 | + ]; |
|
| 418 | + |
|
| 419 | + private function saveLogoFile($Logos) { |
|
| 420 | 420 | $i=0; |
| 421 | 421 | $returnarray= []; |
| 422 | 422 | foreach ($Logos as $blob) { |
| 423 | - $finfo = new finfo(FILEINFO_MIME_TYPE); |
|
| 424 | - $mime = $finfo->buffer($blob); |
|
| 425 | - if(preg_match('/^image\/(.*)/',$mime,$m)) |
|
| 423 | + $finfo = new finfo(FILEINFO_MIME_TYPE); |
|
| 424 | + $mime = $finfo->buffer($blob); |
|
| 425 | + if(preg_match('/^image\/(.*)/',$mime,$m)) |
|
| 426 | 426 | $ext = $m[1]; |
| 427 | - else |
|
| 427 | + else |
|
| 428 | 428 | $ext = 'unsupported'; |
| 429 | - debug(4,"saveLogoFile: $mime : $ext\n"); |
|
| 430 | - $f_name = 'logo-'.$i.'.'.$ext; |
|
| 431 | - $f = fopen($f_name,"w"); |
|
| 432 | - if(! $f) { |
|
| 433 | - debug(2,"saveLogoFile failed for: $f_name\n"); |
|
| 434 | - die("problem opening the file\n"); |
|
| 435 | - } |
|
| 436 | - fwrite($f,$blob); |
|
| 437 | - fclose($f); |
|
| 438 | - $returnarray[]= ['name'=>$f_name,'mime'=>$ext]; |
|
| 439 | - $i++; |
|
| 429 | + debug(4,"saveLogoFile: $mime : $ext\n"); |
|
| 430 | + $f_name = 'logo-'.$i.'.'.$ext; |
|
| 431 | + $f = fopen($f_name,"w"); |
|
| 432 | + if(! $f) { |
|
| 433 | + debug(2,"saveLogoFile failed for: $f_name\n"); |
|
| 434 | + die("problem opening the file\n"); |
|
| 435 | + } |
|
| 436 | + fwrite($f,$blob); |
|
| 437 | + fclose($f); |
|
| 438 | + $returnarray[]= ['name'=>$f_name,'mime'=>$ext]; |
|
| 439 | + $i++; |
|
| 440 | 440 | } |
| 441 | 441 | return($returnarray); |
| 442 | - } |
|
| 442 | + } |
|
| 443 | 443 | |
| 444 | 444 | |
| 445 | - private function saveInfoFile($blob) { |
|
| 445 | + private function saveInfoFile($blob) { |
|
| 446 | 446 | $finfo = new finfo(FILEINFO_MIME_TYPE); |
| 447 | 447 | $mime = $finfo->buffer($blob); |
| 448 | 448 | $ext = isset($this->mime_extensions[$mime]) ? $this->mime_extensions[$mime] : 'usupported'; |
@@ -452,43 +452,43 @@ discard block |
||
| 452 | 452 | fwrite($f,$blob); |
| 453 | 453 | fclose($f); |
| 454 | 454 | return(['name'=>'local-info.'.$ext,'mime'=>$ext]); |
| 455 | - } |
|
| 456 | - |
|
| 457 | - private function getProfileAttributes(Profile $profile) { |
|
| 458 | - $eaps = $profile->getEapMethodsinOrderOfPreference(1); |
|
| 459 | - if($eap = $this->getPreferredEapType($eaps)) { |
|
| 460 | - $a = $profile->getCollapsedAttributes($eap); |
|
| 461 | - $a['eap'] = $eap; |
|
| 462 | - $a['all_eaps'] = $eaps; |
|
| 463 | - return($a); |
|
| 464 | - } else { |
|
| 465 | - error("No supported eap types found for this profile."); |
|
| 466 | - return(FALSE); |
|
| 467 | - } |
|
| 468 | - } |
|
| 455 | + } |
|
| 456 | + |
|
| 457 | + private function getProfileAttributes(Profile $profile) { |
|
| 458 | + $eaps = $profile->getEapMethodsinOrderOfPreference(1); |
|
| 459 | + if($eap = $this->getPreferredEapType($eaps)) { |
|
| 460 | + $a = $profile->getCollapsedAttributes($eap); |
|
| 461 | + $a['eap'] = $eap; |
|
| 462 | + $a['all_eaps'] = $eaps; |
|
| 463 | + return($a); |
|
| 464 | + } else { |
|
| 465 | + error("No supported eap types found for this profile."); |
|
| 466 | + return(FALSE); |
|
| 467 | + } |
|
| 468 | + } |
|
| 469 | 469 | /** |
| 470 | - * dumps attributes for debugging purposes |
|
| 471 | - * |
|
| 472 | - * dumpAttibutes method is supplied for debuging purposes, it simply dumps the attribute array |
|
| 473 | - * to a file with name passed in the attribute. |
|
| 474 | - * @param string $file the output file name |
|
| 475 | - */ |
|
| 476 | - protected function dumpAttibutes($file) { |
|
| 470 | + * dumps attributes for debugging purposes |
|
| 471 | + * |
|
| 472 | + * dumpAttibutes method is supplied for debuging purposes, it simply dumps the attribute array |
|
| 473 | + * to a file with name passed in the attribute. |
|
| 474 | + * @param string $file the output file name |
|
| 475 | + */ |
|
| 476 | + protected function dumpAttibutes($file) { |
|
| 477 | 477 | ob_start(); |
| 478 | 478 | print_r($this->attributes); |
| 479 | 479 | $output = ob_get_clean(); |
| 480 | 480 | $f = fopen($file,"w"); |
| 481 | 481 | fwrite($f,$output); |
| 482 | 482 | fclose($f); |
| 483 | - } |
|
| 483 | + } |
|
| 484 | 484 | /** |
| 485 | - * placeholder for the main device method |
|
| 486 | - * |
|
| 487 | - */ |
|
| 485 | + * placeholder for the main device method |
|
| 486 | + * |
|
| 487 | + */ |
|
| 488 | 488 | |
| 489 | - protected function writeInstaller() { |
|
| 490 | - return("download path"); |
|
| 491 | - } |
|
| 489 | + protected function writeInstaller() { |
|
| 490 | + return("download path"); |
|
| 491 | + } |
|
| 492 | 492 | |
| 493 | 493 | /** |
| 494 | 494 | * Array passing all options to the device module. |
@@ -522,75 +522,75 @@ discard block |
||
| 522 | 522 | * @see X509::processCertificate() |
| 523 | 523 | * @var array $attributes |
| 524 | 524 | */ |
| 525 | - public $attributes; |
|
| 525 | + public $attributes; |
|
| 526 | 526 | /** |
| 527 | - * stores the path to the module source location and is used |
|
| 528 | - * by copyFile and translateFile |
|
| 529 | - * the only reason for it to be a public variable ies that it is set by the DeviceFactory class |
|
| 530 | - * module_path should not be used by module drivers. |
|
| 531 | - * @var string |
|
| 532 | - */ |
|
| 533 | - public $module_path; |
|
| 527 | + * stores the path to the module source location and is used |
|
| 528 | + * by copyFile and translateFile |
|
| 529 | + * the only reason for it to be a public variable ies that it is set by the DeviceFactory class |
|
| 530 | + * module_path should not be used by module drivers. |
|
| 531 | + * @var string |
|
| 532 | + */ |
|
| 533 | + public $module_path; |
|
| 534 | 534 | |
| 535 | 535 | /** |
| 536 | 536 | * The optimal EAP type |
| 537 | 537 | * |
| 538 | 538 | */ |
| 539 | 539 | /** |
| 540 | - * optimal EAP method selected given profile and device |
|
| 541 | - * @var EAP::constant |
|
| 542 | - */ |
|
| 543 | - public $selected_eap; |
|
| 540 | + * optimal EAP method selected given profile and device |
|
| 541 | + * @var EAP::constant |
|
| 542 | + */ |
|
| 543 | + public $selected_eap; |
|
| 544 | 544 | /** |
| 545 | - * the path to the profile signing program |
|
| 546 | - * device modules which require signing should use this property to exec the signer |
|
| 547 | - * the signer program must accept two arguments - input and output file names |
|
| 548 | - * the signer program mus operate in the local directory and filenames are relative to this |
|
| 549 | - * directory |
|
| 550 | - * |
|
| 551 | - *@var string |
|
| 552 | - */ |
|
| 553 | - public $sign; |
|
| 554 | - public $signer; |
|
| 545 | + * the path to the profile signing program |
|
| 546 | + * device modules which require signing should use this property to exec the signer |
|
| 547 | + * the signer program must accept two arguments - input and output file names |
|
| 548 | + * the signer program mus operate in the local directory and filenames are relative to this |
|
| 549 | + * directory |
|
| 550 | + * |
|
| 551 | + *@var string |
|
| 552 | + */ |
|
| 553 | + public $sign; |
|
| 554 | + public $signer; |
|
| 555 | 555 | /** |
| 556 | - * the string referencing the language (index ot the Config::$LANGUAGES array). |
|
| 557 | - * It is set to the current language and may be used by the device module to |
|
| 558 | - * set its language |
|
| 559 | - * |
|
| 560 | - *@var string |
|
| 561 | - */ |
|
| 562 | - public $lang_index; |
|
| 563 | - /** |
|
| 564 | - * The string identifier of the device (don't show this to users) |
|
| 565 | - * @var string |
|
| 566 | - */ |
|
| 567 | - public $device_id; |
|
| 568 | - |
|
| 569 | - /** |
|
| 570 | - * See devices-template.php for a list of available options |
|
| 571 | - * @var array |
|
| 572 | - */ |
|
| 573 | - public $options; |
|
| 574 | - |
|
| 575 | - /** |
|
| 576 | - * This string will be shown if no support email was configured by the admin |
|
| 577 | - * |
|
| 578 | - * @var string |
|
| 579 | - */ |
|
| 580 | - public static $support_email_substitute; |
|
| 581 | - |
|
| 582 | - /** |
|
| 583 | - * This string will be shown if no support URL was configured by the admin |
|
| 584 | - * |
|
| 585 | - * @var string |
|
| 586 | - */ |
|
| 587 | - public static $support_url_substitute; |
|
| 588 | - |
|
| 589 | - /** |
|
| 590 | - * This string should be used by all installer modules to set the |
|
| 591 | - * installer file basename. |
|
| 592 | - * |
|
| 593 | - * @var string |
|
| 594 | - */ |
|
| 595 | - public static $installerBasename; |
|
| 556 | + * the string referencing the language (index ot the Config::$LANGUAGES array). |
|
| 557 | + * It is set to the current language and may be used by the device module to |
|
| 558 | + * set its language |
|
| 559 | + * |
|
| 560 | + *@var string |
|
| 561 | + */ |
|
| 562 | + public $lang_index; |
|
| 563 | + /** |
|
| 564 | + * The string identifier of the device (don't show this to users) |
|
| 565 | + * @var string |
|
| 566 | + */ |
|
| 567 | + public $device_id; |
|
| 568 | + |
|
| 569 | + /** |
|
| 570 | + * See devices-template.php for a list of available options |
|
| 571 | + * @var array |
|
| 572 | + */ |
|
| 573 | + public $options; |
|
| 574 | + |
|
| 575 | + /** |
|
| 576 | + * This string will be shown if no support email was configured by the admin |
|
| 577 | + * |
|
| 578 | + * @var string |
|
| 579 | + */ |
|
| 580 | + public static $support_email_substitute; |
|
| 581 | + |
|
| 582 | + /** |
|
| 583 | + * This string will be shown if no support URL was configured by the admin |
|
| 584 | + * |
|
| 585 | + * @var string |
|
| 586 | + */ |
|
| 587 | + public static $support_url_substitute; |
|
| 588 | + |
|
| 589 | + /** |
|
| 590 | + * This string should be used by all installer modules to set the |
|
| 591 | + * installer file basename. |
|
| 592 | + * |
|
| 593 | + * @var string |
|
| 594 | + */ |
|
| 595 | + public static $installerBasename; |
|
| 596 | 596 | } |
@@ -63,9 +63,9 @@ discard block |
||
| 63 | 63 | */ |
| 64 | 64 | |
| 65 | 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); |
|
| 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 | |
@@ -88,50 +88,50 @@ discard block |
||
| 88 | 88 | * @final not to be redefined |
| 89 | 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"); |
|
| 91 | + debug(4, "module setup start\n"); |
|
| 92 | + if (!$profile instanceof Profile) { |
|
| 93 | + debug(2, "No profile has been set\n"); |
|
| 94 | 94 | error("No profile has been set"); |
| 95 | 95 | exit; |
| 96 | 96 | } |
| 97 | 97 | $this->attributes = $this->getProfileAttributes($profile); |
| 98 | - if(! $this->selected_eap) { |
|
| 98 | + if (!$this->selected_eap) { |
|
| 99 | 99 | error("No EAP type specified."); |
| 100 | 100 | exit; |
| 101 | 101 | } |
| 102 | 102 | // create temporary directory, its full path will be saved in $this->FPATH; |
| 103 | 103 | $T = createTemporaryDirectory('installer'); |
| 104 | 104 | $this->FPATH = $T['dir']; |
| 105 | - mkdir($T['dir'].'/tmp'); |
|
| 106 | - chdir($T['dir'].'/tmp'); |
|
| 105 | + mkdir($T['dir'] . '/tmp'); |
|
| 106 | + chdir($T['dir'] . '/tmp'); |
|
| 107 | 107 | $CAs = []; |
| 108 | - if(isset($this->attributes['eap:ca_file'])) { |
|
| 108 | + if (isset($this->attributes['eap:ca_file'])) { |
|
| 109 | 109 | foreach ($this->attributes['eap:ca_file'] as $ca) { |
| 110 | - if($c = X509::processCertificate($ca)) |
|
| 110 | + if ($c = X509::processCertificate($ca)) |
|
| 111 | 111 | $CAs[] = $c; |
| 112 | 112 | } |
| 113 | - $this->attributes['internal:CAs'][0]=$CAs; |
|
| 113 | + $this->attributes['internal:CAs'][0] = $CAs; |
|
| 114 | 114 | } |
| 115 | - if(isset($this->attributes['support:info_file'])) { |
|
| 115 | + if (isset($this->attributes['support:info_file'])) { |
|
| 116 | 116 | $this->attributes['internal:info_file'][0] = |
| 117 | 117 | $this->saveInfoFile($this->attributes['support:info_file'][0]); |
| 118 | 118 | } |
| 119 | - if(isset($this->attributes['general:logo_file'])) |
|
| 119 | + if (isset($this->attributes['general:logo_file'])) |
|
| 120 | 120 | $this->attributes['internal:logo_file'] = |
| 121 | 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'];; |
|
| 122 | + $this->attributes['internal:SSID'] = $this->getSSIDs()['add']; ; |
|
| 123 | + $this->attributes['internal:remove_SSID'] = $this->getSSIDs()['del']; ; |
|
| 124 | 124 | $this->attributes['internal:consortia'] = $this->getConsortia(); |
| 125 | 125 | $this->lang_index = CAT::get_lang(); |
| 126 | 126 | // phpMD says the below is not needed. Wow. |
| 127 | 127 | // $idp = new IdP($profile->institution); |
| 128 | 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']); |
|
| 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 | 131 | CAT::set_locale($olddomain); |
| 132 | 132 | |
| 133 | - if($this->signer && $this->options['sign']) |
|
| 134 | - $this->sign = CAT::$root . '/signer/'. $this->signer; |
|
| 133 | + if ($this->signer && $this->options['sign']) |
|
| 134 | + $this->sign = CAT::$root . '/signer/' . $this->signer; |
|
| 135 | 135 | $this->installerBasename = $this->getInstallerBasename(); |
| 136 | 136 | } |
| 137 | 137 | |
@@ -143,10 +143,10 @@ discard block |
||
| 143 | 143 | */ |
| 144 | 144 | public function getPreferredEapType($eap_array) { |
| 145 | 145 | foreach ($eap_array as $eap) { |
| 146 | - if(in_array($eap,$this->supportedEapMethods)) { |
|
| 146 | + if (in_array($eap, $this->supportedEapMethods)) { |
|
| 147 | 147 | $this->selected_eap = $eap; |
| 148 | - debug(4,"Selected EAP:"); |
|
| 149 | - debug(4,$eap); |
|
| 148 | + debug(4, "Selected EAP:"); |
|
| 149 | + debug(4, $eap); |
|
| 150 | 150 | return($eap); |
| 151 | 151 | } |
| 152 | 152 | } |
@@ -178,22 +178,22 @@ discard block |
||
| 178 | 178 | * @final not to be redefined |
| 179 | 179 | */ |
| 180 | 180 | final protected function copyFile($source_name, $output_name = 0) { |
| 181 | - if ( $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; |
|
| 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 | 189 | else { |
| 190 | - debug(2,"fileCopy:reqested file $source_name does not exist\n"); |
|
| 190 | + debug(2, "fileCopy:reqested file $source_name does not exist\n"); |
|
| 191 | 191 | return(FALSE); |
| 192 | 192 | } |
| 193 | - debug(4,"Copying $source to $output_name\n"); |
|
| 194 | - $result = copy($source,"$output_name"); |
|
| 195 | - if(! $result ) |
|
| 196 | - debug(2,"fileCopy($source_name, $output_name) failed\n"); |
|
| 193 | + debug(4, "Copying $source to $output_name\n"); |
|
| 194 | + $result = copy($source, "$output_name"); |
|
| 195 | + if (!$result) |
|
| 196 | + debug(2, "fileCopy($source_name, $output_name) failed\n"); |
|
| 197 | 197 | return($result); |
| 198 | 198 | } |
| 199 | 199 | |
@@ -223,31 +223,31 @@ discard block |
||
| 223 | 223 | */ |
| 224 | 224 | |
| 225 | 225 | final protected function translateFile($source_name, $output_name = 0, $encoding = 0) { |
| 226 | - if(Config::$NSIS_VERSION >= 3) |
|
| 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"); |
|
| 231 | + debug(4, "translateFile($source_name, $output_name, $encoding)\n"); |
|
| 232 | 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; |
|
| 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 | 238 | include($source); |
| 239 | 239 | $output = ob_get_clean(); |
| 240 | - if($encoding) { |
|
| 241 | - $output_c = iconv('UTF-8',$encoding.'//TRANSLIT',$output); |
|
| 242 | - if($output_c) |
|
| 240 | + if ($encoding) { |
|
| 241 | + $output_c = iconv('UTF-8', $encoding . '//TRANSLIT', $output); |
|
| 242 | + if ($output_c) |
|
| 243 | 243 | $output = $output_c; |
| 244 | 244 | } |
| 245 | - $f = fopen("$output_name","w"); |
|
| 246 | - if(! $f) |
|
| 247 | - debug(2,"translateFile($source, $output_name, $encoding) failed\n"); |
|
| 248 | - fwrite($f,$output); |
|
| 245 | + $f = fopen("$output_name", "w"); |
|
| 246 | + if (!$f) |
|
| 247 | + debug(2, "translateFile($source, $output_name, $encoding) failed\n"); |
|
| 248 | + fwrite($f, $output); |
|
| 249 | 249 | fclose($f); |
| 250 | - debug(4,"translateFile($source, $output_name, $encoding) end\n"); |
|
| 250 | + debug(4, "translateFile($source, $output_name, $encoding) end\n"); |
|
| 251 | 251 | } |
| 252 | 252 | |
| 253 | 253 | |
@@ -268,17 +268,17 @@ discard block |
||
| 268 | 268 | * @final not to be redefined |
| 269 | 269 | */ |
| 270 | 270 | |
| 271 | - final protected function translateString($source_string,$encoding = 0) { |
|
| 272 | - if(Config::$NSIS_VERSION >= 3) |
|
| 271 | + final protected function translateString($source_string, $encoding = 0) { |
|
| 272 | + if (Config::$NSIS_VERSION >= 3) |
|
| 273 | 273 | $encoding = 0; |
| 274 | - if($encoding) |
|
| 275 | - $output_c = iconv('UTF-8',$encoding.'//TRANSLIT',$source_string); |
|
| 274 | + if ($encoding) |
|
| 275 | + $output_c = iconv('UTF-8', $encoding . '//TRANSLIT', $source_string); |
|
| 276 | 276 | else |
| 277 | 277 | $output_c = $source_string; |
| 278 | - if($output_c) |
|
| 279 | - $source_string = str_replace('"','$\\"',$output_c); |
|
| 278 | + if ($output_c) |
|
| 279 | + $source_string = str_replace('"', '$\\"', $output_c); |
|
| 280 | 280 | else |
| 281 | - debug(2,"Failed to convert string $source_string\n"); |
|
| 281 | + debug(2, "Failed to convert string $source_string\n"); |
|
| 282 | 282 | return $source_string; |
| 283 | 283 | } |
| 284 | 284 | |
@@ -295,19 +295,19 @@ discard block |
||
| 295 | 295 | * root is set to 1 for the CA roor certicicate and 0 otherwise |
| 296 | 296 | */ |
| 297 | 297 | final protected function saveCertificateFiles($format) { |
| 298 | - if($format == 'der' || $format == 'pam') { |
|
| 298 | + if ($format == 'der' || $format == 'pam') { |
|
| 299 | 299 | $i = 0; |
| 300 | 300 | $CA_files = []; |
| 301 | 301 | $ca_array = $this->attributes['internal:CAs'][0]; |
| 302 | - if(! $ca_array) |
|
| 302 | + if (!$ca_array) |
|
| 303 | 303 | return(FALSE); |
| 304 | 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 | - fwrite($f,$CA['pem']); |
|
| 305 | + $f = fopen("cert-$i.crt", "w"); |
|
| 306 | + if (!$f) die("problem opening the file\n"); |
|
| 307 | + if ($format == "pem") |
|
| 308 | + fwrite($f, $CA['pem']); |
|
| 309 | 309 | else |
| 310 | - fwrite($f,$CA['der']); |
|
| 310 | + fwrite($f, $CA['der']); |
|
| 311 | 311 | fclose($f); |
| 312 | 312 | $C = []; |
| 313 | 313 | $C['file'] = "cert-$i.crt"; |
@@ -335,42 +335,42 @@ discard block |
||
| 335 | 335 | private function getInstallerBasename() { |
| 336 | 336 | $replace_pattern = '/[ ()\/\'"]+/'; |
| 337 | 337 | $lang_pointer = Config::$LANGUAGES[$this->lang_index]['latin_based'] == TRUE ? 0 : 1; |
| 338 | - debug(4,"getInstallerBasename1:".$this->attributes['general:instname'][$lang_pointer]."\n"); |
|
| 338 | + debug(4, "getInstallerBasename1:" . $this->attributes['general:instname'][$lang_pointer] . "\n"); |
|
| 339 | 339 | $inst = iconv("UTF-8", "US-ASCII//TRANSLIT", preg_replace($replace_pattern, '_', $this->attributes['general:instname'][$lang_pointer])); |
| 340 | - debug(4,"getInstallerBasename2:$inst\n"); |
|
| 341 | - $Inst_a = explode('_',$inst); |
|
| 342 | - if(count($Inst_a) > 2) { |
|
| 340 | + debug(4, "getInstallerBasename2:$inst\n"); |
|
| 341 | + $Inst_a = explode('_', $inst); |
|
| 342 | + if (count($Inst_a) > 2) { |
|
| 343 | 343 | $inst = ''; |
| 344 | - foreach($Inst_a as $i) |
|
| 344 | + foreach ($Inst_a as $i) |
|
| 345 | 345 | $inst .= $i[0]; |
| 346 | 346 | } |
| 347 | 347 | $c_name = iconv("UTF-8", "US-ASCII//TRANSLIT", preg_replace($replace_pattern, '_', Config::$CONSORTIUM['name'])); |
| 348 | - if($this->attributes['internal:profile_count'][0] > 1) { |
|
| 349 | - if(!empty($this->attributes['profile:name']) && ! empty($this->attributes['profile:name'][$lang_pointer])) { |
|
| 348 | + if ($this->attributes['internal:profile_count'][0] > 1) { |
|
| 349 | + if (!empty($this->attributes['profile:name']) && !empty($this->attributes['profile:name'][$lang_pointer])) { |
|
| 350 | 350 | $prof = iconv("UTF-8", "US-ASCII//TRANSLIT", preg_replace($replace_pattern, '_', $this->attributes['profile:name'][$lang_pointer])); |
| 351 | - $prof = preg_replace('/_+$/','',$prof); |
|
| 352 | - return $c_name. '-'. $this->getDeviceId() . $inst .'-'. $prof; |
|
| 351 | + $prof = preg_replace('/_+$/', '', $prof); |
|
| 352 | + return $c_name . '-' . $this->getDeviceId() . $inst . '-' . $prof; |
|
| 353 | 353 | } |
| 354 | 354 | } |
| 355 | - return $c_name. '-'. $this->getDeviceId() . $inst; |
|
| 355 | + return $c_name . '-' . $this->getDeviceId() . $inst; |
|
| 356 | 356 | } |
| 357 | 357 | |
| 358 | 358 | private function getDeviceId() { |
| 359 | 359 | $d_id = $this->device_id; |
| 360 | - if(isset($this->options['device_id'])) |
|
| 360 | + if (isset($this->options['device_id'])) |
|
| 361 | 361 | $d_id = $this->options['device_id']; |
| 362 | - if($d_id !== '') |
|
| 362 | + if ($d_id !== '') |
|
| 363 | 363 | $d_id .= '-'; |
| 364 | 364 | return $d_id; |
| 365 | 365 | } |
| 366 | 366 | |
| 367 | 367 | |
| 368 | 368 | private function getSSIDs() { |
| 369 | - $S['add']=[]; |
|
| 370 | - $S['del']=[]; |
|
| 369 | + $S['add'] = []; |
|
| 370 | + $S['del'] = []; |
|
| 371 | 371 | if (isset(Config::$CONSORTIUM['ssid'])) { |
| 372 | 372 | foreach (Config::$CONSORTIUM['ssid'] as $ssid) { |
| 373 | - if(isset(Config::$CONSORTIUM['tkipsupport']) && Config::$CONSORTIUM['tkipsupport'] == TRUE) |
|
| 373 | + if (isset(Config::$CONSORTIUM['tkipsupport']) && Config::$CONSORTIUM['tkipsupport'] == TRUE) |
|
| 374 | 374 | $S['add'][$ssid] = 'TKIP'; |
| 375 | 375 | else { |
| 376 | 376 | $S['add'][$ssid] = 'AES'; |
@@ -378,20 +378,20 @@ discard block |
||
| 378 | 378 | } |
| 379 | 379 | } |
| 380 | 380 | } |
| 381 | - if(isset($this->attributes['media:SSID'])) { |
|
| 381 | + if (isset($this->attributes['media:SSID'])) { |
|
| 382 | 382 | $SSID = $this->attributes['media:SSID']; |
| 383 | 383 | |
| 384 | - foreach($SSID as $ssid) |
|
| 384 | + foreach ($SSID as $ssid) |
|
| 385 | 385 | $S['add'][$ssid] = 'AES'; |
| 386 | 386 | } |
| 387 | - if(isset($this->attributes['media:SSID_with_legacy'])) { |
|
| 387 | + if (isset($this->attributes['media:SSID_with_legacy'])) { |
|
| 388 | 388 | $SSID = $this->attributes['media:SSID_with_legacy']; |
| 389 | - foreach($SSID as $ssid) |
|
| 389 | + foreach ($SSID as $ssid) |
|
| 390 | 390 | $S['add'][$ssid] = 'TKIP'; |
| 391 | 391 | } |
| 392 | - if(isset($this->attributes['media:remove_SSID'])) { |
|
| 392 | + if (isset($this->attributes['media:remove_SSID'])) { |
|
| 393 | 393 | $SSID = $this->attributes['media:remove_SSID']; |
| 394 | - foreach($SSID as $ssid) |
|
| 394 | + foreach ($SSID as $ssid) |
|
| 395 | 395 | $S['del'][$ssid] = 'DEL'; |
| 396 | 396 | } |
| 397 | 397 | return $S; |
@@ -417,25 +417,25 @@ discard block |
||
| 417 | 417 | ]; |
| 418 | 418 | |
| 419 | 419 | private function saveLogoFile($Logos) { |
| 420 | - $i=0; |
|
| 421 | - $returnarray= []; |
|
| 420 | + $i = 0; |
|
| 421 | + $returnarray = []; |
|
| 422 | 422 | foreach ($Logos as $blob) { |
| 423 | 423 | $finfo = new finfo(FILEINFO_MIME_TYPE); |
| 424 | 424 | $mime = $finfo->buffer($blob); |
| 425 | - if(preg_match('/^image\/(.*)/',$mime,$m)) |
|
| 425 | + if (preg_match('/^image\/(.*)/', $mime, $m)) |
|
| 426 | 426 | $ext = $m[1]; |
| 427 | 427 | else |
| 428 | 428 | $ext = 'unsupported'; |
| 429 | - debug(4,"saveLogoFile: $mime : $ext\n"); |
|
| 430 | - $f_name = 'logo-'.$i.'.'.$ext; |
|
| 431 | - $f = fopen($f_name,"w"); |
|
| 432 | - if(! $f) { |
|
| 433 | - debug(2,"saveLogoFile failed for: $f_name\n"); |
|
| 429 | + debug(4, "saveLogoFile: $mime : $ext\n"); |
|
| 430 | + $f_name = 'logo-' . $i . '.' . $ext; |
|
| 431 | + $f = fopen($f_name, "w"); |
|
| 432 | + if (!$f) { |
|
| 433 | + debug(2, "saveLogoFile failed for: $f_name\n"); |
|
| 434 | 434 | die("problem opening the file\n"); |
| 435 | 435 | } |
| 436 | - fwrite($f,$blob); |
|
| 436 | + fwrite($f, $blob); |
|
| 437 | 437 | fclose($f); |
| 438 | - $returnarray[]= ['name'=>$f_name,'mime'=>$ext]; |
|
| 438 | + $returnarray[] = ['name'=>$f_name, 'mime'=>$ext]; |
|
| 439 | 439 | $i++; |
| 440 | 440 | } |
| 441 | 441 | return($returnarray); |
@@ -446,17 +446,17 @@ discard block |
||
| 446 | 446 | $finfo = new finfo(FILEINFO_MIME_TYPE); |
| 447 | 447 | $mime = $finfo->buffer($blob); |
| 448 | 448 | $ext = isset($this->mime_extensions[$mime]) ? $this->mime_extensions[$mime] : 'usupported'; |
| 449 | - debug(4,"saveInfoFile: $mime : $ext\n"); |
|
| 450 | - $f = fopen('local-info.'.$ext,"w"); |
|
| 451 | - if(! $f) die("problem opening the file\n"); |
|
| 452 | - fwrite($f,$blob); |
|
| 449 | + debug(4, "saveInfoFile: $mime : $ext\n"); |
|
| 450 | + $f = fopen('local-info.' . $ext, "w"); |
|
| 451 | + if (!$f) die("problem opening the file\n"); |
|
| 452 | + fwrite($f, $blob); |
|
| 453 | 453 | fclose($f); |
| 454 | - return(['name'=>'local-info.'.$ext,'mime'=>$ext]); |
|
| 454 | + return(['name'=>'local-info.' . $ext, 'mime'=>$ext]); |
|
| 455 | 455 | } |
| 456 | 456 | |
| 457 | 457 | private function getProfileAttributes(Profile $profile) { |
| 458 | 458 | $eaps = $profile->getEapMethodsinOrderOfPreference(1); |
| 459 | - if($eap = $this->getPreferredEapType($eaps)) { |
|
| 459 | + if ($eap = $this->getPreferredEapType($eaps)) { |
|
| 460 | 460 | $a = $profile->getCollapsedAttributes($eap); |
| 461 | 461 | $a['eap'] = $eap; |
| 462 | 462 | $a['all_eaps'] = $eaps; |
@@ -477,8 +477,8 @@ discard block |
||
| 477 | 477 | ob_start(); |
| 478 | 478 | print_r($this->attributes); |
| 479 | 479 | $output = ob_get_clean(); |
| 480 | - $f = fopen($file,"w"); |
|
| 481 | - fwrite($f,$output); |
|
| 480 | + $f = fopen($file, "w"); |
|
| 481 | + fwrite($f, $output); |
|
| 482 | 482 | fclose($f); |
| 483 | 483 | } |
| 484 | 484 | /** |
@@ -32,6 +32,7 @@ discard block |
||
| 32 | 32 | /** |
| 33 | 33 | * write debug messages to the log |
| 34 | 34 | * |
| 35 | + * @param integer $level |
|
| 35 | 36 | */ |
| 36 | 37 | function debug($level, $t) { |
| 37 | 38 | if (Config::$DEBUG_LEVEL >= $level) { |
@@ -130,7 +131,7 @@ discard block |
||
| 130 | 131 | * generates a UUID |
| 131 | 132 | * |
| 132 | 133 | * @param string $prefix an extra prefix to set before the UUID |
| 133 | - * @return UUID (possibly prefixed) |
|
| 134 | + * @return string (possibly prefixed) |
|
| 134 | 135 | */ |
| 135 | 136 | function uuid($prefix = '', $deterministic_source = NULL) { |
| 136 | 137 | if ($deterministic_source === NULL) |
@@ -180,32 +180,32 @@ discard block |
||
| 180 | 180 | function createTemporaryDirectory($purpose = 'installer',$fail = 1) { |
| 181 | 181 | $name = md5(time().rand()); |
| 182 | 182 | switch($purpose) { |
| 183 | - case 'installer': |
|
| 183 | + case 'installer': |
|
| 184 | 184 | $path = CAT::$root.'/var/installer_cache'; |
| 185 | - break; |
|
| 186 | - case 'logo': |
|
| 185 | + break; |
|
| 186 | + case 'logo': |
|
| 187 | 187 | $path = CAT::$root.'/web/downloads/logos'; |
| 188 | - break; |
|
| 189 | - case 'test': |
|
| 188 | + break; |
|
| 189 | + case 'test': |
|
| 190 | 190 | $path = CAT::$root.'/var/tmp'; |
| 191 | - break; |
|
| 192 | - default: |
|
| 191 | + break; |
|
| 192 | + default: |
|
| 193 | 193 | error("unable to create temporary directory for unknown purpose: $purpose\n"); |
| 194 | - exit; |
|
| 194 | + exit; |
|
| 195 | 195 | } |
| 196 | 196 | $tmp_dir = $path .'/'. $name; |
| 197 | 197 | debug(4,"temp dir: $purpose : $tmp_dir\n"); |
| 198 | 198 | if(! mkdir($tmp_dir,0700, true)) { |
| 199 | - if($fail) { |
|
| 200 | - error("unable to create temporary directory: $tmp_dir\n"); |
|
| 201 | - exit; |
|
| 202 | - } else { |
|
| 199 | + if($fail) { |
|
| 200 | + error("unable to create temporary directory: $tmp_dir\n"); |
|
| 201 | + exit; |
|
| 202 | + } else { |
|
| 203 | 203 | debug(4, "Directory creation failed for $tmp_dir\n"); |
| 204 | 204 | return ['base'=>$path,'dir'=>'',$name=>'']; |
| 205 | - } |
|
| 205 | + } |
|
| 206 | 206 | } else |
| 207 | - debug(4, "Directory created: $tmp_dir\n"); |
|
| 208 | - return ['base'=>$path,'dir'=>$tmp_dir,'name'=>$name]; |
|
| 207 | + debug(4, "Directory created: $tmp_dir\n"); |
|
| 208 | + return ['base'=>$path,'dir'=>$tmp_dir,'name'=>$name]; |
|
| 209 | 209 | } |
| 210 | 210 | |
| 211 | 211 | function png_inject_consortium_logo ($inputpngstring, $symbolsize = 12, $marginsymbols = 4) { |
@@ -236,7 +236,7 @@ discard block |
||
| 236 | 236 | $targetplacementy = $symbolsize * round(($sizeinput[1] / 2 - ($targetheight - $symbolsize) / 2)/$symbolsize); |
| 237 | 237 | imagecopyresized($inputgd, $whiteimage, $targetplacementx-$symbolsize, $targetplacementy-$symbolsize, 0, 0, $targetwidth+2*$symbolsize, $targetheight+2*$symbolsize, $targetwidth+2*$symbolsize, $targetheight+2*$symbolsize); |
| 238 | 238 | imagecopyresized($inputgd, $logogd, $targetplacementx, $targetplacementy, 0, 0, $targetwidth , $targetheight , $sizelogo[0] , $sizelogo[1]); |
| 239 | - // imagecopyresized($dst_image, $src_image, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h); |
|
| 239 | + // imagecopyresized($dst_image, $src_image, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h); |
|
| 240 | 240 | ob_start(); |
| 241 | 241 | imagepng($inputgd); |
| 242 | 242 | return ob_get_clean(); |
@@ -177,65 +177,65 @@ |
||
| 177 | 177 | * @param $fail (default true) decides if a creation failure should cause an error |
| 178 | 178 | * @return - the tupple full directory path, directory name |
| 179 | 179 | */ |
| 180 | -function createTemporaryDirectory($purpose = 'installer',$fail = 1) { |
|
| 181 | - $name = md5(time().rand()); |
|
| 182 | - switch($purpose) { |
|
| 180 | +function createTemporaryDirectory($purpose = 'installer', $fail = 1) { |
|
| 181 | + $name = md5(time() . rand()); |
|
| 182 | + switch ($purpose) { |
|
| 183 | 183 | case 'installer': |
| 184 | - $path = CAT::$root.'/var/installer_cache'; |
|
| 184 | + $path = CAT::$root . '/var/installer_cache'; |
|
| 185 | 185 | break; |
| 186 | 186 | case 'logo': |
| 187 | - $path = CAT::$root.'/web/downloads/logos'; |
|
| 187 | + $path = CAT::$root . '/web/downloads/logos'; |
|
| 188 | 188 | break; |
| 189 | 189 | case 'test': |
| 190 | - $path = CAT::$root.'/var/tmp'; |
|
| 190 | + $path = CAT::$root . '/var/tmp'; |
|
| 191 | 191 | break; |
| 192 | 192 | default: |
| 193 | 193 | error("unable to create temporary directory for unknown purpose: $purpose\n"); |
| 194 | 194 | exit; |
| 195 | 195 | } |
| 196 | - $tmp_dir = $path .'/'. $name; |
|
| 197 | - debug(4,"temp dir: $purpose : $tmp_dir\n"); |
|
| 198 | - if(! mkdir($tmp_dir,0700, true)) { |
|
| 199 | - if($fail) { |
|
| 196 | + $tmp_dir = $path . '/' . $name; |
|
| 197 | + debug(4, "temp dir: $purpose : $tmp_dir\n"); |
|
| 198 | + if (!mkdir($tmp_dir, 0700, true)) { |
|
| 199 | + if ($fail) { |
|
| 200 | 200 | error("unable to create temporary directory: $tmp_dir\n"); |
| 201 | 201 | exit; |
| 202 | - } else { |
|
| 202 | + } else { |
|
| 203 | 203 | debug(4, "Directory creation failed for $tmp_dir\n"); |
| 204 | - return ['base'=>$path,'dir'=>'',$name=>'']; |
|
| 204 | + return ['base'=>$path, 'dir'=>'', $name=>'']; |
|
| 205 | 205 | } |
| 206 | 206 | } else |
| 207 | 207 | debug(4, "Directory created: $tmp_dir\n"); |
| 208 | - return ['base'=>$path,'dir'=>$tmp_dir,'name'=>$name]; |
|
| 208 | + return ['base'=>$path, 'dir'=>$tmp_dir, 'name'=>$name]; |
|
| 209 | 209 | } |
| 210 | 210 | |
| 211 | -function png_inject_consortium_logo ($inputpngstring, $symbolsize = 12, $marginsymbols = 4) { |
|
| 211 | +function png_inject_consortium_logo($inputpngstring, $symbolsize = 12, $marginsymbols = 4) { |
|
| 212 | 212 | $inputgd = imagecreatefromstring($inputpngstring); |
| 213 | 213 | |
| 214 | - debug(4,"Consortium logo is at: ".CAT::$root."/web/resources/images/consortium_logo_large.png"); |
|
| 215 | - $logogd = imagecreatefrompng(CAT::$root."/web/resources/images/consortium_logo_large.png"); |
|
| 214 | + debug(4, "Consortium logo is at: " . CAT::$root . "/web/resources/images/consortium_logo_large.png"); |
|
| 215 | + $logogd = imagecreatefrompng(CAT::$root . "/web/resources/images/consortium_logo_large.png"); |
|
| 216 | 216 | |
| 217 | - $sizeinput = [imagesx($inputgd),imagesy($inputgd)]; |
|
| 218 | - $sizelogo = [imagesx($logogd),imagesy($logogd)]; |
|
| 217 | + $sizeinput = [imagesx($inputgd), imagesy($inputgd)]; |
|
| 218 | + $sizelogo = [imagesx($logogd), imagesy($logogd)]; |
|
| 219 | 219 | // Q level QR-codes can sustain 25% "damage" |
| 220 | 220 | // make our logo cover approx 15% of area to be sure; mind that there's a $symbolsize * $marginsymbols pixel white border around each edge |
| 221 | - $totalpixels = ($sizeinput[0] - $symbolsize*$marginsymbols) * ($sizeinput[1] - $symbolsize*$marginsymbols); |
|
| 221 | + $totalpixels = ($sizeinput[0] - $symbolsize * $marginsymbols) * ($sizeinput[1] - $symbolsize * $marginsymbols); |
|
| 222 | 222 | $totallogopixels = ($sizelogo[0]) * ($sizelogo[1]); |
| 223 | 223 | $maxoccupy = $totalpixels * 0.04; |
| 224 | 224 | // find out how much we have to scale down logo to reach 10% QR estate |
| 225 | 225 | $scale = sqrt($maxoccupy / $totallogopixels); |
| 226 | - debug(4,"Scaling info: $scale, $maxoccupy, $totallogopixels\n"); |
|
| 226 | + debug(4, "Scaling info: $scale, $maxoccupy, $totallogopixels\n"); |
|
| 227 | 227 | // determine final pixel size - round to multitude of $symbolsize to match exact symbol boundary |
| 228 | 228 | $targetwidth = $symbolsize * round($sizelogo[0] * $scale / $symbolsize); |
| 229 | 229 | $targetheight = $symbolsize * round($sizelogo[1] * $scale / $symbolsize); |
| 230 | 230 | // paint white below the logo, in case it has transparencies (looks bad) |
| 231 | 231 | // have one symbol in each direction extra white space |
| 232 | - $whiteimage = imagecreate($targetwidth+2*$symbolsize, $targetheight+2*$symbolsize); |
|
| 233 | - imagecolorallocate($whiteimage, 255,255,255); |
|
| 232 | + $whiteimage = imagecreate($targetwidth + 2 * $symbolsize, $targetheight + 2 * $symbolsize); |
|
| 233 | + imagecolorallocate($whiteimage, 255, 255, 255); |
|
| 234 | 234 | // also make sure the initial placement is a multitude of 12; otherwise "two half" symbols might be affected |
| 235 | - $targetplacementx = $symbolsize * round(($sizeinput[0] / 2 - ($targetwidth - $symbolsize) / 2)/$symbolsize); |
|
| 236 | - $targetplacementy = $symbolsize * round(($sizeinput[1] / 2 - ($targetheight - $symbolsize) / 2)/$symbolsize); |
|
| 237 | - imagecopyresized($inputgd, $whiteimage, $targetplacementx-$symbolsize, $targetplacementy-$symbolsize, 0, 0, $targetwidth+2*$symbolsize, $targetheight+2*$symbolsize, $targetwidth+2*$symbolsize, $targetheight+2*$symbolsize); |
|
| 238 | - imagecopyresized($inputgd, $logogd, $targetplacementx, $targetplacementy, 0, 0, $targetwidth , $targetheight , $sizelogo[0] , $sizelogo[1]); |
|
| 235 | + $targetplacementx = $symbolsize * round(($sizeinput[0] / 2 - ($targetwidth - $symbolsize) / 2) / $symbolsize); |
|
| 236 | + $targetplacementy = $symbolsize * round(($sizeinput[1] / 2 - ($targetheight - $symbolsize) / 2) / $symbolsize); |
|
| 237 | + imagecopyresized($inputgd, $whiteimage, $targetplacementx - $symbolsize, $targetplacementy - $symbolsize, 0, 0, $targetwidth + 2 * $symbolsize, $targetheight + 2 * $symbolsize, $targetwidth + 2 * $symbolsize, $targetheight + 2 * $symbolsize); |
|
| 238 | + imagecopyresized($inputgd, $logogd, $targetplacementx, $targetplacementy, 0, 0, $targetwidth, $targetheight, $sizelogo[0], $sizelogo[1]); |
|
| 239 | 239 | // imagecopyresized($dst_image, $src_image, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h); |
| 240 | 240 | ob_start(); |
| 241 | 241 | imagepng($inputgd); |
@@ -56,10 +56,11 @@ discard block |
||
| 56 | 56 | |
| 57 | 57 | function rrmdir($dir) { |
| 58 | 58 | foreach (glob($dir . '/*') as $file) { |
| 59 | - if (is_dir($file)) |
|
| 60 | - rrmdir($file); |
|
| 61 | - else |
|
| 62 | - unlink($file); |
|
| 59 | + if (is_dir($file)) { |
|
| 60 | + rrmdir($file); |
|
| 61 | + } else { |
|
| 62 | + unlink($file); |
|
| 63 | + } |
|
| 63 | 64 | } |
| 64 | 65 | rmdir($dir); |
| 65 | 66 | } |
@@ -73,36 +74,42 @@ discard block |
||
| 73 | 74 | */ |
| 74 | 75 | function calculateCommonHostSuffix(array $hosts) { |
| 75 | 76 | // massage names. A trailing dot can be omitted |
| 76 | - foreach ($hosts as $index => $host) |
|
| 77 | - if (substr($host, -1) == '.') { |
|
| 77 | + foreach ($hosts as $index => $host) { |
|
| 78 | + if (substr($host, -1) == '.') { |
|
| 78 | 79 | $hosts[$index] = substr($host, 0, -1); |
| 80 | + } |
|
| 79 | 81 | echo "Changed host to " . $hosts[$index] . "\n"; |
| 80 | 82 | } |
| 81 | 83 | // easy :-) |
| 82 | - if (count($hosts) == 1) |
|
| 83 | - return $hosts[0]; |
|
| 84 | + if (count($hosts) == 1) { |
|
| 85 | + return $hosts[0]; |
|
| 86 | + } |
|
| 84 | 87 | // not so easy :-( |
| 85 | 88 | else { |
| 86 | 89 | // look for the last dot from the end; if the corresponding substring is |
| 87 | 90 | // different, no common match! |
| 88 | 91 | $explodednames = []; |
| 89 | - foreach ($hosts as $host) |
|
| 90 | - $explodednames[] = explode('.', $host); |
|
| 92 | + foreach ($hosts as $host) { |
|
| 93 | + $explodednames[] = explode('.', $host); |
|
| 94 | + } |
|
| 91 | 95 | $commonsuffix = []; |
| 92 | 96 | while (count($explodednames[0]) > 0) { |
| 93 | 97 | $match = TRUE; |
| 94 | 98 | $testname = array_pop($explodednames[0]); |
| 95 | 99 | for ($i = 1; $i < count($explodednames); $i = $i + 1) { |
| 96 | - if (count($explodednames[$i]) == 0) |
|
| 97 | - $match = FALSE; |
|
| 100 | + if (count($explodednames[$i]) == 0) { |
|
| 101 | + $match = FALSE; |
|
| 102 | + } |
|
| 98 | 103 | $bla = array_pop($explodednames[$i]); |
| 99 | - if ($bla != $testname) |
|
| 100 | - $match = FALSE; |
|
| 104 | + if ($bla != $testname) { |
|
| 105 | + $match = FALSE; |
|
| 106 | + } |
|
| 107 | + } |
|
| 108 | + if ($match == TRUE) { |
|
| 109 | + $commonsuffix[] = $testname; |
|
| 110 | + } else { |
|
| 111 | + break; |
|
| 101 | 112 | } |
| 102 | - if ($match == TRUE) |
|
| 103 | - $commonsuffix[] = $testname; |
|
| 104 | - else |
|
| 105 | - break; |
|
| 106 | 113 | } |
| 107 | 114 | $finalsuffix = array_reverse($commonsuffix); |
| 108 | 115 | return implode('.', $finalsuffix); |
@@ -133,10 +140,11 @@ discard block |
||
| 133 | 140 | * @return UUID (possibly prefixed) |
| 134 | 141 | */ |
| 135 | 142 | function uuid($prefix = '', $deterministic_source = NULL) { |
| 136 | - if ($deterministic_source === NULL) |
|
| 137 | - $chars = md5(uniqid(mt_rand(), true)); |
|
| 138 | - else |
|
| 139 | - $chars = md5($deterministic_source); |
|
| 143 | + if ($deterministic_source === NULL) { |
|
| 144 | + $chars = md5(uniqid(mt_rand(), true)); |
|
| 145 | + } else { |
|
| 146 | + $chars = md5($deterministic_source); |
|
| 147 | + } |
|
| 140 | 148 | $uuid = substr($chars, 0, 8) . '-'; |
| 141 | 149 | $uuid .= substr($chars, 8, 4) . '-'; |
| 142 | 150 | $uuid .= substr($chars, 12, 4) . '-'; |
@@ -159,12 +167,13 @@ discard block |
||
| 159 | 167 | $try = unserialize($val['value']); |
| 160 | 168 | $r_val[$try['lang']] = $try['content']; |
| 161 | 169 | } |
| 162 | - if (isset($r_val[$locale])) |
|
| 163 | - $out = $r_val[$locale]; |
|
| 164 | - elseif (isset($r_val['C'])) |
|
| 165 | - $out = $r_val['C']; |
|
| 166 | - else |
|
| 167 | - $out = 0; |
|
| 170 | + if (isset($r_val[$locale])) { |
|
| 171 | + $out = $r_val[$locale]; |
|
| 172 | + } elseif (isset($r_val['C'])) { |
|
| 173 | + $out = $r_val['C']; |
|
| 174 | + } else { |
|
| 175 | + $out = 0; |
|
| 176 | + } |
|
| 168 | 177 | } else { |
| 169 | 178 | $out = 0; |
| 170 | 179 | } |
@@ -203,8 +212,9 @@ discard block |
||
| 203 | 212 | debug(4, "Directory creation failed for $tmp_dir\n"); |
| 204 | 213 | return ['base'=>$path,'dir'=>'',$name=>'']; |
| 205 | 214 | } |
| 206 | - } else |
|
| 207 | - debug(4, "Directory created: $tmp_dir\n"); |
|
| 215 | + } else { |
|
| 216 | + debug(4, "Directory created: $tmp_dir\n"); |
|
| 217 | + } |
|
| 208 | 218 | return ['base'=>$path,'dir'=>$tmp_dir,'name'=>$name]; |
| 209 | 219 | } |
| 210 | 220 | |
@@ -96,6 +96,10 @@ discard block |
||
| 96 | 96 | define('QR_FORMAT_PNG', 1);
|
| 97 | 97 | |
| 98 | 98 | class qrstr {
|
| 99 | + |
|
| 100 | + /** |
|
| 101 | + * @param string $repl |
|
| 102 | + */ |
|
| 99 | 103 | public static function set(&$srctab, $x, $y, $repl, $replLen = false) {
|
| 100 | 104 | $srctab[$y] = substr_replace($srctab[$y], ($replLen !== false)?substr($repl,0,$replLen):$repl, $x, ($replLen !== false)?$replLen:strlen($repl)); |
| 101 | 105 | } |
@@ -231,6 +235,11 @@ discard block |
||
| 231 | 235 | } |
| 232 | 236 | |
| 233 | 237 | //---------------------------------------------------------------------- |
| 238 | + |
|
| 239 | + /** |
|
| 240 | + * @param boolean $outfile |
|
| 241 | + * @param string $err |
|
| 242 | + */ |
|
| 234 | 243 | public static function log($outfile, $err) |
| 235 | 244 | {
|
| 236 | 245 | if (QR_LOG_DIR !== false) {
|
@@ -256,6 +265,10 @@ discard block |
||
| 256 | 265 | } |
| 257 | 266 | |
| 258 | 267 | //---------------------------------------------------------------------- |
| 268 | + |
|
| 269 | + /** |
|
| 270 | + * @param string $markerId |
|
| 271 | + */ |
|
| 259 | 272 | public static function markTime($markerId) |
| 260 | 273 | {
|
| 261 | 274 | list($usec, $sec) = explode(" ", microtime());
|
@@ -410,18 +423,30 @@ discard block |
||
| 410 | 423 | } |
| 411 | 424 | |
| 412 | 425 | //---------------------------------------------------------------------- |
| 426 | + |
|
| 427 | + /** |
|
| 428 | + * @param integer $version |
|
| 429 | + */ |
|
| 413 | 430 | public static function getWidth($version) |
| 414 | 431 | {
|
| 415 | 432 | return self::$capacity[$version][QRCAP_WIDTH]; |
| 416 | 433 | } |
| 417 | 434 | |
| 418 | 435 | //---------------------------------------------------------------------- |
| 436 | + |
|
| 437 | + /** |
|
| 438 | + * @param integer $version |
|
| 439 | + */ |
|
| 419 | 440 | public static function getRemainder($version) |
| 420 | 441 | {
|
| 421 | 442 | return self::$capacity[$version][QRCAP_REMINDER]; |
| 422 | 443 | } |
| 423 | 444 | |
| 424 | 445 | //---------------------------------------------------------------------- |
| 446 | + |
|
| 447 | + /** |
|
| 448 | + * @param integer $size |
|
| 449 | + */ |
|
| 425 | 450 | public static function getMinimumVersion($size, $level) |
| 426 | 451 | {
|
| 427 | 452 | |
@@ -535,6 +560,9 @@ discard block |
||
| 535 | 560 | //---------------------------------------------------------------------- |
| 536 | 561 | // CACHEABLE!!! |
| 537 | 562 | |
| 563 | + /** |
|
| 564 | + * @param integer $version |
|
| 565 | + */ |
|
| 538 | 566 | public static function getEccSpec($version, $level, array &$spec) |
| 539 | 567 | {
|
| 540 | 568 | if (count($spec) < 5) {
|
@@ -857,12 +885,20 @@ discard block |
||
| 857 | 885 | } |
| 858 | 886 | |
| 859 | 887 | //---------------------------------------------------------------------- |
| 888 | + |
|
| 889 | + /** |
|
| 890 | + * @param string $code |
|
| 891 | + */ |
|
| 860 | 892 | public static function unserial($code) |
| 861 | 893 | {
|
| 862 | 894 | return explode("\n", gzuncompress($code));
|
| 863 | 895 | } |
| 864 | 896 | |
| 865 | 897 | //---------------------------------------------------------------------- |
| 898 | + |
|
| 899 | + /** |
|
| 900 | + * @param integer $version |
|
| 901 | + */ |
|
| 866 | 902 | public static function newFrame($version) |
| 867 | 903 | {
|
| 868 | 904 | if($version < 1 || $version > QRSPEC_VERSION_MAX) |
@@ -1236,6 +1272,10 @@ discard block |
||
| 1236 | 1272 | } |
| 1237 | 1273 | |
| 1238 | 1274 | //---------------------------------------------------------------------- |
| 1275 | + |
|
| 1276 | + /** |
|
| 1277 | + * @param integer $version |
|
| 1278 | + */ |
|
| 1239 | 1279 | public function encodeBitStream($version) |
| 1240 | 1280 | {
|
| 1241 | 1281 | try {
|
@@ -1313,6 +1353,10 @@ discard block |
||
| 1313 | 1353 | } |
| 1314 | 1354 | |
| 1315 | 1355 | //---------------------------------------------------------------------- |
| 1356 | + |
|
| 1357 | + /** |
|
| 1358 | + * @param integer $version |
|
| 1359 | + */ |
|
| 1316 | 1360 | public function setVersion($version) |
| 1317 | 1361 | {
|
| 1318 | 1362 | if($version < 0 || $version > QRSPEC_VERSION_MAX) {
|
@@ -1351,6 +1395,12 @@ discard block |
||
| 1351 | 1395 | } |
| 1352 | 1396 | |
| 1353 | 1397 | //---------------------------------------------------------------------- |
| 1398 | + |
|
| 1399 | + /** |
|
| 1400 | + * @param QRinput $mode |
|
| 1401 | + * @param integer $size |
|
| 1402 | + * @param integer $data |
|
| 1403 | + */ |
|
| 1354 | 1404 | public function append($mode, $size, $data) |
| 1355 | 1405 | {
|
| 1356 | 1406 | try {
|
@@ -1446,6 +1496,10 @@ discard block |
||
| 1446 | 1496 | ]; |
| 1447 | 1497 | |
| 1448 | 1498 | //---------------------------------------------------------------------- |
| 1499 | + |
|
| 1500 | + /** |
|
| 1501 | + * @param integer $c |
|
| 1502 | + */ |
|
| 1449 | 1503 | public static function lookAnTable($c) |
| 1450 | 1504 | {
|
| 1451 | 1505 | return (($c > 127)?-1:self::$anTable[$c]); |
@@ -1531,6 +1585,10 @@ discard block |
||
| 1531 | 1585 | |
| 1532 | 1586 | |
| 1533 | 1587 | //---------------------------------------------------------------------- |
| 1588 | + |
|
| 1589 | + /** |
|
| 1590 | + * @param integer $version |
|
| 1591 | + */ |
|
| 1534 | 1592 | public function estimateBitStreamSize($version) |
| 1535 | 1593 | {
|
| 1536 | 1594 | $bits = 0; |
@@ -1648,6 +1706,10 @@ discard block |
||
| 1648 | 1706 | } |
| 1649 | 1707 | |
| 1650 | 1708 | //---------------------------------------------------------------------- |
| 1709 | + |
|
| 1710 | + /** |
|
| 1711 | + * @param QRbitstream $bstream |
|
| 1712 | + */ |
|
| 1651 | 1713 | public function appendPaddingBit(&$bstream) |
| 1652 | 1714 | {
|
| 1653 | 1715 | $bits = $bstream->size(); |
@@ -1977,6 +2039,10 @@ discard block |
||
| 1977 | 2039 | public $modeHint; |
| 1978 | 2040 | |
| 1979 | 2041 | //---------------------------------------------------------------------- |
| 2042 | + |
|
| 2043 | + /** |
|
| 2044 | + * @param QRinput $input |
|
| 2045 | + */ |
|
| 1980 | 2046 | public function __construct($dataStr, $input, $modeHint) |
| 1981 | 2047 | {
|
| 1982 | 2048 | $this->dataStr = $dataStr; |
@@ -1985,6 +2051,10 @@ discard block |
||
| 1985 | 2051 | } |
| 1986 | 2052 | |
| 1987 | 2053 | //---------------------------------------------------------------------- |
| 2054 | + |
|
| 2055 | + /** |
|
| 2056 | + * @param string $str |
|
| 2057 | + */ |
|
| 1988 | 2058 | public static function isdigitat($str, $pos) |
| 1989 | 2059 | {
|
| 1990 | 2060 | if ($pos >= strlen($str)) |
@@ -1994,6 +2064,10 @@ discard block |
||
| 1994 | 2064 | } |
| 1995 | 2065 | |
| 1996 | 2066 | //---------------------------------------------------------------------- |
| 2067 | + |
|
| 2068 | + /** |
|
| 2069 | + * @param string $str |
|
| 2070 | + */ |
|
| 1997 | 2071 | public static function isalnumat($str, $pos) |
| 1998 | 2072 | {
|
| 1999 | 2073 | if ($pos >= strlen($str)) |
@@ -2114,6 +2188,10 @@ discard block |
||
| 2114 | 2188 | } |
| 2115 | 2189 | |
| 2116 | 2190 | //---------------------------------------------------------------------- |
| 2191 | + |
|
| 2192 | + /** |
|
| 2193 | + * @return integer |
|
| 2194 | + */ |
|
| 2117 | 2195 | public function eatKanji() |
| 2118 | 2196 | {
|
| 2119 | 2197 | $p = 0; |
@@ -2447,6 +2525,13 @@ discard block |
||
| 2447 | 2525 | public static $items = []; |
| 2448 | 2526 | |
| 2449 | 2527 | //---------------------------------------------------------------------- |
| 2528 | + |
|
| 2529 | + /** |
|
| 2530 | + * @param integer $symsize |
|
| 2531 | + * @param integer $gfpoly |
|
| 2532 | + * @param integer $fcr |
|
| 2533 | + * @param integer $prim |
|
| 2534 | + */ |
|
| 2450 | 2535 | public static function init_rs($symsize, $gfpoly, $fcr, $prim, $nroots, $pad) |
| 2451 | 2536 | {
|
| 2452 | 2537 | foreach(self::$items as $rs) {
|
@@ -2601,6 +2686,10 @@ discard block |
||
| 2601 | 2686 | } |
| 2602 | 2687 | |
| 2603 | 2688 | //---------------------------------------------------------------------- |
| 2689 | + |
|
| 2690 | + /** |
|
| 2691 | + * @param string $code |
|
| 2692 | + */ |
|
| 2604 | 2693 | public static function unserial($code) |
| 2605 | 2694 | {
|
| 2606 | 2695 | $codeArr = []; |
@@ -2661,6 +2750,10 @@ discard block |
||
| 2661 | 2750 | } |
| 2662 | 2751 | |
| 2663 | 2752 | //---------------------------------------------------------------------- |
| 2753 | + |
|
| 2754 | + /** |
|
| 2755 | + * @param integer $length |
|
| 2756 | + */ |
|
| 2664 | 2757 | public function calcN1N3($length) |
| 2665 | 2758 | {
|
| 2666 | 2759 | $demerit = 0; |
@@ -2971,6 +3064,10 @@ discard block |
||
| 2971 | 3064 | public $data; |
| 2972 | 3065 | |
| 2973 | 3066 | //---------------------------------------------------------------------- |
| 3067 | + |
|
| 3068 | + /** |
|
| 3069 | + * @param integer $mask |
|
| 3070 | + */ |
|
| 2974 | 3071 | public function encodeMask(QRinput $input, $mask) |
| 2975 | 3072 | {
|
| 2976 | 3073 | if($input->getVersion() < 0 || $input->getVersion() > QRSPEC_VERSION_MAX) {
|
@@ -3052,6 +3149,11 @@ discard block |
||
| 3052 | 3149 | } |
| 3053 | 3150 | |
| 3054 | 3151 | //---------------------------------------------------------------------- |
| 3152 | + |
|
| 3153 | + /** |
|
| 3154 | + * @param integer $version |
|
| 3155 | + * @param integer $level |
|
| 3156 | + */ |
|
| 3055 | 3157 | public function encodeString8bit($string, $version, $level) |
| 3056 | 3158 | {
|
| 3057 | 3159 | if(string == NULL) {
|
@@ -3071,6 +3173,12 @@ discard block |
||
| 3071 | 3173 | } |
| 3072 | 3174 | |
| 3073 | 3175 | //---------------------------------------------------------------------- |
| 3176 | + |
|
| 3177 | + /** |
|
| 3178 | + * @param integer $version |
|
| 3179 | + * @param integer $level |
|
| 3180 | + * @param boolean $casesensitive |
|
| 3181 | + */ |
|
| 3074 | 3182 | public function encodeString($string, $version, $level, $hint, $casesensitive) |
| 3075 | 3183 | {
|
| 3076 | 3184 | |
@@ -74,32 +74,32 @@ discard block |
||
| 74 | 74 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 75 | 75 | */ |
| 76 | 76 | |
| 77 | - // Encoding modes |
|
| 77 | + // Encoding modes |
|
| 78 | 78 | |
| 79 | - define('QR_MODE_NUL', -1);
|
|
| 80 | - define('QR_MODE_NUM', 0);
|
|
| 81 | - define('QR_MODE_AN', 1);
|
|
| 82 | - define('QR_MODE_8', 2);
|
|
| 83 | - define('QR_MODE_KANJI', 3);
|
|
| 84 | - define('QR_MODE_STRUCTURE', 4);
|
|
| 85 | - |
|
| 86 | - // Levels of error correction. |
|
| 87 | - |
|
| 88 | - define('QR_ECLEVEL_L', 0);
|
|
| 89 | - define('QR_ECLEVEL_M', 1);
|
|
| 90 | - define('QR_ECLEVEL_Q', 2);
|
|
| 91 | - define('QR_ECLEVEL_H', 3);
|
|
| 79 | + define('QR_MODE_NUL', -1);
|
|
| 80 | + define('QR_MODE_NUM', 0);
|
|
| 81 | + define('QR_MODE_AN', 1);
|
|
| 82 | + define('QR_MODE_8', 2);
|
|
| 83 | + define('QR_MODE_KANJI', 3);
|
|
| 84 | + define('QR_MODE_STRUCTURE', 4);
|
|
| 85 | + |
|
| 86 | + // Levels of error correction. |
|
| 87 | + |
|
| 88 | + define('QR_ECLEVEL_L', 0);
|
|
| 89 | + define('QR_ECLEVEL_M', 1);
|
|
| 90 | + define('QR_ECLEVEL_Q', 2);
|
|
| 91 | + define('QR_ECLEVEL_H', 3);
|
|
| 92 | 92 | |
| 93 | - // Supported output formats |
|
| 93 | + // Supported output formats |
|
| 94 | 94 | |
| 95 | - define('QR_FORMAT_TEXT', 0);
|
|
| 96 | - define('QR_FORMAT_PNG', 1);
|
|
| 95 | + define('QR_FORMAT_TEXT', 0);
|
|
| 96 | + define('QR_FORMAT_PNG', 1);
|
|
| 97 | 97 | |
| 98 | - class qrstr {
|
|
| 99 | - public static function set(&$srctab, $x, $y, $repl, $replLen = false) {
|
|
| 100 | - $srctab[$y] = substr_replace($srctab[$y], ($replLen !== false)?substr($repl,0,$replLen):$repl, $x, ($replLen !== false)?$replLen:strlen($repl)); |
|
| 101 | - } |
|
| 102 | - } |
|
| 98 | + class qrstr {
|
|
| 99 | + public static function set(&$srctab, $x, $y, $repl, $replLen = false) {
|
|
| 100 | + $srctab[$y] = substr_replace($srctab[$y], ($replLen !== false)?substr($repl,0,$replLen):$repl, $x, ($replLen !== false)?$replLen:strlen($repl)); |
|
| 101 | + } |
|
| 102 | + } |
|
| 103 | 103 | |
| 104 | 104 | |
| 105 | 105 | |
@@ -211,9 +211,9 @@ discard block |
||
| 211 | 211 | //---------------------------------------------------------------------- |
| 212 | 212 | public static function buildCache() |
| 213 | 213 | {
|
| 214 | - QRtools::markTime('before_build_cache');
|
|
| 214 | + QRtools::markTime('before_build_cache');
|
|
| 215 | 215 | |
| 216 | - $mask = new QRmask(); |
|
| 216 | + $mask = new QRmask(); |
|
| 217 | 217 | for ($a=1; $a <= QRSPEC_VERSION_MAX; $a++) {
|
| 218 | 218 | $frame = QRspec::newFrame($a); |
| 219 | 219 | if (QR_IMAGE) {
|
@@ -221,13 +221,13 @@ discard block |
||
| 221 | 221 | QRimage::png(self::binarize($frame), $fileName, 1, 0); |
| 222 | 222 | } |
| 223 | 223 | |
| 224 | - $width = count($frame); |
|
| 225 | - $bitMask = array_fill(0, $width, array_fill(0, $width, 0)); |
|
| 226 | - for ($maskNo=0; $maskNo<8; $maskNo++) |
|
| 227 | - $mask->makeMaskNo($maskNo, $width, $frame, $bitMask, true); |
|
| 224 | + $width = count($frame); |
|
| 225 | + $bitMask = array_fill(0, $width, array_fill(0, $width, 0)); |
|
| 226 | + for ($maskNo=0; $maskNo<8; $maskNo++) |
|
| 227 | + $mask->makeMaskNo($maskNo, $width, $frame, $bitMask, true); |
|
| 228 | 228 | } |
| 229 | 229 | |
| 230 | - QRtools::markTime('after_build_cache');
|
|
| 230 | + QRtools::markTime('after_build_cache');
|
|
| 231 | 231 | } |
| 232 | 232 | |
| 233 | 233 | //---------------------------------------------------------------------- |
@@ -647,10 +647,10 @@ discard block |
||
| 647 | 647 | |
| 648 | 648 | // Version information pattern ----------------------------------------- |
| 649 | 649 | |
| 650 | - // Version information pattern (BCH coded). |
|
| 650 | + // Version information pattern (BCH coded). |
|
| 651 | 651 | // See Table 1 in Appendix D (pp.68) of JIS X0510:2004. |
| 652 | 652 | |
| 653 | - // size: [QRSPEC_VERSION_MAX - 6] |
|
| 653 | + // size: [QRSPEC_VERSION_MAX - 6] |
|
| 654 | 654 | |
| 655 | 655 | public static $versionPattern = [ |
| 656 | 656 | 0x07c94, 0x085bc, 0x09a99, 0x0a4d3, 0x0bbf6, 0x0c762, 0x0d847, 0x0e60d, |
@@ -1438,7 +1438,7 @@ discard block |
||
| 1438 | 1438 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
| 1439 | 1439 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
| 1440 | 1440 | 36, -1, -1, -1, 37, 38, -1, -1, -1, -1, 39, 40, -1, 41, 42, 43, |
| 1441 | - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 44, -1, -1, -1, -1, -1, |
|
| 1441 | + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 44, -1, -1, -1, -1, -1, |
|
| 1442 | 1442 | -1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, |
| 1443 | 1443 | 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, -1, -1, -1, -1, -1, |
| 1444 | 1444 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
@@ -2500,17 +2500,17 @@ discard block |
||
| 2500 | 2500 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 2501 | 2501 | */ |
| 2502 | 2502 | |
| 2503 | - define('N1', 3);
|
|
| 2504 | - define('N2', 3);
|
|
| 2505 | - define('N3', 40);
|
|
| 2506 | - define('N4', 10);
|
|
| 2503 | + define('N1', 3);
|
|
| 2504 | + define('N2', 3);
|
|
| 2505 | + define('N3', 40);
|
|
| 2506 | + define('N4', 10);
|
|
| 2507 | 2507 | |
| 2508 | - class QRmask {
|
|
| 2508 | + class QRmask {
|
|
| 2509 | 2509 | |
| 2510 | - public $runLength = []; |
|
| 2510 | + public $runLength = []; |
|
| 2511 | 2511 | |
| 2512 | - //---------------------------------------------------------------------- |
|
| 2513 | - public function __construct() |
|
| 2512 | + //---------------------------------------------------------------------- |
|
| 2513 | + public function __construct() |
|
| 2514 | 2514 | {
|
| 2515 | 2515 | $this->runLength = array_fill(0, QRSPEC_WIDTH_MAX + 1, 0); |
| 2516 | 2516 | } |
@@ -93,11 +93,11 @@ discard block |
||
| 93 | 93 | // Supported output formats |
| 94 | 94 | |
| 95 | 95 | define('QR_FORMAT_TEXT', 0);
|
| 96 | - define('QR_FORMAT_PNG', 1);
|
|
| 96 | + define('QR_FORMAT_PNG', 1);
|
|
| 97 | 97 | |
| 98 | 98 | class qrstr {
|
| 99 | 99 | public static function set(&$srctab, $x, $y, $repl, $replLen = false) {
|
| 100 | - $srctab[$y] = substr_replace($srctab[$y], ($replLen !== false)?substr($repl,0,$replLen):$repl, $x, ($replLen !== false)?$replLen:strlen($repl)); |
|
| 100 | + $srctab[$y] = substr_replace($srctab[$y], ($replLen !== false) ? substr($repl, 0, $replLen) : $repl, $x, ($replLen !== false) ? $replLen : strlen($repl)); |
|
| 101 | 101 | } |
| 102 | 102 | } |
| 103 | 103 | |
@@ -114,15 +114,15 @@ discard block |
||
| 114 | 114 | * Config file, tuned-up for merged verion |
| 115 | 115 | */ |
| 116 | 116 | |
| 117 | - define('QR_CACHEABLE', false); // use cache - more disk reads but less CPU power, masks and format templates are stored there
|
|
| 118 | - define('QR_CACHE_DIR', false); // used when QR_CACHEABLE === true
|
|
| 119 | - define('QR_LOG_DIR', false); // default error logs dir
|
|
| 117 | + define('QR_CACHEABLE', false); // use cache - more disk reads but less CPU power, masks and format templates are stored there
|
|
| 118 | + define('QR_CACHE_DIR', false); // used when QR_CACHEABLE === true
|
|
| 119 | + define('QR_LOG_DIR', false); // default error logs dir
|
|
| 120 | 120 | |
| 121 | - define('QR_FIND_BEST_MASK', true); // if true, estimates best mask (spec. default, but extremally slow; set to false to significant performance boost but (propably) worst quality code
|
|
| 122 | - define('QR_FIND_FROM_RANDOM', 2); // if false, checks all masks available, otherwise value tells count of masks need to be checked, mask id are got randomly
|
|
| 123 | - define('QR_DEFAULT_MASK', 2); // when QR_FIND_BEST_MASK === false
|
|
| 121 | + define('QR_FIND_BEST_MASK', true); // if true, estimates best mask (spec. default, but extremally slow; set to false to significant performance boost but (propably) worst quality code
|
|
| 122 | + define('QR_FIND_FROM_RANDOM', 2); // if false, checks all masks available, otherwise value tells count of masks need to be checked, mask id are got randomly
|
|
| 123 | + define('QR_DEFAULT_MASK', 2); // when QR_FIND_BEST_MASK === false
|
|
| 124 | 124 | |
| 125 | - define('QR_PNG_MAXIMUM_SIZE', 1024); // maximum allowed png image width (in pixels), tune to make sure GD and PHP can handle such big images
|
|
| 125 | + define('QR_PNG_MAXIMUM_SIZE', 1024); // maximum allowed png image width (in pixels), tune to make sure GD and PHP can handle such big images
|
|
| 126 | 126 | |
| 127 | 127 | |
| 128 | 128 | |
@@ -163,8 +163,8 @@ discard block |
||
| 163 | 163 | $len = count($frame); |
| 164 | 164 | foreach ($frame as &$frameLine) {
|
| 165 | 165 | |
| 166 | - for($i=0; $i<$len; $i++) {
|
|
| 167 | - $frameLine[$i] = (ord($frameLine[$i])&1)?'1':'0'; |
|
| 166 | + for ($i = 0; $i < $len; $i++) {
|
|
| 167 | + $frameLine[$i] = (ord($frameLine[$i]) & 1) ? '1' : '0'; |
|
| 168 | 168 | } |
| 169 | 169 | } |
| 170 | 170 | |
@@ -194,8 +194,8 @@ discard block |
||
| 194 | 194 | |
| 195 | 195 | foreach ($qrTab as $line) {
|
| 196 | 196 | $arrAdd = []; |
| 197 | - foreach(str_split($line) as $char) |
|
| 198 | - $arrAdd[] = ($char=='1')?1:0; |
|
| 197 | + foreach (str_split($line) as $char) |
|
| 198 | + $arrAdd[] = ($char == '1') ? 1 : 0; |
|
| 199 | 199 | $barcode_array['bcode'][] = $arrAdd; |
| 200 | 200 | } |
| 201 | 201 | |
@@ -214,16 +214,16 @@ discard block |
||
| 214 | 214 | QRtools::markTime('before_build_cache');
|
| 215 | 215 | |
| 216 | 216 | $mask = new QRmask(); |
| 217 | - for ($a=1; $a <= QRSPEC_VERSION_MAX; $a++) {
|
|
| 217 | + for ($a = 1; $a <= QRSPEC_VERSION_MAX; $a++) {
|
|
| 218 | 218 | $frame = QRspec::newFrame($a); |
| 219 | 219 | if (QR_IMAGE) {
|
| 220 | - $fileName = QR_CACHE_DIR.'frame_'.$a.'.png'; |
|
| 220 | + $fileName = QR_CACHE_DIR . 'frame_' . $a . '.png'; |
|
| 221 | 221 | QRimage::png(self::binarize($frame), $fileName, 1, 0); |
| 222 | 222 | } |
| 223 | 223 | |
| 224 | 224 | $width = count($frame); |
| 225 | 225 | $bitMask = array_fill(0, $width, array_fill(0, $width, 0)); |
| 226 | - for ($maskNo=0; $maskNo<8; $maskNo++) |
|
| 226 | + for ($maskNo = 0; $maskNo < 8; $maskNo++) |
|
| 227 | 227 | $mask->makeMaskNo($maskNo, $width, $frame, $bitMask, true); |
| 228 | 228 | } |
| 229 | 229 | |
@@ -236,9 +236,9 @@ discard block |
||
| 236 | 236 | if (QR_LOG_DIR !== false) {
|
| 237 | 237 | if ($err != '') {
|
| 238 | 238 | if ($outfile !== false) {
|
| 239 | - file_put_contents(QR_LOG_DIR.basename($outfile).'-errors.txt', date('Y-m-d H:i:s').': '.$err, FILE_APPEND);
|
|
| 239 | + file_put_contents(QR_LOG_DIR . basename($outfile) . '-errors.txt', date('Y-m-d H:i:s') . ': ' . $err, FILE_APPEND);
|
|
| 240 | 240 | } else {
|
| 241 | - file_put_contents(QR_LOG_DIR.'errors.txt', date('Y-m-d H:i:s').': '.$err, FILE_APPEND);
|
|
| 241 | + file_put_contents(QR_LOG_DIR . 'errors.txt', date('Y-m-d H:i:s') . ': ' . $err, FILE_APPEND);
|
|
| 242 | 242 | } |
| 243 | 243 | } |
| 244 | 244 | } |
@@ -248,9 +248,9 @@ discard block |
||
| 248 | 248 | public static function dumpMask($frame) |
| 249 | 249 | {
|
| 250 | 250 | $width = count($frame); |
| 251 | - for($y=0;$y<$width;$y++) {
|
|
| 252 | - for($x=0;$x<$width;$x++) {
|
|
| 253 | - echo ord($frame[$y][$x]).','; |
|
| 251 | + for ($y = 0; $y < $width; $y++) {
|
|
| 252 | + for ($x = 0; $x < $width; $x++) {
|
|
| 253 | + echo ord($frame[$y][$x]) . ','; |
|
| 254 | 254 | } |
| 255 | 255 | } |
| 256 | 256 | } |
@@ -259,7 +259,7 @@ discard block |
||
| 259 | 259 | public static function markTime($markerId) |
| 260 | 260 | {
|
| 261 | 261 | list($usec, $sec) = explode(" ", microtime());
|
| 262 | - $time = ((float)$usec + (float)$sec); |
|
| 262 | + $time = ((float) $usec + (float) $sec); |
|
| 263 | 263 | |
| 264 | 264 | if (!isset($GLOBALS['qr_time_bench'])) |
| 265 | 265 | $GLOBALS['qr_time_bench'] = []; |
@@ -280,9 +280,9 @@ discard block |
||
| 280 | 280 | <thead><tr style="border-bottom:1px solid silver"><td colspan="2" style="text-align:center">BENCHMARK</td></tr></thead> |
| 281 | 281 | <tbody>'; |
| 282 | 282 | |
| 283 | - foreach($GLOBALS['qr_time_bench'] as $markerId=>$thisTime) {
|
|
| 283 | + foreach ($GLOBALS['qr_time_bench'] as $markerId=>$thisTime) {
|
|
| 284 | 284 | if ($p > 0) {
|
| 285 | - echo '<tr><th style="text-align:right">till '.$markerId.': </th><td>'.number_format($thisTime-$lastTime, 6).'s</td></tr>'; |
|
| 285 | + echo '<tr><th style="text-align:right">till ' . $markerId . ': </th><td>' . number_format($thisTime - $lastTime, 6) . 's</td></tr>'; |
|
| 286 | 286 | } else {
|
| 287 | 287 | $startTime = $thisTime; |
| 288 | 288 | } |
@@ -292,7 +292,7 @@ discard block |
||
| 292 | 292 | } |
| 293 | 293 | |
| 294 | 294 | echo '</tbody><tfoot> |
| 295 | - <tr style="border-top:2px solid black"><th style="text-align:right">TOTAL: </th><td>'.number_format($lastTime-$startTime, 6).'s</td></tr> |
|
| 295 | + <tr style="border-top:2px solid black"><th style="text-align:right">TOTAL: </th><td>'.number_format($lastTime - $startTime, 6) . 's</td></tr> |
|
| 296 | 296 | </tfoot> |
| 297 | 297 | </table>'; |
| 298 | 298 | } |
@@ -344,57 +344,57 @@ discard block |
||
| 344 | 344 | */ |
| 345 | 345 | |
| 346 | 346 | define('QRSPEC_VERSION_MAX', 40);
|
| 347 | - define('QRSPEC_WIDTH_MAX', 177);
|
|
| 347 | + define('QRSPEC_WIDTH_MAX', 177);
|
|
| 348 | 348 | |
| 349 | - define('QRCAP_WIDTH', 0);
|
|
| 350 | - define('QRCAP_WORDS', 1);
|
|
| 351 | - define('QRCAP_REMINDER', 2);
|
|
| 352 | - define('QRCAP_EC', 3);
|
|
| 349 | + define('QRCAP_WIDTH', 0);
|
|
| 350 | + define('QRCAP_WORDS', 1);
|
|
| 351 | + define('QRCAP_REMINDER', 2);
|
|
| 352 | + define('QRCAP_EC', 3);
|
|
| 353 | 353 | |
| 354 | 354 | class QRspec {
|
| 355 | 355 | |
| 356 | 356 | public static $capacity = [ |
| 357 | - [ 0, 0, 0, [ 0, 0, 0, 0]], |
|
| 358 | - [ 21, 26, 0, [ 7, 10, 13, 17]], // 1 |
|
| 359 | - [ 25, 44, 7, [ 10, 16, 22, 28]], |
|
| 360 | - [ 29, 70, 7, [ 15, 26, 36, 44]], |
|
| 361 | - [ 33, 100, 7, [ 20, 36, 52, 64]], |
|
| 362 | - [ 37, 134, 7, [ 26, 48, 72, 88]], // 5 |
|
| 363 | - [ 41, 172, 7, [ 36, 64, 96, 112]], |
|
| 364 | - [ 45, 196, 0, [ 40, 72, 108, 130]], |
|
| 365 | - [ 49, 242, 0, [ 48, 88, 132, 156]], |
|
| 366 | - [ 53, 292, 0, [ 60, 110, 160, 192]], |
|
| 367 | - [ 57, 346, 0, [ 72, 130, 192, 224]], //10 |
|
| 368 | - [ 61, 404, 0, [ 80, 150, 224, 264]], |
|
| 369 | - [ 65, 466, 0, [ 96, 176, 260, 308]], |
|
| 370 | - [ 69, 532, 0, [ 104, 198, 288, 352]], |
|
| 371 | - [ 73, 581, 3, [ 120, 216, 320, 384]], |
|
| 372 | - [ 77, 655, 3, [ 132, 240, 360, 432]], //15 |
|
| 373 | - [ 81, 733, 3, [ 144, 280, 408, 480]], |
|
| 374 | - [ 85, 815, 3, [ 168, 308, 448, 532]], |
|
| 375 | - [ 89, 901, 3, [ 180, 338, 504, 588]], |
|
| 376 | - [ 93, 991, 3, [ 196, 364, 546, 650]], |
|
| 377 | - [ 97, 1085, 3, [ 224, 416, 600, 700]], //20 |
|
| 378 | - [101, 1156, 4, [ 224, 442, 644, 750]], |
|
| 379 | - [105, 1258, 4, [ 252, 476, 690, 816]], |
|
| 380 | - [109, 1364, 4, [ 270, 504, 750, 900]], |
|
| 381 | - [113, 1474, 4, [ 300, 560, 810, 960]], |
|
| 382 | - [117, 1588, 4, [ 312, 588, 870, 1050]], //25 |
|
| 383 | - [121, 1706, 4, [ 336, 644, 952, 1110]], |
|
| 384 | - [125, 1828, 4, [ 360, 700, 1020, 1200]], |
|
| 385 | - [129, 1921, 3, [ 390, 728, 1050, 1260]], |
|
| 386 | - [133, 2051, 3, [ 420, 784, 1140, 1350]], |
|
| 387 | - [137, 2185, 3, [ 450, 812, 1200, 1440]], //30 |
|
| 388 | - [141, 2323, 3, [ 480, 868, 1290, 1530]], |
|
| 389 | - [145, 2465, 3, [ 510, 924, 1350, 1620]], |
|
| 390 | - [149, 2611, 3, [ 540, 980, 1440, 1710]], |
|
| 391 | - [153, 2761, 3, [ 570, 1036, 1530, 1800]], |
|
| 392 | - [157, 2876, 0, [ 570, 1064, 1590, 1890]], //35 |
|
| 393 | - [161, 3034, 0, [ 600, 1120, 1680, 1980]], |
|
| 394 | - [165, 3196, 0, [ 630, 1204, 1770, 2100]], |
|
| 395 | - [169, 3362, 0, [ 660, 1260, 1860, 2220]], |
|
| 396 | - [173, 3532, 0, [ 720, 1316, 1950, 2310]], |
|
| 397 | - [177, 3706, 0, [ 750, 1372, 2040, 2430]] //40 |
|
| 357 | + [0, 0, 0, [0, 0, 0, 0]], |
|
| 358 | + [21, 26, 0, [7, 10, 13, 17]], // 1 |
|
| 359 | + [25, 44, 7, [10, 16, 22, 28]], |
|
| 360 | + [29, 70, 7, [15, 26, 36, 44]], |
|
| 361 | + [33, 100, 7, [20, 36, 52, 64]], |
|
| 362 | + [37, 134, 7, [26, 48, 72, 88]], // 5 |
|
| 363 | + [41, 172, 7, [36, 64, 96, 112]], |
|
| 364 | + [45, 196, 0, [40, 72, 108, 130]], |
|
| 365 | + [49, 242, 0, [48, 88, 132, 156]], |
|
| 366 | + [53, 292, 0, [60, 110, 160, 192]], |
|
| 367 | + [57, 346, 0, [72, 130, 192, 224]], //10 |
|
| 368 | + [61, 404, 0, [80, 150, 224, 264]], |
|
| 369 | + [65, 466, 0, [96, 176, 260, 308]], |
|
| 370 | + [69, 532, 0, [104, 198, 288, 352]], |
|
| 371 | + [73, 581, 3, [120, 216, 320, 384]], |
|
| 372 | + [77, 655, 3, [132, 240, 360, 432]], //15 |
|
| 373 | + [81, 733, 3, [144, 280, 408, 480]], |
|
| 374 | + [85, 815, 3, [168, 308, 448, 532]], |
|
| 375 | + [89, 901, 3, [180, 338, 504, 588]], |
|
| 376 | + [93, 991, 3, [196, 364, 546, 650]], |
|
| 377 | + [97, 1085, 3, [224, 416, 600, 700]], //20 |
|
| 378 | + [101, 1156, 4, [224, 442, 644, 750]], |
|
| 379 | + [105, 1258, 4, [252, 476, 690, 816]], |
|
| 380 | + [109, 1364, 4, [270, 504, 750, 900]], |
|
| 381 | + [113, 1474, 4, [300, 560, 810, 960]], |
|
| 382 | + [117, 1588, 4, [312, 588, 870, 1050]], //25 |
|
| 383 | + [121, 1706, 4, [336, 644, 952, 1110]], |
|
| 384 | + [125, 1828, 4, [360, 700, 1020, 1200]], |
|
| 385 | + [129, 1921, 3, [390, 728, 1050, 1260]], |
|
| 386 | + [133, 2051, 3, [420, 784, 1140, 1350]], |
|
| 387 | + [137, 2185, 3, [450, 812, 1200, 1440]], //30 |
|
| 388 | + [141, 2323, 3, [480, 868, 1290, 1530]], |
|
| 389 | + [145, 2465, 3, [510, 924, 1350, 1620]], |
|
| 390 | + [149, 2611, 3, [540, 980, 1440, 1710]], |
|
| 391 | + [153, 2761, 3, [570, 1036, 1530, 1800]], |
|
| 392 | + [157, 2876, 0, [570, 1064, 1590, 1890]], //35 |
|
| 393 | + [161, 3034, 0, [600, 1120, 1680, 1980]], |
|
| 394 | + [165, 3196, 0, [630, 1204, 1770, 2100]], |
|
| 395 | + [169, 3362, 0, [660, 1260, 1860, 2220]], |
|
| 396 | + [173, 3532, 0, [720, 1316, 1950, 2310]], |
|
| 397 | + [177, 3706, 0, [750, 1372, 2040, 2430]] //40 |
|
| 398 | 398 | ]; |
| 399 | 399 | |
| 400 | 400 | //---------------------------------------------------------------------- |
@@ -425,9 +425,9 @@ discard block |
||
| 425 | 425 | public static function getMinimumVersion($size, $level) |
| 426 | 426 | {
|
| 427 | 427 | |
| 428 | - for($i=1; $i<= QRSPEC_VERSION_MAX; $i++) {
|
|
| 429 | - $words = self::$capacity[$i][QRCAP_WORDS] - self::$capacity[$i][QRCAP_EC][$level]; |
|
| 430 | - if($words >= $size) |
|
| 428 | + for ($i = 1; $i <= QRSPEC_VERSION_MAX; $i++) {
|
|
| 429 | + $words = self::$capacity[$i][QRCAP_WORDS] - self::$capacity[$i][QRCAP_EC][$level]; |
|
| 430 | + if ($words >= $size) |
|
| 431 | 431 | return $i; |
| 432 | 432 | } |
| 433 | 433 | |
@@ -438,9 +438,9 @@ discard block |
||
| 438 | 438 | |
| 439 | 439 | public static $lengthTableBits = [ |
| 440 | 440 | [10, 12, 14], |
| 441 | - [ 9, 11, 13], |
|
| 442 | - [ 8, 16, 16], |
|
| 443 | - [ 8, 10, 12] |
|
| 441 | + [9, 11, 13], |
|
| 442 | + [8, 16, 16], |
|
| 443 | + [8, 10, 12] |
|
| 444 | 444 | ]; |
| 445 | 445 | |
| 446 | 446 | //---------------------------------------------------------------------- |
@@ -463,12 +463,12 @@ discard block |
||
| 463 | 463 | //---------------------------------------------------------------------- |
| 464 | 464 | public static function maximumWords($mode, $version) |
| 465 | 465 | {
|
| 466 | - if($mode == QR_MODE_STRUCTURE) |
|
| 466 | + if ($mode == QR_MODE_STRUCTURE) |
|
| 467 | 467 | return 3; |
| 468 | 468 | |
| 469 | - if($version <= 9) {
|
|
| 469 | + if ($version <= 9) {
|
|
| 470 | 470 | $l = 0; |
| 471 | - } else if($version <= 26) {
|
|
| 471 | + } else if ($version <= 26) {
|
|
| 472 | 472 | $l = 1; |
| 473 | 473 | } else {
|
| 474 | 474 | $l = 2; |
@@ -477,7 +477,7 @@ discard block |
||
| 477 | 477 | $bits = self::$lengthTableBits[$mode][$l]; |
| 478 | 478 | $words = (1 << $bits) - 1; |
| 479 | 479 | |
| 480 | - if($mode == QR_MODE_KANJI) {
|
|
| 480 | + if ($mode == QR_MODE_KANJI) {
|
|
| 481 | 481 | $words *= 2; // the number of bytes is required |
| 482 | 482 | } |
| 483 | 483 | |
@@ -489,47 +489,47 @@ discard block |
||
| 489 | 489 | // See Table 12-16 (pp.30-36), JIS X0510:2004. |
| 490 | 490 | |
| 491 | 491 | public static $eccTable = [ |
| 492 | - [[ 0, 0], [ 0, 0], [ 0, 0], [ 0, 0]], |
|
| 493 | - [[ 1, 0], [ 1, 0], [ 1, 0], [ 1, 0]], // 1 |
|
| 494 | - [[ 1, 0], [ 1, 0], [ 1, 0], [ 1, 0]], |
|
| 495 | - [[ 1, 0], [ 1, 0], [ 2, 0], [ 2, 0]], |
|
| 496 | - [[ 1, 0], [ 2, 0], [ 2, 0], [ 4, 0]], |
|
| 497 | - [[ 1, 0], [ 2, 0], [ 2, 2], [ 2, 2]], // 5 |
|
| 498 | - [[ 2, 0], [ 4, 0], [ 4, 0], [ 4, 0]], |
|
| 499 | - [[ 2, 0], [ 4, 0], [ 2, 4], [ 4, 1]], |
|
| 500 | - [[ 2, 0], [ 2, 2], [ 4, 2], [ 4, 2]], |
|
| 501 | - [[ 2, 0], [ 3, 2], [ 4, 4], [ 4, 4]], |
|
| 502 | - [[ 2, 2], [ 4, 1], [ 6, 2], [ 6, 2]], //10 |
|
| 503 | - [[ 4, 0], [ 1, 4], [ 4, 4], [ 3, 8]], |
|
| 504 | - [[ 2, 2], [ 6, 2], [ 4, 6], [ 7, 4]], |
|
| 505 | - [[ 4, 0], [ 8, 1], [ 8, 4], [12, 4]], |
|
| 506 | - [[ 3, 1], [ 4, 5], [11, 5], [11, 5]], |
|
| 507 | - [[ 5, 1], [ 5, 5], [ 5, 7], [11, 7]], //15 |
|
| 508 | - [[ 5, 1], [ 7, 3], [15, 2], [ 3, 13]], |
|
| 509 | - [[ 1, 5], [10, 1], [ 1, 15], [ 2, 17]], |
|
| 510 | - [[ 5, 1], [ 9, 4], [17, 1], [ 2, 19]], |
|
| 511 | - [[ 3, 4], [ 3, 11], [17, 4], [ 9, 16]], |
|
| 512 | - [[ 3, 5], [ 3, 13], [15, 5], [15, 10]], //20 |
|
| 513 | - [[ 4, 4], [17, 0], [17, 6], [19, 6]], |
|
| 514 | - [[ 2, 7], [17, 0], [ 7, 16], [34, 0]], |
|
| 515 | - [[ 4, 5], [ 4, 14], [11, 14], [16, 14]], |
|
| 516 | - [[ 6, 4], [ 6, 14], [11, 16], [30, 2]], |
|
| 517 | - [[ 8, 4], [ 8, 13], [ 7, 22], [22, 13]], //25 |
|
| 518 | - [[10, 2], [19, 4], [28, 6], [33, 4]], |
|
| 519 | - [[ 8, 4], [22, 3], [ 8, 26], [12, 28]], |
|
| 520 | - [[ 3, 10], [ 3, 23], [ 4, 31], [11, 31]], |
|
| 521 | - [[ 7, 7], [21, 7], [ 1, 37], [19, 26]], |
|
| 522 | - [[ 5, 10], [19, 10], [15, 25], [23, 25]], //30 |
|
| 523 | - [[13, 3], [ 2, 29], [42, 1], [23, 28]], |
|
| 524 | - [[17, 0], [10, 23], [10, 35], [19, 35]], |
|
| 525 | - [[17, 1], [14, 21], [29, 19], [11, 46]], |
|
| 526 | - [[13, 6], [14, 23], [44, 7], [59, 1]], |
|
| 527 | - [[12, 7], [12, 26], [39, 14], [22, 41]], //35 |
|
| 528 | - [[ 6, 14], [ 6, 34], [46, 10], [ 2, 64]], |
|
| 529 | - [[17, 4], [29, 14], [49, 10], [24, 46]], |
|
| 530 | - [[ 4, 18], [13, 32], [48, 14], [42, 32]], |
|
| 531 | - [[20, 4], [40, 7], [43, 22], [10, 67]], |
|
| 532 | - [[19, 6], [18, 31], [34, 34], [20, 61]],//40 |
|
| 492 | + [[0, 0], [0, 0], [0, 0], [0, 0]], |
|
| 493 | + [[1, 0], [1, 0], [1, 0], [1, 0]], // 1 |
|
| 494 | + [[1, 0], [1, 0], [1, 0], [1, 0]], |
|
| 495 | + [[1, 0], [1, 0], [2, 0], [2, 0]], |
|
| 496 | + [[1, 0], [2, 0], [2, 0], [4, 0]], |
|
| 497 | + [[1, 0], [2, 0], [2, 2], [2, 2]], // 5 |
|
| 498 | + [[2, 0], [4, 0], [4, 0], [4, 0]], |
|
| 499 | + [[2, 0], [4, 0], [2, 4], [4, 1]], |
|
| 500 | + [[2, 0], [2, 2], [4, 2], [4, 2]], |
|
| 501 | + [[2, 0], [3, 2], [4, 4], [4, 4]], |
|
| 502 | + [[2, 2], [4, 1], [6, 2], [6, 2]], //10 |
|
| 503 | + [[4, 0], [1, 4], [4, 4], [3, 8]], |
|
| 504 | + [[2, 2], [6, 2], [4, 6], [7, 4]], |
|
| 505 | + [[4, 0], [8, 1], [8, 4], [12, 4]], |
|
| 506 | + [[3, 1], [4, 5], [11, 5], [11, 5]], |
|
| 507 | + [[5, 1], [5, 5], [5, 7], [11, 7]], //15 |
|
| 508 | + [[5, 1], [7, 3], [15, 2], [3, 13]], |
|
| 509 | + [[1, 5], [10, 1], [1, 15], [2, 17]], |
|
| 510 | + [[5, 1], [9, 4], [17, 1], [2, 19]], |
|
| 511 | + [[3, 4], [3, 11], [17, 4], [9, 16]], |
|
| 512 | + [[3, 5], [3, 13], [15, 5], [15, 10]], //20 |
|
| 513 | + [[4, 4], [17, 0], [17, 6], [19, 6]], |
|
| 514 | + [[2, 7], [17, 0], [7, 16], [34, 0]], |
|
| 515 | + [[4, 5], [4, 14], [11, 14], [16, 14]], |
|
| 516 | + [[6, 4], [6, 14], [11, 16], [30, 2]], |
|
| 517 | + [[8, 4], [8, 13], [7, 22], [22, 13]], //25 |
|
| 518 | + [[10, 2], [19, 4], [28, 6], [33, 4]], |
|
| 519 | + [[8, 4], [22, 3], [8, 26], [12, 28]], |
|
| 520 | + [[3, 10], [3, 23], [4, 31], [11, 31]], |
|
| 521 | + [[7, 7], [21, 7], [1, 37], [19, 26]], |
|
| 522 | + [[5, 10], [19, 10], [15, 25], [23, 25]], //30 |
|
| 523 | + [[13, 3], [2, 29], [42, 1], [23, 28]], |
|
| 524 | + [[17, 0], [10, 23], [10, 35], [19, 35]], |
|
| 525 | + [[17, 1], [14, 21], [29, 19], [11, 46]], |
|
| 526 | + [[13, 6], [14, 23], [44, 7], [59, 1]], |
|
| 527 | + [[12, 7], [12, 26], [39, 14], [22, 41]], //35 |
|
| 528 | + [[6, 14], [6, 34], [46, 10], [2, 64]], |
|
| 529 | + [[17, 4], [29, 14], [49, 10], [24, 46]], |
|
| 530 | + [[4, 18], [13, 32], [48, 14], [42, 32]], |
|
| 531 | + [[20, 4], [40, 7], [43, 22], [10, 67]], |
|
| 532 | + [[19, 6], [18, 31], [34, 34], [20, 61]], //40 |
|
| 533 | 533 | ]; |
| 534 | 534 | |
| 535 | 535 | //---------------------------------------------------------------------- |
@@ -538,7 +538,7 @@ discard block |
||
| 538 | 538 | public static function getEccSpec($version, $level, array &$spec) |
| 539 | 539 | {
|
| 540 | 540 | if (count($spec) < 5) {
|
| 541 | - $spec = [0,0,0,0,0]; |
|
| 541 | + $spec = [0, 0, 0, 0, 0]; |
|
| 542 | 542 | } |
| 543 | 543 | |
| 544 | 544 | $b1 = self::$eccTable[$version][$level][0]; |
@@ -546,16 +546,16 @@ discard block |
||
| 546 | 546 | $data = self::getDataLength($version, $level); |
| 547 | 547 | $ecc = self::getECCLength($version, $level); |
| 548 | 548 | |
| 549 | - if($b2 == 0) {
|
|
| 549 | + if ($b2 == 0) {
|
|
| 550 | 550 | $spec[0] = $b1; |
| 551 | - $spec[1] = (int)($data / $b1); |
|
| 552 | - $spec[2] = (int)($ecc / $b1); |
|
| 551 | + $spec[1] = (int) ($data / $b1); |
|
| 552 | + $spec[2] = (int) ($ecc / $b1); |
|
| 553 | 553 | $spec[3] = 0; |
| 554 | 554 | $spec[4] = 0; |
| 555 | 555 | } else {
|
| 556 | 556 | $spec[0] = $b1; |
| 557 | - $spec[1] = (int)($data / ($b1 + $b2)); |
|
| 558 | - $spec[2] = (int)($ecc / ($b1 + $b2)); |
|
| 557 | + $spec[1] = (int) ($data / ($b1 + $b2)); |
|
| 558 | + $spec[2] = (int) ($ecc / ($b1 + $b2)); |
|
| 559 | 559 | $spec[3] = $b2; |
| 560 | 560 | $spec[4] = $spec[1] + 1; |
| 561 | 561 | } |
@@ -571,9 +571,9 @@ discard block |
||
| 571 | 571 | // See Table 1 in Appendix E (pp.71) of JIS X0510:2004. |
| 572 | 572 | |
| 573 | 573 | public static $alignmentPattern = [ |
| 574 | - [ 0, 0], |
|
| 575 | - [ 0, 0], [18, 0], [22, 0], [26, 0], [30, 0], // 1- 5 |
|
| 576 | - [34, 0], [22, 38], [24, 42], [26, 46], [28, 50], // 6-10 |
|
| 574 | + [0, 0], |
|
| 575 | + [0, 0], [18, 0], [22, 0], [26, 0], [30, 0], // 1- 5 |
|
| 576 | + [34, 0], [22, 38], [24, 42], [26, 46], [28, 50], // 6-10 |
|
| 577 | 577 | [30, 54], [32, 58], [34, 62], [26, 46], [26, 48], //11-15 |
| 578 | 578 | [26, 50], [30, 54], [30, 56], [30, 58], [34, 62], //16-20 |
| 579 | 579 | [28, 50], [26, 50], [30, 54], [28, 54], [32, 58], //21-25 |
@@ -599,28 +599,28 @@ discard block |
||
| 599 | 599 | "\xa1\xa1\xa1\xa1\xa1" |
| 600 | 600 | ]; |
| 601 | 601 | |
| 602 | - $yStart = $oy-2; |
|
| 603 | - $xStart = $ox-2; |
|
| 602 | + $yStart = $oy - 2; |
|
| 603 | + $xStart = $ox - 2; |
|
| 604 | 604 | |
| 605 | - for($y=0; $y<5; $y++) {
|
|
| 606 | - QRstr::set($frame, $xStart, $yStart+$y, $finder[$y]); |
|
| 605 | + for ($y = 0; $y < 5; $y++) {
|
|
| 606 | + QRstr::set($frame, $xStart, $yStart + $y, $finder[$y]); |
|
| 607 | 607 | } |
| 608 | 608 | } |
| 609 | 609 | |
| 610 | 610 | //---------------------------------------------------------------------- |
| 611 | 611 | public static function putAlignmentPattern($version, &$frame, $width) |
| 612 | 612 | {
|
| 613 | - if($version < 2) |
|
| 613 | + if ($version < 2) |
|
| 614 | 614 | return; |
| 615 | 615 | |
| 616 | 616 | $d = self::$alignmentPattern[$version][1] - self::$alignmentPattern[$version][0]; |
| 617 | - if($d < 0) {
|
|
| 617 | + if ($d < 0) {
|
|
| 618 | 618 | $w = 2; |
| 619 | 619 | } else {
|
| 620 | - $w = (int)(($width - self::$alignmentPattern[$version][0]) / $d + 2); |
|
| 620 | + $w = (int) (($width - self::$alignmentPattern[$version][0]) / $d + 2); |
|
| 621 | 621 | } |
| 622 | 622 | |
| 623 | - if($w * $w - 3 == 1) {
|
|
| 623 | + if ($w * $w - 3 == 1) {
|
|
| 624 | 624 | $x = self::$alignmentPattern[$version][0]; |
| 625 | 625 | $y = self::$alignmentPattern[$version][0]; |
| 626 | 626 | self::putAlignmentMarker($frame, $x, $y); |
@@ -628,16 +628,16 @@ discard block |
||
| 628 | 628 | } |
| 629 | 629 | |
| 630 | 630 | $cx = self::$alignmentPattern[$version][0]; |
| 631 | - for($x=1; $x<$w - 1; $x++) {
|
|
| 631 | + for ($x = 1; $x < $w - 1; $x++) {
|
|
| 632 | 632 | self::putAlignmentMarker($frame, 6, $cx); |
| 633 | - self::putAlignmentMarker($frame, $cx, 6); |
|
| 633 | + self::putAlignmentMarker($frame, $cx, 6); |
|
| 634 | 634 | $cx += $d; |
| 635 | 635 | } |
| 636 | 636 | |
| 637 | 637 | $cy = self::$alignmentPattern[$version][0]; |
| 638 | - for($y=0; $y<$w-1; $y++) {
|
|
| 638 | + for ($y = 0; $y < $w - 1; $y++) {
|
|
| 639 | 639 | $cx = self::$alignmentPattern[$version][0]; |
| 640 | - for($x=0; $x<$w-1; $x++) {
|
|
| 640 | + for ($x = 0; $x < $w - 1; $x++) {
|
|
| 641 | 641 | self::putAlignmentMarker($frame, $cx, $cy); |
| 642 | 642 | $cx += $d; |
| 643 | 643 | } |
@@ -663,10 +663,10 @@ discard block |
||
| 663 | 663 | //---------------------------------------------------------------------- |
| 664 | 664 | public static function getVersionPattern($version) |
| 665 | 665 | {
|
| 666 | - if($version < 7 || $version > QRSPEC_VERSION_MAX) |
|
| 666 | + if ($version < 7 || $version > QRSPEC_VERSION_MAX) |
|
| 667 | 667 | return 0; |
| 668 | 668 | |
| 669 | - return self::$versionPattern[$version -7]; |
|
| 669 | + return self::$versionPattern[$version - 7]; |
|
| 670 | 670 | } |
| 671 | 671 | |
| 672 | 672 | // Format information -------------------------------------------------- |
@@ -681,10 +681,10 @@ discard block |
||
| 681 | 681 | |
| 682 | 682 | public static function getFormatInfo($mask, $level) |
| 683 | 683 | {
|
| 684 | - if($mask < 0 || $mask > 7) |
|
| 684 | + if ($mask < 0 || $mask > 7) |
|
| 685 | 685 | return 0; |
| 686 | 686 | |
| 687 | - if($level < 0 || $level > 3) |
|
| 687 | + if ($level < 0 || $level > 3) |
|
| 688 | 688 | return 0; |
| 689 | 689 | |
| 690 | 690 | return self::$formatInfo[$level][$mask]; |
@@ -713,8 +713,8 @@ discard block |
||
| 713 | 713 | "\xc1\xc1\xc1\xc1\xc1\xc1\xc1" |
| 714 | 714 | ]; |
| 715 | 715 | |
| 716 | - for($y=0; $y<7; $y++) {
|
|
| 717 | - QRstr::set($frame, $ox, $oy+$y, $finder[$y]); |
|
| 716 | + for ($y = 0; $y < 7; $y++) {
|
|
| 717 | + QRstr::set($frame, $ox, $oy + $y, $finder[$y]); |
|
| 718 | 718 | } |
| 719 | 719 | } |
| 720 | 720 | |
@@ -722,7 +722,7 @@ discard block |
||
| 722 | 722 | public static function createFrame($version) |
| 723 | 723 | {
|
| 724 | 724 | $width = self::$capacity[$version][QRCAP_WIDTH]; |
| 725 | - $frameLine = str_repeat ("\0", $width);
|
|
| 725 | + $frameLine = str_repeat("\0", $width);
|
|
| 726 | 726 | $frame = array_fill(0, $width, $frameLine); |
| 727 | 727 | |
| 728 | 728 | // Finder pattern |
@@ -733,7 +733,7 @@ discard block |
||
| 733 | 733 | // Separator |
| 734 | 734 | $yOffset = $width - 7; |
| 735 | 735 | |
| 736 | - for($y=0; $y<7; $y++) {
|
|
| 736 | + for ($y = 0; $y < 7; $y++) {
|
|
| 737 | 737 | $frame[$y][7] = "\xc0"; |
| 738 | 738 | $frame[$y][$width - 8] = "\xc0"; |
| 739 | 739 | $frame[$yOffset][7] = "\xc0"; |
@@ -743,7 +743,7 @@ discard block |
||
| 743 | 743 | $setPattern = str_repeat("\xc0", 8);
|
| 744 | 744 | |
| 745 | 745 | QRstr::set($frame, 0, 7, $setPattern); |
| 746 | - QRstr::set($frame, $width-8, 7, $setPattern); |
|
| 746 | + QRstr::set($frame, $width - 8, 7, $setPattern); |
|
| 747 | 747 | QRstr::set($frame, 0, $width - 8, $setPattern); |
| 748 | 748 | |
| 749 | 749 | // Format info |
@@ -753,38 +753,38 @@ discard block |
||
| 753 | 753 | |
| 754 | 754 | $yOffset = $width - 8; |
| 755 | 755 | |
| 756 | - for($y=0; $y<8; $y++,$yOffset++) {
|
|
| 756 | + for ($y = 0; $y < 8; $y++, $yOffset++) {
|
|
| 757 | 757 | $frame[$y][8] = "\x84"; |
| 758 | 758 | $frame[$yOffset][8] = "\x84"; |
| 759 | 759 | } |
| 760 | 760 | |
| 761 | 761 | // Timing pattern |
| 762 | 762 | |
| 763 | - for($i=1; $i<$width-15; $i++) {
|
|
| 764 | - $frame[6][7+$i] = chr(0x90 | ($i & 1)); |
|
| 765 | - $frame[7+$i][6] = chr(0x90 | ($i & 1)); |
|
| 763 | + for ($i = 1; $i < $width - 15; $i++) {
|
|
| 764 | + $frame[6][7 + $i] = chr(0x90 | ($i & 1)); |
|
| 765 | + $frame[7 + $i][6] = chr(0x90 | ($i & 1)); |
|
| 766 | 766 | } |
| 767 | 767 | |
| 768 | 768 | // Alignment pattern |
| 769 | 769 | self::putAlignmentPattern($version, $frame, $width); |
| 770 | 770 | |
| 771 | 771 | // Version information |
| 772 | - if($version >= 7) {
|
|
| 772 | + if ($version >= 7) {
|
|
| 773 | 773 | $vinf = self::getVersionPattern($version); |
| 774 | 774 | |
| 775 | 775 | $v = $vinf; |
| 776 | 776 | |
| 777 | - for($x=0; $x<6; $x++) {
|
|
| 778 | - for($y=0; $y<3; $y++) {
|
|
| 779 | - $frame[($width - 11)+$y][$x] = chr(0x88 | ($v & 1)); |
|
| 777 | + for ($x = 0; $x < 6; $x++) {
|
|
| 778 | + for ($y = 0; $y < 3; $y++) {
|
|
| 779 | + $frame[($width - 11) + $y][$x] = chr(0x88 | ($v & 1)); |
|
| 780 | 780 | $v = $v >> 1; |
| 781 | 781 | } |
| 782 | 782 | } |
| 783 | 783 | |
| 784 | 784 | $v = $vinf; |
| 785 | - for($y=0; $y<6; $y++) {
|
|
| 786 | - for($x=0; $x<3; $x++) {
|
|
| 787 | - $frame[$y][$x+($width - 11)] = chr(0x88 | ($v & 1)); |
|
| 785 | + for ($y = 0; $y < 6; $y++) {
|
|
| 786 | + for ($x = 0; $x < 3; $x++) {
|
|
| 787 | + $frame[$y][$x + ($width - 11)] = chr(0x88 | ($v & 1)); |
|
| 788 | 788 | $v = $v >> 1; |
| 789 | 789 | } |
| 790 | 790 | } |
@@ -818,16 +818,16 @@ discard block |
||
| 818 | 818 | } else {
|
| 819 | 819 | |
| 820 | 820 | foreach ($frame as &$frameLine) {
|
| 821 | - $frameLine = join('<span class="m"> </span>', explode("\xc0", $frameLine));
|
|
| 821 | + $frameLine = join('<span class="m"> </span>', explode("\xc0", $frameLine));
|
|
| 822 | 822 | $frameLine = join('<span class="m">▒</span>', explode("\xc1", $frameLine));
|
| 823 | - $frameLine = join('<span class="p"> </span>', explode("\xa0", $frameLine));
|
|
| 823 | + $frameLine = join('<span class="p"> </span>', explode("\xa0", $frameLine));
|
|
| 824 | 824 | $frameLine = join('<span class="p">▒</span>', explode("\xa1", $frameLine));
|
| 825 | 825 | $frameLine = join('<span class="s">◇</span>', explode("\x84", $frameLine)); //format 0
|
| 826 | 826 | $frameLine = join('<span class="s">◆</span>', explode("\x85", $frameLine)); //format 1
|
| 827 | 827 | $frameLine = join('<span class="x">☢</span>', explode("\x81", $frameLine)); //special bit
|
| 828 | - $frameLine = join('<span class="c"> </span>', explode("\x90", $frameLine)); //clock 0
|
|
| 828 | + $frameLine = join('<span class="c"> </span>', explode("\x90", $frameLine)); //clock 0
|
|
| 829 | 829 | $frameLine = join('<span class="c">◷</span>', explode("\x91", $frameLine)); //clock 1
|
| 830 | - $frameLine = join('<span class="f"> </span>', explode("\x88", $frameLine)); //version
|
|
| 830 | + $frameLine = join('<span class="f"> </span>', explode("\x88", $frameLine)); //version
|
|
| 831 | 831 | $frameLine = join('<span class="f">▒</span>', explode("\x89", $frameLine)); //version
|
| 832 | 832 | $frameLine = join('♦', explode("\x01", $frameLine));
|
| 833 | 833 | $frameLine = join('⋅', explode("\0", $frameLine));
|
@@ -865,12 +865,12 @@ discard block |
||
| 865 | 865 | //---------------------------------------------------------------------- |
| 866 | 866 | public static function newFrame($version) |
| 867 | 867 | {
|
| 868 | - if($version < 1 || $version > QRSPEC_VERSION_MAX) |
|
| 868 | + if ($version < 1 || $version > QRSPEC_VERSION_MAX) |
|
| 869 | 869 | return null; |
| 870 | 870 | |
| 871 | - if(!isset(self::$frames[$version])) {
|
|
| 871 | + if (!isset(self::$frames[$version])) {
|
|
| 872 | 872 | |
| 873 | - $fileName = QR_CACHE_DIR.'frame_'.$version.'.dat'; |
|
| 873 | + $fileName = QR_CACHE_DIR . 'frame_' . $version . '.dat'; |
|
| 874 | 874 | |
| 875 | 875 | if (QR_CACHEABLE) {
|
| 876 | 876 | if (file_exists($fileName)) {
|
@@ -884,22 +884,22 @@ discard block |
||
| 884 | 884 | } |
| 885 | 885 | } |
| 886 | 886 | |
| 887 | - if(is_null(self::$frames[$version])) |
|
| 887 | + if (is_null(self::$frames[$version])) |
|
| 888 | 888 | return null; |
| 889 | 889 | |
| 890 | 890 | return self::$frames[$version]; |
| 891 | 891 | } |
| 892 | 892 | |
| 893 | 893 | //---------------------------------------------------------------------- |
| 894 | - public static function rsBlockNum($spec) { return $spec[0] + $spec[3]; }
|
|
| 895 | - public static function rsBlockNum1($spec) { return $spec[0]; }
|
|
| 896 | - public static function rsDataCodes1($spec) { return $spec[1]; }
|
|
| 897 | - public static function rsEccCodes1($spec) { return $spec[2]; }
|
|
| 898 | - public static function rsBlockNum2($spec) { return $spec[3]; }
|
|
| 899 | - public static function rsDataCodes2($spec) { return $spec[4]; }
|
|
| 900 | - public static function rsEccCodes2($spec) { return $spec[2]; }
|
|
| 901 | - public static function rsDataLength($spec) { return ($spec[0] * $spec[1]) + ($spec[3] * $spec[4]); }
|
|
| 902 | - public static function rsEccLength($spec) { return ($spec[0] + $spec[3]) * $spec[2]; }
|
|
| 894 | + public static function rsBlockNum($spec) { return $spec[0] + $spec[3]; }
|
|
| 895 | + public static function rsBlockNum1($spec) { return $spec[0]; }
|
|
| 896 | + public static function rsDataCodes1($spec) { return $spec[1]; }
|
|
| 897 | + public static function rsEccCodes1($spec) { return $spec[2]; }
|
|
| 898 | + public static function rsBlockNum2($spec) { return $spec[3]; }
|
|
| 899 | + public static function rsDataCodes2($spec) { return $spec[4]; }
|
|
| 900 | + public static function rsEccCodes2($spec) { return $spec[2]; }
|
|
| 901 | + public static function rsDataLength($spec) { return ($spec[0] * $spec[1]) + ($spec[3] * $spec[4]); }
|
|
| 902 | + public static function rsEccLength($spec) { return ($spec[0] + $spec[3]) * $spec[2]; }
|
|
| 903 | 903 | |
| 904 | 904 | } |
| 905 | 905 | |
@@ -938,7 +938,7 @@ discard block |
||
| 938 | 938 | class QRimage {
|
| 939 | 939 | |
| 940 | 940 | //---------------------------------------------------------------------- |
| 941 | - public static function png($frame, $filename = false, $pixelPerPoint = 4, $outerFrame = 4,$saveandprint=FALSE) |
|
| 941 | + public static function png($frame, $filename = false, $pixelPerPoint = 4, $outerFrame = 4, $saveandprint = FALSE) |
|
| 942 | 942 | {
|
| 943 | 943 | $image = self::image($frame, $pixelPerPoint, $outerFrame); |
| 944 | 944 | |
@@ -949,11 +949,11 @@ discard block |
||
| 949 | 949 | $output = ob_get_clean(); |
| 950 | 950 | return $output; |
| 951 | 951 | } else {
|
| 952 | - if($saveandprint===TRUE){
|
|
| 952 | + if ($saveandprint === TRUE) {
|
|
| 953 | 953 | ImagePng($image, $filename); |
| 954 | 954 | header("Content-type: image/png");
|
| 955 | 955 | ImagePng($image); |
| 956 | - }else{
|
|
| 956 | + } else {
|
|
| 957 | 957 | ImagePng($image, $filename); |
| 958 | 958 | } |
| 959 | 959 | } |
@@ -982,25 +982,25 @@ discard block |
||
| 982 | 982 | $h = count($frame); |
| 983 | 983 | $w = strlen($frame[0]); |
| 984 | 984 | |
| 985 | - $imgW = $w + 2*$outerFrame; |
|
| 986 | - $imgH = $h + 2*$outerFrame; |
|
| 985 | + $imgW = $w + 2 * $outerFrame; |
|
| 986 | + $imgH = $h + 2 * $outerFrame; |
|
| 987 | 987 | |
| 988 | - $base_image =ImageCreate($imgW, $imgH); |
|
| 988 | + $base_image = ImageCreate($imgW, $imgH); |
|
| 989 | 989 | |
| 990 | - $col[0] = ImageColorAllocate($base_image,255,255,255); |
|
| 991 | - $col[1] = ImageColorAllocate($base_image,0,0,0); |
|
| 990 | + $col[0] = ImageColorAllocate($base_image, 255, 255, 255); |
|
| 991 | + $col[1] = ImageColorAllocate($base_image, 0, 0, 0); |
|
| 992 | 992 | |
| 993 | 993 | imagefill($base_image, 0, 0, $col[0]); |
| 994 | 994 | |
| 995 | - for($y=0; $y<$h; $y++) {
|
|
| 996 | - for($x=0; $x<$w; $x++) {
|
|
| 995 | + for ($y = 0; $y < $h; $y++) {
|
|
| 996 | + for ($x = 0; $x < $w; $x++) {
|
|
| 997 | 997 | if ($frame[$y][$x] == '1') {
|
| 998 | - ImageSetPixel($base_image,$x+$outerFrame,$y+$outerFrame,$col[1]); |
|
| 998 | + ImageSetPixel($base_image, $x + $outerFrame, $y + $outerFrame, $col[1]); |
|
| 999 | 999 | } |
| 1000 | 1000 | } |
| 1001 | 1001 | } |
| 1002 | 1002 | |
| 1003 | - $target_image =ImageCreate($imgW * $pixelPerPoint, $imgH * $pixelPerPoint); |
|
| 1003 | + $target_image = ImageCreate($imgW * $pixelPerPoint, $imgH * $pixelPerPoint); |
|
| 1004 | 1004 | ImageCopyResized($target_image, $base_image, 0, 0, 0, 0, $imgW * $pixelPerPoint, $imgH * $pixelPerPoint, $imgW, $imgH); |
| 1005 | 1005 | ImageDestroy($base_image); |
| 1006 | 1006 | |
@@ -1041,7 +1041,7 @@ discard block |
||
| 1041 | 1041 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 1042 | 1042 | */ |
| 1043 | 1043 | |
| 1044 | - define('STRUCTURE_HEADER_BITS', 20);
|
|
| 1044 | + define('STRUCTURE_HEADER_BITS', 20);
|
|
| 1045 | 1045 | define('MAX_STRUCTURED_SYMBOLS', 16);
|
| 1046 | 1046 | |
| 1047 | 1047 | class QRinputItem {
|
@@ -1056,11 +1056,11 @@ discard block |
||
| 1056 | 1056 | $setData = array_slice($data, 0, $size); |
| 1057 | 1057 | |
| 1058 | 1058 | if (count($setData) < $size) {
|
| 1059 | - $setData = array_merge($setData, array_fill(0,$size-count($setData),0)); |
|
| 1059 | + $setData = array_merge($setData, array_fill(0, $size - count($setData), 0)); |
|
| 1060 | 1060 | } |
| 1061 | 1061 | |
| 1062 | - if(!QRinput::check($mode, $size, $setData)) {
|
|
| 1063 | - throw new Exception('Error m:'.$mode.',s:'.$size.',d:'.join(',',$setData));
|
|
| 1062 | + if (!QRinput::check($mode, $size, $setData)) {
|
|
| 1063 | + throw new Exception('Error m:' . $mode . ',s:' . $size . ',d:' . join(',', $setData));
|
|
| 1064 | 1064 | return null; |
| 1065 | 1065 | } |
| 1066 | 1066 | |
@@ -1075,26 +1075,26 @@ discard block |
||
| 1075 | 1075 | {
|
| 1076 | 1076 | try {
|
| 1077 | 1077 | |
| 1078 | - $words = (int)($this->size / 3); |
|
| 1078 | + $words = (int) ($this->size / 3); |
|
| 1079 | 1079 | $bs = new QRbitstream(); |
| 1080 | 1080 | |
| 1081 | 1081 | $val = 0x1; |
| 1082 | 1082 | $bs->appendNum(4, $val); |
| 1083 | 1083 | $bs->appendNum(QRspec::lengthIndicator(QR_MODE_NUM, $version), $this->size); |
| 1084 | 1084 | |
| 1085 | - for($i=0; $i<$words; $i++) {
|
|
| 1086 | - $val = (ord($this->data[$i*3 ]) - ord('0')) * 100;
|
|
| 1087 | - $val += (ord($this->data[$i*3+1]) - ord('0')) * 10;
|
|
| 1088 | - $val += (ord($this->data[$i*3+2]) - ord('0'));
|
|
| 1085 | + for ($i = 0; $i < $words; $i++) {
|
|
| 1086 | + $val = (ord($this->data[$i * 3]) - ord('0')) * 100;
|
|
| 1087 | + $val += (ord($this->data[$i * 3 + 1]) - ord('0')) * 10;
|
|
| 1088 | + $val += (ord($this->data[$i * 3 + 2]) - ord('0'));
|
|
| 1089 | 1089 | $bs->appendNum(10, $val); |
| 1090 | 1090 | } |
| 1091 | 1091 | |
| 1092 | - if($this->size - $words * 3 == 1) {
|
|
| 1093 | - $val = ord($this->data[$words*3]) - ord('0');
|
|
| 1092 | + if ($this->size - $words * 3 == 1) {
|
|
| 1093 | + $val = ord($this->data[$words * 3]) - ord('0');
|
|
| 1094 | 1094 | $bs->appendNum(4, $val); |
| 1095 | - } else if($this->size - $words * 3 == 2) {
|
|
| 1096 | - $val = (ord($this->data[$words*3 ]) - ord('0')) * 10;
|
|
| 1097 | - $val += (ord($this->data[$words*3+1]) - ord('0'));
|
|
| 1095 | + } else if ($this->size - $words * 3 == 2) {
|
|
| 1096 | + $val = (ord($this->data[$words * 3]) - ord('0')) * 10;
|
|
| 1097 | + $val += (ord($this->data[$words * 3 + 1]) - ord('0'));
|
|
| 1098 | 1098 | $bs->appendNum(7, $val); |
| 1099 | 1099 | } |
| 1100 | 1100 | |
@@ -1110,20 +1110,20 @@ discard block |
||
| 1110 | 1110 | public function encodeModeAn($version) |
| 1111 | 1111 | {
|
| 1112 | 1112 | try {
|
| 1113 | - $words = (int)($this->size / 2); |
|
| 1113 | + $words = (int) ($this->size / 2); |
|
| 1114 | 1114 | $bs = new QRbitstream(); |
| 1115 | 1115 | |
| 1116 | 1116 | $bs->appendNum(4, 0x02); |
| 1117 | 1117 | $bs->appendNum(QRspec::lengthIndicator(QR_MODE_AN, $version), $this->size); |
| 1118 | 1118 | |
| 1119 | - for($i=0; $i<$words; $i++) {
|
|
| 1120 | - $val = (int)QRinput::lookAnTable(ord($this->data[$i*2 ])) * 45; |
|
| 1121 | - $val += (int)QRinput::lookAnTable(ord($this->data[$i*2+1])); |
|
| 1119 | + for ($i = 0; $i < $words; $i++) {
|
|
| 1120 | + $val = (int) QRinput::lookAnTable(ord($this->data[$i * 2])) * 45; |
|
| 1121 | + $val += (int) QRinput::lookAnTable(ord($this->data[$i * 2 + 1])); |
|
| 1122 | 1122 | |
| 1123 | 1123 | $bs->appendNum(11, $val); |
| 1124 | 1124 | } |
| 1125 | 1125 | |
| 1126 | - if($this->size & 1) {
|
|
| 1126 | + if ($this->size & 1) {
|
|
| 1127 | 1127 | $val = QRinput::lookAnTable(ord($this->data[$words * 2])); |
| 1128 | 1128 | $bs->appendNum(6, $val); |
| 1129 | 1129 | } |
@@ -1145,7 +1145,7 @@ discard block |
||
| 1145 | 1145 | $bs->appendNum(4, 0x4); |
| 1146 | 1146 | $bs->appendNum(QRspec::lengthIndicator(QR_MODE_8, $version), $this->size); |
| 1147 | 1147 | |
| 1148 | - for($i=0; $i<$this->size; $i++) {
|
|
| 1148 | + for ($i = 0; $i < $this->size; $i++) {
|
|
| 1149 | 1149 | $bs->appendNum(8, ord($this->data[$i])); |
| 1150 | 1150 | } |
| 1151 | 1151 | |
@@ -1165,11 +1165,11 @@ discard block |
||
| 1165 | 1165 | $bs = new QRbitrtream(); |
| 1166 | 1166 | |
| 1167 | 1167 | $bs->appendNum(4, 0x8); |
| 1168 | - $bs->appendNum(QRspec::lengthIndicator(QR_MODE_KANJI, $version), (int)($this->size / 2)); |
|
| 1168 | + $bs->appendNum(QRspec::lengthIndicator(QR_MODE_KANJI, $version), (int) ($this->size / 2)); |
|
| 1169 | 1169 | |
| 1170 | - for($i=0; $i<$this->size; $i+=2) {
|
|
| 1171 | - $val = (ord($this->data[$i]) << 8) | ord($this->data[$i+1]); |
|
| 1172 | - if($val <= 0x9ffc) {
|
|
| 1170 | + for ($i = 0; $i < $this->size; $i += 2) {
|
|
| 1171 | + $val = (ord($this->data[$i]) << 8) | ord($this->data[$i + 1]); |
|
| 1172 | + if ($val <= 0x9ffc) {
|
|
| 1173 | 1173 | $val -= 0x8140; |
| 1174 | 1174 | } else {
|
| 1175 | 1175 | $val -= 0xc140; |
@@ -1193,7 +1193,7 @@ discard block |
||
| 1193 | 1193 | public function encodeModeStructure() |
| 1194 | 1194 | {
|
| 1195 | 1195 | try {
|
| 1196 | - $bs = new QRbitstream(); |
|
| 1196 | + $bs = new QRbitstream(); |
|
| 1197 | 1197 | |
| 1198 | 1198 | $bs->appendNum(4, 0x03); |
| 1199 | 1199 | $bs->appendNum(4, ord($this->data[1]) - 1); |
@@ -1213,14 +1213,14 @@ discard block |
||
| 1213 | 1213 | {
|
| 1214 | 1214 | $bits = 0; |
| 1215 | 1215 | |
| 1216 | - if($version == 0) |
|
| 1216 | + if ($version == 0) |
|
| 1217 | 1217 | $version = 1; |
| 1218 | 1218 | |
| 1219 | - switch($this->mode) {
|
|
| 1220 | - case QR_MODE_NUM: $bits = QRinput::estimateBitsModeNum($this->size); break; |
|
| 1221 | - case QR_MODE_AN: $bits = QRinput::estimateBitsModeAn($this->size); break; |
|
| 1222 | - case QR_MODE_8: $bits = QRinput::estimateBitsMode8($this->size); break; |
|
| 1223 | - case QR_MODE_KANJI: $bits = QRinput::estimateBitsModeKanji($this->size);break; |
|
| 1219 | + switch ($this->mode) {
|
|
| 1220 | + case QR_MODE_NUM: $bits = QRinput::estimateBitsModeNum($this->size); break; |
|
| 1221 | + case QR_MODE_AN: $bits = QRinput::estimateBitsModeAn($this->size); break; |
|
| 1222 | + case QR_MODE_8: $bits = QRinput::estimateBitsMode8($this->size); break; |
|
| 1223 | + case QR_MODE_KANJI: $bits = QRinput::estimateBitsModeKanji($this->size); break; |
|
| 1224 | 1224 | case QR_MODE_STRUCTURE: return STRUCTURE_HEADER_BITS; |
| 1225 | 1225 | default: |
| 1226 | 1226 | return 0; |
@@ -1228,7 +1228,7 @@ discard block |
||
| 1228 | 1228 | |
| 1229 | 1229 | $l = QRspec::lengthIndicator($this->mode, $version); |
| 1230 | 1230 | $m = 1 << $l; |
| 1231 | - $num = (int)(($this->size + $m - 1) / $m); |
|
| 1231 | + $num = (int) (($this->size + $m - 1) / $m); |
|
| 1232 | 1232 | |
| 1233 | 1233 | $bits += $num * (4 + $l); |
| 1234 | 1234 | |
@@ -1243,7 +1243,7 @@ discard block |
||
| 1243 | 1243 | unset($this->bstream); |
| 1244 | 1244 | $words = QRspec::maximumWords($this->mode, $version); |
| 1245 | 1245 | |
| 1246 | - if($this->size > $words) {
|
|
| 1246 | + if ($this->size > $words) {
|
|
| 1247 | 1247 | |
| 1248 | 1248 | $st1 = new QRinputItem($this->mode, $words, $this->data); |
| 1249 | 1249 | $st2 = new QRinputItem($this->mode, $this->size - $words, array_slice($this->data, $words)); |
@@ -1262,18 +1262,18 @@ discard block |
||
| 1262 | 1262 | |
| 1263 | 1263 | $ret = 0; |
| 1264 | 1264 | |
| 1265 | - switch($this->mode) {
|
|
| 1266 | - case QR_MODE_NUM: $ret = $this->encodeModeNum($version); break; |
|
| 1267 | - case QR_MODE_AN: $ret = $this->encodeModeAn($version); break; |
|
| 1268 | - case QR_MODE_8: $ret = $this->encodeMode8($version); break; |
|
| 1269 | - case QR_MODE_KANJI: $ret = $this->encodeModeKanji($version);break; |
|
| 1270 | - case QR_MODE_STRUCTURE: $ret = $this->encodeModeStructure(); break; |
|
| 1265 | + switch ($this->mode) {
|
|
| 1266 | + case QR_MODE_NUM: $ret = $this->encodeModeNum($version); break; |
|
| 1267 | + case QR_MODE_AN: $ret = $this->encodeModeAn($version); break; |
|
| 1268 | + case QR_MODE_8: $ret = $this->encodeMode8($version); break; |
|
| 1269 | + case QR_MODE_KANJI: $ret = $this->encodeModeKanji($version); break; |
|
| 1270 | + case QR_MODE_STRUCTURE: $ret = $this->encodeModeStructure(); break; |
|
| 1271 | 1271 | |
| 1272 | 1272 | default: |
| 1273 | 1273 | break; |
| 1274 | 1274 | } |
| 1275 | 1275 | |
| 1276 | - if($ret < 0) |
|
| 1276 | + if ($ret < 0) |
|
| 1277 | 1277 | return -1; |
| 1278 | 1278 | } |
| 1279 | 1279 | |
@@ -1315,7 +1315,7 @@ discard block |
||
| 1315 | 1315 | //---------------------------------------------------------------------- |
| 1316 | 1316 | public function setVersion($version) |
| 1317 | 1317 | {
|
| 1318 | - if($version < 0 || $version > QRSPEC_VERSION_MAX) {
|
|
| 1318 | + if ($version < 0 || $version > QRSPEC_VERSION_MAX) {
|
|
| 1319 | 1319 | throw new Exception('Invalid version no');
|
| 1320 | 1320 | return -1; |
| 1321 | 1321 | } |
@@ -1334,7 +1334,7 @@ discard block |
||
| 1334 | 1334 | //---------------------------------------------------------------------- |
| 1335 | 1335 | public function setErrorCorrectionLevel($level) |
| 1336 | 1336 | {
|
| 1337 | - if($level > QR_ECLEVEL_H) {
|
|
| 1337 | + if ($level > QR_ECLEVEL_H) {
|
|
| 1338 | 1338 | throw new Exception('Invalid ECLEVEL');
|
| 1339 | 1339 | return -1; |
| 1340 | 1340 | } |
@@ -1366,11 +1366,11 @@ discard block |
||
| 1366 | 1366 | |
| 1367 | 1367 | public function insertStructuredAppendHeader($size, $index, $parity) |
| 1368 | 1368 | {
|
| 1369 | - if( $size > MAX_STRUCTURED_SYMBOLS ) {
|
|
| 1369 | + if ($size > MAX_STRUCTURED_SYMBOLS) {
|
|
| 1370 | 1370 | throw new Exception('insertStructuredAppendHeader wrong size');
|
| 1371 | 1371 | } |
| 1372 | 1372 | |
| 1373 | - if( $index <= 0 || $index > MAX_STRUCTURED_SYMBOLS ) {
|
|
| 1373 | + if ($index <= 0 || $index > MAX_STRUCTURED_SYMBOLS) {
|
|
| 1374 | 1374 | throw new Exception('insertStructuredAppendHeader wrong index');
|
| 1375 | 1375 | } |
| 1376 | 1376 | |
@@ -1390,9 +1390,9 @@ discard block |
||
| 1390 | 1390 | {
|
| 1391 | 1391 | $parity = 0; |
| 1392 | 1392 | |
| 1393 | - foreach($this->items as $item) {
|
|
| 1394 | - if($item->mode != QR_MODE_STRUCTURE) {
|
|
| 1395 | - for($i=$item->size-1; $i>=0; $i--) {
|
|
| 1393 | + foreach ($this->items as $item) {
|
|
| 1394 | + if ($item->mode != QR_MODE_STRUCTURE) {
|
|
| 1395 | + for ($i = $item->size - 1; $i >= 0; $i--) {
|
|
| 1396 | 1396 | $parity ^= $item->data[$i]; |
| 1397 | 1397 | } |
| 1398 | 1398 | } |
@@ -1404,8 +1404,8 @@ discard block |
||
| 1404 | 1404 | //---------------------------------------------------------------------- |
| 1405 | 1405 | public static function checkModeNum($size, $data) |
| 1406 | 1406 | {
|
| 1407 | - for($i=0; $i<$size; $i++) {
|
|
| 1408 | - if((ord($data[$i]) < ord('0')) || (ord($data[$i]) > ord('9'))){
|
|
| 1407 | + for ($i = 0; $i < $size; $i++) {
|
|
| 1408 | + if ((ord($data[$i]) < ord('0')) || (ord($data[$i]) > ord('9'))) {
|
|
| 1409 | 1409 | return false; |
| 1410 | 1410 | } |
| 1411 | 1411 | } |
@@ -1416,10 +1416,10 @@ discard block |
||
| 1416 | 1416 | //---------------------------------------------------------------------- |
| 1417 | 1417 | public static function estimateBitsModeNum($size) |
| 1418 | 1418 | {
|
| 1419 | - $w = (int)$size / 3; |
|
| 1419 | + $w = (int) $size / 3; |
|
| 1420 | 1420 | $bits = $w * 10; |
| 1421 | 1421 | |
| 1422 | - switch($size - $w * 3) {
|
|
| 1422 | + switch ($size - $w * 3) {
|
|
| 1423 | 1423 | case 1: |
| 1424 | 1424 | $bits += 4; |
| 1425 | 1425 | break; |
@@ -1438,7 +1438,7 @@ discard block |
||
| 1438 | 1438 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
| 1439 | 1439 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
| 1440 | 1440 | 36, -1, -1, -1, 37, 38, -1, -1, -1, -1, 39, 40, -1, 41, 42, 43, |
| 1441 | - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 44, -1, -1, -1, -1, -1, |
|
| 1441 | + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 44, -1, -1, -1, -1, -1, |
|
| 1442 | 1442 | -1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, |
| 1443 | 1443 | 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, -1, -1, -1, -1, -1, |
| 1444 | 1444 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
@@ -1448,13 +1448,13 @@ discard block |
||
| 1448 | 1448 | //---------------------------------------------------------------------- |
| 1449 | 1449 | public static function lookAnTable($c) |
| 1450 | 1450 | {
|
| 1451 | - return (($c > 127)?-1:self::$anTable[$c]); |
|
| 1451 | + return (($c > 127) ?-1 : self::$anTable[$c]); |
|
| 1452 | 1452 | } |
| 1453 | 1453 | |
| 1454 | 1454 | //---------------------------------------------------------------------- |
| 1455 | 1455 | public static function checkModeAn($size, $data) |
| 1456 | 1456 | {
|
| 1457 | - for($i=0; $i<$size; $i++) {
|
|
| 1457 | + for ($i = 0; $i < $size; $i++) {
|
|
| 1458 | 1458 | if (self::lookAnTable(ord($data[$i])) == -1) {
|
| 1459 | 1459 | return false; |
| 1460 | 1460 | } |
@@ -1466,10 +1466,10 @@ discard block |
||
| 1466 | 1466 | //---------------------------------------------------------------------- |
| 1467 | 1467 | public static function estimateBitsModeAn($size) |
| 1468 | 1468 | {
|
| 1469 | - $w = (int)($size / 2); |
|
| 1469 | + $w = (int) ($size / 2); |
|
| 1470 | 1470 | $bits = $w * 11; |
| 1471 | 1471 | |
| 1472 | - if($size & 1) {
|
|
| 1472 | + if ($size & 1) {
|
|
| 1473 | 1473 | $bits += 6; |
| 1474 | 1474 | } |
| 1475 | 1475 | |
@@ -1485,18 +1485,18 @@ discard block |
||
| 1485 | 1485 | //---------------------------------------------------------------------- |
| 1486 | 1486 | public function estimateBitsModeKanji($size) |
| 1487 | 1487 | {
|
| 1488 | - return (int)(($size / 2) * 13); |
|
| 1488 | + return (int) (($size / 2) * 13); |
|
| 1489 | 1489 | } |
| 1490 | 1490 | |
| 1491 | 1491 | //---------------------------------------------------------------------- |
| 1492 | 1492 | public static function checkModeKanji($size, $data) |
| 1493 | 1493 | {
|
| 1494 | - if($size & 1) |
|
| 1494 | + if ($size & 1) |
|
| 1495 | 1495 | return false; |
| 1496 | 1496 | |
| 1497 | - for($i=0; $i<$size; $i+=2) {
|
|
| 1498 | - $val = (ord($data[$i]) << 8) | ord($data[$i+1]); |
|
| 1499 | - if( $val < 0x8140 |
|
| 1497 | + for ($i = 0; $i < $size; $i += 2) {
|
|
| 1498 | + $val = (ord($data[$i]) << 8) | ord($data[$i + 1]); |
|
| 1499 | + if ($val < 0x8140 |
|
| 1500 | 1500 | || ($val > 0x9ffc && $val < 0xe040) |
| 1501 | 1501 | || $val > 0xebbf) {
|
| 1502 | 1502 | return false; |
@@ -1512,12 +1512,12 @@ discard block |
||
| 1512 | 1512 | |
| 1513 | 1513 | public static function check($mode, $size, $data) |
| 1514 | 1514 | {
|
| 1515 | - if($size <= 0) |
|
| 1515 | + if ($size <= 0) |
|
| 1516 | 1516 | return false; |
| 1517 | 1517 | |
| 1518 | - switch($mode) {
|
|
| 1519 | - case QR_MODE_NUM: return self::checkModeNum($size, $data); break; |
|
| 1520 | - case QR_MODE_AN: return self::checkModeAn($size, $data); break; |
|
| 1518 | + switch ($mode) {
|
|
| 1519 | + case QR_MODE_NUM: return self::checkModeNum($size, $data); break; |
|
| 1520 | + case QR_MODE_AN: return self::checkModeAn($size, $data); break; |
|
| 1521 | 1521 | case QR_MODE_KANJI: return self::checkModeKanji($size, $data); break; |
| 1522 | 1522 | case QR_MODE_8: return true; break; |
| 1523 | 1523 | case QR_MODE_STRUCTURE: return true; break; |
@@ -1535,7 +1535,7 @@ discard block |
||
| 1535 | 1535 | {
|
| 1536 | 1536 | $bits = 0; |
| 1537 | 1537 | |
| 1538 | - foreach($this->items as $item) {
|
|
| 1538 | + foreach ($this->items as $item) {
|
|
| 1539 | 1539 | $bits += $item->estimateBitStreamSizeOfEntry($version); |
| 1540 | 1540 | } |
| 1541 | 1541 | |
@@ -1550,7 +1550,7 @@ discard block |
||
| 1550 | 1550 | do {
|
| 1551 | 1551 | $prev = $version; |
| 1552 | 1552 | $bits = $this->estimateBitStreamSize($prev); |
| 1553 | - $version = QRspec::getMinimumVersion((int)(($bits + 7) / 8), $this->level); |
|
| 1553 | + $version = QRspec::getMinimumVersion((int) (($bits + 7) / 8), $this->level); |
|
| 1554 | 1554 | if ($version < 0) {
|
| 1555 | 1555 | return -1; |
| 1556 | 1556 | } |
@@ -1563,32 +1563,32 @@ discard block |
||
| 1563 | 1563 | public static function lengthOfCode($mode, $version, $bits) |
| 1564 | 1564 | {
|
| 1565 | 1565 | $payload = $bits - 4 - QRspec::lengthIndicator($mode, $version); |
| 1566 | - switch($mode) {
|
|
| 1566 | + switch ($mode) {
|
|
| 1567 | 1567 | case QR_MODE_NUM: |
| 1568 | - $chunks = (int)($payload / 10); |
|
| 1568 | + $chunks = (int) ($payload / 10); |
|
| 1569 | 1569 | $remain = $payload - $chunks * 10; |
| 1570 | 1570 | $size = $chunks * 3; |
| 1571 | - if($remain >= 7) {
|
|
| 1571 | + if ($remain >= 7) {
|
|
| 1572 | 1572 | $size += 2; |
| 1573 | - } else if($remain >= 4) {
|
|
| 1573 | + } else if ($remain >= 4) {
|
|
| 1574 | 1574 | $size += 1; |
| 1575 | 1575 | } |
| 1576 | 1576 | break; |
| 1577 | 1577 | case QR_MODE_AN: |
| 1578 | - $chunks = (int)($payload / 11); |
|
| 1578 | + $chunks = (int) ($payload / 11); |
|
| 1579 | 1579 | $remain = $payload - $chunks * 11; |
| 1580 | 1580 | $size = $chunks * 2; |
| 1581 | - if($remain >= 6) |
|
| 1581 | + if ($remain >= 6) |
|
| 1582 | 1582 | $size++; |
| 1583 | 1583 | break; |
| 1584 | 1584 | case QR_MODE_8: |
| 1585 | - $size = (int)($payload / 8); |
|
| 1585 | + $size = (int) ($payload / 8); |
|
| 1586 | 1586 | break; |
| 1587 | 1587 | case QR_MODE_KANJI: |
| 1588 | - $size = (int)(($payload / 13) * 2); |
|
| 1588 | + $size = (int) (($payload / 13) * 2); |
|
| 1589 | 1589 | break; |
| 1590 | 1590 | case QR_MODE_STRUCTURE: |
| 1591 | - $size = (int)($payload / 8); |
|
| 1591 | + $size = (int) ($payload / 8); |
|
| 1592 | 1592 | break; |
| 1593 | 1593 | default: |
| 1594 | 1594 | $size = 0; |
@@ -1596,8 +1596,8 @@ discard block |
||
| 1596 | 1596 | } |
| 1597 | 1597 | |
| 1598 | 1598 | $maxsize = QRspec::maximumWords($mode, $version); |
| 1599 | - if($size < 0) $size = 0; |
|
| 1600 | - if($size > $maxsize) $size = $maxsize; |
|
| 1599 | + if ($size < 0) $size = 0; |
|
| 1600 | + if ($size > $maxsize) $size = $maxsize; |
|
| 1601 | 1601 | |
| 1602 | 1602 | return $size; |
| 1603 | 1603 | } |
@@ -1607,10 +1607,10 @@ discard block |
||
| 1607 | 1607 | {
|
| 1608 | 1608 | $total = 0; |
| 1609 | 1609 | |
| 1610 | - foreach($this->items as $item) {
|
|
| 1610 | + foreach ($this->items as $item) {
|
|
| 1611 | 1611 | $bits = $item->encodeBitStream($this->version); |
| 1612 | 1612 | |
| 1613 | - if($bits < 0) |
|
| 1613 | + if ($bits < 0) |
|
| 1614 | 1614 | return -1; |
| 1615 | 1615 | |
| 1616 | 1616 | $total += $bits; |
@@ -1623,21 +1623,21 @@ discard block |
||
| 1623 | 1623 | public function convertData() |
| 1624 | 1624 | {
|
| 1625 | 1625 | $ver = $this->estimateVersion(); |
| 1626 | - if($ver > $this->getVersion()) {
|
|
| 1626 | + if ($ver > $this->getVersion()) {
|
|
| 1627 | 1627 | $this->setVersion($ver); |
| 1628 | 1628 | } |
| 1629 | 1629 | |
| 1630 | - for(;;) {
|
|
| 1630 | + for (;;) {
|
|
| 1631 | 1631 | $bits = $this->createBitStream(); |
| 1632 | 1632 | |
| 1633 | - if($bits < 0) |
|
| 1633 | + if ($bits < 0) |
|
| 1634 | 1634 | return -1; |
| 1635 | 1635 | |
| 1636 | - $ver = QRspec::getMinimumVersion((int)(($bits + 7) / 8), $this->level); |
|
| 1637 | - if($ver < 0) {
|
|
| 1636 | + $ver = QRspec::getMinimumVersion((int) (($bits + 7) / 8), $this->level); |
|
| 1637 | + if ($ver < 0) {
|
|
| 1638 | 1638 | throw new Exception('WRONG VERSION');
|
| 1639 | 1639 | return -1; |
| 1640 | - } else if($ver > $this->getVersion()) {
|
|
| 1640 | + } else if ($ver > $this->getVersion()) {
|
|
| 1641 | 1641 | $this->setVersion($ver); |
| 1642 | 1642 | } else {
|
| 1643 | 1643 | break; |
@@ -1663,26 +1663,26 @@ discard block |
||
| 1663 | 1663 | } |
| 1664 | 1664 | |
| 1665 | 1665 | $bits += 4; |
| 1666 | - $words = (int)(($bits + 7) / 8); |
|
| 1666 | + $words = (int) (($bits + 7) / 8); |
|
| 1667 | 1667 | |
| 1668 | 1668 | $padding = new QRbitstream(); |
| 1669 | 1669 | $ret = $padding->appendNum($words * 8 - $bits + 4, 0); |
| 1670 | 1670 | |
| 1671 | - if($ret < 0) |
|
| 1671 | + if ($ret < 0) |
|
| 1672 | 1672 | return $ret; |
| 1673 | 1673 | |
| 1674 | 1674 | $padlen = $maxwords - $words; |
| 1675 | 1675 | |
| 1676 | - if($padlen > 0) {
|
|
| 1676 | + if ($padlen > 0) {
|
|
| 1677 | 1677 | |
| 1678 | 1678 | $padbuf = []; |
| 1679 | - for($i=0; $i<$padlen; $i++) {
|
|
| 1680 | - $padbuf[$i] = ($i&1)?0x11:0xec; |
|
| 1679 | + for ($i = 0; $i < $padlen; $i++) {
|
|
| 1680 | + $padbuf[$i] = ($i & 1) ? 0x11 : 0xec; |
|
| 1681 | 1681 | } |
| 1682 | 1682 | |
| 1683 | 1683 | $ret = $padding->appendBytes($padlen, $padbuf); |
| 1684 | 1684 | |
| 1685 | - if($ret < 0) |
|
| 1685 | + if ($ret < 0) |
|
| 1686 | 1686 | return $ret; |
| 1687 | 1687 | |
| 1688 | 1688 | } |
@@ -1695,15 +1695,15 @@ discard block |
||
| 1695 | 1695 | //---------------------------------------------------------------------- |
| 1696 | 1696 | public function mergeBitStream() |
| 1697 | 1697 | {
|
| 1698 | - if($this->convertData() < 0) {
|
|
| 1698 | + if ($this->convertData() < 0) {
|
|
| 1699 | 1699 | return null; |
| 1700 | 1700 | } |
| 1701 | 1701 | |
| 1702 | 1702 | $bstream = new QRbitstream(); |
| 1703 | 1703 | |
| 1704 | - foreach($this->items as $item) {
|
|
| 1704 | + foreach ($this->items as $item) {
|
|
| 1705 | 1705 | $ret = $bstream->append($item->bstream); |
| 1706 | - if($ret < 0) {
|
|
| 1706 | + if ($ret < 0) {
|
|
| 1707 | 1707 | return null; |
| 1708 | 1708 | } |
| 1709 | 1709 | } |
@@ -1717,12 +1717,12 @@ discard block |
||
| 1717 | 1717 | |
| 1718 | 1718 | $bstream = $this->mergeBitStream(); |
| 1719 | 1719 | |
| 1720 | - if($bstream == null) {
|
|
| 1720 | + if ($bstream == null) {
|
|
| 1721 | 1721 | return null; |
| 1722 | 1722 | } |
| 1723 | 1723 | |
| 1724 | 1724 | $ret = $this->appendPaddingBit($bstream); |
| 1725 | - if($ret < 0) {
|
|
| 1725 | + if ($ret < 0) {
|
|
| 1726 | 1726 | return null; |
| 1727 | 1727 | } |
| 1728 | 1728 | |
@@ -1733,7 +1733,7 @@ discard block |
||
| 1733 | 1733 | public function getByteStream() |
| 1734 | 1734 | {
|
| 1735 | 1735 | $bstream = $this->getBitStream(); |
| 1736 | - if($bstream == null) {
|
|
| 1736 | + if ($bstream == null) {
|
|
| 1737 | 1737 | return null; |
| 1738 | 1738 | } |
| 1739 | 1739 | |
@@ -1801,8 +1801,8 @@ discard block |
||
| 1801 | 1801 | $bstream->allocate($bits); |
| 1802 | 1802 | |
| 1803 | 1803 | $mask = 1 << ($bits - 1); |
| 1804 | - for($i=0; $i<$bits; $i++) {
|
|
| 1805 | - if($num & $mask) {
|
|
| 1804 | + for ($i = 0; $i < $bits; $i++) {
|
|
| 1805 | + if ($num & $mask) {
|
|
| 1806 | 1806 | $bstream->data[$i] = 1; |
| 1807 | 1807 | } else {
|
| 1808 | 1808 | $bstream->data[$i] = 0; |
@@ -1818,12 +1818,12 @@ discard block |
||
| 1818 | 1818 | {
|
| 1819 | 1819 | $bstream = new QRbitstream(); |
| 1820 | 1820 | $bstream->allocate($size * 8); |
| 1821 | - $p=0; |
|
| 1821 | + $p = 0; |
|
| 1822 | 1822 | |
| 1823 | - for($i=0; $i<$size; $i++) {
|
|
| 1823 | + for ($i = 0; $i < $size; $i++) {
|
|
| 1824 | 1824 | $mask = 0x80; |
| 1825 | - for($j=0; $j<8; $j++) {
|
|
| 1826 | - if($data[$i] & $mask) {
|
|
| 1825 | + for ($j = 0; $j < 8; $j++) {
|
|
| 1826 | + if ($data[$i] & $mask) {
|
|
| 1827 | 1827 | $bstream->data[$p] = 1; |
| 1828 | 1828 | } else {
|
| 1829 | 1829 | $bstream->data[$p] = 0; |
@@ -1843,11 +1843,11 @@ discard block |
||
| 1843 | 1843 | return -1; |
| 1844 | 1844 | } |
| 1845 | 1845 | |
| 1846 | - if($arg->size() == 0) {
|
|
| 1846 | + if ($arg->size() == 0) {
|
|
| 1847 | 1847 | return 0; |
| 1848 | 1848 | } |
| 1849 | 1849 | |
| 1850 | - if($this->size() == 0) {
|
|
| 1850 | + if ($this->size() == 0) {
|
|
| 1851 | 1851 | $this->data = $arg->data; |
| 1852 | 1852 | return 0; |
| 1853 | 1853 | } |
@@ -1865,7 +1865,7 @@ discard block |
||
| 1865 | 1865 | |
| 1866 | 1866 | $b = QRbitstream::newFromNum($bits, $num); |
| 1867 | 1867 | |
| 1868 | - if(is_null($b)) |
|
| 1868 | + if (is_null($b)) |
|
| 1869 | 1869 | return -1; |
| 1870 | 1870 | |
| 1871 | 1871 | $ret = $this->append($b); |
@@ -1882,7 +1882,7 @@ discard block |
||
| 1882 | 1882 | |
| 1883 | 1883 | $b = QRbitstream::newFromBytes($size, $data); |
| 1884 | 1884 | |
| 1885 | - if(is_null($b)) |
|
| 1885 | + if (is_null($b)) |
|
| 1886 | 1886 | return -1; |
| 1887 | 1887 | |
| 1888 | 1888 | $ret = $this->append($b); |
@@ -1897,18 +1897,18 @@ discard block |
||
| 1897 | 1897 | |
| 1898 | 1898 | $size = $this->size(); |
| 1899 | 1899 | |
| 1900 | - if($size == 0) {
|
|
| 1900 | + if ($size == 0) {
|
|
| 1901 | 1901 | return []; |
| 1902 | 1902 | } |
| 1903 | 1903 | |
| 1904 | - $data = array_fill(0, (int)(($size + 7) / 8), 0); |
|
| 1905 | - $bytes = (int)($size / 8); |
|
| 1904 | + $data = array_fill(0, (int) (($size + 7) / 8), 0); |
|
| 1905 | + $bytes = (int) ($size / 8); |
|
| 1906 | 1906 | |
| 1907 | 1907 | $p = 0; |
| 1908 | 1908 | |
| 1909 | - for($i=0; $i<$bytes; $i++) {
|
|
| 1909 | + for ($i = 0; $i < $bytes; $i++) {
|
|
| 1910 | 1910 | $v = 0; |
| 1911 | - for($j=0; $j<8; $j++) {
|
|
| 1911 | + for ($j = 0; $j < 8; $j++) {
|
|
| 1912 | 1912 | $v = $v << 1; |
| 1913 | 1913 | $v |= $this->data[$p]; |
| 1914 | 1914 | $p++; |
@@ -1916,9 +1916,9 @@ discard block |
||
| 1916 | 1916 | $data[$i] = $v; |
| 1917 | 1917 | } |
| 1918 | 1918 | |
| 1919 | - if($size & 7) {
|
|
| 1919 | + if ($size & 7) {
|
|
| 1920 | 1920 | $v = 0; |
| 1921 | - for($j=0; $j<($size & 7); $j++) {
|
|
| 1921 | + for ($j = 0; $j < ($size & 7); $j++) {
|
|
| 1922 | 1922 | $v = $v << 1; |
| 1923 | 1923 | $v |= $this->data[$p]; |
| 1924 | 1924 | $p++; |
@@ -1990,7 +1990,7 @@ discard block |
||
| 1990 | 1990 | if ($pos >= strlen($str)) |
| 1991 | 1991 | return false; |
| 1992 | 1992 | |
| 1993 | - return ((ord($str[$pos]) >= ord('0'))&&(ord($str[$pos]) <= ord('9')));
|
|
| 1993 | + return ((ord($str[$pos]) >= ord('0')) && (ord($str[$pos]) <= ord('9')));
|
|
| 1994 | 1994 | } |
| 1995 | 1995 | |
| 1996 | 1996 | //---------------------------------------------------------------------- |
@@ -2010,17 +2010,17 @@ discard block |
||
| 2010 | 2010 | |
| 2011 | 2011 | $c = $this->dataStr[$pos]; |
| 2012 | 2012 | |
| 2013 | - if(self::isdigitat($this->dataStr, $pos)) {
|
|
| 2013 | + if (self::isdigitat($this->dataStr, $pos)) {
|
|
| 2014 | 2014 | return QR_MODE_NUM; |
| 2015 | - } else if(self::isalnumat($this->dataStr, $pos)) {
|
|
| 2015 | + } else if (self::isalnumat($this->dataStr, $pos)) {
|
|
| 2016 | 2016 | return QR_MODE_AN; |
| 2017 | - } else if($this->modeHint == QR_MODE_KANJI) {
|
|
| 2017 | + } else if ($this->modeHint == QR_MODE_KANJI) {
|
|
| 2018 | 2018 | |
| 2019 | - if ($pos+1 < strlen($this->dataStr)) |
|
| 2019 | + if ($pos + 1 < strlen($this->dataStr)) |
|
| 2020 | 2020 | {
|
| 2021 | - $d = $this->dataStr[$pos+1]; |
|
| 2021 | + $d = $this->dataStr[$pos + 1]; |
|
| 2022 | 2022 | $word = (ord($c) << 8) | ord($d); |
| 2023 | - if(($word >= 0x8140 && $word <= 0x9ffc) || ($word >= 0xe040 && $word <= 0xebbf)) {
|
|
| 2023 | + if (($word >= 0x8140 && $word <= 0x9ffc) || ($word >= 0xe040 && $word <= 0xebbf)) {
|
|
| 2024 | 2024 | return QR_MODE_KANJI; |
| 2025 | 2025 | } |
| 2026 | 2026 | } |
@@ -2035,32 +2035,32 @@ discard block |
||
| 2035 | 2035 | $ln = QRspec::lengthIndicator(QR_MODE_NUM, $this->input->getVersion()); |
| 2036 | 2036 | |
| 2037 | 2037 | $p = 0; |
| 2038 | - while(self::isdigitat($this->dataStr, $p)) {
|
|
| 2038 | + while (self::isdigitat($this->dataStr, $p)) {
|
|
| 2039 | 2039 | $p++; |
| 2040 | 2040 | } |
| 2041 | 2041 | |
| 2042 | 2042 | $run = $p; |
| 2043 | 2043 | $mode = $this->identifyMode($p); |
| 2044 | 2044 | |
| 2045 | - if($mode == QR_MODE_8) {
|
|
| 2045 | + if ($mode == QR_MODE_8) {
|
|
| 2046 | 2046 | $dif = QRinput::estimateBitsModeNum($run) + 4 + $ln |
| 2047 | 2047 | + QRinput::estimateBitsMode8(1) // + 4 + l8 |
| 2048 | 2048 | - QRinput::estimateBitsMode8($run + 1); // - 4 - l8 |
| 2049 | - if($dif > 0) {
|
|
| 2049 | + if ($dif > 0) {
|
|
| 2050 | 2050 | return $this->eat8(); |
| 2051 | 2051 | } |
| 2052 | 2052 | } |
| 2053 | - if($mode == QR_MODE_AN) {
|
|
| 2053 | + if ($mode == QR_MODE_AN) {
|
|
| 2054 | 2054 | $dif = QRinput::estimateBitsModeNum($run) + 4 + $ln |
| 2055 | 2055 | + QRinput::estimateBitsModeAn(1) // + 4 + la |
| 2056 | - - QRinput::estimateBitsModeAn($run + 1);// - 4 - la |
|
| 2057 | - if($dif > 0) {
|
|
| 2056 | + - QRinput::estimateBitsModeAn($run + 1); // - 4 - la |
|
| 2057 | + if ($dif > 0) {
|
|
| 2058 | 2058 | return $this->eatAn(); |
| 2059 | 2059 | } |
| 2060 | 2060 | } |
| 2061 | 2061 | |
| 2062 | 2062 | $ret = $this->input->append(QR_MODE_NUM, $run, str_split($this->dataStr)); |
| 2063 | - if($ret < 0) |
|
| 2063 | + if ($ret < 0) |
|
| 2064 | 2064 | return -1; |
| 2065 | 2065 | |
| 2066 | 2066 | return $run; |
@@ -2069,15 +2069,15 @@ discard block |
||
| 2069 | 2069 | //---------------------------------------------------------------------- |
| 2070 | 2070 | public function eatAn() |
| 2071 | 2071 | {
|
| 2072 | - $la = QRspec::lengthIndicator(QR_MODE_AN, $this->input->getVersion()); |
|
| 2072 | + $la = QRspec::lengthIndicator(QR_MODE_AN, $this->input->getVersion()); |
|
| 2073 | 2073 | $ln = QRspec::lengthIndicator(QR_MODE_NUM, $this->input->getVersion()); |
| 2074 | 2074 | |
| 2075 | 2075 | $p = 0; |
| 2076 | 2076 | |
| 2077 | - while(self::isalnumat($this->dataStr, $p)) {
|
|
| 2078 | - if(self::isdigitat($this->dataStr, $p)) {
|
|
| 2077 | + while (self::isalnumat($this->dataStr, $p)) {
|
|
| 2078 | + if (self::isdigitat($this->dataStr, $p)) {
|
|
| 2079 | 2079 | $q = $p; |
| 2080 | - while(self::isdigitat($this->dataStr, $q)) {
|
|
| 2080 | + while (self::isdigitat($this->dataStr, $q)) {
|
|
| 2081 | 2081 | $q++; |
| 2082 | 2082 | } |
| 2083 | 2083 | |
@@ -2085,7 +2085,7 @@ discard block |
||
| 2085 | 2085 | + QRinput::estimateBitsModeNum($q - $p) + 4 + $ln |
| 2086 | 2086 | - QRinput::estimateBitsModeAn($q); // - 4 - la |
| 2087 | 2087 | |
| 2088 | - if($dif < 0) {
|
|
| 2088 | + if ($dif < 0) {
|
|
| 2089 | 2089 | break; |
| 2090 | 2090 | } else {
|
| 2091 | 2091 | $p = $q; |
@@ -2097,17 +2097,17 @@ discard block |
||
| 2097 | 2097 | |
| 2098 | 2098 | $run = $p; |
| 2099 | 2099 | |
| 2100 | - if(!self::isalnumat($this->dataStr, $p)) {
|
|
| 2100 | + if (!self::isalnumat($this->dataStr, $p)) {
|
|
| 2101 | 2101 | $dif = QRinput::estimateBitsModeAn($run) + 4 + $la |
| 2102 | 2102 | + QRinput::estimateBitsMode8(1) // + 4 + l8 |
| 2103 | 2103 | - QRinput::estimateBitsMode8($run + 1); // - 4 - l8 |
| 2104 | - if($dif > 0) {
|
|
| 2104 | + if ($dif > 0) {
|
|
| 2105 | 2105 | return $this->eat8(); |
| 2106 | 2106 | } |
| 2107 | 2107 | } |
| 2108 | 2108 | |
| 2109 | 2109 | $ret = $this->input->append(QR_MODE_AN, $run, str_split($this->dataStr)); |
| 2110 | - if($ret < 0) |
|
| 2110 | + if ($ret < 0) |
|
| 2111 | 2111 | return -1; |
| 2112 | 2112 | |
| 2113 | 2113 | return $run; |
@@ -2118,12 +2118,12 @@ discard block |
||
| 2118 | 2118 | {
|
| 2119 | 2119 | $p = 0; |
| 2120 | 2120 | |
| 2121 | - while($this->identifyMode($p) == QR_MODE_KANJI) {
|
|
| 2121 | + while ($this->identifyMode($p) == QR_MODE_KANJI) {
|
|
| 2122 | 2122 | $p += 2; |
| 2123 | 2123 | } |
| 2124 | 2124 | |
| 2125 | 2125 | $ret = $this->input->append(QR_MODE_KANJI, $p, str_split($this->dataStr)); |
| 2126 | - if($ret < 0) |
|
| 2126 | + if ($ret < 0) |
|
| 2127 | 2127 | return -1; |
| 2128 | 2128 | |
| 2129 | 2129 | return $run; |
@@ -2138,34 +2138,34 @@ discard block |
||
| 2138 | 2138 | $p = 1; |
| 2139 | 2139 | $dataStrLen = strlen($this->dataStr); |
| 2140 | 2140 | |
| 2141 | - while($p < $dataStrLen) {
|
|
| 2141 | + while ($p < $dataStrLen) {
|
|
| 2142 | 2142 | |
| 2143 | 2143 | $mode = $this->identifyMode($p); |
| 2144 | - if($mode == QR_MODE_KANJI) {
|
|
| 2144 | + if ($mode == QR_MODE_KANJI) {
|
|
| 2145 | 2145 | break; |
| 2146 | 2146 | } |
| 2147 | - if($mode == QR_MODE_NUM) {
|
|
| 2147 | + if ($mode == QR_MODE_NUM) {
|
|
| 2148 | 2148 | $q = $p; |
| 2149 | - while(self::isdigitat($this->dataStr, $q)) {
|
|
| 2149 | + while (self::isdigitat($this->dataStr, $q)) {
|
|
| 2150 | 2150 | $q++; |
| 2151 | 2151 | } |
| 2152 | 2152 | $dif = QRinput::estimateBitsMode8($p) // + 4 + l8 |
| 2153 | 2153 | + QRinput::estimateBitsModeNum($q - $p) + 4 + $ln |
| 2154 | 2154 | - QRinput::estimateBitsMode8($q); // - 4 - l8 |
| 2155 | - if($dif < 0) {
|
|
| 2155 | + if ($dif < 0) {
|
|
| 2156 | 2156 | break; |
| 2157 | 2157 | } else {
|
| 2158 | 2158 | $p = $q; |
| 2159 | 2159 | } |
| 2160 | - } else if($mode == QR_MODE_AN) {
|
|
| 2160 | + } else if ($mode == QR_MODE_AN) {
|
|
| 2161 | 2161 | $q = $p; |
| 2162 | - while(self::isalnumat($this->dataStr, $q)) {
|
|
| 2162 | + while (self::isalnumat($this->dataStr, $q)) {
|
|
| 2163 | 2163 | $q++; |
| 2164 | 2164 | } |
| 2165 | 2165 | $dif = QRinput::estimateBitsMode8($p) // + 4 + l8 |
| 2166 | 2166 | + QRinput::estimateBitsModeAn($q - $p) + 4 + $la |
| 2167 | 2167 | - QRinput::estimateBitsMode8($q); // - 4 - l8 |
| 2168 | - if($dif < 0) {
|
|
| 2168 | + if ($dif < 0) {
|
|
| 2169 | 2169 | break; |
| 2170 | 2170 | } else {
|
| 2171 | 2171 | $p = $q; |
@@ -2178,7 +2178,7 @@ discard block |
||
| 2178 | 2178 | $run = $p; |
| 2179 | 2179 | $ret = $this->input->append(QR_MODE_8, $run, str_split($this->dataStr)); |
| 2180 | 2180 | |
| 2181 | - if($ret < 0) |
|
| 2181 | + if ($ret < 0) |
|
| 2182 | 2182 | return -1; |
| 2183 | 2183 | |
| 2184 | 2184 | return $run; |
@@ -2189,7 +2189,7 @@ discard block |
||
| 2189 | 2189 | {
|
| 2190 | 2190 | while (strlen($this->dataStr) > 0) |
| 2191 | 2191 | {
|
| 2192 | - if($this->dataStr == '') |
|
| 2192 | + if ($this->dataStr == '') |
|
| 2193 | 2193 | return 0; |
| 2194 | 2194 | |
| 2195 | 2195 | $mode = $this->identifyMode(0); |
@@ -2206,8 +2206,8 @@ discard block |
||
| 2206 | 2206 | |
| 2207 | 2207 | } |
| 2208 | 2208 | |
| 2209 | - if($length == 0) return 0; |
|
| 2210 | - if($length < 0) return -1; |
|
| 2209 | + if ($length == 0) return 0; |
|
| 2210 | + if ($length < 0) return -1; |
|
| 2211 | 2211 | |
| 2212 | 2212 | $this->dataStr = substr($this->dataStr, $length); |
| 2213 | 2213 | } |
@@ -2219,9 +2219,9 @@ discard block |
||
| 2219 | 2219 | $stringLen = strlen($this->dataStr); |
| 2220 | 2220 | $p = 0; |
| 2221 | 2221 | |
| 2222 | - while ($p<$stringLen) {
|
|
| 2222 | + while ($p < $stringLen) {
|
|
| 2223 | 2223 | $mode = self::identifyMode(substr($this->dataStr, $p), $this->modeHint); |
| 2224 | - if($mode == QR_MODE_KANJI) {
|
|
| 2224 | + if ($mode == QR_MODE_KANJI) {
|
|
| 2225 | 2225 | $p += 2; |
| 2226 | 2226 | } else {
|
| 2227 | 2227 | if (ord($this->dataStr[$p]) >= ord('a') && ord($this->dataStr[$p]) <= ord('z')) {
|
@@ -2237,13 +2237,13 @@ discard block |
||
| 2237 | 2237 | //---------------------------------------------------------------------- |
| 2238 | 2238 | public static function splitStringToQRinput($string, QRinput $input, $modeHint, $casesensitive = true) |
| 2239 | 2239 | {
|
| 2240 | - if(is_null($string) || $string == '\0' || $string == '') {
|
|
| 2240 | + if (is_null($string) || $string == '\0' || $string == '') {
|
|
| 2241 | 2241 | throw new Exception('empty string!!!');
|
| 2242 | 2242 | } |
| 2243 | 2243 | |
| 2244 | 2244 | $split = new QRsplit($string, $input, $modeHint); |
| 2245 | 2245 | |
| 2246 | - if(!$casesensitive) |
|
| 2246 | + if (!$casesensitive) |
|
| 2247 | 2247 | $split->toUpper(); |
| 2248 | 2248 | |
| 2249 | 2249 | return $split->splitString(); |
@@ -2288,16 +2288,16 @@ discard block |
||
| 2288 | 2288 | |
| 2289 | 2289 | class QRrsItem {
|
| 2290 | 2290 | |
| 2291 | - public $mm; // Bits per symbol |
|
| 2292 | - public $nn; // Symbols per block (= (1<<mm)-1) |
|
| 2293 | - public $alpha_to = []; // log lookup table |
|
| 2294 | - public $index_of = []; // Antilog lookup table |
|
| 2295 | - public $genpoly = []; // Generator polynomial |
|
| 2296 | - public $nroots; // Number of generator roots = number of parity symbols |
|
| 2297 | - public $fcr; // First consecutive root, index form |
|
| 2298 | - public $prim; // Primitive element, index form |
|
| 2299 | - public $iprim; // prim-th root of 1, index form |
|
| 2300 | - public $pad; // Padding bytes in shortened block |
|
| 2291 | + public $mm; // Bits per symbol |
|
| 2292 | + public $nn; // Symbols per block (= (1<<mm)-1) |
|
| 2293 | + public $alpha_to = []; // log lookup table |
|
| 2294 | + public $index_of = []; // Antilog lookup table |
|
| 2295 | + public $genpoly = []; // Generator polynomial |
|
| 2296 | + public $nroots; // Number of generator roots = number of parity symbols |
|
| 2297 | + public $fcr; // First consecutive root, index form |
|
| 2298 | + public $prim; // Primitive element, index form |
|
| 2299 | + public $iprim; // prim-th root of 1, index form |
|
| 2300 | + public $pad; // Padding bytes in shortened block |
|
| 2301 | 2301 | public $gfpoly; |
| 2302 | 2302 | |
| 2303 | 2303 | //---------------------------------------------------------------------- |
@@ -2321,47 +2321,47 @@ discard block |
||
| 2321 | 2321 | $rs = null; |
| 2322 | 2322 | |
| 2323 | 2323 | // Check parameter ranges |
| 2324 | - if($symsize < 0 || $symsize > 8) return $rs; |
|
| 2325 | - if($fcr < 0 || $fcr >= (1<<$symsize)) return $rs; |
|
| 2326 | - if($prim <= 0 || $prim >= (1<<$symsize)) return $rs; |
|
| 2327 | - if($nroots < 0 || $nroots >= (1<<$symsize)) return $rs; // Can't have more roots than symbol values! |
|
| 2328 | - if($pad < 0 || $pad >= ((1<<$symsize) -1 - $nroots)) return $rs; // Too much padding |
|
| 2324 | + if ($symsize < 0 || $symsize > 8) return $rs; |
|
| 2325 | + if ($fcr < 0 || $fcr >= (1 << $symsize)) return $rs; |
|
| 2326 | + if ($prim <= 0 || $prim >= (1 << $symsize)) return $rs; |
|
| 2327 | + if ($nroots < 0 || $nroots >= (1 << $symsize)) return $rs; // Can't have more roots than symbol values! |
|
| 2328 | + if ($pad < 0 || $pad >= ((1 << $symsize) - 1 - $nroots)) return $rs; // Too much padding |
|
| 2329 | 2329 | |
| 2330 | 2330 | $rs = new QRrsItem(); |
| 2331 | 2331 | $rs->mm = $symsize; |
| 2332 | - $rs->nn = (1<<$symsize)-1; |
|
| 2332 | + $rs->nn = (1 << $symsize) - 1; |
|
| 2333 | 2333 | $rs->pad = $pad; |
| 2334 | 2334 | |
| 2335 | - $rs->alpha_to = array_fill(0, $rs->nn+1, 0); |
|
| 2336 | - $rs->index_of = array_fill(0, $rs->nn+1, 0); |
|
| 2335 | + $rs->alpha_to = array_fill(0, $rs->nn + 1, 0); |
|
| 2336 | + $rs->index_of = array_fill(0, $rs->nn + 1, 0); |
|
| 2337 | 2337 | |
| 2338 | 2338 | // PHP style macro replacement ;) |
| 2339 | - $NN =& $rs->nn; |
|
| 2340 | - $A0 =& $NN; |
|
| 2339 | + $NN = & $rs->nn; |
|
| 2340 | + $A0 = & $NN; |
|
| 2341 | 2341 | |
| 2342 | 2342 | // Generate Galois field lookup tables |
| 2343 | 2343 | $rs->index_of[0] = $A0; // log(zero) = -inf |
| 2344 | 2344 | $rs->alpha_to[$A0] = 0; // alpha**-inf = 0 |
| 2345 | 2345 | $sr = 1; |
| 2346 | 2346 | |
| 2347 | - for($i=0; $i<$rs->nn; $i++) {
|
|
| 2347 | + for ($i = 0; $i < $rs->nn; $i++) {
|
|
| 2348 | 2348 | $rs->index_of[$sr] = $i; |
| 2349 | 2349 | $rs->alpha_to[$i] = $sr; |
| 2350 | 2350 | $sr <<= 1; |
| 2351 | - if($sr & (1<<$symsize)) {
|
|
| 2351 | + if ($sr & (1 << $symsize)) {
|
|
| 2352 | 2352 | $sr ^= $gfpoly; |
| 2353 | 2353 | } |
| 2354 | 2354 | $sr &= $rs->nn; |
| 2355 | 2355 | } |
| 2356 | 2356 | |
| 2357 | - if($sr != 1){
|
|
| 2357 | + if ($sr != 1) {
|
|
| 2358 | 2358 | // field generator polynomial is not primitive! |
| 2359 | 2359 | $rs = NULL; |
| 2360 | 2360 | return $rs; |
| 2361 | 2361 | } |
| 2362 | 2362 | |
| 2363 | 2363 | /* Form RS code generator polynomial from its roots */ |
| 2364 | - $rs->genpoly = array_fill(0, $nroots+1, 0); |
|
| 2364 | + $rs->genpoly = array_fill(0, $nroots + 1, 0); |
|
| 2365 | 2365 | |
| 2366 | 2366 | $rs->fcr = $fcr; |
| 2367 | 2367 | $rs->prim = $prim; |
@@ -2369,21 +2369,21 @@ discard block |
||
| 2369 | 2369 | $rs->gfpoly = $gfpoly; |
| 2370 | 2370 | |
| 2371 | 2371 | /* Find prim-th root of 1, used in decoding */ |
| 2372 | - for($iprim=1;($iprim % $prim) != 0;$iprim += $rs->nn) |
|
| 2372 | + for ($iprim = 1; ($iprim % $prim) != 0; $iprim += $rs->nn) |
|
| 2373 | 2373 | ; // intentional empty-body loop! |
| 2374 | 2374 | |
| 2375 | - $rs->iprim = (int)($iprim / $prim); |
|
| 2375 | + $rs->iprim = (int) ($iprim / $prim); |
|
| 2376 | 2376 | $rs->genpoly[0] = 1; |
| 2377 | 2377 | |
| 2378 | - for ($i = 0,$root=$fcr*$prim; $i < $nroots; $i++, $root += $prim) {
|
|
| 2379 | - $rs->genpoly[$i+1] = 1; |
|
| 2378 | + for ($i = 0, $root = $fcr * $prim; $i < $nroots; $i++, $root += $prim) {
|
|
| 2379 | + $rs->genpoly[$i + 1] = 1; |
|
| 2380 | 2380 | |
| 2381 | 2381 | // Multiply rs->genpoly[] by @**(root + x) |
| 2382 | 2382 | for ($j = $i; $j > 0; $j--) {
|
| 2383 | 2383 | if ($rs->genpoly[$j] != 0) {
|
| 2384 | - $rs->genpoly[$j] = $rs->genpoly[$j-1] ^ $rs->alpha_to[$rs->modnn($rs->index_of[$rs->genpoly[$j]] + $root)]; |
|
| 2384 | + $rs->genpoly[$j] = $rs->genpoly[$j - 1] ^ $rs->alpha_to[$rs->modnn($rs->index_of[$rs->genpoly[$j]] + $root)]; |
|
| 2385 | 2385 | } else {
|
| 2386 | - $rs->genpoly[$j] = $rs->genpoly[$j-1]; |
|
| 2386 | + $rs->genpoly[$j] = $rs->genpoly[$j - 1]; |
|
| 2387 | 2387 | } |
| 2388 | 2388 | } |
| 2389 | 2389 | // rs->genpoly[0] can never be zero |
@@ -2400,38 +2400,38 @@ discard block |
||
| 2400 | 2400 | //---------------------------------------------------------------------- |
| 2401 | 2401 | public function encode_rs_char($data, &$parity) |
| 2402 | 2402 | {
|
| 2403 | - $MM =& $this->mm; |
|
| 2404 | - $NN =& $this->nn; |
|
| 2405 | - $ALPHA_TO =& $this->alpha_to; |
|
| 2406 | - $INDEX_OF =& $this->index_of; |
|
| 2407 | - $GENPOLY =& $this->genpoly; |
|
| 2408 | - $NROOTS =& $this->nroots; |
|
| 2409 | - $FCR =& $this->fcr; |
|
| 2410 | - $PRIM =& $this->prim; |
|
| 2411 | - $IPRIM =& $this->iprim; |
|
| 2412 | - $PAD =& $this->pad; |
|
| 2413 | - $A0 =& $NN; |
|
| 2403 | + $MM = & $this->mm; |
|
| 2404 | + $NN = & $this->nn; |
|
| 2405 | + $ALPHA_TO = & $this->alpha_to; |
|
| 2406 | + $INDEX_OF = & $this->index_of; |
|
| 2407 | + $GENPOLY = & $this->genpoly; |
|
| 2408 | + $NROOTS = & $this->nroots; |
|
| 2409 | + $FCR = & $this->fcr; |
|
| 2410 | + $PRIM = & $this->prim; |
|
| 2411 | + $IPRIM = & $this->iprim; |
|
| 2412 | + $PAD = & $this->pad; |
|
| 2413 | + $A0 = & $NN; |
|
| 2414 | 2414 | |
| 2415 | 2415 | $parity = array_fill(0, $NROOTS, 0); |
| 2416 | 2416 | |
| 2417 | - for($i=0; $i< ($NN-$NROOTS-$PAD); $i++) {
|
|
| 2417 | + for ($i = 0; $i < ($NN - $NROOTS - $PAD); $i++) {
|
|
| 2418 | 2418 | |
| 2419 | 2419 | $feedback = $INDEX_OF[$data[$i] ^ $parity[0]]; |
| 2420 | - if($feedback != $A0) {
|
|
| 2420 | + if ($feedback != $A0) {
|
|
| 2421 | 2421 | // feedback term is non-zero |
| 2422 | 2422 | |
| 2423 | 2423 | // This line is unnecessary when GENPOLY[NROOTS] is unity, as it must |
| 2424 | 2424 | // always be for the polynomials constructed by init_rs() |
| 2425 | 2425 | $feedback = $this->modnn($NN - $GENPOLY[$NROOTS] + $feedback); |
| 2426 | 2426 | |
| 2427 | - for($j=1;$j<$NROOTS;$j++) {
|
|
| 2428 | - $parity[$j] ^= $ALPHA_TO[$this->modnn($feedback + $GENPOLY[$NROOTS-$j])]; |
|
| 2427 | + for ($j = 1; $j < $NROOTS; $j++) {
|
|
| 2428 | + $parity[$j] ^= $ALPHA_TO[$this->modnn($feedback + $GENPOLY[$NROOTS - $j])]; |
|
| 2429 | 2429 | } |
| 2430 | 2430 | } |
| 2431 | 2431 | |
| 2432 | 2432 | // Shift |
| 2433 | 2433 | array_shift($parity); |
| 2434 | - if($feedback != $A0) {
|
|
| 2434 | + if ($feedback != $A0) {
|
|
| 2435 | 2435 | array_push($parity, $ALPHA_TO[$this->modnn($feedback + $GENPOLY[0])]); |
| 2436 | 2436 | } else {
|
| 2437 | 2437 | array_push($parity, 0); |
@@ -2449,13 +2449,13 @@ discard block |
||
| 2449 | 2449 | //---------------------------------------------------------------------- |
| 2450 | 2450 | public static function init_rs($symsize, $gfpoly, $fcr, $prim, $nroots, $pad) |
| 2451 | 2451 | {
|
| 2452 | - foreach(self::$items as $rs) {
|
|
| 2453 | - if($rs->pad != $pad) continue; |
|
| 2454 | - if($rs->nroots != $nroots) continue; |
|
| 2455 | - if($rs->mm != $symsize) continue; |
|
| 2456 | - if($rs->gfpoly != $gfpoly) continue; |
|
| 2457 | - if($rs->fcr != $fcr) continue; |
|
| 2458 | - if($rs->prim != $prim) continue; |
|
| 2452 | + foreach (self::$items as $rs) {
|
|
| 2453 | + if ($rs->pad != $pad) continue; |
|
| 2454 | + if ($rs->nroots != $nroots) continue; |
|
| 2455 | + if ($rs->mm != $symsize) continue; |
|
| 2456 | + if ($rs->gfpoly != $gfpoly) continue; |
|
| 2457 | + if ($rs->fcr != $fcr) continue; |
|
| 2458 | + if ($rs->prim != $prim) continue; |
|
| 2459 | 2459 | |
| 2460 | 2460 | return $rs; |
| 2461 | 2461 | } |
@@ -2519,10 +2519,10 @@ discard block |
||
| 2519 | 2519 | public function writeFormatInformation($width, &$frame, $mask, $level) |
| 2520 | 2520 | {
|
| 2521 | 2521 | $blacks = 0; |
| 2522 | - $format = QRspec::getFormatInfo($mask, $level); |
|
| 2522 | + $format = QRspec::getFormatInfo($mask, $level); |
|
| 2523 | 2523 | |
| 2524 | - for($i=0; $i<8; $i++) {
|
|
| 2525 | - if($format & 1) {
|
|
| 2524 | + for ($i = 0; $i < 8; $i++) {
|
|
| 2525 | + if ($format & 1) {
|
|
| 2526 | 2526 | $blacks += 2; |
| 2527 | 2527 | $v = 0x85; |
| 2528 | 2528 | } else {
|
@@ -2530,7 +2530,7 @@ discard block |
||
| 2530 | 2530 | } |
| 2531 | 2531 | |
| 2532 | 2532 | $frame[8][$width - 1 - $i] = chr($v); |
| 2533 | - if($i < 6) {
|
|
| 2533 | + if ($i < 6) {
|
|
| 2534 | 2534 | $frame[$i][8] = chr($v); |
| 2535 | 2535 | } else {
|
| 2536 | 2536 | $frame[$i + 1][8] = chr($v); |
@@ -2538,8 +2538,8 @@ discard block |
||
| 2538 | 2538 | $format = $format >> 1; |
| 2539 | 2539 | } |
| 2540 | 2540 | |
| 2541 | - for($i=0; $i<7; $i++) {
|
|
| 2542 | - if($format & 1) {
|
|
| 2541 | + for ($i = 0; $i < 7; $i++) {
|
|
| 2542 | + if ($format & 1) {
|
|
| 2543 | 2543 | $blacks += 2; |
| 2544 | 2544 | $v = 0x85; |
| 2545 | 2545 | } else {
|
@@ -2547,7 +2547,7 @@ discard block |
||
| 2547 | 2547 | } |
| 2548 | 2548 | |
| 2549 | 2549 | $frame[$width - 7 + $i][8] = chr($v); |
| 2550 | - if($i == 0) {
|
|
| 2550 | + if ($i == 0) {
|
|
| 2551 | 2551 | $frame[8][7] = chr($v); |
| 2552 | 2552 | } else {
|
| 2553 | 2553 | $frame[8][6 - $i] = chr($v); |
@@ -2560,27 +2560,27 @@ discard block |
||
| 2560 | 2560 | } |
| 2561 | 2561 | |
| 2562 | 2562 | //---------------------------------------------------------------------- |
| 2563 | - public function mask0($x, $y) { return ($x+$y)&1; }
|
|
| 2564 | - public function mask1($x, $y) { return ($y&1); }
|
|
| 2565 | - public function mask2($x, $y) { return ($x%3); }
|
|
| 2566 | - public function mask3($x, $y) { return ($x+$y)%3; }
|
|
| 2567 | - public function mask4($x, $y) { return (((int)($y/2))+((int)($x/3)))&1; }
|
|
| 2568 | - public function mask5($x, $y) { return (($x*$y)&1)+($x*$y)%3; }
|
|
| 2569 | - public function mask6($x, $y) { return ((($x*$y)&1)+($x*$y)%3)&1; }
|
|
| 2570 | - public function mask7($x, $y) { return ((($x*$y)%3)+(($x+$y)&1))&1; }
|
|
| 2563 | + public function mask0($x, $y) { return ($x + $y) & 1; }
|
|
| 2564 | + public function mask1($x, $y) { return ($y & 1); }
|
|
| 2565 | + public function mask2($x, $y) { return ($x % 3); }
|
|
| 2566 | + public function mask3($x, $y) { return ($x + $y) % 3; }
|
|
| 2567 | + public function mask4($x, $y) { return (((int) ($y / 2)) + ((int) ($x / 3))) & 1; }
|
|
| 2568 | + public function mask5($x, $y) { return (($x * $y) & 1) + ($x * $y) % 3; }
|
|
| 2569 | + public function mask6($x, $y) { return ((($x * $y) & 1) + ($x * $y) % 3) & 1; }
|
|
| 2570 | + public function mask7($x, $y) { return ((($x * $y) % 3) + (($x + $y) & 1)) & 1; }
|
|
| 2571 | 2571 | |
| 2572 | 2572 | //---------------------------------------------------------------------- |
| 2573 | 2573 | private function generateMaskNo($maskNo, $width, $frame) |
| 2574 | 2574 | {
|
| 2575 | 2575 | $bitMask = array_fill(0, $width, array_fill(0, $width, 0)); |
| 2576 | 2576 | |
| 2577 | - for($y=0; $y<$width; $y++) {
|
|
| 2578 | - for($x=0; $x<$width; $x++) {
|
|
| 2579 | - if(ord($frame[$y][$x]) & 0x80) {
|
|
| 2577 | + for ($y = 0; $y < $width; $y++) {
|
|
| 2578 | + for ($x = 0; $x < $width; $x++) {
|
|
| 2579 | + if (ord($frame[$y][$x]) & 0x80) {
|
|
| 2580 | 2580 | $bitMask[$y][$x] = 0; |
| 2581 | 2581 | } else {
|
| 2582 | - $maskFunc = call_user_func([$this, 'mask'.$maskNo], $x, $y); |
|
| 2583 | - $bitMask[$y][$x] = ($maskFunc == 0)?1:0; |
|
| 2582 | + $maskFunc = call_user_func([$this, 'mask' . $maskNo], $x, $y); |
|
| 2583 | + $bitMask[$y][$x] = ($maskFunc == 0) ? 1 : 0; |
|
| 2584 | 2584 | } |
| 2585 | 2585 | |
| 2586 | 2586 | } |
@@ -2618,15 +2618,15 @@ discard block |
||
| 2618 | 2618 | $b = 0; |
| 2619 | 2619 | $bitMask = []; |
| 2620 | 2620 | |
| 2621 | - $fileName = QR_CACHE_DIR.'mask_'.$maskNo.DIRECTORY_SEPARATOR.'mask_'.$width.'_'.$maskNo.'.dat'; |
|
| 2621 | + $fileName = QR_CACHE_DIR . 'mask_' . $maskNo . DIRECTORY_SEPARATOR . 'mask_' . $width . '_' . $maskNo . '.dat'; |
|
| 2622 | 2622 | |
| 2623 | 2623 | if (QR_CACHEABLE) {
|
| 2624 | 2624 | if (file_exists($fileName)) {
|
| 2625 | 2625 | $bitMask = self::unserial(file_get_contents($fileName)); |
| 2626 | 2626 | } else {
|
| 2627 | 2627 | $bitMask = $this->generateMaskNo($maskNo, $width, $s, $d); |
| 2628 | - if (!file_exists(QR_CACHE_DIR.'mask_'.$maskNo)) |
|
| 2629 | - mkdir(QR_CACHE_DIR.'mask_'.$maskNo); |
|
| 2628 | + if (!file_exists(QR_CACHE_DIR . 'mask_' . $maskNo)) |
|
| 2629 | + mkdir(QR_CACHE_DIR . 'mask_' . $maskNo); |
|
| 2630 | 2630 | file_put_contents($fileName, self::serial($bitMask)); |
| 2631 | 2631 | } |
| 2632 | 2632 | } else {
|
@@ -2638,12 +2638,12 @@ discard block |
||
| 2638 | 2638 | |
| 2639 | 2639 | $d = $s; |
| 2640 | 2640 | |
| 2641 | - for($y=0; $y<$width; $y++) {
|
|
| 2642 | - for($x=0; $x<$width; $x++) {
|
|
| 2643 | - if($bitMask[$y][$x] == 1) {
|
|
| 2644 | - $d[$y][$x] = chr(ord($s[$y][$x]) ^ (int)$bitMask[$y][$x]); |
|
| 2641 | + for ($y = 0; $y < $width; $y++) {
|
|
| 2642 | + for ($x = 0; $x < $width; $x++) {
|
|
| 2643 | + if ($bitMask[$y][$x] == 1) {
|
|
| 2644 | + $d[$y][$x] = chr(ord($s[$y][$x]) ^ (int) $bitMask[$y][$x]); |
|
| 2645 | 2645 | } |
| 2646 | - $b += (int)(ord($d[$y][$x]) & 1); |
|
| 2646 | + $b += (int) (ord($d[$y][$x]) & 1); |
|
| 2647 | 2647 | } |
| 2648 | 2648 | } |
| 2649 | 2649 | |
@@ -2665,21 +2665,21 @@ discard block |
||
| 2665 | 2665 | {
|
| 2666 | 2666 | $demerit = 0; |
| 2667 | 2667 | |
| 2668 | - for($i=0; $i<$length; $i++) {
|
|
| 2668 | + for ($i = 0; $i < $length; $i++) {
|
|
| 2669 | 2669 | |
| 2670 | - if($this->runLength[$i] >= 5) {
|
|
| 2670 | + if ($this->runLength[$i] >= 5) {
|
|
| 2671 | 2671 | $demerit += (N1 + ($this->runLength[$i] - 5)); |
| 2672 | 2672 | } |
| 2673 | - if($i & 1) {
|
|
| 2674 | - if(($i >= 3) && ($i < ($length-2)) && ($this->runLength[$i] % 3 == 0)) {
|
|
| 2675 | - $fact = (int)($this->runLength[$i] / 3); |
|
| 2676 | - if(($this->runLength[$i-2] == $fact) && |
|
| 2677 | - ($this->runLength[$i-1] == $fact) && |
|
| 2678 | - ($this->runLength[$i+1] == $fact) && |
|
| 2679 | - ($this->runLength[$i+2] == $fact)) {
|
|
| 2680 | - if(($this->runLength[$i-3] < 0) || ($this->runLength[$i-3] >= (4 * $fact))) {
|
|
| 2673 | + if ($i & 1) {
|
|
| 2674 | + if (($i >= 3) && ($i < ($length - 2)) && ($this->runLength[$i] % 3 == 0)) {
|
|
| 2675 | + $fact = (int) ($this->runLength[$i] / 3); |
|
| 2676 | + if (($this->runLength[$i - 2] == $fact) && |
|
| 2677 | + ($this->runLength[$i - 1] == $fact) && |
|
| 2678 | + ($this->runLength[$i + 1] == $fact) && |
|
| 2679 | + ($this->runLength[$i + 2] == $fact)) {
|
|
| 2680 | + if (($this->runLength[$i - 3] < 0) || ($this->runLength[$i - 3] >= (4 * $fact))) {
|
|
| 2681 | 2681 | $demerit += N3; |
| 2682 | - } else if((($i+3) >= $length) || ($this->runLength[$i+3] >= (4 * $fact))) {
|
|
| 2682 | + } else if ((($i + 3) >= $length) || ($this->runLength[$i + 3] >= (4 * $fact))) {
|
|
| 2683 | 2683 | $demerit += N3; |
| 2684 | 2684 | } |
| 2685 | 2685 | } |
@@ -2695,30 +2695,30 @@ discard block |
||
| 2695 | 2695 | $head = 0; |
| 2696 | 2696 | $demerit = 0; |
| 2697 | 2697 | |
| 2698 | - for($y=0; $y<$width; $y++) {
|
|
| 2698 | + for ($y = 0; $y < $width; $y++) {
|
|
| 2699 | 2699 | $head = 0; |
| 2700 | 2700 | $this->runLength[0] = 1; |
| 2701 | 2701 | |
| 2702 | 2702 | $frameY = $frame[$y]; |
| 2703 | 2703 | |
| 2704 | - if ($y>0) |
|
| 2705 | - $frameYM = $frame[$y-1]; |
|
| 2704 | + if ($y > 0) |
|
| 2705 | + $frameYM = $frame[$y - 1]; |
|
| 2706 | 2706 | |
| 2707 | - for($x=0; $x<$width; $x++) {
|
|
| 2708 | - if(($x > 0) && ($y > 0)) {
|
|
| 2709 | - $b22 = ord($frameY[$x]) & ord($frameY[$x-1]) & ord($frameYM[$x]) & ord($frameYM[$x-1]); |
|
| 2710 | - $w22 = ord($frameY[$x]) | ord($frameY[$x-1]) | ord($frameYM[$x]) | ord($frameYM[$x-1]); |
|
| 2707 | + for ($x = 0; $x < $width; $x++) {
|
|
| 2708 | + if (($x > 0) && ($y > 0)) {
|
|
| 2709 | + $b22 = ord($frameY[$x]) & ord($frameY[$x - 1]) & ord($frameYM[$x]) & ord($frameYM[$x - 1]); |
|
| 2710 | + $w22 = ord($frameY[$x]) | ord($frameY[$x - 1]) | ord($frameYM[$x]) | ord($frameYM[$x - 1]); |
|
| 2711 | 2711 | |
| 2712 | - if(($b22 | ($w22 ^ 1))&1) {
|
|
| 2712 | + if (($b22 | ($w22 ^ 1)) & 1) {
|
|
| 2713 | 2713 | $demerit += N2; |
| 2714 | 2714 | } |
| 2715 | 2715 | } |
| 2716 | - if(($x == 0) && (ord($frameY[$x]) & 1)) {
|
|
| 2716 | + if (($x == 0) && (ord($frameY[$x]) & 1)) {
|
|
| 2717 | 2717 | $this->runLength[0] = -1; |
| 2718 | 2718 | $head = 1; |
| 2719 | 2719 | $this->runLength[$head] = 1; |
| 2720 | - } else if($x > 0) {
|
|
| 2721 | - if((ord($frameY[$x]) ^ ord($frameY[$x-1])) & 1) {
|
|
| 2720 | + } else if ($x > 0) {
|
|
| 2721 | + if ((ord($frameY[$x]) ^ ord($frameY[$x - 1])) & 1) {
|
|
| 2722 | 2722 | $head++; |
| 2723 | 2723 | $this->runLength[$head] = 1; |
| 2724 | 2724 | } else {
|
@@ -2727,20 +2727,20 @@ discard block |
||
| 2727 | 2727 | } |
| 2728 | 2728 | } |
| 2729 | 2729 | |
| 2730 | - $demerit += $this->calcN1N3($head+1); |
|
| 2730 | + $demerit += $this->calcN1N3($head + 1); |
|
| 2731 | 2731 | } |
| 2732 | 2732 | |
| 2733 | - for($x=0; $x<$width; $x++) {
|
|
| 2733 | + for ($x = 0; $x < $width; $x++) {
|
|
| 2734 | 2734 | $head = 0; |
| 2735 | 2735 | $this->runLength[0] = 1; |
| 2736 | 2736 | |
| 2737 | - for($y=0; $y<$width; $y++) {
|
|
| 2738 | - if($y == 0 && (ord($frame[$y][$x]) & 1)) {
|
|
| 2737 | + for ($y = 0; $y < $width; $y++) {
|
|
| 2738 | + if ($y == 0 && (ord($frame[$y][$x]) & 1)) {
|
|
| 2739 | 2739 | $this->runLength[0] = -1; |
| 2740 | 2740 | $head = 1; |
| 2741 | 2741 | $this->runLength[$head] = 1; |
| 2742 | - } else if($y > 0) {
|
|
| 2743 | - if((ord($frame[$y][$x]) ^ ord($frame[$y-1][$x])) & 1) {
|
|
| 2742 | + } else if ($y > 0) {
|
|
| 2743 | + if ((ord($frame[$y][$x]) ^ ord($frame[$y - 1][$x])) & 1) {
|
|
| 2744 | 2744 | $head++; |
| 2745 | 2745 | $this->runLength[$head] = 1; |
| 2746 | 2746 | } else {
|
@@ -2749,7 +2749,7 @@ discard block |
||
| 2749 | 2749 | } |
| 2750 | 2750 | } |
| 2751 | 2751 | |
| 2752 | - $demerit += $this->calcN1N3($head+1); |
|
| 2752 | + $demerit += $this->calcN1N3($head + 1); |
|
| 2753 | 2753 | } |
| 2754 | 2754 | |
| 2755 | 2755 | return $demerit; |
@@ -2763,13 +2763,13 @@ discard block |
||
| 2763 | 2763 | $bestMaskNum = 0; |
| 2764 | 2764 | $bestMask = []; |
| 2765 | 2765 | |
| 2766 | - $checked_masks = [0,1,2,3,4,5,6,7]; |
|
| 2766 | + $checked_masks = [0, 1, 2, 3, 4, 5, 6, 7]; |
|
| 2767 | 2767 | |
| 2768 | 2768 | if (QR_FIND_FROM_RANDOM !== false) {
|
| 2769 | 2769 | |
| 2770 | - $howManuOut = 8-(QR_FIND_FROM_RANDOM % 9); |
|
| 2771 | - for ($i = 0; $i < $howManuOut; $i++) {
|
|
| 2772 | - $remPos = rand (0, count($checked_masks)-1); |
|
| 2770 | + $howManuOut = 8 - (QR_FIND_FROM_RANDOM % 9); |
|
| 2771 | + for ($i = 0; $i < $howManuOut; $i++) {
|
|
| 2772 | + $remPos = rand(0, count($checked_masks) - 1); |
|
| 2773 | 2773 | unset($checked_masks[$remPos]); |
| 2774 | 2774 | $checked_masks = array_values($checked_masks); |
| 2775 | 2775 | } |
@@ -2778,18 +2778,18 @@ discard block |
||
| 2778 | 2778 | |
| 2779 | 2779 | $bestMask = $frame; |
| 2780 | 2780 | |
| 2781 | - foreach($checked_masks as $i) {
|
|
| 2781 | + foreach ($checked_masks as $i) {
|
|
| 2782 | 2782 | $mask = array_fill(0, $width, str_repeat("\0", $width));
|
| 2783 | 2783 | |
| 2784 | 2784 | $demerit = 0; |
| 2785 | 2785 | $blacks = 0; |
| 2786 | 2786 | $blacks = $this->makeMaskNo($i, $width, $frame, $mask); |
| 2787 | 2787 | $blacks += $this->writeFormatInformation($width, $mask, $i, $level); |
| 2788 | - $blacks = (int)(100 * $blacks / ($width * $width)); |
|
| 2789 | - $demerit = (int)((int)(abs($blacks - 50) / 5) * N4); |
|
| 2788 | + $blacks = (int) (100 * $blacks / ($width * $width)); |
|
| 2789 | + $demerit = (int) ((int) (abs($blacks - 50) / 5) * N4); |
|
| 2790 | 2790 | $demerit += $this->evaluateSymbol($width, $mask); |
| 2791 | 2791 | |
| 2792 | - if($demerit < $minDemerit) {
|
|
| 2792 | + if ($demerit < $minDemerit) {
|
|
| 2793 | 2793 | $minDemerit = $demerit; |
| 2794 | 2794 | $bestMask = $mask; |
| 2795 | 2795 | $bestMaskNum = $i; |
@@ -2869,10 +2869,10 @@ discard block |
||
| 2869 | 2869 | //---------------------------------------------------------------------- |
| 2870 | 2870 | public function __construct(QRinput $input) |
| 2871 | 2871 | {
|
| 2872 | - $spec = [0,0,0,0,0]; |
|
| 2872 | + $spec = [0, 0, 0, 0, 0]; |
|
| 2873 | 2873 | |
| 2874 | 2874 | $this->datacode = $input->getByteStream(); |
| 2875 | - if(is_null($this->datacode)) {
|
|
| 2875 | + if (is_null($this->datacode)) {
|
|
| 2876 | 2876 | throw new Exception('null imput string');
|
| 2877 | 2877 | } |
| 2878 | 2878 | |
@@ -2886,7 +2886,7 @@ discard block |
||
| 2886 | 2886 | $this->blocks = QRspec::rsBlockNum($spec); |
| 2887 | 2887 | |
| 2888 | 2888 | $ret = $this->init($spec); |
| 2889 | - if($ret < 0) {
|
|
| 2889 | + if ($ret < 0) {
|
|
| 2890 | 2890 | throw new Exception('block alloc error');
|
| 2891 | 2891 | return null; |
| 2892 | 2892 | } |
@@ -2905,29 +2905,29 @@ discard block |
||
| 2905 | 2905 | $blockNo = 0; |
| 2906 | 2906 | $dataPos = 0; |
| 2907 | 2907 | $eccPos = 0; |
| 2908 | - for($i=0; $i<QRspec::rsBlockNum1($spec); $i++) {
|
|
| 2909 | - $ecc = array_slice($this->ecccode,$eccPos); |
|
| 2910 | - $this->rsblocks[$blockNo] = new QRrsblock($dl, array_slice($this->datacode, $dataPos), $el, $ecc, $rs); |
|
| 2911 | - $this->ecccode = array_merge(array_slice($this->ecccode,0, $eccPos), $ecc); |
|
| 2908 | + for ($i = 0; $i < QRspec::rsBlockNum1($spec); $i++) {
|
|
| 2909 | + $ecc = array_slice($this->ecccode, $eccPos); |
|
| 2910 | + $this->rsblocks[$blockNo] = new QRrsblock($dl, array_slice($this->datacode, $dataPos), $el, $ecc, $rs); |
|
| 2911 | + $this->ecccode = array_merge(array_slice($this->ecccode, 0, $eccPos), $ecc); |
|
| 2912 | 2912 | |
| 2913 | 2913 | $dataPos += $dl; |
| 2914 | 2914 | $eccPos += $el; |
| 2915 | 2915 | $blockNo++; |
| 2916 | 2916 | } |
| 2917 | 2917 | |
| 2918 | - if(QRspec::rsBlockNum2($spec) == 0) |
|
| 2918 | + if (QRspec::rsBlockNum2($spec) == 0) |
|
| 2919 | 2919 | return 0; |
| 2920 | 2920 | |
| 2921 | 2921 | $dl = QRspec::rsDataCodes2($spec); |
| 2922 | 2922 | $el = QRspec::rsEccCodes2($spec); |
| 2923 | 2923 | $rs = QRrs::init_rs(8, 0x11d, 0, 1, $el, 255 - $dl - $el); |
| 2924 | 2924 | |
| 2925 | - if($rs == NULL) return -1; |
|
| 2925 | + if ($rs == NULL) return -1; |
|
| 2926 | 2926 | |
| 2927 | - for($i=0; $i<QRspec::rsBlockNum2($spec); $i++) {
|
|
| 2928 | - $ecc = array_slice($this->ecccode,$eccPos); |
|
| 2927 | + for ($i = 0; $i < QRspec::rsBlockNum2($spec); $i++) {
|
|
| 2928 | + $ecc = array_slice($this->ecccode, $eccPos); |
|
| 2929 | 2929 | $this->rsblocks[$blockNo] = new QRrsblock($dl, array_slice($this->datacode, $dataPos), $el, $ecc, $rs); |
| 2930 | - $this->ecccode = array_merge(array_slice($this->ecccode,0, $eccPos), $ecc); |
|
| 2930 | + $this->ecccode = array_merge(array_slice($this->ecccode, 0, $eccPos), $ecc); |
|
| 2931 | 2931 | |
| 2932 | 2932 | $dataPos += $dl; |
| 2933 | 2933 | $eccPos += $el; |
@@ -2942,14 +2942,14 @@ discard block |
||
| 2942 | 2942 | {
|
| 2943 | 2943 | $ret; |
| 2944 | 2944 | |
| 2945 | - if($this->count < $this->dataLength) {
|
|
| 2945 | + if ($this->count < $this->dataLength) {
|
|
| 2946 | 2946 | $row = $this->count % $this->blocks; |
| 2947 | 2947 | $col = $this->count / $this->blocks; |
| 2948 | - if($col >= $this->rsblocks[0]->dataLength) {
|
|
| 2948 | + if ($col >= $this->rsblocks[0]->dataLength) {
|
|
| 2949 | 2949 | $row += $this->b1; |
| 2950 | 2950 | } |
| 2951 | 2951 | $ret = $this->rsblocks[$row]->data[$col]; |
| 2952 | - } else if($this->count < $this->dataLength + $this->eccLength) {
|
|
| 2952 | + } else if ($this->count < $this->dataLength + $this->eccLength) {
|
|
| 2953 | 2953 | $row = ($this->count - $this->dataLength) % $this->blocks; |
| 2954 | 2954 | $col = ($this->count - $this->dataLength) / $this->blocks; |
| 2955 | 2955 | $ret = $this->rsblocks[$row]->ecc[$col]; |
@@ -2973,10 +2973,10 @@ discard block |
||
| 2973 | 2973 | //---------------------------------------------------------------------- |
| 2974 | 2974 | public function encodeMask(QRinput $input, $mask) |
| 2975 | 2975 | {
|
| 2976 | - if($input->getVersion() < 0 || $input->getVersion() > QRSPEC_VERSION_MAX) {
|
|
| 2976 | + if ($input->getVersion() < 0 || $input->getVersion() > QRSPEC_VERSION_MAX) {
|
|
| 2977 | 2977 | throw new Exception('wrong version');
|
| 2978 | 2978 | } |
| 2979 | - if($input->getErrorCorrectionLevel() > QR_ECLEVEL_H) {
|
|
| 2979 | + if ($input->getErrorCorrectionLevel() > QR_ECLEVEL_H) {
|
|
| 2980 | 2980 | throw new Exception('wrong level');
|
| 2981 | 2981 | } |
| 2982 | 2982 | |
@@ -2989,15 +2989,15 @@ discard block |
||
| 2989 | 2989 | $frame = QRspec::newFrame($version); |
| 2990 | 2990 | |
| 2991 | 2991 | $filler = new FrameFiller($width, $frame); |
| 2992 | - if(is_null($filler)) {
|
|
| 2992 | + if (is_null($filler)) {
|
|
| 2993 | 2993 | return NULL; |
| 2994 | 2994 | } |
| 2995 | 2995 | |
| 2996 | 2996 | // inteleaved data and ecc codes |
| 2997 | - for($i=0; $i<$raw->dataLength + $raw->eccLength; $i++) {
|
|
| 2997 | + for ($i = 0; $i < $raw->dataLength + $raw->eccLength; $i++) {
|
|
| 2998 | 2998 | $code = $raw->getCode(); |
| 2999 | 2999 | $bit = 0x80; |
| 3000 | - for($j=0; $j<8; $j++) {
|
|
| 3000 | + for ($j = 0; $j < 8; $j++) {
|
|
| 3001 | 3001 | $addr = $filler->next(); |
| 3002 | 3002 | $filler->setFrameAt($addr, 0x02 | (($bit & $code) != 0)); |
| 3003 | 3003 | $bit = $bit >> 1; |
@@ -3010,7 +3010,7 @@ discard block |
||
| 3010 | 3010 | |
| 3011 | 3011 | // remainder bits |
| 3012 | 3012 | $j = QRspec::getRemainder($version); |
| 3013 | - for($i=0; $i<$j; $i++) {
|
|
| 3013 | + for ($i = 0; $i < $j; $i++) {
|
|
| 3014 | 3014 | $addr = $filler->next(); |
| 3015 | 3015 | $filler->setFrameAt($addr, 0x02); |
| 3016 | 3016 | } |
@@ -3021,7 +3021,7 @@ discard block |
||
| 3021 | 3021 | |
| 3022 | 3022 | // masking |
| 3023 | 3023 | $maskObj = new QRmask(); |
| 3024 | - if($mask < 0) {
|
|
| 3024 | + if ($mask < 0) {
|
|
| 3025 | 3025 | |
| 3026 | 3026 | if (QR_FIND_BEST_MASK) {
|
| 3027 | 3027 | $masked = $maskObj->mask($width, $frame, $input->getErrorCorrectionLevel()); |
@@ -3032,7 +3032,7 @@ discard block |
||
| 3032 | 3032 | $masked = $maskObj->makeMask($width, $frame, $mask, $input->getErrorCorrectionLevel()); |
| 3033 | 3033 | } |
| 3034 | 3034 | |
| 3035 | - if($masked == NULL) {
|
|
| 3035 | + if ($masked == NULL) {
|
|
| 3036 | 3036 | return NULL; |
| 3037 | 3037 | } |
| 3038 | 3038 | |
@@ -3054,16 +3054,16 @@ discard block |
||
| 3054 | 3054 | //---------------------------------------------------------------------- |
| 3055 | 3055 | public function encodeString8bit($string, $version, $level) |
| 3056 | 3056 | {
|
| 3057 | - if(string == NULL) {
|
|
| 3057 | + if (string == NULL) {
|
|
| 3058 | 3058 | throw new Exception('empty string!');
|
| 3059 | 3059 | return NULL; |
| 3060 | 3060 | } |
| 3061 | 3061 | |
| 3062 | 3062 | $input = new QRinput($version, $level); |
| 3063 | - if($input == NULL) return NULL; |
|
| 3063 | + if ($input == NULL) return NULL; |
|
| 3064 | 3064 | |
| 3065 | 3065 | $ret = $input->append($input, QR_MODE_8, strlen($string), str_split($string)); |
| 3066 | - if($ret < 0) {
|
|
| 3066 | + if ($ret < 0) {
|
|
| 3067 | 3067 | unset($input); |
| 3068 | 3068 | return NULL; |
| 3069 | 3069 | } |
@@ -3074,16 +3074,16 @@ discard block |
||
| 3074 | 3074 | public function encodeString($string, $version, $level, $hint, $casesensitive) |
| 3075 | 3075 | {
|
| 3076 | 3076 | |
| 3077 | - if($hint != QR_MODE_8 && $hint != QR_MODE_KANJI) {
|
|
| 3077 | + if ($hint != QR_MODE_8 && $hint != QR_MODE_KANJI) {
|
|
| 3078 | 3078 | throw new Exception('bad hint');
|
| 3079 | 3079 | return NULL; |
| 3080 | 3080 | } |
| 3081 | 3081 | |
| 3082 | 3082 | $input = new QRinput($version, $level); |
| 3083 | - if($input == NULL) return NULL; |
|
| 3083 | + if ($input == NULL) return NULL; |
|
| 3084 | 3084 | |
| 3085 | 3085 | $ret = QRsplit::splitStringToQRinput($string, $input, $hint, $casesensitive); |
| 3086 | - if($ret < 0) {
|
|
| 3086 | + if ($ret < 0) {
|
|
| 3087 | 3087 | return NULL; |
| 3088 | 3088 | } |
| 3089 | 3089 | |
@@ -3091,10 +3091,10 @@ discard block |
||
| 3091 | 3091 | } |
| 3092 | 3092 | |
| 3093 | 3093 | //---------------------------------------------------------------------- |
| 3094 | - public static function png($text, $outfile = false, $level = QR_ECLEVEL_L, $size = 3, $margin = 4, $saveandprint=false) |
|
| 3094 | + public static function png($text, $outfile = false, $level = QR_ECLEVEL_L, $size = 3, $margin = 4, $saveandprint = false) |
|
| 3095 | 3095 | {
|
| 3096 | 3096 | $enc = QRencode::factory($level, $size, $margin); |
| 3097 | - return $enc->encodePNG($text, $outfile, $saveandprint=false); |
|
| 3097 | + return $enc->encodePNG($text, $outfile, $saveandprint = false); |
|
| 3098 | 3098 | } |
| 3099 | 3099 | |
| 3100 | 3100 | //---------------------------------------------------------------------- |
@@ -3151,7 +3151,7 @@ discard block |
||
| 3151 | 3151 | {
|
| 3152 | 3152 | do {
|
| 3153 | 3153 | |
| 3154 | - if($this->bit == -1) {
|
|
| 3154 | + if ($this->bit == -1) {
|
|
| 3155 | 3155 | $this->bit = 0; |
| 3156 | 3156 | return ['x'=>$this->x, 'y'=>$this->y]; |
| 3157 | 3157 | } |
@@ -3160,7 +3160,7 @@ discard block |
||
| 3160 | 3160 | $y = $this->y; |
| 3161 | 3161 | $w = $this->width; |
| 3162 | 3162 | |
| 3163 | - if($this->bit == 0) {
|
|
| 3163 | + if ($this->bit == 0) {
|
|
| 3164 | 3164 | $x--; |
| 3165 | 3165 | $this->bit++; |
| 3166 | 3166 | } else {
|
@@ -3169,33 +3169,33 @@ discard block |
||
| 3169 | 3169 | $this->bit--; |
| 3170 | 3170 | } |
| 3171 | 3171 | |
| 3172 | - if($this->dir < 0) {
|
|
| 3173 | - if($y < 0) {
|
|
| 3172 | + if ($this->dir < 0) {
|
|
| 3173 | + if ($y < 0) {
|
|
| 3174 | 3174 | $y = 0; |
| 3175 | 3175 | $x -= 2; |
| 3176 | 3176 | $this->dir = 1; |
| 3177 | - if($x == 6) {
|
|
| 3177 | + if ($x == 6) {
|
|
| 3178 | 3178 | $x--; |
| 3179 | 3179 | $y = 9; |
| 3180 | 3180 | } |
| 3181 | 3181 | } |
| 3182 | 3182 | } else {
|
| 3183 | - if($y == $w) {
|
|
| 3183 | + if ($y == $w) {
|
|
| 3184 | 3184 | $y = $w - 1; |
| 3185 | 3185 | $x -= 2; |
| 3186 | 3186 | $this->dir = -1; |
| 3187 | - if($x == 6) {
|
|
| 3187 | + if ($x == 6) {
|
|
| 3188 | 3188 | $x--; |
| 3189 | 3189 | $y -= 8; |
| 3190 | 3190 | } |
| 3191 | 3191 | } |
| 3192 | 3192 | } |
| 3193 | - if($x < 0 || $y < 0) return null; |
|
| 3193 | + if ($x < 0 || $y < 0) return null; |
|
| 3194 | 3194 | |
| 3195 | 3195 | $this->x = $x; |
| 3196 | 3196 | $this->y = $y; |
| 3197 | 3197 | |
| 3198 | - } while(ord($this->frame[$y][$x]) & 0x80); |
|
| 3198 | + } while (ord($this->frame[$y][$x]) & 0x80); |
|
| 3199 | 3199 | |
| 3200 | 3200 | return ['x'=>$x, 'y'=>$y]; |
| 3201 | 3201 | } |
@@ -3225,7 +3225,7 @@ discard block |
||
| 3225 | 3225 | $enc->size = $size; |
| 3226 | 3226 | $enc->margin = $margin; |
| 3227 | 3227 | |
| 3228 | - switch ($level.'') {
|
|
| 3228 | + switch ($level . '') {
|
|
| 3229 | 3229 | case '0': |
| 3230 | 3230 | case '1': |
| 3231 | 3231 | case '2': |
@@ -3258,7 +3258,7 @@ discard block |
||
| 3258 | 3258 | {
|
| 3259 | 3259 | $code = new QRcode(); |
| 3260 | 3260 | |
| 3261 | - if($this->eightbit) {
|
|
| 3261 | + if ($this->eightbit) {
|
|
| 3262 | 3262 | $code->encodeString8bit($intext, $this->version, $this->level); |
| 3263 | 3263 | } else {
|
| 3264 | 3264 | $code->encodeString($intext, $this->version, $this->level, $this->hint, $this->casesensitive); |
@@ -3272,7 +3272,7 @@ discard block |
||
| 3272 | 3272 | {
|
| 3273 | 3273 | $code = new QRcode(); |
| 3274 | 3274 | |
| 3275 | - if($this->eightbit) {
|
|
| 3275 | + if ($this->eightbit) {
|
|
| 3276 | 3276 | $code->encodeString8bit($intext, $this->version, $this->level); |
| 3277 | 3277 | } else {
|
| 3278 | 3278 | $code->encodeString($intext, $this->version, $this->level, $this->hint, $this->casesensitive); |
@@ -3280,7 +3280,7 @@ discard block |
||
| 3280 | 3280 | |
| 3281 | 3281 | QRtools::markTime('after_encode');
|
| 3282 | 3282 | |
| 3283 | - if ($outfile!== false) {
|
|
| 3283 | + if ($outfile !== false) {
|
|
| 3284 | 3284 | file_put_contents($outfile, join("\n", QRtools::binarize($code->data)));
|
| 3285 | 3285 | } else {
|
| 3286 | 3286 | return QRtools::binarize($code->data); |
@@ -3288,7 +3288,7 @@ discard block |
||
| 3288 | 3288 | } |
| 3289 | 3289 | |
| 3290 | 3290 | //---------------------------------------------------------------------- |
| 3291 | - public function encodePNG($intext, $outfile = false,$saveandprint=false) |
|
| 3291 | + public function encodePNG($intext, $outfile = false, $saveandprint = false) |
|
| 3292 | 3292 | {
|
| 3293 | 3293 | try {
|
| 3294 | 3294 | |
@@ -3300,9 +3300,9 @@ discard block |
||
| 3300 | 3300 | if ($err != '') |
| 3301 | 3301 | QRtools::log($outfile, $err); |
| 3302 | 3302 | |
| 3303 | - $maxSize = (int)(QR_PNG_MAXIMUM_SIZE / (count($tab)+2*$this->margin)); |
|
| 3303 | + $maxSize = (int) (QR_PNG_MAXIMUM_SIZE / (count($tab) + 2 * $this->margin)); |
|
| 3304 | 3304 | |
| 3305 | - return QRimage::png($tab, $outfile, min(max(1, $this->size), $maxSize), $this->margin,$saveandprint); |
|
| 3305 | + return QRimage::png($tab, $outfile, min(max(1, $this->size), $maxSize), $this->margin, $saveandprint); |
|
| 3306 | 3306 | |
| 3307 | 3307 | } catch (Exception $e) {
|
| 3308 | 3308 | |
@@ -176,8 +176,9 @@ discard block |
||
| 176 | 176 | {
|
| 177 | 177 | $barcode_array = []; |
| 178 | 178 | |
| 179 | - if (!is_array($mode)) |
|
| 180 | - $mode = explode(',', $mode);
|
|
| 179 | + if (!is_array($mode)) { |
|
| 180 | + $mode = explode(',', $mode); |
|
| 181 | + } |
|
| 181 | 182 | |
| 182 | 183 | $eccLevel = 'L'; |
| 183 | 184 | |
@@ -194,8 +195,9 @@ discard block |
||
| 194 | 195 | |
| 195 | 196 | foreach ($qrTab as $line) {
|
| 196 | 197 | $arrAdd = []; |
| 197 | - foreach(str_split($line) as $char) |
|
| 198 | - $arrAdd[] = ($char=='1')?1:0; |
|
| 198 | + foreach(str_split($line) as $char) { |
|
| 199 | + $arrAdd[] = ($char=='1')?1:0; |
|
| 200 | + } |
|
| 199 | 201 | $barcode_array['bcode'][] = $arrAdd; |
| 200 | 202 | } |
| 201 | 203 | |
@@ -223,8 +225,9 @@ discard block |
||
| 223 | 225 | |
| 224 | 226 | $width = count($frame); |
| 225 | 227 | $bitMask = array_fill(0, $width, array_fill(0, $width, 0)); |
| 226 | - for ($maskNo=0; $maskNo<8; $maskNo++) |
|
| 227 | - $mask->makeMaskNo($maskNo, $width, $frame, $bitMask, true); |
|
| 228 | + for ($maskNo=0; $maskNo<8; $maskNo++) { |
|
| 229 | + $mask->makeMaskNo($maskNo, $width, $frame, $bitMask, true); |
|
| 230 | + } |
|
| 228 | 231 | } |
| 229 | 232 | |
| 230 | 233 | QRtools::markTime('after_build_cache');
|
@@ -261,8 +264,9 @@ discard block |
||
| 261 | 264 | list($usec, $sec) = explode(" ", microtime());
|
| 262 | 265 | $time = ((float)$usec + (float)$sec); |
| 263 | 266 | |
| 264 | - if (!isset($GLOBALS['qr_time_bench'])) |
|
| 265 | - $GLOBALS['qr_time_bench'] = []; |
|
| 267 | + if (!isset($GLOBALS['qr_time_bench'])) { |
|
| 268 | + $GLOBALS['qr_time_bench'] = []; |
|
| 269 | + } |
|
| 266 | 270 | |
| 267 | 271 | $GLOBALS['qr_time_bench'][$markerId] = $time; |
| 268 | 272 | } |
@@ -427,8 +431,9 @@ discard block |
||
| 427 | 431 | |
| 428 | 432 | for($i=1; $i<= QRSPEC_VERSION_MAX; $i++) {
|
| 429 | 433 | $words = self::$capacity[$i][QRCAP_WORDS] - self::$capacity[$i][QRCAP_EC][$level]; |
| 430 | - if($words >= $size) |
|
| 431 | - return $i; |
|
| 434 | + if($words >= $size) { |
|
| 435 | + return $i; |
|
| 436 | + } |
|
| 432 | 437 | } |
| 433 | 438 | |
| 434 | 439 | return -1; |
@@ -446,8 +451,9 @@ discard block |
||
| 446 | 451 | //---------------------------------------------------------------------- |
| 447 | 452 | public static function lengthIndicator($mode, $version) |
| 448 | 453 | {
|
| 449 | - if ($mode == QR_MODE_STRUCTURE) |
|
| 450 | - return 0; |
|
| 454 | + if ($mode == QR_MODE_STRUCTURE) { |
|
| 455 | + return 0; |
|
| 456 | + } |
|
| 451 | 457 | |
| 452 | 458 | if ($version <= 9) {
|
| 453 | 459 | $l = 0; |
@@ -463,8 +469,9 @@ discard block |
||
| 463 | 469 | //---------------------------------------------------------------------- |
| 464 | 470 | public static function maximumWords($mode, $version) |
| 465 | 471 | {
|
| 466 | - if($mode == QR_MODE_STRUCTURE) |
|
| 467 | - return 3; |
|
| 472 | + if($mode == QR_MODE_STRUCTURE) { |
|
| 473 | + return 3; |
|
| 474 | + } |
|
| 468 | 475 | |
| 469 | 476 | if($version <= 9) {
|
| 470 | 477 | $l = 0; |
@@ -610,8 +617,9 @@ discard block |
||
| 610 | 617 | //---------------------------------------------------------------------- |
| 611 | 618 | public static function putAlignmentPattern($version, &$frame, $width) |
| 612 | 619 | {
|
| 613 | - if($version < 2) |
|
| 614 | - return; |
|
| 620 | + if($version < 2) { |
|
| 621 | + return; |
|
| 622 | + } |
|
| 615 | 623 | |
| 616 | 624 | $d = self::$alignmentPattern[$version][1] - self::$alignmentPattern[$version][0]; |
| 617 | 625 | if($d < 0) {
|
@@ -663,8 +671,9 @@ discard block |
||
| 663 | 671 | //---------------------------------------------------------------------- |
| 664 | 672 | public static function getVersionPattern($version) |
| 665 | 673 | {
|
| 666 | - if($version < 7 || $version > QRSPEC_VERSION_MAX) |
|
| 667 | - return 0; |
|
| 674 | + if($version < 7 || $version > QRSPEC_VERSION_MAX) { |
|
| 675 | + return 0; |
|
| 676 | + } |
|
| 668 | 677 | |
| 669 | 678 | return self::$versionPattern[$version -7]; |
| 670 | 679 | } |
@@ -681,11 +690,13 @@ discard block |
||
| 681 | 690 | |
| 682 | 691 | public static function getFormatInfo($mask, $level) |
| 683 | 692 | {
|
| 684 | - if($mask < 0 || $mask > 7) |
|
| 685 | - return 0; |
|
| 693 | + if($mask < 0 || $mask > 7) { |
|
| 694 | + return 0; |
|
| 695 | + } |
|
| 686 | 696 | |
| 687 | - if($level < 0 || $level > 3) |
|
| 688 | - return 0; |
|
| 697 | + if($level < 0 || $level > 3) { |
|
| 698 | + return 0; |
|
| 699 | + } |
|
| 689 | 700 | |
| 690 | 701 | return self::$formatInfo[$level][$mask]; |
| 691 | 702 | } |
@@ -865,8 +876,9 @@ discard block |
||
| 865 | 876 | //---------------------------------------------------------------------- |
| 866 | 877 | public static function newFrame($version) |
| 867 | 878 | {
|
| 868 | - if($version < 1 || $version > QRSPEC_VERSION_MAX) |
|
| 869 | - return null; |
|
| 879 | + if($version < 1 || $version > QRSPEC_VERSION_MAX) { |
|
| 880 | + return null; |
|
| 881 | + } |
|
| 870 | 882 | |
| 871 | 883 | if(!isset(self::$frames[$version])) {
|
| 872 | 884 | |
@@ -884,8 +896,9 @@ discard block |
||
| 884 | 896 | } |
| 885 | 897 | } |
| 886 | 898 | |
| 887 | - if(is_null(self::$frames[$version])) |
|
| 888 | - return null; |
|
| 899 | + if(is_null(self::$frames[$version])) { |
|
| 900 | + return null; |
|
| 901 | + } |
|
| 889 | 902 | |
| 890 | 903 | return self::$frames[$version]; |
| 891 | 904 | } |
@@ -953,7 +966,7 @@ discard block |
||
| 953 | 966 | ImagePng($image, $filename); |
| 954 | 967 | header("Content-type: image/png");
|
| 955 | 968 | ImagePng($image); |
| 956 | - }else{
|
|
| 969 | + } else{
|
|
| 957 | 970 | ImagePng($image, $filename); |
| 958 | 971 | } |
| 959 | 972 | } |
@@ -1213,8 +1226,9 @@ discard block |
||
| 1213 | 1226 | {
|
| 1214 | 1227 | $bits = 0; |
| 1215 | 1228 | |
| 1216 | - if($version == 0) |
|
| 1217 | - $version = 1; |
|
| 1229 | + if($version == 0) { |
|
| 1230 | + $version = 1; |
|
| 1231 | + } |
|
| 1218 | 1232 | |
| 1219 | 1233 | switch($this->mode) {
|
| 1220 | 1234 | case QR_MODE_NUM: $bits = QRinput::estimateBitsModeNum($this->size); break; |
@@ -1273,8 +1287,9 @@ discard block |
||
| 1273 | 1287 | break; |
| 1274 | 1288 | } |
| 1275 | 1289 | |
| 1276 | - if($ret < 0) |
|
| 1277 | - return -1; |
|
| 1290 | + if($ret < 0) { |
|
| 1291 | + return -1; |
|
| 1292 | + } |
|
| 1278 | 1293 | } |
| 1279 | 1294 | |
| 1280 | 1295 | return $this->bstream->size(); |
@@ -1491,8 +1506,9 @@ discard block |
||
| 1491 | 1506 | //---------------------------------------------------------------------- |
| 1492 | 1507 | public static function checkModeKanji($size, $data) |
| 1493 | 1508 | {
|
| 1494 | - if($size & 1) |
|
| 1495 | - return false; |
|
| 1509 | + if($size & 1) { |
|
| 1510 | + return false; |
|
| 1511 | + } |
|
| 1496 | 1512 | |
| 1497 | 1513 | for($i=0; $i<$size; $i+=2) {
|
| 1498 | 1514 | $val = (ord($data[$i]) << 8) | ord($data[$i+1]); |
@@ -1512,8 +1528,9 @@ discard block |
||
| 1512 | 1528 | |
| 1513 | 1529 | public static function check($mode, $size, $data) |
| 1514 | 1530 | {
|
| 1515 | - if($size <= 0) |
|
| 1516 | - return false; |
|
| 1531 | + if($size <= 0) { |
|
| 1532 | + return false; |
|
| 1533 | + } |
|
| 1517 | 1534 | |
| 1518 | 1535 | switch($mode) {
|
| 1519 | 1536 | case QR_MODE_NUM: return self::checkModeNum($size, $data); break; |
@@ -1578,8 +1595,9 @@ discard block |
||
| 1578 | 1595 | $chunks = (int)($payload / 11); |
| 1579 | 1596 | $remain = $payload - $chunks * 11; |
| 1580 | 1597 | $size = $chunks * 2; |
| 1581 | - if($remain >= 6) |
|
| 1582 | - $size++; |
|
| 1598 | + if($remain >= 6) { |
|
| 1599 | + $size++; |
|
| 1600 | + } |
|
| 1583 | 1601 | break; |
| 1584 | 1602 | case QR_MODE_8: |
| 1585 | 1603 | $size = (int)($payload / 8); |
@@ -1596,8 +1614,12 @@ discard block |
||
| 1596 | 1614 | } |
| 1597 | 1615 | |
| 1598 | 1616 | $maxsize = QRspec::maximumWords($mode, $version); |
| 1599 | - if($size < 0) $size = 0; |
|
| 1600 | - if($size > $maxsize) $size = $maxsize; |
|
| 1617 | + if($size < 0) { |
|
| 1618 | + $size = 0; |
|
| 1619 | + } |
|
| 1620 | + if($size > $maxsize) { |
|
| 1621 | + $size = $maxsize; |
|
| 1622 | + } |
|
| 1601 | 1623 | |
| 1602 | 1624 | return $size; |
| 1603 | 1625 | } |
@@ -1610,8 +1632,9 @@ discard block |
||
| 1610 | 1632 | foreach($this->items as $item) {
|
| 1611 | 1633 | $bits = $item->encodeBitStream($this->version); |
| 1612 | 1634 | |
| 1613 | - if($bits < 0) |
|
| 1614 | - return -1; |
|
| 1635 | + if($bits < 0) { |
|
| 1636 | + return -1; |
|
| 1637 | + } |
|
| 1615 | 1638 | |
| 1616 | 1639 | $total += $bits; |
| 1617 | 1640 | } |
@@ -1630,8 +1653,9 @@ discard block |
||
| 1630 | 1653 | for(;;) {
|
| 1631 | 1654 | $bits = $this->createBitStream(); |
| 1632 | 1655 | |
| 1633 | - if($bits < 0) |
|
| 1634 | - return -1; |
|
| 1656 | + if($bits < 0) { |
|
| 1657 | + return -1; |
|
| 1658 | + } |
|
| 1635 | 1659 | |
| 1636 | 1660 | $ver = QRspec::getMinimumVersion((int)(($bits + 7) / 8), $this->level); |
| 1637 | 1661 | if($ver < 0) {
|
@@ -1668,8 +1692,9 @@ discard block |
||
| 1668 | 1692 | $padding = new QRbitstream(); |
| 1669 | 1693 | $ret = $padding->appendNum($words * 8 - $bits + 4, 0); |
| 1670 | 1694 | |
| 1671 | - if($ret < 0) |
|
| 1672 | - return $ret; |
|
| 1695 | + if($ret < 0) { |
|
| 1696 | + return $ret; |
|
| 1697 | + } |
|
| 1673 | 1698 | |
| 1674 | 1699 | $padlen = $maxwords - $words; |
| 1675 | 1700 | |
@@ -1682,8 +1707,9 @@ discard block |
||
| 1682 | 1707 | |
| 1683 | 1708 | $ret = $padding->appendBytes($padlen, $padbuf); |
| 1684 | 1709 | |
| 1685 | - if($ret < 0) |
|
| 1686 | - return $ret; |
|
| 1710 | + if($ret < 0) { |
|
| 1711 | + return $ret; |
|
| 1712 | + } |
|
| 1687 | 1713 | |
| 1688 | 1714 | } |
| 1689 | 1715 | |
@@ -1860,13 +1886,15 @@ discard block |
||
| 1860 | 1886 | //---------------------------------------------------------------------- |
| 1861 | 1887 | public function appendNum($bits, $num) |
| 1862 | 1888 | {
|
| 1863 | - if ($bits == 0) |
|
| 1864 | - return 0; |
|
| 1889 | + if ($bits == 0) { |
|
| 1890 | + return 0; |
|
| 1891 | + } |
|
| 1865 | 1892 | |
| 1866 | 1893 | $b = QRbitstream::newFromNum($bits, $num); |
| 1867 | 1894 | |
| 1868 | - if(is_null($b)) |
|
| 1869 | - return -1; |
|
| 1895 | + if(is_null($b)) { |
|
| 1896 | + return -1; |
|
| 1897 | + } |
|
| 1870 | 1898 | |
| 1871 | 1899 | $ret = $this->append($b); |
| 1872 | 1900 | unset($b); |
@@ -1877,13 +1905,15 @@ discard block |
||
| 1877 | 1905 | //---------------------------------------------------------------------- |
| 1878 | 1906 | public function appendBytes($size, $data) |
| 1879 | 1907 | {
|
| 1880 | - if ($size == 0) |
|
| 1881 | - return 0; |
|
| 1908 | + if ($size == 0) { |
|
| 1909 | + return 0; |
|
| 1910 | + } |
|
| 1882 | 1911 | |
| 1883 | 1912 | $b = QRbitstream::newFromBytes($size, $data); |
| 1884 | 1913 | |
| 1885 | - if(is_null($b)) |
|
| 1886 | - return -1; |
|
| 1914 | + if(is_null($b)) { |
|
| 1915 | + return -1; |
|
| 1916 | + } |
|
| 1887 | 1917 | |
| 1888 | 1918 | $ret = $this->append($b); |
| 1889 | 1919 | unset($b); |
@@ -1987,8 +2017,9 @@ discard block |
||
| 1987 | 2017 | //---------------------------------------------------------------------- |
| 1988 | 2018 | public static function isdigitat($str, $pos) |
| 1989 | 2019 | {
|
| 1990 | - if ($pos >= strlen($str)) |
|
| 1991 | - return false; |
|
| 2020 | + if ($pos >= strlen($str)) { |
|
| 2021 | + return false; |
|
| 2022 | + } |
|
| 1992 | 2023 | |
| 1993 | 2024 | return ((ord($str[$pos]) >= ord('0'))&&(ord($str[$pos]) <= ord('9')));
|
| 1994 | 2025 | } |
@@ -1996,8 +2027,9 @@ discard block |
||
| 1996 | 2027 | //---------------------------------------------------------------------- |
| 1997 | 2028 | public static function isalnumat($str, $pos) |
| 1998 | 2029 | {
|
| 1999 | - if ($pos >= strlen($str)) |
|
| 2000 | - return false; |
|
| 2030 | + if ($pos >= strlen($str)) { |
|
| 2031 | + return false; |
|
| 2032 | + } |
|
| 2001 | 2033 | |
| 2002 | 2034 | return (QRinput::lookAnTable(ord($str[$pos])) >= 0); |
| 2003 | 2035 | } |
@@ -2005,8 +2037,9 @@ discard block |
||
| 2005 | 2037 | //---------------------------------------------------------------------- |
| 2006 | 2038 | public function identifyMode($pos) |
| 2007 | 2039 | {
|
| 2008 | - if ($pos >= strlen($this->dataStr)) |
|
| 2009 | - return QR_MODE_NUL; |
|
| 2040 | + if ($pos >= strlen($this->dataStr)) { |
|
| 2041 | + return QR_MODE_NUL; |
|
| 2042 | + } |
|
| 2010 | 2043 | |
| 2011 | 2044 | $c = $this->dataStr[$pos]; |
| 2012 | 2045 | |
@@ -2060,8 +2093,9 @@ discard block |
||
| 2060 | 2093 | } |
| 2061 | 2094 | |
| 2062 | 2095 | $ret = $this->input->append(QR_MODE_NUM, $run, str_split($this->dataStr)); |
| 2063 | - if($ret < 0) |
|
| 2064 | - return -1; |
|
| 2096 | + if($ret < 0) { |
|
| 2097 | + return -1; |
|
| 2098 | + } |
|
| 2065 | 2099 | |
| 2066 | 2100 | return $run; |
| 2067 | 2101 | } |
@@ -2107,8 +2141,9 @@ discard block |
||
| 2107 | 2141 | } |
| 2108 | 2142 | |
| 2109 | 2143 | $ret = $this->input->append(QR_MODE_AN, $run, str_split($this->dataStr)); |
| 2110 | - if($ret < 0) |
|
| 2111 | - return -1; |
|
| 2144 | + if($ret < 0) { |
|
| 2145 | + return -1; |
|
| 2146 | + } |
|
| 2112 | 2147 | |
| 2113 | 2148 | return $run; |
| 2114 | 2149 | } |
@@ -2123,8 +2158,9 @@ discard block |
||
| 2123 | 2158 | } |
| 2124 | 2159 | |
| 2125 | 2160 | $ret = $this->input->append(QR_MODE_KANJI, $p, str_split($this->dataStr)); |
| 2126 | - if($ret < 0) |
|
| 2127 | - return -1; |
|
| 2161 | + if($ret < 0) { |
|
| 2162 | + return -1; |
|
| 2163 | + } |
|
| 2128 | 2164 | |
| 2129 | 2165 | return $run; |
| 2130 | 2166 | } |
@@ -2178,8 +2214,9 @@ discard block |
||
| 2178 | 2214 | $run = $p; |
| 2179 | 2215 | $ret = $this->input->append(QR_MODE_8, $run, str_split($this->dataStr)); |
| 2180 | 2216 | |
| 2181 | - if($ret < 0) |
|
| 2182 | - return -1; |
|
| 2217 | + if($ret < 0) { |
|
| 2218 | + return -1; |
|
| 2219 | + } |
|
| 2183 | 2220 | |
| 2184 | 2221 | return $run; |
| 2185 | 2222 | } |
@@ -2189,8 +2226,9 @@ discard block |
||
| 2189 | 2226 | {
|
| 2190 | 2227 | while (strlen($this->dataStr) > 0) |
| 2191 | 2228 | {
|
| 2192 | - if($this->dataStr == '') |
|
| 2193 | - return 0; |
|
| 2229 | + if($this->dataStr == '') { |
|
| 2230 | + return 0; |
|
| 2231 | + } |
|
| 2194 | 2232 | |
| 2195 | 2233 | $mode = $this->identifyMode(0); |
| 2196 | 2234 | |
@@ -2198,16 +2236,22 @@ discard block |
||
| 2198 | 2236 | case QR_MODE_NUM: $length = $this->eatNum(); break; |
| 2199 | 2237 | case QR_MODE_AN: $length = $this->eatAn(); break; |
| 2200 | 2238 | case QR_MODE_KANJI: |
| 2201 | - if ($hint == QR_MODE_KANJI) |
|
| 2202 | - $length = $this->eatKanji(); |
|
| 2203 | - else $length = $this->eat8(); |
|
| 2239 | + if ($hint == QR_MODE_KANJI) { |
|
| 2240 | + $length = $this->eatKanji(); |
|
| 2241 | + } else { |
|
| 2242 | + $length = $this->eat8(); |
|
| 2243 | + } |
|
| 2204 | 2244 | break; |
| 2205 | 2245 | default: $length = $this->eat8(); break; |
| 2206 | 2246 | |
| 2207 | 2247 | } |
| 2208 | 2248 | |
| 2209 | - if($length == 0) return 0; |
|
| 2210 | - if($length < 0) return -1; |
|
| 2249 | + if($length == 0) { |
|
| 2250 | + return 0; |
|
| 2251 | + } |
|
| 2252 | + if($length < 0) { |
|
| 2253 | + return -1; |
|
| 2254 | + } |
|
| 2211 | 2255 | |
| 2212 | 2256 | $this->dataStr = substr($this->dataStr, $length); |
| 2213 | 2257 | } |
@@ -2243,8 +2287,9 @@ discard block |
||
| 2243 | 2287 | |
| 2244 | 2288 | $split = new QRsplit($string, $input, $modeHint); |
| 2245 | 2289 | |
| 2246 | - if(!$casesensitive) |
|
| 2247 | - $split->toUpper(); |
|
| 2290 | + if(!$casesensitive) { |
|
| 2291 | + $split->toUpper(); |
|
| 2292 | + } |
|
| 2248 | 2293 | |
| 2249 | 2294 | return $split->splitString(); |
| 2250 | 2295 | } |
@@ -2321,11 +2366,23 @@ discard block |
||
| 2321 | 2366 | $rs = null; |
| 2322 | 2367 | |
| 2323 | 2368 | // Check parameter ranges |
| 2324 | - if($symsize < 0 || $symsize > 8) return $rs; |
|
| 2325 | - if($fcr < 0 || $fcr >= (1<<$symsize)) return $rs; |
|
| 2326 | - if($prim <= 0 || $prim >= (1<<$symsize)) return $rs; |
|
| 2327 | - if($nroots < 0 || $nroots >= (1<<$symsize)) return $rs; // Can't have more roots than symbol values! |
|
| 2328 | - if($pad < 0 || $pad >= ((1<<$symsize) -1 - $nroots)) return $rs; // Too much padding |
|
| 2369 | + if($symsize < 0 || $symsize > 8) { |
|
| 2370 | + return $rs; |
|
| 2371 | + } |
|
| 2372 | + if($fcr < 0 || $fcr >= (1<<$symsize)) { |
|
| 2373 | + return $rs; |
|
| 2374 | + } |
|
| 2375 | + if($prim <= 0 || $prim >= (1<<$symsize)) { |
|
| 2376 | + return $rs; |
|
| 2377 | + } |
|
| 2378 | + if($nroots < 0 || $nroots >= (1<<$symsize)) { |
|
| 2379 | + return $rs; |
|
| 2380 | + } |
|
| 2381 | + // Can't have more roots than symbol values! |
|
| 2382 | + if($pad < 0 || $pad >= ((1<<$symsize) -1 - $nroots)) { |
|
| 2383 | + return $rs; |
|
| 2384 | + } |
|
| 2385 | + // Too much padding |
|
| 2329 | 2386 | |
| 2330 | 2387 | $rs = new QRrsItem(); |
| 2331 | 2388 | $rs->mm = $symsize; |
@@ -2391,8 +2448,9 @@ discard block |
||
| 2391 | 2448 | } |
| 2392 | 2449 | |
| 2393 | 2450 | // convert rs->genpoly[] to index form for quicker encoding |
| 2394 | - for ($i = 0; $i <= $nroots; $i++) |
|
| 2395 | - $rs->genpoly[$i] = $rs->index_of[$rs->genpoly[$i]]; |
|
| 2451 | + for ($i = 0; $i <= $nroots; $i++) { |
|
| 2452 | + $rs->genpoly[$i] = $rs->index_of[$rs->genpoly[$i]]; |
|
| 2453 | + } |
|
| 2396 | 2454 | |
| 2397 | 2455 | return $rs; |
| 2398 | 2456 | } |
@@ -2450,12 +2508,24 @@ discard block |
||
| 2450 | 2508 | public static function init_rs($symsize, $gfpoly, $fcr, $prim, $nroots, $pad) |
| 2451 | 2509 | {
|
| 2452 | 2510 | foreach(self::$items as $rs) {
|
| 2453 | - if($rs->pad != $pad) continue; |
|
| 2454 | - if($rs->nroots != $nroots) continue; |
|
| 2455 | - if($rs->mm != $symsize) continue; |
|
| 2456 | - if($rs->gfpoly != $gfpoly) continue; |
|
| 2457 | - if($rs->fcr != $fcr) continue; |
|
| 2458 | - if($rs->prim != $prim) continue; |
|
| 2511 | + if($rs->pad != $pad) { |
|
| 2512 | + continue; |
|
| 2513 | + } |
|
| 2514 | + if($rs->nroots != $nroots) { |
|
| 2515 | + continue; |
|
| 2516 | + } |
|
| 2517 | + if($rs->mm != $symsize) { |
|
| 2518 | + continue; |
|
| 2519 | + } |
|
| 2520 | + if($rs->gfpoly != $gfpoly) { |
|
| 2521 | + continue; |
|
| 2522 | + } |
|
| 2523 | + if($rs->fcr != $fcr) { |
|
| 2524 | + continue; |
|
| 2525 | + } |
|
| 2526 | + if($rs->prim != $prim) { |
|
| 2527 | + continue; |
|
| 2528 | + } |
|
| 2459 | 2529 | |
| 2460 | 2530 | return $rs; |
| 2461 | 2531 | } |
@@ -2594,8 +2664,9 @@ discard block |
||
| 2594 | 2664 | {
|
| 2595 | 2665 | $codeArr = []; |
| 2596 | 2666 | |
| 2597 | - foreach ($bitFrame as $line) |
|
| 2598 | - $codeArr[] = join('', $line);
|
|
| 2667 | + foreach ($bitFrame as $line) { |
|
| 2668 | + $codeArr[] = join('', $line); |
|
| 2669 | + } |
|
| 2599 | 2670 | |
| 2600 | 2671 | return gzcompress(join("\n", $codeArr), 9);
|
| 2601 | 2672 | } |
@@ -2606,8 +2677,9 @@ discard block |
||
| 2606 | 2677 | $codeArr = []; |
| 2607 | 2678 | |
| 2608 | 2679 | $codeLines = explode("\n", gzuncompress($code));
|
| 2609 | - foreach ($codeLines as $line) |
|
| 2610 | - $codeArr[] = str_split($line); |
|
| 2680 | + foreach ($codeLines as $line) { |
|
| 2681 | + $codeArr[] = str_split($line); |
|
| 2682 | + } |
|
| 2611 | 2683 | |
| 2612 | 2684 | return $codeArr; |
| 2613 | 2685 | } |
@@ -2625,16 +2697,18 @@ discard block |
||
| 2625 | 2697 | $bitMask = self::unserial(file_get_contents($fileName)); |
| 2626 | 2698 | } else {
|
| 2627 | 2699 | $bitMask = $this->generateMaskNo($maskNo, $width, $s, $d); |
| 2628 | - if (!file_exists(QR_CACHE_DIR.'mask_'.$maskNo)) |
|
| 2629 | - mkdir(QR_CACHE_DIR.'mask_'.$maskNo); |
|
| 2700 | + if (!file_exists(QR_CACHE_DIR.'mask_'.$maskNo)) { |
|
| 2701 | + mkdir(QR_CACHE_DIR.'mask_'.$maskNo); |
|
| 2702 | + } |
|
| 2630 | 2703 | file_put_contents($fileName, self::serial($bitMask)); |
| 2631 | 2704 | } |
| 2632 | 2705 | } else {
|
| 2633 | 2706 | $bitMask = $this->generateMaskNo($maskNo, $width, $s, $d); |
| 2634 | 2707 | } |
| 2635 | 2708 | |
| 2636 | - if ($maskGenOnly) |
|
| 2637 | - return; |
|
| 2709 | + if ($maskGenOnly) { |
|
| 2710 | + return; |
|
| 2711 | + } |
|
| 2638 | 2712 | |
| 2639 | 2713 | $d = $s; |
| 2640 | 2714 | |
@@ -2701,8 +2775,9 @@ discard block |
||
| 2701 | 2775 | |
| 2702 | 2776 | $frameY = $frame[$y]; |
| 2703 | 2777 | |
| 2704 | - if ($y>0) |
|
| 2705 | - $frameYM = $frame[$y-1]; |
|
| 2778 | + if ($y>0) { |
|
| 2779 | + $frameYM = $frame[$y-1]; |
|
| 2780 | + } |
|
| 2706 | 2781 | |
| 2707 | 2782 | for($x=0; $x<$width; $x++) {
|
| 2708 | 2783 | if(($x > 0) && ($y > 0)) {
|
@@ -2915,14 +2990,17 @@ discard block |
||
| 2915 | 2990 | $blockNo++; |
| 2916 | 2991 | } |
| 2917 | 2992 | |
| 2918 | - if(QRspec::rsBlockNum2($spec) == 0) |
|
| 2919 | - return 0; |
|
| 2993 | + if(QRspec::rsBlockNum2($spec) == 0) { |
|
| 2994 | + return 0; |
|
| 2995 | + } |
|
| 2920 | 2996 | |
| 2921 | 2997 | $dl = QRspec::rsDataCodes2($spec); |
| 2922 | 2998 | $el = QRspec::rsEccCodes2($spec); |
| 2923 | 2999 | $rs = QRrs::init_rs(8, 0x11d, 0, 1, $el, 255 - $dl - $el); |
| 2924 | 3000 | |
| 2925 | - if($rs == NULL) return -1; |
|
| 3001 | + if($rs == NULL) { |
|
| 3002 | + return -1; |
|
| 3003 | + } |
|
| 2926 | 3004 | |
| 2927 | 3005 | for($i=0; $i<QRspec::rsBlockNum2($spec); $i++) {
|
| 2928 | 3006 | $ecc = array_slice($this->ecccode,$eccPos); |
@@ -3060,7 +3138,9 @@ discard block |
||
| 3060 | 3138 | } |
| 3061 | 3139 | |
| 3062 | 3140 | $input = new QRinput($version, $level); |
| 3063 | - if($input == NULL) return NULL; |
|
| 3141 | + if($input == NULL) { |
|
| 3142 | + return NULL; |
|
| 3143 | + } |
|
| 3064 | 3144 | |
| 3065 | 3145 | $ret = $input->append($input, QR_MODE_8, strlen($string), str_split($string)); |
| 3066 | 3146 | if($ret < 0) {
|
@@ -3080,7 +3160,9 @@ discard block |
||
| 3080 | 3160 | } |
| 3081 | 3161 | |
| 3082 | 3162 | $input = new QRinput($version, $level); |
| 3083 | - if($input == NULL) return NULL; |
|
| 3163 | + if($input == NULL) { |
|
| 3164 | + return NULL; |
|
| 3165 | + } |
|
| 3084 | 3166 | |
| 3085 | 3167 | $ret = QRsplit::splitStringToQRinput($string, $input, $hint, $casesensitive); |
| 3086 | 3168 | if($ret < 0) {
|
@@ -3190,7 +3272,9 @@ discard block |
||
| 3190 | 3272 | } |
| 3191 | 3273 | } |
| 3192 | 3274 | } |
| 3193 | - if($x < 0 || $y < 0) return null; |
|
| 3275 | + if($x < 0 || $y < 0) { |
|
| 3276 | + return null; |
|
| 3277 | + } |
|
| 3194 | 3278 | |
| 3195 | 3279 | $this->x = $x; |
| 3196 | 3280 | $this->y = $y; |
@@ -3297,8 +3381,9 @@ discard block |
||
| 3297 | 3381 | $err = ob_get_contents(); |
| 3298 | 3382 | ob_end_clean(); |
| 3299 | 3383 | |
| 3300 | - if ($err != '') |
|
| 3301 | - QRtools::log($outfile, $err); |
|
| 3384 | + if ($err != '') { |
|
| 3385 | + QRtools::log($outfile, $err); |
|
| 3386 | + } |
|
| 3302 | 3387 | |
| 3303 | 3388 | $maxSize = (int)(QR_PNG_MAXIMUM_SIZE / (count($tab)+2*$this->margin)); |
| 3304 | 3389 | |
@@ -957,6 +957,11 @@ discard block |
||
| 957 | 957 | return $anon_id; |
| 958 | 958 | } |
| 959 | 959 | |
| 960 | + /** |
|
| 961 | + * @param string $inner_user |
|
| 962 | + * @param string $password |
|
| 963 | + * @param string $clientcertdata |
|
| 964 | + */ |
|
| 960 | 965 | public function UDP_login($probeindex, $eaptype, $inner_user, $password, $outer_user = '', $opname_check = TRUE, $frag = TRUE, $clientcertdata = NULL) { |
| 961 | 966 | if (!isset(Config::$RADIUSTESTS['UDP-hosts'][$probeindex])) { |
| 962 | 967 | $this->UDP_reachability_executed = RETVAL_NOTCONFIGURED; |
@@ -1478,10 +1483,8 @@ discard block |
||
| 1478 | 1483 | /** |
| 1479 | 1484 | * This function executes openssl s_client command |
| 1480 | 1485 | * |
| 1481 | - * @param string $key points NAPTR_hostname_records |
|
| 1482 | - * @param string $bracketaddr IP address |
|
| 1483 | - * @param int $port |
|
| 1484 | - * @param string $arg arguments to add to the openssl command |
|
| 1486 | + * @param string $arg arguments to add to the openssl command |
|
| 1487 | + * @param string $host |
|
| 1485 | 1488 | * @return string result of oenssl s_client ... |
| 1486 | 1489 | */ |
| 1487 | 1490 | function openssl_s_client($host, $arg, &$testresults) { |
@@ -328,7 +328,6 @@ |
||
| 328 | 328 | * - RETVAL_NOT_CONFIGURED; needs Config::$RADIUSTESTS['TLS-discoverytag'] |
| 329 | 329 | * - RETVAL_INVALID (at least one format error) |
| 330 | 330 | * - RETVAL_OK (all fine) |
| 331 | - |
|
| 332 | 331 | * @return int one of two RETVALs above |
| 333 | 332 | */ |
| 334 | 333 | public function NAPTR_compliance() { |
@@ -274,10 +274,11 @@ discard block |
||
| 274 | 274 | ]; |
| 275 | 275 | $this->errorlist = []; |
| 276 | 276 | $this->initialise_errors(); |
| 277 | - if ($profile_id !== 0) |
|
| 278 | - $this->profile = new Profile($profile_id); |
|
| 279 | - else |
|
| 280 | - $this->profile = FALSE; |
|
| 277 | + if ($profile_id !== 0) { |
|
| 278 | + $this->profile = new Profile($profile_id); |
|
| 279 | + } else { |
|
| 280 | + $this->profile = FALSE; |
|
| 281 | + } |
|
| 281 | 282 | |
| 282 | 283 | CAT::set_locale($oldlocale); |
| 283 | 284 | } |
@@ -303,8 +304,9 @@ discard block |
||
| 303 | 304 | if ($NAPTRs !== FALSE && count($NAPTRs) > 0) { |
| 304 | 305 | $NAPTRs_consortium = []; |
| 305 | 306 | foreach ($NAPTRs as $naptr) { |
| 306 | - if ($naptr["services"] == Config::$RADIUSTESTS['TLS-discoverytag']) |
|
| 307 | - $NAPTRs_consortium[] = $naptr; |
|
| 307 | + if ($naptr["services"] == Config::$RADIUSTESTS['TLS-discoverytag']) { |
|
| 308 | + $NAPTRs_consortium[] = $naptr; |
|
| 309 | + } |
|
| 308 | 310 | } |
| 309 | 311 | |
| 310 | 312 | if (count($NAPTRs_consortium) > 0) { |
@@ -333,8 +335,9 @@ discard block |
||
| 333 | 335 | */ |
| 334 | 336 | public function NAPTR_compliance() { |
| 335 | 337 | // did we query DNS for the NAPTRs yet? If not, do so now. |
| 336 | - if ($this->NAPTR_executed === FALSE) |
|
| 337 | - $this->NAPTR(); |
|
| 338 | + if ($this->NAPTR_executed === FALSE) { |
|
| 339 | + $this->NAPTR(); |
|
| 340 | + } |
|
| 338 | 341 | // if the NAPTR checks aren't configured, tell the caller |
| 339 | 342 | if ($this->NAPTR_executed === RETVAL_NOTCONFIGURED) { |
| 340 | 343 | $this->NAPTR_compliance_executed = RETVAL_NOTCONFIGURED; |
@@ -351,11 +354,13 @@ discard block |
||
| 351 | 354 | if (Config::$CONSORTIUM['name'] == "eduroam") { // SW: APPROVED |
| 352 | 355 | foreach ($this->NAPTR_records as $edupointer) { |
| 353 | 356 | // must be "s" type for SRV |
| 354 | - if ($edupointer["flags"] != "s" && $edupointer["flags"] != "S") |
|
| 355 | - $format_errors[] = ["TYPE" => "NAPTR-FLAG", "TARGET" => $edupointer['flag']]; |
|
| 357 | + if ($edupointer["flags"] != "s" && $edupointer["flags"] != "S") { |
|
| 358 | + $format_errors[] = ["TYPE" => "NAPTR-FLAG", "TARGET" => $edupointer['flag']]; |
|
| 359 | + } |
|
| 356 | 360 | // no regex |
| 357 | - if ($edupointer["regex"] != "") |
|
| 358 | - $format_errors[] = ["TYPE" => "NAPTR-REGEX", "TARGET" => $edupointer['regex']]; |
|
| 361 | + if ($edupointer["regex"] != "") { |
|
| 362 | + $format_errors[] = ["TYPE" => "NAPTR-REGEX", "TARGET" => $edupointer['regex']]; |
|
| 363 | + } |
|
| 359 | 364 | } |
| 360 | 365 | } |
| 361 | 366 | if (count($format_errors) > 0) { |
@@ -665,8 +670,9 @@ discard block |
||
| 665 | 670 | function NAPTR_SRV() { |
| 666 | 671 | // see if preceding checks have been run, and run them if not |
| 667 | 672 | // compliance check will cascade NAPTR check on its own |
| 668 | - if ($this->NAPTR_compliance_executed === FALSE) |
|
| 669 | - $this->NAPTR_compliance(); |
|
| 673 | + if ($this->NAPTR_compliance_executed === FALSE) { |
|
| 674 | + $this->NAPTR_compliance(); |
|
| 675 | + } |
|
| 670 | 676 | // we only run the SRV checks if all records are compliant and more than one relevant NAPTR exists |
| 671 | 677 | if ($this->NAPTR_executed <= 0 || $this->NAPTR_compliance_executed == RETVAL_INVALID) { |
| 672 | 678 | $this->NAPTR_SRV_executed = RETVAL_SKIPPED; |
@@ -680,9 +686,10 @@ discard block |
||
| 680 | 686 | $temp_result = dns_get_record($edupointer["replacement"], DNS_SRV); |
| 681 | 687 | if ($temp_result === FALSE || count($temp_result) == 0) { |
| 682 | 688 | $SRV_errors[] = ["TYPE" => "SRV_NOT_RESOLVING", "TARGET" => $edupointer['replacement']]; |
| 683 | - } else |
|
| 684 | - foreach ($temp_result as $res) |
|
| 689 | + } else { |
|
| 690 | + foreach ($temp_result as $res) |
|
| 685 | 691 | $SRV_targets[] = ["hostname" => $res["target"], "port" => $res["port"]]; |
| 692 | + } |
|
| 686 | 693 | } |
| 687 | 694 | $this->NAPTR_SRV_records = $SRV_targets; |
| 688 | 695 | if (count($SRV_errors) > 0) { |
@@ -697,8 +704,9 @@ discard block |
||
| 697 | 704 | function NAPTR_hostnames() { |
| 698 | 705 | // make sure the previous tests have been run before we go on |
| 699 | 706 | // preceeding tests will cascade automatically if needed |
| 700 | - if ($this->NAPTR_SRV_executed === FALSE) |
|
| 701 | - $this->NAPTR_SRV(); |
|
| 707 | + if ($this->NAPTR_SRV_executed === FALSE) { |
|
| 708 | + $this->NAPTR_SRV(); |
|
| 709 | + } |
|
| 702 | 710 | // if previous are SKIPPED, skip this one, too |
| 703 | 711 | if ($this->NAPTR_SRV_executed == RETVAL_SKIPPED) { |
| 704 | 712 | $this->NAPTR_hostname_executed = RETVAL_SKIPPED; |
@@ -717,12 +725,14 @@ discard block |
||
| 717 | 725 | $host_resolution = array_merge($host_resolution_6, $host_resolution_4); |
| 718 | 726 | if ($host_resolution === FALSE || count($host_resolution) == 0) { |
| 719 | 727 | $resolution_errors[] = ["TYPE" => "HOST_NO_ADDRESS", "TARGET" => $server['hostname']]; |
| 720 | - } else |
|
| 721 | - foreach ($host_resolution as $address) |
|
| 728 | + } else { |
|
| 729 | + foreach ($host_resolution as $address) |
|
| 722 | 730 | if (isset($address["ip"])) |
| 723 | 731 | $ip_addresses[] = ["family" => "IPv4", "IP" => $address["ip"], "port" => $server["port"], "status" => ""]; |
| 724 | - else |
|
| 725 | - $ip_addresses[] = ["family" => "IPv6", "IP" => $address["ipv6"], "port" => $server["port"], "status" => ""]; |
|
| 732 | + } |
|
| 733 | + else { |
|
| 734 | + $ip_addresses[] = ["family" => "IPv6", "IP" => $address["ipv6"], "port" => $server["port"], "status" => ""]; |
|
| 735 | + } |
|
| 726 | 736 | } |
| 727 | 737 | |
| 728 | 738 | $this->NAPTR_hostname_records = $ip_addresses; |
@@ -761,38 +771,43 @@ discard block |
||
| 761 | 771 | // check for wildcards |
| 762 | 772 | |
| 763 | 773 | if (isset($servercert['full_details']['subject']['CN'])) { |
| 764 | - if (is_array($servercert['full_details']['subject']['CN'])) |
|
| 765 | - $CN = $servercert['full_details']['subject']['CN']; |
|
| 766 | - else |
|
| 767 | - $CN = [$servercert['full_details']['subject']['CN']]; |
|
| 768 | - } |
|
| 769 | - else { |
|
| 774 | + if (is_array($servercert['full_details']['subject']['CN'])) { |
|
| 775 | + $CN = $servercert['full_details']['subject']['CN']; |
|
| 776 | + } else { |
|
| 777 | + $CN = [$servercert['full_details']['subject']['CN']]; |
|
| 778 | + } |
|
| 779 | + } else { |
|
| 770 | 780 | $CN = [""]; |
| 771 | 781 | } |
| 772 | 782 | |
| 773 | - if (isset($servercert['full_details']['extensions']) && isset($servercert['full_details']['extensions']['subjectAltName'])) |
|
| 774 | - $sAN_list = explode(", ", $servercert['full_details']['extensions']['subjectAltName']); |
|
| 775 | - else |
|
| 776 | - $sAN_list = []; |
|
| 783 | + if (isset($servercert['full_details']['extensions']) && isset($servercert['full_details']['extensions']['subjectAltName'])) { |
|
| 784 | + $sAN_list = explode(", ", $servercert['full_details']['extensions']['subjectAltName']); |
|
| 785 | + } else { |
|
| 786 | + $sAN_list = []; |
|
| 787 | + } |
|
| 777 | 788 | |
| 778 | 789 | $sAN_DNS = []; |
| 779 | - foreach ($sAN_list as $san_name) |
|
| 780 | - if (preg_match("/^DNS:/", $san_name)) |
|
| 790 | + foreach ($sAN_list as $san_name) { |
|
| 791 | + if (preg_match("/^DNS:/", $san_name)) |
|
| 781 | 792 | $sAN_DNS[] = substr($san_name, 4); |
| 793 | + } |
|
| 782 | 794 | |
| 783 | 795 | $allnames = array_unique(array_merge($CN, $sAN_DNS)); |
| 784 | 796 | |
| 785 | - if (preg_match("/\*/", implode($allnames))) |
|
| 786 | - $returnarray[] = CERTPROB_WILDCARD_IN_NAME; |
|
| 797 | + if (preg_match("/\*/", implode($allnames))) { |
|
| 798 | + $returnarray[] = CERTPROB_WILDCARD_IN_NAME; |
|
| 799 | + } |
|
| 787 | 800 | |
| 788 | 801 | // is there more than one CN? None or one is okay, more is asking for trouble. |
| 789 | - if (count($CN) > 1) |
|
| 790 | - $returnarray[] = CERTPROB_MULTIPLE_CN; |
|
| 802 | + if (count($CN) > 1) { |
|
| 803 | + $returnarray[] = CERTPROB_MULTIPLE_CN; |
|
| 804 | + } |
|
| 791 | 805 | |
| 792 | 806 | // check for real hostname |
| 793 | 807 | foreach ($allnames as $onename) { |
| 794 | - if ($onename != "" && filter_var("foo@" . idn_to_ascii($onename), FILTER_VALIDATE_EMAIL) === FALSE) |
|
| 795 | - $returnarray[] = CERTPROB_NOT_A_HOSTNAME; |
|
| 808 | + if ($onename != "" && filter_var("foo@" . idn_to_ascii($onename), FILTER_VALIDATE_EMAIL) === FALSE) { |
|
| 809 | + $returnarray[] = CERTPROB_NOT_A_HOSTNAME; |
|
| 810 | + } |
|
| 796 | 811 | } |
| 797 | 812 | $servercert['incoming_server_names'] = $allnames; |
| 798 | 813 | $servercert['sAN_DNS'] = $sAN_DNS; |
@@ -816,16 +831,19 @@ discard block |
||
| 816 | 831 | if ($intermediate_ca['basicconstraints_set'] == 0) { |
| 817 | 832 | $returnarray[] = CERTPROB_NO_BASICCONSTRAINTS; |
| 818 | 833 | } |
| 819 | - if ($intermediate_ca['full_details']['public_key_length'] < 1024) |
|
| 820 | - $returnarray[] = CERTPROB_LOW_KEY_LENGTH; |
|
| 834 | + if ($intermediate_ca['full_details']['public_key_length'] < 1024) { |
|
| 835 | + $returnarray[] = CERTPROB_LOW_KEY_LENGTH; |
|
| 836 | + } |
|
| 821 | 837 | $from = $intermediate_ca['full_details']['validFrom_time_t']; |
| 822 | 838 | $now = time(); |
| 823 | 839 | $to = $intermediate_ca['full_details']['validTo_time_t']; |
| 824 | - if ($from > $now || $to < $now) |
|
| 825 | - $returnarray[] = CERTPROB_OUTSIDE_VALIDITY_PERIOD; |
|
| 840 | + if ($from > $now || $to < $now) { |
|
| 841 | + $returnarray[] = CERTPROB_OUTSIDE_VALIDITY_PERIOD; |
|
| 842 | + } |
|
| 826 | 843 | $add_cert_crl_result = $this->add_cert_crl($intermediate_ca); |
| 827 | - if ($add_cert_crl_result !== 0 && $server_cert) |
|
| 828 | - $returnarray[] = $add_cert_crl_result; |
|
| 844 | + if ($add_cert_crl_result !== 0 && $server_cert) { |
|
| 845 | + $returnarray[] = $add_cert_crl_result; |
|
| 846 | + } |
|
| 829 | 847 | |
| 830 | 848 | return $returnarray; |
| 831 | 849 | } |
@@ -869,8 +887,9 @@ discard block |
||
| 869 | 887 | $returnresult = CERTPROB_NO_CDP_HTTP; |
| 870 | 888 | } else { // first and second sub-match is the full URL... check it |
| 871 | 889 | $crlcontent = downloadFile($crl_url[1] . $crl_url[2]); |
| 872 | - if ($crlcontent === FALSE) |
|
| 873 | - $returnresult = CERTPROB_NO_CRL_AT_CDP_URL; |
|
| 890 | + if ($crlcontent === FALSE) { |
|
| 891 | + $returnresult = CERTPROB_NO_CRL_AT_CDP_URL; |
|
| 892 | + } |
|
| 874 | 893 | $begin_crl = strpos($crlcontent, "-----BEGIN X509 CRL-----"); |
| 875 | 894 | if ($begin_crl === FALSE) { |
| 876 | 895 | $pem = chunk_split(base64_encode($crlcontent), 64, "\n"); |
@@ -1074,11 +1093,16 @@ discard block |
||
| 1074 | 1093 | " -c ./udp_login_test.conf" . |
| 1075 | 1094 | " -M 22:44:66:CA:20:" . sprintf("%02d", $probeindex) . " " . |
| 1076 | 1095 | " -t " . Config::$RADIUSTESTS['UDP-hosts'][$probeindex]['timeout'] . " "; |
| 1077 | - if ($opname_check) |
|
| 1078 | - $cmdline .= '-N126:s:"1cat.eduroam.org" '; |
|
| 1079 | - if ($frag) |
|
| 1080 | - for ($i = 0; $i < 6; $i++) // 6 x 250 bytes means UDP fragmentation will occur - good! |
|
| 1096 | + if ($opname_check) { |
|
| 1097 | + $cmdline .= '-N126:s:"1cat.eduroam.org" '; |
|
| 1098 | + } |
|
| 1099 | + if ($frag) { |
|
| 1100 | + for ($i = 0; |
|
| 1101 | + } |
|
| 1102 | + $i < 6; $i++) { |
|
| 1103 | + // 6 x 250 bytes means UDP fragmentation will occur - good! |
|
| 1081 | 1104 | $cmdline .= '-N26:x:0000625A0BF961616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161 '; |
| 1105 | + } |
|
| 1082 | 1106 | |
| 1083 | 1107 | debug(4, "Shallow reachability check cmdline: $cmdline\n"); |
| 1084 | 1108 | debug(4, "Shallow reachability check config: $tmp_dir\n$log_config\n"); |
@@ -1087,8 +1111,9 @@ discard block |
||
| 1087 | 1111 | $time_stop = microtime(true); |
| 1088 | 1112 | debug(5, print_r($this->redact($password, $packetflow_orig), TRUE)); |
| 1089 | 1113 | $packetflow = $this->filter_packettype($packetflow_orig); |
| 1090 | - if ($packetflow[count($packetflow) - 1] == 11 && $this->check_mschap_691_r($packetflow_orig)) |
|
| 1091 | - $packetflow[count($packetflow) - 1] = 3; |
|
| 1114 | + if ($packetflow[count($packetflow) - 1] == 11 && $this->check_mschap_691_r($packetflow_orig)) { |
|
| 1115 | + $packetflow[count($packetflow) - 1] = 3; |
|
| 1116 | + } |
|
| 1092 | 1117 | debug(5, "Packetflow: " . print_r($packetflow, TRUE)); |
| 1093 | 1118 | $testresults['time_millisec'] = ($time_stop - $time_start) * 1000; |
| 1094 | 1119 | $packetcount = array_count_values($packetflow); |
@@ -1099,10 +1124,11 @@ discard block |
||
| 1099 | 1124 | $accepts = (isset($packetcount[2]) ? $packetcount[2] : 0); |
| 1100 | 1125 | $rejects = (isset($packetcount[3]) ? $packetcount[3] : 0); |
| 1101 | 1126 | $challenges = (isset($packetcount[11]) ? $packetcount[11] : 0); |
| 1102 | - if ($reqs - $accepts - $rejects - $challenges != 0 || $accepts > 1 || $rejects > 1) |
|
| 1103 | - $testresults['packetflow_sane'] = FALSE; |
|
| 1104 | - else |
|
| 1105 | - $testresults['packetflow_sane'] = TRUE; |
|
| 1127 | + if ($reqs - $accepts - $rejects - $challenges != 0 || $accepts > 1 || $rejects > 1) { |
|
| 1128 | + $testresults['packetflow_sane'] = FALSE; |
|
| 1129 | + } else { |
|
| 1130 | + $testresults['packetflow_sane'] = TRUE; |
|
| 1131 | + } |
|
| 1106 | 1132 | |
| 1107 | 1133 | // calculate the main return values that this test yielded |
| 1108 | 1134 | |
@@ -1127,8 +1153,9 @@ discard block |
||
| 1127 | 1153 | |
| 1128 | 1154 | if ($finalretval == RETVAL_CONVERSATION_REJECT) { |
| 1129 | 1155 | $ackedmethod = $this->check_conversation_eap_method_ack($packetflow_orig); |
| 1130 | - if (!$ackedmethod) |
|
| 1131 | - $testresults['cert_oddities'][] = CERTPROB_NO_COMMON_EAP_METHOD; |
|
| 1156 | + if (!$ackedmethod) { |
|
| 1157 | + $testresults['cert_oddities'][] = CERTPROB_NO_COMMON_EAP_METHOD; |
|
| 1158 | + } |
|
| 1132 | 1159 | }; |
| 1133 | 1160 | |
| 1134 | 1161 | |
@@ -1189,8 +1216,9 @@ discard block |
||
| 1189 | 1216 | |
| 1190 | 1217 | foreach ($eap_certarray as $cert_pem) { |
| 1191 | 1218 | $cert = $x509->processCertificate($cert_pem); |
| 1192 | - if ($cert == FALSE) |
|
| 1193 | - continue; |
|
| 1219 | + if ($cert == FALSE) { |
|
| 1220 | + continue; |
|
| 1221 | + } |
|
| 1194 | 1222 | // consider the certificate a server cert |
| 1195 | 1223 | // a) if it is not a CA and is not a self-signed root |
| 1196 | 1224 | // b) if it is a CA, and self-signed, and it is the only cert in |
@@ -1236,12 +1264,15 @@ discard block |
||
| 1236 | 1264 | $testresults['certdata'][] = $cert['full_details']; |
| 1237 | 1265 | } |
| 1238 | 1266 | fclose($server_file); |
| 1239 | - if ($number_root > 0 && !$totally_selfsigned) |
|
| 1240 | - $testresults['cert_oddities'][] = CERTPROB_ROOT_INCLUDED; |
|
| 1241 | - if ($number_server > 1) |
|
| 1242 | - $testresults['cert_oddities'][] = CERTPROB_TOO_MANY_SERVER_CERTS; |
|
| 1243 | - if ($number_server == 0) |
|
| 1244 | - $testresults['cert_oddities'][] = CERTPROB_NO_SERVER_CERT; |
|
| 1267 | + if ($number_root > 0 && !$totally_selfsigned) { |
|
| 1268 | + $testresults['cert_oddities'][] = CERTPROB_ROOT_INCLUDED; |
|
| 1269 | + } |
|
| 1270 | + if ($number_server > 1) { |
|
| 1271 | + $testresults['cert_oddities'][] = CERTPROB_TOO_MANY_SERVER_CERTS; |
|
| 1272 | + } |
|
| 1273 | + if ($number_server == 0) { |
|
| 1274 | + $testresults['cert_oddities'][] = CERTPROB_NO_SERVER_CERT; |
|
| 1275 | + } |
|
| 1245 | 1276 | // check server cert properties |
| 1246 | 1277 | if ($number_server > 0) { |
| 1247 | 1278 | $testresults['cert_oddities'] = array_merge($testresults['cert_oddities'], $this->property_check_servercert($servercert)); |
@@ -1287,8 +1318,9 @@ discard block |
||
| 1287 | 1318 | } |
| 1288 | 1319 | } |
| 1289 | 1320 | } |
| 1290 | - if ($number_server > 0) |
|
| 1291 | - debug(4, "This is the server certificate, with CRL content if applicable: " . print_r($servercert, true)); |
|
| 1321 | + if ($number_server > 0) { |
|
| 1322 | + debug(4, "This is the server certificate, with CRL content if applicable: " . print_r($servercert, true)); |
|
| 1323 | + } |
|
| 1292 | 1324 | $checkstring = ""; |
| 1293 | 1325 | if (isset($servercert['CRL']) && isset($servercert['CRL'][0])) { |
| 1294 | 1326 | debug(4, "got a server CRL; adding them to the chain checks. (Remember: checking end-entity cert only, not the whole chain"); |
@@ -1365,8 +1397,9 @@ discard block |
||
| 1365 | 1397 | // WARN if the configured name is only in either CN or sAN:DNS |
| 1366 | 1398 | $confnames = $my_profile->getAttributes("eap:server_name"); |
| 1367 | 1399 | $expected_names = []; |
| 1368 | - foreach ($confnames as $tuple) |
|
| 1369 | - $expected_names[] = $tuple['value']; |
|
| 1400 | + foreach ($confnames as $tuple) { |
|
| 1401 | + $expected_names[] = $tuple['value']; |
|
| 1402 | + } |
|
| 1370 | 1403 | |
| 1371 | 1404 | // Strategy for checks: we are TOTALLY happy if any one of the |
| 1372 | 1405 | // configured names shows up in both the CN and a sAN |
@@ -1437,9 +1470,10 @@ discard block |
||
| 1437 | 1470 | function property_check_policy($cert) { |
| 1438 | 1471 | $oids = []; |
| 1439 | 1472 | if ($cert['extensions']['certificatePolicies']) { |
| 1440 | - foreach (Config::$RADIUSTESTS['TLS-acceptableOIDs'] as $key => $oid) |
|
| 1441 | - if (preg_match("/Policy: $oid/", $cert['extensions']['certificatePolicies'])) |
|
| 1473 | + foreach (Config::$RADIUSTESTS['TLS-acceptableOIDs'] as $key => $oid) { |
|
| 1474 | + if (preg_match("/Policy: $oid/", $cert['extensions']['certificatePolicies'])) |
|
| 1442 | 1475 | $oids[$key] = $oid; |
| 1476 | + } |
|
| 1443 | 1477 | } |
| 1444 | 1478 | return $oids; |
| 1445 | 1479 | } |
@@ -1452,12 +1486,14 @@ discard block |
||
| 1452 | 1486 | */ |
| 1453 | 1487 | function property_certificate_get_issuer($cert) { |
| 1454 | 1488 | $issuer = ''; |
| 1455 | - foreach ($cert['issuer'] as $key => $val) |
|
| 1456 | - if (is_array($val)) |
|
| 1489 | + foreach ($cert['issuer'] as $key => $val) { |
|
| 1490 | + if (is_array($val)) |
|
| 1457 | 1491 | foreach ($val as $v) |
| 1458 | 1492 | $issuer .= "/$key=$v"; |
| 1459 | - else |
|
| 1460 | - $issuer .= "/$key=$val"; |
|
| 1493 | + } |
|
| 1494 | + else { |
|
| 1495 | + $issuer .= "/$key=$val"; |
|
| 1496 | + } |
|
| 1461 | 1497 | return $issuer; |
| 1462 | 1498 | } |
| 1463 | 1499 | |
@@ -1532,8 +1568,9 @@ discard block |
||
| 1532 | 1568 | } |
| 1533 | 1569 | $oids = $this->property_check_policy($data); |
| 1534 | 1570 | if (!empty($oids)) { |
| 1535 | - foreach ($oids as $k => $o) |
|
| 1536 | - $testresults[$host]['certdata']['extensions']['policyoid'][] = " $o ($k)"; |
|
| 1571 | + foreach ($oids as $k => $o) { |
|
| 1572 | + $testresults[$host]['certdata']['extensions']['policyoid'][] = " $o ($k)"; |
|
| 1573 | + } |
|
| 1537 | 1574 | } |
| 1538 | 1575 | if (($crl = $this->property_certificate_get_field($data, 'crlDistributionPoints'))) { |
| 1539 | 1576 | $testresults[$host]['certdata']['extensions']['crlDistributionPoint'] = $crl; |
@@ -1547,23 +1584,24 @@ discard block |
||
| 1547 | 1584 | $ret = $testresults[$host]['ca'][$type]['certificate'][$k]['returncode']; |
| 1548 | 1585 | $output = implode($opensslbabble); |
| 1549 | 1586 | $unknownca = 0; |
| 1550 | - if ($ret == 0) |
|
| 1551 | - $testresults[$host]['ca'][$type]['certificate'][$k]['connected'] = 1; |
|
| 1552 | - else { |
|
| 1587 | + if ($ret == 0) { |
|
| 1588 | + $testresults[$host]['ca'][$type]['certificate'][$k]['connected'] = 1; |
|
| 1589 | + } else { |
|
| 1553 | 1590 | $testresults[$host]['ca'][$type]['certificate'][$k]['connected'] = 0; |
| 1554 | 1591 | if (preg_match('/connect: Connection refused/', implode($opensslbabble))) { |
| 1555 | 1592 | $testresults[$host]['ca'][$type]['certificate'][$k]['returncode'] = RETVAL_CONNECTION_REFUSED; |
| 1556 | - } elseif (preg_match('/sslv3 alert certificate expired/', $output)) |
|
| 1557 | - $res_comment = _("certificate expired"); |
|
| 1558 | - elseif (preg_match('/sslv3 alert certificate revoked/', $output)) |
|
| 1559 | - $res_comment = _("certificate was revoked"); |
|
| 1560 | - elseif (preg_match('/SSL alert number 46/', $output)) |
|
| 1561 | - $res_comment = _("bad policy"); |
|
| 1562 | - elseif (preg_match('/tlsv1 alert unknown ca/', $output)) { |
|
| 1593 | + } elseif (preg_match('/sslv3 alert certificate expired/', $output)) { |
|
| 1594 | + $res_comment = _("certificate expired"); |
|
| 1595 | + } elseif (preg_match('/sslv3 alert certificate revoked/', $output)) { |
|
| 1596 | + $res_comment = _("certificate was revoked"); |
|
| 1597 | + } elseif (preg_match('/SSL alert number 46/', $output)) { |
|
| 1598 | + $res_comment = _("bad policy"); |
|
| 1599 | + } elseif (preg_match('/tlsv1 alert unknown ca/', $output)) { |
|
| 1563 | 1600 | $res_comment = _("unknown authority"); |
| 1564 | 1601 | $testresults[$host]['ca'][$type]['certificate'][$k]['reason'] = CERTPROB_UNKNOWN_CA; |
| 1565 | - } else |
|
| 1566 | - $res_comment = _("unknown authority or no certificate policy or another problem"); |
|
| 1602 | + } else { |
|
| 1603 | + $res_comment = _("unknown authority or no certificate policy or another problem"); |
|
| 1604 | + } |
|
| 1567 | 1605 | $testresults[$host]['ca'][$type]['certificate'][$k]['resultcomment'] = $res_comment; |
| 1568 | 1606 | } |
| 1569 | 1607 | break; |
@@ -1583,8 +1621,9 @@ discard block |
||
| 1583 | 1621 | $res = RETVAL_OK; |
| 1584 | 1622 | /* if (preg_match("/\[/", $host)) |
| 1585 | 1623 | return RETVAL_INVALID; */ |
| 1586 | - if (!isset($this->TLS_CA_checks_result[$host])) |
|
| 1587 | - $this->TLS_CA_checks_result[$host] = []; |
|
| 1624 | + if (!isset($this->TLS_CA_checks_result[$host])) { |
|
| 1625 | + $this->TLS_CA_checks_result[$host] = []; |
|
| 1626 | + } |
|
| 1588 | 1627 | $opensslbabble = $this->openssl_s_client($host, '', $this->TLS_CA_checks_result[$host]); |
| 1589 | 1628 | fputs($f, serialize($this->TLS_CA_checks_result) . "\n"); |
| 1590 | 1629 | $res = $this->openssl_result($host, 'capath', $opensslbabble, $this->TLS_CA_checks_result); |
@@ -1600,8 +1639,9 @@ discard block |
||
| 1600 | 1639 | public function TLS_clients_side_check($host) { |
| 1601 | 1640 | $res = RETVAL_OK; |
| 1602 | 1641 | if (is_array(Config::$RADIUSTESTS['TLS-clientcerts']) && count(Config::$RADIUSTESTS['TLS-clientcerts']) > 0) { |
| 1603 | - if (preg_match("/\[/", $host)) |
|
| 1604 | - return RETVAL_INVALID; |
|
| 1642 | + if (preg_match("/\[/", $host)) { |
|
| 1643 | + return RETVAL_INVALID; |
|
| 1644 | + } |
|
| 1605 | 1645 | foreach (Config::$RADIUSTESTS['TLS-clientcerts'] as $type => $tlsclient) { |
| 1606 | 1646 | $this->TLS_clients_checks_result[$host]['ca'][$type]['clientcertinfo']['from'] = $type; |
| 1607 | 1647 | $this->TLS_clients_checks_result[$host]['ca'][$type]['clientcertinfo']['status'] = $tlsclient['status']; |
@@ -1612,8 +1652,9 @@ discard block |
||
| 1612 | 1652 | $this->TLS_clients_checks_result[$host]['ca'][$type]['certificate'][$k]['message'] = $this->TLS_certkeys[$cert['status']]; |
| 1613 | 1653 | $this->TLS_clients_checks_result[$host]['ca'][$type]['certificate'][$k]['expected'] = $cert['expected']; |
| 1614 | 1654 | $add = ' -cert ' . CAT::$root . '/config/cli-certs/' . $cert['public'] . ' -key ' . CAT::$root . '/config/cli-certs/' . $cert['private']; |
| 1615 | - if (!isset($this->TLS_clients_checks_result[$host]['ca'][$type]['certificate'][$k])) |
|
| 1616 | - $this->TLS_clients_checks_result[$host]['ca'][$type]['certificate'][$k] = []; |
|
| 1655 | + if (!isset($this->TLS_clients_checks_result[$host]['ca'][$type]['certificate'][$k])) { |
|
| 1656 | + $this->TLS_clients_checks_result[$host]['ca'][$type]['certificate'][$k] = []; |
|
| 1657 | + } |
|
| 1617 | 1658 | $opensslbabble = $this->openssl_s_client($host, $add, $this->TLS_clients_checks_result[$host]['ca'][$type]['certificate'][$k]); |
| 1618 | 1659 | $res = $this->openssl_result($host, 'clients', $opensslbabble, $this->TLS_clients_checks_result, $type, $k); |
| 1619 | 1660 | if ($cert['expected'] == 'PASS') { |
@@ -1625,8 +1666,9 @@ discard block |
||
| 1625 | 1666 | } |
| 1626 | 1667 | } |
| 1627 | 1668 | } else { |
| 1628 | - if ($this->TLS_clients_checks_result[$host]['ca'][$type]['certificate'][$k]['connected']) |
|
| 1629 | - $this->TLS_clients_checks_result[$host]['ca'][$type]['certificate'][$k]['returncode'] = CERTPROB_WRONGLY_ACCEPTED; |
|
| 1669 | + if ($this->TLS_clients_checks_result[$host]['ca'][$type]['certificate'][$k]['connected']) { |
|
| 1670 | + $this->TLS_clients_checks_result[$host]['ca'][$type]['certificate'][$k]['returncode'] = CERTPROB_WRONGLY_ACCEPTED; |
|
| 1671 | + } |
|
| 1630 | 1672 | |
| 1631 | 1673 | if (($this->TLS_clients_checks_result[$host]['ca'][$type]['certificate'][$k]['reason'] == CERTPROB_UNKNOWN_CA) && ($tlsclient['status'] == 'ACCREDITED') && ($cert['status'] == 'CORRECT')) { |
| 1632 | 1674 | $this->TLS_clients_checks_result[$host]['ca'][$type]['certificate'][$k]['finalerror'] = 1; |
@@ -138,6 +138,9 @@ |
||
| 138 | 138 | $this->test_result['global'] = max($this->test_result['global'],$level); |
| 139 | 139 | } |
| 140 | 140 | |
| 141 | + /** |
|
| 142 | + * @param string $s |
|
| 143 | + */ |
|
| 141 | 144 | private function get_exec_path($s) { |
| 142 | 145 | $the_path = ""; |
| 143 | 146 | $exec_is = "UNDEFINED"; |
@@ -75,12 +75,12 @@ discard block |
||
| 75 | 75 | * @param string $test the test name |
| 76 | 76 | */ |
| 77 | 77 | public function test($test) { |
| 78 | - $this->out[$test] =[]; |
|
| 78 | + $this->out[$test] = []; |
|
| 79 | 79 | $this->name = $test; |
| 80 | - $m_name = $test.'_test'; |
|
| 80 | + $m_name = $test . '_test'; |
|
| 81 | 81 | $this->test_result[$test] = 0; |
| 82 | - if(! method_exists($this,$m_name)) { |
|
| 83 | - $this->test_return($test,L_ERROR,"Configuration error, no test configured for <strong>$test</strong>."); |
|
| 82 | + if (!method_exists($this, $m_name)) { |
|
| 83 | + $this->test_return($test, L_ERROR, "Configuration error, no test configured for <strong>$test</strong>."); |
|
| 84 | 84 | return; |
| 85 | 85 | } |
| 86 | 86 | $this->$m_name(); |
@@ -97,10 +97,10 @@ discard block |
||
| 97 | 97 | */ |
| 98 | 98 | public function run_tests($Tests) { |
| 99 | 99 | foreach ($Tests as $t) { |
| 100 | - if(preg_match('/(.+)=>(.+)/',$t,$m)) { |
|
| 100 | + if (preg_match('/(.+)=>(.+)/', $t, $m)) { |
|
| 101 | 101 | $tst = $m[1]; |
| 102 | - $subtst=$m[2]; |
|
| 103 | - if($this->test_result[$tst] < L_ERROR) |
|
| 102 | + $subtst = $m[2]; |
|
| 103 | + if ($this->test_result[$tst] < L_ERROR) |
|
| 104 | 104 | $this->test($subtst); |
| 105 | 105 | } |
| 106 | 106 | else |
@@ -111,8 +111,8 @@ discard block |
||
| 111 | 111 | public function get_test_names() { |
| 112 | 112 | $T = get_class_methods($this); |
| 113 | 113 | $out = []; |
| 114 | - foreach($T as $t) { |
|
| 115 | - if(preg_match('/^(.*)_test$/',$t,$m)) { |
|
| 114 | + foreach ($T as $t) { |
|
| 115 | + if (preg_match('/^(.*)_test$/', $t, $m)) { |
|
| 116 | 116 | $out[] = $m[1]; |
| 117 | 117 | } |
| 118 | 118 | } |
@@ -132,17 +132,17 @@ discard block |
||
| 132 | 132 | */ |
| 133 | 133 | public $test_result; |
| 134 | 134 | |
| 135 | - private function test_return($level,$message) { |
|
| 135 | + private function test_return($level, $message) { |
|
| 136 | 136 | $this->out[$this->name][] = ['level'=>$level, 'message'=>$message]; |
| 137 | - $this->test_result[$this->name] = max($this->test_result[$this->name],$level); |
|
| 138 | - $this->test_result['global'] = max($this->test_result['global'],$level); |
|
| 137 | + $this->test_result[$this->name] = max($this->test_result[$this->name], $level); |
|
| 138 | + $this->test_result['global'] = max($this->test_result['global'], $level); |
|
| 139 | 139 | } |
| 140 | 140 | |
| 141 | 141 | private function get_exec_path($s) { |
| 142 | 142 | $the_path = ""; |
| 143 | 143 | $exec_is = "UNDEFINED"; |
| 144 | 144 | if (!empty(Config::$PATHS[$s])) { |
| 145 | - preg_match('/([^ ]+) ?/',Config::$PATHS[$s],$m); |
|
| 145 | + preg_match('/([^ ]+) ?/', Config::$PATHS[$s], $m); |
|
| 146 | 146 | $exe = $m[1]; |
| 147 | 147 | $the_path = exec("which " . Config::$PATHS[$s]); |
| 148 | 148 | if ($the_path == $exe) |
@@ -150,7 +150,7 @@ discard block |
||
| 150 | 150 | else |
| 151 | 151 | $exec_is = "IMPLICIT"; |
| 152 | 152 | } |
| 153 | - return(['exec'=>$the_path,'exec_is'=>$exec_is]); |
|
| 153 | + return(['exec'=>$the_path, 'exec_is'=>$exec_is]); |
|
| 154 | 154 | } |
| 155 | 155 | |
| 156 | 156 | /** |
@@ -158,9 +158,9 @@ discard block |
||
| 158 | 158 | */ |
| 159 | 159 | private function php_test() { |
| 160 | 160 | if (version_compare(phpversion(), $this->php_needversion, '>=')) |
| 161 | - $this->test_return(L_OK,"<strong>PHP</strong> is sufficiently recent. You are running " . phpversion() . "."); |
|
| 161 | + $this->test_return(L_OK, "<strong>PHP</strong> is sufficiently recent. You are running " . phpversion() . "."); |
|
| 162 | 162 | else |
| 163 | - $this->test_return(L_ERROR,"<strong>PHP</strong> is too old. We need at least $this->php_needversion, but you only have ".phpversion(). "."); |
|
| 163 | + $this->test_return(L_ERROR, "<strong>PHP</strong> is too old. We need at least $this->php_needversion, but you only have " . phpversion() . "."); |
|
| 164 | 164 | } |
| 165 | 165 | |
| 166 | 166 | /** |
@@ -168,9 +168,9 @@ discard block |
||
| 168 | 168 | */ |
| 169 | 169 | private function ssp_test() { |
| 170 | 170 | if (!is_file(CONFIG::$AUTHENTICATION['ssp-path-to-autoloader'])) |
| 171 | - $this->test_return(L_ERROR,"<strong>simpleSAMLphp</strong> not found!"); |
|
| 171 | + $this->test_return(L_ERROR, "<strong>simpleSAMLphp</strong> not found!"); |
|
| 172 | 172 | else |
| 173 | - $this->test_return(L_OK,"<strong>simpleSAMLphp</strong> autoloader found."); |
|
| 173 | + $this->test_return(L_OK, "<strong>simpleSAMLphp</strong> autoloader found."); |
|
| 174 | 174 | } |
| 175 | 175 | |
| 176 | 176 | /** |
@@ -178,7 +178,7 @@ discard block |
||
| 178 | 178 | */ |
| 179 | 179 | private function security_test() { |
| 180 | 180 | if (in_array("I do not care about security!", Config::$SUPERADMINS)) |
| 181 | - $this->test_return(L_WARN,"You do not care about security. This page should be made accessible to the CAT admin only! See config.php 'Superadmins'!"); |
|
| 181 | + $this->test_return(L_WARN, "You do not care about security. This page should be made accessible to the CAT admin only! See config.php 'Superadmins'!"); |
|
| 182 | 182 | } |
| 183 | 183 | |
| 184 | 184 | /** |
@@ -186,9 +186,9 @@ discard block |
||
| 186 | 186 | */ |
| 187 | 187 | private function zip_test() { |
| 188 | 188 | if (exec("which zip") != "") |
| 189 | - $this->test_return(L_OK,"<strong>zip</strong> binary found."); |
|
| 189 | + $this->test_return(L_OK, "<strong>zip</strong> binary found."); |
|
| 190 | 190 | else |
| 191 | - $this->test_return(L_ERROR,"<strong>zip</strong> not found in your \$PATH!"); |
|
| 191 | + $this->test_return(L_ERROR, "<strong>zip</strong> not found in your \$PATH!"); |
|
| 192 | 192 | } |
| 193 | 193 | |
| 194 | 194 | /** |
@@ -196,15 +196,15 @@ discard block |
||
| 196 | 196 | */ |
| 197 | 197 | private function eapol_test_test() { |
| 198 | 198 | exec(Config::$PATHS['eapol_test'], $out, $retval); |
| 199 | - if($retval == 255 ) { |
|
| 200 | - $o = preg_grep('/-o<server cert/',$out); |
|
| 201 | - if(count($o) > 0) |
|
| 202 | - $this->test_return(L_OK,"<strong>eapol_test</strong> script found."); |
|
| 199 | + if ($retval == 255) { |
|
| 200 | + $o = preg_grep('/-o<server cert/', $out); |
|
| 201 | + if (count($o) > 0) |
|
| 202 | + $this->test_return(L_OK, "<strong>eapol_test</strong> script found."); |
|
| 203 | 203 | else |
| 204 | - $this->test_return(L_ERROR,"<strong>eapol_test</strong> found, but is too old!"); |
|
| 204 | + $this->test_return(L_ERROR, "<strong>eapol_test</strong> found, but is too old!"); |
|
| 205 | 205 | } |
| 206 | 206 | else |
| 207 | - $this->test_return(L_ERROR,"<strong>eapol_test</strong> not found!"); |
|
| 207 | + $this->test_return(L_ERROR, "<strong>eapol_test</strong> not found!"); |
|
| 208 | 208 | } |
| 209 | 209 | |
| 210 | 210 | /** |
@@ -212,9 +212,9 @@ discard block |
||
| 212 | 212 | */ |
| 213 | 213 | private function logdir_test() { |
| 214 | 214 | if (fopen(Config::$PATHS['logdir'] . "/debug.log", "a") == FALSE) |
| 215 | - $this->test_return(L_WARN,"Log files in <strong>" . Config::$PATHS['logdir'] . "</strong> are not writable!"); |
|
| 215 | + $this->test_return(L_WARN, "Log files in <strong>" . Config::$PATHS['logdir'] . "</strong> are not writable!"); |
|
| 216 | 216 | else |
| 217 | - $this->test_return(L_OK,"Log directory is writable."); |
|
| 217 | + $this->test_return(L_OK, "Log directory is writable."); |
|
| 218 | 218 | } |
| 219 | 219 | |
| 220 | 220 | /** |
@@ -222,34 +222,34 @@ discard block |
||
| 222 | 222 | */ |
| 223 | 223 | private function phpModules_test() { |
| 224 | 224 | if (function_exists('idn_to_ascii')) |
| 225 | - $this->test_return(L_OK,"PHP can handle internationalisation."); |
|
| 225 | + $this->test_return(L_OK, "PHP can handle internationalisation."); |
|
| 226 | 226 | else |
| 227 | - $this->test_return(L_ERROR,"PHP can <strongNOT</strong> handle internationalisation (idn_to_ascii() from php5-intl)."); |
|
| 227 | + $this->test_return(L_ERROR, "PHP can <strongNOT</strong> handle internationalisation (idn_to_ascii() from php5-intl)."); |
|
| 228 | 228 | |
| 229 | 229 | if (function_exists('gettext')) |
| 230 | - $this->test_return(L_OK,"PHP extension <strong>GNU Gettext</strong> is installed."); |
|
| 230 | + $this->test_return(L_OK, "PHP extension <strong>GNU Gettext</strong> is installed."); |
|
| 231 | 231 | else |
| 232 | - $this->test_return(L_ERROR,"PHP extension <strong>GNU Gettext</strong> not found!"); |
|
| 232 | + $this->test_return(L_ERROR, "PHP extension <strong>GNU Gettext</strong> not found!"); |
|
| 233 | 233 | |
| 234 | 234 | if (function_exists('openssl_sign')) |
| 235 | - $this->test_return(L_OK,"PHP extension <strong>OpenSSL</strong> is installed."); |
|
| 235 | + $this->test_return(L_OK, "PHP extension <strong>OpenSSL</strong> is installed."); |
|
| 236 | 236 | else |
| 237 | - $this->test_return(L_ERROR,"PHP extension <strong>OpenSSL</strong> not found!"); |
|
| 237 | + $this->test_return(L_ERROR, "PHP extension <strong>OpenSSL</strong> not found!"); |
|
| 238 | 238 | |
| 239 | 239 | if (class_exists('Imagick')) |
| 240 | - $this->test_return(L_OK,"PHP extension <strong>Imagick</strong> is installed."); |
|
| 240 | + $this->test_return(L_OK, "PHP extension <strong>Imagick</strong> is installed."); |
|
| 241 | 241 | else |
| 242 | - $this->test_return(L_ERROR,"PHP extension <strong>Imagick</strong> not found! Get it from your distribution or <a href='http://pecl.php.net/package/imagick'>here</a>."); |
|
| 242 | + $this->test_return(L_ERROR, "PHP extension <strong>Imagick</strong> not found! Get it from your distribution or <a href='http://pecl.php.net/package/imagick'>here</a>."); |
|
| 243 | 243 | |
| 244 | 244 | if (function_exists('ImageCreate')) |
| 245 | - $this->test_return(L_OK,"PHP extension <strong>GD</strong> is installed."); |
|
| 245 | + $this->test_return(L_OK, "PHP extension <strong>GD</strong> is installed."); |
|
| 246 | 246 | else |
| 247 | - $this->test_return(L_ERROR,"PHP extension <strong>GD</strong> not found!</a>."); |
|
| 247 | + $this->test_return(L_ERROR, "PHP extension <strong>GD</strong> not found!</a>."); |
|
| 248 | 248 | |
| 249 | 249 | if (function_exists('mysqli_connect')) |
| 250 | - $this->test_return(L_OK,"PHP extension <strong>MySQL</strong> is installed."); |
|
| 250 | + $this->test_return(L_OK, "PHP extension <strong>MySQL</strong> is installed."); |
|
| 251 | 251 | else |
| 252 | - $this->test_return(L_ERROR,"PHP extension <strong>MySQL</strong> not found!"); |
|
| 252 | + $this->test_return(L_ERROR, "PHP extension <strong>MySQL</strong> not found!"); |
|
| 253 | 253 | /* |
| 254 | 254 | if (function_exists('geoip_record_by_name')) { |
| 255 | 255 | $host = '158.75.1.10'; |
@@ -275,31 +275,31 @@ discard block |
||
| 275 | 275 | $host_6 = '2001:610:188:444::50'; |
| 276 | 276 | switch (Config::$GEOIP['version']) { |
| 277 | 277 | case 0: |
| 278 | - $this->test_return(L_REMARK,"As set in the config, no geolocation service will be used"); |
|
| 278 | + $this->test_return(L_REMARK, "As set in the config, no geolocation service will be used"); |
|
| 279 | 279 | break; |
| 280 | 280 | case 1: |
| 281 | 281 | if (!function_exists('geoip_record_by_name')) { |
| 282 | - $this->test_return(L_ERROR,"PHP extension <strong>GeoIP</strong> (legacy) not found! Get it from your distribution or <a href='http://pecl.php.net/package/geoip'>here</a> or better install GeoIP2 from <a href='https://github.com/maxmind/GeoIP2-php'>here</a>."); |
|
| 282 | + $this->test_return(L_ERROR, "PHP extension <strong>GeoIP</strong> (legacy) not found! Get it from your distribution or <a href='http://pecl.php.net/package/geoip'>here</a> or better install GeoIP2 from <a href='https://github.com/maxmind/GeoIP2-php'>here</a>."); |
|
| 283 | 283 | return; |
| 284 | 284 | } |
| 285 | 285 | $record = geoip_record_by_name($host_4); |
| 286 | - if(! $record) { |
|
| 287 | - $this->test_return(L_ERROR,"PHP extension <strong>GeoIP</strong> (legacy) found but not working properly, perhaps you need to download the databases. See utils/GeoIP-update.sh in the CAT distribution and use it tu update the GeoIP database regularly."); |
|
| 286 | + if (!$record) { |
|
| 287 | + $this->test_return(L_ERROR, "PHP extension <strong>GeoIP</strong> (legacy) found but not working properly, perhaps you need to download the databases. See utils/GeoIP-update.sh in the CAT distribution and use it tu update the GeoIP database regularly."); |
|
| 288 | 288 | return; |
| 289 | 289 | } |
| 290 | - if($record['city'] != 'Utrecht') { |
|
| 291 | - $this->test_return(L_ERROR,"PHP extension <strong>GeoIP</strong> (legacy) found but not working properly, perhaps you need to download the databases. See utils/GeoIP-update.sh in the CAT distribution and use it tu update the GeoIP database regularly."); |
|
| 290 | + if ($record['city'] != 'Utrecht') { |
|
| 291 | + $this->test_return(L_ERROR, "PHP extension <strong>GeoIP</strong> (legacy) found but not working properly, perhaps you need to download the databases. See utils/GeoIP-update.sh in the CAT distribution and use it tu update the GeoIP database regularly."); |
|
| 292 | 292 | return; |
| 293 | 293 | } |
| 294 | - $this->test_return(L_REMARK,"PHP extension <strong>GeoIP</strong> (legacy) is installed and working. See utils/GeoIP-update.sh in the CAT distribution and use it tu update the GeoIP database regularly. We stronly advise to replace the legacy GeoIP with GeoIP2 from <a href='https://github.com/maxmind/GeoIP2-php'>here</a>."); |
|
| 294 | + $this->test_return(L_REMARK, "PHP extension <strong>GeoIP</strong> (legacy) is installed and working. See utils/GeoIP-update.sh in the CAT distribution and use it tu update the GeoIP database regularly. We stronly advise to replace the legacy GeoIP with GeoIP2 from <a href='https://github.com/maxmind/GeoIP2-php'>here</a>."); |
|
| 295 | 295 | break; |
| 296 | 296 | case 2: |
| 297 | - if(! is_file(Config::$GEOIP['geoip2-path-to-autoloader'])) { |
|
| 298 | - $this->test_return(L_ERROR,"PHP extension <strong>GeoIP2</strong> not found! Get it from <a href='https://github.com/maxmind/GeoIP2-php'>here</a>."); |
|
| 297 | + if (!is_file(Config::$GEOIP['geoip2-path-to-autoloader'])) { |
|
| 298 | + $this->test_return(L_ERROR, "PHP extension <strong>GeoIP2</strong> not found! Get it from <a href='https://github.com/maxmind/GeoIP2-php'>here</a>."); |
|
| 299 | 299 | return; |
| 300 | 300 | } |
| 301 | - if(! is_file(Config::$GEOIP['geoip2-path-to-db'])) { |
|
| 302 | - $this->test_return(L_ERROR,"<strong>GeoIP2 database</strong> not found! See utils/GeoIP-update.sh in the CAT distribution and use it tu update the GeoIP database regularly."); |
|
| 301 | + if (!is_file(Config::$GEOIP['geoip2-path-to-db'])) { |
|
| 302 | + $this->test_return(L_ERROR, "<strong>GeoIP2 database</strong> not found! See utils/GeoIP-update.sh in the CAT distribution and use it tu update the GeoIP database regularly."); |
|
| 303 | 303 | return; |
| 304 | 304 | } |
| 305 | 305 | require_once Config::$GEOIP['geoip2-path-to-autoloader']; |
@@ -307,27 +307,27 @@ discard block |
||
| 307 | 307 | try { |
| 308 | 308 | $record = $reader->city($host_4); |
| 309 | 309 | } catch (Exception $e) { |
| 310 | - $this->test_return(L_ERROR,"PHP extension <strong>GeoIP2</strong> found but not working properly, perhaps you need to download the databases. See utils/GeoIP-update.sh in the CAT distribution and use it tu update the GeoIP database regularly."); |
|
| 310 | + $this->test_return(L_ERROR, "PHP extension <strong>GeoIP2</strong> found but not working properly, perhaps you need to download the databases. See utils/GeoIP-update.sh in the CAT distribution and use it tu update the GeoIP database regularly."); |
|
| 311 | 311 | return; |
| 312 | 312 | } |
| 313 | - if( $record->city->name != 'Utrecht') { |
|
| 314 | - $this->test_return(L_ERROR,"PHP extension <strong>GeoIP2</strong> found but not working properly, perhaps you need to download the databases. See utils/GeoIP-update.sh in the CAT distribution and use it tu update the GeoIP database regularly."); |
|
| 313 | + if ($record->city->name != 'Utrecht') { |
|
| 314 | + $this->test_return(L_ERROR, "PHP extension <strong>GeoIP2</strong> found but not working properly, perhaps you need to download the databases. See utils/GeoIP-update.sh in the CAT distribution and use it tu update the GeoIP database regularly."); |
|
| 315 | 315 | return; |
| 316 | 316 | } |
| 317 | 317 | try { |
| 318 | 318 | $record = $reader->city($host_6); |
| 319 | 319 | } catch (Exception $e) { |
| 320 | - $this->test_return(L_ERROR,"PHP extension <strong>GeoIP2</strong> found but not working properly with IPv6, perhaps you need to download the databases. See utils/GeoIP-update.sh in the CAT distribution and use it tu update the GeoIP database regularly."); |
|
| 320 | + $this->test_return(L_ERROR, "PHP extension <strong>GeoIP2</strong> found but not working properly with IPv6, perhaps you need to download the databases. See utils/GeoIP-update.sh in the CAT distribution and use it tu update the GeoIP database regularly."); |
|
| 321 | 321 | return; |
| 322 | 322 | } |
| 323 | - if( $record->city->name != 'Utrecht') { |
|
| 324 | - $this->test_return(L_ERROR,"PHP extension <strong>GeoIP2</strong> found but not working properly with IPv6, perhaps you need to download the databases. See utils/GeoIP-update.sh in the CAT distribution and use it tu update the GeoIP database regularly."); |
|
| 323 | + if ($record->city->name != 'Utrecht') { |
|
| 324 | + $this->test_return(L_ERROR, "PHP extension <strong>GeoIP2</strong> found but not working properly with IPv6, perhaps you need to download the databases. See utils/GeoIP-update.sh in the CAT distribution and use it tu update the GeoIP database regularly."); |
|
| 325 | 325 | return; |
| 326 | 326 | } |
| 327 | - $this->test_return(L_OK,"PHP extension <strong>GeoIP2</strong> is installed and working. See utils/GeoIP-update.sh in the CAT distribution and use it tu update the GeoIP database regularly."); |
|
| 327 | + $this->test_return(L_OK, "PHP extension <strong>GeoIP2</strong> is installed and working. See utils/GeoIP-update.sh in the CAT distribution and use it tu update the GeoIP database regularly."); |
|
| 328 | 328 | break; |
| 329 | 329 | default: |
| 330 | - $this->test_return(L_ERROR,'Check Config::$GEOIP[\'version\'], it must be set to either 1 or 2'); |
|
| 330 | + $this->test_return(L_ERROR, 'Check Config::$GEOIP[\'version\'], it must be set to either 1 or 2'); |
|
| 331 | 331 | break; |
| 332 | 332 | } |
| 333 | 333 | } |
@@ -337,88 +337,88 @@ discard block |
||
| 337 | 337 | */ |
| 338 | 338 | private function openssl_test() { |
| 339 | 339 | $A = $this->get_exec_path('openssl'); |
| 340 | - if($A['exec'] != "") { |
|
| 340 | + if ($A['exec'] != "") { |
|
| 341 | 341 | $t = exec($A['exec'] . ' version'); |
| 342 | - if($A['exec_is'] == "EXPLICIT") |
|
| 343 | - $this->test_return(L_OK,"<strong>$t</strong> was found and is configured explicitly in your config."); |
|
| 342 | + if ($A['exec_is'] == "EXPLICIT") |
|
| 343 | + $this->test_return(L_OK, "<strong>$t</strong> was found and is configured explicitly in your config."); |
|
| 344 | 344 | else |
| 345 | - $this->test_return(L_WARN,"<strong>$t</strong> was found, but is not configured with an absolute path in your config."); |
|
| 345 | + $this->test_return(L_WARN, "<strong>$t</strong> was found, but is not configured with an absolute path in your config."); |
|
| 346 | 346 | } else |
| 347 | - $this->test_return(L_ERROR,"<strong>openssl</strong> was not found on your system!"); |
|
| 347 | + $this->test_return(L_ERROR, "<strong>openssl</strong> was not found on your system!"); |
|
| 348 | 348 | } |
| 349 | 349 | |
| 350 | 350 | /** |
| 351 | 351 | * test if makensis is available |
| 352 | 352 | */ |
| 353 | 353 | private function makensis_test() { |
| 354 | - if(! is_numeric(Config::$NSIS_VERSION)) { |
|
| 355 | - $this->test_return(L_ERROR,"NSIS_VERSION needs to be numeric!"); |
|
| 354 | + if (!is_numeric(Config::$NSIS_VERSION)) { |
|
| 355 | + $this->test_return(L_ERROR, "NSIS_VERSION needs to be numeric!"); |
|
| 356 | 356 | return; |
| 357 | 357 | } |
| 358 | - if(Config::$NSIS_VERSION < 2) { |
|
| 359 | - $this->test_return(L_ERROR,"NSIS_VERSION needs to be at least 2!"); |
|
| 358 | + if (Config::$NSIS_VERSION < 2) { |
|
| 359 | + $this->test_return(L_ERROR, "NSIS_VERSION needs to be at least 2!"); |
|
| 360 | 360 | return; |
| 361 | 361 | } |
| 362 | 362 | $A = $this->get_exec_path('makensis'); |
| 363 | - if($A['exec'] != "") { |
|
| 363 | + if ($A['exec'] != "") { |
|
| 364 | 364 | $t = exec($A['exec'] . ' -VERSION'); |
| 365 | - if($A['exec_is'] == "EXPLICIT") |
|
| 366 | - $this->test_return(L_OK,"<strong>makensis $t</strong> was found and is configured explicitly in your config."); |
|
| 365 | + if ($A['exec_is'] == "EXPLICIT") |
|
| 366 | + $this->test_return(L_OK, "<strong>makensis $t</strong> was found and is configured explicitly in your config."); |
|
| 367 | 367 | else |
| 368 | - $this->test_return(L_WARN,"<strong>makensis $t</strong> was found, but is not configured with an absolute path in your config."); |
|
| 369 | - exec($A['exec'] . ' -HELP',$t); |
|
| 370 | - $t1 = count(preg_grep('/INPUTCHARSET/',$t)); |
|
| 371 | - if($t1 == 1 && Config::$NSIS_VERSION == 2) |
|
| 372 | - $this->test_return(L_ERROR,"Declared NSIS_VERSION does not seem to match the file pointed to by PATHS['makensis']!"); |
|
| 373 | - if($t1 == 0 && Config::$NSIS_VERSION >= 3) |
|
| 374 | - $this->test_return(L_ERROR,"Declared NSIS_VERSION does not seem to match the file pointed to by PATHS['makensis']!"); |
|
| 368 | + $this->test_return(L_WARN, "<strong>makensis $t</strong> was found, but is not configured with an absolute path in your config."); |
|
| 369 | + exec($A['exec'] . ' -HELP', $t); |
|
| 370 | + $t1 = count(preg_grep('/INPUTCHARSET/', $t)); |
|
| 371 | + if ($t1 == 1 && Config::$NSIS_VERSION == 2) |
|
| 372 | + $this->test_return(L_ERROR, "Declared NSIS_VERSION does not seem to match the file pointed to by PATHS['makensis']!"); |
|
| 373 | + if ($t1 == 0 && Config::$NSIS_VERSION >= 3) |
|
| 374 | + $this->test_return(L_ERROR, "Declared NSIS_VERSION does not seem to match the file pointed to by PATHS['makensis']!"); |
|
| 375 | 375 | } else |
| 376 | - $this->test_return(L_ERROR,"<strong>makensis</strong> was not found on your system!"); |
|
| 376 | + $this->test_return(L_ERROR, "<strong>makensis</strong> was not found on your system!"); |
|
| 377 | 377 | } |
| 378 | 378 | |
| 379 | 379 | /** |
| 380 | 380 | * test if all required NSIS modules are available |
| 381 | 381 | */ |
| 382 | 382 | private function NSISmodules_test() { |
| 383 | - $tmp_dir = createTemporaryDirectory('installer',0)['dir']; |
|
| 384 | - if(!chdir($tmp_dir)) { |
|
| 383 | + $tmp_dir = createTemporaryDirectory('installer', 0)['dir']; |
|
| 384 | + if (!chdir($tmp_dir)) { |
|
| 385 | 385 | debug(2, "Cannot chdir to $tmp_dir\n"); |
| 386 | - $this->test_return(L_ERROR,"NSIS modules test - problem with temporary directory permissions, cannot continue"); |
|
| 386 | + $this->test_return(L_ERROR, "NSIS modules test - problem with temporary directory permissions, cannot continue"); |
|
| 387 | 387 | return; |
| 388 | 388 | } |
| 389 | - $exe= 'tt.exe'; |
|
| 389 | + $exe = 'tt.exe'; |
|
| 390 | 390 | $NSIS_Module_status = []; |
| 391 | 391 | foreach ($this->NSIS_Modules as $module) { |
| 392 | 392 | unset($out); |
| 393 | - exec(Config::$PATHS['makensis']." -V1 '-X!include $module' '-XOutFile $exe' '-XSection X' '-XSectionEnd'", $out, $retval); |
|
| 394 | - if($retval > 0) |
|
| 393 | + exec(Config::$PATHS['makensis'] . " -V1 '-X!include $module' '-XOutFile $exe' '-XSection X' '-XSectionEnd'", $out, $retval); |
|
| 394 | + if ($retval > 0) |
|
| 395 | 395 | $NSIS_Module_status[$module] = 0; |
| 396 | 396 | else |
| 397 | 397 | $NSIS_Module_status[$module] = 1; |
| 398 | 398 | } |
| 399 | - if(is_file($exe)) |
|
| 399 | + if (is_file($exe)) |
|
| 400 | 400 | unlink($exe); |
| 401 | 401 | foreach ($NSIS_Module_status as $module => $status) { |
| 402 | - if($status == 1) |
|
| 403 | - $this->test_return(L_OK,"NSIS module <strong>$module</strong> was found."); |
|
| 402 | + if ($status == 1) |
|
| 403 | + $this->test_return(L_OK, "NSIS module <strong>$module</strong> was found."); |
|
| 404 | 404 | else |
| 405 | - $this->test_return(L_ERROR,"NSIS module <strong>$module</strong> was not found or is not working correctly."); |
|
| 405 | + $this->test_return(L_ERROR, "NSIS module <strong>$module</strong> was not found or is not working correctly."); |
|
| 406 | 406 | } |
| 407 | 407 | } |
| 408 | 408 | private function NSIS_GetVersion_test() { |
| 409 | - $tmp_dir = createTemporaryDirectory('installer',0)['dir']; |
|
| 410 | - if(!chdir($tmp_dir)) { |
|
| 409 | + $tmp_dir = createTemporaryDirectory('installer', 0)['dir']; |
|
| 410 | + if (!chdir($tmp_dir)) { |
|
| 411 | 411 | debug(2, "Cannot chdir to $tmp_dir\n"); |
| 412 | - $this->test_return(L_ERROR,"NSIS module <strong>GetVersion</strong> - problem with temporary directory permissions, cannot continue"); |
|
| 412 | + $this->test_return(L_ERROR, "NSIS module <strong>GetVersion</strong> - problem with temporary directory permissions, cannot continue"); |
|
| 413 | 413 | return; |
| 414 | 414 | } |
| 415 | - $exe= 'tt.exe'; |
|
| 416 | - exec(Config::$PATHS['makensis']." -V1 '-XOutFile $exe' '-XSection X' '-XGetVersion::WindowsName' '-XSectionEnd'", $out, $retval); |
|
| 417 | - if($retval > 0) |
|
| 418 | - $this->test_return(L_ERROR,"NSIS module <strong>GetVersion</strong> was not found or is not working correctly."); |
|
| 415 | + $exe = 'tt.exe'; |
|
| 416 | + exec(Config::$PATHS['makensis'] . " -V1 '-XOutFile $exe' '-XSection X' '-XGetVersion::WindowsName' '-XSectionEnd'", $out, $retval); |
|
| 417 | + if ($retval > 0) |
|
| 418 | + $this->test_return(L_ERROR, "NSIS module <strong>GetVersion</strong> was not found or is not working correctly."); |
|
| 419 | 419 | else |
| 420 | - $this->test_return(L_OK,"NSIS module <strong>GetVersion</strong> was found."); |
|
| 421 | - if(is_file($exe)) |
|
| 420 | + $this->test_return(L_OK, "NSIS module <strong>GetVersion</strong> was found."); |
|
| 421 | + if (is_file($exe)) |
|
| 422 | 422 | unlink($exe); |
| 423 | 423 | } |
| 424 | 424 | |
@@ -426,32 +426,32 @@ discard block |
||
| 426 | 426 | * test access to dowloads directories |
| 427 | 427 | */ |
| 428 | 428 | private function directories_test() { |
| 429 | - $Dir = createTemporaryDirectory('installer',0); |
|
| 429 | + $Dir = createTemporaryDirectory('installer', 0); |
|
| 430 | 430 | $dir = $Dir['dir']; |
| 431 | 431 | $base = $Dir['base']; |
| 432 | - if($dir) { |
|
| 433 | - $this->test_return(L_OK,"Installer cache directory is writable."); |
|
| 432 | + if ($dir) { |
|
| 433 | + $this->test_return(L_OK, "Installer cache directory is writable."); |
|
| 434 | 434 | rrmdir($dir); |
| 435 | 435 | } else { |
| 436 | - $this->test_return(L_ERROR,"Installer cache directory $base does not exist or is not writable!"); |
|
| 436 | + $this->test_return(L_ERROR, "Installer cache directory $base does not exist or is not writable!"); |
|
| 437 | 437 | } |
| 438 | - $Dir = createTemporaryDirectory('test',0); |
|
| 438 | + $Dir = createTemporaryDirectory('test', 0); |
|
| 439 | 439 | $dir = $Dir['dir']; |
| 440 | 440 | $base = $Dir['base']; |
| 441 | - if($dir) { |
|
| 442 | - $this->test_return(L_OK,"Test directory is writable."); |
|
| 441 | + if ($dir) { |
|
| 442 | + $this->test_return(L_OK, "Test directory is writable."); |
|
| 443 | 443 | rrmdir($dir); |
| 444 | 444 | } else { |
| 445 | - $this->test_return(L_ERROR,"Test directory $base does not exist or is not writable!"); |
|
| 445 | + $this->test_return(L_ERROR, "Test directory $base does not exist or is not writable!"); |
|
| 446 | 446 | } |
| 447 | - $Dir = createTemporaryDirectory('logo',0); |
|
| 447 | + $Dir = createTemporaryDirectory('logo', 0); |
|
| 448 | 448 | $dir = $Dir['dir']; |
| 449 | 449 | $base = $Dir['base']; |
| 450 | - if($dir) { |
|
| 451 | - $this->test_return(L_OK,"Logos cache directory is writable."); |
|
| 450 | + if ($dir) { |
|
| 451 | + $this->test_return(L_OK, "Logos cache directory is writable."); |
|
| 452 | 452 | rrmdir($dir); |
| 453 | 453 | } else { |
| 454 | - $this->test_return(L_ERROR,"Logos cache directory $base does not exist or is not writable!"); |
|
| 454 | + $this->test_return(L_ERROR, "Logos cache directory $base does not exist or is not writable!"); |
|
| 455 | 455 | } |
| 456 | 456 | } |
| 457 | 457 | |
@@ -466,16 +466,16 @@ discard block |
||
| 466 | 466 | $allthere .= $onelanguage['locale'] . " "; |
| 467 | 467 | |
| 468 | 468 | if ($allthere == "") |
| 469 | - $this->test_return(L_OK,"All of your configured locales are available on your system."); |
|
| 469 | + $this->test_return(L_OK, "All of your configured locales are available on your system."); |
|
| 470 | 470 | else |
| 471 | - $this->test_return(L_WARN,"Some of your configured locales (<strong>$allthere</strong>) are not installed and will not be displayed correctly!"); |
|
| 471 | + $this->test_return(L_WARN, "Some of your configured locales (<strong>$allthere</strong>) are not installed and will not be displayed correctly!"); |
|
| 472 | 472 | } |
| 473 | 473 | |
| 474 | - private function check_config_default($type,$key,$value) { |
|
| 474 | + private function check_config_default($type, $key, $value) { |
|
| 475 | 475 | if (empty(Config::$type[$key])) |
| 476 | - $missingvalues .="type/webcert_OCSP "; |
|
| 476 | + $missingvalues .= "type/webcert_OCSP "; |
|
| 477 | 477 | elseif (Config::$type['webcert_OCSP'] == $value) |
| 478 | - $defaultvalues .="type/$key "; |
|
| 478 | + $defaultvalues .= "type/$key "; |
|
| 479 | 479 | } |
| 480 | 480 | |
| 481 | 481 | |
@@ -486,31 +486,31 @@ discard block |
||
| 486 | 486 | $defaultvalues = ""; |
| 487 | 487 | $missingvalues = ""; |
| 488 | 488 | if (Config::$APPEARANCE['from-mail'] == "[email protected]") |
| 489 | - $defaultvalues .="APPEARANCE/from-mail "; |
|
| 489 | + $defaultvalues .= "APPEARANCE/from-mail "; |
|
| 490 | 490 | if (Config::$APPEARANCE['support-contact']['url'] == "[email protected]?body=Only%20English%20language%20please!") |
| 491 | - $defaultvalues .="APPEARANCE/support-contact/url "; |
|
| 491 | + $defaultvalues .= "APPEARANCE/support-contact/url "; |
|
| 492 | 492 | if (Config::$APPEARANCE['support-contact']['display'] == "[email protected]") |
| 493 | - $defaultvalues .="APPEARANCE/support-contact/display "; |
|
| 493 | + $defaultvalues .= "APPEARANCE/support-contact/display "; |
|
| 494 | 494 | if (Config::$APPEARANCE['support-contact']['developer-mail'] == "[email protected]") |
| 495 | - $defaultvalues .="APPEARANCE/support-contact/mail "; |
|
| 495 | + $defaultvalues .= "APPEARANCE/support-contact/mail "; |
|
| 496 | 496 | if (Config::$APPEARANCE['abuse-mail'] == "[email protected]") |
| 497 | - $defaultvalues .="APPEARANCE/abuse-mail "; |
|
| 497 | + $defaultvalues .= "APPEARANCE/abuse-mail "; |
|
| 498 | 498 | if (Config::$APPEARANCE['MOTD'] == "Release Candidate. All bugs to be shot on sight!") |
| 499 | - $defaultvalues .="APPEARANCE/MOTD "; |
|
| 499 | + $defaultvalues .= "APPEARANCE/MOTD "; |
|
| 500 | 500 | if (Config::$APPEARANCE['webcert_CRLDP'] == ['list', 'of', 'CRL', 'pointers']) |
| 501 | - $defaultvalues .="APPEARANCE/webcert_CRLDP "; |
|
| 501 | + $defaultvalues .= "APPEARANCE/webcert_CRLDP "; |
|
| 502 | 502 | if (empty(Config::$APPEARANCE['webcert_OCSP'])) |
| 503 | - $missingvalues .="APPEARANCE/webcert_OCSP "; |
|
| 503 | + $missingvalues .= "APPEARANCE/webcert_OCSP "; |
|
| 504 | 504 | elseif (Config::$APPEARANCE['webcert_OCSP'] == ['list', 'of', 'OCSP', 'pointers']) |
| 505 | - $defaultvalues .="APPEARANCE/webcert_OCSP "; |
|
| 505 | + $defaultvalues .= "APPEARANCE/webcert_OCSP "; |
|
| 506 | 506 | if (isset(Config::$RADIUSTESTS['UDP-hosts'][0]) && Config::$RADIUSTESTS['UDP-hosts'][0]['ip'] == "192.0.2.1") |
| 507 | - $defaultvalues .="RADIUSTESTS/UDP-hosts "; |
|
| 507 | + $defaultvalues .= "RADIUSTESTS/UDP-hosts "; |
|
| 508 | 508 | if (Config::$DB['INST']['host'] == "db.host.example") |
| 509 | - $defaultvalues .="DB/INST "; |
|
| 509 | + $defaultvalues .= "DB/INST "; |
|
| 510 | 510 | if (Config::$DB['INST']['host'] == "db.host.example") |
| 511 | - $defaultvalues .="DB/USER "; |
|
| 512 | - if(!empty(Config::$DB['EXTERNAL']) && Config::$DB['EXTERNAL']['host'] == "customerdb.otherhost.example") |
|
| 513 | - $defaultvalues .="DB/EXTERNAL "; |
|
| 511 | + $defaultvalues .= "DB/USER "; |
|
| 512 | + if (!empty(Config::$DB['EXTERNAL']) && Config::$DB['EXTERNAL']['host'] == "customerdb.otherhost.example") |
|
| 513 | + $defaultvalues .= "DB/EXTERNAL "; |
|
| 514 | 514 | $files = []; |
| 515 | 515 | foreach (Config::$RADIUSTESTS['TLS-clientcerts'] as $cadata) { |
| 516 | 516 | foreach ($cadata['certificates'] as $cert_files) { |
@@ -522,14 +522,14 @@ discard block |
||
| 522 | 522 | foreach ($files as $file) { |
| 523 | 523 | $handle = fopen(CAT::$root . "/config/cli-certs/" . $file, 'r'); |
| 524 | 524 | if (!$handle) |
| 525 | - $defaultvalues .="CERTIFICATE/$file "; |
|
| 525 | + $defaultvalues .= "CERTIFICATE/$file "; |
|
| 526 | 526 | else |
| 527 | 527 | fclose($handle); |
| 528 | 528 | } |
| 529 | 529 | if ($defaultvalues != "") |
| 530 | - $this->test_return(L_WARN,"Your configuration in config/config.php contains unchanged default values or links to inexistent files: <strong>$defaultvalues</strong>!"); |
|
| 530 | + $this->test_return(L_WARN, "Your configuration in config/config.php contains unchanged default values or links to inexistent files: <strong>$defaultvalues</strong>!"); |
|
| 531 | 531 | else |
| 532 | - $this->test_return(L_OK,"Your configuration does not contain any unchanged defaults, which is a good sign."); |
|
| 532 | + $this->test_return(L_OK, "Your configuration does not contain any unchanged defaults, which is a good sign."); |
|
| 533 | 533 | } |
| 534 | 534 | |
| 535 | 535 | /** |
@@ -538,37 +538,37 @@ discard block |
||
| 538 | 538 | private function databases_test() { |
| 539 | 539 | $DB = 'INST'; |
| 540 | 540 | $db = mysqli_connect(Config::$DB[$DB]['host'], Config::$DB[$DB]['user'], Config::$DB[$DB]['pass'], Config::$DB[$DB]['db']); |
| 541 | - if(! $db) { |
|
| 542 | - $this->test_return(L_ERROR,"Connection to the $DB database failed"); |
|
| 541 | + if (!$db) { |
|
| 542 | + $this->test_return(L_ERROR, "Connection to the $DB database failed"); |
|
| 543 | 543 | } else { |
| 544 | - $r = mysqli_query($db,'select * from profile_option_dict'); |
|
| 545 | - if($r->num_rows == $this->profile_option_ct) |
|
| 546 | - $this->test_return(L_OK,"The $DB database appears to be OK."); |
|
| 544 | + $r = mysqli_query($db, 'select * from profile_option_dict'); |
|
| 545 | + if ($r->num_rows == $this->profile_option_ct) |
|
| 546 | + $this->test_return(L_OK, "The $DB database appears to be OK."); |
|
| 547 | 547 | else |
| 548 | - $this->test_return(L_ERROR,"The $DB database is reacheable but probably not updated to this version of CAT."); |
|
| 548 | + $this->test_return(L_ERROR, "The $DB database is reacheable but probably not updated to this version of CAT."); |
|
| 549 | 549 | } |
| 550 | 550 | $DB = 'USER'; |
| 551 | 551 | $db = mysqli_connect(Config::$DB[$DB]['host'], Config::$DB[$DB]['user'], Config::$DB[$DB]['pass'], Config::$DB[$DB]['db']); |
| 552 | - if(! $db) { |
|
| 553 | - $this->test_return(L_ERROR,"Connection to the $DB database failed"); |
|
| 552 | + if (!$db) { |
|
| 553 | + $this->test_return(L_ERROR, "Connection to the $DB database failed"); |
|
| 554 | 554 | } else { |
| 555 | - $r = mysqli_query($db,'desc view_admin'); |
|
| 556 | - if($r->num_rows == $this->view_admin_ct) |
|
| 557 | - $this->test_return(L_OK,"The $DB database appears to be OK."); |
|
| 555 | + $r = mysqli_query($db, 'desc view_admin'); |
|
| 556 | + if ($r->num_rows == $this->view_admin_ct) |
|
| 557 | + $this->test_return(L_OK, "The $DB database appears to be OK."); |
|
| 558 | 558 | else |
| 559 | - $this->test_return(L_ERROR,"The $DB is reacheable but there is something wrong with the schema"); |
|
| 559 | + $this->test_return(L_ERROR, "The $DB is reacheable but there is something wrong with the schema"); |
|
| 560 | 560 | } |
| 561 | 561 | $DB = 'EXTERNAL'; |
| 562 | - if(! empty(Config::$DB[$DB])) { |
|
| 562 | + if (!empty(Config::$DB[$DB])) { |
|
| 563 | 563 | $db = mysqli_connect(Config::$DB[$DB]['host'], Config::$DB[$DB]['user'], Config::$DB[$DB]['pass'], Config::$DB[$DB]['db']); |
| 564 | - if(! $db) { |
|
| 565 | - $this->test_return(L_ERROR,"Connection to the $DB database failed"); |
|
| 564 | + if (!$db) { |
|
| 565 | + $this->test_return(L_ERROR, "Connection to the $DB database failed"); |
|
| 566 | 566 | } else { |
| 567 | - $r = mysqli_query($db,'desc view_admin'); |
|
| 568 | - if($r->num_rows == $this->view_admin_ct) |
|
| 569 | - $this->test_return(L_OK,"The $DB database appears to be OK."); |
|
| 567 | + $r = mysqli_query($db, 'desc view_admin'); |
|
| 568 | + if ($r->num_rows == $this->view_admin_ct) |
|
| 569 | + $this->test_return(L_OK, "The $DB database appears to be OK."); |
|
| 570 | 570 | else |
| 571 | - $this->test_return(L_ERROR,"The $DB is reacheable but there is something wrong with the schema"); |
|
| 571 | + $this->test_return(L_ERROR, "The $DB is reacheable but there is something wrong with the schema"); |
|
| 572 | 572 | } |
| 573 | 573 | } |
| 574 | 574 | } |
@@ -578,37 +578,37 @@ discard block |
||
| 578 | 578 | * test devices.php for the no_cache option |
| 579 | 579 | */ |
| 580 | 580 | private function device_cache_test() { |
| 581 | - if((! empty(Devices::$Options['no_cache'])) && Devices::$Options['no_cache']) |
|
| 581 | + if ((!empty(Devices::$Options['no_cache'])) && Devices::$Options['no_cache']) |
|
| 582 | 582 | $global_no_cache = 1; |
| 583 | 583 | else |
| 584 | 584 | $global_no_cache = 0; |
| 585 | 585 | |
| 586 | - if($global_no_cache == 1) |
|
| 587 | - $this->test_return(L_WARN,"Devices no_cache global option is set, this is not a good idea in a production setting\n"); |
|
| 586 | + if ($global_no_cache == 1) |
|
| 587 | + $this->test_return(L_WARN, "Devices no_cache global option is set, this is not a good idea in a production setting\n"); |
|
| 588 | 588 | $Devs = Devices::listDevices(); |
| 589 | 589 | $no_cache_dev = ''; |
| 590 | 590 | $no_cache_dev_count = 0; |
| 591 | - if($global_no_cache) { |
|
| 591 | + if ($global_no_cache) { |
|
| 592 | 592 | foreach ($Devs as $dev=>$D) { |
| 593 | - if(empty($D['options']['no_cache']) || $D['options']['no_cache'] != 0) { |
|
| 594 | - $no_cache_dev .= $dev." "; |
|
| 593 | + if (empty($D['options']['no_cache']) || $D['options']['no_cache'] != 0) { |
|
| 594 | + $no_cache_dev .= $dev . " "; |
|
| 595 | 595 | $no_cache_dev_count++; |
| 596 | 596 | } |
| 597 | 597 | } |
| 598 | 598 | } else { |
| 599 | 599 | foreach ($Devs as $dev=>$D) { |
| 600 | - if(!empty($D['options']['no_cache']) && $D['options']['no_cache'] != 0) { |
|
| 601 | - $no_cache_dev .= $dev." "; |
|
| 600 | + if (!empty($D['options']['no_cache']) && $D['options']['no_cache'] != 0) { |
|
| 601 | + $no_cache_dev .= $dev . " "; |
|
| 602 | 602 | $no_cache_dev_count++; |
| 603 | 603 | } |
| 604 | 604 | } |
| 605 | 605 | } |
| 606 | 606 | |
| 607 | 607 | |
| 608 | - if($no_cache_dev_count > 1 ) |
|
| 609 | - $this->test_return(L_WARN,"The following devices will not be cached: $no_cache_dev"); |
|
| 610 | - if($no_cache_dev_count == 1 ) |
|
| 611 | - $this->test_return(L_WARN,"The following device will not be cached: $no_cache_dev"); |
|
| 608 | + if ($no_cache_dev_count > 1) |
|
| 609 | + $this->test_return(L_WARN, "The following devices will not be cached: $no_cache_dev"); |
|
| 610 | + if ($no_cache_dev_count == 1) |
|
| 611 | + $this->test_return(L_WARN, "The following device will not be cached: $no_cache_dev"); |
|
| 612 | 612 | |
| 613 | 613 | } |
| 614 | 614 | |
@@ -617,7 +617,7 @@ discard block |
||
| 617 | 617 | */ |
| 618 | 618 | private function mailer_test() { |
| 619 | 619 | if (empty(Config::$APPEARANCE['abuse-mail']) || Config::$APPEARANCE['abuse-mail'] == "[email protected]") { |
| 620 | - $this->test_return(L_ERROR,"Your abuse-mail has not been set, cannot continue with mailer tests."); |
|
| 620 | + $this->test_return(L_ERROR, "Your abuse-mail has not been set, cannot continue with mailer tests."); |
|
| 621 | 621 | return; |
| 622 | 622 | } |
| 623 | 623 | $mail = new PHPMailer(); |
@@ -637,10 +637,10 @@ discard block |
||
| 637 | 637 | $mail->Subject = "testing CAT configuration mail"; |
| 638 | 638 | $mail->Body = "Testing CAT mailing\n"; |
| 639 | 639 | $sent = $mail->send(); |
| 640 | - if($sent) |
|
| 641 | - $this->test_return(L_OK,"mailer settings appear to be working, check ".Config::$APPEARANCE['abuse-mail']." mailbox if the message was receiced."); |
|
| 640 | + if ($sent) |
|
| 641 | + $this->test_return(L_OK, "mailer settings appear to be working, check " . Config::$APPEARANCE['abuse-mail'] . " mailbox if the message was receiced."); |
|
| 642 | 642 | else |
| 643 | - $this->test_return(L_ERROR,"mailer settings failed, check the Config::MAILSETTINGS"); |
|
| 643 | + $this->test_return(L_ERROR, "mailer settings failed, check the Config::MAILSETTINGS"); |
|
| 644 | 644 | |
| 645 | 645 | } |
| 646 | 646 | |
@@ -100,11 +100,12 @@ discard block |
||
| 100 | 100 | if(preg_match('/(.+)=>(.+)/',$t,$m)) { |
| 101 | 101 | $tst = $m[1]; |
| 102 | 102 | $subtst=$m[2]; |
| 103 | - if($this->test_result[$tst] < L_ERROR) |
|
| 104 | - $this->test($subtst); |
|
| 103 | + if($this->test_result[$tst] < L_ERROR) { |
|
| 104 | + $this->test($subtst); |
|
| 105 | + } |
|
| 106 | + } else { |
|
| 107 | + $this->test($t); |
|
| 105 | 108 | } |
| 106 | - else |
|
| 107 | - $this->test($t); |
|
| 108 | 109 | } |
| 109 | 110 | } |
| 110 | 111 | |
@@ -145,10 +146,11 @@ discard block |
||
| 145 | 146 | preg_match('/([^ ]+) ?/',Config::$PATHS[$s],$m); |
| 146 | 147 | $exe = $m[1]; |
| 147 | 148 | $the_path = exec("which " . Config::$PATHS[$s]); |
| 148 | - if ($the_path == $exe) |
|
| 149 | - $exec_is = "EXPLICIT"; |
|
| 150 | - else |
|
| 151 | - $exec_is = "IMPLICIT"; |
|
| 149 | + if ($the_path == $exe) { |
|
| 150 | + $exec_is = "EXPLICIT"; |
|
| 151 | + } else { |
|
| 152 | + $exec_is = "IMPLICIT"; |
|
| 153 | + } |
|
| 152 | 154 | } |
| 153 | 155 | return(['exec'=>$the_path,'exec_is'=>$exec_is]); |
| 154 | 156 | } |
@@ -157,38 +159,42 @@ discard block |
||
| 157 | 159 | * Test for php version |
| 158 | 160 | */ |
| 159 | 161 | private function php_test() { |
| 160 | - if (version_compare(phpversion(), $this->php_needversion, '>=')) |
|
| 161 | - $this->test_return(L_OK,"<strong>PHP</strong> is sufficiently recent. You are running " . phpversion() . "."); |
|
| 162 | - else |
|
| 163 | - $this->test_return(L_ERROR,"<strong>PHP</strong> is too old. We need at least $this->php_needversion, but you only have ".phpversion(). "."); |
|
| 162 | + if (version_compare(phpversion(), $this->php_needversion, '>=')) { |
|
| 163 | + $this->test_return(L_OK,"<strong>PHP</strong> is sufficiently recent. You are running " . phpversion() . "."); |
|
| 164 | + } else { |
|
| 165 | + $this->test_return(L_ERROR,"<strong>PHP</strong> is too old. We need at least $this->php_needversion, but you only have ".phpversion(). "."); |
|
| 166 | + } |
|
| 164 | 167 | } |
| 165 | 168 | |
| 166 | 169 | /** |
| 167 | 170 | * test for simpleSAMLphp |
| 168 | 171 | */ |
| 169 | 172 | private function ssp_test() { |
| 170 | - if (!is_file(CONFIG::$AUTHENTICATION['ssp-path-to-autoloader'])) |
|
| 171 | - $this->test_return(L_ERROR,"<strong>simpleSAMLphp</strong> not found!"); |
|
| 172 | - else |
|
| 173 | - $this->test_return(L_OK,"<strong>simpleSAMLphp</strong> autoloader found."); |
|
| 173 | + if (!is_file(CONFIG::$AUTHENTICATION['ssp-path-to-autoloader'])) { |
|
| 174 | + $this->test_return(L_ERROR,"<strong>simpleSAMLphp</strong> not found!"); |
|
| 175 | + } else { |
|
| 176 | + $this->test_return(L_OK,"<strong>simpleSAMLphp</strong> autoloader found."); |
|
| 177 | + } |
|
| 174 | 178 | } |
| 175 | 179 | |
| 176 | 180 | /** |
| 177 | 181 | * test for security setting |
| 178 | 182 | */ |
| 179 | 183 | private function security_test() { |
| 180 | - if (in_array("I do not care about security!", Config::$SUPERADMINS)) |
|
| 181 | - $this->test_return(L_WARN,"You do not care about security. This page should be made accessible to the CAT admin only! See config.php 'Superadmins'!"); |
|
| 184 | + if (in_array("I do not care about security!", Config::$SUPERADMINS)) { |
|
| 185 | + $this->test_return(L_WARN,"You do not care about security. This page should be made accessible to the CAT admin only! See config.php 'Superadmins'!"); |
|
| 186 | + } |
|
| 182 | 187 | } |
| 183 | 188 | |
| 184 | 189 | /** |
| 185 | 190 | * test if zip is available |
| 186 | 191 | */ |
| 187 | 192 | private function zip_test() { |
| 188 | - if (exec("which zip") != "") |
|
| 189 | - $this->test_return(L_OK,"<strong>zip</strong> binary found."); |
|
| 190 | - else |
|
| 191 | - $this->test_return(L_ERROR,"<strong>zip</strong> not found in your \$PATH!"); |
|
| 193 | + if (exec("which zip") != "") { |
|
| 194 | + $this->test_return(L_OK,"<strong>zip</strong> binary found."); |
|
| 195 | + } else { |
|
| 196 | + $this->test_return(L_ERROR,"<strong>zip</strong> not found in your \$PATH!"); |
|
| 197 | + } |
|
| 192 | 198 | } |
| 193 | 199 | |
| 194 | 200 | /** |
@@ -198,59 +204,67 @@ discard block |
||
| 198 | 204 | exec(Config::$PATHS['eapol_test'], $out, $retval); |
| 199 | 205 | if($retval == 255 ) { |
| 200 | 206 | $o = preg_grep('/-o<server cert/',$out); |
| 201 | - if(count($o) > 0) |
|
| 202 | - $this->test_return(L_OK,"<strong>eapol_test</strong> script found."); |
|
| 203 | - else |
|
| 204 | - $this->test_return(L_ERROR,"<strong>eapol_test</strong> found, but is too old!"); |
|
| 207 | + if(count($o) > 0) { |
|
| 208 | + $this->test_return(L_OK,"<strong>eapol_test</strong> script found."); |
|
| 209 | + } else { |
|
| 210 | + $this->test_return(L_ERROR,"<strong>eapol_test</strong> found, but is too old!"); |
|
| 211 | + } |
|
| 212 | + } else { |
|
| 213 | + $this->test_return(L_ERROR,"<strong>eapol_test</strong> not found!"); |
|
| 205 | 214 | } |
| 206 | - else |
|
| 207 | - $this->test_return(L_ERROR,"<strong>eapol_test</strong> not found!"); |
|
| 208 | 215 | } |
| 209 | 216 | |
| 210 | 217 | /** |
| 211 | 218 | * test if logdir exists and is writable |
| 212 | 219 | */ |
| 213 | 220 | private function logdir_test() { |
| 214 | - if (fopen(Config::$PATHS['logdir'] . "/debug.log", "a") == FALSE) |
|
| 215 | - $this->test_return(L_WARN,"Log files in <strong>" . Config::$PATHS['logdir'] . "</strong> are not writable!"); |
|
| 216 | - else |
|
| 217 | - $this->test_return(L_OK,"Log directory is writable."); |
|
| 221 | + if (fopen(Config::$PATHS['logdir'] . "/debug.log", "a") == FALSE) { |
|
| 222 | + $this->test_return(L_WARN,"Log files in <strong>" . Config::$PATHS['logdir'] . "</strong> are not writable!"); |
|
| 223 | + } else { |
|
| 224 | + $this->test_return(L_OK,"Log directory is writable."); |
|
| 225 | + } |
|
| 218 | 226 | } |
| 219 | 227 | |
| 220 | 228 | /** |
| 221 | 229 | * test for required PHP modules |
| 222 | 230 | */ |
| 223 | 231 | private function phpModules_test() { |
| 224 | - if (function_exists('idn_to_ascii')) |
|
| 225 | - $this->test_return(L_OK,"PHP can handle internationalisation."); |
|
| 226 | - else |
|
| 227 | - $this->test_return(L_ERROR,"PHP can <strongNOT</strong> handle internationalisation (idn_to_ascii() from php5-intl)."); |
|
| 232 | + if (function_exists('idn_to_ascii')) { |
|
| 233 | + $this->test_return(L_OK,"PHP can handle internationalisation."); |
|
| 234 | + } else { |
|
| 235 | + $this->test_return(L_ERROR,"PHP can <strongNOT</strong> handle internationalisation (idn_to_ascii() from php5-intl)."); |
|
| 236 | + } |
|
| 228 | 237 | |
| 229 | - if (function_exists('gettext')) |
|
| 230 | - $this->test_return(L_OK,"PHP extension <strong>GNU Gettext</strong> is installed."); |
|
| 231 | - else |
|
| 232 | - $this->test_return(L_ERROR,"PHP extension <strong>GNU Gettext</strong> not found!"); |
|
| 238 | + if (function_exists('gettext')) { |
|
| 239 | + $this->test_return(L_OK,"PHP extension <strong>GNU Gettext</strong> is installed."); |
|
| 240 | + } else { |
|
| 241 | + $this->test_return(L_ERROR,"PHP extension <strong>GNU Gettext</strong> not found!"); |
|
| 242 | + } |
|
| 233 | 243 | |
| 234 | - if (function_exists('openssl_sign')) |
|
| 235 | - $this->test_return(L_OK,"PHP extension <strong>OpenSSL</strong> is installed."); |
|
| 236 | - else |
|
| 237 | - $this->test_return(L_ERROR,"PHP extension <strong>OpenSSL</strong> not found!"); |
|
| 244 | + if (function_exists('openssl_sign')) { |
|
| 245 | + $this->test_return(L_OK,"PHP extension <strong>OpenSSL</strong> is installed."); |
|
| 246 | + } else { |
|
| 247 | + $this->test_return(L_ERROR,"PHP extension <strong>OpenSSL</strong> not found!"); |
|
| 248 | + } |
|
| 238 | 249 | |
| 239 | - if (class_exists('Imagick')) |
|
| 240 | - $this->test_return(L_OK,"PHP extension <strong>Imagick</strong> is installed."); |
|
| 241 | - else |
|
| 242 | - $this->test_return(L_ERROR,"PHP extension <strong>Imagick</strong> not found! Get it from your distribution or <a href='http://pecl.php.net/package/imagick'>here</a>."); |
|
| 250 | + if (class_exists('Imagick')) { |
|
| 251 | + $this->test_return(L_OK,"PHP extension <strong>Imagick</strong> is installed."); |
|
| 252 | + } else { |
|
| 253 | + $this->test_return(L_ERROR,"PHP extension <strong>Imagick</strong> not found! Get it from your distribution or <a href='http://pecl.php.net/package/imagick'>here</a>."); |
|
| 254 | + } |
|
| 243 | 255 | |
| 244 | - if (function_exists('ImageCreate')) |
|
| 245 | - $this->test_return(L_OK,"PHP extension <strong>GD</strong> is installed."); |
|
| 246 | - else |
|
| 247 | - $this->test_return(L_ERROR,"PHP extension <strong>GD</strong> not found!</a>."); |
|
| 256 | + if (function_exists('ImageCreate')) { |
|
| 257 | + $this->test_return(L_OK,"PHP extension <strong>GD</strong> is installed."); |
|
| 258 | + } else { |
|
| 259 | + $this->test_return(L_ERROR,"PHP extension <strong>GD</strong> not found!</a>."); |
|
| 260 | + } |
|
| 248 | 261 | |
| 249 | - if (function_exists('mysqli_connect')) |
|
| 250 | - $this->test_return(L_OK,"PHP extension <strong>MySQL</strong> is installed."); |
|
| 251 | - else |
|
| 252 | - $this->test_return(L_ERROR,"PHP extension <strong>MySQL</strong> not found!"); |
|
| 253 | -/* |
|
| 262 | + if (function_exists('mysqli_connect')) { |
|
| 263 | + $this->test_return(L_OK,"PHP extension <strong>MySQL</strong> is installed."); |
|
| 264 | + } else { |
|
| 265 | + $this->test_return(L_ERROR,"PHP extension <strong>MySQL</strong> not found!"); |
|
| 266 | + } |
|
| 267 | + /* |
|
| 254 | 268 | if (function_exists('geoip_record_by_name')) { |
| 255 | 269 | $host = '158.75.1.10'; |
| 256 | 270 | $record = geoip_record_by_name($host); |
@@ -339,12 +353,14 @@ discard block |
||
| 339 | 353 | $A = $this->get_exec_path('openssl'); |
| 340 | 354 | if($A['exec'] != "") { |
| 341 | 355 | $t = exec($A['exec'] . ' version'); |
| 342 | - if($A['exec_is'] == "EXPLICIT") |
|
| 343 | - $this->test_return(L_OK,"<strong>$t</strong> was found and is configured explicitly in your config."); |
|
| 344 | - else |
|
| 345 | - $this->test_return(L_WARN,"<strong>$t</strong> was found, but is not configured with an absolute path in your config."); |
|
| 346 | - } else |
|
| 347 | - $this->test_return(L_ERROR,"<strong>openssl</strong> was not found on your system!"); |
|
| 356 | + if($A['exec_is'] == "EXPLICIT") { |
|
| 357 | + $this->test_return(L_OK,"<strong>$t</strong> was found and is configured explicitly in your config."); |
|
| 358 | + } else { |
|
| 359 | + $this->test_return(L_WARN,"<strong>$t</strong> was found, but is not configured with an absolute path in your config."); |
|
| 360 | + } |
|
| 361 | + } else { |
|
| 362 | + $this->test_return(L_ERROR,"<strong>openssl</strong> was not found on your system!"); |
|
| 363 | + } |
|
| 348 | 364 | } |
| 349 | 365 | |
| 350 | 366 | /** |
@@ -362,18 +378,22 @@ discard block |
||
| 362 | 378 | $A = $this->get_exec_path('makensis'); |
| 363 | 379 | if($A['exec'] != "") { |
| 364 | 380 | $t = exec($A['exec'] . ' -VERSION'); |
| 365 | - if($A['exec_is'] == "EXPLICIT") |
|
| 366 | - $this->test_return(L_OK,"<strong>makensis $t</strong> was found and is configured explicitly in your config."); |
|
| 367 | - else |
|
| 368 | - $this->test_return(L_WARN,"<strong>makensis $t</strong> was found, but is not configured with an absolute path in your config."); |
|
| 381 | + if($A['exec_is'] == "EXPLICIT") { |
|
| 382 | + $this->test_return(L_OK,"<strong>makensis $t</strong> was found and is configured explicitly in your config."); |
|
| 383 | + } else { |
|
| 384 | + $this->test_return(L_WARN,"<strong>makensis $t</strong> was found, but is not configured with an absolute path in your config."); |
|
| 385 | + } |
|
| 369 | 386 | exec($A['exec'] . ' -HELP',$t); |
| 370 | 387 | $t1 = count(preg_grep('/INPUTCHARSET/',$t)); |
| 371 | - if($t1 == 1 && Config::$NSIS_VERSION == 2) |
|
| 372 | - $this->test_return(L_ERROR,"Declared NSIS_VERSION does not seem to match the file pointed to by PATHS['makensis']!"); |
|
| 373 | - if($t1 == 0 && Config::$NSIS_VERSION >= 3) |
|
| 374 | - $this->test_return(L_ERROR,"Declared NSIS_VERSION does not seem to match the file pointed to by PATHS['makensis']!"); |
|
| 375 | - } else |
|
| 376 | - $this->test_return(L_ERROR,"<strong>makensis</strong> was not found on your system!"); |
|
| 388 | + if($t1 == 1 && Config::$NSIS_VERSION == 2) { |
|
| 389 | + $this->test_return(L_ERROR,"Declared NSIS_VERSION does not seem to match the file pointed to by PATHS['makensis']!"); |
|
| 390 | + } |
|
| 391 | + if($t1 == 0 && Config::$NSIS_VERSION >= 3) { |
|
| 392 | + $this->test_return(L_ERROR,"Declared NSIS_VERSION does not seem to match the file pointed to by PATHS['makensis']!"); |
|
| 393 | + } |
|
| 394 | + } else { |
|
| 395 | + $this->test_return(L_ERROR,"<strong>makensis</strong> was not found on your system!"); |
|
| 396 | + } |
|
| 377 | 397 | } |
| 378 | 398 | |
| 379 | 399 | /** |
@@ -391,18 +411,21 @@ discard block |
||
| 391 | 411 | foreach ($this->NSIS_Modules as $module) { |
| 392 | 412 | unset($out); |
| 393 | 413 | exec(Config::$PATHS['makensis']." -V1 '-X!include $module' '-XOutFile $exe' '-XSection X' '-XSectionEnd'", $out, $retval); |
| 394 | - if($retval > 0) |
|
| 395 | - $NSIS_Module_status[$module] = 0; |
|
| 396 | - else |
|
| 397 | - $NSIS_Module_status[$module] = 1; |
|
| 414 | + if($retval > 0) { |
|
| 415 | + $NSIS_Module_status[$module] = 0; |
|
| 416 | + } else { |
|
| 417 | + $NSIS_Module_status[$module] = 1; |
|
| 418 | + } |
|
| 419 | + } |
|
| 420 | + if(is_file($exe)) { |
|
| 421 | + unlink($exe); |
|
| 398 | 422 | } |
| 399 | - if(is_file($exe)) |
|
| 400 | - unlink($exe); |
|
| 401 | 423 | foreach ($NSIS_Module_status as $module => $status) { |
| 402 | - if($status == 1) |
|
| 403 | - $this->test_return(L_OK,"NSIS module <strong>$module</strong> was found."); |
|
| 404 | - else |
|
| 405 | - $this->test_return(L_ERROR,"NSIS module <strong>$module</strong> was not found or is not working correctly."); |
|
| 424 | + if($status == 1) { |
|
| 425 | + $this->test_return(L_OK,"NSIS module <strong>$module</strong> was found."); |
|
| 426 | + } else { |
|
| 427 | + $this->test_return(L_ERROR,"NSIS module <strong>$module</strong> was not found or is not working correctly."); |
|
| 428 | + } |
|
| 406 | 429 | } |
| 407 | 430 | } |
| 408 | 431 | private function NSIS_GetVersion_test() { |
@@ -414,12 +437,14 @@ discard block |
||
| 414 | 437 | } |
| 415 | 438 | $exe= 'tt.exe'; |
| 416 | 439 | exec(Config::$PATHS['makensis']." -V1 '-XOutFile $exe' '-XSection X' '-XGetVersion::WindowsName' '-XSectionEnd'", $out, $retval); |
| 417 | - if($retval > 0) |
|
| 418 | - $this->test_return(L_ERROR,"NSIS module <strong>GetVersion</strong> was not found or is not working correctly."); |
|
| 419 | - else |
|
| 420 | - $this->test_return(L_OK,"NSIS module <strong>GetVersion</strong> was found."); |
|
| 421 | - if(is_file($exe)) |
|
| 422 | - unlink($exe); |
|
| 440 | + if($retval > 0) { |
|
| 441 | + $this->test_return(L_ERROR,"NSIS module <strong>GetVersion</strong> was not found or is not working correctly."); |
|
| 442 | + } else { |
|
| 443 | + $this->test_return(L_OK,"NSIS module <strong>GetVersion</strong> was found."); |
|
| 444 | + } |
|
| 445 | + if(is_file($exe)) { |
|
| 446 | + unlink($exe); |
|
| 447 | + } |
|
| 423 | 448 | } |
| 424 | 449 | |
| 425 | 450 | /** |
@@ -461,21 +486,24 @@ discard block |
||
| 461 | 486 | private function locales_test() { |
| 462 | 487 | $locales = shell_exec("locale -a"); |
| 463 | 488 | $allthere = ""; |
| 464 | - foreach (Config::$LANGUAGES as $onelanguage) |
|
| 465 | - if (preg_match("/" . $onelanguage['locale'] . "/", $locales) == 0) |
|
| 489 | + foreach (Config::$LANGUAGES as $onelanguage) { |
|
| 490 | + if (preg_match("/" . $onelanguage['locale'] . "/", $locales) == 0) |
|
| 466 | 491 | $allthere .= $onelanguage['locale'] . " "; |
| 492 | + } |
|
| 467 | 493 | |
| 468 | - if ($allthere == "") |
|
| 469 | - $this->test_return(L_OK,"All of your configured locales are available on your system."); |
|
| 470 | - else |
|
| 471 | - $this->test_return(L_WARN,"Some of your configured locales (<strong>$allthere</strong>) are not installed and will not be displayed correctly!"); |
|
| 494 | + if ($allthere == "") { |
|
| 495 | + $this->test_return(L_OK,"All of your configured locales are available on your system."); |
|
| 496 | + } else { |
|
| 497 | + $this->test_return(L_WARN,"Some of your configured locales (<strong>$allthere</strong>) are not installed and will not be displayed correctly!"); |
|
| 498 | + } |
|
| 472 | 499 | } |
| 473 | 500 | |
| 474 | 501 | private function check_config_default($type,$key,$value) { |
| 475 | - if (empty(Config::$type[$key])) |
|
| 476 | - $missingvalues .="type/webcert_OCSP "; |
|
| 477 | - elseif (Config::$type['webcert_OCSP'] == $value) |
|
| 478 | - $defaultvalues .="type/$key "; |
|
| 502 | + if (empty(Config::$type[$key])) { |
|
| 503 | + $missingvalues .="type/webcert_OCSP "; |
|
| 504 | + } elseif (Config::$type['webcert_OCSP'] == $value) { |
|
| 505 | + $defaultvalues .="type/$key "; |
|
| 506 | + } |
|
| 479 | 507 | } |
| 480 | 508 | |
| 481 | 509 | |
@@ -485,32 +513,44 @@ discard block |
||
| 485 | 513 | private function defaults_test() { |
| 486 | 514 | $defaultvalues = ""; |
| 487 | 515 | $missingvalues = ""; |
| 488 | - if (Config::$APPEARANCE['from-mail'] == "[email protected]") |
|
| 489 | - $defaultvalues .="APPEARANCE/from-mail "; |
|
| 490 | - if (Config::$APPEARANCE['support-contact']['url'] == "[email protected]?body=Only%20English%20language%20please!") |
|
| 491 | - $defaultvalues .="APPEARANCE/support-contact/url "; |
|
| 492 | - if (Config::$APPEARANCE['support-contact']['display'] == "[email protected]") |
|
| 493 | - $defaultvalues .="APPEARANCE/support-contact/display "; |
|
| 494 | - if (Config::$APPEARANCE['support-contact']['developer-mail'] == "[email protected]") |
|
| 495 | - $defaultvalues .="APPEARANCE/support-contact/mail "; |
|
| 496 | - if (Config::$APPEARANCE['abuse-mail'] == "[email protected]") |
|
| 497 | - $defaultvalues .="APPEARANCE/abuse-mail "; |
|
| 498 | - if (Config::$APPEARANCE['MOTD'] == "Release Candidate. All bugs to be shot on sight!") |
|
| 499 | - $defaultvalues .="APPEARANCE/MOTD "; |
|
| 500 | - if (Config::$APPEARANCE['webcert_CRLDP'] == ['list', 'of', 'CRL', 'pointers']) |
|
| 501 | - $defaultvalues .="APPEARANCE/webcert_CRLDP "; |
|
| 502 | - if (empty(Config::$APPEARANCE['webcert_OCSP'])) |
|
| 503 | - $missingvalues .="APPEARANCE/webcert_OCSP "; |
|
| 504 | - elseif (Config::$APPEARANCE['webcert_OCSP'] == ['list', 'of', 'OCSP', 'pointers']) |
|
| 505 | - $defaultvalues .="APPEARANCE/webcert_OCSP "; |
|
| 506 | - if (isset(Config::$RADIUSTESTS['UDP-hosts'][0]) && Config::$RADIUSTESTS['UDP-hosts'][0]['ip'] == "192.0.2.1") |
|
| 507 | - $defaultvalues .="RADIUSTESTS/UDP-hosts "; |
|
| 508 | - if (Config::$DB['INST']['host'] == "db.host.example") |
|
| 509 | - $defaultvalues .="DB/INST "; |
|
| 510 | - if (Config::$DB['INST']['host'] == "db.host.example") |
|
| 511 | - $defaultvalues .="DB/USER "; |
|
| 512 | - if(!empty(Config::$DB['EXTERNAL']) && Config::$DB['EXTERNAL']['host'] == "customerdb.otherhost.example") |
|
| 513 | - $defaultvalues .="DB/EXTERNAL "; |
|
| 516 | + if (Config::$APPEARANCE['from-mail'] == "[email protected]") { |
|
| 517 | + $defaultvalues .="APPEARANCE/from-mail "; |
|
| 518 | + } |
|
| 519 | + if (Config::$APPEARANCE['support-contact']['url'] == "[email protected]?body=Only%20English%20language%20please!") { |
|
| 520 | + $defaultvalues .="APPEARANCE/support-contact/url "; |
|
| 521 | + } |
|
| 522 | + if (Config::$APPEARANCE['support-contact']['display'] == "[email protected]") { |
|
| 523 | + $defaultvalues .="APPEARANCE/support-contact/display "; |
|
| 524 | + } |
|
| 525 | + if (Config::$APPEARANCE['support-contact']['developer-mail'] == "[email protected]") { |
|
| 526 | + $defaultvalues .="APPEARANCE/support-contact/mail "; |
|
| 527 | + } |
|
| 528 | + if (Config::$APPEARANCE['abuse-mail'] == "[email protected]") { |
|
| 529 | + $defaultvalues .="APPEARANCE/abuse-mail "; |
|
| 530 | + } |
|
| 531 | + if (Config::$APPEARANCE['MOTD'] == "Release Candidate. All bugs to be shot on sight!") { |
|
| 532 | + $defaultvalues .="APPEARANCE/MOTD "; |
|
| 533 | + } |
|
| 534 | + if (Config::$APPEARANCE['webcert_CRLDP'] == ['list', 'of', 'CRL', 'pointers']) { |
|
| 535 | + $defaultvalues .="APPEARANCE/webcert_CRLDP "; |
|
| 536 | + } |
|
| 537 | + if (empty(Config::$APPEARANCE['webcert_OCSP'])) { |
|
| 538 | + $missingvalues .="APPEARANCE/webcert_OCSP "; |
|
| 539 | + } elseif (Config::$APPEARANCE['webcert_OCSP'] == ['list', 'of', 'OCSP', 'pointers']) { |
|
| 540 | + $defaultvalues .="APPEARANCE/webcert_OCSP "; |
|
| 541 | + } |
|
| 542 | + if (isset(Config::$RADIUSTESTS['UDP-hosts'][0]) && Config::$RADIUSTESTS['UDP-hosts'][0]['ip'] == "192.0.2.1") { |
|
| 543 | + $defaultvalues .="RADIUSTESTS/UDP-hosts "; |
|
| 544 | + } |
|
| 545 | + if (Config::$DB['INST']['host'] == "db.host.example") { |
|
| 546 | + $defaultvalues .="DB/INST "; |
|
| 547 | + } |
|
| 548 | + if (Config::$DB['INST']['host'] == "db.host.example") { |
|
| 549 | + $defaultvalues .="DB/USER "; |
|
| 550 | + } |
|
| 551 | + if(!empty(Config::$DB['EXTERNAL']) && Config::$DB['EXTERNAL']['host'] == "customerdb.otherhost.example") { |
|
| 552 | + $defaultvalues .="DB/EXTERNAL "; |
|
| 553 | + } |
|
| 514 | 554 | $files = []; |
| 515 | 555 | foreach (Config::$RADIUSTESTS['TLS-clientcerts'] as $cadata) { |
| 516 | 556 | foreach ($cadata['certificates'] as $cert_files) { |
@@ -521,15 +561,17 @@ discard block |
||
| 521 | 561 | |
| 522 | 562 | foreach ($files as $file) { |
| 523 | 563 | $handle = fopen(CAT::$root . "/config/cli-certs/" . $file, 'r'); |
| 524 | - if (!$handle) |
|
| 525 | - $defaultvalues .="CERTIFICATE/$file "; |
|
| 526 | - else |
|
| 527 | - fclose($handle); |
|
| 564 | + if (!$handle) { |
|
| 565 | + $defaultvalues .="CERTIFICATE/$file "; |
|
| 566 | + } else { |
|
| 567 | + fclose($handle); |
|
| 568 | + } |
|
| 569 | + } |
|
| 570 | + if ($defaultvalues != "") { |
|
| 571 | + $this->test_return(L_WARN,"Your configuration in config/config.php contains unchanged default values or links to inexistent files: <strong>$defaultvalues</strong>!"); |
|
| 572 | + } else { |
|
| 573 | + $this->test_return(L_OK,"Your configuration does not contain any unchanged defaults, which is a good sign."); |
|
| 528 | 574 | } |
| 529 | - if ($defaultvalues != "") |
|
| 530 | - $this->test_return(L_WARN,"Your configuration in config/config.php contains unchanged default values or links to inexistent files: <strong>$defaultvalues</strong>!"); |
|
| 531 | - else |
|
| 532 | - $this->test_return(L_OK,"Your configuration does not contain any unchanged defaults, which is a good sign."); |
|
| 533 | 575 | } |
| 534 | 576 | |
| 535 | 577 | /** |
@@ -542,10 +584,11 @@ discard block |
||
| 542 | 584 | $this->test_return(L_ERROR,"Connection to the $DB database failed"); |
| 543 | 585 | } else { |
| 544 | 586 | $r = mysqli_query($db,'select * from profile_option_dict'); |
| 545 | - if($r->num_rows == $this->profile_option_ct) |
|
| 546 | - $this->test_return(L_OK,"The $DB database appears to be OK."); |
|
| 547 | - else |
|
| 548 | - $this->test_return(L_ERROR,"The $DB database is reacheable but probably not updated to this version of CAT."); |
|
| 587 | + if($r->num_rows == $this->profile_option_ct) { |
|
| 588 | + $this->test_return(L_OK,"The $DB database appears to be OK."); |
|
| 589 | + } else { |
|
| 590 | + $this->test_return(L_ERROR,"The $DB database is reacheable but probably not updated to this version of CAT."); |
|
| 591 | + } |
|
| 549 | 592 | } |
| 550 | 593 | $DB = 'USER'; |
| 551 | 594 | $db = mysqli_connect(Config::$DB[$DB]['host'], Config::$DB[$DB]['user'], Config::$DB[$DB]['pass'], Config::$DB[$DB]['db']); |
@@ -553,10 +596,11 @@ discard block |
||
| 553 | 596 | $this->test_return(L_ERROR,"Connection to the $DB database failed"); |
| 554 | 597 | } else { |
| 555 | 598 | $r = mysqli_query($db,'desc view_admin'); |
| 556 | - if($r->num_rows == $this->view_admin_ct) |
|
| 557 | - $this->test_return(L_OK,"The $DB database appears to be OK."); |
|
| 558 | - else |
|
| 559 | - $this->test_return(L_ERROR,"The $DB is reacheable but there is something wrong with the schema"); |
|
| 599 | + if($r->num_rows == $this->view_admin_ct) { |
|
| 600 | + $this->test_return(L_OK,"The $DB database appears to be OK."); |
|
| 601 | + } else { |
|
| 602 | + $this->test_return(L_ERROR,"The $DB is reacheable but there is something wrong with the schema"); |
|
| 603 | + } |
|
| 560 | 604 | } |
| 561 | 605 | $DB = 'EXTERNAL'; |
| 562 | 606 | if(! empty(Config::$DB[$DB])) { |
@@ -565,10 +609,11 @@ discard block |
||
| 565 | 609 | $this->test_return(L_ERROR,"Connection to the $DB database failed"); |
| 566 | 610 | } else { |
| 567 | 611 | $r = mysqli_query($db,'desc view_admin'); |
| 568 | - if($r->num_rows == $this->view_admin_ct) |
|
| 569 | - $this->test_return(L_OK,"The $DB database appears to be OK."); |
|
| 570 | - else |
|
| 571 | - $this->test_return(L_ERROR,"The $DB is reacheable but there is something wrong with the schema"); |
|
| 612 | + if($r->num_rows == $this->view_admin_ct) { |
|
| 613 | + $this->test_return(L_OK,"The $DB database appears to be OK."); |
|
| 614 | + } else { |
|
| 615 | + $this->test_return(L_ERROR,"The $DB is reacheable but there is something wrong with the schema"); |
|
| 616 | + } |
|
| 572 | 617 | } |
| 573 | 618 | } |
| 574 | 619 | } |
@@ -578,13 +623,15 @@ discard block |
||
| 578 | 623 | * test devices.php for the no_cache option |
| 579 | 624 | */ |
| 580 | 625 | private function device_cache_test() { |
| 581 | - if((! empty(Devices::$Options['no_cache'])) && Devices::$Options['no_cache']) |
|
| 582 | - $global_no_cache = 1; |
|
| 583 | - else |
|
| 584 | - $global_no_cache = 0; |
|
| 626 | + if((! empty(Devices::$Options['no_cache'])) && Devices::$Options['no_cache']) { |
|
| 627 | + $global_no_cache = 1; |
|
| 628 | + } else { |
|
| 629 | + $global_no_cache = 0; |
|
| 630 | + } |
|
| 585 | 631 | |
| 586 | - if($global_no_cache == 1) |
|
| 587 | - $this->test_return(L_WARN,"Devices no_cache global option is set, this is not a good idea in a production setting\n"); |
|
| 632 | + if($global_no_cache == 1) { |
|
| 633 | + $this->test_return(L_WARN,"Devices no_cache global option is set, this is not a good idea in a production setting\n"); |
|
| 634 | + } |
|
| 588 | 635 | $Devs = Devices::listDevices(); |
| 589 | 636 | $no_cache_dev = ''; |
| 590 | 637 | $no_cache_dev_count = 0; |
@@ -605,10 +652,12 @@ discard block |
||
| 605 | 652 | } |
| 606 | 653 | |
| 607 | 654 | |
| 608 | - if($no_cache_dev_count > 1 ) |
|
| 609 | - $this->test_return(L_WARN,"The following devices will not be cached: $no_cache_dev"); |
|
| 610 | - if($no_cache_dev_count == 1 ) |
|
| 611 | - $this->test_return(L_WARN,"The following device will not be cached: $no_cache_dev"); |
|
| 655 | + if($no_cache_dev_count > 1 ) { |
|
| 656 | + $this->test_return(L_WARN,"The following devices will not be cached: $no_cache_dev"); |
|
| 657 | + } |
|
| 658 | + if($no_cache_dev_count == 1 ) { |
|
| 659 | + $this->test_return(L_WARN,"The following device will not be cached: $no_cache_dev"); |
|
| 660 | + } |
|
| 612 | 661 | |
| 613 | 662 | } |
| 614 | 663 | |
@@ -637,10 +686,11 @@ discard block |
||
| 637 | 686 | $mail->Subject = "testing CAT configuration mail"; |
| 638 | 687 | $mail->Body = "Testing CAT mailing\n"; |
| 639 | 688 | $sent = $mail->send(); |
| 640 | - if($sent) |
|
| 641 | - $this->test_return(L_OK,"mailer settings appear to be working, check ".Config::$APPEARANCE['abuse-mail']." mailbox if the message was receiced."); |
|
| 642 | - else |
|
| 643 | - $this->test_return(L_ERROR,"mailer settings failed, check the Config::MAILSETTINGS"); |
|
| 689 | + if($sent) { |
|
| 690 | + $this->test_return(L_OK,"mailer settings appear to be working, check ".Config::$APPEARANCE['abuse-mail']." mailbox if the message was receiced."); |
|
| 691 | + } else { |
|
| 692 | + $this->test_return(L_ERROR,"mailer settings failed, check the Config::MAILSETTINGS"); |
|
| 693 | + } |
|
| 644 | 694 | |
| 645 | 695 | } |
| 646 | 696 | |
@@ -45,13 +45,13 @@ discard block |
||
| 45 | 45 | |
| 46 | 46 | /* List all required NSIS modules below */ |
| 47 | 47 | private $NSIS_Modules = [ |
| 48 | - "nsArray.nsh", |
|
| 49 | - "FileFunc.nsh", |
|
| 50 | - "LogicLib.nsh", |
|
| 51 | - "WordFunc.nsh", |
|
| 52 | - "FileFunc.nsh", |
|
| 53 | - "x64.nsh", |
|
| 54 | - ]; |
|
| 48 | + "nsArray.nsh", |
|
| 49 | + "FileFunc.nsh", |
|
| 50 | + "LogicLib.nsh", |
|
| 51 | + "WordFunc.nsh", |
|
| 52 | + "FileFunc.nsh", |
|
| 53 | + "x64.nsh", |
|
| 54 | + ]; |
|
| 55 | 55 | |
| 56 | 56 | /* set $profile_option_ct to the number of rows returned by "SELECT * FROM profile_option_dict" */ |
| 57 | 57 | private $profile_option_ct = 28; |
@@ -64,9 +64,9 @@ discard block |
||
| 64 | 64 | public $name; |
| 65 | 65 | |
| 66 | 66 | public function __construct() { |
| 67 | - parent::__construct(); |
|
| 68 | - $this->test_result = []; |
|
| 69 | - $this->test_result['global'] = 0; |
|
| 67 | + parent::__construct(); |
|
| 68 | + $this->test_result = []; |
|
| 69 | + $this->test_result['global'] = 0; |
|
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | /** |
@@ -74,15 +74,15 @@ discard block |
||
| 74 | 74 | * @param string $test the test name |
| 75 | 75 | */ |
| 76 | 76 | public function test($test) { |
| 77 | - $this->out[$test] =[]; |
|
| 78 | - $this->name = $test; |
|
| 79 | - $m_name = $test.'_test'; |
|
| 80 | - $this->test_result[$test] = 0; |
|
| 81 | - if(! method_exists($this,$m_name)) { |
|
| 82 | - $this->test_return($test,L_ERROR,"Configuration error, no test configured for <strong>$test</strong>."); |
|
| 83 | - return; |
|
| 84 | - } |
|
| 85 | - $this->$m_name(); |
|
| 77 | + $this->out[$test] =[]; |
|
| 78 | + $this->name = $test; |
|
| 79 | + $m_name = $test.'_test'; |
|
| 80 | + $this->test_result[$test] = 0; |
|
| 81 | + if(! method_exists($this,$m_name)) { |
|
| 82 | + $this->test_return($test,L_ERROR,"Configuration error, no test configured for <strong>$test</strong>."); |
|
| 83 | + return; |
|
| 84 | + } |
|
| 85 | + $this->$m_name(); |
|
| 86 | 86 | } |
| 87 | 87 | |
| 88 | 88 | /** |
@@ -95,27 +95,27 @@ discard block |
||
| 95 | 95 | * and returned a success. |
| 96 | 96 | */ |
| 97 | 97 | public function run_tests($Tests) { |
| 98 | - foreach ($Tests as $t) { |
|
| 99 | - if(preg_match('/(.+)=>(.+)/',$t,$m)) { |
|
| 98 | + foreach ($Tests as $t) { |
|
| 99 | + if(preg_match('/(.+)=>(.+)/',$t,$m)) { |
|
| 100 | 100 | $tst = $m[1]; |
| 101 | 101 | $subtst=$m[2]; |
| 102 | 102 | if($this->test_result[$tst] < L_ERROR) |
| 103 | - $this->test($subtst); |
|
| 104 | - } |
|
| 105 | - else |
|
| 103 | + $this->test($subtst); |
|
| 104 | + } |
|
| 105 | + else |
|
| 106 | 106 | $this->test($t); |
| 107 | - } |
|
| 107 | + } |
|
| 108 | 108 | } |
| 109 | 109 | |
| 110 | 110 | public function get_test_names() { |
| 111 | - $T = get_class_methods($this); |
|
| 112 | - $out = []; |
|
| 113 | - foreach($T as $t) { |
|
| 114 | - if(preg_match('/^(.*)_test$/',$t,$m)) { |
|
| 111 | + $T = get_class_methods($this); |
|
| 112 | + $out = []; |
|
| 113 | + foreach($T as $t) { |
|
| 114 | + if(preg_match('/^(.*)_test$/',$t,$m)) { |
|
| 115 | 115 | $out[] = $m[1]; |
| 116 | - } |
|
| 117 | - } |
|
| 118 | - return $out; |
|
| 116 | + } |
|
| 117 | + } |
|
| 118 | + return $out; |
|
| 119 | 119 | } |
| 120 | 120 | |
| 121 | 121 | /** |
@@ -141,84 +141,84 @@ discard block |
||
| 141 | 141 | $the_path = ""; |
| 142 | 142 | $exec_is = "UNDEFINED"; |
| 143 | 143 | if (!empty(Config::$PATHS[$s])) { |
| 144 | - preg_match('/([^ ]+) ?/',Config::$PATHS[$s],$m); |
|
| 145 | - $exe = $m[1]; |
|
| 146 | - $the_path = exec("which " . Config::$PATHS[$s]); |
|
| 147 | - if ($the_path == $exe) |
|
| 148 | - $exec_is = "EXPLICIT"; |
|
| 149 | - else |
|
| 150 | - $exec_is = "IMPLICIT"; |
|
| 151 | - } |
|
| 144 | + preg_match('/([^ ]+) ?/',Config::$PATHS[$s],$m); |
|
| 145 | + $exe = $m[1]; |
|
| 146 | + $the_path = exec("which " . Config::$PATHS[$s]); |
|
| 147 | + if ($the_path == $exe) |
|
| 148 | + $exec_is = "EXPLICIT"; |
|
| 149 | + else |
|
| 150 | + $exec_is = "IMPLICIT"; |
|
| 151 | + } |
|
| 152 | 152 | return(['exec'=>$the_path,'exec_is'=>$exec_is]); |
| 153 | 153 | } |
| 154 | 154 | |
| 155 | 155 | /** |
| 156 | - * Test for php version |
|
| 157 | - */ |
|
| 156 | + * Test for php version |
|
| 157 | + */ |
|
| 158 | 158 | private function php_test() { |
| 159 | - if (version_compare(phpversion(), $this->php_needversion, '>=')) |
|
| 159 | + if (version_compare(phpversion(), $this->php_needversion, '>=')) |
|
| 160 | 160 | $this->test_return(L_OK,"<strong>PHP</strong> is sufficiently recent. You are running " . phpversion() . "."); |
| 161 | - else |
|
| 161 | + else |
|
| 162 | 162 | $this->test_return(L_ERROR,"<strong>PHP</strong> is too old. We need at least $this->php_needversion, but you only have ".phpversion(). "."); |
| 163 | 163 | } |
| 164 | 164 | |
| 165 | 165 | /** |
| 166 | - * test for simpleSAMLphp |
|
| 167 | - */ |
|
| 166 | + * test for simpleSAMLphp |
|
| 167 | + */ |
|
| 168 | 168 | private function ssp_test() { |
| 169 | - if (!is_file(CONFIG::$AUTHENTICATION['ssp-path-to-autoloader'])) |
|
| 170 | - $this->test_return(L_ERROR,"<strong>simpleSAMLphp</strong> not found!"); |
|
| 171 | - else |
|
| 172 | - $this->test_return(L_OK,"<strong>simpleSAMLphp</strong> autoloader found."); |
|
| 169 | + if (!is_file(CONFIG::$AUTHENTICATION['ssp-path-to-autoloader'])) |
|
| 170 | + $this->test_return(L_ERROR,"<strong>simpleSAMLphp</strong> not found!"); |
|
| 171 | + else |
|
| 172 | + $this->test_return(L_OK,"<strong>simpleSAMLphp</strong> autoloader found."); |
|
| 173 | 173 | } |
| 174 | 174 | |
| 175 | 175 | /** |
| 176 | - * test for security setting |
|
| 177 | - */ |
|
| 176 | + * test for security setting |
|
| 177 | + */ |
|
| 178 | 178 | private function security_test() { |
| 179 | - if (in_array("I do not care about security!", Config::$SUPERADMINS)) |
|
| 180 | - $this->test_return(L_WARN,"You do not care about security. This page should be made accessible to the CAT admin only! See config.php 'Superadmins'!"); |
|
| 179 | + if (in_array("I do not care about security!", Config::$SUPERADMINS)) |
|
| 180 | + $this->test_return(L_WARN,"You do not care about security. This page should be made accessible to the CAT admin only! See config.php 'Superadmins'!"); |
|
| 181 | 181 | } |
| 182 | 182 | |
| 183 | 183 | /** |
| 184 | - * test if zip is available |
|
| 185 | - */ |
|
| 184 | + * test if zip is available |
|
| 185 | + */ |
|
| 186 | 186 | private function zip_test() { |
| 187 | - if (exec("which zip") != "") |
|
| 188 | - $this->test_return(L_OK,"<strong>zip</strong> binary found."); |
|
| 189 | - else |
|
| 190 | - $this->test_return(L_ERROR,"<strong>zip</strong> not found in your \$PATH!"); |
|
| 187 | + if (exec("which zip") != "") |
|
| 188 | + $this->test_return(L_OK,"<strong>zip</strong> binary found."); |
|
| 189 | + else |
|
| 190 | + $this->test_return(L_ERROR,"<strong>zip</strong> not found in your \$PATH!"); |
|
| 191 | 191 | } |
| 192 | 192 | |
| 193 | 193 | /** |
| 194 | - * test if eapol_test is availabe and reacent enough |
|
| 195 | - */ |
|
| 194 | + * test if eapol_test is availabe and reacent enough |
|
| 195 | + */ |
|
| 196 | 196 | private function eapol_test_test() { |
| 197 | - exec(Config::$PATHS['eapol_test'], $out, $retval); |
|
| 198 | - if($retval == 255 ) { |
|
| 197 | + exec(Config::$PATHS['eapol_test'], $out, $retval); |
|
| 198 | + if($retval == 255 ) { |
|
| 199 | 199 | $o = preg_grep('/-o<server cert/',$out); |
| 200 | - if(count($o) > 0) |
|
| 201 | - $this->test_return(L_OK,"<strong>eapol_test</strong> script found."); |
|
| 202 | - else |
|
| 203 | - $this->test_return(L_ERROR,"<strong>eapol_test</strong> found, but is too old!"); |
|
| 204 | - } |
|
| 205 | - else |
|
| 200 | + if(count($o) > 0) |
|
| 201 | + $this->test_return(L_OK,"<strong>eapol_test</strong> script found."); |
|
| 202 | + else |
|
| 203 | + $this->test_return(L_ERROR,"<strong>eapol_test</strong> found, but is too old!"); |
|
| 204 | + } |
|
| 205 | + else |
|
| 206 | 206 | $this->test_return(L_ERROR,"<strong>eapol_test</strong> not found!"); |
| 207 | 207 | } |
| 208 | 208 | |
| 209 | 209 | /** |
| 210 | - * test if logdir exists and is writable |
|
| 211 | - */ |
|
| 210 | + * test if logdir exists and is writable |
|
| 211 | + */ |
|
| 212 | 212 | private function logdir_test() { |
| 213 | - if (fopen(Config::$PATHS['logdir'] . "/debug.log", "a") == FALSE) |
|
| 214 | - $this->test_return(L_WARN,"Log files in <strong>" . Config::$PATHS['logdir'] . "</strong> are not writable!"); |
|
| 215 | - else |
|
| 216 | - $this->test_return(L_OK,"Log directory is writable."); |
|
| 213 | + if (fopen(Config::$PATHS['logdir'] . "/debug.log", "a") == FALSE) |
|
| 214 | + $this->test_return(L_WARN,"Log files in <strong>" . Config::$PATHS['logdir'] . "</strong> are not writable!"); |
|
| 215 | + else |
|
| 216 | + $this->test_return(L_OK,"Log directory is writable."); |
|
| 217 | 217 | } |
| 218 | 218 | |
| 219 | 219 | /** |
| 220 | - * test for required PHP modules |
|
| 221 | - */ |
|
| 220 | + * test for required PHP modules |
|
| 221 | + */ |
|
| 222 | 222 | private function phpModules_test() { |
| 223 | 223 | if (function_exists('idn_to_ascii')) |
| 224 | 224 | $this->test_return(L_OK,"PHP can handle internationalisation."); |
@@ -228,7 +228,7 @@ discard block |
||
| 228 | 228 | if (function_exists('gettext')) |
| 229 | 229 | $this->test_return(L_OK,"PHP extension <strong>GNU Gettext</strong> is installed."); |
| 230 | 230 | else |
| 231 | - $this->test_return(L_ERROR,"PHP extension <strong>GNU Gettext</strong> not found!"); |
|
| 231 | + $this->test_return(L_ERROR,"PHP extension <strong>GNU Gettext</strong> not found!"); |
|
| 232 | 232 | |
| 233 | 233 | if (function_exists('openssl_sign')) |
| 234 | 234 | $this->test_return(L_OK,"PHP extension <strong>OpenSSL</strong> is installed."); |
@@ -270,193 +270,193 @@ discard block |
||
| 270 | 270 | */ |
| 271 | 271 | |
| 272 | 272 | private function geoip_test() { |
| 273 | - $host_4 = '145.0.2.50'; |
|
| 274 | - $host_6 = '2001:610:188:444::50'; |
|
| 275 | - switch (Config::$GEOIP['version']) { |
|
| 276 | - case 0: |
|
| 273 | + $host_4 = '145.0.2.50'; |
|
| 274 | + $host_6 = '2001:610:188:444::50'; |
|
| 275 | + switch (Config::$GEOIP['version']) { |
|
| 276 | + case 0: |
|
| 277 | 277 | $this->test_return(L_REMARK,"As set in the config, no geolocation service will be used"); |
| 278 | - break; |
|
| 279 | - case 1: |
|
| 278 | + break; |
|
| 279 | + case 1: |
|
| 280 | 280 | if (!function_exists('geoip_record_by_name')) { |
| 281 | - $this->test_return(L_ERROR,"PHP extension <strong>GeoIP</strong> (legacy) not found! Get it from your distribution or <a href='http://pecl.php.net/package/geoip'>here</a> or better install GeoIP2 from <a href='https://github.com/maxmind/GeoIP2-php'>here</a>."); |
|
| 282 | - return; |
|
| 283 | - } |
|
| 284 | - $record = geoip_record_by_name($host_4); |
|
| 285 | - if(! $record) { |
|
| 286 | - $this->test_return(L_ERROR,"PHP extension <strong>GeoIP</strong> (legacy) found but not working properly, perhaps you need to download the databases. See utils/GeoIP-update.sh in the CAT distribution and use it tu update the GeoIP database regularly."); |
|
| 287 | - return; |
|
| 288 | - } |
|
| 289 | - if($record['city'] != 'Utrecht') { |
|
| 290 | - $this->test_return(L_ERROR,"PHP extension <strong>GeoIP</strong> (legacy) found but not working properly, perhaps you need to download the databases. See utils/GeoIP-update.sh in the CAT distribution and use it tu update the GeoIP database regularly."); |
|
| 291 | - return; |
|
| 292 | - } |
|
| 293 | - $this->test_return(L_REMARK,"PHP extension <strong>GeoIP</strong> (legacy) is installed and working. See utils/GeoIP-update.sh in the CAT distribution and use it tu update the GeoIP database regularly. We stronly advise to replace the legacy GeoIP with GeoIP2 from <a href='https://github.com/maxmind/GeoIP2-php'>here</a>."); |
|
| 294 | - break; |
|
| 295 | - case 2: |
|
| 281 | + $this->test_return(L_ERROR,"PHP extension <strong>GeoIP</strong> (legacy) not found! Get it from your distribution or <a href='http://pecl.php.net/package/geoip'>here</a> or better install GeoIP2 from <a href='https://github.com/maxmind/GeoIP2-php'>here</a>."); |
|
| 282 | + return; |
|
| 283 | + } |
|
| 284 | + $record = geoip_record_by_name($host_4); |
|
| 285 | + if(! $record) { |
|
| 286 | + $this->test_return(L_ERROR,"PHP extension <strong>GeoIP</strong> (legacy) found but not working properly, perhaps you need to download the databases. See utils/GeoIP-update.sh in the CAT distribution and use it tu update the GeoIP database regularly."); |
|
| 287 | + return; |
|
| 288 | + } |
|
| 289 | + if($record['city'] != 'Utrecht') { |
|
| 290 | + $this->test_return(L_ERROR,"PHP extension <strong>GeoIP</strong> (legacy) found but not working properly, perhaps you need to download the databases. See utils/GeoIP-update.sh in the CAT distribution and use it tu update the GeoIP database regularly."); |
|
| 291 | + return; |
|
| 292 | + } |
|
| 293 | + $this->test_return(L_REMARK,"PHP extension <strong>GeoIP</strong> (legacy) is installed and working. See utils/GeoIP-update.sh in the CAT distribution and use it tu update the GeoIP database regularly. We stronly advise to replace the legacy GeoIP with GeoIP2 from <a href='https://github.com/maxmind/GeoIP2-php'>here</a>."); |
|
| 294 | + break; |
|
| 295 | + case 2: |
|
| 296 | 296 | if(! is_file(Config::$GEOIP['geoip2-path-to-autoloader'])) { |
| 297 | - $this->test_return(L_ERROR,"PHP extension <strong>GeoIP2</strong> not found! Get it from <a href='https://github.com/maxmind/GeoIP2-php'>here</a>."); |
|
| 298 | - return; |
|
| 299 | - } |
|
| 300 | - if(! is_file(Config::$GEOIP['geoip2-path-to-db'])) { |
|
| 301 | - $this->test_return(L_ERROR,"<strong>GeoIP2 database</strong> not found! See utils/GeoIP-update.sh in the CAT distribution and use it tu update the GeoIP database regularly."); |
|
| 302 | - return; |
|
| 303 | - } |
|
| 304 | - require_once Config::$GEOIP['geoip2-path-to-autoloader']; |
|
| 305 | - $reader = new Reader(Config::$GEOIP['geoip2-path-to-db']); |
|
| 306 | - try { |
|
| 307 | - $record = $reader->city($host_4); |
|
| 308 | - } catch (Exception $e) { |
|
| 309 | - $this->test_return(L_ERROR,"PHP extension <strong>GeoIP2</strong> found but not working properly, perhaps you need to download the databases. See utils/GeoIP-update.sh in the CAT distribution and use it tu update the GeoIP database regularly."); |
|
| 310 | - return; |
|
| 311 | - } |
|
| 312 | - if( $record->city->name != 'Utrecht') { |
|
| 313 | - $this->test_return(L_ERROR,"PHP extension <strong>GeoIP2</strong> found but not working properly, perhaps you need to download the databases. See utils/GeoIP-update.sh in the CAT distribution and use it tu update the GeoIP database regularly."); |
|
| 314 | - return; |
|
| 315 | - } |
|
| 316 | - try { |
|
| 317 | - $record = $reader->city($host_6); |
|
| 318 | - } catch (Exception $e) { |
|
| 319 | - $this->test_return(L_ERROR,"PHP extension <strong>GeoIP2</strong> found but not working properly with IPv6, perhaps you need to download the databases. See utils/GeoIP-update.sh in the CAT distribution and use it tu update the GeoIP database regularly."); |
|
| 320 | - return; |
|
| 321 | - } |
|
| 322 | - if( $record->city->name != 'Utrecht') { |
|
| 323 | - $this->test_return(L_ERROR,"PHP extension <strong>GeoIP2</strong> found but not working properly with IPv6, perhaps you need to download the databases. See utils/GeoIP-update.sh in the CAT distribution and use it tu update the GeoIP database regularly."); |
|
| 324 | - return; |
|
| 325 | - } |
|
| 326 | - $this->test_return(L_OK,"PHP extension <strong>GeoIP2</strong> is installed and working. See utils/GeoIP-update.sh in the CAT distribution and use it tu update the GeoIP database regularly."); |
|
| 327 | - break; |
|
| 328 | - default: |
|
| 297 | + $this->test_return(L_ERROR,"PHP extension <strong>GeoIP2</strong> not found! Get it from <a href='https://github.com/maxmind/GeoIP2-php'>here</a>."); |
|
| 298 | + return; |
|
| 299 | + } |
|
| 300 | + if(! is_file(Config::$GEOIP['geoip2-path-to-db'])) { |
|
| 301 | + $this->test_return(L_ERROR,"<strong>GeoIP2 database</strong> not found! See utils/GeoIP-update.sh in the CAT distribution and use it tu update the GeoIP database regularly."); |
|
| 302 | + return; |
|
| 303 | + } |
|
| 304 | + require_once Config::$GEOIP['geoip2-path-to-autoloader']; |
|
| 305 | + $reader = new Reader(Config::$GEOIP['geoip2-path-to-db']); |
|
| 306 | + try { |
|
| 307 | + $record = $reader->city($host_4); |
|
| 308 | + } catch (Exception $e) { |
|
| 309 | + $this->test_return(L_ERROR,"PHP extension <strong>GeoIP2</strong> found but not working properly, perhaps you need to download the databases. See utils/GeoIP-update.sh in the CAT distribution and use it tu update the GeoIP database regularly."); |
|
| 310 | + return; |
|
| 311 | + } |
|
| 312 | + if( $record->city->name != 'Utrecht') { |
|
| 313 | + $this->test_return(L_ERROR,"PHP extension <strong>GeoIP2</strong> found but not working properly, perhaps you need to download the databases. See utils/GeoIP-update.sh in the CAT distribution and use it tu update the GeoIP database regularly."); |
|
| 314 | + return; |
|
| 315 | + } |
|
| 316 | + try { |
|
| 317 | + $record = $reader->city($host_6); |
|
| 318 | + } catch (Exception $e) { |
|
| 319 | + $this->test_return(L_ERROR,"PHP extension <strong>GeoIP2</strong> found but not working properly with IPv6, perhaps you need to download the databases. See utils/GeoIP-update.sh in the CAT distribution and use it tu update the GeoIP database regularly."); |
|
| 320 | + return; |
|
| 321 | + } |
|
| 322 | + if( $record->city->name != 'Utrecht') { |
|
| 323 | + $this->test_return(L_ERROR,"PHP extension <strong>GeoIP2</strong> found but not working properly with IPv6, perhaps you need to download the databases. See utils/GeoIP-update.sh in the CAT distribution and use it tu update the GeoIP database regularly."); |
|
| 324 | + return; |
|
| 325 | + } |
|
| 326 | + $this->test_return(L_OK,"PHP extension <strong>GeoIP2</strong> is installed and working. See utils/GeoIP-update.sh in the CAT distribution and use it tu update the GeoIP database regularly."); |
|
| 327 | + break; |
|
| 328 | + default: |
|
| 329 | 329 | $this->test_return(L_ERROR,'Check Config::$GEOIP[\'version\'], it must be set to either 1 or 2'); |
| 330 | - break; |
|
| 331 | - } |
|
| 330 | + break; |
|
| 331 | + } |
|
| 332 | 332 | } |
| 333 | 333 | |
| 334 | 334 | /** |
| 335 | - * test if openssl is available |
|
| 336 | - */ |
|
| 335 | + * test if openssl is available |
|
| 336 | + */ |
|
| 337 | 337 | private function openssl_test() { |
| 338 | - $A = $this->get_exec_path('openssl'); |
|
| 339 | - if($A['exec'] != "") { |
|
| 340 | - $t = exec($A['exec'] . ' version'); |
|
| 341 | - if($A['exec_is'] == "EXPLICIT") |
|
| 338 | + $A = $this->get_exec_path('openssl'); |
|
| 339 | + if($A['exec'] != "") { |
|
| 340 | + $t = exec($A['exec'] . ' version'); |
|
| 341 | + if($A['exec_is'] == "EXPLICIT") |
|
| 342 | 342 | $this->test_return(L_OK,"<strong>$t</strong> was found and is configured explicitly in your config."); |
| 343 | - else |
|
| 343 | + else |
|
| 344 | 344 | $this->test_return(L_WARN,"<strong>$t</strong> was found, but is not configured with an absolute path in your config."); |
| 345 | - } else |
|
| 345 | + } else |
|
| 346 | 346 | $this->test_return(L_ERROR,"<strong>openssl</strong> was not found on your system!"); |
| 347 | 347 | } |
| 348 | 348 | |
| 349 | 349 | /** |
| 350 | - * test if makensis is available |
|
| 351 | - */ |
|
| 350 | + * test if makensis is available |
|
| 351 | + */ |
|
| 352 | 352 | private function makensis_test() { |
| 353 | - if(! is_numeric(Config::$NSIS_VERSION)) { |
|
| 353 | + if(! is_numeric(Config::$NSIS_VERSION)) { |
|
| 354 | 354 | $this->test_return(L_ERROR,"NSIS_VERSION needs to be numeric!"); |
| 355 | 355 | return; |
| 356 | - } |
|
| 357 | - if(Config::$NSIS_VERSION < 2) { |
|
| 356 | + } |
|
| 357 | + if(Config::$NSIS_VERSION < 2) { |
|
| 358 | 358 | $this->test_return(L_ERROR,"NSIS_VERSION needs to be at least 2!"); |
| 359 | 359 | return; |
| 360 | - } |
|
| 361 | - $A = $this->get_exec_path('makensis'); |
|
| 362 | - if($A['exec'] != "") { |
|
| 363 | - $t = exec($A['exec'] . ' -VERSION'); |
|
| 364 | - if($A['exec_is'] == "EXPLICIT") |
|
| 360 | + } |
|
| 361 | + $A = $this->get_exec_path('makensis'); |
|
| 362 | + if($A['exec'] != "") { |
|
| 363 | + $t = exec($A['exec'] . ' -VERSION'); |
|
| 364 | + if($A['exec_is'] == "EXPLICIT") |
|
| 365 | 365 | $this->test_return(L_OK,"<strong>makensis $t</strong> was found and is configured explicitly in your config."); |
| 366 | - else |
|
| 366 | + else |
|
| 367 | 367 | $this->test_return(L_WARN,"<strong>makensis $t</strong> was found, but is not configured with an absolute path in your config."); |
| 368 | - exec($A['exec'] . ' -HELP',$t); |
|
| 369 | - $t1 = count(preg_grep('/INPUTCHARSET/',$t)); |
|
| 370 | - if($t1 == 1 && Config::$NSIS_VERSION == 2) |
|
| 368 | + exec($A['exec'] . ' -HELP',$t); |
|
| 369 | + $t1 = count(preg_grep('/INPUTCHARSET/',$t)); |
|
| 370 | + if($t1 == 1 && Config::$NSIS_VERSION == 2) |
|
| 371 | 371 | $this->test_return(L_ERROR,"Declared NSIS_VERSION does not seem to match the file pointed to by PATHS['makensis']!"); |
| 372 | - if($t1 == 0 && Config::$NSIS_VERSION >= 3) |
|
| 372 | + if($t1 == 0 && Config::$NSIS_VERSION >= 3) |
|
| 373 | 373 | $this->test_return(L_ERROR,"Declared NSIS_VERSION does not seem to match the file pointed to by PATHS['makensis']!"); |
| 374 | - } else |
|
| 374 | + } else |
|
| 375 | 375 | $this->test_return(L_ERROR,"<strong>makensis</strong> was not found on your system!"); |
| 376 | 376 | } |
| 377 | 377 | |
| 378 | 378 | /** |
| 379 | - * test if all required NSIS modules are available |
|
| 380 | - */ |
|
| 379 | + * test if all required NSIS modules are available |
|
| 380 | + */ |
|
| 381 | 381 | private function NSISmodules_test() { |
| 382 | - $tmp_dir = createTemporaryDirectory('installer',0)['dir']; |
|
| 383 | - if(!chdir($tmp_dir)) { |
|
| 384 | - debug(2, "Cannot chdir to $tmp_dir\n"); |
|
| 385 | - $this->test_return(L_ERROR,"NSIS modules test - problem with temporary directory permissions, cannot continue"); |
|
| 386 | - return; |
|
| 387 | - } |
|
| 388 | - $exe= 'tt.exe'; |
|
| 389 | - $NSIS_Module_status = []; |
|
| 390 | - foreach ($this->NSIS_Modules as $module) { |
|
| 382 | + $tmp_dir = createTemporaryDirectory('installer',0)['dir']; |
|
| 383 | + if(!chdir($tmp_dir)) { |
|
| 384 | + debug(2, "Cannot chdir to $tmp_dir\n"); |
|
| 385 | + $this->test_return(L_ERROR,"NSIS modules test - problem with temporary directory permissions, cannot continue"); |
|
| 386 | + return; |
|
| 387 | + } |
|
| 388 | + $exe= 'tt.exe'; |
|
| 389 | + $NSIS_Module_status = []; |
|
| 390 | + foreach ($this->NSIS_Modules as $module) { |
|
| 391 | 391 | unset($out); |
| 392 | 392 | exec(Config::$PATHS['makensis']." -V1 '-X!include $module' '-XOutFile $exe' '-XSection X' '-XSectionEnd'", $out, $retval); |
| 393 | 393 | if($retval > 0) |
| 394 | - $NSIS_Module_status[$module] = 0; |
|
| 394 | + $NSIS_Module_status[$module] = 0; |
|
| 395 | 395 | else |
| 396 | - $NSIS_Module_status[$module] = 1; |
|
| 397 | - } |
|
| 398 | - if(is_file($exe)) |
|
| 396 | + $NSIS_Module_status[$module] = 1; |
|
| 397 | + } |
|
| 398 | + if(is_file($exe)) |
|
| 399 | 399 | unlink($exe); |
| 400 | - foreach ($NSIS_Module_status as $module => $status) { |
|
| 400 | + foreach ($NSIS_Module_status as $module => $status) { |
|
| 401 | 401 | if($status == 1) |
| 402 | - $this->test_return(L_OK,"NSIS module <strong>$module</strong> was found."); |
|
| 402 | + $this->test_return(L_OK,"NSIS module <strong>$module</strong> was found."); |
|
| 403 | 403 | else |
| 404 | - $this->test_return(L_ERROR,"NSIS module <strong>$module</strong> was not found or is not working correctly."); |
|
| 405 | - } |
|
| 404 | + $this->test_return(L_ERROR,"NSIS module <strong>$module</strong> was not found or is not working correctly."); |
|
| 405 | + } |
|
| 406 | 406 | } |
| 407 | 407 | private function NSIS_GetVersion_test() { |
| 408 | - $tmp_dir = createTemporaryDirectory('installer',0)['dir']; |
|
| 409 | - if(!chdir($tmp_dir)) { |
|
| 410 | - debug(2, "Cannot chdir to $tmp_dir\n"); |
|
| 411 | - $this->test_return(L_ERROR,"NSIS module <strong>GetVersion</strong> - problem with temporary directory permissions, cannot continue"); |
|
| 412 | - return; |
|
| 413 | - } |
|
| 414 | - $exe= 'tt.exe'; |
|
| 415 | - exec(Config::$PATHS['makensis']." -V1 '-XOutFile $exe' '-XSection X' '-XGetVersion::WindowsName' '-XSectionEnd'", $out, $retval); |
|
| 416 | - if($retval > 0) |
|
| 408 | + $tmp_dir = createTemporaryDirectory('installer',0)['dir']; |
|
| 409 | + if(!chdir($tmp_dir)) { |
|
| 410 | + debug(2, "Cannot chdir to $tmp_dir\n"); |
|
| 411 | + $this->test_return(L_ERROR,"NSIS module <strong>GetVersion</strong> - problem with temporary directory permissions, cannot continue"); |
|
| 412 | + return; |
|
| 413 | + } |
|
| 414 | + $exe= 'tt.exe'; |
|
| 415 | + exec(Config::$PATHS['makensis']." -V1 '-XOutFile $exe' '-XSection X' '-XGetVersion::WindowsName' '-XSectionEnd'", $out, $retval); |
|
| 416 | + if($retval > 0) |
|
| 417 | 417 | $this->test_return(L_ERROR,"NSIS module <strong>GetVersion</strong> was not found or is not working correctly."); |
| 418 | - else |
|
| 418 | + else |
|
| 419 | 419 | $this->test_return(L_OK,"NSIS module <strong>GetVersion</strong> was found."); |
| 420 | - if(is_file($exe)) |
|
| 420 | + if(is_file($exe)) |
|
| 421 | 421 | unlink($exe); |
| 422 | 422 | } |
| 423 | 423 | |
| 424 | 424 | /** |
| 425 | - * test access to dowloads directories |
|
| 426 | - */ |
|
| 425 | + * test access to dowloads directories |
|
| 426 | + */ |
|
| 427 | 427 | private function directories_test() { |
| 428 | - $Dir = createTemporaryDirectory('installer',0); |
|
| 429 | - $dir = $Dir['dir']; |
|
| 430 | - $base = $Dir['base']; |
|
| 431 | - if($dir) { |
|
| 432 | - $this->test_return(L_OK,"Installer cache directory is writable."); |
|
| 433 | - rrmdir($dir); |
|
| 434 | - } else { |
|
| 435 | - $this->test_return(L_ERROR,"Installer cache directory $base does not exist or is not writable!"); |
|
| 436 | - } |
|
| 437 | - $Dir = createTemporaryDirectory('test',0); |
|
| 438 | - $dir = $Dir['dir']; |
|
| 439 | - $base = $Dir['base']; |
|
| 440 | - if($dir) { |
|
| 441 | - $this->test_return(L_OK,"Test directory is writable."); |
|
| 442 | - rrmdir($dir); |
|
| 443 | - } else { |
|
| 444 | - $this->test_return(L_ERROR,"Test directory $base does not exist or is not writable!"); |
|
| 445 | - } |
|
| 446 | - $Dir = createTemporaryDirectory('logo',0); |
|
| 447 | - $dir = $Dir['dir']; |
|
| 448 | - $base = $Dir['base']; |
|
| 449 | - if($dir) { |
|
| 450 | - $this->test_return(L_OK,"Logos cache directory is writable."); |
|
| 451 | - rrmdir($dir); |
|
| 452 | - } else { |
|
| 453 | - $this->test_return(L_ERROR,"Logos cache directory $base does not exist or is not writable!"); |
|
| 454 | - } |
|
| 428 | + $Dir = createTemporaryDirectory('installer',0); |
|
| 429 | + $dir = $Dir['dir']; |
|
| 430 | + $base = $Dir['base']; |
|
| 431 | + if($dir) { |
|
| 432 | + $this->test_return(L_OK,"Installer cache directory is writable."); |
|
| 433 | + rrmdir($dir); |
|
| 434 | + } else { |
|
| 435 | + $this->test_return(L_ERROR,"Installer cache directory $base does not exist or is not writable!"); |
|
| 436 | + } |
|
| 437 | + $Dir = createTemporaryDirectory('test',0); |
|
| 438 | + $dir = $Dir['dir']; |
|
| 439 | + $base = $Dir['base']; |
|
| 440 | + if($dir) { |
|
| 441 | + $this->test_return(L_OK,"Test directory is writable."); |
|
| 442 | + rrmdir($dir); |
|
| 443 | + } else { |
|
| 444 | + $this->test_return(L_ERROR,"Test directory $base does not exist or is not writable!"); |
|
| 445 | + } |
|
| 446 | + $Dir = createTemporaryDirectory('logo',0); |
|
| 447 | + $dir = $Dir['dir']; |
|
| 448 | + $base = $Dir['base']; |
|
| 449 | + if($dir) { |
|
| 450 | + $this->test_return(L_OK,"Logos cache directory is writable."); |
|
| 451 | + rrmdir($dir); |
|
| 452 | + } else { |
|
| 453 | + $this->test_return(L_ERROR,"Logos cache directory $base does not exist or is not writable!"); |
|
| 454 | + } |
|
| 455 | 455 | } |
| 456 | 456 | |
| 457 | 457 | /** |
| 458 | - * test if all required locales are enabled |
|
| 459 | - */ |
|
| 458 | + * test if all required locales are enabled |
|
| 459 | + */ |
|
| 460 | 460 | private function locales_test() { |
| 461 | 461 | $locales = shell_exec("locale -a"); |
| 462 | 462 | $allthere = ""; |
@@ -479,8 +479,8 @@ discard block |
||
| 479 | 479 | |
| 480 | 480 | |
| 481 | 481 | /** |
| 482 | - * test if detalts in the config have been replaced with some real values |
|
| 483 | - */ |
|
| 482 | + * test if detalts in the config have been replaced with some real values |
|
| 483 | + */ |
|
| 484 | 484 | private function defaults_test() { |
| 485 | 485 | $defaultvalues = ""; |
| 486 | 486 | $missingvalues = ""; |
@@ -531,121 +531,121 @@ discard block |
||
| 531 | 531 | $this->test_return(L_OK,"Your configuration does not contain any unchanged defaults, which is a good sign."); |
| 532 | 532 | } |
| 533 | 533 | |
| 534 | - /** |
|
| 534 | + /** |
|
| 535 | 535 | * test access to databases |
| 536 | 536 | */ |
| 537 | - private function databases_test() { |
|
| 537 | + private function databases_test() { |
|
| 538 | 538 | $DB = 'INST'; |
| 539 | 539 | $db = mysqli_connect(Config::$DB[$DB]['host'], Config::$DB[$DB]['user'], Config::$DB[$DB]['pass'], Config::$DB[$DB]['db']); |
| 540 | 540 | if(! $db) { |
| 541 | - $this->test_return(L_ERROR,"Connection to the $DB database failed"); |
|
| 541 | + $this->test_return(L_ERROR,"Connection to the $DB database failed"); |
|
| 542 | 542 | } else { |
| 543 | - $r = mysqli_query($db,'select * from profile_option_dict'); |
|
| 544 | - if($r->num_rows == $this->profile_option_ct) |
|
| 545 | - $this->test_return(L_OK,"The $DB database appears to be OK."); |
|
| 546 | - else |
|
| 547 | - $this->test_return(L_ERROR,"The $DB database is reacheable but probably not updated to this version of CAT."); |
|
| 543 | + $r = mysqli_query($db,'select * from profile_option_dict'); |
|
| 544 | + if($r->num_rows == $this->profile_option_ct) |
|
| 545 | + $this->test_return(L_OK,"The $DB database appears to be OK."); |
|
| 546 | + else |
|
| 547 | + $this->test_return(L_ERROR,"The $DB database is reacheable but probably not updated to this version of CAT."); |
|
| 548 | 548 | } |
| 549 | 549 | $DB = 'USER'; |
| 550 | 550 | $db = mysqli_connect(Config::$DB[$DB]['host'], Config::$DB[$DB]['user'], Config::$DB[$DB]['pass'], Config::$DB[$DB]['db']); |
| 551 | 551 | if(! $db) { |
| 552 | - $this->test_return(L_ERROR,"Connection to the $DB database failed"); |
|
| 552 | + $this->test_return(L_ERROR,"Connection to the $DB database failed"); |
|
| 553 | 553 | } else { |
| 554 | - $r = mysqli_query($db,'desc view_admin'); |
|
| 555 | - if($r->num_rows == $this->view_admin_ct) |
|
| 556 | - $this->test_return(L_OK,"The $DB database appears to be OK."); |
|
| 557 | - else |
|
| 558 | - $this->test_return(L_ERROR,"The $DB is reacheable but there is something wrong with the schema"); |
|
| 554 | + $r = mysqli_query($db,'desc view_admin'); |
|
| 555 | + if($r->num_rows == $this->view_admin_ct) |
|
| 556 | + $this->test_return(L_OK,"The $DB database appears to be OK."); |
|
| 557 | + else |
|
| 558 | + $this->test_return(L_ERROR,"The $DB is reacheable but there is something wrong with the schema"); |
|
| 559 | 559 | } |
| 560 | 560 | $DB = 'EXTERNAL'; |
| 561 | 561 | if(! empty(Config::$DB[$DB])) { |
| 562 | 562 | $db = mysqli_connect(Config::$DB[$DB]['host'], Config::$DB[$DB]['user'], Config::$DB[$DB]['pass'], Config::$DB[$DB]['db']); |
| 563 | 563 | if(! $db) { |
| 564 | - $this->test_return(L_ERROR,"Connection to the $DB database failed"); |
|
| 564 | + $this->test_return(L_ERROR,"Connection to the $DB database failed"); |
|
| 565 | 565 | } else { |
| 566 | - $r = mysqli_query($db,'desc view_admin'); |
|
| 567 | - if($r->num_rows == $this->view_admin_ct) |
|
| 568 | - $this->test_return(L_OK,"The $DB database appears to be OK."); |
|
| 569 | - else |
|
| 570 | - $this->test_return(L_ERROR,"The $DB is reacheable but there is something wrong with the schema"); |
|
| 566 | + $r = mysqli_query($db,'desc view_admin'); |
|
| 567 | + if($r->num_rows == $this->view_admin_ct) |
|
| 568 | + $this->test_return(L_OK,"The $DB database appears to be OK."); |
|
| 569 | + else |
|
| 570 | + $this->test_return(L_ERROR,"The $DB is reacheable but there is something wrong with the schema"); |
|
| 571 | 571 | } |
| 572 | 572 | } |
| 573 | - } |
|
| 573 | + } |
|
| 574 | 574 | |
| 575 | 575 | |
| 576 | - /** |
|
| 576 | + /** |
|
| 577 | 577 | * test devices.php for the no_cache option |
| 578 | 578 | */ |
| 579 | - private function device_cache_test() { |
|
| 580 | - if((! empty(Devices::$Options['no_cache'])) && Devices::$Options['no_cache']) |
|
| 581 | - $global_no_cache = 1; |
|
| 582 | - else |
|
| 583 | - $global_no_cache = 0; |
|
| 584 | - |
|
| 585 | - if($global_no_cache == 1) |
|
| 586 | - $this->test_return(L_WARN,"Devices no_cache global option is set, this is not a good idea in a production setting\n"); |
|
| 587 | - $Devs = Devices::listDevices(); |
|
| 588 | - $no_cache_dev = ''; |
|
| 589 | - $no_cache_dev_count = 0; |
|
| 590 | - if($global_no_cache) { |
|
| 591 | - foreach ($Devs as $dev=>$D) { |
|
| 592 | - if(empty($D['options']['no_cache']) || $D['options']['no_cache'] != 0) { |
|
| 579 | + private function device_cache_test() { |
|
| 580 | + if((! empty(Devices::$Options['no_cache'])) && Devices::$Options['no_cache']) |
|
| 581 | + $global_no_cache = 1; |
|
| 582 | + else |
|
| 583 | + $global_no_cache = 0; |
|
| 584 | + |
|
| 585 | + if($global_no_cache == 1) |
|
| 586 | + $this->test_return(L_WARN,"Devices no_cache global option is set, this is not a good idea in a production setting\n"); |
|
| 587 | + $Devs = Devices::listDevices(); |
|
| 588 | + $no_cache_dev = ''; |
|
| 589 | + $no_cache_dev_count = 0; |
|
| 590 | + if($global_no_cache) { |
|
| 591 | + foreach ($Devs as $dev=>$D) { |
|
| 592 | + if(empty($D['options']['no_cache']) || $D['options']['no_cache'] != 0) { |
|
| 593 | 593 | $no_cache_dev .= $dev." "; |
| 594 | 594 | $no_cache_dev_count++; |
| 595 | - } |
|
| 596 | - } |
|
| 597 | - } else { |
|
| 598 | - foreach ($Devs as $dev=>$D) { |
|
| 599 | - if(!empty($D['options']['no_cache']) && $D['options']['no_cache'] != 0) { |
|
| 595 | + } |
|
| 596 | + } |
|
| 597 | + } else { |
|
| 598 | + foreach ($Devs as $dev=>$D) { |
|
| 599 | + if(!empty($D['options']['no_cache']) && $D['options']['no_cache'] != 0) { |
|
| 600 | 600 | $no_cache_dev .= $dev." "; |
| 601 | 601 | $no_cache_dev_count++; |
| 602 | - } |
|
| 603 | - } |
|
| 604 | - } |
|
| 602 | + } |
|
| 603 | + } |
|
| 604 | + } |
|
| 605 | 605 | |
| 606 | 606 | |
| 607 | - if($no_cache_dev_count > 1 ) |
|
| 608 | - $this->test_return(L_WARN,"The following devices will not be cached: $no_cache_dev"); |
|
| 609 | - if($no_cache_dev_count == 1 ) |
|
| 610 | - $this->test_return(L_WARN,"The following device will not be cached: $no_cache_dev"); |
|
| 607 | + if($no_cache_dev_count > 1 ) |
|
| 608 | + $this->test_return(L_WARN,"The following devices will not be cached: $no_cache_dev"); |
|
| 609 | + if($no_cache_dev_count == 1 ) |
|
| 610 | + $this->test_return(L_WARN,"The following device will not be cached: $no_cache_dev"); |
|
| 611 | 611 | |
| 612 | - } |
|
| 612 | + } |
|
| 613 | 613 | |
| 614 | - /** |
|
| 614 | + /** |
|
| 615 | 615 | * test if mailer works |
| 616 | 616 | */ |
| 617 | - private function mailer_test() { |
|
| 618 | - if (empty(Config::$APPEARANCE['abuse-mail']) || Config::$APPEARANCE['abuse-mail'] == "[email protected]") { |
|
| 619 | - $this->test_return(L_ERROR,"Your abuse-mail has not been set, cannot continue with mailer tests."); |
|
| 620 | - return; |
|
| 621 | - } |
|
| 622 | - $mail = new PHPMailer\PHPMailer\PHPMailer(); |
|
| 623 | - $mail->isSMTP(); |
|
| 624 | - $mail->Port = 587; |
|
| 625 | - $mail->SMTPAuth = true; |
|
| 626 | - $mail->SMTPSecure = 'tls'; |
|
| 627 | - $mail->Host = Config::$MAILSETTINGS['host']; |
|
| 628 | - $mail->Username = Config::$MAILSETTINGS['user']; |
|
| 629 | - $mail->Password = Config::$MAILSETTINGS['pass']; |
|
| 630 | - $mail->WordWrap = 72; |
|
| 631 | - $mail->isHTML(FALSE); |
|
| 632 | - $mail->CharSet = 'UTF-8'; |
|
| 633 | - $mail->From = Config::$APPEARANCE['from-mail']; |
|
| 634 | - $mail->FromName = Config::$APPEARANCE['productname'] . " Invitation System"; |
|
| 635 | - $mail->addAddress(Config::$APPEARANCE['abuse-mail']); |
|
| 636 | - $mail->Subject = "testing CAT configuration mail"; |
|
| 637 | - $mail->Body = "Testing CAT mailing\n"; |
|
| 638 | - $sent = $mail->send(); |
|
| 639 | - if($sent) |
|
| 640 | - $this->test_return(L_OK,"mailer settings appear to be working, check ".Config::$APPEARANCE['abuse-mail']." mailbox if the message was receiced."); |
|
| 641 | - else |
|
| 642 | - $this->test_return(L_ERROR,"mailer settings failed, check the Config::MAILSETTINGS"); |
|
| 643 | - |
|
| 644 | - } |
|
| 617 | + private function mailer_test() { |
|
| 618 | + if (empty(Config::$APPEARANCE['abuse-mail']) || Config::$APPEARANCE['abuse-mail'] == "[email protected]") { |
|
| 619 | + $this->test_return(L_ERROR,"Your abuse-mail has not been set, cannot continue with mailer tests."); |
|
| 620 | + return; |
|
| 621 | + } |
|
| 622 | + $mail = new PHPMailer\PHPMailer\PHPMailer(); |
|
| 623 | + $mail->isSMTP(); |
|
| 624 | + $mail->Port = 587; |
|
| 625 | + $mail->SMTPAuth = true; |
|
| 626 | + $mail->SMTPSecure = 'tls'; |
|
| 627 | + $mail->Host = Config::$MAILSETTINGS['host']; |
|
| 628 | + $mail->Username = Config::$MAILSETTINGS['user']; |
|
| 629 | + $mail->Password = Config::$MAILSETTINGS['pass']; |
|
| 630 | + $mail->WordWrap = 72; |
|
| 631 | + $mail->isHTML(FALSE); |
|
| 632 | + $mail->CharSet = 'UTF-8'; |
|
| 633 | + $mail->From = Config::$APPEARANCE['from-mail']; |
|
| 634 | + $mail->FromName = Config::$APPEARANCE['productname'] . " Invitation System"; |
|
| 635 | + $mail->addAddress(Config::$APPEARANCE['abuse-mail']); |
|
| 636 | + $mail->Subject = "testing CAT configuration mail"; |
|
| 637 | + $mail->Body = "Testing CAT mailing\n"; |
|
| 638 | + $sent = $mail->send(); |
|
| 639 | + if($sent) |
|
| 640 | + $this->test_return(L_OK,"mailer settings appear to be working, check ".Config::$APPEARANCE['abuse-mail']." mailbox if the message was receiced."); |
|
| 641 | + else |
|
| 642 | + $this->test_return(L_ERROR,"mailer settings failed, check the Config::MAILSETTINGS"); |
|
| 643 | + |
|
| 644 | + } |
|
| 645 | 645 | |
| 646 | 646 | /** |
| 647 | - * TODO test if RADIUS connections work |
|
| 648 | - */ |
|
| 647 | + * TODO test if RADIUS connections work |
|
| 648 | + */ |
|
| 649 | 649 | private function UDPhosts_test() { |
| 650 | 650 | // if(empty) |
| 651 | 651 | } |
@@ -260,7 +260,6 @@ discard block |
||
| 260 | 260 | /** |
| 261 | 261 | * Return the list of IdPs in a given country |
| 262 | 262 | * |
| 263 | - * @param int $idp_id the IdP identifier |
|
| 264 | 263 | * @return string JSON encoded data |
| 265 | 264 | */ |
| 266 | 265 | |
@@ -301,7 +300,6 @@ discard block |
||
| 301 | 300 | /** |
| 302 | 301 | * Return the list of IdPs in a given country ordered with respect to the user location |
| 303 | 302 | * |
| 304 | - * @param int $idp_id the IdP identifier |
|
| 305 | 303 | * @return string JSON encoded data |
| 306 | 304 | */ |
| 307 | 305 | |
@@ -82,9 +82,9 @@ discard block |
||
| 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'] )) |
|
| 86 | - $this->i_path = FALSE; |
|
| 87 | - else { |
|
| 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; |
|
| 87 | + } else { |
|
| 88 | 88 | $cache = $profile->testCache($device); |
| 89 | 89 | $this->i_path = $cache['cache']; |
| 90 | 90 | } |
@@ -100,9 +100,9 @@ discard block |
||
| 100 | 100 | $installer = $dev->writeInstaller(); |
| 101 | 101 | $i_path = $dev->FPATH.'/tmp/'.$installer; |
| 102 | 102 | if($i_path && is_file($i_path)) { |
| 103 | - if(isset($dev->options['mime'])) |
|
| 104 | - $a['mime'] = $dev->options['mime']; |
|
| 105 | - else { |
|
| 103 | + if(isset($dev->options['mime'])) { |
|
| 104 | + $a['mime'] = $dev->options['mime']; |
|
| 105 | + } else { |
|
| 106 | 106 | $info = new finfo(); |
| 107 | 107 | $a['mime'] = $info->file($i_path, FILEINFO_MIME_TYPE); |
| 108 | 108 | } |
@@ -129,19 +129,23 @@ discard block |
||
| 129 | 129 | $Dev = Devices::listDevices(); |
| 130 | 130 | $R = []; |
| 131 | 131 | $ct = 0; |
| 132 | - if($show_hidden !== 0 && $show_hidden != 1) |
|
| 133 | - return; |
|
| 132 | + if($show_hidden !== 0 && $show_hidden != 1) { |
|
| 133 | + return; |
|
| 134 | + } |
|
| 134 | 135 | foreach ($Dev as $device => $D) { |
| 135 | - if(isset($D['options']['hidden']) && $D['options']['hidden'] && $show_hidden == 0) |
|
| 136 | - continue; |
|
| 136 | + if(isset($D['options']['hidden']) && $D['options']['hidden'] && $show_hidden == 0) { |
|
| 137 | + continue; |
|
| 138 | + } |
|
| 137 | 139 | $ct ++; |
| 138 | - if($this->version == 1) |
|
| 139 | - $D['device'] = $device; |
|
| 140 | - else |
|
| 141 | - $D['device'] = $device; |
|
| 140 | + if($this->version == 1) { |
|
| 141 | + $D['device'] = $device; |
|
| 142 | + } else { |
|
| 143 | + $D['device'] = $device; |
|
| 144 | + } |
|
| 142 | 145 | $group = isset($D['group']) ? $D['group'] : 'other'; |
| 143 | - if (! isset($R[$group])) |
|
| 144 | - $R[$group] = []; |
|
| 146 | + if (! isset($R[$group])) { |
|
| 147 | + $R[$group] = []; |
|
| 148 | + } |
|
| 145 | 149 | $R[$group][$device] = $D; |
| 146 | 150 | } |
| 147 | 151 | return $R; |
@@ -178,14 +182,18 @@ discard block |
||
| 178 | 182 | $profile = new Profile($prof_id); |
| 179 | 183 | $attr = $profile->getCollapsedAttributes(); |
| 180 | 184 | $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]; |
|
| 185 | + if(isset($attr['support:email'])) { |
|
| 186 | + $a['local_email'] = $attr['support:email'][0]; |
|
| 187 | + } |
|
| 188 | + if(isset($attr['support:phone'])) { |
|
| 189 | + $a['local_phone'] = $attr['support:phone'][0]; |
|
| 190 | + } |
|
| 191 | + if(isset($attr['support:url'])) { |
|
| 192 | + $a['local_url'] = $attr['support:url'][0]; |
|
| 193 | + } |
|
| 194 | + if(isset($attr['profile:description'])) { |
|
| 195 | + $a['description'] = $attr['profile:description'][0]; |
|
| 196 | + } |
|
| 189 | 197 | $a['devices'] = $profile->listDevices(); |
| 190 | 198 | $this->set_locale("web_user"); |
| 191 | 199 | return($a); |
@@ -200,14 +208,17 @@ discard block |
||
| 200 | 208 | $F = array_pop($backtrace); |
| 201 | 209 | $file= $F['file']; |
| 202 | 210 | $file = substr($file,strlen(dirname(__DIR__))); |
| 203 | - while(substr($file,0,1) == '/') |
|
| 204 | - $file = substr($file,1); |
|
| 211 | + while(substr($file,0,1) == '/') { |
|
| 212 | + $file = substr($file,1); |
|
| 213 | + } |
|
| 205 | 214 | $n = count(explode('/',$file)); |
| 206 | 215 | $out = $_SERVER['SCRIPT_NAME']; |
| 207 | - for ($i= 0; $i < $n; $i++) |
|
| 208 | - $out = dirname($out); |
|
| 209 | - if ($out == '/') |
|
| 210 | - $out = ''; |
|
| 216 | + for ($i= 0; $i < $n; $i++) { |
|
| 217 | + $out = dirname($out); |
|
| 218 | + } |
|
| 219 | + if ($out == '/') { |
|
| 220 | + $out = ''; |
|
| 221 | + } |
|
| 211 | 222 | $s = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] ? 'https' : 'http'; |
| 212 | 223 | $s .= '://'.$_SERVER['HTTP_HOST'] . $out; |
| 213 | 224 | return $s; |
@@ -231,10 +242,11 @@ discard block |
||
| 231 | 242 | public function JSON_listLanguages() { |
| 232 | 243 | $return_array = []; |
| 233 | 244 | 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']]; |
|
| 245 | + if($this->version == 1) { |
|
| 246 | + $return_array[] = ['id'=>$id,'display'=>$val['display'],'locale'=>$val['locale']]; |
|
| 247 | + } else { |
|
| 248 | + $return_array[] = ['lang'=>$id,'display'=>$val['display'],'locale'=>$val['locale']]; |
|
| 249 | + } |
|
| 238 | 250 | } |
| 239 | 251 | echo $this->return_json($return_array); |
| 240 | 252 | } |
@@ -249,10 +261,11 @@ discard block |
||
| 249 | 261 | $FED = $this->printCountryList(1); |
| 250 | 262 | $return_array = []; |
| 251 | 263 | 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]; |
|
| 264 | + if($this->version == 1) { |
|
| 265 | + $return_array[] = ['id'=>$id,'display'=>$val]; |
|
| 266 | + } else { |
|
| 267 | + $return_array[] = ['federation'=>$id,'display'=>$val]; |
|
| 268 | + } |
|
| 256 | 269 | } |
| 257 | 270 | echo $this->return_json($return_array); |
| 258 | 271 | } |
@@ -268,10 +281,11 @@ discard block |
||
| 268 | 281 | $idps = Federation::listAllIdentityProviders(1,$country); |
| 269 | 282 | $return_array = []; |
| 270 | 283 | foreach ($idps as $idp) { |
| 271 | - if($this->version == 1) |
|
| 272 | - $return_array[] = ['id'=>$idp['entityID'],'display'=>$idp['title']]; |
|
| 273 | - else |
|
| 274 | - $return_array[] = ['idp'=>$idp['entityID'],'display'=>$idp['title']]; |
|
| 284 | + if($this->version == 1) { |
|
| 285 | + $return_array[] = ['id'=>$idp['entityID'],'display'=>$idp['title']]; |
|
| 286 | + } else { |
|
| 287 | + $return_array[] = ['idp'=>$idp['entityID'],'display'=>$idp['title']]; |
|
| 288 | + } |
|
| 275 | 289 | } |
| 276 | 290 | echo $this->return_json($return_array); |
| 277 | 291 | } |
@@ -287,10 +301,11 @@ discard block |
||
| 287 | 301 | $idps = Federation::listAllIdentityProviders(1); |
| 288 | 302 | $return_array = []; |
| 289 | 303 | foreach ($idps as $idp) { |
| 290 | - if($this->version == 1) |
|
| 291 | - $idp['id'] = $idp['entityID']; |
|
| 292 | - else |
|
| 293 | - $idp['idp'] = $idp['entityID']; |
|
| 304 | + if($this->version == 1) { |
|
| 305 | + $idp['id'] = $idp['entityID']; |
|
| 306 | + } else { |
|
| 307 | + $idp['idp'] = $idp['entityID']; |
|
| 308 | + } |
|
| 294 | 309 | $return_array[] = $idp; |
| 295 | 310 | } |
| 296 | 311 | echo json_encode($return_array); |
@@ -310,10 +325,11 @@ discard block |
||
| 310 | 325 | $idps = $this->orderIdentityProviders($country,$L); |
| 311 | 326 | $return_array = []; |
| 312 | 327 | foreach ($idps as $idp) { |
| 313 | - if($this->version == 1) |
|
| 314 | - $return_array[] = ['id'=>$idp['id'],'display'=>$idp['title']]; |
|
| 315 | - else |
|
| 316 | - $return_array[] = ['idp'=>$idp['id'],'display'=>$idp['title']]; |
|
| 328 | + if($this->version == 1) { |
|
| 329 | + $return_array[] = ['id'=>$idp['id'],'display'=>$idp['title']]; |
|
| 330 | + } else { |
|
| 331 | + $return_array[] = ['idp'=>$idp['id'],'display'=>$idp['title']]; |
|
| 332 | + } |
|
| 317 | 333 | } |
| 318 | 334 | echo $this->return_json($return_array); |
| 319 | 335 | } |
@@ -329,23 +345,25 @@ discard block |
||
| 329 | 345 | $return_array = []; |
| 330 | 346 | try { |
| 331 | 347 | $idp = new IdP($idp_id); |
| 332 | - } |
|
| 333 | - catch (Exception $fail) { |
|
| 348 | + } catch (Exception $fail) { |
|
| 334 | 349 | echo $this->return_json($return_array,0); |
| 335 | 350 | return; |
| 336 | 351 | } |
| 337 | 352 | $l = 0; |
| 338 | 353 | $logo = $idp->getAttributes('general:logo_file'); |
| 339 | - if($logo) |
|
| 340 | - $l = 1; |
|
| 354 | + if($logo) { |
|
| 355 | + $l = 1; |
|
| 356 | + } |
|
| 341 | 357 | $profiles = $idp->listProfiles(1); |
| 342 | - if($sort == 1) |
|
| 343 | - usort($profiles,"profile_sort"); |
|
| 358 | + if($sort == 1) { |
|
| 359 | + usort($profiles,"profile_sort"); |
|
| 360 | + } |
|
| 344 | 361 | 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]; |
|
| 362 | + if($this->version == 1) { |
|
| 363 | + $return_array[] = ['id'=>$P->identifier,'display'=>$P->name, 'idp_name'=>$P->inst_name,'logo'=>$l]; |
|
| 364 | + } else { |
|
| 365 | + $return_array[] = ['profile'=>$P->identifier,'display'=>$P->name, 'idp_name'=>$P->inst_name,'logo'=>$l]; |
|
| 366 | + } |
|
| 349 | 367 | } |
| 350 | 368 | echo $this->return_json($return_array); |
| 351 | 369 | } |
@@ -364,8 +382,9 @@ discard block |
||
| 364 | 382 | if(!isset($profile_redirect) || ! $profile_redirect) { |
| 365 | 383 | $profile_redirect = 0; |
| 366 | 384 | foreach ($thedevices as $D) { |
| 367 | - if(isset($D['options']) && isset($D['options']['hidden']) && $D['options']['hidden']) |
|
| 368 | - continue; |
|
| 385 | + if(isset($D['options']) && isset($D['options']['hidden']) && $D['options']['hidden']) { |
|
| 386 | + continue; |
|
| 387 | + } |
|
| 369 | 388 | $disp = $D['display']; |
| 370 | 389 | if($this->version == 1) { |
| 371 | 390 | if($D['id'] === '0') { |
@@ -449,10 +468,12 @@ discard block |
||
| 449 | 468 | $resize = 0; |
| 450 | 469 | if(($width || $height) && is_numeric($width) && is_numeric($height)) { |
| 451 | 470 | $resize = 1; |
| 452 | - if($height == 0) |
|
| 453 | - $height = 10000; |
|
| 454 | - if($width == 0) |
|
| 455 | - $width = 10000; |
|
| 471 | + if($height == 0) { |
|
| 472 | + $height = 10000; |
|
| 473 | + } |
|
| 474 | + if($width == 0) { |
|
| 475 | + $width = 10000; |
|
| 476 | + } |
|
| 456 | 477 | $logo_file = CAT::$root.'/web/downloads/logos/'.$idp_id.'_'.$width.'_'.$height.'.png'; |
| 457 | 478 | } elseif($disco == 1) { |
| 458 | 479 | $width = 120; |
@@ -465,8 +486,7 @@ discard block |
||
| 465 | 486 | debug(4,"Using cached logo $logo_file for: $idp_id\n"); |
| 466 | 487 | $blob = file_get_contents($logo_file); |
| 467 | 488 | $filetype = 'image/png'; |
| 468 | - } |
|
| 469 | - else { |
|
| 489 | + } else { |
|
| 470 | 490 | $idp = new IdP($idp_id); |
| 471 | 491 | $at = $idp->getAttributes('general:logo_file'); |
| 472 | 492 | $blob = $at[0]['value']; |
@@ -483,9 +503,9 @@ discard block |
||
| 483 | 503 | $blob = $image->getImageBlob(); |
| 484 | 504 | debug(4,"Writing cached logo $logo_file for: $idp_id\n"); |
| 485 | 505 | file_put_contents($logo_file,$blob); |
| 506 | + } else { |
|
| 507 | + $blob = "XXXXXX"; |
|
| 486 | 508 | } |
| 487 | - else |
|
| 488 | - $blob = "XXXXXX"; |
|
| 489 | 509 | } |
| 490 | 510 | } |
| 491 | 511 | header( "Content-type: ".$filetype ); |
@@ -501,8 +521,9 @@ discard block |
||
| 501 | 521 | $result = ['status' => 'ok']; |
| 502 | 522 | $result['country'] = $record['country_code']; |
| 503 | 523 | // 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'; |
|
| 524 | + if($result['country'] == 'GB') { |
|
| 525 | + $result['country'] = 'UK'; |
|
| 526 | + } |
|
| 506 | 527 | $result['region'] = $record['region']; |
| 507 | 528 | $result['geo'] = ['lat' => (float)$record['latitude'] , 'lon' => (float)$record['longitude']]; |
| 508 | 529 | } else { |
@@ -525,8 +546,9 @@ discard block |
||
| 525 | 546 | $result = ['status' => 'ok']; |
| 526 | 547 | $result['country'] = $record->country->isoCode; |
| 527 | 548 | // 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'; |
|
| 549 | + if($result['country'] == 'GB') { |
|
| 550 | + $result['country'] = 'UK'; |
|
| 551 | + } |
|
| 530 | 552 | $result['region'] = $record->continent->name; |
| 531 | 553 | |
| 532 | 554 | $result['geo'] = ['lat' => (float)$record->location->latitude , 'lon' => (float)$record->location->longitude]; |
@@ -536,13 +558,16 @@ discard block |
||
| 536 | 558 | public function JSON_locateUser() { |
| 537 | 559 | header('Content-type: application/json; utf-8'); |
| 538 | 560 | |
| 539 | - if(empty(Config::$GEOIP['version']) || Config::$GEOIP['version'] == 0) |
|
| 540 | - echo json_encode(['status' => 'error', 'error' =>'Geolocation not supported']); |
|
| 541 | - if(Config::$GEOIP['version'] == 1) |
|
| 542 | - echo json_encode($this->locateUser()); |
|
| 543 | - if(Config::$GEOIP['version'] == 2) |
|
| 544 | - echo json_encode($this->locateUser2()); |
|
| 545 | -} |
|
| 561 | + if(empty(Config::$GEOIP['version']) || Config::$GEOIP['version'] == 0) { |
|
| 562 | + echo json_encode(['status' => 'error', 'error' =>'Geolocation not supported']); |
|
| 563 | + } |
|
| 564 | + if(Config::$GEOIP['version'] == 1) { |
|
| 565 | + echo json_encode($this->locateUser()); |
|
| 566 | + } |
|
| 567 | + if(Config::$GEOIP['version'] == 2) { |
|
| 568 | + echo json_encode($this->locateUser2()); |
|
| 569 | + } |
|
| 570 | + } |
|
| 546 | 571 | |
| 547 | 572 | /** |
| 548 | 573 | * Produce support data prepared within {@link GUI::profileAttributes()} |
@@ -594,27 +619,31 @@ discard block |
||
| 594 | 619 | $G=$idp['geo']; |
| 595 | 620 | if(isset($G['lon'])) { |
| 596 | 621 | $d1 = $this->geoDistance($L,$G); |
| 597 | - if( $d1 < $dist) |
|
| 598 | - $dist = $d1; |
|
| 622 | + if( $d1 < $dist) { |
|
| 623 | + $dist = $d1; |
|
| 624 | + } |
|
| 599 | 625 | } else { |
| 600 | 626 | foreach ($G as $g) { |
| 601 | 627 | $d1 = $this->geoDistance($L,$g); |
| 602 | - if( $d1 < $dist) |
|
| 603 | - $dist = $d1; |
|
| 628 | + if( $d1 < $dist) { |
|
| 629 | + $dist = $d1; |
|
| 630 | + } |
|
| 604 | 631 | } |
| 605 | 632 | } |
| 606 | 633 | } |
| 607 | - if($dist > 100) |
|
| 608 | - $dist=10000; |
|
| 634 | + if($dist > 100) { |
|
| 635 | + $dist=10000; |
|
| 636 | + } |
|
| 609 | 637 | $d = sprintf("%06d",$dist); |
| 610 | 638 | $R[$idp['entityID']] = $d." ".$idp['title']; |
| 611 | 639 | } |
| 612 | 640 | asort($R); |
| 613 | 641 | 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]]; |
|
| 642 | + if($this->version == 1) { |
|
| 643 | + $outarray[] = ['id'=>$r, 'title'=>$T[$r]]; |
|
| 644 | + } else { |
|
| 645 | + $outarray[] = ['idp'=>$r, 'title'=>$T[$r]]; |
|
| 646 | + } |
|
| 618 | 647 | } |
| 619 | 648 | return($outarray); |
| 620 | 649 | } |
@@ -632,25 +661,27 @@ discard block |
||
| 632 | 661 | if( isset($_REQUEST['device']) && isset($Dev[$_REQUEST['device']]) && (!isset($device['options']['hidden']) || $device['options']['hidden'] == 0)) { |
| 633 | 662 | $dev_id = $_REQUEST['device']; |
| 634 | 663 | $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']]); |
|
| 664 | + if($this->version == 1) { |
|
| 665 | + return(['id'=>$dev_id,'display'=>$device['display'], 'group'=>$device['group']]); |
|
| 666 | + } else { |
|
| 667 | + return(['device'=>$dev_id,'display'=>$device['display'], 'group'=>$device['group']]); |
|
| 668 | + } |
|
| 639 | 669 | } |
| 640 | 670 | $browser = $_SERVER['HTTP_USER_AGENT']; |
| 641 | 671 | debug(4,"HTTP_USER_AGENT=$browser\n"); |
| 642 | 672 | foreach ($Dev as $dev_id => $device) { |
| 643 | - if(!isset($device['match'])) |
|
| 644 | - continue; |
|
| 673 | + if(!isset($device['match'])) { |
|
| 674 | + continue; |
|
| 675 | + } |
|
| 645 | 676 | if(preg_match('/'.$device['match'].'/',$browser)) { |
| 646 | 677 | if(!isset($device['options']['hidden']) || $device['options']['hidden'] == 0) { |
| 647 | 678 | 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 { |
|
| 679 | + if($this->version == 1) { |
|
| 680 | + return(['id'=>$dev_id,'display'=>$device['display'], 'group'=>$device['group']]); |
|
| 681 | + } else { |
|
| 682 | + return(['device'=>$dev_id,'display'=>$device['display'], 'group'=>$device['group']]); |
|
| 683 | + } |
|
| 684 | + } else { |
|
| 654 | 685 | debug(2, "Unrecognised system: ".$_SERVER['HTTP_USER_AGENT']."\n"); |
| 655 | 686 | return(false); |
| 656 | 687 | } |
@@ -662,10 +693,11 @@ discard block |
||
| 662 | 693 | |
| 663 | 694 | public function JSON_detectOS() { |
| 664 | 695 | $return_array=$this->detectOS(); |
| 665 | - if($return_array) |
|
| 666 | - $status = 1; |
|
| 667 | - else |
|
| 668 | - $status = 0; |
|
| 696 | + if($return_array) { |
|
| 697 | + $status = 1; |
|
| 698 | + } else { |
|
| 699 | + $status = 0; |
|
| 700 | + } |
|
| 669 | 701 | echo $this->return_json($return_array,$status); |
| 670 | 702 | } |
| 671 | 703 | |
@@ -52,7 +52,7 @@ discard block |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
@@ -52,21 +52,21 @@ discard block |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
@@ -78,9 +78,6 @@ |
||
| 78 | 78 | * It is CRUTCIAL that the constructor sets $this->supportedEapMethods to an array of methods |
| 79 | 79 | * available for the particular device. |
| 80 | 80 | * {@source} |
| 81 | - * @param string $device a pointer to a device module, which must |
|
| 82 | - * be an index of one of the devices defined in the {@link Devices} |
|
| 83 | - * array in {@link devices.php}. |
|
| 84 | 81 | * @final not to be redefined |
| 85 | 82 | */ |
| 86 | 83 | final public function __construct() { |
@@ -170,13 +170,13 @@ |
||
| 170 | 170 | // define CA certificates |
| 171 | 171 | foreach ($this->attributes['internal:CAs'][0] as $ca) { |
| 172 | 172 | // strip -----BEGIN CERTIFICATE----- and -----END CERTIFICATE----- |
| 173 | - debug(2,$ca['pem']); |
|
| 173 | + debug(2, $ca['pem']); |
|
| 174 | 174 | $caSanitized = substr($ca['pem'], 27, strlen($ca['pem']) - 27 - 25 - 1); |
| 175 | - debug(2,$caSanitized."\n"); |
|
| 175 | + debug(2, $caSanitized . "\n"); |
|
| 176 | 176 | // remove \n |
| 177 | 177 | $caSanitized = str_replace("\n", "", $caSanitized); |
| 178 | 178 | $jsonArray["Certificates"][] = ["GUID" => "{" . $ca['uuid'] . "}", "Type" => "Authority", "X509" => $caSanitized]; |
| 179 | - debug(2,$caSanitized."\n"); |
|
| 179 | + debug(2, $caSanitized . "\n"); |
|
| 180 | 180 | } |
| 181 | 181 | |
| 182 | 182 | $outputJson = json_encode($jsonArray, JSON_PRETTY_PRINT); |
@@ -108,8 +108,9 @@ discard block |
||
| 108 | 108 | $outerId = 0; |
| 109 | 109 | if (isset($this->attributes['internal:use_anon_outer']) && $this->attributes['internal:use_anon_outer'][0] == "1" && isset($this->attributes['internal:realm'])) { |
| 110 | 110 | $outerId = "@" . $this->attributes['internal:realm'][0]; |
| 111 | - if (isset($this->attributes['internal:anon_local_value'])) |
|
| 112 | - $outerId = $this->attributes['internal:anon_local_value'][0] . $outerId; |
|
| 111 | + if (isset($this->attributes['internal:anon_local_value'])) { |
|
| 112 | + $outerId = $this->attributes['internal:anon_local_value'][0] . $outerId; |
|
| 113 | + } |
|
| 113 | 114 | } |
| 114 | 115 | |
| 115 | 116 | // define networks |
@@ -117,26 +118,30 @@ discard block |
||
| 117 | 118 | $networkUuid = uuid($prefix, $ssid); |
| 118 | 119 | $eapPrettyprint = EAP::eapDisplayName($this->selected_eap); |
| 119 | 120 | // ONC has its own enums, and guess what, they don't always match |
| 120 | - if ($eapPrettyprint["OUTER"] == "PEAP" && $eapPrettyprint["INNER"] == "MSCHAPV2") |
|
| 121 | - // the dictionary entry EAP-MSCHAPv2 does not work. Setting MSCHAPv2 does. (ChromeOS 50) |
|
| 121 | + if ($eapPrettyprint["OUTER"] == "PEAP" && $eapPrettyprint["INNER"] == "MSCHAPV2") { |
|
| 122 | + // the dictionary entry EAP-MSCHAPv2 does not work. Setting MSCHAPv2 does. (ChromeOS 50) |
|
| 122 | 123 | $eapPrettyprint["INNER"] = "MSCHAPv2"; |
| 124 | + } |
|
| 123 | 125 | if ($eapPrettyprint["OUTER"] == "TTLS" && $eapPrettyprint["INNER"] == "MSCHAPV2") { |
| 124 | 126 | $eapPrettyprint["OUTER"] = "EAP-TTLS"; |
| 125 | 127 | $eapPrettyprint["INNER"] = "MSCHAPv2"; |
| 126 | 128 | } |
| 127 | - if ($eapPrettyprint["OUTER"] == "TLS") |
|
| 128 | - $eapPrettyprint["OUTER"] = "EAP-TLS"; |
|
| 129 | + if ($eapPrettyprint["OUTER"] == "TLS") { |
|
| 130 | + $eapPrettyprint["OUTER"] = "EAP-TLS"; |
|
| 131 | + } |
|
| 129 | 132 | // define EAP properties |
| 130 | 133 | |
| 131 | 134 | $eaparray = array("Outer" => $eapPrettyprint["OUTER"]); |
| 132 | - if ($eapPrettyprint["INNER"] == "MSCHAPv2") |
|
| 133 | - $eaparray["Inner"] = $eapPrettyprint["INNER"]; |
|
| 135 | + if ($eapPrettyprint["INNER"] == "MSCHAPv2") { |
|
| 136 | + $eaparray["Inner"] = $eapPrettyprint["INNER"]; |
|
| 137 | + } |
|
| 134 | 138 | $eaparray["SaveCredentials"] = true; |
| 135 | 139 | $eaparray["ServerCARefs"] = $caRefs; // maybe takes just one CA? |
| 136 | 140 | $eaparray["UseSystemCAs"] = false; |
| 137 | 141 | |
| 138 | - if ($outerId) |
|
| 139 | - $eaparray["AnonymousIdentity"] = "$outerId"; |
|
| 142 | + if ($outerId) { |
|
| 143 | + $eaparray["AnonymousIdentity"] = "$outerId"; |
|
| 144 | + } |
|
| 140 | 145 | |
| 141 | 146 | $jsonArray["NetworkConfigurations"][] = [ |
| 142 | 147 | "GUID" => $networkUuid, |
@@ -308,6 +308,9 @@ |
||
| 308 | 308 | |
| 309 | 309 | /** |
| 310 | 310 | * produce PEAP, TLS and TTLS configuration files for Windows 8 |
| 311 | + * @param string $auth |
|
| 312 | + * @param string $encryption |
|
| 313 | + * @param integer $i |
|
| 311 | 314 | */ |
| 312 | 315 | private function writeWLANprofile($wlan_profile_name,$ssid,$auth,$encryption,$eap_config,$i) { |
| 313 | 316 | $profile_file_contents = '<?xml version="1.0"?> |
@@ -28,8 +28,8 @@ discard block |
||
| 28 | 28 | final public function __construct() { |
| 29 | 29 | $this->supportedEapMethods = [EAP::$TLS, EAP::$PEAP_MSCHAP2, EAP::$TTLS_PAP, EAP::$TTLS_MSCHAP2, EAP::$PWD]; |
| 30 | 30 | # $this->supportedEapMethods = array(EAP::$TLS, EAP::$PEAP_MSCHAP2, EAP::$TTLS_PAP, EAP::$PWD); |
| 31 | - debug(4,"This device supports the following EAP methods: "); |
|
| 32 | - debug(4,$this->supportedEapMethods); |
|
| 31 | + debug(4, "This device supports the following EAP methods: "); |
|
| 32 | + debug(4, $this->supportedEapMethods); |
|
| 33 | 33 | $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."); |
| 34 | 34 | } |
| 35 | 35 | |
@@ -46,42 +46,42 @@ discard block |
||
| 46 | 46 | // create a list of profiles to be deleted after installation |
| 47 | 47 | $delProfiles = []; |
| 48 | 48 | foreach ($delSSIDs as $ssid => $cipher) { |
| 49 | - if($cipher == 'DEL') |
|
| 49 | + if ($cipher == 'DEL') |
|
| 50 | 50 | $delProfiles[] = $ssid; |
| 51 | - if($cipher == 'TKIP') |
|
| 52 | - $delProfiles[] = $ssid.' (TKIP)'; |
|
| 51 | + if ($cipher == 'TKIP') |
|
| 52 | + $delProfiles[] = $ssid . ' (TKIP)'; |
|
| 53 | 53 | } |
| 54 | 54 | |
| 55 | 55 | |
| 56 | - if ($this->selected_eap == EAP::$TLS || $this->selected_eap == EAP::$PEAP_MSCHAP2 || $this->selected_eap == EAP::$TTLS_PAP || $this->selected_eap == EAP::$TTLS_MSCHAP2 || $this->selected_eap == EAP::$PWD) { |
|
| 56 | + if ($this->selected_eap == EAP::$TLS || $this->selected_eap == EAP::$PEAP_MSCHAP2 || $this->selected_eap == EAP::$TTLS_PAP || $this->selected_eap == EAP::$TTLS_MSCHAP2 || $this->selected_eap == EAP::$PWD) { |
|
| 57 | 57 | $WindowsProfile = []; |
| 58 | 58 | $eap_config = $this->prepareEapConfig($this->attributes); |
| 59 | 59 | $i = 0; |
| 60 | 60 | foreach ($SSIDs as $ssid => $cipher) { |
| 61 | - if($cipher == 'TKIP') { |
|
| 62 | - $WindowsProfile[$i] = $this->writeWLANprofile ($ssid.' (TKIP)',$ssid,'WPA','TKIP',$eap_config,$i); |
|
| 61 | + if ($cipher == 'TKIP') { |
|
| 62 | + $WindowsProfile[$i] = $this->writeWLANprofile($ssid . ' (TKIP)', $ssid, 'WPA', 'TKIP', $eap_config, $i); |
|
| 63 | 63 | $i++; |
| 64 | 64 | } |
| 65 | - $WindowsProfile[$i] = $this->writeWLANprofile ($ssid,$ssid,'WPA2','AES',$eap_config,$i); |
|
| 65 | + $WindowsProfile[$i] = $this->writeWLANprofile($ssid, $ssid, 'WPA2', 'AES', $eap_config, $i); |
|
| 66 | 66 | $i++; |
| 67 | 67 | } |
| 68 | - if($set_wired) { |
|
| 68 | + if ($set_wired) { |
|
| 69 | 69 | $this->writeLANprofile($eap_config); |
| 70 | 70 | } |
| 71 | 71 | } else { |
| 72 | 72 | error(" this EAP type is not handled yet"); |
| 73 | 73 | return; |
| 74 | 74 | } |
| 75 | - debug(4,"WindowsProfile"); debug(4,$WindowsProfile); |
|
| 75 | + debug(4, "WindowsProfile"); debug(4, $WindowsProfile); |
|
| 76 | 76 | |
| 77 | - $this->writeProfilesNSH($WindowsProfile, $CA_files,$set_wired); |
|
| 77 | + $this->writeProfilesNSH($WindowsProfile, $CA_files, $set_wired); |
|
| 78 | 78 | $this->writeAdditionalDeletes($delProfiles); |
| 79 | - if(isset($additional_deletes) && count($additional_deletes)) |
|
| 79 | + if (isset($additional_deletes) && count($additional_deletes)) |
|
| 80 | 80 | $this->writeAdditionalDeletes($additional_deletes); |
| 81 | 81 | $this->copyFiles($this->selected_eap); |
| 82 | - if(isset($this->attributes['internal:logo_file'])) |
|
| 82 | + if (isset($this->attributes['internal:logo_file'])) |
|
| 83 | 83 | $this->combineLogo($this->attributes['internal:logo_file']); |
| 84 | - $this->writeMainNSH($this->selected_eap,$this->attributes); |
|
| 84 | + $this->writeMainNSH($this->selected_eap, $this->attributes); |
|
| 85 | 85 | $this->compileNSIS(); |
| 86 | 86 | $installer_path = $this->signInstaller($this->attributes); |
| 87 | 87 | |
@@ -90,19 +90,19 @@ discard block |
||
| 90 | 90 | } |
| 91 | 91 | |
| 92 | 92 | public function writeDeviceInfo() { |
| 93 | - $ssid_ct=count($this->attributes['internal:SSID']); |
|
| 93 | + $ssid_ct = count($this->attributes['internal:SSID']); |
|
| 94 | 94 | $out = "<p>"; |
| 95 | - $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']); |
|
| 95 | + $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']); |
|
| 96 | 96 | $out .= "<p>"; |
| 97 | - if($ssid_ct > 1) { |
|
| 98 | - if($ssid_ct > 2) { |
|
| 99 | - $out .= sprintf(_("In addition to <strong>%s</strong> the installer will also configure access to the following networks:"),implode(', ',Config::$CONSORTIUM['ssid']))." "; |
|
| 97 | + if ($ssid_ct > 1) { |
|
| 98 | + if ($ssid_ct > 2) { |
|
| 99 | + $out .= sprintf(_("In addition to <strong>%s</strong> the installer will also configure access to the following networks:"), implode(', ', Config::$CONSORTIUM['ssid'])) . " "; |
|
| 100 | 100 | } else |
| 101 | - $out .= sprintf(_("In addition to <strong>%s</strong> the installer will also configure access to:"),implode(', ',Config::$CONSORTIUM['ssid']))." "; |
|
| 101 | + $out .= sprintf(_("In addition to <strong>%s</strong> the installer will also configure access to:"), implode(', ', Config::$CONSORTIUM['ssid'])) . " "; |
|
| 102 | 102 | $i = 0; |
| 103 | 103 | foreach ($this->attributes['internal:SSID'] as $ssid=>$v) { |
| 104 | - if(! in_array($ssid, Config::$CONSORTIUM['ssid'])) { |
|
| 105 | - if($i > 0) |
|
| 104 | + if (!in_array($ssid, Config::$CONSORTIUM['ssid'])) { |
|
| 105 | + if ($i > 0) |
|
| 106 | 106 | $out .= ", "; |
| 107 | 107 | $i++; |
| 108 | 108 | $out .= "<strong>$ssid</strong>"; |
@@ -111,18 +111,18 @@ discard block |
||
| 111 | 111 | $out .= "<p>"; |
| 112 | 112 | } |
| 113 | 113 | |
| 114 | -if($this->eap == EAP::$TLS) |
|
| 114 | +if ($this->eap == EAP::$TLS) |
|
| 115 | 115 | $out .= _("In order to connect to the network you will need an a personal certificate in the form of a p12 file. You should obtain this certificate from your home institution. Consult the support page to find out how this certificate can be obtained. Such certificate files are password protected. You should have both the file and the password available during the installation process."); |
| 116 | 116 | else { |
| 117 | 117 | $out .= _("In order to connect to the network you will need an account from your home institution. You should consult the support page to find out how this account can be obtained. It is very likely that your account is already activated."); |
| 118 | 118 | $out .= "<p>"; |
| 119 | 119 | $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."); |
| 120 | - if($ssid_ct > 1) { |
|
| 120 | + if ($ssid_ct > 1) { |
|
| 121 | 121 | $out .= "<p>"; |
| 122 | - $out .= _("You will be required to enter the same credentials for each of the configured notworks:")." "; |
|
| 122 | + $out .= _("You will be required to enter the same credentials for each of the configured notworks:") . " "; |
|
| 123 | 123 | $i = 0; |
| 124 | 124 | foreach ($this->attributes['internal:SSID'] as $ssid=>$v) { |
| 125 | - if($i > 0) |
|
| 125 | + if ($i > 0) |
|
| 126 | 126 | $out .= ", "; |
| 127 | 127 | $i++; |
| 128 | 128 | $out .= "<strong>$ssid</strong>"; |
@@ -141,10 +141,10 @@ discard block |
||
| 141 | 141 | $use_anon = $attr['internal:use_anon_outer'] [0]; |
| 142 | 142 | if ($use_anon) { |
| 143 | 143 | $outer_user = $attr['internal:anon_local_value'][0]; |
| 144 | - $outer_id = $outer_user.'@'.$attr['internal:realm'][0]; |
|
| 144 | + $outer_id = $outer_user . '@' . $attr['internal:realm'][0]; |
|
| 145 | 145 | } |
| 146 | 146 | // $servers = preg_quote(implode(';',$attr['eap:server_name'])); |
| 147 | - $servers = implode(';',$attr['eap:server_name']); |
|
| 147 | + $servers = implode(';', $attr['eap:server_name']); |
|
| 148 | 148 | |
| 149 | 149 | $ca_array = $attr['internal:CAs'][0]; |
| 150 | 150 | |
@@ -153,12 +153,12 @@ discard block |
||
| 153 | 153 | <EapMethod> |
| 154 | 154 | '; |
| 155 | 155 | |
| 156 | -$profile_file_contents .= '<Type xmlns="http://www.microsoft.com/provisioning/EapCommon">'. |
|
| 157 | - $this->selected_eap["OUTER"].'</Type> |
|
| 156 | +$profile_file_contents .= '<Type xmlns="http://www.microsoft.com/provisioning/EapCommon">' . |
|
| 157 | + $this->selected_eap["OUTER"] . '</Type> |
|
| 158 | 158 | <VendorId xmlns="http://www.microsoft.com/provisioning/EapCommon">0</VendorId> |
| 159 | 159 | <VendorType xmlns="http://www.microsoft.com/provisioning/EapCommon">0</VendorType> |
| 160 | 160 | '; |
| 161 | -if( $eap == EAP::$TLS) { |
|
| 161 | +if ($eap == EAP::$TLS) { |
|
| 162 | 162 | $profile_file_contents .= '<AuthorId xmlns="http://www.microsoft.com/provisioning/EapCommon">0</AuthorId> |
| 163 | 163 | </EapMethod> |
| 164 | 164 | '; |
@@ -174,15 +174,15 @@ discard block |
||
| 174 | 174 | </eapTls:CredentialsSource> |
| 175 | 175 | <eapTls:ServerValidation> |
| 176 | 176 | <eapTls:DisableUserPromptForServerValidation>true</eapTls:DisableUserPromptForServerValidation> |
| 177 | -<eapTls:ServerNames>'.$servers.'</eapTls:ServerNames>'; |
|
| 178 | -if($ca_array) { |
|
| 177 | +<eapTls:ServerNames>'.$servers . '</eapTls:ServerNames>'; |
|
| 178 | +if ($ca_array) { |
|
| 179 | 179 | foreach ($ca_array as $CA) |
| 180 | - if($CA['root']) |
|
| 181 | - $profile_file_contents .= "<eapTls:TrustedRootCA>".$CA['sha1']."</eapTls:TrustedRootCA>\n"; |
|
| 180 | + if ($CA['root']) |
|
| 181 | + $profile_file_contents .= "<eapTls:TrustedRootCA>" . $CA['sha1'] . "</eapTls:TrustedRootCA>\n"; |
|
| 182 | 182 | } |
| 183 | 183 | $profile_file_contents .= '</eapTls:ServerValidation> |
| 184 | 184 | '; |
| 185 | -if(isset($attr['eap-specific:tls_use_other_id']) && $attr['eap-specific:tls_use_other_id'][0] == 'on') |
|
| 185 | +if (isset($attr['eap-specific:tls_use_other_id']) && $attr['eap-specific:tls_use_other_id'][0] == 'on') |
|
| 186 | 186 | $profile_file_contents .= '<eapTls:DifferentUsername>true</eapTls:DifferentUsername>'; |
| 187 | 187 | else |
| 188 | 188 | $profile_file_contents .= '<eapTls:DifferentUsername>false</eapTls:DifferentUsername>'; |
@@ -191,8 +191,8 @@ discard block |
||
| 191 | 191 | </baseEap:Eap> |
| 192 | 192 | </Config> |
| 193 | 193 | '; |
| 194 | -} elseif ( $eap == EAP::$PEAP_MSCHAP2) { |
|
| 195 | -if(isset($attr['eap:enable_nea']) && $attr['eap:enable_nea'][0] == 'on') |
|
| 194 | +} elseif ($eap == EAP::$PEAP_MSCHAP2) { |
|
| 195 | +if (isset($attr['eap:enable_nea']) && $attr['eap:enable_nea'][0] == 'on') |
|
| 196 | 196 | $nea = 'true'; |
| 197 | 197 | else |
| 198 | 198 | $nea = 'false'; |
@@ -205,11 +205,11 @@ discard block |
||
| 205 | 205 | <EapType xmlns="http://www.microsoft.com/provisioning/MsPeapConnectionPropertiesV1"> |
| 206 | 206 | <ServerValidation> |
| 207 | 207 | <DisableUserPromptForServerValidation>true</DisableUserPromptForServerValidation> |
| 208 | -<ServerNames>'.$servers.'</ServerNames>'; |
|
| 209 | -if($ca_array) { |
|
| 208 | +<ServerNames>'.$servers . '</ServerNames>'; |
|
| 209 | +if ($ca_array) { |
|
| 210 | 210 | foreach ($ca_array as $CA) |
| 211 | - if($CA['root']) |
|
| 212 | - $w8_ext .= "<TrustedRootCA>".$CA['sha1']."</TrustedRootCA>\n"; |
|
| 211 | + if ($CA['root']) |
|
| 212 | + $w8_ext .= "<TrustedRootCA>" . $CA['sha1'] . "</TrustedRootCA>\n"; |
|
| 213 | 213 | } |
| 214 | 214 | $w8_ext .= '</ServerValidation> |
| 215 | 215 | <FastReconnect>true</FastReconnect> |
@@ -220,50 +220,50 @@ discard block |
||
| 220 | 220 | <UseWinLogonCredentials>false</UseWinLogonCredentials> |
| 221 | 221 | </EapType> |
| 222 | 222 | </Eap> |
| 223 | -<EnableQuarantineChecks>'.$nea.'</EnableQuarantineChecks> |
|
| 223 | +<EnableQuarantineChecks>'.$nea . '</EnableQuarantineChecks> |
|
| 224 | 224 | <RequireCryptoBinding>false</RequireCryptoBinding> |
| 225 | 225 | '; |
| 226 | -if($use_anon == 1) { |
|
| 227 | -$w8_ext .='<PeapExtensions> |
|
| 226 | +if ($use_anon == 1) { |
|
| 227 | +$w8_ext .= '<PeapExtensions> |
|
| 228 | 228 | <IdentityPrivacy xmlns="http://www.microsoft.com/provisioning/MsPeapConnectionPropertiesV2"> |
| 229 | 229 | <EnableIdentityPrivacy>true</EnableIdentityPrivacy> |
| 230 | 230 | '; |
| 231 | -if(isset($outer_user) && $outer_user) |
|
| 232 | -$w8_ext .='<AnonymousUserName>'.$outer_user.'</AnonymousUserName> |
|
| 231 | +if (isset($outer_user) && $outer_user) |
|
| 232 | +$w8_ext .= '<AnonymousUserName>' . $outer_user . '</AnonymousUserName> |
|
| 233 | 233 | '; |
| 234 | 234 | else |
| 235 | -$w8_ext .='<AnonymousUserName/> |
|
| 235 | +$w8_ext .= '<AnonymousUserName/> |
|
| 236 | 236 | '; |
| 237 | -$w8_ext .='</IdentityPrivacy> |
|
| 237 | +$w8_ext .= '</IdentityPrivacy> |
|
| 238 | 238 | </PeapExtensions> |
| 239 | 239 | '; |
| 240 | 240 | } |
| 241 | -$w8_ext .='</EapType> |
|
| 241 | +$w8_ext .= '</EapType> |
|
| 242 | 242 | </Eap> |
| 243 | 243 | </Config> |
| 244 | 244 | '; |
| 245 | -} elseif ( $eap == EAP::$TTLS_PAP || $eap == EAP::$TTLS_MSCHAP2) { |
|
| 245 | +} elseif ($eap == EAP::$TTLS_PAP || $eap == EAP::$TTLS_MSCHAP2) { |
|
| 246 | 246 | $profile_file_contents .= '<AuthorId xmlns="http://www.microsoft.com/provisioning/EapCommon">311</AuthorId> |
| 247 | 247 | </EapMethod> |
| 248 | 248 | '; |
| 249 | 249 | $w8_ext = '<Config xmlns="http://www.microsoft.com/provisioning/EapHostConfig"> |
| 250 | 250 | <EapTtls xmlns="http://www.microsoft.com/provisioning/EapTtlsConnectionPropertiesV1"> |
| 251 | 251 | <ServerValidation> |
| 252 | -<ServerNames>'.$servers.'</ServerNames> '; |
|
| 253 | -if($ca_array) { |
|
| 252 | +<ServerNames>'.$servers . '</ServerNames> '; |
|
| 253 | +if ($ca_array) { |
|
| 254 | 254 | foreach ($ca_array as $CA) |
| 255 | - if($CA['root']) |
|
| 256 | - $w8_ext .= "<TrustedRootCAHash>".chunk_split($CA['sha1'],2,' ')."</TrustedRootCAHash>\n"; |
|
| 255 | + if ($CA['root']) |
|
| 256 | + $w8_ext .= "<TrustedRootCAHash>" . chunk_split($CA['sha1'], 2, ' ') . "</TrustedRootCAHash>\n"; |
|
| 257 | 257 | } |
| 258 | -$w8_ext .='<DisablePrompt>true</DisablePrompt> |
|
| 258 | +$w8_ext .= '<DisablePrompt>true</DisablePrompt> |
|
| 259 | 259 | </ServerValidation> |
| 260 | 260 | <Phase2Authentication> |
| 261 | 261 | '; |
| 262 | -if ( $eap == EAP::$TTLS_PAP) { |
|
| 263 | - $w8_ext .='<PAPAuthentication /> '; |
|
| 262 | +if ($eap == EAP::$TTLS_PAP) { |
|
| 263 | + $w8_ext .= '<PAPAuthentication /> '; |
|
| 264 | 264 | } |
| 265 | -if ( $eap == EAP::$TTLS_MSCHAP2) { |
|
| 266 | - $w8_ext .='<MSCHAPv2Authentication> |
|
| 265 | +if ($eap == EAP::$TTLS_MSCHAP2) { |
|
| 266 | + $w8_ext .= '<MSCHAPv2Authentication> |
|
| 267 | 267 | <UseWinlogonCredentials>false</UseWinlogonCredentials> |
| 268 | 268 | </MSCHAPv2Authentication> |
| 269 | 269 | '; |
@@ -271,24 +271,24 @@ discard block |
||
| 271 | 271 | $w8_ext .= '</Phase2Authentication> |
| 272 | 272 | <Phase1Identity> |
| 273 | 273 | '; |
| 274 | -if($use_anon == 1) { |
|
| 274 | +if ($use_anon == 1) { |
|
| 275 | 275 | $w8_ext .= '<IdentityPrivacy>true</IdentityPrivacy> |
| 276 | 276 | '; |
| 277 | - if(isset($outer_id) && $outer_id) |
|
| 278 | - $w8_ext .='<AnonymousIdentity>'.$outer_id.'</AnonymousIdentity> |
|
| 277 | + if (isset($outer_id) && $outer_id) |
|
| 278 | + $w8_ext .= '<AnonymousIdentity>' . $outer_id . '</AnonymousIdentity> |
|
| 279 | 279 | '; |
| 280 | 280 | else |
| 281 | - $w8_ext .='<AnonymousIdentity/> |
|
| 281 | + $w8_ext .= '<AnonymousIdentity/> |
|
| 282 | 282 | '; |
| 283 | 283 | } else { |
| 284 | 284 | $w8_ext .= '<IdentityPrivacy>false</IdentityPrivacy> |
| 285 | 285 | '; |
| 286 | 286 | } |
| 287 | -$w8_ext .='</Phase1Identity> |
|
| 287 | +$w8_ext .= '</Phase1Identity> |
|
| 288 | 288 | </EapTtls> |
| 289 | 289 | </Config> |
| 290 | 290 | '; |
| 291 | -} elseif ( $eap == EAP::$PWD) { |
|
| 291 | +} elseif ($eap == EAP::$PWD) { |
|
| 292 | 292 | $profile_file_contents .= '<AuthorId xmlns="http://www.microsoft.com/provisioning/EapCommon">0</AuthorId> |
| 293 | 293 | </EapMethod> |
| 294 | 294 | '; |
@@ -297,7 +297,7 @@ discard block |
||
| 297 | 297 | |
| 298 | 298 | $profile_file_contents_end = '</EapHostConfig></EAPConfig>'; |
| 299 | 299 | $return_array = []; |
| 300 | -$return_array['w8'] = $profile_file_contents.$w8_ext.$profile_file_contents_end; |
|
| 300 | +$return_array['w8'] = $profile_file_contents . $w8_ext . $profile_file_contents_end; |
|
| 301 | 301 | return $return_array; |
| 302 | 302 | } |
| 303 | 303 | |
@@ -309,13 +309,13 @@ discard block |
||
| 309 | 309 | /** |
| 310 | 310 | * produce PEAP, TLS and TTLS configuration files for Windows 8 |
| 311 | 311 | */ |
| 312 | - private function writeWLANprofile($wlan_profile_name,$ssid,$auth,$encryption,$eap_config,$i) { |
|
| 312 | + private function writeWLANprofile($wlan_profile_name, $ssid, $auth, $encryption, $eap_config, $i) { |
|
| 313 | 313 | $profile_file_contents = '<?xml version="1.0"?> |
| 314 | 314 | <WLANProfile xmlns="http://www.microsoft.com/networking/WLAN/profile/v1"> |
| 315 | -<name>'.$wlan_profile_name.'</name> |
|
| 315 | +<name>'.$wlan_profile_name . '</name> |
|
| 316 | 316 | <SSIDConfig> |
| 317 | 317 | <SSID> |
| 318 | -<name>'.$ssid.'</name> |
|
| 318 | +<name>'.$ssid . '</name> |
|
| 319 | 319 | </SSID> |
| 320 | 320 | <nonBroadcast>true</nonBroadcast> |
| 321 | 321 | </SSIDConfig> |
@@ -325,12 +325,12 @@ discard block |
||
| 325 | 325 | <MSM> |
| 326 | 326 | <security> |
| 327 | 327 | <authEncryption> |
| 328 | -<authentication>'.$auth.'</authentication> |
|
| 329 | -<encryption>'.$encryption.'</encryption> |
|
| 328 | +<authentication>'.$auth . '</authentication> |
|
| 329 | +<encryption>'.$encryption . '</encryption> |
|
| 330 | 330 | <useOneX>true</useOneX> |
| 331 | 331 | </authEncryption> |
| 332 | 332 | '; |
| 333 | -if($auth == 'WPA2') |
|
| 333 | +if ($auth == 'WPA2') |
|
| 334 | 334 | $profile_file_contents .= '<PMKCacheMode>enabled</PMKCacheMode> |
| 335 | 335 | <PMKCacheTTL>720</PMKCacheTTL> |
| 336 | 336 | <PMKCacheSize>128</PMKCacheSize> |
@@ -348,14 +348,14 @@ discard block |
||
| 348 | 348 | </WLANProfile> |
| 349 | 349 | '; |
| 350 | 350 | |
| 351 | -if(! is_dir('w8')) |
|
| 351 | +if (!is_dir('w8')) |
|
| 352 | 352 | mkdir('w8'); |
| 353 | 353 | $xml_f_name = "w8/wlan_prof-$i.xml"; |
| 354 | -$xml_f = fopen($xml_f_name,'w'); |
|
| 355 | -fwrite($xml_f,$profile_file_contents. $eap_config['w8']. $closing) ; |
|
| 354 | +$xml_f = fopen($xml_f_name, 'w'); |
|
| 355 | +fwrite($xml_f, $profile_file_contents . $eap_config['w8'] . $closing); |
|
| 356 | 356 | fclose($xml_f); |
| 357 | -debug(2,"Installer has been written into directory $this->FPATH\n"); |
|
| 358 | -debug(4,"WWWWLAN_Profile:$wlan_profile_name:$encryption\n"); |
|
| 357 | +debug(2, "Installer has been written into directory $this->FPATH\n"); |
|
| 358 | +debug(4, "WWWWLAN_Profile:$wlan_profile_name:$encryption\n"); |
|
| 359 | 359 | return("\"$wlan_profile_name\" \"$encryption\""); |
| 360 | 360 | } |
| 361 | 361 | |
@@ -375,29 +375,29 @@ discard block |
||
| 375 | 375 | </LANProfile> |
| 376 | 376 | '; |
| 377 | 377 | |
| 378 | -if(! is_dir('w8')) |
|
| 378 | +if (!is_dir('w8')) |
|
| 379 | 379 | mkdir('w8'); |
| 380 | 380 | $xml_f_name = "w8/lan_prof.xml"; |
| 381 | -$xml_f = fopen($xml_f_name,'w'); |
|
| 382 | -fwrite($xml_f,$profile_file_contents. $eap_config['w8']. $closing) ; |
|
| 381 | +$xml_f = fopen($xml_f_name, 'w'); |
|
| 382 | +fwrite($xml_f, $profile_file_contents . $eap_config['w8'] . $closing); |
|
| 383 | 383 | fclose($xml_f); |
| 384 | -debug(2,"Installer has been written into directory $this->FPATH\n"); |
|
| 384 | +debug(2, "Installer has been written into directory $this->FPATH\n"); |
|
| 385 | 385 | } |
| 386 | 386 | |
| 387 | 387 | |
| 388 | 388 | |
| 389 | -private function writeMainNSH($eap,$attr) { |
|
| 390 | -debug(4,"writeMainNSH"); debug(4,$attr); |
|
| 389 | +private function writeMainNSH($eap, $attr) { |
|
| 390 | +debug(4, "writeMainNSH"); debug(4, $attr); |
|
| 391 | 391 | $fcontents = "!define W8\n"; |
| 392 | -if(Config::$NSIS_VERSION >= 3) |
|
| 393 | - $fcontents .= "Unicode true\n"; |
|
| 392 | +if (Config::$NSIS_VERSION >= 3) |
|
| 393 | + $fcontents .= "Unicode true\n"; |
|
| 394 | 394 | |
| 395 | 395 | |
| 396 | 396 | $EAP_OPTS = [ |
| 397 | -PEAP=>['str'=>'PEAP','exec'=>'user'], |
|
| 398 | -TLS=>['str'=>'TLS','exec'=>'user'], |
|
| 399 | -TTLS=>['str'=>'TTLS','exec'=>'user'], |
|
| 400 | -PWD=>['str'=>'PWD','exec'=>'user'], |
|
| 397 | +PEAP=>['str'=>'PEAP', 'exec'=>'user'], |
|
| 398 | +TLS=>['str'=>'TLS', 'exec'=>'user'], |
|
| 399 | +TTLS=>['str'=>'TTLS', 'exec'=>'user'], |
|
| 400 | +PWD=>['str'=>'PWD', 'exec'=>'user'], |
|
| 401 | 401 | ]; |
| 402 | 402 | |
| 403 | 403 | // Uncomment the line below if you want this module to run under XP (only displaying a warning) |
@@ -407,24 +407,24 @@ discard block |
||
| 407 | 407 | $exec_level = $EAP_OPTS[$eap["OUTER"]]['exec']; |
| 408 | 408 | $eap_str = $EAP_OPTS[$eap["OUTER"]]['str']; |
| 409 | 409 | |
| 410 | -$fcontents .= '!define '.$eap_str; |
|
| 411 | -$fcontents .= "\n".'!define EXECLEVEL "'.$exec_level.'"'; |
|
| 410 | +$fcontents .= '!define ' . $eap_str; |
|
| 411 | +$fcontents .= "\n" . '!define EXECLEVEL "' . $exec_level . '"'; |
|
| 412 | 412 | |
| 413 | -if($attr['internal:profile_count'][0] > 1) |
|
| 414 | -$fcontents .= "\n".'!define USER_GROUP "'.$this->translateString(str_replace('"','$\\"',$attr['profile:name'][0]), $this->code_page).'"'; |
|
| 413 | +if ($attr['internal:profile_count'][0] > 1) |
|
| 414 | +$fcontents .= "\n" . '!define USER_GROUP "' . $this->translateString(str_replace('"', '$\\"', $attr['profile:name'][0]), $this->code_page) . '"'; |
|
| 415 | 415 | $fcontents .= ' |
| 416 | -Caption "'. $this->translateString(sprintf(sprint_nsi(_("%s installer for %s")),Config::$CONSORTIUM['name'],$attr['general:instname'][0]), $this->code_page).'" |
|
| 417 | -!define APPLICATION "'. $this->translateString(sprintf(sprint_nsi(_("%s installer for %s")),Config::$CONSORTIUM['name'],$attr['general:instname'][0]), $this->code_page).'" |
|
| 418 | -!define VERSION "'.CAT::$VERSION_MAJOR.'.'.CAT::$VERSION_MINOR.'" |
|
| 416 | +Caption "'. $this->translateString(sprintf(sprint_nsi(_("%s installer for %s")), Config::$CONSORTIUM['name'], $attr['general:instname'][0]), $this->code_page) . '" |
|
| 417 | +!define APPLICATION "'. $this->translateString(sprintf(sprint_nsi(_("%s installer for %s")), Config::$CONSORTIUM['name'], $attr['general:instname'][0]), $this->code_page) . '" |
|
| 418 | +!define VERSION "'.CAT::$VERSION_MAJOR . '.' . CAT::$VERSION_MINOR . '" |
|
| 419 | 419 | !define INSTALLER_NAME "installer.exe" |
| 420 | -!define LANG "'.$this->lang.'" |
|
| 420 | +!define LANG "'.$this->lang . '" |
|
| 421 | 421 | '; |
| 422 | 422 | $fcontents .= $this->msInfoFile($attr); |
| 423 | 423 | |
| 424 | 424 | $fcontents .= ';-------------------------------- |
| 425 | -!define ORGANISATION "'.$this->translateString($attr['general:instname'][0], $this->code_page).'" |
|
| 426 | -!define SUPPORT "'. ((isset($attr['support:email'][0]) && $attr['support:email'][0] ) ? $attr['support:email'][0] : $this->translateString($this->support_email_substitute , $this->code_page)) .'" |
|
| 427 | -!define URL "'. ((isset($attr['support:url'][0]) && $attr['support:url'][0] ) ? $attr['support:url'][0] : $this->translateString($this->support_url_substitute, $this->code_page)) .'" |
|
| 425 | +!define ORGANISATION "'.$this->translateString($attr['general:instname'][0], $this->code_page) . '" |
|
| 426 | +!define SUPPORT "'. ((isset($attr['support:email'][0]) && $attr['support:email'][0]) ? $attr['support:email'][0] : $this->translateString($this->support_email_substitute, $this->code_page)) . '" |
|
| 427 | +!define URL "'. ((isset($attr['support:url'][0]) && $attr['support:url'][0]) ? $attr['support:url'][0] : $this->translateString($this->support_url_substitute, $this->code_page)) . '" |
|
| 428 | 428 | |
| 429 | 429 | !ifdef TLS |
| 430 | 430 | '; |
@@ -434,33 +434,33 @@ discard block |
||
| 434 | 434 | !endif |
| 435 | 435 | '; |
| 436 | 436 | |
| 437 | -if(isset($this->attributes['media:wired'][0]) && $attr['media:wired'][0] == 'on') |
|
| 437 | +if (isset($this->attributes['media:wired'][0]) && $attr['media:wired'][0] == 'on') |
|
| 438 | 438 | $fcontents .= '!define WIRED |
| 439 | 439 | '; |
| 440 | 440 | |
| 441 | -$f = fopen('main.nsh','w'); |
|
| 441 | +$f = fopen('main.nsh', 'w'); |
|
| 442 | 442 | fwrite($f, $fcontents); |
| 443 | 443 | fclose($f); |
| 444 | 444 | |
| 445 | 445 | } |
| 446 | 446 | |
| 447 | -private function writeProfilesNSH($P,$ca_array,$wired=0) { |
|
| 448 | -debug(4,"writeProfilesNSH"); |
|
| 449 | -debug(4,$P); |
|
| 447 | +private function writeProfilesNSH($P, $ca_array, $wired = 0) { |
|
| 448 | +debug(4, "writeProfilesNSH"); |
|
| 449 | +debug(4, $P); |
|
| 450 | 450 | $fcontents = ''; |
| 451 | - foreach($P as $p) |
|
| 451 | + foreach ($P as $p) |
|
| 452 | 452 | $fcontents .= "!insertmacro define_wlan_profile $p\n"; |
| 453 | 453 | |
| 454 | -$f = fopen('profiles.nsh','w'); |
|
| 454 | +$f = fopen('profiles.nsh', 'w'); |
|
| 455 | 455 | fwrite($f, $fcontents); |
| 456 | 456 | fclose($f); |
| 457 | 457 | |
| 458 | 458 | $fcontents = ''; |
| 459 | -$f = fopen('certs.nsh','w'); |
|
| 460 | -if($ca_array) { |
|
| 459 | +$f = fopen('certs.nsh', 'w'); |
|
| 460 | +if ($ca_array) { |
|
| 461 | 461 | foreach ($ca_array as $CA) { |
| 462 | 462 | $store = $CA['root'] ? "root" : "ca"; |
| 463 | - $fcontents .= '!insertmacro install_ca_cert "'.$CA['file'].'" "'.$CA['sha1'].'" "'.$store."\"\n"; |
|
| 463 | + $fcontents .= '!insertmacro install_ca_cert "' . $CA['file'] . '" "' . $CA['sha1'] . '" "' . $store . "\"\n"; |
|
| 464 | 464 | } |
| 465 | 465 | fwrite($f, $fcontents); |
| 466 | 466 | } |
@@ -469,8 +469,8 @@ discard block |
||
| 469 | 469 | |
| 470 | 470 | //private function write |
| 471 | 471 | |
| 472 | -private function copyFiles ($eap) { |
|
| 473 | -debug(4,"copyFiles start\n"); |
|
| 472 | +private function copyFiles($eap) { |
|
| 473 | +debug(4, "copyFiles start\n"); |
|
| 474 | 474 | $result; |
| 475 | 475 | $result = $this->copyFile('wlan_test.exe'); |
| 476 | 476 | $result = $this->copyFile('check_wired.cmd'); |
@@ -480,16 +480,16 @@ discard block |
||
| 480 | 480 | $result = $this->copyFile('base64.nsh'); |
| 481 | 481 | $result = $result && $this->copyFile('cat32.ico'); |
| 482 | 482 | $result = $result && $this->copyFile('cat_150.bmp'); |
| 483 | - $this->translateFile('common.inc','common.nsh',$this->code_page); |
|
| 484 | - if($eap["OUTER"] == PWD) { |
|
| 485 | - $this->translateFile('pwd.inc','cat.NSI',$this->code_page); |
|
| 483 | + $this->translateFile('common.inc', 'common.nsh', $this->code_page); |
|
| 484 | + if ($eap["OUTER"] == PWD) { |
|
| 485 | + $this->translateFile('pwd.inc', 'cat.NSI', $this->code_page); |
|
| 486 | 486 | $result = $result && $this->copyFile('Aruba_Networks_EAP-pwd_x32.msi'); |
| 487 | 487 | $result = $result && $this->copyFile('Aruba_Networks_EAP-pwd_x64.msi'); |
| 488 | 488 | } else { |
| 489 | - $this->translateFile('eap_w8.inc','cat.NSI',$this->code_page); |
|
| 489 | + $this->translateFile('eap_w8.inc', 'cat.NSI', $this->code_page); |
|
| 490 | 490 | $result = 1; |
| 491 | 491 | } |
| 492 | -debug(4,"copyFiles end\n"); |
|
| 492 | +debug(4, "copyFiles end\n"); |
|
| 493 | 493 | return($result); |
| 494 | 494 | } |
| 495 | 495 | |
@@ -46,10 +46,12 @@ discard block |
||
| 46 | 46 | // create a list of profiles to be deleted after installation |
| 47 | 47 | $delProfiles = []; |
| 48 | 48 | foreach ($delSSIDs as $ssid => $cipher) { |
| 49 | - if($cipher == 'DEL') |
|
| 50 | - $delProfiles[] = $ssid; |
|
| 51 | - if($cipher == 'TKIP') |
|
| 52 | - $delProfiles[] = $ssid.' (TKIP)'; |
|
| 49 | + if($cipher == 'DEL') { |
|
| 50 | + $delProfiles[] = $ssid; |
|
| 51 | + } |
|
| 52 | + if($cipher == 'TKIP') { |
|
| 53 | + $delProfiles[] = $ssid.' (TKIP)'; |
|
| 54 | + } |
|
| 53 | 55 | } |
| 54 | 56 | |
| 55 | 57 | |
@@ -76,11 +78,13 @@ discard block |
||
| 76 | 78 | |
| 77 | 79 | $this->writeProfilesNSH($WindowsProfile, $CA_files,$set_wired); |
| 78 | 80 | $this->writeAdditionalDeletes($delProfiles); |
| 79 | - if(isset($additional_deletes) && count($additional_deletes)) |
|
| 80 | - $this->writeAdditionalDeletes($additional_deletes); |
|
| 81 | + if(isset($additional_deletes) && count($additional_deletes)) { |
|
| 82 | + $this->writeAdditionalDeletes($additional_deletes); |
|
| 83 | + } |
|
| 81 | 84 | $this->copyFiles($this->selected_eap); |
| 82 | - if(isset($this->attributes['internal:logo_file'])) |
|
| 83 | - $this->combineLogo($this->attributes['internal:logo_file']); |
|
| 85 | + if(isset($this->attributes['internal:logo_file'])) { |
|
| 86 | + $this->combineLogo($this->attributes['internal:logo_file']); |
|
| 87 | + } |
|
| 84 | 88 | $this->writeMainNSH($this->selected_eap,$this->attributes); |
| 85 | 89 | $this->compileNSIS(); |
| 86 | 90 | $installer_path = $this->signInstaller($this->attributes); |
@@ -97,13 +101,15 @@ discard block |
||
| 97 | 101 | if($ssid_ct > 1) { |
| 98 | 102 | if($ssid_ct > 2) { |
| 99 | 103 | $out .= sprintf(_("In addition to <strong>%s</strong> the installer will also configure access to the following networks:"),implode(', ',Config::$CONSORTIUM['ssid']))." "; |
| 100 | - } else |
|
| 101 | - $out .= sprintf(_("In addition to <strong>%s</strong> the installer will also configure access to:"),implode(', ',Config::$CONSORTIUM['ssid']))." "; |
|
| 104 | + } else { |
|
| 105 | + $out .= sprintf(_("In addition to <strong>%s</strong> the installer will also configure access to:"),implode(', ',Config::$CONSORTIUM['ssid']))." "; |
|
| 106 | + } |
|
| 102 | 107 | $i = 0; |
| 103 | 108 | foreach ($this->attributes['internal:SSID'] as $ssid=>$v) { |
| 104 | 109 | if(! in_array($ssid, Config::$CONSORTIUM['ssid'])) { |
| 105 | - if($i > 0) |
|
| 106 | - $out .= ", "; |
|
| 110 | + if($i > 0) { |
|
| 111 | + $out .= ", "; |
|
| 112 | + } |
|
| 107 | 113 | $i++; |
| 108 | 114 | $out .= "<strong>$ssid</strong>"; |
| 109 | 115 | } |
@@ -111,9 +117,9 @@ discard block |
||
| 111 | 117 | $out .= "<p>"; |
| 112 | 118 | } |
| 113 | 119 | |
| 114 | -if($this->eap == EAP::$TLS) |
|
| 120 | +if($this->eap == EAP::$TLS) { |
|
| 115 | 121 | $out .= _("In order to connect to the network you will need an a personal certificate in the form of a p12 file. You should obtain this certificate from your home institution. Consult the support page to find out how this certificate can be obtained. Such certificate files are password protected. You should have both the file and the password available during the installation process."); |
| 116 | -else { |
|
| 122 | +} else { |
|
| 117 | 123 | $out .= _("In order to connect to the network you will need an account from your home institution. You should consult the support page to find out how this account can be obtained. It is very likely that your account is already activated."); |
| 118 | 124 | $out .= "<p>"; |
| 119 | 125 | $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."); |
@@ -122,8 +128,9 @@ discard block |
||
| 122 | 128 | $out .= _("You will be required to enter the same credentials for each of the configured notworks:")." "; |
| 123 | 129 | $i = 0; |
| 124 | 130 | foreach ($this->attributes['internal:SSID'] as $ssid=>$v) { |
| 125 | - if($i > 0) |
|
| 126 | - $out .= ", "; |
|
| 131 | + if($i > 0) { |
|
| 132 | + $out .= ", "; |
|
| 133 | + } |
|
| 127 | 134 | $i++; |
| 128 | 135 | $out .= "<strong>$ssid</strong>"; |
| 129 | 136 | } |
@@ -176,26 +183,29 @@ discard block |
||
| 176 | 183 | <eapTls:DisableUserPromptForServerValidation>true</eapTls:DisableUserPromptForServerValidation> |
| 177 | 184 | <eapTls:ServerNames>'.$servers.'</eapTls:ServerNames>'; |
| 178 | 185 | if($ca_array) { |
| 179 | -foreach ($ca_array as $CA) |
|
| 186 | +foreach ($ca_array as $CA) { |
|
| 180 | 187 | if($CA['root']) |
| 181 | 188 | $profile_file_contents .= "<eapTls:TrustedRootCA>".$CA['sha1']."</eapTls:TrustedRootCA>\n"; |
| 182 | 189 | } |
| 190 | +} |
|
| 183 | 191 | $profile_file_contents .= '</eapTls:ServerValidation> |
| 184 | 192 | '; |
| 185 | -if(isset($attr['eap-specific:tls_use_other_id']) && $attr['eap-specific:tls_use_other_id'][0] == 'on') |
|
| 193 | +if(isset($attr['eap-specific:tls_use_other_id']) && $attr['eap-specific:tls_use_other_id'][0] == 'on') { |
|
| 186 | 194 | $profile_file_contents .= '<eapTls:DifferentUsername>true</eapTls:DifferentUsername>'; |
| 187 | -else |
|
| 195 | +} else { |
|
| 188 | 196 | $profile_file_contents .= '<eapTls:DifferentUsername>false</eapTls:DifferentUsername>'; |
| 197 | +} |
|
| 189 | 198 | $profile_file_contents .= ' |
| 190 | 199 | </eapTls:EapType> |
| 191 | 200 | </baseEap:Eap> |
| 192 | 201 | </Config> |
| 193 | 202 | '; |
| 194 | 203 | } elseif ( $eap == EAP::$PEAP_MSCHAP2) { |
| 195 | -if(isset($attr['eap:enable_nea']) && $attr['eap:enable_nea'][0] == 'on') |
|
| 204 | +if(isset($attr['eap:enable_nea']) && $attr['eap:enable_nea'][0] == 'on') { |
|
| 196 | 205 | $nea = 'true'; |
| 197 | -else |
|
| 206 | +} else { |
|
| 198 | 207 | $nea = 'false'; |
| 208 | +} |
|
| 199 | 209 | $profile_file_contents .= '<AuthorId xmlns="http://www.microsoft.com/provisioning/EapCommon">0</AuthorId> |
| 200 | 210 | </EapMethod> |
| 201 | 211 | '; |
@@ -207,10 +217,11 @@ discard block |
||
| 207 | 217 | <DisableUserPromptForServerValidation>true</DisableUserPromptForServerValidation> |
| 208 | 218 | <ServerNames>'.$servers.'</ServerNames>'; |
| 209 | 219 | if($ca_array) { |
| 210 | -foreach ($ca_array as $CA) |
|
| 220 | +foreach ($ca_array as $CA) { |
|
| 211 | 221 | if($CA['root']) |
| 212 | 222 | $w8_ext .= "<TrustedRootCA>".$CA['sha1']."</TrustedRootCA>\n"; |
| 213 | 223 | } |
| 224 | +} |
|
| 214 | 225 | $w8_ext .= '</ServerValidation> |
| 215 | 226 | <FastReconnect>true</FastReconnect> |
| 216 | 227 | <InnerEapOptional>false</InnerEapOptional> |
@@ -228,12 +239,13 @@ discard block |
||
| 228 | 239 | <IdentityPrivacy xmlns="http://www.microsoft.com/provisioning/MsPeapConnectionPropertiesV2"> |
| 229 | 240 | <EnableIdentityPrivacy>true</EnableIdentityPrivacy> |
| 230 | 241 | '; |
| 231 | -if(isset($outer_user) && $outer_user) |
|
| 232 | -$w8_ext .='<AnonymousUserName>'.$outer_user.'</AnonymousUserName> |
|
| 242 | +if(isset($outer_user) && $outer_user) { |
|
| 243 | + $w8_ext .='<AnonymousUserName>'.$outer_user.'</AnonymousUserName> |
|
| 233 | 244 | '; |
| 234 | -else |
|
| 235 | -$w8_ext .='<AnonymousUserName/> |
|
| 245 | +} else { |
|
| 246 | + $w8_ext .='<AnonymousUserName/> |
|
| 236 | 247 | '; |
| 248 | +} |
|
| 237 | 249 | $w8_ext .='</IdentityPrivacy> |
| 238 | 250 | </PeapExtensions> |
| 239 | 251 | '; |
@@ -251,10 +263,11 @@ discard block |
||
| 251 | 263 | <ServerValidation> |
| 252 | 264 | <ServerNames>'.$servers.'</ServerNames> '; |
| 253 | 265 | if($ca_array) { |
| 254 | -foreach ($ca_array as $CA) |
|
| 266 | +foreach ($ca_array as $CA) { |
|
| 255 | 267 | if($CA['root']) |
| 256 | 268 | $w8_ext .= "<TrustedRootCAHash>".chunk_split($CA['sha1'],2,' ')."</TrustedRootCAHash>\n"; |
| 257 | 269 | } |
| 270 | +} |
|
| 258 | 271 | $w8_ext .='<DisablePrompt>true</DisablePrompt> |
| 259 | 272 | </ServerValidation> |
| 260 | 273 | <Phase2Authentication> |
@@ -274,13 +287,14 @@ discard block |
||
| 274 | 287 | if($use_anon == 1) { |
| 275 | 288 | $w8_ext .= '<IdentityPrivacy>true</IdentityPrivacy> |
| 276 | 289 | '; |
| 277 | - if(isset($outer_id) && $outer_id) |
|
| 278 | - $w8_ext .='<AnonymousIdentity>'.$outer_id.'</AnonymousIdentity> |
|
| 290 | + if(isset($outer_id) && $outer_id) { |
|
| 291 | + $w8_ext .='<AnonymousIdentity>'.$outer_id.'</AnonymousIdentity> |
|
| 279 | 292 | '; |
| 280 | - else |
|
| 281 | - $w8_ext .='<AnonymousIdentity/> |
|
| 293 | + } else { |
|
| 294 | + $w8_ext .='<AnonymousIdentity/> |
|
| 282 | 295 | '; |
| 283 | -} else { |
|
| 296 | + } |
|
| 297 | + } else { |
|
| 284 | 298 | $w8_ext .= '<IdentityPrivacy>false</IdentityPrivacy> |
| 285 | 299 | '; |
| 286 | 300 | } |
@@ -330,12 +344,13 @@ discard block |
||
| 330 | 344 | <useOneX>true</useOneX> |
| 331 | 345 | </authEncryption> |
| 332 | 346 | '; |
| 333 | -if($auth == 'WPA2') |
|
| 334 | -$profile_file_contents .= '<PMKCacheMode>enabled</PMKCacheMode> |
|
| 347 | +if($auth == 'WPA2') { |
|
| 348 | + $profile_file_contents .= '<PMKCacheMode>enabled</PMKCacheMode> |
|
| 335 | 349 | <PMKCacheTTL>720</PMKCacheTTL> |
| 336 | 350 | <PMKCacheSize>128</PMKCacheSize> |
| 337 | 351 | <preAuthMode>disabled</preAuthMode> |
| 338 | 352 | '; |
| 353 | +} |
|
| 339 | 354 | $profile_file_contents .= '<OneX xmlns="http://www.microsoft.com/networking/OneX/v1"> |
| 340 | 355 | <cacheUserData>true</cacheUserData> |
| 341 | 356 | <authMode>user</authMode> |
@@ -348,8 +363,9 @@ discard block |
||
| 348 | 363 | </WLANProfile> |
| 349 | 364 | '; |
| 350 | 365 | |
| 351 | -if(! is_dir('w8')) |
|
| 366 | +if(! is_dir('w8')) { |
|
| 352 | 367 | mkdir('w8'); |
| 368 | +} |
|
| 353 | 369 | $xml_f_name = "w8/wlan_prof-$i.xml"; |
| 354 | 370 | $xml_f = fopen($xml_f_name,'w'); |
| 355 | 371 | fwrite($xml_f,$profile_file_contents. $eap_config['w8']. $closing) ; |
@@ -375,8 +391,9 @@ discard block |
||
| 375 | 391 | </LANProfile> |
| 376 | 392 | '; |
| 377 | 393 | |
| 378 | -if(! is_dir('w8')) |
|
| 394 | +if(! is_dir('w8')) { |
|
| 379 | 395 | mkdir('w8'); |
| 396 | +} |
|
| 380 | 397 | $xml_f_name = "w8/lan_prof.xml"; |
| 381 | 398 | $xml_f = fopen($xml_f_name,'w'); |
| 382 | 399 | fwrite($xml_f,$profile_file_contents. $eap_config['w8']. $closing) ; |
@@ -389,8 +406,9 @@ discard block |
||
| 389 | 406 | private function writeMainNSH($eap,$attr) { |
| 390 | 407 | debug(4,"writeMainNSH"); debug(4,$attr); |
| 391 | 408 | $fcontents = "!define W8\n"; |
| 392 | -if(Config::$NSIS_VERSION >= 3) |
|
| 409 | +if(Config::$NSIS_VERSION >= 3) { |
|
| 393 | 410 | $fcontents .= "Unicode true\n"; |
| 411 | +} |
|
| 394 | 412 | |
| 395 | 413 | |
| 396 | 414 | $EAP_OPTS = [ |
@@ -410,8 +428,9 @@ discard block |
||
| 410 | 428 | $fcontents .= '!define '.$eap_str; |
| 411 | 429 | $fcontents .= "\n".'!define EXECLEVEL "'.$exec_level.'"'; |
| 412 | 430 | |
| 413 | -if($attr['internal:profile_count'][0] > 1) |
|
| 414 | -$fcontents .= "\n".'!define USER_GROUP "'.$this->translateString(str_replace('"','$\\"',$attr['profile:name'][0]), $this->code_page).'"'; |
|
| 431 | +if($attr['internal:profile_count'][0] > 1) { |
|
| 432 | + $fcontents .= "\n".'!define USER_GROUP "'.$this->translateString(str_replace('"','$\\"',$attr['profile:name'][0]), $this->code_page).'"'; |
|
| 433 | +} |
|
| 415 | 434 | $fcontents .= ' |
| 416 | 435 | Caption "'. $this->translateString(sprintf(sprint_nsi(_("%s installer for %s")),Config::$CONSORTIUM['name'],$attr['general:instname'][0]), $this->code_page).'" |
| 417 | 436 | !define APPLICATION "'. $this->translateString(sprintf(sprint_nsi(_("%s installer for %s")),Config::$CONSORTIUM['name'],$attr['general:instname'][0]), $this->code_page).'" |
@@ -434,9 +453,10 @@ discard block |
||
| 434 | 453 | !endif |
| 435 | 454 | '; |
| 436 | 455 | |
| 437 | -if(isset($this->attributes['media:wired'][0]) && $attr['media:wired'][0] == 'on') |
|
| 456 | +if(isset($this->attributes['media:wired'][0]) && $attr['media:wired'][0] == 'on') { |
|
| 438 | 457 | $fcontents .= '!define WIRED |
| 439 | 458 | '; |
| 459 | +} |
|
| 440 | 460 | |
| 441 | 461 | $f = fopen('main.nsh','w'); |
| 442 | 462 | fwrite($f, $fcontents); |
@@ -448,8 +468,9 @@ discard block |
||
| 448 | 468 | debug(4,"writeProfilesNSH"); |
| 449 | 469 | debug(4,$P); |
| 450 | 470 | $fcontents = ''; |
| 451 | - foreach($P as $p) |
|
| 452 | - $fcontents .= "!insertmacro define_wlan_profile $p\n"; |
|
| 471 | + foreach($P as $p) { |
|
| 472 | + $fcontents .= "!insertmacro define_wlan_profile $p\n"; |
|
| 473 | + } |
|
| 453 | 474 | |
| 454 | 475 | $f = fopen('profiles.nsh','w'); |
| 455 | 476 | fwrite($f, $fcontents); |
@@ -26,74 +26,74 @@ discard block |
||
| 26 | 26 | */ |
| 27 | 27 | class Device_W8 extends WindowsCommon { |
| 28 | 28 | final public function __construct() { |
| 29 | - $this->supportedEapMethods = [EAP::$TLS, EAP::$PEAP_MSCHAP2, EAP::$TTLS_PAP, EAP::$TTLS_MSCHAP2, EAP::$PWD]; |
|
| 29 | + $this->supportedEapMethods = [EAP::$TLS, EAP::$PEAP_MSCHAP2, EAP::$TTLS_PAP, EAP::$TTLS_MSCHAP2, EAP::$PWD]; |
|
| 30 | 30 | # $this->supportedEapMethods = array(EAP::$TLS, EAP::$PEAP_MSCHAP2, EAP::$TTLS_PAP, EAP::$PWD); |
| 31 | - debug(4,"This device supports the following EAP methods: "); |
|
| 32 | - debug(4,$this->supportedEapMethods); |
|
| 33 | - $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."); |
|
| 31 | + debug(4,"This device supports the following EAP methods: "); |
|
| 32 | + debug(4,$this->supportedEapMethods); |
|
| 33 | + $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."); |
|
| 34 | 34 | } |
| 35 | 35 | |
| 36 | - public function writeInstaller() { |
|
| 37 | - $dom = textdomain(NULL); |
|
| 38 | - textdomain("devices"); |
|
| 39 | - // create certificate files and save their names in $CA_files arrary |
|
| 40 | - $CA_files = $this->saveCertificateFiles('der'); |
|
| 36 | + public function writeInstaller() { |
|
| 37 | + $dom = textdomain(NULL); |
|
| 38 | + textdomain("devices"); |
|
| 39 | + // create certificate files and save their names in $CA_files arrary |
|
| 40 | + $CA_files = $this->saveCertificateFiles('der'); |
|
| 41 | 41 | |
| 42 | - $SSIDs = $this->attributes['internal:SSID']; |
|
| 43 | - $delSSIDs = $this->attributes['internal:remove_SSID']; |
|
| 44 | - $this->prepareInstallerLang(); |
|
| 45 | - $set_wired = isset($this->attributes['media:wired'][0]) && $this->attributes['media:wired'][0] == 'on' ? 1 : 0; |
|
| 42 | + $SSIDs = $this->attributes['internal:SSID']; |
|
| 43 | + $delSSIDs = $this->attributes['internal:remove_SSID']; |
|
| 44 | + $this->prepareInstallerLang(); |
|
| 45 | + $set_wired = isset($this->attributes['media:wired'][0]) && $this->attributes['media:wired'][0] == 'on' ? 1 : 0; |
|
| 46 | 46 | // create a list of profiles to be deleted after installation |
| 47 | - $delProfiles = []; |
|
| 48 | - foreach ($delSSIDs as $ssid => $cipher) { |
|
| 49 | - if($cipher == 'DEL') |
|
| 50 | - $delProfiles[] = $ssid; |
|
| 51 | - if($cipher == 'TKIP') |
|
| 52 | - $delProfiles[] = $ssid.' (TKIP)'; |
|
| 53 | - } |
|
| 54 | - |
|
| 55 | - |
|
| 56 | - if ($this->selected_eap == EAP::$TLS || $this->selected_eap == EAP::$PEAP_MSCHAP2 || $this->selected_eap == EAP::$TTLS_PAP || $this->selected_eap == EAP::$TTLS_MSCHAP2 || $this->selected_eap == EAP::$PWD) { |
|
| 57 | - $WindowsProfile = []; |
|
| 58 | - $eap_config = $this->prepareEapConfig($this->attributes); |
|
| 59 | - $i = 0; |
|
| 60 | - foreach ($SSIDs as $ssid => $cipher) { |
|
| 61 | - if($cipher == 'TKIP') { |
|
| 62 | - $WindowsProfile[$i] = $this->writeWLANprofile ($ssid.' (TKIP)',$ssid,'WPA','TKIP',$eap_config,$i); |
|
| 63 | - $i++; |
|
| 64 | - } |
|
| 65 | - $WindowsProfile[$i] = $this->writeWLANprofile ($ssid,$ssid,'WPA2','AES',$eap_config,$i); |
|
| 66 | - $i++; |
|
| 67 | - } |
|
| 68 | - if($set_wired) { |
|
| 69 | - $this->writeLANprofile($eap_config); |
|
| 70 | - } |
|
| 71 | - } else { |
|
| 72 | - error(" this EAP type is not handled yet"); |
|
| 73 | - return; |
|
| 74 | - } |
|
| 47 | + $delProfiles = []; |
|
| 48 | + foreach ($delSSIDs as $ssid => $cipher) { |
|
| 49 | + if($cipher == 'DEL') |
|
| 50 | + $delProfiles[] = $ssid; |
|
| 51 | + if($cipher == 'TKIP') |
|
| 52 | + $delProfiles[] = $ssid.' (TKIP)'; |
|
| 53 | + } |
|
| 54 | + |
|
| 55 | + |
|
| 56 | + if ($this->selected_eap == EAP::$TLS || $this->selected_eap == EAP::$PEAP_MSCHAP2 || $this->selected_eap == EAP::$TTLS_PAP || $this->selected_eap == EAP::$TTLS_MSCHAP2 || $this->selected_eap == EAP::$PWD) { |
|
| 57 | + $WindowsProfile = []; |
|
| 58 | + $eap_config = $this->prepareEapConfig($this->attributes); |
|
| 59 | + $i = 0; |
|
| 60 | + foreach ($SSIDs as $ssid => $cipher) { |
|
| 61 | + if($cipher == 'TKIP') { |
|
| 62 | + $WindowsProfile[$i] = $this->writeWLANprofile ($ssid.' (TKIP)',$ssid,'WPA','TKIP',$eap_config,$i); |
|
| 63 | + $i++; |
|
| 64 | + } |
|
| 65 | + $WindowsProfile[$i] = $this->writeWLANprofile ($ssid,$ssid,'WPA2','AES',$eap_config,$i); |
|
| 66 | + $i++; |
|
| 67 | + } |
|
| 68 | + if($set_wired) { |
|
| 69 | + $this->writeLANprofile($eap_config); |
|
| 70 | + } |
|
| 71 | + } else { |
|
| 72 | + error(" this EAP type is not handled yet"); |
|
| 73 | + return; |
|
| 74 | + } |
|
| 75 | 75 | debug(4,"WindowsProfile"); debug(4,$WindowsProfile); |
| 76 | 76 | |
| 77 | 77 | $this->writeProfilesNSH($WindowsProfile, $CA_files,$set_wired); |
| 78 | 78 | $this->writeAdditionalDeletes($delProfiles); |
| 79 | 79 | if(isset($additional_deletes) && count($additional_deletes)) |
| 80 | - $this->writeAdditionalDeletes($additional_deletes); |
|
| 80 | + $this->writeAdditionalDeletes($additional_deletes); |
|
| 81 | 81 | $this->copyFiles($this->selected_eap); |
| 82 | 82 | if(isset($this->attributes['internal:logo_file'])) |
| 83 | - $this->combineLogo($this->attributes['internal:logo_file']); |
|
| 83 | + $this->combineLogo($this->attributes['internal:logo_file']); |
|
| 84 | 84 | $this->writeMainNSH($this->selected_eap,$this->attributes); |
| 85 | 85 | $this->compileNSIS(); |
| 86 | 86 | $installer_path = $this->signInstaller($this->attributes); |
| 87 | 87 | |
| 88 | 88 | textdomain($dom); |
| 89 | 89 | return($installer_path); |
| 90 | - } |
|
| 90 | + } |
|
| 91 | 91 | |
| 92 | - public function writeDeviceInfo() { |
|
| 92 | + public function writeDeviceInfo() { |
|
| 93 | 93 | $ssid_ct=count($this->attributes['internal:SSID']); |
| 94 | - $out = "<p>"; |
|
| 95 | - $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']); |
|
| 96 | - $out .= "<p>"; |
|
| 94 | + $out = "<p>"; |
|
| 95 | + $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']); |
|
| 96 | + $out .= "<p>"; |
|
| 97 | 97 | if($ssid_ct > 1) { |
| 98 | 98 | if($ssid_ct > 2) { |
| 99 | 99 | $out .= sprintf(_("In addition to <strong>%s</strong> the installer will also configure access to the following networks:"),implode(', ',Config::$CONSORTIUM['ssid']))." "; |
@@ -101,52 +101,52 @@ discard block |
||
| 101 | 101 | $out .= sprintf(_("In addition to <strong>%s</strong> the installer will also configure access to:"),implode(', ',Config::$CONSORTIUM['ssid']))." "; |
| 102 | 102 | $i = 0; |
| 103 | 103 | foreach ($this->attributes['internal:SSID'] as $ssid=>$v) { |
| 104 | - if(! in_array($ssid, Config::$CONSORTIUM['ssid'])) { |
|
| 105 | - if($i > 0) |
|
| 106 | - $out .= ", "; |
|
| 107 | - $i++; |
|
| 108 | - $out .= "<strong>$ssid</strong>"; |
|
| 109 | - } |
|
| 104 | + if(! in_array($ssid, Config::$CONSORTIUM['ssid'])) { |
|
| 105 | + if($i > 0) |
|
| 106 | + $out .= ", "; |
|
| 107 | + $i++; |
|
| 108 | + $out .= "<strong>$ssid</strong>"; |
|
| 109 | + } |
|
| 110 | 110 | } |
| 111 | 111 | $out .= "<p>"; |
| 112 | 112 | } |
| 113 | 113 | |
| 114 | 114 | if($this->eap == EAP::$TLS) |
| 115 | - $out .= _("In order to connect to the network you will need an a personal certificate in the form of a p12 file. You should obtain this certificate from your home institution. Consult the support page to find out how this certificate can be obtained. Such certificate files are password protected. You should have both the file and the password available during the installation process."); |
|
| 115 | + $out .= _("In order to connect to the network you will need an a personal certificate in the form of a p12 file. You should obtain this certificate from your home institution. Consult the support page to find out how this certificate can be obtained. Such certificate files are password protected. You should have both the file and the password available during the installation process."); |
|
| 116 | 116 | else { |
| 117 | - $out .= _("In order to connect to the network you will need an account from your home institution. You should consult the support page to find out how this account can be obtained. It is very likely that your account is already activated."); |
|
| 118 | - $out .= "<p>"; |
|
| 119 | - $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 | + $out .= _("In order to connect to the network you will need an account from your home institution. You should consult the support page to find out how this account can be obtained. It is very likely that your account is already activated."); |
|
| 118 | + $out .= "<p>"; |
|
| 119 | + $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."); |
|
| 120 | 120 | if($ssid_ct > 1) { |
| 121 | - $out .= "<p>"; |
|
| 122 | - $out .= _("You will be required to enter the same credentials for each of the configured notworks:")." "; |
|
| 123 | - $i = 0; |
|
| 121 | + $out .= "<p>"; |
|
| 122 | + $out .= _("You will be required to enter the same credentials for each of the configured notworks:")." "; |
|
| 123 | + $i = 0; |
|
| 124 | 124 | foreach ($this->attributes['internal:SSID'] as $ssid=>$v) { |
| 125 | - if($i > 0) |
|
| 126 | - $out .= ", "; |
|
| 127 | - $i++; |
|
| 128 | - $out .= "<strong>$ssid</strong>"; |
|
| 125 | + if($i > 0) |
|
| 126 | + $out .= ", "; |
|
| 127 | + $i++; |
|
| 128 | + $out .= "<strong>$ssid</strong>"; |
|
| 129 | 129 | } |
| 130 | 130 | } |
| 131 | 131 | |
| 132 | 132 | |
| 133 | 133 | } |
| 134 | 134 | return $out; |
| 135 | - } |
|
| 135 | + } |
|
| 136 | 136 | |
| 137 | 137 | |
| 138 | 138 | private function prepareEapConfig($attr) { |
| 139 | - $eap = $this->selected_eap; |
|
| 140 | - $w8_ext = ''; |
|
| 141 | - $use_anon = $attr['internal:use_anon_outer'] [0]; |
|
| 142 | - if ($use_anon) { |
|
| 143 | - $outer_user = $attr['internal:anon_local_value'][0]; |
|
| 144 | - $outer_id = $outer_user.'@'.$attr['internal:realm'][0]; |
|
| 145 | - } |
|
| 139 | + $eap = $this->selected_eap; |
|
| 140 | + $w8_ext = ''; |
|
| 141 | + $use_anon = $attr['internal:use_anon_outer'] [0]; |
|
| 142 | + if ($use_anon) { |
|
| 143 | + $outer_user = $attr['internal:anon_local_value'][0]; |
|
| 144 | + $outer_id = $outer_user.'@'.$attr['internal:realm'][0]; |
|
| 145 | + } |
|
| 146 | 146 | // $servers = preg_quote(implode(';',$attr['eap:server_name'])); |
| 147 | - $servers = implode(';',$attr['eap:server_name']); |
|
| 147 | + $servers = implode(';',$attr['eap:server_name']); |
|
| 148 | 148 | |
| 149 | - $ca_array = $attr['internal:CAs'][0]; |
|
| 149 | + $ca_array = $attr['internal:CAs'][0]; |
|
| 150 | 150 | |
| 151 | 151 | |
| 152 | 152 | $profile_file_contents = '<EAPConfig><EapHostConfig xmlns="http://www.microsoft.com/provisioning/EapHostConfig"> |
@@ -162,7 +162,7 @@ discard block |
||
| 162 | 162 | $profile_file_contents .= '<AuthorId xmlns="http://www.microsoft.com/provisioning/EapCommon">0</AuthorId> |
| 163 | 163 | </EapMethod> |
| 164 | 164 | '; |
| 165 | - $profile_file_contents .= ' |
|
| 165 | + $profile_file_contents .= ' |
|
| 166 | 166 | |
| 167 | 167 | <Config xmlns:baseEap="http://www.microsoft.com/provisioning/BaseEapConnectionPropertiesV1" |
| 168 | 168 | xmlns:eapTls="http://www.microsoft.com/provisioning/EapTlsConnectionPropertiesV1"> |
@@ -178,14 +178,14 @@ discard block |
||
| 178 | 178 | if($ca_array) { |
| 179 | 179 | foreach ($ca_array as $CA) |
| 180 | 180 | if($CA['root']) |
| 181 | - $profile_file_contents .= "<eapTls:TrustedRootCA>".$CA['sha1']."</eapTls:TrustedRootCA>\n"; |
|
| 181 | + $profile_file_contents .= "<eapTls:TrustedRootCA>".$CA['sha1']."</eapTls:TrustedRootCA>\n"; |
|
| 182 | 182 | } |
| 183 | 183 | $profile_file_contents .= '</eapTls:ServerValidation> |
| 184 | 184 | '; |
| 185 | 185 | if(isset($attr['eap-specific:tls_use_other_id']) && $attr['eap-specific:tls_use_other_id'][0] == 'on') |
| 186 | - $profile_file_contents .= '<eapTls:DifferentUsername>true</eapTls:DifferentUsername>'; |
|
| 186 | + $profile_file_contents .= '<eapTls:DifferentUsername>true</eapTls:DifferentUsername>'; |
|
| 187 | 187 | else |
| 188 | - $profile_file_contents .= '<eapTls:DifferentUsername>false</eapTls:DifferentUsername>'; |
|
| 188 | + $profile_file_contents .= '<eapTls:DifferentUsername>false</eapTls:DifferentUsername>'; |
|
| 189 | 189 | $profile_file_contents .= ' |
| 190 | 190 | </eapTls:EapType> |
| 191 | 191 | </baseEap:Eap> |
@@ -193,9 +193,9 @@ discard block |
||
| 193 | 193 | '; |
| 194 | 194 | } elseif ( $eap == EAP::$PEAP_MSCHAP2) { |
| 195 | 195 | if(isset($attr['eap:enable_nea']) && $attr['eap:enable_nea'][0] == 'on') |
| 196 | - $nea = 'true'; |
|
| 196 | + $nea = 'true'; |
|
| 197 | 197 | else |
| 198 | - $nea = 'false'; |
|
| 198 | + $nea = 'false'; |
|
| 199 | 199 | $profile_file_contents .= '<AuthorId xmlns="http://www.microsoft.com/provisioning/EapCommon">0</AuthorId> |
| 200 | 200 | </EapMethod> |
| 201 | 201 | '; |
@@ -260,10 +260,10 @@ discard block |
||
| 260 | 260 | <Phase2Authentication> |
| 261 | 261 | '; |
| 262 | 262 | if ( $eap == EAP::$TTLS_PAP) { |
| 263 | - $w8_ext .='<PAPAuthentication /> '; |
|
| 263 | + $w8_ext .='<PAPAuthentication /> '; |
|
| 264 | 264 | } |
| 265 | 265 | if ( $eap == EAP::$TTLS_MSCHAP2) { |
| 266 | - $w8_ext .='<MSCHAPv2Authentication> |
|
| 266 | + $w8_ext .='<MSCHAPv2Authentication> |
|
| 267 | 267 | <UseWinlogonCredentials>false</UseWinlogonCredentials> |
| 268 | 268 | </MSCHAPv2Authentication> |
| 269 | 269 | '; |
@@ -272,16 +272,16 @@ discard block |
||
| 272 | 272 | <Phase1Identity> |
| 273 | 273 | '; |
| 274 | 274 | if($use_anon == 1) { |
| 275 | - $w8_ext .= '<IdentityPrivacy>true</IdentityPrivacy> |
|
| 275 | + $w8_ext .= '<IdentityPrivacy>true</IdentityPrivacy> |
|
| 276 | 276 | '; |
| 277 | - if(isset($outer_id) && $outer_id) |
|
| 277 | + if(isset($outer_id) && $outer_id) |
|
| 278 | 278 | $w8_ext .='<AnonymousIdentity>'.$outer_id.'</AnonymousIdentity> |
| 279 | 279 | '; |
| 280 | - else |
|
| 280 | + else |
|
| 281 | 281 | $w8_ext .='<AnonymousIdentity/> |
| 282 | 282 | '; |
| 283 | 283 | } else { |
| 284 | - $w8_ext .= '<IdentityPrivacy>false</IdentityPrivacy> |
|
| 284 | + $w8_ext .= '<IdentityPrivacy>false</IdentityPrivacy> |
|
| 285 | 285 | '; |
| 286 | 286 | } |
| 287 | 287 | $w8_ext .='</Phase1Identity> |
@@ -292,7 +292,7 @@ discard block |
||
| 292 | 292 | $profile_file_contents .= '<AuthorId xmlns="http://www.microsoft.com/provisioning/EapCommon">0</AuthorId> |
| 293 | 293 | </EapMethod> |
| 294 | 294 | '; |
| 295 | - $profile_file_contents .= '<ConfigBlob></ConfigBlob>'; |
|
| 295 | + $profile_file_contents .= '<ConfigBlob></ConfigBlob>'; |
|
| 296 | 296 | } |
| 297 | 297 | |
| 298 | 298 | $profile_file_contents_end = '</EapHostConfig></EAPConfig>'; |
@@ -309,7 +309,7 @@ discard block |
||
| 309 | 309 | /** |
| 310 | 310 | * produce PEAP, TLS and TTLS configuration files for Windows 8 |
| 311 | 311 | */ |
| 312 | - private function writeWLANprofile($wlan_profile_name,$ssid,$auth,$encryption,$eap_config,$i) { |
|
| 312 | + private function writeWLANprofile($wlan_profile_name,$ssid,$auth,$encryption,$eap_config,$i) { |
|
| 313 | 313 | $profile_file_contents = '<?xml version="1.0"?> |
| 314 | 314 | <WLANProfile xmlns="http://www.microsoft.com/networking/WLAN/profile/v1"> |
| 315 | 315 | <name>'.$wlan_profile_name.'</name> |
@@ -349,7 +349,7 @@ discard block |
||
| 349 | 349 | '; |
| 350 | 350 | |
| 351 | 351 | if(! is_dir('w8')) |
| 352 | - mkdir('w8'); |
|
| 352 | + mkdir('w8'); |
|
| 353 | 353 | $xml_f_name = "w8/wlan_prof-$i.xml"; |
| 354 | 354 | $xml_f = fopen($xml_f_name,'w'); |
| 355 | 355 | fwrite($xml_f,$profile_file_contents. $eap_config['w8']. $closing) ; |
@@ -376,7 +376,7 @@ discard block |
||
| 376 | 376 | '; |
| 377 | 377 | |
| 378 | 378 | if(! is_dir('w8')) |
| 379 | - mkdir('w8'); |
|
| 379 | + mkdir('w8'); |
|
| 380 | 380 | $xml_f_name = "w8/lan_prof.xml"; |
| 381 | 381 | $xml_f = fopen($xml_f_name,'w'); |
| 382 | 382 | fwrite($xml_f,$profile_file_contents. $eap_config['w8']. $closing) ; |
@@ -435,7 +435,7 @@ discard block |
||
| 435 | 435 | '; |
| 436 | 436 | |
| 437 | 437 | if(isset($this->attributes['media:wired'][0]) && $attr['media:wired'][0] == 'on') |
| 438 | - $fcontents .= '!define WIRED |
|
| 438 | + $fcontents .= '!define WIRED |
|
| 439 | 439 | '; |
| 440 | 440 | |
| 441 | 441 | $f = fopen('main.nsh','w'); |
@@ -448,7 +448,7 @@ discard block |
||
| 448 | 448 | debug(4,"writeProfilesNSH"); |
| 449 | 449 | debug(4,$P); |
| 450 | 450 | $fcontents = ''; |
| 451 | - foreach($P as $p) |
|
| 451 | + foreach($P as $p) |
|
| 452 | 452 | $fcontents .= "!insertmacro define_wlan_profile $p\n"; |
| 453 | 453 | |
| 454 | 454 | $f = fopen('profiles.nsh','w'); |
@@ -459,8 +459,8 @@ discard block |
||
| 459 | 459 | $f = fopen('certs.nsh','w'); |
| 460 | 460 | if($ca_array) { |
| 461 | 461 | foreach ($ca_array as $CA) { |
| 462 | - $store = $CA['root'] ? "root" : "ca"; |
|
| 463 | - $fcontents .= '!insertmacro install_ca_cert "'.$CA['file'].'" "'.$CA['sha1'].'" "'.$store."\"\n"; |
|
| 462 | + $store = $CA['root'] ? "root" : "ca"; |
|
| 463 | + $fcontents .= '!insertmacro install_ca_cert "'.$CA['file'].'" "'.$CA['sha1'].'" "'.$store."\"\n"; |
|
| 464 | 464 | } |
| 465 | 465 | fwrite($f, $fcontents); |
| 466 | 466 | } |
@@ -471,26 +471,26 @@ discard block |
||
| 471 | 471 | |
| 472 | 472 | private function copyFiles ($eap) { |
| 473 | 473 | debug(4,"copyFiles start\n"); |
| 474 | - $result; |
|
| 475 | - $result = $this->copyFile('wlan_test.exe'); |
|
| 476 | - $result = $this->copyFile('check_wired.cmd'); |
|
| 477 | - $result = $this->copyFile('install_wired.cmd'); |
|
| 478 | - $result = $this->copyFile('setEAPCred.exe'); |
|
| 479 | - $result = $this->copyFile('cat_bg.bmp'); |
|
| 480 | - $result = $this->copyFile('base64.nsh'); |
|
| 481 | - $result = $result && $this->copyFile('cat32.ico'); |
|
| 482 | - $result = $result && $this->copyFile('cat_150.bmp'); |
|
| 483 | - $this->translateFile('common.inc','common.nsh',$this->code_page); |
|
| 484 | - if($eap["OUTER"] == PWD) { |
|
| 485 | - $this->translateFile('pwd.inc','cat.NSI',$this->code_page); |
|
| 486 | - $result = $result && $this->copyFile('Aruba_Networks_EAP-pwd_x32.msi'); |
|
| 487 | - $result = $result && $this->copyFile('Aruba_Networks_EAP-pwd_x64.msi'); |
|
| 488 | - } else { |
|
| 489 | - $this->translateFile('eap_w8.inc','cat.NSI',$this->code_page); |
|
| 490 | - $result = 1; |
|
| 491 | - } |
|
| 474 | + $result; |
|
| 475 | + $result = $this->copyFile('wlan_test.exe'); |
|
| 476 | + $result = $this->copyFile('check_wired.cmd'); |
|
| 477 | + $result = $this->copyFile('install_wired.cmd'); |
|
| 478 | + $result = $this->copyFile('setEAPCred.exe'); |
|
| 479 | + $result = $this->copyFile('cat_bg.bmp'); |
|
| 480 | + $result = $this->copyFile('base64.nsh'); |
|
| 481 | + $result = $result && $this->copyFile('cat32.ico'); |
|
| 482 | + $result = $result && $this->copyFile('cat_150.bmp'); |
|
| 483 | + $this->translateFile('common.inc','common.nsh',$this->code_page); |
|
| 484 | + if($eap["OUTER"] == PWD) { |
|
| 485 | + $this->translateFile('pwd.inc','cat.NSI',$this->code_page); |
|
| 486 | + $result = $result && $this->copyFile('Aruba_Networks_EAP-pwd_x32.msi'); |
|
| 487 | + $result = $result && $this->copyFile('Aruba_Networks_EAP-pwd_x64.msi'); |
|
| 488 | + } else { |
|
| 489 | + $this->translateFile('eap_w8.inc','cat.NSI',$this->code_page); |
|
| 490 | + $result = 1; |
|
| 491 | + } |
|
| 492 | 492 | debug(4,"copyFiles end\n"); |
| 493 | - return($result); |
|
| 493 | + return($result); |
|
| 494 | 494 | } |
| 495 | 495 | |
| 496 | 496 | } |
| 497 | 497 | \ No newline at end of file |