CHips L MINI SHELL

CHips L pro

Current Path : /proc/2/root/usr/local/rvglobalsoft/rvglobalsoftmanager/modules/
Upload File :
Current File : //proc/2/root/usr/local/rvglobalsoft/rvglobalsoftmanager/modules/ApiProcess.pm

#!/usr/bin/perl
package ApiProcess;
##LICENSE##

use strict;
use Carp;
use warnings;
use Cwd;
use Cwd 'realpath';
use File::Basename qw(&basename &dirname);
#use CGI ':standard';
use CGI;
use Data::Dumper;
use File::Basename;
use Socket;
use JSON;

use lib dirname(realpath(__FILE__));
use lib dirname(realpath(__FILE__)).'/lib';
use lib dirname(realpath(__FILE__)).'/modules';

use Template;

use RvglobalsoftManager qw($CONF);
use RvglobalsoftManager::Config();
use RvglobalsoftManager::Rvlibary();
use RvglobalsoftManager::ServerInfo();
use CPHandle;

use vars qw (@ISA @EXPORT_OK @EXPORT $PARAM $CONF $API);
require Exporter;
@ISA = qw(Exporter);
@EXPORT_OK = qw(
  $OUTPUT $ERROR $CONF $VERSIONCACHE
);
@EXPORT = qw(isSetupApiKey validateApiAction buildApiOutput mainApi _cmd_notprivilege);

$CONF->{CPHandle} = new CPHandle();

sub mainApi {
	#print "Content-Type: text/html; charset=utf-8\n\n";
	RvglobalsoftManager::buildHtmlPageHeader();
	$CONF->{CPHandle} = new CPHandle();
	RvglobalsoftManager::getParam();
	RvglobalsoftManager::getServerInfo();
	$API->{homeDir} = $CONF->{CPHandle}->getHomeDir();
	$API->{isRoot} = $CONF->{CPHandle}->isRoot();
	$API->{isReseller} = $CONF->{CPHandle}->isReseller();
	$API->{allowReseller} = $CONF->{CPHandle}->getAllowReseller();
	
	if(!$CONF->{CPHandle}->isRoot()){
		if(!$CONF->{CPHandle}->getAllowReseller()){
			$PARAM->{'action'} = 'notprivilege';
		}
	}
	validateApiAction();
	
	$API->{isSetupApiKey} = isSetupApiKey();
	buildApiOutput();
}

sub validateApiAction {
	$CONF->{baseUrl} = $CONF->{CPHandle}->getBaseUrl();
	my $action = (defined $PARAM->{'action'} && $PARAM->{'action'} ne '')?'_cmd_' . $PARAM->{'action'}:'_cmd_view';
	
	RvglobalsoftManager::rvDumper($action) if($CONF->{debug});
	RvglobalsoftManager::rvDumper($PARAM) if($CONF->{debug});
	
	if(function_exists($action)){
		print "eval(" . $action . ");\n" if($CONF->{debug});
		eval("$action()");
		print dirname(realpath(__FILE__)) . '/template/API' .$PARAM->{'action'} . '.tmpl' . "\n" if($CONF->{debug});
		$CONF->{'template'} = 'API' .$PARAM->{'action'} . '.tmpl' if(-f dirname(realpath(__FILE__)) . '/template/API' .$PARAM->{'action'} . '.tmpl'); 
	}else{
		_cmd_view();
	}
}

sub buildApiOutput {
    # some useful options (see below for full list)
    my $config = {
        INCLUDE_PATH => dirname(realpath(__FILE__)) . '/template',  # or list ref
        INTERPOLATE  => 1,               # expand "$var" in plain text
        POST_CHOMP   => 1,               # cleanup whitespace
        #PRE_PROCESS  => 'header',        # prefix each template
        EVAL_PERL    => 1,               # evaluate Perl code blocks
    };

    # create Template object
    my $template = Template->new($config);

    # define template variables for replacement
	my $vars = {
#        var1  => $value,
#        var2  => \%hash,
#        var3  => \@list,
#        var4  => \&code,
#        var5  => $object,
		'Config' => $CONF,
		'Api' => $API,
		
    };

	RvglobalsoftManager::rvDumper($vars) if($CONF->{debug});
	
    # specify input filename, or file handle, text reference, etc.
    my $input = 'APImanager.tmpl';
    
    if(defined $CONF->{'template'} && $CONF->{'template'} ne ''){
    	$input = $CONF->{'template'};
    }

    # process input template, substituting variables
    $template->process($input, $vars)
        || die $template->error();
}

sub _cmd_view {
	print "=====>Call _cmd_view();\n" if($CONF->{debug});
	$CONF->{CPHandle} = new CPHandle();
	if (-f $CONF->{CPHandle}->getHomeDir() . '/.rvglobalsoft/accesskey.pem') {
		open(FD, '<', $CONF->{CPHandle}->getHomeDir() . '/.rvglobalsoft/accesskey.pem');
		$API->{whmPublicKey} = join('', <FD>);
		close(FD);
	}
        
	if (-f $CONF->{CPHandle}->getHomeDir() . '/.rvglobalsoft/authorizeid.pub') {
		open(FD, '<', $CONF->{CPHandle}->getHomeDir() . '/.rvglobalsoft/authorizeid.pub');
		$API->{username} = join('', <FD>);
		close(FD); 
	}
	
	$API->{restrictReseller} = $CONF->{CPHandle}->getAllowReseller();
	
	RvglobalsoftManager::rvDumper($API) if($CONF->{debug});
	#print Dumper($API);
}

sub _cmd_notprivilege {
	print "=====>Call _cmd_notprivileget();\n" if($CONF->{debug});
	RvglobalsoftManager::rvDumper($API) if($CONF->{debug});
}

sub isSetupApiKey {
	
    if (!-f $CONF->{CPHandle}->getHomeDir() . '/.rvglobalsoft/accesskey.pem' 
        || !-f $CONF->{CPHandle}->getHomeDir() . '/.rvglobalsoft/authorizeid.pub') {
       return 0;
    }
    return 1;
}

sub function_exists {
    no strict 'refs';
    my $funcname = shift;
    return \&{$funcname} if defined &{$funcname};
    return;
}
    
1;

Copyright 2K16 - 2K18 Indonesian Hacker Rulez