1<?php
2
3$no_refresh = true;
4
5$link_array = [
6    'page' => 'device',
7    'device' => $device['device_id'],
8    'tab' => 'nac',
9];
10$pagetitle[] = 'NAC';
11
12//manage the column visibility depending on OS
13$vlan_visibility = ' data-visible="false"';
14$t_elapsed_visibility = ' data-visible="false"';
15$t_left_visibility = ' data-visible="false"';
16$timeout_visibility = ' data-visible="false"';
17$mode_visibility = ' data-visible="false"';
18if ($device['os'] === 'vrp') {
19    $vlan_visibility = '';
20    $t_elapsed_visibility = '';
21} else {
22    $t_left_visibility = '';
23    $timeout_visibility = '';
24    $mode_visibility = '';
25}
26
27?>
28<br/>
29<div class="container-fluid">
30    <div class="panel panel-default">
31        <div class="panel-heading">
32            <h3 class="panel-title">Network Access Controls</h3>
33        </div>
34        <div class="panel-body" style="padding: 15px 0">
35            <table id="nac-grid" data-toggle="bootgrid" class="table table-condensed table-responsive table-striped">
36                <thead>
37                <tr>
38                    <th data-column-id="port_id" data-width="100px">Port</th>
39                    <th data-column-id="mac_address" data-width="150px" data-formatter="tooltip">MAC Address</th>
40<?php
41if (\LibreNMS\Config::get('mac_oui.enabled') === true) {
42    echo '                    <th data-column-id="mac_oui" data-sortable="false" data-width="130px" data-visible="false" data-formatter="tooltip">Vendor</th>';
43}
44?>
45                    <th data-column-id="ip_address" data-width="140px" data-formatter="tooltip">IP Address</th>
46                    <th data-column-id="vlan" data-width="60px" data-formatter="tooltip"<?php echo $vlan_visibility ?>>Vlan</th>
47                    <th data-column-id="domain" data-formatter="nac_domain" data-formatter="tooltip">Domain</th>
48                    <th data-column-id="host_mode"<?php echo $mode_visibility ?>data-formatter="nac_mode">Mode</th>
49                    <th data-column-id="username" data-width="250px" data-formatter="tooltip">Username</th>
50                    <th data-column-id="authz_by" data-visible="false" data-formatter="tooltip">Auth By</th>
51                    <th data-column-id="timeout"<?php echo $timeout_visibility ?> data-formatter="time_interval">Timeout</th>
52                    <th data-column-id="time_elapsed"<?php echo $t_elapsed_visibility ?> data-formatter="time_interval">Elapsed time</th>
53                    <th data-column-id="time_left"<?php echo $t_left_visibility ?> data-formatter="time_interval">Time left</th>
54                    <th data-column-id="authc_status" data-formatter="nac_authc" data-formatter="tooltip">AuthC</th>
55                    <th data-column-id="authz_status" data-width="76px" data-formatter="nac_authz">AuthZ</th>
56                    <th data-column-id="method" data-width="100px" data-formatter="nac_method">Method</th>
57                </tr>
58                </thead>
59            </table>
60        </div>
61    </div>
62</div>
63
64<script type="text/javascript">
65    $('#nac-grid').bootgrid({
66        ajax: true,
67        rowCount: [25, 50, 100, -1],
68        url: "<?php echo url('/ajax/table/port-nac'); ?>",
69        post: function () {
70            return {
71                device_id: <?php echo $device['device_id'] ?>
72            };
73        },
74        formatters: {
75            "time_interval": function (column, row) {
76                var value = row[column.id];
77                var res = humanize_duration(value);
78                var res_light = res.split(' ').slice(0, 2).join(' ');
79                return "<span title=\'" + res.trim() + "\' data-toggle=\'tooltip\'>" + res_light + "</span>";
80            },
81            "tooltip": function (column, row) {
82                var value = row[column.id];
83                var vendor = '';
84                if (column.id == 'mac_address' && ((vendor = row['mac_oui']) != '' )) {
85                    return "<span title=\'" + value + " (" + vendor + ")\' data-toggle=\'tooltip\'>" + value + "</span>";
86                }
87                return "<span title=\'" + value + "\' data-toggle=\'tooltip\'>" + value + "</span>";
88            },
89            "nac_authz": function (column, row) {
90                var value = row[column.id];
91
92                if (value === 'authorizationSuccess' || value === 'sussess') {
93                    //typo in huawei MIB so we must keep sussess
94                    return "<i class=\"fa fa-check-circle fa-lg icon-theme\"  aria-hidden=\"true\" style=\"color:green;\"></i>";
95                } else if (value === 'authorizationFailed') {
96                    return "<i class=\"fa fa-times-circle fa-lg icon-theme\" aria-hidden=\"true\" style=\"color:red;\"></i>";
97                } else {
98                    return "<span class=\'label label-default\' title=\'" + value + "\' data-toggle=\'tooltip\'>" + value + "</span>";
99                }
100            },
101            "nac_domain": function (column, row) {
102                var value = row[column.id];
103                if (value === 'voice') {
104                    return "<i class=\"fa fa-phone fa-lg icon-theme\"  aria-hidden=\"true\"></i>";
105                } else if (value === 'data') {
106                    return "<i class=\"fa fa-desktop fa-lg icon-theme\"  aria-hidden=\"true\"></i>";
107                } else if (value === 'Disabled') {
108                    return "<i class=\"fa fa-desktop fa-lg icon-theme\"  aria-hidden=\"true\"></i>";
109                } else {
110                    return "<span class=\'label label-default\' title=\'" + value + "\' data-toggle=\'tooltip\'>" + value + "</span>";
111                }
112            },
113            "nac_authc": function (column, row) {
114                var value = row[column.id];
115                if (value === 'notRun') {
116                    return "<span class=\"label label-primary\">notRun</span>";
117                } else if (value === 'running') {
118                    return "<span class=\"label label-primary\">running</span>";
119                } else if (value === 'failedOver') {
120                    return "<i class=\"fa fa-times-circle fa-lg icon-theme\"  aria-hidden=\"true\" style=\"color:red;\"></i>";
121                } else if (value === 'authcSuccess') {
122                    return "<i class=\"fa fa-check-circle fa-lg icon-theme\"  aria-hidden=\"true\" style=\"color:green;\">";
123                } else if (value === 'authcFailed') {
124                    return "<i class=\"fa fa-times-circle fa-lg icon-theme\"  aria-hidden=\"true\" style=\"color:red;\"></i>";
125                } else if (value === '6') {
126                    return "<i class=\"fa fa-times-circle fa-lg icon-theme\"  aria-hidden=\"true\" style=\"color:red;\"></i>";
127                } else {
128                    return "<span class=\'label label-default\' title=\'" + value + "\' data-toggle=\'tooltip\'>" + value + "</span>";
129                }
130            },
131            "nac_method": function (column, row) {
132                var value = row[column.id];
133                if (value === 'dot1x') {
134                    return "<span class=\"label label-success\">802.1x</span>";
135                } else if (value === 'macAuthBypass') {
136                    return "<span class=\"label label-primary\">MAB</span>";
137                } else if (value === 'other') {
138                    return "<span class=\"label label-danger\">Disabled</span>";
139                } else {
140                    return "<span class=\'label label-default\' title=\'" + value + "\' data-toggle=\'tooltip\'>" + value + "</span>";
141                }
142            }
143        }
144    });
145</script>
146