Ready for version 1.1.2
PR for the main repository, version 1.1.2 with sms_tool as the major change
This commit is contained in:
@@ -1,52 +0,0 @@
|
||||
#!/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
|
||||
@@ -1,38 +0,0 @@
|
||||
#!/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 "}"
|
||||
@@ -1,64 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
# Send CGI headers first
|
||||
echo "Content-Type: application/json"
|
||||
echo "Cache-Control: no-cache"
|
||||
echo
|
||||
|
||||
# Initialize variables for file paths
|
||||
APN_SCRIPT="/etc/quecmanager/apn_profile/apnProfiles.sh"
|
||||
IMEI_SCRIPT="/etc/quecmanager/imei_profile/imeiProfiles.sh"
|
||||
|
||||
# Function to output JSON
|
||||
output_json() {
|
||||
local status="$1"
|
||||
local message="$2"
|
||||
echo "{\"status\": \"$status\", \"message\": \"$message\"}"
|
||||
}
|
||||
|
||||
# Function to execute script if it exists
|
||||
execute_if_exists() {
|
||||
local script_path="$1"
|
||||
|
||||
if [ -f "$script_path" ] && [ -x "$script_path" ]; then
|
||||
$script_path >/dev/null 2>&1
|
||||
return $?
|
||||
fi
|
||||
return 2
|
||||
}
|
||||
|
||||
# Main execution
|
||||
main() {
|
||||
scripts_executed=0
|
||||
has_error=0
|
||||
|
||||
# Try to execute APN script
|
||||
execute_if_exists "$APN_SCRIPT"
|
||||
apn_result=$?
|
||||
if [ $apn_result -eq 0 ]; then
|
||||
scripts_executed=$(($scripts_executed + 1))
|
||||
elif [ $apn_result -eq 1 ]; then
|
||||
has_error=1
|
||||
fi
|
||||
|
||||
# Try to execute IMEI script
|
||||
execute_if_exists "$IMEI_SCRIPT"
|
||||
imei_result=$?
|
||||
if [ $imei_result -eq 0 ]; then
|
||||
scripts_executed=$(($scripts_executed + 1))
|
||||
elif [ $imei_result -eq 1 ]; then
|
||||
has_error=1
|
||||
fi
|
||||
|
||||
# Output appropriate message based on results
|
||||
if [ $scripts_executed -eq 0 ]; then
|
||||
output_json "info" "No scripts to restart"
|
||||
elif [ $has_error -eq 1 ]; then
|
||||
output_json "error" "Error executing one or more scripts"
|
||||
else
|
||||
output_json "success" "Scripts restarted successfully"
|
||||
fi
|
||||
}
|
||||
|
||||
# Run main function
|
||||
main
|
||||
@@ -1,11 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
# Set the content type to JSON
|
||||
echo "Content-Type: application/json"
|
||||
echo ""
|
||||
|
||||
# Get the IP address of the br-lan interface
|
||||
brlan_ip=$(ip route | grep 'dev br-lan proto kernel scope link' | awk '{print $9}')
|
||||
|
||||
# Output the IP in JSON format
|
||||
echo "{\"br_lan_ip\": \"$brlan_ip\"}"
|
||||
@@ -1,29 +0,0 @@
|
||||
#!/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