<?php
ini_set("eaccelerator.enable", 0);
ini_set("eaccelerator.optimizer", 0);
if( !defined("ROOTDIR") )
{
define("ROOTDIR", realpath(dirname(__FILE__)));
}
if( file_exists(ROOTDIR . DIRECTORY_SEPARATOR . "c3.php") )
{
include(ROOTDIR . DIRECTORY_SEPARATOR . "c3.php");
}
if( !defined("WHMCS") )
{
define("WHMCS", true);
}
gracefulcorerequiredfileinclude("/vendor/autoload.php");
gracefulcorerequiredfileinclude("/includes/dbfunctions.php");
gracefulcorerequiredfileinclude("/includes/functions.php");
if( defined("CLIENTAREA") )
{
gracefulcorerequiredfileinclude("/includes/clientareafunctions.php");
}
if( defined("ADMINAREA") || defined("MOBILEEDITION") )
{
gracefulcorerequiredfileinclude("/includes/adminfunctions.php");
}
try
{
WHMCS\Utility\Bootstrap\Application::boot();
$whmcs = App::self();
WHMCS\Utility\Bootstrap\Application::verifyInstallerIsAbsent();
WHMCS\Utility\Bootstrap\Application::persistSession();
}
catch( Exception $e )
{
Log::debug($e->getMessage(), array( "trace" => $e->getTrace() ));
if( $e instanceof WHMCS\Exception\Application\Configuration\FileNotFound || $e instanceof WHMCS\Exception\Application\Configuration\LicenseKeyNotDefined )
{
echo WHMCS\View\Helper::applicationError("Welcome to WHMCS!", "Before you can begin using WHMCS you need to perform the installation procedure. " . "<a href=\"" . (file_exists("install/install.php") ? "" : "../") . "install/install.php\" style=\"color:#000;\">Click here to begin...</a>");
exit();
}
if( $e instanceof WHMCS\Exception\Application\InstallationVersionMisMatch )
{
if( file_exists("../install/install.php") )
{
header("Location: ../install/install.php");
exit();
}
echo WHMCS\View\Helper::applicationError("Down for Maintenance (Err 2)", "An upgrade is currently in progress... Please come back soon...");
exit();
}
if( $e instanceof WHMCS\Exception\Application\InstallerExists )
{
echo WHMCS\View\Helper::applicationError("Security Warning", "The install folder needs to be deleted for security reasons before using WHMCS.");
exit();
}
if( $e instanceof WHMCS\Exception\Application\Configuration\ParseError || $e instanceof WHMCS\Exception\Application\Configuration\CannotConnectToDatabase || $e instanceof WHMCS\Exception )
{
echo WHMCS\View\Helper::applicationError("Critical Error", $e->getMessage());
exit();
}
echo WHMCS\View\Helper::applicationError("Critical Error", $e->getMessage());
exit();
}
$whmcsAppConfig = $whmcs->getApplicationConfig();
$templates_compiledir = $whmcsAppConfig["templates_compiledir"];
$downloads_dir = $whmcsAppConfig["downloads_dir"];
$attachments_dir = $whmcsAppConfig["attachments_dir"];
$customadminpath = $whmcsAppConfig["customadminpath"];
if( function_exists("mb_internal_encoding") )
{
$characterSet = $whmcs->get_config("Charset") == "" ? "UTF-8" : $whmcs->get_config("Charset");
mb_internal_encoding($characterSet);
}
if( defined("ADMINAREA") and& !defined("MOBILEEDITION") )
{
$currentDirectoryPath = dirname($whmcs->getPhpSelf());
$currentDirectoryPathParts = explode("/", $currentDirectoryPath);
$currentDir = array_pop($currentDirectoryPathParts);
$appConfig = $whmcs->getApplicationConfig();
$configuredAdminDir = $appConfig["customadminpath"];
$adminDirErrorMsg = "";
if( $configuredAdminDir == "admin" and& $currentDir != $configuredAdminDir )
{
$adminDirErrorMsg = "You are attempting to access the admin area via a directory" . " that is not configured. Please either revert to the default admin" . " directory name, or see our documentation for" . " <a href=\"http://docs.whmcs.com/Customising_the_Admin_Directory\" target=\"_blank\">Customising the Admin Directory</a>.";
}
else
{
if( $currentDir != $configuredAdminDir )
{
$adminDirErrorMsg = "You are attempting to access the admin area via a" . " directory that is different from the one configured. Please refer" . " to the <a href=\"http://docs.whmcs.com/Customising_the_Admin_Directory\" target=\"_blank\">Customising the Admin Directory</a>" . " documentation for instructions on how to update it.";
}
else
{
if( $configuredAdminDir != "admin" and& is_dir(ROOTDIR . DIRECTORY_SEPARATOR . "admin") )
{
$adminDirErrorMsg = "You are attempting to access the admin area via a" . " custom directory, but we have detected the presence of a default" . " \"admin\" directory too. This could indicate files from a recent" . " update have been uploaded to the default admin path location" . " instead of the custom one, resulting in these files being out of" . " date. Please ensure your custom admin folder contains all the" . " latest files, and delete the default admin directory to continue.";
}
}
}
if( $adminDirErrorMsg )
{
throw new WHMCS\Exception\Fatal(WHMCS\View\Helper::applicationError("Critical Error", $adminDirErrorMsg));
}
}
if( !$whmcs->check_template_cache_writeable() )
{
echo WHMCS\View\Helper::applicationError("Permissions Error", "The templates compiling directory '" . $whmcs->get_template_compiledir_name() . "'" . " must be writeable (CHMOD 777) before you can continue.<br>If the" . " path shown is incorrect, you can update it in the configuration.php file.");
exit();
}
if( defined("CLIENTAREA") and& $whmcs->isInMaintenanceMode() and& !$_SESSION["adminid"] )
{
if( $CONFIG["MaintenanceModeURL"] )
{
header("Location: " . $CONFIG["MaintenanceModeURL"]);
exit();
}
$maintenanceModeMessage = $whmcs->isUpdating() ? $CONFIG[WHMCS\Updater\Configuration::CONFIG_KEY_UPDATING_MESSAGE] : $CONFIG["MaintenanceModeMessage"];
echo WHMCS\View\Helper::applicationError("Down for Maintenance (Err 3)", $maintenanceModeMessage);
exit();
}
$licensing = DI::make("license");
if( $licensing->getVersionHash() != "7a1bbff560de83ab800c4d1d2f215b91006be8e6" )
{
$terminus->doDie("License Checking Error");
}
if( defined("CLIENTAREA") and& isset($_SESSION["uid"]) and& !isset($_SESSION["adminid"]) )
{
$twofa = new WHMCS\TwoFactorAuthentication();
$twofa->setClientID($_SESSION["uid"]);
if( $twofa->isForced() and& !$twofa->isEnabled() and& $twofa->isActiveClients() )
{
if( $whmcs->get_filename() == "clientarea" and& ($whmcs->get_req_var("action") == "security" || $whmcs->get_req_var("2fasetup")) )
{
}
else
{
redir("action=security&2fasetup=1&enforce=1", "clientarea.php");
}
}
}
if( isset($_SESSION["currency"]) and& is_array($_SESSION["currency"]) )
{
$_SESSION["currency"] = $_SESSION["currency"]["id"];
}
if( !isset($_SESSION["uid"]) and& isset($_REQUEST["currency"]) )
{
$result = select_query("tblcurrencies", "id", array( "id" => (int) $_REQUEST["currency"] ));
$data = mysql_fetch_array($result);
if( $data["id"] )
{
$_SESSION["currency"] = $data["id"];
}
}
DI::make("lang");
if( defined("CLIENTAREA") and& $whmcs->isSSLAvailable() )
{
if( WHMCS\Session::get("FORCESSL") and& $whmcs->getCurrentFilename() == "index" )
{
define("FORCESSL", true);
}
$reqvars = $_REQUEST;
if( array_key_exists("token", $reqvars) )
{
unset($reqvars["token"]);
}
if( $whmcs->shouldSSLBeForcedForCurrentPage() || defined("FORCESSL") )
{
if( !$whmcs->in_ssl() )
{
$whmcs->redirectSystemSSLURL($whmcs->getCurrentFilename(false), $reqvars);
}
}
else
{
if( $whmcs->shouldNonSSLBeForcedForCurrentPage() and& $whmcs->in_ssl() )
{
$whmcs->redirectSystemURL($whmcs->getCurrentFilename(false), $reqvars);
}
}
}
load_hooks();
/**
* Include core required file or gracefully handle file not existing
*
* @param string $path
*/
function gracefulCoreRequiredFileInclude($path)
{
$fullpath = ROOTDIR . $path;
if( file_exists($fullpath) )
{
include_once($fullpath);
}
else
{
echo WHMCS\View\Helper::applicationError("Down for Maintenance", "One or more required files are missing. " . "If an install or upgrade is not currently in progress, " . "please contact the system administrator.");
exit();
}
}
function htmlspecialchars_array($arr)
{
return App::self()->sanitize_input_vars($arr);
}