Class: CertificateManager
- Inherits:
-
Object
- Object
- CertificateManager
- Defined in:
- app/models/certificate_manager.rb
Instance Attribute Summary collapse
-
#interpreter ⇒ Object
readonly
Returns the value of attribute interpreter.
Class Method Summary collapse
Instance Method Summary collapse
- #dkim_cert_gen(domain, selector) ⇒ Object
- #https_cert_gen(params) ⇒ Object
-
#initialize ⇒ CertificateManager
constructor
A new instance of CertificateManager.
- #smtpd_cert_gen(params) ⇒ Object
Constructor Details
#initialize ⇒ CertificateManager
Returns a new instance of CertificateManager.
10 11 12 |
# File 'app/models/certificate_manager.rb', line 10 def initialize @i = @interpreter = AutomateIt.new end |
Instance Attribute Details
#interpreter ⇒ Object (readonly)
Returns the value of attribute interpreter.
3 4 5 |
# File 'app/models/certificate_manager.rb', line 3 def interpreter @interpreter end |
Class Method Details
.save_all_and_restart ⇒ Object
5 6 7 8 |
# File 'app/models/certificate_manager.rb', line 5 def self.save_all_and_restart sm = CertificateManager.new sm.send 'smtpd_cert_gen', {} end |
Instance Method Details
#dkim_cert_gen(domain, selector) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'app/models/certificate_manager.rb', line 30 def dkim_cert_gen(domain, selector) @i.shell_manager.sh("opendkim-genkey -r -s #{selector} -d #{domain} -D /etc/ssl/dkim") @i.shell_manager.chown 'opendkim', 'opendkim', "/etc/ssl/dkim/#{selector}.private" @i.chown 'opendkim', 'opendkim', "/etc/ssl/dkim/#{selector}.private" @i.chown 'opendkim', 'rmails', "/etc/ssl/dkim/#{selector}.txt" @i.chmod 0660, "/etc/ssl/dkim/#{selector}.txt" # correct bad dns record edit "/etc/ssl/dkim/#{selector}.txt" do replace ';=rsa;', ";k=rsa;" end key_table = "#{selector}._domainkey.#{domain} #{domain}:#{selector}:/etc/ssl/dkim/#{selector}.private" signing_table = "*@#{domain} #{selector}._domainkey.#{domain}" @i.edit :file => '/etc/opendkim/KeyTable' do append key_table end @i.edit :file => '/etc/opendkim/SigningTable' do append signing_table end end |
#https_cert_gen(params) ⇒ Object
25 26 27 28 |
# File 'app/models/certificate_manager.rb', line 25 def https_cert_gen(params) params[:email] ||= '[email protected]' @i.shell_manager.sh "openssl req -new -newkey rsa:4096 -x509 -days 3650 -nodes -out /etc/ssl/certs/https.pem -keyout /etc/ssl/private/https.pem -subj /C=/ST=/L=/O=/OU=/CN=#{params[:name]||Property.find_by_key('mydomain').value}/emailAddress=#{params[:email]}" end |
#smtpd_cert_gen(params) ⇒ Object
14 15 16 17 18 19 20 21 22 23 |
# File 'app/models/certificate_manager.rb', line 14 def smtpd_cert_gen(params) #pass = SecureRandom.base64(25) #@i.edit :file => pass_file = @i.mktemp do # append pass #end params[:email] ||= '[email protected]' # Property.find_by_key('postmaster').value @i.shell_manager.sh "openssl req -new -newkey rsa:4096 -x509 -days 3650 -nodes -out /etc/ssl/certs/smtpd.pem -keyout /etc/ssl/private/smtpd.pem -subj /C=#{params[:country]}/ST=#{params[:state]}/L=#{params[:locality]}/O=#{params[:org]}/OU=#{params[:org_unit]}/CN=#{params[:name]||Property.find_by_key('myhostname').value}/emailAddress=#{params[:email]}" #@i.shell_manager.rm pass_file #pass end |