feed_us_grabber 0.1.15 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
=begin
|
2
1
|
= feed_us_grabber
|
3
2
|
|
4
3
|
== ENVIRONEMNT
|
@@ -67,7 +66,7 @@ To clear cache goto following url
|
|
67
66
|
* Clear entire cache
|
68
67
|
http://rails_app/FeedUsGrabber?cachecommand=clearall
|
69
68
|
|
70
|
-
:Note that if you receive a failure message that your IP is not authorized to clear the cache, add your IP to the ClientWhiteList in your controller
|
69
|
+
:Note that if you receive a failure message that your IP is not authorized to clear the cache, add your IP to the ClientWhiteList in your controller
|
71
70
|
def index
|
72
71
|
@grabber = feedUsGrabber(:FeedUsURL => 'http://render.feed.us/Feed.aspx?g=00767d50-bde8-e111-9875-4040419a7f04', :ClientWhiteList => '127.0.0.1')
|
73
72
|
end
|
@@ -90,6 +89,6 @@ end
|
|
90
89
|
|
91
90
|
== Copyright
|
92
91
|
|
93
|
-
Copyright (c)
|
92
|
+
Copyright (c) 2013 Feed.Us See LICENSE.txt for
|
94
93
|
further details.
|
95
|
-
|
94
|
+
|
@@ -10,71 +10,73 @@ class FeedUsGrabberController < ActionController::Base
|
|
10
10
|
# ! IMPORTANT: TO DISABLE THIS CHECK SET BOTH ARRAYS TO nil
|
11
11
|
@mClientWhiteList = [ "75.126.108.226", "75.126.107.10", "127.0.0.1", "50.56.95.92" ]
|
12
12
|
@mClientHostNameWhileList = [ "app.feed.us", "request.feed.us", "feed.us", "classic.syndication.feed.us", "render.feed.us", "dev.feed.us", "stage.feed.us", "localhost"]
|
13
|
-
@mClientIp
|
13
|
+
@mClientIp = ""
|
14
14
|
end
|
15
15
|
|
16
|
-
|
17
|
-
|
16
|
+
@mArgs = {}
|
17
|
+
|
18
18
|
# URL that will be checked for connectivity before clearing the cache (phone home)
|
19
|
-
|
19
|
+
@mArgs[:FeedUsURL] = 'http://render.feed.us/grabberdefault.htm?phonehome=true'
|
20
|
+
@mArgs[:DebugOutput] = ""
|
21
|
+
@mArgs[:Debug] = false
|
22
|
+
@mDebugLogger = FeedUsGrabber.new
|
20
23
|
|
21
24
|
unless params[:cachecommand].nil?
|
22
|
-
|
25
|
+
@mArgs[:CacheCommand] = params[:cachecommand]
|
23
26
|
end
|
24
27
|
unless params[:group].nil?
|
25
|
-
|
28
|
+
@mArgs[:FeedUsCacheGroup] = params[:group]
|
26
29
|
end
|
27
|
-
|
28
|
-
args[:Debug] = false
|
30
|
+
|
29
31
|
unless params[:debug].nil?
|
30
|
-
|
32
|
+
@mArgs[:Debug] = params[:debug] == "1"
|
31
33
|
end
|
32
34
|
|
33
|
-
if
|
34
|
-
|
35
|
+
if @mArgs[:FeedUsCacheGroup] && @mArgs[:CacheCommand].nil?
|
36
|
+
@mArgs[:CacheCommand] = 'clear'
|
35
37
|
end
|
36
38
|
|
37
|
-
if
|
38
|
-
|
39
|
+
if @mArgs[:CacheCommand].nil?
|
40
|
+
@mArgs[:CacheCommand] = 'clearall'
|
39
41
|
end
|
40
42
|
|
41
|
-
if
|
43
|
+
if @mArgs[:CacheCommand] == 'clear' && @mArgs[:FeedUsCacheGroup]
|
42
44
|
fetch = true
|
43
45
|
else
|
44
46
|
fetch = false
|
45
47
|
end
|
46
|
-
if
|
48
|
+
if @mArgs[:CacheCommand] == 'clearall' || @mArgs[:CacheCommand] == CACHE_COMMAND_FORCE
|
47
49
|
fetch = true
|
48
50
|
end
|
49
51
|
|
50
52
|
# Client ip check
|
51
|
-
|
53
|
+
isPermitted = IsPermittedToProceed()
|
52
54
|
|
53
55
|
renderText = ""
|
54
|
-
if
|
55
|
-
renderText
|
56
|
-
|
57
|
-
|
56
|
+
if @mArgs[:Debug] == true && isPermitted
|
57
|
+
renderText << @mArgs[:DebugOutput]
|
58
|
+
end
|
59
|
+
|
60
|
+
if isPermitted
|
58
61
|
if fetch == true
|
59
|
-
feedUsGrabber(
|
60
|
-
renderText
|
62
|
+
grabber = feedUsGrabber(@mArgs)
|
63
|
+
renderText << grabber.getDebugOutput
|
64
|
+
renderText << "<img src=\"http://feed.us/images/feedus_logo_people.png\"><br />
|
61
65
|
<p style=\"font-family:arial;\">Congratulations! You have successfully refreshed your content.</p>
|
62
66
|
<p style=\"font-family:arial;\"><a href=\"/\">Home</a></p> "
|
63
67
|
else
|
64
|
-
renderText
|
68
|
+
renderText << "<img src=\"http://feed.us/images/feedus_logo_people.png\"><br />
|
65
69
|
<p style=\"font-family:arial;\"> Please specify cachecommand=clear&group=GROUPNAME or cachecommand=clearall or cachecommand=force_clear_all in the URL</p> "
|
66
|
-
end
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
renderText << args[:DebugOutput]
|
71
|
-
renderText << @mClientWhiteList.to_s
|
70
|
+
end
|
71
|
+
else
|
72
|
+
renderText << "<img src=\"http://feed.us/images/feedus_logo_people.png\"><br />
|
73
|
+
<p style=\"font-family:arial;\"> IP " + @mClientIp + " is not authorized. Modify the feed_us_grabber_controller @mClientWhiteList array if this IP should have access. "
|
72
74
|
end
|
73
|
-
|
75
|
+
|
74
76
|
render :text=> renderText
|
75
77
|
end
|
76
78
|
|
77
|
-
def IsPermittedToProceed
|
79
|
+
def IsPermittedToProceed
|
78
80
|
isPermitted = false
|
79
81
|
@mClientIp = request.remote_addr
|
80
82
|
|
@@ -82,7 +84,7 @@ class FeedUsGrabberController < ActionController::Base
|
|
82
84
|
@mClientIp = request.env["HTTP_X_FORWARDED_FOR"]
|
83
85
|
end
|
84
86
|
|
85
|
-
isPermitted = IsClientIpInWhiteList(
|
87
|
+
isPermitted = IsClientIpInWhiteList()
|
86
88
|
|
87
89
|
if isPermitted == false
|
88
90
|
if @mClientHostNameWhileList.nil? == false
|
@@ -90,7 +92,7 @@ class FeedUsGrabberController < ActionController::Base
|
|
90
92
|
begin
|
91
93
|
s = Socket.getaddrinfo(@mClientIp,nil)
|
92
94
|
host = s[0][2]
|
93
|
-
|
95
|
+
AddToDebugOutput("Host is #{host}")
|
94
96
|
if @mClientHostNameWhileList.include?(host) == true
|
95
97
|
isPermitted = true
|
96
98
|
end
|
@@ -106,25 +108,17 @@ class FeedUsGrabberController < ActionController::Base
|
|
106
108
|
if @mClientIp == "" || @mClientIp.nil?
|
107
109
|
@mClientIp = request.env["X-Forwarded-For"]
|
108
110
|
end
|
109
|
-
isPermitted = IsClientIpInWhiteList(
|
110
|
-
|
111
|
-
puts "Trace: using fwd header isPermitted = #{isPermitted}"
|
112
|
-
end
|
113
|
-
|
114
|
-
# Set the Debug flag - do not want to output Debug info if not permitted
|
115
|
-
if isPermitted == false
|
116
|
-
args[:Debug] = false
|
111
|
+
isPermitted = IsClientIpInWhiteList()
|
112
|
+
AddToDebugOutput("Trying to use X-Forwarded-For #{@mClientIp}")
|
117
113
|
end
|
118
|
-
|
119
|
-
|
120
|
-
puts "Trace: returning is permitted true"
|
121
|
-
args[:DebugOutput] << "Debug: mClientIp = #{@mClientIp}"
|
114
|
+
|
115
|
+
AddToDebugOutput("Results of is permitted check = #{isPermitted.to_s} for IP #{@mClientIp}")
|
122
116
|
|
123
|
-
|
117
|
+
isPermitted
|
124
118
|
end
|
125
119
|
|
126
|
-
def IsClientIpInWhiteList
|
127
|
-
included = false
|
120
|
+
def IsClientIpInWhiteList
|
121
|
+
included = false
|
128
122
|
if @mClientWhiteList.nil? && @mClientHostNameWhileList.nil?
|
129
123
|
included = true
|
130
124
|
else
|
@@ -134,10 +128,16 @@ class FeedUsGrabberController < ActionController::Base
|
|
134
128
|
@mClientWhiteList.push(configuredClientWhiteList)
|
135
129
|
end
|
136
130
|
|
131
|
+
AddToDebugOutput("Checking if IP #{@mClientIp} is in ClientWhiteList #{@mClientWhiteList.to_s}")
|
132
|
+
|
137
133
|
if @mClientWhiteList.nil? == false && @mClientWhiteList.include?(@mClientIp) == true
|
138
134
|
included = true
|
139
135
|
end
|
140
136
|
end
|
141
137
|
return included
|
142
138
|
end
|
139
|
+
|
140
|
+
def AddToDebugOutput(info)
|
141
|
+
@mDebugLogger.addToDebugOutput(@mArgs[:DebugOutput], info)
|
142
|
+
end
|
143
143
|
end
|
@@ -18,6 +18,7 @@ class FeedUsGrabber
|
|
18
18
|
@mstrCacheGroup = ""
|
19
19
|
@mstrStateFile = File.join(Rails.root.to_s,'tmp','FeedUsGrabberState')
|
20
20
|
@mstrClientWhiteList = ""
|
21
|
+
@mstrDebugOutput = ""
|
21
22
|
end
|
22
23
|
|
23
24
|
def setCacheGroup(param)
|
@@ -91,6 +92,14 @@ class FeedUsGrabber
|
|
91
92
|
@mstrClientWhiteList
|
92
93
|
end
|
93
94
|
|
95
|
+
def setDebugOutput(param)
|
96
|
+
@mstrDebugOutput = param
|
97
|
+
end
|
98
|
+
|
99
|
+
def getDebugOutput
|
100
|
+
@mstrDebugOutput
|
101
|
+
end
|
102
|
+
|
94
103
|
def getDynURL
|
95
104
|
@mstrDynURL
|
96
105
|
end
|
@@ -122,12 +131,12 @@ class FeedUsGrabber
|
|
122
131
|
end
|
123
132
|
|
124
133
|
def autoCacheToFile
|
125
|
-
|
134
|
+
appendDebugOutput("Start autoCacheToFile. bIsPostBack = #{@bIsPostBack}")
|
126
135
|
if @bIsPostBack
|
127
136
|
return
|
128
137
|
end
|
129
138
|
|
130
|
-
|
139
|
+
appendDebugOutput("Cache command received = #{@mstrCacheCommand}")
|
131
140
|
if @mstrCacheCommand.nil? || @mstrCacheCommand == ''
|
132
141
|
if (!self.cachedFileExists) or self.cacheFileIsExpired
|
133
142
|
self.createCacheFile
|
@@ -295,8 +304,8 @@ class FeedUsGrabber
|
|
295
304
|
end
|
296
305
|
|
297
306
|
def clearAllCachedFiles
|
298
|
-
# For testing heroku logging
|
299
|
-
|
307
|
+
# For testing heroku logging
|
308
|
+
appendDebugOutput("Clearing all caches at path = #{@mstrCacheFolder}")
|
300
309
|
logfile = File.open(File.join(Rails.root.to_s,'log','FeedUsGrabber.log'),'a');
|
301
310
|
grabber_logger = FeedUsGrabberLogger.new(logfile)
|
302
311
|
grabber_logger.info("Clearing all caches at path #{@mstrCacheFolder}")
|
@@ -308,7 +317,7 @@ class FeedUsGrabber
|
|
308
317
|
canConnect = canConnectToFeedUs()
|
309
318
|
|
310
319
|
if canConnect == true
|
311
|
-
|
320
|
+
appendDebugOutput("Clear cache folder can connect")
|
312
321
|
FileUtils.rm_r Dir.glob("#{folder}/*")
|
313
322
|
else
|
314
323
|
logError("Unable to connect to Feed.Us. Cache will not be cleared. URL that was checked: #{@mstrDynURL}")
|
@@ -343,4 +352,14 @@ class FeedUsGrabber
|
|
343
352
|
logfile.close
|
344
353
|
end
|
345
354
|
|
355
|
+
def addToDebugOutput(debugOutput, info)
|
356
|
+
debugOutput << info + "<br />"
|
357
|
+
puts " Debug Trace -> " + info
|
358
|
+
end
|
359
|
+
|
360
|
+
private
|
361
|
+
|
362
|
+
def appendDebugOutput(info)
|
363
|
+
self.addToDebugOutput(@mstrDebugOutput, info)
|
364
|
+
end
|
346
365
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: feed_us_grabber
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -124,7 +124,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
124
124
|
version: '0'
|
125
125
|
segments:
|
126
126
|
- 0
|
127
|
-
hash:
|
127
|
+
hash: 39973683
|
128
128
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
129
129
|
none: false
|
130
130
|
requirements:
|