public function admin_export($id = null) { if (!$id) { $this->notice('invalid'); } $this->Template->recursive = -1; $template = $this->Template->read(array('name', 'description', 'author', 'header', 'footer'), $id); if (empty($template)) { $this->notice('invalid'); } $pattern = "/src=[\\\"']?([^\\\"']?.*(png|jpg|gif|jpeg))[\\\"']?/i"; preg_match_all($pattern, $template['Template']['header'], $images); $path = TMP . 'cache' . DS . 'newsletter' . DS . 'template' . DS . $template['Template']['name']; $Folder = new Folder($path, 0777); $slash = $Folder->correctSlashFor($path); App::import('File'); App::import('Folder'); $File = new File($path . DS . 'template.xml', true, 0777); $imageFiles = array(); if (!empty($images[1])) { foreach ($images[1] as $img) { $img = str_replace('/', $slash, $img); $img = str_replace('\\', $slash . $slash, $img); $imageFiles[] = $img; if (is_file(APP . 'webroot' . $img)) { $Folder->create(dirname($path . $img), 0777); $File->path = APP . 'webroot' . $img; $File->copy(dirname($path . $img) . DS . basename($img)); } } } $xml['template']['name'] = 'Infinitas Newsletter Template'; $xml['template']['generator'] = 'Infinitas Template Generator'; $xml['template']['version'] = $this->version; $xml['template']['template'] = $template['Template']['name']; $xml['template']['description'] = $template['Template']['description']; $xml['template']['author'] = $template['Template']['author']; $xml['data']['header'] = $template['Template']['header']; $xml['data']['footer'] = $template['Template']['footer']; $xml['files']['images'] = $imageFiles; App::Import('Helper', 'Xml'); $Xml = new XmlHelper(); $File->path = $path . DS . 'template.xml'; $File->write($Xml->serialize($xml)); App::import('Vendor', 'Zip', array('file' => 'zip.php')); $Zip = new CreateZipFile(); $Zip->zipDirectory($path, null); $File = new File($path . DS . 'template.zip', true, 0777); $File->write($Zip->getZippedfile()); $this->view = 'Media'; $params = array('id' => 'template.zip', 'name' => $template['Template']['name'], 'download' => true, 'extension' => 'zip', 'path' => $path . DS); $this->set($params); $Folder = new Folder($path); $Folder->read(); $Folder->delete($path); }
/** * XML宣言を生成 * IE6以外の場合のみ生成する * * @param array $attrib * @return string XML宣言 */ function header($attrib = array()) { $ua = @$_SERVER['HTTP_USER_AGENT']; if (!(ereg("Windows", $ua) && ereg("MSIE", $ua)) || ereg("MSIE 7", $ua)) { return parent::header($attrib); } }
public static function CreateSifLogEvents($header, $category, $code, $desc) { $db = Zend_Registry::get('my_db'); $xml = XmlHelper::buildSifLogEvent(Utility::createMessageId(), Utility::createTimestamp(), $header, $category, $code, $desc); $xml = str_replace('xmlns="http://www.sifinfo.org/uk/infrastructure/2.x"', '', $xml); $xml = str_replace('xmlns="http://www.sifinfo.org/infrastructure/2.x"', '', $xml); $xml = str_replace('xmlns="http://www.sifinfo.org/infrastructure/1.x"', '', $xml); $dataObject = new DataObject('sif_logentry'); $query = "select\r\n\t\t\t\t \tagent_registered.agent_id,\r\n\t\t\t\t\tagent_registered.agent_mode_id,\r\n agent_registered.context_id,\r\n agent_registered.zone_id\r\n\t\t\t\t from \r\n\t\t\t\t \t" . DBConvertor::convertCase('agent_registered') . " \r\n\t\t\t\t where \r\n\t\t\t\t \tagent_registered.context_id = " . $_SESSION["CONTEXT_ID"] . " \r\n\t\t\t\t\tand agent_registered.zone_id = " . $_SESSION["ZONE_ID"] . "\r\n\t\t\t\t\tand agent_registered.unregister_timestamp is null"; $result = $db->fetchAll($query); foreach ($result as $row) { switch (DB_TYPE) { case 'mysql': $agentId = intval($row->agent_id); $agentModeId = intval($row->agent_mode_id); $zoneId = intval($row->zone_id); $contextId = intval($row->context_id); break; case 'oci8': $agentId = intval($row->AGENT_ID); $agentModeId = intval($row->AGENT_MODE_ID); $zoneId = intval($row->ZONE_ID); $contextId = intval($row->CONTEXT_ID); break; } $data = array('event_timestamp' => new Zend_Db_Expr(DBConvertor::convertCurrentTime()), 'agent_id_sender' => intval(0), 'agent_id_rec' => $agentId, 'event_data' => $xml, 'object_id' => $dataObject->objectId, 'action_id' => intval(1), 'zone_id' => $zoneId, 'context_id' => $contextId, 'agent_mode_id' => $agentModeId); /* * $db->insert('event', $data); */ } }
public function setValue($value, $process = true) { if ($process == true) { $value = $this->process($value); } XmlHelper::setText($this->xml, $value != null ? $value : ""); }
private function __construct($objectId, $mySide) { $this->mySide = $mySide; $this->object = \steam_factory::get_object($GLOBALS["STEAM"]->get_id(), $objectId); if (!$this->object || !$this->object instanceof \steam_container) { throw new Exception("Wave side not found."); } //$controlObject = \steam_factory::get_object_by_name($GLOBALS["STEAM"]->get_id(), $this->object->get_path() . "/control.xml"); if (isset($controlObject) && $controlObject instanceof \steam_document) { $xmlStr = $controlObject->get_content(); $xml = simplexml_load_string($xmlStr); $children = $xml->children(); foreach ($children as $child) { if ($child->getName() == "OBJ_DESC") { $this->object->set_attribute(OBJ_DESC, $child->asXML()); } else { if ($child->getName() == "steamweb_type") { $this->object->set_attribute("WAVEPAGE_TYPE", $child->asXML()); } else { if ($child->getName() == "steamweb_type_config") { $subChildren = $child->children(); $map = XmlHelper::xml_to_array($subChildren[0]); $this->object->set_attribute("WAVEPAGE_TYPE_CONFIG", $map[0]); } else { if ($child->getName() == "steamweb_module_ssp") { $subChildren = $child->children(); $this->object->set_attribute("WAVEPAGE_MODULE_SSP_ALBUM_NO", $subChildren[0]->asXML()); } } } } } } }
private function processEvent() { $dom = $this->dom; $headerNode = $dom->getElementsByTagName('SIF_Header')->item(0); $originalMsgId = $headerNode->getElementsByTagName('SIF_MsgId')->item(0)->nodeValue; $originalSourceId = $headerNode->getElementsByTagName('SIF_SourceId')->item(0)->nodeValue; $originalTimestamp = $headerNode->getElementsByTagName('SIF_Timestamp')->item(0)->nodeValue; $validSourceId = Agent::checkSourceId($originalSourceId); if (!$validSourceId) { RegisterError::invalidSourceId($agent->sourceId, $originalMsgId); } else { $agent = new Agent($originalSourceId); if ($agent->isRegistered()) { $eventObjectNode = $dom->getElementsByTagName('SIF_EventObject')->item(0); $objectName = $eventObjectNode->getAttribute('ObjectName'); $objectAction = $eventObjectNode->getAttribute('Action'); $objectAction = strtolower($objectAction); if (!DataObject::objectExists($objectName)) { ProvisionError::invalidObject($originalSourceId, $originalMsgId, $objectName); exit; } else { $allowed = $this->hasPermission($objectName, $objectAction, $agent->agentId); if ($allowed) { $provider = DataObject::isProvider($objectName, $agent->agentId); if ($provider) { $this->publishEvent($agent->agentId, $objectName, $objectAction, $_SESSION['ZONE_VERSION'], $dom->saveXml($headerNode)); $timestamp = Utility::createTimestamp(); $msgId = Utility::createMessageId(); $sifMessageNode = $dom->getElementsByTagName('SIF_Message')->item(0); XmlHelper::buildSuccessMessage($msgId, $timestamp, $originalSourceId, $originalMsgId, 0, $originalMsg = null, $desc = null); } else { ProvisionError::notProviderError($originalSourceId, $originalMsgId); } } else { switch ($objectAction) { case 'add': ProvisionError::invalidPermissionToPublishAdd($originalSourceId, $originalMsgId, $objectName); break; case 'change': ProvisionError::invalidPermissionToPublishChange($originalSourceId, $originalMsgId, $objectName); break; case 'delete': ProvisionError::invalidPermissionToPublishDelete($originalSourceId, $originalMsgId, $objectName); break; } //switch for error message } //allowed } //object exist } else { RegisterError::notRegisteredError($originalSourceId, $originalMsgId); } //not registered } //valid sourceId }
public function getViews() { $aryViews = array(); $views_xml = XmlHelper::xpath($this->xml->ownerDocument, "/content/options/placeholders/descendant::placeholder[@name='{$this->name}']/descendant::view"); foreach ($views_xml as $view_xml) { $aryViews[] = new View($view_xml->getAttribute("path"), $view_xml); } return $aryViews; }
public function Subscribe($dom) { $this->dom = $dom; $this->processSubscribe(); $this->saveSubscribes(); $timestamp = Utility::createTimestamp(); $msgId = Utility::createMessageId(); $sifMessageNode = $dom->getElementsByTagName('SIF_Message')->item(0); XmlHelper::buildSuccessMessage($msgId, $timestamp, $this->originalSourceId, $this->originalMsgId, 0, $originalMsg = null, $desc = null); }
public static function notRegisteredError($originalSourceId, $originalMsgId) { $categoryCode = "5"; $sifCode = "1"; $shortDesc = "Registration Error"; $longDesc = "Agent Not Registerd"; $timestamp = Utility::createTimestamp(); $msgId = Utility::createMessageId(); XmlHelper::buildErrorMessage($categoryCode, $sifCode, $shortDesc, $longDesc, $msgId, $timestamp, $originalSourceId, $originalMsgId); }
/** * Cria o snapshot na pasta que esta configurada * * @return boolean */ public function generate() { $this->Menu = ClassRegistry::init("Cms.Menu"); $aDados = $this->Menu->find('all'); if (!$this->isUpToDate($aDados)) { App::import("Helper", "Xml"); App::import("File"); $oXml = new XmlHelper(); $oXml->header(); $oXml->serialize($aDados); $oFile = new File(Configure::read('Cms.CheckPoint.menus') . time() . ".xml", true, 0777); $oFile->append($oXml->header()); $oFile->append("<menus>"); $oFile->append($oXml->serialize($aDados)); $oFile->append("</menus>"); return true; } return false; }
public function Provide($dom) { $this->dom = $dom; $this->processProvide(); DataObject::saveProvides($this->provideObjects, $this->agent->agentId); $timestamp = Utility::createTimestamp(); $msgId = Utility::createMessageId(); $sifMessageNode = $dom->getElementsByTagName('SIF_Message')->item(0); XmlHelper::buildSuccessMessage($msgId, $timestamp, $this->originalSourceId, $this->originalMsgId, 0, $originalMsg = null, $desc = null); }
private function updateMessageQueue($agent, $originalMsgId, $msgId) { $res = DataObject::updateEvent($agent->agentId, $originalMsgId, $msgId); if ($res == 1) { $timestamp = Utility::createTimestamp(); $msgId_u = Utility::createMessageId(); XmlHelper::buildSuccessMessage($msgId_u, $timestamp, $agent->sourceId, $msgId, 0, $originalMsg = null, $desc = null); } else { GeneralError::EventACKError($this->xml); } }
public static function FormatRequestData(array $data, $outputType) { $requestData = ""; switch ($outputType) { case "xml": $requestData = urlencode('<?xml version="1.0" encoding="UTF-8"?><request>' . XmlHelper::array2xml($data) . '</request>'); break; case "json": $requestData = json_encode($data); break; } return $requestData; }
/** * get langugage setting * require xmlhelper */ static function getLanguageConfig() { $config = array(); $file_filter = JPATH_ADMINISTRATOR . '/components/com_bookpro/data/language_filter.xml'; $filter = JFactory::getXML($file_filter); $config['main_lang'] = 'en-GB'; $config['folder_site'] = JPATH_SITE . DS . "language" . DS; $config['folder_admin'] = JPATH_ADMINISTRATOR . DS . "language" . DS; //admin language file $config['file_admin'] = XmlHelper::getAttribute($filter->admin->file, 'name'); //site language file $config['file_site'] = XmlHelper::getAttribute($filter->site->file, 'name'); return $config; }
public function setOption($name, $value) { $xmlOptions = XmlHelper::getChildNode($this->xml, "options"); $lstOptions = $xmlOptions->childNodes; // look for option, set, exit foreach ($lstOptions as $xmlOption) { if ($xmlOption->getAttribute("name") == $name) { XmlHelper::setValue($xmlOption, $value); return; } } // add new option if not found $xmlNewOption = $this->xml->ownerDocument->createElement("option", ""); $xmlNewOption->setAttribute("name", $name); $xmlOptions->appendChild($xmlNewOption); }
private function processProvision() { $dom = $this->dom; $headerNode = $dom->getElementsByTagName('SIF_Header')->item(0); $this->originalMsgId = $headerNode->getElementsByTagName('SIF_MsgId')->item(0)->nodeValue; $this->originalSourceId = $headerNode->getElementsByTagName('SIF_SourceId')->item(0)->nodeValue; $this->originalTimestamp = $headerNode->getElementsByTagName('SIF_Timestamp')->item(0)->nodeValue; $validSourceId = Agent::checkSourceId($this->originalSourceId); if (!$validSourceId) { ProvisionError::invalidSourceId($this->originalSourceId, $this->originalMsgId); if (CODELEVEL != 3) { exit; } else { return false; } } else { $this->agent = new Agent($this->originalSourceId); if (!$this->agent->isRegistered()) { RegisterError::notRegisteredError($this->originalSourceId, $this->originalMsgId); } else { $provideObjectNode = $dom->getElementsByTagName('SIF_ProvideObjects')->item(0); $this->processProvideObjects($provideObjectNode); $subscribeObjectNode = $dom->getElementsByTagName('SIF_SubscribeObjects')->item(0); $this->processSubscribeObjects($subscribeObjectNode); $publishAddObjectNode = $dom->getElementsByTagName('SIF_PublishAddObjects')->item(0); $this->processPublishAddObjects($publishAddObjectNode); $publishChangeObjectNode = $dom->getElementsByTagName('SIF_PublishChangeObjects')->item(0); $this->processPublishChangeObjects($publishChangeObjectNode); $publishDeleteObjectNode = $dom->getElementsByTagName('SIF_PublishDeleteObjects')->item(0); $this->processPublishDeleteObjects($publishDeleteObjectNode); $requestObjectNode = $dom->getElementsByTagName('SIF_RequestObjects')->item(0); $this->processRequestObjects($requestObjectNode); $respondObjectNode = $dom->getElementsByTagName('SIF_RespondObjects')->item(0); $this->processRespondObjects($respondObjectNode); $this->saveProvisions(); $timestamp = Utility::createTimestamp(); $msgId = Utility::createMessageId(); $sifMessageNode = $dom->getElementsByTagName('SIF_Message')->item(0); XmlHelper::buildSuccessMessage($msgId, $timestamp, $this->originalSourceId, $this->originalMsgId, 0, $originalMsg = null, $desc = null); } } }
public function setOption($name, $value) { $xmlOptions = XmlHelper::getNode($this->xml, "options"); $lstOptions = $xmlOptions->childNodes; // search for option, if found, set & exit if ($lstOptions != null) { foreach ($lstOptions as $xmlOption) { if ($xmlOption->getAttribute("name") == $name) { XmlHelper::setValue($xmlOption, $value); return; } } } // create new option $xmlNewOption = $this->xml->ownerDocument->createElement("option"); $xmlNewOption->setAttribute("name", $name); XmlHelper::setValue($xmlNewOption, $value); $xmlOption->appendChild($xmlNewOption); return ""; }
public static function buildSuccessMessage($msgId, $timestamp, $originalSourceId, $originalMsgId, $sifCodeNum, $zoneVersion, $versionNamespace, $zoneName, $originalMsg = null, $desc = null) { $root = XmlHelper::buildSifAckMessage($msgId, $timestamp, $originalSourceId, $originalMsgId, $zoneVersion, $versionNamespace, $zoneName); $sifAck = $root->getElementsByTagName('SIF_Ack')->item(0); $sifStatusNode = $root->createElement('SIF_Status'); $sifCodeNode = $root->createElement('SIF_Code'); $text = $root->createTextNode($sifCodeNum); $sifCodeNode->appendChild($text); $sifStatusNode->appendChild($sifCodeNode); if ($desc != null) { $sifDesc = $root->createElement('SIF_Desc'); $text = $root->createTextNode($desc); $sifDesc->appendChild($text); $sifStatusNode->appendChild($sifDesc); } if ($originalMsg != null) { $f_dom = new DOMDocument('1.0', 'UTF-8'); $f_dom->preserveWhiteSpace = false; $f_dom->formatOutput = false; $f_dom->loadXML($originalMsg); $messageNode = $f_dom->getElementsByTagName('SIF_Message')->item(0); if ($messageNode == null) { $messageNode = $f_dom->getElementsByTagName('SIF_AgentACL')->item(0); if ($messageNode == null) { $messageNode = $f_dom->getElementsByTagName('SIF_ZoneStatus')->item(0); } } $xmlStr_ = $f_dom->saveXML($messageNode); $sifDataNode = $root->createElement('SIF_Data'); $f = $root->createDocumentFragment(); $f->appendXML($xmlStr_); $domNode = $root->importNode($f, true); $sifDataNode->appendChild($domNode); $sifStatusNode->appendChild($sifDataNode); } $sifAck->appendChild($sifStatusNode); $root->preserveWhiteSpace = false; $root->formatOutput = false; $xmlStr = $root->saveXML(); return $xmlStr; }
public function processUnregistration() { $dom = $this->xmlDom; $headerNode = $dom->getElementsByTagName('SIF_Header')->item(0); $originalMsgId = $headerNode->getElementsByTagName('SIF_MsgId')->item(0)->nodeValue; $originalSourceId = $headerNode->getElementsByTagName('SIF_SourceId')->item(0)->nodeValue; $originalTimestamp = $headerNode->getElementsByTagName('SIF_Timestamp')->item(0)->nodeValue; $validSourceId = Agent::checkSourceId($originalSourceId); if (!$validSourceId) { RegisterError::invalidSourceId($agent->sourceId, $originalMsgId); } else { $agent = new Agent($originalSourceId); if ($agent->isRegistered()) { if ($agent->unRegister()) { XmlHelper::buildSuccessMessage(Utility::createMessageId(), Utility::createTimestamp(), $agent->sourceId, $originalMsgId, 0); } else { RegisterError::genericError($agent->sourceId, $originalMsgId); } } else { RegisterError::notRegisteredError($originalSourceId, $originalMsgId); } } }
private function setupResponseNew($agent, $msgId, $m) { $dom = $m->dom; $dataObject = null; $db = Zend_Registry::get('my_db'); $requesterId = RequestObject::getRequesterId($msgId); $agentModeId = RequestObject::getRequesterAgentMode($msgId); try { $sifObjectDataNode = $dom->getElementsByTagName('SIF_ObjectData')->item(0); $children = isset($sifObjectDataNode->childNodes) ? $sifObjectDataNode->childNodes : ''; if (is_object($children)) { $objectName = isset($children->item(0)->nodeName) ? $children->item(0)->nodeName : null; } else { $objectName = null; ZitLog::writeToErrorLog('[SIF_ObjectData Error]', 'No SIF_ObjectData found from agent = ' . $agent->sourceId, $this->xmlStr); GeneralError::systemError($this->xmlStr); } $dataObject = new DataObject($objectName); } catch (Exception $e) { ZitLog::writeToErrorLog('[Error processing message]', "DataObject Name: " . $objectName . "\nError Message\n" . $e->getMessage() . "\n\nStack Trace\n" . $e->getTraceAsString() . ' ' . $this->xmlStr, 'Process Message', $_SESSION['ZONE_ID']); GeneralError::systemError($this->xmlStr); } $sifMessageNode = $dom->getElementsByTagName('SIF_Message')->item(0); $responseXml = $dom->saveXML($sifMessageNode); $responseXml = str_replace('xmlns="http://www.sifinfo.org/infrastructure/1.x"', '', $responseXml); $responseXml = str_replace('xmlns:sif="http://www.sifinfo.org/infrastructure/1.x"', '', $responseXml); $responseXml = str_replace('xmlns="http://www.sifinfo.org/infrastructure/2.x" ', '', $responseXml); $responseXml = str_replace('xmlns="http://www.sifinfo.org/uk/infrastructure/2.x" ', '', $responseXml); $responseXml = str_replace('xmlns="http://www.sifinfo.org/au/infrastructure/2.x" ', '', $responseXml); $responseXml = str_replace('xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ', '', $responseXml); # $data = array( # DBConvertor::convertCase('request_msg_id') => $msgId, # DBConvertor::convertCase('response_data') => $responseXml, # DBConvertor::convertCase('next_packet_num') => '2', # DBConvertor::convertCase('status_id') => '1', # DBConvertor::convertCase('agent_id_requester') => intval($requesterId), # DBConvertor::convertCase('agent_id_responder') => $agent->agentId, # DBConvertor::convertCase('agent_mode_id') => intval($agentModeId), # DBConvertor::convertCase('zone_id') => $_SESSION["ZONE_ID"], # DBConvertor::convertCase('context_id') => $_SESSION["CONTEXT_ID"] # ); # $db->insert(DBConvertor::convertCase('response'), $data); /* Removing the filterUtility as it should be reworked. $filterUtility = new FilterUtility(); $filterUtility->FilterCommonElements($dataObject->objectId, $dom, intval($requesterId)); */ try { $this->xslt = null; $permissions = new AgentPermissions($db); $where = "object_id = " . $dataObject->objectId . " and agent_id = " . $requesterId . " and zone_id = " . $_SESSION['ZONE_ID'] . " and context_id = " . $_SESSION['CONTEXT_ID']; $result = $permissions->fetchAll($where); switch (DB_TYPE) { case 'mysql': $this->xslt = isset($result[0]->xslt) ? $result[0]->xslt : null; break; case 'oci8': $this->xslt = isset($result[0]->XSLT) ? $result[0]->XSLT : null; break; } if ($this->xslt != null) { $xsltpro = new XSLTProcessor(); $XSL = new DOMDocument(); $XSL->loadXML($this->xslt); $xsltpro->importStylesheet($XSL); $XML = new DOMDocument(); $XML->loadXML($responseXml); $responseXml = $xsltpro->transformToXML($XML); } $responseXml = str_replace('<?xml version="1.0"?>' . "\n", '', $responseXml); } catch (Zend_Exception $e) { ZitLog::writeToErrorLog('[Error filtering message]', "DataObject Name: " . $objectName . "\nError Message\n" . $e->getMessage() . "\n\nStack Trace\n" . $e->getTraceAsString() . ' ' . $this->xmlStr, 'Process Message', $_SESSION['ZONE_ID']); GeneralError::systemError($this->xmlStr); } $messagequeue = new MessageQueues($db); $data = null; $data = array(DBConvertor::convertCase('msg_id') => $this->originalMsgId, DBConvertor::convertCase('ref_msg_id') => $msgId, DBConvertor::convertCase('msg_type') => 2, DBConvertor::convertCase('status_id') => '1', DBConvertor::convertCase('version') => $_SESSION['ZONE_VERSION'], DBConvertor::convertCase('insert_timestamp') => new Zend_Db_Expr(DBConvertor::convertCurrentTime()), DBConvertor::convertCase('agt_id_in') => $agent->agentId, DBConvertor::convertCase('agt_id_out') => intval($requesterId), DBConvertor::convertCase('data') => $responseXml, DBConvertor::convertCase('next_packet_num') => 2, DBConvertor::convertCase('agt_mode_id') => intval($agentModeId), DBConvertor::convertCase('zone_id') => $_SESSION["ZONE_ID"], DBConvertor::convertCase('context_id') => $_SESSION["CONTEXT_ID"]); $messagequeue->insert($data); $timestamp = Utility::createTimestamp(); $msgId = Utility::createMessageId(); XmlHelper::buildSuccessMessage($msgId, $timestamp, $this->originalSourceId, $this->originalMsgId, 0, $originalMsg = null, $desc = null); }
private function createAclAckMessage($sourceId, $originalMsgId) { $acl = new ACL($this->xmlDom); $timestamp = Utility::createTimestamp(); $msgId = Utility::createMessageId(); XmlHelper::buildSuccessMessage($msgId, $timestamp, $sourceId, $originalMsgId, 0, $originalMsg = $acl->BuildACL(), $desc = null); }
static function systemError($xml) { try { if ($xml != '' or $xml != null) { $dom = new DomDocument(); $dom->loadXML($xml); $header = $dom->getElementsByTagName('SIF_Header')->item(0); $msgIdNode = $header->getElementsByTagName('SIF_MsgId')->item(0); $sourceIdNode = $header->getElementsByTagName('SIF_SourceId')->item(0); $originalMsgId = isset($msgIdNode->nodeValue) ? $msgIdNode->nodeValue : ''; $originalSourceId = isset($sourceIdNode->nodeValue) ? $sourceIdNode->nodeValue : ''; $longDesc = "Event was not updated as recieved."; } else { $originalMsgId = ''; $originalSourceId = ''; $longDesc = "Event was not updated as recieved. XML not found."; } } catch (Exception $e) { $originalMsgId = ''; $originalSourceId = ''; $longDesc = "Event was not updated as recieved. XML not found."; } $categoryCode = "11"; $sifCode = "1"; $shortDesc = "Generic Error"; $timestamp = Utility::createTimestamp(); $msgId = Utility::createMessageId(); XmlHelper::buildErrorMessage($categoryCode, $sifCode, $shortDesc, $longDesc, $msgId, $timestamp, $originalSourceId, $originalMsgId, false); }
static function systemError($xml) { try { if ($xml != '' or $xml != null) { $dom = new DomDocument(); try { $dom->loadXML($xml); } catch (Exception $e) { $originalMsgId = ''; $originalSourceId = ''; $longDesc = "Premature end of Data."; $categoryCode = "11"; $sifCode = "1"; $shortDesc = "Generic Error"; $timestamp = Utility::createTimestamp(); $msgId = Utility::createMessageId(); XmlHelper::buildErrorMessage($categoryCode, $sifCode, $shortDesc, $longDesc, $msgId, $timestamp, $originalSourceId, $originalMsgId, false); exit; } $headerNode = $dom->getElementsByTagName('SIF_Header'); if ($headerNode->length != 0) { $header = $headerNode->item(0); } else { $originalMsgId = ''; $originalSourceId = ''; $longDesc = "SIF_Header failed: possible a premature end of data caused this."; $categoryCode = "11"; $sifCode = "1"; $shortDesc = "Generic Error"; $timestamp = Utility::createTimestamp(); $msgId = Utility::createMessageId(); XmlHelper::buildErrorMessage($categoryCode, $sifCode, $shortDesc, $longDesc, $msgId, $timestamp, $originalSourceId, $originalMsgId, false); exit; } $SIF_MsgIdNode = $header->getElementsByTagName('SIF_MsgId'); if ($SIF_MsgIdNode->length != 0) { $msgIdNode = $header->getElementsByTagName('SIF_MsgId')->item(0); } else { $originalMsgId = ''; $originalSourceId = ''; $longDesc = "SIF_MsgId - has issues."; $categoryCode = "11"; $sifCode = "1"; $shortDesc = "Generic Error"; $timestamp = Utility::createTimestamp(); $msgId = Utility::createMessageId(); XmlHelper::buildErrorMessage($categoryCode, $sifCode, $shortDesc, $longDesc, $msgId, $timestamp, $originalSourceId, $originalMsgId, false); exit; } $sourceIdNode = $header->getElementsByTagName('SIF_SourceId')->item(0); $originalMsgId = isset($msgIdNode->nodeValue) ? $msgIdNode->nodeValue : ''; $originalSourceId = isset($sourceIdNode->nodeValue) ? $sourceIdNode->nodeValue : ''; $longDesc = "Event was not updated as recieved."; } else { $originalMsgId = ''; $originalSourceId = ''; $longDesc = "Event was not updated as recieved. XML not found."; } } catch (Exception $e) { $originalMsgId = ''; $originalSourceId = ''; $longDesc = "Event was not updated as recieved. XML not found."; } $categoryCode = "11"; $sifCode = "1"; $shortDesc = "Generic Error"; $timestamp = Utility::createTimestamp(); $msgId = Utility::createMessageId(); XmlHelper::buildErrorMessage($categoryCode, $sifCode, $shortDesc, $longDesc, $msgId, $timestamp, $originalSourceId, $originalMsgId, false); }
public static function invalidObject($originalSourceId, $originalMsgId, $objectName) { $categoryCode = "8"; $sifCode = "3"; $shortDesc = "Request Error"; $longDesc = "Invalid object (" . $objectName . ")."; $timestamp = Utility::createTimestamp(); $msgId = Utility::createMessageId(); XmlHelper::buildErrorMessage($categoryCode, $sifCode, $shortDesc, $longDesc, $msgId, $timestamp, $originalSourceId, $originalMsgId); }
private function setupRequest($objectName, $sourceId, $agent) { $db = ZitDBAdapter::getDBAdapter(); $dom = $this->dom; $providerId = null; if ($sourceId != null) { $agent = new Agent($sourceId); $providerId = $agent->agentId; } else { $providerId = DataObject::getProviderId($objectName); } if ($providerId == 0) { RequestError::invalidProvider($this->originalSourceId, $this->originalMsgId); } else { $error = false; $sifMessageNode = $dom->getElementsByTagName('SIF_Message')->item(0); $eventXML = $dom->saveXML($sifMessageNode); $eventXML = str_replace('xmlns:sif="http://www.sifinfo.org/infrastructure/2.x" ', '', $eventXML); $eventXML = str_replace('xmlns="http://www.sifinfo.org/infrastructure/2.x" ', '', $eventXML); $eventXML = str_replace('xmlns:sif="http://www.sifinfo.org/infrastructure/1.x" ', '', $eventXML); $eventXML = str_replace('xmlns="http://www.sifinfo.org/infrastructure/1.x" ', '', $eventXML); $eventXML = str_replace('xmlns="http://www.sifinfo.org/uk/infrastructure/2.x" ', '', $eventXML); $eventXML = str_replace('xmlns="http://www.sifinfo.org/au/infrastructure/2.x" ', '', $eventXML); $eventXML = str_replace('xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ', '', $eventXML); $messageId = $dom->getElementsByTagName('SIF_MsgId')->item(0)->nodeValue; $bufferSize = $dom->getElementsByTagName('SIF_MaxBufferSize')->item(0)->nodeValue; /* PUSH all messages to the ZONE Version: DO NOT Check Message Version: */ $version = $_SESSION['ZONE_VERSION']; $query = "select\r\n agent_registered.sif_version,\r\n agent_registered.maxbuffersize,\r\n agent_registered.agent_mode_id,\r\n agent.source_id\r\n from " . DBConvertor::convertCase('agent_registered') . " \r\n inner join " . DBConvertor::convertCase('agent') . " on agent.agent_id = agent_registered.agent_id\r\n where agent_registered.agent_id = {$providerId} and agent_registered.unregister_timestamp is null\r\n and agent_registered.zone_id = " . $_SESSION["ZONE_ID"] . "\r\n and agent_registered.context_id = " . $_SESSION["CONTEXT_ID"]; $result = $db->fetchAll($query); switch (DB_TYPE) { case 'mysql': $agentModeId = $result[0]->agent_mode_id; $maxbuffersize = intval($result[0]->maxbuffersize); $source_id = $result[0]->source_id; $sif_version = $result[0]->sif_version; break; case 'oci8': $agentModeId = $result[0]->AGENT_MODE_ID; $maxbuffersize = intval($result[0]->MAXBUFFERSIZE); $source_id = $result[0]->SOURCE_ID; $sif_version = $result[0]->SIF_VERSION; break; } $messageSize = strlen($eventXML); if ($messageSize > $maxbuffersize) { $error = true; $header = $this->headerNode; SifLogEntry::CreateSifLogEvents($header, '4', '2', 'Buffer size of agent ' . $source_id . ' is too small to recieve this request [size : ' . $maxbuffersize . ']'); } /* if($version != '2.*') { if($version != $sif_version) { $header = $this->headerNode; $error = true; SifLogEntry::CreateSifLogEvents($header, '4', '4', 'Version in request not supported by agent '.$source_id ); } } else { $version = $_SESSION['ZONE_VERSION']; } */ if (!$error) { $dataObject = new DataObject($objectName); # $request = new Requests($db); # $data = array( # DBConvertor::convertCase('request_msg_id') => $messageId, # DBConvertor::convertCase('request_timestamp') => new Zend_Db_Expr(DBConvertor::convertCurrentTime()), # DBConvertor::convertCase('agent_id_requester') => $agent->agentId, # DBConvertor::convertCase('agent_id_responder') => intval($providerId), # DBConvertor::convertCase('request_data') => $eventXML, # DBConvertor::convertCase('max_buffer_size') => $bufferSize, # DBConvertor::convertCase('version') => $version, # DBConvertor::convertCase('agent_mode_id') => intval($agentModeId), # DBConvertor::convertCase('zone_id') => $_SESSION["ZONE_ID"], # DBConvertor::convertCase('context_id') => $_SESSION["CONTEXT_ID"] # ); # $request->insert($data); $messagequeue = new MessageQueues($db); $data = null; $data = array(DBConvertor::convertCase('msg_id') => $messageId, DBConvertor::convertCase('msg_type') => 1, DBConvertor::convertCase('status_id') => 1, DBConvertor::convertCase('insert_timestamp') => new Zend_Db_Expr(DBConvertor::convertCurrentTime()), DBConvertor::convertCase('agt_id_in') => intval($agent->agentId), DBConvertor::convertCase('agt_id_out') => intval($providerId), DBConvertor::convertCase('data') => $eventXML, DBConvertor::convertCase('maxbuffersize') => intval($bufferSize), DBConvertor::convertCase('version') => $version, DBConvertor::convertCase('agt_mode_id') => intval($agentModeId), DBConvertor::convertCase('zone_id') => $_SESSION["ZONE_ID"], DBConvertor::convertCase('context_id') => $_SESSION["CONTEXT_ID"]); $messagequeue->insert($data); } $timestamp = Utility::createTimestamp(); $msgId = Utility::createMessageId(); $sifMessageNode = $dom->getElementsByTagName('SIF_Message')->item(0); XmlHelper::buildSuccessMessage($msgId, $timestamp, $this->originalSourceId, $this->originalMsgId, 0, $originalMsg = null, $desc = null); } //invalid provider check }
public static function checkIfZitIsSleeping($dom) { if (Zit::isAsleep()) { /* todo: Should create a SIF_MESSAGE_TYPE for errors */ $_SESSION['SIF_MESSAGE_TYPE'] = 1; $headerNode = $dom->getElementsByTagName('SIF_Header')->item(0); $originalMsgId = $headerNode->getElementsByTagName('SIF_MsgId')->item(0)->nodeValue; $originalSourceId = $headerNode->getElementsByTagName('SIF_SourceId')->item(0)->nodeValue; $timestamp = Utility::createTimestamp(); $msgId = Utility::createMessageId(); $sifMessageNode = $dom->getElementsByTagName('SIF_Message')->item(0); XmlHelper::buildSuccessMessage($msgId, $timestamp, $originalSourceId, $originalMsgId, 8, $originalMsg = null, $desc = 'Receiver is sleeping'); exit; } }
private function processZoneStatus() { $dom = $this->xmlDom; $headerNode = $dom->getElementsByTagName('SIF_Header')->item(0); $originalSourceId = $headerNode->getElementsByTagName('SIF_SourceId')->item(0)->nodeValue; $originalMsgId = $headerNode->getElementsByTagName('SIF_MsgId')->item(0)->nodeValue; $validSourceId = Agent::checkSourceId($originalSourceId); if (!$validSourceId) { RegisterError::invalidSourceId($originalSourceId, $originalMsgId); } else { $dom = new DOMDocument('1.0', 'iso-8859-1'); $zoneStatusNode = $dom->createElement('SIF_ZoneStatus'); $zoneStatusNode->setAttribute('ZoneId', $_SESSION['ZONE_NAME']); $dom->appendChild($zoneStatusNode); $zoneNameNode = $dom->createElement('SIF_Name'); $zoneNameNode->appendChild($dom->createTextNode($_SESSION['ZONE_DESC'])); $zoneStatusNode->appendChild($zoneNameNode); $sifVendorNode = $dom->createElement('SIF_Vendor'); $sifVendorName = $dom->createElement('SIF_Name'); $sifVendorName->appendChild($dom->createTextNode(VENDOR_NAME)); $sifVendorNode->appendChild($sifVendorName); $sifVendorProduct = $dom->createElement('SIF_Product'); $sifVendorProduct->appendChild($dom->createTextNode(VENDOR_PRODUCT)); $sifVendorNode->appendChild($sifVendorProduct); $sifVendorVersion = $dom->createElement('SIF_Version'); $sifVendorVersion->appendChild($dom->createTextNode(VENDOR_VERSION)); $sifVendorNode->appendChild($sifVendorVersion); $zoneStatusNode->appendChild($sifVendorNode); $sifProvidersNode = $dom->createElement('SIF_Providers'); $sifProvidersNode = $this->buildProviders($sifProvidersNode, $dom); $zoneStatusNode->appendChild($sifProvidersNode); $sifSubscribersNode = $dom->createElement('SIF_Subscribers'); $sifSubscribersNode = $this->buildSubscribers($sifSubscribersNode, $dom); $zoneStatusNode->appendChild($sifSubscribersNode); $sifNodes = $dom->createElement('SIF_SIFNodes'); $sifSubscribersNode = $this->buildNodeList($sifNodes, $dom); $zoneStatusNode->appendChild($sifNodes); /*$sifSupportedAuth = $dom->createElement('SIF_SupportedAuthentication'); $sifProtocolName = $dom->createElement('SIF_ProtocolName'); $sifSupportedAuth->appendChild($sifProtocolName); $zoneStatusNode->appendChild($sifSupportedAuth);*/ $sifSupportedProtocols = $dom->createElement('SIF_SupportedProtocols'); $sifProtocol = $dom->createElement('SIF_Protocol'); $sifProtocol->setAttribute('Type', 'HTTP'); $sifProtocol->setAttribute('Secure', 'No'); $sifUrl = $dom->createElement('SIF_URL'); $sifUrl->appendChild($dom->createTextNode(ZIT::getZitUrl())); $sifProtocol->appendChild($sifUrl); $sifSupportedProtocols->appendChild($sifProtocol); $zoneStatusNode->appendChild($sifSupportedProtocols); $sifSupportedVersions = $dom->createElement('SIF_SupportedVersions'); $versions = ZIT::getVersions(); foreach ($versions as $version) { $sifVersion = $dom->createElement('SIF_Version'); $sifVersion->appendChild($dom->createTextNode($version['VERSION'])); $sifSupportedVersions->appendChild($sifVersion); } $zoneStatusNode->appendChild($sifSupportedVersions); $sifAdminUrl = $dom->createElement('SIF_AdministrationURL'); $sifAdminUrl->appendChild($dom->createTextNode(ZIT::getAdminUrl())); $zoneStatusNode->appendChild($sifAdminUrl); $sifContexts = $dom->createElement('SIF_Contexts'); $sifContexts = $this->buildContexts($sifContexts, $dom); $zoneStatusNode->appendChild($sifContexts); $xml = $dom->saveXML($dom->documentElement); $msgId = Utility::createMessageId(); $timestamp = Utility::createTimestamp(); XmlHelper::buildSuccessMessage($msgId, $timestamp, $originalSourceId, $originalMsgId, 0, $originalMsg = $xml, $desc = null); } }
public function processRequestMessages() { $db = ZitDBAdapter::getDBAdapter(); $query = "select \r\n\t\t\t \trequest_data,\r\n\t\t\t\t\tagent_registered.callback_url,\r\n\t\t\t\t\tagent_registered.frozen,\r\n\t\t\t\t\trequest_id\r\n\t\t\t\t from\r\n\t\t\t\t \trequest\r\n\t\t\t\t inner join\r\n\t\t\t\t \tagent_registered on request.agent_id_responder = agent_registered.agent_id\r\n\t\t\t\t where\r\n\t\t\t\t \trequest.status_id in (1,2)\r\n\t\t\t\t and\r\n\t\t\t\t \tagent_registered.asleep = 0\r\n\t\t\t\t and\r\n\t\t\t\t \trequest.agent_mode_id = 1\r\n\t\t\t\t and\r\n\t\t\t\t \trequest.zone_id = " . $this->zoneId . "\r\n\t\t\t\t and\r\n\t\t\t\t\tagent_registered.zone_id = " . $this->zoneId . "\r\n\t\t\t\t and \r\n\t\t\t\t \trequest.context_id = " . $this->contextId . "\r\n\t\t\t\t and \r\n\t\t\t\t\tagent_registered.context_id = " . $this->contextId; $result = $db->fetchAll($query); foreach ($result as $row) { if ($row->frozen != 1) { $timestamp = Utility::createTimestamp(); $msgId = Utility::createMessageId(); $xml = XmlHelper::buildSuccessMessage($msgId, $timestamp, $this->zoneName, $msgId, 0, $this->zoneVersion, $this->versionNamespace, $this->zoneName, $originalMsg = $row->request_data, $desc = null); $sendMessageResult = $this->sendMessage($xml, $row->callback_url, $this->zoneId, $this->contextId, $row->agent_id); echo 'here after'; if (!$sendMessageResult['Error']) { $data = array('status_id' => 2, 'msg_id' => $msgId); $db->update('request', $data, 'request_id = ' . $row->request_id); $processResponseResult = $this->processResponseMessage($sendMessageResult['Xml'], $this->zoneId, $this->contextId, $row->agent_id); if (!$processResponseResult['Error']) { if ($processResponseResult['ImmediateUpdate']) { $data = array('status_id' => 3, 'msg_id' => $msgId); $db->update('request', $data, 'request_id = ' . $row->request_id); } ZitLog::writeToLog($sendMessageResult['Xml'], $xml, $this->zoneId, $row->agent_id, 6); } //check for errors in response } else { $data = array('status_id' => 4, 'msg_id' => $msgId); $db->update('request', $data, 'request_id = ' . $row->request_id); } //errors in request } //make sure agent is not frozen } //loop through results }
/** * Uses the XML helper to return the proper header * * @return string XML header * @author Jose Diaz-Gonzalez **/ public function header() { $xml = new XmlHelper(); return $xml->header() . "\n"; }
private function createAclAckMessage($sourceId, $originalMsgId) { $acl = new ACL($this->xmlDom); $timestamp = Utility::createTimestamp(); $msgId = Utility::createMessageId(); if ($_SESSION['ZONE_VERSION'] == '1.5r1') { XmlHelper::buildSuccessMessage($msgId, $timestamp, $sourceId, $originalMsgId, 0); } else { XmlHelper::buildSuccessMessage($msgId, $timestamp, $sourceId, $originalMsgId, 0, $originalMsg = $acl->BuildACL(), $desc = null); } }