initial test release for quecmanager-beta
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
#!/bin/sh
|
||||
|
||||
# Set Content-Type for CGI script
|
||||
echo "Content-type: application/json"
|
||||
echo ""
|
||||
|
||||
# Read POST data
|
||||
read POST_DATA
|
||||
|
||||
# Debug log
|
||||
DEBUG_LOG="/tmp/password_change.log"
|
||||
|
||||
# Extract the passwords from POST data
|
||||
OLD_PASSWORD=$(echo "$POST_DATA" | sed -n 's/^.*oldPassword=\([^&]*\).*$/\1/p')
|
||||
NEW_PASSWORD=$(echo "$POST_DATA" | sed -n 's/^.*newPassword=\([^&]*\).*$/\1/p')
|
||||
|
||||
# URL-decode the passwords
|
||||
OLD_PASSWORD=$(echo "$OLD_PASSWORD" | sed 's/+/ /g;s/%\(..\)/\\x\1/g' | xargs -0 printf "%b")
|
||||
NEW_PASSWORD=$(echo "$NEW_PASSWORD" | sed 's/+/ /g;s/%\(..\)/\\x\1/g' | xargs -0 printf "%b")
|
||||
|
||||
# User to change password for
|
||||
USER="root"
|
||||
|
||||
# Verify old password first
|
||||
USER_SHADOW_ENTRY=$(grep "^$USER:" /etc/shadow)
|
||||
if [ -z "$USER_SHADOW_ENTRY" ]; then
|
||||
echo '{"state":"failed", "message":"User not found"}'
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Extract current password hash and salt
|
||||
USER_HASH=$(echo "$USER_SHADOW_ENTRY" | cut -d: -f2)
|
||||
SALT=$(echo "$USER_HASH" | cut -d'$' -f3)
|
||||
|
||||
# Generate hash from old password
|
||||
OLD_GENERATED_HASH=$(echo "$OLD_PASSWORD" | openssl passwd -1 -salt "$SALT" -stdin)
|
||||
|
||||
# Verify old password
|
||||
if [ "$OLD_GENERATED_HASH" != "$USER_HASH" ]; then
|
||||
echo '{"state":"failed", "message":"Current password is incorrect"}'
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Change password using passwd command
|
||||
# We need to pass both the new password and its confirmation
|
||||
(echo "$NEW_PASSWORD"; echo "$NEW_PASSWORD") | passwd $USER 2>> $DEBUG_LOG
|
||||
|
||||
if [ $? -eq 0 ]; then
|
||||
echo '{"state":"success", "message":"Password changed successfully"}'
|
||||
else
|
||||
echo '{"state":"failed", "message":"Failed to change password"}'
|
||||
fi
|
||||
@@ -0,0 +1,38 @@
|
||||
#!/bin/sh
|
||||
# Set the content type to JSON
|
||||
echo "Content-Type: application/json"
|
||||
echo ""
|
||||
|
||||
# Configuration file path
|
||||
CONFIG_FILE="/etc/quecManager.conf"
|
||||
|
||||
# Check if the config file exists
|
||||
if [ ! -f "$CONFIG_FILE" ]; then
|
||||
echo '{"error": "Configuration file not found"}'
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Initialize variables
|
||||
AT_PORT=""
|
||||
AT_PORT_CUSTOM=""
|
||||
DATA_REFRESH_RATE=""
|
||||
|
||||
# Read the config file line by line and extract values
|
||||
while IFS='=' read -r key value; do
|
||||
# Remove leading/trailing whitespace
|
||||
key=$(echo "$key" | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')
|
||||
value=$(echo "$value" | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')
|
||||
|
||||
case "$key" in
|
||||
"AT_port") AT_PORT="$value" ;;
|
||||
"AT_port_custom") AT_PORT_CUSTOM="$value" ;;
|
||||
"data_refresh_rate") DATA_REFRESH_RATE="$value" ;;
|
||||
esac
|
||||
done <"$CONFIG_FILE"
|
||||
|
||||
# Output JSON
|
||||
echo "{"
|
||||
echo " \"AT_port\": \"$AT_PORT\","
|
||||
echo " \"AT_port_custom\": \"$AT_PORT_CUSTOM\","
|
||||
echo " \"data_refresh_rate\": $DATA_REFRESH_RATE"
|
||||
echo "}"
|
||||
@@ -0,0 +1,29 @@
|
||||
#!/bin/sh
|
||||
# save-config.sh
|
||||
echo "Content-Type: application/json"
|
||||
echo ""
|
||||
|
||||
# Read POST data
|
||||
read -n $CONTENT_LENGTH POST_DATA
|
||||
|
||||
# Configuration file path
|
||||
CONFIG_FILE="/etc/quecManager.conf"
|
||||
|
||||
# Parse JSON input and update config file
|
||||
AT_PORT=$(echo "$POST_DATA" | grep -o '"AT_port":"[^"]*"' | cut -d'"' -f4)
|
||||
AT_PORT_CUSTOM=$(echo "$POST_DATA" | grep -o '"AT_port_custom":"[^"]*"' | cut -d'"' -f4)
|
||||
DATA_REFRESH_RATE=$(echo "$POST_DATA" | grep -o '"data_refresh_rate":"[^"]*"' | cut -d'"' -f4)
|
||||
|
||||
# Create new config content
|
||||
cat > "$CONFIG_FILE" << EOF
|
||||
AT_port = $AT_PORT
|
||||
AT_port_custom = $AT_PORT_CUSTOM
|
||||
data_refresh_rate = $DATA_REFRESH_RATE
|
||||
EOF
|
||||
|
||||
# Check if write was successful
|
||||
if [ $? -eq 0 ]; then
|
||||
echo '{"success": true, "message": "Configuration saved successfully"}'
|
||||
else
|
||||
echo '{"success": false, "error": "Failed to save configuration"}'
|
||||
fi
|
||||
Reference in New Issue
Block a user