Skip to content

Commit

Permalink
Ajout du referer dans les logs
Browse files Browse the repository at this point in the history
Ajout du referer dans les logs et ajout des logs dans les modules
sla_secure et sla_articles
  • Loading branch information
wakdev committed Mar 30, 2013
1 parent 001c6fb commit a6559ca
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 8 deletions.
40 changes: 37 additions & 3 deletions admin/modules/sla_articles/controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,14 +159,30 @@ private function load_params() {
$this->mode = "edit";
}else{
$this->message = $this->articles->save_item($this->datas["id"],$this->datas);

//Log action
$log_info = "";
if ($this->datas["id"] == 0) {$log_info .= "add article";}else{$log_info .= "edit article [id=".$this->datas["id"]."].";}
$this->slash->log($log_info,$this->module_name);

$this->mode = "show";
}

break;

case "delete"://Delete
if ($this->slash->sl_param($this->module_name."_valid","POST")) {
$this->articles->delete_items($this->slash->sl_param($this->module_name."_checked","POST"));

$id_array = $this->slash->sl_param($this->module_name."_checked","POST");
$this->articles->delete_items($id_array);

//Log action
$ids = "";
foreach ($id_array as $value) {$ids .= $value.",";}
$ids = substr($ids,0,-1);
$log_info = "delete article [id=".$ids."].";
$this->slash->log($log_info,$this->module_name);

$this->mode = "show";
$this->message = $this->slash->trad_word("DELETE_SUCCESS");
}else {
Expand All @@ -182,7 +198,16 @@ private function load_params() {
case "set_enabled": //Set enabled
$values = $this->slash->sl_param($this->module_name."_checked","POST");
if (isset ($values) && count($values) > 0) {
$this->articles->set_items_enabled($this->slash->sl_param($this->module_name."_checked","POST"),1);
$id_array = $this->slash->sl_param($this->module_name."_checked","POST");
$this->articles->set_items_enabled($id_array,1);

//Log action
$ids = "";
foreach ($id_array as $value) {$ids .= $value.",";}
$ids = substr($ids,0,-1);
$log_info = "enable article [id=".$ids."].";
$this->slash->log($log_info,$this->module_name);

$this->mode = "show";
$this->message = $this->slash->trad_word("ITEM_ENABLE_SUCCESS");
}else{
Expand All @@ -193,7 +218,16 @@ private function load_params() {
case "set_disabled": //Set disabled
$values = $this->slash->sl_param($this->module_name."_checked","POST");
if (isset ($values) && count($values) > 0) {
$this->articles->set_items_enabled($this->slash->sl_param($this->module_name."_checked","POST"),0);
$id_array = $this->slash->sl_param($this->module_name."_checked","POST");
$this->articles->set_items_enabled($id_array,0);

//Log action
$ids = "";
foreach ($id_array as $value) {$ids .= $value.",";}
$ids = substr($ids,0,-1);
$log_info = "disable article [id=".$ids."].";
$this->slash->log($log_info,$this->module_name);

$this->mode = "show";
$this->message = $this->slash->trad_word("ITEM_DISABLE_SUCCESS");
}else{
Expand Down
13 changes: 11 additions & 2 deletions admin/modules/sla_secure/controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
/**
* @todo Use Cookies
* @todo Log connexion function
* @todo MVC
*/


Expand All @@ -44,8 +45,7 @@

class sla_secure_controller extends slaController implements iController{



public $module_name = "sla_secure";
public $view;

/**
Expand Down Expand Up @@ -90,6 +90,11 @@ public function initialize() {

$_SESSION["user_language"] = $row["language"];
$this->slash->get_params["mod"] = "sla_panel";

//Log connexion
$log_info = "user [".$row["login"]."] [".$_SERVER["REMOTE_ADDR"]."] connected.";
$this->slash->log($log_info,$this->module_name);

}else{
$this->error = "inactive_user";
}
Expand All @@ -102,6 +107,10 @@ public function initialize() {
// Logout script
if ($this->slash->get_params["act"] == "logout") {

//Log connexion
$log_info = "[".$_SERVER["REMOTE_ADDR"]."] disconnected.";
$this->slash->log($log_info,$this->module_name);

$_SESSION = array();
/*
if (isset($_COOKIE[session_name()])) {
Expand Down
5 changes: 3 additions & 2 deletions core/slash.php
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,7 @@ public function log($log_info,$log_title=null,$log_type=SL_LOG_TYPE_INFO,$clear=

$id_user = 0;
$log_url = $_SERVER["REQUEST_URI"];
$log_referer = $_SERVER["HTTP_REFERER"];
$log_date = date("Y-m-d H:i:s",time());

if (isset($_SESSION["id_user"])) {$id_user=$_SESSION["id_user"];}
Expand All @@ -416,8 +417,8 @@ public function log($log_info,$log_title=null,$log_type=SL_LOG_TYPE_INFO,$clear=

$this->database->setQuery("
INSERT INTO ".$this->db_prefix."logs
(id,log_type,log_url,log_info,id_user,log_date) value
('','".$log_type."','".$log_url."','".$log_info."','".$id_user."','".$log_date."')");
(id,log_type,log_url,log_referer,log_info,id_user,log_date) value
('','".$log_type."','".$log_url."','".$log_referer."',\"".$log_info."\",'".$id_user."','".$log_date."')");
if (!$this->database->execute()) {
$this->show_fatal_error("QUERY_ERROR",$this->database->getError());
}
Expand Down
3 changes: 2 additions & 1 deletion db_slashcms.sql
Original file line number Diff line number Diff line change
Expand Up @@ -236,11 +236,12 @@ CREATE TABLE IF NOT EXISTS `sl_logs` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`log_type` varchar(45) NOT NULL,
`log_url` varchar(255) NOT NULL,
`log_referer` varchar(255) NOT NULL,
`log_info` varchar(255) NOT NULL,
`id_user` int(10) unsigned NOT NULL,
`log_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;

-- --------------------------------------------------------

Expand Down

0 comments on commit a6559ca

Please sign in to comment.