diff --git a/static/.DS_Store b/static/.DS_Store new file mode 100644 index 0000000..623572f Binary files /dev/null and b/static/.DS_Store differ diff --git a/static/css/style.css b/static/css/style.css index 2db54c9..9fc9b03 100644 --- a/static/css/style.css +++ b/static/css/style.css @@ -1,128 +1,125 @@ -/* Variables */ +/* Color Definitions */ :root { - --font: 'Roboto', sans-serif; - --bg: #1c1c1e; - --text: #ececec; - --bold-text: #2ebd52; - --accent: #007BFF; - --border-color: #19191b; - --light: #D3D3D3; + --sigma-blue: #00bbe6; + --sigma-dark: #12141c; } -/* Font Import for Google Fonts */ -@import url('https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;500&display=swap'); +::selection { + color: white; + background: var(--sigma-blue); +} + +.text-sigma-blue { + color: var(--sigma-blue); +} -/* New Styles */ -body, html { - scroll-behavior: smooth; - scroll-padding-top: 1rem; - font-kerning: normal; - -webkit-text-size-adjust: 100%; - font-size: 18px; - background-color: var(--bg); - color: var(--text); +.bg-sigma-blue { + background-color: var(--sigma-blue); } -a { - text-decoration: none; - color: inherit; +.border-sigma-blue { + border-color: var(--sigma-blue); +} + +.text-sigma-dark { + color: var(--sigma-dark); +} + +.bg-sigma-dark { + background-color: var(--sigma-dark); +} + +.border-sigma-dark { + border-color: var(--sigma-dark); +} + +/* Code Area CSS */ +pre:has(> #rule-code), +pre:has(> #query-code) { + min-height: 200px; + cursor: text; } -/* Updated existing styles */ -.dark-mode { - background-color: var(--bg); - color: var(--text); +pre:has(> #rule-code:empty)::after { + content: "start writing your sigma rule..."; + color: #c5c8c6; + width: 20px; } -/* Lighter background for code display */ div[class*="language-"], code[class*="language-"], code[class*="language-"] *, pre[class*="language-"] { - background-color: #2d2d2f; /* Lighter than the previous */ word-break: break-word !important; - white-space: pre-wrap !important; + white-space: pre-line !important; +} + +:not(pre) > code[class*="language-"], +pre[class*="language-"] { + background-color: var(--sigma-dark) !important; } div[class*="language-"]::selection, div[class*="language-"] span::selection, code[class*="language-"]::selection, code[class*="language-"] span::selection { - background: hsl(320, 80%, 25%); - color: hsla(0, 0%, 100%, .8); + background: var(--sigma-blue); + color: var(--sigma-dark); } -.font-size-10 { - font-size: 1.0rem !important; +.token.atrule, +.token.attr-value, +.token.function, +.token.property, +.token.keyword, +.token.string { + color: var(--sigma-blue) !important; } -.row { - padding-left: 3% !important; - padding-right: 3% !important; +.token.attr-name, +.token.builtin, +.token.char, +.token.inserted, +.token.selector, +.token.string { + color: white !important; } -.dark-mode .ui.selection.dropdown, -.dark-mode .ui.selection.dropdown:hover, -.dark-mode .ui.selection.active.dropdown .menu, -.dark-mode .ui.selection.active.dropdown:hover .menu, -.dark-mode .ui.selection.active.visible.dropdown, -.dark-mode .ui.selection.active.visible.dropdown:hover { - border-color: var(--light); +/* tom-select css override */ +.select-sigma > .ts-control, +.select-sigma > .ts-control input { + color: white; + background-color: var(--sigma-dark) !important; + border-color: var(--sigma-blue) !important; } -.dark-mode .ui.selection.dropdown, .dark-mode .ui.selection.active.dropdown > div.text { - color: var(--text); - background-color: rgba(255,255,255,.05); - border-color: var(--border-color); +.select-sigma > .ts-dropdown [data-selectable].option { + color: var(--sigma-blue); + background-color: var(--sigma-dark); } -.dark-mode .ui.selection.active.dropdown div.item { - color: var(--text); - background-color: #1d1f21; - border-color: var(--border-color); +.select-sigma > .ts-dropdown [data-selectable].option.active { + color: white; + background-color: var(--sigma-blue); } -.dark-mode .ui.form .field>label { - color: var(--text); +.select-sigma input[type="checkbox"] { + background-color: var(--sigma-dark); } -pre[class*=language-] { - min-height: 49px; - cursor: text; +.select-sigma input[type="checkbox"]:checked { + background-color: var(--sigma-blue); + border-color: var(--sigma-dark); } -.notification-box { - position: fixed !important; - top: 20px; - right: 20px; - z-index: 1000; - display: none; -} - -.dark-mode .ui.modal>.header, -.dark-mode .ui.modal>.content { +.select-sigma.ts-wrapper.multi .ts-control > div { color: white; - background-color: var(--bg); -} - -@media only screen and (max-width: 768px) { - .ui.selection.dropdown { - width: 100% !important; - } + background-color: var(--sigma-dark); + border: 1px solid var(--sigma-blue); + border-radius: 2px; } -/* Increase contrast for text boxes */ -.ui.selection.dropdown, .ui.selection.active.dropdown > div.text { - color: #ffffff; - background-color: #1c1c1e; - border-color: #2ebd52; -} - -/* Add a minimum width to the cli-code box to prevent clashing */ -#cli-code { - min-width: 300px; -} -/* Add a minimum width to the dropdowns to prevent clashing */ -.field .ui.selection.dropdown { - min-width: 200px; +.select-sigma > .ts-dropdown, +.select-sigma.ts-wrapper.plugin-remove_button:not(.rtl) .item .remove { + border-color: var(--sigma-blue); } diff --git a/static/fav.png b/static/fav.png deleted file mode 100644 index c3435a1..0000000 Binary files a/static/fav.png and /dev/null differ diff --git a/static/favicon.ico b/static/favicon.ico new file mode 100644 index 0000000..86f4645 Binary files /dev/null and b/static/favicon.ico differ diff --git a/static/js/index.js b/static/js/index.js index 8531033..2c9c827 100644 --- a/static/js/index.js +++ b/static/js/index.js @@ -1,103 +1,176 @@ -function copy() { - - let resultCode = document.getElementById('result-code'); - navigator.clipboard.writeText(resultCode.value); - - // alert("successfully copied") - $('.notification-box').transition('fade in'); // display the notification - - setTimeout(function(){ - $('.notification-box').transition('fade out'); // hide the notification after 2 seconds - }, 2000); +// initialize select dropdowns +new TomSelect("#select-backend", { + controlInput: null, + valueField: "value", + labelField: "label" +}); +new TomSelect("#select-format", { + controlInput: null, + valueField: "value", + labelField: "label" +}); +new TomSelect("#select-pipeline", { + allowEmptyOption: true, + plugins: ["remove_button", "checkbox_options"], + persist: false, + hidePlaceholder: true, + searchField: "value", + valueField: "value", + labelField: "label" +}); + +// inital stuff todo when page is loaded +window.onload = function () { + // select splunk backend by default + let backendSelect = document.getElementById("select-backend"); + backendSelect.tomselect.addItem("splunk"); + // init filtering of dropdowns on page load + filterFormatOptions(); + filterPipelineOptions(); + // load cli command + generateCli(); + // inital conversion of example rule + convert(sigmaJar.toString()); +}; + +// define onchange handler for select dropdowns +document.getElementById("select-backend").onchange = function () { + filterFormatOptions(); + filterPipelineOptions(); + generateCli(); + convert(sigmaJar.toString()); +}; + +document.getElementById("select-format").onchange = function () { + generateCli(); + convert(sigmaJar.toString()); +}; + +document.getElementById("select-pipeline").onchange = function () { + generateCli(); + convert(sigmaJar.toString()); +}; + +// define onclick handler for buttons +document.getElementById("query-copy-btn").onclick = function () { + copyQuery(); +}; + +function copyQuery() { + let queryCode = document.getElementById("query-code"); + navigator.clipboard.writeText(queryCode.value); + + var queryCopyBtn = document.getElementById("query-copy-btn"); + queryCopyBtn.classList.toggle("text-sigma-blue"); + queryCopyBtn.classList.toggle("text-green-400"); + + setTimeout(function () { + queryCopyBtn.classList.toggle("text-sigma-blue"); + queryCopyBtn.classList.toggle("text-green-400"); + }, 1200); } -function info() { - $('.ui.modal').modal('show'); - $('.ui.modal').addClass('inverted'); +function focusSelect(elementId) { + document.getElementById(elementId).focus(); } -const showFormats = () => { - let backend = $('#target-select').dropdown('get value'); - - let options = $('#format-select').find("option[backend$=" + backend + "]") - - values = [] - options = [...options] - options.forEach(option => { - values.push({"value": option.value, "name": option.innerHTML}) - }); - $('#format-select').dropdown('change values', values); - $('#format-select').dropdown('set selected', values[0].value); - +function getSelectValue(elementId) { + let select = document.getElementById(elementId); + let tomSelect = select.tomselect; + return tomSelect.getValue(); } -const showPipelines = () => { - let backend = $('#target-select').dropdown('get value'); - - let options = $('#pipeline-select').find("option[backend$=" + backend + "], option[backend$=all]") +function generateCli() { + let cliCode = document.getElementById("cli-code"); + let backend = getSelectValue("select-backend"); + let format = getSelectValue("select-format"); + let pipelines = getSelectValue("select-pipeline"); - values = [] - options = [...options] - options.forEach(option => { - values.push({"value": option.value, "name": option.innerHTML}) - }); - $('#pipeline-select').dropdown('change values', values); -} + cliCommand = "sigma convert"; + if (pipelines.length === 0) { + cliCommand = cliCommand + " --without-pipeline "; + } + pipelines.forEach((e) => { + cliCommand = cliCommand + " -p " + e; + }); -const cli = () => { - - let cliCode = document.getElementById('cli-code'); - let pipeline = $('#pipeline-select').dropdown('get value'); - let target = $('#target-select').dropdown('get value'); - let format = $('#format-select').dropdown('get value'); - - cliCommand = "sigma convert" - if(pipeline.length === 0){ - cliCommand = cliCommand + " --without-pipeline " - } - pipeline.forEach(e => { - cliCommand = cliCommand + " -p " + e - }); - - cliCommand = cliCommand + " -t " + target + " -f " + format + " rule.yml"; + cliCommand = cliCommand + " -t " + backend + " -f " + format + " rule.yml"; cliCode.innerHTML = cliCommand; Prism.highlightElement(cliCode); // rerun code highlighting } -const convert = () => { - let resultCode = document.getElementById('result-code'); +function convert(sigmaRule) { + let queryCode = document.getElementById("query-code"); - // get form values - let sigma = jar.toString() - let pipeline = $('#pipeline-select').dropdown('get value'); - let target = $('#target-select').dropdown('get value'); - let format = $('#format-select').dropdown('get value'); + let backend = getSelectValue("select-backend"); + let format = getSelectValue("select-format"); + let pipelines = getSelectValue("select-pipeline"); // create json object const params = { - rule: btoa(sigma), - pipeline: pipeline, - target: target, + rule: btoa(sigmaRule), + pipeline: pipelines, + target: backend, format: format }; - // send post request const xhr = new XMLHttpRequest(); - xhr.onreadystatechange = function(e) { - if(xhr.readyState === 4){ - if(xhr.status === 200 ){ - // write converted querie to output - resultCode.innerHTML = xhr.response - resultCode.value = xhr.response - Prism.highlightElement(resultCode); // rerun code highlighting - } - else if(xhr.status === 500){ - resultCode.innerHTML = "Error: Something went wrong" + xhr.onreadystatechange = function (e) { + if (xhr.readyState === 4) { + if (xhr.status === 200) { + // write converted query to output code area + queryCode.innerHTML = xhr.response; + queryCode.value = xhr.response; + Prism.highlightElement(queryCode); // rerun code highlighting + } else if (xhr.status === 500) { + queryCode.innerHTML = "Error: Something went wrong"; } } - } - xhr.open("post", window.location.origin + "/sigma", true) - xhr.setRequestHeader('Content-Type', 'application/json'); + }; + xhr.open("post", window.location.origin + "/sigma", true); + xhr.setRequestHeader("Content-Type", "application/json"); xhr.send(JSON.stringify(params)); } + +function filterFormatOptions() { + // clear all elemeents from select + let select = document.getElementById("select-format"); + let tomSelect = select.tomselect; + tomSelect.clear(); + tomSelect.clearOptions(); + + // only add the formats which match the selected backend + let backend = getSelectValue("select-backend"); + var options = select.querySelectorAll('option[backend$="' + backend + '"]'); + options = [...options]; + options.forEach((option) => { + tomSelect.addOption({ + label: option.label, + value: option.value + }); + }); + // select the first element + tomSelect.addItem(options[0].value); +} + +function filterPipelineOptions() { + // clear all elemeents from select + let select = document.getElementById("select-pipeline"); + let tomSelect = select.tomselect; + tomSelect.clear(); + tomSelect.clearOptions(); + + // only add the pipeplines which match the selected backend or have backend=="all" + let backend = getSelectValue("select-backend"); + var options = select.querySelectorAll( + 'option[backend$="' + backend + '"], option[backend$=all]' + ); + options = [...options]; + options.forEach((option) => { + tomSelect.addOption({ + label: option.label, + value: option.value + }); + }); +} diff --git a/templates/index.html b/templates/index.html index f2369a1..2e96f39 100644 --- a/templates/index.html +++ b/templates/index.html @@ -1,27 +1,23 @@
- - - - - - - - + +