user_routes.html 15.8 KB
Newer Older
1
{% extends "base.html" %}
2 3
{% load i18n %}
{% block extrahead %}
4
<link href="{{STATIC_URL}}b3theme/css/plugins/dataTables/dataTables.bootstrap.css" rel="stylesheet">
5 6 7
{% endblock %}
{% block pagejsbodttom %}

8 9
<script type="text/javascript" src="{{STATIC_URL}}js/jquery.dataTables.js"></script>
<script type="text/javascript" src="{{STATIC_URL}}js/datatables_bootstrap.js"></script>
Leonidas Poulopoulos's avatar
Leonidas Poulopoulos committed
10 11


12 13 14 15 16 17 18 19 20 21
{% endblock %}
{% block title %}{% trans "My rules" %}{% endblock %}
{% block contentplaceholder %}
{% csrf_token %}
    <div class="row">
        <div class="col-md-12">
            <h1 class="page-header">{% trans "My rules" %} </h1>
        </div>
        <!-- /.col-lg-12 -->
    </div>
Leonidas Poulopoulos's avatar
Leonidas Poulopoulos committed
22 23


24 25 26 27 28
<div class="row">
        <div class="col-md-10">
        	<div class="panel panel-primary">
                <div class="panel-heading"> <i class="fa fa-shield"></i> Firewall Rules
                </div>
Leonidas Poulopoulos's avatar
Leonidas Poulopoulos committed
29

30
<div class="panel-body">
31 32


33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 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 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
                    <div class="table-responsive">
                    	<table class="table table-striped table-bordered" id="routes_table">
<thead>
<tr>
	<th>Id</th>
	<th>{% trans "Name" %}</th>
	<th>{% trans "Match" %}</th>
	<th style="text-align: center;">{% trans "Then" %}</th>
	<th style="text-align: center; ">{% trans "Status" %}</th>
	<th style="text-align: center;">{% trans "Applier" %}</th>
	<th style="text-align: center;">{% trans "Expires" %}</th>
	<th style="text-align: center;">{% trans "Response" %}</th>
	<th style="text-align: center;">{% trans "Actions" %}</th>
</tr>
</thead>

<tbody>
</tbody>
</table>
</div></div>
</div></div>


                   <div class="col-md-2">
                	<div class="panel panel-default">
                        <div class="panel-heading">
                            <i class="fa fa-tags"></i> {% trans "Shortcuts" %}
                        </div>
                        <!-- /.panel-heading -->
<div class="panel-body">
				<a class="btn btn-sm btn-outline btn-success" id="routebutton" href="{% url add-route %}"><i class="fa fa-plus-circle"></i> {% trans "Add Rule" %}</a>
				<a class="btn btn-sm btn-outline btn-info"  href="{% url user-profile %}"><i class="fa fa-user"></i> {% trans "My Profile" %}</a>
                        </div>
                        <!-- /.panel-body -->
                    </div>
                    <!-- /.panel -->

                	<div class="chat-panel panel panel-info">
                        <div class="panel-heading">
                            <i class="fa fa-comment fa-fw"></i> Live status
                        </div>
                        <!-- /.panel-heading -->
<div class="panel-body">
	{% include "polldash.html" %}
                        </div>
                        <!-- /.panel-body -->
                    </div>
                    <!-- /.panel -->
                	</div>
</div>


{% endblock %}

{% block pagejsbottom %}
    <script src="{{STATIC_URL}}js/dataTableslatest/jquery.dataTables.min.js"></script>
    <script src="{{STATIC_URL}}js/dataTableslatest/dataTables.bootstrap.js"></script>
    {% if user.is_authenticated %}
<script type="text/javascript" src="{% url load-js 'poller' %}"></script>
{% endif %}

<script type="text/javascript">
var filterbtns = '<div class="btn-group col-centered">\
    <button type="button" class="btn btn-outline btn-sm btn-success" name="status_filter" value="ACTIVE" id="show_active">ACTIVE</button>\
    <button type="button" class="btn btn-outline btn-sm btn-info" name="status_filter" value="PENDING" id="show_pending">PENDING</button>\
    <button type="button" class="btn btn-outline btn-sm btn-warning" name="status_filter" value="ERROR" id="show_error">ERROR</button>\
    <button type="button" class="btn btn-outline btn-sm btn-default" name="status_filter" value="DEACTIVATED" id="show_deactivated">DEACTIVATED</button>\
    </div>';


$.fn.dataTableExt.oApi.fnReloadAjax = function ( oSettings, sNewSource, fnCallback, bStandingRedraw )
104
{
105 106 107 108 109
    // DataTables 1.10 compatibility - if 1.10 then versionCheck exists.
    // 1.10s API has ajax reloading built in, so we use those abilities
    // directly.
    if ( $.fn.dataTable.versionCheck ) {
        var api = new $.fn.dataTable.Api( oSettings );
110

111 112
        if ( sNewSource ) {
            api.ajax.url( sNewSource ).load( fnCallback, !bStandingRedraw );
113
        }
114 115
        else {
            api.ajax.reload( fnCallback, !bStandingRedraw );
116
        }
117
        return;
118
    }
119

120 121 122
    if ( sNewSource !== undefined && sNewSource !== null ) {
        oSettings.sAjaxSource = sNewSource;
    }
123

124 125 126 127 128
    // Server-side processing should just call fnDraw
    if ( oSettings.oFeatures.bServerSide ) {
        this.fnDraw();
        return;
    }
129

130 131 132 133
    this.oApi._fnProcessingDisplay( oSettings, true );
    var that = this;
    var iStart = oSettings._iDisplayStart;
    var aData = [];
134

135
    this.oApi._fnServerParams( oSettings, aData );
136

137 138 139
    oSettings.fnServerData.call( oSettings.oInstance, oSettings.sAjaxSource, aData, function(json) {
        /* Clear the old information from the table */
        that.oApi._fnClearTable( oSettings );
140

141 142 143
        /* Got the data - add it to the table */
        var aData =  (oSettings.sAjaxDataProp !== "") ?
            that.oApi._fnGetObjectDataFn( oSettings.sAjaxDataProp )( json ) : json;
144

145 146 147
        for ( var i=0 ; i<aData.length ; i++ )
        {
            that.oApi._fnAddData( oSettings, aData[i] );
148
        }
149

150
        oSettings.aiDisplay = oSettings.aiDisplayMaster.slice();
151

152
        that.fnDraw();
153

154 155 156 157 158 159
        if ( bStandingRedraw === true )
        {
            oSettings._iDisplayStart = iStart;
            that.oApi._fnCalculateEnd( oSettings );
            that.fnDraw( false );
        }
160

161
        that.oApi._fnProcessingDisplay( oSettings, false );
162

163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178
        /* Callback user function - for event handlers etc */
        if ( typeof fnCallback == 'function' && fnCallback !== null )
        {
            fnCallback( oSettings );
        }
    }, oSettings );
};
var oTable;
var start;
var end;
var oldhtml;
var last_element = false;
var refreshUrl = "{% url group-routes-ajax %}";
$(document).ready( function(){


179

180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195
    oTable = $('#routes_table').dataTable( {
        "bPaginate": true,
        "bFilter": true,
        "bAutoWidth": true,
        "aLengthMenu" : [
            [5, 15, 20, -1],
            [5, 15, 20, "All"]
        ],
        "sDom": "<'row'<'col-xs-4'l><'col-xs-4'<'#filterplaceholder'>><'col-xs-4'f>><'row'<'col-xs-6'i><'col-xs-6'p>>tr<'row'<'col-xs-6'i><'col-xs-6'p>>",
        "iDisplayLength": 20,
        "bProcessing": true,
        "sAjaxSource": refreshUrl,
        "bDeferRender": true,
         "fnInitComplete": function(oSettings, json) {
         	oTable.fnSetColumnVis( 0,false );
         	update_size();
196

197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235
          	$('body').on('click', '.revertbutton', function () {
            	var my = $(this);
            	my.parent().html(oldhtml);
            	last_element = false;
            	return false;
            });
            $('body').on('click', ".del_buttonpre", function(){
            	var my = $(this);
            	if (last_element != false){
            		last_element.html(oldhtml);
            	}
            	oldhtml = my.parent().html();
            	last_element = my.parent();
            	var routename = $(this).data("routename");
				var btn = '<a href="#" data-toggle="tooltip" title="This will deactivate your rule"  data-routename="'+routename+'" class="del_button btn btn-sm btn-warning"> {% trans "Deactivate" %}</a>'
				var back = '<a href="#" class="revertbutton btn btn-sm btn-info"><i class="fa fa-undo"></i></a>';
            	my.parent().html(back+" "+btn);
            	return false;
            });

            $('body').on('click', ".del_button", function(){
            	last_element = false;
            	var my = $(this);
            	my.html('Deactivating...')
				var routename = $(this).data("routename");
				var delurl = "{% url delete-route 'route_placeholder'%}".replace('route_placeholder', routename.toString());
				$.ajax({
        			type: 'POST',
        			url: delurl,
        			cache: false,
        			success: function(data) {
            		 oTable.fnReloadAjax(refreshUrl);
	        		}
	    		});
				return false;
			});
          },
        "aoColumns":[
                     {"mData":"id", "bSearchable": false,"bSortable": false, "bvisible":false},
Stauros Kroustouris's avatar
Stauros Kroustouris committed
236
                     {"mData":"details", "sClass" : "alignCenter","bSearchable": true,"bSortable": true,
237
                     "mRender": function (data, type, full) {
238 239
                        if (full.comments !== null) {
                            if (!full.comments.trim()) {
Stauros Kroustouris's avatar
Stauros Kroustouris committed
240
                               return '<small>' + data + '</small>';
241 242 243 244 245
                            }
                            return '<a rel="tooltip" href="#" data-toggle="tooltip" data-placement="top" title='+full.comments+'><small>'+data+'</small>'
                        } else {
                            return 'No comments'
                        }
246 247 248 249
                     }
                     },
                     {"mData":"match", "sClass" : "alignCenter","bSearchable": true,"bSortable": true,
                     "mRender": function (data, type, full) {
250
                     	return '<small>'+data+'</small>';
251 252 253 254
                     }
                     },
                     {"mData":"then", "sClass" : "alignCenter","bSearchable": true,"bSortable": true,
                     "mRender": function (data, type, full) {
255
                     	return '<small>'+data+'</small>';
256 257 258 259 260 261 262 263 264 265
                     }
                     },
                     {"mData":"status", "sClass" : "alignCenter","bSearchable": true,"bSortable": true,
                     "mRender": function (data, type, full) {
                     	var status = data;
                     	if (status == "EXPIRED" ||status == "ADMININACTIVE" || status == "INACTIVE" || status == "OUTOFSYNC"){
                     		if (status == "EXPIRED" ||status == "ADMININACTIVE" || status == "INACTIVE" ){
                     			return '<span class="label label-default">DEACTIVATED</span>';
                     		}
                     		else
266
                     		{
267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286
                     			if (status == "OUTOFSYNC"){
                     				return '<span class="label label-danger">ERROR</span>';
                     			}
                     			else{
                     				return status;
                     			}
                     		}
                     	}
                     	else{
                     		if (status == 'ACTIVE'){
                     			return '<span class="label label-success">'+status+'</span>';
                     		}
                     		else{
                     			if (status == 'PENDING'){
                     				return '<span class="label label-info">'+status+'</span>';
                     			}
                     			else{
                     				return '<span class="label label-danger">'+status+'</span>';
                     			}
                     		}
287
                     	}
288 289 290 291
                     }
                     },
                     {"mData":"applier", "sClass" : "alignCenter","bSearchable": true,"bSortable": true,
                     "mRender": function (data, type, full) {
292
                     	return '<small>'+data+' ('+full.peer+')</small>';
293 294 295 296
                     }
                     },
                     {"mData":"expires", "sClass" : "alignCenter","bSearchable": true,"bSortable": true,
                     "mRender": function (data, type, full) {
297
                     	return '<small>'+data+'</small>';
298 299 300 301 302
                     }},
                     {"mData":"response", "sClass" : "alignCenter","bSearchable": true,"bSortable": true,
                     "mRender": function (data, type, full) {
                     	status = full.status;
                     	toolt = '<a rel="tooltip" href="#" data-toggle="tooltip" data-placement="top"';
303
   	                     	if (status == "EXPIRED" ||status == "ADMININACTIVE" || status == "INACTIVE" || status == "OUTOFSYNC"){
304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331
	                     		if (status == "INACTIVE" ){
	                     			title = "{% trans 'Deactivated by user' %}";
	                     		}
	                     		if (status == "ADMININACTIVE" ){
	                     			title = "{% trans 'Deactivated by administrator' %}";
	                     		}
	                     		if (status == "EXPIRED" ){
	                     			title = "{% trans 'Deactivated due to expiration' %}";
	                     		}
	                     		if (status == "OUTOFSYNC" ){
	                     			title = "{% trans 'Syncronization error. Configuration in device differs from rule' %}";
	                     		}
	                     		return toolt+" title=\""+title+"\">"+"<small>{% trans 'Rule expired' %}</small>"+"</a>";
	                     	}
                     		if (status == "PENDING"){
                     				return '<img src="{{STATIC_URL}}dots.gif">';
                     			}
                     		return "<small>"+full.response+"</small>";

                     }
                     },
                     {"mData":"comments", "sClass" : "alignCenter","bSearchable": true,"bSortable": true,
                      "mRender": function (data, type, full) {
                     status = full.status;
                     btn = '';
                     editurl = "{% url edit-route 'routename'  %}".replace('routename', full.name.toString());
                     if (status == "ACTIVE" ){
                     	btn = '<a href="'+editurl+'" class="btn-info btn btn-sm btn-outline">{% trans "Edit" %}</a>';
332
        				btn = btn + ' <button class="del_buttonpre btn-warning btn btn-sm btn-outline" id="'+full.name+'" data-routename="'+full.name+'">{% trans "Deactivate" %}</button>';
333 334 335 336 337 338 339 340 341 342 343 344 345
                     }
                     if (status == 'EXPIRED' || status == 'ADMININACTIVE' || status == 'INACTIVE' ){
                     	btn = '<a href="'+editurl+'" class="btn-info btn btn-sm btn-outline" id="edit_button_{{route.pk}}">{% trans "Reactivate" %}</a>';
                     }
                     if (status == "OUTOFSYNC" ){
                     	btn = '<a href="'+editurl+'" class="btn-info btn btn-sm btn-outline" id="edit_button_{{route.pk}}">{% trans "Resync" %}</a>';
                     }
                     if (status == "ERROR" ){
                     	btn = '<a href="'+editurl+'" class="btn-info btn btn-sm btn-outline" id="edit_button_{{route.pk}}">{% trans "Fix it!" %}</a>';
                     }
                     return btn;
                     },
                    }
346

347 348 349 350
         ]
} );
$('#filterplaceholder').html(filterbtns);

351 352


353
    $('body').on('click', 'button[name="status_filter"]', function(){
Leonidas Poulopoulos's avatar
Leonidas Poulopoulos committed
354 355 356 357 358 359
    	var reg_exp = '';
        var checkboxs = document.getElementsByName('status_filter');
        $(this).button('toggle');
        for (var i = 0, inp; inp = checkboxs[i]; i++) {
            if (inp.type.toLowerCase() == 'button' && $(inp).hasClass('active')) {
                reg_exp = reg_exp + inp.value + '|';
360
            }
Leonidas Poulopoulos's avatar
Leonidas Poulopoulos committed
361 362 363 364 365 366
        }
        //passing an empty string will result in no filter
        //thus, it must be set to something that will not exist in the column
        if (reg_exp == '') {
            reg_exp = '|'
        }
367 368
        oTable.fnFilter(reg_exp.slice(0, -1), 4, true, false, false);
        console.log(reg_exp.slice(0, -1))
Leonidas Poulopoulos's avatar
Leonidas Poulopoulos committed
369
        return false;
370
    });
Leonidas Poulopoulos's avatar
Leonidas Poulopoulos committed
371

372 373 374 375
  $(window).resize(function() {
    clearTimeout(window.refresh_size);
    window.refresh_size = setTimeout(function() { update_size(); }, 250);
  });
376

377 378 379 380 381 382 383 384 385 386 387
var update_size = function() {
    $(oTable).css({ width: $(oTable).parent().width() });
    pw=$(oTable).parent().width();
    tw=$(oTable).width();
    if (tw>pw){
		oTable.fnSetColumnVis( 7,false );
		oTable.fnSetColumnVis( 5,false );
    }else{
    	oTable.fnSetColumnVis( 7,true );
    	oTable.fnSetColumnVis( 5,true );
    }
388
    oTable.fnAdjustColumnSizing();
389
  }
390

391 392
$("body").tooltip({ selector: '[data-toggle="tooltip"]' });
});
393
</script>
394
<style type="text/css">
Leonidas Poulopoulos's avatar
Leonidas Poulopoulos committed
395

396

397 398 399 400 401 402 403 404 405 406 407
	.dl-horizontal dt {
    width: 70px;
}
.dl-horizontal dd {
    margin-left: 90px;
}

th{
	font-size: 12px;
}
</style>
408 409

{% endblock %}
410