From e1b64e4088232b9d7b4acb2dc24279bb38fcafba Mon Sep 17 00:00:00 2001 From: dj3c1t Date: Sun, 26 May 2013 17:23:12 +0200 Subject: [PATCH] nouveau SQL import / maj donnees XML --- content/data/mysql/mtweb.sql | 89 +++++++++++++------- content/data/xml/mw/actions_roles/.index | 2 +- content/data/xml/mw/actions_roles/189.xml | 4 + content/data/xml/mw/roles/0.xml | 4 + content/data/xml/mw/roles/3.xml | 4 + content/data/xml/mw/users_roles/.index | 2 +- content/data/xml/mw/users_roles/33.xml | 4 + mw/app/config.xml | 18 +++- mw/app/data/modules/share/mw_data_users_files.php | 20 +++++ .../data/modules/share/mw_data_users_sessions.php | 91 ++++++++++++++++++++ mw/app/data/modules/sql/mw_data_users.php | 98 ---------------------- mw/app/data/modules/xml/mw_data_users.php | 90 -------------------- 12 files changed, 204 insertions(+), 222 deletions(-) create mode 100644 content/data/xml/mw/actions_roles/189.xml create mode 100644 content/data/xml/mw/roles/0.xml create mode 100644 content/data/xml/mw/roles/3.xml create mode 100644 content/data/xml/mw/users_roles/33.xml create mode 100644 mw/app/data/modules/share/mw_data_users_files.php create mode 100644 mw/app/data/modules/share/mw_data_users_sessions.php diff --git a/content/data/mysql/mtweb.sql b/content/data/mysql/mtweb.sql index 368c36c..982650c 100644 --- a/content/data/mysql/mtweb.sql +++ b/content/data/mysql/mtweb.sql @@ -3,9 +3,9 @@ -- http://www.phpmyadmin.net -- -- Serveur: localhost --- Généré le : Mer 13 Février 2013 à 23:03 --- Version du serveur: 5.1.67 --- Version de PHP: 5.3.2-1ubuntu4.18 +-- Généré le : Dim 26 Mai 2013 à 15:46 +-- Version du serveur: 5.1.69 +-- Version de PHP: 5.3.2-1ubuntu4.19 SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO"; @@ -16,24 +16,26 @@ SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO"; -- -------------------------------------------------------- -- --- Structure de la table `mw_action_status` +-- Structure de la table `mw_actions_roles` -- -CREATE TABLE IF NOT EXISTS `mw_actions_roles` ( - `id` int(11) NOT NULL AUTO_INCREMENT, - `action` varchar(255) NOT NULL, - `id_role` int(11) NOT NULL, - PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=16 ; - --- --- Contenu de la table `mw_actions_roles` --- - -INSERT INTO `mw_actions_roles` (`id`, `action`, `id_role`) VALUES -(13, 'admin', 1), -(14, 'users', 2), -(15, 'users/identification', 0); +CREATE TABLE IF NOT EXISTS `mw_actions_roles` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `action` varchar(255) NOT NULL, + `id_role` int(11) NOT NULL, + PRIMARY KEY (`id`), + KEY `id_role` (`id_role`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=21 ; + +-- +-- Contenu de la table `mw_actions_roles` +-- + +INSERT INTO `mw_actions_roles` (`id`, `action`, `id_role`) VALUES +(13, 'admin', 1), +(14, 'users', 2), +(19, 'users/identification', 0), +(20, 'config', 3); -- -------------------------------------------------------- @@ -46,7 +48,7 @@ CREATE TABLE IF NOT EXISTS `mw_config` ( `key` varchar(255) NOT NULL, `value` text NOT NULL, PRIMARY KEY (`id`) -) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=30 ; +) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=38 ; -- -- Contenu de la table `mw_config` @@ -61,10 +63,13 @@ INSERT INTO `mw_config` (`id`, `key`, `value`) VALUES (6, 'contact_form', '0'), (8, 'email', ''), (9, 'captcha', '0'), -(29, 'default_allow', '1'), -(22, 'out_colonne', 'on'), (16, 'start_action_params', ''), -(20, 'out_navig_menu_top', 'on'); +(20, 'out_navig_menu_top', 'on'), +(22, 'out_colonne', 'on'), +(29, 'default_allow', '1'), +(30, 'cache_actif', '0'), +(31, 'cache_maj_auto', '0'), +(32, 'cache_time', '72'); -- -------------------------------------------------------- @@ -76,16 +81,18 @@ CREATE TABLE IF NOT EXISTS `mw_roles` ( `id` int(11) NOT NULL AUTO_INCREMENT, `nom` varchar(255) NOT NULL, `intitule` varchar(255) NOT NULL, - PRIMARY KEY (`id`) -) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=8 ; + KEY `id` (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=4 ; -- -- Contenu de la table `mw_roles` -- INSERT INTO `mw_roles` (`id`, `nom`, `intitule`) VALUES +(0, 'guest', 'invité'), (1, 'admin', 'administrateur'), -(2, 'membre', 'membre'); +(2, 'membre', 'membre'), +(3, 'webmaster', 'webmaster'); -- -------------------------------------------------------- @@ -99,14 +106,14 @@ CREATE TABLE IF NOT EXISTS `mw_users` ( `password` varchar(255) NOT NULL, `email` varchar(255) NOT NULL, PRIMARY KEY (`id`) -) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=18 ; +) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=20 ; -- -- Contenu de la table `mw_users` -- INSERT INTO `mw_users` (`id`, `login`, `password`, `email`) VALUES -(17, 'admin', '25e4ee4e9229397b6b17776bfceaf8e7', 'admin@domain.tld'); +(19, 'admin', '25e4ee4e9229397b6b17776bfceaf8e7', 'admin@domain.tld'); -- -------------------------------------------------------- @@ -117,7 +124,8 @@ INSERT INTO `mw_users` (`id`, `login`, `password`, `email`) VALUES CREATE TABLE IF NOT EXISTS `mw_users_roles` ( `id_user` int(11) NOT NULL, `id_role` int(11) NOT NULL, - PRIMARY KEY (`id_user`,`id_role`) + PRIMARY KEY (`id_user`,`id_role`), + KEY `id_role` (`id_role`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; -- @@ -125,5 +133,24 @@ CREATE TABLE IF NOT EXISTS `mw_users_roles` ( -- INSERT INTO `mw_users_roles` (`id_user`, `id_role`) VALUES -(17, 1), -(17, 2); +(19, 1), +(19, 2), +(19, 3); + +-- +-- Contraintes pour les tables exportées +-- +-- DECOMMENTER POUR AJOUTER LES CONTRAINTES + +-- +-- Contraintes pour la table `mw_actions_roles` +-- +-- ALTER TABLE `mw_actions_roles` +-- ADD CONSTRAINT `mw_actions_roles_ibfk_1` FOREIGN KEY (`id_role`) REFERENCES `mw_roles` (`id`); + +-- +-- Contraintes pour la table `mw_users_roles` +-- +-- ALTER TABLE `mw_users_roles` +-- ADD CONSTRAINT `mw_users_roles_ibfk_1` FOREIGN KEY (`id_user`) REFERENCES `mw_users` (`id`), +-- ADD CONSTRAINT `mw_users_roles_ibfk_2` FOREIGN KEY (`id_role`) REFERENCES `mw_roles` (`id`); diff --git a/content/data/xml/mw/actions_roles/.index b/content/data/xml/mw/actions_roles/.index index 0947c33..66321c0 100644 --- a/content/data/xml/mw/actions_roles/.index +++ b/content/data/xml/mw/actions_roles/.index @@ -1 +1 @@ -188 \ No newline at end of file +189 \ No newline at end of file diff --git a/content/data/xml/mw/actions_roles/189.xml b/content/data/xml/mw/actions_roles/189.xml new file mode 100644 index 0000000..3794dfc --- /dev/null +++ b/content/data/xml/mw/actions_roles/189.xml @@ -0,0 +1,4 @@ + + + + diff --git a/content/data/xml/mw/roles/0.xml b/content/data/xml/mw/roles/0.xml new file mode 100644 index 0000000..4c10cf8 --- /dev/null +++ b/content/data/xml/mw/roles/0.xml @@ -0,0 +1,4 @@ + + + + diff --git a/content/data/xml/mw/roles/3.xml b/content/data/xml/mw/roles/3.xml new file mode 100644 index 0000000..d711a8b --- /dev/null +++ b/content/data/xml/mw/roles/3.xml @@ -0,0 +1,4 @@ + + + + diff --git a/content/data/xml/mw/users_roles/.index b/content/data/xml/mw/users_roles/.index index 1758ddd..dc7b54a 100644 --- a/content/data/xml/mw/users_roles/.index +++ b/content/data/xml/mw/users_roles/.index @@ -1 +1 @@ -32 \ No newline at end of file +33 \ No newline at end of file diff --git a/content/data/xml/mw/users_roles/33.xml b/content/data/xml/mw/users_roles/33.xml new file mode 100644 index 0000000..b16b47e --- /dev/null +++ b/content/data/xml/mw/users_roles/33.xml @@ -0,0 +1,4 @@ + + + + diff --git a/mw/app/config.xml b/mw/app/config.xml index e16483f..1118636 100644 --- a/mw/app/config.xml +++ b/mw/app/config.xml @@ -71,8 +71,24 @@ + + + + + + + + + + + + + + + + - + diff --git a/mw/app/data/modules/share/mw_data_users_files.php b/mw/app/data/modules/share/mw_data_users_files.php new file mode 100644 index 0000000..5e35a4f --- /dev/null +++ b/mw/app/data/modules/share/mw_data_users_files.php @@ -0,0 +1,20 @@ +env(); + if(!isset($id_user)){ + $user = $env->user(); + if(isset($user["id"])) $id_user = $user["id"]; + } + if(!isset($id_user) || !$id_user) return false; + if(!preg_match("/^[0-9]+$/", $id_user)) return false; + $user_dir = $env->path("content")."uploads/".$id_user; + if(!file_exists($user_dir)) @mkdir($user_dir); + return file_exists($user_dir); + } + + } + +?> \ No newline at end of file diff --git a/mw/app/data/modules/share/mw_data_users_sessions.php b/mw/app/data/modules/share/mw_data_users_sessions.php new file mode 100644 index 0000000..daabe2b --- /dev/null +++ b/mw/app/data/modules/share/mw_data_users_sessions.php @@ -0,0 +1,91 @@ +user($login)) !== false){ + if($this->password_ok($user, $password)){ + if(!$this->set_session($user)) $user = false; + } + else{ + $this->clear_session(); + $user = array(); + } + } + return $user; + } + + function logout(){ + return $this->clear_session(); + } + + function user_ok($user){ + return + strcmp(md5($user["password"].$_SESSION["id"]), $_SESSION["pass"]) == 0 + && $_SESSION["ip"] == $_SERVER["REMOTE_ADDR"]; + } + + function password_ok($user, $password){ + if(!$user) return false; + return + strcmp(md5($user["password"].$_SESSION["id"]), $password) == 0 + && $_SESSION["ip"] == $_SERVER["REMOTE_ADDR"]; + } + + # ---------------------------------------------------------------------------------------- + # session + # + + function load_session(){ + @session_start(); + if(!isset($_SESSION["id"])) $this->clear_session(); + $user = array(); + if(isset($_SESSION["user"])){ + $user = $this->user($_SESSION["user"]); + } + elseif(isset($_COOKIE["user"]) && isset($_COOKIE["pass"])){ + if($user = $this->user($_COOKIE["user"])){ + $user["password"] = $_COOKIE["pass"]; + $this->set_session($user); + } + } + if($user){ + if(!$this->user_ok($user)){ + $this->clear_session(); + $user = array(); + } + } + else $user = array(); + $this->user = $user; + return $user; + } + + function set_session($user){ + $_SESSION["user"] = $user["login"]; + $_SESSION["pass"] = md5($user["password"].$_SESSION["id"]); + $env = $this->env(); + return + setcookie("user", $user["login"], time() + (60 * 60 * 24 * 7), $env->path("web")) + && setcookie("pass", $user["password"], time() + (60 * 60 * 24 * 7), $env->path("web")); + } + + function clear_session(){ + unset($_SESSION["user"]); + unset($_SESSION["pass"]); + $_SESSION["ip"] = $_SERVER["REMOTE_ADDR"]; + $_SESSION["id"] = md5(rand()); + $env = $this->env(); + return + setcookie("user", "", 0, $env->path("web")) + && setcookie("pass", "", 0, $env->path("web")); + } + + function get_session_user(){ + return $this->user; + } + + } + +?> \ No newline at end of file diff --git a/mw/app/data/modules/sql/mw_data_users.php b/mw/app/data/modules/sql/mw_data_users.php index 32bc0c5..66783fa 100644 --- a/mw/app/data/modules/sql/mw_data_users.php +++ b/mw/app/data/modules/sql/mw_data_users.php @@ -409,104 +409,6 @@ return array(); } - # ---------------------------------------------------------------------------------------- - # log in / out - # - - function login($login, $password){ - if(($user = $this->user($login)) !== false){ - if($this->password_ok($user, $password)){ - if(!$this->set_session($user)) $user = false; - } - else{ - $this->clear_session(); - $user = array(); - } - } - return $user; - } - - function logout(){ - return $this->clear_session(); - } - - function user_ok($user){ - return - strcmp(md5($user["password"].$_SESSION["id"]), $_SESSION["pass"]) == 0 - && $_SESSION["ip"] == $_SERVER["REMOTE_ADDR"]; - } - - function password_ok($user, $password){ - if(!$user) return false; - return - strcmp(md5($user["password"].$_SESSION["id"]), $password) == 0 - && $_SESSION["ip"] == $_SERVER["REMOTE_ADDR"]; - } - - # ---------------------------------------------------------------------------------------- - # session - # - - function load_session(){ - @session_start(); - if(!isset($_SESSION["id"])) $this->clear_session(); - $user = array(); - if(isset($_SESSION["user"])){ - $user = $this->user($_SESSION["user"]); - } - elseif(isset($_COOKIE["user"]) && isset($_COOKIE["pass"])){ - if($user = $this->user($_COOKIE["user"])){ - $user["password"] = $_COOKIE["pass"]; - $this->set_session($user); - } - } - if($user){ - if(!$this->user_ok($user)){ - $this->clear_session(); - $user = array(); - } - } - else $user = array(); - $this->user = $user; - return $user; - } - - function set_session($user){ - $_SESSION["user"] = $user["login"]; - $_SESSION["pass"] = md5($user["password"].$_SESSION["id"]); - $env = $this->env(); - return - setcookie("user", $user["login"], time() + (60 * 60 * 24 * 7), $env->path("web")) - && setcookie("pass", $user["password"], time() + (60 * 60 * 24 * 7), $env->path("web")); - } - - function clear_session(){ - unset($_SESSION["user"]); - unset($_SESSION["pass"]); - $_SESSION["ip"] = $_SERVER["REMOTE_ADDR"]; - $_SESSION["id"] = md5(rand()); - $env = $this->env(); - return - setcookie("user", "", 0, $env->path("web")) - && setcookie("pass", "", 0, $env->path("web")); - } - - function get_session_user(){ - return $this->user; - } - - # ---------------------------------------------------------------------------------------- - # uploads - # - - function check_user_uploads_dir($user = null){ - $env = $this->env(); - if((!isset($user) || !$user) && !isset($this->user["id"])) return false; - $user_dir = $env->path("content")."uploads/".(isset($user) && $user ? $user : $this->user["id"]); - if(!file_exists($user_dir)) @mkdir($user_dir); - return file_exists($user_dir); - } - } ?> \ No newline at end of file diff --git a/mw/app/data/modules/xml/mw_data_users.php b/mw/app/data/modules/xml/mw_data_users.php index a5e5e9c..3bbffee 100644 --- a/mw/app/data/modules/xml/mw_data_users.php +++ b/mw/app/data/modules/xml/mw_data_users.php @@ -524,96 +524,6 @@ return array(); } - # ---------------------------------------------------------------------------------------- - # log in / out - # - - function login($login, $password){ - if(($user = $this->user($login)) !== false){ - if($this->password_ok($user, $password)){ - if(!$this->set_session($user)) $user = false; - } - else{ - $this->clear_session(); - $user = array(); - } - } - return $user; - } - - function logout(){ - return $this->clear_session(); - } - - function user_ok($user){ - return - strcmp(md5($user["password"].$_SESSION["id"]), $_SESSION["pass"]) == 0 - && $_SESSION["ip"] == $_SERVER["REMOTE_ADDR"]; - } - - function password_ok($user, $password){ - if(!$user) return false; - return - strcmp(md5($user["password"].$_SESSION["id"]), $password) == 0 - && $_SESSION["ip"] == $_SERVER["REMOTE_ADDR"]; - } - - # ---------------------------------------------------------------------------------------- - # session - # - - function load_session(){ - session_start(); - if(!isset($_SESSION["id"])) $this->clear_session(); - if( - $user = ( - isset($_COOKIE["user"]) || isset($_SESSION["user"]) ? - $this->user(isset($_COOKIE["user"]) ? $_COOKIE["user"] : $_SESSION["user"]) - : array() - ) - ){ - if(isset($_COOKIE["user"])) $this->set_session($user); - if(!$this->user_ok($user)){ - $this->clear_session(); - $user = array(); - } - } - $this->user = $user; - return $user; - } - - function set_session($user){ - $_SESSION["user"] = $user["login"]; - $_SESSION["pass"] = md5($user["password"].$_SESSION["id"]); - $env = $this->env(); - return setcookie("user", $user["login"], time() + (60 * 60 * 24 * 7), $env->path("web")); - } - - function clear_session(){ - unset($_SESSION["user"]); - unset($_SESSION["pass"]); - $_SESSION["ip"] = $_SERVER["REMOTE_ADDR"]; - $_SESSION["id"] = md5(rand()); - $env = $this->env(); - return setcookie("user", "", 0, $env->path("web")); - } - - function get_session_user(){ - return $this->user; - } - - # ---------------------------------------------------------------------------------------- - # uploads - # - - function check_user_uploads_dir($user = null){ - $env = $this->env(); - if((!isset($user) || !$user) && !isset($this->user["id"])) return false; - $user_dir = $env->path("content")."uploads/".(isset($user) && $user ? $user : $this->user["id"]); - if(!file_exists($user_dir)) @mkdir($user_dir); - return file_exists($user_dir); - } - } ?> \ No newline at end of file -- 2.1.4