示例#1
0
 /**
  *  configure cli command for making api calls
  */
 protected function configure()
 {
     // get systemname
     $sAppName = SystemSettings::get('app_name');
     // set cli options
     $this->setName($sAppName . ':remote:cron')->addOption('app', null, InputOption::VALUE_REQUIRED, 'run only for specific remote app', false)->addOption('force', null, InputOption::VALUE_NONE, 'force to run remote app / ignore cron settings')->setDescription('Run/Crawl registered remote apps');
 }
 /**
  * Exclude object from result
  *
  * @param   SystemSettings $systemSettings Object to remove from the list of results
  *
  * @return SystemSettingsQuery The current query, for fluid interface
  */
 public function prune($systemSettings = null)
 {
     if ($systemSettings) {
         $this->addUsingAlias(SystemSettingsPeer::ID, $systemSettings->getId(), Criteria::NOT_EQUAL);
     }
     return $this;
 }
 /**
  * @param $key
  *
  * @return mixed
  */
 public function settings($key)
 {
     $sValue = SystemSettings::get($key);
     return $sValue;
 }
 /**
  * Get current Control URl
  *
  * @return string
  */
 public function _getSiteURL()
 {
     $sUrl = SystemSettings::get("control_url");
     return $sUrl;
 }
 /**
  * Update license
  *
  * @param \Symfony\Component\HttpFoundation\Request $request
  *
  * @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response
  * @throws \Exception
  * @throws \PropelException
  */
 public function updateAction(Request $request)
 {
     /** @var License $oLicense */
     $oLicense = LicenseQuery::create()->findOne();
     if ($oLicense === null) {
         throw $this->createNotFoundException('Unable to find License entity.');
     }
     $editForm = $this->createEditForm($oLicense);
     $editForm->handleRequest($request);
     $aResult = array("success" => false, "message" => "");
     $sLico = SystemSettings::get("lico");
     $aHeaders = array('Content-Type: application/json');
     $sDomain = $this->_getSiteURL();
     $aRequest = array('lico' => array('domain' => $sDomain, 'license' => $oLicense->getSerial()));
     $sRequest = json_encode($aRequest);
     /*
      * Check license against license-server
      */
     $oRequest = curl_init($sLico . "/api/check/license");
     curl_setopt($oRequest, CURLOPT_HTTPHEADER, $aHeaders);
     curl_setopt($oRequest, CURLOPT_TIMEOUT, 120);
     curl_setopt($oRequest, CURLOPT_POST, 1);
     curl_setopt($oRequest, CURLOPT_SSL_VERIFYPEER, false);
     curl_setopt($oRequest, CURLOPT_SSL_VERIFYHOST, false);
     curl_setopt($oRequest, CURLOPT_POSTFIELDS, $sRequest);
     curl_setopt($oRequest, CURLOPT_RETURNTRANSFER, true);
     $response = curl_exec($oRequest);
     $iHttpStatus = curl_getinfo($oRequest, CURLINFO_HTTP_CODE);
     $error = curl_error($oRequest);
     curl_close($oRequest);
     if ($iHttpStatus == 200) {
         $oResponse = json_decode($response);
         if ($editForm->isValid() && $oResponse->valid == true) {
             $aResult['max_clients'] = $oResponse->max_clients;
             $aResult['valid_until'] = $oResponse->valid_until;
             $aResult['domain'] = $sDomain;
             $aResult['success'] = true;
             $aResult['message'] = $this->get("translator")->trans("license.update.successful");
             // license valid, save new license-data
             $oLicense->setValidUntil($aResult['valid_until']);
             $oLicense->setMaxClients($aResult['max_clients']);
             $oLicense->setDomain($sDomain);
             $oLicense->save();
         } else {
             $aResult['success'] = false;
             $aResult['message'] = $this->get("translator")->trans("license.update.failed");
             $aResult['valid_until'] = strtotime("1970-01-01");
             $aResult['max_clients'] = 0;
             $aResult['domain'] = "-";
         }
     } else {
         $aResult['max_clients'] = $oLicense->getMaxClients();
         $aResult['valid_until'] = strtotime($oLicense->getValidUntil());
         $aResult['domain'] = $sDomain;
         $aResult['success'] = false;
         $aResult['message'] = $this->get("translator")->trans("license.update.failed_lico");
     }
     $sResult = json_encode($aResult);
     $response = new Response($sResult);
     $response->headers->set('Content-Type', 'application/json');
     return $response;
 }
 /**
  * Adds an object to the instance pool.
  *
  * Propel keeps cached copies of objects in an instance pool when they are retrieved
  * from the database.  In some cases -- especially when you override doSelect*()
  * methods in your stub classes -- you may need to explicitly add objects
  * to the cache in order to ensure that the same objects are always returned by doSelect*()
  * and retrieveByPK*() calls.
  *
  * @param SystemSettings $obj A SystemSettings object.
  * @param      string $key (optional) key to use for instance map (for performance boost if key was already calculated externally).
  */
 public static function addInstanceToPool($obj, $key = null)
 {
     if (Propel::isInstancePoolingEnabled()) {
         if ($key === null) {
             $key = (string) $obj->getId();
         }
         // if key === null
         SystemSettingsPeer::$instances[$key] = $obj;
     }
 }
 /**
  *  configure cli command for listing remoteapps
  */
 protected function configure()
 {
     $appName = SystemSettings::get("app_name");
     $this->setName($appName . ':remote:list')->setDescription('List remote apps with their id\'s and status');
 }
 /**
  * run single api call for one remote app
  *
  * @param $id
  *
  * @return \Symfony\Component\HttpFoundation\Response
  * @throws \Exception
  * @throws \PropelException
  */
 public function runSingleApiCallAction($id)
 {
     $sLico = SystemSettings::get("lico");
     $iLvdc = SystemSettings::get("lvdc");
     if ($iLvdc < strtotime("-7 days")) {
         $aRemoteApps = RemoteAppQuery::create()->filterByWebsiteHash(null, \Criteria::ISNOTNULL);
         $lico = $sLico . "/api/lvdc/" . base64_encode($this->_getSiteURL()) . "/" . $aRemoteApps->count();
         try {
             $res = @file_get_contents($lico);
             if ($res === false) {
                 throw new \Exception($this->get("translator")->trans("license.update.failed_lico"));
             }
             $oResult = json_decode($res);
             if ($oResult->valid !== true) {
                 $aResponse = array("error" => true, "message" => $oResult->message);
             } else {
                 SystemSettings::set("lvdc", time());
             }
         } catch (\Exception $e) {
             $aResponse = array("error" => true, "message" => $e->getMessage());
         }
     }
     try {
         if (!isset($aResponse)) {
             $command = new ApiCommand();
             $command->setContainer($this->container);
             $input = new ArgvInput(array('control:remote:cron', '--app=' . $id, '--force'));
             $output = new NullOutput();
             // Run the command
             $retval = $command->run($input, $output);
             $oRemoteApp = RemoteAppQuery::create()->findOneById($id);
             $sJsonData = $this->renderView('SlashworksAppBundle:RemoteApp:data.json.twig', array('entities' => array($oRemoteApp)));
             $aData = json_decode($sJsonData, true);
             if (!$retval) {
                 $aResponse = $aData;
             } else {
                 $aResponse = array("error" => true);
             }
         }
     } catch (\Exception $e) {
         $aResponse = array("error" => true, "message" => $e->getMessage());
     }
     $response = new Response(json_encode($aResponse));
     $response->headers->set('Content-Type', 'application/json');
     return $response;
 }