CEO updated

This commit is contained in:
andrei-mihnea-cerbu
2024-04-20 03:18:44 +03:00
parent 869305a491
commit 57c2c7ec55
81 changed files with 3517 additions and 1035 deletions
@@ -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">
+1 -1
View File
@@ -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>
+3 -2
View File
@@ -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">
+5 -3
View File
@@ -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)
+3 -4
View File
@@ -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));
}
});
+96 -17
View File
@@ -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');
+1 -4
View File
@@ -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) {
+47 -15
View File
@@ -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'))
});
+5 -3
View File
@@ -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)