mirror of https://github.com/acanas/swad-core.git
Version 21.13: Sep 22, 2021 New module swad_log_database for database queries related to access logs.
This commit is contained in:
parent
ebc93b6c27
commit
02f5eeb7c0
2
Makefile
2
Makefile
|
@ -60,7 +60,7 @@ OBJS = swad_account.o swad_account_database.o swad_action.o swad_admin.o \
|
|||
swad_institution.o swad_institution_config.o \
|
||||
swad_institution_database.o \
|
||||
swad_language.o swad_layout.o swad_link.o swad_link_database.o \
|
||||
swad_log.o swad_logo.o \
|
||||
swad_log.o swad_log_database.o swad_logo.o \
|
||||
swad_MAC.o swad_mail.o swad_main.o swad_maintenance.o swad_map.o \
|
||||
swad_mark.o swad_match.o swad_match_print.o swad_match_result.o \
|
||||
swad_media.o swad_media_database.o swad_menu.o swad_message.o \
|
||||
|
|
|
@ -602,13 +602,14 @@ TODO: FIX BUG, URGENT! En las fechas como par
|
|||
|
||||
TODO: En las encuestas, que los estudiantes no puedan ver los resultados hasta que no finalice el plazo.
|
||||
*/
|
||||
#define Log_PLATFORM_VERSION "SWAD 21.12 (2021-09-22)"
|
||||
#define Log_PLATFORM_VERSION "SWAD 21.13 (2021-09-22)"
|
||||
#define CSS_FILE "swad20.45.css"
|
||||
#define JS_FILE "swad20.69.1.js"
|
||||
/*
|
||||
TODO: Rename CENTRE to CENTER in help wiki.
|
||||
TODO: Rename ASSESSMENT.Announcements to ASSESSMENT.Calls_for_exams
|
||||
|
||||
Version 21.13: Sep 22, 2021 New module swad_log_database for database queries related to access logs. (316510 lines)
|
||||
Version 21.12: Sep 22, 2021 New module swad_link_database for database queries related to institutional links. (316361 lines)
|
||||
Version 21.11.1: Sep 22, 2021 Queries moved to module swad_info_database. (316237 lines)
|
||||
Version 21.11: Sep 22, 2021 New module swad_info_database for database queries related to course information. (316228 lines)
|
||||
|
|
|
@ -53,6 +53,7 @@
|
|||
#include "swad_language.h"
|
||||
#include "swad_link.h"
|
||||
#include "swad_log.h"
|
||||
#include "swad_log_database.h"
|
||||
#include "swad_logo.h"
|
||||
#include "swad_match.h"
|
||||
#include "swad_MFU.h"
|
||||
|
@ -1449,7 +1450,7 @@ void Lay_RefreshNotifsAndConnected (void)
|
|||
else if (!(Gbl.PID % 103))
|
||||
Set_RemoveOldSettingsFromIP (); // Remove old settings from IP
|
||||
else if (!(Gbl.PID % 107))
|
||||
Log_RemoveOldEntriesRecentLog (); // Remove old entries in recent log table, it's a slow query
|
||||
Log_DB_RemoveOldEntriesRecentLog (); // Remove old entries in recent log table, it's a slow query
|
||||
else if (!(Gbl.PID % 109))
|
||||
Fil_RemoveOldTmpFiles (Cfg_PATH_OUT_PRIVATE ,Cfg_TIME_TO_DELETE_HTML_OUTPUT ,false);
|
||||
else if (!(Gbl.PID % 113))
|
||||
|
|
122
swad_log.c
122
swad_log.c
|
@ -40,6 +40,7 @@
|
|||
#include "swad_HTML.h"
|
||||
#include "swad_institution_database.h"
|
||||
#include "swad_log.h"
|
||||
#include "swad_log_database.h"
|
||||
#include "swad_profile.h"
|
||||
#include "swad_role.h"
|
||||
#include "swad_statistic.h"
|
||||
|
@ -52,8 +53,6 @@
|
|||
/***************************** Private constants *****************************/
|
||||
/*****************************************************************************/
|
||||
|
||||
#define Log_SECONDS_IN_RECENT_LOG ((time_t) (Cfg_DAYS_IN_RECENT_LOG * 24UL * 60UL * 60UL)) // Remove entries in recent log oldest than this time
|
||||
|
||||
/*****************************************************************************/
|
||||
/****************************** Private types ********************************/
|
||||
/*****************************************************************************/
|
||||
|
@ -88,50 +87,10 @@ void Log_LogAccess (const char *Comments)
|
|||
|
||||
/***** Insert access into database *****/
|
||||
/* Log access in historical log */
|
||||
LogCod =
|
||||
DB_QueryINSERTandReturnCode ("can not log access",
|
||||
"INSERT INTO log"
|
||||
" (ActCod,CtyCod,InsCod,CtrCod,DegCod,CrsCod,"
|
||||
"UsrCod,Role,ClickTime,"
|
||||
"TimeToGenerate,TimeToSend,IP)"
|
||||
" VALUES"
|
||||
" (%ld,%ld,%ld,%ld,%ld,%ld,"
|
||||
"%ld,%u,NOW(),"
|
||||
"%ld,%ld,'%s')",
|
||||
ActCod,
|
||||
Gbl.Hierarchy.Cty.CtyCod,
|
||||
Gbl.Hierarchy.Ins.InsCod,
|
||||
Gbl.Hierarchy.Ctr.CtrCod,
|
||||
Gbl.Hierarchy.Deg.DegCod,
|
||||
Gbl.Hierarchy.Crs.CrsCod,
|
||||
Gbl.Usrs.Me.UsrDat.UsrCod,
|
||||
(unsigned) RoleToStore,
|
||||
Gbl.TimeGenerationInMicroseconds,
|
||||
Gbl.TimeSendInMicroseconds,
|
||||
Gbl.IP);
|
||||
LogCod = Log_DB_LogAccessInHistoricalLog (ActCod,RoleToStore);
|
||||
|
||||
/* Log access in recent log (log_recent) */
|
||||
DB_QueryINSERT ("can not log access (recent)",
|
||||
"INSERT INTO log_recent"
|
||||
" (LogCod,ActCod,CtyCod,InsCod,CtrCod,DegCod,CrsCod,"
|
||||
"UsrCod,Role,ClickTime,"
|
||||
"TimeToGenerate,TimeToSend,IP)"
|
||||
" VALUES"
|
||||
" (%ld,%ld,%ld,%ld,%ld,%ld,%ld,"
|
||||
"%ld,%u,NOW(),"
|
||||
"%ld,%ld,'%s')",
|
||||
LogCod,
|
||||
ActCod,
|
||||
Gbl.Hierarchy.Cty.CtyCod,
|
||||
Gbl.Hierarchy.Ins.InsCod,
|
||||
Gbl.Hierarchy.Ctr.CtrCod,
|
||||
Gbl.Hierarchy.Deg.DegCod,
|
||||
Gbl.Hierarchy.Crs.CrsCod,
|
||||
Gbl.Usrs.Me.UsrDat.UsrCod,
|
||||
(unsigned) RoleToStore,
|
||||
Gbl.TimeGenerationInMicroseconds,
|
||||
Gbl.TimeSendInMicroseconds,
|
||||
Gbl.IP);
|
||||
Log_DB_LogAccessInRecentLog (LogCod,ActCod,RoleToStore);
|
||||
|
||||
/* Log access while answering exam prints */
|
||||
ExaLog_LogAccess (LogCod);
|
||||
|
@ -145,49 +104,24 @@ void Log_LogAccess (const char *Comments)
|
|||
Str_Copy (CommentsDB,Comments,MaxLength);
|
||||
Str_ChangeFormat (Str_FROM_TEXT,Str_TO_TEXT,
|
||||
CommentsDB,MaxLength,true); // Avoid SQL injection
|
||||
DB_QueryINSERT ("can not log access (comments)",
|
||||
"INSERT INTO log_comments"
|
||||
" (LogCod,Comments)"
|
||||
" VALUES"
|
||||
" (%ld,'%s')",
|
||||
LogCod,
|
||||
CommentsDB);
|
||||
Log_DB_LogComments (LogCod,CommentsDB);
|
||||
free (CommentsDB);
|
||||
}
|
||||
}
|
||||
|
||||
/* Log search string */
|
||||
if (Gbl.Search.LogSearch && Gbl.Search.Str[0])
|
||||
DB_QueryINSERT ("can not log access (search)",
|
||||
"INSERT INTO log_search"
|
||||
" (LogCod,SearchStr)"
|
||||
" VALUES"
|
||||
" (%ld,'%s')",
|
||||
LogCod,
|
||||
Gbl.Search.Str);
|
||||
Log_DB_LogSearchString (LogCod);
|
||||
|
||||
if (Gbl.WebService.IsWebService)
|
||||
/* Log web service plugin and function */
|
||||
DB_QueryINSERT ("can not log access (comments)",
|
||||
"INSERT INTO log_api"
|
||||
" (LogCod,PlgCod,FunCod)"
|
||||
" VALUES"
|
||||
" (%ld,%ld,%u)",
|
||||
LogCod,
|
||||
Gbl.WebService.PlgCod,
|
||||
(unsigned) Gbl.WebService.Function);
|
||||
/* Log web service plugin and API function */
|
||||
Log_DB_LogAPI (LogCod);
|
||||
else
|
||||
{
|
||||
BanCodClicked = Ban_GetBanCodClicked ();
|
||||
if (BanCodClicked > 0)
|
||||
/* Log banner clicked */
|
||||
DB_QueryINSERT ("can not log banner clicked",
|
||||
"INSERT INTO log_banners"
|
||||
" (LogCod,BanCod)"
|
||||
" VALUES"
|
||||
" (%ld,%ld)",
|
||||
LogCod,
|
||||
BanCodClicked);
|
||||
Log_DB_LogBanner (LogCod,BanCodClicked);
|
||||
}
|
||||
|
||||
/***** Increment my number of clicks *****/
|
||||
|
@ -195,19 +129,6 @@ void Log_LogAccess (const char *Comments)
|
|||
Prf_DB_IncrementNumClicksUsr (Gbl.Usrs.Me.UsrDat.UsrCod);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/************ Sometimes, we delete old entries in recent log table ***********/
|
||||
/*****************************************************************************/
|
||||
|
||||
void Log_RemoveOldEntriesRecentLog (void)
|
||||
{
|
||||
/***** Remove all expired clipboards *****/
|
||||
DB_QueryDELETE ("can not remove old entries from recent log",
|
||||
"DELETE LOW_PRIORITY FROM log_recent"
|
||||
" WHERE ClickTime<FROM_UNIXTIME(UNIX_TIMESTAMP()-%lu)",
|
||||
Log_SECONDS_IN_RECENT_LOG);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/*************** Put a link to show last clicks in real time *****************/
|
||||
/*****************************************************************************/
|
||||
|
@ -233,8 +154,8 @@ void Log_ShowLastClicks (void)
|
|||
|
||||
/***** Contextual menu *****/
|
||||
Mnu_ContextMenuBegin ();
|
||||
Sta_PutLinkToGlobalHits (); // Global hits
|
||||
Sta_PutLinkToCourseHits (); // Course hits
|
||||
Sta_PutLinkToGlobalHits (); // Global hits
|
||||
Sta_PutLinkToCourseHits (); // Course hits
|
||||
Mnu_ContextMenuEnd ();
|
||||
|
||||
/***** Begin box *****/
|
||||
|
@ -242,10 +163,10 @@ void Log_ShowLastClicks (void)
|
|||
NULL,NULL,
|
||||
Hlp_USERS_Connected_last_clicks,Box_NOT_CLOSABLE);
|
||||
|
||||
/***** Get and show last clicks *****/
|
||||
HTM_DIV_Begin ("id=\"lastclicks\" class=\"CM\""); // Used for AJAX based refresh
|
||||
Log_GetAndShowLastClicks ();
|
||||
HTM_DIV_End (); // Used for AJAX based refresh
|
||||
/***** Get and show last clicks *****/
|
||||
HTM_DIV_Begin ("id=\"lastclicks\" class=\"CM\""); // Used for AJAX based refresh
|
||||
Log_GetAndShowLastClicks ();
|
||||
HTM_DIV_End (); // Used for AJAX based refresh
|
||||
|
||||
/***** End box *****/
|
||||
Box_BoxEnd ();
|
||||
|
@ -277,20 +198,7 @@ void Log_GetAndShowLastClicks (void)
|
|||
struct Hie_Hierarchy Hie;
|
||||
|
||||
/***** Get last clicks from database *****/
|
||||
NumClicks = (unsigned)
|
||||
DB_QuerySELECT (&mysql_res,"can not get last clicks",
|
||||
"SELECT LogCod," // row[0]
|
||||
"ActCod," // row[1]
|
||||
"UNIX_TIMESTAMP()-"
|
||||
"UNIX_TIMESTAMP(ClickTime)," // row[2]
|
||||
"Role," // row[3]
|
||||
"CtyCod," // row[4]
|
||||
"InsCod," // row[5]
|
||||
"CtrCod," // row[6]
|
||||
"DegCod" // row[7]
|
||||
" FROM log_recent"
|
||||
" ORDER BY LogCod DESC"
|
||||
" LIMIT 20");
|
||||
NumClicks = Log_DB_GetLastClicks (&mysql_res);
|
||||
|
||||
/***** Write list of connected users *****/
|
||||
HTM_TABLE_BeginCenterPadding (1);
|
||||
|
|
|
@ -31,6 +31,8 @@
|
|||
/***************************** Public constants ******************************/
|
||||
/*****************************************************************************/
|
||||
|
||||
#define Log_SECONDS_IN_RECENT_LOG ((time_t) (Cfg_DAYS_IN_RECENT_LOG * 24UL * 60UL * 60UL)) // Remove entries in recent log oldest than this time
|
||||
|
||||
/*****************************************************************************/
|
||||
/******************************* Public types ********************************/
|
||||
/*****************************************************************************/
|
||||
|
@ -40,7 +42,6 @@
|
|||
/*****************************************************************************/
|
||||
|
||||
void Log_LogAccess (const char *Comments);
|
||||
void Log_RemoveOldEntriesRecentLog (void);
|
||||
|
||||
void Log_PutLinkToLastClicks (void);
|
||||
void Log_ShowLastClicks (void);
|
||||
|
|
Loading…
Reference in New Issue