From 3d69c6b093eb557bde56274d42626633b5397c76 Mon Sep 17 00:00:00 2001 From: Matthieu Leproux Date: Tue, 21 Jun 2022 13:56:34 +0200 Subject: [PATCH] creating user agent column for activities --- include/functions.inc.php | 7 ++++--- include/ws_functions/pwg.php | 11 +++++++++-- install/db/164-database.php | 23 +++++++++++++++++++++++ install/piwigo_structure-mysql.sql | 1 + 4 files changed, 37 insertions(+), 5 deletions(-) create mode 100644 install/db/164-database.php diff --git a/include/functions.inc.php b/include/functions.inc.php index 24e8c8cf0..158e3deee 100644 --- a/include/functions.inc.php +++ b/include/functions.inc.php @@ -556,9 +556,10 @@ function pwg_activity($object, $object_id, $action, $details=array()) } } - if ('user' == $object and 'login' == $action) + $user_agent = null; + if ('user' == $object and 'login' == $action and isset($_SERVER['HTTP_USER_AGENT'])) { - $details['agent'] = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : 'unknown'; + $user_agent = $_SERVER['HTTP_USER_AGENT']; } if ('photo' == $object and 'add' == $action and !isset($details['sync'])) @@ -568,7 +569,6 @@ function pwg_activity($object, $object_id, $action, $details=array()) { $details['added_with'] = 'browser'; } - $details['agent'] = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : 'unknown'; } if (in_array($object, array('album', 'photo')) and 'delete' == $action and isset($_GET['page']) and 'site_update' == $_GET['page']) @@ -603,6 +603,7 @@ function pwg_activity($object, $object_id, $action, $details=array()) 'session_idx' => session_id(), 'ip_address' => $ip_address, 'details' => $details_insert, + 'user_agent' => $user_agent, ); } diff --git a/include/ws_functions/pwg.php b/include/ws_functions/pwg.php index bc81f1f49..fe9a9ebd6 100644 --- a/include/ws_functions/pwg.php +++ b/include/ws_functions/pwg.php @@ -445,7 +445,8 @@ SELECT session_idx, ip_address, occured_on, - details + details, + user_agent FROM '.ACTIVITY_TABLE.' WHERE performed_by = '.$param['uid'].' ORDER BY activity_id DESC LIMIT '.$page_size.' OFFSET '.$page_offset.'; @@ -463,7 +464,8 @@ SELECT session_idx, ip_address, occured_on, - details + details, + user_agent FROM '.ACTIVITY_TABLE.' ORDER BY activity_id DESC LIMIT '.$page_size.' OFFSET '.$page_offset.'; ;'; @@ -477,6 +479,11 @@ SELECT $row['details'] = str_replace('`rank`', 'rank', $row['details']); $details = @unserialize($row['details']); + if (isset($row['user_agent'])) + { + $details['agent'] = $row['user_agent']; + } + if (isset($details['method'])) { $detailsType = 'method'; diff --git a/install/db/164-database.php b/install/db/164-database.php new file mode 100644 index 000000000..96f0cb2ab --- /dev/null +++ b/install/db/164-database.php @@ -0,0 +1,23 @@ + diff --git a/install/piwigo_structure-mysql.sql b/install/piwigo_structure-mysql.sql index 556180890..a298c86e6 100644 --- a/install/piwigo_structure-mysql.sql +++ b/install/piwigo_structure-mysql.sql @@ -19,6 +19,7 @@ CREATE TABLE `piwigo_activity` ( `ip_address` varchar(50) DEFAULT NULL, `occured_on` TIMESTAMP DEFAULT CURRENT_TIMESTAMP, `details` varchar(255) DEFAULT NULL, + `user_agent` varchar(255) DEFAULT NULL, PRIMARY KEY (`activity_id`) ) ENGINE=MyISAM;