Kenji Okimoto
null+****@clear*****
Mon Jun 26 17:21:37 JST 2017
Kenji Okimoto 2017-06-26 17:21:37 +0900 (Mon, 26 Jun 2017) New Revision: ca74ab0b1d2002f0d89d1a553c071cdb1e58b9b5 https://github.com/milter-manager/milter-manager/commit/ca74ab0b1d2002f0d89d1a553c071cdb1e58b9b5 Merged 8a5f2c2: Merge pull request #126 from milter-manager/auto-detect-rspamd-proxy Message: binding ruby manager: Detect rspamd_proxy automatically Added files: binding/ruby/lib/milter/manager/rspamd-proxy-detector.rb Modified files: binding/ruby/lib/milter/manager/detector.rb binding/ruby/lib/milter/manager/freebsd-rc-detector.rb binding/ruby/lib/milter/manager/redhat-init-detector.rb binding/ruby/lib/milter/manager/systemd-detector.rb Modified: binding/ruby/lib/milter/manager/detector.rb (+5 -0) =================================================================== --- binding/ruby/lib/milter/manager/detector.rb 2017-06-26 14:22:19 +0900 (13df44d) +++ binding/ruby/lib/milter/manager/detector.rb 2017-06-26 17:21:37 +0900 (747a8a5) @@ -17,6 +17,7 @@ require 'milter/manager/clamav-milter-config-parser' require 'milter/manager/milter-greylist-config-parser' require 'milter/manager/opendkim-config-parser' require 'milter/manager/rmilter-socket-detector' +require 'milter/manager/rspamd-proxy-detector' module Milter::Manager module Detector @@ -88,6 +89,10 @@ module Milter::Manager Milter::Manager::RmilterSocketDetector.new(rmilter_conf).detect end + def detect_rspamd_proxy_connection_spec + Milter::Manager::RspamdProxyDetector.new(rspamadm_path).detect + end + def have_service_command? not service_command.nil? end Modified: binding/ruby/lib/milter/manager/freebsd-rc-detector.rb (+5 -0) =================================================================== --- binding/ruby/lib/milter/manager/freebsd-rc-detector.rb 2017-06-26 14:22:19 +0900 (929a0ae) +++ binding/ruby/lib/milter/manager/freebsd-rc-detector.rb 2017-06-26 17:21:37 +0900 (c311180) @@ -63,6 +63,10 @@ module Milter::Manager @script_name == "rmilter" or @name == "rmilter" end + def rspamd_proxy? + @script_name == "rspamd" or @name == "rspamd" + end + private def enma_conf @variables["cfgfile"] || @@ -108,6 +112,7 @@ module Milter::Manager spec ||= detect_clamav_milter_connection_spec if clamav_milter? spec ||= detect_opendkim_connection_spec if opendkim? spec ||= detect_rmilter_connection_spec if rmilter? + spec ||= detect_rspamd_proxy_connection_spec if rspamd_proxy? spec end end Modified: binding/ruby/lib/milter/manager/redhat-init-detector.rb (+5 -0) =================================================================== --- binding/ruby/lib/milter/manager/redhat-init-detector.rb 2017-06-26 14:22:19 +0900 (c05a079) +++ binding/ruby/lib/milter/manager/redhat-init-detector.rb 2017-06-26 17:21:37 +0900 (9e791a7) @@ -73,6 +73,10 @@ module Milter::Manager etc_file("rmilter", "rmilter.conf.sysvinit") end + def rspamd_proxy? + @script_name == "rspamd" + end + private def parse_custom_conf parse_sysconfig(sysconfig) @@ -170,6 +174,7 @@ module Milter::Manager end spec ||= detect_opendkim_connection_spec if opendkim? spec ||= detect_rmilter_connection_spec if rmilter? + spec ||= detect_rspamd_proxy_connection_spec if rspamd_proxy? spec end Added: binding/ruby/lib/milter/manager/rspamd-proxy-detector.rb (+26 -0) 100644 =================================================================== --- /dev/null +++ binding/ruby/lib/milter/manager/rspamd-proxy-detector.rb 2017-06-26 17:21:37 +0900 (cf29f57) @@ -0,0 +1,26 @@ +require "json" + +module Milter::Manager + class RspamdProxyDetector + def initialize(rspamadm_path="/usr/bin/rspamadm") + @rspamadm_path = rspamadm_path + end + + def detect + return unless File.executable?(@rspamadm_path) + + config = JSON.parse(`#{@rspamadm_path} configdump --json` || "{}") + workers = config["worker"] + return unless workers + rspamd_proxy = workers.detect do |worker| + worker.key?("rspamd_proxy") && worker.dig("rspamd_proxy", "milter") + end + host, port = rspamd_proxy["bind_socket"].split(":", 2) + if host == "*" + "inet:#{port}@localhost" + else + "inet:#{port}@#{host}" + end + end + end +end Modified: binding/ruby/lib/milter/manager/systemd-detector.rb (+5 -0) =================================================================== --- binding/ruby/lib/milter/manager/systemd-detector.rb 2017-06-26 14:22:19 +0900 (95a25ad) +++ binding/ruby/lib/milter/manager/systemd-detector.rb 2017-06-26 17:21:37 +0900 (72cdaca) @@ -45,6 +45,10 @@ module Milter::Manager @script_name == "rmilter" end + def rspamd_proxy? + @script_name == "rspamd" + end + private def init_variables super @@ -103,6 +107,7 @@ module Milter::Manager spec ||= detect_milter_greylist_connection_spec if milter_greylist? spec ||= detect_opendkim_connection_spec if opendkim? spec ||= detect_rmilter_connection_spec if rmilter? + spec ||= detect_rspamd_proxy_connection_spec if rspamd_proxy? spec end -------------- next part -------------- An HTML attachment was scrubbed... Download