openstamanager/log.php

120 lines
3.9 KiB
PHP
Raw Normal View History

<?php
2020-09-07 15:04:06 +02:00
/*
* OpenSTAManager: il software gestionale open source per l'assistenza tecnica e la fatturazione
2021-01-20 15:08:51 +01:00
* Copyright (C) DevCode s.r.l.
2020-09-07 15:04:06 +02:00
*
* 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/>.
*/
2024-04-01 23:09:37 +02:00
use Carbon\Carbon;
include_once __DIR__.'/core.php';
$pageTitle = tr('Log');
2018-06-26 09:41:43 +02:00
include_once App::filepath('include|custom|', 'top.php');
echo '
<div class="box">
<div class="box-header">
<h3 class="box-title"><i class="fa fa-book"></i> '.tr('Ultimi 100 accessi').'</h3>
</div>
<!-- /.box-header -->
<div class="box-body table-responsive no-padding">
<table class="datatables table table-hover">
<thead>
<tr>
2024-04-01 23:09:37 +02:00
<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';
}
2024-04-01 23:09:37 +02:00
$logs = $dbo->fetchArray($q);
2024-04-01 23:09:37 +02:00
foreach ($logs as $log) {
$timestamp = Translator::timestampToLocale($log['created_at']);
$status = Auth::getStatus();
2024-04-01 23:09:37 +02:00
if ($log['stato'] == $status['success']['code']) {
$type = 'success';
$stato = $status['success']['message'];
2024-04-01 23:09:37 +02:00
} elseif ($log['stato'] == $status['disabled']['code']) {
$type = 'warning';
$stato = $status['disabled']['message'];
2024-04-01 23:09:37 +02:00
} elseif ($log['stato'] == $status['unauthorized']['code']) {
$type = 'warning';
$stato = $status['unauthorized']['message'];
} else {
$type = 'danger';
$stato = $status['failed']['message'];
}
2024-04-01 23:09:37 +02:00
$created_at = new Carbon($log['created_at']);
echo '
<tr class="'.$type.'">
2024-04-01 23:09:37 +02:00
<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="label label-'.$type.'">'.$stato.'</span></td>
</tr>';
}
echo '
</tbody>
</table>
</div>
<!-- /.box-body -->
</div>
<!-- /.box -->';
2024-04-01 23:09:37 +02:00
?>
<script>
$(document).ready(function() {
var parser = new UAParser();
2024-04-01 23:09:37 +02:00
$('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);
console.log(device);
}
})
})
</script>
<?php
2018-06-26 09:41:43 +02:00
include_once App::filepath('include|custom|', 'bottom.php');