Skip to content

Commit

Permalink
Fixed some linting issues
Browse files Browse the repository at this point in the history
  • Loading branch information
0x6368 committed Oct 1, 2023
1 parent 5bed8e3 commit 1e5d419
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 48 deletions.
60 changes: 30 additions & 30 deletions embark/static/scripts/logViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@

/* global analysis_id */

import { AnsiUp } from '/static/external/scripts/ansi_up.js';
import { Base64 } from '/static/external/scripts/base64.js';

window.addEventListener(
"load",
function () {
Expand All @@ -27,38 +30,35 @@ window.addEventListener(
console.log("error", evt);
}

var socket = undefined;

import('/static/external/scripts/ansi_up.js').then(({ AnsiUp }) => {
socket = new WebSocket(
wsStart + location.hostname + wsPort + "/ws/logs/" + analysis_id
);
var socket = new WebSocket(
wsStart + location.hostname + wsPort + "/ws/logs/" + analysis_id
);

function onMessage(evt) {
var message = JSON.parse(evt.data);
function onMessage(evt) {
var message = JSON.parse(evt.data);

if (message.file_view) {
var fileContent = Base64.decode(message.file_view.content) // We cannot use atob because of unicode (see https://stackoverflow.com/questions/30106476/using-javascripts-atob-to-decode-base64-doesnt-properly-decode-utf-8-strings)
fileContent = fileContent + "\u00a0"; // The nbsp is required in order to preserve trailing newlines
if (message.file_view) {
var fileContent = Base64.decode(message.file_view.content); // We cannot use atob because of unicode (see https://stackoverflow.com/questions/30106476/using-javascripts-atob-to-decode-base64-doesnt-properly-decode-utf-8-strings)
fileContent = fileContent + "\u00a0"; // The nbsp is required in order to preserve trailing newlines

var ansi_up = new AnsiUp();
var coloredFileContent = ansi_up.ansi_to_html(fileContent);
logArea.innerHTML = coloredFileContent;
file_view = message.file_view;
}
var ansi_up = new AnsiUp();
var coloredFileContent = ansi_up.ansi_to_html(fileContent);
logArea.innerHTML = coloredFileContent;
window.file_view = message.file_view;
}
}

socket.onmessage = function (evt) {
onMessage(evt);
};
socket.onmessage = function (evt) {
onMessage(evt);
};

socket.onerror = function (evt) {
onError(evt);
};
});
socket.onerror = function (evt) {
onError(evt);
};

function requestUpdate() {
var requestView = Object.assign({}, file_view);
var requestView = Object.assign({}, window.file_view);
requestView.content = "";
socket.send(
JSON.stringify({ action: "change_view", file_view: requestView })
Expand All @@ -67,20 +67,20 @@ window.addEventListener(

window.LogControls = {
move_offset: function (lines) {
file_view.offset += lines;
window.file_view.offset += lines;
requestUpdate();
},
set_offset: function (offset) {
file_view.offset = offset;
window.file_view.offset = offset;
requestUpdate();
},
increase_view_size: function (lines) {
file_view.limit += lines;
if (file_view.limit < 5) {
file_view.limit = 5;
window.file_view.limit += lines;
if (window.file_view.limit < 5) {
window.file_view.limit = 5;
}
if (file_view.num_lines != 0 && file_view.limit > file_view.num_lines) {
file_view.limit = file_view.num_lines;
if (window.file_view.num_lines != 0 && window.file_view.limit > window.file_view.num_lines) {
window.file_view.limit = window.file_view.num_lines;
}
requestUpdate();
},
Expand Down
3 changes: 1 addition & 2 deletions embark/templates/dashboard/logViewer.html
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,5 @@
{% endblock maincontent %}
{% block inlinejs %}
<script>var analysis_id = "{{analysis_id}}";</script>
<script type="module" src="{% static 'external/scripts/base64.js' %}"></script>
<script type="text/javascript" src="{% static 'scripts/logViewer.js' %}"></script>
<script type="module" src="{% static 'scripts/logViewer.js' %}"></script>
{% endblock inlinejs %}
32 changes: 16 additions & 16 deletions installer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export GREEN='\033[0;32m'
export ORANGE='\033[0;33m'
export CYAN='\033[0;36m'
export BOLD='\033[1m'
export NC='\033[0m' # no
export NC='\033[0m' # no

print_help(){
echo -e "\\n""$CYAN""USAGE""$NC"
Expand Down Expand Up @@ -88,7 +88,7 @@ write_env(){
local ENV_FILES=()
local LAST_PW_HASH=""
local CHECK_PW=""

if [[ -d safe ]]; then
mapfile -d '' ENV_FILES < <(find ./safe -iname "*.env" -print0 2> /dev/null)
if [[ ${#ENV_FILES[@]} -gt 0 ]] && [[ -f safe/history.env ]]; then
Expand All @@ -111,11 +111,11 @@ write_env(){
DJANGO_SECRET_KEY=$(python3.10 -c 'from django.core.management.utils import get_random_secret_key; print(get_random_secret_key())')
RANDOM_PW=$(openssl rand -base64 12)
fi

echo -e "$ORANGE""$BOLD""Creating a EMBArk configuration file .env""$NC"
{
echo "DATABASE_NAME=embark"
echo "DATABASE_USER=embark"
echo "DATABASE_USER=embark"
echo "DATABASE_PASSWORD=$RANDOM_PW"
echo "DATABASE_HOST=172.22.0.5"
echo "DATABASE_PORT=3306"
Expand All @@ -136,7 +136,7 @@ write_env(){
install_emba(){
echo -e "\n$GREEN""$BOLD""Installation of the firmware scanner EMBA on host""$NC"
if git submodule status emba | grep --quiet '^-'; then
sudo -u "${SUDO_USER:-${USER}}" git submodule init emba
sudo -u "${SUDO_USER:-${USER}}" git submodule init emba
fi
sudo -u "${SUDO_USER:-${USER}}" git submodule update --remote
sudo -u "${SUDO_USER:-${USER}}" git config --global --add safe.directory "$PWD"/emba
Expand All @@ -152,13 +152,13 @@ install_emba(){
}

create_ca (){
# FIXME could use some work
# FIXME could use some work
echo -e "\n$GREEN""$BOLD""Creating SSL Cert""$NC"
if ! [[ -d cert ]]; then
sudo -u "${SUDO_USER:-${USER}}" git checkout -- cert
fi
cd cert || exit 1
if [[ -f embark.local.csr ]] || [[ -f embark-ws.local.csr ]] || [[ -f embark.local.crt ]] || [[ -f embark-ws.local.crt ]]; then
if [[ -f embark.local.csr ]] || [[ -f embark-ws.local.csr ]] || [[ -f embark.local.crt ]] || [[ -f embark-ws.local.crt ]]; then
echo -e "\n$GREEN""$BOLD""Certs already generated, skipping""$NC"
else
# create CA
Expand Down Expand Up @@ -284,10 +284,10 @@ install_embark_default(){
if [[ "$WSL" -eq 1 ]]; then
echo -e "$RED""$BOLD""EMBArk currently does not support WSL in default mode. (only in Dev-mode)""$NC"
fi

#debs
apt-get install -y -q default-libmysqlclient-dev build-essential mysql-client-core-8.0

# install pipenv
pip3.10 install pipenv

Expand Down Expand Up @@ -323,7 +323,7 @@ install_embark_default(){

# daemon
install_daemon

#add ssl cert
create_ca

Expand All @@ -333,7 +333,7 @@ install_embark_default(){
#install packages
cp ./Pipfile* /var/www/
(cd /var/www && PIPENV_VENV_IN_PROJECT=1 pipenv install)


# download externals
if ! [[ -d ./embark/static/external ]]; then
Expand All @@ -344,7 +344,7 @@ install_embark_default(){
wget -O ./embark/static/external/scripts/bootstrap.js https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js
wget -O ./embark/static/external/scripts/datatable.js https://cdn.datatables.net/v/bs5/dt-1.11.2/datatables.min.js
wget -O ./embark/static/external/scripts/charts.js https://cdn.jsdelivr.net/npm/[email protected]/dist/chart.min.js
wget -O ./embark/static/external/scripts/base64.js https://cdn.jsdelivr.net/npm/[email protected]/base64.min.js
wget -O ./embark/static/external/scripts/base64.js https://cdn.jsdelivr.net/npm/[email protected]/+esm
wget -O ./embark/static/external/scripts/ansi_up.js https://cdn.jsdelivr.net/npm/[email protected]/ansi_up.min.js
wget -O ./embark/static/external/css/confirm.css https://cdnjs.cloudflare.com/ajax/libs/jquery-confirm/3.3.2/jquery-confirm.min.css
wget -O ./embark/static/external/css/bootstrap.css https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css
Expand Down Expand Up @@ -383,7 +383,7 @@ install_embark_dev(){
# npm packages
npm install -g jshint
# npm install -g dockerlinter

# install pipenv
pip3 install pipenv

Expand All @@ -392,7 +392,7 @@ install_embark_dev(){
echo "${SUDO_USER:-${USER}}"" ALL=(ALL) NOPASSWD: /bin/pkill" | EDITOR='tee -a' visudo
echo "root ALL=(ALL) NOPASSWD: ""$PWD""/emba/emba" | EDITOR='tee -a' visudo
echo "root ALL=(ALL) NOPASSWD: /bin/pkill" | EDITOR='tee -a' visudo


#pipenv
PIPENV_VENV_IN_PROJECT=1 pipenv install --dev
Expand Down Expand Up @@ -495,7 +495,7 @@ uninstall (){

# delete user www-embark and reset visudo
echo -e "$ORANGE""$BOLD""Delete user""$NC"

if id -u www-embark &>/dev/null ; then
userdel www-embark
fi
Expand Down Expand Up @@ -549,7 +549,7 @@ uninstall (){
systemctl daemon-reload
fi
sudo -u "${SUDO_USER:-${USER}}" git checkout HEAD -- embark.service

# reset ownership etc

# reset server-certs
Expand Down

0 comments on commit 1e5d419

Please sign in to comment.