Class: Jekyll::Secinfo::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/jekyll-secinfo/config.rb

Class Method Summary collapse

Class Method Details

.get(site_config, page) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/jekyll-secinfo/config.rb', line 11

def self.get(site_config, page)
	config = { 
		"cve" => {},
		"cwe" => {} 
	}
	if site_config && site_config.key?(CONFIG_NAME) 
		#config["site"] = site_config[CONFIG_NAME]
		if site_config[CONFIG_NAME].key?("cve") && site_config[CONFIG_NAME]["cve"]
			if site_config[CONFIG_NAME]["cve"].key?("style") && site_config[CONFIG_NAME]["cve"]["style"]
				config["cve"]["style"] = site_config[CONFIG_NAME]["cve"]["style"]
			end
			if site_config[CONFIG_NAME]["cve"].key?("url") && site_config[CONFIG_NAME]["cve"]["url"]
				config["cve"]["url"] = site_config[CONFIG_NAME]["cve"]["url"]
			end
		end
		if site_config[CONFIG_NAME].key?("cwe") && site_config[CONFIG_NAME]["cwe"]
			if site_config[CONFIG_NAME]["cwe"].key?("style") && site_config[CONFIG_NAME]["cwe"]["style"]
				config["cwe"]["style"] = site_config[CONFIG_NAME]["cwe"]["style"]
			end
			if site_config[CONFIG_NAME]["cwe"].key?("url") && site_config[CONFIG_NAME]["cwe"]["url"]
				config["cwe"]["url"] = site_config[CONFIG_NAME]["cwe"]["url"]
			end
		end
	end

	if page.key?(CONFIG_NAME) && page[CONFIG_NAME]
   		if page[CONFIG_NAME].key?("cve") && page[CONFIG_NAME]["cve"]
   			if page[CONFIG_NAME]["cve"].key?("style") && page[CONFIG_NAME]["cve"]["style"]
   				config["cve"]["style"]=page[CONFIG_NAME]["cve"]["style"]
   				config["cve"].delete("url")
    		end
   			if page[CONFIG_NAME]["cve"].key?("url") && page[CONFIG_NAME]["cve"]["url"]
   				config["cve"]["url"]=page[CONFIG_NAME]["cve"]["url"]
   				config["cve"].delete("style")
    		end
    	end
   		if page[CONFIG_NAME].key?("cwe") && page[CONFIG_NAME]["cwe"]
   			if page[CONFIG_NAME]["cwe"].key?("style") && page[CONFIG_NAME]["cwe"]["style"]
   				config["cwe"]["style"]=page[CONFIG_NAME]["cwe"]["style"]
   				config["cwe"].delete("url")
    		end
   			if page[CONFIG_NAME]["cwe"].key?("url") && page[CONFIG_NAME]["cwe"]["url"]
   				config["cwe"]["url"]=page[CONFIG_NAME]["cwe"]["url"]
   				config["cwe"].delete("style")
    		end
    	end
	end			

	if not config["cve"]["url"]  
		case config["cve"]["style"]
		when "mitre"
			config["cve"]["url"] = "https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-"
		when "cvedetails"
			config["cve"]["url"] = "https://www.cvedetails.com/cve/CVE-%s/"
		when "nvd"
			config["cve"]["url"] = "https://nvd.nist.gov/vuln/detail/CVE-"
		else
			# Unknown CVE style using 'mitre'-style instead
			config["cve"]["url"] = "https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-"
		end
	end

	if not config["cwe"]["url"]  
		case config["cwe"]["style"]
		when "mitre", "nvd"
			config["cwe"]["url"] = "https://cwe.mitre.org/data/definitions/%s.html"
		when "cvedetails"
			config["cwe"]["url"] = "https://www.cvedetails.com/cwe-details/"
		else
			# Unknown CWE style using 'mitre'-style instead
			config["cwe"]["url"] = "https://cwe.mitre.org/data/definitions/%s.html"
		end
	end


	return config
end