Merge pull request #2 from MugoSquero/feature-config

Adds support for configuring variables from a JSON file
This commit is contained in:
Yusuf İpek
2023-10-31 19:06:45 +03:00
committed by GitHub
4 changed files with 68 additions and 39 deletions
+20 -18
View File
@@ -23,31 +23,32 @@ Before using the script, you need to have the following prerequisites in place:
## Configuration ## Configuration
You need to configure the script with your SMTP server settings and email details. Open the script and modify the following variables in the "Configuration" section: You need to configure the config.json file with your SMTP server settings and email details. Open the config file and modify the following variables:
- `smtp_host`: SMTP server hostname. - `config.json`: JSON configuration file containing the following settings:
- `smtp_port`: SMTP server port. - `smtp_host`: SMTP server hostname.
- `smtp_user`: Your SMTP server username. - `smtp_port`: SMTP server port.
- `smtp_password`: Your SMTP server password. - `smtp_user`: Your SMTP server username.
- `from_email`: Your email address (the sender). - `smtp_password`: Your SMTP server password.
- `to_email`: Recipient's email address. - `from_email`: Your email address (the sender).
- `checkin_file`: Path to the check-in timestamp file. - `to_email`: Recipient's email address.
- `counter_file`: Path to the email counter file. - `checkin_file`: Path to the check-in timestamp file.
- `DAYS_REMINDER`: Number of days for the reminder period. - `counter_file`: Path to the email counter file.
- `DAYS_DEADMAN`: Number of days for the Dead Man's Switch activation. - `DAYS_REMINDER`: Number of days for the reminder period.
- `SECONDS_IN_A_DAY`: Number of seconds in a day. - `DAYS_DEADMAN`: Number of days for the Dead Man's Switch activation.
- `count_sent_mail`: Number of dead man mails to send after activation. - `SECONDS_IN_A_DAY`: Number of seconds in a day.
- `family_members`: List of family members' email addresses. - `count_sent_mail`: Number of dead man mails to send after activation.
- `files_to_attach`: List of files to attach to the emails. - `family_members`: List of family members' email addresses.
- `files_to_attach`: List of files to attach to the emails.
## Customization ## Customization
You can customize the email content by modifying the following variables in the script: You can customize the email content by modifying the following variables in the config:
- `reminder_subject`: Subject for the reminder email. - `reminder_subject`: Subject for the reminder email.
- `reminder_message`: Message for the reminder email. - `reminder_message`: Message for the reminder email.
- `dead_man_subject`: Subject for the Dead Man's Switch activation email. - `dead_man_activation_subject`: Subject for the Dead Man's Switch activation email.
- `dead_man_message`: Message for the Dead Man's Switch activation email. - `dead_man_activation_message`: Message for the Dead Man's Switch activation email.
## Usage ## Usage
@@ -65,6 +66,7 @@ You can customize the email content by modifying the following variables in the
- [Yusuf İpek](https://github.com/yusufipk) - [Yusuf İpek](https://github.com/yusufipk)
- [Koray Üstündağ](https://github.com/korayustundag) - [Koray Üstündağ](https://github.com/korayustundag)
- [Mugo Squero](https://github.com/MugoSquero)
## License ## License
This script is provided under the GPL-3.0 License. You are free to use, modify, and distribute it as needed. See the [LICENSE](https://github.com/yusufipk/dead-man-message/blob/master/LICENSE) file for details. This script is provided under the GPL-3.0 License. You are free to use, modify, and distribute it as needed. See the [LICENSE](https://github.com/yusufipk/dead-man-message/blob/master/LICENSE) file for details.
+1 -1
View File
@@ -1,4 +1,4 @@
#!/bin/bash #!/bin/bash
# Save the current timestamp to your checkin file # Save the current timestamp to your checkin file
date +%s > ./checkin_file.txt date +%s > "$(jq -r .checkin_file config.json)"
echo "Checked in" echo "Checked in"
+25 -20
View File
@@ -4,33 +4,38 @@ from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText from email.mime.text import MIMEText
from email.mime.base import MIMEBase from email.mime.base import MIMEBase
from email import encoders from email import encoders
import json
# Load configuration from JSON file
with open('config.json', 'r') as config_file:
config = json.load(config_file)
# Configuration # Configuration
smtp_host = 'your_smpt_server' # SMTP server hostname smtp_host = config['smtp_host'] # SMTP server hostname
smtp_port = 587 # SMTP server port smtp_port = config['smtp_port'] # SMTP server port
smtp_user = 'username' # SMTP server username smtp_user = config['smtp_user'] # SMTP server username
smtp_password = 'password' # SMTP server password smtp_password = config['smtp_password'] # SMTP server password
from_email = 'coming_from' # Sender's email address from_email = config['from_email'] # Sender's email address
to_email = 'going_to' # Recipient's email address to_email = config['to_email'] # Recipient's email address
checkin_file = "./checkin_file.txt" # File path for check-in timestamp checkin_file = config['checkin_file'] # File path for check-in timestamp
counter_file = "./counter_file.txt" # File path for email counter counter_file = config['counter_file'] # File path for email counter
DAYS_REMINDER = 25 # Days for the reminder period DAYS_REMINDER = config['DAYS_REMINDER'] # Days for the reminder period
DAYS_DEADMAN = 30 # Days for the dead man's switch DAYS_DEADMAN = config['DAYS_DEADMAN'] # Days for the dead man's switch
SECONDS_IN_A_DAY = 86400 # Number of seconds in a day SECONDS_IN_A_DAY = config['SECONDS_IN_A_DAY'] # Number of seconds in a day
count_sent_mail = 7 # Number of dead man mails to send after activation. count_sent_mail = config['count_sent_mail'] # Number of dead man mails to send after activation.
family_members = ['[email protected]'] # List of family members' email addresses family_members = config['family_members'] # List of family members' email addresses
# Email content # Email content
reminder_subject = "REMINDER" # Subject for the reminder email reminder_subject = config['reminder_subject'] # Subject for the reminder email
reminder_message = "Please check-in" # Message for the reminder email reminder_message = config['reminder_message'] # Message for the reminder email
dead_man_activation_subject = "Dead Man's Switch Activated" # Subject for the activation email dead_man_activation_subject = config['dead_man_activation_subject'] # Subject for the activation email
dead_man_activation_message = "You forgot to check-in" # Message for the activation email dead_man_activation_message = config['dead_man_activation_message'] # Message for the activation email
dead_man_subject = "I Am Gone" # Subject for the dead man's switch email dead_man_subject = config['dead_man_subject'] # Subject for the dead man's switch email
dead_man_message = "I'm dead" # Message for the dead man's switch email dead_man_message = config['dead_man_message'] # Message for the dead man's switch email
files_to_attach = ['file.gpg'] # List of files to attach files_to_attach = config['files_to_attach'] # List of files to attach
# Function to send an email # Function to send an email
def send_email(subject, message, to, attachments=[]): def send_email(subject, message, to, attachments=[]):
+22
View File
@@ -0,0 +1,22 @@
{
"smtp_host": "your_smpt_server",
"smtp_port": 587,
"smtp_user": "username",
"smtp_password": "password",
"from_email": "coming_from",
"to_email": "going_to",
"checkin_file": "./checkin_file.txt",
"counter_file": "./counter_file.txt",
"DAYS_REMINDER": 25,
"DAYS_DEADMAN": 30,
"SECONDS_IN_A_DAY": 86400,
"count_sent_mail": 7,
"family_members": ["[email protected]"],
"reminder_subject": "REMINDER",
"reminder_message": "Please check-in",
"dead_man_activation_subject": "Dead Man's Switch Activated",
"dead_man_activation_message": "You forgot to check-in",
"dead_man_subject": "I Am Gone",
"dead_man_message": "I'm dead",
"files_to_attach": ["file.gpg"]
}