MOON
Server: Apache
System: Linux server.cny.com.sg 4.18.0-477.21.1.el8_8.x86_64 #1 SMP Thu Aug 10 13:51:50 EDT 2023 x86_64
User: tissuegurucom (1020)
PHP: 8.1.29
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //bin/perms
#!/bin/bash
SC="Permissionairy"
VSN=".0991"
UN=$(pwd | cut -d / -f3)

print() { printf "[${blue}+${NC}] $* \n" ; }

declare -x blue='\e[0;34m'
declare -x NC='\e[0m'

error() {
                print "If you believe this to be an error, please email jacob.perkins@arvixe.com"
		print "with details of the errors, what you did, and how he can get the error"
                print "and when he stops drinking, he will fix this bad-boy up"
		quit
}

quit() {
	print "[Peace, I'm outtie!]" 
	echo $1
	exit 2
}

pre_checks() {
        print "$SC $VSN By Perk"
        #DSO Check
        if [[ $(/usr/local/cpanel/bin/rebuild_phpconf --current | grep dso) =~ "PHP[4-5][ \t]+SAPI:[ \t]dso" ]]; then
                print "ALERT!  This server is DSO.  Do not run this script with this PHP Configuration"
                error
	fi
        if [[ $(pwd) =~ "^(/root|/bin|/usr|/var|/boot|/tmp|/dev|/home$)" ]]; then
                print "You are in $(pwd).  Do not run this script here " 
		error
	fi
}

user_check() {
        if [ ! -f /var/cpanel/users/${UN} ]; then
                print "User doesn't exist, exiting"
                error
        fi
}

public_html_check(){
	if [ ! -d /home/${UN}/public_html ]; then
	print "Public_html doesn't exist, creating it"
                mkdir /home/${UN}/public_html; fi
}


public_html_perms(){
       cd /home/${UN}/public_html
        print "Fixing 755 Permissions in /home/${UN}/public_html"
                find -type d -exec chmod 755 '{}' \;
        print "Fixing 644 Permissions in /home/${UN}/public_html"
                find -type f -exec chmod 644 '{}' \;
        print "Fixing Executable Permissions in /home/${UN}/public_html"
                find -iname "*.pl" -exec chmod 755 '{}' \; -o -iname "*.cgi" -exec chmod 755 '{}' \; -o -iname "*.fcgi" -exec chmod 755 '{}' \;
        print "Chowning"
                chown ${UN}. -R .
}


htpass_fix(){
	if [ -d /home/${UN}/.htpasswds ]; then
                print "Fixing ${UN}'s .htpasswds file & Misc"
                chown ${UN}.nobody /home/${UN}/.htpasswds && chmod 750 /home/${UN}/.htpasswds
        fi
}


home_fix(){
        print "Fixing ${UN}'s public_html and home Folder"
                chmod 711 /home/${UN}
                chown ${UN}.${UN} /home/${UN} -R > /dev/null 2>&1
                chmod 750 /home/${UN}/public_html
                chown ${UN}.nobody /home/${UN}/public_html
        if [ ! -L /home/${UN}/www ]; then
                cd /home/${UN}
                print "Fixing ${UN}'s www Symlink"
                ln -s public_html www
        fi
}


pass_shadow_quota_fix(){
	print "Fixing /home/${UN}/etc/* passwd, shadow and quota files"
                chown ${UN}.mail /home/${UN}/etc/
		find /home/${UN}/etc/ -maxdepth 1 -type d -exec chown ${UN}.mail '{}' \;
		chown ${UN}.${UN} /home/${UN}/etc/quota > /dev/null 2>&1 && chmod 644 /home/${UN}/etc/quota > /dev/null 2>&1
		chown ${UN}.mail /home/${UN}/etc/shadow > /dev/null 2>&1 && chmod 600 /home/${UN}/etc/shadow > /dev/null 2>&1
                chown ${UN}.mail /home/${UN}/etc/passwd > /dev/null 2>&1 && chmod 644 /home/${UN}/etc/passwd > /dev/null 2>&1
	for shad in `ls /home/${UN}/etc/*/shadow`;do
                        chown ${UN}.mail $shad && chmod 640 $shad; done > /dev/null 2>&1
        for quot in `ls /home/${UN}/etc/*/quota` ;do
                        chown ${UN}.${UN} $quot && chmod 644 $quot; done > /dev/null 2>&1
        for pawd in `ls /home/${UN}/etc/*/passwd`;do
                        chown ${UN}.mail $pawd && chmod 644 $pawd; done > /dev/null 2>&1
}


fix_mail_perms(){
	print "Fixing Mail Perms for ${UN}"
	/scripts/mailperm ${UN} > /dev/null 2>&1
}

fix_fantastico_perms(){
	if [ -d /home/${UN}/.fantasticodata ]; then
	print "Fixing Fantastico Perms"
	cd /home/${UN}/.fantasticodata
	find -type d -exec chmod 750 {} \;
	fi
}

fix_addon_docroot(){
        print "Fixing Domain doc_root's"
        for addonroot in $(grep "/home/${UN}" "/usr/local/apache/conf/httpd.conf" | grep DocumentRoot | awk '{print $2}');do
                if [[ -d ${addonroot} ]]; then
			if [[ ${addonroot} != $PUB_HTML ]]; then
		                chmod 755 ${addonroot} > /dev/null 2>&1
                	fi
		fi
        done
}


pre_checks
user_check
public_html_check
public_html_perms
home_fix
htpass_fix
pass_shadow_quota_fix
fix_fantastico_perms
fix_mail_perms
fix_addon_docroot
quit