Permalink
Browse files

Detection of the user's ip is added

  • Loading branch information...
1 parent 3399489 commit d10249dc13c9ee85efb4b83dbda563d54d16fe01 Esenbek Kydyr uulu committed with Daniel Vartanov Dec 13, 2009
Showing with 29 additions and 11 deletions.
  1. +19 −3 lib/traffic.rb
  2. +3 −3 lib/traffic_calculator.rb
  3. +5 −3 server.rb
  4. +2 −2 views/results.erb
View
@@ -2,9 +2,9 @@ class Traffic
attr_accessor :local_address
attr_reader :records
- def initialize(records, local_address)
+ def initialize(records, local_address_found = false)
@records = records
- @local_address = local_address
+ @local_address = (local_address_found) ? local_address_found : local_address_find
end
def incoming
@@ -40,5 +40,21 @@ def grouped_by_host
end
@grouped_by_host
- end
+ end
+
+ def local_address_find
+ if (@records[0])
+ ip1, ip2 = @records[0].map {|address| address}
+ end
+ @records.each do |record|
+ ipn1, ipn2 = record.map {|address| address}
+ if (ip1!=ipn1 && ip1!=ipn2) then
+ return ip2
+ else if (ip2!=ipn1 && ip2!=ipn2) then
+ return ip1
+ end
+ end
+ end
+ ip2
+ end
end
@@ -1,9 +1,9 @@
-class TrafficCalculator < Struct.new(:log_file_name, :user_address)
+class TrafficCalculator < Struct.new(:log_file_name)
def calculate!
parser = Parser.new
parser.parse_file!(self.log_file_name)
- @traffic = Traffic.new(parser.records, self.user_address)
+ @traffic = Traffic.new(parser.records)
end
def get_results
@@ -24,7 +24,7 @@ def get_results
def print_results
puts results_string
- end
+ end
def results_string
result = ''
View
@@ -15,9 +15,9 @@
post '/' do
tempfile = params[:logsfile][:tempfile]
- traffic_calculator = TrafficCalculator.new tempfile.path, '77.235.9.36'
+ traffic_calculator = TrafficCalculator.new tempfile.path
traffic_calculator.calculate!
- @data = traffic_calculator.get_results
+ @data = traffic_calculator.get_results
erb :results
end
@@ -29,4 +29,6 @@
rescue Resolv::ResolvError
params[:ip]
end
-end
+end
+
+
View
@@ -9,7 +9,7 @@
<table width="500px"><tr><td>
<fieldset>
- <legend><span class="contentheading">Your inner traffic</span></legend>
+ <legend><span class="contentheading">Your incomming traffic</span></legend>
<table width="500px">
<thead>
<tr>
@@ -35,7 +35,7 @@
</td></tr><tr><td>
<fieldset>
- <legend><span class="contentheading">Your outer traffic</span></legend>
+ <legend><span class="contentheading">Your outcomming traffic</span></legend>
<table width="500px">
<thead>
<tr>

0 comments on commit d10249d

Please sign in to comment.