perl << 'EOF'
use strict;
my $filepath = "filepath_placeholder";
sub parse_folder {
        my $abspath = shift;
        my $homepattern = '^\/home\d?\/[a-z][a-z0-9]*\/public_html\/';
        my @patterns = (
                # Likely wordpress paths
                '(.+?)\/(wp\-(?:admin|content|includes)\/.+)',
                '(.+?)\/(wp\-[\w-]+\.php)',
                '(.+?)\/((?:xmlrpc|index)\.php|license\.txt|readme\.html)',

                # Likely Joomla patterns
                '(.+?)\/((?:administrator|cli|components|images|includes|installation|language)\/.+)',
                '(.+?)\/((?:layouts|libraries|media|modules|plugins|templates)\/.+)',
                '(.+?)\/((?:bin|cache)\/(?:index.html|keychain\.php))',
                '(.+?)\/((?:htaccess|README|LICENSE|web\.config)\.txt|robots\.txt\.dist)'
        );

        if($abspath=~/$homepattern/){
                foreach(@patterns){
                        return ($1, $2) if($abspath=~/$_/);
                }
        }
        die("Unknown path tokens");
}

die("sak-cli not found") unless(-x '/root/bin/sak-cli');
my($dir, $file) = parse_folder($filepath);
die($dir." does not exist") unless(-d $dir);
die("Cannot change: ".$1) unless chdir($dir);
system('/root/bin/sak-cli', 'replace', $file);
EOF
