@@ -55,11 +55,11 @@ discard block |
||
55 | 55 | // * Still work to do in this area, and new functions to write |
56 | 56 | |
57 | 57 | /** |
58 | - * Create a contact |
|
59 | - * |
|
60 | - * @param array $attributes The attributes to set to the contact |
|
61 | - * @return string|boolean |
|
62 | - */ |
|
58 | + * Create a contact |
|
59 | + * |
|
60 | + * @param array $attributes The attributes to set to the contact |
|
61 | + * @return string|boolean |
|
62 | + */ |
|
63 | 63 | public function create($attributes) { |
64 | 64 | // Check for compulsory fields |
65 | 65 | if (!array_key_exists("display_name", $attributes)) { return "Missing compulsory field [display_name]"; } |
@@ -93,12 +93,12 @@ discard block |
||
93 | 93 | } |
94 | 94 | |
95 | 95 | /** |
96 | - * Determine the list of groups a contact is a member of |
|
97 | - * |
|
98 | - * @param string $distinguishedName The full DN of a contact |
|
99 | - * @param bool $recursive Recursively check groups |
|
100 | - * @return array |
|
101 | - */ |
|
96 | + * Determine the list of groups a contact is a member of |
|
97 | + * |
|
98 | + * @param string $distinguishedName The full DN of a contact |
|
99 | + * @param bool $recursive Recursively check groups |
|
100 | + * @return array |
|
101 | + */ |
|
102 | 102 | public function groups($distinguishedName, $recursive = NULL) { |
103 | 103 | if ($distinguishedName === NULL) { return false; } |
104 | 104 | if ($recursive === NULL) { $recursive = $this->adldap->getRecursiveGroups(); } //use the default option if they haven't set it |
@@ -118,12 +118,12 @@ discard block |
||
118 | 118 | } |
119 | 119 | |
120 | 120 | /** |
121 | - * Get contact information. Returned in a raw array format from AD |
|
122 | - * |
|
123 | - * @param string $distinguishedName The full DN of a contact |
|
124 | - * @param array $fields Attributes to be returned |
|
125 | - * @return array |
|
126 | - */ |
|
121 | + * Get contact information. Returned in a raw array format from AD |
|
122 | + * |
|
123 | + * @param string $distinguishedName The full DN of a contact |
|
124 | + * @param array $fields Attributes to be returned |
|
125 | + * @return array |
|
126 | + */ |
|
127 | 127 | public function info($distinguishedName, $fields = NULL) |
128 | 128 | { |
129 | 129 | if ($distinguishedName === NULL) { return false; } |
@@ -195,12 +195,12 @@ discard block |
||
195 | 195 | } |
196 | 196 | |
197 | 197 | /** |
198 | - * Modify a contact |
|
199 | - * |
|
200 | - * @param string $distinguishedName The contact to query |
|
201 | - * @param array $attributes The attributes to modify. Note if you set the enabled attribute you must not specify any other attributes |
|
202 | - * @return string|boolean |
|
203 | - */ |
|
198 | + * Modify a contact |
|
199 | + * |
|
200 | + * @param string $distinguishedName The contact to query |
|
201 | + * @param array $attributes The attributes to modify. Note if you set the enabled attribute you must not specify any other attributes |
|
202 | + * @return string|boolean |
|
203 | + */ |
|
204 | 204 | public function modify($distinguishedName, $attributes) { |
205 | 205 | if ($distinguishedName === NULL) { return "Missing compulsory field [distinguishedname]"; } |
206 | 206 | |
@@ -221,11 +221,11 @@ discard block |
||
221 | 221 | } |
222 | 222 | |
223 | 223 | /** |
224 | - * Delete a contact |
|
225 | - * |
|
226 | - * @param string $distinguishedName The contact dn to delete (please be careful here!) |
|
227 | - * @return boolean |
|
228 | - */ |
|
224 | + * Delete a contact |
|
225 | + * |
|
226 | + * @param string $distinguishedName The contact dn to delete (please be careful here!) |
|
227 | + * @return boolean |
|
228 | + */ |
|
229 | 229 | public function delete($distinguishedName) { |
230 | 230 | $result = $this->folder()->delete($distinguishedName); |
231 | 231 | if ($result != true) { |
@@ -268,14 +268,14 @@ discard block |
||
268 | 268 | } |
269 | 269 | |
270 | 270 | /** |
271 | - * Mail enable a contact |
|
272 | - * Allows email to be sent to them through Exchange |
|
273 | - * |
|
274 | - * @param string $distinguishedName The contact to mail enable |
|
275 | - * @param string $emailAddress The email address to allow emails to be sent through |
|
276 | - * @param string $mailNickname The mailnickname for the contact in Exchange. If NULL this will be set to the display name |
|
277 | - * @return string|boolean |
|
278 | - */ |
|
271 | + * Mail enable a contact |
|
272 | + * Allows email to be sent to them through Exchange |
|
273 | + * |
|
274 | + * @param string $distinguishedName The contact to mail enable |
|
275 | + * @param string $emailAddress The email address to allow emails to be sent through |
|
276 | + * @param string $mailNickname The mailnickname for the contact in Exchange. If NULL this will be set to the display name |
|
277 | + * @return string|boolean |
|
278 | + */ |
|
279 | 279 | public function contactMailEnable($distinguishedName, $emailAddress, $mailNickname = NULL) { |
280 | 280 | return $this->adldap->exchange()->contactMailEnable($distinguishedName, $emailAddress, $mailNickname); |
281 | 281 | } |
@@ -96,13 +96,13 @@ |
||
96 | 96 | } |
97 | 97 | |
98 | 98 | /** |
99 | - * Check if a computer is in a group |
|
100 | - * |
|
101 | - * @param string $computerName The name of the computer |
|
102 | - * @param string $group The group to check |
|
103 | - * @param bool $recursive Whether to check recursively |
|
104 | - * @return boolean |
|
105 | - */ |
|
99 | + * Check if a computer is in a group |
|
100 | + * |
|
101 | + * @param string $computerName The name of the computer |
|
102 | + * @param string $group The group to check |
|
103 | + * @param bool $recursive Whether to check recursively |
|
104 | + * @return boolean |
|
105 | + */ |
|
106 | 106 | public function inGroup($computerName, $group, $recursive = NULL) { |
107 | 107 | if ($computerName === NULL) { return false; } |
108 | 108 | if ($group === NULL) { return false; } |
@@ -129,14 +129,14 @@ |
||
129 | 129 | public function groups($computerName, $recursive = NULL) { |
130 | 130 | if ($computerName === NULL) { return false; } |
131 | 131 | if ($recursive === NULL) { $recursive = $this->adldap->getRecursiveGroups(); } //use the default option if they haven't set it |
132 | - if (!$this->adldap->getLdapBind()){ return false; } |
|
132 | + if (!$this->adldap->getLdapBind()) { return false; } |
|
133 | 133 | |
134 | 134 | //search the directory for their information |
135 | 135 | $info = @$this->info($computerName, array("memberof", "primarygroupid")); |
136 | 136 | $groups = $this->adldap->utilities()->niceNames($info[0]["memberof"]); //presuming the entry returned is our guy (unique usernames) |
137 | 137 | |
138 | 138 | if ($recursive === true) { |
139 | - foreach ($groups as $id => $groupName){ |
|
139 | + foreach ($groups as $id => $groupName) { |
|
140 | 140 | $extraGroups = $this->adldap->group()->recursiveGroups($groupName); |
141 | 141 | $groups = array_merge($groups, $extraGroups); |
142 | 142 | } |
@@ -140,11 +140,11 @@ |
||
140 | 140 | } |
141 | 141 | |
142 | 142 | /** |
143 | - * Create an organizational unit |
|
144 | - * |
|
145 | - * @param array $attributes Default attributes of the ou |
|
146 | - * @return string|boolean |
|
147 | - */ |
|
143 | + * Create an organizational unit |
|
144 | + * |
|
145 | + * @param array $attributes Default attributes of the ou |
|
146 | + * @return string|boolean |
|
147 | + */ |
|
148 | 148 | public function create($attributes) { |
149 | 149 | if (!is_array($attributes)) { return "Attributes must be an array"; } |
150 | 150 | if (!is_array($attributes["container"])) { return "Container attribute must be an array."; } |
@@ -118,8 +118,7 @@ |
||
118 | 118 | $ou = $dnType."=".implode(",".$dnType."=", $folderName); |
119 | 119 | $filter .= '(!(distinguishedname='.$ou.','.$this->adldap->getBaseDn().')))'; |
120 | 120 | $searchOu = $ou.','.$this->adldap->getBaseDn(); |
121 | - } |
|
122 | - else { |
|
121 | + } else { |
|
123 | 122 | $filter .= '(!(distinguishedname='.$this->adldap->getBaseDn().')))'; |
124 | 123 | } |
125 | 124 |
@@ -312,27 +312,27 @@ discard block |
||
312 | 312 | array_unshift($args, $table); |
313 | 313 | array_unshift($args, $query); |
314 | 314 | return call_user_func_array(array($this, 'query'), $args); |
315 | - } |
|
315 | + } |
|
316 | 316 | |
317 | - /** |
|
318 | - * @param string $which |
|
319 | - */ |
|
320 | - public function insertOrReplace($which, $table, $datas, $options=array()) { |
|
317 | + /** |
|
318 | + * @param string $which |
|
319 | + */ |
|
320 | + public function insertOrReplace($which, $table, $datas, $options=array()) { |
|
321 | 321 | $datas = unserialize(serialize($datas)); // break references within array |
322 | 322 | $keys = $values = array(); |
323 | 323 | |
324 | 324 | if (isset($datas[0]) && is_array($datas[0])) { |
325 | - foreach ($datas as $datum) { |
|
325 | + foreach ($datas as $datum) { |
|
326 | 326 | ksort($datum); |
327 | 327 | if (! $keys) { |
328 | 328 | $keys = array_keys($datum); |
329 | 329 | } |
330 | 330 | $values[] = array_values($datum); |
331 | - } |
|
331 | + } |
|
332 | 332 | |
333 | 333 | } else { |
334 | - $keys = array_keys($datas); |
|
335 | - $values = array_values($datas); |
|
334 | + $keys = array_keys($datas); |
|
335 | + $values = array_values($datas); |
|
336 | 336 | } |
337 | 337 | |
338 | 338 | if (isset($options['ignore']) && $options['ignore']) { |
@@ -340,35 +340,35 @@ discard block |
||
340 | 340 | } |
341 | 341 | |
342 | 342 | if (isset($options['update']) && is_array($options['update']) && $options['update'] && strtolower($which) == 'insert') { |
343 | - if (array_values($options['update']) !== $options['update']) { |
|
343 | + if (array_values($options['update']) !== $options['update']) { |
|
344 | 344 | return $this->query("INSERT INTO %b %lb VALUES %? ON DUPLICATE KEY UPDATE %?", $table, $keys, $values, $options['update']); |
345 | - } else { |
|
345 | + } else { |
|
346 | 346 | $update_str = array_shift($options['update']); |
347 | 347 | $query_param = array("INSERT INTO %b %lb VALUES %? ON DUPLICATE KEY UPDATE $update_str", $table, $keys, $values); |
348 | 348 | $query_param = array_merge($query_param, $options['update']); |
349 | 349 | return call_user_func_array(array($this, 'query'), $query_param); |
350 | - } |
|
350 | + } |
|
351 | 351 | |
352 | 352 | } |
353 | 353 | |
354 | 354 | return $this->query("%l INTO %b %lb VALUES %?", $which, $table, $keys, $values); |
355 | - } |
|
355 | + } |
|
356 | 356 | |
357 | - public function insert($table, $data) { return $this->insertOrReplace('INSERT', $table, $data); } |
|
358 | - public function insertIgnore($table, $data) { return $this->insertOrReplace('INSERT', $table, $data, array('ignore' => true)); } |
|
359 | - public function replace($table, $data) { return $this->insertOrReplace('REPLACE', $table, $data); } |
|
357 | + public function insert($table, $data) { return $this->insertOrReplace('INSERT', $table, $data); } |
|
358 | + public function insertIgnore($table, $data) { return $this->insertOrReplace('INSERT', $table, $data, array('ignore' => true)); } |
|
359 | + public function replace($table, $data) { return $this->insertOrReplace('REPLACE', $table, $data); } |
|
360 | 360 | |
361 | - public function insertUpdate() { |
|
361 | + public function insertUpdate() { |
|
362 | 362 | $args = func_get_args(); |
363 | 363 | $table = array_shift($args); |
364 | 364 | $data = array_shift($args); |
365 | 365 | |
366 | 366 | if (!isset($args[0])) { // update will have all the data of the insert |
367 | - if (isset($data[0]) && is_array($data[0])) { //multiple insert rows specified -- failing! |
|
367 | + if (isset($data[0]) && is_array($data[0])) { //multiple insert rows specified -- failing! |
|
368 | 368 | $this->nonSQLError("Badly formatted insertUpdate() query -- you didn't specify the update component!"); |
369 | - } |
|
369 | + } |
|
370 | 370 | |
371 | - $args[0] = $data; |
|
371 | + $args[0] = $data; |
|
372 | 372 | } |
373 | 373 | |
374 | 374 | if (is_array($args[0])) { |
@@ -378,31 +378,31 @@ discard block |
||
378 | 378 | } |
379 | 379 | |
380 | 380 | return $this->insertOrReplace('INSERT', $table, $data, array('update' => $update)); |
381 | - } |
|
381 | + } |
|
382 | 382 | |
383 | - public function delete() { |
|
383 | + public function delete() { |
|
384 | 384 | $args = func_get_args(); |
385 | 385 | $table = $this->formatTableName(array_shift($args)); |
386 | 386 | $where = array_shift($args); |
387 | 387 | $buildquery = "DELETE FROM $table WHERE $where"; |
388 | 388 | array_unshift($args, $buildquery); |
389 | 389 | return call_user_func_array(array($this, 'query'), $args); |
390 | - } |
|
390 | + } |
|
391 | 391 | |
392 | - public function sqleval() { |
|
392 | + public function sqleval() { |
|
393 | 393 | $args = func_get_args(); |
394 | 394 | $text = call_user_func_array(array($this, 'parseQueryParams'), $args); |
395 | 395 | return new MeekroDBEval($text); |
396 | - } |
|
396 | + } |
|
397 | 397 | |
398 | - public function columnList($table) { |
|
398 | + public function columnList($table) { |
|
399 | 399 | return $this->queryOneColumn('Field', "SHOW COLUMNS FROM $table"); |
400 | - } |
|
400 | + } |
|
401 | 401 | |
402 | - public function tableList($db = null) { |
|
402 | + public function tableList($db = null) { |
|
403 | 403 | if ($db) { |
404 | - $olddb = $this->current_db; |
|
405 | - $this->useDB($db); |
|
404 | + $olddb = $this->current_db; |
|
405 | + $this->useDB($db); |
|
406 | 406 | } |
407 | 407 | |
408 | 408 | $result = $this->queryFirstColumn('SHOW TABLES'); |
@@ -410,9 +410,9 @@ discard block |
||
410 | 410 | $this->useDB($olddb); |
411 | 411 | } |
412 | 412 | return $result; |
413 | - } |
|
413 | + } |
|
414 | 414 | |
415 | - protected function preparseQueryParams() { |
|
415 | + protected function preparseQueryParams() { |
|
416 | 416 | $args = func_get_args(); |
417 | 417 | $sql = trim(strval(array_shift($args))); |
418 | 418 | $args_all = $args; |
@@ -562,60 +562,60 @@ discard block |
||
562 | 562 | $array_types = array('ls', 'li', 'ld', 'lb', 'll', 'lt'); |
563 | 563 | |
564 | 564 | foreach ($chunkyQuery as $chunk) { |
565 | - if (is_string($chunk)) { |
|
565 | + if (is_string($chunk)) { |
|
566 | 566 | $query .= $chunk; |
567 | 567 | continue; |
568 | - } |
|
568 | + } |
|
569 | 569 | |
570 | - $type = $chunk['type']; |
|
571 | - $arg = $chunk['value']; |
|
572 | - $result = ''; |
|
570 | + $type = $chunk['type']; |
|
571 | + $arg = $chunk['value']; |
|
572 | + $result = ''; |
|
573 | 573 | |
574 | - if ($type != '?') { |
|
574 | + if ($type != '?') { |
|
575 | 575 | $is_array_type = in_array($type, $array_types, true); |
576 | 576 | if ($is_array_type && !is_array($arg)) $this->nonSQLError("Badly formatted SQL query: Expected array, got scalar instead!"); |
577 | 577 | else if (!$is_array_type && is_array($arg)) $this->nonSQLError("Badly formatted SQL query: Expected scalar, got array instead!"); |
578 | - } |
|
578 | + } |
|
579 | 579 | |
580 | - if ($type == 's') $result = $this->escape($arg); |
|
581 | - else if ($type == 'i') $result = $this->intval($arg); |
|
582 | - else if ($type == 'd') $result = doubleval($arg); |
|
583 | - else if ($type == 'b') $result = $this->formatTableName($arg); |
|
584 | - else if ($type == 'l') $result = $arg; |
|
585 | - else if ($type == 'ss') $result = $this->escape("%".str_replace(array('%', '_'), array('\%', '\_'), $arg)."%"); |
|
586 | - else if ($type == 't') $result = $this->escape($this->parseTS($arg)); |
|
580 | + if ($type == 's') $result = $this->escape($arg); |
|
581 | + else if ($type == 'i') $result = $this->intval($arg); |
|
582 | + else if ($type == 'd') $result = doubleval($arg); |
|
583 | + else if ($type == 'b') $result = $this->formatTableName($arg); |
|
584 | + else if ($type == 'l') $result = $arg; |
|
585 | + else if ($type == 'ss') $result = $this->escape("%".str_replace(array('%', '_'), array('\%', '\_'), $arg)."%"); |
|
586 | + else if ($type == 't') $result = $this->escape($this->parseTS($arg)); |
|
587 | 587 | |
588 | - else if ($type == 'ls') $result = array_map(array($this, 'escape'), $arg); |
|
589 | - else if ($type == 'li') $result = array_map(array($this, 'intval'), $arg); |
|
590 | - else if ($type == 'ld') $result = array_map('doubleval', $arg); |
|
591 | - else if ($type == 'lb') $result = array_map(array($this, 'formatTableName'), $arg); |
|
592 | - else if ($type == 'll') $result = $arg; |
|
593 | - else if ($type == 'lt') $result = array_map(array($this, 'escape'), array_map(array($this, 'parseTS'), $arg)); |
|
588 | + else if ($type == 'ls') $result = array_map(array($this, 'escape'), $arg); |
|
589 | + else if ($type == 'li') $result = array_map(array($this, 'intval'), $arg); |
|
590 | + else if ($type == 'ld') $result = array_map('doubleval', $arg); |
|
591 | + else if ($type == 'lb') $result = array_map(array($this, 'formatTableName'), $arg); |
|
592 | + else if ($type == 'll') $result = $arg; |
|
593 | + else if ($type == 'lt') $result = array_map(array($this, 'escape'), array_map(array($this, 'parseTS'), $arg)); |
|
594 | 594 | |
595 | - else if ($type == '?') $result = $this->sanitize($arg); |
|
595 | + else if ($type == '?') $result = $this->sanitize($arg); |
|
596 | 596 | |
597 | - else $this->nonSQLError("Badly formatted SQL query: Invalid MeekroDB param $type"); |
|
597 | + else $this->nonSQLError("Badly formatted SQL query: Invalid MeekroDB param $type"); |
|
598 | 598 | |
599 | - if (is_array($result)) $result = '('.implode(',', $result).')'; |
|
599 | + if (is_array($result)) $result = '('.implode(',', $result).')'; |
|
600 | 600 | |
601 | - $query .= $result; |
|
601 | + $query .= $result; |
|
602 | 602 | } |
603 | 603 | |
604 | 604 | return $query; |
605 | - } |
|
605 | + } |
|
606 | 606 | |
607 | - /** |
|
608 | - * @param string $prepend |
|
609 | - */ |
|
610 | - protected function prependCall($function, $args, $prepend) { array_unshift($args, $prepend); return call_user_func_array($function, $args); } |
|
611 | - public function query() { $args = func_get_args(); return $this->prependCall(array($this, 'queryHelper'), $args, 'assoc'); } |
|
612 | - public function queryAllLists() { $args = func_get_args(); return $this->prependCall(array($this, 'queryHelper'), $args, 'list'); } |
|
613 | - public function queryFullColumns() { $args = func_get_args(); return $this->prependCall(array($this, 'queryHelper'), $args, 'full'); } |
|
607 | + /** |
|
608 | + * @param string $prepend |
|
609 | + */ |
|
610 | + protected function prependCall($function, $args, $prepend) { array_unshift($args, $prepend); return call_user_func_array($function, $args); } |
|
611 | + public function query() { $args = func_get_args(); return $this->prependCall(array($this, 'queryHelper'), $args, 'assoc'); } |
|
612 | + public function queryAllLists() { $args = func_get_args(); return $this->prependCall(array($this, 'queryHelper'), $args, 'list'); } |
|
613 | + public function queryFullColumns() { $args = func_get_args(); return $this->prependCall(array($this, 'queryHelper'), $args, 'full'); } |
|
614 | 614 | |
615 | - public function queryRaw() { $args = func_get_args(); return $this->prependCall(array($this, 'queryHelper'), $args, 'raw_buf'); } |
|
616 | - public function queryRawUnbuf() { $args = func_get_args(); return $this->prependCall(array($this, 'queryHelper'), $args, 'raw_unbuf'); } |
|
615 | + public function queryRaw() { $args = func_get_args(); return $this->prependCall(array($this, 'queryHelper'), $args, 'raw_buf'); } |
|
616 | + public function queryRawUnbuf() { $args = func_get_args(); return $this->prependCall(array($this, 'queryHelper'), $args, 'raw_unbuf'); } |
|
617 | 617 | |
618 | - protected function queryHelper() { |
|
618 | + protected function queryHelper() { |
|
619 | 619 | $args = func_get_args(); |
620 | 620 | $type = array_shift($args); |
621 | 621 | $db = $this->get(); |
@@ -160,7 +160,7 @@ discard block |
||
160 | 160 | public $nested_transactions_count = 0; |
161 | 161 | |
162 | 162 | |
163 | - public function __construct($host=null, $user=null, $password=null, $dbName=null, $port=null, $encoding=null) { |
|
163 | + public function __construct($host = null, $user = null, $password = null, $dbName = null, $port = null, $encoding = null) { |
|
164 | 164 | if ($host === null) $host = DB::$host; |
165 | 165 | if ($user === null) $user = DB::$user; |
166 | 166 | if ($password === null) $password = DB::$password; |
@@ -180,13 +180,13 @@ discard block |
||
180 | 180 | $mysql = $this->internal_mysql; |
181 | 181 | |
182 | 182 | if (!($mysql instanceof MySQLi)) { |
183 | - if (! $this->port) $this->port = ini_get('mysqli.default_port'); |
|
183 | + if (!$this->port) $this->port = ini_get('mysqli.default_port'); |
|
184 | 184 | $this->current_db = $this->dbName; |
185 | 185 | |
186 | 186 | $mysql = new mysqli($this->host, $this->user, $this->password, $this->dbName, $this->port); |
187 | 187 | |
188 | 188 | if ($mysql->connect_error) { |
189 | - $this->nonSQLError('Unable to connect to MySQL server! Error: ' . $mysql->connect_error); |
|
189 | + $this->nonSQLError('Unable to connect to MySQL server! Error: '.$mysql->connect_error); |
|
190 | 190 | } |
191 | 191 | |
192 | 192 | $mysql->set_charset($this->encoding); |
@@ -234,7 +234,7 @@ discard block |
||
234 | 234 | public function useDB() { $args = func_get_args(); return call_user_func_array(array($this, 'setDB'), $args); } |
235 | 235 | public function setDB($dbName) { |
236 | 236 | $db = $this->get(); |
237 | - if (! $db->select_db($dbName)) { |
|
237 | + if (!$db->select_db($dbName)) { |
|
238 | 238 | $this->nonSQLError("Unable to set database to $dbName"); |
239 | 239 | } |
240 | 240 | $this->current_db = $dbName; |
@@ -243,7 +243,7 @@ discard block |
||
243 | 243 | |
244 | 244 | public function startTransaction() { |
245 | 245 | if ($this->nested_transactions && $this->serverVersion() < '5.5') { |
246 | - return $this->nonSQLError("Nested transactions are only available on MySQL 5.5 and greater. You are using MySQL " . $this->serverVersion()); |
|
246 | + return $this->nonSQLError("Nested transactions are only available on MySQL 5.5 and greater. You are using MySQL ".$this->serverVersion()); |
|
247 | 247 | } |
248 | 248 | |
249 | 249 | if (!$this->nested_transactions || $this->nested_transactions_count == 0) { |
@@ -257,9 +257,9 @@ discard block |
||
257 | 257 | return $this->nested_transactions_count; |
258 | 258 | } |
259 | 259 | |
260 | - public function commit($all=false) { |
|
260 | + public function commit($all = false) { |
|
261 | 261 | if ($this->nested_transactions && $this->serverVersion() < '5.5') { |
262 | - return $this->nonSQLError("Nested transactions are only available on MySQL 5.5 and greater. You are using MySQL " . $this->serverVersion()); |
|
262 | + return $this->nonSQLError("Nested transactions are only available on MySQL 5.5 and greater. You are using MySQL ".$this->serverVersion()); |
|
263 | 263 | } |
264 | 264 | |
265 | 265 | if ($this->nested_transactions && $this->nested_transactions_count > 0) |
@@ -275,9 +275,9 @@ discard block |
||
275 | 275 | return $this->nested_transactions_count; |
276 | 276 | } |
277 | 277 | |
278 | - public function rollback($all=false) { |
|
278 | + public function rollback($all = false) { |
|
279 | 279 | if ($this->nested_transactions && $this->serverVersion() < '5.5') { |
280 | - return $this->nonSQLError("Nested transactions are only available on MySQL 5.5 and greater. You are using MySQL " . $this->serverVersion()); |
|
280 | + return $this->nonSQLError("Nested transactions are only available on MySQL 5.5 and greater. You are using MySQL ".$this->serverVersion()); |
|
281 | 281 | } |
282 | 282 | |
283 | 283 | if ($this->nested_transactions && $this->nested_transactions_count > 0) |
@@ -297,7 +297,7 @@ discard block |
||
297 | 297 | $table = trim($table, '`'); |
298 | 298 | |
299 | 299 | if (strpos($table, '.')) return implode('.', array_map(array($this, 'formatTableName'), explode('.', $table))); |
300 | - else return '`' . str_replace('`', '``', $table) . '`'; |
|
300 | + else return '`'.str_replace('`', '``', $table).'`'; |
|
301 | 301 | } |
302 | 302 | |
303 | 303 | public function update() { |
@@ -317,14 +317,14 @@ discard block |
||
317 | 317 | /** |
318 | 318 | * @param string $which |
319 | 319 | */ |
320 | - public function insertOrReplace($which, $table, $datas, $options=array()) { |
|
320 | + public function insertOrReplace($which, $table, $datas, $options = array()) { |
|
321 | 321 | $datas = unserialize(serialize($datas)); // break references within array |
322 | 322 | $keys = $values = array(); |
323 | 323 | |
324 | 324 | if (isset($datas[0]) && is_array($datas[0])) { |
325 | 325 | foreach ($datas as $datum) { |
326 | 326 | ksort($datum); |
327 | - if (! $keys) { |
|
327 | + if (!$keys) { |
|
328 | 328 | $keys = array_keys($datum); |
329 | 329 | } |
330 | 330 | $values[] = array_values($datum); |
@@ -425,20 +425,20 @@ discard block |
||
425 | 425 | $named_seperator_length = strlen($this->named_param_seperator); |
426 | 426 | |
427 | 427 | $types = array( |
428 | - $this->param_char . 'll', // list of literals |
|
429 | - $this->param_char . 'ls', // list of strings |
|
430 | - $this->param_char . 'l', // literal |
|
431 | - $this->param_char . 'li', // list of integers |
|
432 | - $this->param_char . 'ld', // list of decimals |
|
433 | - $this->param_char . 'lb', // list of backticks |
|
434 | - $this->param_char . 'lt', // list of timestamps |
|
435 | - $this->param_char . 's', // string |
|
436 | - $this->param_char . 'i', // integer |
|
437 | - $this->param_char . 'd', // double / decimal |
|
438 | - $this->param_char . 'b', // backtick |
|
439 | - $this->param_char . 't', // timestamp |
|
440 | - $this->param_char . '?', // infer type |
|
441 | - $this->param_char . 'ss' // search string (like string, surrounded with %'s) |
|
428 | + $this->param_char.'ll', // list of literals |
|
429 | + $this->param_char.'ls', // list of strings |
|
430 | + $this->param_char.'l', // literal |
|
431 | + $this->param_char.'li', // list of integers |
|
432 | + $this->param_char.'ld', // list of decimals |
|
433 | + $this->param_char.'lb', // list of backticks |
|
434 | + $this->param_char.'lt', // list of timestamps |
|
435 | + $this->param_char.'s', // string |
|
436 | + $this->param_char.'i', // integer |
|
437 | + $this->param_char.'d', // double / decimal |
|
438 | + $this->param_char.'b', // backtick |
|
439 | + $this->param_char.'t', // timestamp |
|
440 | + $this->param_char.'?', // infer type |
|
441 | + $this->param_char.'ss' // search string (like string, surrounded with %'s) |
|
442 | 442 | ); |
443 | 443 | |
444 | 444 | // generate list of all MeekroDB variables in our query, and their position |
@@ -513,7 +513,7 @@ discard block |
||
513 | 513 | return $chunkyQuery; |
514 | 514 | } |
515 | 515 | |
516 | - protected function escape($str) { return "'" . $this->get()->real_escape_string(strval($str)) . "'"; } |
|
516 | + protected function escape($str) { return "'".$this->get()->real_escape_string(strval($str))."'"; } |
|
517 | 517 | |
518 | 518 | protected function sanitize($value) { |
519 | 519 | if (is_object($value)) { |
@@ -531,12 +531,12 @@ discard block |
||
531 | 531 | // non-assoc array? |
532 | 532 | if (array_values($value) === $value) { |
533 | 533 | if (is_array($value[0])) return implode(', ', array_map(array($this, 'sanitize'), $value)); |
534 | - else return '(' . implode(', ', array_map(array($this, 'sanitize'), $value)) . ')'; |
|
534 | + else return '('.implode(', ', array_map(array($this, 'sanitize'), $value)).')'; |
|
535 | 535 | } |
536 | 536 | |
537 | 537 | $pairs = array(); |
538 | 538 | foreach ($value as $k => $v) { |
539 | - $pairs[] = $this->formatTableName($k) . '=' . $this->sanitize($v); |
|
539 | + $pairs[] = $this->formatTableName($k).'='.$this->sanitize($v); |
|
540 | 540 | } |
541 | 541 | |
542 | 542 | return implode(', ', $pairs); |
@@ -712,7 +712,7 @@ discard block |
||
712 | 712 | if ($full_names) { |
713 | 713 | $infos = array(); |
714 | 714 | foreach ($result->fetch_fields() as $info) { |
715 | - if (strlen($info->table)) $infos[] = $info->table . '.' . $info->name; |
|
715 | + if (strlen($info->table)) $infos[] = $info->table.'.'.$info->name; |
|
716 | 716 | else $infos[] = $info->name; |
717 | 717 | } |
718 | 718 | } |
@@ -843,12 +843,12 @@ discard block |
||
843 | 843 | if ($this->clauses[$i] instanceof WhereClause) { |
844 | 844 | $this->clauses[$i]->negate(); |
845 | 845 | } else { |
846 | - $this->clauses[$i]['sql'] = 'NOT (' . $this->clauses[$i]['sql'] . ')'; |
|
846 | + $this->clauses[$i]['sql'] = 'NOT ('.$this->clauses[$i]['sql'].')'; |
|
847 | 847 | } |
848 | 848 | } |
849 | 849 | |
850 | 850 | function negate() { |
851 | - $this->negate = ! $this->negate; |
|
851 | + $this->negate = !$this->negate; |
|
852 | 852 | } |
853 | 853 | |
854 | 854 | function addClause($type) { |
@@ -900,7 +900,7 @@ discard block |
||
900 | 900 | DB::startTransaction(); |
901 | 901 | } |
902 | 902 | function __destruct() { |
903 | - if (! $this->committed) DB::rollback(); |
|
903 | + if (!$this->committed) DB::rollback(); |
|
904 | 904 | } |
905 | 905 | function commit() { |
906 | 906 | DB::commit(); |
@@ -913,7 +913,7 @@ discard block |
||
913 | 913 | class MeekroDBException extends Exception { |
914 | 914 | protected $query = ''; |
915 | 915 | |
916 | - function __construct($message='', $query='', $code = 0) { |
|
916 | + function __construct($message = '', $query = '', $code = 0) { |
|
917 | 917 | parent::__construct($message); |
918 | 918 | $this->query = $query; |
919 | 919 | $this->code = $code; |
@@ -934,10 +934,10 @@ discard block |
||
934 | 934 | |
935 | 935 | $R = array(); |
936 | 936 | foreach ($array as $obj) { |
937 | - if (! array_key_exists($field, $obj)) die("verticalSlice: array doesn't have requested field\n"); |
|
937 | + if (!array_key_exists($field, $obj)) die("verticalSlice: array doesn't have requested field\n"); |
|
938 | 938 | |
939 | 939 | if ($keyfield) { |
940 | - if (! array_key_exists($keyfield, $obj)) die("verticalSlice: array doesn't have requested field\n"); |
|
940 | + if (!array_key_exists($keyfield, $obj)) die("verticalSlice: array doesn't have requested field\n"); |
|
941 | 941 | $R[$obj[$keyfield]] = $obj[$field]; |
942 | 942 | } else { |
943 | 943 | $R[] = $obj[$field]; |
@@ -958,13 +958,13 @@ discard block |
||
958 | 958 | |
959 | 959 | $R = array(); |
960 | 960 | foreach ($array as $obj) { |
961 | - $target =& $R; |
|
961 | + $target = & $R; |
|
962 | 962 | |
963 | 963 | foreach ($fields as $field) { |
964 | - if (! array_key_exists($field, $obj)) die("reIndex: array doesn't have requested field\n"); |
|
964 | + if (!array_key_exists($field, $obj)) die("reIndex: array doesn't have requested field\n"); |
|
965 | 965 | |
966 | 966 | $nextkey = $obj[$field]; |
967 | - $target =& $target[$nextkey]; |
|
967 | + $target = & $target[$nextkey]; |
|
968 | 968 | } |
969 | 969 | $target = $obj; |
970 | 970 | } |
@@ -979,7 +979,7 @@ discard block |
||
979 | 979 | } |
980 | 980 | |
981 | 981 | function meekrodb_debugmode_handler($params) { |
982 | - echo "QUERY: " . $params['query'] . " [" . $params['runtime'] . " ms]"; |
|
982 | + echo "QUERY: ".$params['query']." [".$params['runtime']." ms]"; |
|
983 | 983 | if (php_sapi_name() == 'cli' && empty($_SERVER['REMOTE_ADDR'])) { |
984 | 984 | echo "\n"; |
985 | 985 | } else { |
@@ -161,12 +161,24 @@ discard block |
||
161 | 161 | |
162 | 162 | |
163 | 163 | public function __construct($host=null, $user=null, $password=null, $dbName=null, $port=null, $encoding=null) { |
164 | - if ($host === null) $host = DB::$host; |
|
165 | - if ($user === null) $user = DB::$user; |
|
166 | - if ($password === null) $password = DB::$password; |
|
167 | - if ($dbName === null) $dbName = DB::$dbName; |
|
168 | - if ($port === null) $port = DB::$port; |
|
169 | - if ($encoding === null) $encoding = DB::$encoding; |
|
164 | + if ($host === null) { |
|
165 | + $host = DB::$host; |
|
166 | + } |
|
167 | + if ($user === null) { |
|
168 | + $user = DB::$user; |
|
169 | + } |
|
170 | + if ($password === null) { |
|
171 | + $password = DB::$password; |
|
172 | + } |
|
173 | + if ($dbName === null) { |
|
174 | + $dbName = DB::$dbName; |
|
175 | + } |
|
176 | + if ($port === null) { |
|
177 | + $port = DB::$port; |
|
178 | + } |
|
179 | + if ($encoding === null) { |
|
180 | + $encoding = DB::$encoding; |
|
181 | + } |
|
170 | 182 | |
171 | 183 | $this->host = $host; |
172 | 184 | $this->user = $user; |
@@ -180,7 +192,9 @@ discard block |
||
180 | 192 | $mysql = $this->internal_mysql; |
181 | 193 | |
182 | 194 | if (!($mysql instanceof MySQLi)) { |
183 | - if (! $this->port) $this->port = ini_get('mysqli.default_port'); |
|
195 | + if (! $this->port) { |
|
196 | + $this->port = ini_get('mysqli.default_port'); |
|
197 | + } |
|
184 | 198 | $this->current_db = $this->dbName; |
185 | 199 | |
186 | 200 | $mysql = new mysqli($this->host, $this->user, $this->password, $this->dbName, $this->port); |
@@ -200,7 +214,9 @@ discard block |
||
200 | 214 | public function disconnect() { |
201 | 215 | $mysqli = $this->internal_mysql; |
202 | 216 | if ($mysqli instanceof MySQLi) { |
203 | - if ($thread_id = $mysqli->thread_id) $mysqli->kill($thread_id); |
|
217 | + if ($thread_id = $mysqli->thread_id) { |
|
218 | + $mysqli->kill($thread_id); |
|
219 | + } |
|
204 | 220 | $mysqli->close(); |
205 | 221 | } |
206 | 222 | $this->internal_mysql = null; |
@@ -262,8 +278,9 @@ discard block |
||
262 | 278 | return $this->nonSQLError("Nested transactions are only available on MySQL 5.5 and greater. You are using MySQL " . $this->serverVersion()); |
263 | 279 | } |
264 | 280 | |
265 | - if ($this->nested_transactions && $this->nested_transactions_count > 0) |
|
266 | - $this->nested_transactions_count--; |
|
281 | + if ($this->nested_transactions && $this->nested_transactions_count > 0) { |
|
282 | + $this->nested_transactions_count--; |
|
283 | + } |
|
267 | 284 | |
268 | 285 | if (!$this->nested_transactions || $all || $this->nested_transactions_count == 0) { |
269 | 286 | $this->nested_transactions_count = 0; |
@@ -280,8 +297,9 @@ discard block |
||
280 | 297 | return $this->nonSQLError("Nested transactions are only available on MySQL 5.5 and greater. You are using MySQL " . $this->serverVersion()); |
281 | 298 | } |
282 | 299 | |
283 | - if ($this->nested_transactions && $this->nested_transactions_count > 0) |
|
284 | - $this->nested_transactions_count--; |
|
300 | + if ($this->nested_transactions && $this->nested_transactions_count > 0) { |
|
301 | + $this->nested_transactions_count--; |
|
302 | + } |
|
285 | 303 | |
286 | 304 | if (!$this->nested_transactions || $all || $this->nested_transactions_count == 0) { |
287 | 305 | $this->nested_transactions_count = 0; |
@@ -296,8 +314,11 @@ discard block |
||
296 | 314 | protected function formatTableName($table) { |
297 | 315 | $table = trim($table, '`'); |
298 | 316 | |
299 | - if (strpos($table, '.')) return implode('.', array_map(array($this, 'formatTableName'), explode('.', $table))); |
|
300 | - else return '`' . str_replace('`', '``', $table) . '`'; |
|
317 | + if (strpos($table, '.')) { |
|
318 | + return implode('.', array_map(array($this, 'formatTableName'), explode('.', $table))); |
|
319 | + } else { |
|
320 | + return '`' . str_replace('`', '``', $table) . '`'; |
|
321 | + } |
|
301 | 322 | } |
302 | 323 | |
303 | 324 | public function update() { |
@@ -471,7 +492,9 @@ discard block |
||
471 | 492 | // handle numbered parameters |
472 | 493 | if ($arg_number_length = strspn($sql, '0123456789', $new_pos_back)) { |
473 | 494 | $arg_number = substr($sql, $new_pos_back, $arg_number_length); |
474 | - if (!array_key_exists($arg_number, $args_all)) $this->nonSQLError("Non existent argument reference (arg $arg_number): $sql"); |
|
495 | + if (!array_key_exists($arg_number, $args_all)) { |
|
496 | + $this->nonSQLError("Non existent argument reference (arg $arg_number): $sql"); |
|
497 | + } |
|
475 | 498 | |
476 | 499 | $arg = $args_all[$arg_number]; |
477 | 500 | |
@@ -481,8 +504,12 @@ discard block |
||
481 | 504 | $new_pos_back + $named_seperator_length) + $named_seperator_length; |
482 | 505 | |
483 | 506 | $arg_number = substr($sql, $new_pos_back + $named_seperator_length, $arg_number_length - $named_seperator_length); |
484 | - if (count($args_all) != 1 || !is_array($args_all[0])) $this->nonSQLError("If you use named parameters, the second argument must be an array of parameters"); |
|
485 | - if (!array_key_exists($arg_number, $args_all[0])) $this->nonSQLError("Non existent argument reference (arg $arg_number): $sql"); |
|
507 | + if (count($args_all) != 1 || !is_array($args_all[0])) { |
|
508 | + $this->nonSQLError("If you use named parameters, the second argument must be an array of parameters"); |
|
509 | + } |
|
510 | + if (!array_key_exists($arg_number, $args_all[0])) { |
|
511 | + $this->nonSQLError("Non existent argument reference (arg $arg_number): $sql"); |
|
512 | + } |
|
486 | 513 | |
487 | 514 | $arg = $args_all[0][$arg_number]; |
488 | 515 | |
@@ -491,7 +518,9 @@ discard block |
||
491 | 518 | $arg = array_shift($args); |
492 | 519 | } |
493 | 520 | |
494 | - if ($new_pos > 0) $chunkyQuery[] = substr($sql, 0, $new_pos); |
|
521 | + if ($new_pos > 0) { |
|
522 | + $chunkyQuery[] = substr($sql, 0, $new_pos); |
|
523 | + } |
|
495 | 524 | |
496 | 525 | if (is_object($arg) && ($arg instanceof WhereClause)) { |
497 | 526 | list($clause_sql, $clause_args) = $arg->textAndArgs(); |
@@ -517,21 +546,31 @@ discard block |
||
517 | 546 | |
518 | 547 | protected function sanitize($value) { |
519 | 548 | if (is_object($value)) { |
520 | - if ($value instanceof MeekroDBEval) return $value->text; |
|
521 | - else if ($value instanceof DateTime) return $this->escape($value->format('Y-m-d H:i:s')); |
|
522 | - else return ''; |
|
549 | + if ($value instanceof MeekroDBEval) { |
|
550 | + return $value->text; |
|
551 | + } else if ($value instanceof DateTime) { |
|
552 | + return $this->escape($value->format('Y-m-d H:i:s')); |
|
553 | + } else { |
|
554 | + return ''; |
|
555 | + } |
|
523 | 556 | } |
524 | 557 | |
525 | - if (is_null($value)) return $this->usenull ? 'NULL' : "''"; |
|
526 | - else if (is_bool($value)) return ($value ? 1 : 0); |
|
527 | - else if (is_int($value)) return $value; |
|
528 | - else if (is_float($value)) return $value; |
|
529 | - |
|
530 | - else if (is_array($value)) { |
|
558 | + if (is_null($value)) { |
|
559 | + return $this->usenull ? 'NULL' : "''"; |
|
560 | + } else if (is_bool($value)) { |
|
561 | + return ($value ? 1 : 0); |
|
562 | + } else if (is_int($value)) { |
|
563 | + return $value; |
|
564 | + } else if (is_float($value)) { |
|
565 | + return $value; |
|
566 | + } else if (is_array($value)) { |
|
531 | 567 | // non-assoc array? |
532 | 568 | if (array_values($value) === $value) { |
533 | - if (is_array($value[0])) return implode(', ', array_map(array($this, 'sanitize'), $value)); |
|
534 | - else return '(' . implode(', ', array_map(array($this, 'sanitize'), $value)) . ')'; |
|
569 | + if (is_array($value[0])) { |
|
570 | + return implode(', ', array_map(array($this, 'sanitize'), $value)); |
|
571 | + } else { |
|
572 | + return '(' . implode(', ', array_map(array($this, 'sanitize'), $value)) . ')'; |
|
573 | + } |
|
535 | 574 | } |
536 | 575 | |
537 | 576 | $pairs = array(); |
@@ -540,17 +579,23 @@ discard block |
||
540 | 579 | } |
541 | 580 | |
542 | 581 | return implode(', ', $pairs); |
582 | + } else { |
|
583 | + return $this->escape($value); |
|
543 | 584 | } |
544 | - else return $this->escape($value); |
|
545 | 585 | } |
546 | 586 | |
547 | 587 | protected function parseTS($ts) { |
548 | - if (is_string($ts)) return date('Y-m-d H:i:s', strtotime($ts)); |
|
549 | - else if (is_object($ts) && ($ts instanceof DateTime)) return $ts->format('Y-m-d H:i:s'); |
|
588 | + if (is_string($ts)) { |
|
589 | + return date('Y-m-d H:i:s', strtotime($ts)); |
|
590 | + } else if (is_object($ts) && ($ts instanceof DateTime)) { |
|
591 | + return $ts->format('Y-m-d H:i:s'); |
|
592 | + } |
|
550 | 593 | } |
551 | 594 | |
552 | 595 | protected function intval($var) { |
553 | - if (PHP_INT_SIZE == 8) return intval($var); |
|
596 | + if (PHP_INT_SIZE == 8) { |
|
597 | + return intval($var); |
|
598 | + } |
|
554 | 599 | return floor(doubleval($var)); |
555 | 600 | } |
556 | 601 | |
@@ -573,30 +618,48 @@ discard block |
||
573 | 618 | |
574 | 619 | if ($type != '?') { |
575 | 620 | $is_array_type = in_array($type, $array_types, true); |
576 | - if ($is_array_type && !is_array($arg)) $this->nonSQLError("Badly formatted SQL query: Expected array, got scalar instead!"); |
|
577 | - else if (!$is_array_type && is_array($arg)) $this->nonSQLError("Badly formatted SQL query: Expected scalar, got array instead!"); |
|
621 | + if ($is_array_type && !is_array($arg)) { |
|
622 | + $this->nonSQLError("Badly formatted SQL query: Expected array, got scalar instead!"); |
|
623 | + } else if (!$is_array_type && is_array($arg)) { |
|
624 | + $this->nonSQLError("Badly formatted SQL query: Expected scalar, got array instead!"); |
|
625 | + } |
|
578 | 626 | } |
579 | 627 | |
580 | - if ($type == 's') $result = $this->escape($arg); |
|
581 | - else if ($type == 'i') $result = $this->intval($arg); |
|
582 | - else if ($type == 'd') $result = doubleval($arg); |
|
583 | - else if ($type == 'b') $result = $this->formatTableName($arg); |
|
584 | - else if ($type == 'l') $result = $arg; |
|
585 | - else if ($type == 'ss') $result = $this->escape("%".str_replace(array('%', '_'), array('\%', '\_'), $arg)."%"); |
|
586 | - else if ($type == 't') $result = $this->escape($this->parseTS($arg)); |
|
587 | - |
|
588 | - else if ($type == 'ls') $result = array_map(array($this, 'escape'), $arg); |
|
589 | - else if ($type == 'li') $result = array_map(array($this, 'intval'), $arg); |
|
590 | - else if ($type == 'ld') $result = array_map('doubleval', $arg); |
|
591 | - else if ($type == 'lb') $result = array_map(array($this, 'formatTableName'), $arg); |
|
592 | - else if ($type == 'll') $result = $arg; |
|
593 | - else if ($type == 'lt') $result = array_map(array($this, 'escape'), array_map(array($this, 'parseTS'), $arg)); |
|
594 | - |
|
595 | - else if ($type == '?') $result = $this->sanitize($arg); |
|
596 | - |
|
597 | - else $this->nonSQLError("Badly formatted SQL query: Invalid MeekroDB param $type"); |
|
628 | + if ($type == 's') { |
|
629 | + $result = $this->escape($arg); |
|
630 | + } else if ($type == 'i') { |
|
631 | + $result = $this->intval($arg); |
|
632 | + } else if ($type == 'd') { |
|
633 | + $result = doubleval($arg); |
|
634 | + } else if ($type == 'b') { |
|
635 | + $result = $this->formatTableName($arg); |
|
636 | + } else if ($type == 'l') { |
|
637 | + $result = $arg; |
|
638 | + } else if ($type == 'ss') { |
|
639 | + $result = $this->escape("%".str_replace(array('%', '_'), array('\%', '\_'), $arg)."%"); |
|
640 | + } else if ($type == 't') { |
|
641 | + $result = $this->escape($this->parseTS($arg)); |
|
642 | + } else if ($type == 'ls') { |
|
643 | + $result = array_map(array($this, 'escape'), $arg); |
|
644 | + } else if ($type == 'li') { |
|
645 | + $result = array_map(array($this, 'intval'), $arg); |
|
646 | + } else if ($type == 'ld') { |
|
647 | + $result = array_map('doubleval', $arg); |
|
648 | + } else if ($type == 'lb') { |
|
649 | + $result = array_map(array($this, 'formatTableName'), $arg); |
|
650 | + } else if ($type == 'll') { |
|
651 | + $result = $arg; |
|
652 | + } else if ($type == 'lt') { |
|
653 | + $result = array_map(array($this, 'escape'), array_map(array($this, 'parseTS'), $arg)); |
|
654 | + } else if ($type == '?') { |
|
655 | + $result = $this->sanitize($arg); |
|
656 | + } else { |
|
657 | + $this->nonSQLError("Badly formatted SQL query: Invalid MeekroDB param $type"); |
|
658 | + } |
|
598 | 659 | |
599 | - if (is_array($result)) $result = '('.implode(',', $result).')'; |
|
660 | + if (is_array($result)) { |
|
661 | + $result = '('.implode(',', $result).')'; |
|
662 | + } |
|
600 | 663 | |
601 | 664 | $query .= $result; |
602 | 665 | } |
@@ -702,23 +765,33 @@ discard block |
||
702 | 765 | $this->affected_rows = $db->affected_rows; |
703 | 766 | |
704 | 767 | // mysqli_result->num_rows won't initially show correct results for unbuffered data |
705 | - if ($is_buffered && ($result instanceof MySQLi_Result)) $this->num_rows = $result->num_rows; |
|
706 | - else $this->num_rows = null; |
|
768 | + if ($is_buffered && ($result instanceof MySQLi_Result)) { |
|
769 | + $this->num_rows = $result->num_rows; |
|
770 | + } else { |
|
771 | + $this->num_rows = null; |
|
772 | + } |
|
707 | 773 | |
708 | - if ($row_type == 'raw' || !($result instanceof MySQLi_Result)) return $result; |
|
774 | + if ($row_type == 'raw' || !($result instanceof MySQLi_Result)) { |
|
775 | + return $result; |
|
776 | + } |
|
709 | 777 | |
710 | 778 | $return = array(); |
711 | 779 | |
712 | 780 | if ($full_names) { |
713 | 781 | $infos = array(); |
714 | 782 | foreach ($result->fetch_fields() as $info) { |
715 | - if (strlen($info->table)) $infos[] = $info->table . '.' . $info->name; |
|
716 | - else $infos[] = $info->name; |
|
783 | + if (strlen($info->table)) { |
|
784 | + $infos[] = $info->table . '.' . $info->name; |
|
785 | + } else { |
|
786 | + $infos[] = $info->name; |
|
787 | + } |
|
717 | 788 | } |
718 | 789 | } |
719 | 790 | |
720 | 791 | while ($row = ($row_type == 'assoc' ? $result->fetch_assoc() : $result->fetch_row())) { |
721 | - if ($full_names) $row = array_combine($infos, $row); |
|
792 | + if ($full_names) { |
|
793 | + $row = array_combine($infos, $row); |
|
794 | + } |
|
722 | 795 | $return[] = $row; |
723 | 796 | } |
724 | 797 | |
@@ -726,7 +799,9 @@ discard block |
||
726 | 799 | $result->free(); |
727 | 800 | while ($db->more_results()) { |
728 | 801 | $db->next_result(); |
729 | - if ($result = $db->use_result()) $result->free(); |
|
802 | + if ($result = $db->use_result()) { |
|
803 | + $result->free(); |
|
804 | + } |
|
730 | 805 | } |
731 | 806 | |
732 | 807 | return $return; |
@@ -736,7 +811,9 @@ discard block |
||
736 | 811 | public function queryFirstRow() { |
737 | 812 | $args = func_get_args(); |
738 | 813 | $result = call_user_func_array(array($this, 'query'), $args); |
739 | - if (!$result) return null; |
|
814 | + if (!$result) { |
|
815 | + return null; |
|
816 | + } |
|
740 | 817 | return reset($result); |
741 | 818 | } |
742 | 819 | |
@@ -744,7 +821,9 @@ discard block |
||
744 | 821 | public function queryFirstList() { |
745 | 822 | $args = func_get_args(); |
746 | 823 | $result = call_user_func_array(array($this, 'queryAllLists'), $args); |
747 | - if (!$result) return null; |
|
824 | + if (!$result) { |
|
825 | + return null; |
|
826 | + } |
|
748 | 827 | return reset($result); |
749 | 828 | } |
750 | 829 | |
@@ -881,10 +960,15 @@ discard block |
||
881 | 960 | $args = array_merge($args, $clause_args); |
882 | 961 | } |
883 | 962 | |
884 | - if ($this->type == 'and') $sql = implode(' AND ', $sql); |
|
885 | - else $sql = implode(' OR ', $sql); |
|
963 | + if ($this->type == 'and') { |
|
964 | + $sql = implode(' AND ', $sql); |
|
965 | + } else { |
|
966 | + $sql = implode(' OR ', $sql); |
|
967 | + } |
|
886 | 968 | |
887 | - if ($this->negate) $sql = '(NOT '.$sql.')'; |
|
969 | + if ($this->negate) { |
|
970 | + $sql = '(NOT '.$sql.')'; |
|
971 | + } |
|
888 | 972 | return array($sql, $args); |
889 | 973 | } |
890 | 974 | |
@@ -900,7 +984,9 @@ discard block |
||
900 | 984 | DB::startTransaction(); |
901 | 985 | } |
902 | 986 | function __destruct() { |
903 | - if (! $this->committed) DB::rollback(); |
|
987 | + if (! $this->committed) { |
|
988 | + DB::rollback(); |
|
989 | + } |
|
904 | 990 | } |
905 | 991 | function commit() { |
906 | 992 | DB::commit(); |
@@ -934,10 +1020,14 @@ discard block |
||
934 | 1020 | |
935 | 1021 | $R = array(); |
936 | 1022 | foreach ($array as $obj) { |
937 | - if (! array_key_exists($field, $obj)) die("verticalSlice: array doesn't have requested field\n"); |
|
1023 | + if (! array_key_exists($field, $obj)) { |
|
1024 | + die("verticalSlice: array doesn't have requested field\n"); |
|
1025 | + } |
|
938 | 1026 | |
939 | 1027 | if ($keyfield) { |
940 | - if (! array_key_exists($keyfield, $obj)) die("verticalSlice: array doesn't have requested field\n"); |
|
1028 | + if (! array_key_exists($keyfield, $obj)) { |
|
1029 | + die("verticalSlice: array doesn't have requested field\n"); |
|
1030 | + } |
|
941 | 1031 | $R[$obj[$keyfield]] = $obj[$field]; |
942 | 1032 | } else { |
943 | 1033 | $R[] = $obj[$field]; |
@@ -961,7 +1051,9 @@ discard block |
||
961 | 1051 | $target =& $R; |
962 | 1052 | |
963 | 1053 | foreach ($fields as $field) { |
964 | - if (! array_key_exists($field, $obj)) die("reIndex: array doesn't have requested field\n"); |
|
1054 | + if (! array_key_exists($field, $obj)) { |
|
1055 | + die("reIndex: array doesn't have requested field\n"); |
|
1056 | + } |
|
965 | 1057 | |
966 | 1058 | $nextkey = $obj[$field]; |
967 | 1059 | $target =& $target[$nextkey]; |
@@ -18,7 +18,7 @@ |
||
18 | 18 | $PHPMAILER_LANG['invalid_address'] = 'الإرسال غير ممكن لأن عنوان البريد الإلكتروني غير صالح: '; |
19 | 19 | $PHPMAILER_LANG['mailer_not_supported'] = ' برنامج الإرسال غير مدعوم.'; |
20 | 20 | $PHPMAILER_LANG['provide_address'] = 'يجب توفير عنوان البريد الإلكتروني لمستلم واحد على الأقل.'; |
21 | -$PHPMAILER_LANG['recipients_failed'] = 'خطأ SMTP: الأخطاء التالية ' . |
|
21 | +$PHPMAILER_LANG['recipients_failed'] = 'خطأ SMTP: الأخطاء التالية '. |
|
22 | 22 | 'فشل في الارسال لكل من : '; |
23 | 23 | $PHPMAILER_LANG['signing'] = 'خطأ في التوقيع: '; |
24 | 24 | $PHPMAILER_LANG['smtp_connect_failed'] = 'SMTP Connect() غير ممكن.'; |
@@ -17,17 +17,17 @@ discard block |
||
17 | 17 | const ERR_SKEY = 'ERR|The Duo secret key passed to sign_request() is invalid.'; |
18 | 18 | const ERR_AKEY = 'ERR|The application secret key passed to sign_request() must be at least 40 characters.'; |
19 | 19 | |
20 | - private static function sign_vals($key, $vals, $prefix, $expire, $time=NULL) { |
|
20 | + private static function sign_vals($key, $vals, $prefix, $expire, $time = NULL) { |
|
21 | 21 | $exp = ($time ? $time : time()) + $expire; |
22 | - $val = $vals . '|' . $exp; |
|
22 | + $val = $vals.'|'.$exp; |
|
23 | 23 | $b64 = base64_encode($val); |
24 | - $cookie = $prefix . '|' . $b64; |
|
24 | + $cookie = $prefix.'|'.$b64; |
|
25 | 25 | |
26 | 26 | $sig = hash_hmac("sha1", $cookie, $key); |
27 | - return $cookie . '|' . $sig; |
|
27 | + return $cookie.'|'.$sig; |
|
28 | 28 | } |
29 | 29 | |
30 | - private static function parse_vals($key, $val, $prefix, $ikey, $time=NULL) { |
|
30 | + private static function parse_vals($key, $val, $prefix, $ikey, $time = NULL) { |
|
31 | 31 | $ts = ($time ? $time : time()); |
32 | 32 | |
33 | 33 | $parts = explode('|', $val); |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | } |
37 | 37 | list($u_prefix, $u_b64, $u_sig) = $parts; |
38 | 38 | |
39 | - $sig = hash_hmac("sha1", $u_prefix . '|' . $u_b64, $key); |
|
39 | + $sig = hash_hmac("sha1", $u_prefix.'|'.$u_b64, $key); |
|
40 | 40 | if (hash_hmac("sha1", $sig, $key) !== hash_hmac("sha1", $u_sig, $key)) { |
41 | 41 | return null; |
42 | 42 | } |
@@ -61,7 +61,7 @@ discard block |
||
61 | 61 | return $user; |
62 | 62 | } |
63 | 63 | |
64 | - public static function signRequest($ikey, $skey, $akey, $username, $time=NULL) { |
|
64 | + public static function signRequest($ikey, $skey, $akey, $username, $time = NULL) { |
|
65 | 65 | if (!isset($username) || strlen($username) === 0) { |
66 | 66 | return self::ERR_USER; |
67 | 67 | } |
@@ -78,15 +78,15 @@ discard block |
||
78 | 78 | return self::ERR_AKEY; |
79 | 79 | } |
80 | 80 | |
81 | - $vals = $username . '|' . $ikey; |
|
81 | + $vals = $username.'|'.$ikey; |
|
82 | 82 | |
83 | 83 | $duo_sig = self::sign_vals($skey, $vals, self::DUO_PREFIX, self::DUO_EXPIRE, $time); |
84 | 84 | $app_sig = self::sign_vals($akey, $vals, self::APP_PREFIX, self::APP_EXPIRE, $time); |
85 | 85 | |
86 | - return $duo_sig . ':' . $app_sig; |
|
86 | + return $duo_sig.':'.$app_sig; |
|
87 | 87 | } |
88 | 88 | |
89 | - public static function verifyResponse($ikey, $skey, $akey, $sig_response, $time=NULL) { |
|
89 | + public static function verifyResponse($ikey, $skey, $akey, $sig_response, $time = NULL) { |
|
90 | 90 | list($auth_sig, $app_sig) = explode(':', $sig_response); |
91 | 91 | |
92 | 92 | $auth_user = self::parse_vals($skey, $auth_sig, self::AUTH_PREFIX, $ikey, $time); |
@@ -34,343 +34,343 @@ |
||
34 | 34 | */ |
35 | 35 | class Auth_Yubico |
36 | 36 | { |
37 | - /**#@+ |
|
37 | + /**#@+ |
|
38 | 38 | * @access private |
39 | 39 | */ |
40 | 40 | |
41 | - /** |
|
42 | - * Yubico client ID |
|
43 | - * @var string |
|
44 | - */ |
|
45 | - var $_id; |
|
41 | + /** |
|
42 | + * Yubico client ID |
|
43 | + * @var string |
|
44 | + */ |
|
45 | + var $_id; |
|
46 | 46 | |
47 | - /** |
|
48 | - * Yubico client key |
|
49 | - * @var string |
|
50 | - */ |
|
51 | - var $_key; |
|
47 | + /** |
|
48 | + * Yubico client key |
|
49 | + * @var string |
|
50 | + */ |
|
51 | + var $_key; |
|
52 | 52 | |
53 | - /** |
|
54 | - * URL part of validation server |
|
55 | - * @var string |
|
56 | - */ |
|
57 | - var $_url; |
|
53 | + /** |
|
54 | + * URL part of validation server |
|
55 | + * @var string |
|
56 | + */ |
|
57 | + var $_url; |
|
58 | 58 | |
59 | - /** |
|
60 | - * List with URL part of validation servers |
|
61 | - * @var array |
|
62 | - */ |
|
63 | - var $_url_list; |
|
59 | + /** |
|
60 | + * List with URL part of validation servers |
|
61 | + * @var array |
|
62 | + */ |
|
63 | + var $_url_list; |
|
64 | 64 | |
65 | - /** |
|
66 | - * index to _url_list |
|
67 | - * @var int |
|
68 | - */ |
|
69 | - var $_url_index; |
|
65 | + /** |
|
66 | + * index to _url_list |
|
67 | + * @var int |
|
68 | + */ |
|
69 | + var $_url_index; |
|
70 | 70 | |
71 | - /** |
|
72 | - * Last query to server |
|
73 | - * @var string |
|
74 | - */ |
|
75 | - var $_lastquery; |
|
71 | + /** |
|
72 | + * Last query to server |
|
73 | + * @var string |
|
74 | + */ |
|
75 | + var $_lastquery; |
|
76 | 76 | |
77 | - /** |
|
78 | - * Response from server |
|
79 | - * @var string |
|
80 | - */ |
|
81 | - var $_response; |
|
77 | + /** |
|
78 | + * Response from server |
|
79 | + * @var string |
|
80 | + */ |
|
81 | + var $_response; |
|
82 | 82 | |
83 | - /** |
|
84 | - * Flag whether to use https or not. |
|
85 | - * @var boolean |
|
86 | - */ |
|
87 | - var $_https; |
|
83 | + /** |
|
84 | + * Flag whether to use https or not. |
|
85 | + * @var boolean |
|
86 | + */ |
|
87 | + var $_https; |
|
88 | 88 | |
89 | - /** |
|
90 | - * Flag whether to verify HTTPS server certificates or not. |
|
91 | - * @var boolean |
|
92 | - */ |
|
93 | - var $_httpsverify; |
|
94 | - |
|
95 | - /** |
|
96 | - * Constructor |
|
97 | - * |
|
98 | - * Sets up the object |
|
99 | - * @param string $id The client identity |
|
100 | - * @param string $key The client MAC key (optional) |
|
101 | - * @param integer $https Flag whether to use https (optional) |
|
102 | - * @param integer $httpsverify Flag whether to use verify HTTPS |
|
103 | - * server certificates (optional, |
|
104 | - * default true) |
|
105 | - * @access public |
|
106 | - */ |
|
107 | - public function __construct($id, $key = '', $https = 0, $httpsverify = 1) |
|
108 | - { |
|
109 | - $this->_id = $id; |
|
110 | - $this->_key = base64_decode($key); |
|
111 | - $this->_https = $https; |
|
112 | - $this->_httpsverify = $httpsverify; |
|
113 | - } |
|
114 | - |
|
115 | - /** |
|
116 | - * Specify to use a different URL part for verification. |
|
117 | - * The default is "api.yubico.com/wsapi/verify". |
|
118 | - * |
|
119 | - * @param string $url New server URL part to use |
|
120 | - * @access public |
|
121 | - */ |
|
122 | - function setURLpart($url) |
|
123 | - { |
|
124 | - $this->_url = $url; |
|
125 | - } |
|
126 | - |
|
127 | - /** |
|
128 | - * Get URL part to use for validation. |
|
129 | - * |
|
130 | - * @return string Server URL part |
|
131 | - * @access public |
|
132 | - */ |
|
133 | - function getURLpart() |
|
134 | - { |
|
135 | - if ($this->_url) { |
|
136 | - return $this->_url; |
|
137 | - } else { |
|
138 | - return "api.yubico.com/wsapi/verify"; |
|
139 | - } |
|
140 | - } |
|
141 | - |
|
142 | - |
|
143 | - /** |
|
144 | - * Get next URL part from list to use for validation. |
|
145 | - * |
|
146 | - * @return mixed string with URL part of false if no more URLs in list |
|
147 | - * @access public |
|
148 | - */ |
|
149 | - function getNextURLpart() |
|
150 | - { |
|
151 | - if ($this->_url_list) $url_list = $this->_url_list; |
|
152 | - else $url_list = array('api.yubico.com/wsapi/2.0/verify', |
|
153 | - 'api2.yubico.com/wsapi/2.0/verify', |
|
154 | - 'api3.yubico.com/wsapi/2.0/verify', |
|
155 | - 'api4.yubico.com/wsapi/2.0/verify', |
|
156 | - 'api5.yubico.com/wsapi/2.0/verify'); |
|
89 | + /** |
|
90 | + * Flag whether to verify HTTPS server certificates or not. |
|
91 | + * @var boolean |
|
92 | + */ |
|
93 | + var $_httpsverify; |
|
94 | + |
|
95 | + /** |
|
96 | + * Constructor |
|
97 | + * |
|
98 | + * Sets up the object |
|
99 | + * @param string $id The client identity |
|
100 | + * @param string $key The client MAC key (optional) |
|
101 | + * @param integer $https Flag whether to use https (optional) |
|
102 | + * @param integer $httpsverify Flag whether to use verify HTTPS |
|
103 | + * server certificates (optional, |
|
104 | + * default true) |
|
105 | + * @access public |
|
106 | + */ |
|
107 | + public function __construct($id, $key = '', $https = 0, $httpsverify = 1) |
|
108 | + { |
|
109 | + $this->_id = $id; |
|
110 | + $this->_key = base64_decode($key); |
|
111 | + $this->_https = $https; |
|
112 | + $this->_httpsverify = $httpsverify; |
|
113 | + } |
|
114 | + |
|
115 | + /** |
|
116 | + * Specify to use a different URL part for verification. |
|
117 | + * The default is "api.yubico.com/wsapi/verify". |
|
118 | + * |
|
119 | + * @param string $url New server URL part to use |
|
120 | + * @access public |
|
121 | + */ |
|
122 | + function setURLpart($url) |
|
123 | + { |
|
124 | + $this->_url = $url; |
|
125 | + } |
|
126 | + |
|
127 | + /** |
|
128 | + * Get URL part to use for validation. |
|
129 | + * |
|
130 | + * @return string Server URL part |
|
131 | + * @access public |
|
132 | + */ |
|
133 | + function getURLpart() |
|
134 | + { |
|
135 | + if ($this->_url) { |
|
136 | + return $this->_url; |
|
137 | + } else { |
|
138 | + return "api.yubico.com/wsapi/verify"; |
|
139 | + } |
|
140 | + } |
|
141 | + |
|
142 | + |
|
143 | + /** |
|
144 | + * Get next URL part from list to use for validation. |
|
145 | + * |
|
146 | + * @return mixed string with URL part of false if no more URLs in list |
|
147 | + * @access public |
|
148 | + */ |
|
149 | + function getNextURLpart() |
|
150 | + { |
|
151 | + if ($this->_url_list) $url_list = $this->_url_list; |
|
152 | + else $url_list = array('api.yubico.com/wsapi/2.0/verify', |
|
153 | + 'api2.yubico.com/wsapi/2.0/verify', |
|
154 | + 'api3.yubico.com/wsapi/2.0/verify', |
|
155 | + 'api4.yubico.com/wsapi/2.0/verify', |
|
156 | + 'api5.yubico.com/wsapi/2.0/verify'); |
|
157 | 157 | |
158 | - if ($this->_url_index >= count($url_list)) return false; |
|
159 | - else return $url_list[$this->_url_index++]; |
|
160 | - } |
|
161 | - |
|
162 | - /** |
|
163 | - * Resets index to URL list |
|
164 | - * |
|
165 | - * @access public |
|
166 | - */ |
|
167 | - function URLreset() |
|
168 | - { |
|
169 | - $this->_url_index = 0; |
|
170 | - } |
|
171 | - |
|
172 | - /** |
|
173 | - * Add another URLpart. |
|
174 | - * |
|
175 | - * @access public |
|
176 | - */ |
|
177 | - function addURLpart($URLpart) |
|
178 | - { |
|
179 | - $this->_url_list[] = $URLpart; |
|
180 | - } |
|
158 | + if ($this->_url_index >= count($url_list)) return false; |
|
159 | + else return $url_list[$this->_url_index++]; |
|
160 | + } |
|
161 | + |
|
162 | + /** |
|
163 | + * Resets index to URL list |
|
164 | + * |
|
165 | + * @access public |
|
166 | + */ |
|
167 | + function URLreset() |
|
168 | + { |
|
169 | + $this->_url_index = 0; |
|
170 | + } |
|
171 | + |
|
172 | + /** |
|
173 | + * Add another URLpart. |
|
174 | + * |
|
175 | + * @access public |
|
176 | + */ |
|
177 | + function addURLpart($URLpart) |
|
178 | + { |
|
179 | + $this->_url_list[] = $URLpart; |
|
180 | + } |
|
181 | 181 | |
182 | - /** |
|
183 | - * Return the last query sent to the server, if any. |
|
184 | - * |
|
185 | - * @return string Request to server |
|
186 | - * @access public |
|
187 | - */ |
|
188 | - function getLastQuery() |
|
189 | - { |
|
190 | - return $this->_lastquery; |
|
191 | - } |
|
192 | - |
|
193 | - /** |
|
194 | - * Return the last data received from the server, if any. |
|
195 | - * |
|
196 | - * @return string Output from server |
|
197 | - * @access public |
|
198 | - */ |
|
199 | - function getLastResponse() |
|
200 | - { |
|
201 | - return $this->_response; |
|
202 | - } |
|
203 | - |
|
204 | - /** |
|
205 | - * Parse input string into password, yubikey prefix, |
|
206 | - * ciphertext, and OTP. |
|
207 | - * |
|
208 | - * @param string Input string to parse |
|
209 | - * @param string Optional delimiter re-class, default is '[:]' |
|
210 | - * @param string $str |
|
211 | - * @return array Keyed array with fields |
|
212 | - * @access public |
|
213 | - */ |
|
214 | - function parsePasswordOTP($str, $delim = '[:]') |
|
215 | - { |
|
216 | - if (!preg_match("/^((.*)".$delim.")?". |
|
217 | - "(([cbdefghijklnrtuv]{0,16})". |
|
218 | - "([cbdefghijklnrtuv]{32}))$/i", |
|
219 | - $str, $matches)) { |
|
220 | - /* Dvorak? */ |
|
221 | - if (!preg_match("/^((.*)".$delim.")?". |
|
222 | - "(([jxe\.uidchtnbpygk]{0,16})". |
|
223 | - "([jxe\.uidchtnbpygk]{32}))$/i", |
|
224 | - $str, $matches)) { |
|
225 | - return false; |
|
226 | - } else { |
|
227 | - $ret['otp'] = strtr($matches[3], "jxe.uidchtnbpygk", "cbdefghijklnrtuv"); |
|
228 | - } |
|
229 | - } else { |
|
230 | - $ret['otp'] = $matches[3]; |
|
231 | - } |
|
232 | - $ret['password'] = $matches[2]; |
|
233 | - $ret['prefix'] = $matches[4]; |
|
234 | - $ret['ciphertext'] = $matches[5]; |
|
235 | - return $ret; |
|
236 | - } |
|
237 | - |
|
238 | - /* TODO? Add functions to get parsed parts of server response? */ |
|
239 | - |
|
240 | - /** |
|
241 | - * Parse parameters from last response |
|
242 | - * |
|
243 | - * example: getParameters("timestamp", "sessioncounter", "sessionuse"); |
|
244 | - * |
|
245 | - * @param array @parameters Array with strings representing |
|
246 | - * parameters to parse |
|
247 | - * @return array parameter array from last response |
|
248 | - * @access public |
|
249 | - */ |
|
250 | - function getParameters($parameters) |
|
251 | - { |
|
252 | - if ($parameters == null) { |
|
253 | - $parameters = array('timestamp', 'sessioncounter', 'sessionuse'); |
|
254 | - } |
|
255 | - $param_array = array(); |
|
256 | - foreach ($parameters as $param) { |
|
257 | - if (!preg_match("/".$param."=([0-9]+)/", $this->_response, $out)) { |
|
258 | - return PEAR::raiseError('Could not parse parameter '.$param.' from response'); |
|
259 | - } |
|
260 | - $param_array[$param] = $out[1]; |
|
261 | - } |
|
262 | - return $param_array; |
|
263 | - } |
|
264 | - |
|
265 | - /** |
|
266 | - * Verify Yubico OTP against multiple URLs |
|
267 | - * Protocol specification 2.0 is used to construct validation requests |
|
268 | - * |
|
269 | - * @param string $token Yubico OTP |
|
270 | - * @param int $use_timestamp 1=>send request with ×tamp=1 to |
|
271 | - * get timestamp and session information |
|
272 | - * in the response |
|
273 | - * @param boolean $wait_for_all If true, wait until all |
|
274 | - * servers responds (for debugging) |
|
275 | - * @param string $sl Sync level in percentage between 0 |
|
276 | - * and 100 or "fast" or "secure". |
|
277 | - * @param int $timeout Max number of seconds to wait |
|
278 | - * for responses |
|
279 | - * @return mixed PEAR error on error, true otherwise |
|
280 | - * @access public |
|
281 | - */ |
|
282 | - function verify($token, $use_timestamp = null, $wait_for_all = False, |
|
283 | - $sl = null, $timeout = null) |
|
284 | - { |
|
285 | - /* Construct parameters string */ |
|
286 | - $ret = $this->parsePasswordOTP($token); |
|
287 | - if (!$ret) { |
|
288 | - return PEAR::raiseError('Could not parse Yubikey OTP'); |
|
289 | - } |
|
290 | - $params = array('id'=>$this->_id, |
|
291 | - 'otp'=>$ret['otp'], |
|
292 | - 'nonce'=>md5(uniqid(rand()))); |
|
293 | - /* Take care of protocol version 2 parameters */ |
|
294 | - if ($use_timestamp) $params['timestamp'] = 1; |
|
295 | - if ($sl) $params['sl'] = $sl; |
|
296 | - if ($timeout) $params['timeout'] = $timeout; |
|
297 | - ksort($params); |
|
298 | - $parameters = ''; |
|
299 | - foreach ($params as $p=>$v) $parameters .= "&".$p."=".$v; |
|
300 | - $parameters = ltrim($parameters, "&"); |
|
182 | + /** |
|
183 | + * Return the last query sent to the server, if any. |
|
184 | + * |
|
185 | + * @return string Request to server |
|
186 | + * @access public |
|
187 | + */ |
|
188 | + function getLastQuery() |
|
189 | + { |
|
190 | + return $this->_lastquery; |
|
191 | + } |
|
192 | + |
|
193 | + /** |
|
194 | + * Return the last data received from the server, if any. |
|
195 | + * |
|
196 | + * @return string Output from server |
|
197 | + * @access public |
|
198 | + */ |
|
199 | + function getLastResponse() |
|
200 | + { |
|
201 | + return $this->_response; |
|
202 | + } |
|
203 | + |
|
204 | + /** |
|
205 | + * Parse input string into password, yubikey prefix, |
|
206 | + * ciphertext, and OTP. |
|
207 | + * |
|
208 | + * @param string Input string to parse |
|
209 | + * @param string Optional delimiter re-class, default is '[:]' |
|
210 | + * @param string $str |
|
211 | + * @return array Keyed array with fields |
|
212 | + * @access public |
|
213 | + */ |
|
214 | + function parsePasswordOTP($str, $delim = '[:]') |
|
215 | + { |
|
216 | + if (!preg_match("/^((.*)".$delim.")?". |
|
217 | + "(([cbdefghijklnrtuv]{0,16})". |
|
218 | + "([cbdefghijklnrtuv]{32}))$/i", |
|
219 | + $str, $matches)) { |
|
220 | + /* Dvorak? */ |
|
221 | + if (!preg_match("/^((.*)".$delim.")?". |
|
222 | + "(([jxe\.uidchtnbpygk]{0,16})". |
|
223 | + "([jxe\.uidchtnbpygk]{32}))$/i", |
|
224 | + $str, $matches)) { |
|
225 | + return false; |
|
226 | + } else { |
|
227 | + $ret['otp'] = strtr($matches[3], "jxe.uidchtnbpygk", "cbdefghijklnrtuv"); |
|
228 | + } |
|
229 | + } else { |
|
230 | + $ret['otp'] = $matches[3]; |
|
231 | + } |
|
232 | + $ret['password'] = $matches[2]; |
|
233 | + $ret['prefix'] = $matches[4]; |
|
234 | + $ret['ciphertext'] = $matches[5]; |
|
235 | + return $ret; |
|
236 | + } |
|
237 | + |
|
238 | + /* TODO? Add functions to get parsed parts of server response? */ |
|
239 | + |
|
240 | + /** |
|
241 | + * Parse parameters from last response |
|
242 | + * |
|
243 | + * example: getParameters("timestamp", "sessioncounter", "sessionuse"); |
|
244 | + * |
|
245 | + * @param array @parameters Array with strings representing |
|
246 | + * parameters to parse |
|
247 | + * @return array parameter array from last response |
|
248 | + * @access public |
|
249 | + */ |
|
250 | + function getParameters($parameters) |
|
251 | + { |
|
252 | + if ($parameters == null) { |
|
253 | + $parameters = array('timestamp', 'sessioncounter', 'sessionuse'); |
|
254 | + } |
|
255 | + $param_array = array(); |
|
256 | + foreach ($parameters as $param) { |
|
257 | + if (!preg_match("/".$param."=([0-9]+)/", $this->_response, $out)) { |
|
258 | + return PEAR::raiseError('Could not parse parameter '.$param.' from response'); |
|
259 | + } |
|
260 | + $param_array[$param] = $out[1]; |
|
261 | + } |
|
262 | + return $param_array; |
|
263 | + } |
|
264 | + |
|
265 | + /** |
|
266 | + * Verify Yubico OTP against multiple URLs |
|
267 | + * Protocol specification 2.0 is used to construct validation requests |
|
268 | + * |
|
269 | + * @param string $token Yubico OTP |
|
270 | + * @param int $use_timestamp 1=>send request with ×tamp=1 to |
|
271 | + * get timestamp and session information |
|
272 | + * in the response |
|
273 | + * @param boolean $wait_for_all If true, wait until all |
|
274 | + * servers responds (for debugging) |
|
275 | + * @param string $sl Sync level in percentage between 0 |
|
276 | + * and 100 or "fast" or "secure". |
|
277 | + * @param int $timeout Max number of seconds to wait |
|
278 | + * for responses |
|
279 | + * @return mixed PEAR error on error, true otherwise |
|
280 | + * @access public |
|
281 | + */ |
|
282 | + function verify($token, $use_timestamp = null, $wait_for_all = False, |
|
283 | + $sl = null, $timeout = null) |
|
284 | + { |
|
285 | + /* Construct parameters string */ |
|
286 | + $ret = $this->parsePasswordOTP($token); |
|
287 | + if (!$ret) { |
|
288 | + return PEAR::raiseError('Could not parse Yubikey OTP'); |
|
289 | + } |
|
290 | + $params = array('id'=>$this->_id, |
|
291 | + 'otp'=>$ret['otp'], |
|
292 | + 'nonce'=>md5(uniqid(rand()))); |
|
293 | + /* Take care of protocol version 2 parameters */ |
|
294 | + if ($use_timestamp) $params['timestamp'] = 1; |
|
295 | + if ($sl) $params['sl'] = $sl; |
|
296 | + if ($timeout) $params['timeout'] = $timeout; |
|
297 | + ksort($params); |
|
298 | + $parameters = ''; |
|
299 | + foreach ($params as $p=>$v) $parameters .= "&".$p."=".$v; |
|
300 | + $parameters = ltrim($parameters, "&"); |
|
301 | 301 | |
302 | - /* Generate signature. */ |
|
303 | - if ($this->_key <> "") { |
|
304 | - $signature = base64_encode(hash_hmac('sha1', $parameters, |
|
305 | - $this->_key, true)); |
|
306 | - $signature = preg_replace('/\+/', '%2B', $signature); |
|
307 | - $parameters .= '&h='.$signature; |
|
308 | - } |
|
309 | - |
|
310 | - /* Generate and prepare request. */ |
|
311 | - $this->_lastquery = null; |
|
312 | - $this->URLreset(); |
|
313 | - $mh = curl_multi_init(); |
|
314 | - $ch = array(); |
|
315 | - while ($URLpart = $this->getNextURLpart()) |
|
316 | - { |
|
317 | - /* Support https. */ |
|
318 | - if ($this->_https) { |
|
319 | - $query = "https://"; |
|
320 | - } else { |
|
321 | - $query = "http://"; |
|
322 | - } |
|
323 | - $query .= $URLpart."?".$parameters; |
|
324 | - |
|
325 | - if ($this->_lastquery) { $this->_lastquery .= " "; } |
|
326 | - $this->_lastquery .= $query; |
|
302 | + /* Generate signature. */ |
|
303 | + if ($this->_key <> "") { |
|
304 | + $signature = base64_encode(hash_hmac('sha1', $parameters, |
|
305 | + $this->_key, true)); |
|
306 | + $signature = preg_replace('/\+/', '%2B', $signature); |
|
307 | + $parameters .= '&h='.$signature; |
|
308 | + } |
|
309 | + |
|
310 | + /* Generate and prepare request. */ |
|
311 | + $this->_lastquery = null; |
|
312 | + $this->URLreset(); |
|
313 | + $mh = curl_multi_init(); |
|
314 | + $ch = array(); |
|
315 | + while ($URLpart = $this->getNextURLpart()) |
|
316 | + { |
|
317 | + /* Support https. */ |
|
318 | + if ($this->_https) { |
|
319 | + $query = "https://"; |
|
320 | + } else { |
|
321 | + $query = "http://"; |
|
322 | + } |
|
323 | + $query .= $URLpart."?".$parameters; |
|
324 | + |
|
325 | + if ($this->_lastquery) { $this->_lastquery .= " "; } |
|
326 | + $this->_lastquery .= $query; |
|
327 | 327 | |
328 | - $handle = curl_init($query); |
|
329 | - curl_setopt($handle, CURLOPT_USERAGENT, "PEAR Auth_Yubico"); |
|
330 | - curl_setopt($handle, CURLOPT_RETURNTRANSFER, 1); |
|
331 | - if (!$this->_httpsverify) { |
|
332 | - curl_setopt($handle, CURLOPT_SSL_VERIFYPEER, 0); |
|
333 | - curl_setopt($handle, CURLOPT_SSL_VERIFYHOST, 0); |
|
334 | - } |
|
335 | - curl_setopt($handle, CURLOPT_FAILONERROR, true); |
|
336 | - /* If timeout is set, we better apply it here as well |
|
328 | + $handle = curl_init($query); |
|
329 | + curl_setopt($handle, CURLOPT_USERAGENT, "PEAR Auth_Yubico"); |
|
330 | + curl_setopt($handle, CURLOPT_RETURNTRANSFER, 1); |
|
331 | + if (!$this->_httpsverify) { |
|
332 | + curl_setopt($handle, CURLOPT_SSL_VERIFYPEER, 0); |
|
333 | + curl_setopt($handle, CURLOPT_SSL_VERIFYHOST, 0); |
|
334 | + } |
|
335 | + curl_setopt($handle, CURLOPT_FAILONERROR, true); |
|
336 | + /* If timeout is set, we better apply it here as well |
|
337 | 337 | in case the validation server fails to follow it. |
338 | 338 | */ |
339 | - if ($timeout) { |
|
340 | - curl_setopt($handle, CURLOPT_TIMEOUT, $timeout); |
|
341 | - } |
|
342 | - curl_multi_add_handle($mh, $handle); |
|
339 | + if ($timeout) { |
|
340 | + curl_setopt($handle, CURLOPT_TIMEOUT, $timeout); |
|
341 | + } |
|
342 | + curl_multi_add_handle($mh, $handle); |
|
343 | 343 | |
344 | - $ch[(int) $handle] = $handle; |
|
345 | - } |
|
346 | - |
|
347 | - /* Execute and read request. */ |
|
348 | - $this->_response = null; |
|
349 | - $replay = False; |
|
350 | - $valid = False; |
|
351 | - do { |
|
352 | - /* Let curl do its work. */ |
|
353 | - while (($mrc = curl_multi_exec($mh, $active)) |
|
354 | - == CURLM_CALL_MULTI_PERFORM) |
|
355 | - ; |
|
356 | - |
|
357 | - while ($info = curl_multi_info_read($mh)) { |
|
358 | - if ($info['result'] == CURLE_OK) { |
|
359 | - |
|
360 | - /* We have a complete response from one server. */ |
|
361 | - |
|
362 | - $str = curl_multi_getcontent($info['handle']); |
|
363 | - $cinfo = curl_getinfo($info['handle']); |
|
344 | + $ch[(int) $handle] = $handle; |
|
345 | + } |
|
346 | + |
|
347 | + /* Execute and read request. */ |
|
348 | + $this->_response = null; |
|
349 | + $replay = False; |
|
350 | + $valid = False; |
|
351 | + do { |
|
352 | + /* Let curl do its work. */ |
|
353 | + while (($mrc = curl_multi_exec($mh, $active)) |
|
354 | + == CURLM_CALL_MULTI_PERFORM) |
|
355 | + ; |
|
356 | + |
|
357 | + while ($info = curl_multi_info_read($mh)) { |
|
358 | + if ($info['result'] == CURLE_OK) { |
|
359 | + |
|
360 | + /* We have a complete response from one server. */ |
|
361 | + |
|
362 | + $str = curl_multi_getcontent($info['handle']); |
|
363 | + $cinfo = curl_getinfo($info['handle']); |
|
364 | 364 | |
365 | - if ($wait_for_all) { # Better debug info |
|
366 | - $this->_response .= 'URL='.$cinfo['url']."\n" |
|
367 | - . $str."\n"; |
|
368 | - } |
|
365 | + if ($wait_for_all) { # Better debug info |
|
366 | + $this->_response .= 'URL='.$cinfo['url']."\n" |
|
367 | + . $str."\n"; |
|
368 | + } |
|
369 | 369 | |
370 | - if (preg_match("/status=([a-zA-Z0-9_]+)/", $str, $out)) { |
|
371 | - $status = $out[1]; |
|
370 | + if (preg_match("/status=([a-zA-Z0-9_]+)/", $str, $out)) { |
|
371 | + $status = $out[1]; |
|
372 | 372 | |
373 | - /* |
|
373 | + /* |
|
374 | 374 | * There are 3 cases. |
375 | 375 | * |
376 | 376 | * 1. OTP or Nonce values doesn't match - ignore |
@@ -389,7 +389,7 @@ discard block |
||
389 | 389 | elseif ($this->_key <> "") { |
390 | 390 | /* Case 2. Verify signature first */ |
391 | 391 | $rows = explode("\r\n", trim($str)); |
392 | - $response=array(); |
|
392 | + $response = array(); |
|
393 | 393 | while (list($key, $val) = each($rows)) { |
394 | 394 | /* = is also used in BASE64 encoding so we only replace the first = by # which is not used in BASE64 */ |
395 | 395 | $val = preg_replace('/=/', '#', $val, 1); |
@@ -397,13 +397,13 @@ discard block |
||
397 | 397 | $response[$row[0]] = $row[1]; |
398 | 398 | } |
399 | 399 | |
400 | - $parameters=array('nonce','otp', 'sessioncounter', 'sessionuse', 'sl', 'status', 't', 'timeout', 'timestamp'); |
|
400 | + $parameters = array('nonce', 'otp', 'sessioncounter', 'sessionuse', 'sl', 'status', 't', 'timeout', 'timestamp'); |
|
401 | 401 | sort($parameters); |
402 | - $check=Null; |
|
402 | + $check = Null; |
|
403 | 403 | foreach ($parameters as $param) { |
404 | 404 | if (array_key_exists($param, $response)) { |
405 | - if ($check) $check = $check . '&'; |
|
406 | - $check = $check . $param . '=' . $response[$param]; |
|
405 | + if ($check) $check = $check.'&'; |
|
406 | + $check = $check.$param.'='.$response[$param]; |
|
407 | 407 | } |
408 | 408 | } |
409 | 409 | |
@@ -411,25 +411,25 @@ discard block |
||
411 | 411 | base64_encode(hash_hmac('sha1', utf8_encode($check), |
412 | 412 | $this->_key, true)); |
413 | 413 | |
414 | - if($response['h'] == $checksignature) { |
|
414 | + if ($response['h'] == $checksignature) { |
|
415 | 415 | if ($status == 'REPLAYED_OTP') { |
416 | 416 | if (!$wait_for_all) { $this->_response = $str; } |
417 | - $replay=True; |
|
417 | + $replay = True; |
|
418 | 418 | } |
419 | 419 | if ($status == 'OK') { |
420 | 420 | if (!$wait_for_all) { $this->_response = $str; } |
421 | - $valid=True; |
|
421 | + $valid = True; |
|
422 | 422 | } |
423 | 423 | } |
424 | 424 | } else { |
425 | 425 | /* Case 3. We check the status directly */ |
426 | 426 | if ($status == 'REPLAYED_OTP') { |
427 | 427 | if (!$wait_for_all) { $this->_response = $str; } |
428 | - $replay=True; |
|
428 | + $replay = True; |
|
429 | 429 | } |
430 | 430 | if ($status == 'OK') { |
431 | 431 | if (!$wait_for_all) { $this->_response = $str; } |
432 | - $valid=True; |
|
432 | + $valid = True; |
|
433 | 433 | } |
434 | 434 | } |
435 | 435 | } |
@@ -448,7 +448,7 @@ discard block |
||
448 | 448 | |
449 | 449 | curl_multi_remove_handle($mh, $info['handle']); |
450 | 450 | curl_close($info['handle']); |
451 | - unset ($ch[(int)$info['handle']]); |
|
451 | + unset ($ch[(int) $info['handle']]); |
|
452 | 452 | } |
453 | 453 | curl_multi_select($mh); |
454 | 454 | } |
@@ -460,10 +460,10 @@ discard block |
||
460 | 460 | */ |
461 | 461 | |
462 | 462 | foreach ($ch as $h) { |
463 | - curl_multi_remove_handle ($mh, $h); |
|
464 | - curl_close ($h); |
|
463 | + curl_multi_remove_handle($mh, $h); |
|
464 | + curl_close($h); |
|
465 | 465 | } |
466 | - curl_multi_close ($mh); |
|
466 | + curl_multi_close($mh); |
|
467 | 467 | |
468 | 468 | if ($replay) return PEAR::raiseError('REPLAYED_OTP'); |
469 | 469 | if ($valid) return true; |
@@ -148,15 +148,21 @@ discard block |
||
148 | 148 | */ |
149 | 149 | function getNextURLpart() |
150 | 150 | { |
151 | - if ($this->_url_list) $url_list = $this->_url_list; |
|
152 | - else $url_list = array('api.yubico.com/wsapi/2.0/verify', |
|
151 | + if ($this->_url_list) { |
|
152 | + $url_list = $this->_url_list; |
|
153 | + } else { |
|
154 | + $url_list = array('api.yubico.com/wsapi/2.0/verify', |
|
153 | 155 | 'api2.yubico.com/wsapi/2.0/verify', |
154 | 156 | 'api3.yubico.com/wsapi/2.0/verify', |
155 | 157 | 'api4.yubico.com/wsapi/2.0/verify', |
156 | 158 | 'api5.yubico.com/wsapi/2.0/verify'); |
159 | + } |
|
157 | 160 | |
158 | - if ($this->_url_index >= count($url_list)) return false; |
|
159 | - else return $url_list[$this->_url_index++]; |
|
161 | + if ($this->_url_index >= count($url_list)) { |
|
162 | + return false; |
|
163 | + } else { |
|
164 | + return $url_list[$this->_url_index++]; |
|
165 | + } |
|
160 | 166 | } |
161 | 167 | |
162 | 168 | /** |
@@ -291,12 +297,20 @@ discard block |
||
291 | 297 | 'otp'=>$ret['otp'], |
292 | 298 | 'nonce'=>md5(uniqid(rand()))); |
293 | 299 | /* Take care of protocol version 2 parameters */ |
294 | - if ($use_timestamp) $params['timestamp'] = 1; |
|
295 | - if ($sl) $params['sl'] = $sl; |
|
296 | - if ($timeout) $params['timeout'] = $timeout; |
|
300 | + if ($use_timestamp) { |
|
301 | + $params['timestamp'] = 1; |
|
302 | + } |
|
303 | + if ($sl) { |
|
304 | + $params['sl'] = $sl; |
|
305 | + } |
|
306 | + if ($timeout) { |
|
307 | + $params['timeout'] = $timeout; |
|
308 | + } |
|
297 | 309 | ksort($params); |
298 | 310 | $parameters = ''; |
299 | - foreach ($params as $p=>$v) $parameters .= "&".$p."=".$v; |
|
311 | + foreach ($params as $p=>$v) { |
|
312 | + $parameters .= "&".$p."=".$v; |
|
313 | + } |
|
300 | 314 | $parameters = ltrim($parameters, "&"); |
301 | 315 | |
302 | 316 | /* Generate signature. */ |
@@ -385,8 +399,7 @@ discard block |
||
385 | 399 | if (!preg_match("/otp=".$params['otp']."/", $str) || |
386 | 400 | !preg_match("/nonce=".$params['nonce']."/", $str)) { |
387 | 401 | /* Case 1. Ignore response. */ |
388 | - } |
|
389 | - elseif ($this->_key <> "") { |
|
402 | + } elseif ($this->_key <> "") { |
|
390 | 403 | /* Case 2. Verify signature first */ |
391 | 404 | $rows = explode("\r\n", trim($str)); |
392 | 405 | $response=array(); |
@@ -402,7 +415,9 @@ discard block |
||
402 | 415 | $check=Null; |
403 | 416 | foreach ($parameters as $param) { |
404 | 417 | if (array_key_exists($param, $response)) { |
405 | - if ($check) $check = $check . '&'; |
|
418 | + if ($check) { |
|
419 | + $check = $check . '&'; |
|
420 | + } |
|
406 | 421 | $check = $check . $param . '=' . $response[$param]; |
407 | 422 | } |
408 | 423 | } |
@@ -441,8 +456,12 @@ discard block |
||
441 | 456 | curl_close($h); |
442 | 457 | } |
443 | 458 | curl_multi_close($mh); |
444 | - if ($replay) return PEAR::raiseError('REPLAYED_OTP'); |
|
445 | - if ($valid) return true; |
|
459 | + if ($replay) { |
|
460 | + return PEAR::raiseError('REPLAYED_OTP'); |
|
461 | + } |
|
462 | + if ($valid) { |
|
463 | + return true; |
|
464 | + } |
|
446 | 465 | return PEAR::raiseError($status); |
447 | 466 | } |
448 | 467 | |
@@ -465,8 +484,12 @@ discard block |
||
465 | 484 | } |
466 | 485 | curl_multi_close ($mh); |
467 | 486 | |
468 | - if ($replay) return PEAR::raiseError('REPLAYED_OTP'); |
|
469 | - if ($valid) return true; |
|
487 | + if ($replay) { |
|
488 | + return PEAR::raiseError('REPLAYED_OTP'); |
|
489 | + } |
|
490 | + if ($valid) { |
|
491 | + return true; |
|
492 | + } |
|
470 | 493 | return PEAR::raiseError('NO_VALID_ANSWER'); |
471 | 494 | } |
472 | 495 | } |
@@ -1,58 +1,58 @@ |
||
1 | 1 | <?php |
2 | 2 | class AXSILPortal_V1_Auth { |
3 | - var $server; |
|
3 | + var $server; |
|
4 | 4 | |
5 | - private $url = ""; |
|
6 | - private $AAId = ""; |
|
7 | - private $apiKey = ""; |
|
5 | + private $url = ""; |
|
6 | + private $AAId = ""; |
|
7 | + private $apiKey = ""; |
|
8 | 8 | |
9 | - private $baseUrl = ""; |
|
9 | + private $baseUrl = ""; |
|
10 | 10 | |
11 | - function setUrl($url) { |
|
12 | - $this->url = $url; |
|
13 | - } |
|
11 | + function setUrl($url) { |
|
12 | + $this->url = $url; |
|
13 | + } |
|
14 | 14 | |
15 | - function setAAId($AAId) { |
|
16 | - $this->AAId = $AAId; |
|
17 | - } |
|
15 | + function setAAId($AAId) { |
|
16 | + $this->AAId = $AAId; |
|
17 | + } |
|
18 | 18 | |
19 | - function setApiKey($apiKey) { |
|
20 | - $this->apiKey = $apiKey; |
|
21 | - } |
|
19 | + function setApiKey($apiKey) { |
|
20 | + $this->apiKey = $apiKey; |
|
21 | + } |
|
22 | 22 | |
23 | 23 | |
24 | - // Verify that you can open the URL from the web server. |
|
25 | - function create() { |
|
26 | - if ($this->url != "" && $this->AAId != "" && $this->apiKey != "") { |
|
27 | - $this->baseUrl = $this->url."".$this->apiKey."/".$this->AAId; |
|
28 | - } else { |
|
29 | - die("Cannot initialize Agses webservice without credentials, please set them in settings"); |
|
30 | - } |
|
31 | - } |
|
24 | + // Verify that you can open the URL from the web server. |
|
25 | + function create() { |
|
26 | + if ($this->url != "" && $this->AAId != "" && $this->apiKey != "") { |
|
27 | + $this->baseUrl = $this->url."".$this->apiKey."/".$this->AAId; |
|
28 | + } else { |
|
29 | + die("Cannot initialize Agses webservice without credentials, please set them in settings"); |
|
30 | + } |
|
31 | + } |
|
32 | 32 | |
33 | - function createAuthenticationMessage($apn, $createFlickerCode, $returnPath, $authenticationLevel, $hedgeId) { |
|
33 | + function createAuthenticationMessage($apn, $createFlickerCode, $returnPath, $authenticationLevel, $hedgeId) { |
|
34 | 34 | |
35 | - $serviceCall = $this->baseUrl."/authmessage/".$apn."/create/".$hedgeId; |
|
35 | + $serviceCall = $this->baseUrl."/authmessage/".$apn."/create/".$hedgeId; |
|
36 | 36 | |
37 | - $json = file_get_contents($serviceCall); |
|
38 | - $response = json_decode($json, true); |
|
37 | + $json = file_get_contents($serviceCall); |
|
38 | + $response = json_decode($json, true); |
|
39 | 39 | |
40 | - return $response['flickerCode']; |
|
41 | - } |
|
42 | - |
|
43 | - /** |
|
44 | - * @param string $response |
|
45 | - * @param string $hedgeId |
|
46 | - */ |
|
47 | - function verifyResponse($apn, $response, $hedgeId) { |
|
40 | + return $response['flickerCode']; |
|
41 | + } |
|
42 | + |
|
43 | + /** |
|
44 | + * @param string $response |
|
45 | + * @param string $hedgeId |
|
46 | + */ |
|
47 | + function verifyResponse($apn, $response, $hedgeId) { |
|
48 | 48 | |
49 | - $serviceCall = $this->baseUrl."/authmessage/".$apn."/verify/".$hedgeId."/".$response; |
|
49 | + $serviceCall = $this->baseUrl."/authmessage/".$apn."/verify/".$hedgeId."/".$response; |
|
50 | 50 | |
51 | - $json = file_get_contents($serviceCall); |
|
52 | - $response = json_decode($json, true); |
|
51 | + $json = file_get_contents($serviceCall); |
|
52 | + $response = json_decode($json, true); |
|
53 | 53 | |
54 | - return $response['response']; |
|
55 | - } |
|
54 | + return $response['response']; |
|
55 | + } |
|
56 | 56 | |
57 | 57 | } |
58 | 58 | ?> |
59 | 59 | \ No newline at end of file |
@@ -52,21 +52,21 @@ discard block |
||
52 | 52 | // get frame delay from GET request, default to "safe speed" if delay not |
53 | 53 | // defined or invalid. delay is specified in ms in the request and needs |
54 | 54 | // to be converted to 1/100s for use in GIF files |
55 | - $delay = isset($_GET['delay']) ? ($_GET['delay']+0)/10 : 8; |
|
55 | + $delay = isset($_GET['delay']) ? ($_GET['delay'] + 0) / 10 : 8; |
|
56 | 56 | $delay = ($delay > 0) ? $delay : 8; |
57 | 57 | |
58 | 58 | // code string must only contain hex characters, code length is limited to |
59 | 59 | // 1024 characters (512 frames) |
60 | 60 | $codelen = strlen($code); |
61 | - if ( ctype_xdigit($code) && $codelen < 1024 ) { |
|
61 | + if (ctype_xdigit($code) && $codelen < 1024) { |
|
62 | 62 | |
63 | 63 | // get prepared gif file header |
64 | - $gif = file_get_contents($path.'/head.bin'); |
|
64 | + $gif = file_get_contents($path.'/head.bin'); |
|
65 | 65 | |
66 | 66 | // build graphic control extension block |
67 | 67 | // disposal method = 0 |
68 | 68 | // transparent color = 255 |
69 | - $ext = "\x21\xf9\x04\x01".chr($delay&0xff).chr(($delay>>8)&0xff)."\xff\x00"; |
|
69 | + $ext = "\x21\xf9\x04\x01".chr($delay & 0xff).chr(($delay >> 8) & 0xff)."\xff\x00"; |
|
70 | 70 | |
71 | 71 | // output image header |
72 | 72 | header('Content-type:image/gif'); |
@@ -74,28 +74,28 @@ discard block |
||
74 | 74 | |
75 | 75 | // append image data blocks as necessary |
76 | 76 | $size = filesize($path.'/data.bin'); |
77 | - $data = fopen($path.'/data.bin','r'); |
|
77 | + $data = fopen($path.'/data.bin', 'r'); |
|
78 | 78 | if ($data) { |
79 | 79 | |
80 | 80 | // load the index from the data file and unpack it into a PHP array. |
81 | 81 | // the index array contains the file offsets of the 4096 delta and |
82 | 82 | // base images inside the data file. |
83 | - $index = unpack("V*", fread($data, 64*64*4)); |
|
83 | + $index = unpack("V*", fread($data, 64 * 64 * 4)); |
|
84 | 84 | |
85 | 85 | // when a code is repeated (prev and curr have the same value) a |
86 | 86 | // base image is inserted instead of a delta image. the first frame |
87 | 87 | // in the animation must be a base image, so we peek at the flicker |
88 | 88 | // code and set $prev to the first value in the string |
89 | 89 | $prev = hexdec(substr($code, 0, 2)); |
90 | - for ($i = 0; $i < $codelen; $i+=2) { |
|
90 | + for ($i = 0; $i < $codelen; $i += 2) { |
|
91 | 91 | |
92 | 92 | // get current code |
93 | 93 | $curr = hexdec(substr($code, $i, 2)); |
94 | 94 | |
95 | 95 | // locate image block in data file |
96 | - $blockIdx = $prev*64+$curr+1; // array starts at 1 |
|
96 | + $blockIdx = $prev * 64 + $curr + 1; // array starts at 1 |
|
97 | 97 | $blockPos = $index[$blockIdx]; |
98 | - $blockLen = ($blockIdx < 4096 ? $index[$blockIdx+1] : $size) - $blockPos; |
|
98 | + $blockLen = ($blockIdx < 4096 ? $index[$blockIdx + 1] : $size) - $blockPos; |
|
99 | 99 | |
100 | 100 | // output extension header |
101 | 101 | print($ext); |