Skip to content

Commit 317884b

Browse files
committed
Aggiunta user-agent nei log di accesso
1 parent 3d85b76 commit 317884b

5 files changed

Lines changed: 48 additions & 21 deletions

File tree

‎gulpfile.js‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,8 @@ const JS = gulp.parallel(() => {
122122
'bootstrap-maxlength/dist/bootstrap-maxlength.js',
123123
'leaflet/dist/leaflet.js',
124124
'leaflet-gesture-handling/dist/leaflet-gesture-handling.min.js',
125-
'ismobilejs/dist/isMobile.min.js'
125+
'ismobilejs/dist/isMobile.min.js',
126+
'ua-parser-js/dist/ua-parser.min.js',
126127
];
127128

128129
for (const i in vendor) {

‎log.php‎

Lines changed: 41 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
* along with this program. If not, see <https://www.gnu.org/licenses/>.
1818
*/
1919

20+
use Carbon\Carbon;
21+
2022
include_once __DIR__.'/core.php';
2123

2224
$pageTitle = tr('Log');
@@ -34,10 +36,11 @@
3436
<table class="datatables table table-hover">
3537
<thead>
3638
<tr>
37-
<th>'.tr('Username').'</th>
38-
<th>'.tr('Data').'</th>
39-
<th>'.tr('Stato').'</th>
40-
<th>'.tr('Indirizzo IP').'</th>
39+
<th width="200">'.tr('Username').'</th>
40+
<th width="150">'.tr('Data').'</th>
41+
<th width="100">'.tr('Indirizzo IP').'</th>
42+
<th>'.tr('Dispositivo').'</th>
43+
<th width="180">'.tr('Stato').'</th>
4144
</tr>
4245
</thead>
4346
<tbody>';
@@ -50,38 +53,35 @@
5053
} else {
5154
$q = 'SELECT * FROM `zz_logs` WHERE `id_utente`='.prepare(Auth::user()['id']).' ORDER BY `created_at` DESC LIMIT 0, 100';
5255
}
53-
$rs = $dbo->fetchArray($q);
54-
$n = sizeof($rs);
55-
56-
for ($i = 0; $i < $n; ++$i) {
57-
$id = $rs[$i]['id'];
58-
$id_utente = $rs[$i]['id_utente'];
59-
$username = $rs[$i]['username'];
60-
$ip = $rs[$i]['ip'];
56+
$logs = $dbo->fetchArray($q);
6157

62-
$timestamp = Translator::timestampToLocale($rs[$i]['created_at']);
58+
foreach ($logs as $log) {
59+
$timestamp = Translator::timestampToLocale($log['created_at']);
6360

6461
$status = Auth::getStatus();
65-
if ($rs[$i]['stato'] == $status['success']['code']) {
62+
if ($log['stato'] == $status['success']['code']) {
6663
$type = 'success';
6764
$stato = $status['success']['message'];
68-
} elseif ($rs[$i]['stato'] == $status['disabled']['code']) {
65+
} elseif ($log['stato'] == $status['disabled']['code']) {
6966
$type = 'warning';
7067
$stato = $status['disabled']['message'];
71-
} elseif ($rs[$i]['stato'] == $status['unauthorized']['code']) {
68+
} elseif ($log['stato'] == $status['unauthorized']['code']) {
7269
$type = 'warning';
7370
$stato = $status['unauthorized']['message'];
7471
} else {
7572
$type = 'danger';
7673
$stato = $status['failed']['message'];
7774
}
7875

76+
$created_at = new Carbon($log['created_at']);
77+
7978
echo '
8079
<tr class="'.$type.'">
81-
<td>'.$username.'</td>
82-
<td>'.$timestamp.'</td>
80+
<td>'.$log['username'].'</td>
81+
<td class="tip" title="'.$created_at->format('d/m/Y H:i:s').'">'.$created_at->diffForHumans().'</td>
82+
<td>'.$log['ip'].'</td>
83+
<td class="user-agent tip" title="'.strip_tags($log['user_agent']).'">'.$log['user_agent'].'</td>
8384
<td><span class="label label-'.$type.'">'.$stato.'</span></td>
84-
<td>'.$ip.'</td>
8585
</tr>';
8686
}
8787

@@ -93,5 +93,27 @@
9393
<!-- /.box-body -->
9494
</div>
9595
<!-- /.box -->';
96+
?>
97+
98+
<script>
99+
$(document).ready(function() {
100+
var parser = new UAParser();
96101

102+
$('tr').each(function(){
103+
user_agent_cell = $(this).find('.user-agent');
104+
user_agent = user_agent_cell.text();
105+
106+
if (user_agent !== '') {
107+
parser.setUA(user_agent);
108+
device = parser.getResult();
109+
110+
user_agent_cell.html('<strong>' + device.browser.name + '</strong> ' + device.browser.version + ' | <strong>' + device.os.name + '</strong> ' + device.os.version);
111+
112+
console.log(device);
113+
}
114+
})
115+
})
116+
</script>
117+
118+
<?php
97119
include_once App::filepath('include|custom|', 'bottom.php');

‎package.json‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@
4444
"smartwizard": "^4.2.2",
4545
"sweetalert2": "^6.11.4",
4646
"toastr": "^2.1.4",
47-
"tooltipster": "^4.2.5"
47+
"tooltipster": "^4.2.5",
48+
"ua-parser-js": "^1.0.37"
4849
},
4950
"devDependencies": {
5051
"@babel/core": "^7.11.1",

‎src/Auth.php‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ public function attempt($username, $password, $force = false)
168168

169169
// Salvataggio dello stato corrente
170170
$log['stato'] = self::getStatus()[$status]['code'];
171+
$log['user_agent'] = \Filter::getPurifier()->purify($_SERVER['HTTP_USER_AGENT']);
171172
$this->current_status = $status;
172173

173174
// Salvataggio del tentativo nel database

‎update/2_5_1.sql‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
-- Aggiunta user-agent nei log
2+
ALTER TABLE `zz_logs` ADD `user_agent` VARCHAR(255) NULL DEFAULT NULL AFTER `ip`;

0 commit comments

Comments
 (0)