nilsteampassnet /
TeamPass
| 1 | <?php |
||
| 2 | /** |
||
| 3 | * Teampass - a collaborative passwords manager. |
||
| 4 | * --- |
||
| 5 | * This file is part of the TeamPass project. |
||
| 6 | * |
||
| 7 | * TeamPass is free software: you can redistribute it and/or modify it |
||
| 8 | * under the terms of the GNU General Public License as published by |
||
| 9 | * the Free Software Foundation, version 3 of the License. |
||
| 10 | * |
||
| 11 | * TeamPass is distributed in the hope that it will be useful, |
||
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
| 14 | * GNU General Public License for more details. |
||
| 15 | * |
||
| 16 | * You should have received a copy of the GNU General Public License |
||
| 17 | * along with this program. If not, see <https://www.gnu.org/licenses/>. |
||
| 18 | * |
||
| 19 | * Certain components of this file may be under different licenses. For |
||
| 20 | * details, see the `licenses` directory or individual file headers. |
||
| 21 | * --- |
||
| 22 | * @file ItemHandlerTrait.php |
||
| 23 | * @author Nils Laumaillé ([email protected]) |
||
| 24 | * @copyright 2009-2025 Teampass.net |
||
| 25 | * @license GPL-3.0 |
||
| 26 | * @see https://www.teampass.net |
||
| 27 | */ |
||
| 28 | |||
| 29 | trait ItemHandlerTrait { |
||
| 30 | |||
| 31 | private function generateUserPasswordKeys($arguments) { |
||
| 32 | if (LOG_TASKS=== true) $this->logger->log('Processing generateUserPasswordKeys : '.print_r($arguments, true), 'DEBUG'); |
||
|
1 ignored issue
–
show
introduced
by
Loading history...
|
|||
| 33 | // Generate keys for user passwords |
||
| 34 | storeUsersShareKey( |
||
| 35 | prefixTable('sharekeys_items'), |
||
| 36 | 0, |
||
| 37 | (int) $arguments['item_id'], |
||
| 38 | (string) (array_key_exists('pwd', $arguments) === true ? $arguments['pwd'] : (array_key_exists('object_key', $arguments) === true ? $arguments['object_key'] : '')), |
||
| 39 | false, |
||
| 40 | false, |
||
| 41 | [], |
||
| 42 | array_key_exists('all_users_except_id', $arguments) === true ? $arguments['all_users_except_id'] : -1 |
||
| 43 | ); |
||
| 44 | } |
||
| 45 | |||
| 46 | |||
| 47 | /** |
||
| 48 | * Generate keys for user files |
||
| 49 | * @param array $taskData |
||
| 50 | */ |
||
| 51 | private function generateUserFileKeys($taskData) { |
||
| 52 | if (LOG_TASKS=== true) $this->logger->log('Processing generateUserFileKeys : '.print_r($taskData, true), 'DEBUG'); |
||
|
1 ignored issue
–
show
|
|||
| 53 | foreach($taskData['files_keys'] as $file) { |
||
| 54 | storeUsersShareKey( |
||
| 55 | prefixTable('sharekeys_files'), |
||
| 56 | 0, |
||
| 57 | (int) $file['object_id'], |
||
| 58 | (string) $file['object_key'], |
||
| 59 | false, |
||
| 60 | false, |
||
| 61 | [], |
||
| 62 | array_key_exists('all_users_except_id', $taskData) === true ? $taskData['all_users_except_id'] : -1, |
||
| 63 | ); |
||
| 64 | } |
||
| 65 | } |
||
| 66 | |||
| 67 | |||
| 68 | /** |
||
| 69 | * Generate keys for user fields |
||
| 70 | * @param array $arguments |
||
| 71 | */ |
||
| 72 | private function generateUserFieldKeys($arguments) { |
||
| 73 | if (LOG_TASKS=== true) $this->logger->log('Processing generateUserFieldKeys : '.print_r($arguments, true), 'DEBUG'); |
||
|
1 ignored issue
–
show
|
|||
| 74 | foreach($arguments['fields_keys'] as $field) { |
||
| 75 | $this->logger->log('Processing generateUserFieldKeys for: ' . $field['object_id'], 'DEBUG'); |
||
| 76 | storeUsersShareKey( |
||
| 77 | prefixTable('sharekeys_fields'), |
||
| 78 | 0, |
||
| 79 | (int) $field['object_id'], |
||
| 80 | (string) $field['object_key'], |
||
| 81 | false, |
||
| 82 | false, |
||
| 83 | [], |
||
| 84 | array_key_exists('all_users_except_id', $arguments) === true ? $arguments['all_users_except_id'] : -1, |
||
| 85 | ); |
||
| 86 | } |
||
| 87 | } |
||
| 88 | |||
| 89 | |||
| 90 | /** |
||
| 91 | * Handle item copy |
||
| 92 | * @param array $arguments |
||
| 93 | */ |
||
| 94 | private function handleItemCopy($arguments) { |
||
| 95 | storeUsersShareKey( |
||
| 96 | prefixTable('sharekeys_items'), |
||
| 97 | 0, |
||
| 98 | $arguments['item_id'], |
||
| 99 | $arguments['object_key'] ?? '', |
||
| 100 | false, |
||
| 101 | false, |
||
| 102 | [], |
||
| 103 | $arguments['all_users_except_id'] ?? -1 |
||
| 104 | ); |
||
| 105 | } |
||
| 106 | |||
| 107 | |||
| 108 | /** |
||
| 109 | * Handle item update for passwords |
||
| 110 | * @param array $arguments |
||
| 111 | */ |
||
| 112 | private function handleItemUpdateCreateKeys($arguments) { |
||
| 113 | storeUsersShareKey( |
||
| 114 | prefixTable('sharekeys_items'), |
||
| 115 | 0, |
||
| 116 | (int) $arguments['item_id'], |
||
| 117 | (string) (array_key_exists('pwd', $arguments) === true ? $arguments['pwd'] : (array_key_exists('object_key', $arguments) === true ? $arguments['object_key'] : '')), |
||
| 118 | false, |
||
| 119 | false, |
||
| 120 | [], |
||
| 121 | array_key_exists('all_users_except_id', $arguments) === true ? $arguments['all_users_except_id'] : -1 |
||
| 122 | ); |
||
| 123 | } |
||
| 124 | |||
| 125 | /** |
||
| 126 | * Handle item update for fields |
||
| 127 | * @param array $arguments |
||
| 128 | */ |
||
| 129 | private function handleFieldUpdateCreateKeys($arguments) { |
||
| 130 | foreach ($arguments['fields_keys'] ?? [] as $field) { |
||
| 131 | storeUsersShareKey( |
||
| 132 | prefixTable('sharekeys_items'), |
||
| 133 | 0, |
||
| 134 | $field['object_id'], |
||
| 135 | $field['object_key'], |
||
| 136 | false, |
||
| 137 | false, |
||
| 138 | [], |
||
| 139 | $arguments['all_users_except_id'] ?? -1 |
||
| 140 | ); |
||
| 141 | } |
||
| 142 | } |
||
| 143 | } |