diag_logs_vpn.inc 4.58 KB
Newer Older
Ad Schellevis's avatar
Ad Schellevis committed
1
<?php
2

Ad Schellevis's avatar
Ad Schellevis committed
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
    Copyright (C) 2014-2016 Deciso B.V.
    Copyright (C) 2003-2006 Manuel Kasper <mk@neon1.net>
    All rights reserved.

    Redistribution and use in source and binary forms, with or without
    modification, are permitted provided that the following conditions are met:

    1. Redistributions of source code must retain the above copyright notice,
       this list of conditions and the following disclaimer.

    2. Redistributions in binary form must reproduce the above copyright
       notice, this list of conditions and the following disclaimer in the
       documentation and/or other materials provided with the distribution.

    THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
    INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
    AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
    AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
    OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
    INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
    CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
    ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
    POSSIBILITY OF SUCH DAMAGE.
Ad Schellevis's avatar
Ad Schellevis committed
28 29
*/

30
require_once("guiconfig.inc");
31
require_once("system.inc");
32 33
require_once('services.inc');
require_once('plugins.inc');
34
require_once("interfaces.inc");
Ad Schellevis's avatar
Ad Schellevis committed
35

36
if (empty($config['syslog']['nentries'])) {
37
    $nentries = 50;
38
} else {
39
    $nentries = $config['syslog']['nentries'];
40
}
Ad Schellevis's avatar
Ad Schellevis committed
41 42

if ($_POST['clear']) {
43
    clear_clog($logfile);
Ad Schellevis's avatar
Ad Schellevis committed
44 45
}

46 47
function dump_clog_vpn($logfile, $tail, $logtype)
{
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
    global $config;

    $sor = isset($config['syslog']['reverse']) ? "-r" : "";

    $logarr = "";

    exec("/usr/local/sbin/clog " . escapeshellarg($logfile) . " | tail {$sor} -n " . $tail, $logarr);

    foreach ($logarr as $logent) {
        $logent = preg_split("/\s+/", $logent, 6);
        $llent = explode(",", $logent[5]);
        $iftype = substr($llent[1], 0, 4);
        if ($iftype != $logtype) {
            continue;
        }
        echo "<tr>\n";
        echo "<td class=\"listlr nowrap\">" . htmlspecialchars(join(" ", array_slice($logent, 0, 3))) . "</td>\n";

        if ($llent[0] == "login") {
            echo "<td class=\"listr\"><span class=\"glyphicon glyphicon-arrow-right\" aria-hidden=\"true\" alt=\"in\"></span></td>\n";
        } else {
            echo "<td class=\"listr\"><span class=\"glyphicon glyphicon-arrow-left\" aria-hidden=\"true\" alt=\"out\"></span></td>\n";
        }

        echo "<td class=\"listr\">" . htmlspecialchars($llent[3]) . "</td>\n";
        echo "<td class=\"listr\">" . htmlspecialchars($llent[2]) . "&nbsp;</td>\n";
        echo "</tr>\n";
    }
Ad Schellevis's avatar
Ad Schellevis committed
76 77 78 79
}

include("head.inc");
?>
80 81

<body>
Ad Schellevis's avatar
Ad Schellevis committed
82
<?php include("fbegin.inc"); ?>
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 118 119 120 121 122 123 124 125
<section class="page-content-main">
  <div class="container-fluid">
    <div class="row">
      <section class="col-xs-12">
        <div class="tab-content content-box col-xs-12">
          <div class="table-responsive">
            <table class="table table-striped table-sort">
              <tr>
                <td colspan="4">
                  <ul class="nav nav-pills" role="tablist">
                    <?php foreach ($tab_array as $tab): ?>
                      <li role="presentation" <?php if (str_replace('amp;','', $tab[2]) == $_SERVER['REQUEST_URI']):?>class="active"<?php endif; ?>><a href="<?=$tab[2];?>"><?=$tab[0];?></a></li>
                      <?php endforeach; ?>
                  </ul>
                </td>
              </tr>
               <?php if ($mode != "raw"): ?>
              <tr>
                <td class="listhdrr"><?=gettext("Time");?></td>
                <td class="listhdrr"><?=gettext("Action");?></td>
                <td class="listhdrr"><?=gettext("User");?></td>
                <td class="listhdrr"><?=gettext("IP address");?></td>
              </tr>
              <?php dump_clog_vpn($logfile, $nentries, $logname); ?>
              <?php else:
                dump_clog($logfile, $nentries);
              endif; ?>
              <tr>
                <td colspan="4">
                  <form method="post">
                    <input type="hidden" name="mode" id="mode" value="<?=$mode;?>" />
                    <input name="clear" type="submit" class="btn" value="<?= gettext("Clear log");?>" />
                  </form>
                </td>
              </tr>
            </table>
          </div>
        </div>
      </section>
    </div>
  </div>
</section>
126
<?php include("foot.inc"); ?>