| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132 |
- <?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\UI\ResponseTemplates\HtmlDataJsonResponse;
- use ThurData\Servers\KerioEmail\App\Libs\Product\ProductManager;
- use ThurData\Servers\KerioEmail\Core\Helper\DnsHelper;
- use ThurData\Servers\KerioEmail\Core\UI\Widget\Forms\DataProviders\BaseDataProvider;
- use ThurData\Servers\KerioEmail\Api\KerioWhmcs;
- /**
- *
- * Created by PhpStorm.
- * User: ThurData
- * Date: 10.09.19
- * Time: 13:06
- * Class SettingDataProvider
- */
- class InfoSettingDataProvider 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' => $params['userid']));
- $dns = new DnsHelper();
- /**
- * format model to array
- */
- in_array($domain,$clientDomains) ? $selfdomain = 1 : $selfdomain = 0;
- $dnsRecords = $dns->getRecords($domain);
- $dnsRecords['selfdns'] ? $selfDns = 1 : $selfDns = 0;
- if(empty($dnsRecords['mx'])){
- $mx = 'unset';
- } else {
- in_array($params['serverhostname'],$dnsRecords['mx']) ? $mx = $dnsRecords['mx'] : $mx = 'wrong';
- }
- if(empty($dnsRecords['spf'])) {
- $spf = 'unset';
- } else {
- if (count($dnsRecords['spf']) > 1) {
- $spf = 'multi';
- } else {
- if($dnsRecords['spf'][0] === $this->spfConfig){
- $dnsRecords['spf'][0];
- } else {
- $spf = 'wrong';
- }
- }
- }
- if(empty($dnsRecords['dmarc'])) {
- $dmarc = 'unset';
- } else {
- if (count($dnsRecords['dmarc']) > 1) {
- $dmarc = 'multi';
- } else {
- if($dnsRecords['dmarc'][0] === $this->dmarcConfig){
- $dmarc = $dnsRecords['dmarc'][0];
- } else {
- $dmarc = 'wrong';
- }
- }
- }
- in_array($this->domainKey, $dnsRecords['dkim']) ? $dkim = 'set' : $dkim = 'unset';
- $this->data = [
- 'id' => $domain,
- 'domain' => $domain,
- 'mxactive' => $mx,
- 'spf' => $spf,
- 'dmarc' => $dmarc,
- 'dkim' => $dkim,
- 'selfdns' => $selfDns,
- 'selfdomain' => $selfdomain,
- 'mxthurdata' => $this->getWhmcsParamByKey('serverhostname'),
- 'spfthurdata' => $this->spfConfig,
- ];
- $this->availableValues['dnsrecords'] = $dnsRecords;
- logModuleCall(
- 'kerioEmail',
- __FUNCTION__,
- $this->data,
- 'Debug Data',
- $this->actionElementId
- );
- }
- public function create()
- {
- }
- public function updateStatus()
- {
- }
- public function update()
- {
- }
- }
|