@@ -74,8 +74,8 @@ |
||
| 74 | 74 | function reloadCacheTable(): void |
| 75 | 75 | { |
| 76 | 76 | // Load expected files |
| 77 | - require_once __DIR__. '/../sources/main.functions.php'; |
|
| 78 | - include __DIR__. '/../includes/config/tp.config.php'; |
|
| 77 | + require_once __DIR__.'/../sources/main.functions.php'; |
|
| 78 | + include __DIR__.'/../includes/config/tp.config.php'; |
|
| 79 | 79 | |
| 80 | 80 | updateCacheTable('reload', NULL); |
| 81 | 81 | } |
| 82 | 82 | \ No newline at end of file |
@@ -24,7 +24,7 @@ discard block |
||
| 24 | 24 | */ |
| 25 | 25 | use TeampassClasses\NestedTree\NestedTree; |
| 26 | 26 | |
| 27 | -require_once API_ROOT_PATH . "/Model/Database.php"; |
|
| 27 | +require_once API_ROOT_PATH."/Model/Database.php"; |
|
| 28 | 28 | |
| 29 | 29 | class ItemModel extends Database |
| 30 | 30 | { |
@@ -46,16 +46,16 @@ discard block |
||
| 46 | 46 | "SELECT i.id, label, description, i.pw, i.url, i.id_tree, i.login, i.email, i.viewed_no, i.fa_icon, i.inactif, i.perso, t.title as folder_label |
| 47 | 47 | FROM ".prefixTable('items')." as i |
| 48 | 48 | LEFT JOIN ".prefixTable('nested_tree')." as t ON (t.id = i.id_tree) ". |
| 49 | - $sqlExtra . |
|
| 50 | - " ORDER BY i.id ASC" . |
|
| 49 | + $sqlExtra. |
|
| 50 | + " ORDER BY i.id ASC". |
|
| 51 | 51 | //($limit > 0 ? " LIMIT ?". ["i", $limit] : '') |
| 52 | - ($limit > 0 ? " LIMIT ". $limit : '') |
|
| 52 | + ($limit > 0 ? " LIMIT ".$limit : '') |
|
| 53 | 53 | ); |
| 54 | 54 | $ret = []; |
| 55 | 55 | foreach ($rows as $row) { |
| 56 | 56 | $userKey = $this->select( |
| 57 | 57 | 'SELECT share_key |
| 58 | - FROM ' . prefixTable('sharekeys_items') . ' |
|
| 58 | + FROM ' . prefixTable('sharekeys_items').' |
|
| 59 | 59 | WHERE user_id = '.$userId.' AND object_id = '.$row['id'] |
| 60 | 60 | ); |
| 61 | 61 | if (count($userKey) === 0 || empty($row['pw']) === true) { |
@@ -89,7 +89,7 @@ discard block |
||
| 89 | 89 | if (empty($path) === true) { |
| 90 | 90 | $path = htmlspecialchars(stripslashes(htmlspecialchars_decode($elem->title, ENT_QUOTES)), ENT_QUOTES); |
| 91 | 91 | } else { |
| 92 | - $path .= '/' . htmlspecialchars(stripslashes(htmlspecialchars_decode($elem->title, ENT_QUOTES)), ENT_QUOTES); |
|
| 92 | + $path .= '/'.htmlspecialchars(stripslashes(htmlspecialchars_decode($elem->title, ENT_QUOTES)), ENT_QUOTES); |
|
| 93 | 93 | } |
| 94 | 94 | } |
| 95 | 95 | |
@@ -30,13 +30,13 @@ discard block |
||
| 30 | 30 | header("Access-Control-Allow-Methods: POST"); |
| 31 | 31 | header("Access-Control-Max-Age: 3600"); |
| 32 | 32 | header("Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With"); |
| 33 | -require __DIR__ . "/inc/bootstrap.php"; |
|
| 33 | +require __DIR__."/inc/bootstrap.php"; |
|
| 34 | 34 | |
| 35 | 35 | // sanitize url segments |
| 36 | 36 | $base = new BaseController(); |
| 37 | 37 | $uri = $base->getUriSegments(); |
| 38 | 38 | if (is_array($uri) === false || is_string($uri) === true) { |
| 39 | - $uri = [$uri]; // ensure $uril is table |
|
| 39 | + $uri = [$uri]; // ensure $uril is table |
|
| 40 | 40 | } |
| 41 | 41 | |
| 42 | 42 | // Prepare DB password |
@@ -52,9 +52,9 @@ discard block |
||
| 52 | 52 | if ($uri[0] === 'authorize') { |
| 53 | 53 | // Is API enabled in Teampass settings |
| 54 | 54 | if ($apiStatus['error'] === false) { |
| 55 | - require API_ROOT_PATH . "/Controller/Api/AuthController.php"; |
|
| 55 | + require API_ROOT_PATH."/Controller/Api/AuthController.php"; |
|
| 56 | 56 | $objFeedController = new AuthController(); |
| 57 | - $strMethodName = $uri[0] . 'Action'; |
|
| 57 | + $strMethodName = $uri[0].'Action'; |
|
| 58 | 58 | $objFeedController->{$strMethodName}(); |
| 59 | 59 | } else { |
| 60 | 60 | // Error management |
@@ -80,9 +80,9 @@ discard block |
||
| 80 | 80 | |
| 81 | 81 | // action related to USER |
| 82 | 82 | } elseif ($controller === 'user') { |
| 83 | - require API_ROOT_PATH . "/Controller/Api/UserController.php"; |
|
| 83 | + require API_ROOT_PATH."/Controller/Api/UserController.php"; |
|
| 84 | 84 | $objFeedController = new UserController(); |
| 85 | - $strMethodName = (string) $action . 'Action'; |
|
| 85 | + $strMethodName = (string) $action.'Action'; |
|
| 86 | 86 | $objFeedController->{$strMethodName}(); |
| 87 | 87 | |
| 88 | 88 | // action related to ITEM |
@@ -160,7 +160,7 @@ discard block |
||
| 160 | 160 | |
| 161 | 161 | // Show passwords inputs and form |
| 162 | 162 | $('#dialog-user-change-password-info') |
| 163 | - .html('<i class="icon fa-solid fa-info mr-2"></i><?php echo $lang->get('user_has_to_change_password_info');?>') |
|
| 163 | + .html('<i class="icon fa-solid fa-info mr-2"></i><?php echo $lang->get('user_has_to_change_password_info'); ?>') |
|
| 164 | 164 | .removeClass('hidden'); |
| 165 | 165 | $('#dialog-user-change-password').removeClass('hidden'); |
| 166 | 166 | |
@@ -173,7 +173,7 @@ discard block |
||
| 173 | 173 | |
| 174 | 174 | // Show passwords inputs and form |
| 175 | 175 | $('#dialog-ldap-user-change-password-info') |
| 176 | - .html('<i class="icon fa-solid fa-info mr-2"></i><?php echo $lang->get('ldap_user_has_changed_his_password');?>') |
|
| 176 | + .html('<i class="icon fa-solid fa-info mr-2"></i><?php echo $lang->get('ldap_user_has_changed_his_password'); ?>') |
|
| 177 | 177 | .removeClass('hidden'); |
| 178 | 178 | $('#dialog-ldap-user-change-password').removeClass('hidden'); |
| 179 | 179 | |
@@ -300,7 +300,7 @@ discard block |
||
| 300 | 300 | /*console.log('User has to regenerate keys') |
| 301 | 301 | // HIde |
| 302 | 302 | $('.content-header, .content').addClass('hidden'); |
| 303 | - $('#dialog-user-temporary-code-info').html('<i class="icon fa-solid fa-info mr-2"></i><?php echo $lang->get('renecyption_expected');?>'); |
|
| 303 | + $('#dialog-user-temporary-code-info').html('<i class="icon fa-solid fa-info mr-2"></i><?php echo $lang->get('renecyption_expected'); ?>'); |
|
| 304 | 304 | |
| 305 | 305 | // Show passwords inputs and form |
| 306 | 306 | $('#dialog-user-temporary-code').removeClass('hidden'); |
@@ -382,13 +382,13 @@ discard block |
||
| 382 | 382 | { |
| 383 | 383 | if (step === 'psk') { |
| 384 | 384 | // Inform user |
| 385 | - $("#user-current-defuse-psk-progress").html('<b><?php echo $lang->get('encryption_keys'); ?> </b> [' + start + ' - ' + (parseInt(start) + <?php echo NUMBER_ITEMS_IN_BATCH;?>) + '] ' + |
|
| 385 | + $("#user-current-defuse-psk-progress").html('<b><?php echo $lang->get('encryption_keys'); ?> </b> [' + start + ' - ' + (parseInt(start) + <?php echo NUMBER_ITEMS_IN_BATCH; ?>) + '] ' + |
|
| 386 | 386 | '... <?php echo $lang->get('please_wait'); ?><i class="fa-solid fa-spinner fa-pulse ml-3 text-primary"></i>'); |
| 387 | 387 | |
| 388 | 388 | var data = { |
| 389 | 389 | 'userPsk' : $('#user-current-defuse-psk').val(), |
| 390 | 390 | 'start': start, |
| 391 | - 'length': <?php echo NUMBER_ITEMS_IN_BATCH;?>, |
|
| 391 | + 'length': <?php echo NUMBER_ITEMS_IN_BATCH; ?>, |
|
| 392 | 392 | 'user_id': userId, |
| 393 | 393 | }; |
| 394 | 394 | // Do query |
@@ -465,7 +465,7 @@ discard block |
||
| 465 | 465 | |
| 466 | 466 | // Show passwords inputs and form |
| 467 | 467 | $('#dialog-ldap-user-change-password-info') |
| 468 | - .html('<i class="icon fa-solid fa-info mr-2"></i><?php echo $lang->get('ldap_user_has_changed_his_password');?>') |
|
| 468 | + .html('<i class="icon fa-solid fa-info mr-2"></i><?php echo $lang->get('ldap_user_has_changed_his_password'); ?>') |
|
| 469 | 469 | .removeClass('hidden'); |
| 470 | 470 | $('#dialog-ldap-user-change-password').removeClass('hidden'); |
| 471 | 471 | |
@@ -554,7 +554,7 @@ discard block |
||
| 554 | 554 | '</div>' + |
| 555 | 555 | '</div>' + |
| 556 | 556 | '</div>' + |
| 557 | - '<div class="row mt-2<?php echo isset($SETTINGS['enable_pf_feature']) === true && (int) $SETTINGS['enable_pf_feature'] === 1 ? '' : ' hidden'; ?>">' + |
|
| 557 | + '<div class="row mt-2<?php echo isset($SETTINGS['enable_pf_feature']) === true && (int) $SETTINGS['enable_pf_feature'] === 1 ? '' : ' hidden'; ?>">' + |
|
| 558 | 558 | '<h6><?php echo $lang->get('provide_recovery_keys'); ?></h6>' + |
| 559 | 559 | '<div class="input-group mb-2">' + |
| 560 | 560 | '<div class="input-group-prepend">' + |
@@ -569,7 +569,7 @@ discard block |
||
| 569 | 569 | '<textarea rows="2" id="recovery-private-key" class="form-control form-item-control"></textarea>' + |
| 570 | 570 | '</div>' + |
| 571 | 571 | '</div>' + |
| 572 | - '<div class="row mt-2<?php echo isset($SETTINGS['enable_pf_feature']) === true && (int) $SETTINGS['enable_pf_feature'] === 1 ? '' : ' hidden'; ?>">' + |
|
| 572 | + '<div class="row mt-2<?php echo isset($SETTINGS['enable_pf_feature']) === true && (int) $SETTINGS['enable_pf_feature'] === 1 ? '' : ' hidden'; ?>">' + |
|
| 573 | 573 | '<div class="alert" id="confirm-no-recovery-keys-div">' + |
| 574 | 574 | '<div class="form-check">' + |
| 575 | 575 | '<input type="checkbox" class="form-check-input" id="confirm-no-recovery-keys">' + |
@@ -1073,15 +1073,15 @@ discard block |
||
| 1073 | 1073 | // Prepare data |
| 1074 | 1074 | var data = { |
| 1075 | 1075 | 'receipt': $('#temp-user-email').val(), |
| 1076 | - 'subject': '[Teampass] <?php echo $lang->get('your_new_password');?>', |
|
| 1077 | - 'body': '<?php echo $lang->get('email_body_temporary_login_password');?>', |
|
| 1076 | + 'subject': '[Teampass] <?php echo $lang->get('your_new_password'); ?>', |
|
| 1077 | + 'body': '<?php echo $lang->get('email_body_temporary_login_password'); ?>', |
|
| 1078 | 1078 | 'pre_replace' : { |
| 1079 | 1079 | '#enc_code#' : $('#temp-user-pwd').val(), |
| 1080 | 1080 | } |
| 1081 | 1081 | } |
| 1082 | 1082 | if (debugJavascript === true) console.log(data); |
| 1083 | 1083 | // Prepare form |
| 1084 | - $('#dialog-admin-change-user-password-info').html('<?php echo $lang->get('sending_email_message');?>'); |
|
| 1084 | + $('#dialog-admin-change-user-password-info').html('<?php echo $lang->get('sending_email_message'); ?>'); |
|
| 1085 | 1085 | toastr.remove(); |
| 1086 | 1086 | toastr.info( |
| 1087 | 1087 | '<?php echo $lang->get('in_progress'); ?><i class="fa-solid fa-circle-notch fa-spin fa-2x ml-3"></i>' |
@@ -1593,7 +1593,7 @@ discard block |
||
| 1593 | 1593 | '#warningModal', |
| 1594 | 1594 | '<i class="fa-solid fa-clock fa-lg warning mr-2"></i><?php echo $lang->get('index_add_one_hour'); ?>', |
| 1595 | 1595 | '<div class="form-group">' + |
| 1596 | - '<label for="warningModal-input" class="col-form-label"><?php echo $lang->get('extend_session_duration_by') . ' (' . $lang->get('minutes') . ')'; ?>:</label>' + |
|
| 1596 | + '<label for="warningModal-input" class="col-form-label"><?php echo $lang->get('extend_session_duration_by').' ('.$lang->get('minutes').')'; ?>:</label>' + |
|
| 1597 | 1597 | '<input type="number" max="'+(60*60*24)+'" class="form-control" id="warningModal-input" value="60">' + |
| 1598 | 1598 | '</div>' + |
| 1599 | 1599 | '<div class="form-text text-muted"><i class=\"fa-solid fa-info-circle mr-2\"></i><?php echo $lang->get('maximum_session_expiration_time'); ?>: '+data.max_session_duration+'</div>', |
@@ -76,7 +76,7 @@ discard block |
||
| 76 | 76 | DB::debugmode(false); |
| 77 | 77 | $process_to_perform = DB::queryfirstrow( |
| 78 | 78 | 'SELECT * |
| 79 | - FROM ' . prefixTable('processes') . ' |
|
| 79 | + FROM ' . prefixTable('processes').' |
|
| 80 | 80 | WHERE is_in_progress = %i AND process_type = %s |
| 81 | 81 | ORDER BY increment_id ASC', |
| 82 | 82 | 1, |
@@ -96,7 +96,7 @@ discard block |
||
| 96 | 96 | // search for next process to handle |
| 97 | 97 | $process_to_perform = DB::queryfirstrow( |
| 98 | 98 | 'SELECT * |
| 99 | - FROM ' . prefixTable('processes') . ' |
|
| 99 | + FROM ' . prefixTable('processes').' |
|
| 100 | 100 | WHERE is_in_progress = %i AND finished_at = "" AND process_type = %s |
| 101 | 101 | ORDER BY increment_id ASC', |
| 102 | 102 | 0, |
@@ -114,7 +114,7 @@ discard block |
||
| 114 | 114 | $process_to_perform['increment_id'] |
| 115 | 115 | ); |
| 116 | 116 | |
| 117 | - provideLog('[PROCESS][#'. $process_to_perform['increment_id'].'][START]', $SETTINGS); |
|
| 117 | + provideLog('[PROCESS][#'.$process_to_perform['increment_id'].'][START]', $SETTINGS); |
|
| 118 | 118 | handleTask( |
| 119 | 119 | $process_to_perform['increment_id'], |
| 120 | 120 | json_decode($process_to_perform['arguments'], true), |
@@ -129,7 +129,7 @@ discard block |
||
| 129 | 129 | // launch a new iterative process |
| 130 | 130 | $process_to_perform = DB::queryfirstrow( |
| 131 | 131 | 'SELECT * |
| 132 | - FROM ' . prefixTable('processes') . ' |
|
| 132 | + FROM ' . prefixTable('processes').' |
|
| 133 | 133 | WHERE is_in_progress = %i AND process_type = %s |
| 134 | 134 | ORDER BY increment_id ASC', |
| 135 | 135 | 1, |
@@ -153,11 +153,11 @@ discard block |
||
| 153 | 153 | */ |
| 154 | 154 | function handleTask(int $processId, array $ProcessArguments, array $SETTINGS): bool |
| 155 | 155 | { |
| 156 | - provideLog('[PROCESS][#'. $processId.'][START]', $SETTINGS); |
|
| 156 | + provideLog('[PROCESS][#'.$processId.'][START]', $SETTINGS); |
|
| 157 | 157 | //DB::debugmode(false); |
| 158 | 158 | $task_to_perform = DB::queryfirstrow( |
| 159 | 159 | 'SELECT * |
| 160 | - FROM ' . prefixTable('processes_tasks') . ' |
|
| 160 | + FROM ' . prefixTable('processes_tasks').' |
|
| 161 | 161 | WHERE process_id = %i AND finished_at IS NULL |
| 162 | 162 | ORDER BY increment_id ASC', |
| 163 | 163 | $processId |
@@ -172,7 +172,7 @@ discard block |
||
| 172 | 172 | // check if a linux process is not currently on going |
| 173 | 173 | // if sub_task_in_progress === 1 then exit |
| 174 | 174 | if ((int) $task_to_perform['sub_task_in_progress'] === 0) { |
| 175 | - provideLog('[TASK][#'. $task_to_perform['increment_id'].'][START]', $SETTINGS); |
|
| 175 | + provideLog('[TASK][#'.$task_to_perform['increment_id'].'][START]', $SETTINGS); |
|
| 176 | 176 | |
| 177 | 177 | // handle next task |
| 178 | 178 | $args = json_decode($task_to_perform['task'], true); |
@@ -225,10 +225,9 @@ discard block |
||
| 225 | 225 | DB::update( |
| 226 | 226 | prefixTable('processes_tasks'), |
| 227 | 227 | array( |
| 228 | - 'sub_task_in_progress' => 0, // flag sub task is no more in prgoress |
|
| 228 | + 'sub_task_in_progress' => 0, // flag sub task is no more in prgoress |
|
| 229 | 229 | 'task' => $taskStatus['new_action'] !== $args['step'] ? |
| 230 | - json_encode(["status" => "Done"]) : |
|
| 231 | - json_encode([ |
|
| 230 | + json_encode(["status" => "Done"]) : json_encode([ |
|
| 232 | 231 | "step" => $taskStatus['new_action'], |
| 233 | 232 | "index" => $taskStatus['new_index'], |
| 234 | 233 | "nb" => isset($SETTINGS['maximum_number_of_items_to_treat']) === true ? $SETTINGS['maximum_number_of_items_to_treat'] : $args['nb'], |
@@ -264,7 +263,7 @@ discard block |
||
| 264 | 263 | |
| 265 | 264 | } else { |
| 266 | 265 | // Task is currently being in progress by another server process |
| 267 | - provideLog('[TASK][#'. $task_to_perform['increment_id'].'][WARNING] Similar task already being processes', $SETTINGS); |
|
| 266 | + provideLog('[TASK][#'.$task_to_perform['increment_id'].'][WARNING] Similar task already being processes', $SETTINGS); |
|
| 268 | 267 | return false; |
| 269 | 268 | } |
| 270 | 269 | } |
@@ -297,7 +296,7 @@ discard block |
||
| 297 | 296 | // Check if user exists |
| 298 | 297 | $userInfo = DB::queryFirstRow( |
| 299 | 298 | 'SELECT public_key, private_key |
| 300 | - FROM ' . prefixTable('users') . ' |
|
| 299 | + FROM ' . prefixTable('users').' |
|
| 301 | 300 | WHERE id = %i', |
| 302 | 301 | $post_user_id |
| 303 | 302 | ); |
@@ -426,13 +425,13 @@ discard block |
||
| 426 | 425 | { |
| 427 | 426 | $userInfo = DB::queryFirstRow( |
| 428 | 427 | 'SELECT pw, public_key, private_key, login, name |
| 429 | - FROM ' . prefixTable('users') . ' |
|
| 428 | + FROM ' . prefixTable('users').' |
|
| 430 | 429 | WHERE id = %i', |
| 431 | 430 | $owner_id |
| 432 | 431 | ); |
| 433 | 432 | |
| 434 | 433 | // decrypt owner password |
| 435 | - $pwd = cryption($owner_pwd, '','decrypt', $SETTINGS)['string']; |
|
| 434 | + $pwd = cryption($owner_pwd, '', 'decrypt', $SETTINGS)['string']; |
|
| 436 | 435 | provideLog('[USER][INFO] ID:'.$owner_id, $SETTINGS); |
| 437 | 436 | //provideLog('[DEBUG] '.$pwd." -- ", $SETTINGS); |
| 438 | 437 | // decrypt private key and send back |
@@ -471,17 +470,17 @@ discard block |
||
| 471 | 470 | // Loop on items |
| 472 | 471 | $rows = DB::query( |
| 473 | 472 | 'SELECT id, pw, perso |
| 474 | - FROM ' . prefixTable('items') . ' |
|
| 473 | + FROM ' . prefixTable('items').' |
|
| 475 | 474 | '.(isset($extra_arguments['only_personal_items']) === true && $extra_arguments['only_personal_items'] === 1 ? 'WHERE perso = 1' : '').' |
| 476 | 475 | ORDER BY id ASC |
| 477 | - LIMIT ' . $post_start . ', ' . $post_length |
|
| 476 | + LIMIT ' . $post_start.', '.$post_length |
|
| 478 | 477 | ); |
| 479 | 478 | // WHERE perso = 0 |
| 480 | 479 | foreach ($rows as $record) { |
| 481 | 480 | // Get itemKey from current user |
| 482 | 481 | $currentUserKey = DB::queryFirstRow( |
| 483 | 482 | 'SELECT share_key, increment_id |
| 484 | - FROM ' . prefixTable('sharekeys_items') . ' |
|
| 483 | + FROM ' . prefixTable('sharekeys_items').' |
|
| 485 | 484 | WHERE object_id = %i AND user_id = %i', |
| 486 | 485 | $record['id'], |
| 487 | 486 | //$extra_arguments['owner_id'] |
@@ -510,7 +509,7 @@ discard block |
||
| 510 | 509 | |
| 511 | 510 | $currentUserKey = DB::queryFirstRow( |
| 512 | 511 | 'SELECT increment_id |
| 513 | - FROM ' . prefixTable('sharekeys_items') . ' |
|
| 512 | + FROM ' . prefixTable('sharekeys_items').' |
|
| 514 | 513 | WHERE object_id = %i AND user_id = %i', |
| 515 | 514 | $record['id'], |
| 516 | 515 | $post_user_id |
@@ -581,15 +580,15 @@ discard block |
||
| 581 | 580 | // Loop on logs |
| 582 | 581 | $rows = DB::query( |
| 583 | 582 | 'SELECT increment_id |
| 584 | - FROM ' . prefixTable('log_items') . ' |
|
| 583 | + FROM ' . prefixTable('log_items').' |
|
| 585 | 584 | WHERE raison LIKE "at_pw :%" AND encryption_type = "teampass_aes" |
| 586 | - LIMIT ' . $post_start . ', ' . $post_length |
|
| 585 | + LIMIT ' . $post_start.', '.$post_length |
|
| 587 | 586 | ); |
| 588 | 587 | foreach ($rows as $record) { |
| 589 | 588 | // Get itemKey from current user |
| 590 | 589 | $currentUserKey = DB::queryFirstRow( |
| 591 | 590 | 'SELECT share_key |
| 592 | - FROM ' . prefixTable('sharekeys_logs') . ' |
|
| 591 | + FROM ' . prefixTable('sharekeys_logs').' |
|
| 593 | 592 | WHERE object_id = %i AND user_id = %i', |
| 594 | 593 | $record['increment_id'], |
| 595 | 594 | $extra_arguments['owner_id'] |
@@ -621,7 +620,7 @@ discard block |
||
| 621 | 620 | if ((int) $post_user_id !== (int) $extra_arguments['owner_id']) { |
| 622 | 621 | $currentUserKey = DB::queryFirstRow( |
| 623 | 622 | 'SELECT increment_id |
| 624 | - FROM ' . prefixTable('sharekeys_items') . ' |
|
| 623 | + FROM ' . prefixTable('sharekeys_items').' |
|
| 625 | 624 | WHERE object_id = %i AND user_id = %i', |
| 626 | 625 | $record['id'], |
| 627 | 626 | $post_user_id |
@@ -643,7 +642,7 @@ discard block |
||
| 643 | 642 | // SHould we change step? |
| 644 | 643 | DB::query( |
| 645 | 644 | 'SELECT increment_id |
| 646 | - FROM ' . prefixTable('log_items') . ' |
|
| 645 | + FROM ' . prefixTable('log_items').' |
|
| 647 | 646 | WHERE raison LIKE "at_pw :%" AND encryption_type = "teampass_aes"' |
| 648 | 647 | ); |
| 649 | 648 | |
@@ -683,15 +682,15 @@ discard block |
||
| 683 | 682 | // Loop on fields |
| 684 | 683 | $rows = DB::query( |
| 685 | 684 | 'SELECT id |
| 686 | - FROM ' . prefixTable('categories_items') . ' |
|
| 685 | + FROM ' . prefixTable('categories_items').' |
|
| 687 | 686 | WHERE encryption_type = "teampass_aes" |
| 688 | - LIMIT ' . $post_start . ', ' . $post_length |
|
| 687 | + LIMIT ' . $post_start.', '.$post_length |
|
| 689 | 688 | ); |
| 690 | 689 | foreach ($rows as $record) { |
| 691 | 690 | // Get itemKey from current user |
| 692 | 691 | $currentUserKey = DB::queryFirstRow( |
| 693 | 692 | 'SELECT share_key |
| 694 | - FROM ' . prefixTable('sharekeys_fields') . ' |
|
| 693 | + FROM ' . prefixTable('sharekeys_fields').' |
|
| 695 | 694 | WHERE object_id = %i AND user_id = %i', |
| 696 | 695 | $record['id'], |
| 697 | 696 | $extra_arguments['owner_id'] |
@@ -719,7 +718,7 @@ discard block |
||
| 719 | 718 | if ((int) $post_user_id !== (int) $extra_arguments['owner_id']) { |
| 720 | 719 | $currentUserKey = DB::queryFirstRow( |
| 721 | 720 | 'SELECT increment_id |
| 722 | - FROM ' . prefixTable('sharekeys_items') . ' |
|
| 721 | + FROM ' . prefixTable('sharekeys_items').' |
|
| 723 | 722 | WHERE object_id = %i AND user_id = %i', |
| 724 | 723 | $record['id'], |
| 725 | 724 | $post_user_id |
@@ -742,7 +741,7 @@ discard block |
||
| 742 | 741 | // SHould we change step? |
| 743 | 742 | DB::query( |
| 744 | 743 | 'SELECT * |
| 745 | - FROM ' . prefixTable('categories_items') . ' |
|
| 744 | + FROM ' . prefixTable('categories_items').' |
|
| 746 | 745 | WHERE encryption_type = "teampass_aes"' |
| 747 | 746 | ); |
| 748 | 747 | |
@@ -782,14 +781,14 @@ discard block |
||
| 782 | 781 | // Loop on suggestions |
| 783 | 782 | $rows = DB::query( |
| 784 | 783 | 'SELECT id |
| 785 | - FROM ' . prefixTable('suggestion') . ' |
|
| 786 | - LIMIT ' . $post_start . ', ' . $post_length |
|
| 784 | + FROM ' . prefixTable('suggestion').' |
|
| 785 | + LIMIT ' . $post_start.', '.$post_length |
|
| 787 | 786 | ); |
| 788 | 787 | foreach ($rows as $record) { |
| 789 | 788 | // Get itemKey from current user |
| 790 | 789 | $currentUserKey = DB::queryFirstRow( |
| 791 | 790 | 'SELECT share_key |
| 792 | - FROM ' . prefixTable('sharekeys_suggestions') . ' |
|
| 791 | + FROM ' . prefixTable('sharekeys_suggestions').' |
|
| 793 | 792 | WHERE object_id = %i AND user_id = %i', |
| 794 | 793 | $record['id'], |
| 795 | 794 | $extra_arguments['owner_id'] |
@@ -821,7 +820,7 @@ discard block |
||
| 821 | 820 | if ((int) $post_user_id !== (int) $extra_arguments['owner_id']) { |
| 822 | 821 | $currentUserKey = DB::queryFirstRow( |
| 823 | 822 | 'SELECT increment_id |
| 824 | - FROM ' . prefixTable('sharekeys_items') . ' |
|
| 823 | + FROM ' . prefixTable('sharekeys_items').' |
|
| 825 | 824 | WHERE object_id = %i AND user_id = %i', |
| 826 | 825 | $record['id'], |
| 827 | 826 | $post_user_id |
@@ -881,16 +880,16 @@ discard block |
||
| 881 | 880 | // Loop on files |
| 882 | 881 | $rows = DB::query( |
| 883 | 882 | 'SELECT f.id AS id, i.perso AS perso |
| 884 | - FROM ' . prefixTable('files') . ' AS f |
|
| 885 | - INNER JOIN ' . prefixTable('items') . ' AS i ON i.id = f.id_item |
|
| 886 | - WHERE f.status = "' . TP_ENCRYPTION_NAME . '" |
|
| 887 | - LIMIT ' . $post_start . ', ' . $post_length |
|
| 883 | + FROM ' . prefixTable('files').' AS f |
|
| 884 | + INNER JOIN ' . prefixTable('items').' AS i ON i.id = f.id_item |
|
| 885 | + WHERE f.status = "' . TP_ENCRYPTION_NAME.'" |
|
| 886 | + LIMIT ' . $post_start.', '.$post_length |
|
| 888 | 887 | ); //aes_encryption |
| 889 | 888 | foreach ($rows as $record) { |
| 890 | 889 | // Get itemKey from current user |
| 891 | 890 | $currentUserKey = DB::queryFirstRow( |
| 892 | 891 | 'SELECT share_key, increment_id |
| 893 | - FROM ' . prefixTable('sharekeys_files') . ' |
|
| 892 | + FROM ' . prefixTable('sharekeys_files').' |
|
| 894 | 893 | WHERE object_id = %i AND user_id = %i', |
| 895 | 894 | $record['id'], |
| 896 | 895 | (int) $record['perso'] === 0 ? $extra_arguments['owner_id'] : $extra_arguments['new_user_id'] |
@@ -918,7 +917,7 @@ discard block |
||
| 918 | 917 | |
| 919 | 918 | $currentUserKey = DB::queryFirstRow( |
| 920 | 919 | 'SELECT increment_id |
| 921 | - FROM ' . prefixTable('sharekeys_files') . ' |
|
| 920 | + FROM ' . prefixTable('sharekeys_files').' |
|
| 922 | 921 | WHERE object_id = %i AND user_id = %i', |
| 923 | 922 | $record['id'], |
| 924 | 923 | $post_user_id |
@@ -980,8 +979,8 @@ discard block |
||
| 980 | 979 | // SHould we change step? Finished ? |
| 981 | 980 | DB::query( |
| 982 | 981 | 'SELECT * |
| 983 | - FROM ' . prefixTable('files') . ' |
|
| 984 | - WHERE status = "' . TP_ENCRYPTION_NAME . '"' |
|
| 982 | + FROM ' . prefixTable('files').' |
|
| 983 | + WHERE status = "' . TP_ENCRYPTION_NAME.'"' |
|
| 985 | 984 | ); |
| 986 | 985 | $counter = DB::count(); |
| 987 | 986 | $next_start = (int) $post_start + (int) $post_length; |
@@ -1045,7 +1044,7 @@ discard block |
||
| 1045 | 1044 | // get user info |
| 1046 | 1045 | $userInfo = DB::queryFirstRow( |
| 1047 | 1046 | 'SELECT email, login, auth_type, special, lastname, name |
| 1048 | - FROM ' . prefixTable('users') . ' |
|
| 1047 | + FROM ' . prefixTable('users').' |
|
| 1049 | 1048 | WHERE id = %i', |
| 1050 | 1049 | $extra_arguments['new_user_id'] |
| 1051 | 1050 | ); |
@@ -1059,13 +1058,13 @@ discard block |
||
| 1059 | 1058 | sendMailToUser( |
| 1060 | 1059 | filter_var($userInfo['email'], FILTER_SANITIZE_FULL_SPECIAL_CHARS), |
| 1061 | 1060 | empty($extra_arguments['email_body']) === false ? $extra_arguments['email_body'] : $lang->get('email_body_user_config_1'), |
| 1062 | - 'TEAMPASS - ' . $lang->get('login_credentials'), |
|
| 1061 | + 'TEAMPASS - '.$lang->get('login_credentials'), |
|
| 1063 | 1062 | (array) filter_var_array( |
| 1064 | 1063 | [ |
| 1065 | - '#code#' => cryption($extra_arguments['new_user_code'], '','decrypt', $SETTINGS)['string'], |
|
| 1064 | + '#code#' => cryption($extra_arguments['new_user_code'], '', 'decrypt', $SETTINGS)['string'], |
|
| 1066 | 1065 | '#lastname#' => isset($userInfo['name']) === true ? $userInfo['name'] : '', |
| 1067 | 1066 | '#login#' => isset($userInfo['login']) === true ? $userInfo['login'] : '', |
| 1068 | - '#password#' => cryption($extra_arguments['new_user_pwd'], '','decrypt', $SETTINGS)['string'], |
|
| 1067 | + '#password#' => cryption($extra_arguments['new_user_pwd'], '', 'decrypt', $SETTINGS)['string'], |
|
| 1069 | 1068 | ], |
| 1070 | 1069 | FILTER_SANITIZE_FULL_SPECIAL_CHARS |
| 1071 | 1070 | ), |
@@ -31,7 +31,7 @@ discard block |
||
| 31 | 31 | try { |
| 32 | 32 | $this->connection = new \mysqli(DB_HOST, DB_USER, DB_PASSWD_CLEAR, DB_NAME); |
| 33 | 33 | |
| 34 | - if ( mysqli_connect_errno()) { |
|
| 34 | + if (mysqli_connect_errno()) { |
|
| 35 | 35 | throw new Exception("Could not connect to database."); |
| 36 | 36 | } |
| 37 | 37 | } catch (Exception $e) { |
@@ -39,37 +39,37 @@ discard block |
||
| 39 | 39 | } |
| 40 | 40 | } |
| 41 | 41 | |
| 42 | - public function select($query = "" , $params = []) |
|
| 42 | + public function select($query = "", $params = []) |
|
| 43 | 43 | { |
| 44 | 44 | try { |
| 45 | - $stmt = $this->executeStatement( $query , $params ); |
|
| 45 | + $stmt = $this->executeStatement($query, $params); |
|
| 46 | 46 | $result = $stmt->get_result()->fetch_all(MYSQLI_ASSOC); |
| 47 | 47 | $stmt->close(); |
| 48 | 48 | |
| 49 | 49 | return $result; |
| 50 | - } catch(Exception $e) { |
|
| 51 | - throw New Exception( $e->getMessage() ); |
|
| 50 | + } catch (Exception $e) { |
|
| 51 | + throw New Exception($e->getMessage()); |
|
| 52 | 52 | } |
| 53 | 53 | } |
| 54 | 54 | |
| 55 | - private function executeStatement($query = "" , $params = []) |
|
| 55 | + private function executeStatement($query = "", $params = []) |
|
| 56 | 56 | { |
| 57 | 57 | try { |
| 58 | - $stmt = $this->connection->prepare( $query ); |
|
| 58 | + $stmt = $this->connection->prepare($query); |
|
| 59 | 59 | |
| 60 | - if($stmt === false) { |
|
| 61 | - throw New Exception("Unable to do prepared statement: " . $query); |
|
| 60 | + if ($stmt === false) { |
|
| 61 | + throw New Exception("Unable to do prepared statement: ".$query); |
|
| 62 | 62 | } |
| 63 | 63 | |
| 64 | - if( $params ) { |
|
| 64 | + if ($params) { |
|
| 65 | 65 | $stmt->bind_param($params[0], $params[1]); |
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | $stmt->execute(); |
| 69 | 69 | |
| 70 | 70 | return $stmt; |
| 71 | - } catch(Exception $e) { |
|
| 72 | - throw New Exception( $e->getMessage() ); |
|
| 71 | + } catch (Exception $e) { |
|
| 72 | + throw New Exception($e->getMessage()); |
|
| 73 | 73 | } |
| 74 | 74 | } |
| 75 | 75 | } |
| 76 | 76 | \ No newline at end of file |
@@ -26,22 +26,22 @@ discard block |
||
| 26 | 26 | |
| 27 | 27 | use TeampassClasses\SuperGlobal\SuperGlobal; |
| 28 | 28 | |
| 29 | -define("API_ROOT_PATH", __DIR__ . "/.."); |
|
| 29 | +define("API_ROOT_PATH", __DIR__."/.."); |
|
| 30 | 30 | |
| 31 | 31 | // include main configuration file |
| 32 | -require API_ROOT_PATH . '/../sources/main.functions.php'; |
|
| 32 | +require API_ROOT_PATH.'/../sources/main.functions.php'; |
|
| 33 | 33 | |
| 34 | 34 | // init |
| 35 | 35 | loadClasses('DB'); |
| 36 | 36 | $superGlobal = new SuperGlobal(); |
| 37 | 37 | |
| 38 | 38 | // include the base controller file |
| 39 | -require API_ROOT_PATH . "/Controller/Api/BaseController.php"; |
|
| 39 | +require API_ROOT_PATH."/Controller/Api/BaseController.php"; |
|
| 40 | 40 | |
| 41 | 41 | // include the use model file |
| 42 | -require API_ROOT_PATH . "/Model/UserModel.php"; |
|
| 43 | -require API_ROOT_PATH . "/Model/ItemModel.php"; |
|
| 44 | -require API_ROOT_PATH . "/Model/FolderModel.php"; |
|
| 42 | +require API_ROOT_PATH."/Model/UserModel.php"; |
|
| 43 | +require API_ROOT_PATH."/Model/ItemModel.php"; |
|
| 44 | +require API_ROOT_PATH."/Model/FolderModel.php"; |
|
| 45 | 45 | |
| 46 | 46 | /** |
| 47 | 47 | * Launch expected action for ITEM |
@@ -52,10 +52,10 @@ discard block |
||
| 52 | 52 | */ |
| 53 | 53 | function itemAction(array $actions, array $userData) |
| 54 | 54 | { |
| 55 | - require API_ROOT_PATH . "/Controller/Api/ItemController.php"; |
|
| 55 | + require API_ROOT_PATH."/Controller/Api/ItemController.php"; |
|
| 56 | 56 | |
| 57 | 57 | $objFeedController = new ItemController(); |
| 58 | - $strMethodName = $actions[0] . 'Action'; |
|
| 58 | + $strMethodName = $actions[0].'Action'; |
|
| 59 | 59 | $objFeedController->{$strMethodName}($userData); |
| 60 | 60 | } |
| 61 | 61 | |
@@ -68,10 +68,10 @@ discard block |
||
| 68 | 68 | */ |
| 69 | 69 | function folderAction(array $actions, array $userData) |
| 70 | 70 | { |
| 71 | - require API_ROOT_PATH . "/Controller/Api/FolderController.php"; |
|
| 71 | + require API_ROOT_PATH."/Controller/Api/FolderController.php"; |
|
| 72 | 72 | |
| 73 | 73 | $objFeedController = new FolderController(); |
| 74 | - $strMethodName = $actions[0] . 'Action'; |
|
| 74 | + $strMethodName = $actions[0].'Action'; |
|
| 75 | 75 | $objFeedController->{$strMethodName}($userData); |
| 76 | 76 | } |
| 77 | 77 | |
@@ -82,7 +82,7 @@ discard block |
||
| 82 | 82 | */ |
| 83 | 83 | function apiIsEnabled(): string |
| 84 | 84 | { |
| 85 | - include API_ROOT_PATH . '/../includes/config/tp.config.php'; |
|
| 85 | + include API_ROOT_PATH.'/../includes/config/tp.config.php'; |
|
| 86 | 86 | |
| 87 | 87 | if (isset($SETTINGS) === true && isset($SETTINGS['api']) === true && (int) $SETTINGS['api'] === 1) { |
| 88 | 88 | return json_encode( |
@@ -111,7 +111,7 @@ discard block |
||
| 111 | 111 | */ |
| 112 | 112 | function verifyAuth(): string |
| 113 | 113 | { |
| 114 | - include_once API_ROOT_PATH . '/inc/jwt_utils.php'; |
|
| 114 | + include_once API_ROOT_PATH.'/inc/jwt_utils.php'; |
|
| 115 | 115 | $bearer_token = get_bearer_token(); |
| 116 | 116 | |
| 117 | 117 | if (empty($bearer_token) === false && is_jwt_valid($bearer_token) === true) { |
@@ -141,7 +141,7 @@ discard block |
||
| 141 | 141 | */ |
| 142 | 142 | function getDataFromToken(): string |
| 143 | 143 | { |
| 144 | - include_once API_ROOT_PATH . '/inc/jwt_utils.php'; |
|
| 144 | + include_once API_ROOT_PATH.'/inc/jwt_utils.php'; |
|
| 145 | 145 | $bearer_token = get_bearer_token(); |
| 146 | 146 | |
| 147 | 147 | if (empty($bearer_token) === false) { |
@@ -37,45 +37,45 @@ discard block |
||
| 37 | 37 | * @return boolean |
| 38 | 38 | */ |
| 39 | 39 | function is_jwt_valid($jwt) { |
| 40 | - try { |
|
| 41 | - $decoded = (array) JWT::decode($jwt, new Key(DB_PASSWD, 'HS256')); |
|
| 40 | + try { |
|
| 41 | + $decoded = (array) JWT::decode($jwt, new Key(DB_PASSWD, 'HS256')); |
|
| 42 | 42 | |
| 43 | - // Check if expiration is reached |
|
| 44 | - if ($decoded['exp'] - time() < 0) { |
|
| 45 | - return false; |
|
| 46 | - } |
|
| 43 | + // Check if expiration is reached |
|
| 44 | + if ($decoded['exp'] - time() < 0) { |
|
| 45 | + return false; |
|
| 46 | + } |
|
| 47 | 47 | /* |
| 48 | 48 | $decoded1 = JWT::decode($jwt, new Key(DB_PASSWD, 'HS256'), $headers = new stdClass()); |
| 49 | 49 | print_r($headers); |
| 50 | 50 | */ |
| 51 | 51 | |
| 52 | - return true; |
|
| 53 | - } catch (InvalidArgumentException $e) { |
|
| 54 | - // provided key/key-array is empty or malformed. |
|
| 55 | - return false; |
|
| 56 | - } catch (DomainException $e) { |
|
| 57 | - // provided algorithm is unsupported OR |
|
| 58 | - // provided key is invalid OR |
|
| 59 | - // unknown error thrown in openSSL or libsodium OR |
|
| 60 | - // libsodium is required but not available. |
|
| 61 | - return false; |
|
| 62 | - } catch (SignatureInvalidException $e) { |
|
| 63 | - // provided JWT signature verification failed. |
|
| 64 | - return false; |
|
| 65 | - } catch (BeforeValidException $e) { |
|
| 66 | - // provided JWT is trying to be used before "nbf" claim OR |
|
| 67 | - // provided JWT is trying to be used before "iat" claim. |
|
| 68 | - return false; |
|
| 69 | - } catch (ExpiredException $e) { |
|
| 70 | - // provided JWT is trying to be used after "exp" claim. |
|
| 71 | - return false; |
|
| 72 | - } catch (UnexpectedValueException $e) { |
|
| 73 | - // provided JWT is malformed OR |
|
| 74 | - // provided JWT is missing an algorithm / using an unsupported algorithm OR |
|
| 75 | - // provided JWT algorithm does not match provided key OR |
|
| 76 | - // provided key ID in key/key-array is empty or invalid. |
|
| 77 | - return false; |
|
| 78 | - } |
|
| 52 | + return true; |
|
| 53 | + } catch (InvalidArgumentException $e) { |
|
| 54 | + // provided key/key-array is empty or malformed. |
|
| 55 | + return false; |
|
| 56 | + } catch (DomainException $e) { |
|
| 57 | + // provided algorithm is unsupported OR |
|
| 58 | + // provided key is invalid OR |
|
| 59 | + // unknown error thrown in openSSL or libsodium OR |
|
| 60 | + // libsodium is required but not available. |
|
| 61 | + return false; |
|
| 62 | + } catch (SignatureInvalidException $e) { |
|
| 63 | + // provided JWT signature verification failed. |
|
| 64 | + return false; |
|
| 65 | + } catch (BeforeValidException $e) { |
|
| 66 | + // provided JWT is trying to be used before "nbf" claim OR |
|
| 67 | + // provided JWT is trying to be used before "iat" claim. |
|
| 68 | + return false; |
|
| 69 | + } catch (ExpiredException $e) { |
|
| 70 | + // provided JWT is trying to be used after "exp" claim. |
|
| 71 | + return false; |
|
| 72 | + } catch (UnexpectedValueException $e) { |
|
| 73 | + // provided JWT is malformed OR |
|
| 74 | + // provided JWT is missing an algorithm / using an unsupported algorithm OR |
|
| 75 | + // provided JWT algorithm does not match provided key OR |
|
| 76 | + // provided key ID in key/key-array is empty or invalid. |
|
| 77 | + return false; |
|
| 78 | + } |
|
| 79 | 79 | } |
| 80 | 80 | |
| 81 | 81 | function base64url_encode($data) { |
@@ -83,24 +83,24 @@ discard block |
||
| 83 | 83 | } |
| 84 | 84 | |
| 85 | 85 | function get_authorization_header(){ |
| 86 | - $superGlobal = new SuperGlobal(); |
|
| 87 | - $headers = null; |
|
| 86 | + $superGlobal = new SuperGlobal(); |
|
| 87 | + $headers = null; |
|
| 88 | 88 | |
| 89 | - if (null !== $superGlobal->get('Authorization', 'SERVER')) { |
|
| 90 | - $headers = trim($superGlobal->get('Authorization', 'SERVER')); |
|
| 91 | - } else if (null !== $superGlobal->get('HTTP_AUTHORIZATION', 'SERVER')) { //Nginx or fast CGI |
|
| 92 | - $headers = trim($superGlobal->get('HTTP_AUTHORIZATION', 'SERVER')); |
|
| 93 | - } else if (function_exists('apache_request_headers') === true) { |
|
| 94 | - $requestHeaders = (array) apache_request_headers(); |
|
| 95 | - // Server-side fix for bug in old Android versions (a nice side-effect of this fix means we don't care about capitalization for Authorization) |
|
| 96 | - $requestHeaders = array_combine(array_map('ucwords', array_keys($requestHeaders)), array_values($requestHeaders)); |
|
| 97 | - //print_r($requestHeaders); |
|
| 98 | - if (isset($requestHeaders['Authorization']) === true) { |
|
| 99 | - $headers = trim($requestHeaders['Authorization']); |
|
| 100 | - } |
|
| 101 | - } |
|
| 89 | + if (null !== $superGlobal->get('Authorization', 'SERVER')) { |
|
| 90 | + $headers = trim($superGlobal->get('Authorization', 'SERVER')); |
|
| 91 | + } else if (null !== $superGlobal->get('HTTP_AUTHORIZATION', 'SERVER')) { //Nginx or fast CGI |
|
| 92 | + $headers = trim($superGlobal->get('HTTP_AUTHORIZATION', 'SERVER')); |
|
| 93 | + } else if (function_exists('apache_request_headers') === true) { |
|
| 94 | + $requestHeaders = (array) apache_request_headers(); |
|
| 95 | + // Server-side fix for bug in old Android versions (a nice side-effect of this fix means we don't care about capitalization for Authorization) |
|
| 96 | + $requestHeaders = array_combine(array_map('ucwords', array_keys($requestHeaders)), array_values($requestHeaders)); |
|
| 97 | + //print_r($requestHeaders); |
|
| 98 | + if (isset($requestHeaders['Authorization']) === true) { |
|
| 99 | + $headers = trim($requestHeaders['Authorization']); |
|
| 100 | + } |
|
| 101 | + } |
|
| 102 | 102 | |
| 103 | - return $headers; |
|
| 103 | + return $headers; |
|
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | function get_bearer_token() { |
@@ -117,8 +117,8 @@ discard block |
||
| 117 | 117 | |
| 118 | 118 | function get_bearer_data($jwt) { |
| 119 | 119 | // split the jwt |
| 120 | - $tokenParts = explode('.', $jwt); |
|
| 121 | - $payload = base64_decode($tokenParts[1]); |
|
| 120 | + $tokenParts = explode('.', $jwt); |
|
| 121 | + $payload = base64_decode($tokenParts[1]); |
|
| 122 | 122 | |
| 123 | 123 | // HEADER: Get the access token from the header |
| 124 | 124 | if (empty($payload) === false) { |
@@ -82,7 +82,7 @@ |
||
| 82 | 82 | return rtrim(strtr(base64_encode($data), '+/', '-_'), '='); |
| 83 | 83 | } |
| 84 | 84 | |
| 85 | -function get_authorization_header(){ |
|
| 85 | +function get_authorization_header() { |
|
| 86 | 86 | $superGlobal = new SuperGlobal(); |
| 87 | 87 | $headers = null; |
| 88 | 88 | |
@@ -133,7 +133,7 @@ |
||
| 133 | 133 | { |
| 134 | 134 | include API_ROOT_PATH . '/../includes/config/tp.config.php'; |
| 135 | 135 | |
| 136 | - $payload = [ |
|
| 136 | + $payload = [ |
|
| 137 | 137 | 'username' => $login, |
| 138 | 138 | 'id' => $id, |
| 139 | 139 | 'exp' => (time() + $SETTINGS['api_token_duration'] + 600), |
@@ -27,7 +27,7 @@ discard block |
||
| 27 | 27 | use Firebase\JWT\JWT; |
| 28 | 28 | use Firebase\JWT\Key; |
| 29 | 29 | |
| 30 | -require_once API_ROOT_PATH . "/Model/Database.php"; |
|
| 30 | +require_once API_ROOT_PATH."/Model/Database.php"; |
|
| 31 | 31 | |
| 32 | 32 | |
| 33 | 33 | class AuthModel extends Database |
@@ -45,7 +45,7 @@ discard block |
||
| 45 | 45 | public function getUserAuth(string $login, string $password, string $apikey): array |
| 46 | 46 | { |
| 47 | 47 | // Sanitize |
| 48 | - include_once API_ROOT_PATH . '/../sources/main.functions.php'; |
|
| 48 | + include_once API_ROOT_PATH.'/../sources/main.functions.php'; |
|
| 49 | 49 | $inputData = dataSanitizer( |
| 50 | 50 | [ |
| 51 | 51 | 'login' => isset($login) === true ? $login : '', |
@@ -57,7 +57,7 @@ discard block |
||
| 57 | 57 | 'password' => 'trim|escape', |
| 58 | 58 | 'apikey' => 'trim|escape', |
| 59 | 59 | ], |
| 60 | - API_ROOT_PATH . '/..' |
|
| 60 | + API_ROOT_PATH.'/..' |
|
| 61 | 61 | ); |
| 62 | 62 | if (empty($inputData['login']) === true || empty($inputData['apikey']) === true) { |
| 63 | 63 | return ["error" => "Login failed0.", "info" => "Empty entry"]; |
@@ -66,7 +66,7 @@ discard block |
||
| 66 | 66 | // Check apikey |
| 67 | 67 | if (empty($inputData['password']) === true) { |
| 68 | 68 | // case where it is a generic key |
| 69 | - $apiInfo = $this->select("SELECT count(*) FROM " . prefixTable('api') . " WHERE value='".$inputData['apikey']."' AND label='".$inputData['login']."'"); |
|
| 69 | + $apiInfo = $this->select("SELECT count(*) FROM ".prefixTable('api')." WHERE value='".$inputData['apikey']."' AND label='".$inputData['login']."'"); |
|
| 70 | 70 | if ((int) $apiInfo[0]['count(*)'] === 0) { |
| 71 | 71 | return ["error" => "Login failed1.", "info" => "apikey : Not valid"]; |
| 72 | 72 | } |
@@ -77,8 +77,8 @@ discard block |
||
| 77 | 77 | // Check if user exists |
| 78 | 78 | $userInfoRes = $this->select( |
| 79 | 79 | "SELECT u.id, u.pw, u.public_key, u.private_key, u.personal_folder, u.fonction_id, u.groupes_visibles, u.groupes_interdits, a.value AS user_api_key |
| 80 | - FROM " . prefixTable('users') . " AS u |
|
| 81 | - INNER JOIN " . prefixTable('api') . " AS a ON (a.user_id=u.id) |
|
| 80 | + FROM " . prefixTable('users')." AS u |
|
| 81 | + INNER JOIN " . prefixTable('api')." AS a ON (a.user_id=u.id) |
|
| 82 | 82 | WHERE login='".$inputData['login']."'"); |
| 83 | 83 | if (count($userInfoRes) === 0) { |
| 84 | 84 | return ["error" => "Login failed3.", "info" => "apikey : Not valid"]; |
@@ -131,7 +131,7 @@ discard block |
||
| 131 | 131 | */ |
| 132 | 132 | private function createUserJWT(int $id, string $login, int $pf_enabled, string $pubkey, string $privkey, string $folders, string $items): array |
| 133 | 133 | { |
| 134 | - include API_ROOT_PATH . '/../includes/config/tp.config.php'; |
|
| 134 | + include API_ROOT_PATH.'/../includes/config/tp.config.php'; |
|
| 135 | 135 | |
| 136 | 136 | $payload = [ |
| 137 | 137 | 'username' => $login, |
@@ -175,7 +175,7 @@ discard block |
||
| 175 | 175 | |
| 176 | 176 | // Get folders from the roles |
| 177 | 177 | if (empty($userFunctionId) === false) { |
| 178 | - $rows = $this->select("SELECT * FROM " . prefixTable('roles_values') . " WHERE role_id IN (".$userFunctionId.") AND type IN ('W', 'ND', 'NE', 'NDNE', 'R')"); |
|
| 178 | + $rows = $this->select("SELECT * FROM ".prefixTable('roles_values')." WHERE role_id IN (".$userFunctionId.") AND type IN ('W', 'ND', 'NE', 'NDNE', 'R')"); |
|
| 179 | 179 | foreach ($rows as $record) { |
| 180 | 180 | if ($record['type'] === 'R') { |
| 181 | 181 | array_push($readOnlyFolders, $record['folder_id']); |
@@ -196,7 +196,7 @@ discard block |
||
| 196 | 196 | |
| 197 | 197 | // Does this user is allowed to see other items |
| 198 | 198 | $inc = 0; |
| 199 | - $rows = $this->select("SELECT id, id_tree FROM " . prefixTable('items') . " WHERE restricted_to LIKE '".$userInfo['id']."'". |
|
| 199 | + $rows = $this->select("SELECT id, id_tree FROM ".prefixTable('items')." WHERE restricted_to LIKE '".$userInfo['id']."'". |
|
| 200 | 200 | (empty($userFunctionId) === false ? ' AND id_tree NOT IN ('.$userFunctionId.')' : '')); |
| 201 | 201 | foreach ($rows as $record) { |
| 202 | 202 | // Exclude restriction on item if folder is fully accessible |
@@ -206,8 +206,8 @@ discard block |
||
| 206 | 206 | |
| 207 | 207 | // Check for the users roles if some specific rights exist on items |
| 208 | 208 | $rows = $this->select("SELECT i.id_tree, r.item_id |
| 209 | - FROM " . prefixTable('items') . " as i |
|
| 210 | - INNER JOIN " . prefixTable('restriction_to_roles') . " as r ON (r.item_id=i.id) |
|
| 209 | + FROM " . prefixTable('items')." as i |
|
| 210 | + INNER JOIN " . prefixTable('restriction_to_roles')." as r ON (r.item_id=i.id) |
|
| 211 | 211 | WHERE ".(empty($userFunctionId) === false ? ' id_tree NOT IN ('.$userFunctionId.') AND ' : '')." i.id_tree != '' |
| 212 | 212 | ORDER BY i.id_tree ASC"); |
| 213 | 213 | foreach ($rows as $record) { |
@@ -221,7 +221,7 @@ discard block |
||
| 221 | 221 | // Add all personal folders |
| 222 | 222 | $rows = $this->select( |
| 223 | 223 | 'SELECT id |
| 224 | - FROM ' . prefixTable('nested_tree') . ' |
|
| 224 | + FROM ' . prefixTable('nested_tree').' |
|
| 225 | 225 | WHERE title = '.$userInfo['id'].' AND personal_folder = 1'. |
| 226 | 226 | (empty($userFunctionId) === false ? ' AND id NOT IN ('.$userFunctionId.')' : ''). |
| 227 | 227 | ' LIMIT 0,1' |