| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197 |
- <?php
- namespace ThurData\Servers\KerioEmail\App\UI\Client\Setting\Providers;
- use ThurData\Servers\KerioEmail\App\Enums\Kerio;
- use function ThurData\Servers\KerioEmail\Core\Helper\di;
- use ThurData\Servers\KerioEmail\Core\Helper\DnsHelper;
- use ThurData\Servers\KerioEmail\App\Libs\Product\ProductManager;
- use ThurData\Servers\KerioEmail\Core\UI\ResponseTemplates\HtmlDataJsonResponse;
- use ThurData\Servers\KerioEmail\Core\UI\Widget\Forms\DataProviders\BaseDataProvider;
- use ThurData\Servers\KerioEmail\Api\KerioWhmcs;
- /**
- *
- * Created by PhpStorm.
- * User: ThurData
- * Date: 18.09.19
- * Time: 09:35
- * Class EditSettingDataProvider
- */
- class EditSettingDataProvider extends BaseDataProvider
- {
- /**
- *
- */
- public function read()
- {
- $maildomain = $this->actionElementId;
- $api = new KerioWhmcs('whmcsKerioEmail', 'Thurdata', '1.0');
- try {
- $api->login($this->getWhmcsParamByKey('serverhostname'), $this->getWhmcsParamByKey('serverusername'), $this->getWhmcsParamByKey('serverpassword'));
- $dkimSet = $api->getDkimDnsRecord($maildomain);
- } catch (KerioApiException $error) {
- logModuleCall(
- 'kerioEmail',
- __FUNCTION__,
- $error,
- 'Debug Error',
- $error->getMessage()
- );
- return ['error' => $error->getMessage()];
- }
- $api->logout();
- // format dkim response
- $dkimArray = explode(PHP_EOL,$dkimSet['detail']);
- $dkimValue = explode(":",$dkimArray[1]);
- $this->domainKey = ltrim($dkimValue[1]);
- $dkimName = explode(":",$dkimArray[0]);
- $this->dkimName = ltrim($dkimName[1]);
- // get settings from product configuration
- $productManager = new ProductManager();
- $productManager->loadById($this->getWhmcsParamByKey('pid'));
- $this->spfConfig = $productManager->get('spf_string');
- $this->dmarcConfig = $productManager->get('dmarc_string');
- $clientDomains = localAPI('GetClientsDomains', array('clientid' => $this->getWhmcsParamByKey('userid')));
- $dns = new DnsHelper();
- /**
- * format model to array
- */
- in_array($maildomain,$clientDomains) ? $selfdomain = 1 : $selfdomain = 0;
- $dnsRecords = $dns->getRecords($maildomain);
- $dnsRecords['selfdns'] ? $selfDns = $dnsRecords['selfdns'] : $selfDns = 0;
- $this->mxthurdata = $this->getWhmcsParamByKey('serverhostname');
- if(empty($dnsRecords['mx'])){
- $mx = 'unset';
- } else {
- $mx = implode('',$dnsRecords['mx']);
- }
- if(empty($dnsRecords['spf'])) {
- $spf = 'unset';
- } else {
- $spf = implode('',$dnsRecords['spf']);
- }
- if(empty($dnsRecords['dmarc'])) {
- $dmarc = 'unset';
- } else {
- $dmarc = implode('',$dnsRecords['dmarc']);
- }
- if(empty($dnsRecords['dkim'])) {
- $dkim = 'unset';
- } else {
- $dkim = implode('',$dnsRecords['dkim']);
- }
- if($this->mxthurdata == $mx){
- if($this->spfConfig == $spf && $this->dmarcConfig == $dmarc && in_array($this->domainKey, $dnsRecords['dkim'])){
- $dnsok = 'success';
- } else {
- $dnsok = 'warning';
- }
- } else {
- $dnsok = 'danger';
- }
- $this->data = [
- 'maildomain' => $maildomain,
- 'mxactive' => $mx,
- 'spf' => $spf,
- 'dmarc' => $dmarc,
- 'dkimname' => $this->dkimName,
- 'dkim' => $dkim,
- 'mxthurdata' => $this->mxthurdata,
- 'spfthurdata' => $this->spfConfig,
- 'dmarcthurdata' => $this->dmarcConfig,
- 'dkimthurdata' => $this->domainKey,
- 'zoneid' => $selfDns,
- 'dnsok' => $dnsok
- ];
- }
- /**
- * @return HtmlDataJsonResponse
- */
- public function update()
- {
- logModuleCall(
- 'kerioEmail',
- __FUNCTION__,
- $this->formData,
- 'Debug Formdata',
- $this->params
- );
- return (new HtmlDataJsonResponse())->setMessageAndTranslate('settingHasBeenUpdated')->setStatusSuccess();
- $fieldToProtection = [
- 'maildomain',
- 'mxthurdata',
- 'spfthurdata',
- 'dmarcthurdata',
- 'dkimthurdata',
- 'dkimname',
- 'zoneid'
- ];
- foreach ($this->formData as $field => &$value)
- {
- $value = in_array($field, $fieldToProtection) ? htmlentities($value) : $value;
- }
- $attr = array(
- 'description' => $this->formData['description'],
- 'type' => $this->formData['type'],
- 'isEnabled' => $this->formData['status'] === 'active' ? true : false,
- 'manager' => array(
- 'id' => $this->formData['manager'],
- 'type' => 'UserPrincipal'
- )
- );
- $api = new KerioWhmcs('whmcsKerioEmail', 'Thurdata', '1.0');
- try {
- $api->login($this->getWhmcsParamByKey('serverhostname'), $this->getWhmcsParamByKey('serverusername'), $this->getWhmcsParamByKey('serverpassword'));
- $domainID = $api->getDomainId($this->getWhmcsParamByKey('domain'));
- } catch (KerioApiException $error) {
- logModuleCall(
- 'kerioEmail',
- __FUNCTION__,
- $error,
- 'Debug Error',
- $error->getMessage()
- );
- return ['error' => $error->getMessage()];
- }
- try {
- $result = $api->updateResouce($attr,$this->formData['id']);
- } catch (KerioApiException $error) {
- logModuleCall(
- 'kerioEmail',
- __FUNCTION__,
- $error,
- 'Debug Error',
- $error->getMessage()
- );
- return ['error' => $error->getMessage()];
- }
- $api->logout();
- return (new HtmlDataJsonResponse())->setMessageAndTranslate('settingHasBeenUpdated')->setStatusSuccess();
- }
- /**
- * @return HtmlDataJsonResponse
- */
- public function updateStatus()
- {
- }
- /**
- * @return HtmlDataJsonResponse
- */
- public function changePassword()
- {
- }
- }
|