Fix issue with ports not updating. Implement selects with select2.js lib
[flowspy] / templates / apply.html
1 {% extends "b3theme/base.html" %}
2 {% load widget_tweaks %}
3 {% load i18n %}
4
5 {% block title %}
6         {% if edit %}
7                 {% trans "Edit Rule" %} {{form.data.name}}
8         {% else %}
9                 {% trans "Create new Rule" %}
10         {% endif %}
11 {% endblock %}
12
13 {% block breadcrumbs %}
14  <li class="active"><span class="divider">/</span>
15         {% if edit %}
16                 {% trans "Edit rule" %} {{form.data.name}}
17         {% else %}
18         {% trans "Create rule" %}
19         {% endif %}
20 </li>
21 {% endblock %}
22 {% block extrahead %}
23     <link href="{{STATIC_URL}}b3theme/css/plugins/morris/morris-0.4.3.min.css" rel="stylesheet">
24     <link href="{{STATIC_URL}}b3theme/css/plugins/timeline/timeline.css" rel="stylesheet">
25     <link href="{{STATIC_URL}}datepicker/css/datepicker.css" rel="stylesheet">
26    
27 {% endblock %}
28
29 {% block extraheadbottom %}
30 <style type="text/css">
31
32
33
34 #rule_form_container input:not([type="submit"]), #rule_form_container select {
35     background: none repeat scroll 0 0 #FFFFFF;
36     border: 1px solid #DDDDDD;
37         -moz-border-radius: 3px; border-radius:3px; -webkit-border-radius: 3px; 
38     float: left;
39     font-family: "Century Gothic",Helvetica,sans-serif;
40     font-size: 13px;
41     outline: medium none;
42     padding: 5px;
43     width: 180px;
44 }
45
46
47 #rule_form_container{
48         -moz-border-radius: 10px 10px 10px 10px; border-radius:10px; -webkit-border-radius: 10px;
49         -moz-box-shadow: 0 0 3px #AAAAAA; box-shadow: 0 0 3px #AAAAAA; -webkit-box-shadow: 0 0 3px #AAAAAA; 
50         background-color: #F9F9F9;
51         border: 2px solid #FFFFFF;
52         overflow: hidden;
53     width: 800px;
54         }
55 #rule_form_container div label {
56     color: #666666;
57     float: left;
58     font-family: "Century Gothic",Helvetica,sans-serif;
59     font-size: 15px;
60     font-weight: bold;
61     line-height: 26px;
62     margin-right: 15px;
63     text-align: right;
64     text-shadow: 1px 1px 1px #FFFFFF;
65     width: 180px;
66 }
67 #rule_form_container p.submit {
68     background: none repeat scroll 0 0 transparent;
69     border: medium none;
70     box-shadow: none;
71 }
72
73 .errorlist{
74         list-style: none outside none;
75 }
76
77 </style>
78  <link href="{{STATIC_URL}}js/select2/select2.css" rel="stylesheet">
79  <link href="{{STATIC_URL}}js/select2/select2-bootstrap.css" rel="stylesheet">
80 {% endblock %}
81
82 {% block pagejsbottom %}
83 <script type="text/javascript" src="{{STATIC_URL}}datepicker/js/bootstrap-datepicker.js"></script>
84 <script type="text/javascript" src="{{STATIC_URL}}js/select2/select2.js"></script>
85 <script>
86         $(document).ready( function(){
87                 $('#id_then').removeAttr("multiple");
88                 $("#id_protocol").select2();
89                 $("#id_fragmenttype").select2();
90                 $("#id_then").select2();
91                 
92                 reArrangeSelect("id_sourceport");
93                 $("#id_sourceport").select2({
94                         placeholder: "Source Port(s)"
95                 });
96                 reArrangeSelect("id_destinationport");
97                 $("#id_destinationport").select2({
98                         placeholder: "Destination Port(s)"
99                 });
100                 reArrangeSelect("id_port");
101                 $("#id_port").select2({
102                         placeholder: "Port(s)"
103                 });
104                 $('#id_expires').datepicker({
105                         startDate: '+1d',
106                         endDate: '+10d'
107                 });
108                 $('#setFromAll').click(function(){
109                         $("#id_source").val('0.0.0.0/0');
110                 });
111                 
112                 
113                 /*$('#id_then').attr("multiple", "");*/
114                 /*
115                 $( "#id_expires" ).datepicker({ dateFormat: 'yy-mm-dd' , maxDate: '+10d', minDate: '+1d', changeMonth: false, changeYear: false }).datepicker( $.datepicker.regional[ "el" ] );
116                 */
117                 {% comment %}
118                 $('#then_diag').dialog({
119                         height: 220,
120             width: 340,
121                         modal: true,
122                         autoOpen: false,
123                         buttons: {
124                 '{% trans "Add" %}': function() {
125                         $.ajax({
126                         url:"{% url add-rate-limit %}", 
127                         data:$("#add_rl_form").serialize(),
128                         type: "POST",
129                         cache: false,
130                         success:function(data){
131                                         try {
132                                                 value = data.pk;
133                                                 text = data.value;
134                                                 $('#id_then').append($("<option></option>").attr("value",value).text(text));
135                                                 $('#then_diag').dialog('close');
136                                         }
137                                         catch (exception) {
138                                                 $('#then_diag').html(data);
139                                         }                                       
140                                 }
141                                 });
142                 },
143                 '{% trans "Cancel" %}': function() {
144                         $('#then_diag').dialog('close');
145                 }
146         }
147                 });
148                 {% endcomment %}
149
150                 {% comment %}
151                 $("#new_then_actions").button({
152             icons: {
153                 primary: "ui-icon-plusthick"
154             },
155                         })
156                         .click(function(){
157                                 $.ajax({
158                                         url: "{% url add-rate-limit %}",
159                                         cache: false,
160                                         success: function(data){
161                                                 $("#then_diag").html(data);
162                                         }
163                                 });
164                                 $('#then_diag').dialog('open');
165                                 return false;
166                         });
167                         
168                         {% endcomment %}
169                         $(".new_port").click(function(){
170                                 $(".new_port").hide();
171                                 $("#addnewport").show()
172                                 $.ajax({
173                                         url: "{% url add-port %}",
174                                         cache: false,
175                                         success: function(data){
176                                                 $("#port_diag").html(data);
177                                         }
178                                 });
179                                 // $('#port_diag').dialog('open');
180                                 return false;
181                         });
182                         
183                         function reArrangeSelect(elementId) {
184                            $("#"+elementId).html($("#"+elementId+" option").sort(function(a, b) {
185                                 return parseInt(a.text) == parseInt(b.text) ? 0 : parseInt(a.text) < parseInt(b.text) ? -1 : 1
186                         }));
187                         }
188         });
189                 
190 </script>
191 {% endblock %}
192 {% block contentplaceholder %}
193
194             <div class="row">
195                 <div class="col-lg-12">
196                     <h1 class="page-header"> {% if edit %}{% trans "Edit rule" %}: {{form.data.name}}
197     {% else %}{% trans "Apply for a new rule" %}
198     {% endif %}</h1>
199                 </div>
200                 <!-- /.col-lg-12 -->
201             </div>
202
203 <div class="row">
204                 <div class="col-lg-8">
205                         <div class="panel panel-primary">
206                         <div class="panel-heading">
207                             <i class="fa fa-shield fa-fw"></i> Firewall Rule
208                         </div>
209                         <!-- /.panel-heading -->
210                         <div class="panel-body">
211     <form method="POST" role="form" class="form-horizontal">     
212         
213             {% csrf_token %}
214             {% load unescape %}
215             {% if form.non_field_errors %}
216             <div class="form-group {% if form.non_field_errors %} has-error {% endif %}" style="color: #A94442;">
217                 {{ form.non_field_errors|unescape}}
218                 </div>
219             {% endif %}
220             <fieldset {%  if edit %}  style="display:none;" {%  endif %}>
221                
222                  <div class="form-group {% if form.name.errors %} has-error {% endif %}">
223         <label for="id_name" class="col-md-2 control-label"><b>{% trans "Name" %}</b></label>
224         <div class="col-md-8">
225             {% render_field form.name class+="form-control" placeholder="Eg. ntpattack. A unique identifier will be added as a suffix" %}
226             {% if form.name.errors %} <span class="help-block"> {{ form.name.errors|join:", " }} </span>
227             {% endif %}
228         </div>
229         </div>
230             </fieldset>
231             {% if user.is_superuser %}
232             <fieldset>
233                 <hr>
234                    <div class="form-group {% if form.applier.errors %} has-error {% endif %}">
235                         <label for="id_name" class="col-md-2 control-label"><b>{% trans "Applier" %}</b></label>
236                         <div class="col-md-8">
237                             {% render_field form.applier class+="form-control" %}
238                             {% if form.applier.errors %} <span class="help-block"> {{ form.applier.errors|join:", " }} </span>
239                             {% endif %}
240                         </div>
241                         </div>
242                 </fieldset>
243                 {% else %}
244                  <input type="hidden" id="id_applier" name="applier" value="{{applier}}"/>
245                 {% endif %}
246             <fieldset>
247                 <hr>
248                 <div class="form-group {% if form.source.errors %} has-error {% endif %}"> 
249                         <label for="id_source" class="col-md-2 control-label"><b>{% trans "Source Address" %}</b></label>
250                         <div class="col-md-6">
251                             {% render_field form.source class+="form-control" placeholder=form.source.help_text %}
252                             {% if form.source.errors %} <span class="help-block"> {{ form.source.errors|join:", " }} </span>
253                             {% endif %}
254                         </div>
255                         <div class="col-md-2">
256                             <img src="{{STATIC_URL}}threat_source.png" style="height: 30px;"/> &nbsp;&nbsp;<button type="button" class="btn btn-md btn-info btn-outline" id="setFromAll">Any</button>
257                         </div>
258                         </div>
259                         
260                                 <div class="form-group {% if form.destination.errors %} has-error {% endif %}"> 
261                         <label for="id_destination" class="col-md-2 control-label"><b>{% trans "Destination Address" %}</b></label>
262                         <div class="col-md-6">
263                             {% render_field form.destination class+="form-control" placeholder=form.destination.help_text %}
264                             {% if form.destination.errors %} <span class="help-block"> {{ form.destination.errors|join:", " }} </span>
265                             {% endif %}
266                         </div>
267                         <div class="col-md-2">
268                             <img src="{{STATIC_URL}}secure_destination.png" style="height: 30px;"/>
269                         </div>
270                         </div>
271                         
272                                 <div class="form-group {% if form.protocol.errors %} has-error {% endif %}"> 
273                         <label for="id_protocol" class="col-md-2 control-label" style="font-weight: normal;">{% trans "Protocol(s)" %}</label>
274                         <div class="col-md-8">
275                             {% render_field form.protocol class+="form-control" %}
276                             {% if form.protocol.errors %} <span class="help-block"> {{ form.protocol.errors|join:", " }} </span>
277                             {% endif %}
278                         </div>
279                         </div>
280                         
281                         <div class="form-group {% if form.fragmenttype.errors %} has-error {% endif %}"> 
282                         <label for="id_fragmenttype" class="col-md-2 control-label" style="font-weight: normal;">{% trans "Fragment Type" %}</label>
283                         <div class="col-md-8">
284                             {% render_field form.fragmenttype class+="form-control" %}
285                             {% if form.fragmenttype.errors %} <span class="help-block"> {{ form.fragmenttype.errors|join:", " }} </span>
286                             {% endif %}
287                         </div>
288                         </div>
289                         </fieldset>
290                         <!--  PORTS -->
291                         <fieldset>
292                 <hr>
293                         <div class="form-group ">
294                                 <label class="col-md-10" style="font-weight: normal;"><small>{% trans "Select source/destination port(s), or select common port(s) for both source/destination" %}. {{ form.sourceport.help_text }}</small></label>
295                         </div>
296                         <div class="form-group {% if form.sourceport.errors %} has-error {% endif %} {% if form.destinationport.errors %} has-error {% endif %} {% if form.port.errors %} has-error {% endif %}"> 
297                         <label for="id_sourceport" class="col-md-2 control-label" style="font-weight: normal;">{% trans "Src. Port(s)" %}</label>
298                         <div class="col-md-2">
299                             {% render_field form.sourceport class+="form-control"  %}
300                             {% if form.sourceport.errors %} <span class="help-block"> {{ form.sourceport.errors|join:", " }} </span>
301                             {% endif %}
302                         </div>
303                                 <label for="id_destinationport" class="col-md-1 control-label" style="font-weight: normal;">{% trans "Dest. Port(s)" %}</label>
304                         <div class="col-md-2">
305                             {% render_field form.destinationport class+="form-control"  %}
306                             {% if form.destinationport.errors %} <span class="help-block"> {{ form.destinationport.errors|join:", " }} </span>
307                             {% endif %}
308                         </div>
309                         <label for="id_port" class="col-md-1 control-label" style="font-weight: normal;">{% trans "Port(s)" %}</label>
310                         <div class="col-md-2">
311                             {% render_field form.port class+="form-control"  %}
312                             {% if form.port.errors %} <span class="help-block"> {{ form.port.errors|join:", " }} </span>
313                             {% endif %}
314                         </div>
315                         </div>
316                                 <div class="form-group ">
317                                 <label class="col-md-2" style="font-weight: normal;"></label>
318                                 <div class="col-md-8">
319                                         <button class="new_port btn-info btn btn-md btn-outline" type="button">{% trans "Add Port" %}</button>
320                                 </div>
321                         </div>
322                         <div class="form-group " id="addnewport" style="display:none">
323                                 <label class="col-md-2  control-label" style="font-weight: normal;">{% trans "Add New Port" %}</label>
324                                 <div class="col-md-8">
325                                         <div id="port_diag" title="{% trans "Add new port" %}">
326                                 </div>
327                         </div>
328                                 </fieldset>
329                         
330                         <!--  END OF PORTS -->
331                 
332             <fieldset>
333                                 <hr>
334                 
335                 <div class="form-group {% if form.then.errors %} has-error {% endif %}"> 
336                         <label for="id_then" class="col-md-2 control-label">{% trans "Then Actions" %}</label>
337                         <div class="col-md-8">
338                             {% render_field form.then class+="form-control" %}
339                             {% if form.then.errors %} <span class="help-block"> {{ form.then.errors|join:", " }} </span>
340                             {% endif %}
341                         </div>
342                         </div>
343                 
344             </fieldset>
345             <fieldset>
346                                 <hr>
347                 <div class="form-group {% if form.expires.errors %} has-error {% endif %}"> 
348                         <label for="id_then" class="col-md-2 control-label">{% trans "Expires" %}</label>
349                         <div class="col-md-8">
350                             {% render_field form.expires class+="form-control datepicker" data-date-format="yyyy-mm-dd"  %}
351                             {% if form.expires.errors %} <span class="help-block"> {{ form.expires.errors|join:", " }} </span>
352                             {% endif %}
353                         </div>
354                         </div>
355             </fieldset>
356             
357             
358             <fieldset>
359                         <hr>
360                 
361                                 <div class="form-group {% if form.comments.errors %} has-error {% endif %}"> 
362                         <label for="id_comments" class="col-md-2 control-label">{% trans "Comments" %}</label>
363                         <div class="col-md-8">
364                             {% render_field form.comments class+="form-control" placeholder="Give a short description of the intended use of this rule, that justifies the parameter selection above. Feel free to include any additional comments." %}
365                             {% if form.comments.errors %} <span class="help-block"> {{ form.comments.errors|join:", " }} </span>
366                             {% endif %}
367                         </div>
368                         </div>
369
370             
371             </fieldset>
372                          <div class="form-group">
373                                 <div class="col-md-2"></div>
374                                  <div class="col-md-8">
375                         <button type="submit" id="applybutton" value="{% trans 'Apply' %}" class="btn btn-md btn-primary">Apply</button>
376                                 </div>
377                         </div>
378                 
379
380     </form>
381 </div></div></div></div>
382 <div id="then_diag" title="Add new rate-limit value">
383 </div>
384 <!-- <div id="port_diag" title="{% trans "Add new port" %}">
385 </div> -->
386
387 {% endblock %}