/**
  * Singelton Pattern
  *
  * @return SyncCtoCommunicationClient
  */
 public static function getInstance()
 {
     if (self::$instance == null) {
         self::$instance = new SyncCtoCommunicationClient();
     }
     return self::$instance;
 }
示例#2
0
 /**
  * Constructor
  *
  * @param DataContainer $objDc
  */
 public function __construct(DataContainer $objDc = null)
 {
     parent::__construct($objDc);
     // Load helper
     $this->objSyncCtoDatabase = SyncCtoDatabase::getInstance();
     $this->objSyncCtoFiles = SyncCtoFiles::getInstance();
     $this->objSyncCtoCommunicationClient = SyncCtoCommunicationClient::getInstance();
     $this->objSyncCtoHelper = SyncCtoHelper::getInstance();
     // Load language
     $this->loadLanguageFile("tl_syncCto_steps");
     $this->loadLanguageFile("tl_syncCto_check");
     // Load CSS
     $GLOBALS['TL_CSS'][] = 'system/modules/syncCto/assets/css/steps.css';
     // Init classes.
     $this->User = \BackendUser::getInstance();
 }
示例#3
0
 protected function sendFile()
 {
     if (strlen($strFile = $this->Input->post("file")) == 0) {
         throw new Exception("No file was send.");
     }
     if (!file_exists(TL_ROOT . "/" . $strFile)) {
         throw new Exception("File: {$strFile} not exists.");
     }
     parent::sendFile(dirname($strFile), basename($strFile), md5_file(TL_ROOT . "/" . $strFile), SyncCtoEnum::UPLOAD_SYNC_TEMP);
 }
示例#4
0
 /**
  * Ping the SyncCto sub system.
  */
 protected function pingSyncCtoSystem()
 {
     $objSyncCtoClient = \SyncCtoCommunicationClient::getInstance();
     $objSyncCtoClient->setClientBy($this->clientID);
     try {
         $objSyncCtoClient->startConnection();
         // Check Version of syncCto.
         try {
             $mixVersion = $objSyncCtoClient->getVersionSyncCto();
             if (strlen($mixVersion) == 0) {
                 throw new \Exception('Missing syncCto Version.');
             }
         } catch (\Exception $exc) {
             // State: Blue => SyncCto missing.
             $this->addState(2, $GLOBALS['TL_LANG']['tl_synccto_clients']['state']['blue'], $exc->getMessage());
             $this->output();
         }
         $objSyncCtoClient->stopConnection();
     } catch (\Exception $exc) {
         // State: Orange => Key Error.
         $this->addState(3, $GLOBALS['TL_LANG']['tl_synccto_clients']['state']['orange'], $exc->getMessage());
         $this->output();
     }
 }
示例#5
0
 /**
  * Ping the current client status
  *
  * @param string $strAction
  */
 public function pingClientStatus($strAction)
 {
     if ($strAction == 'syncCtoPing') {
         $intClientId = \Input::getInstance()->post('clientID');
         if (!empty($intClientId) && is_numeric($intClientId)) {
             // Set time limit for this function
             set_time_limit(10);
             try {
                 // Flags fo the check.
                 $blnFlagCheckContao = false;
                 $blnFlagCheckCtoCom = false;
                 $blnFlagCheckSyncCto = false;
                 $blnFlagCheckCtoKey = false;
                 // Return array.
                 $arrReturn = array("success" => false, "value" => 0, "error" => "", "msg" => $GLOBALS['TL_LANG']['tl_synccto_clients']['state']['gray'], "token" => REQUEST_TOKEN);
                 // Load Client from database
                 $objClient = Database::getInstance()->prepare("SELECT * FROM tl_synccto_clients WHERE id = %s")->limit(1)->execute($intClientId);
                 // Check if a client was loaded
                 if ($objClient->numRows == 0) {
                     $arrReturn["success"] = false;
                     $arrReturn["error"] = "Unknown client";
                     echo json_encode($arrReturn);
                     exit;
                 }
                 // Setup request class.
                 $objRequest = new RequestExtendedCached();
                 if ($objClient->http_auth == true) {
                     $this->import("Encryption");
                     $objRequest->username = $objClient->http_username;
                     $objRequest->password = $this->Encryption->decrypt($objClient->http_password);
                 }
                 // Build base link.
                 $objClient->path = preg_replace("/\\/\\z/i", "", $objClient->path);
                 $objClient->path = preg_replace("/ctoCommunication.php\\z/", "", $objClient->path);
                 $strServerBaseUrl = $objClient->address . ":" . $objClient->port;
                 if (strlen($objClient->path)) {
                     $strServerBaseUrl .= $objClient->path;
                 }
                 // ---- First check for Contao ----
                 $objRequest->send($strServerBaseUrl . '/contao/index.php');
                 if ($objRequest->code != '200') {
                     // State: Red => Offline.
                     $arrReturn["success"] = true;
                     $arrReturn["value"] = 1;
                     $arrReturn["error"] = 'Missing contao.';
                     $arrReturn["msg"] = $GLOBALS['TL_LANG']['tl_synccto_clients']['state']['red'];
                     echo json_encode($arrReturn);
                     exit;
                 }
                 // ---- Next CtoCom ----
                 $objRequest->send($strServerBaseUrl . '/ctoCommunication.php?act=ping');
                 if ($objRequest->code != '200') {
                     // State: Blue => No CtoCom.
                     $arrReturn["success"] = true;
                     $arrReturn["value"] = 2;
                     $arrReturn["error"] = 'Missing ctoCommunication.php';
                     $arrReturn["msg"] = $GLOBALS['TL_LANG']['tl_synccto_clients']['state']['blue'];
                     echo json_encode($arrReturn);
                     exit;
                 }
                 // ---- Next CtoCom Key + SyncCto ----
                 $objSyncCtoClient = SyncCtoCommunicationClient::getInstance();
                 $objSyncCtoClient->setClientBy($intClientId);
                 try {
                     $objSyncCtoClient->startConnection();
                     // Check Version of syncCto.
                     try {
                         $mixVersion = $objSyncCtoClient->getVersionSyncCto();
                         if (strlen($mixVersion) == 0) {
                             throw new Exception('Missing syncCto Version.');
                         }
                     } catch (Exception $exc) {
                         // State: Blue => SyncCto missing.
                         $arrReturn["success"] = true;
                         $arrReturn["value"] = 2;
                         $arrReturn["error"] = $exc->getMessage();
                         $arrReturn["msg"] = $GLOBALS['TL_LANG']['tl_synccto_clients']['state']['blue'];
                         echo json_encode($arrReturn);
                         exit;
                     }
                     $objSyncCtoClient->stopConnection();
                 } catch (Exception $exc) {
                     // State: Orange => Key Error.
                     $arrReturn["success"] = true;
                     $arrReturn["value"] = 3;
                     $arrReturn["error"] = $exc->getMessage();
                     $arrReturn["msg"] = $GLOBALS['TL_LANG']['tl_synccto_clients']['state']['orange'];
                     echo json_encode($arrReturn);
                     exit;
                 }
                 // State: Greeb => All systems ready.
                 $arrReturn["success"] = true;
                 $arrReturn["value"] = 4;
                 $arrReturn["msg"] = $GLOBALS['TL_LANG']['tl_synccto_clients']['state']['green'];
                 echo json_encode($arrReturn);
                 exit;
             } catch (Exception $exc) {
                 $arrReturn["success"] = false;
                 $arrReturn["error"] = $exc->getMessage() . " " . $exc->getFile() . " on " . $exc->getLine();
             }
         } else {
             $arrReturn["success"] = false;
             $arrReturn["error"] = "Missing client id.";
         }
         echo json_encode($arrReturn);
         exit;
     }
 }