index.volt 23.7 KB
Newer Older
1 2 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 28 29 30 31
{#

OPNsense® is Copyright © 2014 – 2015 by Deciso B.V.
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.

#}

<script type="text/javascript">

    $( document ).ready(function() {
32 33 34
        //
        var data_get_map = {'frm_GeneralSettings':"/api/ids/settings/get"};

35 36 37 38 39 40 41 42
        /**
         * update service status
         */
        function updateStatus() {
            ajaxCall(url="/api/ids/service/status", sendData={}, callback=function(data,status) {
                updateServiceStatusUI(data['status']);
            });
        }
43

44 45 46
        /**
         * list all known classtypes and add to selection box
         */
47 48 49
        function updateRuleClassTypes() {
            ajaxGet(url="/api/ids/settings/listRuleClasstypes",sendData={}, callback=function(data, status) {
                if (status == "success") {
50
                    $('#ruleclass').html('<option value="">ALL</option>');
51 52 53 54 55 56 57 58 59 60 61 62
                    $.each(data['items'], function(key, value) {
                        $('#ruleclass').append($("<option></option>").attr("value",value).text(value));
                    });
                    $('.selectpicker').selectpicker('refresh');
                    // link on change event
                    $('#ruleclass').on('change', function(){
                        $('#grid-installedrules').bootgrid('reload');
                    });
                }
            });
        }

63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
        /**
         * update list of available alert logs
         */
        function updateAlertLogs() {
            ajaxGet(url="/api/ids/service/getAlertLogs",sendData={}, callback=function(data, status) {
                if (status == "success") {
                    $('#alert-logfile').html("");
                    $.each(data, function(key, value) {
                        if (value['sequence'] == undefined) {
                            $('#alert-logfile').append($("<option></option>").attr("value",'none').text(value['modified']));
                        } else {
                            $('#alert-logfile').append($("<option></option>").attr("value",value['sequence']).text(value['modified']));
                        }
                    });
                    $('.selectpicker').selectpicker('refresh');
                    // link on change event
                    $('#alert-logfile').on('change', function(){
                        $('#grid-alerts').bootgrid('reload');
                    });
                }
            });
        }
85 86 87 88 89

        /**
         * Add classtype to rule filter
         */
        function addRuleFilters(request) {
90 91 92 93 94 95 96
            var selected =$('#ruleclass').find("option:selected").val();
            if ( selected != "") {
                request['classtype'] = selected;
            }
            return request;
        }

97
        /**
98
         *  add filter criteria to log query
99 100
         */
        function addAlertQryFilters(request) {
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
            var selected_logfile =$('#alert-logfile').find("option:selected").val();
            var selected_max_entries =$('#alert-logfile-max').find("option:selected").val();
            var search_phrase = $("#inputSearchAlerts").val();

            // add loading overlay
            $('#processing-dialog').modal('show');
            $("#grid-alerts").bootgrid().on("loaded.rs.jquery.bootgrid", function (e){
                $('#processing-dialog').modal('hide');
            });


            if ( selected_logfile != "") {
                request['fileid'] = selected_logfile;
                request['rowCount'] = selected_max_entries;
                request['searchPhrase'] = search_phrase;
116 117 118 119
            }
            return request;
        }

120
        // load initial data
121 122 123 124 125 126 127 128 129 130 131
        function loadGeneralSettings() {
            mapDataToFormUI(data_get_map).done(function(data){
                // set schedule updates link to cron
                $.each(data.frm_GeneralSettings.ids.general.UpdateCron, function(key, value) {
                    if (value.selected == 1) {
                        $("#scheduled_updates").attr("href","/ui/cron/item/open/"+key);
                        $("#scheduled_updates").show();
                    }
                });
                formatTokenizersUI();
                $('.selectpicker').selectpicker('refresh');
132
            });
133
        }
134

135 136
        /**
         * save (general) settings and reconfigure
137
         * @param  callback_funct: callback function, receives result status true/false
138
         */
139 140
        function actionReconfigure(callback_funct) {
            var result_status = false;
141 142
            saveFormToEndpoint(url="/api/ids/settings/set",formid='frm_GeneralSettings',callback_ok=function(){
                ajaxCall(url="/api/ids/service/reconfigure", sendData={}, callback=function(data,status) {
143 144
                    if (status == "success" || data['status'].toLowerCase().trim() == "ok") {
                        result_status = true;
145
                    }
146
                    callback_funct(result_status);
147 148 149 150
                });
            });
        }

151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184
        /**
         * toggle selected items
         * @param gridId: grid id to to use
         * @param url: ajax action to call
         * @param state: 0/1/undefined
         * @param combine: number of keys to combine (seperate with ,)
         *                 try to avoid too much items per call (results in too long url's)
         */
        function actionToggleSelected(gridId, url, state, combine) {
            var rows =$("#"+gridId).bootgrid('getSelectedRows');
            if (rows != undefined){
                var deferreds = [];
                if (state != undefined) {
                    var url_suffix = state;
                } else {
                    var url_suffix = "";
                }

                var keyset = [];
                $.each(rows, function(key,uuid){
                    keyset.push(uuid);
                    if ( combine == undefined || keyset.length > combine) {
                        deferreds.push(ajaxCall(url + keyset.join(',') +'/'+url_suffix, sendData={},null));
                        keyset = [];
                    }
                });

                // flush remaining items
                if (keyset.length > 0) {
                    deferreds.push(ajaxCall(url + keyset.join(',') +'/'+url_suffix, sendData={},null));
                }

                // refresh when all toggles are executed
                $.when.apply(null, deferreds).done(function(){
185
                    $("#"+gridId).bootgrid("refresh");
186 187 188 189
                });
            }
        }

190 191 192
        /*************************************************************************************************************
         * UI load grids (on tab change)
         *************************************************************************************************************/
193

194
        /**
195
         * load content on tab changes
196
         */
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214
        $('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
            if (e.target.id == 'rule_tab'){
                //
                // activate rule tab page
                //

                // delay refresh for a bit
                setTimeout(updateRuleClassTypes, 500);

                /**
                 * grid installed rules
                 */
                $('#grid-installedrules').bootgrid('destroy'); // always destroy previous grid, so data is always fresh
                $("#grid-installedrules").UIBootgrid(
                        {   search:'/api/ids/settings/searchinstalledrules',
                            get:'/api/ids/settings/getRuleInfo/',
                            options:{
                                requestHandler:addRuleFilters,
215
                                rowCount:[10, 25, 50,100,500,1000] ,
216 217
                                formatters:{
                                    rowtoggle: function (column, row) {
218
                                        var toggle = " <button type=\"button\" class=\"btn btn-xs btn-default command-edit\" data-row-id=\"" + row.sid + "\"><span class=\"fa fa-info-circle\"></span></button> ";
219
                                        if (parseInt(row[column.id], 2) == 1) {
220
                                            toggle += "&nbsp; <span style=\"cursor: pointer;\" class=\"fa fa-check-square-o command-toggle\" data-value=\"1\" data-row-id=\"" + row.sid + "\"></span>";
221
                                        } else {
222
                                            toggle += "&nbsp; <span style=\"cursor: pointer;\" class=\"fa fa-square-o command-toggle\" data-value=\"0\" data-row-id=\"" + row.sid + "\"></span>";
223 224 225
                                        }
                                        return toggle;
                                    }
226
                                }
227 228
                            },
                            toggle:'/api/ids/settings/toggleRule/'
229
                        }
230 231 232 233 234 235 236 237 238 239 240 241 242
                );
            } else if (e.target.id == 'alert_tab') {
                updateAlertLogs();
                /**
                 * grid query alerts
                 */
                $('#grid-alerts').bootgrid('destroy'); // always destroy previous grid, so data is always fresh
                $("#grid-alerts").UIBootgrid(
                        {   search:'/api/ids/service/queryAlerts',
                            get:'/api/ids/service/getAlertInfo/',
                            options:{
                                multiSelect:false,
                                selection:false,
243 244 245
                                templates : {
                                    header: ""
                                },
246 247 248
                                requestHandler:addAlertQryFilters,
                                formatters:{
                                    info: function (column, row) {
249
                                        return "<button type=\"button\" class=\"btn btn-xs btn-default command-edit\" data-row-id=\"" + row.filepos + "/" + row.fileid + "\"><span class=\"fa fa-info-circle\"></span></button> ";
250
                                    }
251
                                },
252
                            }
253 254 255 256 257
                        });
            }
        })


258

259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279
        /**
         * grid for installable rule files
         */
        $("#grid-rule-files").UIBootgrid(
                {   search:'/api/ids/settings/listInstallableRulesets',
                    toggle:'/api/ids/settings/toggleInstalledRuleset/',
                    options:{
                        navigation:0,
                        formatters:{
                            rowtoggle: function (column, row) {
                                if (parseInt(row[column.id], 2) == 1) {
                                    var toggle = "<span style=\"cursor: pointer;\" class=\"fa fa-check-square-o command-toggle\" data-value=\"1\" data-row-id=\"" + row.filename + "\"></span>";
                                } else {
                                    var toggle = "<span style=\"cursor: pointer;\" class=\"fa fa-square-o command-toggle\" data-value=\"0\" data-row-id=\"" + row.filename + "\"></span>";
                                }
                                return toggle;
                            }
                        }
                    }
                });

280
        /*************************************************************************************************************
281
         * UI button Commands
282 283 284 285 286 287
         *************************************************************************************************************/

        /**
         * save settings and reconfigure ids
         */
        $("#reconfigureAct").click(function(){
288 289 290 291 292 293 294 295 296 297 298 299 300 301 302
            $("#reconfigureAct_progress").addClass("fa fa-spinner fa-pulse");
            actionReconfigure(function(status){
                // when done, disable progress animation.
                $("#reconfigureAct_progress").removeClass("fa fa-spinner fa-pulse");
                updateStatus();

                if (!status) {
                    BootstrapDialog.show({
                        type: BootstrapDialog.TYPE_WARNING,
                        title: "Error reconfiguring IDS",
                        message: data['status'],
                        draggable: true
                    });
                }
            });
303
        });
304

305 306 307 308 309 310 311 312
        /**
         * update rule definitions
         */
        $("#updateRulesAct").click(function(){
            $("#updateRulesAct_progress").addClass("fa fa-spinner fa-pulse");
            ajaxCall(url="/api/ids/service/updateRules", sendData={}, callback=function(data,status) {
                // when done, disable progress animation and reload grid.
                $('#grid-rule-files').bootgrid('reload');
313
                updateStatus();
314 315
                if ($('#scheduled_updates').is(':hidden') ){
                    // save and reconfigure on initial download (tries to create a cron job)
316 317 318 319 320 321
                    actionReconfigure(function(status){
                        loadGeneralSettings();
                        $("#updateRulesAct_progress").removeClass("fa fa-spinner fa-pulse");
                    });
                } else {
                    $("#updateRulesAct_progress").removeClass("fa fa-spinner fa-pulse");
322
                }
323 324 325
            });
        });

326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361
        /**
         * disable selected rulesets
         */
        $("#disableSelectedRuleSets").click(function(){
            var gridId = 'grid-rule-files';
            var url = '/api/ids/settings/toggleInstalledRuleset/';
            actionToggleSelected(gridId, url, 0, 20);
        });

        /**
         * enable selected rulesets
         */
        $("#enableSelectedRuleSets").click(function(){
            var gridId = 'grid-rule-files';
            var url = '/api/ids/settings/toggleInstalledRuleset/';
            actionToggleSelected(gridId, url, 1, 20);
        });

        /**
         * disable selected rules
         */
        $("#disableSelectedRules").click(function(){
            var gridId = 'grid-installedrules';
            var url = '/api/ids/settings/toggleRule/';
            actionToggleSelected(gridId, url, 0, 100);
        });

        /**
         * enable selected rules
         */
        $("#enableSelectedRules").click(function(){
            var gridId = 'grid-installedrules';
            var url = '/api/ids/settings/toggleRule/';
            actionToggleSelected(gridId, url, 1, 100);
        });

362 363 364 365 366 367 368
        /**
         * link query alerts button.
         */
        $("#actQueryAlerts").click(function(){
            $('#grid-alerts').bootgrid('reload');
        });

369 370 371 372 373
        /**
         * Initialize
         */
        loadGeneralSettings();
        updateStatus();
374

375 376 377 378 379 380
    });


</script>

<ul class="nav nav-tabs" data-tabs="tabs" id="maintabs">
381 382 383
    <li class="active"><a data-toggle="tab" href="#settings" id="settings_tab">{{ lang._('Settings') }}</a></li>
    <li><a data-toggle="tab" href="#rules" id="rule_tab">{{ lang._('Rules') }}</a></li>
    <li><a data-toggle="tab" href="#alerts" id="alert_tab">{{ lang._('Alerts') }}</a></li>
384
    <li><a href="" id="scheduled_updates" style="display:none">{{ lang._('Schedule') }}</a></li>
385 386
</ul>
<div class="tab-content content-box tab-content">
387 388
    <div id="settings" class="tab-pane fade in active">
        {{ partial("layout_partials/base_form",['fields':formGeneralSettings,'id':'frm_GeneralSettings'])}}
389 390 391 392 393 394 395 396 397 398
        <!-- add installable rule files -->
        <table class="table table-striped table-condensed table-responsive">
            <colgroup>
                <col class="col-md-3"/>
                <col class="col-md-9"/>
            </colgroup>
            <tbody>
            <tr>
                <td><div class="control-label">
                    <i class="fa fa-info-circle text-muted"></i>
399
                    <b>{{ lang._('rulesets') }}</b>
400 401 402 403 404 405
                    </div>
                </td>
                <td>
                <table id="grid-rule-files" class="table table-condensed table-hover table-striped table-responsive" data-editDialog="DialogRule">
                    <thead>
                    <tr>
406
                        <th data-column-id="filename" data-type="string" data-visible="false" data-identifier="true">filename</th>
407 408
                        <th data-column-id="description" data-type="string" data-sortable="false"  data-visible="true">{{ lang._('Description') }}</th>
                        <th data-column-id="modified_local" data-type="string" data-sortable="false"  data-visible="true">{{ lang._('Last updated') }}</th>
409
                        <th data-column-id="enabled" data-formatter="rowtoggle" data-sortable="false"  data-width="10em">{{ lang._('Enabled') }}</th>
410 411 412 413
                    </tr>
                    </thead>
                    <tbody>
                    </tbody>
414 415 416 417 418 419 420 421 422
                    <tfoot>
                    <tr>
                        <td></td>
                        <td>
                            <button title="{{ lang._('disable selected') }}" id="disableSelectedRuleSets" type="button" class="btn btn-xs btn-default"><span class="fa fa-square-o command-toggle"></span></button>
                            <button title="{{ lang._('enable selected') }}" id="enableSelectedRuleSets" type="button" class="btn btn-xs btn-default"><span class="fa fa-check-square-o command-toggle"></span></button>
                        </td>
                    </tr>
                    </tfoot>
423 424 425 426 427
                </table>
                </td>
            </tr>
            </tbody>
        </table>
428 429
    </div>
    <div id="rules" class="tab-pane fade in">
430 431 432 433
        <div class="bootgrid-header container-fluid">
            <div class="row">
                <div class="col-sm-12 actionBar">
                    <b>Classtype &nbsp;</b>
434
                    <select id="ruleclass" class="selectpicker" data-width="200px"></select>
435 436 437 438 439
                </div>
            </div>
        </div>

        <!-- tab page "installed rules" -->
440
        <table id="grid-installedrules" class="table table-condensed table-hover table-striped table-responsive" data-editDialog="DialogRule">
441 442
            <thead>
            <tr>
443
                <th data-column-id="sid" data-type="numeric" data-visible="true" data-identifier="true" data-width="6em">{{ lang._('sid') }}</th>
444 445 446 447
                <th data-column-id="source" data-type="string">{{ lang._('Source') }}</th>
                <th data-column-id="classtype" data-type="string">{{ lang._('ClassType') }}</th>
                <th data-column-id="msg" data-type="string">{{ lang._('Message') }}</th>
                <th data-column-id="enabled" data-formatter="rowtoggle" data-sortable="false"  data-width="10em">{{ lang._('Info / enabled') }}</th>
448 449 450 451
            </tr>
            </thead>
            <tbody>
            </tbody>
452 453 454 455 456 457
            <tfoot>
            <tr>
                <td>
                    <button title="{{ lang._('disable selected') }}" id="disableSelectedRules" type="button" class="btn btn-xs btn-default"><span class="fa fa-square-o command-toggle"></span></button>
                    <button title="{{ lang._('enable selected') }}" id="enableSelectedRules" type="button" class="btn btn-xs btn-default"><span class="fa fa-check-square-o command-toggle"></span></button>
                </td>
458
                <td></td>
459 460
            </tr>
            </tfoot>
461
        </table>
462
    </div>
463
    <div id="alerts" class="tab-pane fade in">
464 465 466 467
        <div class="bootgrid-header container-fluid">
            <div class="row">
                <div class="col-sm-12 actionBar">
                    <select id="alert-logfile" class="selectpicker" data-width="200px"></select>
468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484
                    <select id="alert-logfile-max" class="selectpicker" data-width="80px">
                        <option value="5">5</option>
                        <option value="6">6</option>
                        <option value="7">7</option>
                        <option value="50">50</option>
                        <option value="100">100</option>
                        <option value="250">250</option>
                        <option value="500">500</option>
                        <option value="1000">1000</option>
                        <option value="-1">All</option>
                    </select>
                    <div class="search form-group">
                        <div class="input-group">
                            <input class="search-field form-control" placeholder="{{ lang._('Search') }}" type="text" id="inputSearchAlerts">
                            <span  id="actQueryAlerts" class="icon input-group-addon fa fa-refresh" title="{{ lang._('Query') }}" style="cursor: pointer;"></span>
                        </div>
                    </div>
485 486 487 488
                </div>
            </div>
        </div>
        <!-- tab page "alerts" -->
489 490 491
        <table id="grid-alerts" class="table table-condensed table-hover table-striped table-responsive" data-editDialog="DialogAlert">
            <thead>
            <tr>
492 493 494 495 496
                <th data-column-id="timestamp" data-type="string" data-sortable="false">{{ lang._('Timestamp') }}</th>
                <th data-column-id="src_ip" data-type="string" data-sortable="false"  data-width="10em">{{ lang._('Source') }}</th>
                <th data-column-id="dest_ip" data-type="string"  data-sortable="false"  data-width="10em">{{ lang._('Destination') }}</th>
                <th data-column-id="alert" data-type="string" data-sortable="false" >{{ lang._('Alert') }}</th>
                <th data-column-id="info" data-formatter="info" data-sortable="false" data-width="4em">{{ lang._('Info') }}</th>
497 498 499 500 501 502
            </tr>
            </thead>
            <tbody>
            </tbody>
        </table>
    </div>
503 504
    <div class="col-md-12">
        <hr/>
505 506 507 508
        <button class="btn btn-primary"  id="reconfigureAct" type="button"><b>{{ lang._('Apply') }}</b><i id="reconfigureAct_progress" class=""></i></button>
        <button class="btn btn-primary"  id="updateRulesAct" type="button"><b>{{ lang._('Download & Update Rules') }}</b><i id="updateRulesAct_progress" class=""></i></button>
        <br/>
        <i>{{ lang._('Please use "Download & Update Rules" to fetch your initial ruleset, automatic updating can be scheduled after the first download') }} </i>
509 510
    </div>
</div>
511

512 513 514 515 516 517 518 519 520 521 522 523 524 525
<!-- Static Modal -->
<div class="modal modal-static fade" id="processing-dialog" role="dialog" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-body">
                <div class="text-center">
                    <i class="fa fa-spinner fa-pulse fa-5x"></i>
                    <h4>{{ lang._('Processing request...') }} </h4>
                </div>
            </div>
        </div>
    </div>
</div>

526
{{ partial("layout_partials/base_dialog",['fields':formDialogRule,'id':'DialogRule','label':'Rule details','hasSaveBtn':'false','msgzone_width':1])}}
527
{{ partial("layout_partials/base_dialog",['fields':formDialogAlert,'id':'DialogAlert','label':'Alert details','hasSaveBtn':'false','msgzone_width':1])}}