Skip to content
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
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
/target/
src/main/resources/config.properties
14 changes: 14 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,20 @@
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "java",
"name": "DecryptPassword",
"request": "launch",
"mainClass": "backupmanager.Email.DecryptPassword",
"projectName": "BackupManager"
},
{
"type": "java",
"name": "EncryptPassword",
"request": "launch",
"mainClass": "backupmanager.Email.EncryptPassword",
"projectName": "BackupManager"
},
{
"type": "java",
"name": "Current File",
Expand Down
40 changes: 40 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Contributing to Backup Manager

Thank you for your interest in contributing to **Backup Manager**! Your ideas, bug reports, improvements, and patches are very welcome.

---

## How to contribute

1. **Open an Issue**
If you find a bug or want to propose a new feature, please open an issue describing the problem or request clearly.

2. **Fork & Clone**
Fork the repository and clone it locally:
```bash
git clone https://github.com/DennisTurco/BackupManager.git
cd BackupManager
```
3. **Create a Branch**
```bash
git checkout -b your-feature-or-fix-name
```
4. **Write Code**
* Follow the existing coding style.
* Write clear comments.
* Add automated tests if possible.
5. **Commit & Push**
Make clear, descriptive commits:
```bash
git commit -m "Brief description of the change"
git push origin your-feature-or-fix-name
```
6. **Open a Pull Request (PR)**
Open a PR on GitHub targeting the `master` branch. Describe what you did and why.

## Need Help?

If you have questions about contributing, contact: dennisturco@gmail.com

Thanks again for helping improve Backup Manager!

2 changes: 1 addition & 1 deletion src/main/java/backupmanager/Dialogs/PreferencesDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {
}// </editor-fold>//GEN-END:initComponents

private void themesComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_themesComboBoxActionPerformed

}//GEN-LAST:event_themesComboBoxActionPerformed

private void applyBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_applyBtnActionPerformed
Expand Down
30 changes: 30 additions & 0 deletions src/main/java/backupmanager/Email/DecryptPassword.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package backupmanager.Email;

import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;
import java.util.Base64;

public class DecryptPassword {
public static String decrypt(String encryptedPassword) throws Exception {
String secretKey = System.getenv("BACKUPMANAGER_AES_KEY");
if (secretKey == null || secretKey.isEmpty()) {
throw new IllegalStateException("Secret key not set in BACKUPMANAGER_AES_KEY");
}

SecretKeySpec key = new SecretKeySpec(secretKey.getBytes(), "AES");

Cipher cipher = Cipher.getInstance("AES");
cipher.init(Cipher.DECRYPT_MODE, key);

byte[] decodedBytes = Base64.getDecoder().decode(encryptedPassword);
byte[] decrypted = cipher.doFinal(decodedBytes);

return new String(decrypted);
}

public static void main(String[] args) throws Exception {
String encryptedPassword = "password_to_decrypt";
String decryptedPassword = decrypt(encryptedPassword);
System.out.println("\n"+decryptedPassword);
}
}
23 changes: 12 additions & 11 deletions src/main/java/backupmanager/Email/EmailSender.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class EmailSender {

// Logger for sending critical error emails
private static final Logger emailErrorLogger = LoggerFactory.getLogger("EMAIL_ERROR_LOGGER");

// Logger for sending informational emails
private static final Logger emailInfoLogger = LoggerFactory.getLogger("EMAIL_INFO_LOGGER");

Expand All @@ -47,14 +47,15 @@ public static void sendErrorEmail(String subject, String body) {
logger.warn("User is null, using a default user for the email");
user = User.getDefaultUser();
}

int rows = 300;
String emailMessage = String.format(
"Subject: %s\n\nUser: %s \nEmail: %s \nLanguage: %s \n\nHas encountered the following error:\n%s \n\nLast %d rows of the application.log file:\n%s",
"Subject: %s\n\nUser: %s \nEmail: %s \nLanguage: %s \nInstalled Version: %s \n\nHas encountered the following error:\n%s \n\nLast %d rows of the application.log file:\n%s",
subject,
user.getUserCompleteName(),
user.email,
user.language,
ConfigKey.VERSION.getValue(),
body,
rows,
getTextFromLogFile(rows)
Expand All @@ -69,7 +70,7 @@ public static void sendErrorEmail(String subject, String body) {
* Sends an informational email.
*/
public static void sendUserCreationEmail(User user) {
String userDetails = "New user registered. \n\nName: " + user.getUserCompleteName()+ "\nEmail: " + user.email + "\nLanguage: " + user.language;
String userDetails = "New user registered. \n\nName: " + user.getUserCompleteName()+ "\nEmail: " + user.email + "\nLanguage: " + user.language + "\nInstalled version: " + ConfigKey.VERSION.getValue();

String emailMessage = "\n\n" + userDetails;

Expand All @@ -84,21 +85,21 @@ public static void sendUserCreationEmail(User user) {
*/
public static void sendConfirmEmailToUser(User user) {
if (user == null) throw new IllegalArgumentException("User object cannot be null");

String subject = TranslationCategory.USER_DIALOG.getTranslation(TranslationKey.EMAIL_CONFIRMATION_SUBJECT);
String body = TranslationCategory.USER_DIALOG.getTranslation(TranslationKey.EMAIL_CONFIRMATION_BODY);

// Assicurati di assegnare il risultato della sostituzione
body = body.replace("[UserName]", user.getUserCompleteName());
body = body.replace("[SupportEmail]", ConfigKey.EMAIL.getValue());

String emailMessage = subject + "\n\n" + body;

updateEmailRecipient(user.email);

// Should be info, but if you change it, it doesn't work
emailConfirmationLogger.error(emailMessage); // Log the message as INFO, triggering the SMTPAppender

logger.info("Confirmation registration email sent to the user: " + user.toString());
}

Expand All @@ -116,7 +117,7 @@ private static User getCurrentUser() {

return null;
}

public static String getTextFromLogFile(int rows) {
File file = new File(ConfigKey.LOG_DIRECTORY_STRING.getValue() + ConfigKey.LOG_FILE_STRING.getValue());

Expand Down Expand Up @@ -154,5 +155,5 @@ private static void updateEmailRecipient(String newRecipient) {
smtpAppender.getToList().clear();
smtpAppender.addTo(newRecipient);
}
}
}
}
22 changes: 22 additions & 0 deletions src/main/java/backupmanager/Email/EncryptPassword.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package backupmanager.Email;

import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;
import java.util.Base64;

public class EncryptPassword {
private static final String SECRET_KEY = "SecretKey16chars";

public static String encrypt(String password) throws Exception {
SecretKeySpec key = new SecretKeySpec(SECRET_KEY.getBytes(), "AES");
Cipher cipher = Cipher.getInstance("AES");
cipher.init(Cipher.ENCRYPT_MODE, key);
byte[] encrypted = cipher.doFinal(password.getBytes());

return Base64.getEncoder().encodeToString(encrypted);
}

public static void main(String[] args) throws Exception {
System.out.println("\n"+encrypt("PasswordToEncrypt"));
}
}
17 changes: 17 additions & 0 deletions src/main/java/backupmanager/Email/EncryptedPasswordDefiner.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package backupmanager.Email;

import ch.qos.logback.core.PropertyDefinerBase;

public class EncryptedPasswordDefiner extends PropertyDefinerBase {

@Override
public String getPropertyValue() {
try {
String encryptedPassword = System.getenv("BACKUPMANAGER_SMTP_PASSWORD");
return backupmanager.Email.DecryptPassword.decrypt(encryptedPassword);
} catch (Exception e) {
System.err.println("Error decrypting SMTP password: " + e.getMessage());
return "";
}
}
}
3 changes: 3 additions & 0 deletions src/main/resources/config.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
smtp.from=backupmanager@shardpc.it
smtp.smtp=mail.shardpc.it
smtp.user=backupmanager@shardpc.it
9 changes: 5 additions & 4 deletions src/main/resources/logback.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

<!--<statusListener class="ch.qos.logback.core.status.OnConsoleStatusListener" />--> <!--Scan this configuration for errors-->

<define name="smtpPassword" class="backupmanager.Email.EncryptedPasswordDefiner" />

<!-- Properties -->
<property resource="config.properties" />
<property name="smtp.user" value="${smtp.user}" />
<property name="smtp.from" value="${smtp.from}" />
<property name="smtp.password" value="${smtp.password}" />
<property name="smtp.host" value="${smtp.smtp}" />
<property name="smtp.email_confirmation_to" value="${smtp.email_confirmation_to}" />
<property name="EMAIL_TO" value="assistenza@shardpc.it" /> <!--test1@shardpc.it-->
Expand Down Expand Up @@ -64,7 +65,7 @@
<to>${EMAIL_TO}</to>
<from>${smtp.from}</from>
<username>${smtp.user}</username>
<password>${smtp.password}</password>
<password>${smtpPassword}</password>
<subject>${EMAIL_ERROR_SUBJECT}</subject>
<layout class="ch.qos.logback.classic.PatternLayout">
<pattern>%d{yyyy-MM-dd HH:mm:ss} %-5level %logger{36} - %msg%n</pattern>
Expand All @@ -82,7 +83,7 @@
<to>${EMAIL_TO}</to>
<from>${smtp.from}</from>
<username>${smtp.user}</username>
<password>${smtp.password}</password>
<password>${smtpPassword}</password>
<subject>${EMAIL_INFO_SUBJECT}</subject>
<layout class="ch.qos.logback.classic.PatternLayout">
<pattern>%d{yyyy-MM-dd HH:mm:ss} %logger{36} - %msg%n</pattern>
Expand All @@ -100,7 +101,7 @@
<to>${EMAIL_TO}</to>
<from>${smtp.from}</from>
<username>${smtp.user}</username>
<password>${smtp.password}</password>
<password>${smtpPassword}</password>
<subject>${EMAIL_CONFIRMATION_SUBJECT}</subject>
<layout class="ch.qos.logback.classic.PatternLayout">
<pattern>%msg%n</pattern>
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/res/backup_list2.0.6.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
6 changes: 3 additions & 3 deletions src/main/resources/res/config/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,18 @@
"EMAIL": "assistenza@shardpc.it",
"SHARD_WEBSITE": "https://www.shardpc.it/",
"LOGO_IMG": "/res/img/logo.png",
"VERSION": "2.0.5",
"VERSION": "2.0.6",
"GUI_WIDTH": "982",
"GUI_HEIGHT": "715",

"MenuItems": {
"BugReport": true,
"Preferences": true,
"Clear": false,
"Donate": false,
"Donate": true,
"PaypalDonate": true,
"BuymeacoffeeDonate": true,
"History": false,
"History": true,
"InfoPage": true,
"New": true,
"Quit": true,
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/res/config/preferences.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"Language":"eng.json","Theme":"Light"}
{"Language":"ita.json","Theme":"Light","BackupList":{"Directory":"src/main/resources/res/","File":"backup_list2.0.6.json"}}
1 change: 1 addition & 0 deletions src/main/resources/res/config/user.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"name":"dsasd","surname":"asdasd","email":"dsadas@gmail.comn"}
Binary file not shown.
Loading
Loading