Overview
Comment: | Migration vers KD2\UserSession (composant réutilisable) |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | dev |
Files: | files | file ages | folders |
SHA1: |
0a535d8a8f769512e06754c8a11a3313 |
User & Date: | bohwaz on 2017-09-04 07:06:35 |
Other Links: | branch diff | manifest | tags |
Context
2017-09-04
| ||
07:07 | Corrections pour les changements liés à la migration vers UserSession check-in: 4e5588b1ba user: bohwaz tags: dev | |
07:06 | Migration vers KD2\UserSession (composant réutilisable) check-in: 0a535d8a8f user: bohwaz tags: dev | |
2017-09-03
| ||
00:17 | Ne pas prendre en compte LOCAL_LOGIN s'il est positionné sur false/null/0 check-in: 2b5e5aed0c user: bohwaz tags: dev | |
Changes
Modified src/include/lib/Garradin/Fichiers.php from [6cbd651b6a] to [398f6de205].
︙ | ︙ | |||
170 171 172 173 174 175 176 | // Page wiki publique, aucune vérification à faire, seul cas d'accès à un fichier en dehors de l'espace admin if ($wiki !== false && $wiki == Wiki::LECTURE_PUBLIC) { return true; } // Pas d'utilisateur connecté, pas d'accès aux fichiers de l'espace admin | | | | | | | 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 | // Page wiki publique, aucune vérification à faire, seul cas d'accès à un fichier en dehors de l'espace admin if ($wiki !== false && $wiki == Wiki::LECTURE_PUBLIC) { return true; } // Pas d'utilisateur connecté, pas d'accès aux fichiers de l'espace admin if (!isset($user->droit_wiki)) { return false; } if ($wiki !== false) { // S'il n'a même pas droit à accéder au wiki c'est mort if (!$session->canAccess('wiki', Membres::DROIT_ACCES)) { return false; } // On renvoie à l'objet Wiki pour savoir si l'utilisateur a le droit de lire ce fichier $_w = new Wiki; $_w->setRestrictionCategorie($user->id_categorie, $user->droit_wiki); return $_w->canReadPage($wiki); } // On regarde maintenant si le fichier est lié à la compta $query = sprintf('SELECT 1 FROM fichiers_%s WHERE fichier = ? LIMIT 1;', self::LIEN_COMPTA); $compta = $db->firstColumn($query, (int)$this->id); if ($compta && $session->canAccess('compta', Membres::DROIT_ACCES)) { // OK si accès à la compta return true; } // Enfin, si le fichier est lié à un membre $query = sprintf('SELECT id FROM fichiers_%s WHERE fichier = ? LIMIT 1;', self::LIEN_MEMBRES); $membre = $db->firstColumn($query, (int)$this->id); if ($membre !== false) { // De manière évidente, l'utilisateur a le droit d'accéder aux fichiers liés à son profil if ((int)$membre == $user->id) { return true; } // Pour voir les fichiers des membres il faut pouvoir les gérer if ($session->canAccess('membres', Membres::DROIT_ECRITURE)) { return true; } } return false; } |
︙ | ︙ |
Modified src/include/lib/Garradin/Membres.php from [4adbad4a37] to [0578514af1].
︙ | ︙ | |||
35 36 37 38 39 40 41 | // Remove NUL bytes // see http://blog.ircmaxell.com/2015/03/security-issue-combining-bcrypt-with.html $password = str_replace("\0", '', $password); return password_hash($password, \PASSWORD_DEFAULT); } | < < < < < < < < < | 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | // Remove NUL bytes // see http://blog.ircmaxell.com/2015/03/security-issue-combining-bcrypt-with.html $password = str_replace("\0", '', $password); return password_hash($password, \PASSWORD_DEFAULT); } // Gestion des données /////////////////////////////////////////////////////// public function _checkFields(&$data, $check_editable = true, $check_password = true) { $champs = Config::getInstance()->get('champs_membres'); foreach ($champs->getAll() as $key=>$config) |
︙ | ︙ | |||
255 256 257 258 259 260 261 | public function delete($ids) { if (!is_array($ids)) { $ids = [(int)$ids]; } | > > | | 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 | public function delete($ids) { if (!is_array($ids)) { $ids = [(int)$ids]; } $session = new Session; if ($session->isLogged()) { $user = $session->getUser(); foreach ($ids as $id) { if ($user->id == $id) { |
︙ | ︙ |
Modified src/include/lib/Garradin/Membres/Session.php from [ba6c3b5d63] to [ae5630354e].
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | <?php namespace Garradin\Membres; use Garradin\Config; use Garradin\DB; use Garradin\Utils; use Garradin\Membres; use Garradin\UserException; use const Garradin\SECRET_KEY; use const Garradin\WWW_URL; use KD2\Security; use KD2\Security_OTP; use KD2\QRCode; | > | < < | | | | < < | < < < | < < < < < < < < < < < < < < < < | | < | < < < | < < | < < < < | < < < < < < | > | | | < < < < < < > | < | | < < < < < | < < < | < < < < < | < < | < < | < | < < < < < < < < < < < < < < < < < < < < < | | | < | < < | < < < < | < | < < | < < < < | < < < < | | | < < | < < < < < < < < < < < < < < < < < < | | | | < < | < < < | | | > > | | < > | < > | < | | < | < > | < | > | < | < > > < < > < < | < > | > > > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 | <?php namespace Garradin\Membres; use Garradin\Config; use Garradin\DB; use Garradin\Utils; use Garradin\Membres; use Garradin\UserException; use const Garradin\SECRET_KEY; use const Garradin\WWW_URL; use KD2\Security; use KD2\Security_OTP; use KD2\QRCode; class Session extends \KD2\UserSession { // Personalisation de la config de UserSession protected $cookie_name = 'gdin'; protected $remember_me_cookie_name = 'gdinp'; protected $remember_me_expiry = '+3 months'; // Extension des méthodes de UserSession public function __construct() { $url = parse_url(WWW_URL); parent::__construct(DB::getInstance(), [ 'cookie_domain' => $url['host'], 'cookie_path' => $url['path'], 'cookie_secure' => (\Garradin\PREFER_HTTPS >= 2) ? true : false, ]); } protected function getUserForLogin($login) { $champ_id = Config::getInstance()->get('champ_identifiant'); // Ne renvoie un membre que si celui-ci a le droit de se connecter $query = 'SELECT id, %1$s AS login, passe AS password, secret_otp AS otp_secret FROM membres AS m INNER JOIN membres_categories AS mc ON mc.id = m.id_categorie FROM membres WHERE %1$s = ? AND mc.droit_connexion >= %2$d LIMIT 1;'; $query = sprintf($query, $champ_id, Membres::DROIT_ACCES); return $db->first($query, $login); } protected function getUserDataForSession($id) { return $this->db->first('SELECT m.*, c.droit_connexion, c.droit_wiki, c.droit_membres, c.droit_compta, c.droit_config, c.droit_membres FROM membres AS m INNER JOIN membres_categories AS c ON m.id_categorie = c.id WHERE m.id = ? LIMIT 1;', $id); } protected function storeRememberMeSelector($selector, $hash, \DateTime $expiry, $user_id) { return $this->db->insert('membres_sessions', [ 'selecteur' => $selector, 'hash' => $hash, 'expire' => $expiry, 'id_membre' => $user_id, ]); } protected function expireRememberMeSelectors() { return $this->db->delete('membres_sessions', $this->db->where('expire', '<', new \DateTime)); } protected function getRememberMeSelector($selector) { return $this->db->get('SELECT selecteur AS selector, hash, id_membre AS user_id, m.passe AS user_password FROM membres_sessions AS s INNER JOIN membres AS m ON m.id = s.id_membre WHERE s.selecteur = ? LIMIT 1;', $selector); } protected function deleteRememberMeSelector($selector) { return $this->db->delete('membres_sessions', $this->db->where('selecteur', $selector)); } protected function deleteAllRememberMeSelectors($user_id) { return $this->db->delete('membres_sessions', $this->db->where('id_membre', $user_id)); } // Ajout de la gestion de LOCAL_LOGIN public function isLogged() { if (empty($_SESSION['user']) && defined('\Garradin\LOCAL_LOGIN') && is_int(\Garradin\LOCAL_LOGIN) && \Garradin\LOCAL_LOGIN > 0) { $this->create(\Garradin\LOCAL_LOGIN); } return parent::isLogged(); } // Ici checkOTP utilise NTP en second recours public function checkOTP($secret, $code) { if (!Security_OTP::TOTP($secret, $code)) { // Vérifier encore, mais avec le temps NTP // au cas où l'horloge du serveur n'est pas à l'heure $time = Security_OTP::getTimeFromNTP(\Garradin\NTP_SERVER); if (!Security_OTP::TOTP($secret, $code, $time)) { return false; } } return true; } public function generateNewOTPSecret() { $out = []; $out['secret'] = Security_OTP::getRandomSecret(); $out['secret_display'] = implode(' ', str_split($out['secret'], 4)); $out['url'] = Security_OTP::getOTPAuthURL(Config::getInstance()->get('nom_asso'), $out['secret']); $qrcode = new QRCode($out['url']); $out['qrcode'] = 'data:image/svg+xml;base64,' . base64_encode($qrcode->toSVG()); return $out; } static public function recoverPasswordCheck($id) { $db = DB::getInstance(); $config = Config::getInstance(); $champ_id = $config->get('champ_identifiant'); |
︙ | ︙ | |||
333 334 335 336 337 338 339 | $password = Membres::hashPassword($password); $db->update('membres', ['passe' => $password], 'id = :id', ['id' => (int)$id]); return Utils::mail($membre->email, '['.$config->get('nom_asso').'] Nouveau mot de passe', $message); } | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | < < < < < < < < < < < < < < < < | | 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 | $password = Membres::hashPassword($password); $db->update('membres', ['passe' => $password], 'id = :id', ['id' => (int)$id]); return Utils::mail($membre->email, '['.$config->get('nom_asso').'] Nouveau mot de passe', $message); } public function editUser($data) { (new Membres)->edit($this->id, $data, false); $this->refresh(); return true; } public function canAccess($category, $permission) { if (!$this->user) { return false; } return ($this->user->{'droit_' . $category} >= $permission); } public function requireAccess($category, $permission) { if (!$this->canAccess($category, $permission)) { throw new UserException('Vous n\'avez pas le droit d\'accéder à cette page.'); |
︙ | ︙ | |||
530 531 532 533 534 535 536 | $qrcode = new QRCode($out['url']); $out['qrcode'] = 'data:image/svg+xml;base64,' . base64_encode($qrcode->toSVG()); return $out; } | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 | $qrcode = new QRCode($out['url']); $out['qrcode'] = 'data:image/svg+xml;base64,' . base64_encode($qrcode->toSVG()); return $out; } public function sendMessage($dest, $sujet, $message, $copie = false) { $from = $this->getUser(); $from = $from['email']; // Uniquement adresse email pour le moment car faudrait trouver comment // indiquer le nom mais qu'il soit correctement échappé FIXME $config = Config::getInstance(); $message .= "\n\n--\nCe message a été envoyé par un membre de ".$config->get('nom_asso'); $message .= ", merci de contacter ".$config->get('email_asso')." en cas d'abus."; if ($copie) { Utils::mail($from, $sujet, $message); } return Utils::mail($dest, $sujet, $message, ['From' => $from]); } public function editSecurity(Array $data = []) { $allowed_fields = ['passe', 'clef_pgp', 'secret_otp']; foreach ($data as $key=>$value) { if (!in_array($key, $allowed_fields)) |
︙ | ︙ | |||
623 624 625 626 627 628 629 | { throw new UserException('Clé PGP invalide : impossible d\'extraire l\'empreinte.'); } } $db = DB::getInstance(); $db->update('membres', $data, $db->where('id', (int)$this->id)); | | | < < < < < < < < < < < < < < < < < < < < < < < | 315 316 317 318 319 320 321 322 323 324 325 326 | { throw new UserException('Clé PGP invalide : impossible d\'extraire l\'empreinte.'); } } $db = DB::getInstance(); $db->update('membres', $data, $db->where('id', (int)$this->id)); $this->refresh(); return true; } } |
Modified src/www/admin/_inc.php from [1060426865] to [4e850891ca].
︙ | ︙ | |||
41 42 43 44 45 46 47 | $tpl = Template::getInstance(); $tpl->assign('admin_url', WWW_URL . 'admin/'); $form = new Form; $tpl->assign_by_ref('form', $form); | | > | | | 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | $tpl = Template::getInstance(); $tpl->assign('admin_url', WWW_URL . 'admin/'); $form = new Form; $tpl->assign_by_ref('form', $form); $session = new Session; $tpl->assign('session', $session); $tpl->assign('config', Config::getInstance()->getConfig()); if (!defined('Garradin\LOGIN_PROCESS')) { if (!$session->isLogged()) { if ($session->isOTPRequired()) { Utils::redirect('/admin/login_otp.php'); } else { Utils::redirect('/admin/login.php'); } |
︙ | ︙ |