@@ -1802,6 +1802,10 @@ public function configure_rspamd() {
18021802 mkdir ('/etc/rspamd/local.d/ ' , 0755 , true );
18031803 }
18041804
1805+ if (!is_dir ('/etc/rspamd/local.d/maps.d/ ' )){
1806+ mkdir ('/etc/rspamd/local.d/maps.d/ ' , 0755 , true );
1807+ }
1808+
18051809 if (!is_dir ('/etc/rspamd/override.d/ ' )){
18061810 mkdir ('/etc/rspamd/override.d/ ' , 0755 , true );
18071811 }
@@ -1810,6 +1814,7 @@ public function configure_rspamd() {
18101814 $ mail_config ['dkim_path ' ] = substr ($ mail_config ['dkim_path ' ], 0 , strlen ($ mail_config ['dkim_path ' ])-1 );
18111815 }
18121816 $ dkim_domains = $ this ->db ->queryAllRecords ('SELECT `dkim_selector`, `domain` FROM ?? WHERE `dkim` = ? ORDER BY `domain` ASC ' , $ conf ['mysql ' ]['database ' ] . '.mail_domain ' , 'y ' );
1817+ # should move maps to local.d/maps.d/ ?
18131818 $ fpp = fopen ('/etc/rspamd/local.d/dkim_domains.map ' , 'w ' );
18141819 $ fps = fopen ('/etc/rspamd/local.d/dkim_selectors.map ' , 'w ' );
18151820 foreach ($ dkim_domains as $ dkim_domain ) {
@@ -1820,104 +1825,79 @@ public function configure_rspamd() {
18201825 fclose ($ fps );
18211826 unset($ dkim_domains );
18221827
1828+ # local.d templates with template tags
1829+ $ tpl = new tpl ();
1830+ $ tpl ->newTemplate ('rspamd_dkim_signing.conf.master ' );
1831+ $ tpl ->setVar ('dkim_path ' , $ mail_config ['dkim_path ' ]);
1832+ wf ('/etc/rspamd/local.d/dkim_signing.conf ' , $ tpl ->grab ());
1833+
18231834 $ tpl = new tpl ();
1824- $ tpl ->newTemplate ('rspamd_users.conf .master ' );
1835+ $ tpl ->newTemplate ('rspamd_options.inc .master ' );
18251836
1826- $ whitelist_ips = array ();
1827- $ ips = $ this ->db ->queryAllRecords (" SELECT * FROM server_ip WHERE server_id = ? " , $ conf ['server_id ' ]);
1837+ $ local_addrs = array ();
1838+ $ ips = $ this ->db ->queryAllRecords (' SELECT `ip_address`, `ip_type` FROM ?? WHERE ` server_id` = ? ' , $ conf [ ' mysql ' ][ ' database ' ]. ' .server_ip ' , $ conf ['server_id ' ]);
18281839 if (is_array ($ ips ) && !empty ($ ips )){
18291840 foreach ($ ips as $ ip ){
1830- $ whitelist_ips [] = array ('ip ' => $ ip ['ip_address ' ]);
1841+ $ local_addrs [] = array ('quoted_ip ' => "\"" .$ ip ['ip_address ' ]."\", \n" );
1842+ }
1843+ }
1844+ $ tpl ->setLoop ('local_addrs ' , $ local_addrs );
1845+ wf ('/etc/rspamd/local.d/options.inc ' , $ tpl ->grab ());
1846+
1847+ # local.d templates without template tags
1848+ $ local_d = array (
1849+ 'groups.conf ' ,
1850+ 'antivirus.conf ' ,
1851+ 'classifier-bayes.conf ' ,
1852+ 'greylist.conf ' ,
1853+ 'mx_check.conf ' ,
1854+ 'redis.conf ' ,
1855+ 'milter_headers.conf ' ,
1856+ 'neural.conf ' ,
1857+ 'neural_group.conf ' ,
1858+ 'users.conf ' ,
1859+ 'groups.conf ' ,
1860+ );
1861+ foreach ($ local_d as $ f ) {
1862+ if (file_exists ($ conf ['ispconfig_install_dir ' ]."/server/conf-custom/install/rspamd_ $ {f}.master " )) {
1863+ exec ('cp ' .$ conf ['ispconfig_install_dir ' ]."/server/conf-custom/install/rspamd_ $ {f}.master /etc/rspamd/local.d/ $ {f}" );
1864+ } else {
1865+ exec ("cp tpl/rspamd_ $ {f}.master /etc/rspamd/local.d/ $ {f}" );
18311866 }
18321867 }
1833- $ tpl ->setLoop ('whitelist_ips ' , $ whitelist_ips );
1834- wf ('/etc/rspamd/local.d/users.conf ' , $ tpl ->grab ());
1835-
1836- if (file_exists ($ conf ['ispconfig_install_dir ' ].'/server/conf-custom/install/rspamd_groups.conf.master ' )) {
1837- exec ('cp ' .$ conf ['ispconfig_install_dir ' ].'/server/conf-custom/install/rspamd_groups.conf.master /etc/rspamd/local.d/groups.conf ' );
1838- } else {
1839- exec ('cp tpl/rspamd_groups.conf.master /etc/rspamd/local.d/groups.conf ' );
1840- }
1841-
1842- if (file_exists ($ conf ['ispconfig_install_dir ' ].'/server/conf-custom/install/rspamd_antivirus.conf.master ' )) {
1843- exec ('cp ' .$ conf ['ispconfig_install_dir ' ].'/server/conf-custom/install/rspamd_antivirus.conf.master /etc/rspamd/local.d/antivirus.conf ' );
1844- } else {
1845- exec ('cp tpl/rspamd_antivirus.conf.master /etc/rspamd/local.d/antivirus.conf ' );
1846- }
1847-
1848- if (file_exists ($ conf ['ispconfig_install_dir ' ].'/server/conf-custom/install/rspamd_classifier-bayes.conf.master ' )) {
1849- exec ('cp ' .$ conf ['ispconfig_install_dir ' ].'/server/conf-custom/install/rspamd_classifier-bayes.conf.master /etc/rspamd/local.d/classifier-bayes.conf ' );
1850- } else {
1851- exec ('cp tpl/rspamd_classifier-bayes.conf.master /etc/rspamd/local.d/classifier-bayes.conf ' );
1852- }
1853-
1854- if (file_exists ($ conf ['ispconfig_install_dir ' ].'/server/conf-custom/install/rspamd_greylist.conf.master ' )) {
1855- exec ('cp ' .$ conf ['ispconfig_install_dir ' ].'/server/conf-custom/install/rspamd_greylist.conf.master /etc/rspamd/local.d/greylist.conf ' );
1856- } else {
1857- exec ('cp tpl/rspamd_greylist.conf.master /etc/rspamd/local.d/greylist.conf ' );
1858- }
1859-
1860- if (file_exists ($ conf ['ispconfig_install_dir ' ].'/server/conf-custom/install/rspamd_symbols_antivirus.conf.master ' )) {
1861- exec ('cp ' .$ conf ['ispconfig_install_dir ' ].'/server/conf-custom/install/rspamd_symbols_antivirus.conf.master /etc/rspamd/local.d/antivirus_group.conf ' );
1862- } else {
1863- exec ('cp tpl/rspamd_symbols_antivirus.conf.master /etc/rspamd/local.d/antivirus_group.conf ' );
1864- }
1865-
1866- if (file_exists ($ conf ['ispconfig_install_dir ' ].'/server/conf-custom/install/rspamd_override_rbl.conf.master ' )) {
1867- exec ('cp ' .$ conf ['ispconfig_install_dir ' ].'/server/conf-custom/install/rspamd_override_rbl.conf.master /etc/rspamd/override.d/rbl_group.conf ' );
1868- } else {
1869- exec ('cp tpl/rspamd_override_rbl.conf.master /etc/rspamd/override.d/rbl_group.conf ' );
1870- }
18711868
1872- if (file_exists ($ conf ['ispconfig_install_dir ' ].'/server/conf-custom/install/rspamd_override_surbl.conf.master ' )) {
1873- exec ('cp ' .$ conf ['ispconfig_install_dir ' ].'/server/conf-custom/install/rspamd_override_surbl.conf.master /etc/rspamd/override.d/surbl_group.conf ' );
1874- } else {
1875- exec ('cp tpl/rspamd_override_surbl.conf.master /etc/rspamd/override.d/surbl_group.conf ' );
1876- }
1877-
1878- if (file_exists ($ conf ['ispconfig_install_dir ' ].'/server/conf-custom/install/rspamd_mx_check.conf.master ' )) {
1879- exec ('cp ' .$ conf ['ispconfig_install_dir ' ].'/server/conf-custom/install/rspamd_mx_check.conf.master /etc/rspamd/local.d/mx_check.conf ' );
1880- } else {
1881- exec ('cp tpl/rspamd_mx_check.conf.master /etc/rspamd/local.d/mx_check.conf ' );
1882- }
1883-
1884- if (file_exists ($ conf ['ispconfig_install_dir ' ].'/server/conf-custom/install/rspamd_redis.conf.master ' )) {
1885- exec ('cp ' .$ conf ['ispconfig_install_dir ' ].'/server/conf-custom/install/rspamd_redis.conf.master /etc/rspamd/local.d/redis.conf ' );
1886- } else {
1887- exec ('cp tpl/rspamd_redis.conf.master /etc/rspamd/local.d/redis.conf ' );
1888- }
1889-
1890- if (file_exists ($ conf ['ispconfig_install_dir ' ].'/server/conf-custom/install/rspamd_milter_headers.conf.master ' )) {
1891- exec ('cp ' .$ conf ['ispconfig_install_dir ' ].'/server/conf-custom/install/rspamd_milter_headers.conf.master /etc/rspamd/local.d/milter_headers.conf ' );
1892- } else {
1893- exec ('cp tpl/rspamd_milter_headers.conf.master /etc/rspamd/local.d/milter_headers.conf ' );
1894- }
1895-
1896- if (file_exists ($ conf ['ispconfig_install_dir ' ].'/server/conf-custom/install/rspamd_options.inc.master ' )) {
1897- exec ('cp ' .$ conf ['ispconfig_install_dir ' ].'/server/conf-custom/install/rspamd_options.inc.master /etc/rspamd/local.d/options.inc ' );
1898- } else {
1899- exec ('cp tpl/rspamd_options.inc.master /etc/rspamd/local.d/options.inc ' );
1900- }
1901-
1902- if (file_exists ($ conf ['ispconfig_install_dir ' ].'/server/conf-custom/install/rspamd_neural.conf.master ' )) {
1903- exec ('cp ' .$ conf ['ispconfig_install_dir ' ].'/server/conf-custom/install/rspamd_neural.conf.master /etc/rspamd/local.d/neural.conf ' );
1904- } else {
1905- exec ('cp tpl/rspamd_neural.conf.master /etc/rspamd/local.d/neural.conf ' );
1869+ # override.d templates without template tags
1870+ $ override_d = array (
1871+ 'rbl_group.conf ' ,
1872+ 'surbl_group.conf ' ,
1873+ );
1874+ foreach ($ override_d as $ f ) {
1875+ if (file_exists ($ conf ['ispconfig_install_dir ' ]."/server/conf-custom/install/rspamd_ $ {f}.master " )) {
1876+ exec ('cp ' .$ conf ['ispconfig_install_dir ' ]."/server/conf-custom/install/rspamd_ $ {f}.master /etc/rspamd/override.d/ $ {f}" );
1877+ } else {
1878+ exec ("cp tpl/rspamd_ $ {f}.master /etc/rspamd/override.d/ $ {f}" );
1879+ }
19061880 }
19071881
1908- if (file_exists ($ conf ['ispconfig_install_dir ' ].'/server/conf-custom/install/rspamd_neural_group.conf.master ' )) {
1909- exec ('cp ' .$ conf ['ispconfig_install_dir ' ].'/server/conf-custom/install/rspamd_neural_group.conf.master /etc/rspamd/local.d/neural_group.conf ' );
1910- } else {
1911- exec ('cp tpl/rspamd_neural_group.conf.master /etc/rspamd/local.d/neural_group.conf ' );
1882+ # local.d/maps.d templates without template tags
1883+ $ maps_d = array (
1884+ 'dkim_whitelist.inc ' ,
1885+ 'dmarc_whitelist.inc ' ,
1886+ 'spf_dkim_whitelist.inc ' ,
1887+ 'spf_whitelist.inc ' ,
1888+ );
1889+ foreach ($ maps_d as $ f ) {
1890+ if (file_exists ($ conf ['ispconfig_install_dir ' ]."/server/conf-custom/install/rspamd_ $ {f}.master " )) {
1891+ exec ('cp ' .$ conf ['ispconfig_install_dir ' ]."/server/conf-custom/install/rspamd_ $ {f}.master /etc/rspamd/local.d/maps.d/ $ {f}" );
1892+ } else {
1893+ exec ("cp tpl/rspamd_ $ {f}.master /etc/rspamd/local.d/maps.d/ $ {f}" );
1894+ }
19121895 }
19131896
1914- $ tpl = new tpl ();
1915- $ tpl ->newTemplate ('rspamd_dkim_signing.conf.master ' );
1916- $ tpl ->setVar ('dkim_path ' , $ mail_config ['dkim_path ' ]);
1917- wf ('/etc/rspamd/local.d/dkim_signing.conf ' , $ tpl ->grab ());
19181897
1919- exec ('chmod a+r /etc/rspamd/local.d/* /etc/rspamd/override.d/* ' );
1898+ exec ('chmod a+r /etc/rspamd/local.d/* /etc/rspamd/local.d/maps.d/* /etc/rspamd/ override.d/* ' );
19201899
1900+ # unneccesary, since this was done above?
19211901 $ command = 'usermod -a -G amavis _rspamd ' ;
19221902 caselog ($ command .' &> /dev/null ' , __FILE__ , __LINE__ , "EXECUTED: $ command " , "Failed to execute the command $ command " );
19231903
0 commit comments