forked from GhostManager/Ghostwriter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
base_generic.html
751 lines (679 loc) · 32.3 KB
/
base_generic.html
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
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
{% load static i18n compress custom_tags %}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>{% block title %}Ghostwriter{% endblock %}</title>
<!-- Load Static Files -->
<link rel="shortcut icon" href="{% static 'favicon.ico' %}"/>
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="{% static 'css/bootstrap.min.css' %}"/>
<!-- Font Awesome -->
<link rel="stylesheet" href="{% static 'css/fontawesome/all.css' %}"/>
<!-- jQuery JS -->
<script src="{% static 'js/jquery-3.6.1.min.js' %}"></script>
<script src="{% static 'js/jquery-ui.js' %}"></script>
<script src="{% static 'js/popper.min.js' %}"></script>
<script src="{% static 'js/bootstrap.min.js' %}"></script>
<!-- Sugar Parser -->
<script src="{% static 'js/sugar.min.js' %}"></script>
<!-- jQuery Tablesorter Plugin -->
<script type="text/javascript" src="{% static 'js/jquery.tablesorter.js' %}"></script>
<script type="text/javascript" src="{% static 'js/jquery.tablesorter.widgets.js' %}"></script>
<script type="text/javascript" src="{% static 'js/parser-date-range.min.js' %}"></script>
<script type="text/javascript" src="{% static 'js/parser-date.js' %}"></script>
<!-- SortableJS for Drag n Drop -->
<script src="{% static 'js/Sortable.min.js' %}"></script>
<!-- Toastr -->
<link rel="stylesheet" type="text/css" href="{% static 'css/toastr.min.css' %}">
<script type="text/javascript" src="{% static 'js/toastr.min.js' %}"></script>
<!-- TinyMCE -->
<script src="{% static 'js/tinymce/tinymce.min.js' %}"></script>
<!-- Ghostwriter JS & CSS -->
<script src="{% static 'js/project.js' %}"></script>
<link rel="stylesheet" href="{% static 'css/styles.css' %}"/>
<!-- TinyMCE -->
<script type="application/javascript" src="{% static 'js/tinymce/config.js' %}"></script>
<!-- FullCalendar -->
<script src="{% static 'js/fullcalendar-main.min.js' %}"></script>
<script src="{% static 'js/fullcalendar-locales-all.min.js' %}"></script>
<link rel="stylesheet" type="text/css" href="{% static 'css/fullcalendar-main.min.css' %}">
<!-- ClipboardJS -->
<script src="{% static 'js/clipboard.min.js' %}"></script>
<!-- Textarea Autoresize -->
<script src="{% static 'js/jquery.textarea_autosize.js' %}"></script>
<!-- CVSS JS & CSS -->
<!--
Copyright (c) 2019, FIRST.ORG, INC.
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.
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote
products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "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 COPYRIGHT HOLDER OR CONTRIBUTORS 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.
-->
<link rel="stylesheet" href="{% static 'css/cvss_styles.css' %}">
<script src="{% static 'js/cvsscalc30.js' %}"></script>
<script src="{% static 'js/cvsscalc30_ui.js' %}"></script>
</head>
<body>
<div class="wrapper">
<!-- Sidebar Holder -->
{% if user.is_authenticated %}
<nav id="sidebar" class="{% if request.session.sidebar.sticky %}active{% endif %}">
<!-- Sidebar Top Section -->
<div class="sidebar-header col d-flex align-items-center justify-content-center">
<a href="{% url 'home:dashboard' %}">
<img src="{% static 'images/all_white_header.png' %}" alt="Ghostwriter">
</a>
<div class="sidebar-header-tab">
<div class="square">
<i
class="sidebar-toggle-btn fas fa-angle-double-right {% if request.session.sidebar.sticky %}fa-flip-horizontal{% endif %}"></i>
</div>
</div>
</div>
<div class="sidebar-body">
<!-- Project Shortcut Section -->
<ul class="list-unstyled components">
<p class="sideheader icon icon home-icon">Project Shortcuts</p>
<a
{% if request.session.active_report.id and request.session.active_report.title %}
class="btn btn-primary mb-3 col-10 active-report-shortcut icon ext-link-icon"
href="{% url 'reporting:report_detail' request.session.active_report.id %}"
>Jump to Report
{% else %}
class="btn btn-primary col-10 active-report-shortcut icon ext-link-icon btn-disabled"
href="#"
>Select Report Below
{% endif %}
</a>
<!-- Menu Section -->
<li>
<a href="#activeReportsSubmenu" data-toggle="collapse" aria-expanded="false"
class="dropdown-toggle sidebar-dropdown-toggle" data-target="#activeReportsSubmenu">
My Active Reports
<div class="expand_caret caret"></div>
</a>
<ul class="collapse list-unstyled text-left" id="activeReportsSubmenu">
{% get_reports request as reports %}
{% if reports %}
{% for report in reports %}
<li>
<a title="Set this report as your active report"
class="js-activate-report icon toggle-off-icon
{% if request.session.active_report.id and request.session.active_report.title and request.session.active_report.id == report.id %}
selected-report
{% endif %}
" activate-report-csrftoken="{{ csrf_token }}"
activate-report-url="{% url 'reporting:ajax_activate_report' report.id %}"
activate-report-id="{{ report.id }}">
{{ report.title }}</a>
</li>
{% endfor %}
{% else %}
<li><a href="{% url 'reporting:reports' %}">You have no active reports; click to visit the library.</a>
</li>
{% endif %}
</ul>
</li>
<li>
<a href="#activeProjectsSubmenu" data-toggle="collapse" aria-expanded="false"
class="dropdown-toggle sidebar-dropdown-toggle" data-target="#activeProjectsSubmenu">
My Active Projects
<div class="expand_caret caret"></div>
</a>
<ul class="collapse list-unstyled text-left" id="activeProjectsSubmenu">
{% if request.user.projectassignment_set.all %}
{% for assignment in request.user.projectassignment_set.all %}
{% if not assignment.project.complete %}
<li><a href="{% url 'rolodex:project_detail' assignment.project.id %}">{{ assignment.project }}</a>
</li>
{% endif %}
{% endfor %}
{% else %}
<li><a href="{% url 'rolodex:projects' %}">You have no assignments; click to visit the library.</a></li>
{% endif %}
</ul>
</li>
</ul>
<!-- Rolodex Section -->
<ul class="list-unstyled components">
<p class="sideheader icon icon tasks-icon">Pre-engagement</p>
<!-- Menu Section -->
<li>
<a href="#clientSubmenu" data-toggle="collapse" aria-expanded="false"
class="dropdown-toggle sidebar-dropdown-toggle" data-target="#clientSubmenu">
Clients
<div class="expand_caret caret"></div>
</a>
<ul class="collapse list-unstyled text-left" id="clientSubmenu">
{% comment %} Search for Clients {% endcomment %}
<form class="px-6 py-2" action="{% url 'rolodex:clients' %}" method="GET">
<input type="search" autocomplete="off" class="form-control" id="client-search" name="name"
placeholder="Search Clients..." autofocus="autofocus">
</form>
{% comment %} Clients Submenu Items {% endcomment %}
<li><a class="icon list-icon" href="{% url 'rolodex:clients' %}">Client Library</a></li>
{% if request.user|is_privileged %}
<li><a class="icon plus-icon" href="{% url 'rolodex:client_create' %}">Add New Client</a></li>
{% endif %}
</ul>
</li>
<li>
<a href="#findingsSubmenu" data-toggle="collapse" aria-expanded="false"
class="dropdown-toggle sidebar-dropdown-toggle">Findings</a>
<ul class="collapse list-unstyled text-left" id="findingsSubmenu">
{% comment %} Search for Findings {% endcomment %}
<form class="px-6 py-2" action="{% url 'reporting:findings' %}" method="GET">
<input type="search" autocomplete="off" class="form-control" id="finding-search" name="title"
placeholder="Search Findings..." autofocus="autofocus">
</form>
{% comment %} Findings Submenu Items {% endcomment %}
<li><a class="icon list-icon" href="{% url 'reporting:findings' %}">Finding Library</a></li>
{% if request.user|can_create_finding %}
<li><a class="icon plus-icon" href="{% url 'reporting:finding_create' %}">Add New Finding</a></li>
{% endif %}
</ul>
</li>
</ul>
<!-- Operations Section -->
<ul class="list-unstyled components">
<p class="sideheader icon execution-icon">Execution</p>
<!-- Menu Section -->
{% if user.is_authenticated %}
<li><a href="{% url 'shepherd:user_assets' %}">My Active Assets</a></li>
{% endif %}
<li>
<a href="#projectSubmenu" data-toggle="collapse" aria-expanded="false"
class="dropdown-toggle sidebar-dropdown-toggle">Projects</a>
<ul class="collapse list-unstyled text-left" id="projectSubmenu">
<li><a class="icon list-icon" href="{% url 'rolodex:projects' %}">Projects Library</a></li>
{% if request.user|is_privileged %}
<li><a class="icon plus-icon" href="{% url 'rolodex:project_create_no_client' %}">Add New Project</a></li>
{% endif %}
</ul>
</li>
<li>
<a href="#oplogSubmenu" data-toggle="collapse" aria-expanded="false"
class="dropdown-toggle sidebar-dropdown-toggle">Operation Logs</a>
<ul class="collapse list-unstyled text-left" id="oplogSubmenu">
<li><a class="icon list-icon" href="{% url 'oplog:index' %}">Oplog Library</a></li>
<li><a class="icon plus-icon" href="{% url 'oplog:oplog_create_no_project' %}">Add New Oplog</a></li>
<li><a class="icon import-icon" href="{% url 'oplog:oplog_import' %}">Import Oplog Entries</a></li>
</ul>
</li>
</ul>
<!-- Reporting Section -->
<ul class="list-unstyled components">
<p class="sideheader icon file-icon">Reporting</p>
<!-- Menu Section -->
<li>
<a href="#reportSubmenu" data-toggle="collapse" aria-expanded="false"
class="dropdown-toggle sidebar-dropdown-toggle">Reports</a>
<ul class="collapse list-unstyled text-left" id="reportSubmenu">
<li><a class="icon list-icon" href="{% url 'reporting:reports' %}">Report Library</a></li>
<li><a class="icon plus-icon" href="{% url 'reporting:report_create_no_project' %}">Add New Report</a>
</li>
</ul>
</li>
<li>
<a href="#templateSubmenu" data-toggle="collapse" aria-expanded="false"
class="dropdown-toggle sidebar-dropdown-toggle">Templates</a>
<ul class="collapse list-unstyled text-left" id="templateSubmenu">
<li><a class="icon list-icon" href="{% url 'reporting:templates' %}">Report Template Library</a></li>
<li><a class="icon plus-icon" href="{% url 'reporting:template_create' %}">Add New Report Template</a>
</li>
</ul>
</li>
{% if not request.user|is_contractor %}
<li><a href="{% url 'stratum:report_findings' %}">Search Report Findings</a></li>
{% endif %}
<li><a href="{% url 'reporting:archived_reports' %}">Archived Reports</a></li>
</ul>
<!-- Shepherd Section -->
<ul class="list-unstyled components">
<p class="sideheader icon maintain-icon">Maintain</p>
<!-- Menu Section -->
<li>
<a href="#serverSubmenu" data-toggle="collapse" aria-expanded="false"
class="dropdown-toggle sidebar-dropdown-toggle">Servers</a>
<ul class="collapse list-unstyled text-left" id="serverSubmenu">
{% comment %} Search for All Servers {% endcomment %}
<form class="px-6 py-2" action="{% url 'shepherd:infrastructure_search' %}" method="GET">
<input type="search" autocomplete="off" class="form-control" id="server-search" name="query"
placeholder="Search Servers..." autofocus="autofocus">
</form>
{% comment %} Server Submenu Items {% endcomment %}
<li><a class="icon list-icon" href="{% url 'shepherd:servers' %}">Server Library</a></li>
<li><a class="icon plus-icon" href="{% url 'shepherd:server_create' %}">Add New Server</a></li>
</ul>
</li>
<li>
<a href="#shepSubmenu" data-toggle="collapse" aria-expanded="false"
class="dropdown-toggle sidebar-dropdown-toggle">Domains</a>
<ul class="collapse list-unstyled text-left" id="shepSubmenu">
{% comment %} Search for Domains {% endcomment %}
<form class="px-6 py-2" action="{% url 'shepherd:domains' %}" method="GET">
<input type="search" autocomplete="off" class="form-control" id="domain-search" name="domain"
placeholder="Search Domains..." autofocus="autofocus">
</form>
{% comment %} Domains Submenu Items {% endcomment %}
<li><a class="icon list-icon" href="{% url 'shepherd:domains' %}">Domain Library</a></li>
<li><a class="icon plus-icon" href="{% url 'shepherd:domain_create' %}">Add New Domain</a></li>
</ul>
</li>
<li><a href="{% url 'shepherd:update' %}">Update Controls</a></li>
</ul>
<!-- Admin Section -->
<ul class="list-unstyled components">
<!-- Admin Panel Shortcuts -->
<p class="sideheader icon admin-icon">Administration</p>
{% if request.user.is_staff or request.user.role == "admin" %}
<li><a href="{% url 'home:management' %}">Review Configuration</a></li>
<li>
<a href="#adminSubmenu" data-toggle="collapse" aria-expanded="false"
class="dropdown-toggle sidebar-dropdown-toggle">Admin Panel</a>
<ul class="collapse list-unstyled text-left" id="adminSubmenu">
<li><a class="icon gears-icon" href="{% url 'admin:index' %}">Admin Panel</a></li>
<li><a class="icon slider-icon" href="{% url 'admin:index' %}commandcenter">Configuration Mgmt</a></li>
{% if perms.users.view_user %}
<li><a class="icon users-icon" href="{% url 'admin:users_user_changelist' %}">User Mgmt</a></li>
{% endif %}
{% if perms.django_q.view_task %}
<li><a class="icon calendar-icon" href="{% url 'admin:app_list' 'django_q' %}">Scheduled Tasks</a>
</li>
{% endif %}
</ul>
</li>
<!-- Bulk Import & Export Shortcuts -->
<li>
<a href="#bulkSubmenu" data-toggle="collapse" aria-expanded="false"
class="dropdown-toggle sidebar-dropdown-toggle">Import & Export</a>
<ul class="collapse list-unstyled text-left" id="bulkSubmenu">
<li><a class="icon import-icon" href="{% url 'admin:reporting_finding_import' %}">Upload Bulk
Findings</a></li>
<li><a class="icon export-icon" href="{% url 'reporting:export_findings_to_csv' %}">Export Findings to
CSV</a></li>
<hr>
<li><a class="icon import-icon" href="{% url 'admin:shepherd_domain_import' %}">Upload Bulk Domains</a>
</li>
<li><a class="icon export-icon" href="{% url 'shepherd:export_domains_to_csv' %}">Export Domains to
CSV</a></li>
<hr>
<li><a class="icon import-icon" href="{% url 'admin:shepherd_staticserver_import' %}">Upload Bulk
Servers</a></li>
<li><a class="icon export-icon" href="{% url 'shepherd:export_servers_to_csv' %}">Export Servers to
CSV</a></li>
</ul>
</li>
{% endif %}
<!-- Documentation Section -->
<li>
<a href="#docsSubmenu" data-toggle="collapse" aria-expanded="false"
class="dropdown-toggle sidebar-dropdown-toggle">Documentation</a>
<ul class="collapse list-unstyled text-left" id="docsSubmenu">
<li><a class="icon docs-icon" href="https://ghostwriter.wiki">Ghostwriter Wiki</a></li>
<li><a class="icon github-icon" href="https://github.com/GhostManager/Ghostwriter">Ghostwriter on
GitHub</a></li>
</ul>
</li>
</ul>
<!-- Sidebar Buttons -->
<div class="align-middle text-center">
{% if user.is_authenticated %}
<a href="{% url 'account_logout' %}" class="btn btn-primary col-10 icon logout-icon">Logout</a>
{% else %}
<a href="{% url 'account_login' %}" class="btn btn-primary col-10 icon login-icon">Login</a>
{% endif %}
<a href="https://www.specterops.io"><img class="col-8" src="{% static 'images/domain.png' %}"
alt="SpecterOps"></a>
</div>
</div>
<div class="sidebar-footer col d-flex align-items-center justify-content-center mb-2">
<span>v{{ VERSION }}, released {{ RELEASE_DATE }}</span>
</div>
</nav>
{% endif %}
<!-- Page Content Holder -->
<div id="content">
{% if user.is_authenticated %}
<div class="top-bar container-fluid align-middle">
<!-- Breadcrumb Links -->
{% block breadcrumbs %}{% endblock %}
<!-- User Profile & Avatar -->
<a href="{% url 'users:user_detail' request.user.username %}">
<img class="navbar-avatar"
data-toggle="tooltip" data-placement="top" title="Logged-in as {{ request.user.username }}"
src="{% url 'users:avatar_download' slug=request.user.username %}"
alt="Avatar">
</a>
</div>
{% endif %}
{% comment %} Page Content Goes Here {% endcomment %}
<div>
{% block content %}{% endblock %}
</div>
</div>
</div>
<a style="display: none;" id="scroll-button"></a>
{% comment %} Scripts included on ALL pages {% endcomment %}
<script>
{% comment %} Handle AJAX errors {% endcomment %}
(function($){
$(document).on('ajaxError', function(event, xhr) {
if (xhr.status === 401 || xhr.status === 403) {
if (xhr.hasOwnProperty('responseJSON')) {
let errorData = xhr.responseJSON;
if (errorData['message']) {
displayToastTop({type:errorData['result'], string:errorData['message'], title:'Error'});
}
}
}
});
})(jQuery);
{% comment %} Scroll button handling {% endcomment %}
let scrollButton = $('#scroll-button');
{% comment %} When the user scrolls down 20px from the top of the document, show the button {% endcomment %}
$(window).on('scroll', function () {
if ($(window).scrollTop() > 300) {
scrollButton.show(500);
} else {
scrollButton.hide(500);
}
});
{% comment %} When the user clicks on the button, scroll to the top of the document {% endcomment %}
scrollButton.on('click', function () {
$('html, body').animate({scrollTop: 0}, '300');
});
{% comment %} Activate a report with AJAX {% endcomment %}
$('.js-activate-report').click(function (e) {
let url = $(this).attr('activate-report-url');
let reportId = $(this).attr('activate-report-id');
let csrftoken = $(this).attr('activate-report-csrftoken');
let shortcut = $('.active-report-shortcut');
let shortcut_url = shortcut.attr('href');
let url_tpl = '{% url 'reporting:report_detail' 0 %}';
$.ajaxSetup({
beforeSend: function (xhr, settings) {
if (!csrfSafeMethod(settings.type) && !this.crossDomain) {
xhr.setRequestHeader('X-CSRFToken', csrftoken);
}
}
});
$.ajax({
url: url,
type: 'POST',
dataType: 'json',
data: {
'report': reportId
},
success: function (data) {
if (data['result'] === 'success') {
let $emptyReport = $('.empty-report')
$emptyReport.addClass('selected-report');
$emptyReport.toggleClass('empty-report');
$('.selected-report').each(function () {
if (reportId !== $(this).attr('activate-report-id')) {
$(this).toggleClass('selected-report');
}
});
$('.js-activate-report').each(function () {
if (reportId === $(this).attr('activate-report-id') && !$(this).hasClass('selected-report')) {
$(this).toggleClass('selected-report');
$(this).addClass('toggle-on-icon');
$(this).removeClass('toggle-off-icon');
} else {
$(this).show(1000);
$(this).removeClass('toggle-on-icon');
$(this).addClass('toggle-off-icon');
}
});
{% comment %} Update shortcut button {% endcomment %}
let current_value = shortcut_url.substring(shortcut_url.lastIndexOf('/') + 1);
if (current_value === reportId) {
shortcut.attr('href', shortcut_url);
} else {
shortcut.attr('href', url_tpl.replace('0', reportId));
shortcut.text('Jump to Report');
shortcut.removeClass('btn-disabled');
}
}
if (data['message']) {
displayToastTop({type: data['result'], string: data['message'], title: 'Report Update', delay: 5});
setTimeout(function () {
window.location.href = shortcut_url;
}, 5000);
}
}
});
e.stopImmediatePropagation();
});
{% comment %} Open and close the sidebar {% endcomment %}
function sidebarOpen() {
$('#sidebar').toggleClass('active');
$('.sidebar-toggle-btn').toggleClass('fa-flip-horizontal');
{% comment %} Send AJAX POST request to update session {% endcomment %}
$.ajax({
url: '/home/ajax/session/update',
type: 'POST',
dataType: 'json',
data: {
'session_data': 'sidebar',
},
});
}
{% comment %} Open the sidebar {% endcomment %}
$('.sidebar-header-tab').click(function () {
sidebarOpen();
});
{% comment %} Activate Bootstrap hover tooltips {% endcomment %}
$(document).ready(function () {
$('[data-toggle="tooltip"]').tooltip();
});
{% comment %} All of the Toastr JavaScript {% endcomment %}
$(document).ready(function () {
toastr.options = {
'closeButton': true,
'debug': false,
'newestOnTop': false,
'progressBar': true,
'positionClass': 'toast-top-right',
'preventDuplicates': false,
'showDuration': '1000',
'hideDuration': '1000',
'timeOut': '4000',
'extendedTimeOut': '4000',
'showEasing': 'swing',
'hideEasing': 'linear',
'showMethod': 'fadeIn',
'hideMethod': 'fadeOut',
}
// Need to set this outside of the dict per the README
// https://github.com/CodeSeven/toastr#escape-html-characters
toastr.options.escapeHtml = true;
});
{% comment %} Display toast notification for each message on page load {% endcomment %}
{% for message in messages %}
{% if 'no-toast' not in message.tags %}
{% if message.level == DEFAULT_MESSAGE_LEVELS.SUCCESS %}
displayToastTop({type: 'success', string: '{{ message }}'});
{% elif message.level == DEFAULT_MESSAGE_LEVELS.WARNING %}
displayToastTop({type: 'warning', string: '{{ message }}'});
{% elif message.level == DEFAULT_MESSAGE_LEVELS.ERROR %}
displayToastTop({type: 'error', string: '{{ message }}'});
{% elif message.level == DEFAULT_MESSAGE_LEVELS.INFO %}
displayToastTop({type: 'info', string: '{{ message }}'});
{% elif message.level == DEFAULT_MESSAGE_LEVELS.DEBUG %}
displayToastTop({type: 'info', string: '{{ message }}'});
{% endif %}
{% endif %}
{% endfor %}
{% if user.is_authenticated %}
{% comment %} Configure WebSockets protocol – HTTP for dev and HTTPS for prod {% endcomment %}
let ws_proto = 'ws://'
if (location.protocol === 'https:') {
ws_proto = 'wss://'
}
const protocol = ws_proto
const username = '{{ user }}';
{% comment %} Connect to channel for individual notifications {% endcomment %}
const ws_user = new WebSocket(
protocol + window.location.host +
'/ws/users/' + username + '/');
{% comment %} Connect to channel for all user notifications {% endcomment %}
const ws_all = new WebSocket(
protocol + window.location.host +
'/ws/users/all/');
{% comment %} Functions for sending messages {% endcomment %}
function sendMessage(socket, msg) {
{% comment %} Wait until the state of the socket is not ready and send the message when it is... {% endcomment %}
waitForSocketConnection(socket, function () {
socket.send(msg);
});
}
{% comment %} Make the function wait until the connection is made... {% endcomment %}
function waitForSocketConnection(socket, callback) {
setTimeout(
function () {
if (socket.readyState === 1) {
if (callback != null) {
callback();
}
} else {
console.log('Waiting for connection...')
waitForSocketConnection(socket, callback);
}
}, 5); // wait 5 millisecond for the connection...
}
{% comment %} Handle receiving messages on channels {% endcomment %}
ws_user.onmessage = function (e) {
let data = JSON.parse(e.data);
displayToastTop({type: data.message.level, string: data.message.message, title: data.message.title});
}
ws_all.onmessage = function (e) {
let data = JSON.parse(e.data);
displayToastTop({type: data.message.level, string: data.message.message, title: data.message.title});
};
{% comment %} Handle unexpected WebSocket closures {% endcomment %}
ws_user.onclose = function () {
console.error('User notification WebSocket closed unexpectedly');
};
ws_all.onclose = function () {
console.error('Global notification WebSocket closed unexpectedly');
};
{% endif %}
</script>
{% comment %} Blocks used by forms that use Bootstrap tabs {% endcomment %}
{% block tabs %}
<script>
$(function () {
let hash = window.location.hash.replace(/[^\w-#]/g, '');
hash && $('ul.nav a[href="' + hash + '"]').tab('show');
$('.nav-tabs a').click(function (e) {
{% comment %} Prevent the scrolling-to-tab animation {% endcomment %}
$('html,body').stop().animate({
scrollTop: $($(this).attr('href')).offset().top - $('.nav').height()
}, 700, 'swing');
e.preventDefault();
e.stopImmediatePropagation();
$(this).tab('show');
window.location.hash = $(this).attr('href');
});
});
</script>
{% endblock %}
{% block tabforms %}
{% comment %} Handle the Delete and Undo buttons {% endcomment %}
<script>
$(document).on('click', '.formset-del-button', function () {
// Get the parent divs for this formset instance
let parent_div = $(this).closest('div.formset-container');
let formset_instance = parent_div.find('div.formset');
// Find the parent formset's Bootstrap alert div
let alert = parent_div.find('div.alert');
// Find the hidden DELETE checkbox and check it
let del_checkbox = formset_instance.find(":input[id*='DELETE']");
console.log(del_checkbox);
del_checkbox.eq(0).prop('checked', true);
console.log(del_checkbox.eq(0).prop('checked'));
// Hide the formset instance and display the alert
formset_instance.hide();
$(alert).show();
});
$(document).on('click', '.formset-undo-button', function () {
// Get the parent divs for the formset instance
let parent_div = $(this).closest('div.formset-container');
let formset_instance = parent_div.find('div.formset');
// Find the hidden DELETE checkbox and uncheck it
let del_checkbox = formset_instance.find(":input[id*='DELETE']");
console.log(del_checkbox);
del_checkbox.eq(0).prop('checked', false);
console.log(del_checkbox.eq(0).prop('checked'));
// Show the formset instance and hide the alert
formset_instance.show();
$(this).hide();
});
</script>
{% comment %} Switch to Tab with Invalid Inputs {% endcomment %}
<script>
// Open tab with the first invalid/missing field on submission but before POST
$('#submit-id-submit').click(function () {
$('input:invalid').each(function () {
// Find the tab-pane that this element is inside, and get the id
let $closest = $(this).closest('.tab-pane');
let id = $closest.attr('id');
// Find the link that corresponds to the pane and have it show
$('.nav a[href="#' + id + '"]').tab('show');
// Only want to do it once
return false;
});
});
// Open tab with the first invalid/missing field when returning from a POST that failed validation
$(window).on('load', function () {
$('input.is-invalid').each(function () {
// Find the tab-pane that this element is inside, and get the id
let $closest = $(this).closest('.tab-pane');
let id = $closest.attr('id');
// Find the link that corresponds to the pane and have it show
$('.nav a[href="#' + id + '"]').tab('show');
// Only want to do it once
return false;
});
// If no invalid fields, look for invalid-feedback messages
// This catches invalid fields taken over by TinyMCE
$('span.invalid-feedback').each(function () {
// Find the tab-pane that this element is inside, and get the id
let $closest = $(this).closest('.tab-pane');
let id = $closest.attr('id');
// Find the link that corresponds to the pane and have it show
$('.nav a[href="#' + id + '"]').tab('show');
// Only want to do it once
return false;
});
});
$(window).click(function () {
{% comment %} Toggle the hamburger menu back to normal if user clicks away {% endcomment %}
let $hamburgerMenu = $('.dropdown-menu-btn')
if ($hamburgerMenu.hasClass('change')) {
$hamburgerMenu.removeClass('change');
}
});
</script>
{% endblock %}
{% comment %} Block to hold additional one-off JavaScript needed by an individual template {% endcomment %}
{% block morescripts %}{% endblock %}
</body>
</html>