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