GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Passed
Push — master ( c2bf29...11c7a3 )
by Jens
05:50 queued 03:00
created
lib/fritzbox_api_php/fritzbox_api.class.php 2 patches
Indentation   +144 added lines, -144 removed lines patch added patch discarded remove patch
@@ -48,70 +48,70 @@  discard block
 block discarded – undo
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
 block discarded – undo
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,23 +147,23 @@  discard block
 block discarded – undo
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_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_CAPATH, '/etc/ssl/certs');
162 162
 
163
-		// support for pre FRITZ!OS 5.50 remote config
164
-		if (!$this->config->getItem('use_lua_login_method')){
165
-		curl_setopt($ch, CURLOPT_USERPWD, $this->config->getItem('remote_config_user') . ':' . $this->config->getItem('remote_config_password'));
166
-		}
163
+    // support for pre FRITZ!OS 5.50 remote config
164
+    if (!$this->config->getItem('use_lua_login_method')){
165
+    curl_setopt($ch, CURLOPT_USERPWD, $this->config->getItem('remote_config_user') . ':' . $this->config->getItem('remote_config_password'));
166
+    }
167 167
     }
168 168
     curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($formfields));
169 169
     $output = curl_exec($ch);
@@ -178,10 +178,10 @@  discard block
 block discarded – undo
178 178
     // add the sid, if it is already set
179 179
     if ($this->sid != '0000000000000000')
180 180
     {
181
-		// 'sid' MUST be the first POST variable!!! (otherwise it will not work!!)
182
-		// therfore we use array_merge to ensuere the foreach outputs 'sid' fist
183
-		$formfields = array_merge(array('sid' => $this->sid), $formfields);
184
-		//$formfields['sid'] = $this->sid;
181
+    // 'sid' MUST be the first POST variable!!! (otherwise it will not work!!)
182
+    // therfore we use array_merge to ensuere the foreach outputs 'sid' fist
183
+    $formfields = array_merge(array('sid' => $this->sid), $formfields);
184
+    //$formfields['sid'] = $this->sid;
185 185
     }   
186 186
     curl_setopt($ch, CURLOPT_URL, $this->config->getItem('fritzbox_url') . '/cgi-bin/firmwarecfg'); 
187 187
     curl_setopt($ch, CURLOPT_POST, 1);
@@ -192,30 +192,30 @@  discard block
 block discarded – undo
192 192
     
193 193
     // if filefileds not specified ('@/path/to/file.xml;type=text/xml' works fine)
194 194
     if(empty( $filefileds )) {
195
-		curl_setopt($ch, CURLOPT_POSTFIELDS, $formfields); // http_build_query
196
-	} 
197
-	// post calculated raw data
198
-	else {
199
-		$header = $this->_create_custom_file_post_header($formfields, $filefileds);
200
-		curl_setopt($ch, CURLOPT_HTTPHEADER , array(
201
-			'Content-Type: multipart/form-data; boundary=' . $header['delimiter'], 'Content-Length: ' . strlen($header['data']) )
202
-			);
195
+    curl_setopt($ch, CURLOPT_POSTFIELDS, $formfields); // http_build_query
196
+  } 
197
+  // post calculated raw data
198
+  else {
199
+    $header = $this->_create_custom_file_post_header($formfields, $filefileds);
200
+    curl_setopt($ch, CURLOPT_HTTPHEADER , array(
201
+      'Content-Type: multipart/form-data; boundary=' . $header['delimiter'], 'Content-Length: ' . strlen($header['data']) )
202
+      );
203 203
 			
204
-		curl_setopt($ch, CURLOPT_POSTFIELDS, $header['data']);		
205
-	}
204
+    curl_setopt($ch, CURLOPT_POSTFIELDS, $header['data']);		
205
+  }
206 206
 	
207 207
     $output = curl_exec($ch);
208 208
 
209
-	// curl error
210
-	if(curl_errno($ch)) {
211
-		$this->error(curl_error($ch)." (".curl_errno($ch).")");
212
-	}
209
+  // curl error
210
+  if(curl_errno($ch)) {
211
+    $this->error(curl_error($ch)." (".curl_errno($ch).")");
212
+  }
213 213
 
214 214
     // finger out an error message, if given
215 215
     preg_match('@<p class="ErrorMsg">(.*?)</p>@is', $output, $matches);
216 216
     if (isset($matches[1]))
217 217
     {
218
-		$this->error(str_replace('&nbsp;', ' ', $matches[1]));
218
+    $this->error(str_replace('&nbsp;', ' ', $matches[1]));
219 219
     }
220 220
 
221 221
     curl_close($ch);
@@ -223,10 +223,10 @@  discard block
 block discarded – undo
223 223
   }
224 224
 
225 225
   private function _create_custom_file_post_header($postFields, $fileFields) {
226
-		// form field separator
227
-		$delimiter = '-------------' . uniqid();
226
+    // form field separator
227
+    $delimiter = '-------------' . uniqid();
228 228
 		
229
-		/*
229
+    /*
230 230
 		// file upload fields: name => array(type=>'mime/type',content=>'raw data')
231 231
 		$fileFields = array(
232 232
 			'file1' => array(
@@ -241,44 +241,44 @@  discard block
 block discarded – undo
241 241
 		);
242 242
 		*/
243 243
 		
244
-		$data = '';
244
+    $data = '';
245 245
 
246
-		// populate normal fields first (simpler)
247
-		foreach ($postFields as $name => $content) {
248
-		   $data .= "--" . $delimiter . "\r\n";
249
-			$data .= 'Content-Disposition: form-data; name="' . urlencode($name) . '"';
250
-			$data .= "\r\n\r\n";
251
-			$data .= $content;
252
-			$data .= "\r\n";
253
-		}
254
-		// populate file fields
255
-		foreach ($fileFields as $name => $file) {
256
-			$data .= "--" . $delimiter . "\r\n";
257
-			// "filename" attribute is not essential; server-side scripts may use it
258
-			$data .= 'Content-Disposition: form-data; name="' . urlencode($name) . '";' .
259
-					 ' filename="' . $file['filename'] . '"' . "\r\n";
246
+    // populate normal fields first (simpler)
247
+    foreach ($postFields as $name => $content) {
248
+        $data .= "--" . $delimiter . "\r\n";
249
+      $data .= 'Content-Disposition: form-data; name="' . urlencode($name) . '"';
250
+      $data .= "\r\n\r\n";
251
+      $data .= $content;
252
+      $data .= "\r\n";
253
+    }
254
+    // populate file fields
255
+    foreach ($fileFields as $name => $file) {
256
+      $data .= "--" . $delimiter . "\r\n";
257
+      // "filename" attribute is not essential; server-side scripts may use it
258
+      $data .= 'Content-Disposition: form-data; name="' . urlencode($name) . '";' .
259
+            ' filename="' . $file['filename'] . '"' . "\r\n";
260 260
 					 
261
-			//$data .= 'Content-Transfer-Encoding: binary'."\r\n";
262
-			// this is, again, informative only; good practice to include though
263
-			$data .= 'Content-Type: ' . $file['type'] . "\r\n";
264
-			// this endline must be here to indicate end of headers
265
-			$data .= "\r\n";
266
-			// the file itself (note: there's no encoding of any kind)
267
-			$data .= $file['content'] . "\r\n";
268
-		}
269
-		// last delimiter
270
-		$data .= "--" . $delimiter . "--\r\n";
261
+      //$data .= 'Content-Transfer-Encoding: binary'."\r\n";
262
+      // this is, again, informative only; good practice to include though
263
+      $data .= 'Content-Type: ' . $file['type'] . "\r\n";
264
+      // this endline must be here to indicate end of headers
265
+      $data .= "\r\n";
266
+      // the file itself (note: there's no encoding of any kind)
267
+      $data .= $file['content'] . "\r\n";
268
+    }
269
+    // last delimiter
270
+    $data .= "--" . $delimiter . "--\r\n";
271 271
 	
272
-		return array('delimiter' => $delimiter, 'data' => $data);
273
-	}
272
+    return array('delimiter' => $delimiter, 'data' => $data);
273
+  }
274 274
   
275 275
   /**
276
-    * do a GET request on the box
277
-    * the main cURL wrapper handles the command
278
-    * 
279
-    * @param  array  $params    an associative array with the GET params to pass
280
-    * @return string            the raw HTML code returned by the Fritz!Box
281
-    */
276
+   * do a GET request on the box
277
+   * the main cURL wrapper handles the command
278
+   * 
279
+   * @param  array  $params    an associative array with the GET params to pass
280
+   * @return string            the raw HTML code returned by the Fritz!Box
281
+   */
282 282
   public function doGetRequest($params = array())
283 283
   {
284 284
     // add the sid, if it is already set
@@ -318,12 +318,12 @@  discard block
 block discarded – undo
318 318
   
319 319
   
320 320
   /**
321
-    * the login method, handles the secured login-process
322
-    * newer firmwares (xx.04.74 and newer) need a challenge-response mechanism to prevent Cross-Site Request Forgery attacks
323
-    * see http://www.avm.de/de/Extern/Technical_Note_Session_ID.pdf for details
324
-    * 
325
-    * @return string                a valid SID, if the login was successful, otherwise throws an Exception with an error message
326
-    */
321
+   * the login method, handles the secured login-process
322
+   * newer firmwares (xx.04.74 and newer) need a challenge-response mechanism to prevent Cross-Site Request Forgery attacks
323
+   * see http://www.avm.de/de/Extern/Technical_Note_Session_ID.pdf for details
324
+   * 
325
+   * @return string                a valid SID, if the login was successful, otherwise throws an Exception with an error message
326
+   */
327 327
   protected function initSID()
328 328
   {
329 329
     // determine, wich login type we have to use
@@ -403,9 +403,9 @@  discard block
 block discarded – undo
403 403
   
404 404
   
405 405
   /**
406
-    * the logout method just sends a logout command to the Fritz!Box
407
-    * 
408
-    */
406
+   * the logout method just sends a logout command to the Fritz!Box
407
+   * 
408
+   */
409 409
   protected function logout()
410 410
   {
411 411
     if ( $this->config->getItem('use_lua_login_method') == true )
@@ -424,10 +424,10 @@  discard block
 block discarded – undo
424 424
   
425 425
   
426 426
   /**
427
-    * the error method just throws an Exception
428
-    * 
429
-    * @param  string   $message     an error message for the Exception
430
-    */
427
+   * the error method just throws an Exception
428
+   * 
429
+   * @param  string   $message     an error message for the Exception
430
+   */
431 431
   public function error($message = null)
432 432
   {
433 433
     throw new Exception($message);
@@ -435,20 +435,20 @@  discard block
 block discarded – undo
435 435
   
436 436
   
437 437
   /**
438
-    * a getter for the session ID
439
-    * 
440
-    * @return string                $this->sid
441
-    */
438
+   * a getter for the session ID
439
+   * 
440
+   * @return string                $this->sid
441
+   */
442 442
   public function getSID()
443 443
   {
444 444
     return $this->sid;
445 445
   }
446 446
   
447 447
   /**
448
-    * log a message
449
-    * 
450
-    * @param  $message  string  the message to log
451
-    */
448
+   * log a message
449
+   * 
450
+   * @param  $message  string  the message to log
451
+   */
452 452
   public function logMessage($message)
453 453
   {
454 454
     if ( $this->config->getItem('newline') == false )
Please login to merge, or discard this patch.
Spacing   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -63,39 +63,39 @@  discard block
 block discarded – undo
63 63
     * 
64 64
     * @access public
65 65
     */
66
-  public function __construct($password = false,$user_name = false,$fritzbox_ip = 'fritz.box',$force_local_login = false)
66
+  public function __construct($password = false, $user_name = false, $fritzbox_ip = 'fritz.box', $force_local_login = false)
67 67
   {
68 68
 	// init the config object
69 69
 	$this->config = new fritzbox_api_config();
70 70
     
71 71
 	// try autoloading the config
72
-	if (file_exists(__DIR__ . '/fritzbox_user.conf.php') && is_readable(__DIR__ . '/fritzbox_user.conf.php') ) {
72
+	if(file_exists(__DIR__ . '/fritzbox_user.conf.php') && is_readable(__DIR__ . '/fritzbox_user.conf.php')) {
73 73
 		require_once(__DIR__ . '/fritzbox_user.conf.php');
74 74
 	}
75 75
 
76 76
 	// set FRITZ!Box-IP and URL
77
-	$this->config->setItem('fritzbox_ip',$fritzbox_ip);
77
+	$this->config->setItem('fritzbox_ip', $fritzbox_ip);
78 78
 
79 79
 	// check if login on local network (fritz.box) or via a dynamic DNS-host
80
-	if ($fritzbox_ip != 'fritz.box' && !$force_local_login) {
81
-		$this->config->setItem('enable_remote_config',true);
82
-		$this->config->setItem('remote_config_user',$user_name);
83
-		$this->config->setItem('remote_config_password',$password);
84
-		$this->config->setItem('fritzbox_url', 'https://'.$this->config->getItem('fritzbox_ip'));
80
+	if($fritzbox_ip != 'fritz.box' && !$force_local_login) {
81
+		$this->config->setItem('enable_remote_config', true);
82
+		$this->config->setItem('remote_config_user', $user_name);
83
+		$this->config->setItem('remote_config_password', $password);
84
+		$this->config->setItem('fritzbox_url', 'https://' . $this->config->getItem('fritzbox_ip'));
85 85
 	} else {
86
-		$this->config->setItem('enable_remote_config',false);
87
-		if($user_name != false){
88
-			$this->config->setItem('username',$user_name);
86
+		$this->config->setItem('enable_remote_config', false);
87
+		if($user_name != false) {
88
+			$this->config->setItem('username', $user_name);
89 89
 		}
90
-		if($password != false){
91
-			$this->config->setItem('password',$password);
90
+		if($password != false) {
91
+			$this->config->setItem('password', $password);
92 92
 		}
93 93
 		$this->config->setItem('fritzbox_url', 'http://' . $this->config->getItem('fritzbox_ip'));
94 94
 	}
95 95
 
96 96
 	// make some config consistency checks
97
-	if ( $this->config->getItem('enable_remote_config') === true ){
98
-		if ( !$this->config->getItem('remote_config_user') || !$this->config->getItem('remote_config_password') ){
97
+	if($this->config->getItem('enable_remote_config') === true) {
98
+		if(!$this->config->getItem('remote_config_user') || !$this->config->getItem('remote_config_password')) {
99 99
 		  $this->error('ERROR: Remote config mode enabled, but no username or no password provided');
100 100
 		}
101 101
 	}
@@ -129,7 +129,7 @@  discard block
 block discarded – undo
129 129
   {
130 130
     $ch = curl_init();
131 131
 
132
-    if ( isset($formfields['getpage']) && strpos($formfields['getpage'], '.lua') > 0 )
132
+    if(isset($formfields['getpage']) && strpos($formfields['getpage'], '.lua') > 0)
133 133
     {
134 134
       curl_setopt($ch, CURLOPT_URL, $this->config->getItem('fritzbox_url') . $formfields['getpage'] . '?sid=' . $this->sid);
135 135
       unset($formfields['getpage']);
@@ -137,7 +137,7 @@  discard block
 block discarded – undo
137 137
     else
138 138
     {
139 139
       // add the sid, if it is already set
140
-      if ($this->sid != '0000000000000000')
140
+      if($this->sid != '0000000000000000')
141 141
       {
142 142
         $formfields['sid'] = $this->sid;
143 143
       }   
@@ -145,10 +145,10 @@  discard block
 block discarded – undo
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 {
@@ -161,7 +161,7 @@  discard block
 block discarded – undo
161 161
 		curl_setopt($ch, CURLOPT_CAPATH, '/etc/ssl/certs');
162 162
 
163 163
 		// support for pre FRITZ!OS 5.50 remote config
164
-		if (!$this->config->getItem('use_lua_login_method')){
164
+		if(!$this->config->getItem('use_lua_login_method')) {
165 165
 		curl_setopt($ch, CURLOPT_USERPWD, $this->config->getItem('remote_config_user') . ':' . $this->config->getItem('remote_config_password'));
166 166
 		}
167 167
     }
@@ -176,7 +176,7 @@  discard block
 block discarded – undo
176 176
     $ch = curl_init();
177 177
    
178 178
     // add the sid, if it is already set
179
-    if ($this->sid != '0000000000000000')
179
+    if($this->sid != '0000000000000000')
180 180
     {
181 181
 		// 'sid' MUST be the first POST variable!!! (otherwise it will not work!!)
182 182
 		// therfore we use array_merge to ensuere the foreach outputs 'sid' fist
@@ -191,13 +191,13 @@  discard block
 block discarded – undo
191 191
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
192 192
     
193 193
     // if filefileds not specified ('@/path/to/file.xml;type=text/xml' works fine)
194
-    if(empty( $filefileds )) {
194
+    if(empty($filefileds)) {
195 195
 		curl_setopt($ch, CURLOPT_POSTFIELDS, $formfields); // http_build_query
196 196
 	} 
197 197
 	// post calculated raw data
198 198
 	else {
199 199
 		$header = $this->_create_custom_file_post_header($formfields, $filefileds);
200
-		curl_setopt($ch, CURLOPT_HTTPHEADER , array(
200
+		curl_setopt($ch, CURLOPT_HTTPHEADER, array(
201 201
 			'Content-Type: multipart/form-data; boundary=' . $header['delimiter'], 'Content-Length: ' . strlen($header['data']) )
202 202
 			);
203 203
 			
@@ -208,12 +208,12 @@  discard block
 block discarded – undo
208 208
 
209 209
 	// curl error
210 210
 	if(curl_errno($ch)) {
211
-		$this->error(curl_error($ch)." (".curl_errno($ch).")");
211
+		$this->error(curl_error($ch) . " (" . curl_errno($ch) . ")");
212 212
 	}
213 213
 
214 214
     // finger out an error message, if given
215 215
     preg_match('@<p class="ErrorMsg">(.*?)</p>@is', $output, $matches);
216
-    if (isset($matches[1]))
216
+    if(isset($matches[1]))
217 217
     {
218 218
 		$this->error(str_replace('&nbsp;', ' ', $matches[1]));
219 219
     }
@@ -244,7 +244,7 @@  discard block
 block discarded – undo
244 244
 		$data = '';
245 245
 
246 246
 		// populate normal fields first (simpler)
247
-		foreach ($postFields as $name => $content) {
247
+		foreach($postFields as $name => $content) {
248 248
 		   $data .= "--" . $delimiter . "\r\n";
249 249
 			$data .= 'Content-Disposition: form-data; name="' . urlencode($name) . '"';
250 250
 			$data .= "\r\n\r\n";
@@ -252,7 +252,7 @@  discard block
 block discarded – undo
252 252
 			$data .= "\r\n";
253 253
 		}
254 254
 		// populate file fields
255
-		foreach ($fileFields as $name => $file) {
255
+		foreach($fileFields as $name => $file) {
256 256
 			$data .= "--" . $delimiter . "\r\n";
257 257
 			// "filename" attribute is not essential; server-side scripts may use it
258 258
 			$data .= 'Content-Disposition: form-data; name="' . urlencode($name) . '";' .
@@ -282,13 +282,13 @@  discard block
 block discarded – undo
282 282
   public function doGetRequest($params = array())
283 283
   {
284 284
     // add the sid, if it is already set
285
-    if ($this->sid != '0000000000000000')
285
+    if($this->sid != '0000000000000000')
286 286
     {
287 287
       $params['sid'] = $this->sid;
288 288
     }    
289 289
   
290 290
     $ch = curl_init();
291
-    if ( strpos($params['getpage'], '.lua') > 0 )
291
+    if(strpos($params['getpage'], '.lua') > 0)
292 292
     {
293 293
       $getpage = $params['getpage'] . '?';
294 294
       unset($params['getpage']);
@@ -300,13 +300,13 @@  discard block
 block discarded – undo
300 300
     curl_setopt($ch, CURLOPT_URL, $this->config->getItem('fritzbox_url') . $getpage . http_build_query($params));
301 301
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
302 302
     curl_setopt($ch, CURLOPT_HTTPGET, 1);
303
-    if ( $this->config->getItem('enable_remote_config') )
303
+    if($this->config->getItem('enable_remote_config'))
304 304
     {
305 305
       curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
306 306
       curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
307 307
 
308 308
       // support for pre FRITZ!OS 5.50 remote config
309
-      if ( !$this->config->getItem('use_lua_login_method') )
309
+      if(!$this->config->getItem('use_lua_login_method'))
310 310
       {
311 311
         curl_setopt($ch, CURLOPT_USERPWD, $this->config->getItem('remote_config_user') . ':' . $this->config->getItem('remote_config_password'));
312 312
       }
@@ -327,7 +327,7 @@  discard block
 block discarded – undo
327 327
   protected function initSID()
328 328
   {
329 329
     // determine, wich login type we have to use
330
-    if ( $this->config->getItem('use_lua_login_method') == true )
330
+    if($this->config->getItem('use_lua_login_method') == true)
331 331
     {
332 332
       $loginpage = '/login_sid.lua';
333 333
     }
@@ -339,13 +339,13 @@  discard block
 block discarded – undo
339 339
     // read the current status
340 340
     $session_status_simplexml = simplexml_load_string($this->doGetRequest(array('getpage' => $loginpage)));
341 341
     
342
-    if ( !is_object($session_status_simplexml) || get_class($session_status_simplexml) != 'SimpleXMLElement' )
342
+    if(!is_object($session_status_simplexml) || get_class($session_status_simplexml) != 'SimpleXMLElement')
343 343
     {
344 344
       $this->error('Response of initialization call ' . $loginpage . ' in ' . __FUNCTION__ . ' was not xml-formatted.');
345 345
     }
346 346
     
347 347
     // perhaps we already have a SID (i.e. when no password is set)
348
-    if ( $session_status_simplexml->SID != '0000000000000000' )
348
+    if($session_status_simplexml->SID != '0000000000000000')
349 349
     {
350 350
       return $session_status_simplexml->SID;
351 351
     }
@@ -359,16 +359,16 @@  discard block
 block discarded – undo
359 359
       $formfields = array(
360 360
         'getpage' => $loginpage,
361 361
       );
362
-      if ( $this->config->getItem('use_lua_login_method') )
362
+      if($this->config->getItem('use_lua_login_method'))
363 363
       {
364
-        if ( $this->config->getItem('enable_remote_config') )
364
+        if($this->config->getItem('enable_remote_config'))
365 365
         {
366 366
           $formfields['username'] = $this->config->getItem('remote_config_user');
367 367
           $response = $challenge . '-' . md5(mb_convert_encoding($challenge . '-' . $this->config->getItem('remote_config_password'), "UCS-2LE", "UTF-8"));
368 368
         }
369 369
         else
370 370
         {
371
-          if ( $this->config->getItem('username') )
371
+          if($this->config->getItem('username'))
372 372
           {
373 373
             $formfields['username'] = $this->config->getItem('username');
374 374
           }
@@ -385,12 +385,12 @@  discard block
 block discarded – undo
385 385
       
386 386
       // finger out the SID from the response
387 387
       $session_status_simplexml = simplexml_load_string($output);
388
-      if ( !is_object($session_status_simplexml) || get_class($session_status_simplexml) != 'SimpleXMLElement' )
388
+      if(!is_object($session_status_simplexml) || get_class($session_status_simplexml) != 'SimpleXMLElement')
389 389
       {
390 390
         $this->error('Response of login call to ' . $loginpage . ' in ' . __FUNCTION__ . ' was not xml-formatted.');
391 391
       }
392 392
       
393
-      if ( $session_status_simplexml->SID != '0000000000000000' )
393
+      if($session_status_simplexml->SID != '0000000000000000')
394 394
       {
395 395
         return (string)$session_status_simplexml->SID;
396 396
       }
@@ -408,7 +408,7 @@  discard block
 block discarded – undo
408 408
     */
409 409
   protected function logout()
410 410
   {
411
-    if ( $this->config->getItem('use_lua_login_method') == true )
411
+    if($this->config->getItem('use_lua_login_method') == true)
412 412
     {
413 413
       $this->doGetRequest(array('getpage' => '/home/home.lua', 'logout' => '1'));
414 414
     }
@@ -451,22 +451,22 @@  discard block
 block discarded – undo
451 451
     */
452 452
   public function logMessage($message)
453 453
   {
454
-    if ( $this->config->getItem('newline') == false )
454
+    if($this->config->getItem('newline') == false)
455 455
     {
456 456
       $this->config->setItem('newline', (PHP_OS == 'WINNT') ? "\r\n" : "\n");
457 457
     }
458 458
   
459
-    if ( $this->config->getItem('logging') == 'console' )
459
+    if($this->config->getItem('logging') == 'console')
460 460
     {
461 461
       echo $message;
462 462
     }
463
-    else if ( $this->config->getItem('logging') == 'silent' || $this->config->getItem('logging') == false )
463
+    else if($this->config->getItem('logging') == 'silent' || $this->config->getItem('logging') == false)
464 464
     {
465 465
       // do nothing
466 466
     }
467 467
     else
468 468
     {
469
-      if ( is_writable($this->config->getItem('logging')) || is_writable(dirname($this->config->getItem('logging'))) )
469
+      if(is_writable($this->config->getItem('logging')) || is_writable(dirname($this->config->getItem('logging'))))
470 470
       {
471 471
         file_put_contents($this->config->getItem('logging'), $message . $this->config->getItem('newline'), FILE_APPEND);
472 472
       }
@@ -516,11 +516,11 @@  discard block
 block discarded – undo
516 516
    */
517 517
   public function getItem($item = 'all')
518 518
   {
519
-    if ( $item == 'all' )
519
+    if($item == 'all')
520 520
     {
521 521
       return $this->config;
522 522
     }
523
-    elseif ( isset($this->config[$item]) )
523
+    elseif(isset($this->config[$item]))
524 524
     {
525 525
       return $this->config[$item];
526 526
     }
Please login to merge, or discard this patch.