Class: Letsencrypt::Cli::App

Inherits:
Thor
  • Object
show all
Defined in:
lib/letsencrypt/cli/app.rb

Instance Method Summary collapse

Instance Method Details

#__print_versionObject



97
98
99
# File 'lib/letsencrypt/cli/app.rb', line 97

def __print_version
  puts Letsencrypt::Cli::VERSION
end

#authorize(*domains) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
# File 'lib/letsencrypt/cli/app.rb', line 39

def authorize(*domains)
  rc = 0
  domains.each do |domain|
    if !wrapper.authorize(domain)
      rc = 1
    end
  end
  if rc != 0
    exit rc
  end
end

#authorize_allObject



31
32
33
34
35
# File 'lib/letsencrypt/cli/app.rb', line 31

def authorize_all
  lines = Dir[ File.join(@options[:webserver_dir], "*")].map{|file| File.read(file).lines.grep(/^\s*server_name/) }.flatten
  domains = lines.flatten.map{|i| i.strip.split(/[; ]/).drop(1) }.flatten.reject{|i| i.length < 3 }.uniq
  authorize(*domains)
end

#cert(*domains) ⇒ Object



58
59
60
61
62
63
64
# File 'lib/letsencrypt/cli/app.rb', line 58

def cert(*domains)
  if domains.length == 0
    wrapper.log "no domains given", :fatal
    exit 1
  end
  wrapper.cert(domains)
end

#check(path) ⇒ Object



68
69
70
71
72
# File 'lib/letsencrypt/cli/app.rb', line 68

def check(path)
  if !wrapper.check_certificate(path)
    exit 1
  end
end

#manage(*domains) ⇒ Object



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/letsencrypt/cli/app.rb', line 79

def manage(*domains)
  key_dir = File.join(@options[:key_directory], domains.first)
  FileUtils.mkdir_p(key_dir)
  @options = @options.merge(
    :private_key_path  => File.join(key_dir, 'key.pem'),
    :fullchain_path    => File.join(key_dir, 'fullchain.pem'),
    :certificate_path  => File.join(key_dir, 'cert.pem'),
    :chain_path        => File.join(key_dir, 'chain.pem'),
  )
  if wrapper.check_certificate(@options[:certificate_path])
    exit 1
  end
  authorize(*domains)
  cert(*domains)
end

#register(email) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/letsencrypt/cli/app.rb', line 14

def register(email)
  if email.nil? || email == ""
    wrapper.log "no E-Mail specified!", :fatal
    exit 1
  end
  if !email[/.*@.*/]
    wrapper.log "not an email", :fatal
    exit 1
  end
  registration = wrapper.client.register(contact: "mailto:" + email)
  registration.agree_terms
  wrapper.log "Account created, Terms accepted"
end