Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- * @ Pirate-Sky Crew :: PHP Decoder v2
- * @ Author: pLa$71k
- * @ Web: http://pirate-sky.com
- * @ Pirate-Sky Crew © 2008 - 2013
- */
- /**
- * =======================================
- * ###################################
- * SWIFT Framework - Cr@cK3D
- * ###################################
- * =======================================
- */
- /**
- * ###############################################
- * BEGIN LICENSE KEY CHECK
- * ###############################################
- */
- class SWIFT_License
- {
- const LIC_KEY = 'A376545AD82A8B695A60';
- static private $_licenseContainer = false;
- static private $_allChecksPass = false;
- /**
- * Constructor
- *
- * @return bool "true" on Success, "false" otherwise
- */
- public function __construct()
- {
- parent::__construct();
- return true;
- }
- /**
- * Destructor
- *
- * @return bool "true" on Success, "false" otherwise
- */
- public function __destruct()
- {
- parent::__destruct();
- return true;
- }
- /**
- * Attempt to load the license system
- *
- * @return bool "true" on Success, "false" otherwise
- */
- static public function Load()
- {
- // No license checks for setup or console
- if (SWIFT_INTERFACE == 'setup' || SWIFT_INTERFACE == 'console' || SWIFT_INTERFACE == 'winapp' || SWIFT_INTERFACE == 'visitor' || SWIFT_INTERFACE == 'staff' || SWIFT_INTERFACE == 'admin' || SWIFT_INTERFACE == 'client' || SWIFT_INTERFACE == 'chat' || SWIFT_INTERFACE == 'archive' || SWIFT_INTERFACE == 'pda' || SWIFT_INTERFACE == 'rss' || SWIFT_INTERFACE == 'syncworks' || SWIFT_INTERFACE == 'instaalert' || SWIFT_INTERFACE == 'api' || SWIFT_INTERFACE == 'cron' || SWIFT_INTERFACE == 'wallboard' || SWIFT_INTERFACE == 'console' || SWIFT_INTERFACE == 'winapp' || SWIFT_INTERFACE == 'intranet') {
- self::$_allChecksPass = true;
- return true;
- }
- if (!file_exists('./key.php')) {
- echo 'Unable to locate key.php, please ensure that the key.php is placed in the root directory of the package.';
- exit;
- }
- $_keyContents = file_get_contents('./key.php');
- if (!self::DecodeKey($_keyContents)) {
- echo 'Invalid key.php. Please try uploading your key file in Binary mode or contact the Kayako Support at https://my.kayako.com for further assistance.';
- exit;
- }
- return true;
- }
- /**
- * The Key Decoder
- *
- * @param string $_keyContents The Key Contents
- * @return bool "true" on Success, "false" otherwise
- */
- static protected function DecodeKey($_keyContents)
- {
- if (trim($_keyContents) == '') {
- echo 'key.php is empty. Please try uploading your key file in Binary mode or contact the Kayako Support at https://my.kayako.com for further assistance.';
- exit;
- }
- $_finalKeyContents = '';
- $_matches = array();
- if (!preg_match('@\[([^\[\]]*)\]@', $_keyContents, $_matches)) {
- echo 'Invalid key.php (3). Please try uploading your key file in Binary mode or contact the Kayako Support at https://my.kayako.com for further assistance.';
- exit;
- }
- $_finalKeyContents = $_matches[1];
- // MD5OFBASEDATA;MD5OFDECRYPTEDDATA;EXTENDEDKEY;BASE64DATA
- $_keyChunksContainer = explode(';', $_finalKeyContents);
- if (count($_keyChunksContainer) != 4) {
- echo 'Invalid key.php (2). Please try uploading your key file in Binary mode or contact the Kayako Support at https://my.kayako.com for further assistance.';
- exit;
- }
- $_md5Base64 = $_keyChunksContainer[0];
- $_md5Decrypted = $_keyChunksContainer[1];
- $_extendedKey = $_keyChunksContainer[2];
- $_base64Data = $_keyChunksContainer[3];
- if (md5($_base64Data) != $_md5Base64) {
- echo 'Invalid key.php (INVALID BASE64HASH). Please try uploading your key file in Binary mode or contact the Kayako Support at https://my.kayako.com for further assistance.';
- exit;
- }
- if (empty($_extendedKey)) {
- echo 'Invalid key.php (INVALID EXTENDEDKEY). Please try uploading your key file in Binary mode or contact the Kayako Support at https://my.kayako.com for further assistance.';
- exit;
- }
- $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB);
- $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
- $_decryptedData = str_replace("\x0", '', mcrypt_decrypt(MCRYPT_RIJNDAEL_256, self::LIC_KEY . $_extendedKey, base64_decode($_base64Data), MCRYPT_MODE_ECB, $iv));
- $_licenseContainer = mb_unserialize($_decryptedData);
- if (empty($_decryptedData) || md5($_decryptedData) != $_md5Decrypted || !_is_array($_licenseContainer)) {
- echo 'Invalid key.php (INVALID DECRYPT). Please try uploading your key file in Binary mode or contact the Kayako Support at https://my.kayako.com for further assistance.';
- exit;
- }
- self::$_licenseContainer = $_licenseContainer;
- SWIFT::Set('licenseexpiry', $_licenseContainer['expiry']);
- SWIFT::Set('licensefullname', $_licenseContainer['fullname']);
- SWIFT::Set('licenseproduct', $_licenseContainer['product']);
- SWIFT::Set('licensestaff', $_licenseContainer['licensedstaff']);
- SWIFT::Set('licensedomains', $_licenseContainer['domains']);
- SWIFT::Set('licensepackage', $_licenseContainer['package']);
- SWIFT::Set('licenseorganization', $_licenseContainer['organization']);
- SWIFT::Set('licenseuniqueid', $_licenseContainer['uniqueid']);
- SWIFT::Set('licenseistrial', $_licenseContainer['istrial']);
- if ($_licenseContainer['istrial'] == '1' && (SWIFT_INTERFACE == 'client' || SWIFT_INTERFACE == 'visitor' || SWIFT_INTERFACE == 'admin' || SWIFT_INTERFACE == 'staff')) {
- ob_start();
- }
- return true;
- }
- /**
- * Check for license expiry
- *
- * @return bool "true" on Success, "false" otherwise
- */
- static public function CheckExpired()
- {
- if (self::$_allChecksPass == true) {
- return true;
- }
- if (!isset(self::$_licenseContainer['expiry']) || (self::$_licenseContainer['expiry'] != '0' && self::$_licenseContainer['expiry'] < time())) {
- echo 'License has expired! Expiry: ' . date('d M Y h:i:s A', self::$_licenseContainer['expiry']);
- exit;
- }
- return true;
- }
- /**
- * Check for valid domain
- *
- * @return bool "true" on Success, "false" otherwise
- * @throws SWIFT_Exception If Invalid Data is Provided
- */
- static public function CheckValidDomain()
- {
- $_SWIFT = SWIFT::GetInstance();
- if (self::$_allChecksPass == true) {
- return true;
- }
- // ======= START DOMAIN CHECK =======
- $_checkHost = false;
- $_domainData = parse_url($_SWIFT->Settings->Get('general_producturl'));
- if (strtolower(substr($_domainData['host'], 0, 4)) == 'www.') {
- $_checkHost = trim(strtolower(substr($_domainData['host'], 4)));
- } else {
- $_checkHost = trim(strtolower($_domainData['host']));
- }
- $_allowedDomains = implode(',', self::$_licenseContainer['domains']);
- if (!in_array($_checkHost, self::$_licenseContainer['domains'])) {
- echo '<div style="position: absolute; left: 10px; top: 0; right: 10px; border: 1px SOLID darkred; background: #ffefbb; z-index: 999999999;"><font face="verdana, arial, helvetica, serif" size="3" color="red"><b>ERROR:</b> Domain does not match license key file domain (' . $_checkHost . '), allowed domains: ' . $_allowedDomains . ', please change the product path to match the domain under Admin CP > Settings > General Settings<br>This Product will not work properly unless untill that value is changed.<br /><br />For more information please contact the kayako support at <a href="https://my.kayako.com" target="blank">https://my.kayako.com</a></font></div>';
- }
- unset($_checkHost);
- unset($_domainData);
- $_httpsExtended = '';
- if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == TRUE) {
- $_httpsExtended = 's';
- }
- /**
- * ---------------------------------------------
- * EXTENDED DOMAIN CHECK
- * ---------------------------------------------
- */
- $_selfURL = sprintf('http%s://%s%s', $_httpsExtended, $_SERVER['HTTP_HOST'], $_SERVER['REQUEST_URI']);
- $_checkHost = false;
- $_domainData = parse_url($_selfURL);
- if (strtolower(substr($_domainData['host'], 0, 4)) == 'www.') {
- $_checkHost = trim(strtolower(substr($_domainData['host'], 4)));
- } else {
- $_checkHost = trim(strtolower($_domainData['host']));
- }
- $_allowedDomains = implode(',', self::$_licenseContainer['domains']);
- if (!in_array($_checkHost, self::$_licenseContainer['domains'])) {
- echo '<div style="position: absolute; left: 10px; top: 0; right: 10px; border: 1px SOLID darkred; background: #ffefbb; z-index: 999999999;"><font face="verdana, arial, helvetica, serif" size="3" color="red"><b>ERROR:</b> Domain does not match license key file domain (' . $_checkHost . '), allowed domains: ' . $_allowedDomains . ', please change the product path to match the domain under Admin CP > Settings > General Settings<br>This Product will not work properly unless untill that value is changed.<br /><br />For more information please contact the kayako support at <a href="https://my.kayako.com" target="blank">https://my.kayako.com</a></font></div>';
- }
- // ======= END DOMAIN CHECK =======
- // If its a trial key AND interface is client, display a message
- if (self::$_licenseContainer['istrial'] == '1' && (SWIFT_INTERFACE == 'client' || SWIFT_INTERFACE == 'visitor' || SWIFT_INTERFACE == 'admin' || SWIFT_INTERFACE == 'staff')) {
- $_contents = ob_get_contents();
- ob_end_clean();
- // Is it compressor page? dont display any message
- if (isset($_SWIFT->Router) && $_SWIFT->Router instanceof SWIFT_Router && strtolower($_SWIFT->Router->GetAction()) == 'compressor') {
- echo $_contents;
- } else if (stristr($_contents, '</body>')) {
- echo str_replace('</body>', '<div style="position: absolute; left: 10px; top: 0; right: 10px; border: 1px SOLID darkred; background: #ffefbb; z-index: 999999999;"><font face="verdana, arial, helvetica, serif" size="3" color="red">This is a trial product!<br /><br />To upgrade or contact kayako sales, please visit <a href="https://my.kayako.com" target="blank">https://my.kayako.com</a></font></div></body>', $_contents);
- } else {
- echo $_contents;
- echo '<div style="position: absolute; left: 10px; top: 0; right: 10px; border: 1px SOLID darkred; background: #ffefbb; z-index: 999999999;"><font face="verdana, arial, helvetica, serif" size="3" color="red">This is a trial product!<br /><br />To upgrade or contact kayako sales, please visit <a href="https://my.kayako.com" target="blank">https://my.kayako.com</a></font></div>';
- }
- }
- return true;
- }
- /**
- * Check for Valid Staff
- *
- * @return bool "true" on Success, "false" otherwise
- * @throws SWIFT_Exception If Invalid Data is Provided
- */
- static public function CheckValidStaff()
- {
- $_SWIFT = SWIFT::GetInstance();
- if (self::$_allChecksPass == true) {
- return true;
- }
- $_staffCache = $_SWIFT->Cache->Get('staffcache');
- if (!isset(self::$_licenseContainer['licensedstaff']) || (self::$_licenseContainer['licensedstaff'] != '0' && count($_staffCache) > self::$_licenseContainer['licensedstaff'])) {
- echo 'Staff count exceeded. (' . count($_staffCache) . ' > ' . self::$_licenseContainer['licensedstaff'] . '). Please contact Kayako Support for further assistance at https://my.kayako.com.';
- exit;
- }
- SWIFT::Set('licensedstaff', self::$_licenseContainer['licensedstaff']);
- return true;
- }
- /**
- * Check for Valid Package
- *
- * @return bool "true" on Success, "false" otherwise
- * @throws SWIFT_Exception If Invalid Data is Provided
- */
- static public function CheckPackage()
- {
- $_SWIFT = SWIFT::GetInstance();
- if (self::$_allChecksPass == true) {
- return true;
- }
- if (strtolower(self::$_licenseContainer['product']) != strtolower(SWIFT_PRODUCT)) {
- echo 'Invalid Product Package (Main). Source: ' . SWIFT_PRODUCT . ', Key: ' . self::$_licenseContainer['product'] . '. Please contact Kayako support for further assistance at https://my.kayako.com.';
- exit;
- }
- if (defined('SWIFT_PACKAGE') && isset(self::$_licenseContainer['package']) && !empty(self::$_licenseContainer['package']) && strtolower(constant('SWIFT_PACKAGE')) != strtolower(constant('SWIFT_PRODUCT')) && strtolower(self::$_licenseContainer['package']) != strtolower(constant('SWIFT_PACKAGE'))) {
- echo 'Invalid Product Package. Source: ' . constant('SWIFT_PACKAGE') . ', Key: ' . self::$_licenseContainer['package'] . '. Please contact Kayako support for further assistance at https://my.kayako.com.';
- exit;
- }
- // Trial Check. We dont want clients with zendclosed and ioncubeclosed builds where the license key isnt activated for trial.. no free SUS!
- if ((strtolower(SOURCE_TYPE) == 'zendclosed' || strtolower(SOURCE_TYPE) == 'ioncubeclosed') && (!isset(self::$_licenseContainer['istrial']) || self::$_licenseContainer['istrial'] == '0')) {
- echo 'Invalid Product Trial Package. Source: ' . constant('SOURCE_TYPE') . ', Key: ' . self::$_licenseContainer['package'] . '. Please contact Kayako support for further assistance at https://my.kayako.com.';
- exit;
- }
- return true;
- }
- }
- SWIFT_License::Load();
- /**
- * ###############################################
- * END LICENSE KEY CHECK
- * ###############################################
- */
- /**
- * The Core SWIFT Class
- *
- * @author Varun Shoor
- */
- class SWIFT
- {
- static private $_alertContainer = array();
- static private $_infoContainer = array();
- static private $_errorContainer = array();
- static private $_errorFieldContainer = array();
- static private $_objectMapContainer = array();
- static private $_Instance = false;
- static private $_valueContainer = array();
- static private $_objectCache = array();
- /**
- * @var SWIFT_FirePHP
- */
- public $FirePHP = false;
- /**
- * @var SWIFT_Database
- */
- public $Database = false;
- /**
- * @var SWIFT_LanguageEngine
- */
- public $Language = false;
- /**
- * @var SWIFT_TemplateEngine
- */
- public $Template = false;
- /**
- * @var SWIFT_Registry
- */
- public $Registry = false;
- /**
- * @var SWIFT_Interface
- */
- public $Interface = false;
- /**
- * @var SWIFT_Module
- */
- public $Module = false;
- /**
- * @var SWIFT_Session
- */
- public $Session = false;
- /**
- * @var SWIFT_Settings
- */
- public $Settings = false;
- /**
- * @var SWIFT_Cache
- */
- public $Cache = false;
- /**
- * @var SWIFT_Router
- */
- public $Router = false;
- /**
- * @var SWIFT_View
- */
- public $View = false;
- /**
- * @var SWIFT_Cookie
- */
- public $Cookie = false;
- /**
- * @var SWIFT_Console
- */
- public $Console = false;
- /**
- * @var SWIFT_System
- */
- public $System = false;
- /**
- * @var SWIFT_Controller
- */
- public $Controller = false;
- /**
- * @var SWIFT_UserInterface
- */
- public $UserInterface = false;
- /**
- * @var SWIFT_Loader
- */
- public $Load = false;
- /**
- * @var SWIFT_Staff
- */
- public $Staff = false;
- /**
- * @var SWIFT_User
- */
- public $User = false;
- /**
- * @var SWIFT_HTMLPurifier
- */
- public $HTMLPurifier = false;
- /**
- * @var SWIFT_TemplateGroup
- */
- public $TemplateGroup = false;
- /**
- * Non Core Objects
- */
- /**
- * @var SWIFT_Server
- */
- public $Server = false;
- /**
- * @var SWIFT_Server
- */
- public $ServerMaster = false;
- /**
- * @var SWIFT_JobQueueMessageRemote
- */
- public $JobQueueMessage = false;
- /**
- * @var SWIFT_DynectSession
- */
- public $DynectSession = false;
- /**
- * Core Constants
- */
- const DEFAULT_ERROR_REPORTING = E_ALL;
- /**
- * Constructor
- *
- * @return bool "true" on Success, "false" otherwise
- */
- private function __construct()
- {
- return true;
- }
- /**
- * Initialize the Class
- *
- * @return bool "true" on Success, "false" otherwise
- * @throws SWIFT_Exception If the Class is not Loaded
- */
- protected function Initialize()
- {
- global $_shutdownQueue;
- $this->SanitizeGlobals();
- $_shutdownQueue = array();
- require_once('./' . SWIFT_BASEDIRECTORY . '/' . SWIFT_CONFIGDIRECTORY . '/config.php');
- // Load FirePHP Connector Class
- $this->FirePHP = new SWIFT_FirePHP();
- self::Set('_startTime', GetMicroTime());
- /*
- * ###############################################
- * Error Reporting Functions
- * ###############################################
- */
- error_reporting(self::DEFAULT_ERROR_REPORTING);
- set_error_handler(array(
- 'SWIFT_Exception',
- 'GlobalErrorHandler'
- ));
- set_exception_handler(array(
- 'SWIFT_Exception',
- 'GlobalExceptionHandler'
- ));
- @ini_set('session.use_trans_sid', false);
- @ini_set('session.bug_compat_42', true);
- require_once('./' . SWIFT_BASEDIRECTORY . '/' . SWIFT_LIBRARYDIRECTORY . '/Database/class.SWIFT_Database.php');
- // Define the DSN
- SWIFT_Database::DefineDSN();
- // Libraries
- require_once('./' . SWIFT_BASEDIRECTORY . '/' . SWIFT_LIBRARYDIRECTORY . '/Interface/class.SWIFT_Interface.php');
- require_once('./' . SWIFT_BASEDIRECTORY . '/' . SWIFT_LIBRARYDIRECTORY . '/MVC/class.SWIFT_Model.php');
- require_once('./' . SWIFT_BASEDIRECTORY . '/' . SWIFT_LIBRARYDIRECTORY . '/MVC/class.SWIFT_View.php');
- require_once('./' . SWIFT_BASEDIRECTORY . '/' . SWIFT_LIBRARYDIRECTORY . '/MVC/class.SWIFT_Controller.php');
- require_once('./' . SWIFT_BASEDIRECTORY . '/' . SWIFT_LIBRARYDIRECTORY . '/MVC/class.SWIFT_Library.php');
- require_once('./' . SWIFT_BASEDIRECTORY . '/' . SWIFT_LIBRARYDIRECTORY . '/Module/class.SWIFT_Module.php');
- require_once('./' . SWIFT_BASEDIRECTORY . '/' . SWIFT_LIBRARYDIRECTORY . '/Registry/class.SWIFT_Registry.php');
- require_once('./' . SWIFT_BASEDIRECTORY . '/' . SWIFT_LIBRARYDIRECTORY . '/Cache/class.SWIFT_CacheStore.php');
- require_once('./' . SWIFT_BASEDIRECTORY . '/' . SWIFT_LIBRARYDIRECTORY . '/Settings/class.SWIFT_Settings.php');
- require_once('./' . SWIFT_BASEDIRECTORY . '/' . SWIFT_LIBRARYDIRECTORY . '/Language/class.SWIFT_LanguagePhraseLinked.php');
- require_once('./' . SWIFT_BASEDIRECTORY . '/' . SWIFT_LIBRARYDIRECTORY . '/LanguageEngine/class.SWIFT_LanguageEngine.php');
- require_once('./' . SWIFT_BASEDIRECTORY . '/' . SWIFT_LIBRARYDIRECTORY . '/TemplateEngine/class.SWIFT_TemplateEngine.php');
- require_once('./' . SWIFT_BASEDIRECTORY . '/' . SWIFT_LIBRARYDIRECTORY . '/Date/class.SWIFT_Date.php');
- require_once('./' . SWIFT_BASEDIRECTORY . '/' . SWIFT_LIBRARYDIRECTORY . '/Session/class.SWIFT_Session.php');
- require_once('./' . SWIFT_BASEDIRECTORY . '/' . SWIFT_LIBRARYDIRECTORY . '/Loader/class.SWIFT_Loader.php');
- require_once('./' . SWIFT_BASEDIRECTORY . '/' . SWIFT_LIBRARYDIRECTORY . '/Cookie/class.SWIFT_Cookie.php');
- require_once('./' . SWIFT_BASEDIRECTORY . '/' . SWIFT_LIBRARYDIRECTORY . '/Router/class.SWIFT_Router.php');
- require_once('./' . SWIFT_BASEDIRECTORY . '/' . SWIFT_LIBRARYDIRECTORY . '/Data/class.SWIFT_Data.php');
- require_once('./' . SWIFT_BASEDIRECTORY . '/' . SWIFT_LIBRARYDIRECTORY . '/Data/class.SWIFT_DataID.php');
- require_once('./' . SWIFT_BASEDIRECTORY . '/' . SWIFT_LIBRARYDIRECTORY . '/Data/class.SWIFT_DataStore.php');
- require_once('./' . SWIFT_BASEDIRECTORY . '/' . SWIFT_LIBRARYDIRECTORY . '/Hook/class.SWIFT_Hook.php');
- // Load only if the interface is Console
- if (SWIFT_INTERFACE == 'console') {
- require_once('./' . SWIFT_BASEDIRECTORY . '/' . SWIFT_LIBRARYDIRECTORY . '/Console/class.SWIFT_Console.php');
- require_once('./' . SWIFT_BASEDIRECTORY . '/' . SWIFT_LIBRARYDIRECTORY . '/System/class.SWIFT_System.php');
- $this->Console = new SWIFT_Console();
- $this->System = new SWIFT_System();
- }
- /*
- * ###############################################
- * BEGIN CORE VARIABLES CREATION
- * ###############################################
- */
- if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
- self::Set('IP', $_SERVER['HTTP_X_FORWARDED_FOR']);
- } elseif (isset($_SERVER['REMOTE_ADDR'])) {
- self::Set('IP', $_SERVER['REMOTE_ADDR']);
- } else {
- self::Set('IP', '');
- }
- self::Set('InstallationHash', '');
- self::Set('ActionHash', BuildHash());
- self::Set('UniqueID', '');
- self::Set('CoreModules', array(
- MODULE_TICKETS,
- MODULE_CORE,
- MODULE_BASE,
- MODULE_LIVECHAT,
- MODULE_KNOWLEDGEBASE,
- MODULE_TROUBLESHOOTER,
- MODULE_NEWS,
- MODULE_DOWNLOADS,
- MODULE_REPORTS,
- MODULE_RINGROUTE,
- MODULE_ISSUES,
- MODULE_MANUALS,
- MODULE_PARSER
- ));
- /*
- * ###############################################
- * BEGIN OBJECT CREATION
- * ###############################################
- */
- try {
- // Create the Cookie Object
- $this->Cookie = new SWIFT_Cookie();
- // Connect to the Database
- $this->Database = new SWIFT_Database();
- if (!$this->Database->IsConnected()) {
- trigger_error('Unable to connect to Database. Please verify the username, password, grant permissions and the database status.', E_USER_ERROR);
- exit;
- }
- // Load the Registry
- $this->Registry = new SWIFT_Registry();
- // Load the CacheStore
- $this->Cache = new SWIFT_CacheStore();
- // Load the Interface
- $this->Interface = SWIFT_Interface::Load();
- // Load the main caches
- $this->Cache->LoadQueue();
- // Load the Settings
- $this->Settings = new SWIFT_Settings();
- // Load the Hook Interface
- $this->Hook = new SWIFT_Hook();
- // Load Interface Related Settings
- $this->Interface->LoadSettings();
- // Set the Installation Hash
- self::Set('InstallationHash', $this->Settings->GetKey('core', 'installationhash'));
- // Set up the timezome and whether or not to use daylight savings
- self::Set('timezone', ($this->Settings->Get('dt_timezonephp')) ? $this->Settings->Get('dt_timezonephp') : 'GMT');
- self::Set('daylightsavings', ($this->Settings->Get('dt_daylightsavings') == 1) ? true : false);
- // Configure PHP to use our time zone when dealing with datetime functions
- if (!date_default_timezone_set(SWIFT::Get('timezone'))) {
- // Fall back to UTC if for some reason PHP doesn't like the one we've chosen.
- date_default_timezone_set('GMT');
- }
- setlocale(LC_ALL, SWIFT_LOCALE);
- if (defined('SWIFTLOCALECTYPE')) {
- setlocale(LC_CTYPE, constant('SWIFTLOCALECTYPE'));
- }
- // Load the User Interface Files
- $this->LoadUserInterfaceFiles();
- // Parse Template Group from Router
- SWIFT_Router::ParseTemplateGroup();
- // Attempt to load the Template Engine
- $this->Template = SWIFT_TemplateEngine::LoadEngine();
- // Attempt to load the Language Engine
- $this->Language = SWIFT_LanguageEngine::LoadEngine();
- // Load the Template Engine Variables
- $this->Template->LoadVariables();
- // Parse the Modules from Settings
- SWIFT_Module::ParseRegisteredModules();
- SWIFT_Module::ParseConfig();
- // Load the User Interface Object
- $this->LoadUserInterfaceObject();
- // Load the Router
- $this->Router = SWIFT_Router::Load();
- }
- catch (Exception $_ExceptionObject) {
- SWIFT_Exception::GlobalExceptionHandler($_ExceptionObject);
- trigger_error($_ExceptionObject->getMessage(), E_USER_ERROR);
- exit;
- }
- /**
- * ###############################################
- * BEGIN LICENSE KEY CHECK
- * ###############################################
- */
- // Check for Expiry
- SWIFT_License::CheckExpired();
- // Check for Staff Licenses
- SWIFT_License::CheckValidStaff();
- // Check for Package
- SWIFT_License::CheckPackage();
- /**
- * ###############################################
- * END LICENSE KEY CHECK
- * ###############################################
- */
- /*
- * ###############################################
- * BEGIN CORE VARIABLE CREATION (PART 2)
- * ###############################################
- */
- $_interfaceType = $this->Interface->GetInterface();
- if ($_interfaceType == SWIFT_Interface::INTERFACE_ADMIN || $_interfaceType == SWIFT_Interface::INTERFACE_STAFF || $_interfaceType == SWIFT_Interface::INTERFACE_WINAPP || $_interfaceType == SWIFT_Interface::INTERFACE_SYNCWORKS || $_interfaceType == SWIFT_Interface::INTERFACE_RSS || $_interfaceType == SWIFT_Interface::INTERFACE_INTRANET || $_interfaceType == SWIFT_Interface::INTERFACE_PDA || $_interfaceType == SWIFT_Interface::INTERFACE_INSTAALERT || $_interfaceType == SWIFT_Interface::INTERFACE_MOBILE || $_interfaceType == SWIFT_Interface::INTERFACE_API) {
- $this->Language->Load('staffactivitylog');
- }
- /*
- * ###############################################
- * END CORE VARIABLE CREATION (PART 2)
- * ###############################################
- */
- try {
- // Load the Module
- $this->Module = $this->Router->GetModule();
- // Execute the relevant controller and load the related objects
- $this->Module->ExecuteController($this->Router);
- }
- catch (Exception $_ExceptionObject) {
- trigger_error($_ExceptionObject->GetTraceAsString() . SWIFT_CRLF . $_ExceptionObject->getMessage(), E_USER_ERROR);
- exit;
- }
- self::RunSystemChecks();
- /**
- * ###############################################
- * BEGIN LICENSE KEY CHECK
- * ###############################################
- */
- SWIFT_License::CheckValidDomain();
- /**
- * ###############################################
- * END LICENSE KEY CHECK
- * ###############################################
- */
- /*
- * ###############################################
- * PROCESS SHUTDOWN QUEUES
- * ###############################################
- */
- self::ProcessAllShutdownFunctions();
- /*
- * ###############################################
- * PROCESS EMAIL QUEUE
- * ###############################################
- */
- $_queueCount = $this->Settings->GetKey('mail', 'queuecount');
- if ($_queueCount) {
- require_once('./' . SWIFT_BASEDIRECTORY . '/' . SWIFT_LIBRARYDIRECTORY . '/Mail/class.SWIFT_MailQueueManager.php');
- $_SWIFT_MailQueueManagerObject = new SWIFT_MailQueueManager();
- $_SWIFT_MailQueueManagerObject->ProcessMailQueue();
- }
- self::Set('_endTime', GetMicroTime());
- $this->FirePHP->Info('Execution Time: ' . number_format(self::Get('_endTime') - self::Get('_startTime'), 5));
- return true;
- }
- /**
- * Process All Shutdown Functions
- *
- * @return bool "true" on Success, "false" otherwise
- */
- static public function ProcessAllShutdownFunctions()
- {
- self::ProcessShutdownQueue(-1);
- SWIFT_Model::ProcessShutdownUpdatePool();
- self::ProcessShutdownQueue();
- return true;
- }
- /**
- * Loads the User Interface Objects
- *
- * @return bool "true" on Success, "false" otherwise
- * @throws SWIFT_Exception If the Class is not Loaded
- */
- protected function LoadUserInterfaceFiles()
- {
- if ($this->Interface->GetInterface() == SWIFT_Interface::INTERFACE_CLIENT || $this->Interface->GetInterface() == SWIFT_Interface::INTERFACE_VISITOR || $this->Interface->GetInterface() == SWIFT_Interface::INTERFACE_RSS) {
- require_once('./' . SWIFT_BASEDIRECTORY . '/' . SWIFT_LIBRARYDIRECTORY . '/UserInterface/class.SWIFT_UserInterface.php');
- require_once('./' . SWIFT_BASEDIRECTORY . '/' . SWIFT_LIBRARYDIRECTORY . '/UserInterface/class.SWIFT_UserInterfaceClient.php');
- } else {
- require_once('./' . SWIFT_BASEDIRECTORY . '/' . SWIFT_LIBRARYDIRECTORY . '/UserInterface/class.SWIFT_UserInterface.php');
- require_once('./' . SWIFT_BASEDIRECTORY . '/' . SWIFT_LIBRARYDIRECTORY . '/UserInterface/class.SWIFT_UserInterfaceControlPanel.php');
- }
- return true;
- }
- /**
- * Loads the User Interface Objects
- *
- * @return bool "true" on Success, "false" otherwise
- * @throws SWIFT_Exception If the Class is not Loaded
- */
- protected function LoadUserInterfaceObject()
- {
- if ($this->Interface->GetInterface() == SWIFT_Interface::INTERFACE_CLIENT || $this->Interface->GetInterface() == SWIFT_Interface::INTERFACE_VISITOR || $this->Interface->GetInterface() == SWIFT_Interface::INTERFACE_RSS) {
- $this->UserInterface = new SWIFT_UserInterfaceClient();
- } else if ($this->Interface->GetInterface() == SWIFT_Interface::INTERFACE_STAFF || $this->Interface->GetInterface() == SWIFT_Interface::INTERFACE_INTRANET || $this->Interface->GetInterface() == SWIFT_Interface::INTERFACE_ADMIN) {
- $this->UserInterface = new SWIFT_UserInterfaceControlPanel();
- }
- return true;
- }
- /**
- * Check the Global Variables and Sanitize them
- *
- * @return bool "true" on Success, "false" otherwise
- * @throws SWIFT_Exception If the Class is not Loaded
- */
- protected function SanitizeGlobals()
- {
- /**
- * Possible globals overwrite attempt, so die
- */
- if (isset($_REQUEST['GLOBALS']) || isset($_FILES['GLOBALS'])) {
- throw new SWIFT_Exception('Globals overwrite attempt detected! Terminating.');
- exit;
- }
- /**
- * Unset all global variables except for the ones defined in _reserved, for servers where register_globals is enabled
- */
- $_reserved = array(
- '_reserved',
- 'GLOBALS',
- '_GET',
- '_POST',
- '_COOKIE',
- '_SERVER',
- '_ENV',
- '_REQUEST',
- '_FILES',
- 'argv'
- );
- if (is_array($GLOBALS)) {
- reset($GLOBALS);
- while (list($_key, $_val) = each($GLOBALS)) {
- if (!in_array($_key, $_reserved) && ($_key != '_key' && $_key != '_val')) {
- unset($GLOBALS[$_key]);
- }
- }
- }
- return true;
- }
- /**
- * Get the instance of this Class
- *
- * @return SWIFT SWIFT Instance
- */
- static public function GetInstance()
- {
- if (!self::$_Instance) {
- self::$_Instance = new SWIFT();
- self::$_Instance->Initialize();
- }
- return self::$_Instance;
- }
- /**
- * Retrieve the Value from the Value Container
- *
- * @param string $_key The Key
- * @return mixed "_valueContainer[_key]" (MIXED) on Success, "false" otherwise
- */
- static public function Get($_key)
- {
- if (!isset(self::$_valueContainer[$_key])) {
- return false;
- }
- return self::$_valueContainer[$_key];
- }
- /**
- * Set the Value in the Container
- *
- * @param string $_key The Key
- * @param mixed $_value The Value
- * @return bool "true" on Success, "false" otherwise
- */
- static public function Set($_key, $_value = '')
- {
- self::$_valueContainer[$_key] = $_value;
- return true;
- }
- /**
- * Set the Value in the Container
- *
- * @param string $_key The Key
- * @param mixed $_value The Value
- * @return bool "true" on Success, "false" otherwise
- */
- static public function SetReference($_key, &$_value)
- {
- if (empty($_key)) {
- return false;
- }
- if (empty($_value)) {
- unset(self::$_valueContainer[$_key]);
- return true;
- }
- self::$_valueContainer[$_key] =& $_value;
- return true;
- }
- /**
- * Retrieve the Info Container
- *
- * @return array The Info Container
- */
- static public function GetInfoContainer()
- {
- return self::$_infoContainer;
- }
- /**
- * Retrieve the Alert Container
- *
- * @return array The Alert Container
- */
- static public function GetAlertContainer()
- {
- return self::$_alertContainer;
- }
- /**
- * Retrieve the Error Container
- *
- * @return array The Error Container
- */
- static public function GetErrorContainer()
- {
- return self::$_errorContainer;
- }
- /**
- * Retrieve the Error Field Container
- *
- * @return array The Error Field Container
- */
- static public function GetErrorFieldContainer()
- {
- return self::$_errorFieldContainer;
- }
- /**
- * Resets all the Containers
- *
- * @return bool "true" on Success, "false" otherwise
- */
- static public function ResetAllContainers()
- {
- self::$_infoContainer = array();
- self::$_alertContainer = array();
- self::$_errorContainer = array();
- return true;
- }
- /**
- * Add to Info Container
- *
- * @param string $_title The Title
- * @param string $_message The Message
- * @return bool "true" on Success, "false" otherwise
- */
- static public function Info($_title, $_message)
- {
- if (empty($_title) || empty($_message)) {
- return false;
- }
- self::$_infoContainer[] = array(
- 'title' => $_title,
- 'message' => $_message
- );
- return true;
- }
- /**
- * Add to Alert Container
- *
- * @param string $_title The Title
- * @param string $_message The Message
- * @return bool "true" on Success, "false" otherwise
- */
- static public function Alert($_title, $_message)
- {
- if (empty($_title) || empty($_message)) {
- return false;
- }
- self::$_alertContainer[] = array(
- 'title' => $_title,
- 'message' => $_message
- );
- return true;
- }
- /**
- * Add to Error Container
- *
- * @param string $_title The Title
- * @param string $_message The Message
- * @return bool "true" on Success, "false" otherwise
- */
- static public function Error($_title, $_message)
- {
- if (empty($_title) || empty($_message)) {
- return false;
- }
- self::$_errorContainer[] = array(
- 'title' => $_title,
- 'message' => $_message
- );
- return true;
- }
- /**
- * Add to Error Field Container
- *
- * @param string $_fieldName The Field Name
- * @return bool "true" on Success, "false" otherwise
- */
- static public function ErrorField($_fieldName)
- {
- if (empty($_fieldName)) {
- return false;
- }
- if (count(func_get_args()) > 1) {
- foreach (func_get_args() as $_key => $_val) {
- if (!in_array($_val, self::$_errorFieldContainer)) {
- self::$_errorFieldContainer[] = $_val;
- }
- }
- } else {
- self::$_errorFieldContainer[] = $_fieldName;
- }
- return true;
- }
- /**
- * Set the relevant class
- *
- * @param string $_className The Local Class name
- * @param object $_SWIFTObject The Object
- * @return bool "true" on Success, "false" otherwise
- * @throws SWIFT_Exception If the Class is not Loaded
- */
- public function SetClass($_className, SWIFT_Base $_SWIFTObject)
- {
- $this->$_className = $_SWIFTObject;
- self::AddToObjectMap($_SWIFTObject);
- foreach (self::$_objectMapContainer as $_key => $_SWIFT_BaseObject) {
- if ($_SWIFT_BaseObject instanceof SWIFT_Base && $_SWIFT_BaseObject->GetIsClassLoaded()) {
- // echo 'SETTING2: ' . $_className . SWIFT_CRLF;
- $_SWIFT_BaseObject->UpdateObject($_className, $_SWIFTObject);
- }
- }
- return true;
- }
- /**
- * Add the object to object map
- *
- * @param SWIFT_Base $_SWIFT_BaseObject The Base Object
- * @return bool "true" on Success, "false" otherwise
- * @throws SWIFT_Exception If Invalid Data is Provided
- */
- static public function AddToObjectMap(SWIFT_Base $_SWIFT_BaseObject)
- {
- $_SWIFT = SWIFT::GetInstance();
- if ($_SWIFT_BaseObject instanceof SWIFT_Base && $_SWIFT_BaseObject->GetIsClassLoaded()) {
- self::$_objectMapContainer[] = $_SWIFT_BaseObject;
- }
- return true;
- }
- /**
- * Return the object map
- *
- * @return array The object map container
- * @throws SWIFT_Exception If Invalid Data is Provided
- */
- static public function GetObjectMap()
- {
- return self::$_objectMapContainer;
- }
- /**
- * Queue a function in object for shutdown execution
- *
- * @param mixed $_SWIFT_Object The SWIFT_Base Object Pointer or Name
- * @param string $_callBackFunction The Callback Function
- * @param int $_queueBatch The Batch of Execution to put in
- * @return bool "true" on Success, "false" otherwise
- * @throws SWIFT_Exception If Invalid Data is Provided
- */
- static public function Shutdown($_SWIFT_Object, $_callBackFunction, $_queueBatch = 1, $_replaceIndex = false)
- {
- global $_shutdownQueue;
- $_SWIFT = SWIFT::GetInstance();
- if ((is_object($_SWIFT_Object) && (!$_SWIFT_Object instanceof SWIFT_Base || !$_SWIFT_Object->GetIsClassLoaded())) || (is_string($_SWIFT_Object) && (empty($_SWIFT_Object) || !class_exists($_SWIFT_Object)))) {
- throw new SWIFT_Exception(SWIFT_INVALIDDATA);
- }
- $_functionArguments = func_get_args();
- $_finalFunctionArguments = array();
- foreach ($_functionArguments as $_key => $_val) {
- if ($_key > 3) {
- $_finalFunctionArguments[] = $_val;
- }
- }
- /* if (is_string($_SWIFT_Object)) {
- echo 'S:' . $_SWIFT_Object;
- } else {
- echo 'C:' . get_class($_SWIFT_Object) . '(' . $_SWIFT_Object->GetInstanceID() . ')';
- }
- echo '::' . $_callBackFunction . '<br />';
- echo '<br />' . SWIFT_CRLF;*/
- $_index = 0;
- if (isset($_shutdownQueue[$_queueBatch])) {
- $_index = count($_shutdownQueue[$_queueBatch]);
- } else {
- $_shutdownQueue[$_queueBatch] = array();
- }
- if ($_replaceIndex !== false) {
- $_index = $_replaceIndex;
- // echo 'REPLACING: ' . $_index;
- }
- $_shutdownQueue[$_queueBatch][$_index] = array(
- $_SWIFT_Object,
- $_callBackFunction,
- $_finalFunctionArguments
- );
- return $_index;
- }
- /**
- * Print the shutdown queue
- *
- * @param int $_batchNumber (OPTIONAL) Print the queue for a specific batch number
- * @return bool "true" on Success, "false" otherwise
- * @throws SWIFT_Exception If Invalid Data is Provided
- */
- static public function PrintShutdownQueue($_batchNumber = false)
- {
- global $_shutdownQueue;
- $_SWIFT = SWIFT::GetInstance();
- for ($index = -1; $index <= 10; $index++) {
- $_batchNumber = $index;
- if (!isset($_shutdownQueue[$_batchNumber]) || !_is_array($_shutdownQueue[$_batchNumber])) {
- continue;
- }
- $_queueContainerList = $_shutdownQueue[$_batchNumber];
- foreach ($_queueContainerList as $_queueContainer) {
- if (is_string($_queueContainer[0])) {
- echo 'S:' . $_queueContainer[0];
- } else {
- echo 'C:' . get_class($_queueContainer[0]) . '(' . $_queueContainer[0]->GetInstanceID() . ')';
- }
- echo '::' . $_queueContainer[1] . '<br />';
- echo '<br />' . SWIFT_CRLF;
- }
- }
- return true;
- }
- /**
- * Process the shutdown queue
- *
- * @param int $_batchNumber (OPTIONAL) Process the queue for a specific batch number
- * @return bool "true" on Success, "false" otherwise
- * @throws SWIFT_Exception If Invalid Data is Provided
- */
- static public function ProcessShutdownQueue($_batchNumber = false)
- {
- global $_shutdownQueue;
- $_SWIFT = SWIFT::GetInstance();
- if ($_batchNumber !== false) {
- if (isset($_shutdownQueue[$_batchNumber]) && _is_array($_shutdownQueue[$_batchNumber])) {
- foreach ($_shutdownQueue[$_batchNumber] as $_queueContainer) {
- $_result = call_user_func_array(array(
- $_queueContainer[0],
- $_queueContainer[1]
- ), $_queueContainer[2]);
- }
- }
- $_shutdownQueue[$_batchNumber] = array();
- return true;
- }
- for ($index = -1; $index <= 10; $index++) {
- $_batchNumber = $index;
- // $_SWIFT->FirePHP->Info('Processing Shutdown Queue Batch #' . $_batchNumber);
- if (!isset($_shutdownQueue[$_batchNumber]) || !_is_array($_shutdownQueue[$_batchNumber])) {
- $_shutdownQueue[$_batchNumber] = array();
- continue;
- }
- $_queueContainerList = $_shutdownQueue[$_batchNumber];
- foreach ($_queueContainerList as $_queueContainer) {
- call_user_func_array(array(
- $_queueContainer[0],
- $_queueContainer[1]
- ), $_queueContainer[2]);
- }
- }
- $_shutdownQueue = array();
- return true;
- }
- /**
- * Run the System Checks
- *
- * @return bool "true" on Success, "false" otherwise
- * @throws SWIFT_Exception If Invalid Data is Provided
- */
- static public function RunSystemChecks()
- {
- $_SWIFT = SWIFT::GetInstance();
- if ((SWIFT_INTERFACE == 'staff' || SWIFT_INTERFACE == 'admin' || SWIFT_INTERFACE == 'intranet') && file_exists('./setup') && is_dir('./setup') && SWIFT::Get('IP') != '127.0.0.1') {
- echo '<div style="position: absolute; left: 10px; top: 0; right: 10px; border: 1px SOLID darkred; background: #ffefbb; z-index: 999999999;"><font face="verdana, arial, helvetica, serif" size="3" color="red"><b>ERROR:</b> Setup directory has not been deleted. It is recommended that you immediately delete the setup directory to prevent any damage to your database.<br /><br />For more information please contact the kayako support at <a href="https://my.kayako.com" target="blank">https://my.kayako.com</a></font></div>';
- } else if ((SWIFT_INTERFACE == 'staff' || SWIFT_INTERFACE == 'admin' || SWIFT_INTERFACE == 'intranet') && $_SWIFT->Settings->GetKey('core', 'version') != SWIFT_VERSION) {
- echo '<div style="position: absolute; left: 10px; top: 0; right: 10px; border: 1px SOLID darkred; background: #ffefbb; z-index: 999999999;"><font face="verdana, arial, helvetica, serif" size="3" color="red"><b>ERROR:</b> Product file version (' . SWIFT_VERSION . ') does not match with the database version (' . $_SWIFT->Settings->GetKey('core', 'version') . '). Please run the upgrade script to ensure that the product is up to date.<br /><br />For more information please contact the kayako support at <a href="https://my.kayako.com" target="blank">https://my.kayako.com</a></font></div>';
- }
- return true;
- }
- /**
- * Cache an Object
- *
- * @param SWIFT_Base $_SWIFT_BaseObject
- * @param int $_objectIdentifier The Unique Object Identifier
- * @return bool "true" on Success, "false" otherwise
- * @throws SWIFT_Exception If Invalid Data is Provided
- */
- static public function CacheObject(SWIFT_Base $_SWIFT_BaseObject, $_objectIdentifier)
- {
- $_SWIFT = SWIFT::GetInstance();
- $_className = get_class($_SWIFT_BaseObject);
- if (!isset(self::$_objectCache[$_className])) {
- self::$_objectCache[$_className] = array();
- }
- self::$_objectCache[$_className][$_objectIdentifier] = $_SWIFT_BaseObject;
- return true;
- }
- /**
- * Check to see if object is cached
- *
- * @param SWIFT_Base $_SWIFT_BaseObject
- * @param int $_objectIdentifier The Unique Object Identifier
- * @return bool "true" on Success, "false" otherwise
- * @throws SWIFT_Exception If Invalid Data is Provided
- */
- static public function IsObjectCached(SWIFT_Base $_SWIFT_BaseObject, $_objectIdentifier)
- {
- $_SWIFT = SWIFT::GetInstance();
- $_className = get_class($_SWIFT_BaseObject);
- if (isset(self::$_objectCache[$_className][$_objectIdentifier])) {
- return true;
- }
- return false;
- }
- /**
- * Retrieve the Cached Object
- *
- * @param SWIFT_Base $_SWIFT_BaseObject
- * @param int $_objectIdentifier The Unique Object Identifier
- * @return bool "true" on Success, "false" otherwise
- * @throws SWIFT_Exception If Invalid Data is Provided
- */
- static public function GetCachedObject(SWIFT_Base $_SWIFT_BaseObject, $_objectIdentifier)
- {
- $_SWIFT = SWIFT::GetInstance();
- $_className = get_class($_SWIFT_BaseObject);
- if (isset(self::$_objectCache[$_className][$_objectIdentifier])) {
- return self::$_objectCache[$_className][$_objectIdentifier];
- }
- throw new SWIFT_Exception(SWIFT_INVALIDDATA);
- return false;
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement