/** * Perform request to registry server * * @param string $command * @param array $data * @return TransportResponse */ public final function Request($command, $data = array()) { // Init transport if (!$this->Transport->IsConnected()) { try { if (!$this->Transport->Connect()) { throw new Exception(_('Could not connect to registry server')); } } catch (Exception $e) { throw new Exception(_('Could not connect to registry server') . ". {$e->getMessage()}"); } try { if (!$this->Transport->Login()) { throw new Exception(_('Could not authenticate on registry server')); } } catch (Exception $e) { throw new Exception(_('Could not authenticate on registry server') . ". {$e->getMessage()}"); } } // Perform request $start_time = microtime(true); try { $result = $this->Transport->Request($command, $data); } catch (Exception $e) { // ����� ����������� ������� � �������� ���� � ��� � ���. ����� ������ ��� ������ ����� ��� ���������� ��� ������� ����.. Log::Log(sprintf("Request to registry failed with Exception: %s", $e->getMessage()), E_USER_ERROR); throw $e; } $request_time = microtime(true) - $start_time; // // Override registry errors by ones that defined in XML manifest // $errors_override = $this->Manifest->GetOverriddenErrors(); foreach ($errors_override as $eo) { switch ($eo["match"]) { case "like": if (strpos($result->ErrMsg, $eo["str"]) !== false) { $result->ErrMsg = $eo["error"]; } break; case "equal": if ($result->ErrMsg == $eo["str"]) { $result->ErrMsg = $eo["error"]; } break; } } Log::Log(sprintf("Request took %d seconds", $request_time), E_USER_NOTICE); return $result; }
function testManifests() { $manifests = glob(CONFIG::$PATH.'/modules/registries/*/module.xml'); foreach ($manifests as $manifest) { preg_match('/(.*)\/(.*)\/module\.xml/', $manifest, $matches); $module_name = $matches[2]; try { $res = RegistryManifest::Validate($manifest); $this->assertTrue(($res === true), "{$module_name} registry module passed manifest test!"); if ($res !== true) $this->error(E_USER_ERROR, $res, null, null); } catch(Exception $e) { $this->error(E_USER_ERROR, $e->getMessage(), $e->getFile(), $e->getLine()); } } }
/** * @access public * @param string $TLD TLD part, without dot * @param bool $extended If true, return all TLD's exports by module * @return Registry */ public function GetRegistryByExtension($extension, $db_check = true, $ignore_cache = false) { $db = Core::GetDBInstance(); $extensions = $this->GetExtensionList($db_check); if (in_array($extension, $extensions)) { $this->ListModules(); $module_name = $this->Modules[$extension]; if (!$module_name) { throw new Exception(sprintf(_("Module not defined for %s domain extension."), $extension)); } // Validate license for this module if (!License::IsModuleLicensed($module_name)) { switch (CONTEXTS::$APPCONTEXT) { case APPCONTEXT::CRONJOB: case APPCONTEXT::REGISTRAR_CP: $message = "Your license does not permit module {$module_name}. For additional module purchases, please contact sales@webta.net"; break; case APPCONTEXT::REGISTRANT_CP: $message = sprintf(_("Application license does not permit module %s. Please contact %s"), $module_name, UI::GetSupportEmailLink()); break; case APPCONTEXT::ORDERWIZARD: $message = "Your license does not permit module {$module_name}. For additional module purchases, please contact sales@webta.net"; break; } // Validate license for this module if (!License::IsModuleLicensed($module_name)) { throw new LicensingException($message); } } $Manifest = new RegistryManifest("{$this->ModulesPath}/{$module_name}/module.xml"); $module_codebase = $Manifest->GetModuleCodebase(); if (!$module_codebase) { $module_codebase = $module_name; } $this->LoadRegistryModule($module_codebase); if (!$this->ModulesCache[$extension] || $ignore_cache) { $reflect = new ReflectionClass("{$module_codebase}RegistryModule"); $Module = $reflect->newInstance($Manifest); $Config = $this->LoadModuleConfig($Module->GetConfigurationForm(), $module_name); $Module->InitializeModule($extension, $Config); $this->ModulesCache[$extension] = $Module; } } else { throw new Exception(sprintf(_("No modules configured to handle extension '%s'"), $extension)); } return new Registry($this->ModulesCache[$extension]); }
private function CreateObject($row, RegistryManifest $registry_manifest = null) { // TODO: // Remove cross-reference to Registry $RegFactory = RegistryModuleFactory::GetInstance(); if ($row['TLD']) { $registry = $RegFactory->GetRegistryByExtension($row['TLD']); } else { $Manifest = new RegistryManifest(sprintf('%s/registries/%s/module.xml', MODULES_PATH, $row['module_name'])); $registryOptions = $Manifest->GetRegistryOptions(); if ((bool) $registryOptions->ability->section_shared_contacts) { // Contacts shared between sections. i.e. contact is suitable for all TLDs $rows = $this->DB->GetAll("SELECT tld FROM tlds WHERE modulename = ? AND isactive = 1", array($row['module_name'])); $tlds = array(); foreach ($rows as $_r) { $tlds[] = $_r['tld']; } } else { $Manifest->SetSection($row['section_name']); list($target) = $Manifest->GetSectionConfig()->xpath(sprintf("contact_groups/group[@name='%s']/targets/target[%d]", $row['groupname'], $row['target_index'] + 1)); if (!$target) { throw new ApplicationException(sprintf(_("Error in module manifest. Cannot find corresponding contact group for %s:%s"), $row['groupname'], $row['target_index'] + 1)); } $tlds = explode(',', $target->attributes()->tlds); if (!$tlds) { throw new ApplicationException(sprintf(_("Error in module manifest. Contact target tlds attribute is empty. " . "Module=%s, SectionName=%s, Index=%s"), $row["module_name"], $row["section_name"], $row['target_index'])); } // Ugly hack that helps contact to find it's configured module $in = array(); foreach ($tlds as $tld) { $in[] = "'{$tld}'"; } $tldrows = $this->DB->GetAll("SELECT TLD FROM tlds WHERE isactive=? AND modulename=? AND TLD IN (" . join(",", $in) . ")", array("1", $row['module_name'])); $tlds = array(); foreach ($tldrows as $tldrow) { $tlds[] = $tldrow["TLD"]; } } foreach ($tlds as $tld) { try { $registry = $RegFactory->GetRegistryByExtension($tld); break; } catch (Exception $e) { // TODO: // This may caught when tld going first in section is inactive. // Dirty bug itself. We must solve it Log::Log("Cannot load contact. tld={$tld} message=" . $e->getMessage(), E_USER_ERROR); } } if (!$registry) { throw new ApplicationException(sprintf(_("Cannot find registry object, that can handle contact ID=%d"), $row["id"])); } } $contact = $registry->NewContactInstanceByGroup($row['groupname']); $contact->Registry = $registry; // Map fields to properties foreach ($this->FieldPropertyMap as $field => $property) { $contact->{$property} = $row[$field]; } $disclose_data = $this->DB->GetAll('SELECT * FROM contacts_discloses WHERE contactid = ?', array($contact->CLID)); foreach ($disclose_data as $disclose_row) { $contact->SetDiscloseValue($disclose_row['field_name'], (int) $disclose_row['value']); } // Load contact fields //$contact_fields = $registry_manifest->GetContactFields($contact->Type); $contact_data = $this->DB->GetAll('SELECT * FROM contacts_data WHERE contactid = ?', array($contact->CLID)); $buf = array(); foreach ($contact_data as $contact_row) { //if (in_array($contact_row['field'], $contact_fields)) $buf[$contact_row['field']] = $contact_row['value']; } try { $contact->SetFieldList($buf, (bool) $row['strict_fields']); } catch (ErrorList $e) { Log::Log(sprintf("Strict data validation failed for contact %s. Marking this contact as non-strictly validated.", $contact->CLID), E_USER_WARNING); Log::Log(join('; ', $e->GetAllMessages()), E_USER_WARNING); $contact->SetFieldList($buf, false); } // Extra stored data is diff between raw contact fields and manifset's defined fields $contact->ExtraStoredData = array_diff_key($buf, $contact->GetFieldList()); // Add pending operations to contact $operations = $this->DB->GetAll("SELECT * FROM pending_operations WHERE objecttype='CONTACT' AND objectid=?", array($contact->ID)); foreach ($operations as $op) { $contact->AddPendingOperation($op["operation"]); } // Add contact to loaded objects storage $this->LoadedObjects[$contact->ID] = clone $contact; return $contact; }
} // Enable modules elseif($get_action == "enable" && $get_module) { // Check if this module licensed if (!License::IsModuleLicensed($get_module)) throw new LicensingException("Your license does not permit module {$get_module}. For additional module purchases, please contact sales@webta.net"); if (CONFIG::$DEV_DEMOMODE != 1) { $get_module = preg_replace("/[^A-Za-z0-9_-]+/", "", $get_module); // Validate Manifest RegistryManifest::LoadCompiledManifest(CONFIG::$PATH."/modules/registries/{$get_module}/module.xml", true); $res = RegistryManifest::Validate(CONFIG::$PATH."/modules/registries/{$get_module}/module.xml"); if ($res !== true) { Log::Log($res, E_USER_ERROR); $errmsg = sprintf(_("Module %s XML manifest did not pass validation. The following errors occured:"), $get_module); $err[] = $res; } if (!$errmsg) { try { $Registry = $RegistryModuleFactory->GetRegistryByName($get_module, true); } catch (Exception $e) {