rail_stat_generator 0.1.0
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.
- data/MIT-LICENSE +21 -0
- data/USAGE +21 -0
- data/rail_stat_generator.rb +40 -0
- data/templates/README +21 -0
- data/templates/app/controllers/rail_stat_controller.rb +111 -0
- data/templates/app/helpers/rail_stat_helper.rb +184 -0
- data/templates/app/models/iptoc.rb +5 -0
- data/templates/app/models/rail_stat.rb +130 -0
- data/templates/app/models/search_term.rb +19 -0
- data/templates/app/views/layouts/rail_stat.rhtml +22 -0
- data/templates/app/views/rail_stat/_menu.rhtml +17 -0
- data/templates/app/views/rail_stat/hits.rhtml +28 -0
- data/templates/app/views/rail_stat/lang.rhtml +25 -0
- data/templates/app/views/rail_stat/other.rhtml +51 -0
- data/templates/app/views/rail_stat/path.rhtml +81 -0
- data/templates/app/views/rail_stat/platform.rhtml +25 -0
- data/templates/app/views/rail_stat/refs.rhtml +25 -0
- data/templates/db/ip-to-country.mysql.sql +22 -0
- data/templates/db/railstat.mysql.sql +43 -0
- data/templates/lib/path_tracker.rb +325 -0
- data/templates/public/images/railstat/1.gif +0 -0
- data/templates/public/images/railstat/10.gif +0 -0
- data/templates/public/images/railstat/11.gif +0 -0
- data/templates/public/images/railstat/12.gif +0 -0
- data/templates/public/images/railstat/13.gif +0 -0
- data/templates/public/images/railstat/14.gif +0 -0
- data/templates/public/images/railstat/15.gif +0 -0
- data/templates/public/images/railstat/16.gif +0 -0
- data/templates/public/images/railstat/17.gif +0 -0
- data/templates/public/images/railstat/18.gif +0 -0
- data/templates/public/images/railstat/19.gif +0 -0
- data/templates/public/images/railstat/1pxtr.gif +0 -0
- data/templates/public/images/railstat/2.gif +0 -0
- data/templates/public/images/railstat/20.gif +0 -0
- data/templates/public/images/railstat/21.gif +0 -0
- data/templates/public/images/railstat/22.gif +0 -0
- data/templates/public/images/railstat/23.gif +0 -0
- data/templates/public/images/railstat/24.gif +0 -0
- data/templates/public/images/railstat/25.gif +0 -0
- data/templates/public/images/railstat/26.gif +0 -0
- data/templates/public/images/railstat/27.gif +0 -0
- data/templates/public/images/railstat/28.gif +0 -0
- data/templates/public/images/railstat/29.gif +0 -0
- data/templates/public/images/railstat/3.gif +0 -0
- data/templates/public/images/railstat/30.gif +0 -0
- data/templates/public/images/railstat/31.gif +0 -0
- data/templates/public/images/railstat/32.gif +0 -0
- data/templates/public/images/railstat/33.gif +0 -0
- data/templates/public/images/railstat/34.gif +0 -0
- data/templates/public/images/railstat/35.gif +0 -0
- data/templates/public/images/railstat/36.gif +0 -0
- data/templates/public/images/railstat/37.gif +0 -0
- data/templates/public/images/railstat/38.gif +0 -0
- data/templates/public/images/railstat/39.gif +0 -0
- data/templates/public/images/railstat/4.gif +0 -0
- data/templates/public/images/railstat/40.gif +0 -0
- data/templates/public/images/railstat/5.gif +0 -0
- data/templates/public/images/railstat/6.gif +0 -0
- data/templates/public/images/railstat/7.gif +0 -0
- data/templates/public/images/railstat/8.gif +0 -0
- data/templates/public/images/railstat/9.gif +0 -0
- data/templates/public/images/railstat/other.gif +0 -0
- data/templates/public/javascripts/railstat.js +10 -0
- data/templates/public/stylesheets/railstat.css +54 -0
- data/templates/public/stylesheets/tabs.css +110 -0
- metadata +116 -0
@@ -0,0 +1,51 @@
|
|
1
|
+
<h1>Other statistics on <%%= @subdomain %> </h1>
|
2
|
+
<%%=render_partial 'menu'%>
|
3
|
+
<h2>Flash supported</h2>
|
4
|
+
<div id="path_stats_flash">
|
5
|
+
<table class="list">
|
6
|
+
<tr><th width='50%'>Version</th><th>Percentage</th></tr>
|
7
|
+
<%% initListClass
|
8
|
+
for data in @flashes %>
|
9
|
+
<tr class="<%%=popListClass%>"><td><%%=path_version_data(data['flash'])%></td><td><%%=data['percent']%> %</td></tr>
|
10
|
+
<%% end %>
|
11
|
+
</table>
|
12
|
+
</div>
|
13
|
+
|
14
|
+
<h2>JavaVM Enabled</h2>
|
15
|
+
<table class="list">
|
16
|
+
<tr><th width='50%'>Version</th><th>Percentage</th></tr>
|
17
|
+
<%% initListClass
|
18
|
+
for data in @jes %>
|
19
|
+
<tr class="<%%=popListClass%>"><td><%%=path_version_data(data['java_enabled'])%></td><td><%%=data['percent']%> %</td></tr>
|
20
|
+
<%% end %>
|
21
|
+
</table>
|
22
|
+
|
23
|
+
<h2>Javascript suported</h2>
|
24
|
+
<table class="list">
|
25
|
+
<tr><th width='50%'>JavaScript</th><th>Percentage</th></tr>
|
26
|
+
<%% initListClass
|
27
|
+
for data in @javas %>
|
28
|
+
<tr class="<%%=popListClass%>"><td><%%=path_version_data(data['java'])%></td><td><%%=data['percent']%> %</td></tr>
|
29
|
+
<%% end %>
|
30
|
+
</table>
|
31
|
+
|
32
|
+
<h2>Screen width</h2>
|
33
|
+
<table class="list">
|
34
|
+
<tr><th width='50%'>Width</th><th>Percentage</th></tr>
|
35
|
+
<%% initListClass
|
36
|
+
for data in @widths %>
|
37
|
+
<tr class="<%%=popListClass%>"><td><%%=path_version_data(data['screen_size'])%></td><td><%%=data['percent']%> %</td></tr>
|
38
|
+
<%% end %>
|
39
|
+
</table>
|
40
|
+
|
41
|
+
<h2>Color depth</h2>
|
42
|
+
<table class="list">
|
43
|
+
<tr><th width='50%'>Color depth</th><th>Percentage</th></tr>
|
44
|
+
<%% initListClass
|
45
|
+
for data in @colors %>
|
46
|
+
<tr class="<%%=popListClass%>"><td><%%=path_version_data(data['colors'])%></td><td><%%=data['percent']%> %</td></tr>
|
47
|
+
<%% end %>
|
48
|
+
</table>
|
49
|
+
|
50
|
+
</div>
|
51
|
+
</div>
|
@@ -0,0 +1,81 @@
|
|
1
|
+
<h1>Path statistics for <%%= @subdomain %> </h1>
|
2
|
+
<%%=render_partial 'menu'%>
|
3
|
+
<h2>Last paths</h2>
|
4
|
+
<div id="path_stats">
|
5
|
+
Number of hits:
|
6
|
+
<a href='?nh=25&ise=<%%=@include_search_engines%>'>25</a>
|
7
|
+
<a href='?nh=50&ise=<%%=@include_search_engines%>'>50</a>
|
8
|
+
<a href='?nh=100&ise=<%%=@include_search_engines%>'>100</a>
|
9
|
+
<a href='?nh=150&ise=<%%=@include_search_engines%>'>150</a>
|
10
|
+
<a href='?nh=200&ise=<%%=@include_search_engines%>'>200</a>
|
11
|
+
<a href='?nh=250&ise=<%%=@include_search_engines%>'>250</a>
|
12
|
+
<br/>
|
13
|
+
Show search engines:
|
14
|
+
<a href='?nh=<%%=@number_hits%>&ise=1'>On</a>
|
15
|
+
<a href='?nh=<%%=@number_hits%>&ise=0'>Off</a> <br/>
|
16
|
+
<%% if @paths.size > 0 %>
|
17
|
+
<table class="list" width='100%'>
|
18
|
+
<tr>
|
19
|
+
<th>D/T</th>
|
20
|
+
<th>Path</th>
|
21
|
+
<th>Addr.</th>
|
22
|
+
<th>Browser</th>
|
23
|
+
<th>Platform</th>
|
24
|
+
</tr>
|
25
|
+
<%% initListClass
|
26
|
+
for i in 0..@paths.size-1
|
27
|
+
row = @paths[i]
|
28
|
+
if not(row.marked?)
|
29
|
+
row.mark
|
30
|
+
domain, refferer = "-", '' %>
|
31
|
+
<tr class='<%%=popListClass%>'>
|
32
|
+
<td width='60px'><div class='cutField'><%%=get_time(row.dt)%></div></td>
|
33
|
+
<td width='200px'><div class='cutField'>
|
34
|
+
<%% last_access_time = row.dt
|
35
|
+
# work through loop backwards so we get the *first* page time wise
|
36
|
+
(@paths.size-1).downto(i+1) { |j|
|
37
|
+
if not(@paths[j].marked?) and row.remote_ip == @paths[j].remote_ip and (last_access_time - 900 <= @paths[j].dt)
|
38
|
+
domain, refferer = @paths[j].domain, @paths[j].referer if domain == "-" and @paths[j].domain and not(@paths[j].domain == SITE_NAME)%>
|
39
|
+
<%%=get_path_image(@paths[j].resource, @ordered_resources)%>
|
40
|
+
<%% @paths[j].mark
|
41
|
+
last_access_time = @paths[j].dt
|
42
|
+
end
|
43
|
+
}
|
44
|
+
# add last page %>
|
45
|
+
<%%=get_path_image(row.resource, @ordered_resources)%>
|
46
|
+
<%% domain, refferer = row.domain, row.referer if domain == "-" and row.domain and not(row.domain == SITE_NAME) %>
|
47
|
+
<%% if domain and not(domain.nil?) and not(domain == '-') %>
|
48
|
+
from <a href="<%%=refferer%>"><%%=domain%></a>
|
49
|
+
<%% end %>
|
50
|
+
</div></td>
|
51
|
+
<td><div class='cutField'><%%=get_domain_name(row.remote_ip)%></div></td>
|
52
|
+
<td width='50px'><div class='cutField'><%%=row.browser%>
|
53
|
+
<%% unless row.version =="unknown" %>
|
54
|
+
<%%=row.version%>
|
55
|
+
<%% end %>
|
56
|
+
</div></td>
|
57
|
+
<td width='50px'><div class='cutField'><%%=row.platform%></div></td>
|
58
|
+
</tr>
|
59
|
+
<%% end
|
60
|
+
end %>
|
61
|
+
</table>
|
62
|
+
<%% end %>
|
63
|
+
</div>
|
64
|
+
|
65
|
+
<div id="pathslegend">
|
66
|
+
<h2>Legend</h2>
|
67
|
+
<%% if @orarr.size > 0 %>
|
68
|
+
<table class="list">
|
69
|
+
<tr><th colspan="2">Resource</th><th>Hits statistics</th></tr>
|
70
|
+
<%% initListClass
|
71
|
+
for resource in @orarr %>
|
72
|
+
<tr class="<%%=popListClass%>">
|
73
|
+
<td><%%=get_path_image(resource['resource'], @ordered_resources)%></td>
|
74
|
+
<td><a href='<%%=resource['resource']%>'><%%=h resource['resource'] %></a></td>
|
75
|
+
<td><%%=resource['requests']%></td></tr>
|
76
|
+
<%% end %>
|
77
|
+
</table>
|
78
|
+
<%% end %>
|
79
|
+
</div>
|
80
|
+
</div>
|
81
|
+
</div>
|
@@ -0,0 +1,25 @@
|
|
1
|
+
<h1>Platform statistics for <%%= @subdomain %> </h1>
|
2
|
+
<%%=render_partial 'menu'%>
|
3
|
+
<h2>Operating systems</h2>
|
4
|
+
<div id="path_stats_pl">
|
5
|
+
<table class="list">
|
6
|
+
<tr><th>OS</th><th>%</th></tr>
|
7
|
+
<%% initListClass
|
8
|
+
for pl in @platforms %>
|
9
|
+
<tr class="<%%=popListClass%>"><td><%%=pl['platform']%></td><td><%%=pl['percent']%>%</td></tr>
|
10
|
+
<%% end %>
|
11
|
+
</table>
|
12
|
+
</div>
|
13
|
+
|
14
|
+
<h2>Browsers usage</h2>
|
15
|
+
<div id="path_stats_br">
|
16
|
+
<table class="list">
|
17
|
+
<tr><th>Browser</th><th>Version</th><th>%</th></tr>
|
18
|
+
<%% initListClass
|
19
|
+
for br in @browsers %>
|
20
|
+
<tr class="<%%=popListClass%>"><td><%%=br['browser']%></td><td><%%=br['version']%></td><td><%%=br['percent']%>%</td></tr>
|
21
|
+
<%% end %>
|
22
|
+
</table>
|
23
|
+
</div>
|
24
|
+
</div>
|
25
|
+
</div>
|
@@ -0,0 +1,25 @@
|
|
1
|
+
<h1>Referrers statistic for <%%= @subdomain %> </h1>
|
2
|
+
<%%=render_partial 'menu'%>
|
3
|
+
<h2>Repeat referrers</h2>
|
4
|
+
<div id="path_stats_refsd">
|
5
|
+
<table class="list">
|
6
|
+
<tr><th>Domains</th><th>Hits</th></tr>
|
7
|
+
<%% initListClass
|
8
|
+
for row in @refs %>
|
9
|
+
<tr class="<%%=popListClass%>"><td><a href='<%%=row['referer']%>' title='<%%=row['resource']%>'><%%=row['domain']%></a></td><td><%%=row['total']%></td></tr>
|
10
|
+
<%% end %>
|
11
|
+
</table>
|
12
|
+
</div>
|
13
|
+
|
14
|
+
<h2>Search strings</h2>
|
15
|
+
<div id="path_stats_refst">
|
16
|
+
<table class="list">
|
17
|
+
<tr><th>Search strings</th><th>Hits</th></tr>
|
18
|
+
<%% initListClass
|
19
|
+
for row in @searchterms %>
|
20
|
+
<tr class="<%%=popListClass%>"><td><%%=h row['searchterms']%></td><td><%%=row['count']%></td></tr>
|
21
|
+
<%% end %>
|
22
|
+
</table>
|
23
|
+
</div>
|
24
|
+
</div>
|
25
|
+
</div>
|
@@ -0,0 +1,22 @@
|
|
1
|
+
drop table if exists iptocs;
|
2
|
+
|
3
|
+
create table IF NOT EXISTS iptocs(
|
4
|
+
ip_from int(10) unsigned zerofill not null,
|
5
|
+
ip_to int(10) unsigned zerofill not null,
|
6
|
+
country_code2 char(2) not null,
|
7
|
+
country_code3 char(3) not null,
|
8
|
+
country_name varchar(50) not null,
|
9
|
+
unique index(ip_from, ip_to)
|
10
|
+
);
|
11
|
+
|
12
|
+
delete from iptocs;
|
13
|
+
|
14
|
+
load data local infile 'ip-to-country.csv'
|
15
|
+
into table iptocs
|
16
|
+
fields terminated by ',' enclosed by '"'
|
17
|
+
lines terminated by '\r\n';
|
18
|
+
|
19
|
+
alter table iptocs add column id bigint(20) NOT NULL auto_increment primary key;
|
20
|
+
|
21
|
+
alter table iptocs add unique index (id);
|
22
|
+
optimize table iptocs;
|
@@ -0,0 +1,43 @@
|
|
1
|
+
CREATE TABLE rail_stats (
|
2
|
+
id int(11) unsigned NOT NULL auto_increment,
|
3
|
+
remote_ip varchar(15) default '',
|
4
|
+
country varchar(50) default '',
|
5
|
+
language VARCHAR(5) default '',
|
6
|
+
domain varchar(250) default '',
|
7
|
+
subdomain varchar(250) default '',
|
8
|
+
referer varchar(255) default '',
|
9
|
+
resource varchar(255) default '',
|
10
|
+
user_agent varchar(255) default '',
|
11
|
+
platform varchar(50) default '',
|
12
|
+
browser varchar(50) default '',
|
13
|
+
version varchar(15) default '',
|
14
|
+
dt int(10) unsigned default '0',
|
15
|
+
screen_size varchar(10) default null,
|
16
|
+
colors varchar(10) default null,
|
17
|
+
java varchar(10) default null,
|
18
|
+
java_enabled varchar(10) default null,
|
19
|
+
flash varchar(10) default null,
|
20
|
+
UNIQUE KEY id (id),
|
21
|
+
INDEX(subdomain)
|
22
|
+
) TYPE=MyISAM;
|
23
|
+
|
24
|
+
CREATE TABLE search_terms (
|
25
|
+
id int(11) unsigned NOT NULL auto_increment,
|
26
|
+
subdomain varchar(250) default '',
|
27
|
+
searchterms varchar(255) NOT NULL default '',
|
28
|
+
count int(10) unsigned NOT NULL default '0',
|
29
|
+
domain varchar(250),
|
30
|
+
PRIMARY KEY (id),
|
31
|
+
INDEX(subdomain)
|
32
|
+
) TYPE=MyISAM;
|
33
|
+
|
34
|
+
CREATE TABLE iptocs (
|
35
|
+
id int(11) unsigned NOT NULL auto_increment,
|
36
|
+
ip_from int(10) unsigned zerofill not null,
|
37
|
+
ip_to int(10) unsigned zerofill not null,
|
38
|
+
country_code2 char(2) not null,
|
39
|
+
country_code3 char(3) not null,
|
40
|
+
country_name varchar(50) not null,
|
41
|
+
PRIMARY KEY (id),
|
42
|
+
unique index(ip_from, ip_to)
|
43
|
+
);
|
@@ -0,0 +1,325 @@
|
|
1
|
+
require 'uri'
|
2
|
+
require 'socket'
|
3
|
+
|
4
|
+
module PathTracker
|
5
|
+
public
|
6
|
+
|
7
|
+
def track_path
|
8
|
+
begin
|
9
|
+
referer = @params['referer'] # env['HTTP_REFERER']
|
10
|
+
req_uri = @params['doc'] # env['REQUEST_URI']
|
11
|
+
|
12
|
+
req_uri = @request.env['HTTP_REFERER'] if req_uri.nil?
|
13
|
+
|
14
|
+
req_uri = get_doc_url(req_uri)
|
15
|
+
|
16
|
+
size = @params['size']
|
17
|
+
colors = @params['colors']
|
18
|
+
java = @params['java']
|
19
|
+
je = @params['je']
|
20
|
+
flash = @params['flash']
|
21
|
+
|
22
|
+
env = @request.env.nil? ? {'HTTP_USER_AGENT' => nil, 'HTTP_REFERER' => nil,
|
23
|
+
'REMOTE_ADDR' => nil, 'HTTP_ACCEPT_LANGUAGE' => nil, 'REQUEST_URI' => nil} : @request.env
|
24
|
+
br = parse_user_agent(env['HTTP_USER_AGENT'])
|
25
|
+
subdomain = detect_subdomain
|
26
|
+
domain = get_urls_host(referer)
|
27
|
+
|
28
|
+
sniff_keywords(domain, subdomain, referer);
|
29
|
+
|
30
|
+
@client_country = Iptoc.find_by_ip_address(@request.env['REMOTE_ADDR'])
|
31
|
+
|
32
|
+
RailStat.create("remote_ip" => env['REMOTE_ADDR'],
|
33
|
+
"country" => ((@client_country.nil? or @client_country.country_name.nil?) ? '' : @client_country.country_name),
|
34
|
+
"language" => determine_lang(env['HTTP_ACCEPT_LANGUAGE']),
|
35
|
+
"domain" => domain,
|
36
|
+
"subdomain" => subdomain,
|
37
|
+
"referer" => referer,
|
38
|
+
"resource" => req_uri,
|
39
|
+
"user_agent" => env['HTTP_USER_AGENT'],
|
40
|
+
"platform" => br['platform'],
|
41
|
+
"browser" => br['browser'],
|
42
|
+
"version" => br['version'],
|
43
|
+
"dt" => Time.now,
|
44
|
+
"screen_size" => size,
|
45
|
+
"colors" => colors,
|
46
|
+
"java" => java,
|
47
|
+
"java_enabled" => je,
|
48
|
+
"flash" => flash)
|
49
|
+
rescue Exception => e
|
50
|
+
RAILS_DEFAULT_LOGGER.error("Error on path track #{e.backtrace.join('\n')}" )
|
51
|
+
end
|
52
|
+
""
|
53
|
+
end
|
54
|
+
|
55
|
+
private
|
56
|
+
|
57
|
+
def determine_lang(language)
|
58
|
+
ret = "empty"
|
59
|
+
unless language.nil? or language == ''
|
60
|
+
# Capture up to the first delimiter (, found in Safari)
|
61
|
+
begin
|
62
|
+
ret = /([^,;]*)/.match(language)[0];
|
63
|
+
rescue
|
64
|
+
end
|
65
|
+
end
|
66
|
+
return ret
|
67
|
+
end
|
68
|
+
|
69
|
+
def get_urls_host(ref)
|
70
|
+
if host = parse_url(ref)
|
71
|
+
if host == SITE_NAME
|
72
|
+
return nil
|
73
|
+
else
|
74
|
+
host
|
75
|
+
end
|
76
|
+
else
|
77
|
+
return nil
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def parse_url(arg)
|
82
|
+
if arg.nil?
|
83
|
+
return nil
|
84
|
+
else
|
85
|
+
URI::split(arg.gsub(' ','%20'))[2]
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def get_doc_url(arg)
|
90
|
+
if arg.nil?
|
91
|
+
return nil
|
92
|
+
else
|
93
|
+
URI::split(arg.gsub(' ','%20'))[5]
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
def get_params_url(arg)
|
98
|
+
if arg.nil?
|
99
|
+
return nil
|
100
|
+
else
|
101
|
+
URI::split(arg.gsub(' ','%20'))[7]
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
def parse_user_agent(ua)
|
106
|
+
browser = {'platform' => "unknown", 'browser' => "unknown",
|
107
|
+
'version' => "unknown", 'majorver' => "unknown", 'minorver' => "unknown"}
|
108
|
+
begin
|
109
|
+
# Test for platform
|
110
|
+
if ua =~ /Win/i
|
111
|
+
browser['platform'] = "Windows";
|
112
|
+
elsif ua =~ /Mac/i
|
113
|
+
browser['platform'] = "Macintosh";
|
114
|
+
elsif ua =~ /Linux/i
|
115
|
+
browser['platform'] = "Linux";
|
116
|
+
end
|
117
|
+
|
118
|
+
|
119
|
+
# Test for browser type
|
120
|
+
if ua =~ /Mozilla\/4/i && !ua =~ /compatible/i
|
121
|
+
browser['browser'] = "Netscape";
|
122
|
+
begin
|
123
|
+
browser['version'] = /Mozilla\/([[:digit:]\.]+)/i.match(ua)[1]
|
124
|
+
rescue
|
125
|
+
end
|
126
|
+
end
|
127
|
+
if ua =~ /Mozilla\/5/i || ua =~ /Gecko/i
|
128
|
+
browser['browser'] = "Mozilla";
|
129
|
+
begin
|
130
|
+
browser['version'] = /rv(:| )([[:digit:]\.]+)/i.match(ua)[2]
|
131
|
+
rescue
|
132
|
+
end
|
133
|
+
end
|
134
|
+
if ua =~ /Safari/i
|
135
|
+
browser['browser'] = "Safari";
|
136
|
+
browser['platform'] = "Macintosh";
|
137
|
+
begin
|
138
|
+
browser['version'] = /Safari\/([[:digit:]\.]+)/i.match(ua)[1]
|
139
|
+
rescue
|
140
|
+
end
|
141
|
+
|
142
|
+
if browser['version'] =~ /125/i
|
143
|
+
browser['version'] = 1.2;
|
144
|
+
browser['majorver'] = 1;
|
145
|
+
browser['minorver'] = 2;
|
146
|
+
elsif browser['version'] =~ /100/i
|
147
|
+
browser['version'] = 1.1;
|
148
|
+
browser['majorver'] = 1;
|
149
|
+
browser['minorver'] = 1;
|
150
|
+
elsif browser['version'] =~ /85/i
|
151
|
+
browser['version'] = 1.0;
|
152
|
+
browser['majorver'] = 1;
|
153
|
+
browser['minorver'] = 0;
|
154
|
+
else
|
155
|
+
begin
|
156
|
+
if browser['version'].to_i < 85
|
157
|
+
browser['version'] = "Pre-1.0 Beta";
|
158
|
+
end
|
159
|
+
rescue
|
160
|
+
end
|
161
|
+
end
|
162
|
+
end
|
163
|
+
if ua =~ /iCab/i
|
164
|
+
browser['browser'] = "iCab";
|
165
|
+
begin
|
166
|
+
browser['version'] = /iCab\/([[:digit:]\.]+)/i.match(ua)[1]
|
167
|
+
rescue
|
168
|
+
end
|
169
|
+
end
|
170
|
+
if ua =~ /Firefox/i
|
171
|
+
browser['browser'] = "Firefox";
|
172
|
+
begin
|
173
|
+
browser['version'] = /Firefox\/([[:digit:]\.]+)/i.match(ua)[1]
|
174
|
+
rescue
|
175
|
+
end
|
176
|
+
end
|
177
|
+
if ua =~ /Firebird/i
|
178
|
+
browser['browser'] = "Firebird";
|
179
|
+
begin
|
180
|
+
browser['version'] = /Firebird\/([[:digit:]\.]+)/i.match(ua)[1]
|
181
|
+
rescue
|
182
|
+
end
|
183
|
+
end
|
184
|
+
if ua =~ /Phoenix/i
|
185
|
+
browser['browser'] = "Phoenix";
|
186
|
+
begin
|
187
|
+
browser['version'] = /Phoenix\/([[:digit:]\.]+)/i.match(ua)[1]
|
188
|
+
rescue
|
189
|
+
end
|
190
|
+
end
|
191
|
+
if ua =~ /Camino/i
|
192
|
+
browser['browser'] = "Camino";
|
193
|
+
begin
|
194
|
+
browser['version'] = /Camino\/([[:digit:]\.]+)/i.match(ua)[1]
|
195
|
+
rescue
|
196
|
+
end
|
197
|
+
end
|
198
|
+
if ua =~ /Chimera/i
|
199
|
+
browser['browser'] = "Chimera";
|
200
|
+
begin
|
201
|
+
browser['version'] = /Chimera\/([[:digit:]\.]+)/i.match(ua)[1]
|
202
|
+
rescue
|
203
|
+
end
|
204
|
+
end
|
205
|
+
if ua =~ /Netscape/i
|
206
|
+
browser['browser'] = "Netscape";
|
207
|
+
begin
|
208
|
+
browser['version'] = /Netscape[0-9]?\/([[:digit:]\.]+)/i.match(ua)[1]
|
209
|
+
rescue
|
210
|
+
end
|
211
|
+
end
|
212
|
+
if ua =~ /MSIE/i
|
213
|
+
browser['browser'] = "IE";
|
214
|
+
begin
|
215
|
+
browser['version'] = /MSIE ([[:digit:]\.]+)/i.match(ua)[1]
|
216
|
+
rescue
|
217
|
+
end
|
218
|
+
end
|
219
|
+
if ua =~ /Opera/i
|
220
|
+
browser['browser'] = "Opera";
|
221
|
+
begin
|
222
|
+
browser['version'] = /Opera( |\/)([[:digit:]\.]+)/i.match(ua)[1]
|
223
|
+
rescue
|
224
|
+
end
|
225
|
+
end
|
226
|
+
if ua =~ /OmniWeb/i
|
227
|
+
browser['browser'] = "OmniWeb";
|
228
|
+
begin
|
229
|
+
browser['version'] = /OmniWeb\/([[:digit:]\.]+)/i.match(ua)[1]
|
230
|
+
rescue
|
231
|
+
end
|
232
|
+
end
|
233
|
+
if ua =~ /Konqueror/i
|
234
|
+
browser['platform'] = "Linux";
|
235
|
+
browser['browser'] = "Konqueror";
|
236
|
+
begin
|
237
|
+
browser['version'] = /Konqueror\/([[:digit:]\.]+)/i.match(ua)[1]
|
238
|
+
rescue
|
239
|
+
end
|
240
|
+
end
|
241
|
+
if ua =~ /Crawl/i || ua =~ /bot/i || ua =~ /slurp/i || ua =~ /spider/i
|
242
|
+
browser['browser'] = "Crawler/Search Engine";
|
243
|
+
end
|
244
|
+
if ua =~ /Lynx/i
|
245
|
+
browser['browser'] = "Lynx";
|
246
|
+
begin
|
247
|
+
browser['version'] = /Lynx\/([[:digit:]\.]+)/i.match(ua)[1]
|
248
|
+
rescue
|
249
|
+
end
|
250
|
+
end
|
251
|
+
if ua =~ /Links/i
|
252
|
+
browser['browser'] = "Links";
|
253
|
+
begin
|
254
|
+
browser['version'] = /\(([[:digit:]\.]+)/i.match(ua)[1]
|
255
|
+
rescue
|
256
|
+
end
|
257
|
+
end
|
258
|
+
|
259
|
+
# Determine browser versions
|
260
|
+
unless browser['browser'] == 'Safari' or browser['browser'] == "unknown" or browser['browser'] == "Crawler/Search Engine" or browser['version'] == "unknown"
|
261
|
+
# Make sure we have at least .0 for a minor version
|
262
|
+
browser['version'] = (!browser['version']=~/\./ ? "#{browser['version']}.0" : browser['version'])
|
263
|
+
|
264
|
+
v = /^([0-9]*).(.*)$/.match(browser['version'])
|
265
|
+
begin
|
266
|
+
browser['majorver'] = v[1];
|
267
|
+
browser['minorver'] = v[2];
|
268
|
+
rescue
|
269
|
+
end
|
270
|
+
end
|
271
|
+
if browser['version'].nil? or browser['version'] == "" or browser['version'] == '.0'
|
272
|
+
browser['version'] = "unknown";
|
273
|
+
browser['majorver'] = "unknown";
|
274
|
+
browser['minorver'] = "unknown";
|
275
|
+
end
|
276
|
+
rescue Exception => e
|
277
|
+
end
|
278
|
+
return browser
|
279
|
+
end
|
280
|
+
|
281
|
+
public
|
282
|
+
|
283
|
+
def sniff_keywords(domain, subdomain, referer)
|
284
|
+
begin
|
285
|
+
searchterms = ''
|
286
|
+
uripars = get_params_url(referer) unless referer.nil?
|
287
|
+
params = CGI.parse(get_params_url(referer)) if uripars and not(uripars.nil?)
|
288
|
+
if domain =~ /google\./i
|
289
|
+
# Googles search terms are in "q"
|
290
|
+
searchterms = params['q']
|
291
|
+
elsif domain =~ /alltheweb\./i
|
292
|
+
# All the Web search terms are in "q"
|
293
|
+
searchterms = params['q']
|
294
|
+
elsif domain =~ /yahoo\./i
|
295
|
+
tempwords = referer.scan(/(\/K=)([^\/]*)(\/)/)
|
296
|
+
if tempwords and tempwords[0]
|
297
|
+
searchterms = tempwords[0][1]
|
298
|
+
else
|
299
|
+
searchterms = params['va']
|
300
|
+
end
|
301
|
+
elsif domain =~ /search\.aol\./i
|
302
|
+
# Yahoo search terms are in "query"
|
303
|
+
searchterms = params['query']
|
304
|
+
elsif domain =~ /search\.msn\./i
|
305
|
+
# MSN search terms are in "q"
|
306
|
+
searchterms = params['q']
|
307
|
+
end
|
308
|
+
SearchTerm.register(searchterms, domain, subdomain) unless searchterms.nil? or searchterms == ''
|
309
|
+
rescue Exception=>ex
|
310
|
+
RAILS_DEFAULT_LOGGER.debug("#{ex} - #{ex.backtrace.join("\n\t")}")
|
311
|
+
end
|
312
|
+
end
|
313
|
+
|
314
|
+
private
|
315
|
+
|
316
|
+
def detect_subdomain
|
317
|
+
subd = ''
|
318
|
+
begin
|
319
|
+
subd = ((@request.subdomains and @request.subdomains.first) ? @request.subdomains.first : nil)
|
320
|
+
rescue Exception => e
|
321
|
+
logger.error("Error on subdomain parse #{e.backtrace.join('\n')}" )
|
322
|
+
end
|
323
|
+
return subd
|
324
|
+
end
|
325
|
+
end
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|