Author Topic: Permission issue after cwppro update  (Read 30 times)

0 Members and 1 Guest are viewing this topic.

Offline
*
Permission issue after cwppro update
« on: December 20, 2024, 01:59:44 PM »
I use cwppro with a custom codeEditor.php I created:
Code: [Select]
https://github.com/JosephChuks/cwp-codeEditor as I find the default codeEditor not up to what I want.

I changed it for admin and user respectively:
Code: [Select]
/usr/local/cwpsrv/htdocs/admin/admin/codeEditor.php and
Code: [Select]
/usr/local/cwpsrv/var/services/users/codeEditor.php and it has been working fine until the recent cwppro update. Although I created a script to overwrite the default cwppro codeEditor.php any time there's an update:

Code: [Select]
#!/bin/bash

# Paths
ORIGINAL_FILES_ADMIN="/usr/local/cwpsrv/htdocs/admin/admin/codeEditor.php"
ORIGINAL_FILES_USER="/usr/local/cwpsrv/var/services/users/codeEditor.php"
CUSTOM_FILE="/root/codeEditor.php"

# Log file
LOG_FILE="/var/log/code_editor_restore.log"

# Function to restore admin file
restore_admin_file() {
    local original_file="$1"
    if [ ! -f "$original_file" ] || [ "$(stat -c%s "$original_file")" -ne "$(stat -c%s "$CUSTOM_FILE")" ]; then
        echo "$(date) - $original_file was overwritten. Restoring custom version." >> "$LOG_FILE"
        cp "$CUSTOM_FILE" "$original_file"
        chown root:root "$original_file"
        chmod 644 "$original_file"
    fi
}

# Function to restore user file
restore_user_file() {
    local original_file="$1"
    if [ ! -f "$original_file" ] || [ "$(stat -c%s "$original_file")" -ne "$(stat -c%s "$CUSTOM_FILE")" ]; then
        echo "$(date) - $original_file was overwritten. Restoring custom version." >> "$LOG_FILE"
        cp "$CUSTOM_FILE" "$original_file"
        chown cwpsvc:cwpsvc "$original_file"
        chmod 644 "$original_file"
    fi
}

# Restore files
restore_admin_file "$ORIGINAL_FILES_ADMIN"
restore_user_file "$ORIGINAL_FILES_USER"

The script works fine as it did the job of overwriting the default codeEditor after the update for user:
Code: [Select]
/usr/local/cwpsrv/var/services/users/codeEditor.php  but throws a permission error for the admin:

Code: [Select]
cp: cannot create regular file '/usr/local/cwpsrv/htdocs/admin/admin/codeEditor.php': Operation not permitted
chown: changing ownership of '/usr/local/cwpsrv/htdocs/admin/admin/codeEditor.php': Operation not permitted
chmod: changing permissions of '/usr/local/cwpsrv/htdocs/admin/admin/codeEditor.php': Operation not permitted

Offline
*
Re: Permission issue after cwppro update
« Reply #1 on: December 20, 2024, 02:43:36 PM »
Problem fixed.

I had to create a script to copy /usr/local/cwpsrv/htdocs to /root and then replace codeEditor.php and move back to /usr/local/cwpsrv/htdocs