|
14 | 14 | </div> |
15 | 15 | </div> |
16 | 16 |
|
17 | | -<nav class="section-nav" role="tablist" aria-label="DAST admin"> |
| 17 | +<nav class="section-nav" role="tablist" aria-label="DAST admin" data-drafting="{{ '1' if drafting else '' }}"> |
18 | 18 | <a href="#tab-rules" role="tab" data-tab="rules" class="active">Premium Curated Rules</a> |
19 | 19 | <a href="#tab-profiles" role="tab" data-tab="profiles">Scan profiles</a> |
20 | 20 | <a href="#tab-integrations" role="tab" data-tab="integrations">Integrations</a> |
|
358 | 358 | </div> |
359 | 359 | {% endif %} |
360 | 360 |
|
361 | | -<script> |
362 | | -(function () { |
363 | | - // A header checkbox ticks or clears every rule in its class. |
364 | | - document.addEventListener("change", function (e) { |
365 | | - var head = e.target; |
366 | | - if (!head.matches || !head.matches("[data-check-all]")) { return; } |
367 | | - var form = head.closest("form"); |
368 | | - if (!form) { return; } |
369 | | - Array.prototype.forEach.call( |
370 | | - form.querySelectorAll('input[name="rule_id"]'), |
371 | | - function (cb) { cb.checked = head.checked; }); |
372 | | - }); |
373 | | - |
374 | | - // Tabs: show one pane at a time, remember it in the address. |
375 | | - var tabs = Array.prototype.slice.call(document.querySelectorAll(".section-nav [data-tab]")); |
376 | | - var panes = Array.prototype.slice.call(document.querySelectorAll("[data-pane]")); |
377 | | - function show(name) { |
378 | | - tabs.forEach(function (t) { t.classList.toggle("active", t.getAttribute("data-tab") === name); }); |
379 | | - panes.forEach(function (p) { p.hidden = p.getAttribute("data-pane") !== name; }); |
380 | | - } |
381 | | - tabs.forEach(function (t) { |
382 | | - t.addEventListener("click", function (e) { |
383 | | - e.preventDefault(); |
384 | | - var name = t.getAttribute("data-tab"); |
385 | | - show(name); |
386 | | - window.history.replaceState(null, "", "#tab-" + name); |
387 | | - }); |
388 | | - }); |
389 | | - var hash = (window.location.hash || "").replace("#tab-", ""); |
390 | | - show(tabs.some(function (t) { return t.getAttribute("data-tab") === hash; }) ? hash : "rules"); |
391 | | - |
392 | | - // The rule modal fills its textarea from the button that opened it, and |
393 | | - // pretty prints the stored spec so it is easy to edit. |
394 | | - var spec = document.getElementById("rule-spec"); |
395 | | - var editing = document.getElementById("rule-editing"); |
396 | | - var origin = document.getElementById("rule-origin"); |
397 | | - function fill(text) { |
398 | | - if (!spec) { return; } |
399 | | - try { spec.value = JSON.stringify(JSON.parse(text), null, 2); } |
400 | | - catch (e) { spec.value = text || ""; } |
401 | | - } |
402 | | - var fromDraft = document.getElementById("rule-from-draft"); |
403 | | - document.addEventListener("click", function (e) { |
404 | | - var b = e.target.closest ? e.target.closest('[data-modal="rule-modal"]') : null; |
405 | | - if (!b) { return; } |
406 | | - if (editing) { editing.value = b.getAttribute("data-editing") || ""; } |
407 | | - if (origin) { origin.value = b.getAttribute("data-origin") || "custom"; } |
408 | | - if (fromDraft) { fromDraft.value = b.getAttribute("data-from-draft") || ""; } |
409 | | - fill(b.getAttribute("data-spec") || ""); |
410 | | - }); |
411 | | - |
412 | | - // The scan profile modal fills from the button that opened it, and ticks |
413 | | - // the rulesets the profile already runs. |
414 | | - document.addEventListener("click", function (e) { |
415 | | - var b = e.target.closest ? e.target.closest('[data-modal="profile-modal"]') : null; |
416 | | - if (!b) { return; } |
417 | | - var set = function (id, v) { var el = document.getElementById(id); if (el) { el.value = v; } }; |
418 | | - set("profile-editing", b.getAttribute("data-editing") || ""); |
419 | | - set("profile-name", b.getAttribute("data-name") || ""); |
420 | | - set("profile-depth", b.getAttribute("data-depth") || "premium"); |
421 | | - set("profile-notes", b.getAttribute("data-notes") || ""); |
422 | | - var chosen = []; |
423 | | - try { chosen = JSON.parse(b.getAttribute("data-rulesets") || "[]"); } catch (x) { chosen = []; } |
424 | | - Array.prototype.forEach.call( |
425 | | - document.querySelectorAll('#profile-modal [name="rulesets"]'), |
426 | | - function (cb) { cb.checked = chosen.indexOf(cb.value) !== -1; }); |
427 | | - }); |
428 | | - |
429 | | - // While a rule is being drafted in the background, refresh so it appears |
430 | | - // under Drafted rules when it is ready, without losing the current tab. |
431 | | - if ({{ 'true' if drafting else 'false' }}) { |
432 | | - window.setTimeout(function () { window.location.reload(); }, 5000); |
433 | | - } |
434 | | -})(); |
435 | | -</script> |
| 361 | +<script src="{{ base }}/static/dast_admin.js?v={{ asset_v('dast_admin.js') }}"></script> |
436 | 362 | {% endblock %} |
0 commit comments