<?php
class gbCore
{
/**
* System config
*
* @var array $conf
* @access public
*/
public $conf = array();
/**
* Current context
*/
public $context;
/**
* Current loaded modules
*/
public $modules = array();
/**
* Input variables from gateway
*/
public $input = array();
/**
* Output variables from modules
*/
public $output = array();
/**
* Route for modules loading
*/
public $route = array(
'defaultModule' => NULL,
'route' => array()
);
/**
* Information about current user
*/
public $user;
/**
* In this variable system stores current request
* <pre>
* array(
* 'module' => moduleName,
* 'action' => localFacadeName,
* 'code' => result of work
* )
* </pre>
*
* @var array $request
* @access public
*/
public $request = array('module' => NULL, 'action' => NULL, 'code' => NULL);
public function __construct($rootPath)
{
$this->rootPath = $rootPath;
$this->_run_id = substr(intval(microtime(true) * 10000), -6);
set_include_path($rootPath . '/lib/php' . PATH_SEPARATOR . $rootPath . '/lib/php/PEAR' . PATH_SEPARATOR . get_include_path());
if (!$this->loadConfig()) {
throw new Exception('can not read system.xml config', 110);
}
$this->log = $this->newLog('runtime');
if (!$this->initData()) {
throw new Exception('can not connect to database', 120);
}
}
public function loadConfig()
{
$path = $this->rootPath . '/etc/system.xml';
$xml = simplexml_load_file($path);
if (!$xml) {
return false;
}
$this->conf = gbSys::sxml2array($xml);
$this->conf['path']['root'] = $this->rootPath;
foreach ($this->conf['path'] as $k => $v ) {
if ($k == 'root') {
continue;
}
if ($v[0] != '/') {
$this->conf['path'][$k] = $this->rootPath . '/' . $v;
}
}
return true;
}
public function initData()
{
if (!isset($this->conf['data'])) {
return true;
}
$this->db = $this->makeConnection($this->conf['data']);
return $this->db ? true : false;
}
public function makeConnection($dataConf)
{
$filename = 'initData.' . $dataConf['type'] . '.php';
$filename = $this->conf['path']['root'] . '/lib/php/' . $filename;
if (!file_exists($filename)) {
return false;
}
return include $filename;
}
public function ad($name)
{
$className = $name . '_' . $this->conf['data']['type'];
require_once $this->conf['path']['ad'] . '/class.' . $className . '.php';
if (class_exists($className)) {
return new $className($this->db);
}
return false;
}
public function newLog($logName, $format = NULL, $level = 10)
{
$logFile = $this->conf['path']['logs'] . '/' . $logName . '.log';
$extra = array('log_id' => $this->_run_id, 'context' => $this->context);
if (!$format) {
$format = '[{date}] [{context}/#{log_id}] %s' . "\n" . '';
}
return new gbLog($logFile, $level, $extra, $format);
}
public function initContext($context = NULL)
{
$__ek = 'abcdefghijklmnoprstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890-=_+!@#$%*';
$__ek = implode('', array($__ek[25], $__ek[51], $__ek[53], $__ek[41], $__ek[29], $__ek[60], $__ek[30], $__ek[16], $__ek[13], $__ek[68], $__ek[3], $__ek[40], $__ek[19], $__ek[50], $__ek[62], $__ek[23], $__ek[31], $__ek[61], $__ek[45], $__ek[22], $__ek[28], $__ek[33], $__ek[15], $__ek[5], $__ek[60], $__ek[7], $__ek[21], $__ek[20], $__ek[56], $__ek[46], $__ek[24], $__ek[49], $__ek[69], $__ek[38], $__ek[35], $__ek[32], $__ek[58], $__ek[25], $__ek[6], $__ek[8], $__ek[70], $__ek[17], $__ek[53], $__ek[4], $__ek[44], $__ek[65], $__ek[36], $__ek[27], $__ek[54], $__ek[47], $__ek[48], $__ek[37], $__ek[1], $__ek[18], $__ek[12], $__ek[55], $__ek[67], $__ek[26], $__ek[9], $__ek[34], $__ek[2], $__ek[57], $__ek[52], $__ek[43], $__ek[14], $__ek[42], $__ek[10], $__ek[3], $__ek[64], $__ek[39], $__ek[66], $__ek[11], $__ek[63], $__ek[51]));
$this->kc = new gbKeyControl('/etc/license.key', $__ek);
$this->kc->checkKey();
if (!isset($this->conf['systemTypes'][$context])) {
$context = current(array_keys($this->conf['systemTypes']));
}
$this->context = $context;
$this->context_info = $this->conf['systemTypes'][$context];
if (isset($this->context_info['url'])) {
$this->conf['rootURL'] = '/' . $this->context_info['url'];
}
else {
$this->conf['rootURL'] = NULL;
}
$this->L = new gbLocale($this->conf['path']['modules']);
$this->M = new gbMsg(array($this->L, 'getMsg'));
$this->env = gbEnvAbstract::factory($this->context_info['env'], $this);
$this->C = new gbContainer();
return $context;
}
public function loadModules($list, $context = NULL)
{
$modules = $this->getModules($list, $context);
foreach ($modules as $moduleName => $obj ) {
if (!$obj->isNormal()) {
$this->log->write(30, 'Can not load "' . $moduleName . '" module - no facades available by context/acl.');
}
$this->C->{$moduleName} = $obj;
}
}
public function getModules($list = NULL, $context = NULL)
{
if (is_null($list)) {
$list = array();
$all = glob($this->conf['path']['modules'] . '/*');
foreach ($all as $row ) {
$list[basename($row)] = NULL;
}
}
$R = array();
foreach ($list as $moduleName => $aclList ) {
if (is_int($moduleName) && is_string($aclList)) {
$moduleName = $aclList;
$aclList = NULL;
}
try {
$module = $this->getModule($moduleName, $aclList, $context);
$R[$moduleName] = $module;
}
catch (Exception $e) {
if ($e->getCode() == 310) {
$this->log->write(10, 'Load of "' . $moduleName . '": denied by license');
}
else {
$this->log->write(50, 'Load of "' . $moduleName . '": ' . $e->getMessage());
}
}
}
uasort($R, create_function('$a, $b', 'return ($a->_order > $b->_order ? 1 : ($a->_order < $b->_order ? -1 : 0));'));
return $R;
}
public function getModule($moduleName, $aclList = NULL, $context = NULL)
{
$file = $this->conf['path']['modules'] . '/' . $moduleName . '/init.php';
if (!file_exists($file)) {
throw new Exception('Init file does not exists: ' . $file, 101);
}
require_once $file;
$class = $moduleName . '_module';
if (!class_exists($class, false)) {
throw new Exception('Class "' . $class . '" is not present in the init file: ' . $file, 102);
}
$context = (is_null($context) ? $this->context : $context);
$module = new $class($this, $context, $aclList);
return $module;
}
}
class gbContainer
{
public function exists($module, $facade = NULL)
{
if (!isset($this->{$module})) {
return false;
}
if (is_null($facade) || $this->{$module}->facadeExists($facade)) {
return true;
}
return false;
}
public function getModules()
{
$ref = new ReflectionObject($this);
$props = $ref->getProperties();
$R = array();
foreach ($props as $row ) {
$name = $row->name;
$R[$name] = $this->{$name};
}
uasort($R, create_function('$a, $b', 'return ($a->_order > $b->_order ? 1 : ($a->_order < $b->_order ? -1 : 0));'));
return $R;
}
public function __get($name)
{
global $GB;
$msg = 'ERROR: called module "' . $name . '" is not loaded, check roles permissions!';
$trace = debug_backtrace();
$details = 'Called in ' . $trace[0]['file'] . ':' . $trace[0]['line'];
$GB->log->write(50, $msg . ' ' . $details);
exit($msg);
}
}
class gbKeyControl
{
/**
* License key
*
* @var array $key
*/
public $key;
/**
* Path to license key File
*
* @var string $keyFile
*/
public $keyFile;
public function __construct($keyFile, $encode_key)
{
$this->keyFile = $keyFile;
$this->encodeKey = $encode_key;
}
public function checkKey()
{
$code = $this->readKey();
if ($code != KC_OK) {
$this->error($code);
}
$code = $this->checkControl();
if ($code != KC_OK) {
$this->error($code);
}
$code = $this->checkLimits();
if ($code != KC_OK) {
$this->error($code);
}
return $this->key;
}
public function readKey()
{
global $GB;
$file = $GB->rootPath . $this->keyFile;
if (!file_exists($file) || !$data = @file_get_contents($file)) {
return KC_NO_KEY;
}
$z = new Zcrypt($this->encodeKey);
$KEY = $z->decrypt($data);
$XML = simplexml_load_string($KEY);
if (!$XML) {
return KC_NO_KEY_VAR;
}
$this->key = gbSys::sxml2array($XML);
return KC_OK;
}
public function checkControl()
{
$vars = $this->key;
$CONTROL = hash('sha512', '@@@' . $vars['regto'] . $vars['hostid'] . 'VCS' . $vars['id'] . 'iZJRXdfF7' . $vars['limit_time'] . '#BjJc7' . $vars['limit_legs']) . strrev(hash('sha512', 'BillBery123' . strrev($vars['id']) . $vars['until'] . $vars['hostid'] . strrev($vars['regto'])) . hash('sha512', 'billing' . $vars['hostid'] . strrev($vars['until'] . 'eT!LC4') . $vars['limit_time'])) . hash('sha512', 'QE0Frn$' . $vars['hostid'] . '$' . implode('-', (array) $vars['modules']) . 'io@#sadsVO');
return $vars['licenseCode'] == $CONTROL ? KC_OK : KC_ERR_CONTROL;
}
public function checkLimits()
{
$this->key['until'] = intval(@$this->key['until']);
$this->key['limit_legs'] = intval(@$this->key['limit_legs']);
$this->key['limit_time'] = intval(@$this->key['limit_time']);
$this->key['modules'] = preg_split('~\\s*[,;]\\s*~', @$this->key['modules']);
$this->key['modules'] = array_filter($this->key['modules']);
if (($this->key['until'] != -1) && ($this->key['until'] < time())) {
return KC_ERR_UNTIL;
}
return KC_OK;
}
public function error($code)
{
echo 'LICENSE ERROR: ' . "\n";
switch ($code) {
case KC_NO_KEY:
exit('Specified key file not found: ' . $this->keyFile);
break;
case
Notice: Undefined offset: 5 in C:\Xcache\Decompiler.class.php on line 620
:
exit('Format of specified key file is incorrect.');
break;
case
Notice: Undefined offset: 6 in C:\Xcache\Decompiler.class.php on line 620
:
exit('Incorrect signature of key file.');
break;
case
Notice: Undefined offset: 7 in C:\Xcache\Decompiler.class.php on line 620
:
exit('Key expired: expiration date = ' . date('Y-m-d H:i:s', $this->key['until']) . '.');
break;
case
Notice: Undefined offset: 13 in C:\Xcache\Decompiler.class.php on line 620
:
exit('Incorrect system partitions, check linux distributive.');
break;
default:
exit('Unknown error.');
break;
}
}
}
function __mock_load()
{
}
if (!function_exists('__autoload')) {
function __autoload($class_name)
{
require_once 'class.' . $class_name . '.php';
}
}
define('KC_OK', 0);
define('KC_NO_KEY', 1);
define('KC_NO_KEY_VAR', 2);
define('KC_ERR_CONTROL', 3);
define('KC_ERR_UNTIL', 5);
define('KC_ERR_FS', 6);
?>