Bug #32753 » sendmail-32753-b.patch
app/models/setting/email.rb | ||
---|---|---|
require 'shellwords'
|
||
class Setting::Email < Setting
|
||
NON_EMAIL_YAML_SETTINGS = %w(send_welcome_email email_reply_address email_subject_prefix)
|
||
SENDMAIL_LOCATIONS = %w(/usr/sbin/sendmail /usr/bin/sendmail /usr/local/sbin/sendmail /usr/local/bin/sendmail)
|
||
def self.sendmail_locations_hash
|
||
SENDMAIL_LOCATIONS.zip(SENDMAIL_LOCATIONS).to_h
|
||
end
|
||
def self.default_settings
|
||
domain = SETTINGS[:domain]
|
||
... | ... | |
set('smtp_password', N_("Password to use to authenticate, if required"), '', N_('SMTP password'), nil, {:encrypted => true}),
|
||
set('smtp_authentication', N_("Specify authentication type, if required"), '', N_('SMTP authentication'), nil, { :collection => proc { {:plain => "plain", :login => "login", :cram_md5 => "cram_md5", '' => _("none")} }}),
|
||
set('sendmail_arguments', N_("Specify additional options to sendmail"), '-i', N_('Sendmail arguments')),
|
||
set('sendmail_location', N_("The location of the sendmail executable"), "/usr/sbin/sendmail", N_('Sendmail location')),
|
||
set('sendmail_location', N_("The location of the sendmail executable"), "/usr/sbin/sendmail", N_('Sendmail location'), nil, { :collection => proc { sendmail_locations_hash } }),
|
||
]
|
||
end
|
||
validates :value, :length => {:maximum => 255}, :if => proc { |s| s.name == "email_subject_prefix" }
|
||
def validate_sendmail_location(record)
|
||
if record.value.present? && !SENDMAIL_LOCATIONS.include?(record.value)
|
||
record.errors[:base] << _("Not a valid sendmail location")
|
||
end
|
||
end
|
||
def self.delivery_settings
|
||
options = {}
|
||
all.find_each do |setting|
|
||
extracted = {:smtp => extract_prefix(setting.name, 'smtp'), :sendmail => extract_prefix(setting.name, 'sendmail')}
|
||
["smtp", "sendmail"].each do |method|
|
||
if Setting[:delivery_method].to_s == method && setting.name.start_with?(method) && setting.value.to_s.present?
|
||
options[extracted[method.to_sym]] = setting.value
|
||
if setting.name == "sendmail_arguments"
|
||
options[extracted[method.to_sym]] = Shellwords.escape(setting.value)
|
||
else
|
||
options[extracted[method.to_sym]] = setting.value
|
||
end
|
||
end
|
||
end
|
||
end
|
db/migrate/20210610131920_restrict_sendmail_location.rb | ||
---|---|---|
class FakeSetting < ApplicationRecord
|
||
self.table_name = 'settings'
|
||
def default=(v)
|
||
write_attribute :default, v.to_yaml
|
||
end
|
||
def value=(v)
|
||
v = v.to_yaml unless v.nil?
|
||
write_attribute :value, v
|
||
end
|
||
def value
|
||
v = read_attribute(:value)
|
||
YAML.load(v) unless v.nil?
|
||
end
|
||
end
|
||
class RestrictSendmailLocation < ActiveRecord::Migration[6.0]
|
||
def up
|
||
Setting.without_auditing do
|
||
existing = FakeSetting.find_by_name("sendmail_location")
|
||
unless Setting::Email::SENDMAIL_LOCATIONS.include?(existing.value)
|
||
say "Sendmail location '#{existing.value}' not allowed, resetting to default"
|
||
existing.value = nil
|
||
existing.save!
|
||
end
|
||
end
|
||
end
|
||
end
|
- « Previous
- 1
- 2
- Next »