CHips L MINI SHELL

CHips L pro

Current Path : /proc/self/root/proc/2/root/usr/local/rvglobalsoft/rvsitebuilder7/etc/
Upload File :
Current File : //proc/self/root/proc/2/root/usr/local/rvglobalsoft/rvsitebuilder7/etc/install.pl

#!/usr/bin/perl
use strict;
use warnings;
use Getopt::Long;
use Sys::Hostname;

my $modulename = '';

GetOptions(
    "module=s"=> \$modulename
);

my %allowModule = (
    'rvskinallcp' => 1,
    'rvexploit' => 1,
);

if($modulename eq '') {
    print "Not found module\n\n";
    exit;
}
if(!exists $allowModule{$modulename}){
    print "Module $modulename is not allow\n\n";
    exit;
}

my $production = 0;

my $servername = hostname;

my $rvglobalPath = '/usr/local/rvglobalsoft';
my $programPath  = sprintf('%s/%s', $rvglobalPath, $modulename);
my $downloadPath = sprintf('%s/.download', $rvglobalPath);
my $varPath      = sprintf('%s/var', $programPath);

#check license

#/usr/local/rvglobalsoft/.download
#/usr/local/rvglobalsoft/.download/rvexploit/* (svn://192.168.1.1/trunk/RvFramework)

#/usr/local/rvglobalsoft/rvframework (perl framework)
#
#/usr/local/rvglobalsoft/rvexploit/
#                                modules/
#                                       exploitscanner/*
#                                       default -> ../../rvframework/modules/default
#                                panelmenu
#                                public_html -> ../../sdjklfsdjkj

#create path structure
mkdir($rvglobalPath) if (!-e $rvglobalPath);
mkdir($programPath)  if (!-e $programPath);
mkdir($downloadPath) if (!-e $downloadPath);
mkdir($varPath)      if (!-e $varPath);

#download package
if ($production == 1) {
    #download xxx.tar.bz2
} else {
    svnexportmodule($rvglobalPath, $modulename);
}

#sync to program path
if(!-e "$downloadPath/$modulename"){
    print "Not found $downloadPath/$modulename \n\n";
    exit;
}    
system2("cp \"-af\" $downloadPath/$modulename/* $programPath/ 2>&1");

#setup framework dependencies
system2("perl $programPath/etc/buildcpan.pl 2>&1");

#setting admin menu
system2("cp \"-f\" $downloadPath/$downloadPath/panelmenu/cpanel/whm/addon_rvexploit.cgi /usr/local/cpanel/whostmgr/docroot/cgi/addon_rvexploit.cgi 2>&1");
symlinkIfNotExists("$programPath/public_html", '/usr/local/cpanel/whostmgr/docroot/cgi/rvexploit');

#setting cpan path
updateCpanPath($programPath);

#setting ip config
if (!-e $programPath . '/var/' . $servername . '.yaml') {
    print '###############################################################' . "\n\n";
    print
"please copy '$programPath/etc/default.conf.dist.yaml'\n\tto  '$programPath/var/$servername.yaml' and fill the correct sql data\n\n";
    print '###############################################################' . "\n";
}

#setting permission
if (-e "$programPath/lib/perl5") {
    chmod(0755, "$programPath/lib/perl5");
}
if (-e "$programPath/public_html/index.pl") {
    chmod(0755, "$programPath/public_html/index.pl");
}
if ("/usr/local/cpanel/whostmgr/docroot/cgi/addon_rvexploit.cgi") {
    chmod(0755, "/usr/local/cpanel/whostmgr/docroot/cgi/addon_rvexploit.cgi");
}



####################
# utility function #
####################
sub system2 {
    my $cmd = $_[0];
    print "[ EXEC : $cmd ]\n";
    system($cmd);
}
sub svnexportmodule {
    my ($rvglobalPath, $modulename) = @_;

    #my $conf = parseIniFile('/root/rvframeworkconf.ini');
    my $svnbin = whichCmd('svn');
    my $svnReposUri = 'svn://local2.webexperts.co.th';
    my $svnUser        = 'amarin';
    my $svnPass        = 'gvlwvgv=5487';
    my $cmd            = '';
    my $svnLoginpOtion = sprintf('--username %s --password %s', $svnUser, $svnPass);

    #export framework
    my $svnPath = 'trunk/RvFramework';

    #$svnPath = 'trunk/rvmodules';
    my $targetPath = sprintf('%s/.download/%s', $rvglobalPath, $modulename);
    $cmd = sprintf('%s export --force %s %s/%s %s 2>&1', $svnbin, $svnLoginpOtion, $svnReposUri, $svnPath, $targetPath);
    system2($cmd);

    #export module
    $svnPath = 'trunk/' . $modulename;
    if($modulename eq 'rvexploit'){
        $svnPath = 'trunk/rvmodules';    
    }
    $cmd = sprintf('%s export --force %s %s/%s %s 2>&1', $svnbin, $svnLoginpOtion, $svnReposUri, $svnPath, $targetPath);
    system2($cmd);
}

sub updateCpanPath {
    my $programPath = $_[0];

    if (open(my $fh, '<', $programPath . '/public_html/index.pl')) {
        my @data = <$fh>;
        close($fh);
    
        my $strData = join('', @data);
    
        my $find    = '@CPAN\-PATH@';
        my $replace = "$programPath/lib/perl5";
    
        $strData =~ s/$find/$replace/g;
        if (open(my $wh, '>', $programPath . '/public_html/index.pl')) {
            print $wh $strData;
            close($wh);
            print "update $programPath/public_html/index.pl complete..\n";
        }
    }
}

sub symlinkIfNotExists {
    my ($target, $link) = @_;

    if (-e $target && !-e $link) {
        symlink($target, $link);
    }
}

sub whichCmd {
    my ($cmd) = $_[0];
    return if ($cmd eq '');
    return if ($cmd =~ /\//);

    my $whichCmd    = '';
    my $binpath     = '';
    my @binpathList = ('/bin', '/usr/bin', '/usr/local/bin', '/sbin', '/usr/sbin', '/usr/local/sbin');

    foreach my $path (@binpathList) {
        if (-x $path . '/' . 'which') {
            $whichCmd = $path . '/' . 'which';
            last;
        }
    }
    if ($whichCmd eq '') {

        print('which command is not support.');
        return $binpath;
    }

    $binpath = callBackticks("$whichCmd $cmd");
    chomp($binpath);
    $binpath =~ s/\n|\r//gi;

    if ($binpath eq '') {
        foreach my $path (@binpathList) {
            if (-x $path . '/' . $cmd) {
                $binpath = $path . '/' . $cmd;
                last;
            }
        }
    }

    if ($binpath eq '') {
        print($cmd . ' is not support.');
    } elsif (!-x $binpath) {
        print($cmd . ' is not executeable.');
    }

    return $binpath;
}

sub callBackticks {
    my $cmd = $_[0];
    return `$cmd`;
}

=pod

usage:
    perl /root/rvglobalsoft/install.pl -module=rvexploit

flow:
1. create path structure

    mkdir /usr/local/rvglobalsoft
    
    mkdir /usr/local/rvglobalsoft/.download    

2. download source code to /usr/local/rvglobalsoft/.download/rvframework

3. download source code to /usr/local/rvglobalsoft/.download/rvexploit

4. sync /usr/local/rvglobalsoft/.download/rvframework to /usr/local/rvglobalsoft/rvexploit

5. sync /usr/local/rvglobalsoft/.download/rvexploit/modules/exploitscanner to /usr/local/rvglobalsoft/rvexploit/modules/exploitscanner

/usr/local/rvglobalsoft/rvexploit
    bin/
    etc/
    lib/
    man/
    modules/
        default
        exploitscanner
        translation
        user
    public_html/
    README
    tests/
    var/

6. setup framework
    install cpan module for framework
        perl /usr/local/rvglobalsoft/rvexploit/etc/buildcpan.pl

7. setup module
    install cpan module for module    
        perl /usr/local/rvglobalsoft/rvexploit/modules/exploitscanner/etc/buildcpan.pl    

8. setting cpan path
    public_html/index.pl   @CPAN-PATH@
   
    
9. cp admin menu
    ln -s /usr/local/cpanel/whostmgr/docroot/cgi/rvexploit /usr/local/rvglobalsoft/rvexploit/public_html
    sync /usr/local/rvglobalsoft/.temp/rvexploit/panelmenu/cpanel/whm/addon_rvexploit.cgi /usr/local/cpanel/whostmgr/docroot/cgi/addon_rvexploit.cgi
    
10. setting permmisson   
    chmod 755 /usr/local/rvglobalsoft/rvexploit/public_html/index.pl
    chmod 755 /usr/local/cpanel/whostmgr/docroot/cgi/addon_rvexploit.cgi    
    
=cut

Copyright 2K16 - 2K18 Indonesian Hacker Rulez