@@ -16,5 +16,5 @@ |
||
16 | 16 | |
17 | 17 | //$vCard = new vCard('Example3.0.vcf'); |
18 | 18 | |
19 | - echo '<pre>'.$vCard.'</pre>'; |
|
19 | + echo '<pre>' . $vCard . '</pre>'; |
|
20 | 20 | ?> |
21 | 21 | \ No newline at end of file |
@@ -208,7 +208,7 @@ discard block |
||
208 | 208 | const EXCEPTION_WRONG_HTTP_STATUS_CODE_ADD = 1004; |
209 | 209 | const EXCEPTION_WRONG_HTTP_STATUS_CODE_UPDATE = 1005; |
210 | 210 | const EXCEPTION_MALFORMED_XML_RESPONSE = 1006; |
211 | - const EXCEPTION_COULD_NOT_GENERATE_NEW_VCARD_ID = 1007; |
|
211 | + const EXCEPTION_COULD_NOT_GENERATE_NEW_VCARD_ID = 1007; |
|
212 | 212 | |
213 | 213 | |
214 | 214 | /** |
@@ -219,7 +219,7 @@ discard block |
||
219 | 219 | */ |
220 | 220 | public function __construct($url = null) |
221 | 221 | { |
222 | - if ($url !== null) { |
|
222 | + if($url !== null) { |
|
223 | 223 | $this->setUrl($url); |
224 | 224 | } |
225 | 225 | } |
@@ -245,14 +245,14 @@ discard block |
||
245 | 245 | { |
246 | 246 | $this->url = $url; |
247 | 247 | |
248 | - if (substr($this->url, -1, 1) !== '/') { |
|
248 | + if(substr($this->url, -1, 1) !== '/') { |
|
249 | 249 | $this->url = $this->url . '/'; |
250 | 250 | } |
251 | 251 | |
252 | 252 | $this->url_parts = parse_url($this->url); |
253 | 253 | |
254 | 254 | // workaround for providers that don't use the default .vcf extension |
255 | - if (strpos($this->url, "google.com")) |
|
255 | + if(strpos($this->url, "google.com")) |
|
256 | 256 | { |
257 | 257 | $this->setVcardExtension(""); |
258 | 258 | } |
@@ -335,11 +335,11 @@ discard block |
||
335 | 335 | // DEBUG: print the response of the carddav-server |
336 | 336 | //print_r($result); |
337 | 337 | |
338 | - switch ($result['http_code']) |
|
338 | + switch($result['http_code']) |
|
339 | 339 | { |
340 | 340 | case 200: |
341 | 341 | case 207: |
342 | - if ($raw === true) { |
|
342 | + if($raw === true) { |
|
343 | 343 | return $result['response']; |
344 | 344 | } else { |
345 | 345 | return $this->simplify($result['response'], $include_vcards); |
@@ -367,17 +367,17 @@ discard block |
||
367 | 367 | // DEBUG: print the response of the carddav-server |
368 | 368 | // print_r($result); |
369 | 369 | |
370 | - switch ($result['http_code']) |
|
370 | + switch($result['http_code']) |
|
371 | 371 | { |
372 | 372 | case 404: |
373 | - $altResult = $this->query($this->url . $vcard_id , 'GET'); |
|
373 | + $altResult = $this->query($this->url . $vcard_id, 'GET'); |
|
374 | 374 | // DEBUG: print the response of the carddav-server |
375 | 375 | // print_r($altResult); |
376 | - switch ($altResult['http_code']) |
|
376 | + switch($altResult['http_code']) |
|
377 | 377 | { |
378 | 378 | case 200: |
379 | 379 | case 207: |
380 | - print "Ignoring given Vcard Extension (".$this->url_vcard_extension.")" . PHP_EOL. "."; |
|
380 | + print "Ignoring given Vcard Extension (" . $this->url_vcard_extension . ")" . PHP_EOL . "."; |
|
381 | 381 | $this->setVcardExtension(""); |
382 | 382 | return $altResult['response']; |
383 | 383 | } |
@@ -425,7 +425,7 @@ discard block |
||
425 | 425 | |
426 | 426 | $result = $this->query($this->url, 'REPORT', $xml->outputMemory(), 'text/xml'); |
427 | 427 | |
428 | - switch ($result['http_code']) |
|
428 | + switch($result['http_code']) |
|
429 | 429 | { |
430 | 430 | case 200: |
431 | 431 | case 207: |
@@ -458,7 +458,7 @@ discard block |
||
458 | 458 | { |
459 | 459 | $result = $this->query($this->url, 'OPTIONS'); |
460 | 460 | |
461 | - if ($result['http_code'] === 200) { |
|
461 | + if($result['http_code'] === 200) { |
|
462 | 462 | return true; |
463 | 463 | } else { |
464 | 464 | return false; |
@@ -488,7 +488,7 @@ discard block |
||
488 | 488 | { |
489 | 489 | $result = $this->query($this->url . $vcard_id . $this->url_vcard_extension, 'DELETE'); |
490 | 490 | |
491 | - switch ($result['http_code']) |
|
491 | + switch($result['http_code']) |
|
492 | 492 | { |
493 | 493 | case 204: |
494 | 494 | return true; |
@@ -509,8 +509,8 @@ discard block |
||
509 | 509 | */ |
510 | 510 | public function add($vcard, $vcard_id = null) |
511 | 511 | { |
512 | - if ($vcard_id === null) { |
|
513 | - $vcard_id = $this->generateVcardId(); |
|
512 | + if($vcard_id === null) { |
|
513 | + $vcard_id = $this->generateVcardId(); |
|
514 | 514 | } |
515 | 515 | $vcard = $this->cleanVcard($vcard); |
516 | 516 | $result = $this->query($this->url . $vcard_id . $this->url_vcard_extension, 'PUT', $vcard, 'text/vcard'); |
@@ -538,7 +538,7 @@ discard block |
||
538 | 538 | { |
539 | 539 | try { |
540 | 540 | return $this->add($vcard, $vcard_id); |
541 | - } catch (Exception $e) { |
|
541 | + } catch(Exception $e) { |
|
542 | 542 | throw new \Exception($e->getMessage(), self::EXCEPTION_WRONG_HTTP_STATUS_CODE_UPDATE); |
543 | 543 | } |
544 | 544 | } |
@@ -556,7 +556,7 @@ discard block |
||
556 | 556 | |
557 | 557 | try { |
558 | 558 | $xml = new \SimpleXMLElement($response); |
559 | - } catch (Exception $e) { |
|
559 | + } catch(Exception $e) { |
|
560 | 560 | throw new \Exception( |
561 | 561 | "The XML response seems to be malformed and can't be simplified!", |
562 | 562 | self::EXCEPTION_MALFORMED_XML_RESPONSE, |
@@ -571,33 +571,33 @@ discard block |
||
571 | 571 | $simplified_xml->startDocument('1.0', 'utf-8'); |
572 | 572 | $simplified_xml->startElement('response'); |
573 | 573 | |
574 | - if (!empty($xml->response)) { |
|
575 | - foreach ($xml->response as $response) { |
|
576 | - if ((preg_match('/vcard/', $response->propstat->prop->getcontenttype) || preg_match('/vcf/', $response->href)) && |
|
574 | + if(!empty($xml->response)) { |
|
575 | + foreach($xml->response as $response) { |
|
576 | + if((preg_match('/vcard/', $response->propstat->prop->getcontenttype) || preg_match('/vcf/', $response->href)) && |
|
577 | 577 | !$response->propstat->prop->resourcetype->collection) { |
578 | 578 | $id = basename($response->href); |
579 | 579 | $id = str_replace($this->url_vcard_extension, null, $id); |
580 | 580 | |
581 | 581 | try { |
582 | 582 | $vcardData = $this->getVcard($id); |
583 | - if (!empty($id)) { |
|
583 | + if(!empty($id)) { |
|
584 | 584 | $simplified_xml->startElement('element'); |
585 | 585 | $simplified_xml->writeElement('id', $id); |
586 | 586 | $simplified_xml->writeElement('etag', str_replace('"', null, $response->propstat->prop->getetag)); |
587 | 587 | $simplified_xml->writeElement('last_modified', $response->propstat->prop->getlastmodified); |
588 | 588 | |
589 | - if ($include_vcards === true) { |
|
589 | + if($include_vcards === true) { |
|
590 | 590 | $simplified_xml->writeElement('vcard', $vcardData); |
591 | 591 | } |
592 | 592 | $simplified_xml->endElement(); |
593 | 593 | } |
594 | - } catch (\Exception $e) { |
|
594 | + } catch(\Exception $e) { |
|
595 | 595 | print("Error fetching vCard: {$id}: {$e->getMessage()}\n"); |
596 | 596 | } |
597 | - } elseif (preg_match('/unix-directory/', $response->propstat->prop->getcontenttype)) { |
|
598 | - if (isset($response->propstat->prop->href)) { |
|
597 | + } elseif(preg_match('/unix-directory/', $response->propstat->prop->getcontenttype)) { |
|
598 | + if(isset($response->propstat->prop->href)) { |
|
599 | 599 | $href = $response->propstat->prop->href; |
600 | - } elseif (isset($response->href)) { |
|
600 | + } elseif(isset($response->href)) { |
|
601 | 601 | $href = $response->href; |
602 | 602 | } else { |
603 | 603 | $href = null; |
@@ -643,22 +643,22 @@ discard block |
||
643 | 643 | */ |
644 | 644 | public function curlInit() |
645 | 645 | { |
646 | - if (empty($this->curl)) { |
|
646 | + if(empty($this->curl)) { |
|
647 | 647 | $this->curl = curl_init(); |
648 | 648 | curl_setopt($this->curl, CURLOPT_HEADER, true); |
649 | 649 | curl_setopt($this->curl, CURLOPT_SSL_VERIFYHOST, false); |
650 | 650 | curl_setopt($this->curl, CURLOPT_SSL_VERIFYPEER, false); |
651 | 651 | curl_setopt($this->curl, CURLOPT_RETURNTRANSFER, true); |
652 | - curl_setopt($this->curl, CURLOPT_USERAGENT, self::USERAGENT.self::VERSION); |
|
652 | + curl_setopt($this->curl, CURLOPT_USERAGENT, self::USERAGENT . self::VERSION); |
|
653 | 653 | |
654 | - if ($this->auth !== null) { |
|
654 | + if($this->auth !== null) { |
|
655 | 655 | curl_setopt($this->curl, CURLOPT_HTTPAUTH, CURLAUTH_ANY); |
656 | 656 | curl_setopt($this->curl, CURLOPT_USERPWD, $this->auth); |
657 | 657 | } |
658 | 658 | |
659 | 659 | /* allow to follow redirects if activated */ |
660 | 660 | curl_setopt($this->curl, CURLOPT_FOLLOWLOCATION, $this->follow_redirects); |
661 | - if ($this->follow_redirects) |
|
661 | + if($this->follow_redirects) |
|
662 | 662 | { |
663 | 663 | curl_setopt($this->curl, CURLOPT_MAXREDIRS, $this->follow_redirects_count); |
664 | 664 | } |
@@ -681,7 +681,7 @@ discard block |
||
681 | 681 | curl_setopt($this->curl, CURLOPT_URL, $url); |
682 | 682 | curl_setopt($this->curl, CURLOPT_CUSTOMREQUEST, $method); |
683 | 683 | |
684 | - if ($content !== null) { |
|
684 | + if($content !== null) { |
|
685 | 685 | curl_setopt($this->curl, CURLOPT_POST, true); |
686 | 686 | curl_setopt($this->curl, CURLOPT_POSTFIELDS, $content); |
687 | 687 | } else { |
@@ -689,8 +689,8 @@ discard block |
||
689 | 689 | curl_setopt($this->curl, CURLOPT_POSTFIELDS, null); |
690 | 690 | } |
691 | 691 | |
692 | - if ($content_type !== null) { |
|
693 | - curl_setopt($this->curl, CURLOPT_HTTPHEADER, array('Content-type: '.$content_type, 'Depth: 1')); |
|
692 | + if($content_type !== null) { |
|
693 | + curl_setopt($this->curl, CURLOPT_HTTPHEADER, array('Content-type: ' . $content_type, 'Depth: 1')); |
|
694 | 694 | } else { |
695 | 695 | curl_setopt($this->curl, CURLOPT_HTTPHEADER, array('Depth: 1')); |
696 | 696 | } |
@@ -698,7 +698,7 @@ discard block |
||
698 | 698 | $complete_response = curl_exec($this->curl); |
699 | 699 | $header_size = curl_getinfo($this->curl, CURLINFO_HEADER_SIZE); |
700 | 700 | $http_code = curl_getinfo($this->curl, CURLINFO_HTTP_CODE); |
701 | - $header = trim(substr($complete_response, 0, $header_size)); |
|
701 | + $header = trim(substr($complete_response, 0, $header_size)); |
|
702 | 702 | $response = substr($complete_response, $header_size); |
703 | 703 | |
704 | 704 | $return = array( |
@@ -706,7 +706,7 @@ discard block |
||
706 | 706 | 'http_code' => $http_code |
707 | 707 | ); |
708 | 708 | |
709 | - if ($this->debug === true) { |
|
709 | + if($this->debug === true) { |
|
710 | 710 | $debug = $return; |
711 | 711 | $debug['url'] = $url; |
712 | 712 | $debug['method'] = $method; |
@@ -728,8 +728,8 @@ discard block |
||
728 | 728 | { |
729 | 729 | $vcard_id = null; |
730 | 730 | |
731 | - for ($number = 0; $number <= 25; $number ++) { |
|
732 | - if ($number == 8 || $number == 17) { |
|
731 | + for($number = 0; $number <= 25; $number++) { |
|
732 | + if($number == 8 || $number == 17) { |
|
733 | 733 | $vcard_id .= '-'; |
734 | 734 | } else { |
735 | 735 | $vcard_id .= $this->vcard_id_chars[mt_rand(0, (count($this->vcard_id_chars) - 1))]; |
@@ -742,12 +742,12 @@ discard block |
||
742 | 742 | |
743 | 743 | $result = $carddav->query($this->url . $vcard_id . $this->url_vcard_extension, 'GET'); |
744 | 744 | |
745 | - if ($result['http_code'] !== 404) { |
|
745 | + if($result['http_code'] !== 404) { |
|
746 | 746 | $vcard_id = $this->generateVcardId(); |
747 | 747 | } |
748 | 748 | |
749 | 749 | return $vcard_id; |
750 | - } catch (Exception $e) { |
|
750 | + } catch(Exception $e) { |
|
751 | 751 | throw new \Exception($e->getMessage(), self::EXCEPTION_COULD_NOT_GENERATE_NEW_VCARD_ID); |
752 | 752 | } |
753 | 753 | } |
@@ -760,7 +760,7 @@ discard block |
||
760 | 760 | */ |
761 | 761 | public function __destruct() |
762 | 762 | { |
763 | - if (!empty($this->curl)) { |
|
763 | + if(!empty($this->curl)) { |
|
764 | 764 | curl_close($this->curl); |
765 | 765 | } |
766 | 766 | } |
@@ -25,13 +25,13 @@ discard block |
||
25 | 25 | $message = date('Y-m-d H:i') . ' '; |
26 | 26 | |
27 | 27 | // handle the CLI arguments or give a help message |
28 | - if (isset($argv[1]) && ($argv[1] == 0 || $argv[1] == 1) ) |
|
28 | + if(isset($argv[1]) && ($argv[1] == 0 || $argv[1] == 1)) |
|
29 | 29 | { |
30 | 30 | $mode = (int)$argv[1]; |
31 | 31 | } |
32 | 32 | else |
33 | 33 | { |
34 | - if ( $fritz->config->getItem('logging') == 'console' ) |
|
34 | + if($fritz->config->getItem('logging') == 'console') |
|
35 | 35 | { |
36 | 36 | echo ' |
37 | 37 | Enables or disables an answering machine (TAM) of a Fritz!Box |
@@ -78,11 +78,11 @@ discard block |
||
78 | 78 | $output = $fritz->doPostForm($formfields); |
79 | 79 | |
80 | 80 | preg_match('@name="tam:settings/TAM' . $tam . '/Active" value="([10])"@i', $output, $matches); |
81 | - if (isset($matches[1]) && $matches[1] == $mode) |
|
81 | + if(isset($matches[1]) && $matches[1] == $mode) |
|
82 | 82 | { |
83 | 83 | $message .= $mode == 1 ? 'TAM' . $tam . ' enabled' : 'TAM' . $tam . ' disabled'; |
84 | 84 | } |
85 | - else if (isset($matches[1])) |
|
85 | + else if(isset($matches[1])) |
|
86 | 86 | { |
87 | 87 | $message .= 'ERROR: TAM' . $tam . ' status change failed, should be ' . $mode . ', but is ' . $matches[1]; |
88 | 88 | } |
@@ -91,13 +91,13 @@ discard block |
||
91 | 91 | $message .= 'NOTICE: TAM' . $tam . ' status change could have failed, should be ' . $mode . ' now, but I don\'t now if it actually is. Check your check section in the script.'; |
92 | 92 | } |
93 | 93 | } |
94 | -catch (Exception $e) |
|
94 | +catch(Exception $e) |
|
95 | 95 | { |
96 | 96 | $message .= $e->getMessage(); |
97 | 97 | } |
98 | 98 | |
99 | 99 | // log the result |
100 | -if ( isset($fritz) && is_object($fritz) && get_class($fritz) == 'fritzbox_api' ) |
|
100 | +if(isset($fritz) && is_object($fritz) && get_class($fritz) == 'fritzbox_api') |
|
101 | 101 | { |
102 | 102 | $fritz->logMessage($message); |
103 | 103 | } |
@@ -22,13 +22,13 @@ discard block |
||
22 | 22 | $message = date('Y-m-d H:i') . ' '; |
23 | 23 | |
24 | 24 | // handle the CLI arguments or give a help message |
25 | - if (isset($argv[1]) && ($argv[1] == 0 || $argv[1] == 1) ) |
|
25 | + if(isset($argv[1]) && ($argv[1] == 0 || $argv[1] == 1)) |
|
26 | 26 | { |
27 | 27 | $mode = (bool)$argv[1]; |
28 | 28 | } |
29 | 29 | else |
30 | 30 | { |
31 | - if ( $fritz->config->getItem('logging') == 'console' ) |
|
31 | + if($fritz->config->getItem('logging') == 'console') |
|
32 | 32 | { |
33 | 33 | echo ' |
34 | 34 | Enables or disables the WLAN guest access of a Fritz!Box |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | |
64 | 64 | // read down_time_activ setting |
65 | 65 | preg_match('@name="down_time_activ"[^>]+(checked)[^>]*@', $output, $matches); |
66 | - if ( isset($matches[1]) ) |
|
66 | + if(isset($matches[1])) |
|
67 | 67 | { |
68 | 68 | $formfields['down_time_activ'] = 'on'; |
69 | 69 | } |
@@ -72,7 +72,7 @@ discard block |
||
72 | 72 | $formfields['down_time_value'] = isset($matches[1]) ? $matches[1] : '15'; |
73 | 73 | // read disconnect_guest_access setting |
74 | 74 | preg_match('@name="disconnect_guest_access"[^>]+(checked)[^>]*@', $output, $matches); |
75 | - if ( isset($matches[1]) ) |
|
75 | + if(isset($matches[1])) |
|
76 | 76 | { |
77 | 77 | $formfields['disconnect_guest_access'] = 'on'; |
78 | 78 | } |
@@ -90,10 +90,10 @@ discard block |
||
90 | 90 | $formfields['wpa_modus'] = isset($matches[1]) ? $matches[1] : 'x'; |
91 | 91 | |
92 | 92 | // set new given setting |
93 | - if ( $mode == true ) |
|
93 | + if($mode == true) |
|
94 | 94 | { |
95 | 95 | $formfields['activate_guest_access'] = 'on'; |
96 | - if ( $wpa_key !== false ) |
|
96 | + if($wpa_key !== false) |
|
97 | 97 | { |
98 | 98 | $formfields['wpa_key'] = $wpa_key; |
99 | 99 | } |
@@ -104,34 +104,34 @@ discard block |
||
104 | 104 | $output = $fritz->doPostForm($formfields); |
105 | 105 | |
106 | 106 | preg_match('@name="activate_guest_access"[^>]+(checked)[^>]*@', $output, $matches); |
107 | - if ( isset($matches[1]) && $mode == true ) |
|
107 | + if(isset($matches[1]) && $mode == true) |
|
108 | 108 | { |
109 | 109 | preg_match('@name="wpa_key"[^>]+value="([^"]*)"[^>]*@', $output, $matches); |
110 | - if ( isset($matches[1]) ) |
|
110 | + if(isset($matches[1])) |
|
111 | 111 | { |
112 | 112 | $message .= 'WLAN guest access is now active. WPA-Key is "' . $matches[1] . '"'; |
113 | 113 | } |
114 | 114 | } |
115 | - else if ( !isset($matches[1]) && $mode == false ) |
|
115 | + else if(!isset($matches[1]) && $mode == false) |
|
116 | 116 | { |
117 | 117 | $message .= 'WLAN guest access is now inactive.'; |
118 | 118 | } |
119 | - else if ( isset($matches[1]) && $mode == false ) |
|
119 | + else if(isset($matches[1]) && $mode == false) |
|
120 | 120 | { |
121 | 121 | $message .= 'ERROR: WLAN guest access status change failed, should be inactive, but is still active.'; |
122 | 122 | } |
123 | - else if ( !isset($matches[1]) && $mode == true ) |
|
123 | + else if(!isset($matches[1]) && $mode == true) |
|
124 | 124 | { |
125 | 125 | $message .= 'ERROR: WLAN guest access status change failed, should be active, but is still inactive.'; |
126 | 126 | } |
127 | 127 | } |
128 | -catch (Exception $e) |
|
128 | +catch(Exception $e) |
|
129 | 129 | { |
130 | 130 | $message .= $e->getMessage(); |
131 | 131 | } |
132 | 132 | |
133 | 133 | // log the result |
134 | -if ( isset($fritz) && is_object($fritz) && get_class($fritz) == 'fritzbox_api' ) |
|
134 | +if(isset($fritz) && is_object($fritz) && get_class($fritz) == 'fritzbox_api') |
|
135 | 135 | { |
136 | 136 | $fritz->logMessage($message); |
137 | 137 | } |
@@ -23,13 +23,13 @@ discard block |
||
23 | 23 | $message = date('Y-m-d H:i') . ' '; |
24 | 24 | |
25 | 25 | // handle the CLI arguments or give a help message |
26 | - if (isset($argv[1]) && ($argv[1] == 0 || $argv[1] == 1) ) |
|
26 | + if(isset($argv[1]) && ($argv[1] == 0 || $argv[1] == 1)) |
|
27 | 27 | { |
28 | 28 | $mode = (bool)$argv[1]; |
29 | 29 | } |
30 | 30 | else |
31 | 31 | { |
32 | - if ( $fritz->config->getItem('logging') == 'console' ) |
|
32 | + if($fritz->config->getItem('logging') == 'console') |
|
33 | 33 | { |
34 | 34 | echo ' |
35 | 35 | Enables or disables the LAN4 guest access of a Fritz!Box |
@@ -61,7 +61,7 @@ discard block |
||
61 | 61 | |
62 | 62 | // read time_server_activ setting |
63 | 63 | preg_match('@name="time_server_activ"[^>]+(checked)[^>]*@', $output, $matches); |
64 | - if ( isset($matches[1]) ) |
|
64 | + if(isset($matches[1])) |
|
65 | 65 | { |
66 | 66 | $formfields['time_server_activ'] = 'on'; |
67 | 67 | } |
@@ -70,19 +70,19 @@ discard block |
||
70 | 70 | $formfields['time_server'] = isset($matches[1]) ? $matches[1] : '0.europe.pool.ntp.org'; |
71 | 71 | // read other_prefix_allowed setting |
72 | 72 | preg_match('@name="other_prefix_allowed"[^>]+(checked)[^>]*@', $output, $matches); |
73 | - if ( isset($matches[1]) ) |
|
73 | + if(isset($matches[1])) |
|
74 | 74 | { |
75 | 75 | $formfields['other_prefix_allowed'] = 'on'; |
76 | 76 | } |
77 | 77 | // read dnsv6_server_activ setting |
78 | 78 | preg_match('@name="dnsv6_server_activ"[^>]+(checked)[^>]*@', $output, $matches); |
79 | - if ( isset($matches[1]) ) |
|
79 | + if(isset($matches[1])) |
|
80 | 80 | { |
81 | 81 | $formfields['dnsv6_server_activ'] = 'on'; |
82 | 82 | } |
83 | 83 | |
84 | 84 | // set new given setting |
85 | - if ( $mode == true ) |
|
85 | + if($mode == true) |
|
86 | 86 | { |
87 | 87 | $formfields['guest_enabled'] = 'on'; |
88 | 88 | } |
@@ -92,30 +92,30 @@ discard block |
||
92 | 92 | $output = $fritz->doPostForm($formfields); |
93 | 93 | |
94 | 94 | preg_match('@name="guest_enabled"[^>]+(checked)[^>]*@', $output, $matches); |
95 | - if ( isset($matches[1]) && $mode == true ) |
|
95 | + if(isset($matches[1]) && $mode == true) |
|
96 | 96 | { |
97 | 97 | $message .= 'LAN4 guest access is now active.'; |
98 | 98 | } |
99 | - else if ( !isset($matches[1]) && $mode == false ) |
|
99 | + else if(!isset($matches[1]) && $mode == false) |
|
100 | 100 | { |
101 | 101 | $message .= 'LAN4 guest access is now inactive.'; |
102 | 102 | } |
103 | - else if ( isset($matches[1]) && $mode == false ) |
|
103 | + else if(isset($matches[1]) && $mode == false) |
|
104 | 104 | { |
105 | 105 | $message .= 'ERROR: LAN4 guest access status change failed, should be inactive, but is still active.'; |
106 | 106 | } |
107 | - else if ( !isset($matches[1]) && $mode == true ) |
|
107 | + else if(!isset($matches[1]) && $mode == true) |
|
108 | 108 | { |
109 | 109 | $message .= 'ERROR: LAN4 guest access status change failed, should be active, but is still inactive.'; |
110 | 110 | } |
111 | 111 | } |
112 | -catch (Exception $e) |
|
112 | +catch(Exception $e) |
|
113 | 113 | { |
114 | 114 | $message .= $e->getMessage(); |
115 | 115 | } |
116 | 116 | |
117 | 117 | // log the result |
118 | -if ( isset($fritz) && is_object($fritz) && get_class($fritz) == 'fritzbox_api' ) |
|
118 | +if(isset($fritz) && is_object($fritz) && get_class($fritz) == 'fritzbox_api') |
|
119 | 119 | { |
120 | 120 | $fritz->logMessage($message); |
121 | 121 | } |
@@ -1,5 +1,5 @@ |
||
1 | 1 | <?php |
2 | -if ( !isset($this->config) ) |
|
2 | +if(!isset($this->config)) |
|
3 | 3 | { |
4 | 4 | die(__FILE__ . ' must not be called directly'); |
5 | 5 | } |
@@ -38,13 +38,13 @@ |
||
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 | 40 | } |
41 | -catch (Exception $e) |
|
41 | +catch(Exception $e) |
|
42 | 42 | { |
43 | 43 | $message .= $e->getMessage(); |
44 | 44 | } |
45 | 45 | |
46 | 46 | // log the result |
47 | -if ( isset($fritz) && is_object($fritz) && get_class($fritz) == 'fritzbox_api' ) |
|
47 | +if(isset($fritz) && is_object($fritz) && get_class($fritz) == 'fritzbox_api') |
|
48 | 48 | { |
49 | 49 | $fritz->logMessage($message); |
50 | 50 | } |
@@ -63,39 +63,39 @@ discard block |
||
63 | 63 | * |
64 | 64 | * @access public |
65 | 65 | */ |
66 | - public function __construct($password = false,$user_name = false,$fritzbox_ip = 'fritz.box',$force_local_login = false) |
|
66 | + public function __construct($password = false, $user_name = false, $fritzbox_ip = 'fritz.box', $force_local_login = false) |
|
67 | 67 | { |
68 | 68 | // init the config object |
69 | 69 | $this->config = new fritzbox_api_config(); |
70 | 70 | |
71 | 71 | // try autoloading the config |
72 | - if (file_exists(__DIR__ . '/fritzbox_user.conf.php') && is_readable(__DIR__ . '/fritzbox_user.conf.php') ) { |
|
72 | + if(file_exists(__DIR__ . '/fritzbox_user.conf.php') && is_readable(__DIR__ . '/fritzbox_user.conf.php')) { |
|
73 | 73 | require_once(__DIR__ . '/fritzbox_user.conf.php'); |
74 | 74 | } |
75 | 75 | |
76 | 76 | // set FRITZ!Box-IP and URL |
77 | - $this->config->setItem('fritzbox_ip',$fritzbox_ip); |
|
77 | + $this->config->setItem('fritzbox_ip', $fritzbox_ip); |
|
78 | 78 | |
79 | 79 | // check if login on local network (fritz.box) or via a dynamic DNS-host |
80 | - if ($fritzbox_ip != 'fritz.box' && !$force_local_login) { |
|
81 | - $this->config->setItem('enable_remote_config',true); |
|
82 | - $this->config->setItem('remote_config_user',$user_name); |
|
83 | - $this->config->setItem('remote_config_password',$password); |
|
84 | - $this->config->setItem('fritzbox_url', 'https://'.$this->config->getItem('fritzbox_ip')); |
|
80 | + if($fritzbox_ip != 'fritz.box' && !$force_local_login) { |
|
81 | + $this->config->setItem('enable_remote_config', true); |
|
82 | + $this->config->setItem('remote_config_user', $user_name); |
|
83 | + $this->config->setItem('remote_config_password', $password); |
|
84 | + $this->config->setItem('fritzbox_url', 'https://' . $this->config->getItem('fritzbox_ip')); |
|
85 | 85 | } else { |
86 | - $this->config->setItem('enable_remote_config',false); |
|
87 | - if($user_name != false){ |
|
88 | - $this->config->setItem('username',$user_name); |
|
86 | + $this->config->setItem('enable_remote_config', false); |
|
87 | + if($user_name != false) { |
|
88 | + $this->config->setItem('username', $user_name); |
|
89 | 89 | } |
90 | - if($password != false){ |
|
91 | - $this->config->setItem('password',$password); |
|
90 | + if($password != false) { |
|
91 | + $this->config->setItem('password', $password); |
|
92 | 92 | } |
93 | 93 | $this->config->setItem('fritzbox_url', 'http://' . $this->config->getItem('fritzbox_ip')); |
94 | 94 | } |
95 | 95 | |
96 | 96 | // make some config consistency checks |
97 | - if ( $this->config->getItem('enable_remote_config') === true ){ |
|
98 | - if ( !$this->config->getItem('remote_config_user') || !$this->config->getItem('remote_config_password') ){ |
|
97 | + if($this->config->getItem('enable_remote_config') === true) { |
|
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 | 101 | } |
@@ -129,7 +129,7 @@ discard block |
||
129 | 129 | { |
130 | 130 | $ch = curl_init(); |
131 | 131 | |
132 | - if ( isset($formfields['getpage']) && strpos($formfields['getpage'], '.lua') > 0 ) |
|
132 | + if(isset($formfields['getpage']) && strpos($formfields['getpage'], '.lua') > 0) |
|
133 | 133 | { |
134 | 134 | curl_setopt($ch, CURLOPT_URL, $this->config->getItem('fritzbox_url') . $formfields['getpage'] . '?sid=' . $this->sid); |
135 | 135 | unset($formfields['getpage']); |
@@ -137,7 +137,7 @@ discard block |
||
137 | 137 | else |
138 | 138 | { |
139 | 139 | // add the sid, if it is already set |
140 | - if ($this->sid != '0000000000000000') |
|
140 | + if($this->sid != '0000000000000000') |
|
141 | 141 | { |
142 | 142 | $formfields['sid'] = $this->sid; |
143 | 143 | } |
@@ -145,10 +145,10 @@ discard block |
||
145 | 145 | } |
146 | 146 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); |
147 | 147 | curl_setopt($ch, CURLOPT_POST, 1); |
148 | - if ( $this->config->getItem('enable_remote_config') == true ) |
|
148 | + if($this->config->getItem('enable_remote_config') == true) |
|
149 | 149 | { |
150 | 150 | // set name of SSL-certificate (must be same as remote-hostname (dynDNS) of FRITZ!Box) and remove port in address if alternate port is given |
151 | - if (strpos($this->config->getItem('fritzbox_ip'),":")){ |
|
151 | + if(strpos($this->config->getItem('fritzbox_ip'), ":")) { |
|
152 | 152 | $ssl_cert_fritzbox = explode(":", $this->config->getItem('fritzbox_ip')); |
153 | 153 | $ssl_cert_fritzbox = $ssl_cert_fritzbox[0]; |
154 | 154 | } else { |
@@ -158,11 +158,11 @@ discard block |
||
158 | 158 | // set SSL-options and path to certificate |
159 | 159 | curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 2); |
160 | 160 | curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); |
161 | - curl_setopt($ch, CURLOPT_CAINFO, '/etc/ssl/certs/'.$ssl_cert_fritzbox.'.pem'); |
|
161 | + curl_setopt($ch, CURLOPT_CAINFO, '/etc/ssl/certs/' . $ssl_cert_fritzbox . '.pem'); |
|
162 | 162 | curl_setopt($ch, CURLOPT_CAPATH, '/etc/ssl/certs'); |
163 | 163 | |
164 | 164 | // support for pre FRITZ!OS 5.50 remote config |
165 | - if (!$this->config->getItem('use_lua_login_method')){ |
|
165 | + if(!$this->config->getItem('use_lua_login_method')) { |
|
166 | 166 | curl_setopt($ch, CURLOPT_USERPWD, $this->config->getItem('remote_config_user') . ':' . $this->config->getItem('remote_config_password')); |
167 | 167 | } |
168 | 168 | } |
@@ -177,7 +177,7 @@ discard block |
||
177 | 177 | $ch = curl_init(); |
178 | 178 | |
179 | 179 | // add the sid, if it is already set |
180 | - if ($this->sid != '0000000000000000') |
|
180 | + if($this->sid != '0000000000000000') |
|
181 | 181 | { |
182 | 182 | // 'sid' MUST be the first POST variable!!! (otherwise it will not work!!) |
183 | 183 | // therfore we use array_merge to ensuere the foreach outputs 'sid' fist |
@@ -192,13 +192,13 @@ discard block |
||
192 | 192 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); |
193 | 193 | |
194 | 194 | // if filefileds not specified ('@/path/to/file.xml;type=text/xml' works fine) |
195 | - if(empty( $filefileds )) { |
|
195 | + if(empty($filefileds)) { |
|
196 | 196 | curl_setopt($ch, CURLOPT_POSTFIELDS, $formfields); // http_build_query |
197 | 197 | } |
198 | 198 | // post calculated raw data |
199 | 199 | else { |
200 | 200 | $header = $this->_create_custom_file_post_header($formfields, $filefileds); |
201 | - curl_setopt($ch, CURLOPT_HTTPHEADER , array( |
|
201 | + curl_setopt($ch, CURLOPT_HTTPHEADER, array( |
|
202 | 202 | 'Content-Type: multipart/form-data; boundary=' . $header['delimiter'], 'Content-Length: ' . strlen($header['data']) ) |
203 | 203 | ); |
204 | 204 | |
@@ -209,12 +209,12 @@ discard block |
||
209 | 209 | |
210 | 210 | // curl error |
211 | 211 | if(curl_errno($ch)) { |
212 | - $this->error(curl_error($ch)." (".curl_errno($ch).")"); |
|
212 | + $this->error(curl_error($ch) . " (" . curl_errno($ch) . ")"); |
|
213 | 213 | } |
214 | 214 | |
215 | 215 | // finger out an error message, if given |
216 | 216 | preg_match('@<p class="ErrorMsg">(.*?)</p>@is', $output, $matches); |
217 | - if (isset($matches[1])) |
|
217 | + if(isset($matches[1])) |
|
218 | 218 | { |
219 | 219 | $this->error(str_replace(' ', ' ', $matches[1])); |
220 | 220 | } |
@@ -245,7 +245,7 @@ discard block |
||
245 | 245 | $data = ''; |
246 | 246 | |
247 | 247 | // populate normal fields first (simpler) |
248 | - foreach ($postFields as $name => $content) { |
|
248 | + foreach($postFields as $name => $content) { |
|
249 | 249 | $data .= "--" . $delimiter . "\r\n"; |
250 | 250 | $data .= 'Content-Disposition: form-data; name="' . urlencode($name) . '"'; |
251 | 251 | $data .= "\r\n\r\n"; |
@@ -253,7 +253,7 @@ discard block |
||
253 | 253 | $data .= "\r\n"; |
254 | 254 | } |
255 | 255 | // populate file fields |
256 | - foreach ($fileFields as $name => $file) { |
|
256 | + foreach($fileFields as $name => $file) { |
|
257 | 257 | $data .= "--" . $delimiter . "\r\n"; |
258 | 258 | // "filename" attribute is not essential; server-side scripts may use it |
259 | 259 | $data .= 'Content-Disposition: form-data; name="' . urlencode($name) . '";' . |
@@ -283,13 +283,13 @@ discard block |
||
283 | 283 | public function doGetRequest($params = array()) |
284 | 284 | { |
285 | 285 | // add the sid, if it is already set |
286 | - if ($this->sid != '0000000000000000') |
|
286 | + if($this->sid != '0000000000000000') |
|
287 | 287 | { |
288 | 288 | $params['sid'] = $this->sid; |
289 | 289 | } |
290 | 290 | |
291 | 291 | $ch = curl_init(); |
292 | - if ( strpos($params['getpage'], '.lua') > 0 ) |
|
292 | + if(strpos($params['getpage'], '.lua') > 0) |
|
293 | 293 | { |
294 | 294 | $getpage = $params['getpage'] . '?'; |
295 | 295 | unset($params['getpage']); |
@@ -301,13 +301,13 @@ discard block |
||
301 | 301 | curl_setopt($ch, CURLOPT_URL, $this->config->getItem('fritzbox_url') . $getpage . http_build_query($params)); |
302 | 302 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); |
303 | 303 | curl_setopt($ch, CURLOPT_HTTPGET, 1); |
304 | - if ( $this->config->getItem('enable_remote_config') ) |
|
304 | + if($this->config->getItem('enable_remote_config')) |
|
305 | 305 | { |
306 | 306 | curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); |
307 | 307 | curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); |
308 | 308 | |
309 | 309 | // support for pre FRITZ!OS 5.50 remote config |
310 | - if ( !$this->config->getItem('use_lua_login_method') ) |
|
310 | + if(!$this->config->getItem('use_lua_login_method')) |
|
311 | 311 | { |
312 | 312 | curl_setopt($ch, CURLOPT_USERPWD, $this->config->getItem('remote_config_user') . ':' . $this->config->getItem('remote_config_password')); |
313 | 313 | } |
@@ -328,7 +328,7 @@ discard block |
||
328 | 328 | protected function initSID() |
329 | 329 | { |
330 | 330 | // determine, wich login type we have to use |
331 | - if ( $this->config->getItem('use_lua_login_method') == true ) |
|
331 | + if($this->config->getItem('use_lua_login_method') == true) |
|
332 | 332 | { |
333 | 333 | $loginpage = '/login_sid.lua'; |
334 | 334 | } |
@@ -340,13 +340,13 @@ discard block |
||
340 | 340 | // read the current status |
341 | 341 | $session_status_simplexml = simplexml_load_string($this->doGetRequest(array('getpage' => $loginpage))); |
342 | 342 | |
343 | - if ( !is_object($session_status_simplexml) || get_class($session_status_simplexml) != 'SimpleXMLElement' ) |
|
343 | + if(!is_object($session_status_simplexml) || get_class($session_status_simplexml) != 'SimpleXMLElement') |
|
344 | 344 | { |
345 | 345 | $this->error('Response of initialization call ' . $loginpage . ' in ' . __FUNCTION__ . ' was not xml-formatted.'); |
346 | 346 | } |
347 | 347 | |
348 | 348 | // perhaps we already have a SID (i.e. when no password is set) |
349 | - if ( $session_status_simplexml->SID != '0000000000000000' ) |
|
349 | + if($session_status_simplexml->SID != '0000000000000000') |
|
350 | 350 | { |
351 | 351 | return $session_status_simplexml->SID; |
352 | 352 | } |
@@ -360,16 +360,16 @@ discard block |
||
360 | 360 | $formfields = array( |
361 | 361 | 'getpage' => $loginpage, |
362 | 362 | ); |
363 | - if ( $this->config->getItem('use_lua_login_method') ) |
|
363 | + if($this->config->getItem('use_lua_login_method')) |
|
364 | 364 | { |
365 | - if ( $this->config->getItem('enable_remote_config') ) |
|
365 | + if($this->config->getItem('enable_remote_config')) |
|
366 | 366 | { |
367 | 367 | $formfields['username'] = $this->config->getItem('remote_config_user'); |
368 | 368 | $response = $challenge . '-' . md5(mb_convert_encoding($challenge . '-' . $this->config->getItem('remote_config_password'), "UCS-2LE", "UTF-8")); |
369 | 369 | } |
370 | 370 | else |
371 | 371 | { |
372 | - if ( $this->config->getItem('username') ) |
|
372 | + if($this->config->getItem('username')) |
|
373 | 373 | { |
374 | 374 | $formfields['username'] = $this->config->getItem('username'); |
375 | 375 | } |
@@ -386,12 +386,12 @@ discard block |
||
386 | 386 | |
387 | 387 | // finger out the SID from the response |
388 | 388 | $session_status_simplexml = simplexml_load_string($output); |
389 | - if ( !is_object($session_status_simplexml) || get_class($session_status_simplexml) != 'SimpleXMLElement' ) |
|
389 | + if(!is_object($session_status_simplexml) || get_class($session_status_simplexml) != 'SimpleXMLElement') |
|
390 | 390 | { |
391 | 391 | $this->error('Response of login call to ' . $loginpage . ' in ' . __FUNCTION__ . ' was not xml-formatted.'); |
392 | 392 | } |
393 | 393 | |
394 | - if ( $session_status_simplexml->SID != '0000000000000000' ) |
|
394 | + if($session_status_simplexml->SID != '0000000000000000') |
|
395 | 395 | { |
396 | 396 | return (string)$session_status_simplexml->SID; |
397 | 397 | } |
@@ -409,7 +409,7 @@ discard block |
||
409 | 409 | */ |
410 | 410 | protected function logout() |
411 | 411 | { |
412 | - if ( $this->config->getItem('use_lua_login_method') == true ) |
|
412 | + if($this->config->getItem('use_lua_login_method') == true) |
|
413 | 413 | { |
414 | 414 | $this->doGetRequest(array('getpage' => '/home/home.lua', 'logout' => '1')); |
415 | 415 | } |
@@ -452,22 +452,22 @@ discard block |
||
452 | 452 | */ |
453 | 453 | public function logMessage($message) |
454 | 454 | { |
455 | - if ( $this->config->getItem('newline') == false ) |
|
455 | + if($this->config->getItem('newline') == false) |
|
456 | 456 | { |
457 | 457 | $this->config->setItem('newline', (PHP_OS == 'WINNT') ? "\r\n" : "\n"); |
458 | 458 | } |
459 | 459 | |
460 | - if ( $this->config->getItem('logging') == 'console' ) |
|
460 | + if($this->config->getItem('logging') == 'console') |
|
461 | 461 | { |
462 | 462 | echo $message; |
463 | 463 | } |
464 | - else if ( $this->config->getItem('logging') == 'silent' || $this->config->getItem('logging') == false ) |
|
464 | + else if($this->config->getItem('logging') == 'silent' || $this->config->getItem('logging') == false) |
|
465 | 465 | { |
466 | 466 | // do nothing |
467 | 467 | } |
468 | 468 | else |
469 | 469 | { |
470 | - if ( is_writable($this->config->getItem('logging')) || is_writable(dirname($this->config->getItem('logging'))) ) |
|
470 | + if(is_writable($this->config->getItem('logging')) || is_writable(dirname($this->config->getItem('logging')))) |
|
471 | 471 | { |
472 | 472 | file_put_contents($this->config->getItem('logging'), $message . $this->config->getItem('newline'), FILE_APPEND); |
473 | 473 | } |
@@ -517,11 +517,11 @@ discard block |
||
517 | 517 | */ |
518 | 518 | public function getItem($item = 'all') |
519 | 519 | { |
520 | - if ( $item == 'all' ) |
|
520 | + if($item == 'all') |
|
521 | 521 | { |
522 | 522 | return $this->config; |
523 | 523 | } |
524 | - elseif ( isset($this->config[$item]) ) |
|
524 | + elseif(isset($this->config[$item])) |
|
525 | 525 | { |
526 | 526 | return $this->config[$item]; |
527 | 527 | } |
@@ -23,11 +23,11 @@ discard block |
||
23 | 23 | // init the output message |
24 | 24 | $message = date('Y-m-d H:i') . ' '; |
25 | 25 | |
26 | - if ( !$fritz->config->getItem('foncallslist_path') ) |
|
26 | + if(!$fritz->config->getItem('foncallslist_path')) |
|
27 | 27 | { |
28 | 28 | throw new Exception('Mandatory config Item foncallslist_path not set.'); |
29 | 29 | } |
30 | - if ( ( file_exists($fritz->config->getItem('foncallslist_path')) && !is_writable($fritz->config->getItem('foncallslist_path')) ) || ( !file_exists($fritz->config->getItem('foncallslist_path')) && !is_writable(dirname($fritz->config->getItem('foncallslist_path'))) ) ) |
|
30 | + if((file_exists($fritz->config->getItem('foncallslist_path')) && !is_writable($fritz->config->getItem('foncallslist_path'))) || (!file_exists($fritz->config->getItem('foncallslist_path')) && !is_writable(dirname($fritz->config->getItem('foncallslist_path'))))) |
|
31 | 31 | { |
32 | 32 | throw new Exception('Config item foncallslist_path (' . $fritz->config->getItem('foncallslist_path') . ') is not writeable.'); |
33 | 33 | } |
@@ -54,13 +54,13 @@ discard block |
||
54 | 54 | // set a log message |
55 | 55 | $message .= 'Call list sucessfully downloaded'; |
56 | 56 | } |
57 | -catch (Exception $e) |
|
57 | +catch(Exception $e) |
|
58 | 58 | { |
59 | 59 | $message .= $e->getMessage(); |
60 | 60 | } |
61 | 61 | |
62 | 62 | // log the result |
63 | -if ( isset($fritz) && is_object($fritz) && get_class($fritz) == 'fritzbox_api' ) |
|
63 | +if(isset($fritz) && is_object($fritz) && get_class($fritz) == 'fritzbox_api') |
|
64 | 64 | { |
65 | 65 | $fritz->logMessage($message); |
66 | 66 | } |