Projects
home:rottame:mail
postfix-rate-policyd
Log In
Username
Password
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
Expand all
Collapse all
Changes of Revision 7
View file
config.yml
Changed
@@ -3,3 +3,60 @@ bind_port: 10031 log: syslog log_level: info + +defaults: &defaults + h_max_addresses: 5 + h_activity_threshold: 14400 + h_interval: 1800 + h_interval_count: 50 + h_grace_threshold: 1296000 + +policies: + - name: '128' + <<: *defaults + description: '128 mail/h' + interval: 3600 + heuristics: true + count: 128 + recipients: null + volume: null + - name: '512' + <<: *defaults + description: '512 mail/h' + interval: 3600 + heuristics: true + count: 512 + recipients: null + volume: null + - name: '1k' + <<: *defaults + description: '1k mail/h' + interval: 3600 + heuristics: true + count: 1024 + recipients: null + volume: null + - name: '4k' + <<: *defaults + description: '4k mail/h' + interval: 3600 + heuristics: true + count: 4096 + recipients: null + volume: null + - name: '12k' + <<: *defaults + description: '12k mail/h' + interval: 3600 + heuristics: true + count: 12228 + recipients: null + volume: null + - name: 'trusted' + <<: *defaults + description: 'Trusted email senders' + interval: 3600 + heuristics: true + count: null + recipients: null + volume: null
View file
postfix-rate-policyd-0.0.1.gem/checksums.yaml.gz
Changed
@@ -1,7 +1,7 @@ --- SHA256: - metadata.gz: b195d99cddebe71364eba1de1410651719c819f95b99b7f1de330e9c5bb4b810 - data.tar.gz: 9366eed92d095cfc08a28504b1516a6ea4c3e12a936f5efab1742fbf08a6e302 + metadata.gz: c2ee8419a2b8c3ff151e9e1619ac08446091ad1ce5827a782bd6aee4e1b5a004 + data.tar.gz: 0e732f9bc04d604d13a96dea0de1d4a0f5c0a86b37237247d73f7036fa70b7c9 SHA512: - metadata.gz: 0f5a17b5379c687cbf7a4eb512b8389c93d5c552e641a23381f8689938225d966ecc05f9a055dcdd77adadcb45996d1235c23427c8cce041b314ab8b8499f960 - data.tar.gz: 31174bab45e2148445c69d1769b8767cf25d17c69706911d56521f0384a04b12408399e3f5c333e02841a1e1131152ef2bf98eaaa7ce9015736ac96b706cda5b + metadata.gz: 8acc4fbe2b6bd8be640d073bb9c6dd5b3e174a63817c97485ee04e1819e1bd05e2d3024457f8c0261ddd4a11050f4ad29495dcb1fc5cbdff5c5f6a7761029309 + data.tar.gz: 13f82572bb4b185086e41ca81e68eb686026453cdd2cc8b224f1324187e686914ac72dcccd7d38db2cd68860e4e3d50fbcd20aab642b2d1167ef226751833b02
View file
postfix-rate-policyd-0.0.1.gem/data/Makefile
Added
@@ -0,0 +1,30 @@ +.PHONY: shell + +$(eval VERSION = $(shell grep VERSION lib/postfix/rate/policyd/version.rb | sed -r 's/^.*"(.*?)".*/\1/g')) + +tmp: Makefile + mkdir -p tmp + mkdir -p tmp/home + touch tmp + +tmp/dev-image: tmp Dockerfile + docker build -t policyd-dev . + touch tmp/dev-image + +shell: tmp/dev-image + docker run --rm -ti \ + -p 10031:10031 \ + -v ${PWD}/tmp/home:/home/user \ + -v ${PWD}:/policyd \ + policyd-dev \ + bash + +rpm-sources: + rm -f postfix-rate-policyd-*.gem + mkdir -p rpm_sources + gem build postfix-rate-policyd.gemspec + mv postfix-rate-policyd-${VERSION}.gem rpm_sources/ + cp config.yml rpm_sources/config.yml + cp postfix-rate-policyd.service rpm_sources/postfix-rate-policyd.service + cp postfix-rate-policyd.spec.in rpm_sources/rubygem-postfix-rate-policyd.spec + sed -i s/VERSION/${VERSION}/g rpm_sources/rubygem-postfix-rate-policyd.spec
View file
postfix-rate-policyd-0.0.1.gem/data/config.yml
Added
@@ -0,0 +1,62 @@ +database_url: mysql2://username:passwword@host:port/database +bind_address: '::' +bind_port: 10031 +log: syslog +log_level: info + +defaults: &defaults + h_max_addresses: 5 + h_activity_threshold: 14400 + h_interval: 1800 + h_interval_count: 50 + h_grace_threshold: 1296000 + +policies: + - name: '128' + <<: *defaults + description: '128 mail/h' + interval: 3600 + heuristics: true + count: 128 + recipients: null + volume: null + - name: '512' + <<: *defaults + description: '512 mail/h' + interval: 3600 + heuristics: true + count: 512 + recipients: null + volume: null + - name: '1k' + <<: *defaults + description: '1k mail/h' + interval: 3600 + heuristics: true + count: 1024 + recipients: null + volume: null + - name: '4k' + <<: *defaults + description: '4k mail/h' + interval: 3600 + heuristics: true + count: 4096 + recipients: null + volume: null + - name: '12k' + <<: *defaults + description: '12k mail/h' + interval: 3600 + heuristics: true + count: 12228 + recipients: null + volume: null + - name: 'trusted' + <<: *defaults + description: 'Trusted email senders' + interval: 3600 + heuristics: true + count: null + recipients: null + volume: null
View file
postfix-rate-policyd-0.0.1.gem/data/lib/postfix/rate/models.rb
Added
@@ -0,0 +1,7 @@ +require "postfix/rate/models/policy" +require "postfix/rate/models/tracking" +require "postfix/rate/models/tracker" + +require "postfix/rate/models/authenticated_identity" +require "postfix/rate/models/client_address" +require "postfix/rate/models/network_address" \ No newline at end of file
View file
postfix-rate-policyd-0.0.1.gem/data/lib/postfix/rate/models/authenticated_identity.rb
Changed
@@ -7,10 +7,6 @@ plugin :association_dependencies, tracker: :destroy - def self.initialize_table - end - - def label "authenticated user '#{identity}'" end
View file
postfix-rate-policyd-0.0.1.gem/data/lib/postfix/rate/models/client_address.rb
Changed
@@ -7,9 +7,6 @@ plugin :association_dependencies, tracker: :destroy - def self.initialize_table - end - def label "network address '#{address}'" end
View file
postfix-rate-policyd-0.0.1.gem/data/lib/postfix/rate/models/network_address.rb
Changed
@@ -1,9 +1,6 @@ module Postfix::Rate::Models class NetworkAddress < Sequel::Model - def self.initialize_table - end - def blacklisted? flags == 'b' end
View file
postfix-rate-policyd-0.0.1.gem/data/lib/postfix/rate/models/policy.rb
Changed
@@ -2,13 +2,11 @@ class Policy < Sequel::Model plugin :validation_helpers - def validate super validates_presence :name, :description end - def count_tracker? count && count > 0 end @@ -20,36 +18,5 @@ def volume_tracker? volume && volume > 0 end - - - def self.initialize_table - if db.table_exists?(table_name) - Policy.find_or_create(name: 'default', - description: 'Default Policy', - interval: 3600, - heuristics: true, - count: 10, - recipients: nil, - volume: nil) - - Policy.find_or_create(name: 'default_for_addresses', - description: 'Default Policy for unauthenticated addresses', - interval: 86400, - heuristics: true, - count: 200, - recipients: nil, - volume: nil) - - Policy.find_or_create(name: 'default_for_identities', - description: 'Default Policy for authenticated identities', - interval: 86400, - heuristics: true, - count: 500, - recipients: nil, - volume: nil) - else - true - end - end end end \ No newline at end of file
View file
postfix-rate-policyd-0.0.1.gem/data/lib/postfix/rate/models/tracker.rb
Changed
@@ -3,9 +3,6 @@ plugin :serialization, :yaml, :heuristics plugin :serialization_modification_detection - def self.initialize_table - end - def before_create self.first_seen = Time.now self.last_update = Time.now
View file
postfix-rate-policyd-0.0.1.gem/data/lib/postfix/rate/policyd/agent.rb
Changed
@@ -25,6 +25,8 @@ @signals_queue = case config.command + when 'setup' + setup_backend! when 'start' start! when 'stop' @@ -41,6 +43,11 @@ self end + def setup_backend! + setup_backend + shutdown! + end + def shutdown! exit end @@ -75,12 +82,22 @@ end end + def setup_backend + opts = config.debug? ? {loggers: logger} : {} + + Sequel::Model.require_valid_table = false + Sequel::Model.db = Sequel.connect(config.database_url, opts) + Postfix::Rate::Models.init(@config) + end + def configure_backend opts = config.debug? ? {loggers: logger} : {} Sequel::Model.require_valid_table = false Sequel::Model.db = Sequel.connect(config.database_url, opts) - Postfix::Rate::Models.init + #Postfix::Rate::Models.init + + require "postfix/rate/models" end def start_server
View file
postfix-rate-policyd-0.0.1.gem/data/lib/postfix/rate/policyd/configuration.rb
Changed
@@ -5,6 +5,7 @@ DEFAULT_CORE_CONFIGURATION = { 'config_file' => '/etc/postfix-rate/policyd.yml', + 'trackers_file' => '/etc/postfix-rate/trackers.yml', 'database_url' => nil, 'daemonize' => true, 'bind_address' => '::', @@ -18,7 +19,7 @@ 'chdir' => Dir.getwd, }.freeze - DEFAULT_COMMANDS = 'start', 'stop', 'restart', 'reload' .freeze + DEFAULT_COMMANDS = 'start', 'setup' .freeze class Configuration @@ -27,6 +28,7 @@ def initialize(argv) config_file = DEFAULT_CORE_CONFIGURATION'config_file' + trackers_file = DEFAULT_CORE_CONFIGURATION'trackers_file' options = {} @data = DEFAULT_CORE_CONFIGURATION.dup @@ -38,6 +40,10 @@ options'config_file' = config_file = file end + opts.on("-t", "--trackers FILE", "Initialize trackers from file") do |file| + options'trackers_file' = trackers_file = file + end + opts.on("-l", "--log-level LEVEL", "Specify the log level (fatal, error, warn, info, debug).") do |level| options'log_level' = level.to_sym end @@ -74,7 +80,12 @@ puts "= reading configuration from '#{config_file}'." raw_config = File.exists?(config_file) ? (YAML.load_file(config_file) || {}) : {} + trackers = File.exists?(trackers_file) ? (YAML.load_file(trackers_file) || {}) : nil + data.merge!(raw_config).merge!(options) + if trackers + data.merge!(trackers: trackers) + end data'command' = argv.shift if argv data'argument' = argv @@ -142,11 +153,19 @@ data'debug' end + def policies + data'policies' || {} + end + + def trackers + data'trackers' || {} + end + def usage u = '-'*80 + "\n" u << "= postfix-rate-policyd: a postfix filter implementing rate policies\n\n" u << "usage:\n" - u << "postfix-rate-policyd params (start|stop|restart|reload)\n" + u << "postfix-rate-policyd params (start|setup)\n" u << '-'*80 + "\n" end
View file
postfix-rate-policyd-0.0.1.gem/data/lib/postfix/rate/policyd/models.rb
Changed
@@ -1,24 +1,17 @@ module Postfix::Rate::Models - def self.init + def self.init(config = nil) create_policies_schema create_trackers_schema create_authenticated_identities_schema create_client_addresses_schema create_network_addresses_schema - require "postfix/rate/models/policy" - require "postfix/rate/models/tracking" - require "postfix/rate/models/tracker" + require "postfix/rate/models" - require "postfix/rate/models/authenticated_identity" - require "postfix/rate/models/client_address" - require "postfix/rate/models/network_address" - - Policy, Tracker, AuthenticatedIdentity, ClientAddress, NetworkAddress.each do | m | - m.initialize_table - end + initialize_policies(config) + initialize_trackers(config) end def self.create_authenticated_identities_schema @@ -123,4 +116,78 @@ true end end + + def self.initialize_policies(config = nil) + Policy.find_or_create( + name: 'default', + description: 'Default Policy', + interval: 3600, + heuristics: true, + count: 10, + recipients: nil, + volume: nil) + + Policy.find_or_create( + name: 'default_for_addresses', + description: 'Default Policy for unauthenticated addresses', + interval: 86400, + heuristics: true, + count: 200, + recipients: nil, + volume: nil) + + Policy.find_or_create( + name: 'default_for_identities', + description: 'Default Policy for authenticated identities', + interval: 86400, + heuristics: true, + count: 500, + recipients: nil, + volume: nil) + + # Bulk IP Senders 128 45 Bulk Anon Senders 128 no + # Bulk Senders 512/IP 45 Bulk Senders 512/IP no + # Bulk Anon Senders 1k 45 Bulk Anon Senders 1k no + # Bulk IP Senders 4k 45 Bulk Anon Senders 4k no + # Bulk Senders 12k/IP 45 IP Addesses authorized to send 12kM/h no + + if config && config.policies.any? + config.policies.each do | pol | + policy = Policy.find(name: pol'name') + policy ||= Policy.new + pol.each do | k, v | + policy.send("#{k}=", v) + end + policy.save + end + end + end + + def self.initialize_trackers(config = nil) + if config && config.trackers + if config.trackers'identities' + config.trackers'identities'.each do | id | + authid = AuthenticatedIdentity.find(identity: id'identity') + authid ||= AuthenticatedIdentity.new + authid.identity = id'identity' + authid.notes = id'notes' + authid.policy = Policy.find(name: id'policy') + raise StandardError.new("Policy #{id'policy'} not found") unless authid.policy + authid.save + end + end + + if config.trackers'addresses' + config.trackers'addresses'.each do | add | + cladd = ClientAddress.find(address: add'address') + cladd ||= ClientAddress.new + cladd.address = add'address' + cladd.notes = add'notes' + cladd.policy = Policy.find(name: add'policy') + raise StandardError.new("Policy #{add'policy'} not found") unless cladd.policy + cladd.save + end + end + end + end end \ No newline at end of file
View file
postfix-rate-policyd-0.0.1.gem/data/lib/wm/syslog/logger.rb
Changed
@@ -66,7 +66,7 @@ def self.make_methods meth level = ::Logger.const_get(meth.upcase) eval <<-EOM, nil, __FILE__, __LINE__ + 1 - def #{meth}(message = nil, &block) + def #{meth}(message = nil, &block) add(#{level}, message, &block) end
View file
postfix-rate-policyd-0.0.1.gem/data/postfix-rate-policyd.service
Added
@@ -0,0 +1,14 @@ +Unit +Description=Starts and stops the intercom mail policyd service + +Service +Type=simple +User=itmpolicyd +Group=itmpolicyd +ExecStartPre=/usr/bin/postfix-rate-policyd -c /etc/postfix-rate/policyd.yml --no-daemonize setup +ExecStart=/usr/bin/postfix-rate-policyd -c /etc/postfix-rate/policyd.yml --no-daemonize start +WorkingDirectory=/var/lib/postfix-rate-policyd +Restart=always + +Install +WantedBy=multi-user.target
View file
postfix-rate-policyd-0.0.1.gem/data/postfix-rate-policyd.spec.in
Added
@@ -0,0 +1,69 @@ +%define mod_name postfix-rate-policyd +%define mod_full_name %{mod_name}-%{version} +Name: rubygem-postfix-rate-policyd +Version: VERSION +Release: 0 +Summary: Intercom mail policyd rubygem +License: Apache-2.0 +Group: Development/Languages/Ruby +URL: https://rubygems.org/gems/postfix-rate-policyd +Source: %{mod_full_name}.gem +Source1: config.yml +Source2: postfix-rate-policyd.service +BuildRequires: %{ruby >= 1.9} +BuildRequires: %{rubygem gem2rpm} +BuildRequires: ruby-macros >= 5 + +%description +Intercom mail policyd rubygem + +%package -n postfix-rate-policyd +Summary: Intercom mail policyd +Group: System/Daemons +Requires: rubygem(%{mod_name}) = %{version} + +%description -n postfix-rate-policyd +Intercom mail policyd daemon + +%prep + +%build + +%install +%gem_install \ + --symlink-binaries \ + --doc-files="README.md" \ + -f +install -d %{buildroot}%{_sysconfdir}/postfix-rate +install -m 644 %{SOURCE1} %{buildroot}%{_sysconfdir}/postfix-rate/policyd.yml +install -D -m 0644 %{SOURCE2} %{buildroot}%{_unitdir}/postfix-rate-policyd.service +install -d -m 0644 %{buildroot}%{_localstatedir}/lib/postfix-rate-policyd + +%gem_packages + +%files -n postfix-rate-policyd +%dir %{_sysconfdir}/postfix-rate +%config(noreplace) %{_sysconfdir}/postfix-rate/policyd.yml +%{_unitdir}/postfix-rate-policyd.service +%attr(0700, itmpolicyd, itmpolicyd) %dir %{_localstatedir}/lib/postfix-rate-policyd + +%pre -n postfix-rate-policyd +%{_bindir}/getent group itmpolicyd >/dev/null || %{_sbindir}/groupadd -r itmpolicyd +%{_bindir}/getent passwd itmpolicyd >/dev/null || %{_sbindir}/useradd -r -d %{_localstatedir}/lib/postfix-rate-policyd -s /bin/false -c "intercom mail policyd" -g itmpolicyd itmpolicyd +%service_add_pre postfix-rate-policyd.service +exit 0 + +%preun -n postfix-rate-policyd +%service_del_preun postfix-rate-policyd.service +exit 0 + +%post -n postfix-rate-policyd +%tmpfiles_create %_tmpfilesdir/mailserver_agent.conf +%service_add_post postfix-rate-policyd.service +exit 0 + +%postun -n postfix-rate-policyd +%service_del_postun postfix-rate-policyd.service +exit 0 + +%changelog
View file
postfix-rate-policyd-0.0.1.gem/metadata.gz
Changed
@@ -8,7 +8,7 @@ autorequire: bindir: bin cert_chain: -date: 2022-11-15 00:00:00.000000000 Z +date: 2022-11-16 00:00:00.000000000 Z dependencies: - !ruby/object:Gem::Dependency name: celluloid-io @@ -177,11 +177,14 @@ - Dockerfile - Gemfile - LICENSE.txt +- Makefile - README.md - Rakefile - bin/postfix-rate-policyd +- config.yml - lib/blank.rb - lib/concern.rb +- lib/postfix/rate/models.rb - lib/postfix/rate/models/authenticated_identity.rb - lib/postfix/rate/models/client_address.rb - lib/postfix/rate/models/network_address.rb @@ -205,6 +208,8 @@ - lib/wm/syslog/remote_logger.rb - lib/wm/syslog/severity.rb - postfix-rate-policyd.gemspec +- postfix-rate-policyd.service +- postfix-rate-policyd.spec.in - spec/data_backend_spec.rb - spec/helpers/database_helpers.rb - spec/heuristics_spec.rb
View file
postfix-rate-policyd.service
Changed
@@ -5,6 +5,7 @@ Type=simple User=itmpolicyd Group=itmpolicyd +ExecStartPre=/usr/bin/postfix-rate-policyd -c /etc/postfix-rate/policyd.yml --no-daemonize setup ExecStart=/usr/bin/postfix-rate-policyd -c /etc/postfix-rate/policyd.yml --no-daemonize start WorkingDirectory=/var/lib/postfix-rate-policyd Restart=always
Locations
Projects
Search
Status Monitor
Help
Open Build Service
OBS Manuals
API Documentation
OBS Portal
Reporting a Bug
Contact
Mailing List
Forums
Chat (IRC)
Twitter
Open Build Service (OBS)
is an
openSUSE project
.