From df868971086a571e34f2501780af3d561c2b2f60 Mon Sep 17 00:00:00 2001 From: Zedifus Date: Fri, 3 Jun 2022 18:33:21 +0100 Subject: [PATCH 1/9] Change for to forEach loop > Fixes ESLint rule ID security/detect-object-injection --- app/frontend/templates/panel/dashboard.html | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/app/frontend/templates/panel/dashboard.html b/app/frontend/templates/panel/dashboard.html index c51c35f0..593e717c 100644 --- a/app/frontend/templates/panel/dashboard.html +++ b/app/frontend/templates/panel/dashboard.html @@ -593,14 +593,16 @@ let servers = document.getElementsByClassName("server-player-totals"); let all_total_players = 0; let all_total_max_players = 0; - for (let i = 0; i < servers.length; i++) { + + servers.forEach(server => { try { - all_total_players += parseInt(servers[i].getAttribute('data-players')); - all_total_max_players += parseInt(servers[i].getAttribute('data-max')); + all_total_players += server.getAttribute('data-players'); + all_total_max_players += servers.getAttribute('data-max'); } catch { console.log("Player totals are not of type int"); } - } + }) + total_players.innerHTML = all_total_players; document.getElementById('max_players').innerHTML = all_total_max_players; document.getElementById('sync').innerHTML = ''; From 04ffe0eb657008614cb5c4f14d7b4a5602b7afd5 Mon Sep 17 00:00:00 2001 From: Zedifus Date: Fri, 3 Jun 2022 18:41:05 +0100 Subject: [PATCH 2/9] Remove unused function --- app/frontend/templates/server/wizard.html | 19 +------------------ 1 file changed, 1 insertion(+), 18 deletions(-) diff --git a/app/frontend/templates/server/wizard.html b/app/frontend/templates/server/wizard.html index 113ba2f1..a377b43a 100644 --- a/app/frontend/templates/server/wizard.html +++ b/app/frontend/templates/server/wizard.html @@ -672,24 +672,8 @@ - {% end %} \ No newline at end of file + {% end %} From 62bdf2261843bb0e2f6be83c1604be6e114158d4 Mon Sep 17 00:00:00 2001 From: Zedifus Date: Fri, 3 Jun 2022 19:49:51 +0100 Subject: [PATCH 3/9] Change for to forEach loop > Fixes ESLint rule ID security/detect-object-injection --- .../templates/panel/server_files.html | 40 +++++++++---------- app/frontend/templates/server/wizard.html | 17 ++++---- 2 files changed, 29 insertions(+), 28 deletions(-) diff --git a/app/frontend/templates/panel/server_files.html b/app/frontend/templates/panel/server_files.html index 27fb29b3..bdc5c258 100644 --- a/app/frontend/templates/panel/server_files.html +++ b/app/frontend/templates/panel/server_files.html @@ -765,14 +765,15 @@ message: waitMessage, closeButton: false }); + let nFiles = files.files.length; - for (i = 0; i < files.files.length; i++) { + for (i = 0; i < nFiles; i++) { if (!doUpload) { doUpload = true; hideUploadBox(); break; } - console.log(files.files[i].name); + const progressHtml = `
${files.files[i].name}: @@ -788,8 +789,8 @@

`; $('#upload-progress-bar-parent').append(progressHtml); - console.log(files.files.length) - sendFile(files.files[i], path, serverId, files.files.length - i - 1, (progress) => { + + sendFile(files.files[i], path, serverId, nFiles - i - 1, (progress) => { $(`#upload-progress-bar-${i + 1}`).attr('aria-valuenow', progress) $(`#upload-progress-bar-${i + 1}`).css('width', progress + '%') }); @@ -804,16 +805,16 @@ var fileList = document.getElementById("files"); fileList.addEventListener("change", function (e) { var list = ""; - for (var i = 0; i < this.files.length; i++) { - list += "
  • " + this.files[i].name + "
  • " - } + this.files.forEach(file => { + list += "
  • " + file.name + "
  • " + }) document.getElementById("fileList").innerHTML = list; }, false); }); } - function getTreeView(event) { + function getTreeView(event) { const path = $('#root_dir').data('path');; $.ajax({ @@ -901,8 +902,7 @@ function setTreeViewContext() { var treeItems = document.getElementsByClassName('tree-ctx-item'); - for (var i = 0; i < treeItems.length; i++) { - var treeItem = treeItems[i]; + treeItems.forEach(item => { if ([ 'iPad Simulator', 'iPhone Simulator', @@ -913,10 +913,10 @@ ].includes(navigator.platform) // iPad on iOS 13 detection || (navigator.userAgent.includes("Mac") && "ontouchend" in document)) { - treeItem.addEventListener("touchstart", touchstart, false); - treeItem.addEventListener("touchend", touchend, false); + item.addEventListener("touchstart", touchstart, false); + item.addEventListener("touchend", touchend, false); } - treeItem.addEventListener('contextmenu', function contextListener(event) { + item.addEventListener('contextmenu', function contextListener(event) { event.preventDefault(); var ctxmenuPath = event.target.getAttribute('data-path'); var ctxmenuName = event.target.getAttribute('data-name'); @@ -959,8 +959,6 @@ var clientX = event.clientX; var clientY = event.clientY; - - document.getElementById('files-tree-nav-content') .setAttribute('data-path', ctxmenuPath); document.getElementById('files-tree-nav-content') @@ -977,7 +975,7 @@ console.log(domRect) console.log(window.innerHeight) }) - } + }) } document.addEventListener('click', function (e) { @@ -1117,10 +1115,10 @@ editor.setKeyboardHandler(handlerName); var nodes = target.parentNode.querySelectorAll("[data-handler-name]"); - for (var i = 0; i < nodes.length; i++) { - nodes[i].classList.remove('btn-primary'); - nodes[i].classList.add('btn-secondary'); - } + nodes.forEach(node => { + node.classList.remove('btn-primary'); + node.classList.add('btn-secondary'); + }) target.classList.remove('btn-secondary'); target.classList.add('btn-primary'); @@ -1130,4 +1128,4 @@ -{% end %} \ No newline at end of file +{% end %} diff --git a/app/frontend/templates/server/wizard.html b/app/frontend/templates/server/wizard.html index a377b43a..ee9669e2 100644 --- a/app/frontend/templates/server/wizard.html +++ b/app/frontend/templates/server/wizard.html @@ -522,13 +522,16 @@ event.target.parentElement.children[1].classList.remove("d-none"); document.getElementById("overlay").classList.remove("d-none"); } + function hide(event) { var items = document.getElementsByClassName('menu'); - for (let i = 0; i < items.length; i++) { - items[i].classList.add("d-none"); - } + items.forEach(item => { + item.classList.add("d-none"); + }) + document.getElementById("overlay").classList.add("d-none"); } + $(document).ready(function () { console.log('ready'); var forms = $('form.server-wizard'); @@ -693,10 +696,10 @@ } var newOption; // create new options ordered by ascending - for (var i = 0; i < (cList.length); i++) { + cList.forEach(type => { newOption = document.createElement("option"); - newOption.value = which + "|" + cList[i]; // assumes option string and value are the same - newOption.text = cList[i]; + newOption.value = which + "|" + type; // assumes option string and value are the same + newOption.text = type; // add the new option try { cSelect.add(newOption); // this will fail in DOM browsers but is needed for IE @@ -704,7 +707,7 @@ catch (e) { cSelect.appendChild(newOption); } - } + }) } {% end %} From 4cdd2bf776e3cbf4610f8bdb15cab549749ea673 Mon Sep 17 00:00:00 2001 From: Zedifus Date: Fri, 3 Jun 2022 19:50:58 +0100 Subject: [PATCH 4/9] Remove unused code --- .../templates/server/bedrock_wizard.html | 29 ++++--------------- 1 file changed, 6 insertions(+), 23 deletions(-) diff --git a/app/frontend/templates/server/bedrock_wizard.html b/app/frontend/templates/server/bedrock_wizard.html index e700b1a1..42ab590c 100644 --- a/app/frontend/templates/server/bedrock_wizard.html +++ b/app/frontend/templates/server/bedrock_wizard.html @@ -133,7 +133,7 @@ - +
    @@ -367,7 +367,7 @@ function hide(event) { }catch{ document.getElementById('files-tree').innerHTML = text; } - + document.getElementsByClassName('files-tree-title')[0].setAttribute('data-path', serverDir); document.getElementsByClassName('files-tree-title')[0].setAttribute('data-name', 'Files'); @@ -382,7 +382,7 @@ function hide(event) { document.getElementById(path+"span").classList.toggle("tree-caret-down"); document.getElementById(path+"span").classList.toggle("tree-caret"); } - + function getDirView(event) { path = event.target.parentElement.getAttribute('data-path'); @@ -417,7 +417,7 @@ function hide(event) { } var toggler = document.getElementById(path); - + if (toggler.classList.contains('files-tree-title')){ document.getElementById(path+"span").addEventListener("click", function caretListener() { document.getElementById(path+"ul").classList.toggle("d-block"); @@ -442,27 +442,10 @@ function hide(event) { document.getElementById('main-tree-input').setAttribute('value', data.path) getTreeView(data.path); show_file_tree(); - + }, 5000); }); } - -{% end %} \ No newline at end of file +{% end %} From 6eb3e541bfce09224ce5b516af8b5d4f5c4368c7 Mon Sep 17 00:00:00 2001 From: amcmanu3 Date: Fri, 3 Jun 2022 15:21:57 -0400 Subject: [PATCH 5/9] Fix player counts on dashboard --- app/frontend/templates/panel/dashboard.html | 113 +++++++++++--------- 1 file changed, 62 insertions(+), 51 deletions(-) diff --git a/app/frontend/templates/panel/dashboard.html b/app/frontend/templates/panel/dashboard.html index 593e717c..26cb274e 100644 --- a/app/frontend/templates/panel/dashboard.html +++ b/app/frontend/templates/panel/dashboard.html @@ -39,12 +39,12 @@

    + title="{% raw translate('dashboard', 'cpuCores', data['lang']) %}: {{ data.get('hosts_data').get('cpu_cores') }}
    {% raw translate('dashboard', 'cpuCurFreq', data['lang']) %}: {{ data.get('hosts_data').get('cpu_cur_freq') }}
    {% raw translate('dashboard', 'cpuMaxFreq', data['lang']) %}: {{ data.get('hosts_data').get('cpu_max_freq') }}"> {{ translate('dashboard', 'cpuUsage', data['lang']) }}: {{ data.get('hosts_data').get('cpu_usage') }}

    + title="{{ translate('dashboard', 'memUsage', data['lang']) }}: {{ data.get('hosts_data').get('mem_usage') }}"> {{ translate('dashboard', 'memUsage', data['lang']) }}: {{ data.get('hosts_data').get('mem_percent') }}%

    @@ -95,8 +95,8 @@ {% if len(data['servers']) > 0 %} {% if data['user_data']['hints'] %} + data-content="{{ translate('dashboard', 'cannotSeeOnMobile2', data['lang']) }}" , + data-placement="top"> {% end %} {% end %}
      {{ @@ -141,18 +141,18 @@ {% if server['user_command_permission'] %} {% if server['stats']['running'] %} - +   - +   - +   @@ -166,19 +166,20 @@ translate('dashboard', 'delay-explained' , data['lang'])}}">{{ translate('dashboard', 'starting', data['lang']) }} {% elif server['stats']['downloading']%} - {{ translate('serverTerm', 'downloading', + + {{ translate('serverTerm', 'downloading', data['lang']) }} {% else %} - +   - +   - +   {% end %} @@ -187,7 +188,7 @@
    + title="{{server['stats']['cpu']}}">
    + aria-valuemin="0" aria-valuemax="100">
    {{server['stats']['cpu']}}%
    + title="{{server['stats']['mem']}}">
    + aria-valuemin="0" aria-valuemax="100">
    {{server['stats']['mem_percent']}}% - @@ -234,7 +235,7 @@ {% if server['stats']['desc'] != 'False' %}
    {{ + style="overflow-wrap: break-word !important; max-width: 85px !important; overflow: scroll;">{{ server['stats']['desc'] }}

    {% end %} @@ -249,7 +250,8 @@ {{ translate('dashboard', 'online', data['lang']) }} {% elif server['stats']['crashed'] %} - {{ translate('dashboard', 'crashed', + {{ translate('dashboard', + 'crashed', data['lang']) }} {% else %} {{ translate('dashboard', 'offline', @@ -257,7 +259,7 @@ {% end %} + data-players="{{ server['stats']['online']}}" data-max="{{ server['stats']['max'] }}"> {% end %} @@ -283,41 +285,44 @@ {% if server['user_command_permission'] %} {% if server['stats']['running'] %} - +   - +   - +   {% elif server['stats']['updating']%} - {{ translate('serverTerm', 'updating', data['lang']) }} + {{ translate('serverTerm', 'updating', + data['lang']) }} {% elif server['stats']['waiting_start']%} {{ translate('dashboard', 'starting', data['lang']) }} + translate('dashboard', 'delay-explained' , data['lang'])}}">{{ translate('dashboard', 'starting', + data['lang']) }} {% elif server['stats']['downloading']%} - {{ translate('serverTerm', 'downloading', data['lang']) }} + + {{ translate('serverTerm', 'downloading', data['lang']) }} {% else %} - +   - +   - +   {% end %} @@ -328,7 +333,8 @@ {{ translate('dashboard', 'online', data['lang']) }} {% elif server['stats']['crashed'] %} - {{ translate('dashboard', 'crashed', + {{ translate('dashboard', + 'crashed', data['lang']) }} {% else %} {{ translate('dashboard', 'offline', @@ -336,7 +342,9 @@ {% end %} - + @@ -347,7 +355,7 @@
    {{ translate('dashboard', 'cpuUsage', data['lang']) }}
    + title="{{server['stats']['cpu']}}">
    + aria-valuemin="0" aria-valuemax="100">
    {{server['stats']['cpu']}}%
    @@ -366,7 +374,7 @@
    {{ translate('dashboard', 'memUsage', data['lang']) }}
    + title="{{server['stats']['mem']}}">
    + aria-valuemin="0" aria-valuemax="100">
    {{server['stats']['mem_percent']}}% - @@ -400,11 +408,14 @@
    {{ translate('dashboard', 'players', data['lang']) }}
    {% if server['stats']['int_ping_results'] %} - {{ server['stats']['online'] }} / {{ server['stats']['max'] }} {{ translate('dashboard', 'max', + {{ server['stats']['online'] }} / {{ server['stats']['max'] }} {{ translate('dashboard', + 'max', data['lang']) }}
    {% if server['stats']['desc'] != 'False' %} -
    {{ server['stats']['desc'] }}

    +
    + {{ server['stats']['desc'] }}

    {% end %} {% if server['stats']['version'] != 'False' %} @@ -590,14 +601,14 @@ server_players.setAttribute('data-players', server.online); server_players.setAttribute('data-max', server.max); - let servers = document.getElementsByClassName("server-player-totals"); + let servers = Array.from(document.getElementsByClassName("server-player-totals")); let all_total_players = 0; let all_total_max_players = 0; servers.forEach(server => { try { - all_total_players += server.getAttribute('data-players'); - all_total_max_players += servers.getAttribute('data-max'); + all_total_players += parseInt(server.getAttribute('data-players')); + all_total_max_players += parseInt(server.getAttribute('data-max')); } catch { console.log("Player totals are not of type int"); } @@ -876,4 +887,4 @@ -{% end %} +{% end %} \ No newline at end of file From 0200f1caeca3f0231c48bf2634b222afa5491e41 Mon Sep 17 00:00:00 2001 From: amcmanu3 Date: Fri, 3 Jun 2022 15:53:12 -0400 Subject: [PATCH 6/9] Remove useless console logs --- .../templates/panel/server_files.html | 27 +++++-------------- 1 file changed, 6 insertions(+), 21 deletions(-) diff --git a/app/frontend/templates/panel/server_files.html b/app/frontend/templates/panel/server_files.html index bdc5c258..66ed9c86 100644 --- a/app/frontend/templates/panel/server_files.html +++ b/app/frontend/templates/panel/server_files.html @@ -450,9 +450,7 @@ var ctxmenuName = e.target.getAttribute('data-name'); document.getElementById('context-title').innerHTML = ctxmenuName; - console.log(ctxmenuName); if (!ctxmenuPath) { - console.log({ 'event.target': e.target, ctxmenuPath }); return; } $('#renameItem').show(); @@ -466,7 +464,6 @@ var isFile = e.target.classList.contains('tree-file'); $('#deleteFile').toggle(isFile); $('#downloadFile').toggle(isFile); - console.log({ 'event.target': e.target, isDir, isFile }); if (e.target.classList.contains('root-dir')) { $('#createFile').show(); @@ -479,7 +476,6 @@ } if (e.target.textContent.endsWith('.zip')) { $('#unzip').show(); - console.log(e.target.textContent) } else { $('#unzip').hide(); } @@ -502,7 +498,6 @@ } document.getElementById("files-tree-nav").style.top = clientY + 'px'; document.getElementById("files-tree-nav").style.left = clientX + 'px'; - console.log(window.innerHeight) timer = null; }; } @@ -585,7 +580,6 @@ console.log("got response:"); document.getElementById("save_status").innerHTML = ''; document.getElementById('save_status').style.color = '#2fb689'; - console.log(data); }, }); } @@ -602,7 +596,6 @@ }, success: function (data) { console.log("got response:"); - console.log(data); callback(); }, }); @@ -620,7 +613,6 @@ }, success: function (data) { console.log("got response:"); - console.log(data); callback(); }, }); @@ -638,7 +630,6 @@ }, success: function (data) { console.log("got response:"); - console.log(data); callback(); }, }); @@ -656,7 +647,6 @@ }, success: function (data) { console.log("got response:"); - console.log(data); callback(); }, }); @@ -673,13 +663,13 @@ }, success: function (data) { console.log("got response:"); - console.log(data); callback(); }, }); } function unZip(path, callback) { + console.log('path: ', path) var token = getCookie("_xsrf") $.ajax({ type: "POST", @@ -731,7 +721,6 @@ function uploadFilesE(event) { path = event.target.parentElement.getAttribute('data-path'); - console.log("PATH: " + path); $(function () { var uploadHtml = "
    " + '
    ' + "