@@ -532,7 +532,7 @@ discard block |
||
| 532 | 532 | * |
| 533 | 533 | * @param string $vcard vCard |
| 534 | 534 | * @param string $vcard_id vCard id on the CardDAV server |
| 535 | - * @return boolean |
|
| 535 | + * @return string |
|
| 536 | 536 | */ |
| 537 | 537 | public function update($vcard, $vcard_id) |
| 538 | 538 | { |
@@ -672,7 +672,7 @@ discard block |
||
| 672 | 672 | * @param string $method HTTP method like (OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, COPY, MOVE) |
| 673 | 673 | * @param string $content Content for CardDAV queries |
| 674 | 674 | * @param string $content_type Set content type |
| 675 | - * @return array Raw CardDAV Response and http status code |
|
| 675 | + * @return boolean Raw CardDAV Response and http status code |
|
| 676 | 676 | */ |
| 677 | 677 | private function query($url, $method, $content = null, $content_type = null) |
| 678 | 678 | { |
@@ -143,17 +143,17 @@ discard block |
||
| 143 | 143 | private $auth = null; |
| 144 | 144 | |
| 145 | 145 | /** |
| 146 | - * Authentication: username |
|
| 147 | - * |
|
| 148 | - * @var string |
|
| 149 | - */ |
|
| 146 | + * Authentication: username |
|
| 147 | + * |
|
| 148 | + * @var string |
|
| 149 | + */ |
|
| 150 | 150 | private $username = null; |
| 151 | 151 | |
| 152 | 152 | /** |
| 153 | - * Authentication: password |
|
| 154 | - * |
|
| 155 | - * @var string |
|
| 156 | - */ |
|
| 153 | + * Authentication: password |
|
| 154 | + * |
|
| 155 | + * @var string |
|
| 156 | + */ |
|
| 157 | 157 | private $password = null; |
| 158 | 158 | |
| 159 | 159 | /** |
@@ -236,11 +236,11 @@ discard block |
||
| 236 | 236 | } |
| 237 | 237 | |
| 238 | 238 | /** |
| 239 | - * Sets the CardDAV server url |
|
| 240 | - * |
|
| 241 | - * @param string $url CardDAV server url |
|
| 242 | - * @return void |
|
| 243 | - */ |
|
| 239 | + * Sets the CardDAV server url |
|
| 240 | + * |
|
| 241 | + * @param string $url CardDAV server url |
|
| 242 | + * @return void |
|
| 243 | + */ |
|
| 244 | 244 | public function setUrl($url) |
| 245 | 245 | { |
| 246 | 246 | $this->url = $url; |
@@ -354,11 +354,11 @@ discard block |
||
| 354 | 354 | } |
| 355 | 355 | |
| 356 | 356 | /** |
| 357 | - * Gets a clean vCard from the CardDAV server |
|
| 358 | - * |
|
| 359 | - * @param string $vcard_id vCard id on the CardDAV server |
|
| 360 | - * @return string vCard (text/vcard) |
|
| 361 | - */ |
|
| 357 | + * Gets a clean vCard from the CardDAV server |
|
| 358 | + * |
|
| 359 | + * @param string $vcard_id vCard id on the CardDAV server |
|
| 360 | + * @return string vCard (text/vcard) |
|
| 361 | + */ |
|
| 362 | 362 | public function getVcard($vcard_id) |
| 363 | 363 | { |
| 364 | 364 | $vcard_id = str_replace($this->url_vcard_extension, null, $vcard_id); |
@@ -367,29 +367,29 @@ 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 | - case 404: |
|
| 373 | - $altResult = $this->query($this->url . $vcard_id , 'GET'); |
|
| 374 | - // DEBUG: print the response of the carddav-server |
|
| 375 | - // print_r($altResult); |
|
| 376 | - switch ($altResult['http_code']) |
|
| 377 | - { |
|
| 378 | - case 200: |
|
| 379 | - case 207: |
|
| 380 | - print "Ignoring given Vcard Extension (".$this->url_vcard_extension.")" . PHP_EOL. "."; |
|
| 381 | - $this->setVcardExtension(""); |
|
| 382 | - return $altResult['response']; |
|
| 383 | - } |
|
| 384 | - throw new \Exception( |
|
| 385 | - "Woops, something's gone wrong! The CardDAV server returned the http status code {$result['http_code']}:{$result['response']}:{$vcard_id}.", |
|
| 386 | - self::EXCEPTION_WRONG_HTTP_STATUS_CODE_GET_VCARD |
|
| 387 | - ); |
|
| 388 | - |
|
| 389 | - case 200: |
|
| 390 | - case 207: |
|
| 391 | - print "."; |
|
| 392 | - return $result['response']; |
|
| 372 | + case 404: |
|
| 373 | + $altResult = $this->query($this->url . $vcard_id , 'GET'); |
|
| 374 | + // DEBUG: print the response of the carddav-server |
|
| 375 | + // print_r($altResult); |
|
| 376 | + switch ($altResult['http_code']) |
|
| 377 | + { |
|
| 378 | + case 200: |
|
| 379 | + case 207: |
|
| 380 | + print "Ignoring given Vcard Extension (".$this->url_vcard_extension.")" . PHP_EOL. "."; |
|
| 381 | + $this->setVcardExtension(""); |
|
| 382 | + return $altResult['response']; |
|
| 383 | + } |
|
| 384 | + throw new \Exception( |
|
| 385 | + "Woops, something's gone wrong! The CardDAV server returned the http status code {$result['http_code']}:{$result['response']}:{$vcard_id}.", |
|
| 386 | + self::EXCEPTION_WRONG_HTTP_STATUS_CODE_GET_VCARD |
|
| 387 | + ); |
|
| 388 | + |
|
| 389 | + case 200: |
|
| 390 | + case 207: |
|
| 391 | + print "."; |
|
| 392 | + return $result['response']; |
|
| 393 | 393 | } |
| 394 | 394 | |
| 395 | 395 | throw new \Exception( |
@@ -450,10 +450,10 @@ discard block |
||
| 450 | 450 | } |
| 451 | 451 | |
| 452 | 452 | /** |
| 453 | - * Checks if the CardDAV server is reachable |
|
| 454 | - * |
|
| 455 | - * @return boolean |
|
| 456 | - */ |
|
| 453 | + * Checks if the CardDAV server is reachable |
|
| 454 | + * |
|
| 455 | + * @return boolean |
|
| 456 | + */ |
|
| 457 | 457 | public function checkConnection() |
| 458 | 458 | { |
| 459 | 459 | $result = $this->query($this->url, 'OPTIONS'); |
@@ -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 | /** |
@@ -370,14 +370,14 @@ discard block |
||
| 370 | 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 | 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 | } |
@@ -510,12 +510,12 @@ discard block |
||
| 510 | 510 | public function add($vcard, $vcard_id = null) |
| 511 | 511 | { |
| 512 | 512 | if ($vcard_id === null) { |
| 513 | - $vcard_id = $this->generateVcardId(); |
|
| 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'); |
| 517 | 517 | |
| 518 | - switch($result['http_code']) |
|
| 518 | + switch ($result['http_code']) |
|
| 519 | 519 | { |
| 520 | 520 | case 201: |
| 521 | 521 | return $vcard_id; |
@@ -649,7 +649,7 @@ discard block |
||
| 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 | 654 | if ($this->auth !== null) { |
| 655 | 655 | curl_setopt($this->curl, CURLOPT_HTTPAUTH, CURLAUTH_ANY); |
@@ -690,7 +690,7 @@ discard block |
||
| 690 | 690 | } |
| 691 | 691 | |
| 692 | 692 | if ($content_type !== null) { |
| 693 | - curl_setopt($this->curl, CURLOPT_HTTPHEADER, array('Content-type: '.$content_type, 'Depth: 1')); |
|
| 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( |
@@ -728,7 +728,7 @@ discard block |
||
| 728 | 728 | { |
| 729 | 729 | $vcard_id = null; |
| 730 | 730 | |
| 731 | - for ($number = 0; $number <= 25; $number ++) { |
|
| 731 | + for ($number = 0; $number <= 25; $number++) { |
|
| 732 | 732 | if ($number == 8 || $number == 17) { |
| 733 | 733 | $vcard_id .= '-'; |
| 734 | 734 | } else { |
@@ -533,6 +533,10 @@ |
||
| 533 | 533 | * @param $item string the item to set |
| 534 | 534 | * @param $value mixed the value to store into the item |
| 535 | 535 | */ |
| 536 | + |
|
| 537 | + /** |
|
| 538 | + * @param string $item |
|
| 539 | + */ |
|
| 536 | 540 | public function setItem($item, $value) |
| 537 | 541 | { |
| 538 | 542 | $this->config[$item] = $value; |
@@ -48,70 +48,70 @@ discard block |
||
| 48 | 48 | */ |
| 49 | 49 | class fritzbox_api { |
| 50 | 50 | /** |
| 51 | - * @var object config object |
|
| 52 | - */ |
|
| 51 | + * @var object config object |
|
| 52 | + */ |
|
| 53 | 53 | public $config = array(); |
| 54 | 54 | |
| 55 | 55 | /** |
| 56 | - * @var string the session ID, set by method initSID() after login |
|
| 57 | - */ |
|
| 56 | + * @var string the session ID, set by method initSID() after login |
|
| 57 | + */ |
|
| 58 | 58 | protected $sid = '0000000000000000'; |
| 59 | 59 | |
| 60 | 60 | |
| 61 | 61 | /** |
| 62 | - * the constructor, initializes the object and calls the login method |
|
| 63 | - * |
|
| 64 | - * @access public |
|
| 65 | - */ |
|
| 62 | + * the constructor, initializes the object and calls the login method |
|
| 63 | + * |
|
| 64 | + * @access public |
|
| 65 | + */ |
|
| 66 | 66 | public function __construct($password = false,$user_name = false,$fritzbox_ip = 'fritz.box',$force_local_login = false) |
| 67 | 67 | { |
| 68 | - // init the config object |
|
| 69 | - $this->config = new fritzbox_api_config(); |
|
| 68 | + // init the config object |
|
| 69 | + $this->config = new fritzbox_api_config(); |
|
| 70 | 70 | |
| 71 | - // try autoloading the config |
|
| 72 | - if (file_exists(__DIR__ . '/fritzbox_user.conf.php') && is_readable(__DIR__ . '/fritzbox_user.conf.php') ) { |
|
| 73 | - require_once(__DIR__ . '/fritzbox_user.conf.php'); |
|
| 74 | - } |
|
| 71 | + // try autoloading the config |
|
| 72 | + if (file_exists(__DIR__ . '/fritzbox_user.conf.php') && is_readable(__DIR__ . '/fritzbox_user.conf.php') ) { |
|
| 73 | + require_once(__DIR__ . '/fritzbox_user.conf.php'); |
|
| 74 | + } |
|
| 75 | 75 | |
| 76 | - // set FRITZ!Box-IP and URL |
|
| 77 | - $this->config->setItem('fritzbox_ip',$fritzbox_ip); |
|
| 76 | + // set FRITZ!Box-IP and URL |
|
| 77 | + $this->config->setItem('fritzbox_ip',$fritzbox_ip); |
|
| 78 | 78 | |
| 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')); |
|
| 85 | - } else { |
|
| 86 | - $this->config->setItem('enable_remote_config',false); |
|
| 87 | - if($user_name != false){ |
|
| 88 | - $this->config->setItem('username',$user_name); |
|
| 89 | - } |
|
| 90 | - if($password != false){ |
|
| 91 | - $this->config->setItem('password',$password); |
|
| 92 | - } |
|
| 93 | - $this->config->setItem('fritzbox_url', 'http://' . $this->config->getItem('fritzbox_ip')); |
|
| 94 | - } |
|
| 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')); |
|
| 85 | + } else { |
|
| 86 | + $this->config->setItem('enable_remote_config',false); |
|
| 87 | + if($user_name != false){ |
|
| 88 | + $this->config->setItem('username',$user_name); |
|
| 89 | + } |
|
| 90 | + if($password != false){ |
|
| 91 | + $this->config->setItem('password',$password); |
|
| 92 | + } |
|
| 93 | + $this->config->setItem('fritzbox_url', 'http://' . $this->config->getItem('fritzbox_ip')); |
|
| 94 | + } |
|
| 95 | 95 | |
| 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') ){ |
|
| 99 | - $this->error('ERROR: Remote config mode enabled, but no username or no password provided'); |
|
| 100 | - } |
|
| 101 | - } |
|
| 102 | - else { |
|
| 103 | - $this->config->setItem('old_remote_config_user', null); |
|
| 104 | - $this->config->setItem('old_remote_config_password', null); |
|
| 105 | - } |
|
| 106 | - $this->sid = $this->initSID(); |
|
| 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') ){ |
|
| 99 | + $this->error('ERROR: Remote config mode enabled, but no username or no password provided'); |
|
| 100 | + } |
|
| 101 | + } |
|
| 102 | + else { |
|
| 103 | + $this->config->setItem('old_remote_config_user', null); |
|
| 104 | + $this->config->setItem('old_remote_config_password', null); |
|
| 105 | + } |
|
| 106 | + $this->sid = $this->initSID(); |
|
| 107 | 107 | } |
| 108 | 108 | |
| 109 | 109 | |
| 110 | 110 | /** |
| 111 | - * the destructor just calls the logout method |
|
| 112 | - * |
|
| 113 | - * @access public |
|
| 114 | - */ |
|
| 111 | + * the destructor just calls the logout method |
|
| 112 | + * |
|
| 113 | + * @access public |
|
| 114 | + */ |
|
| 115 | 115 | public function __destruct() |
| 116 | 116 | { |
| 117 | 117 | $this->logout(); |
@@ -119,12 +119,12 @@ discard block |
||
| 119 | 119 | |
| 120 | 120 | |
| 121 | 121 | /** |
| 122 | - * do a POST request on the box |
|
| 123 | - * the main cURL wrapper handles the command |
|
| 124 | - * |
|
| 125 | - * @param array $formfields an associative array with the POST fields to pass |
|
| 126 | - * @return string the raw HTML code returned by the Fritz!Box |
|
| 127 | - */ |
|
| 122 | + * do a POST request on the box |
|
| 123 | + * the main cURL wrapper handles the command |
|
| 124 | + * |
|
| 125 | + * @param array $formfields an associative array with the POST fields to pass |
|
| 126 | + * @return string the raw HTML code returned by the Fritz!Box |
|
| 127 | + */ |
|
| 128 | 128 | public function doPostForm($formfields = array()) |
| 129 | 129 | { |
| 130 | 130 | $ch = curl_init(); |
@@ -147,24 +147,24 @@ discard block |
||
| 147 | 147 | curl_setopt($ch, CURLOPT_POST, 1); |
| 148 | 148 | if ( $this->config->getItem('enable_remote_config') == true ) |
| 149 | 149 | { |
| 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'),":")){ |
|
| 152 | - $ssl_cert_fritzbox = explode(":", $this->config->getItem('fritzbox_ip')); |
|
| 153 | - $ssl_cert_fritzbox = $ssl_cert_fritzbox[0]; |
|
| 154 | - } else { |
|
| 155 | - $ssl_cert_fritzbox = $this->config->getItem('fritzbox_ip'); |
|
| 156 | - } |
|
| 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'),":")){ |
|
| 152 | + $ssl_cert_fritzbox = explode(":", $this->config->getItem('fritzbox_ip')); |
|
| 153 | + $ssl_cert_fritzbox = $ssl_cert_fritzbox[0]; |
|
| 154 | + } else { |
|
| 155 | + $ssl_cert_fritzbox = $this->config->getItem('fritzbox_ip'); |
|
| 156 | + } |
|
| 157 | 157 | |
| 158 | - // set SSL-options and path to certificate |
|
| 159 | - curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 2); |
|
| 160 | - curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); |
|
| 161 | - curl_setopt($ch, CURLOPT_CAINFO, '/etc/ssl/certs/'.$ssl_cert_fritzbox.'.pem'); |
|
| 162 | - curl_setopt($ch, CURLOPT_CAPATH, '/etc/ssl/certs'); |
|
| 158 | + // set SSL-options and path to certificate |
|
| 159 | + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 2); |
|
| 160 | + curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); |
|
| 161 | + curl_setopt($ch, CURLOPT_CAINFO, '/etc/ssl/certs/'.$ssl_cert_fritzbox.'.pem'); |
|
| 162 | + curl_setopt($ch, CURLOPT_CAPATH, '/etc/ssl/certs'); |
|
| 163 | 163 | |
| 164 | - // support for pre FRITZ!OS 5.50 remote config |
|
| 165 | - if (!$this->config->getItem('use_lua_login_method')){ |
|
| 166 | - curl_setopt($ch, CURLOPT_USERPWD, $this->config->getItem('remote_config_user') . ':' . $this->config->getItem('remote_config_password')); |
|
| 167 | - } |
|
| 164 | + // support for pre FRITZ!OS 5.50 remote config |
|
| 165 | + if (!$this->config->getItem('use_lua_login_method')){ |
|
| 166 | + curl_setopt($ch, CURLOPT_USERPWD, $this->config->getItem('remote_config_user') . ':' . $this->config->getItem('remote_config_password')); |
|
| 167 | + } |
|
| 168 | 168 | } |
| 169 | 169 | curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($formfields)); |
| 170 | 170 | $output = curl_exec($ch); |
@@ -179,10 +179,10 @@ discard block |
||
| 179 | 179 | // add the sid, if it is already set |
| 180 | 180 | if ($this->sid != '0000000000000000') |
| 181 | 181 | { |
| 182 | - // 'sid' MUST be the first POST variable!!! (otherwise it will not work!!) |
|
| 183 | - // therfore we use array_merge to ensuere the foreach outputs 'sid' fist |
|
| 184 | - $formfields = array_merge(array('sid' => $this->sid), $formfields); |
|
| 185 | - //$formfields['sid'] = $this->sid; |
|
| 182 | + // 'sid' MUST be the first POST variable!!! (otherwise it will not work!!) |
|
| 183 | + // therfore we use array_merge to ensuere the foreach outputs 'sid' fist |
|
| 184 | + $formfields = array_merge(array('sid' => $this->sid), $formfields); |
|
| 185 | + //$formfields['sid'] = $this->sid; |
|
| 186 | 186 | } |
| 187 | 187 | curl_setopt($ch, CURLOPT_URL, $this->config->getItem('fritzbox_url') . '/cgi-bin/firmwarecfg'); |
| 188 | 188 | curl_setopt($ch, CURLOPT_POST, 1); |
@@ -193,30 +193,30 @@ discard block |
||
| 193 | 193 | |
| 194 | 194 | // if filefileds not specified ('@/path/to/file.xml;type=text/xml' works fine) |
| 195 | 195 | if(empty( $filefileds )) { |
| 196 | - curl_setopt($ch, CURLOPT_POSTFIELDS, $formfields); // http_build_query |
|
| 197 | - } |
|
| 198 | - // post calculated raw data |
|
| 199 | - else { |
|
| 200 | - $header = $this->_create_custom_file_post_header($formfields, $filefileds); |
|
| 201 | - curl_setopt($ch, CURLOPT_HTTPHEADER , array( |
|
| 202 | - 'Content-Type: multipart/form-data; boundary=' . $header['delimiter'], 'Content-Length: ' . strlen($header['data']) ) |
|
| 203 | - ); |
|
| 196 | + curl_setopt($ch, CURLOPT_POSTFIELDS, $formfields); // http_build_query |
|
| 197 | + } |
|
| 198 | + // post calculated raw data |
|
| 199 | + else { |
|
| 200 | + $header = $this->_create_custom_file_post_header($formfields, $filefileds); |
|
| 201 | + curl_setopt($ch, CURLOPT_HTTPHEADER , array( |
|
| 202 | + 'Content-Type: multipart/form-data; boundary=' . $header['delimiter'], 'Content-Length: ' . strlen($header['data']) ) |
|
| 203 | + ); |
|
| 204 | 204 | |
| 205 | - curl_setopt($ch, CURLOPT_POSTFIELDS, $header['data']); |
|
| 206 | - } |
|
| 205 | + curl_setopt($ch, CURLOPT_POSTFIELDS, $header['data']); |
|
| 206 | + } |
|
| 207 | 207 | |
| 208 | 208 | $output = curl_exec($ch); |
| 209 | 209 | |
| 210 | - // curl error |
|
| 211 | - if(curl_errno($ch)) { |
|
| 212 | - $this->error(curl_error($ch)." (".curl_errno($ch).")"); |
|
| 213 | - } |
|
| 210 | + // curl error |
|
| 211 | + if(curl_errno($ch)) { |
|
| 212 | + $this->error(curl_error($ch)." (".curl_errno($ch).")"); |
|
| 213 | + } |
|
| 214 | 214 | |
| 215 | 215 | // finger out an error message, if given |
| 216 | 216 | preg_match('@<p class="ErrorMsg">(.*?)</p>@is', $output, $matches); |
| 217 | 217 | if (isset($matches[1])) |
| 218 | 218 | { |
| 219 | - $this->error(str_replace(' ', ' ', $matches[1])); |
|
| 219 | + $this->error(str_replace(' ', ' ', $matches[1])); |
|
| 220 | 220 | } |
| 221 | 221 | |
| 222 | 222 | curl_close($ch); |
@@ -224,10 +224,10 @@ discard block |
||
| 224 | 224 | } |
| 225 | 225 | |
| 226 | 226 | private function _create_custom_file_post_header($postFields, $fileFields) { |
| 227 | - // form field separator |
|
| 228 | - $delimiter = '-------------' . uniqid(); |
|
| 227 | + // form field separator |
|
| 228 | + $delimiter = '-------------' . uniqid(); |
|
| 229 | 229 | |
| 230 | - /* |
|
| 230 | + /* |
|
| 231 | 231 | // file upload fields: name => array(type=>'mime/type',content=>'raw data') |
| 232 | 232 | $fileFields = array( |
| 233 | 233 | 'file1' => array( |
@@ -242,44 +242,44 @@ discard block |
||
| 242 | 242 | ); |
| 243 | 243 | */ |
| 244 | 244 | |
| 245 | - $data = ''; |
|
| 245 | + $data = ''; |
|
| 246 | 246 | |
| 247 | - // populate normal fields first (simpler) |
|
| 248 | - foreach ($postFields as $name => $content) { |
|
| 249 | - $data .= "--" . $delimiter . "\r\n"; |
|
| 250 | - $data .= 'Content-Disposition: form-data; name="' . urlencode($name) . '"'; |
|
| 251 | - $data .= "\r\n\r\n"; |
|
| 252 | - $data .= $content; |
|
| 253 | - $data .= "\r\n"; |
|
| 254 | - } |
|
| 255 | - // populate file fields |
|
| 256 | - foreach ($fileFields as $name => $file) { |
|
| 257 | - $data .= "--" . $delimiter . "\r\n"; |
|
| 258 | - // "filename" attribute is not essential; server-side scripts may use it |
|
| 259 | - $data .= 'Content-Disposition: form-data; name="' . urlencode($name) . '";' . |
|
| 260 | - ' filename="' . $file['filename'] . '"' . "\r\n"; |
|
| 247 | + // populate normal fields first (simpler) |
|
| 248 | + foreach ($postFields as $name => $content) { |
|
| 249 | + $data .= "--" . $delimiter . "\r\n"; |
|
| 250 | + $data .= 'Content-Disposition: form-data; name="' . urlencode($name) . '"'; |
|
| 251 | + $data .= "\r\n\r\n"; |
|
| 252 | + $data .= $content; |
|
| 253 | + $data .= "\r\n"; |
|
| 254 | + } |
|
| 255 | + // populate file fields |
|
| 256 | + foreach ($fileFields as $name => $file) { |
|
| 257 | + $data .= "--" . $delimiter . "\r\n"; |
|
| 258 | + // "filename" attribute is not essential; server-side scripts may use it |
|
| 259 | + $data .= 'Content-Disposition: form-data; name="' . urlencode($name) . '";' . |
|
| 260 | + ' filename="' . $file['filename'] . '"' . "\r\n"; |
|
| 261 | 261 | |
| 262 | - //$data .= 'Content-Transfer-Encoding: binary'."\r\n"; |
|
| 263 | - // this is, again, informative only; good practice to include though |
|
| 264 | - $data .= 'Content-Type: ' . $file['type'] . "\r\n"; |
|
| 265 | - // this endline must be here to indicate end of headers |
|
| 266 | - $data .= "\r\n"; |
|
| 267 | - // the file itself (note: there's no encoding of any kind) |
|
| 268 | - $data .= $file['content'] . "\r\n"; |
|
| 269 | - } |
|
| 270 | - // last delimiter |
|
| 271 | - $data .= "--" . $delimiter . "--\r\n"; |
|
| 262 | + //$data .= 'Content-Transfer-Encoding: binary'."\r\n"; |
|
| 263 | + // this is, again, informative only; good practice to include though |
|
| 264 | + $data .= 'Content-Type: ' . $file['type'] . "\r\n"; |
|
| 265 | + // this endline must be here to indicate end of headers |
|
| 266 | + $data .= "\r\n"; |
|
| 267 | + // the file itself (note: there's no encoding of any kind) |
|
| 268 | + $data .= $file['content'] . "\r\n"; |
|
| 269 | + } |
|
| 270 | + // last delimiter |
|
| 271 | + $data .= "--" . $delimiter . "--\r\n"; |
|
| 272 | 272 | |
| 273 | - return array('delimiter' => $delimiter, 'data' => $data); |
|
| 274 | - } |
|
| 273 | + return array('delimiter' => $delimiter, 'data' => $data); |
|
| 274 | + } |
|
| 275 | 275 | |
| 276 | 276 | /** |
| 277 | - * do a GET request on the box |
|
| 278 | - * the main cURL wrapper handles the command |
|
| 279 | - * |
|
| 280 | - * @param array $params an associative array with the GET params to pass |
|
| 281 | - * @return string the raw HTML code returned by the Fritz!Box |
|
| 282 | - */ |
|
| 277 | + * do a GET request on the box |
|
| 278 | + * the main cURL wrapper handles the command |
|
| 279 | + * |
|
| 280 | + * @param array $params an associative array with the GET params to pass |
|
| 281 | + * @return string the raw HTML code returned by the Fritz!Box |
|
| 282 | + */ |
|
| 283 | 283 | public function doGetRequest($params = array()) |
| 284 | 284 | { |
| 285 | 285 | // add the sid, if it is already set |
@@ -319,12 +319,12 @@ discard block |
||
| 319 | 319 | |
| 320 | 320 | |
| 321 | 321 | /** |
| 322 | - * the login method, handles the secured login-process |
|
| 323 | - * newer firmwares (xx.04.74 and newer) need a challenge-response mechanism to prevent Cross-Site Request Forgery attacks |
|
| 324 | - * see http://www.avm.de/de/Extern/Technical_Note_Session_ID.pdf for details |
|
| 325 | - * |
|
| 326 | - * @return string a valid SID, if the login was successful, otherwise throws an Exception with an error message |
|
| 327 | - */ |
|
| 322 | + * the login method, handles the secured login-process |
|
| 323 | + * newer firmwares (xx.04.74 and newer) need a challenge-response mechanism to prevent Cross-Site Request Forgery attacks |
|
| 324 | + * see http://www.avm.de/de/Extern/Technical_Note_Session_ID.pdf for details |
|
| 325 | + * |
|
| 326 | + * @return string a valid SID, if the login was successful, otherwise throws an Exception with an error message |
|
| 327 | + */ |
|
| 328 | 328 | protected function initSID() |
| 329 | 329 | { |
| 330 | 330 | // determine, wich login type we have to use |
@@ -404,9 +404,9 @@ discard block |
||
| 404 | 404 | |
| 405 | 405 | |
| 406 | 406 | /** |
| 407 | - * the logout method just sends a logout command to the Fritz!Box |
|
| 408 | - * |
|
| 409 | - */ |
|
| 407 | + * the logout method just sends a logout command to the Fritz!Box |
|
| 408 | + * |
|
| 409 | + */ |
|
| 410 | 410 | protected function logout() |
| 411 | 411 | { |
| 412 | 412 | if ( $this->config->getItem('use_lua_login_method') == true ) |
@@ -425,10 +425,10 @@ discard block |
||
| 425 | 425 | |
| 426 | 426 | |
| 427 | 427 | /** |
| 428 | - * the error method just throws an Exception |
|
| 429 | - * |
|
| 430 | - * @param string $message an error message for the Exception |
|
| 431 | - */ |
|
| 428 | + * the error method just throws an Exception |
|
| 429 | + * |
|
| 430 | + * @param string $message an error message for the Exception |
|
| 431 | + */ |
|
| 432 | 432 | public function error($message = null) |
| 433 | 433 | { |
| 434 | 434 | throw new Exception($message); |
@@ -436,20 +436,20 @@ discard block |
||
| 436 | 436 | |
| 437 | 437 | |
| 438 | 438 | /** |
| 439 | - * a getter for the session ID |
|
| 440 | - * |
|
| 441 | - * @return string $this->sid |
|
| 442 | - */ |
|
| 439 | + * a getter for the session ID |
|
| 440 | + * |
|
| 441 | + * @return string $this->sid |
|
| 442 | + */ |
|
| 443 | 443 | public function getSID() |
| 444 | 444 | { |
| 445 | 445 | return $this->sid; |
| 446 | 446 | } |
| 447 | 447 | |
| 448 | 448 | /** |
| 449 | - * log a message |
|
| 450 | - * |
|
| 451 | - * @param $message string the message to log |
|
| 452 | - */ |
|
| 449 | + * log a message |
|
| 450 | + * |
|
| 451 | + * @param $message string the message to log |
|
| 452 | + */ |
|
| 453 | 453 | public function logMessage($message) |
| 454 | 454 | { |
| 455 | 455 | if ( $this->config->getItem('newline') == false ) |
@@ -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 | 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')); |
|
| 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']); |
@@ -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 | } |
@@ -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 | |
@@ -208,8 +208,8 @@ discard block |
||
| 208 | 208 | $output = curl_exec($ch); |
| 209 | 209 | |
| 210 | 210 | // curl error |
| 211 | - if(curl_errno($ch)) { |
|
| 212 | - $this->error(curl_error($ch)." (".curl_errno($ch).")"); |
|
| 211 | + if (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 |
@@ -289,7 +289,7 @@ discard block |
||
| 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 | } |
@@ -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 | } |
@@ -615,7 +615,7 @@ discard block |
||
| 615 | 615 | print " Added photo: " . basename($photo_file) . PHP_EOL; |
| 616 | 616 | } |
| 617 | 617 | else |
| 618 | - print " WARNING: Only jpg contact photos are currently supported." . PHP_EOL; |
|
| 618 | + print " WARNING: Only jpg contact photos are currently supported." . PHP_EOL; |
|
| 619 | 619 | } |
| 620 | 620 | elseif(substr($entry['photo_data'][0], 0, 4) == 'http') |
| 621 | 621 | { |
@@ -804,10 +804,10 @@ discard block |
||
| 804 | 804 | ); |
| 805 | 805 | |
| 806 | 806 | $filefileds = array('PhonebookImportFile' => array( |
| 807 | - 'type' => 'text/xml', |
|
| 808 | - 'filename' => 'updatepb.xml', |
|
| 809 | - 'content' => $this->fbxml, |
|
| 810 | - ) |
|
| 807 | + 'type' => 'text/xml', |
|
| 808 | + 'filename' => 'updatepb.xml', |
|
| 809 | + 'content' => $this->fbxml, |
|
| 810 | + ) |
|
| 811 | 811 | ); |
| 812 | 812 | |
| 813 | 813 | $raw_result = $fritz->doPostFile($formfields, $filefileds); // send the command |
@@ -133,6 +133,9 @@ discard block |
||
| 133 | 133 | return $path; |
| 134 | 134 | } |
| 135 | 135 | |
| 136 | + /** |
|
| 137 | + * @param string $dir |
|
| 138 | + */ |
|
| 136 | 139 | public function rmtemp($dir) |
| 137 | 140 | { |
| 138 | 141 | if(is_dir($dir)) |
@@ -177,6 +180,10 @@ discard block |
||
| 177 | 180 | } |
| 178 | 181 | } |
| 179 | 182 | |
| 183 | + /** |
|
| 184 | + * @param string $inputfile |
|
| 185 | + * @param string $outputfile |
|
| 186 | + */ |
|
| 180 | 187 | public function base64_to_jpeg($inputfile, $outputfile) |
| 181 | 188 | { |
| 182 | 189 | // read data (binary) |
@@ -27,9 +27,9 @@ discard block |
||
| 27 | 27 | |
| 28 | 28 | // check for the minimum php version |
| 29 | 29 | $php_min_version = '5.3.6'; |
| 30 | -if(version_compare(PHP_VERSION, $php_min_version) < 0) |
|
| 30 | +if (version_compare(PHP_VERSION, $php_min_version) < 0) |
|
| 31 | 31 | { |
| 32 | - print 'ERROR: PHP version '.$php_min_version.' is required. Found version: ' . PHP_VERSION . PHP_EOL; |
|
| 32 | + print 'ERROR: PHP version ' . $php_min_version . ' is required. Found version: ' . PHP_VERSION . PHP_EOL; |
|
| 33 | 33 | exit(1); |
| 34 | 34 | } |
| 35 | 35 | |
@@ -37,7 +37,7 @@ 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 | 42 | else |
| 43 | 43 | $config_file_name = __DIR__ . '/config.php'; |
@@ -59,11 +59,11 @@ discard block |
||
| 59 | 59 | $config['build_photos'] = true; |
| 60 | 60 | $config['quickdial_keyword'] = 'Quickdial:'; |
| 61 | 61 | |
| 62 | -if(is_file($config_file_name)) |
|
| 62 | +if (is_file($config_file_name)) |
|
| 63 | 63 | require($config_file_name); |
| 64 | 64 | else |
| 65 | 65 | { |
| 66 | - print 'ERROR: No '.$config_file_name.' found, please take a look at config.example.php and create a '.$config_file_name.' file!'.PHP_EOL; |
|
| 66 | + 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 | 67 | exit(1); |
| 68 | 68 | } |
| 69 | 69 | |
@@ -119,14 +119,14 @@ discard block |
||
| 119 | 119 | } |
| 120 | 120 | |
| 121 | 121 | // Source: https://php.net/manual/de/function.tempnam.php#61436 |
| 122 | - public function mktemp($dir, $prefix='', $mode=0700) |
|
| 122 | + public function mktemp($dir, $prefix = '', $mode = 0700) |
|
| 123 | 123 | { |
| 124 | - if(substr($dir, -1) != '/') |
|
| 124 | + if (substr($dir, -1) != '/') |
|
| 125 | 125 | $dir .= '/'; |
| 126 | 126 | |
| 127 | 127 | do |
| 128 | 128 | { |
| 129 | - $path = $dir.$prefix.mt_rand(0, 9999999); |
|
| 129 | + $path = $dir . $prefix . mt_rand(0, 9999999); |
|
| 130 | 130 | } |
| 131 | 131 | while (!mkdir($path, $mode)); |
| 132 | 132 | |
@@ -135,15 +135,15 @@ discard block |
||
| 135 | 135 | |
| 136 | 136 | public function rmtemp($dir) |
| 137 | 137 | { |
| 138 | - if(is_dir($dir)) |
|
| 138 | + if (is_dir($dir)) |
|
| 139 | 139 | { |
| 140 | 140 | $objects = scandir($dir); |
| 141 | - foreach($objects as $object) |
|
| 141 | + foreach ($objects as $object) |
|
| 142 | 142 | { |
| 143 | - if($object != "." && $object != "..") |
|
| 143 | + if ($object != "." && $object != "..") |
|
| 144 | 144 | { |
| 145 | - if(filetype($dir."/".$object) == "dir") |
|
| 146 | - rrmdir($dir."/".$object); else unlink($dir."/".$object); |
|
| 145 | + if (filetype($dir . "/" . $object) == "dir") |
|
| 146 | + rrmdir($dir . "/" . $object); else unlink($dir . "/" . $object); |
|
| 147 | 147 | } |
| 148 | 148 | } |
| 149 | 149 | reset($objects); |
@@ -156,21 +156,21 @@ discard block |
||
| 156 | 156 | try |
| 157 | 157 | { |
| 158 | 158 | // Check if there are valid base64 characters |
| 159 | - if(!preg_match('/^[a-zA-Z0-9\/\r\n+]*={0,2}$/', $str)) |
|
| 159 | + if (!preg_match('/^[a-zA-Z0-9\/\r\n+]*={0,2}$/', $str)) |
|
| 160 | 160 | return false; |
| 161 | 161 | |
| 162 | 162 | // Decode the string in strict mode and check the results |
| 163 | 163 | $decoded = base64_decode($str, true); |
| 164 | - if($decoded === false) |
|
| 164 | + if ($decoded === false) |
|
| 165 | 165 | return false; |
| 166 | 166 | |
| 167 | 167 | // Encode the string again |
| 168 | - if(base64_encode($decoded) === $str) |
|
| 168 | + if (base64_encode($decoded) === $str) |
|
| 169 | 169 | return true; |
| 170 | 170 | else |
| 171 | 171 | return false; |
| 172 | 172 | } |
| 173 | - catch(Exception $e) |
|
| 173 | + catch (Exception $e) |
|
| 174 | 174 | { |
| 175 | 175 | // If exception is caught, then it is not a base64 encoded string |
| 176 | 176 | return false; |
@@ -199,9 +199,9 @@ discard block |
||
| 199 | 199 | $imgseqfname = 1; |
| 200 | 200 | $snum = 0; |
| 201 | 201 | |
| 202 | - if(is_array($this->config['carddav'])) |
|
| 202 | + if (is_array($this->config['carddav'])) |
|
| 203 | 203 | { |
| 204 | - foreach($this->config['carddav'] as $conf) |
|
| 204 | + foreach ($this->config['carddav'] as $conf) |
|
| 205 | 205 | { |
| 206 | 206 | print " [" . $snum . "]: " . $conf['url'] . " "; |
| 207 | 207 | $carddav = new CardDavPHP\CardDavBackend($conf['url']); |
@@ -209,23 +209,23 @@ discard block |
||
| 209 | 209 | |
| 210 | 210 | // set the vcard extension in case the user |
| 211 | 211 | // defined it in the config |
| 212 | - if(isset($conf['extension'])) |
|
| 212 | + if (isset($conf['extension'])) |
|
| 213 | 213 | $carddav->setVcardExtension($conf['extension']); |
| 214 | 214 | |
| 215 | 215 | // retrieve data from the CardDAV server now |
| 216 | - $xmldata = $carddav->get(); |
|
| 216 | + $xmldata = $carddav->get(); |
|
| 217 | 217 | |
| 218 | 218 | // identify if we received UTF-8 encoded data from the |
| 219 | 219 | // CardDAV server and if not reencode it since the FRITZ!Box |
| 220 | 220 | // requires UTF-8 encoded data |
| 221 | - if(iconv('utf-8', 'utf-8//IGNORE', $xmldata) != $xmldata) |
|
| 221 | + if (iconv('utf-8', 'utf-8//IGNORE', $xmldata) != $xmldata) |
|
| 222 | 222 | $xmldata = utf8_encode($xmldata); |
| 223 | 223 | |
| 224 | 224 | // read raw_vcard data from xml response |
| 225 | 225 | $raw_vcards = array(); |
| 226 | 226 | $xmlvcard = new SimpleXMLElement($xmldata); |
| 227 | 227 | |
| 228 | - foreach($xmlvcard->element as $vcard_element) |
|
| 228 | + foreach ($xmlvcard->element as $vcard_element) |
|
| 229 | 229 | { |
| 230 | 230 | $id = $vcard_element->id->__toString(); |
| 231 | 231 | $value = (string)$vcard_element->vcard->__toString(); |
@@ -236,14 +236,14 @@ discard block |
||
| 236 | 236 | |
| 237 | 237 | // parse raw_vcards |
| 238 | 238 | $quick_dial_arr = array(); |
| 239 | - foreach($raw_vcards as $v) |
|
| 239 | + foreach ($raw_vcards as $v) |
|
| 240 | 240 | { |
| 241 | 241 | $vcard_obj = new vCard(false, $v); |
| 242 | 242 | $name_arr = null; |
| 243 | - if(isset($vcard_obj->n[0])) |
|
| 243 | + if (isset($vcard_obj->n[0])) |
|
| 244 | 244 | $name_arr = $vcard_obj->n[0]; |
| 245 | 245 | $org_arr = null; |
| 246 | - if(isset($vcard_obj->org[0])) |
|
| 246 | + if (isset($vcard_obj->org[0])) |
|
| 247 | 247 | $org_arr = $vcard_obj->org[0]; |
| 248 | 248 | $addnames = ''; |
| 249 | 249 | $prefix = ''; |
@@ -251,16 +251,16 @@ discard block |
||
| 251 | 251 | $orgname = ''; |
| 252 | 252 | |
| 253 | 253 | // Build name Parts if existing ans switch to true in config |
| 254 | - if(isset($name_arr['prefixes']) AND $this->config['prefix']) |
|
| 254 | + if (isset($name_arr['prefixes']) AND $this->config['prefix']) |
|
| 255 | 255 | $prefix = trim($name_arr['prefixes']); |
| 256 | 256 | |
| 257 | - if(isset($name_arr['suffixes']) AND $this->config['suffix']) |
|
| 257 | + if (isset($name_arr['suffixes']) AND $this->config['suffix']) |
|
| 258 | 258 | $suffix = trim($name_arr['suffixes']); |
| 259 | 259 | |
| 260 | - if(isset($name_arr['additionalnames']) AND $this->config['addnames']) |
|
| 260 | + if (isset($name_arr['additionalnames']) AND $this->config['addnames']) |
|
| 261 | 261 | $addnames = trim($name_arr['additionalnames']); |
| 262 | 262 | |
| 263 | - if(isset($org_arr['name']) AND $this->config['orgname']) |
|
| 263 | + if (isset($org_arr['name']) AND $this->config['orgname']) |
|
| 264 | 264 | $orgname = trim($org_arr['name']); |
| 265 | 265 | |
| 266 | 266 | $firstname = trim($name_arr['firstname']); |
@@ -280,13 +280,13 @@ discard block |
||
| 280 | 280 | $format = $this->config['fullname_format']; |
| 281 | 281 | |
| 282 | 282 | // Prefix |
| 283 | - if(!empty($prefix)) |
|
| 283 | + if (!empty($prefix)) |
|
| 284 | 284 | $name .= $prefix; |
| 285 | 285 | |
| 286 | - if($format == 0) |
|
| 286 | + if ($format == 0) |
|
| 287 | 287 | { |
| 288 | 288 | // Lastname |
| 289 | - if(!empty($name) AND !empty($lastname)) |
|
| 289 | + if (!empty($name) AND !empty($lastname)) |
|
| 290 | 290 | $name .= ' ' . $lastname; |
| 291 | 291 | else |
| 292 | 292 | $name .= $lastname; |
@@ -294,25 +294,25 @@ discard block |
||
| 294 | 294 | else |
| 295 | 295 | { |
| 296 | 296 | // Firstname |
| 297 | - if(!empty($name) AND !empty($firstname)) |
|
| 297 | + if (!empty($name) AND !empty($firstname)) |
|
| 298 | 298 | $name .= ' ' . $firstname; |
| 299 | 299 | else |
| 300 | 300 | $name .= $firstname; |
| 301 | 301 | } |
| 302 | 302 | |
| 303 | - if($format == 2) |
|
| 303 | + if ($format == 2) |
|
| 304 | 304 | { |
| 305 | 305 | // AdditionalNames |
| 306 | - if(!empty($name) AND !empty($addnames)) |
|
| 306 | + if (!empty($name) AND !empty($addnames)) |
|
| 307 | 307 | $name .= ' ' . $addnames; |
| 308 | 308 | else |
| 309 | 309 | $name .= $addnames; |
| 310 | 310 | } |
| 311 | 311 | |
| 312 | - if($format == 0) |
|
| 312 | + if ($format == 0) |
|
| 313 | 313 | { |
| 314 | 314 | // Firstname |
| 315 | - if(!empty($name) AND !empty($firstname)) |
|
| 315 | + if (!empty($name) AND !empty($firstname)) |
|
| 316 | 316 | $name .= ', ' . $firstname; |
| 317 | 317 | else |
| 318 | 318 | $name .= $firstname; |
@@ -320,29 +320,29 @@ discard block |
||
| 320 | 320 | else |
| 321 | 321 | { |
| 322 | 322 | // Lastname |
| 323 | - if(!empty($name) AND !empty($lastname)) |
|
| 323 | + if (!empty($name) AND !empty($lastname)) |
|
| 324 | 324 | $name .= ' ' . $lastname; |
| 325 | 325 | else |
| 326 | 326 | $name .= $lastname; |
| 327 | 327 | } |
| 328 | 328 | |
| 329 | - if($format != 2) |
|
| 329 | + if ($format != 2) |
|
| 330 | 330 | { |
| 331 | 331 | // AdditionalNames |
| 332 | - if(!empty($name) AND !empty($addnames)) |
|
| 332 | + if (!empty($name) AND !empty($addnames)) |
|
| 333 | 333 | $name .= ' ' . $addnames; |
| 334 | 334 | else |
| 335 | 335 | $name .= $addnames; |
| 336 | 336 | } |
| 337 | 337 | |
| 338 | 338 | // Suffix |
| 339 | - if(!empty($name) AND !empty($suffix)) |
|
| 339 | + if (!empty($name) AND !empty($suffix)) |
|
| 340 | 340 | $name .= ' ' . $suffix; |
| 341 | 341 | else |
| 342 | 342 | $name .= $suffix; |
| 343 | 343 | |
| 344 | 344 | // OrgName |
| 345 | - if(!empty($name) AND !empty($orgname)) |
|
| 345 | + if (!empty($name) AND !empty($orgname)) |
|
| 346 | 346 | $name .= ' (' . $orgname . ')'; |
| 347 | 347 | else |
| 348 | 348 | $name .= $orgname; |
@@ -350,24 +350,24 @@ discard block |
||
| 350 | 350 | // make sure to trim whitespaces and double spaces |
| 351 | 351 | $name = trim(str_replace(' ', ' ', $name)); |
| 352 | 352 | |
| 353 | - if(empty($name)) |
|
| 353 | + if (empty($name)) |
|
| 354 | 354 | { |
| 355 | 355 | print ' WARNING: No fullname, lastname or orgname found!'; |
| 356 | 356 | $name = 'UNKNOWN'; |
| 357 | 357 | } |
| 358 | 358 | |
| 359 | 359 | // format filename of contact photo; remove special letters, added config option for sequential filnames default is false |
| 360 | - if($vcard_obj->photo) |
|
| 360 | + if ($vcard_obj->photo) |
|
| 361 | 361 | { |
| 362 | - if(isset($this->config['seq_photo_name']) AND $this->config['seq_photo_name'] == true) |
|
| 362 | + if (isset($this->config['seq_photo_name']) AND $this->config['seq_photo_name'] == true) |
|
| 363 | 363 | { |
| 364 | 364 | $photo = $imgseqfname; |
| 365 | 365 | $imgseqfname++; |
| 366 | 366 | } |
| 367 | 367 | else |
| 368 | 368 | { |
| 369 | - $photo = str_replace(array(',','&',' ','/','ä','ö','ü','Ä','Ö','Ü','ß','á','à','ó','ò','ú','ù','í','ø'), |
|
| 370 | - array('','_','_','_','ae','oe','ue','Ae','Oe','Ue','ss','a','a','o','o','u','u','i','oe'),$name); |
|
| 369 | + $photo = str_replace(array(',', '&', ' ', '/', 'ä', 'ö', 'ü', 'Ä', 'Ö', 'Ü', 'ß', 'á', 'à', 'ó', 'ò', 'ú', 'ù', 'í', 'ø'), |
|
| 370 | + array('', '_', '_', '_', 'ae', 'oe', 'ue', 'Ae', 'Oe', 'Ue', 'ss', 'a', 'a', 'o', 'o', 'u', 'u', 'i', 'oe'), $name); |
|
| 371 | 371 | } |
| 372 | 372 | } |
| 373 | 373 | else |
@@ -375,25 +375,25 @@ discard block |
||
| 375 | 375 | |
| 376 | 376 | // phone |
| 377 | 377 | $phone_no = array(); |
| 378 | - if($vcard_obj->categories) |
|
| 378 | + if ($vcard_obj->categories) |
|
| 379 | 379 | $categories = $vcard_obj->categories[0]; |
| 380 | 380 | else |
| 381 | 381 | $categories = array(); |
| 382 | 382 | |
| 383 | 383 | // check for quickdial entry |
| 384 | - if(isset($vcard_obj->note[0])) |
|
| 384 | + if (isset($vcard_obj->note[0])) |
|
| 385 | 385 | { |
| 386 | 386 | $note = $vcard_obj->note[0]; |
| 387 | 387 | $notes = explode($this->config['quickdial_keyword'], $note); |
| 388 | - foreach($notes as $linenr => $linecontent) |
|
| 388 | + foreach ($notes as $linenr => $linecontent) |
|
| 389 | 389 | { |
| 390 | - $found = strrpos($linecontent , ":**7"); |
|
| 391 | - if($found > 0) |
|
| 390 | + $found = strrpos($linecontent, ":**7"); |
|
| 391 | + if ($found > 0) |
|
| 392 | 392 | { |
| 393 | - $pos_qd_start = strrpos($linecontent , ":**7" ); |
|
| 394 | - $quick_dial_for_nr = preg_replace("/[^0-9+]/", "",substr($linecontent , 0, $pos_qd_start)); |
|
| 395 | - $quick_dial_nr = intval(substr($linecontent , $pos_qd_start+4, 3)); |
|
| 396 | - $quick_dial_arr[$quick_dial_for_nr]=$quick_dial_nr; |
|
| 393 | + $pos_qd_start = strrpos($linecontent, ":**7"); |
|
| 394 | + $quick_dial_for_nr = preg_replace("/[^0-9+]/", "", substr($linecontent, 0, $pos_qd_start)); |
|
| 395 | + $quick_dial_nr = intval(substr($linecontent, $pos_qd_start + 4, 3)); |
|
| 396 | + $quick_dial_arr[$quick_dial_for_nr] = $quick_dial_nr; |
|
| 397 | 397 | } |
| 398 | 398 | } |
| 399 | 399 | } |
@@ -402,12 +402,12 @@ discard block |
||
| 402 | 402 | $email_add = array(); |
| 403 | 403 | $vip = isset($this->config['group_vip']) && in_array((string)$this->config['group_vip'], $categories); |
| 404 | 404 | |
| 405 | - if(array_key_exists('group_filter',$this->config) && is_array($this->config['group_filter'])) |
|
| 405 | + if (array_key_exists('group_filter', $this->config) && is_array($this->config['group_filter'])) |
|
| 406 | 406 | { |
| 407 | 407 | $add_entry = 0; |
| 408 | - foreach($this->config['group_filter'] as $group_filter) |
|
| 408 | + foreach ($this->config['group_filter'] as $group_filter) |
|
| 409 | 409 | { |
| 410 | - if(in_array($group_filter,$categories)) |
|
| 410 | + if (in_array($group_filter, $categories)) |
|
| 411 | 411 | { |
| 412 | 412 | $add_entry = 1; |
| 413 | 413 | break; |
@@ -417,14 +417,14 @@ discard block |
||
| 417 | 417 | else |
| 418 | 418 | $add_entry = 1; |
| 419 | 419 | |
| 420 | - if($add_entry == 1) |
|
| 420 | + if ($add_entry == 1) |
|
| 421 | 421 | { |
| 422 | - foreach($vcard_obj->tel as $t) |
|
| 422 | + foreach ($vcard_obj->tel as $t) |
|
| 423 | 423 | { |
| 424 | 424 | $prio = 0; |
| 425 | - $quickdial =null; |
|
| 425 | + $quickdial = null; |
|
| 426 | 426 | |
| 427 | - if(!is_array($t) || empty($t['type'])) |
|
| 427 | + if (!is_array($t) || empty($t['type'])) |
|
| 428 | 428 | { |
| 429 | 429 | $type = "mobile"; |
| 430 | 430 | $phone_number = $t; |
@@ -433,15 +433,15 @@ discard block |
||
| 433 | 433 | { |
| 434 | 434 | $phone_number = $t['value']; |
| 435 | 435 | |
| 436 | - $phone_number_clean = preg_replace("/[^0-9+]/", "",$phone_number); |
|
| 437 | - foreach($quick_dial_arr as $qd_phone_nr => $value) |
|
| 436 | + $phone_number_clean = preg_replace("/[^0-9+]/", "", $phone_number); |
|
| 437 | + foreach ($quick_dial_arr as $qd_phone_nr => $value) |
|
| 438 | 438 | { |
| 439 | - if($qd_phone_nr == $phone_number_clean) |
|
| 439 | + if ($qd_phone_nr == $phone_number_clean) |
|
| 440 | 440 | { |
| 441 | 441 | //Set quickdial |
| 442 | - if($value == 1) |
|
| 442 | + if ($value == 1) |
|
| 443 | 443 | print "\nWARNING: Quickdial value 1 (**701) is not possible but used! \n"; |
| 444 | - elseif($value >= 100) |
|
| 444 | + elseif ($value >= 100) |
|
| 445 | 445 | print "\nWARNING: Quickdial value bigger than 99 (**799) is not possible but used! \n"; |
| 446 | 446 | |
| 447 | 447 | $quickdial = $value; |
@@ -451,34 +451,34 @@ discard block |
||
| 451 | 451 | $typearr_lower = unserialize(strtolower(serialize($t['type']))); |
| 452 | 452 | |
| 453 | 453 | // find out priority |
| 454 | - if(in_array("pref", $typearr_lower)) |
|
| 454 | + if (in_array("pref", $typearr_lower)) |
|
| 455 | 455 | $prio = 1; |
| 456 | 456 | |
| 457 | 457 | // set the proper type |
| 458 | - if(in_array("cell", $typearr_lower)) |
|
| 458 | + if (in_array("cell", $typearr_lower)) |
|
| 459 | 459 | $type = "mobile"; |
| 460 | - elseif(in_array("home", $typearr_lower)) |
|
| 460 | + elseif (in_array("home", $typearr_lower)) |
|
| 461 | 461 | $type = "home"; |
| 462 | - elseif(in_array("fax", $typearr_lower)) |
|
| 462 | + elseif (in_array("fax", $typearr_lower)) |
|
| 463 | 463 | $type = "fax_work"; |
| 464 | - elseif(in_array("work", $typearr_lower)) |
|
| 464 | + elseif (in_array("work", $typearr_lower)) |
|
| 465 | 465 | $type = "work"; |
| 466 | - elseif(in_array("other", $typearr_lower)) |
|
| 466 | + elseif (in_array("other", $typearr_lower)) |
|
| 467 | 467 | $type = "other"; |
| 468 | - elseif(in_array("dom", $typearr_lower)) |
|
| 468 | + elseif (in_array("dom", $typearr_lower)) |
|
| 469 | 469 | $type = "other"; |
| 470 | 470 | else |
| 471 | 471 | continue; |
| 472 | 472 | } |
| 473 | - $phone_no[] = array("type"=>$type, "prio"=>$prio, "quickdial"=>$quickdial, "value" => $this->_clear_phone_number($phone_number)); |
|
| 473 | + $phone_no[] = array("type"=>$type, "prio"=>$prio, "quickdial"=>$quickdial, "value" => $this->_clear_phone_number($phone_number)); |
|
| 474 | 474 | } |
| 475 | 475 | |
| 476 | 476 | // request email address and type |
| 477 | - if($vcard_obj->email) |
|
| 477 | + if ($vcard_obj->email) |
|
| 478 | 478 | { |
| 479 | - foreach($vcard_obj->email as $e) |
|
| 479 | + foreach ($vcard_obj->email as $e) |
|
| 480 | 480 | { |
| 481 | - if(empty($e['type'])) |
|
| 481 | + if (empty($e['type'])) |
|
| 482 | 482 | { |
| 483 | 483 | $type_email = "work"; |
| 484 | 484 | $email = $e; |
@@ -487,11 +487,11 @@ discard block |
||
| 487 | 487 | { |
| 488 | 488 | $email = $e['value']; |
| 489 | 489 | $typearr_lower = unserialize(strtolower(serialize($e['type']))); |
| 490 | - if(in_array("work", $typearr_lower)) |
|
| 490 | + if (in_array("work", $typearr_lower)) |
|
| 491 | 491 | $type_email = "work"; |
| 492 | - elseif(in_array("home", $typearr_lower)) |
|
| 492 | + elseif (in_array("home", $typearr_lower)) |
|
| 493 | 493 | $type_email = "home"; |
| 494 | - elseif(in_array("other", $typearr_lower)) |
|
| 494 | + elseif (in_array("other", $typearr_lower)) |
|
| 495 | 495 | $type_email = "other"; |
| 496 | 496 | else |
| 497 | 497 | continue; |
@@ -521,15 +521,15 @@ discard block |
||
| 521 | 521 | |
| 522 | 522 | public function build_fb_xml() |
| 523 | 523 | { |
| 524 | - if(empty($this->entries)) |
|
| 524 | + if (empty($this->entries)) |
|
| 525 | 525 | throw new Exception('No entries available! Call get_carddav_entries or set $this->entries manually!'); |
| 526 | 526 | |
| 527 | 527 | // create FB XML in utf-8 format |
| 528 | 528 | $root = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?><phonebooks><phonebook></phonebook></phonebooks>'); |
| 529 | 529 | $pb = $root->phonebook; |
| 530 | - $pb->addAttribute("name",$this->config['phonebook_name']); |
|
| 530 | + $pb->addAttribute("name", $this->config['phonebook_name']); |
|
| 531 | 531 | |
| 532 | - foreach($this->entries as $entry) |
|
| 532 | + foreach ($this->entries as $entry) |
|
| 533 | 533 | { |
| 534 | 534 | $contact = $pb->addChild("contact"); |
| 535 | 535 | $contact->addChild("category", $entry['vip']); |
@@ -541,17 +541,17 @@ discard block |
||
| 541 | 541 | // telephone: put the phonenumbers into the fritzbox xml file |
| 542 | 542 | $telephony = $contact->addChild("telephony"); |
| 543 | 543 | $id = 0; |
| 544 | - foreach($entry['telephony'] as $tel) |
|
| 544 | + foreach ($entry['telephony'] as $tel) |
|
| 545 | 545 | { |
| 546 | 546 | $num = $telephony->addChild("number", $tel['value']); |
| 547 | 547 | $num->addAttribute("type", $tel['type']); |
| 548 | - $num->addAttribute("vanity",""); |
|
| 548 | + $num->addAttribute("vanity", ""); |
|
| 549 | 549 | $num->addAttribute("prio", $tel['prio']); |
| 550 | 550 | $num->addAttribute("id", $id); |
| 551 | 551 | |
| 552 | - if(isset($tel['quickdial'])) |
|
| 552 | + if (isset($tel['quickdial'])) |
|
| 553 | 553 | { |
| 554 | - $num->addAttribute("quickdial",$tel['quickdial']); |
|
| 554 | + $num->addAttribute("quickdial", $tel['quickdial']); |
|
| 555 | 555 | print " Added quickdial: " . $tel['quickdial'] . " for: " . $tel['value'] . " (" . $tel['type'] . ")" . PHP_EOL; |
| 556 | 556 | } |
| 557 | 557 | |
@@ -560,13 +560,13 @@ discard block |
||
| 560 | 560 | } |
| 561 | 561 | |
| 562 | 562 | // output a warning if no telephone number was found |
| 563 | - if($id == 0) |
|
| 563 | + if ($id == 0) |
|
| 564 | 564 | print " WARNING: no phone entry found. VCard will be ignored." . PHP_EOL; |
| 565 | 565 | |
| 566 | 566 | // email: put the email addresses into the fritzbox xml file |
| 567 | 567 | $email = $contact->addChild("services"); |
| 568 | 568 | $id = 0; |
| 569 | - foreach($entry['email'] as $mail) |
|
| 569 | + foreach ($entry['email'] as $mail) |
|
| 570 | 570 | { |
| 571 | 571 | $mail_adr = $email->addChild("email", $mail['value']); |
| 572 | 572 | $mail_adr->addAttribute("classifier", $mail['type']); |
@@ -577,14 +577,14 @@ discard block |
||
| 577 | 577 | } |
| 578 | 578 | |
| 579 | 579 | // check for a photo being part of the VCard |
| 580 | - if(($entry['photo']) and ($entry['photo_data']) and (is_array($entry['photo_data'])) and ($entry['photo_data'][0])) |
|
| 580 | + if (($entry['photo']) and ($entry['photo_data']) and (is_array($entry['photo_data'])) and ($entry['photo_data'][0])) |
|
| 581 | 581 | { |
| 582 | 582 | // check if 'photo_data'[0] is an array as well because then |
| 583 | 583 | // we have to extract ['value'] and friends. |
| 584 | - if(is_array($entry['photo_data'][0]) and (array_key_exists('value', $entry['photo_data'][0]))) |
|
| 584 | + if (is_array($entry['photo_data'][0]) and (array_key_exists('value', $entry['photo_data'][0]))) |
|
| 585 | 585 | { |
| 586 | 586 | // check if photo_data really contains JPEG data |
| 587 | - if((array_key_exists('type', $entry['photo_data'][0])) and (is_array($entry['photo_data'][0]['type'])) and |
|
| 587 | + if ((array_key_exists('type', $entry['photo_data'][0])) and (is_array($entry['photo_data'][0]['type'])) and |
|
| 588 | 588 | ($entry['photo_data'][0]['type'][0] == 'jpeg' or $entry['photo_data'][0]['type'][0] == 'jpg')) |
| 589 | 589 | { |
| 590 | 590 | // get photo, rename, base64 convert and save as jpg |
@@ -594,7 +594,7 @@ discard block |
||
| 594 | 594 | |
| 595 | 595 | // check for base64 encoding of the photo data and convert it |
| 596 | 596 | // accordingly. |
| 597 | - if(((array_key_exists('encoding', $entry['photo_data'][0])) and ($entry['photo_data'][0]['encoding'] == 'b')) or $this->is_base64($photo_data)) |
|
| 597 | + if (((array_key_exists('encoding', $entry['photo_data'][0])) and ($entry['photo_data'][0]['encoding'] == 'b')) or $this->is_base64($photo_data)) |
|
| 598 | 598 | { |
| 599 | 599 | file_put_contents($photo_file . ".b64", $photo_data); |
| 600 | 600 | $this->base64_to_jpeg($photo_file . ".b64", $photo_file); |
@@ -607,14 +607,14 @@ discard block |
||
| 607 | 607 | } |
| 608 | 608 | |
| 609 | 609 | // add contact photo to xml |
| 610 | - $person->addChild("imageURL", $this->config['fritzbox_path'].$this->config['usb_disk']."FRITZ/fonpix/".basename($photo_file)); |
|
| 610 | + $person->addChild("imageURL", $this->config['fritzbox_path'] . $this->config['usb_disk'] . "FRITZ/fonpix/" . basename($photo_file)); |
|
| 611 | 611 | |
| 612 | 612 | print " Added photo: " . basename($photo_file) . PHP_EOL; |
| 613 | 613 | } |
| 614 | 614 | else |
| 615 | 615 | print " WARNING: Only jpg contact photos are currently supported." . PHP_EOL; |
| 616 | 616 | } |
| 617 | - elseif(substr($entry['photo_data'][0], 0, 4) == 'http') |
|
| 617 | + elseif (substr($entry['photo_data'][0], 0, 4) == 'http') |
|
| 618 | 618 | { |
| 619 | 619 | // add contact photo to xml |
| 620 | 620 | $person->addChild("imageURL", $entry['photo_data'][0]); |
@@ -639,20 +639,20 @@ discard block |
||
| 639 | 639 | return $text; |
| 640 | 640 | } |
| 641 | 641 | |
| 642 | - public function _concat ($text1,$text2) |
|
| 642 | + public function _concat($text1, $text2) |
|
| 643 | 643 | { |
| 644 | - if($text1 == '') |
|
| 644 | + if ($text1 == '') |
|
| 645 | 645 | return $text2; |
| 646 | - elseif($text2 == '') |
|
| 646 | + elseif ($text2 == '') |
|
| 647 | 647 | return $text1; |
| 648 | 648 | else |
| 649 | - return $text1.", ".$text2; |
|
| 649 | + return $text1 . ", " . $text2; |
|
| 650 | 650 | } |
| 651 | 651 | |
| 652 | 652 | public function _parse_fb_result($text) |
| 653 | 653 | { |
| 654 | 654 | preg_match("/\<h2\>([^\<]+)\<\/h2\>/", $text, $matches); |
| 655 | - if($matches) |
|
| 655 | + if ($matches) |
|
| 656 | 656 | return $matches[1]; |
| 657 | 657 | else |
| 658 | 658 | return "Error while uploading xml to fritzbox"; |
@@ -661,10 +661,10 @@ discard block |
||
| 661 | 661 | public function upload_to_fb() |
| 662 | 662 | { |
| 663 | 663 | // if the user wants to save the xml to a separate file, we do so now |
| 664 | - if(array_key_exists('output_file',$this->config)) |
|
| 664 | + if (array_key_exists('output_file', $this->config)) |
|
| 665 | 665 | { |
| 666 | 666 | $output = fopen($this->config['output_file'], 'w'); |
| 667 | - if($output) |
|
| 667 | + if ($output) |
|
| 668 | 668 | { |
| 669 | 669 | fwrite($output, $this->fbxml); |
| 670 | 670 | fclose($output); |
@@ -679,24 +679,24 @@ discard block |
||
| 679 | 679 | // perform an ftps-connection to copy over the photos to a specified directory |
| 680 | 680 | $ftp_server = $this->config['fritzbox_ip_ftp']; |
| 681 | 681 | $conn_id = ftp_ssl_connect($ftp_server); |
| 682 | - if($conn_id == false) |
|
| 682 | + if ($conn_id == false) |
|
| 683 | 683 | { |
| 684 | 684 | print " WARNING: Secure connection to FTP-server '" . $ftp_server . "' failed, retrying without SSL." . PHP_EOL; |
| 685 | 685 | $conn_id = ftp_connect($ftp_server); |
| 686 | 686 | } |
| 687 | 687 | |
| 688 | - if($conn_id != false) |
|
| 688 | + if ($conn_id != false) |
|
| 689 | 689 | { |
| 690 | 690 | ftp_set_option($conn_id, FTP_TIMEOUT_SEC, 60); |
| 691 | 691 | $login_result = ftp_login($conn_id, $this->config['fritzbox_user'], $this->config['fritzbox_pw']); |
| 692 | - if($login_result === true) |
|
| 692 | + if ($login_result === true) |
|
| 693 | 693 | { |
| 694 | 694 | ftp_pasv($conn_id, true); |
| 695 | 695 | |
| 696 | 696 | // create remote photo path on FRITZ!Box if it doesn't exist |
| 697 | - $remote_path = $this->config['usb_disk']."/FRITZ/fonpix"; |
|
| 697 | + $remote_path = $this->config['usb_disk'] . "/FRITZ/fonpix"; |
|
| 698 | 698 | $all_existing_files = ftp_nlist($conn_id, $remote_path); |
| 699 | - if($all_existing_files == false) |
|
| 699 | + if ($all_existing_files == false) |
|
| 700 | 700 | { |
| 701 | 701 | ftp_mkdir($conn_id, $remote_path); |
| 702 | 702 | $all_existing_files = array(); |
@@ -704,43 +704,43 @@ discard block |
||
| 704 | 704 | |
| 705 | 705 | // now iterate through all jpg files in tempdir and upload them if necessary |
| 706 | 706 | $dir = new DirectoryIterator($this->tmpdir); |
| 707 | - foreach($dir as $fileinfo) |
|
| 707 | + foreach ($dir as $fileinfo) |
|
| 708 | 708 | { |
| 709 | - if(!$fileinfo->isDot()) |
|
| 709 | + if (!$fileinfo->isDot()) |
|
| 710 | 710 | { |
| 711 | - if($fileinfo->getExtension() == "jpg") |
|
| 711 | + if ($fileinfo->getExtension() == "jpg") |
|
| 712 | 712 | { |
| 713 | 713 | $file = $fileinfo->getFilename(); |
| 714 | 714 | |
| 715 | 715 | print " FTP-Upload '" . $file . "'..."; |
| 716 | - if(!in_array($remote_path . "/" . $file, $all_existing_files)) |
|
| 716 | + if (!in_array($remote_path . "/" . $file, $all_existing_files)) |
|
| 717 | 717 | { |
| 718 | - if(!ftp_put($conn_id, $remote_path . "/" . $file, $fileinfo->getPathname(), FTP_BINARY)) |
|
| 718 | + if (!ftp_put($conn_id, $remote_path . "/" . $file, $fileinfo->getPathname(), FTP_BINARY)) |
|
| 719 | 719 | { |
| 720 | 720 | // retry when a fault occurs. |
| 721 | 721 | print " retrying... "; |
| 722 | 722 | $conn_id = ftp_ssl_connect($ftp_server); |
| 723 | - if($conn_id == false) |
|
| 723 | + if ($conn_id == false) |
|
| 724 | 724 | { |
| 725 | 725 | print " WARNING: Secure re-connection to FTP-server '" . $ftp_server . "' failed, retrying without SSL." . PHP_EOL; |
| 726 | 726 | $conn_id = ftp_connect($ftp_server); |
| 727 | 727 | } |
| 728 | 728 | |
| 729 | - if($conn_id == false) |
|
| 729 | + if ($conn_id == false) |
|
| 730 | 730 | { |
| 731 | 731 | print " ERROR: couldn't re-connect to FTP server '" . $ftp_server . "', abortіng." . PHP_EOL; |
| 732 | 732 | break; |
| 733 | 733 | } |
| 734 | 734 | |
| 735 | 735 | $login_result = ftp_login($conn_id, $this->config['fritzbox_user'], $this->config['fritzbox_pw']); |
| 736 | - if($login_result === false) |
|
| 736 | + if ($login_result === false) |
|
| 737 | 737 | { |
| 738 | 738 | print " ERROR: couldn't re-login to FTP-server '" . $ftp_server . "' with provided username/password settings." . PHP_EOL; |
| 739 | 739 | break; |
| 740 | 740 | } |
| 741 | 741 | |
| 742 | 742 | ftp_pasv($conn_id, true); |
| 743 | - if(!ftp_put($conn_id, $remote_path . "/" . $file, $fileinfo->getPathname(), FTP_BINARY)) |
|
| 743 | + if (!ftp_put($conn_id, $remote_path . "/" . $file, $fileinfo->getPathname(), FTP_BINARY)) |
|
| 744 | 744 | print " ERROR: while uploading file " . $fileinfo->getFilename() . PHP_EOL; |
| 745 | 745 | else |
| 746 | 746 | print " ok." . PHP_EOL; |
@@ -749,9 +749,9 @@ discard block |
||
| 749 | 749 | print " ok." . PHP_EOL; |
| 750 | 750 | |
| 751 | 751 | // cleanup old files |
| 752 | - foreach($all_existing_files as $existing_file) |
|
| 752 | + foreach ($all_existing_files as $existing_file) |
|
| 753 | 753 | { |
| 754 | - if(strpos($existing_file, $remote_path."/".substr($file, 0, -10)) !== false) |
|
| 754 | + if (strpos($existing_file, $remote_path . "/" . substr($file, 0, -10)) !== false) |
|
| 755 | 755 | { |
| 756 | 756 | print " FTP-Delete: " . $existing_file . PHP_EOL; |
| 757 | 757 | ftp_delete($conn_id, $remote_path . "/" . basename($existing_file)); |
@@ -775,14 +775,14 @@ discard block |
||
| 775 | 775 | |
| 776 | 776 | // 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 | 777 | $hostname = $this->config['fritzbox_ip']; |
| 778 | - if(filter_var($hostname, FILTER_VALIDATE_IP)) |
|
| 778 | + if (filter_var($hostname, FILTER_VALIDATE_IP)) |
|
| 779 | 779 | { |
| 780 | 780 | $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; |
|
| 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 | 783 | else |
| 784 | 784 | { |
| 785 | - print " INFO: Given IP address (". $this->config['fritzbox_ip'] .") has hostname ". $hostname . "." . PHP_EOL; |
|
| 785 | + print " INFO: Given IP address (" . $this->config['fritzbox_ip'] . ") has hostname " . $hostname . "." . PHP_EOL; |
|
| 786 | 786 | $this->config['fritzbox_ip'] = $hostname; |
| 787 | 787 | } |
| 788 | 788 | } |
@@ -807,15 +807,15 @@ discard block |
||
| 807 | 807 | ) |
| 808 | 808 | ); |
| 809 | 809 | |
| 810 | - $raw_result = $fritz->doPostFile($formfields, $filefileds); // send the command |
|
| 810 | + $raw_result = $fritz->doPostFile($formfields, $filefileds); // send the command |
|
| 811 | 811 | $msg = $this->_parse_fb_result($raw_result); |
| 812 | - unset($fritz); // destroy the object to log out |
|
| 812 | + unset($fritz); // destroy the object to log out |
|
| 813 | 813 | |
| 814 | 814 | print " FRITZ!Box returned message: '" . $msg . "'" . PHP_EOL; |
| 815 | 815 | } |
| 816 | - catch(Exception $e) |
|
| 816 | + catch (Exception $e) |
|
| 817 | 817 | { |
| 818 | - print " ERROR: " . $e->getMessage() . PHP_EOL; // show the error message in anything failed |
|
| 818 | + print " ERROR: " . $e->getMessage() . PHP_EOL; // show the error message in anything failed |
|
| 819 | 819 | } |
| 820 | 820 | } |
| 821 | 821 | } |
@@ -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 | } |
@@ -94,7 +94,7 @@ |
||
| 94 | 94 | preg_match('@name="guest_enabled"[^>]+(checked)[^>]*@', $output, $matches); |
| 95 | 95 | if ( isset($matches[1]) && $mode == true ) |
| 96 | 96 | { |
| 97 | - $message .= 'LAN4 guest access is now active.'; |
|
| 97 | + $message .= 'LAN4 guest access is now active.'; |
|
| 98 | 98 | } |
| 99 | 99 | else if ( !isset($matches[1]) && $mode == false ) |
| 100 | 100 | { |
@@ -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,19 +92,19 @@ 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 | } |
@@ -115,7 +115,7 @@ discard block |
||
| 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 | } |
@@ -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 | } |
@@ -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 | } |
@@ -21,11 +21,11 @@ |
||
| 21 | 21 | |
| 22 | 22 | // delete calllist form fields |
| 23 | 23 | $formfields = array( |
| 24 | - 'getpage' => '/fon_num/foncalls_list.lua', |
|
| 25 | - 'usejournal' => '1', |
|
| 26 | - 'callstab' => 'all', |
|
| 27 | - 'submit' => 'clear', |
|
| 28 | - 'clear' => '1', |
|
| 24 | + 'getpage' => '/fon_num/foncalls_list.lua', |
|
| 25 | + 'usejournal' => '1', |
|
| 26 | + 'callstab' => 'all', |
|
| 27 | + 'submit' => 'clear', |
|
| 28 | + 'clear' => '1', |
|
| 29 | 29 | ); |
| 30 | 30 | |
| 31 | 31 | $fritz->doPostForm($formfields); |
@@ -44,7 +44,7 @@ |
||
| 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 | } |
@@ -54,8 +54,7 @@ discard block |
||
| 54 | 54 | |
| 55 | 55 | // set a log message |
| 56 | 56 | $message .= 'Call list sucessfully downloaded'; |
| 57 | -} |
|
| 58 | -catch (Exception $e) |
|
| 57 | +} catch (Exception $e) |
|
| 59 | 58 | { |
| 60 | 59 | $message .= $e->getMessage(); |
| 61 | 60 | } |
@@ -64,8 +63,7 @@ discard block |
||
| 64 | 63 | if ( isset($fritz) && is_object($fritz) && get_class($fritz) == 'fritzbox_api' ) |
| 65 | 64 | { |
| 66 | 65 | $fritz->logMessage($message); |
| 67 | -} |
|
| 68 | -else |
|
| 66 | +} else |
|
| 69 | 67 | { |
| 70 | 68 | echo($message); |
| 71 | 69 | } |
@@ -44,7 +44,7 @@ |
||
| 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 | } |
@@ -54,8 +54,7 @@ discard block |
||
| 54 | 54 | |
| 55 | 55 | // set a log message |
| 56 | 56 | $message .= 'Call list sucessfully downloaded'; |
| 57 | -} |
|
| 58 | -catch (Exception $e) |
|
| 57 | +} catch (Exception $e) |
|
| 59 | 58 | { |
| 60 | 59 | $message .= $e->getMessage(); |
| 61 | 60 | } |
@@ -64,8 +63,7 @@ discard block |
||
| 64 | 63 | if ( isset($fritz) && is_object($fritz) && get_class($fritz) == 'fritzbox_api' ) |
| 65 | 64 | { |
| 66 | 65 | $fritz->logMessage($message); |
| 67 | -} |
|
| 68 | -else |
|
| 66 | +} else |
|
| 69 | 67 | { |
| 70 | 68 | echo($message); |
| 71 | 69 | } |
@@ -106,11 +106,11 @@ |
||
| 106 | 106 | preg_match('@name="activate_guest_access"[^>]+(checked)[^>]*@', $output, $matches); |
| 107 | 107 | if ( isset($matches[1]) && $mode == true ) |
| 108 | 108 | { |
| 109 | - preg_match('@name="wpa_key"[^>]+value="([^"]*)"[^>]*@', $output, $matches); |
|
| 110 | - if ( isset($matches[1]) ) |
|
| 111 | - { |
|
| 112 | - $message .= 'WLAN guest access is now active. WPA-Key is "' . $matches[1] . '"'; |
|
| 113 | - } |
|
| 109 | + preg_match('@name="wpa_key"[^>]+value="([^"]*)"[^>]*@', $output, $matches); |
|
| 110 | + if ( isset($matches[1]) ) |
|
| 111 | + { |
|
| 112 | + $message .= 'WLAN guest access is now active. WPA-Key is "' . $matches[1] . '"'; |
|
| 113 | + } |
|
| 114 | 114 | } |
| 115 | 115 | else if ( !isset($matches[1]) && $mode == false ) |
| 116 | 116 | { |
@@ -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,23 +104,23 @@ 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 | } |
@@ -131,7 +131,7 @@ discard block |
||
| 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 | } |
@@ -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 | } |
@@ -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 |
@@ -97,7 +97,7 @@ discard block |
||
| 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 | } |
@@ -28,8 +28,7 @@ discard block |
||
| 28 | 28 | if (isset($argv[1]) && ($argv[1] == 0 || $argv[1] == 1) ) |
| 29 | 29 | { |
| 30 | 30 | $mode = (int)$argv[1]; |
| 31 | - } |
|
| 32 | - else |
|
| 31 | + } else |
|
| 33 | 32 | { |
| 34 | 33 | if ( $fritz->config->getItem('logging') == 'console' ) |
| 35 | 34 | { |
@@ -51,8 +50,7 @@ discard block |
||
| 51 | 50 | Warning: A non existent TAM will not lead to an error message but adds a |
| 52 | 51 | new TAM to the Fritz!Box, which will answer all incoming calls by default! |
| 53 | 52 | '; |
| 54 | - } |
|
| 55 | - else |
|
| 53 | + } else |
|
| 56 | 54 | { |
| 57 | 55 | $fritz->logMessage($message . 'ERROR: Script was called without or with an invalid argument'); |
| 58 | 56 | } |
@@ -81,17 +79,14 @@ discard block |
||
| 81 | 79 | if (isset($matches[1]) && $matches[1] == $mode) |
| 82 | 80 | { |
| 83 | 81 | $message .= $mode == 1 ? 'TAM' . $tam . ' enabled' : 'TAM' . $tam . ' disabled'; |
| 84 | - } |
|
| 85 | - else if (isset($matches[1])) |
|
| 82 | + } else if (isset($matches[1])) |
|
| 86 | 83 | { |
| 87 | 84 | $message .= 'ERROR: TAM' . $tam . ' status change failed, should be ' . $mode . ', but is ' . $matches[1]; |
| 88 | - } |
|
| 89 | - else |
|
| 85 | + } else |
|
| 90 | 86 | { |
| 91 | 87 | $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 | 88 | } |
| 93 | -} |
|
| 94 | -catch (Exception $e) |
|
| 89 | +} catch (Exception $e) |
|
| 95 | 90 | { |
| 96 | 91 | $message .= $e->getMessage(); |
| 97 | 92 | } |
@@ -100,8 +95,7 @@ discard block |
||
| 100 | 95 | if ( isset($fritz) && is_object($fritz) && get_class($fritz) == 'fritzbox_api' ) |
| 101 | 96 | { |
| 102 | 97 | $fritz->logMessage($message); |
| 103 | -} |
|
| 104 | -else |
|
| 98 | +} else |
|
| 105 | 99 | { |
| 106 | 100 | echo($message); |
| 107 | 101 | } |