Skip to content
This repository has been archived by the owner on Feb 28, 2018. It is now read-only.

Commit

Permalink
Refactored if/then constructs to ternary operators.
Browse files Browse the repository at this point in the history
  • Loading branch information
evilsocket committed Feb 26, 2016
1 parent bbb63f4 commit c08ae99
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 13 deletions.
4 changes: 2 additions & 2 deletions lib/bettercap/discovery/thread.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,13 @@ def print_differences( prev )
if diff[:new].empty?
snew = ""
else
snew = "Acquired #{diff[:new].size} new target#{if diff[:new].size > 1 then "s" else "" end}"
snew = "Acquired #{diff[:new].size} new target#{diff[:new].size > 1 ? "s" : ""}"
end

if diff[:lost].empty?
slost = ""
else
slost = "#{if snew == "" then 'L' else ', l' end}ost #{diff[:lost].size} target#{if diff[:lost].size > 1 then "s" else "" end}"
slost = "#{snew.empty?? 'L' : ', l'}ost #{diff[:lost].size} target#{diff[:lost].size > 1 ? "s" : ""}"
end

Logger.info "#{snew}#{slost} :"
Expand Down
14 changes: 7 additions & 7 deletions lib/bettercap/network/target.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,13 @@ def mac=(value)

# Return a verbose string representation of this object.
def to_s(padding=true)
if padding
s = sprintf( '%-15s : %-17s', if @ip.nil? then '???' else @ip end, @mac )
else
s = sprintf( '%s : %s', if @ip.nil? then '???' else @ip end, @mac )
end
address = @ip.nil?? '???' : @ip
fmt = padding ? '%-15s : %-17s' : '%s : %s'
vendor = @vendor.nil?? " ( ??? )" : " ( #{@vendor} )"

s = sprintf( fmt, address, @mac )
s += " / #{@hostname}" unless @hostname.nil?
s += if @vendor.nil? then " ( ??? )" else " ( #{@vendor} )" end
s += vendor
s
end

Expand Down Expand Up @@ -111,7 +111,7 @@ def equals?(ip, mac)
end

def self.normalized_mac(v)
v.split(':').map { |e| if e.size == 2 then e.upcase else "0#{e.upcase}" end }.join(':')
v.split(':').map { |e| e.size == 2 ? e.upcase : "0#{e.upcase}" }.join(':')
end

private
Expand Down
2 changes: 1 addition & 1 deletion lib/bettercap/proxy/modules/injectcss.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def initialize
def on_request( request, response )
# is it a html page?
if response.content_type =~ /^text\/html.*/
BetterCap::Logger.info "[#{'INJECTCSS'.green}] Injecting CSS #{if @@cssdata.nil? then "URL" else "file" end} into #{request.to_url}"
BetterCap::Logger.info "[#{'INJECTCSS'.green}] Injecting CSS #{@@cssdata.nil?? "URL" : "file"} into #{request.to_url}"
# inject URL
if @@cssdata.nil?
response.body.sub!( '</head>', " <link rel=\"stylesheet\" href=\"#{@cssurl}\"></script></head>" )
Expand Down
2 changes: 1 addition & 1 deletion lib/bettercap/proxy/modules/injectjs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def initialize
def on_request( request, response )
# is it a html page?
if response.content_type =~ /^text\/html.*/
BetterCap::Logger.info "[#{'INJECTJS'.green}] Injecting javascript #{if @@jsdata.nil? then "URL" else "file" end} into #{request.to_url}"
BetterCap::Logger.info "[#{'INJECTJS'.green}] Injecting javascript #{@@jsdata.nil?? "URL" : "file"} into #{request.to_url}"
# inject URL
if @@jsdata.nil?
response.body.sub!( '</head>', "<script src=\"#{@@jsurl}\" type=\"text/javascript\"></script></head>" )
Expand Down
2 changes: 1 addition & 1 deletion lib/bettercap/proxy/sslstrip/strip.rb
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ def process_body!(request, response)
rescue; end

unless links.empty?
Logger.info "[#{'SSLSTRIP'.green} #{request.client}] Stripping #{links.size} HTTPS link#{if links.size > 1 then 's' else '' end} inside '#{request.to_url}'."
Logger.info "[#{'SSLSTRIP'.green} #{request.client}] Stripping #{links.size} HTTPS link#{links.size > 1 ? 's' : ''} inside '#{request.to_url}'."

links.each do |l|
original, stripped = l
Expand Down
2 changes: 1 addition & 1 deletion lib/bettercap/update_checker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def self.check
def self.vton v
vi = 0.0
v.split('.').reverse.each_with_index do |e,i|
vi += ( e.to_i * 10**i ) - ( if e =~ /[\d+]b/ then 0.5 else 0 end )
vi += ( e.to_i * 10**i ) - ( e =~ /[\d+]b/ ? 0.5 : 0 )
end
vi
end
Expand Down

0 comments on commit c08ae99

Please sign in to comment.