summaryrefslogtreecommitdiff
blob: 34ed17fca11ccf64c3ac79f7a1b10a244fec1102 (plain)
1
2
3
4
5
6
7
8
9
10
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
require 'sanitize'
require 'erb'
require 'rss'

COMP_MAP = {
  '>=' => 'ge',
  '>'  => 'gt',
  '='  => 'eq',
  '<=' => 'le',
  '<'  => 'lt',
  'revision <' => 'rlt',
  'revision <=' => 'rle',
  'revision >' => 'rgt',
  'revision >=' => 'rge'
}.freeze

helpers do
  def h(text)
    Rack::Utils.escape_html(text)
  end

  def u(text)
    ERB::Util::url_encode(text)
  end

  def h2(text)
    Sanitize.clean(text, Sanitize::Config::BASIC)
  end

  def code2pre(text)
    text.gsub('<code>', '<pre>').gsub('</code>', '</pre>').gsub(/ +/, ' ').chomp
  end

  # Returns the comparator in the format needed for the XML
  def xml_comp(val)
    COMP_MAP[val]
  end

  def reverse_xml_comp(val)
    COMP_MAP.invert[val]
  end

  def feed(type, items)
    RSS::Maker.make(type) do |maker|
      maker.channel.author      = "Gentoo Security Team"
      maker.channel.about       = "https://security.gentoo.org/glsa"
      maker.channel.link        = "https://security.gentoo.org/glsa"
      maker.channel.description = "This feed contains new Gentoo Linux Security Advisories. Contact security@gentoo.org with questions."
      maker.channel.title       = "Gentoo Linux Security Advisories"
      maker.channel.updated     = Time.now.to_s

      items.each do |input_item|
        maker.items.new_item do |item|
          item.link = BASE_URL + 'glsa/' + input_item.id
          item.title = "GLSA %s: %s" % [input_item.id, input_item.title]
          item.updated = Time.now.to_s
        end
      end
    end.to_s
  end

end