@@ -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; |
@@ -209,8 +216,9 @@ discard block |
||
| 209 | 216 | |
| 210 | 217 | // set the vcard extension in case the user |
| 211 | 218 | // defined it in the config |
| 212 | - if(isset($conf['extension'])) |
|
| 213 | - $carddav->setVcardExtension($conf['extension']); |
|
| 219 | + if(isset($conf['extension'])) { |
|
| 220 | + $carddav->setVcardExtension($conf['extension']); |
|
| 221 | + } |
|
| 214 | 222 | |
| 215 | 223 | // retrieve data from the CardDAV server now |
| 216 | 224 | $xmldata = $carddav->get(); |
@@ -218,8 +226,9 @@ discard block |
||
| 218 | 226 | // identify if we received UTF-8 encoded data from the |
| 219 | 227 | // CardDAV server and if not reencode it since the FRITZ!Box |
| 220 | 228 | // requires UTF-8 encoded data |
| 221 | - if(iconv('utf-8', 'utf-8//IGNORE', $xmldata) != $xmldata) |
|
| 222 | - $xmldata = utf8_encode($xmldata); |
|
| 229 | + if(iconv('utf-8', 'utf-8//IGNORE', $xmldata) != $xmldata) { |
|
| 230 | + $xmldata = utf8_encode($xmldata); |
|
| 231 | + } |
|
| 223 | 232 | |
| 224 | 233 | // read raw_vcard data from xml response |
| 225 | 234 | $raw_vcards = array(); |
@@ -240,28 +249,34 @@ discard block |
||
| 240 | 249 | { |
| 241 | 250 | $vcard_obj = new vCard(false, $v); |
| 242 | 251 | $name_arr = null; |
| 243 | - if(isset($vcard_obj->n[0])) |
|
| 244 | - $name_arr = $vcard_obj->n[0]; |
|
| 252 | + if(isset($vcard_obj->n[0])) { |
|
| 253 | + $name_arr = $vcard_obj->n[0]; |
|
| 254 | + } |
|
| 245 | 255 | $org_arr = null; |
| 246 | - if(isset($vcard_obj->org[0])) |
|
| 247 | - $org_arr = $vcard_obj->org[0]; |
|
| 256 | + if(isset($vcard_obj->org[0])) { |
|
| 257 | + $org_arr = $vcard_obj->org[0]; |
|
| 258 | + } |
|
| 248 | 259 | $addnames = ''; |
| 249 | 260 | $prefix = ''; |
| 250 | 261 | $suffix = ''; |
| 251 | 262 | $orgname = ''; |
| 252 | 263 | |
| 253 | 264 | // Build name Parts if existing ans switch to true in config |
| 254 | - if(isset($name_arr['prefixes']) AND $this->config['prefix']) |
|
| 255 | - $prefix = trim($name_arr['prefixes']); |
|
| 265 | + if(isset($name_arr['prefixes']) AND $this->config['prefix']) { |
|
| 266 | + $prefix = trim($name_arr['prefixes']); |
|
| 267 | + } |
|
| 256 | 268 | |
| 257 | - if(isset($name_arr['suffixes']) AND $this->config['suffix']) |
|
| 258 | - $suffix = trim($name_arr['suffixes']); |
|
| 269 | + if(isset($name_arr['suffixes']) AND $this->config['suffix']) { |
|
| 270 | + $suffix = trim($name_arr['suffixes']); |
|
| 271 | + } |
|
| 259 | 272 | |
| 260 | - if(isset($name_arr['additionalnames']) AND $this->config['addnames']) |
|
| 261 | - $addnames = trim($name_arr['additionalnames']); |
|
| 273 | + if(isset($name_arr['additionalnames']) AND $this->config['addnames']) { |
|
| 274 | + $addnames = trim($name_arr['additionalnames']); |
|
| 275 | + } |
|
| 262 | 276 | |
| 263 | - if(isset($org_arr['name']) AND $this->config['orgname']) |
|
| 264 | - $orgname = trim($org_arr['name']); |
|
| 277 | + if(isset($org_arr['name']) AND $this->config['orgname']) { |
|
| 278 | + $orgname = trim($org_arr['name']); |
|
| 279 | + } |
|
| 265 | 280 | |
| 266 | 281 | $firstname = trim($name_arr['firstname']); |
| 267 | 282 | $lastname = trim($name_arr['lastname']); |
@@ -280,72 +295,79 @@ discard block |
||
| 280 | 295 | $format = $this->config['fullname_format']; |
| 281 | 296 | |
| 282 | 297 | // Prefix |
| 283 | - if(!empty($prefix)) |
|
| 284 | - $name .= $prefix; |
|
| 298 | + if(!empty($prefix)) { |
|
| 299 | + $name .= $prefix; |
|
| 300 | + } |
|
| 285 | 301 | |
| 286 | 302 | if($format == 0) |
| 287 | 303 | { |
| 288 | 304 | // Lastname |
| 289 | - if(!empty($name) AND !empty($lastname)) |
|
| 290 | - $name .= ' ' . $lastname; |
|
| 291 | - else |
|
| 292 | - $name .= $lastname; |
|
| 293 | - } |
|
| 294 | - else |
|
| 305 | + if(!empty($name) AND !empty($lastname)) { |
|
| 306 | + $name .= ' ' . $lastname; |
|
| 307 | + } else { |
|
| 308 | + $name .= $lastname; |
|
| 309 | + } |
|
| 310 | + } else |
|
| 295 | 311 | { |
| 296 | 312 | // Firstname |
| 297 | - if(!empty($name) AND !empty($firstname)) |
|
| 298 | - $name .= ' ' . $firstname; |
|
| 299 | - else |
|
| 300 | - $name .= $firstname; |
|
| 313 | + if(!empty($name) AND !empty($firstname)) { |
|
| 314 | + $name .= ' ' . $firstname; |
|
| 315 | + } else { |
|
| 316 | + $name .= $firstname; |
|
| 317 | + } |
|
| 301 | 318 | } |
| 302 | 319 | |
| 303 | 320 | if($format == 2) |
| 304 | 321 | { |
| 305 | 322 | // AdditionalNames |
| 306 | - if(!empty($name) AND !empty($addnames)) |
|
| 307 | - $name .= ' ' . $addnames; |
|
| 308 | - else |
|
| 309 | - $name .= $addnames; |
|
| 323 | + if(!empty($name) AND !empty($addnames)) { |
|
| 324 | + $name .= ' ' . $addnames; |
|
| 325 | + } else { |
|
| 326 | + $name .= $addnames; |
|
| 327 | + } |
|
| 310 | 328 | } |
| 311 | 329 | |
| 312 | 330 | if($format == 0) |
| 313 | 331 | { |
| 314 | 332 | // Firstname |
| 315 | - if(!empty($name) AND !empty($firstname)) |
|
| 316 | - $name .= ', ' . $firstname; |
|
| 317 | - else |
|
| 318 | - $name .= $firstname; |
|
| 319 | - } |
|
| 320 | - else |
|
| 333 | + if(!empty($name) AND !empty($firstname)) { |
|
| 334 | + $name .= ', ' . $firstname; |
|
| 335 | + } else { |
|
| 336 | + $name .= $firstname; |
|
| 337 | + } |
|
| 338 | + } else |
|
| 321 | 339 | { |
| 322 | 340 | // Lastname |
| 323 | - if(!empty($name) AND !empty($lastname)) |
|
| 324 | - $name .= ' ' . $lastname; |
|
| 325 | - else |
|
| 326 | - $name .= $lastname; |
|
| 341 | + if(!empty($name) AND !empty($lastname)) { |
|
| 342 | + $name .= ' ' . $lastname; |
|
| 343 | + } else { |
|
| 344 | + $name .= $lastname; |
|
| 345 | + } |
|
| 327 | 346 | } |
| 328 | 347 | |
| 329 | 348 | if($format != 2) |
| 330 | 349 | { |
| 331 | 350 | // AdditionalNames |
| 332 | - if(!empty($name) AND !empty($addnames)) |
|
| 333 | - $name .= ' ' . $addnames; |
|
| 334 | - else |
|
| 335 | - $name .= $addnames; |
|
| 351 | + if(!empty($name) AND !empty($addnames)) { |
|
| 352 | + $name .= ' ' . $addnames; |
|
| 353 | + } else { |
|
| 354 | + $name .= $addnames; |
|
| 355 | + } |
|
| 336 | 356 | } |
| 337 | 357 | |
| 338 | 358 | // Suffix |
| 339 | - if(!empty($name) AND !empty($suffix)) |
|
| 340 | - $name .= ' ' . $suffix; |
|
| 341 | - else |
|
| 342 | - $name .= $suffix; |
|
| 359 | + if(!empty($name) AND !empty($suffix)) { |
|
| 360 | + $name .= ' ' . $suffix; |
|
| 361 | + } else { |
|
| 362 | + $name .= $suffix; |
|
| 363 | + } |
|
| 343 | 364 | |
| 344 | 365 | // OrgName |
| 345 | - if(!empty($name) AND !empty($orgname)) |
|
| 346 | - $name .= ' (' . $orgname . ')'; |
|
| 347 | - else |
|
| 348 | - $name .= $orgname; |
|
| 366 | + if(!empty($name) AND !empty($orgname)) { |
|
| 367 | + $name .= ' (' . $orgname . ')'; |
|
| 368 | + } else { |
|
| 369 | + $name .= $orgname; |
|
| 370 | + } |
|
| 349 | 371 | |
| 350 | 372 | // make sure to trim whitespaces and double spaces |
| 351 | 373 | $name = trim(str_replace(' ', ' ', $name)); |
@@ -363,22 +385,22 @@ discard block |
||
| 363 | 385 | { |
| 364 | 386 | $photo = $imgseqfname; |
| 365 | 387 | $imgseqfname++; |
| 366 | - } |
|
| 367 | - else |
|
| 388 | + } else |
|
| 368 | 389 | { |
| 369 | 390 | $photo = str_replace(array(',','&',' ','/','ä','ö','ü','Ä','Ö','Ü','ß','á','à','ó','ò','ú','ù','í','ø'), |
| 370 | 391 | array('','_','_','_','ae','oe','ue','Ae','Oe','Ue','ss','a','a','o','o','u','u','i','oe'),$name); |
| 371 | 392 | } |
| 393 | + } else { |
|
| 394 | + $photo = ''; |
|
| 372 | 395 | } |
| 373 | - else |
|
| 374 | - $photo = ''; |
|
| 375 | 396 | |
| 376 | 397 | // phone |
| 377 | 398 | $phone_no = array(); |
| 378 | - if($vcard_obj->categories) |
|
| 379 | - $categories = $vcard_obj->categories[0]; |
|
| 380 | - else |
|
| 381 | - $categories = array(); |
|
| 399 | + if($vcard_obj->categories) { |
|
| 400 | + $categories = $vcard_obj->categories[0]; |
|
| 401 | + } else { |
|
| 402 | + $categories = array(); |
|
| 403 | + } |
|
| 382 | 404 | |
| 383 | 405 | // check for quickdial entry |
| 384 | 406 | if(isset($vcard_obj->note[0])) |
@@ -413,9 +435,9 @@ discard block |
||
| 413 | 435 | break; |
| 414 | 436 | } |
| 415 | 437 | } |
| 416 | - } |
|
| 417 | - else |
|
| 418 | - $add_entry = 1; |
|
| 438 | + } else { |
|
| 439 | + $add_entry = 1; |
|
| 440 | + } |
|
| 419 | 441 | |
| 420 | 442 | if($add_entry == 1) |
| 421 | 443 | { |
@@ -428,8 +450,7 @@ discard block |
||
| 428 | 450 | { |
| 429 | 451 | $type = "mobile"; |
| 430 | 452 | $phone_number = $t; |
| 431 | - } |
|
| 432 | - else |
|
| 453 | + } else |
|
| 433 | 454 | { |
| 434 | 455 | $phone_number = $t['value']; |
| 435 | 456 | |
@@ -439,10 +460,11 @@ discard block |
||
| 439 | 460 | if($qd_phone_nr == $phone_number_clean) |
| 440 | 461 | { |
| 441 | 462 | //Set quickdial |
| 442 | - if($value == 1) |
|
| 443 | - print "\nWARNING: Quickdial value 1 (**701) is not possible but used! \n"; |
|
| 444 | - elseif($value >= 100) |
|
| 445 | - print "\nWARNING: Quickdial value bigger than 99 (**799) is not possible but used! \n"; |
|
| 463 | + if($value == 1) { |
|
| 464 | + print "\nWARNING: Quickdial value 1 (**701) is not possible but used! \n"; |
|
| 465 | + } elseif($value >= 100) { |
|
| 466 | + print "\nWARNING: Quickdial value bigger than 99 (**799) is not possible but used! \n"; |
|
| 467 | + } |
|
| 446 | 468 | |
| 447 | 469 | $quickdial = $value; |
| 448 | 470 | } |
@@ -451,24 +473,26 @@ discard block |
||
| 451 | 473 | $typearr_lower = unserialize(strtolower(serialize($t['type']))); |
| 452 | 474 | |
| 453 | 475 | // find out priority |
| 454 | - if(in_array("pref", $typearr_lower)) |
|
| 455 | - $prio = 1; |
|
| 476 | + if(in_array("pref", $typearr_lower)) { |
|
| 477 | + $prio = 1; |
|
| 478 | + } |
|
| 456 | 479 | |
| 457 | 480 | // set the proper type |
| 458 | - if(in_array("cell", $typearr_lower)) |
|
| 459 | - $type = "mobile"; |
|
| 460 | - elseif(in_array("home", $typearr_lower)) |
|
| 461 | - $type = "home"; |
|
| 462 | - elseif(in_array("fax", $typearr_lower)) |
|
| 463 | - $type = "fax_work"; |
|
| 464 | - elseif(in_array("work", $typearr_lower)) |
|
| 465 | - $type = "work"; |
|
| 466 | - elseif(in_array("other", $typearr_lower)) |
|
| 467 | - $type = "other"; |
|
| 468 | - elseif(in_array("dom", $typearr_lower)) |
|
| 469 | - $type = "other"; |
|
| 470 | - else |
|
| 471 | - continue; |
|
| 481 | + if(in_array("cell", $typearr_lower)) { |
|
| 482 | + $type = "mobile"; |
|
| 483 | + } elseif(in_array("home", $typearr_lower)) { |
|
| 484 | + $type = "home"; |
|
| 485 | + } elseif(in_array("fax", $typearr_lower)) { |
|
| 486 | + $type = "fax_work"; |
|
| 487 | + } elseif(in_array("work", $typearr_lower)) { |
|
| 488 | + $type = "work"; |
|
| 489 | + } elseif(in_array("other", $typearr_lower)) { |
|
| 490 | + $type = "other"; |
|
| 491 | + } elseif(in_array("dom", $typearr_lower)) { |
|
| 492 | + $type = "other"; |
|
| 493 | + } else { |
|
| 494 | + continue; |
|
| 495 | + } |
|
| 472 | 496 | } |
| 473 | 497 | $phone_no[] = array("type"=>$type, "prio"=>$prio, "quickdial"=>$quickdial, "value" => $this->_clear_phone_number($phone_number)); |
| 474 | 498 | } |
@@ -482,19 +506,19 @@ discard block |
||
| 482 | 506 | { |
| 483 | 507 | $type_email = "work"; |
| 484 | 508 | $email = $e; |
| 485 | - } |
|
| 486 | - else |
|
| 509 | + } else |
|
| 487 | 510 | { |
| 488 | 511 | $email = $e['value']; |
| 489 | 512 | $typearr_lower = unserialize(strtolower(serialize($e['type']))); |
| 490 | - if(in_array("work", $typearr_lower)) |
|
| 491 | - $type_email = "work"; |
|
| 492 | - elseif(in_array("home", $typearr_lower)) |
|
| 493 | - $type_email = "home"; |
|
| 494 | - elseif(in_array("other", $typearr_lower)) |
|
| 495 | - $type_email = "other"; |
|
| 496 | - else |
|
| 497 | - continue; |
|
| 513 | + if(in_array("work", $typearr_lower)) { |
|
| 514 | + $type_email = "work"; |
|
| 515 | + } elseif(in_array("home", $typearr_lower)) { |
|
| 516 | + $type_email = "home"; |
|
| 517 | + } elseif(in_array("other", $typearr_lower)) { |
|
| 518 | + $type_email = "other"; |
|
| 519 | + } else { |
|
| 520 | + continue; |
|
| 521 | + } |
|
| 498 | 522 | } |
| 499 | 523 | |
| 500 | 524 | // DEBUG: print out the email address on the console |
@@ -521,8 +545,9 @@ discard block |
||
| 521 | 545 | |
| 522 | 546 | public function build_fb_xml() |
| 523 | 547 | { |
| 524 | - if(empty($this->entries)) |
|
| 525 | - throw new Exception('No entries available! Call get_carddav_entries or set $this->entries manually!'); |
|
| 548 | + if(empty($this->entries)) { |
|
| 549 | + throw new Exception('No entries available! Call get_carddav_entries or set $this->entries manually!'); |
|
| 550 | + } |
|
| 526 | 551 | |
| 527 | 552 | // create FB XML in utf-8 format |
| 528 | 553 | $root = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?><phonebooks><phonebook></phonebook></phonebooks>'); |
@@ -560,8 +585,9 @@ discard block |
||
| 560 | 585 | } |
| 561 | 586 | |
| 562 | 587 | // output a warning if no telephone number was found |
| 563 | - if($id == 0) |
|
| 564 | - print " WARNING: no phone entry found. VCard will be ignored." . PHP_EOL; |
|
| 588 | + if($id == 0) { |
|
| 589 | + print " WARNING: no phone entry found. VCard will be ignored." . PHP_EOL; |
|
| 590 | + } |
|
| 565 | 591 | |
| 566 | 592 | // email: put the email addresses into the fritzbox xml file |
| 567 | 593 | $email = $contact->addChild("services"); |
@@ -599,8 +625,7 @@ discard block |
||
| 599 | 625 | file_put_contents($photo_file . ".b64", $photo_data); |
| 600 | 626 | $this->base64_to_jpeg($photo_file . ".b64", $photo_file); |
| 601 | 627 | unlink($photo_file . ".b64"); |
| 602 | - } |
|
| 603 | - else |
|
| 628 | + } else |
|
| 604 | 629 | { |
| 605 | 630 | print " WARNING: non-base64 encoded photo data found and used." . PHP_EOL; |
| 606 | 631 | file_put_contents($photo_file, $photo_data); |
@@ -610,19 +635,18 @@ discard block |
||
| 610 | 635 | $person->addChild("imageURL", $this->config['fritzbox_path'].$this->config['usb_disk']."FRITZ/fonpix/".basename($photo_file)); |
| 611 | 636 | |
| 612 | 637 | print " Added photo: " . basename($photo_file) . PHP_EOL; |
| 638 | + } else { |
|
| 639 | + print " WARNING: Only jpg contact photos are currently supported." . PHP_EOL; |
|
| 613 | 640 | } |
| 614 | - else |
|
| 615 | - print " WARNING: Only jpg contact photos are currently supported." . PHP_EOL; |
|
| 616 | - } |
|
| 617 | - elseif(substr($entry['photo_data'][0], 0, 4) == 'http') |
|
| 641 | + } elseif(substr($entry['photo_data'][0], 0, 4) == 'http') |
|
| 618 | 642 | { |
| 619 | 643 | // add contact photo to xml |
| 620 | 644 | $person->addChild("imageURL", $entry['photo_data'][0]); |
| 621 | 645 | |
| 622 | 646 | print " Added photo: " . $entry['photo_data'][0] . PHP_EOL; |
| 647 | + } else { |
|
| 648 | + print " WARNING: Only VCard embedded photo data or a reference URL is currently supported." . PHP_EOL; |
|
| 623 | 649 | } |
| 624 | - else |
|
| 625 | - print " WARNING: Only VCard embedded photo data or a reference URL is currently supported." . PHP_EOL; |
|
| 626 | 650 | } |
| 627 | 651 | |
| 628 | 652 | $contact->addChild("services"); |
@@ -641,21 +665,23 @@ discard block |
||
| 641 | 665 | |
| 642 | 666 | public function _concat ($text1,$text2) |
| 643 | 667 | { |
| 644 | - if($text1 == '') |
|
| 645 | - return $text2; |
|
| 646 | - elseif($text2 == '') |
|
| 647 | - return $text1; |
|
| 648 | - else |
|
| 649 | - return $text1.", ".$text2; |
|
| 668 | + if($text1 == '') { |
|
| 669 | + return $text2; |
|
| 670 | + } elseif($text2 == '') { |
|
| 671 | + return $text1; |
|
| 672 | + } else { |
|
| 673 | + return $text1.", ".$text2; |
|
| 674 | + } |
|
| 650 | 675 | } |
| 651 | 676 | |
| 652 | 677 | public function _parse_fb_result($text) |
| 653 | 678 | { |
| 654 | 679 | preg_match("/\<h2\>([^\<]+)\<\/h2\>/", $text, $matches); |
| 655 | - if($matches) |
|
| 656 | - return $matches[1]; |
|
| 657 | - else |
|
| 658 | - return "Error while uploading xml to fritzbox"; |
|
| 680 | + if($matches) { |
|
| 681 | + return $matches[1]; |
|
| 682 | + } else { |
|
| 683 | + return "Error while uploading xml to fritzbox"; |
|
| 684 | + } |
|
| 659 | 685 | } |
| 660 | 686 | |
| 661 | 687 | public function upload_to_fb() |
@@ -740,13 +766,14 @@ discard block |
||
| 740 | 766 | } |
| 741 | 767 | |
| 742 | 768 | ftp_pasv($conn_id, true); |
| 743 | - if(!ftp_put($conn_id, $remote_path . "/" . $file, $fileinfo->getPathname(), FTP_BINARY)) |
|
| 744 | - print " ERROR: while uploading file " . $fileinfo->getFilename() . PHP_EOL; |
|
| 745 | - else |
|
| 746 | - print " ok." . PHP_EOL; |
|
| 769 | + if(!ftp_put($conn_id, $remote_path . "/" . $file, $fileinfo->getPathname(), FTP_BINARY)) { |
|
| 770 | + print " ERROR: while uploading file " . $fileinfo->getFilename() . PHP_EOL; |
|
| 771 | + } else { |
|
| 772 | + print " ok." . PHP_EOL; |
|
| 773 | + } |
|
| 774 | + } else { |
|
| 775 | + print " ok." . PHP_EOL; |
|
| 747 | 776 | } |
| 748 | - else |
|
| 749 | - print " ok." . PHP_EOL; |
|
| 750 | 777 | |
| 751 | 778 | // cleanup old files |
| 752 | 779 | foreach($all_existing_files as $existing_file) |
@@ -757,30 +784,30 @@ discard block |
||
| 757 | 784 | ftp_delete($conn_id, $remote_path . "/" . basename($existing_file)); |
| 758 | 785 | } |
| 759 | 786 | } |
| 787 | + } else { |
|
| 788 | + print " already exists." . PHP_EOL; |
|
| 760 | 789 | } |
| 761 | - else |
|
| 762 | - print " already exists." . PHP_EOL; |
|
| 763 | 790 | } |
| 764 | 791 | } |
| 765 | 792 | } |
| 793 | + } else { |
|
| 794 | + print " ERROR: couldn't login to FTP-server '" . $ftp_server . "' with provided username/password settings." . PHP_EOL; |
|
| 766 | 795 | } |
| 767 | - else |
|
| 768 | - print " ERROR: couldn't login to FTP-server '" . $ftp_server . "' with provided username/password settings." . PHP_EOL; |
|
| 769 | 796 | |
| 770 | 797 | // close ftp connection |
| 771 | 798 | ftp_close($conn_id); |
| 799 | + } else { |
|
| 800 | + print " ERROR: couldn't connect to FTP server '" . $ftp_server . "'." . PHP_EOL; |
|
| 772 | 801 | } |
| 773 | - else |
|
| 774 | - print " ERROR: couldn't connect to FTP server '" . $ftp_server . "'." . PHP_EOL; |
|
| 775 | 802 | |
| 776 | 803 | // 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 |
| 777 | 804 | $hostname = $this->config['fritzbox_ip']; |
| 778 | 805 | if(filter_var($hostname, FILTER_VALIDATE_IP)) |
| 779 | 806 | { |
| 780 | 807 | $hostname = gethostbyaddr($hostname); |
| 781 | - if($hostname == $this->config['fritzbox_ip']) |
|
| 782 | - print " WARNING: Unable to get hostname for IP address (". $this->config['fritzbox_ip'] .") <" . $hostname . "<" . PHP_EOL; |
|
| 783 | - else |
|
| 808 | + if($hostname == $this->config['fritzbox_ip']) { |
|
| 809 | + print " WARNING: Unable to get hostname for IP address (". $this->config['fritzbox_ip'] .") <" . $hostname . "<" . PHP_EOL; |
|
| 810 | + } else |
|
| 784 | 811 | { |
| 785 | 812 | print " INFO: Given IP address (". $this->config['fritzbox_ip'] .") has hostname ". $hostname . "." . PHP_EOL; |
| 786 | 813 | $this->config['fritzbox_ip'] = $hostname; |
@@ -812,8 +839,7 @@ discard block |
||
| 812 | 839 | unset($fritz); // destroy the object to log out |
| 813 | 840 | |
| 814 | 841 | print " FRITZ!Box returned message: '" . $msg . "'" . PHP_EOL; |
| 815 | - } |
|
| 816 | - catch(Exception $e) |
|
| 842 | + } catch(Exception $e) |
|
| 817 | 843 | { |
| 818 | 844 | print " ERROR: " . $e->getMessage() . PHP_EOL; // show the error message in anything failed |
| 819 | 845 | } |