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/ApiManager.pm

#!/usr/bin/perl
package ApiManager;
##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 vars qw (@ISA @EXPORT_OK  $INSTANCE %CONSTANTS %GLOBALS $PARAM $CONF $API);

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

#use vars qw(@ISA @EXPORT_OK $CONF $API $PARAM);
require Exporter;
@ISA = qw(Exporter);
@EXPORT_OK = qw(
  $OUTPUT $ERROR $CONF $VERSIONCACHE
);

$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();
	validateApiAction();
	$API->{isSetupApiKey} = isSetupApiKey();
	#isAcceptLicense
	#isAllowResellerAccess
	
	buildApiOutput();
}

sub apiKeySetup {
	#RvglobalsoftManager::buildAjaxPageHeader();
	#print "Content-Type: text/html; charset=utf-8\n\n";

		print "Expires: 0\n";
		print "Cache-Control: no-cache, must-revalidate, post-check=0, pre-check=0";
		print "Content-Type: application/json; charset=utf-8\n\n" ;
		
	print '{"status":"callnext","nextaction":"testwhmapikey","action":"verifywhmapikey"}';
	exit;
}

sub validateApiAction {
	$CONF->{baseUrl} = $CONF->{CPHandle}->getBaseUrl();
	my $action = (defined $PARAM->{'action'} && $PARAM->{'action'} ne '')?'_cmd' . $PARAM->{'action'}:'_cmd_view';
	if(RvglobalsoftManager::Rvlibary::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 {
	my ($this, $input, $output) = @_;
	$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 isSetupApiKey {
	
    if (!-f $CONF->{CPHandle}->getHomeDir() . '/.rvglobalsoft/accesskey.pem' 
        || !-f $CONF->{CPHandle}->getHomeDir() . '/.rvglobalsoft/authorizeid.pub') {
       return 0;
    }
    return 1;
}
    
1;

Copyright 2K16 - 2K18 Indonesian Hacker Rulez