Skip to content

pushing dev changes to production after test #22

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

Merged
merged 7 commits into from
Sep 13, 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
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ flask-session==0.8.0 # Server-side session handling for Flask
# File system monitoring and watching
watchdog==5.0.2

#
requests
# python requests library for making HTTP requests
requests==2.32.3
19 changes: 11 additions & 8 deletions setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -300,10 +300,7 @@ add_cron_job() {
local cron_job="* * * * * /bin/bash $script_path >> $log_dir/$APP_NAME_LOWER-cron.log 2>&1"

# Create log directory with error handling
if [ $? -ne 0 ]; then
log "CRITICAL" "Failed to create log directory: $log_dir"
exit 1
fi
create_dir "$log_dir"


# Temporarily store current crontab to avoid overwriting on error
Expand All @@ -314,10 +311,16 @@ add_cron_job() {
fi

# List the current crontab
if ! $crontab_cmd -l 2>/dev/null > "$temp_cron"; then
log "CRITICAL" "Unable to list current crontab."
rm "$temp_cron"
exit 1
if ! $crontab_cmd -l > "$temp_cron" 2>&1; then
# If no crontab exists, create an empty file
if grep -q "no crontab for" "$temp_cron" 2>/dev/null; then
: > "$temp_cron" # Create an empty file
log "No crontab for user $USER_NAME. Creating new crontab."
else
log "CRITICAL" "Unable to list current crontab."
rm "$temp_cron"
exit 1
fi
fi

# Ensure the cron job does not already exist
Expand Down
2 changes: 1 addition & 1 deletion src/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
DESCRIPTION = f"{APP_NAME} is a web application that allows you to monitor your system resources."
AUTHOR = "Deepak Raj"
YEAR = "2024"
VERSION = "v1.0.4-pre-release"
VERSION = "v1.0.4"
PROJECT_URL = f"https://github.com/codeperfectplus/{APP_NAME}"
CONTACT_EMAIL = ""
SYSTEM_NAME = get_system_node_name()
Expand Down
2 changes: 1 addition & 1 deletion src/docs/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ systemguard-installer --help

| Version | Release Date | Status | Key Features |
| ---------- | ------------ | ----------- | --------------------------------------------------- |
| v1.0.4 | - | In Testing | Stable version of pre-release features |
| v1.0.4 | 13/09/2024 | Stable | Stable version of pre-release features, stability |
| v1.0.4-pre | 10/09/2024 | Pre-release | Auto-update, website monitoring, graph improvements |
| v1.0.3 | 05/09/2024 | Stable | Performance optimization, CPU graphs, bug fixes |
| v1.0.2 | 02/09/2024 | Deprecated | Minor fixes, initial graph improvements |
Expand Down
55 changes: 54 additions & 1 deletion src/routes/settings.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import os
import time
import datetime
from flask import render_template, request, flash, blueprints, redirect, url_for
import subprocess
from flask import render_template, request, flash, blueprints, redirect, url_for, Response, session

from src.config import app, db
from src.models import UserCardSettings, UserDashboardSettings, UserProfile, GeneralSettings, PageToggleSettings
Expand Down Expand Up @@ -112,3 +114,54 @@ def settings():
return render_template("error/403.html")

return render_template("settings/settings.html", settings=settings)

def check_sudo_password(sudo_password):
"""
Verify the given sudo password by executing a harmless sudo command.
If the password is correct, it returns True. Otherwise, returns False.

:param sudo_password: The user's sudo password to validate.
:return: True if the password is correct, otherwise False.
"""
try:
# Test if the sudo password is valid by running a safe sudo command
result = subprocess.run(
['sudo', '-S', 'true'],
input=f'{sudo_password}\n',
text=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE
)
return result.returncode == 0

except Exception as e:
# Log any exception that occurs while validating the sudo password
return False, str(e)

@app.route('/control', methods=['GET', 'POST'])
def control():
if request.method == 'POST':
action = request.form.get('action')
sudo_password = request.form.get('sudo_password', '')

if action == 'shutdown':
command = ['sudo', '-S', 'shutdown', '-h', 'now']
success_message = "Server is shutting down..."
error_message = "Failed to shutdown: {}"
elif action == 'reboot':
command = ['sudo', '-S', 'reboot']
success_message = "Server is rebooting..."
error_message = "Failed to reboot: {}"
else:
flash("Invalid action!", 'danger')
return redirect(url_for('control'))

try:
# Execute the command with the sudo password
result = subprocess.run(command, input=sudo_password.encode(), check=True, capture_output=True, text=True)
flash(success_message, 'info')
except subprocess.CalledProcessError as e:
flash(error_message.format(e), 'danger')

# Render the control form on GET request
return render_template("settings/control.html")
59 changes: 59 additions & 0 deletions src/static/css/control.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
.title {
text-align: center;
margin-top: 50px;
font-size: 36px;
color: #333;
}

.container {
margin-top: 50px;
padding: 20px;
max-width: 500px;
background-color: #ffffff;
border-radius: 8px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}

h1 {
font-size: 24px;
margin-bottom: 20px;
color: #333;
}

.form-group {
margin-bottom: 20px;
}

.form-control {
padding: 10px;
font-size: 16px;
border-radius: 4px;
border: 1px solid #ced4da;
}

.btn {
padding: 10px 15px;
font-size: 16px;
border-radius: 4px;
margin-right: 10px;
transition: background-color 0.3s;
}

.btn-danger {
background-color: #dc3545;
border: none;
}

.btn-danger:hover {
background-color: #c82333;
}

.btn-warning {
background-color: #ffc107;
border: none;
color: #212529;
}

.btn-warning:hover {
background-color: #e0a800;
}
Loading