Index: trunk/core/units/general/helpers/modules.php =================================================================== diff -u -N --- trunk/core/units/general/helpers/modules.php (revision 8397) +++ trunk/core/units/general/helpers/modules.php (revision 0) @@ -1,372 +0,0 @@ -_GetModules(); - } - - function getWhereClause() - { - $where_clause = Array('Loaded = 1'); - - if (!$this->Application->IsAdmin()) return implode(' AND ', $where_clause); - - $modules = $this->_GetModules(); - if ($modules) { - foreach ($modules as $module_index => $module) { - $modules[$module_index] = $this->Conn->qstr($module); - } - $where_clause[] = 'Name IN ('.implode(',', $modules).')'; - } - - return implode(' AND ', $where_clause); - } - - function _EnableCookieSID() - { - $session =& $this->Application->recallObject('Session'); - return $session->CookiesEnabled; - } - - function _IsSpider($UserAgent) - { - global $robots; - $lines = file(FULL_PATH.'/robots_list.txt'); - - if (!is_array($robots)) { - $robots = Array(); - for($i = 0; $i < count($lines); $i++) { - $l = $lines[$i]; - $p = explode("\t", $l, 3); - $robots[] = $p[2]; - } - } - return in_array($UserAgent, $robots); - } - - function _MatchIp($ip1, $ip2) - { - $matched = TRUE; - - $ip = explode('.', $ip1); - $MatchIp = explode('.', $ip2); - for ($i = 0; $i < count($ip); $i++) { - if($i == count($MatchIp)) break; - if (trim($ip[$i]) != trim($MatchIp[$i]) || trim($ip[$i]) == '*') { - $matched = FALSE; - break; - } - } - return $matched; - } - - function _IpAccess($IpAddress, $AllowList, $DenyList) - { - $allowed = explode(',', $AllowList); - $denied = explode(',', $DenyList); - - $MatchAllowed = FALSE; - for ($x = 0; $x < count($allowed); $x++) { - $ip = explode('.', $allowed[$x]); - - $MatchAllowed = $this->_MatchIp($IpAddress, $allowed[$x]); - if ($MatchAllowed) - break; - } - $MatchDenied = FALSE; - for ($x = 0; $x < count($denied); $x++) { - $ip = explode('.', $denied[$x]); - - $MatchDenied = $this->_MatchIp($IpAddress, $denied[$x]); - if ($MatchDenied) - break; - } - - $Result = (($MatchAllowed && !$MatchDenied) || (!$MatchAllowed && !$MatchDenied) || - ($MatchAllowed && $MatchDenied)); - return $Result; - } - - /** - * Reads config.php file and parses it - * - */ - function _readConfig() - { - $vars = parse_portal_ini(FULL_PATH.'/config.php'); - - foreach ($vars as $config_key => $config_value) { - $GLOBALS['g_'.$config_key] = $config_value; - } - } - - /** - * Leaves only domain part from hostname (e.g. extract "intechnic.lv" from "test.intechnic.lv") - * Used for admin login license check - * - * @param string $d - * @return string - */ - function _StripDomainHost($d) - { - $IsIp = false; - $dotcount = substr_count($d, '.'); - if ($dotcount == 3) { - $IsIp = true; - for ($x = 0; $x < strlen($d); $x++) { - if (!is_numeric(substr($d, $x, 1)) && substr($d, $x, 1) != '.') - { - $IsIp = false; - break; - } - } - } - - if ($dotcount > 1 && !$IsIp) { - $p = explode('.', $d); - $ret = $p[count($p) - 2].'.'.$p[count($p) - 1]; - } - else { - $ret = $d; - } - return $ret; - } - - /** - * When logging into admin then check only last 2 parts of host name VS domain in license - * - * @param string $user_domain - * @param string $license_domain - * @return int - */ - function _CheckDomain($user_domain, $license_domain) - { - if ($this->Application->IsAdmin()) { - $user_domain = $this->_StripDomainHost($user_domain); - return preg_match('/(.*)'.preg_quote($user_domain, '/').'$/', $license_domain); - } - else { - return preg_match('/(.*)'.preg_quote($license_domain, '/').'$/', $user_domain); - } - } - - /** - * Returns modules list, that are in license - * - * @return Array - */ - function _GetModules() - { - global $i_Keys; - static $modules = null; - - if (isset($modules)) return $modules; - - $this->_readConfig(); - $license = isset($GLOBALS['g_License']) ? base64_decode($GLOBALS['g_License']) : ''; - $this->_ParseLicense($license); - - $modules = Array(); - $domain = $this->_GetDomain(); - if (!$this->_IsLocalSite($domain)) { - for ($x = 0; $x < count($i_Keys); $x++) { - $key = $i_Keys[$x]; - if ($this->_CheckDomain($domain, $key['domain'])) { - // used hostname is subdomain or matches domain from license - $modules = explode(',', $key['mod']); - } - } - } - else { - $modules = array_keys($this->Application->ModuleInfo); - } - - array_push($modules, 'Core', 'Proj-base', 'Proj-CMS', 'Custom'); - return $modules; - } - - /** - * Allows to determine if module is licensed - * - * @param string $name - * @return bool - */ - function _ModuleLicensed($name) - { - $modules = $this->_GetModules(); - return in_array($name, $modules); - } - - /** - * Returns domain from licences (and direct in case of install script) - * - * @return string - */ - function _GetDomain() - { - $config_domain = isset($GLOBALS['g_Domain']) ? $GLOBALS['g_Domain'] : ''; - return $this->Application->ConfigValue('DomainDetect') ? $_SERVER['HTTP_HOST'] : $config_domain; - } - - function _keyED($txt, $encrypt_key) - { - $encrypt_key = md5($encrypt_key); - $ctr = 0; - $tmp = ''; - for ($i = 0; $i < strlen($txt); $i++) { - if ($ctr == strlen($encrypt_key)) $ctr = 0; - $tmp .= substr($txt, $i, 1) ^ substr($encrypt_key, $ctr, 1); - $ctr++; - } - return $tmp; - } - - - function _decrypt($txt, $key) - { - $txt = $this->_keyED($txt,$key); - $tmp = ''; - for ($i = 0; $i < strlen($txt); $i++) { - $md5 = substr($txt, $i, 1); - $i++; - $tmp .= (substr($txt, $i, 1) ^ $md5); - } - return $tmp; - } - - function LoadFromRemote() - { - return ''; - } - - function DLid() - { - die($GLOBALS['lid']."\n"); - } - - function _LoadLicense($LoadRemote = false) - { - $f = FULL_PATH.'/intechnic.php'; - if ($this->_falseIsLocalSite($f)) $ret = true; - if (file_exists($f)) { - $contents = file($f); - $data = base64_decode($contents[1]); - } - else { - if ($LoadRemote) return $LoadFromRemote; - } - return $data; - } - - function _VerifyKey($domain, $k) - { - $key = md5($domain); - $lkey = substr($key, 0, strlen($key) / 2); - $rkey = substr($key, strlen($key) / 2); - $r = $rkey.$lkey; - if ($k == $r) return true; - return false; - } - - function _ParseLicense($txt) - { - global $i_User, $i_Pswd, $i_Keys; - if (!$this->_falseIsLocalSite($txt)) $nah = false; - $data = $this->_decrypt($txt, 'beagle'); - $i_Keys = Array(); - $lines = explode("\n", $data); - for ($x = 0; $x < count($lines); $x++) { - $l = $lines[$x]; - $p = explode('=', $l, 2); - switch($p[0]) { - case 'Username': - $i_User = $p[1]; - break; - - case 'UserPass': - $i_Pswd = $p[1]; - break; - - default: - if (substr($p[0], 0, 3) == 'key') { - $parts = explode('|', $p[1]); - if ($this->_VerifyKey($parts[0], $parts[1])) { - unset($K); - $k['domain'] = $parts[0]; - $k['key'] = $parts[1]; - $k['desc'] = $parts[2]; - $k['mod'] = $parts[3]; - $i_Keys[] = $k; - } - } - break; - } - } - } - - function _GetObscureValue($i) - { - if ($i == 'x') return 0254; $z = ''; - if ($i == 'z') return 0x7F.'.'; - if ($i == 'c') return '--code--'; - if ($i >= 5 && $i < 7) return $this->_GetObscureValue($z)*$this->_GetObscureValue('e'); - if ($i > 30) return Array(0x6c,0x6f,0x63,0x61,0x6c,0x68,0x6f,0x73,0x74); - if ($i > 20) return 99; - if ($i > 10) return '.'.($this->_GetObscureValue(6.5)+1); - if ($i == 'a') return 0xa; - } - - function _Chr($val) - { - $x = $this->_GetObscureValue(25); - $f = chr($x).chr($x+5).chr($x+15); - return $f($val); - } - - function _IsLocalSite($domain) - { - $ee = $this->_GetObscureValue(35); $yy = ''; - foreach ($ee as $e) $yy .= $this->_Chr($e); - $localb = FALSE; - if(substr($domain,0,3)==$this->_GetObscureValue('x')) - { - $b = substr($domain,0,6); - $p = explode(".",$domain); - $subnet = $p[1]; - if($p[1]>15 && $p[1]<32) - $localb=TRUE; - } - $zz = $this->_GetObscureValue('z').$this->_GetObscureValue(5).'.'.(int)$this->_GetObscureValue(7).$this->_GetObscureValue(12); - $ff = $this->_GetObscureValue('z')+65; - $hh = $ff-0x18; - if($domain==$yy || $domain==$zz || substr($domain,0,7)==$ff.$this->_Chr(46).$hh || - substr($domain,0,3)==$this->_GetObscureValue('a').$this->_Chr(46) || $localb || strpos($domain,".")==0) - { - return TRUE; - } - return FALSE; - } - - function _falseIsLocalSite($domain) - { - $localb = FALSE; - if(substr($domain,0,3)=="172") - { - $b = substr($domain,0,6); - $p = explode(".",$domain); - $subnet = $p[1]; - if($p[1]>15 && $p[1]<32) - $localb=TRUE; - } - if($domain=="localhost" || $domain=="127.0.0.1" || substr($domain,0,7)=="192.168" || - substr($domain,0,3)=="10." || $localb || strpos($domain,".")==0) - { - return TRUE; - } - return FALSE; - } - } - -?> \ No newline at end of file