@@ -37,10 +37,11 @@ discard block |
||
| 37 | 37 | require_once('lib/vCard-parser/vCard.php'); |
| 38 | 38 | require_once('lib/fritzbox_api_php/fritzbox_api.class.php'); |
| 39 | 39 | |
| 40 | -if($argc == 2) |
|
| 40 | +if($argc == 2) { |
|
| 41 | 41 | $config_file_name = $argv[1]; |
| 42 | -else |
|
| 42 | +} else { |
|
| 43 | 43 | $config_file_name = __DIR__ . '/config.php'; |
| 44 | +} |
|
| 44 | 45 | |
| 45 | 46 | // default/fallback config options |
| 46 | 47 | $config['tmp_dir'] = sys_get_temp_dir(); |
@@ -59,9 +60,9 @@ discard block |
||
| 59 | 60 | $config['build_photos'] = true; |
| 60 | 61 | $config['quickdial_keyword'] = 'Quickdial:'; |
| 61 | 62 | |
| 62 | -if(is_file($config_file_name)) |
|
| 63 | +if(is_file($config_file_name)) { |
|
| 63 | 64 | require($config_file_name); |
| 64 | -else |
|
| 65 | +} else |
|
| 65 | 66 | { |
| 66 | 67 | print 'ERROR: No '.$config_file_name.' found, please take a look at config.example.php and create a '.$config_file_name.' file!'.PHP_EOL; |
| 67 | 68 | exit(1); |
@@ -121,8 +122,9 @@ discard block |
||
| 121 | 122 | // Source: https://php.net/manual/de/function.tempnam.php#61436 |
| 122 | 123 | public function mktemp($dir, $prefix='', $mode=0700) |
| 123 | 124 | { |
| 124 | - if(substr($dir, -1) != '/') |
|
| 125 | - $dir .= '/'; |
|
| 125 | + if(substr($dir, -1) != '/') { |
|
| 126 | + $dir .= '/'; |
|
| 127 | + } |
|
| 126 | 128 | |
| 127 | 129 | do |
| 128 | 130 | { |
@@ -142,8 +144,11 @@ discard block |
||
| 142 | 144 | { |
| 143 | 145 | if($object != "." && $object != "..") |
| 144 | 146 | { |
| 145 | - if(filetype($dir."/".$object) == "dir") |
|
| 146 | - rrmdir($dir."/".$object); else unlink($dir."/".$object); |
|
| 147 | + if(filetype($dir."/".$object) == "dir") { |
|
| 148 | + rrmdir($dir."/".$object); |
|
| 149 | + } else { |
|
| 150 | + unlink($dir."/".$object); |
|
| 151 | + } |
|
| 147 | 152 | } |
| 148 | 153 | } |
| 149 | 154 | reset($objects); |
@@ -156,21 +161,23 @@ discard block |
||
| 156 | 161 | try |
| 157 | 162 | { |
| 158 | 163 | // Check if there are valid base64 characters |
| 159 | - if(!preg_match('/^[a-zA-Z0-9\/\r\n+]*={0,2}$/', $str)) |
|
| 160 | - return false; |
|
| 164 | + if(!preg_match('/^[a-zA-Z0-9\/\r\n+]*={0,2}$/', $str)) { |
|
| 165 | + return false; |
|
| 166 | + } |
|
| 161 | 167 | |
| 162 | 168 | // Decode the string in strict mode and check the results |
| 163 | 169 | $decoded = base64_decode($str, true); |
| 164 | - if($decoded === false) |
|
| 165 | - return false; |
|
| 170 | + if($decoded === false) { |
|
| 171 | + return false; |
|
| 172 | + } |
|
| 166 | 173 | |
| 167 | 174 | // Encode the string again |
| 168 | - if(base64_encode($decoded) === $str) |
|
| 169 | - return true; |
|
| 170 | - else |
|
| 171 | - return false; |
|
| 172 | - } |
|
| 173 | - catch(Exception $e) |
|
| 175 | + if(base64_encode($decoded) === $str) { |
|
| 176 | + return true; |
|
| 177 | + } else { |
|
| 178 | + return false; |
|
| 179 | + } |
|
| 180 | + } catch(Exception $e) |
|
| 174 | 181 | { |
| 175 | 182 | // If exception is caught, then it is not a base64 encoded string |
| 176 | 183 | return false; |
@@ -207,8 +214,9 @@ discard block |
||
| 207 | 214 | |
| 208 | 215 | // set the vcard extension in case the user |
| 209 | 216 | // defined it in the config |
| 210 | - if(isset($conf['extension'])) |
|
| 211 | - $carddav->setVcardExtension($conf['extension']); |
|
| 217 | + if(isset($conf['extension'])) { |
|
| 218 | + $carddav->setVcardExtension($conf['extension']); |
|
| 219 | + } |
|
| 212 | 220 | |
| 213 | 221 | // retrieve data from the CardDAV server now |
| 214 | 222 | $xmldata = $carddav->get(); |
@@ -216,8 +224,9 @@ discard block |
||
| 216 | 224 | // identify if we received UTF-8 encoded data from the |
| 217 | 225 | // CardDAV server and if not reencode it since the FRITZ!Box |
| 218 | 226 | // requires UTF-8 encoded data |
| 219 | - if(iconv('utf-8', 'utf-8//IGNORE', $xmldata) != $xmldata) |
|
| 220 | - $xmldata = utf8_encode($xmldata); |
|
| 227 | + if(iconv('utf-8', 'utf-8//IGNORE', $xmldata) != $xmldata) { |
|
| 228 | + $xmldata = utf8_encode($xmldata); |
|
| 229 | + } |
|
| 221 | 230 | |
| 222 | 231 | // read raw_vcard data from xml response |
| 223 | 232 | $raw_vcards = array(); |
@@ -239,11 +248,13 @@ discard block |
||
| 239 | 248 | { |
| 240 | 249 | $vcard_obj = new vCard(false, $v); |
| 241 | 250 | $name_arr = null; |
| 242 | - if(isset($vcard_obj->n[0])) |
|
| 243 | - $name_arr = $vcard_obj->n[0]; |
|
| 251 | + if(isset($vcard_obj->n[0])) { |
|
| 252 | + $name_arr = $vcard_obj->n[0]; |
|
| 253 | + } |
|
| 244 | 254 | $org_arr = null; |
| 245 | - if(isset($vcard_obj->org[0])) |
|
| 246 | - $org_arr = $vcard_obj->org[0]; |
|
| 255 | + if(isset($vcard_obj->org[0])) { |
|
| 256 | + $org_arr = $vcard_obj->org[0]; |
|
| 257 | + } |
|
| 247 | 258 | $addnames = ''; |
| 248 | 259 | $prefix = ''; |
| 249 | 260 | $suffix = ''; |
@@ -252,17 +263,21 @@ discard block |
||
| 252 | 263 | $lastname = ''; |
| 253 | 264 | |
| 254 | 265 | // Build name Parts if existing ans switch to true in config |
| 255 | - if(isset($name_arr['prefixes']) AND $this->config['prefix']) |
|
| 256 | - $prefix = trim($name_arr['prefixes']); |
|
| 266 | + if(isset($name_arr['prefixes']) AND $this->config['prefix']) { |
|
| 267 | + $prefix = trim($name_arr['prefixes']); |
|
| 268 | + } |
|
| 257 | 269 | |
| 258 | - if(isset($name_arr['suffixes']) AND $this->config['suffix']) |
|
| 259 | - $suffix = trim($name_arr['suffixes']); |
|
| 270 | + if(isset($name_arr['suffixes']) AND $this->config['suffix']) { |
|
| 271 | + $suffix = trim($name_arr['suffixes']); |
|
| 272 | + } |
|
| 260 | 273 | |
| 261 | - if(isset($name_arr['additionalnames']) AND $this->config['addnames']) |
|
| 262 | - $addnames = trim($name_arr['additionalnames']); |
|
| 274 | + if(isset($name_arr['additionalnames']) AND $this->config['addnames']) { |
|
| 275 | + $addnames = trim($name_arr['additionalnames']); |
|
| 276 | + } |
|
| 263 | 277 | |
| 264 | - if(isset($org_arr['name']) AND $this->config['orgname']) |
|
| 265 | - $orgname = trim($org_arr['name']); |
|
| 278 | + if(isset($org_arr['name']) AND $this->config['orgname']) { |
|
| 279 | + $orgname = trim($org_arr['name']); |
|
| 280 | + } |
|
| 266 | 281 | |
| 267 | 282 | $firstname = trim($name_arr['firstname']); |
| 268 | 283 | $lastname = trim($name_arr['lastname']); |
@@ -281,72 +296,79 @@ discard block |
||
| 281 | 296 | $format = $this->config['fullname_format']; |
| 282 | 297 | |
| 283 | 298 | // Prefix |
| 284 | - if(!empty($prefix)) |
|
| 285 | - $name .= $prefix; |
|
| 299 | + if(!empty($prefix)) { |
|
| 300 | + $name .= $prefix; |
|
| 301 | + } |
|
| 286 | 302 | |
| 287 | 303 | if($format == 0) |
| 288 | 304 | { |
| 289 | 305 | // Lastname |
| 290 | - if(!empty($name) AND !empty($lastname)) |
|
| 291 | - $name .= ' ' . $lastname; |
|
| 292 | - else |
|
| 293 | - $name .= $lastname; |
|
| 294 | - } |
|
| 295 | - else |
|
| 306 | + if(!empty($name) AND !empty($lastname)) { |
|
| 307 | + $name .= ' ' . $lastname; |
|
| 308 | + } else { |
|
| 309 | + $name .= $lastname; |
|
| 310 | + } |
|
| 311 | + } else |
|
| 296 | 312 | { |
| 297 | 313 | // Firstname |
| 298 | - if(!empty($name) AND !empty($firstname)) |
|
| 299 | - $name .= ' ' . $firstname; |
|
| 300 | - else |
|
| 301 | - $name .= $firstname; |
|
| 314 | + if(!empty($name) AND !empty($firstname)) { |
|
| 315 | + $name .= ' ' . $firstname; |
|
| 316 | + } else { |
|
| 317 | + $name .= $firstname; |
|
| 318 | + } |
|
| 302 | 319 | } |
| 303 | 320 | |
| 304 | 321 | if($format == 2) |
| 305 | 322 | { |
| 306 | 323 | // AdditionalNames |
| 307 | - if(!empty($name) AND !empty($addnames)) |
|
| 308 | - $name .= ' ' . $addnames; |
|
| 309 | - else |
|
| 310 | - $name .= $addnames; |
|
| 324 | + if(!empty($name) AND !empty($addnames)) { |
|
| 325 | + $name .= ' ' . $addnames; |
|
| 326 | + } else { |
|
| 327 | + $name .= $addnames; |
|
| 328 | + } |
|
| 311 | 329 | } |
| 312 | 330 | |
| 313 | 331 | if($format == 0) |
| 314 | 332 | { |
| 315 | 333 | // Firstname |
| 316 | - if(!empty($name) AND !empty($firstname)) |
|
| 317 | - $name .= ', ' . $firstname; |
|
| 318 | - else |
|
| 319 | - $name .= $firstname; |
|
| 320 | - } |
|
| 321 | - else |
|
| 334 | + if(!empty($name) AND !empty($firstname)) { |
|
| 335 | + $name .= ', ' . $firstname; |
|
| 336 | + } else { |
|
| 337 | + $name .= $firstname; |
|
| 338 | + } |
|
| 339 | + } else |
|
| 322 | 340 | { |
| 323 | 341 | // Lastname |
| 324 | - if(!empty($name) AND !empty($lastname)) |
|
| 325 | - $name .= ' ' . $lastname; |
|
| 326 | - else |
|
| 327 | - $name .= $lastname; |
|
| 342 | + if(!empty($name) AND !empty($lastname)) { |
|
| 343 | + $name .= ' ' . $lastname; |
|
| 344 | + } else { |
|
| 345 | + $name .= $lastname; |
|
| 346 | + } |
|
| 328 | 347 | } |
| 329 | 348 | |
| 330 | 349 | if($format != 2) |
| 331 | 350 | { |
| 332 | 351 | // AdditionalNames |
| 333 | - if(!empty($name) AND !empty($addnames)) |
|
| 334 | - $name .= ' ' . $addnames; |
|
| 335 | - else |
|
| 336 | - $name .= $addnames; |
|
| 352 | + if(!empty($name) AND !empty($addnames)) { |
|
| 353 | + $name .= ' ' . $addnames; |
|
| 354 | + } else { |
|
| 355 | + $name .= $addnames; |
|
| 356 | + } |
|
| 337 | 357 | } |
| 338 | 358 | |
| 339 | 359 | // Suffix |
| 340 | - if(!empty($name) AND !empty($suffix)) |
|
| 341 | - $name .= ' ' . $suffix; |
|
| 342 | - else |
|
| 343 | - $name .= $suffix; |
|
| 360 | + if(!empty($name) AND !empty($suffix)) { |
|
| 361 | + $name .= ' ' . $suffix; |
|
| 362 | + } else { |
|
| 363 | + $name .= $suffix; |
|
| 364 | + } |
|
| 344 | 365 | |
| 345 | 366 | // OrgName |
| 346 | - if(!empty($name) AND !empty($orgname)) |
|
| 347 | - $name .= ' (' . $orgname . ')'; |
|
| 348 | - else |
|
| 349 | - $name .= $orgname; |
|
| 367 | + if(!empty($name) AND !empty($orgname)) { |
|
| 368 | + $name .= ' (' . $orgname . ')'; |
|
| 369 | + } else { |
|
| 370 | + $name .= $orgname; |
|
| 371 | + } |
|
| 350 | 372 | |
| 351 | 373 | // make sure to trim whitespaces and double spaces |
| 352 | 374 | $name = trim(str_replace(' ', ' ', $name)); |
@@ -364,22 +386,22 @@ discard block |
||
| 364 | 386 | { |
| 365 | 387 | $photo = $imgseqfname; |
| 366 | 388 | $imgseqfname++; |
| 367 | - } |
|
| 368 | - else |
|
| 389 | + } else |
|
| 369 | 390 | { |
| 370 | 391 | $photo = str_replace(array(',','&',' ','/','ä','ö','ü','Ä','Ö','Ü','ß','á','à','ó','ò','ú','ù','í','ø'), |
| 371 | 392 | array('','_','_','_','ae','oe','ue','Ae','Oe','Ue','ss','a','a','o','o','u','u','i','oe'),$name); |
| 372 | 393 | } |
| 394 | + } else { |
|
| 395 | + $photo = ''; |
|
| 373 | 396 | } |
| 374 | - else |
|
| 375 | - $photo = ''; |
|
| 376 | 397 | |
| 377 | 398 | // phone |
| 378 | 399 | $phone_no = array(); |
| 379 | - if($vcard_obj->categories) |
|
| 380 | - $categories = $vcard_obj->categories[0]; |
|
| 381 | - else |
|
| 382 | - $categories = array(); |
|
| 400 | + if($vcard_obj->categories) { |
|
| 401 | + $categories = $vcard_obj->categories[0]; |
|
| 402 | + } else { |
|
| 403 | + $categories = array(); |
|
| 404 | + } |
|
| 383 | 405 | |
| 384 | 406 | $quick_dial_for_nr = null; |
| 385 | 407 | $quick_dial_nr = null; |
@@ -417,9 +439,9 @@ discard block |
||
| 417 | 439 | break; |
| 418 | 440 | } |
| 419 | 441 | } |
| 420 | - } |
|
| 421 | - else |
|
| 422 | - $add_entry = 1; |
|
| 442 | + } else { |
|
| 443 | + $add_entry = 1; |
|
| 444 | + } |
|
| 423 | 445 | |
| 424 | 446 | if($add_entry == 1) |
| 425 | 447 | { |
@@ -432,8 +454,7 @@ discard block |
||
| 432 | 454 | { |
| 433 | 455 | $type = "mobile"; |
| 434 | 456 | $phone_number = $t; |
| 435 | - } |
|
| 436 | - else |
|
| 457 | + } else |
|
| 437 | 458 | { |
| 438 | 459 | $phone_number = $t['value']; |
| 439 | 460 | |
@@ -443,10 +464,11 @@ discard block |
||
| 443 | 464 | if($qd_phone_nr == $phone_number_clean) |
| 444 | 465 | { |
| 445 | 466 | //Set quickdial |
| 446 | - if($value == 1) |
|
| 447 | - print "\nWARNING: Quickdial value 1 (**701) is not possible but used! \n"; |
|
| 448 | - elseif($value >= 100) |
|
| 449 | - print "\nWARNING: Quickdial value bigger than 99 (**799) is not possible but used! \n"; |
|
| 467 | + if($value == 1) { |
|
| 468 | + print "\nWARNING: Quickdial value 1 (**701) is not possible but used! \n"; |
|
| 469 | + } elseif($value >= 100) { |
|
| 470 | + print "\nWARNING: Quickdial value bigger than 99 (**799) is not possible but used! \n"; |
|
| 471 | + } |
|
| 450 | 472 | |
| 451 | 473 | $quickdial = $value; |
| 452 | 474 | } |
@@ -455,24 +477,26 @@ discard block |
||
| 455 | 477 | $typearr_lower = unserialize(strtolower(serialize($t['type']))); |
| 456 | 478 | |
| 457 | 479 | // find out priority |
| 458 | - if(in_array("pref", $typearr_lower)) |
|
| 459 | - $prio = 1; |
|
| 480 | + if(in_array("pref", $typearr_lower)) { |
|
| 481 | + $prio = 1; |
|
| 482 | + } |
|
| 460 | 483 | |
| 461 | 484 | // set the proper type |
| 462 | - if(in_array("cell", $typearr_lower)) |
|
| 463 | - $type = "mobile"; |
|
| 464 | - elseif(in_array("home", $typearr_lower)) |
|
| 465 | - $type = "home"; |
|
| 466 | - elseif(in_array("fax", $typearr_lower)) |
|
| 467 | - $type = "fax_work"; |
|
| 468 | - elseif(in_array("work", $typearr_lower)) |
|
| 469 | - $type = "work"; |
|
| 470 | - elseif(in_array("other", $typearr_lower)) |
|
| 471 | - $type = "other"; |
|
| 472 | - elseif(in_array("dom", $typearr_lower)) |
|
| 473 | - $type = "other"; |
|
| 474 | - else |
|
| 475 | - continue; |
|
| 485 | + if(in_array("cell", $typearr_lower)) { |
|
| 486 | + $type = "mobile"; |
|
| 487 | + } elseif(in_array("home", $typearr_lower)) { |
|
| 488 | + $type = "home"; |
|
| 489 | + } elseif(in_array("fax", $typearr_lower)) { |
|
| 490 | + $type = "fax_work"; |
|
| 491 | + } elseif(in_array("work", $typearr_lower)) { |
|
| 492 | + $type = "work"; |
|
| 493 | + } elseif(in_array("other", $typearr_lower)) { |
|
| 494 | + $type = "other"; |
|
| 495 | + } elseif(in_array("dom", $typearr_lower)) { |
|
| 496 | + $type = "other"; |
|
| 497 | + } else { |
|
| 498 | + continue; |
|
| 499 | + } |
|
| 476 | 500 | } |
| 477 | 501 | $phone_no[] = array("type"=>$type, "prio"=>$prio, "quickdial"=>$quickdial, "value" => $this->_clear_phone_number($phone_number)); |
| 478 | 502 | } |
@@ -486,19 +510,19 @@ discard block |
||
| 486 | 510 | { |
| 487 | 511 | $type_email = "work"; |
| 488 | 512 | $email = $e; |
| 489 | - } |
|
| 490 | - else |
|
| 513 | + } else |
|
| 491 | 514 | { |
| 492 | 515 | $email = $e['value']; |
| 493 | 516 | $typearr_lower = unserialize(strtolower(serialize($e['type']))); |
| 494 | - if(in_array("work", $typearr_lower)) |
|
| 495 | - $type_email = "work"; |
|
| 496 | - elseif(in_array("home", $typearr_lower)) |
|
| 497 | - $type_email = "home"; |
|
| 498 | - elseif(in_array("other", $typearr_lower)) |
|
| 499 | - $type_email = "other"; |
|
| 500 | - else |
|
| 501 | - continue; |
|
| 517 | + if(in_array("work", $typearr_lower)) { |
|
| 518 | + $type_email = "work"; |
|
| 519 | + } elseif(in_array("home", $typearr_lower)) { |
|
| 520 | + $type_email = "home"; |
|
| 521 | + } elseif(in_array("other", $typearr_lower)) { |
|
| 522 | + $type_email = "other"; |
|
| 523 | + } else { |
|
| 524 | + continue; |
|
| 525 | + } |
|
| 502 | 526 | } |
| 503 | 527 | |
| 504 | 528 | // DEBUG: print out the email address on the console |
@@ -524,8 +548,9 @@ discard block |
||
| 524 | 548 | |
| 525 | 549 | public function build_fb_xml() |
| 526 | 550 | { |
| 527 | - if(empty($this->entries)) |
|
| 528 | - throw new Exception('No entries available! Call get_carddav_entries or set $this->entries manually!'); |
|
| 551 | + if(empty($this->entries)) { |
|
| 552 | + throw new Exception('No entries available! Call get_carddav_entries or set $this->entries manually!'); |
|
| 553 | + } |
|
| 529 | 554 | |
| 530 | 555 | // create FB XML in utf-8 format |
| 531 | 556 | $root = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?><phonebooks><phonebook></phonebook></phonebooks>'); |
@@ -563,8 +588,9 @@ discard block |
||
| 563 | 588 | } |
| 564 | 589 | |
| 565 | 590 | // output a warning if no telephone number was found |
| 566 | - if($id == 0) |
|
| 567 | - print " WARNING: no phone entry found. VCard will be ignored." . PHP_EOL; |
|
| 591 | + if($id == 0) { |
|
| 592 | + print " WARNING: no phone entry found. VCard will be ignored." . PHP_EOL; |
|
| 593 | + } |
|
| 568 | 594 | |
| 569 | 595 | // email: put the email addresses into the fritzbox xml file |
| 570 | 596 | $email = $contact->addChild("services"); |
@@ -602,8 +628,7 @@ discard block |
||
| 602 | 628 | file_put_contents($photo_file . ".b64", $photo_data); |
| 603 | 629 | $this->base64_to_jpeg($photo_file . ".b64", $photo_file); |
| 604 | 630 | unlink($photo_file . ".b64"); |
| 605 | - } |
|
| 606 | - else |
|
| 631 | + } else |
|
| 607 | 632 | { |
| 608 | 633 | print " WARNING: non-base64 encoded photo data found and used." . PHP_EOL; |
| 609 | 634 | file_put_contents($photo_file, $photo_data); |
@@ -613,19 +638,18 @@ discard block |
||
| 613 | 638 | $person->addChild("imageURL", $this->config['fritzbox_path'].$this->config['usb_disk']."FRITZ/fonpix/".basename($photo_file)); |
| 614 | 639 | |
| 615 | 640 | print " Added photo: " . basename($photo_file) . PHP_EOL; |
| 641 | + } else { |
|
| 642 | + print " WARNING: Only jpg contact photos are currently supported." . PHP_EOL; |
|
| 616 | 643 | } |
| 617 | - else |
|
| 618 | - print " WARNING: Only jpg contact photos are currently supported." . PHP_EOL; |
|
| 619 | - } |
|
| 620 | - elseif(substr($entry['photo_data'][0], 0, 4) == 'http') |
|
| 644 | + } elseif(substr($entry['photo_data'][0], 0, 4) == 'http') |
|
| 621 | 645 | { |
| 622 | 646 | // add contact photo to xml |
| 623 | 647 | $person->addChild("imageURL", $entry['photo_data'][0]); |
| 624 | 648 | |
| 625 | 649 | print " Added photo: " . $entry['photo_data'][0] . PHP_EOL; |
| 650 | + } else { |
|
| 651 | + print " WARNING: Only VCard embedded photo data or a reference URL is currently supported." . PHP_EOL; |
|
| 626 | 652 | } |
| 627 | - else |
|
| 628 | - print " WARNING: Only VCard embedded photo data or a reference URL is currently supported." . PHP_EOL; |
|
| 629 | 653 | } |
| 630 | 654 | |
| 631 | 655 | $contact->addChild("services"); |
@@ -644,21 +668,23 @@ discard block |
||
| 644 | 668 | |
| 645 | 669 | public function _concat ($text1,$text2) |
| 646 | 670 | { |
| 647 | - if($text1 == '') |
|
| 648 | - return $text2; |
|
| 649 | - elseif($text2 == '') |
|
| 650 | - return $text1; |
|
| 651 | - else |
|
| 652 | - return $text1.", ".$text2; |
|
| 671 | + if($text1 == '') { |
|
| 672 | + return $text2; |
|
| 673 | + } elseif($text2 == '') { |
|
| 674 | + return $text1; |
|
| 675 | + } else { |
|
| 676 | + return $text1.", ".$text2; |
|
| 677 | + } |
|
| 653 | 678 | } |
| 654 | 679 | |
| 655 | 680 | public function _parse_fb_result($text) |
| 656 | 681 | { |
| 657 | 682 | preg_match("/\<h2\>([^\<]+)\<\/h2\>/", $text, $matches); |
| 658 | - if($matches) |
|
| 659 | - return $matches[1]; |
|
| 660 | - else |
|
| 661 | - return "Error while uploading xml to fritzbox"; |
|
| 683 | + if($matches) { |
|
| 684 | + return $matches[1]; |
|
| 685 | + } else { |
|
| 686 | + return "Error while uploading xml to fritzbox"; |
|
| 687 | + } |
|
| 662 | 688 | } |
| 663 | 689 | |
| 664 | 690 | public function upload_to_fb() |
@@ -743,13 +769,14 @@ discard block |
||
| 743 | 769 | } |
| 744 | 770 | |
| 745 | 771 | ftp_pasv($conn_id, true); |
| 746 | - if(!ftp_put($conn_id, $remote_path . "/" . $file, $fileinfo->getPathname(), FTP_BINARY)) |
|
| 747 | - print " ERROR: while uploading file " . $fileinfo->getFilename() . PHP_EOL; |
|
| 748 | - else |
|
| 749 | - print " ok." . PHP_EOL; |
|
| 772 | + if(!ftp_put($conn_id, $remote_path . "/" . $file, $fileinfo->getPathname(), FTP_BINARY)) { |
|
| 773 | + print " ERROR: while uploading file " . $fileinfo->getFilename() . PHP_EOL; |
|
| 774 | + } else { |
|
| 775 | + print " ok." . PHP_EOL; |
|
| 776 | + } |
|
| 777 | + } else { |
|
| 778 | + print " ok." . PHP_EOL; |
|
| 750 | 779 | } |
| 751 | - else |
|
| 752 | - print " ok." . PHP_EOL; |
|
| 753 | 780 | |
| 754 | 781 | // cleanup old files |
| 755 | 782 | foreach($all_existing_files as $existing_file) |
@@ -760,30 +787,30 @@ discard block |
||
| 760 | 787 | ftp_delete($conn_id, $remote_path . "/" . basename($existing_file)); |
| 761 | 788 | } |
| 762 | 789 | } |
| 790 | + } else { |
|
| 791 | + print " already exists." . PHP_EOL; |
|
| 763 | 792 | } |
| 764 | - else |
|
| 765 | - print " already exists." . PHP_EOL; |
|
| 766 | 793 | } |
| 767 | 794 | } |
| 768 | 795 | } |
| 769 | - } |
|
| 770 | - else |
|
| 771 | - print " ERROR: couldn't login to FTP-server '" . $ftp_server . "' with provided username/password settings." |
|
| 796 | + } else { |
|
| 797 | + print " ERROR: couldn't login to FTP-server '" . $ftp_server . "' with provided username/password settings." |
|
| 772 | 798 | |
| 773 | 799 | // close ftp connection |
| 774 | 800 | ftp_close($conn_id); |
| 775 | - } |
|
| 776 | - else |
|
| 777 | - print " ERROR: couldn't connect to FTP server '" . $ftp_server . "'." |
|
| 801 | + } |
|
| 802 | + } else { |
|
| 803 | + print " ERROR: couldn't connect to FTP server '" . $ftp_server . "'." |
|
| 778 | 804 | |
| 779 | 805 | // in case numeric IP is given, try to resolve to hostname. Otherwise Fritzbox may decline login, because it is determine to be (prohibited) remote access |
| 780 | 806 | $hostname = $this->config['fritzbox_ip']; |
| 807 | + } |
|
| 781 | 808 | if(filter_var($hostname, FILTER_VALIDATE_IP)) |
| 782 | 809 | { |
| 783 | 810 | $hostname = gethostbyaddr($hostname); |
| 784 | - if($hostname == $this->config['fritzbox_ip']) |
|
| 785 | - print " WARNING: Unable to get hostname for IP address (". $this->config['fritzbox_ip'] .") <" . $hostname . "<" . PHP_EOL; |
|
| 786 | - else |
|
| 811 | + if($hostname == $this->config['fritzbox_ip']) { |
|
| 812 | + print " WARNING: Unable to get hostname for IP address (". $this->config['fritzbox_ip'] .") <" . $hostname . "<" . PHP_EOL; |
|
| 813 | + } else |
|
| 787 | 814 | { |
| 788 | 815 | print " INFO: Given IP address (". $this->config['fritzbox_ip'] .") has hostname ". $hostname . "." . PHP_EOL; |
| 789 | 816 | $this->config['fritzbox_ip'] = $hostname; |
@@ -815,8 +842,7 @@ discard block |
||
| 815 | 842 | $fritz = null; // destroy the object to log out |
| 816 | 843 | |
| 817 | 844 | print " FRITZ!Box returned message: '" . $msg . "'" . PHP_EOL; |
| 818 | - } |
|
| 819 | - catch(Exception $e) |
|
| 845 | + } catch(Exception $e) |
|
| 820 | 846 | { |
| 821 | 847 | print " ERROR: " . $e->getMessage() . PHP_EOL; // show the error message in anything failed |
| 822 | 848 | } |
@@ -26,8 +26,7 @@ discard block |
||
| 26 | 26 | if (isset($argv[1]) && ($argv[1] == 0 || $argv[1] == 1) ) |
| 27 | 27 | { |
| 28 | 28 | $mode = (bool)$argv[1]; |
| 29 | - } |
|
| 30 | - else |
|
| 29 | + } else |
|
| 31 | 30 | { |
| 32 | 31 | if ( $fritz->config->getItem('logging') == 'console' ) |
| 33 | 32 | { |
@@ -43,8 +42,7 @@ discard block |
||
| 43 | 42 | 0 disables the guest access |
| 44 | 43 | 1 enables the guest access |
| 45 | 44 | '; |
| 46 | - } |
|
| 47 | - else |
|
| 45 | + } else |
|
| 48 | 46 | { |
| 49 | 47 | $fritz->logMessage($message . 'ERROR: Script was called without or with an invalid argument'); |
| 50 | 48 | } |
@@ -95,21 +93,17 @@ discard block |
||
| 95 | 93 | if ( isset($matches[1]) && $mode == true ) |
| 96 | 94 | { |
| 97 | 95 | $message .= 'LAN4 guest access is now active.'; |
| 98 | - } |
|
| 99 | - else if ( !isset($matches[1]) && $mode == false ) |
|
| 96 | + } else if ( !isset($matches[1]) && $mode == false ) |
|
| 100 | 97 | { |
| 101 | 98 | $message .= 'LAN4 guest access is now inactive.'; |
| 102 | - } |
|
| 103 | - else if ( isset($matches[1]) && $mode == false ) |
|
| 99 | + } else if ( isset($matches[1]) && $mode == false ) |
|
| 104 | 100 | { |
| 105 | 101 | $message .= 'ERROR: LAN4 guest access status change failed, should be inactive, but is still active.'; |
| 106 | - } |
|
| 107 | - else if ( !isset($matches[1]) && $mode == true ) |
|
| 102 | + } else if ( !isset($matches[1]) && $mode == true ) |
|
| 108 | 103 | { |
| 109 | 104 | $message .= 'ERROR: LAN4 guest access status change failed, should be active, but is still inactive.'; |
| 110 | 105 | } |
| 111 | -} |
|
| 112 | -catch (Exception $e) |
|
| 106 | +} catch (Exception $e) |
|
| 113 | 107 | { |
| 114 | 108 | $message .= $e->getMessage(); |
| 115 | 109 | } |
@@ -118,8 +112,7 @@ discard block |
||
| 118 | 112 | if ( isset($fritz) && is_object($fritz) && get_class($fritz) == 'fritzbox_api' ) |
| 119 | 113 | { |
| 120 | 114 | $fritz->logMessage($message); |
| 121 | -} |
|
| 122 | -else |
|
| 115 | +} else |
|
| 123 | 116 | { |
| 124 | 117 | echo($message); |
| 125 | 118 | } |
@@ -98,8 +98,7 @@ discard block |
||
| 98 | 98 | if ( !$this->config->getItem('remote_config_user') || !$this->config->getItem('remote_config_password') ){ |
| 99 | 99 | $this->error('ERROR: Remote config mode enabled, but no username or no password provided'); |
| 100 | 100 | } |
| 101 | - } |
|
| 102 | - else { |
|
| 101 | + } else { |
|
| 103 | 102 | $this->config->setItem('old_remote_config_user', null); |
| 104 | 103 | $this->config->setItem('old_remote_config_password', null); |
| 105 | 104 | } |
@@ -133,8 +132,7 @@ discard block |
||
| 133 | 132 | { |
| 134 | 133 | curl_setopt($ch, CURLOPT_URL, $this->config->getItem('fritzbox_url') . $formfields['getpage'] . '?sid=' . $this->sid); |
| 135 | 134 | unset($formfields['getpage']); |
| 136 | - } |
|
| 137 | - else |
|
| 135 | + } else |
|
| 138 | 136 | { |
| 139 | 137 | // add the sid, if it is already set |
| 140 | 138 | if ($this->sid != '0000000000000000') |
@@ -293,8 +291,7 @@ discard block |
||
| 293 | 291 | { |
| 294 | 292 | $getpage = $params['getpage'] . '?'; |
| 295 | 293 | unset($params['getpage']); |
| 296 | - } |
|
| 297 | - else |
|
| 294 | + } else |
|
| 298 | 295 | { |
| 299 | 296 | $getpage = '/cgi-bin/webcm?'; |
| 300 | 297 | } |
@@ -331,8 +328,7 @@ discard block |
||
| 331 | 328 | if ( $this->config->getItem('use_lua_login_method') == true ) |
| 332 | 329 | { |
| 333 | 330 | $loginpage = '/login_sid.lua'; |
| 334 | - } |
|
| 335 | - else |
|
| 331 | + } else |
|
| 336 | 332 | { |
| 337 | 333 | $loginpage = '../html/login_sid.xml'; |
| 338 | 334 | } |
@@ -366,8 +362,7 @@ discard block |
||
| 366 | 362 | { |
| 367 | 363 | $formfields['username'] = $this->config->getItem('remote_config_user'); |
| 368 | 364 | $response = $challenge . '-' . md5(mb_convert_encoding($challenge . '-' . $this->config->getItem('remote_config_password'), "UCS-2LE", "UTF-8")); |
| 369 | - } |
|
| 370 | - else |
|
| 365 | + } else |
|
| 371 | 366 | { |
| 372 | 367 | if ( $this->config->getItem('username') ) |
| 373 | 368 | { |
@@ -376,8 +371,7 @@ discard block |
||
| 376 | 371 | $response = $challenge . '-' . md5(mb_convert_encoding($challenge . '-' . $this->config->getItem('password'), "UCS-2LE", "UTF-8")); |
| 377 | 372 | } |
| 378 | 373 | $formfields['response'] = $response; |
| 379 | - } |
|
| 380 | - else |
|
| 374 | + } else |
|
| 381 | 375 | { |
| 382 | 376 | $response = $challenge . '-' . md5(mb_convert_encoding($challenge . '-' . $this->config->getItem('password'), "UCS-2LE", "UTF-8")); |
| 383 | 377 | $formfields['login:command/response'] = $response; |
@@ -394,8 +388,7 @@ discard block |
||
| 394 | 388 | if ( $session_status_simplexml->SID != '0000000000000000' ) |
| 395 | 389 | { |
| 396 | 390 | return (string)$session_status_simplexml->SID; |
| 397 | - } |
|
| 398 | - else |
|
| 391 | + } else |
|
| 399 | 392 | { |
| 400 | 393 | $this->error('ERROR: Login failed with an unknown response.'); |
| 401 | 394 | } |
@@ -412,8 +405,7 @@ discard block |
||
| 412 | 405 | if ( $this->config->getItem('use_lua_login_method') == true ) |
| 413 | 406 | { |
| 414 | 407 | $this->doGetRequest(array('getpage' => '/home/home.lua', 'logout' => '1')); |
| 415 | - } |
|
| 416 | - else |
|
| 408 | + } else |
|
| 417 | 409 | { |
| 418 | 410 | $formfields = array( |
| 419 | 411 | 'getpage' => '../html/de/menus/menu2.html', |
@@ -460,18 +452,15 @@ discard block |
||
| 460 | 452 | if ( $this->config->getItem('logging') == 'console' ) |
| 461 | 453 | { |
| 462 | 454 | echo $message; |
| 463 | - } |
|
| 464 | - else if ( $this->config->getItem('logging') == 'silent' || $this->config->getItem('logging') == false ) |
|
| 455 | + } else if ( $this->config->getItem('logging') == 'silent' || $this->config->getItem('logging') == false ) |
|
| 465 | 456 | { |
| 466 | 457 | // do nothing |
| 467 | - } |
|
| 468 | - else |
|
| 458 | + } else |
|
| 469 | 459 | { |
| 470 | 460 | if ( is_writable($this->config->getItem('logging')) || is_writable(dirname($this->config->getItem('logging'))) ) |
| 471 | 461 | { |
| 472 | 462 | file_put_contents($this->config->getItem('logging'), $message . $this->config->getItem('newline'), FILE_APPEND); |
| 473 | - } |
|
| 474 | - else |
|
| 463 | + } else |
|
| 475 | 464 | { |
| 476 | 465 | echo('Error: Cannot log to non-writeable file or dir: ' . $this->config->getItem('logging')); |
| 477 | 466 | } |
@@ -520,8 +509,7 @@ discard block |
||
| 520 | 509 | if ( $item == 'all' ) |
| 521 | 510 | { |
| 522 | 511 | return $this->config; |
| 523 | - } |
|
| 524 | - elseif ( isset($this->config[$item]) ) |
|
| 512 | + } elseif ( isset($this->config[$item]) ) |
|
| 525 | 513 | { |
| 526 | 514 | return $this->config[$item]; |
| 527 | 515 | } |
@@ -31,8 +31,7 @@ discard block |
||
| 31 | 31 | $fritz->doPostForm($formfields); |
| 32 | 32 | // set a log message |
| 33 | 33 | $message .= 'Call list sucessfully deleted'; |
| 34 | -} |
|
| 35 | -catch (Exception $e) |
|
| 34 | +} catch (Exception $e) |
|
| 36 | 35 | { |
| 37 | 36 | $message .= $e->getMessage(); |
| 38 | 37 | } |
@@ -41,8 +40,7 @@ discard block |
||
| 41 | 40 | if ( isset($fritz) && is_object($fritz) && get_class($fritz) == 'fritzbox_api' ) |
| 42 | 41 | { |
| 43 | 42 | $fritz->logMessage($message); |
| 44 | -} |
|
| 45 | -else |
|
| 43 | +} else |
|
| 46 | 44 | { |
| 47 | 45 | echo($message); |
| 48 | 46 | } |
@@ -14,8 +14,7 @@ discard block |
||
| 14 | 14 | ); |
| 15 | 15 | $fritz->doPostForm($formfields); |
| 16 | 16 | $message .= 'Phone ' . $dial . ' ringed.'; |
| 17 | -} |
|
| 18 | -catch (Exception $e) |
|
| 17 | +} catch (Exception $e) |
|
| 19 | 18 | { |
| 20 | 19 | $message .= $e->getMessage(); |
| 21 | 20 | } |
@@ -24,8 +23,7 @@ discard block |
||
| 24 | 23 | if ( isset($fritz) && is_object($fritz) && get_class($fritz) == 'fritzbox_api' ) |
| 25 | 24 | { |
| 26 | 25 | $fritz->logMessage($message); |
| 27 | -} |
|
| 28 | -else |
|
| 26 | +} else |
|
| 29 | 27 | { |
| 30 | 28 | echo($message); |
| 31 | 29 | } |
@@ -18,8 +18,7 @@ discard block |
||
| 18 | 18 | 'telcfg:settings/Diversity' . $diversity . '/Active' => $mode, |
| 19 | 19 | ); |
| 20 | 20 | $fritz->doPostForm($formfields); |
| 21 | -} |
|
| 22 | -catch (Exception $e) |
|
| 21 | +} catch (Exception $e) |
|
| 23 | 22 | { |
| 24 | 23 | $message .= $e->getMessage(); |
| 25 | 24 | } |
@@ -28,8 +27,7 @@ discard block |
||
| 28 | 27 | if ( isset($fritz) && is_object($fritz) && get_class($fritz) == 'fritzbox_api' ) |
| 29 | 28 | { |
| 30 | 29 | $fritz->logMessage($message); |
| 31 | -} |
|
| 32 | -else |
|
| 30 | +} else |
|
| 33 | 31 | { |
| 34 | 32 | echo($message); |
| 35 | 33 | } |
@@ -37,8 +37,7 @@ discard block |
||
| 37 | 37 | // 3 for the first and the second, 5 for the first and the third and so on |
| 38 | 38 | // this is based on 1 => 1, 2 => 10, 3 => 11, 4 => 100, 5 => 101, 6 => 110, 7 => 111 |
| 39 | 39 | $fritz->doPostForm($formfields); |
| 40 | -} |
|
| 41 | -catch (Exception $e) |
|
| 40 | +} catch (Exception $e) |
|
| 42 | 41 | { |
| 43 | 42 | $message .= $e->getMessage(); |
| 44 | 43 | } |
@@ -47,8 +46,7 @@ discard block |
||
| 47 | 46 | if ( isset($fritz) && is_object($fritz) && get_class($fritz) == 'fritzbox_api' ) |
| 48 | 47 | { |
| 49 | 48 | $fritz->logMessage($message); |
| 50 | -} |
|
| 51 | -else |
|
| 49 | +} else |
|
| 52 | 50 | { |
| 53 | 51 | echo($message); |
| 54 | 52 | } |
@@ -25,8 +25,7 @@ discard block |
||
| 25 | 25 | if (isset($argv[1]) && ($argv[1] == 0 || $argv[1] == 1) ) |
| 26 | 26 | { |
| 27 | 27 | $mode = (bool)$argv[1]; |
| 28 | - } |
|
| 29 | - else |
|
| 28 | + } else |
|
| 30 | 29 | { |
| 31 | 30 | if ( $fritz->config->getItem('logging') == 'console' ) |
| 32 | 31 | { |
@@ -45,8 +44,7 @@ discard block |
||
| 45 | 44 | The optional argument PASSWORD sets a new guest access password (min 8 chars) |
| 46 | 45 | Defaults to false, so the current password is kept. |
| 47 | 46 | '; |
| 48 | - } |
|
| 49 | - else |
|
| 47 | + } else |
|
| 50 | 48 | { |
| 51 | 49 | $fritz->logMessage($message . 'ERROR: Script was called without or with an invalid argument'); |
| 52 | 50 | } |
@@ -111,21 +109,17 @@ discard block |
||
| 111 | 109 | { |
| 112 | 110 | $message .= 'WLAN guest access is now active. WPA-Key is "' . $matches[1] . '"'; |
| 113 | 111 | } |
| 114 | - } |
|
| 115 | - else if ( !isset($matches[1]) && $mode == false ) |
|
| 112 | + } else if ( !isset($matches[1]) && $mode == false ) |
|
| 116 | 113 | { |
| 117 | 114 | $message .= 'WLAN guest access is now inactive.'; |
| 118 | - } |
|
| 119 | - else if ( isset($matches[1]) && $mode == false ) |
|
| 115 | + } else if ( isset($matches[1]) && $mode == false ) |
|
| 120 | 116 | { |
| 121 | 117 | $message .= 'ERROR: WLAN guest access status change failed, should be inactive, but is still active.'; |
| 122 | - } |
|
| 123 | - else if ( !isset($matches[1]) && $mode == true ) |
|
| 118 | + } else if ( !isset($matches[1]) && $mode == true ) |
|
| 124 | 119 | { |
| 125 | 120 | $message .= 'ERROR: WLAN guest access status change failed, should be active, but is still inactive.'; |
| 126 | 121 | } |
| 127 | -} |
|
| 128 | -catch (Exception $e) |
|
| 122 | +} catch (Exception $e) |
|
| 129 | 123 | { |
| 130 | 124 | $message .= $e->getMessage(); |
| 131 | 125 | } |
@@ -134,8 +128,7 @@ discard block |
||
| 134 | 128 | if ( isset($fritz) && is_object($fritz) && get_class($fritz) == 'fritzbox_api' ) |
| 135 | 129 | { |
| 136 | 130 | $fritz->logMessage($message); |
| 137 | -} |
|
| 138 | -else |
|
| 131 | +} else |
|
| 139 | 132 | { |
| 140 | 133 | echo($message); |
| 141 | 134 | } |
@@ -53,8 +53,7 @@ discard block |
||
| 53 | 53 | |
| 54 | 54 | // set a log message |
| 55 | 55 | $message .= 'Call list sucessfully downloaded'; |
| 56 | -} |
|
| 57 | -catch (Exception $e) |
|
| 56 | +} catch (Exception $e) |
|
| 58 | 57 | { |
| 59 | 58 | $message .= $e->getMessage(); |
| 60 | 59 | } |
@@ -63,8 +62,7 @@ discard block |
||
| 63 | 62 | if ( isset($fritz) && is_object($fritz) && get_class($fritz) == 'fritzbox_api' ) |
| 64 | 63 | { |
| 65 | 64 | $fritz->logMessage($message); |
| 66 | -} |
|
| 67 | -else |
|
| 65 | +} else |
|
| 68 | 66 | { |
| 69 | 67 | echo($message); |
| 70 | 68 | } |