diag_ipsec.php 9.32 KB
Newer Older
Ad Schellevis's avatar
Ad Schellevis committed
1
<?php
2

Ad Schellevis's avatar
Ad Schellevis committed
3
/*
Ad Schellevis's avatar
Ad Schellevis committed
4
    Copyright (C) 2014-2016 Deciso B.V.
5 6 7 8
    Copyright (C) 2004-2009 Scott Ullrich
    Copyright (C) 2008 Shrew Soft Inc <mgrooms@shrew.net>
    Copyright (C) 2003-2004 Manuel Kasper
    All rights reserved.
9

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

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

16 17 18
    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.
19

20 21 22 23 24 25 26 27 28 29
    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
30 31
*/

32
require_once("guiconfig.inc");
33
require_once("services.inc");
Ad Schellevis's avatar
Ad Schellevis committed
34

35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
/**
 * search config for phase 1 description
 * @param string $conn connection string in format conXXX-XX
 * @return string description (or blank if none found)
 */
function ipsec_conn_description($conn)
{
    global $config;
    $ipsec_conn_seq = substr(explode('-', $conn)[0],3);
    if (isset($config['ipsec']['phase1']) && is_array($config['ipsec']['phase1'])) {
        foreach ($config['ipsec']['phase1'] as $phase1) {
            if ($phase1['ikeid'] == $ipsec_conn_seq && !empty($phase1['descr'])) {
                return $phase1['descr'];
            }
        }
    }
    return "";
}

54
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
    if (isset($_POST['action'])) {
        $act = $_POST['action'];
    } else {
        $act = null;
    }
    switch ($act) {
      case 'connect':
          if (!empty($_POST['connid'])) {
              configd_run("ipsec connect ".$_POST['connid']);
          }
          break;
      case 'disconnect':
          if (!empty($_POST['connid'])) {
              configd_run("ipsec disconnect ".$_POST['connid']);
          }
          break;
      default:
          break;
    }

    header("Location: diag_ipsec.php");
    exit(0);
77
}
Ad Schellevis's avatar
Ad Schellevis committed
78

79
$ipsec_status = json_decode(configd_run("ipsec list status"), true);
80 81 82
if ($ipsec_status == null) {
    $ipsec_status = array();
}
83

84
$service_hook = 'ipsec';
Ad Schellevis's avatar
Ad Schellevis committed
85

86
include("head.inc");
87

Ad Schellevis's avatar
Ad Schellevis committed
88
?>
89
<script type="text/javascript">
90 91 92 93 94 95 96
  $( document ).ready(function() {
      // show / hide connection details
      $(".ipsec_info").click(function(event){
          $("#" + $(this).data('target')).toggleClass('hidden visible');
          event.preventDefault();
      });
  });
97
</script>
98
<body>
Ad Schellevis's avatar
Ad Schellevis committed
99

100
<?php include("fbegin.inc"); ?>
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
  <section class="page-content-main">
    <div class="container-fluid">
      <div class="row">
        <?php if (isset($input_errors) && count($input_errors) > 0) print_input_errors($input_errors); ?>
          <section class="col-xs-12">
            <div class="tab-content content-box">
              <div class="table-responsive">
                <table class="table table-striped">
                  <thead>
                  <tr>
                    <th><?= gettext("Connection");?></th>
                    <th class="hidden-xs hidden-sm"><?= gettext("Version");?></th>
                    <th class="hidden-xs"><?= gettext("Local ID");?></th>
                    <th class="hidden-xs"><?= gettext("Local IP");?></th>
                    <th class="hidden-xs"><?= gettext("Remote ID");?></th>
                    <th><?= gettext("Remote IP");?></th>
                    <th class="hidden-xs hidden-sm"><?= gettext("Local Auth");?></th>
                    <th class="hidden-xs hidden-sm"><?= gettext("Remote Auth");?></th>
                    <th><?= gettext("Status");?></th>
                  </tr>
                  </thead>
                  <tbody>
123
                    <?php foreach ($ipsec_status as $ipsec_conn_key => $ipsec_conn):?>
124
                      <tr>
125
                        <td><?=ipsec_conn_description($ipsec_conn_key);?> <small>(<?= $ipsec_conn_key;?>)</small></td>
126 127 128 129 130 131 132 133 134
                        <td class="hidden-xs hidden-sm"><?= $ipsec_conn['version'] ?></td>
                        <td class="hidden-xs"><?= $ipsec_conn['local-id'] ?></td>
                        <td class="hidden-xs"><?= $ipsec_conn['local-addrs'] ?></td>
                        <td class="hidden-xs"><?= $ipsec_conn['remote-id'] ?></td>
                        <td><?= $ipsec_conn['remote-addrs'] ?></td>
                        <td class="hidden-xs hidden-sm"><?= $ipsec_conn['local-class'] ?></td>
                        <td class="hidden-xs hidden-sm"><?= $ipsec_conn['remote-class'] ?></td>
                        <td>
                            <?php if (count($ipsec_conn['sas'])):
135
?>
136 137 138 139 140 141 142 143 144 145 146 147 148
                            <form method="post">
                              <input type="hidden" value="<?=$ipsec_conn_key;?>" name="connid"/>
                              <button type="submit" class="btn btn-xs" name="action" value="disconnect">
                                <span class="glyphicon glyphicon-remove text-default"/>
                              </button>
                              <button type="submit" class="btn btn-xs" name="action" value="connect">
                                  <span class="glyphicon glyphicon-play text-success" title="" alt=""></span>
                              </button>
                              <button type="none" class="btn btn-xs ipsec_info" data-target="info_<?=$ipsec_conn_key?>">
                                  <span class="glyphicon glyphicon-info-sign"></i>
                              </button>
                            </form>
                            <?php else:
149
?>
150 151 152 153 154 155 156
                            <form method="post">
                              <input type="hidden" value="<?=$ipsec_conn_key;?>" name="connid"/>
                              <button type="submit" class="btn btn-xs" name="action" value="connect">
                                <span class="glyphicon glyphicon-play text-warning"/>
                              </button>
                            </form>
                            <?php endif;
157
?>
158 159 160
                        </td>
                      </tr>
                      <?php if (count($ipsec_conn['sas'])):
161
?>
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204
                      <tr>
                        <td colspan="9" class="hidden" id="info_<?=$ipsec_conn_key?>">
                          <table class="table table-condensed">
                            <thead>
                              <tr>
                                <th><?= gettext("Local subnets");?></th>
                                <th class="hidden-xs hidden-sm"><?= gettext("SPI(s)");?></th>
                                <th><?= gettext("Remote subnets");?></th>
                                <th class="hidden-xs hidden-sm"><?= gettext("State");?></th>
                                <th><?= gettext("Stats");?></th>
                              </tr>
                            </head>
                            <tbody>
                            <?php foreach ($ipsec_conn['sas'] as $sa_key => $sa):?>
                              <?php foreach ($sa['child-sas'] as $child_sa_key => $child_sa):?>
                              <tr>
                                <td>
                                  <?= implode('<br/>', $child_sa['local-ts'])?>
                                </td>
                                <td class="hidden-xs hidden-sm">
                                  <?=gettext('in')?> : <?= $child_sa['spi-in'] ?><br/>
                                  <?=gettext('out')?> : <?= $child_sa['spi-out'] ?>
                                </td>
                                <td>
                                  <?= implode('<br/>', $child_sa['remote-ts'])?>
                                </td>
                                <td class="hidden-xs hidden-sm">
                                  <?= $child_sa['state']?>
                                </td>
                                <td>
                                    <small>
                                    <?= gettext('Time');?>  : <?= $child_sa['install-time']?><br/>
                                    <?= gettext('Bytes in');?> : <?= $child_sa['bytes-in']?><br/>
                                    <?= gettext('Bytes out');?> : <?= $child_sa['bytes-out']?>
                                    </small>
                                </td>
                              </tr>
                              <?php endforeach; ?>
                            <?php endforeach; ?>
                            </tbody>
                          </table>
                        </td>
                      </tr>
205
                      <?php endif; ?>
206 207 208 209 210 211 212 213 214
                    <?php endforeach; ?>
                  </tbody>
                </table>
              </div>
            </div>
          </section>
      </div>
    </div>
  </section>
215
<?php include("foot.inc"); ?>