HEX
Server: LiteSpeed
System: Linux CentOS-79-64-minimal 3.10.0-1160.119.1.el7.x86_64 #1 SMP Tue Jun 4 14:43:51 UTC 2024 x86_64
User: vishn3436 (5293)
PHP: 8.0.15
Disabled: NONE
Upload Files
File: //data/fileMonitor/checkFileChange.sh-singleFile
#!/bin/bash

# Configuration
FILE="index.php"                      # File to monitor
RECORD_FILE="mod_time_record.log"    # File to store previous hash and modification time

# Check if file exists
if [[ ! -f "$FILE" ]]; then
    echo "Error: $FILE does not exist!"
    exit 1
fi

# Get current hash and modification time
CURRENT_HASH=$(sha256sum "$FILE" | awk '{print $1}')
CURRENT_MOD_TIME=$(stat -c %y "$FILE")

# Initialize record file if it doesn't exist
if [[ ! -f "$RECORD_FILE" ]]; then
    echo "$CURRENT_HASH|$CURRENT_MOD_TIME" > "$RECORD_FILE"
    echo "Monitoring started. Initial values recorded."
    exit 0
fi

# Read last record
IFS="|" read LAST_HASH LAST_MOD_TIME < "$RECORD_FILE"

# Check for changes
if [[ "$CURRENT_HASH" != "$LAST_HASH" ]]; then
    echo "File changed!"
    echo "Last Modification Time: $LAST_MOD_TIME"
    echo "Current Modification Time: $CURRENT_MOD_TIME"

   # Send notification via static curl command
    curl --location --request POST 'https://marketing.wp.karmanye.in/api/Karmanye/send-message' \
        --header 'Content-Type: application/json; charset=utf-8' \
        --header 'Accept: application/json' \
        --header 'Authorization: Bearer $2b$10$f7yAQHm3Y1eOxs92aiEJ9eohJ0AdUQ2YwXxUARzk3sVLgKIVw0k2q' \
        -d "{
            \"phone\": \"919033595842\",
            \"message\": \"🚨 *Security Alert: File Change Detected* 🚨\n\nšŸ“‚ *File*: index.php\nšŸ”‘ *Previous Modification Time*: \`$LAST_MOD_TIME\`\nšŸ†• *Current Modification Time*: \`$CURRENT_MOD_TIME\`\n\nāš ļø *Immediate Attention Required!*\n\nPlease verify the change to ensure it's authorized.\"
        }"

    # Update the record file
    echo "$CURRENT_HASH|$CURRENT_MOD_TIME" > "$RECORD_FILE"
else
    echo "No changes detected."
fi