iesoretania /
atica
This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | |||
| 3 | /* ATICA - Web application for supporting Quality Management Systems |
||
| 4 | Copyright (C) 2009-2015: Luis-Ramón López López |
||
| 5 | |||
| 6 | This program is free software: you can redistribute it and/or modify |
||
| 7 | it under the terms of the GNU Affero General Public License as published by |
||
| 8 | the Free Software Foundation, either version 3 of the License, or |
||
| 9 | (at your option) any later version. |
||
| 10 | |||
| 11 | This program 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 Affero General Public License for more details. |
||
| 15 | |||
| 16 | You should have received a copy of the GNU Affero General Public License |
||
| 17 | along with this program. If not, see [http://www.gnu.org/licenses/]. */ |
||
| 18 | |||
| 19 | $app->get('/centros', function () use ($app, $user) { |
||
| 20 | if (isset($user)) { |
||
| 21 | $app->redirect($app->urlFor('activities')); |
||
| 22 | } |
||
| 23 | $breadcrumb = null; |
||
| 24 | $organizations = ORM::for_table('organization')-> |
||
| 25 | order_by_asc('display_name')->find_array(); |
||
| 26 | $app->render('organization.html.twig', array('navigation' => $breadcrumb, |
||
| 27 | 'organizations' => $organizations)); |
||
| 28 | })->name('organization'); |
||
| 29 | |||
| 30 | $app->post('/centros', function () use ($app, $user) { |
||
| 31 | if (isset($user)) { |
||
| 32 | $app->redirect($app->urlFor('activities')); |
||
| 33 | } |
||
| 34 | $organization_nr = ORM::for_table('organization')-> |
||
| 35 | where('id',$_POST['organization_id'])->count(); |
||
| 36 | if (1 == $organization_nr) { |
||
| 37 | $_SESSION['organization_id'] = $_POST['organization_id']; |
||
| 38 | $app->redirect($app->urlFor('frontpage')); |
||
| 39 | } |
||
| 40 | else { |
||
| 41 | $app->redirect($app->urlFor('organization')); |
||
| 42 | } |
||
| 43 | }); |
||
| 44 | |||
| 45 | $app->get('/entrar', function () use ($app) { |
||
| 46 | if (!isset($_SESSION['organization_id'])) { |
||
| 47 | $app->redirect($app->urlFor('organization')); |
||
| 48 | } |
||
| 49 | $breadcrumb = array(array('display_name' => 'Acceder', 'target' => '#')); |
||
| 50 | $app->render('login.html.twig', array('navigation' => $breadcrumb)); |
||
| 51 | })->name('login'); |
||
| 52 | |||
| 53 | $app->post('/entrar', function () use ($app, $preferences, $organization) { |
||
| 54 | if (!isset($_SESSION['organization_id'])) { |
||
| 55 | $app->redirect($app->urlFor('organization')); |
||
| 56 | } |
||
| 57 | $username = strtolower(trim($_POST['username'])); |
||
| 58 | |||
| 59 | // comprobar si el usuario está bloqueado |
||
| 60 | $now = date('Y-m-d H:i:s'); |
||
| 61 | $login_security = ORM::for_table('person')-> |
||
| 62 | select('id')-> |
||
| 63 | select('user_name')-> |
||
| 64 | select('blocked_access')-> |
||
| 65 | select('retry_count')-> |
||
| 66 | select('last_login')-> |
||
| 67 | select('is_external')-> |
||
| 68 | select('password')-> |
||
| 69 | where('user_name', $username)-> |
||
| 70 | find_one(); |
||
| 71 | |||
| 72 | if ((!$login_security) || |
||
| 73 | ($login_security && ($login_security['blocked_access'] <= $now))) { |
||
| 74 | |||
| 75 | $ok = false; |
||
| 76 | $user = null; |
||
| 77 | |||
| 78 | // si la autenticación externa está activada y el usuario habilitado, comprobar |
||
| 79 | if ($login_security && $login_security['is_external'] && isset($preferences['external.enabled'])) { |
||
| 80 | $authenticator = new \Atica\Service\SenecaAuthenticatorService($preferences['external.url'], |
||
| 81 | $preferences['external.url.force_security'], $preferences['external.enabled']); |
||
| 82 | $ok = $authenticator->checkUserCredentials($username, $_POST['password']); |
||
| 83 | // si autentica, actualizar la clave en la base de datos |
||
| 84 | View Code Duplication | if ($ok) { |
|
| 85 | $user = ORM::for_table('person')-> |
||
| 86 | where('user_name', $username)-> |
||
| 87 | find_one(); |
||
| 88 | $login_security->set('password', sha1($preferences['salt'] . $_POST['password'])); |
||
| 89 | $login_security->save(); |
||
| 90 | } |
||
| 91 | } |
||
| 92 | |||
| 93 | View Code Duplication | if (!$ok) { |
|
|
0 ignored issues
–
show
|
|||
| 94 | $user = ORM::for_table('person')-> |
||
| 95 | where('user_name', $username)-> |
||
| 96 | where('password', sha1($preferences['salt'] . $_POST['password']))-> |
||
| 97 | find_one(); |
||
| 98 | } |
||
| 99 | |||
| 100 | if ($ok || $user) { |
||
| 101 | // obtener pertenencia a la organización |
||
| 102 | $membership = ORM::for_table('person_organization')-> |
||
| 103 | where('organization_id', $_SESSION['organization_id'])-> |
||
| 104 | where('person_id', $user['id'])->find_one(); |
||
| 105 | |||
| 106 | // poner a cero la cuenta de intentos infructuosos |
||
| 107 | $user->set('retry_count' ,0); |
||
| 108 | $user->set('blocked_access', null); |
||
| 109 | $firstLogin = ($user['last_login'] == null); |
||
| 110 | |||
| 111 | if ($membership) { |
||
| 112 | if ($membership['is_active']) { |
||
| 113 | // registrar la hora en la que ha entrado con éxito |
||
| 114 | $user->set('last_login', $now); |
||
| 115 | $user->save(); |
||
| 116 | $_SESSION['person_id'] = $user['id']; |
||
| 117 | // si es la primera conexión, enviar a su página de datos |
||
| 118 | // personales |
||
| 119 | if ($firstLogin) { |
||
| 120 | doRegisterAction($app, $user, $organization, 'session', 0, 'login', 'first'); |
||
| 121 | $app->flash('last_url', $app->urlFor('activities')); |
||
| 122 | $app->redirect($app->urlFor('personal', array('id' => $user['id'], 'section' => 0))); |
||
| 123 | } |
||
| 124 | else { |
||
| 125 | doRegisterAction($app, $user, $organization, 'session', 0, 'login', ''); |
||
| 126 | $app->redirect($app->urlFor('activities')); |
||
| 127 | } |
||
| 128 | } |
||
| 129 | else { |
||
| 130 | doRegisterAction($app, $user, $organization, 'session', 1, 'login_error', 'not active'); |
||
| 131 | $app->flash('login_error', 'not active'); |
||
| 132 | } |
||
| 133 | } |
||
| 134 | else { |
||
| 135 | doRegisterAction($app, $user, null, 'session', 2, 'login_error', 'no organization'); |
||
| 136 | $app->flash('login_error', 'no organization'); |
||
| 137 | } |
||
| 138 | // guardar cambios aunque haya ocurrido un error |
||
| 139 | $user->save(); |
||
| 140 | } |
||
| 141 | else { |
||
| 142 | if ($login_security) { |
||
| 143 | // comprobar el número de intentos infructuosos |
||
| 144 | $login_security->set('retry_count', $login_security['retry_count']+1); |
||
| 145 | doRegisterAction($app, $user, null, 'session', 3, 'login_error', 'bad password'); |
||
| 146 | if ($login_security['retry_count'] >= $preferences['login.retries']) { |
||
| 147 | // bloquear al usuario |
||
| 148 | $until = new DateTime; |
||
| 149 | $until->modify("+" . $preferences['login.block'] . " min"); |
||
| 150 | $login_security->set('blocked_access', $until->format('Y-m-d H:i:s')); |
||
| 151 | doRegisterAction($app, $user, null, 'session', 4, 'login_error', 'blocked'); |
||
| 152 | } |
||
| 153 | $login_security->save(); |
||
| 154 | } |
||
| 155 | $app->flash('login_error', 'not found'); |
||
| 156 | } |
||
| 157 | } |
||
| 158 | else { |
||
| 159 | $app->flash('login_error', 'blocked'); |
||
| 160 | $until = new DateTime($login_security['blocked_access']); |
||
| 161 | $until->modify('+1 min'); |
||
| 162 | $app->flash('login_blocked_for', $until->format('H:i')); |
||
| 163 | } |
||
| 164 | $app->redirect($app->urlFor('login')); |
||
| 165 | }); |
||
| 166 | |||
| 167 | $app->get('/salir', function () use ($app, $user, $organization) { |
||
| 168 | if (isset($user['id'])) { |
||
| 169 | doRegisterAction($app, $user, $organization, 'session', 0, 'logout', ''); |
||
| 170 | } |
||
| 171 | unset($_SESSION['person_id']); |
||
| 172 | $app->flash('home_info', 'logout'); |
||
| 173 | $app->redirect($app->urlFor('frontpage')); |
||
| 174 | })->name('logout'); |
||
| 175 | |||
| 176 | function doRegisterAction($app, $user, $organization, $module, $command, $action, |
||
| 177 | $info, $data = null, |
||
| 178 | $time = null, $activityId = null, $eventId = null, $groupingId = null, |
||
| 179 | $folderId = null, $profileId = null, $deliveryId = null, |
||
| 180 | $revisionId = null, $documentId = null, $deliveryItemId = null) { |
||
| 181 | |||
| 182 | if (null == $time) { |
||
| 183 | $time = date('Y-m-d H:i:s'); |
||
| 184 | } |
||
| 185 | |||
| 186 | $personId = is_null($user) ? null : $user['id']; |
||
| 187 | $orgId = is_null($organization) ? null : $organization['id']; |
||
| 188 | |||
| 189 | $log = ORM::for_table('log')->create(); |
||
| 190 | $log->set(array( |
||
| 191 | 'time' => $time, |
||
| 192 | 'person_id' => $personId, |
||
| 193 | 'ip' => $app->request()->getIp(), |
||
| 194 | 'organization_id' => $orgId, |
||
| 195 | 'module' => $module, |
||
| 196 | 'command' => $command, |
||
| 197 | 'action' => $action, |
||
| 198 | 'url' => $app->request()->getPathInfo(), |
||
| 199 | 'info' => $info, |
||
| 200 | 'data' => $data, |
||
| 201 | 'activity_id' => $activityId, |
||
| 202 | 'event_id' => $eventId, |
||
| 203 | 'grouping_id' => $groupingId, |
||
| 204 | 'folder_id' => $folderId, |
||
| 205 | 'profile_id' => $profileId, |
||
| 206 | 'delivery_id' => $deliveryId, |
||
| 207 | 'revision_id' => $revisionId, |
||
| 208 | 'document_id' => $documentId, |
||
| 209 | 'delivery_item_id' => $deliveryItemId |
||
| 210 | )); |
||
| 211 | |||
| 212 | return $log->save(); |
||
| 213 | } |
||
| 214 |
If an expression can have both
false, andnullas possible values. It is generally a good practice to always use strict comparison to clearly distinguish between those two values.