Index: trunk/core/units/general/helpers/modules.php =================================================================== diff -u -N -r4490 -r4590 --- trunk/core/units/general/helpers/modules.php (.../modules.php) (revision 4490) +++ trunk/core/units/general/helpers/modules.php (.../modules.php) (revision 4590) @@ -4,7 +4,7 @@ function checkLogin() { - return $this->_ValidateModules(); + return $this->_GetModules(); } function _EnableCookieSID() @@ -29,28 +29,6 @@ return in_array($UserAgent, $robots); } - function _StripDomainHost($d) - { - $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; - } - function _MatchIp($ip1, $ip2) { $matched = TRUE; @@ -94,205 +72,169 @@ return $Result; } - function _ValidateModules() - { - global $i_Keys, $g_License; - - $this->_readConfig(); - - $lic = base64_decode($g_License); - $this->_ParseLicense($lic); - - $modules = array(); - //echo "License: ".$lic."
"; - $domain = $this->_GetDomain(); - //echo "Domain: ".$domain."
"; - if(!$this->_IsLocalSite($domain)) - { - $domain = $this->_StripDomainHost($domain); - //echo "New domain: $domain
"; - // echo "
"; print_r($i_Keys); echo "
"; - for($x=0;$x0) - { - return TRUE; - } - } - else - return TRUE; - return FALSE; - } - + /** + * Reads config.php file and parses it + * + */ function _readConfig() { - static $config_read = false; - if (!$config_read) { - $vars = parse_portal_ini(FULL_PATH.'/config.php'); - - foreach ($vars as $config_key => $config_value) { - $GLOBALS['g_'.$config_key] = $config_value; - } - $config_read = true; + $vars = parse_portal_ini(FULL_PATH.'/config.php'); + + foreach ($vars as $config_key => $config_value) { + $GLOBALS['g_'.$config_key] = $config_value; } } - function _ModuleLicensed($name) + /** + * Returns modules list, that are in license + * + * @return Array + */ + function _GetModules() { - global $i_Keys; - - $this->_readConfig(); + global $i_Keys; + static $modules = null; - $lic = base64_decode($GLOBALS['g_License']); - - $this->_ParseLicense($lic); - $modules = array(); - if(!$this->_IsLocalSite($this->_GetDomain())) - { - for($x=0;$x_readConfig(); + $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(strlen(stristr($this->_GetDomain(),$key["domain"]))) - { - //echo "ok
"; - $modules = explode(",",$key["mod"]); + if (preg_match('/(.*)'.preg_quote($key['domain'], '/').'$/', $domain)) { + // used hostname is subdomain or matches domain from license + $modules = explode(',', $key['mod']); } } - //print_pre($modules); - if(in_array($name,$modules)) { - //echo "ok
"; - return TRUE; - } } else { - return TRUE; + $modules = array_keys($this->Application->ModuleInfo); } - return FALSE; + return $modules; } - function _GetDomain() + /** + * Allows to determine if module is licensed + * + * @param string $name + * @return bool + */ + function _ModuleLicensed($name) { - global $g_Domain; + $modules = $this->_GetModules(); + return in_array($name, $modules); + } - if ($this->Application->ConfigValue('DomainDetect')) { - $d = $_SERVER['HTTP_HOST']; - } - else { - $d = $g_Domain; - } - return $d; + /** + * Returns domain from licences (and direct in case of install script) + * + * @return string + */ + function _GetDomain() + { + return $this->Application->ConfigValue('DomainDetect') ? $_SERVER['HTTP_HOST'] : $GLOBALS['g_Domain']; } - function _keyED($txt,$encrypt_key) + function _keyED($txt, $encrypt_key) { - $encrypt_key = md5($encrypt_key); - $ctr=0; - $tmp = ""; - for ($i=0;$i_keyED($txt,$key); - $tmp = ""; - for ($i=0;$i_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 ""; + return ''; } function DLid() { - global $lid; - echo $lid."\n"; - die(); + die($GLOBALS['lid']."\n"); } - function _LoadLicense($LoadRemote=FALSE) + function _LoadLicense($LoadRemote = false) { $f = FULL_PATH.'/intechnic.php'; if ($this->_falseIsLocalSite($f)) $ret = true; - if(file_exists($f)) - { + if (file_exists($f)) { $contents = file($f); $data = base64_decode($contents[1]); } - else - if($LoadRemote) - return $LoadFromRemote; + else { + if ($LoadRemote) return $LoadFromRemote; + } return $data; } - function _VerifyKey($domain,$k) + function _VerifyKey($domain, $k) { $key = md5($domain); - $lkey = substr($key,0,strlen($key)/2); - $rkey = substr($key,strlen($key)/2); + $lkey = substr($key, 0, strlen($key) / 2); + $rkey = substr($key, strlen($key) / 2); $r = $rkey.$lkey; - if($k==$r) - return TRUE; - return FALSE; + if ($k == $r) return true; + return false; } function _ParseLicense($txt) { - global $i_User, $i_Pswd, $i_Keys; + 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_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; - } - } + $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)