Subversion Repositories ALCASAR

Rev

Rev 2182 | Rev 2268 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log

<?php
# $Id: admin_log.php 2191 2017-04-28 22:00:32Z tom.houdayer $

$Language = 'en';
if(isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
        $Langue = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']);
        $Language = strtolower(substr(chop($Langue[0]), 0, 2)); 
}

if ($Language === 'fr') {
        $l_title_amdin_log = "Connexion à l'ALCASAR Control Center (ACC)";
} else {
        $l_title_amdin_log = "Connection to ALCASAR Control Center (ACC)";
}

// Read access log
$accessLogs = [];
$accessLogFilename = 'admin_log.txt';
$filePtn = fopen($accessLogFilename, 'r');
if ($filePtn !== false){
        while (!feof($filePtn)) {
                $ligne = fgets($filePtn);
                if (empty($ligne)) {
                        continue;
                }
                $infos = explode('|||', $ligne);
                $accessLogs[] = (object) [
                        'date'     => trim($infos[0]),
                        'username' => trim($infos[1]),
                        'ip'       => trim($infos[2])
                ];
        }
        fclose($filePtn);
}
$accessLogs = array_reverse($accessLogs);

// Remove access before startTime
if (isset($_GET['startTime'])) {
        $startTime = intval($_GET['startTime']);
        foreach ($accessLogs as $key => $access) {
                $timestamp = date_timestamp_get(date_create_from_format('d/m/Y H:i:s', $access->date));
                if ($timestamp < $startTime) {
                        $accessLogs = array_slice($accessLogs, 0, $key);
                        break;
                }
        }
}

?>
<!doctype html>
<html>
<head>
        <meta charset="utf-8">
        <title>Admin Logs</title>
        <link rel="stylesheet" type="text/css" href="../css/bootstrap.min.css">
        <style>
        body {
                background-color: #EFEFEF;
        }
        </style>
        <script src="../js/jquery.min.js"></script>
        <script src="../js/bootstrap.min.js"></script>
</head>
<body>
        <div class="container">
                <center>
                        <h3><?= $l_title_amdin_log ?></h3>
                </center>
                <table class="table table-striped">
                        <thead>
                                <tr>
                                        <th>Date</th>
                                        <th>User</th>
                                        <th>IP address</th>
                                </tr>
                        </thead>
                        <tbody>
                                <?php if (empty($accessLogs)): ?>
                                        <tr>
                                                <td colspan="3"><center>Empty</center></td>
                                        </tr>
                                <?php else: ?>
                                        <?php foreach ($accessLogs as $access): ?>
                                                <tr>
                                                        <td><?= $access->date ?></td>
                                                        <td><?= $access->username ?></td>
                                                        <td><?= $access->ip ?></td>
                                                </tr>
                                        <?php endforeach; ?>
                                <?php endif; ?>
                        </tbody>
                </table>
        </div>
</body>
</html>