aboutsummaryrefslogtreecommitdiffstats
path: root/lib/srtgui/templates/cves-select-toastertable.html
blob: eaf8f4f022b3f9a3c4caa6033757011328591447 (plain)
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
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
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
185
186
187
188
189
190
191
192
193
194
195
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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
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
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
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
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
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
{% extends 'base.html' %}
{% load static %}


{% block extraheadcontent %}
  <link rel="stylesheet" href="{% static 'css/jquery-ui.min.css' %}" type='text/css'>
  <link rel="stylesheet" href="{% static 'css/jquery-ui.structure.min.css' %}" type='text/css'>
  <link rel="stylesheet" href="{% static 'css/jquery-ui.theme.min.css' %}" type='text/css'>
  <script src="{% static 'js/jquery-ui.min.js' %}">
  </script>
  <script>
  // Toggle the row checkbox if any column element is clicked
  function toggle_select(toggle_id) {
  	row_check_box = document.getElementById(toggle_id);
  	row_check_box.checked = !row_check_box.checked;
  }
  </script>

  {% if request.user.is_creator %}{% else %}<meta http-equiv="refresh" content="0; url=/" />{% endif %}

  <style>
  /* Style the execution buttons */
  button.execute { height:50px;width:210px;background-color:#4CAF50;text-align:center; border:2px #f69c55;border-radius: 12px; }

  button:disabled {
    cursor: not-allowed;
  }

  /* Define the columns that floats next to each other */
  .column1 {
      float: left;
      width: 280px;
      padding: 10px;
  }
  .column2 {
      float: left;
      width: 150px;
      padding: 10px;
  }

  /* Clear floats after the columns */
  .row:after {
      content: "";
      display: table;
      clear: both;
  }
  </style>

{% endblock %}

{% block title %} Select CVE's - SRTool {% endblock %}

{% block pagecontent %}

  <div class="row">
    <!-- Breadcrumbs -->
  	<div class="col-md-12">
  		<ul class="breadcrumb" id="breadcrumb">
			<li><a href="{% url 'landing' %}">Home</a></li><span class="divider">&rarr;</span>
			<li><a href="{% url 'manage' %}">Management</a></li><span class="divider">&rarr;</span>
			<li><a href="{% url 'triage_cves' %}">Triage CVE's</a></li><span class="divider">&rarr;</span>
			<li>Select CVE's</li>
  		</ul>
  	</div>
  </div>

  <div id="change-vulnerable-state" > <!--class="form-inline" -->
    <b><big>Actions: </big></b>
    <button id="select-these" class="btn btn-default" type="button">Select these</button>
    <button id="unselect-these" class="btn btn-default" type="button">Un-select these</button>
    <button id="select-isvulnerable" class="btn btn-default" type="button">Vulnerable ...</button>
    <button id="select-notvulnerable" class="btn btn-default" type="button">Not vulnerable ...</button>
    <button id="select-investigate" class="btn btn-default" type="button">Investigate ...</button>
    <button id="select-other" class="btn btn-default" type="button">Other ...</button>
  </div>
<!--
  <div id="display-objects-created">
      <p><b><label id="objects-created">Created: </label></b>
  </div>
-->

  <div id="details-isvulnerable" style="display:none;">
  	<p><p>
    <button class="execute" id="submit-isvulnerable"> Submit Vulnerable CVE's </button>
    <div class="row">
      <div class="column1">
        <p><b><label id="products_count">Optional: Add Vulnerable Products (0):</label></b>
        <div id="all-products" class="scrolling" style="width: 250px;">
        {% for product in products %}
    		<div class="checkbox">
    		  <label>
    			<input class="checkbox-products" name="{{product.pk}}" type="checkbox">{{product.long_name}}
    		  </label>
    		  <p>
    		</div>
    	{% endfor %}
        </div>
      </div>
      <div class="column2">
        <p><b><label id="priority">Set Priority:</label></b>

        <div id="priority-list" class="scrolling" style="width: 120px;">
    		<div class="checkbox"> <label>
    			<input type="radio" name="priority" value="4" type="checkbox">  High
            </label><p></div>
    		<div class="checkbox"> <label>
    			<input type="radio" name="priority" value="3" type="checkbox" checked="yes">  Medium
            </label><p></div>
    		<div class="checkbox"> <label>
    			<input type="radio" name="priority" value="2" type="checkbox">  Low
            </label><p></div>
        </div>
      </div>
      <div class="column2">
        <p><b><label id="components">Set Components:</label></b>
        <div id="all-components" class="scrolling" style="width: 150px;">
        {% for component in components %}
    		<div class="checkbox">
    		  <label>
    			<input class="checkbox-components" name="{{component}}" type="checkbox">{{component}}
    			{% if "Userspace" == component %}<hr>{% endif %}
    		  </label>
    		  <p>
    		</div>
    	{% endfor %}
        </div>
      </div>
    </div>

	<p><input id="create_defects" type="checkbox">  Create Defect(s)  </input>
    Reason: <input type="text" id="input-defect-reason" name="defect-reason" size="20" placeholder="(optional)"> (e.g. "Security Advisory [- REASON -] CVE-2020-1234")

    &nbsp;&nbsp;<input id="create_notifications" type="checkbox" checked>&nbsp;Create Notifications</input>
    <p><b><big>Reason: </big></b>
    <input type="text" id="input-isvulnerable-reason" name="reason" size="40">&nbsp;&nbsp;<input id="markPublishIs" type="checkbox">&nbsp;Mark for Publish</input>&nbsp;&nbsp;<input id="markFor" type="checkbox">  Add Keywords to 'For' </input>

	<div id="group_vulnerability" style="border: 1px solid #dddddd; padding: 0 5px; width: 400px; margin-bottom: 10px; margin-top: 0px; " >
		<div class="checkbox"> <label>
			<input type="radio" name="group_vulnerability" value="0" type="checkbox" checked="yes">   Each CVE creates a Vulnerability
		</label><p></div>
		<div class="checkbox"> <label>
			<input type="radio" name="group_vulnerability" value="1" type="checkbox">  Group CVEs into one Vulnerability
		</label><p></div>
		<div class="checkbox"> <label>
			<input type="radio" name="group_vulnerability" value="2" type="checkbox">  Attach CVEs to existing Vulnerability
			<input type="text" id="vulnerability_name" name="vulnerability_name" size="20" style="margin-left: 20px;" placeholder="(Vunerability name)">
		</label>
		<p></div>
	</div>

  </div>

  <div id="details-notvulnerable" style="display:none;">
  	<p><p>
    <button class="execute" id="submit-notvulnerable"> Submit Not-vulnerable CVE's </button>
	<input id="notship" type="checkbox">  "We do not ship ..."  </input>
    <p><b><big>Reason: </big></b>
    <p><input type="text" id="input-notvulnerable-reason" name="reason" size="40">&nbsp;&nbsp;<input id="markPublishNot" type="checkbox">&nbsp;Mark for Publish</input>&nbsp;&nbsp;<input id="markAgainst" type="checkbox">  Add Keywords to 'Against' </input>
  </div>

  <div id="details-investigate" style="display:none;">
  	<p><p>
    <button class="execute" id="submit-investigate"> Submit Investigation CVE's </button>
  </div>

  <div id="details-other" style="display:none;">
  	<p><p>
    <button class="execute" id="submit-other"> Set selected status for CVEs </button>
    <p><i>Status</i> =
    <select name="Status" id="select-status-state">
    <option value="0">Historical</option>
    <option value="1" selected>New</option>
    <option value="2">New-Reserved</option>
    </select>
    <p>
  </div>


  <div class="row">
    <div class="col-md-12">
  	<div class="page-header">
  	  <h1 class="top-air" data-role="page-title"></h1>
  	</div>

    {# xhr_table_url is just the current url so leave it blank #}
    {% url '' as xhr_table_url %}
  	{% include 'toastertable.html' %}
    </div>
  </div>

  <!-- Javascript support -->
  <script>

  //# sourceURL=somename.js

  // global variables
  var selected_isvulnerable=false;
  var selected_notvulnerable=false;
  var selected_investigate=false;
  var selected_other=false;
  var cve_total=0;

  $(document).ready(function() {

    function onCommitAjaxSuccess(data, textstatus) {
      if (window.console && window.console.log) {
        console.log("XHR returned:", data, "(" + textstatus + ")");
      } else {
        alert("NO CONSOLE:\n");
        return;
      }
      if (data.error != "ok") {
        alert("error on request:\n" + data.error);
        return;
      } else if (('created_list' in data) && ("" != data.created_list)) {
        alert(data.created_list);
      }
      // reload the page with the updated tables
      location.reload(true);
    }

    function onCommitAjaxError(jqXHR, textstatus, error) {
      console.log("ERROR:"+error+"|"+textstatus);
      alert("XHR errored1:\n" + error + "\n(" + textstatus + ")");
    }

    /* ensure cookie exists {% csrf_token %} */
    function postCommitAjaxRequest(reqdata) {
	  var ajax = $.ajax({
        type:"POST",
        data: reqdata,
        url:"{% url 'xhr_triage_commit'%}",
        headers: { 'X-CSRFToken': $.cookie("csrftoken")},
        success: onCommitAjaxSuccess,
        error: onCommitAjaxError,
      })
    }

    function update_vulnerable_status() {
      var cve_count = 0;
      var cve_checked_count = 0;
      $('#selectcvetable input').each(function(){
        cve_count = cve_count + 1;
        if ($(this).is(':checked')) {
          cve_checked_count = cve_checked_count + 1;
        }
      });
      if (cve_total > cve_count) {
          document.getElementById("select-these").innerText = "Select "+(cve_count-cve_checked_count)+" unchecked ("+(cve_total-cve_count)+" offpage)";
      } else {
          document.getElementById("select-these").innerText = "Select "+(cve_count-cve_checked_count)+" unchecked";
      }
      document.getElementById("unselect-these").innerText = "Un-select "+cve_checked_count+" checked";
      if (0 == cve_checked_count) {
        //$("#submit-isvulnerable").attr("disabled","disabled");
        document.getElementById("submit-notvulnerable").disabled = true;
        document.getElementById("submit-isvulnerable").disabled = true;
      } else {
        //$("#submit-isvulnerable").removeAttr("disabled");
        document.getElementById("submit-notvulnerable").disabled = false;
        document.getElementById("submit-isvulnerable").disabled = false;
      }
    }

    $('#select-these').click(function(){
      $('#selectcvetable input').each(function(){
        $(this).prop('checked', true);
      });
      update_vulnerable_status();
    });

    $('#unselect-these').click(function(){
      $('#selectcvetable input').each(function(){
        $(this).prop('checked', false);
      });
      update_vulnerable_status();
    });

    // Open IsVulnerable Action
    $('#select-isvulnerable').click(function(){
      if (selected_isvulnerable) {
        selected_isvulnerable=false;
        $("#select-these").removeAttr("disabled");
        $("#unselect-these").removeAttr("disabled");
        $("#select-notvulnerable").removeAttr("disabled");
        $("#select-investigate").removeAttr("disabled");
        $("#select-other").removeAttr("disabled");
	    $("#details-isvulnerable").slideUp();
      } else {
        selected_isvulnerable=true;
        $("#select-these").attr("disabled","disabled");
        $("#unselect-these").attr("disabled","disabled");
        $("#select-notvulnerable").attr("disabled","disabled");
        $("#select-investigate").attr("disabled","disabled");
        $("#select-other").attr("disabled","disabled");
        $("#input-isvulnerable-reason").val($("#search-input-selectcvetable").val())
        update_vulnerable_status();
	    $("#details-isvulnerable").slideDown();
      }
    });

    // Open NotVulnerable Action
    $('#select-notvulnerable').click(function(){
      if (selected_notvulnerable) {
        selected_notvulnerable=false;
        $("#select-these").removeAttr("disabled");
        $("#unselect-these").removeAttr("disabled");
        $("#select-isvulnerable").removeAttr("disabled");
        $("#select-investigate").removeAttr("disabled");
        $("#select-other").removeAttr("disabled");
	    $("#details-notvulnerable").slideUp();
      } else {
        selected_notvulnerable=true;
        $("#select-these").attr("disabled","disabled");
        $("#unselect-these").attr("disabled","disabled");
        $("#select-isvulnerable").attr("disabled","disabled");
        $("#select-investigate").attr("disabled","disabled");
        $("#select-other").attr("disabled","disabled");
        $("#input-notvulnerable-reason").val($("#search-input-selectcvetable").val())
        update_vulnerable_status();
        $("#details-notvulnerable").slideDown();
      }
    });

    // Open Investigate Action
    $('#select-investigate').click(function(){
      if (selected_investigate) {
        selected_investigate=false;
        $("#select-these").removeAttr("disabled");
        $("#unselect-these").removeAttr("disabled");
        $("#select-isvulnerable").removeAttr("disabled");
        $("#select-notvulnerable").removeAttr("disabled");
        $("#select-other").removeAttr("disabled");
	    $("#details-investigate").slideUp();
      } else {
        selected_investigate=true;
        $("#select-these").attr("disabled","disabled");
        $("#unselect-these").attr("disabled","disabled");
        $("#select-isvulnerable").attr("disabled","disabled");
        $("#select-notvulnerable").attr("disabled","disabled");
        $("#select-other").attr("disabled","disabled");
        update_vulnerable_status();
        $("#details-investigate").slideDown();
      }
    });

    // Open Investigate Action
    $('#select-other').click(function(){
      if (selected_other) {
        selected_other=false;
        $("#select-these").removeAttr("disabled");
        $("#unselect-these").removeAttr("disabled");
        $("#select-isvulnerable").removeAttr("disabled");
        $("#select-notvulnerable").removeAttr("disabled");
        $("#select-investigate").removeAttr("disabled");
	    $("#details-other").slideUp();
      } else {
        selected_other=true;
        $("#select-these").attr("disabled","disabled");
        $("#unselect-these").attr("disabled","disabled");
        $("#select-isvulnerable").attr("disabled","disabled");
        $("#select-notvulnerable").attr("disabled","disabled");
        $("#select-investigate").attr("disabled","disabled");
        update_vulnerable_status();
        $("#details-other").slideDown();
      }
    });


    $('#notship').click(function(){
    	not_ship = "We do not ship '";
    	var reason = $("#input-notvulnerable-reason").val().trim();
    	reason = reason.replace(not_ship,'');
    	if ("'" == reason.slice(-1)) {
    		reason = reason.slice(0,-1)
    	}
        if ($('#notship').is(':checked')) {
	    	reason = not_ship + reason + "'";
        }
    	$("#input-notvulnerable-reason").val(reason);
    });

    $('#submit-isvulnerable').click(function(){

      var cve_list=[];
      $('#selectcvetable input:checked').each(function(){
        cve_list.push($(this).attr('name'));
      });
      cve_list = cve_list.join(",");
      if ("" == cve_list) {
        alert("No CVE's were selected");
        return;
      }
      var product_list=[];
      $('#all-products input:checked').each(function(){
        product_list.push($(this).attr('name'));
      });
      product_list = product_list.join(",");
      var component_list=[];
      $('#all-components input:checked').each(function(){
        component_list.push($(this).attr('name'));
      });
      /* components are space delimited */
      component_list = component_list.join(" ");
      var priority=0
      $('#priority-list input:checked').each(function(){
        priority = $(this).attr('value');
      });
      var group_vulnerability=0
      $('#group_vulnerability input:checked').each(function(){
        group_vulnerability = $(this).attr('value');
      });
      postCommitAjaxRequest({
      	"action" : 'submit-isvulnerable',
      	"reason" : $("#input-isvulnerable-reason").val(),
      	"defect_reason" : $("#input-defect-reason").val(),
      	"cves"   : cve_list,
      	"products": product_list,
      	"components": component_list,
      	"priority": priority,
      	"pub"    : $('#markPublishIs').is(':checked') ? "yes" : "no",
      	"for"    : $('#markFor').is(':checked') ? "yes" : "no",
      	"mk_d"   : $('#create_defects').is(':checked') ? "yes" : "no",
      	"vul_group": group_vulnerability,
      	"vul_name": $("#vulnerability_name").val(),
      	"notify" : $('#create_notifications').is(':checked') ? "yes" : "no",
      	});
    });

    $('#submit-notvulnerable').click(function(){
      var cve_list=[];
      $('#selectcvetable input').each(function(){
        if ($(this).is(':checked')) {
          cve_list.push($(this).prop('name'));
        }
      });
      cve_list = cve_list.join(",");
      if ("" == cve_list) {
        alert("No CVE's were selected");
        return;
      }
      postCommitAjaxRequest({
      	"action"  : 'submit-notvulnerable',
      	"reason"  : $("#input-notvulnerable-reason").val(),
      	"cves"    : cve_list,
      	"pub"     : $('#markPublishNot').is(':checked') ? "yes" : "no",
      	"against" : $('#markAgainst').is(':checked') ? "yes" : "no",
      	});
    });

    $('#submit-investigate').click(function(){
      var cve_list=[];
      $('#selectcvetable input').each(function(){
        if ($(this).is(':checked')) {
          cve_list.push($(this).prop('name'));
        }
      });
      cve_list = cve_list.join(",");
      if ("" == cve_list) {
        alert("No CVE's were selected");
        return;
      }
      postCommitAjaxRequest({
      	"action"  : 'submit-investigate',
      	"cves"    : cve_list,
      	});
    });

    $('#submit-other').click(function(){
      var cve_list=[];
      $('#selectcvetable input').each(function(){
        if ($(this).is(':checked')) {
          cve_list.push($(this).prop('name'));
        }
      });
      cve_list = cve_list.join(",");
      if ("" == cve_list) {
        alert("No CVE's were selected");
        return;
      }
      var status=$('#select-status-state').val();
      postCommitAjaxRequest({
      	"action"  : 'submit-other',
      	"cves"    : cve_list,
      	"status"  : status,
      	});
    });

    // When change in product selections, update labels and enables
    $(document).on("change", "#all-products :checkbox", function() {
      update_vulnerable_status();
    });

    // When change in CVE selections, update labels and enables
    $(document).on("change", "#selectcvetable :checkbox", function() {
      update_vulnerable_status();
    });

    // Standard Toaster Table enablement

      var tableElt = $("#{{table_name}}");
      var titleElt = $("[data-role='page-title']");

      tableElt.on("table-done", function (e, total, tableParams) {
        var title = "Triage CVE's";

        if (tableParams.search || tableParams.filter) {
          if (total === 0) {
            title = "No CVE's found";
          }
          else if (total > 0) {
            title = total + " CVE" + (total > 1 ? "'s" : '') + " found";
          }
        }

        titleElt.text(title);
        cve_total = total;
        update_vulnerable_status();

        /* Set the report link */
        var record_list=""
        $(".name > a").each(function(){
          var this_id=$(this).prop('id');
          if (this_id.startsWith("dataid_")) {
            record_list +=this_id.replace(/dataid_/,"") + ",";
          }
        });
        $('#report_link').attr('href',"{% url 'report' request.resolver_match.url_name %}?record_list="+record_list);

      });
    });
  </script>
{% endblock %}