From 6d7fbfcb3620af42745a1e7a3901afaa805344c4 Mon Sep 17 00:00:00 2001 From: Dany De Bontridder Date: Wed, 17 Nov 2010 20:16:43 +0000 Subject: [PATCH] task 126 : add security audit --- html/admin_repo.php | 5 ++ html/login.php | 2 +- include/audit_log.php | 84 ++++++++++++++++++++++++ include/class_database.php | 2 +- include/class_dossier.php | 2 +- include/class_user.php | 20 ++++-- include/constant.php | 2 +- include/constant.security.php | 2 + include/user_menu.php | 4 ++ sql/trunk/upgrade_account_repository.sql | 1 + 10 files changed, 116 insertions(+), 8 deletions(-) create mode 100644 include/audit_log.php diff --git a/html/admin_repo.php b/html/admin_repo.php index b6322e00a..aaf46cdf8 100644 --- a/html/admin_repo.php +++ b/html/admin_repo.php @@ -80,6 +80,11 @@ if ( isset ($_REQUEST["action"]) ) // Backup and restaure folders require_once("restore.inc.php"); } + if ($_REQUEST['action'] == 'audit_log') + { + /* List the connexion successuf and failed */ + require_once('audit_log.php'); + } }// action = modele_mgt ?> diff --git a/html/login.php b/html/login.php index 227c4c235..8b349af4a 100644 --- a/html/login.php +++ b/html/login.php @@ -40,7 +40,7 @@ if ( isset ($_POST["p_user"] ) ) $rep=new Database(); include_once ("class_user.php"); $User=new User($rep); - $User->Check(); + $User->Check(false,'LOGIN'); if ($g_captcha == true) { include("securimage/securimage.php"); diff --git a/include/audit_log.php b/include/audit_log.php new file mode 100644 index 000000000..c4d1c7753 --- /dev/null +++ b/include/audit_log.php @@ -0,0 +1,84 @@ + +
+exec_sql("select ac_user,ac_ip,to_char(ac_date,'DD.MM.YYYY HH24:MI') as fmt_date,ac_state,ac_module from audit_connect order by 3"); +?> + + + + + + + + + + count(); + for ($i=0;$i < $max ;$i++): + $r=$cn->fetch($i); +?> + + + + + + + + + +'; + break; + case 'SUCCESS'; + echo ' + + + + \ No newline at end of file diff --git a/include/class_database.php b/include/class_database.php index a86c62106..418677af8 100644 --- a/include/class_database.php +++ b/include/class_database.php @@ -311,7 +311,7 @@ class Database function fetch($p_indice) { if ( $this->ret == false ) throw new Exception ('this->ret is empty'); - return pg_fetch_array($this->ret ) ; + return pg_fetch_array($this->ret,$p_indice ) ; } /*!@brief return the number of rows found by the last query, synomym for count()*/ diff --git a/include/class_dossier.php b/include/class_dossier.php index 97267f1bc..a4efa22ec 100644 --- a/include/class_dossier.php +++ b/include/class_dossier.php @@ -95,7 +95,7 @@ class dossier if ( $Max == 0 ) return null; for ( $i=0;$i<$Max; $i++) { - $row[]=$this->cn->fetch($p_res); + $row[]=$this->cn->fetch($i); } return $row; } diff --git a/include/class_user.php b/include/class_user.php index 0fa472c93..40b8e41ee 100644 --- a/include/class_user.php +++ b/include/class_user.php @@ -127,7 +127,7 @@ class User * default is false * ++*/ - function Check($silent=false) + function Check($silent=false,$from='') { $res=0; @@ -158,9 +158,12 @@ class User } - + $sql="insert into audit_connect (ac_user,ac_ip,ac_module,ac_state) values ($1,$2,$3,$4)"; + if ( $res == 0 ) { + if ( $from=='LOGIN') + $cn->exec_sql($sql,array($_SESSION['g_user'],$_SERVER["REMOTE_ADDR"],$from,'FAIL')); if ( ! $silent) { alert(_('Utilisateur ou mot de passe incorrect')); @@ -171,7 +174,9 @@ class User } else { - $this->valid=1; + if ( $from=='LOGIN') + $cn->exec_sql($sql,array($_SESSION['g_user'],$_SERVER["REMOTE_ADDR"],$from,'SUCCESS')); + $this->valid=1; } return $ret; @@ -468,7 +473,14 @@ class User */ function check_action ( $p_action_id) { - + /* save it into the log */ + global $audit; + if (isset ($audit) && $audit == true) + { + $cn=new Database(); + $sql="insert into audit_connect (ac_user,ac_ip,ac_module,ac_state) values ($1,$2,$3,$4)"; + $cn->exec_sql($sql,array($_SESSION['g_user'],$_SERVER["REMOTE_ADDR"],$_SERVER['REQUEST_URI'],'FAIL')); + } if ( $this->Admin()==1 ) return 1; if ( $this->is_local_admin(dossier::id()) == 1 ) return 1; diff --git a/include/constant.php b/include/constant.php index 6d0a3624e..8caf65b47 100644 --- a/include/constant.php +++ b/include/constant.php @@ -31,7 +31,7 @@ global $version_phpcompta; error_reporting (15); global $g_captcha; -$g_captcha=true; +$g_captcha=false; /* set to none for production */ /* uncomment for production */ diff --git a/include/constant.security.php b/include/constant.security.php index cdd9fb615..9c3eb7c55 100644 --- a/include/constant.security.php +++ b/include/constant.security.php @@ -44,4 +44,6 @@ define ("STOWRITE",1510); //Stock (changement) define ("EXTENSION",1600); //Extension define ("PREVCON",1701); //Prevision define ("PREVMOD",1702); //Prevision + +global $audit; $audit=true; ?> diff --git a/include/user_menu.php b/include/user_menu.php index da497a687..7ce23c5f9 100644 --- a/include/user_menu.php +++ b/include/user_menu.php @@ -312,6 +312,9 @@ function MenuAdmin() case 'modele_mgt': $def=2; break; + case 'audit_log': + $def=4; + break; case 'restore'; $def=3; break; @@ -321,6 +324,7 @@ function MenuAdmin() array("admin_repo.php?action=dossier_mgt",_("Dossiers"),_('Gestion des dossiers'),1), array("admin_repo.php?action=modele_mgt",_("Modèles"),_('Gestion des modèles'),2), array("admin_repo.php?action=restore",_("Restaure"),_("Restaure une base de données"),3), + array("admin_repo.php?action=audit_log",_("Audit"),_("Utilisateurs qui se sont connectés"),4), array("login.php",_("Accueil")) ); diff --git a/sql/trunk/upgrade_account_repository.sql b/sql/trunk/upgrade_account_repository.sql index 02aa687a6..8c4e846b8 100644 --- a/sql/trunk/upgrade_account_repository.sql +++ b/sql/trunk/upgrade_account_repository.sql @@ -23,6 +23,7 @@ CREATE TABLE audit_connect ( ac_user text, ac_date timestamp without time zone DEFAULT now(), ac_ip text, + ac_module text, ac_state text, CONSTRAINT valid_state CHECK (((ac_state = 'FAIL'::text) OR (ac_state = 'SUCCESS'::text))) );
Utilisateur Date Adresse Module Résultat
+ + + + + + + +'; + break; + + } +?> + +