Module: KSConnect::Helpers

Defined in:
lib/ksconnect/helpers.rb

Instance Method Summary collapse

Instance Method Details

#autossl_verification_path_and_key_for(domain_name) ⇒ Object



53
54
55
56
57
58
59
60
# File 'lib/ksconnect/helpers.rb', line 53

def autossl_verification_path_and_key_for(domain_name)
  d = plugins[:autossl].domains[domain_name].try(:private_data)
  if d
    return d['verify_endpoint'], d['verify_content']
  else
    return nil, nil
  end
end

#https_enabled?(domain_name) ⇒ Boolean

Returns:

  • (Boolean)


15
16
17
18
# File 'lib/ksconnect/helpers.rb', line 15

def https_enabled?(domain_name)
  k, c = ssl_key_and_cert_for(domain_name)
  k && c
end

#https_redirect_enabled?(domain_name) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/ksconnect/helpers.rb', line 20

def https_redirect_enabled?(domain_name)
  https_enabled?(domain_name) && plugins[:ssl].domains[domain_name].data['redirect'] == "true"
end

#https_rewriting_enabled?(domain_name) ⇒ Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/ksconnect/helpers.rb', line 24

def https_rewriting_enabled?(domain_name)
  https_enabled?(domain_name) && plugins[:ssl].domains[domain_name].data['rewriteHTTPS'] == "true"
end

#ip_address_for(domain_name) ⇒ Object



6
7
8
9
10
11
12
13
# File 'lib/ksconnect/helpers.rb', line 6

def ip_address_for(domain_name)
  if all_domains[domain_name]
    ip = all_domains[domain_name].ip_address
    Resolv::IPv4::Regex.match(ip) ? ip : "kloudsec.com" # go to something safe if ip is invalid
  else
    "kloudsec.com" # go to something safe if domain is missing
  end
end

#pagespeed_enabled?(domain_name) ⇒ Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/ksconnect/helpers.rb', line 44

def pagespeed_enabled?(domain_name)
  plugins[:mod_cache].domains.has_key?(domain_name)
end

#pending_autossl?(domain_name) ⇒ Boolean

Returns:

  • (Boolean)


48
49
50
51
# File 'lib/ksconnect/helpers.rb', line 48

def pending_autossl?(domain_name)
  p, k = autossl_verification_path_and_key_for(domain_name)
  plugins[:autossl].domains.has_key?(domain_name) && p && k
end

#ssl_key_and_cert_for(domain_name) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/ksconnect/helpers.rb', line 62

def ssl_key_and_cert_for(domain_name)
  ssl = plugins[:ssl].domains[domain_name].try(:private_data)
  autossl = plugins[:autossl].domains[domain_name].try(:private_data)

  if ssl && ssl['key'] && ssl['cert']
    return ssl['key'], ssl['cert']
  elsif autossl && autossl['key'] && autossl['cert']
    return autossl['key'], autossl['cert']
  else
    return nil, nil
  end
end

#waf_enabled?(domain_name) ⇒ Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/ksconnect/helpers.rb', line 28

def waf_enabled?(domain_name)
  plugins[:web_shield].domains.has_key?(domain_name)
end

#waf_learning?(domain_name) ⇒ Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/ksconnect/helpers.rb', line 32

def waf_learning?(domain_name)
  waf_enabled?(domain_name) && plugins[:web_shield].domains[domain_name].data['learning']
end

#waf_location_config(domain_name) ⇒ Object



36
37
38
# File 'lib/ksconnect/helpers.rb', line 36

def waf_location_config(domain_name)
  waf_enabled?(domain_name) ? plugins[:web_shield].domains[domain_name].private_data['location.conf'] : ""
end

#waf_server_config(domain_name) ⇒ Object



40
41
42
# File 'lib/ksconnect/helpers.rb', line 40

def waf_server_config(domain_name)
  waf_enabled?(domain_name) ? plugins[:web_shield].domains[domain_name].private_data['server.conf'] : ""
end