mirror of
https://github.com/devcode-it/openstamanager.git
synced 2025-02-16 19:40:44 +01:00
Aggiunta user-agent nei log di accesso
This commit is contained in:
parent
3d85b76a93
commit
317884b8ea
@ -122,7 +122,8 @@ const JS = gulp.parallel(() => {
|
|||||||
'bootstrap-maxlength/dist/bootstrap-maxlength.js',
|
'bootstrap-maxlength/dist/bootstrap-maxlength.js',
|
||||||
'leaflet/dist/leaflet.js',
|
'leaflet/dist/leaflet.js',
|
||||||
'leaflet-gesture-handling/dist/leaflet-gesture-handling.min.js',
|
'leaflet-gesture-handling/dist/leaflet-gesture-handling.min.js',
|
||||||
'ismobilejs/dist/isMobile.min.js'
|
'ismobilejs/dist/isMobile.min.js',
|
||||||
|
'ua-parser-js/dist/ua-parser.min.js',
|
||||||
];
|
];
|
||||||
|
|
||||||
for (const i in vendor) {
|
for (const i in vendor) {
|
||||||
|
60
log.php
60
log.php
@ -17,6 +17,8 @@
|
|||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
use Carbon\Carbon;
|
||||||
|
|
||||||
include_once __DIR__.'/core.php';
|
include_once __DIR__.'/core.php';
|
||||||
|
|
||||||
$pageTitle = tr('Log');
|
$pageTitle = tr('Log');
|
||||||
@ -34,10 +36,11 @@ echo '
|
|||||||
<table class="datatables table table-hover">
|
<table class="datatables table table-hover">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th>'.tr('Username').'</th>
|
<th width="200">'.tr('Username').'</th>
|
||||||
<th>'.tr('Data').'</th>
|
<th width="150">'.tr('Data').'</th>
|
||||||
<th>'.tr('Stato').'</th>
|
<th width="100">'.tr('Indirizzo IP').'</th>
|
||||||
<th>'.tr('Indirizzo IP').'</th>
|
<th>'.tr('Dispositivo').'</th>
|
||||||
|
<th width="180">'.tr('Stato').'</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>';
|
<tbody>';
|
||||||
@ -50,25 +53,19 @@ if (Auth::admin()) {
|
|||||||
} else {
|
} else {
|
||||||
$q = 'SELECT * FROM `zz_logs` WHERE `id_utente`='.prepare(Auth::user()['id']).' ORDER BY `created_at` DESC LIMIT 0, 100';
|
$q = 'SELECT * FROM `zz_logs` WHERE `id_utente`='.prepare(Auth::user()['id']).' ORDER BY `created_at` DESC LIMIT 0, 100';
|
||||||
}
|
}
|
||||||
$rs = $dbo->fetchArray($q);
|
$logs = $dbo->fetchArray($q);
|
||||||
$n = sizeof($rs);
|
|
||||||
|
|
||||||
for ($i = 0; $i < $n; ++$i) {
|
foreach ($logs as $log) {
|
||||||
$id = $rs[$i]['id'];
|
$timestamp = Translator::timestampToLocale($log['created_at']);
|
||||||
$id_utente = $rs[$i]['id_utente'];
|
|
||||||
$username = $rs[$i]['username'];
|
|
||||||
$ip = $rs[$i]['ip'];
|
|
||||||
|
|
||||||
$timestamp = Translator::timestampToLocale($rs[$i]['created_at']);
|
|
||||||
|
|
||||||
$status = Auth::getStatus();
|
$status = Auth::getStatus();
|
||||||
if ($rs[$i]['stato'] == $status['success']['code']) {
|
if ($log['stato'] == $status['success']['code']) {
|
||||||
$type = 'success';
|
$type = 'success';
|
||||||
$stato = $status['success']['message'];
|
$stato = $status['success']['message'];
|
||||||
} elseif ($rs[$i]['stato'] == $status['disabled']['code']) {
|
} elseif ($log['stato'] == $status['disabled']['code']) {
|
||||||
$type = 'warning';
|
$type = 'warning';
|
||||||
$stato = $status['disabled']['message'];
|
$stato = $status['disabled']['message'];
|
||||||
} elseif ($rs[$i]['stato'] == $status['unauthorized']['code']) {
|
} elseif ($log['stato'] == $status['unauthorized']['code']) {
|
||||||
$type = 'warning';
|
$type = 'warning';
|
||||||
$stato = $status['unauthorized']['message'];
|
$stato = $status['unauthorized']['message'];
|
||||||
} else {
|
} else {
|
||||||
@ -76,12 +73,15 @@ for ($i = 0; $i < $n; ++$i) {
|
|||||||
$stato = $status['failed']['message'];
|
$stato = $status['failed']['message'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$created_at = new Carbon($log['created_at']);
|
||||||
|
|
||||||
echo '
|
echo '
|
||||||
<tr class="'.$type.'">
|
<tr class="'.$type.'">
|
||||||
<td>'.$username.'</td>
|
<td>'.$log['username'].'</td>
|
||||||
<td>'.$timestamp.'</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>
|
<td><span class="label label-'.$type.'">'.$stato.'</span></td>
|
||||||
<td>'.$ip.'</td>
|
|
||||||
</tr>';
|
</tr>';
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -93,5 +93,27 @@ echo '
|
|||||||
<!-- /.box-body -->
|
<!-- /.box-body -->
|
||||||
</div>
|
</div>
|
||||||
<!-- /.box -->';
|
<!-- /.box -->';
|
||||||
|
?>
|
||||||
|
|
||||||
|
<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);
|
||||||
|
|
||||||
|
console.log(device);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<?php
|
||||||
include_once App::filepath('include|custom|', 'bottom.php');
|
include_once App::filepath('include|custom|', 'bottom.php');
|
||||||
|
@ -44,7 +44,8 @@
|
|||||||
"smartwizard": "^4.2.2",
|
"smartwizard": "^4.2.2",
|
||||||
"sweetalert2": "^6.11.4",
|
"sweetalert2": "^6.11.4",
|
||||||
"toastr": "^2.1.4",
|
"toastr": "^2.1.4",
|
||||||
"tooltipster": "^4.2.5"
|
"tooltipster": "^4.2.5",
|
||||||
|
"ua-parser-js": "^1.0.37"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@babel/core": "^7.11.1",
|
"@babel/core": "^7.11.1",
|
||||||
|
@ -168,6 +168,7 @@ class Auth extends Util\Singleton
|
|||||||
|
|
||||||
// Salvataggio dello stato corrente
|
// Salvataggio dello stato corrente
|
||||||
$log['stato'] = self::getStatus()[$status]['code'];
|
$log['stato'] = self::getStatus()[$status]['code'];
|
||||||
|
$log['user_agent'] = \Filter::getPurifier()->purify($_SERVER['HTTP_USER_AGENT']);
|
||||||
$this->current_status = $status;
|
$this->current_status = $status;
|
||||||
|
|
||||||
// Salvataggio del tentativo nel database
|
// Salvataggio del tentativo nel database
|
||||||
|
2
update/2_5_1.sql
Normal file
2
update/2_5_1.sql
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
-- Aggiunta user-agent nei log
|
||||||
|
ALTER TABLE `zz_logs` ADD `user_agent` VARCHAR(255) NULL DEFAULT NULL AFTER `ip`;
|
Loading…
x
Reference in New Issue
Block a user