Skip to content

Commit

Permalink
Merge branch 'bzr/golem' of /Users/distler/Sites/code/instiki
Browse files Browse the repository at this point in the history
  • Loading branch information
distler committed Feb 16, 2013
2 parents 17451c7 + 1d0fef9 commit cb60cb2
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 17 deletions.
6 changes: 6 additions & 0 deletions app/controllers/application_controller.rb
Expand Up @@ -23,6 +23,12 @@ def self.wiki


protected protected


def remote_ip
ip = request.remote_ip
logger.info(ip)
ip.dup.gsub!(Regexp.union(Resolv::IPv4::Regex, Resolv::IPv6::Regex), '\0') || 'bogus address'
end

def xhtml_enabled? def xhtml_enabled?
in_a_web? and [:markdownMML, :markdownPNG, :markdown].include?(@web.markup) in_a_web? and [:markdownMML, :markdownPNG, :markdown].include?(@web.markup)
end end
Expand Down
6 changes: 0 additions & 6 deletions app/controllers/wiki_controller.rb
Expand Up @@ -529,12 +529,6 @@ def parse_category
end end
end end


def remote_ip
ip = request.remote_ip
logger.info(ip)
ip.dup.gsub!(Regexp.union(Resolv::IPv4::Regex, Resolv::IPv6::Regex), '\0') || 'bogus address'
end

def render_atom(hide_description = false, limit = 15) def render_atom(hide_description = false, limit = 15)
@pages_by_revision = @web.select.by_revision.first(limit) @pages_by_revision = @web.select.by_revision.first(limit)
@hide_description = hide_description @hide_description = hide_description
Expand Down
4 changes: 2 additions & 2 deletions test/functional/wiki_controller_test.rb
Expand Up @@ -1352,7 +1352,7 @@ def test_tex


assert_equal @tex_header1 + @tex_header2 + %q!\section*{HomePage} assert_equal @tex_header1 + @tex_header2 + %q!\section*{HomePage}
HisWay would be MyWay $\sin(x) \includegraphics[width=3em]{foo}$ in kinda ThatWay in HisWay though MyWay $\backslash$OverThere --{} see SmartEngine in that SmartEngineGUI HisWay would be MyWay $\sin(x) \includegraphics[width=3em]{foo}$ in kinda ThatWay in HisWay though MyWay $\backslash$OverThere -- see SmartEngine in that SmartEngineGUI
Expand Down Expand Up @@ -1407,7 +1407,7 @@ def test_tex_list
\section*{HomePage} \section*{HomePage}
HisWay would be MyWay $\sin(x) \includegraphics[width=3em]{foo}$ in kinda ThatWay in HisWay though MyWay $\backslash$OverThere --{} see SmartEngine in that SmartEngineGUI HisWay would be MyWay $\sin(x) \includegraphics[width=3em]{foo}$ in kinda ThatWay in HisWay though MyWay $\backslash$OverThere -- see SmartEngine in that SmartEngineGUI
Expand Down
20 changes: 11 additions & 9 deletions vendor/plugins/dnsbl_check/lib/dnsbl_check.rb
Expand Up @@ -30,22 +30,23 @@ module DNSBL_Check
private private
# Filter to check if the client is listed. This will be run before all requests. # Filter to check if the client is listed. This will be run before all requests.
def dnsbl_check def dnsbl_check
ip = self.remote_ip
return true if respond_to?(:logged_in?) && logged_in? return true if respond_to?(:logged_in?) && logged_in?
return true if $dnsbl_passed.include? request.remote_addr return true if $dnsbl_passed.include? ip


passed = true passed = true
ban_help = '' ban_help = ''
threads = [] threads = []
request.remote_addr =~ /(\d+).(\d+).(\d+).(\d+)/ ip =~ /(\d+).(\d+).(\d+).(\d+)/


# Check the remote address against each dnsbl in a separate thread # Check the remote address against each dnsbl in a separate thread
DNSBLS.each_key do |dnsbl| DNSBLS.each_key do |dnsbl|
threads << Thread.new("#$4.#$3.#$2.#$1.#{dnsbl}") do |host| threads << Thread.new("#$4.#$3.#$2.#$1.#{dnsbl}") do |host|
logger.warn("Checking DNSBL #{host}") logger.warn("Checking DNSBL #{host}")
addr = Resolv.getaddress("#{host}") rescue '' addr = Resolv.getaddress("#{host}") rescue ''
if addr[0,7]=="127.0.0" if addr[0,7]=="127.0.0"
logger.info("#{request.remote_addr} found using DNSBL #{host}") logger.info("#{ip} found using DNSBL #{host}")
ban_help << "\n<p>See <a href='#{DNSBLS[dnsbl]}#{request.remote_addr}'>here</a> for more information.</p>" ban_help << "\n<p>See <a href='#{DNSBLS[dnsbl]}#{ip}'>here</a> for more information.</p>"
passed = false passed = false
end end
end end
Expand All @@ -54,12 +55,13 @@ def dnsbl_check


# Add client ip to global passed cache if no dnsbls objected. else deny service. # Add client ip to global passed cache if no dnsbls objected. else deny service.
if passed if passed
# $dnsbl_passed = $dnsbl_passed[0,99].unshift request.remote_addr # $dnsbl_passed = $dnsbl_passed[0,99].unshift ip
$dnsbl_passed.push request.remote_addr $dnsbl_passed.push ip
logger.warn("#{request.remote_addr} added to DNSBL passed cache") logger.warn("#{ip} added to DNSBL passed cache")
else else
render( :text => "<p>Access denied. Your IP address, #{request.remote_addr}, was found on one or more DNSBL" + render( :text =>
" blocking list(s).</p>#{ban_help}", :status => 403, :layout => 'error', :locals => {:raw => true}) "<p>Access denied. Your IP address, #{ip}, was found on one or more DNSBL blocking list(s).</p>#{ban_help}".html_safe,
:status => 403, :layout => 'error', :locals => {:raw => true})
return false return false
end end
end end
Expand Down

0 comments on commit cb60cb2

Please sign in to comment.