Skip to navigation
Setup Dkim from Froxlor 2.x with Opendkim
07.09.23
## Activate DKIM and DNS service in Froxlor and activate it for one customer domain ## Let the default settings just change Milter restart command Please specify the restart command for the DKIM milter service: /etc/init.d/opendkim restart ## Change the /etc/opendkim.conf settings to: ```apacheconf Syslog yes SyslogSuccess yes Canonicalization relaxed/simple OversignHeaders From UserID opendkim UMask 007 SigningTable refile:/etc/postfix/dkim/signing.table KeyTable /etc/postfix/dkim/key.table SignatureAlgorithm rsa-sha256 Socket inet:8892@localhost PidFile /run/opendkim/opendkim.pid TrustAnchorFile /usr/share/dns/root.key ``` ## Change /etc/postfix/main.cf Milter setting to bellow like: not i hae local:spamass/spamass.sock as well setup ```apache2conf # Milter configuration milter_default_action = accept milter_protocol = 6 smtpd_milters = inet:localhost:8892, local:spamass/spamass.sock non_smtpd_milters = $smtpd_milters ``` ## Run the below php script to access the Frolxor Database and its files to generate a opendkim format files ```php get_domains($sql); echo "...get dkim settings \n"; $fd_dkims = $fdkim->get_dkims_settings($sql); echo "...create public files \n"; $fdkim->create_public_files($fd_domains, $fd_dkims); echo "...create key table \n"; $fdkim->create_key_table($fd_domains, $fd_dkims); echo "...create signing table \n"; $fdkim->create_signing_table($fd_domains, $fd_dkims); echo "...set dkim ownership \n"; $fdkim->set_ownership($fd_dkims); class FroxlorDkim { /** * Create the signing table file * * @param array $fd_domains Domain list what should get signed * @param array $fd_dkims Froxlors dkim settings * * @return bolean */ function create_signing_table($fd_domains, $fd_dkims) { if ( !file_exists($fd_dkims['dkim_prefix']) ): mkdir($fd_dkims['dkim_prefix'], 0777, true); endif; $path = $fd_dkims['dkim_prefix'] . "/signing.table"; $f = fopen($path, "w") or die("Unable to open file!"); foreach($fd_domains as $k=>$i): $domain = explode(".",$i); $txt = "*@${i} ${domain[0]} \n"; fwrite($f, $txt); endforeach; fclose($f); echo "...successfully signing table created to: ${path} \n"; return 1; } /** * Create the key table file * * @param array $fd_domains Domain list what should get signed * @param array $fd_dkims Froxlors dkim settings * * @return bolean */ function create_key_table($fd_domains, $fd_dkims) { if ( !file_exists($fd_dkims['dkim_prefix']) ): mkdir($fd_dkims['dkim_prefix'], 0777, true); endif; $path = $fd_dkims['dkim_prefix'] . "/key.table"; $f = fopen($path, "w") or die("Unable to open file!"); foreach($fd_domains as $k=>$i): $domain = explode(".",$i); $txt = "${domain[0]} ${i}:default:${fd_dkims['dkim_prefix']}dkim${k}${fd_dkims['privkeysuffix']}\n"; fwrite($f, $txt); endforeach; fclose($f); echo "...successfully key table created to: ${path} \n"; return 1; } /** * Get the Froxlor DKIM Domains * * @param array $access_info Froxlor's SQL access info * @return array List of domains for DKIM */ function get_domains($access_info) { $domains = []; /* Connect to the Froxlor Database and get the domains */ $conn = new mysqli($access_info['host'], $access_info['user'], $access_info['password'], $access_info['db']); if($conn->connect_errno ): echo "Connect failed: " . $conn->connect_error ; return $domains; endif; //echo "Connected successfully! \n\n"; $sql = "SELECT d.dkim_id, d.domain FROM panel_domains AS d WHERE d.dkim = 1 "; $result = $conn->query($sql); if ($result->num_rows > 0): //echo "Query Result: \n"; while($row = $result->fetch_assoc()): //echo "id: " . $row["dkim_id"]. " - Domain: " . $row["domain"] . "\n"; $domains[$row["dkim_id"]] = $row["domain"]; endwhile; endif; $conn->close(); return $domains; } /** * Get the Froxlor DKIM settings * * @param array $access_info Froxlor's SQL access info * @return array Froxlor Setting Info */ function get_dkims_settings($access_info) { $dkims = []; /* Connect to the Froxlor Database and get the domains */ $conn = new mysqli($access_info['host'], $access_info['user'], $access_info['password'], $access_info['db']); if($conn->connect_errno ): echo "Connect failed: " . $conn->connect_error ; return $dkims; endif; //echo "Connected successfully! \n\n"; $sql = "SELECT s.varname, s.value FROM panel_settings AS s WHERE s.settinggroup = 'dkim' "; $result = $conn->query($sql); if ($result->num_rows > 0): //echo "Query Result: \n"; while($row = $result->fetch_assoc()): //echo "varname: " . $row["varname"]. " - value: " . $row["value"] . "\n"; $dkims[$row["varname"]] = $row["value"]; endwhile; endif; $conn->close(); return $dkims; } /** * Set the ownership of the dkim files to opendkim for user and group * * @param array $fd_dkims Froxlors dkim settings * @return void */ function set_ownership($fd_dkims) { if (file_exists($fd_dkims['dkim_prefix'])): $d = opendir ($fd_dkims['dkim_prefix']); while(($file = readdir($d)) !== false): if ($file != "." && $file != ".."): $typepath = $fd_dkims['dkim_prefix'] . "/" . $file ; if (filetype ($typepath) != 'dir'): chown($typepath, 'opendkim'); chgrp($typepath, 'opendkim'); endif; endif; endwhile; endif; return null; } /** * Create public files * * @param array $fd_domains Domain list what should get signed * @param array $fd_dkims Froxlors dkim settings * * @return bolean */ function create_public_files($fd_domains, $fd_dkims) { foreach($fd_domains as $k=>$i): $path = "${fd_dkims['dkim_prefix']}/dkim${k}.public"; if (file_exists($path)): $a = file($path, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); $public_key = "v=DKIM1; k=rsa;p=".$a[1].$a[2].$a[3].$a[4]."\n"; $file_name = "${fd_dkims['dkim_prefix']}default._domainkey.${fd_domains[$k]}"; //var_dump($file_name); $file = fopen($file_name, "w") or die("Unable to open file!");; fwrite($file, $public_key); endif; endforeach; return 1; } } ?> ```
https://www.besuchet.net/2015/08/dkim-configuration-for-postfix-and-plesk/
Reply
Anonymous
Information Epoch 1761493517
Save trees.
Home
Notebook
Contact us