CEO updated
This commit is contained in:
+102
-12
@@ -6,15 +6,17 @@ const {fork} = require('child_process');
|
||||
|
||||
const {encryptFileInPlace, decryptFileInPlace} = require('./aes_encrypt');
|
||||
const {lockFile, unlockFile} = require("../../helpers/lock_mechanism");
|
||||
//const {decryptUserFilesToDirectory} = require("../../jobs/backup");
|
||||
|
||||
const isMac = process.platform === 'darwin';
|
||||
let html_page = undefined;
|
||||
let mainWindow = undefined;
|
||||
let alertWindow = undefined;
|
||||
|
||||
let backupProcess = null;
|
||||
let receiverProcess = null;
|
||||
let fetcherProcess = null;
|
||||
let backupProcess = null;
|
||||
let externalEndpointsProcess = null;
|
||||
let sendFileProcess = null;
|
||||
|
||||
const create_initial_keys = () => {
|
||||
const SECRET_KEY = crypto.randomBytes(32);
|
||||
@@ -144,12 +146,16 @@ app.on('before-quit', () => {
|
||||
if (backupProcess !== null) {
|
||||
backupProcess.kill();
|
||||
}
|
||||
if (receiverProcess !== null) {
|
||||
receiverProcess.kill();
|
||||
if (externalEndpointsProcess !== null) {
|
||||
externalEndpointsProcess.kill();
|
||||
}
|
||||
if (fetcherProcess !== null) {
|
||||
fetcherProcess.kill();
|
||||
}
|
||||
|
||||
if (sendFileProcess !== null) {
|
||||
sendFileProcess.kill();
|
||||
}
|
||||
});
|
||||
|
||||
app.on('window-all-closed', () => {
|
||||
@@ -214,7 +220,24 @@ ipcMain.handle('change-content', async (event, nextPage) => {
|
||||
}
|
||||
});
|
||||
|
||||
ipcMain.handle('open-backup-dir-dialog', async (event) => {
|
||||
ipcMain.handle('open-dir-dialog', async (event) => {
|
||||
try {
|
||||
const result = await dialog.showOpenDialog({
|
||||
properties: ['openDirectory'],
|
||||
});
|
||||
|
||||
if (result.canceled || result.filePaths.length === 0) {
|
||||
return {canceled: true}
|
||||
}
|
||||
|
||||
return result.filePaths[0];
|
||||
} catch (error) {
|
||||
console.error('Error opening file dialog:', error);
|
||||
return null;
|
||||
}
|
||||
})
|
||||
|
||||
ipcMain.handle('open-json-dir-config', async (event, fileName) => {
|
||||
try {
|
||||
const result = await dialog.showOpenDialog({
|
||||
properties: ['openDirectory'],
|
||||
@@ -226,10 +249,9 @@ ipcMain.handle('open-backup-dir-dialog', async (event) => {
|
||||
|
||||
const dirPath = result.filePaths[0];
|
||||
await fs.promises.writeFile(
|
||||
path.join(__dirname, '..', '..', 'dirBackup.json'),
|
||||
path.join(__dirname, '..', '..', fileName),
|
||||
JSON.stringify({
|
||||
path: dirPath,
|
||||
structure: {}
|
||||
path: dirPath
|
||||
}, null, 2));
|
||||
|
||||
return true;
|
||||
@@ -271,13 +293,81 @@ ipcMain.on('close-alert-window', () => {
|
||||
});
|
||||
|
||||
//External processes
|
||||
ipcMain.handle('start-fetcher', async (event, args) => {
|
||||
if (fetcherProcess === null) {
|
||||
fetcherProcess = fork(path.join(__dirname, '..', '..', 'jobs', 'fetcher.js'), args, {silent: false});
|
||||
ipcMain.handle('start-main-processes', async (event, args) => {
|
||||
if (!backupProcess) {
|
||||
backupProcess = fork(path.join(__dirname, '..', '..', 'jobs', 'backup.js'), args, { silent: false });
|
||||
backupProcess.on('exit', () => {
|
||||
backupProcess = null;
|
||||
});
|
||||
backupProcess.on('error', (err) => {
|
||||
console.log('Backup process error:', err);
|
||||
});
|
||||
}
|
||||
|
||||
if (!fetcherProcess) {
|
||||
fetcherProcess = fork(path.join(__dirname, '..', '..', 'jobs', 'fetcher.js'), args, { silent: false });
|
||||
fetcherProcess.on('exit', () => {
|
||||
fetcherProcess = null;
|
||||
// Optionally, notify the renderer process that the fetcher has finished
|
||||
});
|
||||
fetcherProcess.on('error', (err) => {
|
||||
console.log('Fetcher process error:', err);
|
||||
});
|
||||
|
||||
fetcherProcess.on('message', (message) => {
|
||||
if (message.type === 'startBackup') {
|
||||
backupProcess.send({
|
||||
type: 'startBackup'
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (!externalEndpointsProcess) {
|
||||
externalEndpointsProcess = fork(path.join(__dirname, '..', '..', 'jobs', 'external_endpoints.js'), args, { silent: false });
|
||||
externalEndpointsProcess.on('exit', () => {
|
||||
externalEndpointsProcess = null;
|
||||
});
|
||||
externalEndpointsProcess.on('error', (err) => {
|
||||
console.log('External endpoints process error:', err);
|
||||
});
|
||||
}
|
||||
|
||||
return true; // Indicate that the operation has started
|
||||
});
|
||||
|
||||
ipcMain.handle('start-send-file-process', async (event, args) => {
|
||||
if (sendFileProcess === null) {
|
||||
sendFileProcess = fork(path.join(__dirname, '..', '..', 'jobs', 'send_file.js'), args, {silent: false});
|
||||
sendFileProcess.on('exit', () => {
|
||||
sendFileProcess = null;
|
||||
});
|
||||
}
|
||||
return true; // Indicate that the operation has started
|
||||
});
|
||||
|
||||
ipcMain.handle('kill-before-logout', async(event) =>{
|
||||
if (backupProcess !== null) {
|
||||
backupProcess.kill('SIGINT');
|
||||
}
|
||||
if (externalEndpointsProcess !== null) {
|
||||
externalEndpointsProcess.kill('SIGINT');
|
||||
}
|
||||
if (fetcherProcess !== null) {
|
||||
fetcherProcess.kill('SIGINT');
|
||||
}
|
||||
|
||||
if (sendFileProcess !== null) {
|
||||
sendFileProcess.kill('SIGINT');
|
||||
}
|
||||
})
|
||||
|
||||
ipcMain.handle('decrypt-backup-files', async(event, destPath) => {
|
||||
console.log('ai intrat in handle')
|
||||
if(backupProcess != null){
|
||||
console.log('esti in process');
|
||||
backupProcess.send({
|
||||
type: 'decryptBackup',
|
||||
decryptDestPath: destPath
|
||||
});
|
||||
}
|
||||
})
|
||||
|
||||
@@ -7,13 +7,12 @@ contextBridge.exposeInMainWorld('electronAPI', {
|
||||
changeContent: (nextPage) => ipcRenderer.invoke('change-content', nextPage),
|
||||
showAlert: (message) => ipcRenderer.invoke('show-alert', message),
|
||||
closeAlertWindow: () => ipcRenderer.send('close-alert-window'),
|
||||
openBackupDirDialog: () => ipcRenderer.invoke('open-backup-dir-dialog'),
|
||||
openJsonDirConfigDialog: (fileName) => ipcRenderer.invoke('open-json-dir-config', fileName),
|
||||
openDirDialog: () => ipcRenderer.invoke('open-dir-dialog'),
|
||||
openFileDialog: () => ipcRenderer.invoke('open-file-dialog'),
|
||||
checkFileExists: (fileName) => ipcRenderer.invoke('check-file-exists', fileName),
|
||||
|
||||
startFetcher: async (args) => ipcRenderer.invoke('start-fetcher', args),
|
||||
startBackup: async (args) => ipcRenderer.invoke('start-backup', args),
|
||||
startDecryptFiles: async (args) => ipcRenderer.invoke('start-decrypt-files', args),
|
||||
startSendFiles: async (args) => ipcRenderer.invoke('start-send_files', args),
|
||||
startReceiver: async (args) => ipcRenderer.invoke('start-receiver', args)
|
||||
startMainProcesses: async (args) => ipcRenderer.invoke('start-main-processes', args),
|
||||
killBeforeLogout: async() => ipcRenderer.invoke('kill-before-logout'),
|
||||
decryptFiles: async(destPath) => ipcRenderer.invoke('decrypt-backup-files', destPath)
|
||||
});
|
||||
+9
-2
@@ -9,13 +9,20 @@
|
||||
<link href="../css/transition.css" rel="stylesheet">
|
||||
|
||||
<script src="../js/transition.js"></script>
|
||||
<script>
|
||||
document.addEventListener('DOMContentLoaded', async function () {
|
||||
const destPath = await window.electronAPI.openDirDialog();
|
||||
await window.electronAPI.decryptFiles(destPath);
|
||||
fadeOut('main_menu.html');
|
||||
});
|
||||
</script>
|
||||
|
||||
<title>Setup Completion</title>
|
||||
<title>Sending file</title>
|
||||
</head>
|
||||
<body onload="fadeIn()">
|
||||
<div class="container">
|
||||
<div class="header">
|
||||
<h1>SENDING THE FILE!</h1>
|
||||
<h1>DECRYPTING BACKUP!</h1>
|
||||
<h2>PlEASE WAIT</h2>
|
||||
<img alt="Description of GIF" src="../assets/loading.gif">
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<meta content="width=device-width, initial-scale=1.0" name="viewport">
|
||||
<link href="../assets/hard-disk.ico" rel="icon" type="image/x-icon">
|
||||
|
||||
<link href="../css/ip_submit.css" rel="stylesheet">
|
||||
<link href="../../../../CEO/src/renderer/css/ip_submit.css" rel="stylesheet">
|
||||
<link href="../css/transition.css" rel="stylesheet">
|
||||
|
||||
<script src="../js/ip_submit.js"></script>
|
||||
|
||||
@@ -38,13 +38,14 @@
|
||||
<div class="left_block_content">
|
||||
<div class="left_block_buttons">
|
||||
<button id="backup" name="menu_button">Set backup directory</button>
|
||||
<button id="change_department" name="menu_button">Change work department</button>
|
||||
<button id="share_dir" name="menu_button">Set share directory</button>
|
||||
</div>
|
||||
<div class="left_block_buttons">
|
||||
<button id="change_info" name="menu_button">Change your info</button>
|
||||
<button id="share_file" name="menu_button">Share a file</button>
|
||||
<button id="change_department" name="menu_button">Change work department</button>
|
||||
</div>
|
||||
<div class="left_block_buttons">
|
||||
<button id="share_file" name="menu_button">Share a file</button>
|
||||
<button id="decrypt" name="menu_button">Decrypt files</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -9,8 +9,49 @@
|
||||
<link href="../css/transition.css" rel="stylesheet">
|
||||
|
||||
<script src="../js/transition.js"></script>
|
||||
<script>
|
||||
import * as fs from "fs";
|
||||
|
||||
<title>Setup Completion</title>
|
||||
document.addEventListener("DOMContentLoaded", async function () {
|
||||
async function performUploads() {
|
||||
try {
|
||||
const uploadData = JSON.parse(await window.electronAPI.readFile('usersDestTemp.json'));
|
||||
|
||||
const uploadPromises = uploadData.users.map(async (user) => {
|
||||
const formData = new FormData();
|
||||
formData.append('file', fs.readFileSync(uploadData.filePath));
|
||||
formData.append('idUser', user.userId);
|
||||
formData.append('nameOfFile', user.fileName);
|
||||
|
||||
const url = `http://${user.destIp}:${user.destPort}/upload`;
|
||||
const uploadResponse = await fetch(url, {
|
||||
method: 'POST',
|
||||
body: formData
|
||||
});
|
||||
|
||||
if (!uploadResponse.ok) {
|
||||
throw new Error(`HTTP error during file upload to ${user.userId}: status ${uploadResponse.status}`);
|
||||
}
|
||||
|
||||
return { userId: user.userId, success: true, message: `Upload successful for user ${user.userId}` };
|
||||
});
|
||||
|
||||
const results = await Promise.all(uploadPromises);
|
||||
results.forEach(result => {
|
||||
console.log(result.message);
|
||||
});
|
||||
console.log('All files processed. Check the console for detailed results.');
|
||||
} catch (error) {
|
||||
console.error('An error occurred during uploads:', error);
|
||||
}
|
||||
}
|
||||
|
||||
await performUploads();
|
||||
fadeOut('main_menu.html');
|
||||
});
|
||||
</script>
|
||||
|
||||
<title>Sending file</title>
|
||||
</head>
|
||||
<body onload="fadeIn()">
|
||||
<div class="container">
|
||||
|
||||
@@ -17,9 +17,11 @@ document.addEventListener('DOMContentLoaded', async function () {
|
||||
|
||||
const formContent = document.querySelector('.department-form-content');
|
||||
Object.entries(data).forEach(([key, department]) => {
|
||||
const label = document.createElement('label');
|
||||
label.innerHTML = `<input type="radio" name="dept" value="${department.name}">${department.name}`;
|
||||
formContent.appendChild(label);
|
||||
if(department.name !== 'CEO'){
|
||||
const label = document.createElement('label');
|
||||
label.innerHTML = `<input type="radio" name="dept" value="${department.name}">${department.name}`;
|
||||
formContent.appendChild(label);
|
||||
}
|
||||
});
|
||||
}).catch(async error => {
|
||||
await window.electronAPI.showAlert(error.message)
|
||||
|
||||
@@ -34,6 +34,8 @@ document.addEventListener('DOMContentLoaded', async function () {
|
||||
})
|
||||
}).then(async response => {
|
||||
if (response.ok) {
|
||||
await window.electronAPI.killBeforeLogout();
|
||||
await window.electronAPI.startMainProcesses();
|
||||
fadeOut('main_menu.html');
|
||||
} else {
|
||||
await window.electronAPI.deleteFile('loginData.json');
|
||||
@@ -84,6 +86,7 @@ document.addEventListener('DOMContentLoaded', async function () {
|
||||
}).then(async data => {
|
||||
data.data.password = password
|
||||
await window.electronAPI.writeFile('loginData.json', JSON.stringify(data.data, null, 2));
|
||||
await window.electronAPI.startMainProcesses();
|
||||
fadeOut('main_menu.html');
|
||||
})
|
||||
.catch(async error => {
|
||||
@@ -92,8 +95,4 @@ document.addEventListener('DOMContentLoaded', async function () {
|
||||
.catch(error => console.error('Error showing alert:', error));
|
||||
})
|
||||
});
|
||||
|
||||
function delayWithTimeout(ms) {
|
||||
return new Promise(resolve => setTimeout(resolve, ms));
|
||||
}
|
||||
});
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
document.addEventListener('DOMContentLoaded', async function () {
|
||||
await insertUsername();
|
||||
|
||||
const backupButton = document.getElementById('backup');
|
||||
const shareButton = document.getElementById('share_dir');
|
||||
const changeDepartmentButton = document.getElementById('change_department');
|
||||
const changeInfoButton = document.getElementById('change_info');
|
||||
const shareFileButton = document.getElementById('share_file');
|
||||
@@ -19,21 +22,12 @@ document.addEventListener('DOMContentLoaded', async function () {
|
||||
|
||||
let triggerSource = '';
|
||||
|
||||
|
||||
function handleOverlayOpen(buttonId) {
|
||||
overlay.style.display = 'block';
|
||||
triggerSource = buttonId; // Remember the button that triggered the overlay
|
||||
console.log(`${buttonId} button clicked!`);
|
||||
}
|
||||
|
||||
changeDepartmentButton.addEventListener('click', function () {
|
||||
handleOverlayOpen('change_department');
|
||||
});
|
||||
|
||||
decryptButton.addEventListener('click', function () {
|
||||
handleOverlayOpen('decrypt');
|
||||
});
|
||||
|
||||
ceoBackButton.addEventListener('click', function () {
|
||||
overlay.style.display = 'none';
|
||||
});
|
||||
@@ -59,7 +53,8 @@ document.addEventListener('DOMContentLoaded', async function () {
|
||||
if (triggerSource === 'change_department') {
|
||||
fadeOut('change_department.html');
|
||||
} else if (triggerSource === 'decrypt') {
|
||||
fadeOut('decrypting_files.html');
|
||||
console.log('astept decryptarea')
|
||||
fadeOut('decrypting_backup.html');
|
||||
}
|
||||
})
|
||||
|
||||
@@ -68,13 +63,28 @@ document.addEventListener('DOMContentLoaded', async function () {
|
||||
});
|
||||
|
||||
checkDirBackupFileExists()
|
||||
.then(() => console.log('verificare facuta'));
|
||||
await insertUsername();
|
||||
.then(() => console.log('verificare backupDir facuta'));
|
||||
|
||||
checkShareDirFileExists()
|
||||
.then(() => console.log('verificare ShareDir facuta'));
|
||||
|
||||
checkDepartmentDirFileExists()
|
||||
.then(() => {console.log('verificare departmentDir facuta')})
|
||||
|
||||
backupButton.addEventListener('click', function () {
|
||||
console.log('Set backup directory button clicked!');
|
||||
|
||||
window.electronAPI.openBackupDirDialog()
|
||||
window.electronAPI.openJsonDirConfigDialog('dirBackup.json')
|
||||
.then(() => console.log('Back-up directory set'))
|
||||
.catch(async error => await window.electronAPI.showAlert(error.message)
|
||||
.then(() => console.log('Alert window opened'))
|
||||
.catch(error => console.error('Error showing alert:', error)));
|
||||
});
|
||||
|
||||
shareButton.addEventListener('click', function () {
|
||||
console.log('Set backup directory button clicked!');
|
||||
|
||||
window.electronAPI.openJsonDirConfigDialog('dirShare.json')
|
||||
.then(() => console.log('Back-up directory set'))
|
||||
.catch(async error => await window.electronAPI.showAlert(error.message)
|
||||
.then(() => console.log('Alert window opened'))
|
||||
@@ -86,6 +96,14 @@ document.addEventListener('DOMContentLoaded', async function () {
|
||||
fadeOut('profile.html');
|
||||
});
|
||||
|
||||
changeDepartmentButton.addEventListener('click', function () {
|
||||
handleOverlayOpen('change_department');
|
||||
});
|
||||
|
||||
decryptButton.addEventListener('click', function () {
|
||||
handleOverlayOpen('decrypt');
|
||||
});
|
||||
|
||||
shareFileButton.addEventListener('click', function () {
|
||||
console.log('Share a file button clicked!');
|
||||
fadeOut('share_file.html');
|
||||
@@ -93,7 +111,7 @@ document.addEventListener('DOMContentLoaded', async function () {
|
||||
|
||||
logoutButton.addEventListener('click', async function () {
|
||||
console.log('Logout button clicked!');
|
||||
|
||||
await window.electronAPI.killBeforeLogout();
|
||||
await window.electronAPI.deleteFile('loginData.json');
|
||||
fadeOut('login.html');
|
||||
});
|
||||
@@ -109,7 +127,7 @@ document.addEventListener('DOMContentLoaded', async function () {
|
||||
button.id = 'backup_alert';
|
||||
button.name = 'alert';
|
||||
button.textContent = 'Set your backup directory!';
|
||||
button.addEventListener('click', handleButtonClick);
|
||||
button.addEventListener('click', handleBackupButtonPressed);
|
||||
notificationsDiv.appendChild(button);
|
||||
}
|
||||
} catch (error) {
|
||||
@@ -117,11 +135,46 @@ document.addEventListener('DOMContentLoaded', async function () {
|
||||
}
|
||||
}
|
||||
|
||||
async function checkShareDirFileExists() {
|
||||
try {
|
||||
const fileExists = await window.electronAPI.checkFileExists('dirShare.json');
|
||||
|
||||
async function handleButtonClick() {
|
||||
if (!fileExists) {
|
||||
const notificationsDiv = document.getElementById('notifications');
|
||||
const button = document.createElement('button');
|
||||
button.id = 'share_file_alert';
|
||||
button.name = 'alert';
|
||||
button.textContent = 'Set your share directory!';
|
||||
button.addEventListener('click', handleShareButtonPressed);
|
||||
notificationsDiv.appendChild(button);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error checking file existence:', error);
|
||||
}
|
||||
}
|
||||
|
||||
async function checkDepartmentDirFileExists() {
|
||||
try {
|
||||
const fileExists = await window.electronAPI.checkFileExists('dirDepartment.json');
|
||||
|
||||
if (!fileExists) {
|
||||
const notificationsDiv = document.getElementById('notifications');
|
||||
const button = document.createElement('button');
|
||||
button.id = 'department_alert';
|
||||
button.name = 'alert';
|
||||
button.textContent = 'Set your department directory!';
|
||||
button.addEventListener('click', handleDepartmentButtonPressed);
|
||||
notificationsDiv.appendChild(button);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error checking file existence:', error);
|
||||
}
|
||||
}
|
||||
|
||||
async function handleBackupButtonPressed() {
|
||||
console.log('Button clicked!');
|
||||
|
||||
await window.electronAPI.openBackupDirDialog()
|
||||
await window.electronAPI.openJsonDirConfigDialog('dirBackup.json')
|
||||
.then(() => console.log('Back-up directory set'))
|
||||
.catch(async error => await window.electronAPI.showAlert(error.message)
|
||||
.then(() => console.log('Alert window opened'))
|
||||
@@ -131,6 +184,32 @@ document.addEventListener('DOMContentLoaded', async function () {
|
||||
button.remove();
|
||||
}
|
||||
|
||||
async function handleShareButtonPressed() {
|
||||
console.log('Button clicked!');
|
||||
|
||||
await window.electronAPI.openJsonDirConfigDialog('dirShare.json')
|
||||
.then(() => console.log('Share directory set'))
|
||||
.catch(async error => await window.electronAPI.showAlert(error.message)
|
||||
.then(() => console.log('Alert window opened'))
|
||||
.catch(error => console.error('Error showing alert:', error)));
|
||||
|
||||
const button = document.getElementById('backup_alert');
|
||||
button.remove();
|
||||
}
|
||||
|
||||
async function handleDepartmentButtonPressed() {
|
||||
console.log('Button clicked!');
|
||||
|
||||
await window.electronAPI.openJsonDirConfigDialog('dirDepartment.json')
|
||||
.then(() => console.log('Department directory set'))
|
||||
.catch(async error => await window.electronAPI.showAlert(error.message)
|
||||
.then(() => console.log('Alert window opened'))
|
||||
.catch(error => console.error('Error showing alert:', error)));
|
||||
|
||||
const button = document.getElementById('backup_alert');
|
||||
button.remove();
|
||||
}
|
||||
|
||||
async function insertUsername() {
|
||||
try {
|
||||
const userData = await window.electronAPI.readFile('loginData.json');
|
||||
|
||||
@@ -23,10 +23,7 @@ document.addEventListener('DOMContentLoaded', async function () {
|
||||
|
||||
backButton.addEventListener('click', function () {
|
||||
console.log('Back button clicked!');
|
||||
|
||||
window.electronAPI.changeContent('main_menu.html')
|
||||
.then(() => console.log('Navigated to dashboard'))
|
||||
.catch(error => console.error('Error navigating:', error));
|
||||
fadeOut('main_menu.html')
|
||||
});
|
||||
|
||||
submitButton.addEventListener('click', async function (e) {
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
document.addEventListener("DOMContentLoaded", function () {
|
||||
document.addEventListener("DOMContentLoaded", async function () {
|
||||
let pathToFile = '';
|
||||
let serverIp = '';
|
||||
await window.electronAPI.readFile('ipConfig.json')
|
||||
.then(result => {
|
||||
const jsonData = JSON.parse(result.content);
|
||||
serverIp = jsonData.ip;
|
||||
})
|
||||
|
||||
function updateFileName() {
|
||||
const fileNameElement = document.getElementById('fileName');
|
||||
@@ -18,7 +24,7 @@ document.addEventListener("DOMContentLoaded", function () {
|
||||
|
||||
const {id} = loginData;
|
||||
|
||||
fetch('http://localhost:5000/users', {
|
||||
fetch(`http://${serverIp}/users`, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'x-api-key': 'uc_api'
|
||||
@@ -66,32 +72,58 @@ document.addEventListener("DOMContentLoaded", function () {
|
||||
event.preventDefault();
|
||||
console.log('Submit button clicked');
|
||||
|
||||
if (pathToFile === '' || pathToFile.length === 0) {
|
||||
const fileInput = document.getElementById('fileInput');
|
||||
if (!fileInput.files.length) {
|
||||
await window.electronAPI.showAlert('File not chosen!')
|
||||
.then(() => console.log('Alert window opened'))
|
||||
.catch(error => console.error('Error changing content:', error));
|
||||
return
|
||||
.catch(error => console.error('Error showing alert:', error));
|
||||
return;
|
||||
}
|
||||
|
||||
const form = document.getElementById('userDestForm');
|
||||
const checkboxes = form.querySelectorAll('input[name="users"]');
|
||||
const selectedUserIds = [];
|
||||
const selectedUserIds = Array.from(checkboxes)
|
||||
.filter(checkbox => checkbox.checked)
|
||||
.map(checkbox => checkbox.value);
|
||||
|
||||
checkboxes.forEach(checkbox => {
|
||||
if (checkbox.checked) {
|
||||
selectedUserIds.push(checkbox.value);
|
||||
}
|
||||
});
|
||||
|
||||
if (selectedUserIds === []) {
|
||||
if (!selectedUserIds.length) {
|
||||
await window.electronAPI.showAlert('No user selected!')
|
||||
.then(() => console.log('Alert window opened'))
|
||||
.catch(error => console.error('Error changing content:', error));
|
||||
.catch(error => console.error('Error showing alert:', error));
|
||||
return;
|
||||
}
|
||||
|
||||
//TODO: logic to send files
|
||||
const uploadData = {
|
||||
filePath: fileInput.files[0].path,
|
||||
users: []
|
||||
};
|
||||
|
||||
for (const userId of selectedUserIds) {
|
||||
try {
|
||||
const ipResponse = await fetch(`http://${serverIp}/backup_schemes/${userId}`);
|
||||
if (!ipResponse.ok) {
|
||||
throw new Error(`Failed to fetch IP address for user ${userId}: status ${ipResponse.status}`);
|
||||
}
|
||||
const { data: destIp } = await ipResponse.json();
|
||||
uploadData.users.push({
|
||||
userId,
|
||||
destIp,
|
||||
destPort: 3000, // Static destination port
|
||||
fileName: fileInput.files[0].name
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Error fetching user data:', error);
|
||||
}
|
||||
}
|
||||
|
||||
window.electronAPI.writeFile('usersDestTemp.json', JSON.stringify(uploadData))
|
||||
.then(() => {
|
||||
console.log('File saved successfully');
|
||||
fadeOut('sending_file_confirmation.html');
|
||||
})
|
||||
.catch(error => console.error('Failed to save file:', error));
|
||||
});
|
||||
|
||||
|
||||
fetchUsersAndCreateCheckboxes().then(() => console.log('Page rendered'))
|
||||
});
|
||||
|
||||
@@ -17,9 +17,11 @@ document.addEventListener('DOMContentLoaded', async function () {
|
||||
|
||||
const formContent = document.querySelector('.signup-form-content');
|
||||
Object.entries(data).forEach(([key, department]) => {
|
||||
const label = document.createElement('label');
|
||||
label.innerHTML = `<input type="radio" name="dept" value="${department.name}">${department.name}`;
|
||||
formContent.appendChild(label);
|
||||
if(department.name !== 'CEO') {
|
||||
const label = document.createElement('label');
|
||||
label.innerHTML = `<input type="radio" name="dept" value="${department.name}">${department.name}`;
|
||||
formContent.appendChild(label);
|
||||
}
|
||||
});
|
||||
}).catch(async error => {
|
||||
await window.electronAPI.showAlert(error.message)
|
||||
|
||||
Reference in New Issue
Block a user