]> git.openstreetmap.org Git - chef.git/blob - cookbooks/overpass/templates/default/totp-filter.erb
Remove otrs test role from naga
[chef.git] / cookbooks / overpass / templates / default / totp-filter.erb
1 #!/usr/bin/ruby
2
3 require "cgi"
4 require "rotp"
5
6 totp = ROTP::TOTP.new("<%= @totp_key %>", :interval => 3600)
7
8 STDIN.each_line do |header|
9   cookies = CGI::Cookie.parse(header.chomp)
10
11   if cookie = cookies.fetch("_osm_totp_token", nil)
12     if totp.verify(cookie.value.first, :drift_behind => 3600, :drift_ahead => 3600)
13       STDOUT.syswrite("1\n")
14     else
15       STDOUT.syswrite("0\n")
16     end
17   else
18     STDOUT.syswrite("0\n")
19   end
20 end
21
22 exit 0