Class: Wordstress::Site
- Inherits:
-
Object
- Object
- Wordstress::Site
- Defined in:
- lib/wordstress/site.rb
Instance Attribute Summary collapse
-
#version ⇒ Object
readonly
Returns the value of attribute version.
-
#wp_vuln_json ⇒ Object
readonly
Returns the value of attribute wp_vuln_json.
Instance Method Summary collapse
- #detect_version ⇒ Object
- #get(page) ⇒ Object
- #get_wp_vulnerabilities ⇒ Object
-
#initialize(name = "") ⇒ Site
constructor
A new instance of Site.
- #is_valid? ⇒ Boolean
- #version_pad(version) ⇒ Object
Constructor Details
#initialize(name = "") ⇒ Site
Returns a new instance of Site.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/wordstress/site.rb', line 7 def initialize(name="") begin @uri = URI(name) @raw_name = name @valid = true rescue @valid = false end @robots_txt = get(@raw_name + "/robots.txt") @readme_html = get(@raw_name + "/readme.html") @homepage = get(@raw_name) @version = detect_version @wp_vuln_json = get_wp_vulnerabilities unless @version[:version] == "0.0.0" @wp_vuln_json = Hash.new.to_json if @version[:version] == "0.0.0" end |
Instance Attribute Details
#version ⇒ Object (readonly)
Returns the value of attribute version.
6 7 8 |
# File 'lib/wordstress/site.rb', line 6 def version @version end |
#wp_vuln_json ⇒ Object (readonly)
Returns the value of attribute wp_vuln_json.
6 7 8 |
# File 'lib/wordstress/site.rb', line 6 def wp_vuln_json @wp_vuln_json end |
Instance Method Details
#detect_version ⇒ Object
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 |
# File 'lib/wordstress/site.rb', line 36 def detect_version # # 1. trying to detect wordpress version from homepage body meta generator # tag = "" doc = Nokogiri::HTML(@homepage.body) doc.xpath("//meta[@name='generator']/@content").each do |attr| = attr.value.split(' ')[1] end # # 2. trying to detect wordpress version from readme.html in the root # directory v_readme = "" doc = Nokogiri::HTML(@readme_html.body) v_readme = doc.at_css('h1').children.last.text.chop.lstrip.split(' ')[1] v_rss = "" rss_doc = Nokogiri::HTML(@homepage.body) rss = Nokogiri::HTML(get(rss_doc.css('link[type="application/rss+xml"]').first.attr('href')).body) v_rss= rss.css('generator').text.split('=')[1] return {:version => , :accuracy => 1.0} if == v_readme && == v_rss return {:version => , :accuracy => 0.8} if == v_readme || == v_rss # we failed detecting wordpress version return {:version => "0.0.0", :accuracy => 0} end |
#get(page) ⇒ Object
69 70 71 72 |
# File 'lib/wordstress/site.rb', line 69 def get(page) return get_http(page) if @uri.scheme == "http" return get_https(page) if @uri.scheme == "https" end |
#get_wp_vulnerabilities ⇒ Object
25 26 27 |
# File 'lib/wordstress/site.rb', line 25 def get_wp_vulnerabilities get_https("https://wpvulndb.com/api/v1/wordpresses/#{version_pad(@version[:version])}").body end |
#is_valid? ⇒ Boolean
74 75 76 |
# File 'lib/wordstress/site.rb', line 74 def is_valid? return @valid end |
#version_pad(version) ⇒ Object
29 30 31 32 33 34 |
# File 'lib/wordstress/site.rb', line 29 def version_pad(version) # 3.2.1 => 321 # 4.0 => 400 return version.gsub('.', '') if version.split('.').count == 3 return version.gsub('.', '')+'0' if version.split('.').count == 2 end |