<?php
 namespace Modules\Admin\Server\Checks\Connect; class Controller extends \App\Mvc\Controller\Form\PopupAbstract { protected function initialize() { parent::initialize(); $this->actionsCfg['index'] = [ 'checkSection' => 'Modules/Admin/Server/Checks', 'checkOption' => false ]; } protected function getDefaultFormData($R) { return [ 'ssl'=>1 ]; } protected function processFormData(Array $R, \App\MessagesCollector $msgs) { if ($R['save'] && !$R['address']) { $msgs->addWarning($this->lang['index']['emptyAddress']); } elseif ($R['save'] && $R['address']) { $curl_handle = curl_init(); curl_setopt($curl_handle, CURLOPT_URL, htmlUnclean($R['address'])); curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 0); curl_setopt($curl_handle, CURLOPT_TIMEOUT, 0); if ($R['ssl']) { curl_setopt($curl_handle, CURLOPT_SSL_VERIFYPEER, true); curl_setopt($curl_handle, CURLOPT_SSL_VERIFYHOST, true); } else { curl_setopt($curl_handle, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($curl_handle, CURLOPT_SSL_VERIFYHOST, false); } curl_setopt($curl_handle, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); curl_setopt($curl_handle, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, TRUE); $response = curl_exec($curl_handle); $http_code = curl_getinfo($curl_handle); if ($response) { $msgs->addSuccess(sprintf($this->lang['index']['success'], $R['address'])); } else { $msgs->addError(sprintf($this->lang['index']['error'], $R['address'], curl_error($curl_handle))); } } return $http_code; } protected function actionIndex($R) { $msgs = \App\MessagesCollector::create(); $modelOutput = null; if ($R[$this->formSubmitButtonName]) { $modelOutput = $this->processFormData($R, $msgs); } $view = new View_Index($this); if (!$R[$this->formSubmitButtonName]) { $formData=$this->getDefaultFormData($R); } else { $formData=$R; $formData['debugOutput'] = $modelOutput; } $view->addInput('formData', $formData); $view->getMessagesCollector()->appendMessages($msgs); $view->addInput('formSubmitButtonName', $this->formSubmitButtonName); $this->preRenderOperations($view, $formData); return new \Engine\Mvc\Response\Html($view->render()); } }