-
Notifications
You must be signed in to change notification settings - Fork 69
/
log.php
executable file
·117 lines (99 loc) · 3.87 KB
/
log.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
<?php
/*
* OpenSTAManager: il software gestionale open source per l'assistenza tecnica e la fatturazione
* Copyright (C) DevCode s.r.l.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
use Carbon\Carbon;
include_once __DIR__.'/core.php';
$pageTitle = tr('Log');
include_once App::filepath('include|custom|', 'top.php');
echo '
<div class="card">
<div class="card-header">
<h3 class="card-title"><i class="fa fa-book"></i> '.tr('Ultimi 100 accessi').'</h3>
</div>
<!-- /.card-header -->
<div class="card-body table-responsive no-padding">
<table class="datatables table table-hover">
<thead>
<tr>
<th width="200">'.tr('Username').'</th>
<th width="150">'.tr('Data').'</th>
<th width="100">'.tr('Indirizzo IP').'</th>
<th>'.tr('Dispositivo').'</th>
<th width="180">'.tr('Stato').'</th>
</tr>
</thead>
<tbody>';
/*
LEGGO DALLA TABELLA ZZ_LOG
*/
if (Auth::admin()) {
$q = 'SELECT * FROM `zz_logs` ORDER BY `created_at` DESC LIMIT 0, 100';
} else {
$q = 'SELECT * FROM `zz_logs` WHERE `id_utente`='.prepare(Auth::user()['id']).' ORDER BY `created_at` DESC LIMIT 0, 100';
}
$logs = $dbo->fetchArray($q);
foreach ($logs as $log) {
$timestamp = Translator::timestampToLocale($log['created_at']);
$status = Auth::getStatus();
if ($log['stato'] == $status['success']['code']) {
$type = 'success';
$stato = $status['success']['message'];
} elseif ($log['stato'] == $status['disabled']['code']) {
$type = 'warning';
$stato = $status['disabled']['message'];
} elseif ($log['stato'] == $status['unauthorized']['code']) {
$type = 'warning';
$stato = $status['unauthorized']['message'];
} else {
$type = 'danger';
$stato = $status['failed']['message'];
}
$created_at = new Carbon($log['created_at']);
echo '
<tr class="'.$type.'">
<td>'.$log['username'].'</td>
<td class="tip" title="'.$created_at->format('d/m/Y H:i:s').'">'.$created_at->diffForHumans().'</td>
<td>'.$log['ip'].'</td>
<td class="user-agent tip" title="'.strip_tags($log['user_agent'] ?: '').'">'.$log['user_agent'].'</td>
<td><span class="badge badge-'.$type.'">'.$stato.'</span></td>
</tr>';
}
echo '
</tbody>
</table>
</div>
<!-- /.card-body -->
</div>
<!-- /.card -->';
?>
<script>
$(document).ready(function() {
var parser = new UAParser();
$('tr').each(function(){
user_agent_cell = $(this).find('.user-agent');
user_agent = user_agent_cell.text();
if (user_agent !== '') {
parser.setUA(user_agent);
device = parser.getResult();
user_agent_cell.html('<strong>' + (device.browser.name || '') + '</strong> ' + (device.browser.version || '') + ' | <strong>' + (device.os.name || '') + '</strong> ' + (device.os.version || ''));
}
})
})
</script>
<?php
include_once App::filepath('include|custom|', 'bottom.php');