status_lb_vs.php 5.41 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) 2010 Seth Mos <seth.mos@dds.nl>.
    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("filter.inc");
32
require_once("services.inc");
Ad Schellevis's avatar
Ad Schellevis committed
33 34
require_once("vslb.inc");

35 36 37 38
if (empty($config['load_balancer']['lbpool']) || !is_array($config['load_balancer']['lbpool'])) {
    $a_pool = array();
} else {
    $a_pool = &$config['load_balancer']['lbpool'];
Ad Schellevis's avatar
Ad Schellevis committed
39
}
40 41 42 43
if (empty($config['load_balancer']['virtual_server']) || !is_array($config['load_balancer']['virtual_server'])) {
    $a_vs = array();
} else {
    $a_vs = &$config['load_balancer']['virtual_server'];
Ad Schellevis's avatar
Ad Schellevis committed
44
}
45 46 47 48 49 50 51 52 53 54 55

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    if (!empty($_POST['apply'])) {
        relayd_configure();
        filter_configure();
        clear_subsystem_dirty('loadbalancer');
        header("Location: status_lb_vs.php");
        exit;
    }
}

Ad Schellevis's avatar
Ad Schellevis committed
56 57
$rdr_a = get_lb_redirects();

58
$service_hook = 'relayd';
59 60 61
legacy_html_escape_form_data($a_vs);
legacy_html_escape_form_data($a_pool);
legacy_html_escape_form_data($rdr_a);
Ad Schellevis's avatar
Ad Schellevis committed
62 63 64
include("head.inc");

?>
65 66 67

<body>

Ad Schellevis's avatar
Ad Schellevis committed
68 69
<?php include("fbegin.inc"); ?>

70 71 72 73 74 75 76 77
  <section class="page-content-main">
    <div class="container-fluid">
      <div class="row">
        <?php if (is_subsystem_dirty('loadbalancer')): ?><br/>
        <?php print_info_box_apply(sprintf(gettext("The load balancer configuration has been changed%sYou must apply the changes in order for them to take effect."), "<br />"));?>
        <?php endif; ?>
        <section class="col-xs-12">
          <div class="tab-content content-box col-xs-12">
Ad Schellevis's avatar
Ad Schellevis committed
78 79 80 81 82 83 84 85 86 87 88 89
            <div class="table-responsive">
              <table class="table table-striped">
                <thead>
                  <tr>
                    <td><?=gettext("Name"); ?></td>
                    <td><?=gettext("Address"); ?></td>
                    <td><?=gettext("Servers"); ?></td>
                    <td><?=gettext("Status"); ?></td>
                    <td><?=gettext("Description"); ?></td>
                  </tr>
                </thead>
                <tbody>
90
<?php
Ad Schellevis's avatar
Ad Schellevis committed
91 92 93 94 95 96
                $i = 0;
                foreach ($a_vs as $vsent): ?>
                  <tr>
                    <td><?=$vsent['name'];?></td>
                    <td><?=$vsent['ipaddr']." : ".$vsent['port'];?></td>
                    <td>
97
<?php
Ad Schellevis's avatar
Ad Schellevis committed
98 99
                      foreach ($a_pool as $vipent):
                        if ($vipent['name'] == $vsent['poolname']):?>
100

Ad Schellevis's avatar
Ad Schellevis committed
101
                        <?=implode('<br/>',$vipent['servers']);?>
102
<?php
Ad Schellevis's avatar
Ad Schellevis committed
103 104 105
                        endif;
                      endforeach;?>
                    </td>
106
<?php
Ad Schellevis's avatar
Ad Schellevis committed
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
                      switch (trim($rdr_a[$vsent['name']]['status'])) {
                        case 'active':
                          $bgcolor = "#90EE90";  // lightgreen
                          $rdr_a[$vsent['name']]['status'] = "Active";
                          break;
                        case 'down':
                          $bgcolor = "#F08080";  // lightcoral
                          $rdr_a[$vsent['name']]['status'] = "Down";
                          break;
                        default:
                          $bgcolor = "#D3D3D3";  // lightgray
                          $rdr_a[$vsent['name']]['status'] = 'Unknown - relayd not running?';
                      }
                      ?>
                    <td>
                      <table border="0" cellpadding="3" cellspacing="2" summary="status">
                        <tr><td bgcolor="<?=$bgcolor?>"><?=$rdr_a[$vsent['name']]['status']?> </td></tr>
                      </table>
                      <?=!empty($rdr_a[$vsent['name']]['total']) ?  "Total Sessions: {$rdr_a[$vsent['name']]['total']}" : "";?>
                      <?=!empty($rdr_a[$vsent['name']]['last']) ? "<br />Last: {$rdr_a[$vsent['name']]['last']}" : "";?>
                      <?=!empty($rdr_a[$vsent['name']]['average']) ? "<br />Average: {$rdr_a[$vsent['name']]['average']}" : "";?>
                    </td>
                    <td><?=$vsent['descr'];?></td>
                  </tr>
131
<?php
Ad Schellevis's avatar
Ad Schellevis committed
132 133 134 135
                  $i++;
                endforeach; ?>
                </tbody>
              </table>
136 137 138 139 140 141
            </div>
          </div>
        </section>
      </div>
    </div>
  </section>
142
<?php include("foot.inc"); ?>