Code:
<?php
class AccountStatus
{
public $MODULE_AD_DELIVERY = 1;
public $MODULE_PAYMENTS = 2;
public $MODULE_REPORTS = 4;
public $MODULE_ACCOUNT_MANAGEMENT = 8;
public $MODULE_CAMPAIGN_MANAGEMENT = 16;
public $MODULE_CAMPAIGN_CREATION = 32;
public $MODULE_API_SERVICES = 64;
public $MODULE_ALL_MODULES = FALSE;
public $MODULE_CLIENT_DISABLED_MODULES = FALSE;
public $RESULT_CODE_SUCCESSFUL = 1;
public $RESULT_CODE_PERSISTENCE_FAILED = 2;
public $RESULT_CODE_PERSISTENCE_EXPIRED_WARNING = 3;
public $RESULT_CODE_PERSISTENCE_EXPIRED_ERROR = 4;
public $RESULT_CODE_PERSISTENCE_INVALID = 5;
public $RESULT_CODE_COMMUNICATION_FAILED_WARNING = 6;
public $RESULT_CODE_COMMUNICATION_FAILED_ERROR = 7;
public $successful = FALSE;
public $module_mask = FALSE;
public $comment = "";
public $code = FALSE;
public $expiration_timestamp = FALSE;
public $last_successful_check_timestamp = FALSE;
public $site_license = FALSE;
public $cached_time = FALSE;
public $valid_license = TRUE;
public function AccountStatus( )
{
$this->MODULE_ALL_MODULES = $this->MODULE_AD_DELIVERY | $this->MODULE_PAYMENTS | $this->MODULE_REPORTS | $this->MODULE_ACCOUNT_MANAGEMENT | $this->MODULE_CAMPAIGN_MANAGEMENT | $this->MODULE_CAMPAIGN_CREATION;
$this->MODULE_CLIENT_DISABLED_MODULES = 0;
}
public function getSuccessful( )
{
return $this->successful;
}
public function getIsValidLicense( )
{
return $this->valid_license;
}
public function getComment( )
{
return $this->comment;
}
public function getIsValidSiteLicense( )
{
return $this->successful && $this->site_license;
}
public function moduleIsAvailable( $ )
{
return 0 < ( $ & $this->module_mask ) || $this->site_license;
}
public function getLastSuccessfulCheckTime( )
{
return $this->last_successful_check_timestamp;
}
public function getModuleMask( )
{
return $this->module_mask;
}
}
class AccountStatusManager
{
public $error_handler = NULL;
public $logger = FALSE;
public $allow_cache = FALSE;
public $status_file_path = FALSE;
public $signature_key = "crU5uv9ve9rebE7ephuweb8p";
public $old_status_encryption_key = "3as2UtHa5ruteSwEw9a5huza";
public $status_encryption_key = "crewrEbuh5nA29phuFa972a46Swevuje";
public $date_format = "Y-m-d H:i:s";
public $client_id = FALSE;
public $client_license_key = FALSE;
public $has_curl = FALSE;
public $inclick_version = FALSE;
public $inclick_version_build = FALSE;
public $response_separator = ":";
public $system_currency = NULL;
public function AccountStatusManager( $in_allow_cache, $in_error_handler )
{
require_once( LOG4PHP_DIR."/LoggerManager.php" );
global $action_vars;
global $inclick_version;
global $inclick_version_build;
$this->allow_cache = $in_allow_cache;
$this->error_handler = $in_error_handler;
$this->logger = Logger::getlogger( "account_status_manager" );
$this->status_file_path = INCLICK_CONFIGURATION_DIR."/.inclick_status";
$this->client_id = $action_vars['inclick_client_id'];
$this->client_license_key = $action_vars['inclick_license_key'];
$this->inclick_version = $inclick_version;
$this->inclick_version_build = $inclick_version_build;
if ( ( "system_base_currency", $action_vars ) )
{
$this->system_currency = $action_vars['system_base_currency'];
}
else
{
$this->system_currency = "USD";
}
( "curl_version" );
}
public function getStatus( $ = FALSE )
{
$ = $this->_internal_getStatusFromCache( );
if ( $ )
{
return $;
}
$ = new AccountStatus( );
if ( !( $this->status_file_path ) )
{
if ( $ )
{
$this->updateStatus( );
return $this->getStatus( FALSE );
}
$->comment = "Unable to track server status properly. Please check the file permissions of the ".INCLICK_CONFIGURATION_DIR." directory to ensure the web server has write access.";
$->module_mask = $->MODULE_CLIENT_DISABLED_MODULES;
$->code = $->RESULT_CODE_PERSISTENCE_FAILED;
}
else
{
$this->_internal_populateStatusFromFile( $ );
}
$this->_internal_storeStatusInCache( $ );
return $;
}
public function updateStatus( )
{
$ = $this->getStatus( FALSE );
if ( $->getIsValidSiteLicense( ) )
{
return;
}
$this->_internal_postToServer( $, FALSE, FALSE );
$this->_internal_saveStatusToFile( $ );
}
public function getNewInstallationRegistrationStatus( $, $, $, $, $ = 0 )
{
$ = new AccountStatus( );
$ = "www.inclick.net";
$ = "nt/regis";
$ = "/manageme".$."ter.php";
$ = new DataEncrypter( $, "crewrEbuh5nA29phuFa972a46Swevuje" );
$->key = "crewrEbuh5nA29phuFa972a46Swevuje";
$ = "userID=".$."&pd={$}&inclick_version={$}&host={$}";
$ = $->encrypt( $ );
$ = ( $ );
$ = "version=3&data=".$;
$ = AccountStatusManager::_internal_dohttprequest( $, $, $, TRUE );
if ( ( "version", $ ) )
{
$ = $->decrypt( $['results'] );
}
$this->response_separator = ":";
AccountStatusManager::_internal_populatestatusfromresponse( $, $ );
return $;
}
public function processPendingTransactions( )
{
$ = $this->getStatus( FALSE );
if ( $->getIsValidSiteLicense( ) )
{
return TRUE;
}
$ = new DatabaseController( $this->error_handler );
$ = $->getConnection( $->CONNECTION_TYPE_ADMIN, TRUE, "account_status_manager" );
$ = $->getConnection( $->CONNECTION_TYPE_ADMIN, TRUE, "account_status_manager" );
$ = "SELECT user_id, trans_credit, trans_debit, trans_type, trans_id, gateway_id, trans_comment, trans_reason_code";
$ .= " FROM ".$->getTableName( "account_act" ).", ".$->getTableName( "user" );
$ .= " WHERE trans_processed = 0 AND trans_type='credit'";
$ .= " AND id = user_id AND type = 'adv'";
$ .= " ORDER BY trans_id";
$ = FALSE;
if ( !( $ = $->executeQuery( $, "Retrieve the list of transactions to process", $this->error_handler ) ) )
{
return FALSE;
}
while ( $ = $->fetchNextRowAsObject( $ ) )
{
$ = $->trans_id;
$this->_internal_postToServer( $, FALSE, $ );
if ( !$->successful )
{
$this->logger->error( "Failed while trying to log the transaction with ID: ".$->trans_id );
return FALSE;
}
$ = "UPDATE ".$->getTableName( "account_act" );
$ .= " SET trans_processed = 1";
$ .= " WHERE trans_id = ".$->trans_id;
if ( $->executeQuery( $, "Mark transaction: ".$->trans_id." as processed", $this->error_handler ) )
{
continue;
}
$this->logger->error( "Failed while trying to update the transaction with ID: ".$->trans_id );
return FALSE;
}
if ( $ )
{
$ = "UPDATE ".$->getTableName( "account_act" );
$ .= " SET trans_processed=1";
$ .= " WHERE trans_id < ".$;
if ( !$->executeQuery( $, "Update the status of all left over transactions", $this->error_handler ) )
{
return FALSE;
}
}
return TRUE;
}
public function processAdminLogin( )
{
$ = $this->getStatus( FALSE );
if ( $->getIsValidSiteLicense( ) )
{
return;
}
$ = FALSE;
if ( 0 < ( $->comment, "Version Upgrade Notice" ) )
{
$ = FALSE;
( "/You currently have the inClick Ad Server version ([0-9]+\\.[0-9]+\\.[0-9]+) installed/", $->comment, $ );
$ = FALSE;
( "/The current release is ([0-9]+\\.[0-9]+\\.[0-9]+)\\-([0-9]+)/", $->comment, $ );
if ( 0 < ( $ ) && 1 < ( $ ) && ( $[1] != $this->inclick_version || $[1] == $this->inclick_version && $[2] != $this->inclick_version_build ) )
{
$ = TRUE;
}
}
if ( !$->getIsValidLicense( ) && $ || 14400 < $->getIsValidLicense( ) - $->getLastSuccessfulCheckTime( ) || $->getModuleMask( ) < 1983 )
{
$this->_internal_postToServer( $, TRUE, FALSE );
$this->_internal_saveStatusToFile( $ );
$this->_internal_storeStatusInCache( $ );
}
}
public function checkStatusFilePermissions( )
{
$ = $this->getStatus( FALSE );
if ( $->getIsValidSiteLicense( ) )
{
return TRUE;
}
$ = TRUE;
$ = INCLICK_CONFIGURATION_DIR."/.inclick_status";
if ( !( $ ) )
{
$ = FALSE;
$ = @( $, "w+" );
if ( !$ )
{
return FALSE;
}
( $ );
( $, 511 );
}
$ = ( $ );
$ = ( "%o", $ );
$ = ( $, -3 );
if ( $ != "777" && $ != "666" )
{
if ( !( $, 511 ) )
{
return FALSE;
}
if ( !( $ ) )
{
return FALSE;
}
}
return TRUE;
}
public function _internal_getStatusFromCache( )
{
if ( !$this->allow_cache )
{
return FALSE;
}
$ = FALSE;
if ( isset( $_SESSION ) && ( "account_status", $_SESSION ) )
{
$ = ( $_SESSION['account_status'] );
}
return $;
}
public function _internal_storeStatusInCache( &$ )
{
if ( !$this->allow_cache && !isset( $_SESSION ) )
{
return;
}
$->cached_time = $this->allow_cache;
$_SESSION['account_status'] = ( $ );
}
public function _internal_postToServer( &$, $, $ )
{
$ = ( INCLICK_WEB_URL );
$ = $['host'];
$ = INCLICK_WEB_URL;
$ = "2";
$ = "justrubmybellylexie";
$ = "whostheDog_itsallaboutbeingalpha";
$ = ( "U" );
$ = "{$}{$}{$}{$this->client_id}";
$ = ( $ );
$ = "5TUxupr7XeJaYesp";
$ = ( $.$ );
$ = "";
$ = "";
$ = "";
$ = "";
$ = "status";
if ( $ )
{
$ = new TransactionReasonManager( $this->error_handler );
$ = $->user_id;
$ = $->trans_credit - $->trans_debit;
$ = ( $ );
$ = $->trans_comment;
if ( !( $, $ ) )
{
$ .= " Account ID: ".$;
}
$ = ( $ );
$ = $->gateway_id;
if ( $->trans_type == "debit" )
{
if ( $->trans_reason_code == $->refund_reason_code )
{
$ = "credit";
}
else
{
$ = "debit";
}
}
else
{
$ = "payment";
}
}
else if ( $ )
{
$ = "admin_login";
}
$ = "notify_key=".$."¬ify_time={$}&version=".( $this->inclick_version );
$ .= "&version_build=".( $this->inclick_version_build );
$ .= "¬ify_version=".$."&key=".( $this->client_license_key );
$ .= "&id=".$this->client_id."&location_key={$}&install_loc={$}";
$ .= "&amount=".$."&trans_type={$}&ref_id={$}&account_id={$}&gateway_id={$}";
$ .= "¤cy=".$this->system_currency;
$ .= "&phpversion=".$this->system_currency;
$ = new DataEncrypter( $this->error_handler, $this->status_encryption_key );
$ = "h5nA29";
$->key = "crewrEbu".$."phuFa972a46Swevuje";
$ = $->encrypt( $ );
$ = ( $ );
$ = "gwversion=4&data=".$;
$ = "www.inclick.net";
$ = "nt/lice";
$ = "/manageme".$."nse_check.php";
$ = "connection=non_ssl&".$."\r\n";
$ = $this->_internal_doHTTPRequest( $, $, $ );
if ( ( "gwversion", $ ) )
{
$ = $->decrypt( $['results'] );
$this->response_separator = "~";
if ( $ != $['timekey_returned'] )
{
$ = "B~Critical Error Detected! Please contact inClick Support";
}
}
$this->_internal_populateStatusFromResponse( $, $ );
}
public function _internal_populateStatusFromFile( &$ )
{
$ = ( $this->status_file_path, "r" );
if ( !$ )
{
$this->logger->warn( "Failed while trying to load the file: ".$this->status_file_path );
$->comment = "Unable to track server status properly. Please check the file permissions of the ".INCLICK_CONFIGURATION_DIR." directory to ensure the web server has write access.";
$->module_mask = $->MODULE_CLIENT_DISABLED_MODULES;
$->code = $->RESULT_CODE_PERSISTENCE_FAILED;
}
else
{
$ = "";
while ( !( $ ) )
{
$ .= ( $, 1024 );
}
$ = new DataEncrypter( $this->error_handler, $this->status_encryption_key );
$ = $->decrypt( $ );
$ = ( ";", $ );
if ( ( $ ) < 2 || ( $, "modules" ) !== 0 )
{
$ = new DataEncrypter( $this->error_handler, $this->old_status_encryption_key );
$ = $->decrypt( $ );
$ = ( ";", $ );
}
$ = $[0];
$ = $[1];
if ( !( $.$this->signature_key ) == $ )
{
$this->logger->warn( "Failed while trying to verify status signature" );
$->comment = "Unable to track server status properly. Please ensure that the background processes are configured properly and working.";
$->module_mask = $->MODULE_CLIENT_DISABLED_MODULES;
$->code = $->RESULT_CODE_PERSISTENCE_FAILED;
}
else
{
$ = ( "&", $ );
$ = FALSE;
default :
switch ( $ )
{
foreach ( $ as $ )
{
$ = ( "=", $, 2 );
$ = $[0];
$ = ( $[1] );
$ = ( $ );
case "expiration" :
$ = ( $ );
continue;
case "comment" :
$->comment = $;
continue;
case "modules" :
$->module_mask = $;
continue;
case "last_check" :
$->last_successful_check_timestamp = ( $ );
}
continue;
case "site_license" :
if ( $ == "true" )
{
$->site_license = TRUE;
}
}
if ( ( $ ) < $ )
{
$->successful = TRUE;
$->expiration_timestamp = $;
}
else if ( $ + 259200 <= ( $ ) )
{
( "The status has not been checked since: ".$this->logger->warn( "m-d-Y H:i:s", $ ).". Error issued and modules disabled." );
$->comment = "Unable to track server status properly. Please ensure that the background processes are configured properly and working.";
$->module_mask = $->MODULE_CLIENT_DISABLED_MODULES;
$->code = $->RESULT_CODE_PERSISTENCE_EXPIRED_ERROR;
}
else
{
( "The status has not been checked since: ".$this->logger->warn( "m-d-Y H:i:s", $ ).". Warning issued." );
$->successful = TRUE;
$->comment = "Unable to track server status properly. Please ensure that the background processes are configured properly and working.";
$->code = $->RESULT_CODE_PERSISTENCE_EXPIRED_WARNING;
}
}
}
}
public function _internal_saveStatusToFile( &$ )
{
$ = "";
$ .= "modules=".$->module_mask;
$ .= "&expiration=".( ( $this->date_format, $->expiration_timestamp ) );
$ .= "&last_check=".( ( $this->date_format, $->last_successful_check_timestamp ) );
$ .= "&comment=".( $->comment );
if ( $->site_license )
{
$ .= "&site_license=true";
}
$ = new DataEncrypter( $this->error_handler, $this->status_encryption_key );
$ = ( $.$this->signature_key );
$ = $.";".$;
$ = $->encrypt( $ );
$ = ( $this->status_file_path, "w" );
if ( !$ )
{
( $this->status_file_path, 511 );
$ = ( $this->status_file_path, "w" );
}
if ( !$ )
{
$this->logger->warn( "Failed while trying to save to the file: ".$this->status_file_path );
$->comment = "Unable to track server status properly. Please check the file permissions of the ".INCLICK_CONFIGURATION_DIR." directory to ensure the web server has write access.";
$->module_mask = $->MODULE_CLIENT_DISABLED_MODULES;
$->code = $->RESULT_CODE_PERSISTENCE_FAILED;
$this->logger->debug( "Failed saving status to file..." );
}
else
{
$this->logger->debug( "Saving status to file: ".$this->status_file_path );
( $, $ );
( $ );
}
}
public function _internal_doHTTPRequest( $, $, $, $ = TRUE )
{
$ = FALSE;
$ = "Host: ".$."\r\n";
$ .= "User-Agent: PHP Script\r\n";
$ .= "Content-Type: application/x-www-form-urlencoded\r\n";
if ( $ )
{
$ .= "Content-Length: ".( $ )."\r\n";
}
$ .= "Connection: close\r\n\r\n";
$ = ( $ );
if ( !$ )
{
$ = Logger::getlogger( "AccountStatusManager" );
$->warn( "Failed while connecting to the URL: ".."{$} with error: {$}-{$}" );
return $;
}
if ( $ )
{
( $, "POST ".$." HTTP/1.0\r\n" );
( $, $ );
( $, $ );
}
else
{
( $, "GET ".$."?{$} HTTP/1.0\r\n" );
( $, $ );
}
while ( !( $ ) )
{
$ .= ( $, 1024 );
}
( $ );
$ = array( );
$ = 500;
if ( ( "/^HTTP\\/([0-9\\.]+) ([0-9]+).*/i", $, $ ) )
{
$ = $[2];
}
if ( $ < 400 )
{
$ = ( $, "\r\n\r\n" );
if ( $ !== FALSE )
{
$ = ( $, $ + 4 );
$ = ( $, "\r\n" );
if ( $ !== FALSE )
{
$ = ( $, $ );
}
}
$ = ( $ );
}
return $;
}
public function _internal_populateStatusFromResponse( &$, $ )
{
if ( $ )
{
$->successful = TRUE;
$ = ( $this->response_separator, $ );
$ = $[0];
$->comment = $[1];
if ( 2 < ( $ ) )
{
$->module_mask = $[2];
}
else if ( $ == "B" || $ == "Z" )
{
$->module_mask = $->MODULE_CLIENT_DISABLED_MODULES;
if ( $ == "Z" )
{
$->valid_license = FALSE;
}
}
else
{
$->module_mask = $->MODULE_ALL_MODULES;
}
$->last_successful_check_timestamp = $->MODULE_ALL_MODULES;
$->expiration_timestamp = ( $ ) + 28800;
$->RESULT_CODE_SUCCESSFUL;
}
else
{
$->successful = FALSE;
if ( !$->last_successful_check_timestamp && ( $ ) < $->last_successful_check_timestamp + 172800 )
{
if ( !$->last_successful_check_timestamp )
{
$->last_successful_check_timestamp = $->last_successful_check_timestamp;
}
$->comment = "License verification has recently failed. If you see this message for more than one day, you will need to remedy this situation or functionality will be disabled. For further assistance, please open a support ticket.";
$->result_code = $->RESULT_CODE_COMMUNICATION_FAILED_WARNING;
}
else
{
$->comment = "License verification has recently failed. Functionality has been disabled due to this problem being present for too long. Please contact inClick Support for further assistance.";
$->module_mask = $->MODULE_CLIENT_DISABLED_MODULES;
$->result_code = $->RESULT_CODE_COMMUNICATION_FAILED_ERROR;
}
}
}
}
require_once( INCLICK_CLASSES_DIR."/database/DatabaseController.php" );
require_once( INCLICK_CLASSES_DIR."/utility/DataEncrypter.php" );
require_once( INCLICK_CLASSES_DIR."/admin/TransactionReasonManager.php" );
?>