Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating branch, preparing for merge #769

Merged
merged 7 commits into from
May 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 13 additions & 3 deletions pages/[locale]/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export default function Home() {
const [errorOccurred, setError] = useLocalStorage("errorOccurred", 'false');
const { t } = useTranslation('common');
const [updateAvailable, setUpdateAvailable] = useState(false);
const [hash_count, setHashCount] = useState(0);

/**
* Function triggered when a directory was selected
Expand Down Expand Up @@ -91,11 +92,11 @@ export default function Home() {
.catch((error) => {
SetDirSelection(true);
console.error("Couldn't retrieve settings: ", error);
})
});

// Using the backend, check if the app is running on the Raspberry Pi
invoke("check_raspberry", {})
.then((output) => setIsRaspberryPi(output))
.then((output) => setIsRaspberryPi(output));

// Using the backend, ask for a list of connected USB drives
invoke("list_usb_drives", {})
Expand All @@ -112,9 +113,18 @@ export default function Home() {
});
});

invoke("get_hash_count_fe", {}).then((count) => {
console.log("SET Hash count: ", count);
setHashCount(count);
})
.catch((error) => {
console.error(error);
});

// Using the backend, check if an update is available
invoke("check_update", {})
.then((output) => {
console.log("Update available: ", output);
setUpdateAvailable(output);
})
.catch((error) => {
Expand All @@ -137,7 +147,7 @@ export default function Home() {
} else {
router.push({
pathname: "/permission",
query: { scan_path: value },
query: { scan_path: value, hashcount: hash_count },
});
}
};
Expand Down
88 changes: 41 additions & 47 deletions pages/[locale]/loading.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { CircularProgressbar, buildStyles } from 'react-circular-progressbar';
import 'react-circular-progressbar/dist/styles.css';
import { useTranslation } from 'next-i18next';
import { getStaticPaths, makeStaticProps } from '../../lib/getStatic';
import { Config } from "../../services/getConfigSettings";
import Swal from "sweetalert2";

/**
Expand All @@ -26,10 +25,10 @@ export default function Loading() {
const [progress, setProgress] = useState(0);
const router = useRouter();
// Retrieves the query parameters
let { query: { scan_path }, } = router;
let { query: { scan_path, hashcount }, } = router;
// Can be empty, to let the backend choose the best one
let db_location = "";
const {t} = useTranslation('common');
const { t } = useTranslation('common');

useEffect(() => {
// Reads the emited progress signal from the backend
Expand All @@ -47,15 +46,15 @@ export default function Loading() {
query: { scanner_error: event.payload.message }
})
}

// Starts listening for incoming signals emited from the backend
const startListening = async () => {
await listen('progress', handleProgress);
await listen('progerror', handleProgressErr);
};

startListening();

// Clean up function to remove the event listener when the component unmounts
return () => {
removeEventListener('progress', handleProgress);
Expand All @@ -69,12 +68,9 @@ export default function Loading() {

// Starts the scan on the backend and periodically updates the frontend
const scanning = async () => {
const config = new Config();
config.loadConfig();
if (config.hash_count <= 0) {
if (parseInt(hashcount) <= 0) {
// There are no signatures in the database, so the scanner cannot start

const { isConfirmed } = await Swal.fire({
isConfirmed = await Swal.fire({
title: t('empty_db_dialog'),
text: t('empty_db_dialog_text'),
icon: "warning",
Expand All @@ -84,38 +80,36 @@ export default function Loading() {
confirmButtonText: t('empty_db_dialog_confirm'),
cancelButtonText: t('empty_db_dialog_cancel'),
})

if (isConfirmed) {
router.push("/");
return;
}
}
try {
// Start the function on the backend using Tauri
const message = await invoke("start_scanner", {
path: scan_path,
dbfile: db_location,
});
// If the array of found viruses is not empty, redirected to the "infected" page
if (message && message.length > 0 && message != "[]") {
console.log(message);
router.push({
pathname: '/infected',
query: { virus_list: message }
});
} else {
try {
// Start the function on the backend using Tauri
const message = await invoke("start_scanner", {
path: scan_path,
dbfile: db_location,
});

// If the array of found viruses is not empty, redirected to the "infected" page
if (message && message.length > 0 && message != "[]") {
console.log(message);
router.push({
pathname: '/infected',
query: { virus_list: message }
});
} else {
// No virus found, device is clean
router.push("/clean");
}
} catch (error) {
console.error(error);
localStorage.setItem("errorOccurred", 'true');
router.push({
pathname: '/',
query: { scanner_error: error }
})
}
// No virus found, device is clean
router.push("/clean");
}
} catch (error) {
console.error(error);
localStorage.setItem("errorOccurred", 'true');
router.push({
pathname: '/',
query: { scanner_error: error }
})
}
};

Expand All @@ -127,15 +121,15 @@ export default function Loading() {
<main className="flex flex-col items-center justify-center h-screen">
<h1 className="text-2xl font-bold text-center">{t('loading_text')}</h1>
<div className="flex flex-row m-10">
<CircularProgressbar
value={progress}
text={`${progress}%`}
styles={buildStyles({
textColor: '#35c091',
pathColor: '#ff3366',
trailColor: '#d6d6d6'
})}
/>
<CircularProgressbar
value={progress}
text={`${progress}%`}
styles={buildStyles({
textColor: '#35c091',
pathColor: '#ff3366',
trailColor: '#d6d6d6'
})}
/>
</div>
</main>
</>
Expand Down
4 changes: 2 additions & 2 deletions pages/[locale]/permission.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ export default function Permission() {

// When the user accepts the agreement, a redirect takes place with the path to scan retrieved from the Home page
function startScanner() {
let { query: { scan_path }, } = router;
let { query: { scan_path , hashcount}, } = router;
router.push({
pathname: '/loading',
query: { scan_path: scan_path }
query: { scan_path: scan_path, hashcount: hashcount }
})
}

Expand Down
36 changes: 17 additions & 19 deletions pages/[locale]/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { listen } from '@tauri-apps/api/event';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { faFileLines, faUserNinja, faWrench, faHome, faGears,
faLink, faDatabase, faFileZipper, faFingerprint, faHistory } from '@fortawesome/free-solid-svg-icons';
import React, { useState, useEffect, useRef } from 'react';
import React, { useState, useEffect, useRef, use } from 'react';
import Swal from 'sweetalert2';
import withReactContent from 'sweetalert2-react-content';
import { useTranslation } from 'next-i18next';
Expand All @@ -33,14 +33,14 @@ export default function Settings() {
// Data for some of the settings is retrieved directly from the backend and saved back to it
const [hash_count, setCount] = useState(0);
const [updated_date, setDate] = useState(t('update_db_status_1'));
const [unformatted_date, setUnformattedDate] = useState("");
const [logging, setLogging] = useState(false);
const [obfuscated, setObfuscated] = useState(false);
const [use_db_path, setUsedbPath] = useState(false);
const [custom_db_path, setCustomDbPath] = useState("");
const [scan_dir, setScanDir] = useState(false);
const [ignored_hashes, setIgnoredHashes] = useState([]);
const [mirror, setMirror] = useState("");
const [patch_result, setPatchResult] = useState("");
// DB Update progress
const [progress, setProgress] = useState(0);
const progressRef = useRef(progress);
Expand Down Expand Up @@ -136,7 +136,7 @@ export default function Settings() {
const saveSettings = () => {
const jsonData = {
hashes_in_db: hash_count,
last_db_update: updated_date,
last_db_update: unformatted_date,
logging_is_active: logging,
obfuscated_is_active: obfuscated,
db_location: custom_db_path,
Expand Down Expand Up @@ -239,7 +239,8 @@ export default function Settings() {
const parsedData = JSON.parse(output);
console.log("Loaded config: ", parsedData);
if (parsedData.last_db_update != "Never") {
setDate(parsedData.last_db_update);
setUnformattedDate(parsedData.last_db_update);
setDate(getDate(parseInt(parsedData.last_db_update)));
}
setLogging(parsedData.logging_is_active);
setObfuscated(parsedData.obfuscated_is_active);
Expand Down Expand Up @@ -315,15 +316,11 @@ export default function Settings() {
ReactSwal.close(); // Close the SweetAlert
console.log(message);
setCount(Number(message));
// Set the date to the current date
setDate(getDate());
Swal.fire(t('update_db_completed'), t('update_db_completed_val'), "success");
})
.catch((error) => {
console.error(error);
ReactSwal.close(); // Close the SweetAlert
// On error, set the failed update status
setDate(t('update_db_status_2'));
Swal.fire(t('update_db_failed'), t('update_db_failed_val') + ": " + error, "error");
});
} else {
Expand All @@ -332,8 +329,9 @@ export default function Settings() {
}
}

const getDate = () => {
const today = new Date();
const getDate = (unformatted_date) => {
const today = new Date(unformatted_date);
console.log("Today: ", today);
const date = today.getDate() + '-' + (today.getMonth() + 1) + '-' + today.getFullYear();
const hours = today.getHours().toString().padStart(2, '0');
const minutes = today.getMinutes().toString().padStart(2, '0');
Expand Down Expand Up @@ -434,27 +432,27 @@ export default function Settings() {
/>

<SettingComp
title={'Add patch file'}
short={'Allows to patch the DB with custom data'}
short2={'Use: https://github.com/Raspirus/signature-builder'}
title={t('add_patch_title')}
short={t('add_patch_desc')}
short2={t('add_patch_desc2')}
icon={faGears}
isOn={false}
action={handleAddPatchFile}
action_val={'Add Patch'}
action_val={t('add_patch_action')}
/>

<SettingComp
title={"Download logs"}
short={"Download logs from the backend"}
title={t('download_logs')}
short={t('download_logs_desc')}
icon={faHistory}
action={download_log_file}
action_val={"Download"}
action_val={t('download_logs_action')}
isOn={false}
/>

<SettingComp
title={"Mirror website"}
short={"Location where we download the signatures from"}
title={t('mirror_website')}
short={t('mirror_website_desc')}
short2={mirror}
icon={faLink}
isOn={navigator.onLine}
Expand Down
16 changes: 14 additions & 2 deletions public/locales/de/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"update_db_status_1": "Nie",
"update_db_status_2": "Fehlgeschlagen",
"update_db_1": "Hashes in DB",
"update_db_2": "Letzte Aktualisierung",
"update_db_2": "Datum der Datenbank",
"update_db_btn": "AKTUALISIEREN",
"update_db_loading_val": "Bitte warten, dies kann einige Zeit brauchen",
"update_db_completed": "Aktualisierung vollständig",
Expand Down Expand Up @@ -97,5 +97,17 @@
"logs_download_dialog": "Logs heruntergeladen",
"logs_download_dialog_text": "Speicherort: ",

"add_hash_placeholder": "Gib einen Hash ein"
"add_hash_placeholder": "Gib einen Hash ein",

"add_patch_title": "Füge einen Patch hinzu",
"add_patch_desc": "Füge einen Patch hinzu, um eine Signatur zu überschreiben",
"add_patch_desc2": "Siehe: https://github.com/Raspirus/signature-builder",
"add_patch_action": "Hinzufügen",

"download_logs": "Logs herunterladen",
"download_logs_desc": "Lade die Logs als .txt Datei herunter",
"download_logs_action": "Herunterladen",

"mirror_website": "Mirror Webseite",
"mirror_website_desc": "Ort wo wir die hash Datenbank hosten"
}
Loading
Loading