18 require_once SQ_PACKAGES_PATH.
'/squiz_suite/systems/squiz_suite_system/squiz_suite_system.inc';
43 $this->_ser_attrs = TRUE;
44 parent::__construct($assetid);
59 $numberOfRootUrls = 0;
62 preg_match(
'/v(([0-9].?)\.([0-9].?)\.[0-9])/', SQ_SYSTEM_LONG_NAME, $matches);
63 if (isset($matches[1])) {
64 $version = $matches[1];
68 $sql =
'SELECT COUNT(*) FROM sq_ast';
70 if (!empty($result)) {
71 $numberOfAssets = $result;
75 $sql =
'SELECT COUNT(*) FROM sq_ast_url';
77 if (!empty($result)) {
78 $numberOfRootUrls = $result;
82 Array(
'label' =>
'Version',
'value' => $version),
83 Array(
'label' =>
'Assets',
'value' => $numberOfAssets),
84 Array(
'label' =>
'Root URLs',
'value' => $numberOfRootUrls),
99 $suite_manager = $GLOBALS[
'SQ_SYSTEM']->am->getSystemAsset(
'suite_manager');
102 $required = array(
'system_id',
'system_url',
'system_name');
103 $xml = array_get_index($_POST,
'xml', NULL);
104 $xml = html_entity_decode($xml);
105 $message = $suite_manager->parseSuiteXML($xml, $required);
107 $systemid = $message[
'system_id'];
108 $systemUrl = $message[
'system_url'];
109 $systemName = $message[
'system_name'];
112 foreach ($required as $field) {
113 if ($message[$field] === NULL) {
114 $errMsg = $field.
' has not been specified.';
115 throw new Exception($errMsg);
120 $product = $suite_manager->getProductBySystemid($systemid);
121 if (empty($product) === FALSE && $product[
'status'] ===
'sync pending') {
122 $suite_manager->updateProduct($product[
'suiteid'],
'status',
'live');
125 $suite_manager->updateProduct($product[
'suiteid'],
'last_contacted', date(
'c'));
129 }
catch (Exception $e) {
130 $errMsg =
"suitePing failed\n";
131 $errMsg .= $e->getMessage();
132 throw new Exception($errMsg);
151 $suite_manager = $GLOBALS[
'SQ_SYSTEM']->am->getSystemAsset(
'suite_manager');
153 $current_product = $suite_manager->getCurrentProduct();
154 if (empty($current_product) || !isset($current_product[
'url'])) {
155 $errMsg =
'The system is not ready to accept any connection request.';
156 throw new Exception($errMsg);
160 $required = array(
'system_id',
'system_url',
'system_name',
'system_type',
'cert');
161 $xml = array_get_index($_POST,
'xml', NULL);
162 $xml = html_entity_decode($xml);
163 $message = $suite_manager->parseSuiteXML($xml, $required);
166 foreach ($required as $field) {
167 if ($message[$field] === NULL) {
168 $errMsg = $field.
' has not been specified.';
169 throw new Exception($errMsg);
174 $systemid = $message[
'system_id'];
175 $systemUrl = $message[
'system_url'];
176 $systemName = $message[
'system_name'];
177 $systemType = $message[
'system_type'];
178 $certificate = $message[
'cert'];
180 $suite_manager->logReceivedMessage($systemid,
'suiteConnect');
183 $product = $suite_manager->getProductBySystemidURL($systemid, $systemUrl);
184 if (empty($product) === FALSE) {
185 $suiteid = $product[
'suiteid'];
188 if ($product[
'status'] ===
'live' && $product[
'url'] === $systemUrl && $product[
'connection'][
'cert'] === $certificate && $product[
'connection'][
'name'] === $systemName) {
192 $pingRes = $suite_maanger->sendMessage($suiteid,
'suitePing');
193 if (strpos($pingRes[
'result'],
'<?xml') !== 0) {
195 $errMsg =
'The requested system does not exist.';
196 throw new Exception($errMsg);
198 if ($pingRes[
'curlInfo'][
'http_code'] === 200) {
199 if ($product[
'sync_status'] ===
'D') {
201 $errMsg =
'The requested system has been removed.';
202 throw new Exception($errMsg);
205 $errMsg =
'The requested system is already registered.';
206 throw new Exception($errMsg);
213 if (array_key_exists(
'url', $product) === FALSE && array_key_exists(
'cert', $product[
'connection']) === FALSE) {
214 $product[
'connection'][
'cert'] = $certificate;
215 $suite_manager->updateProduct($suiteid,
'url', $systemUrl);
216 $suite_manager->updateProduct($suiteid,
'connection', $product[
'connection']);
218 $errMsg =
'The requested system can not be accepted';
219 throw new Exception($errMsg);
223 $connection = array();
224 $connection[
'cert'] = $certificate;
225 $connection[
'name'] = $systemName;
227 $suiteid = $suite_manager->registerProduct($systemid, $systemType, $systemUrl, $connection);
229 $token = $suite_manager->createConnectionToken();
230 $suite_manager->updateProduct($suiteid,
'token', $token);
235 $suite_manager->updateProduct($suiteid,
'status',
'pending approval');
236 $suite_manager->updateProduct($suiteid,
'last_contacted', date(
'c'));
240 }
catch (Exception $e) {
241 $errMsg =
'suiteConnect failed'.
"\n";
242 $errMsg .= $e->getMessage().
"\n";
243 $suite_manager->logErrorMessage($errMsg);
247 throw new Exception($errMsg);
266 $suite_manager = $GLOBALS[
'SQ_SYSTEM']->am->getSystemAsset(
'suite_manager');
277 $enc = array_get_index($_POST,
'_enc', Array());
278 $xml = array_get_index($enc,
'xml', NULL);
279 $xml = html_entity_decode($xml);
280 $message = $suite_manager->parseSuiteXML($xml, $required);
283 foreach ($required as $field) {
284 if ($field !==
'conn_token' && $message[$field] === NULL) {
285 $errMsg = $field.
' has not been specified.';
286 throw new Exception($errMsg);
290 $systemid = $message[
'system_id'];
291 $systemUrl = rtrim($message[
'system_url'],
'/');
292 $systemName = $message[
'system_name'];
293 $systemType = $message[
'system_type'];
294 $certificate = $message[
'cert'];
295 $token = $message[
'conn_token'];
297 $duplicated = $suite_manager->getProductBySystemidURL($systemid, $systemUrl);
298 if (empty($duplicated) === FALSE) {
299 $errMsg =
'The requested system already exists.';
300 throw new Exception($errMsg);
303 $allProducts = $suite_manager->getProducts();
304 $productInfo = array();
305 foreach ($allProducts as $product) {
306 if ($product[
'status'] ===
'pending' && rtrim($product[
'url'],
'/') === $systemUrl) {
307 $productInfo = $product;
312 if (empty($productInfo) === TRUE) {
313 $errMsg =
'Unknown system has sent suiteConnectAck message.';
314 throw new Exception($errMsg);
317 $suite_manager->logReceivedMessage($systemid,
'suiteConnectAck');
319 $productInfo[
'connection'][
'cert'] = $certificate;
320 $productInfo[
'connection'][
'name'] = $systemName;
322 $suite_manager->updateProduct($productInfo[
'suiteid'],
'systemid', $systemid);
323 $suite_manager->updateProduct($productInfo[
'suiteid'],
'connection', $productInfo[
'connection']);
324 $suite_manager->updateProduct($productInfo[
'suiteid'],
'type', $systemType);
325 $suite_manager->updateProduct($productInfo[
'suiteid'],
'status',
'live');
326 $suite_manager->updateProduct($productInfo[
'suiteid'],
'sync_status',
'A');
327 $suite_manager->updateProduct($productInfo[
'suiteid'],
'last_contacted', date(
'c'));
328 $suite_manager->updateProduct($productInfo[
'suiteid'],
'token', $token);
329 $response = $suite_manager->sendMessage($productInfo[
'suiteid'],
'suiteConnectAckAck');
330 $response = $response[
'result'];
331 if (strpos($response,
'<?xml') !== 0) {
332 $errMsg =
'suiteConnectAckAck message did not reach to '.$systemUrl;
333 throw new Exception($errMsg);
335 $dom =
new DomDocument();
336 $dom->loadXML($response);
338 $responseDom = $dom->getElementsByTagName(
'result')->item(0);
340 if ($response !==
'ok') {
341 $errMsg =
'suiteConnectAckAck message did not reach to '.$systemUrl;
342 throw new Exception($errMsg);
345 }
catch (Exception $e) {
346 $errMsg =
'suiteConnectAck failed.'.
"\n";
347 $errMsg .= $e->getMessage().
"\n";
348 $suite_manager->logErrorMessage($errMsg);
352 throw new Exception($errMsg);
368 $suite_manager = $GLOBALS[
'SQ_SYSTEM']->am->getSystemAsset(
'suite_manager');
376 $enc = array_get_index($_POST,
'_enc', Array());
377 $xml = array_get_index($enc,
'xml', NULL);
378 $xml = html_entity_decode($xml);
379 $message = $suite_manager->parseSuiteXML($xml, $required);
382 foreach ($required as $field) {
383 if ($field !==
'conn_token' && $message[$field] === NULL) {
384 $errMsg = $field.
' has not been specified.';
385 throw new Exception($errMsg);
389 $systemid = $message[
'system_id'];
390 $systemUrl = $message[
'system_url'];
391 $token = $message[
'conn_token'];
395 $productInfo = array();
396 if ($token !== NULL) {
397 $productInfo = $suite_manager->getProductByToken($token);
399 $productInfo = $suite_manager->getProductBySystemid($systemid);
400 if (isset($productInfo[0]) === TRUE) {
401 $productInfo = $productInfo[0];
405 if (empty($productInfo) === TRUE) {
406 $errMsg =
'Unknown system has been requested.';
407 throw new Exception($errMsg);
410 $suite_manager->logReceivedMessage($systemid,
'suiteConnectAckAck');
412 $suiteid = $productInfo[
'suiteid'];
413 if ($productInfo[
'status'] ===
'pending approval') {
414 $suite_manager->updateProduct($suiteid,
'status',
'live');
415 $suite_manager->updateProduct($suiteid,
'sync_status',
'A');
418 $suite_manager->updateProduct($suiteid,
'last_contacted', date(
'c'));
422 }
catch (Exception $e) {
423 $errMsg =
'suiteConnectAckAck failed.'.
"\n";
424 $errMsg .= $e->getMessage().
"\n";
425 $suite_manager->logErrorMessage($errMsg);
439 $suite_manager = $GLOBALS[
'SQ_SYSTEM']->am->getSystemAsset(
'suite_manager');
449 $enc = array_get_index($_POST,
'_enc', Array());
450 $xml = array_get_index($enc,
'xml', NULL);
451 $xml = html_entity_decode($xml);
452 $message = $suite_manager->parseSuiteXML($xml, $required);
455 foreach ($required as $field) {
456 if (isset($message[$field]) === FALSE || $message[$field] === NULL) {
457 $errMsg = $field.
' has not been specified.';
458 throw new Exception($errMsg);
462 $current_product = $suite_manager->getCurrentProduct();
463 $new_request_info = $message[
'options'];
464 $product_info = $suite_manager->getProductByToken($new_request_info[
'token']);
465 if (empty($product_info) === TRUE) {
466 throw new Exception(
'suiteSyncProduct is not allowed');
470 if ($current_product[
'type'] !==
'Squiz Update' && $product_info[
'systemid'] !== $message[
'system_id']) {
471 $suite_manager->updateProduct($product_info[
'suiteid'],
'systemid', $message[
'system_id']);
472 $product_info[
'systemid'] = $message[
'system_id'];
475 $markedDeleted = array();
476 $markedAdded = array();
477 $suite_manager->syncProductDetails($product_info, $new_request_info);
480 'systemid' => $current_product[
'systemid'],
481 'type' => $current_product[
'type'],
482 'apiurl' => $current_product[
'url'],
483 'name' => $current_product[
'connection'][
'name'],
484 'cert' => $current_product[
'connection'][
'cert'],
486 'deleted' => array(),
487 'connected' => array(),
490 if ($current_product[
'type'] !==
'Squiz Update' && $product_info[
'type'] !==
'Squiz Update') {
491 $suite_manager->syncDeletedProducts($new_request_info[
'deleted'], $markedDeleted, $markedAdded);
492 $result = $suite_manager->getSuiteProductInfo($current_product);
493 $suite_manager->syncConnectedProducts($product_info[
'suiteid'], $new_request_info[
'connected'], $markedDeleted, $markedAdded);
496 $suite_manager->updateProduct($product_info[
'suiteid'],
'last_contacted', date(
'c'));
499 }
catch (Exception $e) {
500 $errMsg =
'suiteSyncProduct failed.'.
"\n";
501 $errMsg .= $e->getMessage().
"\n";
502 $suite_manager->logErrorMessage($errMsg);
515 $suite_manager = $GLOBALS[
'SQ_SYSTEM']->am->getSystemAsset(
'suite_manager');
524 $enc = array_get_index($_POST,
'_enc', Array());
525 $xml = array_get_index($enc,
'xml', NULL);
526 $xml = html_entity_decode($xml);
527 $message = $suite_manager->parseSuiteXML($xml, $required);
530 foreach ($required as $field) {
531 if (isset($message[$field]) === FALSE || $message[$field] === NULL) {
532 $errMsg = $field.
' has not been specified.';
533 throw new Exception($errMsg);
537 $product = $suite_manager->getProductBySystemidURL($message[
'system_id'], $message[
'system_url']);
538 if (empty($product) === TRUE) {
539 throw new Exception(
'Operation prohibited');
542 if (empty($product[
'token']) === FALSE) {
543 throw new Exception(
'Operation prohibited');
546 if ($product[
'status'] ===
'live' && $product[
'sync_status'] !==
'D') {
547 $newToken = $suite_manager->createConnectionToken();
548 $result = array(
'token' => $newToken);
549 $suite_manager->updateProduct($product[
'suiteid'],
'token', $newToken);
553 throw new Exception(
'Operation prohibited');
555 }
catch (Exception $e) {
556 $errMsg =
'suiteSetToken failed.'.
"\n";
557 $errMsg .= $e->getMessage().
"\n";
558 $suite_manager->logErrorMessage($errMsg);