* GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) */ namespace Panel\Vmail; class Domains extends \Panel\Vmail { function beforeRoute($f3) { parent::beforeRoute($f3); if ($f3->exists('PARAMS.domain')) { $domain = $f3->get('PARAMS.domain'); if ($domain_array = $f3->call('\Panel::vGet', array("vmail-domains-get.sh -d $domain -c", FALSE))) { $f3->set('domain_array', $domain_array[0]); /* get cert info */ $mxdomain = "mail.$domain"; if ($f3->call('\Panel::verifyCertificateExists', $mxdomain)) { if ($cert_array = $f3->call('\Panel::vGet', array("letsencrypt-get.sh -d $mxdomain -c", FALSE))) { $cert_array = $cert_array[0]; /* remove time from expiration date */ $end = $cert_array['end']; $end_array = explode(' ', $end); unset($end_array[2]); $end = implode(' ', $end_array); $cert_array['end'] = $end; /* add line breaks */ $common = $cert_array['common']; $alternative = $cert_array['alternative']; $alternative = preg_replace('/ /', '
', $alternative); $cert_array['alternative'] = $alternative; $f3->set('cert_array', $cert_array); } } /* get dns info */ $dnsinfo = array(); $dnsinfo['verified_count'] = 0; $dnsinfo['server_addr'] = $_SERVER['SERVER_ADDR']; # A record $dnsinfo['a']['color'] = "red"; if ($certdomain_dns = @dns_get_record("$mxdomain", DNS_A)) { if ($certdomain_dns[0]['ip'] == $dnsinfo['server_addr']) { $dnsinfo['a']['status'] = "Verified"; $dnsinfo['a']['color'] = "black"; $dnsinfo['verified_count']++; } else { $dnsinfo['a']['status'] = "Update"; } } else { $dnsinfo['a']['status'] = "Create"; } # MX record $dnsinfo['mx']['color'] = "red"; if (getmxrr($domain, $mx)) { if (in_array($mxdomain, $mx)) { $dnsinfo['mx']['status'] = "Verified"; $dnsinfo['mx']['color'] = "black"; $dnsinfo['verified_count']++; } else { $dnsinfo['mx']['status'] = "Update"; } } else { $dnsinfo['mx']['status'] = "Create"; } # SPF (TXT) record $dnsinfo['spf']['status'] = "Create"; $dnsinfo['spf']['color'] = "red"; if ($dns_txt_records = @dns_get_record("$domain", DNS_TXT)) { foreach ($dns_txt_records as $k=>$dns_txt_record) { if (str_starts_with($dns_txt_record['txt'], 'v=spf1')) { $dnsinfo['spf']['status'] = "Update"; if (str_contains($dns_txt_record['txt'], ' mx ')) { $dnsinfo['spf']['status'] = "Verified"; $dnsinfo['spf']['color'] = "black"; $dnsinfo['verified_count']++; } } } } # DKIM $dnsinfo['dkim']['color'] = "red"; if ($f3->call('\Panel::verifyDkimExists', $domain)) { if ($dkim_array = $f3->call('\Panel::vGet', array("vmail-dkim-get.sh -d $domain -c", FALSE))) { $dkim_hostname = $dkim_array[0]['selector'] . "._domainkey.$domain"; if ($dns_txt_records = @dns_get_record($dkim_hostname, DNS_TXT)) { $dnsinfo['dkim']['status'] = "Verified"; $dnsinfo['dkim']['color'] = "black"; $dnsinfo['verified_count']++; } else { $dnsinfo['dkim']['status'] = "Update"; $dnsinfo['dkim']['selector'] = $dkim_array[0]['selector']; $dnsinfo['dkim']['dkim'] = $dkim_array[0]['dkim']; } } else { $dnsinfo['dkim']['status'] = "Error"; } } else { $dnsinfo['dkim']['status'] = "Create"; } # DMARC (TXT) record $dnsinfo['dmarc']['status'] = "Create"; $dnsinfo['dmarc']['color'] = "red"; if ($dns_txt_records = @dns_get_record("_dmarc.$domain", DNS_TXT)) { foreach ($dns_txt_records as $k=>$dns_txt_record) { if (str_starts_with($dns_txt_record['txt'], 'v=DMARC1')) { $dnsinfo['dmarc']['status'] = "Verified"; $dnsinfo['dmarc']['color'] = "black"; $dnsinfo['verified_count']++; } else { $dnsinfo['dmarc']['status'] = "Update"; } } } if ($dnsinfo['verified_count'] == 5) { $dnsinfo['status'] = 'Verified'; } else { $dnsinfo['status'] = 'Update'; } $f3->set('dnsinfo', $dnsinfo); } } else { if ($domains_array = $f3->call('\Panel::vGet', array("vmail-domains-get.sh -c", FALSE))) { $f3->set('domains_array', $domains_array); } } } // $dnsinfo['mx']['status'] = ready/update/none // $dnsinfo['spf']['status'] = ready/update/none // $dnsinfo['spf']['data'] = current_record // $dnsinfo['dkim']['status'] = ready/update/none // $dnsinfo['dkim']['selector'] = // $dnsinfo['dkim']['data'] = // dns_a gethostbyname() // dns_mx getmxrr() / dns_get_mx() // dns_spf checkdnsrr() / dns_check_record() // dns_dkim // # domain does not have cert yet, check DNS // $dns_a_record = $_SERVER['SERVER_ADDR']; // if ($certdomain_dns = @dns_get_record("$certdomain", DNS_A)) { // if ($certdomain_dns[0]['ip'] == $dns_a_record) { // $dns_status = "ready"; // } else { // $dns_status = "update"; // } // } else { // $dns_status = "none"; // } // $f3->set('dns_a_record', $dns_a_record); // $f3->set('dns_status', $dns_status); static function get($f3) { if ($f3->exists('PARAMS.domain')) { $domain_array = $f3->get('domain_array'); /* convert data for frontend display */ if ($domain_array['status'] == 1) { $domain_array['status'] = 'Enabled'; } else { $domain_array['status'] = 'Disabled'; } if ($domain_array['mbox_limit'] == "NULL") { $domain_array['mbox_limit'] = 'Unlimited'; } if ($domain_array['mbox_quota_default'] == "NULL") { $domain_array['mbox_quota_default'] = 'Unlimited'; } else { $domain_array['mbox_quota_default'] .= ' GB'; } if ($domain_array['mbox_ratelimit_default'] == "NULL") { $domain_array['mbox_ratelimit_default'] = 'Unlimited'; } else { $domain_array['mbox_ratelimit_default'] .= ' emails per hour'; } $f3->set('domain_array', $domain_array); $domain = $f3->get('PARAMS.domain'); $f3->set('page_header', "Email Domain $domain"); echo \Template::instance()->render('vmail/domains-domain.html'); } else { $f3->set('page_header', "Email Domains"); echo \Template::instance()->render('vmail/domains.html'); } } }