2 SA_CONFIG = YAML::load_file(File.dirname(__FILE__)+'/../../config.yml')
4 class SitealizerController < ActionController::Base
6 before_filter :check_access_type, :except => [:login, :logout]
10 "#{RAILS_ROOT}/vendor/plugins/sitealizer/lib/app/views"
14 return unless request.post?
15 if params[:username] == SA_CONFIG['sitealizer']['username'].to_s && params[:password] == SA_CONFIG['sitealizer']['password'].to_s
16 cookies[:sitealizer] = {:value => Digest::SHA1.hexdigest("--#{Time.now.to_i}--#{params[:username]}--")}
17 redirect_to :action => 'index'
19 flash[:notice] = "Username/Password Invalid"
24 cookies.delete :sitealizer
25 redirect_to :action => 'login'
29 if !params[:month] && !params[:year]
30 params[:month] = sprintf("%02d",Time.now.month)
31 params[:year] = Time.now.year
38 f = SiteTracker.find(:all, :limit => 1, :order => 'created_on ASC')
39 l = SiteTracker.find(:all, :limit => 1, :order => 'created_on DESC')
40 first = !f.empty? ? f.first.created_on : Date.today
41 last = !l.empty? ? l.first.created_on : Date.today
42 (first.to_date..last.to_date).each{|d| months << d.month unless months.include?(d.month)}
43 (first.to_date..last.to_date).each{|d| years << d.year unless years.include?(d.year)}
44 @months = months.sort.map{|m|
46 "<option #{"selected" if m.to_i == params[:month].to_i } value=#{m}>#{m}</option>"
48 @years = years.sort.map{|y|
49 "<option #{"selected" if y == params[:year].to_i} value=#{y}>#{y}</option>"
51 @cookie = cookies[:sitealizer]
58 if "#{params[:year]}-#{params[:month]}-1".to_time
60 @month = params[:month]
64 @month = sprintf("%02d",Time.now.month)
66 @total_hits = SiteTracker.count_hits(:year => @year, :month => @month)
67 @unique_hits = SiteTracker.count_hits(:count => 'DISTINCT ip', :year => @year, :month => @month)
68 @daily_hits = SiteTracker.find_daily_hits(:year => @year, :month => @month)
69 @month_hits = SiteTracker.find_monthly_hits(:year => @year)
70 @year_hits = SiteTracker.count_hits(:date => "#{@year}-%")
71 @year_uniq = SiteTracker.count_hits(:date => "#{@year}-%", :count => "DISTINCT ip")
72 file = File.dirname(__FILE__)+'/../../last_update'
73 @last_update = File.exists?(file) ? open(file,'r'){|f| f.read.to_time.to_s(:long)} : "Not updated yet"
77 @year = params[:year] || Time.now.year
78 @month = params[:month] || sprintf("%02d",Time.now.month)
79 @total_hits = SiteTracker.count_hits(:year => @year, :month => @month)
80 @hourly_hits = SiteTracker.find_hourly_hits(:year => @year, :month => @month)
84 @year = params[:year] || Time.now.year
85 @month = params[:month] || sprintf("%02d",Time.now.month)
86 @keywords = SiteTracker.find_search_terms(:year => @year, :month => @month)
87 @engines = SiteTracker.find_domains(:year => @year, :month => @month, :host => request.host)
88 @robots = SiteTracker.find_robots(:year => @year, :month => @month)
92 @year = params[:year] || Time.now.year
93 @month = params[:month] || sprintf("%02d",Time.now.month)
94 @total_hits = SiteTracker.count_hits(:year => @year, :month => @month)
95 @browsers = SiteTracker.find_browsers(:year => @year, :month => @month)
96 @platforms = SiteTracker.find_platforms(:year => @year, :month => @month)
97 @hosts = SiteTracker.find_hosts(:year => @year, :month => @month)
98 @languages = SiteTracker.find_languages(:year => @year, :month => @month)
102 @year = params[:year] || Time.now.year
103 @month = params[:month] || sprintf("%02d",Time.now.month)
104 @total_hits = SiteTracker.count_hits(:year => @year, :month => @month)
105 @referers = SiteTracker.find_referers(:year => @year, :month => @month)
106 @page_urls = SiteTracker.find_page_urls(:year => @year, :month => @month)
110 def check_access_type
111 if SA_CONFIG['sitealizer']['access_type'] == 'private'
112 unless cookies[:sitealizer]
113 redirect_to :action => 'login'