/** * 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'); }
/** * @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; }
/** * 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; }