headwinds 0.0.8 → 0.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ce924ab8dad600d8b056ee11104953ac7c0e1be8
4
- data.tar.gz: 97bf882db04d87b0b63302d8751555c5ff786b67
3
+ metadata.gz: fd34054c6454f04dda4b91d674d38a255df06000
4
+ data.tar.gz: ffec4f368e32191ef3d88a3493874885daec2578
5
5
  SHA512:
6
- metadata.gz: 5f115587e029fcab65137137ca1d881b0178ab20dfa02113970c0099266cd7b4f17a5de04b573591965568d12100f5d57c01317d3b6d6106f3887fcabd796483
7
- data.tar.gz: 0b2252eae6490f699336fb1249f2b5f78959425ff4aa9e4d7d9c74aced52c538117fac20041c1f5ee78e6e5704ac53dcff190665a8ecf324c4efeb814515cb1f
6
+ metadata.gz: 199849973c1e36c8aa0be901db5a29e7d613254ec41ad58ed71284787a63d6a0ab07980d23ba23498b114b8613ed1d327cab94377d7e13c6ba2690a7fa19a474
7
+ data.tar.gz: c57bd4ea6af9663aa73340734d14a54b95460749747bed36ae7bebcf75359fbb9fd7b26b752f35e453492084d74dc39e3013116499292f88712cb2b2742f6607
data/lib/headwinds.rb CHANGED
@@ -1,71 +1,19 @@
1
- require "headwinds/version"
1
+ require 'headwinds/version'
2
+ require 'headwinds/client_helper'
3
+ require 'headwinds/rails'
2
4
 
3
- module Rack
4
- class Headwinds
5
- #PRIVATE_KEY = 'vLLLZHc9VuihVqYOH3cA'
6
- #API_KEY = '51282dee16d3125926000053'
7
- INTERVAL = 60*5
8
- REFRESHING_TIME = 24 * 3600
5
+ module Headwinds
6
+ class KaPow
7
+ $PRIVATE_KEY = 'VrIDKlCHheYsi0tYUr9U'
8
+ $API_KEY = '512cd0d516d3124c77000001'
9
+ $INTERVAL = 60*5
10
+ $REFRESHING_TIME = 24 * 3600
9
11
 
10
- class << self
11
- attr_accessor :private_key, :api_key
12
+ # move init to client_helper.rb
12
13
 
13
- def test_mode!(options = {})
14
- value = options[:return]
15
- self.test_mode = value.nil? ? true : options[:return]
16
- end
17
- end
18
-
19
-
20
- def initialize(app, options = {})
21
- @app = app
22
- self.class.private_key = options[:private_key]
23
- self.class.api_key = options[:api_key]
24
- end
25
-
26
- def call(env)
27
- dup._call(env)
28
- end
29
-
30
- def _call(env)
31
- print 'testing it'
32
- end
33
-
34
-
35
- def initialize_kapow(location)
36
- print "Content-Type: text/html\n\n"
37
- print '<script src="http://rabbit.cs.pdx.edu/headwinds/application/js/kapow.js"></script>'
38
- print '<input type="hidden" name="kapowField" id="kapowField" value="" />'
39
- print "<script> kapowInitialize('#{location}')</script>"
40
- end
41
-
42
- def headwinds2_return_initial_cookie(msg, author, email)
43
- private_key = Rack::Headwinds.private_key
44
- @Ks = getKsFromPK(private_key)
45
- ip = request.env['REMOTE_ADDR']
46
- @S = String(10)
47
- ts = Time.now.to_i
48
- @Data = msg+author+email
49
-
50
- @total = @Data+@Ks+@S+ts
51
- @Cookie = hashlib.md5(total).hexdigest()
52
- dct = Array({:'Cookie'=> @Cookie,
53
- :'ts'=> ts,
54
- :'S'=> @S,
55
- :'comment_author'=> author,
56
- :'comment_author_email'=> email,
57
- :'comment_author_ip'=> ip,
58
- :'comment_date'=> ts,
59
- :'comment_author_url'=> 'http://google.com',
60
- :'comment_content'=> msg,
61
- :'Data'=> @Data,
62
- :'api_key'=> private_key
63
- })
64
- return dct
65
- end
66
- def kapow_verify(kapowField)
14
+ def self.kapow_verify(kapowField)
67
15
  require 'json'
68
- require 'digest'
16
+ require 'digest/md5'
69
17
  kapow = JSON.parse(kapowField)
70
18
 
71
19
  @Data = kapow['comment'] + kapow['author'] + kapow['email']
@@ -77,7 +25,7 @@ module Rack
77
25
  @Ks_array = generateKsArray()
78
26
  #use Ks to verify the answer
79
27
  for @Ks in @Ks_array
80
- @total = @Data+@Ks+@S+@ts
28
+ @total = @Data+@Ks+@S+String(@ts)
81
29
  end
82
30
  @Cookie = Digest::MD5.hexdigest(@total)
83
31
  @final = @Ks+@Cookie
@@ -89,24 +37,44 @@ module Rack
89
37
  end
90
38
  end
91
39
 
92
- def generateKsArray()
40
+ def self.headwinds2_return_initial_cookie(msg, author, email)
41
+ @Ks = getKsFromPK($PRIVATE_KEY)
42
+ ip = '173.194.33.38'
43
+ @S = String(10)
44
+ @ts = Time.now.strftime("%m.%d.%y %I:%M:%S")
45
+ @Data = msg+author+email
46
+
47
+ @total = @Data+@Ks+@S+String(@ts)
48
+ @Cookie = Digest::MD5.hexdigest(@total)
49
+ dct = {:Cookie=> @Cookie,
50
+ :ts=> @ts,
51
+ :S=> @S,
52
+ :comment_author=> author,
53
+ :comment_author_email=> email,
54
+ :comment_author_ip=> ip,
55
+ :comment_date=> @ts,
56
+ :comment_author_url=> 'http://google.com',
57
+ :comment_content=> msg,
58
+ :Data=> @Data,
59
+ :api_key=> $API_KEY
60
+ }
61
+ return dct
62
+ end
63
+ def self.generateKsArray()
93
64
  # Generate new Ks from the private key. If generation happens at the beginning of a period, two Ks are created.
94
65
  # @param private_key
95
66
  # @return Ks_array array contains key(s)
96
67
 
97
68
  ts = Time.now.to_i
98
-
99
- private_key = Rack::Headwinds.private_key
100
-
101
- if Integer(Integer(ts) % REFRESHING_TIME) < INTERVAL
102
- @Ks_array = [ getKsFromPK(private_key), getKsFromPK(private_key,True) ]
69
+ if Integer(Integer(ts) % $REFRESHING_TIME) < $INTERVAL
70
+ @Ks_array = [ getKsFromPK($PRIVATE_KEY), getKsFromPK($PRIVATE_KEY,True) ]
103
71
  else
104
- @Ks_array = [ getKsFromPK(private_key) ]
72
+ @Ks_array = [ getKsFromPK($PRIVATE_KEY) ]
105
73
  end
106
74
  return @Ks_array
107
75
  end
108
76
 
109
- def getKsFromPK(private_key, previous = FALSE)
77
+ def self.getKsFromPK(private_key, previous = FALSE)
110
78
  # Generate new Ks from the private key. The generated key is different for each period indicated by REFRESHING_TIME
111
79
  # It can also be used to generated Ks from the previous period by setting the $previous param to true
112
80
  # @param $private_key
@@ -119,7 +87,7 @@ module Rack
119
87
  k = 0
120
88
  end
121
89
  ts = Time.now.to_i
122
- concat = String(Integer(Integer(ts) / REFRESHING_TIME) - k)+private_key
90
+ concat = String(Integer(Integer(ts) / $REFRESHING_TIME) - k)+private_key
123
91
  return Digest::SHA256.hexdigest(concat)
124
92
  end
125
93
  end
@@ -0,0 +1,14 @@
1
+ module Headwinds
2
+ module ClientHelper
3
+ def initialize_kapow(location)
4
+ html = ""
5
+ html << %{<script src="http://rabbit.cs.pdx.edu/headwinds/application/js/kapow.js"></script>}
6
+
7
+ html << %{<input type="hidden" name="kapowField" id="kapowField" value="" />}
8
+
9
+ html << %{<script> kapowInitialize('#{location}')</script>\n}
10
+
11
+ return (html.respond_to?(:html_safe) && html.html_safe) || html
12
+ end # headwinds_tags
13
+ end
14
+ end
@@ -0,0 +1,4 @@
1
+ require 'net/http'
2
+ require 'headwinds'
3
+
4
+ ActionView::Base.send(:include, Headwinds::ClientHelper)
@@ -1,3 +1,3 @@
1
1
  module Headwinds
2
- VERSION = "0.0.8"
2
+ VERSION = "0.0.9"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: headwinds
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tien Le
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-02-28 00:00:00.000000000 Z
11
+ date: 2013-03-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -53,8 +53,9 @@ files:
53
53
  - Rakefile
54
54
  - headwinds.gemspec
55
55
  - lib/headwinds.rb
56
+ - lib/headwinds/client_helper.rb
57
+ - lib/headwinds/rails.rb
56
58
  - lib/headwinds/version.rb
57
- - lib/helpers.rb
58
59
  homepage: https://kapow.cs.pdx.edu
59
60
  licenses:
60
61
  - MIT
data/lib/helpers.rb DELETED
@@ -1,17 +0,0 @@
1
- module Rack
2
- class Headwinds
3
- module Helpers
4
- def headwinds_tags(type= :challenge)
5
- html = case type.to_sym
6
- when :challenge
7
- %{<script type="text/javascript" src="#{path}/challenge?#{params}">
8
- </script>}.gsub(/^ +/, '')
9
- when :noscript
10
- %{<noscript>noScript
11
- </noscript>}.gsub(/^ +/, '')
12
- end
13
-
14
- end
15
- end
16
- end
17
- end