Class: GlobalSettings

Inherits:
Object
  • Object
show all
Defined in:
lib/GlobalSettings.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(loadOnStartLog) ⇒ GlobalSettings

Returns a new instance of GlobalSettings.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/GlobalSettings.rb', line 22

def initialize(loadOnStartLog)
  @logFile = nil
  @browserCmd = 'kfmclient exec'
  @loadOnStartLog = loadOnStartLog
  @currentLogFile = nil
  @serverLogFiles = []
  @auxFileExtensions = Set.new [ ".jpg", ".gif", ".png", ".bmp", ".js",
                                 ".css", ".ico" ]
  @robotPatterns = [
  { "name" => "MSB", "ip" => ".*", "browser" => "^msnbot/.*" },
  { "name" => "Yahoo", "ip" => ".*", "browser" => ".*Yahoo\! Slurp.*" },
  { "name" => "Google", "ip" => ".*",
    "browser" => ".*Googlebot/.*" },
  { "name" => "Google Image", "ip" => ".*",
    "browser" => ".*Googlebot-Image/.*" },
  { "name" => "ASK.com", "ip" => ".*",
    "browser" => ".*Ask Jeeves/Teoma.*\.ask\.com" },
  { "name" => "Rambler", "ip" => ".*",
    "browser" => "^StackRambler/2.0 \(MSIE incompatible\).*" },
  { "name" => "Exabot", "ip" => ".*", "browser" => "^NG/.*" },
  { "name" => "NimbleCrawler", "ip" => ".*",
    "browser" => ".*NimbleCrawler .* obeys UserAgent NimbleCrawler.*" },
  { "name" => "ConveraCrawler", "ip" => ".*",
    "browser" => "ConveraCrawler.*" },
  { "name" => "Voyager", "ip" => ".*", "browser" => "voyager/.*" },
  { "name" => "Omni-Explorer", "ip" => ".*",
    "browser" => "OmniExplorer_Bot/.* WorldIndexer" },
  { "name" => "YahooMMCrawler", "ip" => ".*",
    "browser" => "Yahoo-MMCrawler/.*" },
  { "name" => "Alexa Crawler", "ip" => ".*", "browser" => "ia_archiver" },
  { "name" => "QuickFinder.*", "ip" => ".*",
    "browser" => "QuickFinder Crawler" },
  { "name" => "Noxtrum", "ip" => ".*", "browser" => "noxtrumbot/.*" },
  { "name" => "Exabot", "ip" => ".*", "browser" => "Exabot/.*" },
  { "name" => "Picsearch", "ip" => ".*", "browser" => "psbot/.*" }
  ]

  @persistentSettings = {
    "DNSResolver" => true,
    "Geolocator" => true,
    "TraceRouter" => true,
    "MainWindowW" => 0,
    "MainWindowH" => 1,
    "LargeMapW" => 0,
    "LargeMapH" => 0,
    "CurrentStatusSplitter" => [],
    "VisitorWindowW" => 0,
    "VisitorWindowH" => 0,
    "PageWindowW" => 0,
    "PageWindowH" => 0,
    "RefererWindowW" => 0,
    "RefererWindowH" => 0,
    "MonitorWindow" => 10,
    "ShowSurfers" => 1,
    "ShowRobots" => 0,
    "ShowRegularPages" => 1,
    "ShowAuxPages" => 0,
    "BrowserCommand" => "kfmclient exec",
    "DNSCache" => {},
    "GeoLocatorCache" => {},
    "TraceRouterCache" => {},
    "LogFileDataTimeout" => 24,
    "DNSTimeout" => 7,
    "GeolocTimeout" => 30,
    "TracerTimeout" => 48,
    "GeolocHost" => "api.hostip.info",
    "GeolocPort" => 80,
    "WMShowIPs" => false,
    "WMShowHostNames" => false,
    "WMShowCityNames" => false,
    "WMShowRouters" => false,
    "WMShowRoutes" => false,
    "WMShowLast" => false,
    "WMLastMinutes" => 1
  }

  @mainWindowW = 0
  @mainWindowH = 0
  @currentStatusSplitter = []

  loadSettings()
end

Instance Attribute Details

#browserCmdObject

Returns the value of attribute browserCmd.



19
20
21
# File 'lib/GlobalSettings.rb', line 19

def browserCmd
  @browserCmd
end

#currentLogFileObject

Returns the value of attribute currentLogFile.



19
20
21
# File 'lib/GlobalSettings.rb', line 19

def currentLogFile
  @currentLogFile
end

#robotPatternsObject (readonly)

Returns the value of attribute robotPatterns.



20
21
22
# File 'lib/GlobalSettings.rb', line 20

def robotPatterns
  @robotPatterns
end

#serverLogFilesObject

Returns the value of attribute serverLogFiles.



19
20
21
# File 'lib/GlobalSettings.rb', line 19

def serverLogFiles
  @serverLogFiles
end

Instance Method Details

#addServerLogFile(slf) ⇒ Object



197
198
199
# File 'lib/GlobalSettings.rb', line 197

def addServerLogFile(slf)
  @serverLogFiles << slf
end

#defaultServerURLObject



205
206
207
# File 'lib/GlobalSettings.rb', line 205

def defaultServerURL
  @currentLogFile.default
end

#getSetting(name) ⇒ Object



119
120
121
122
123
124
# File 'lib/GlobalSettings.rb', line 119

def getSetting(name)
  if !@persistentSettings.has_key?(name)
    raise "Unknown setting #{name}"
  end
  return @persistentSettings[name]
end

#isAuxFile(fn) ⇒ Object



213
214
215
216
217
218
# File 'lib/GlobalSettings.rb', line 213

def isAuxFile(fn)
  return false unless dot = fn.rindex('.')
  ext = fn[dot .. -1]
  return false if ext.empty?
  @auxFileExtensions.include?(ext)
end

#isRobot(ip, browser, url) ⇒ Object



225
226
227
228
229
230
231
232
233
234
# File 'lib/GlobalSettings.rb', line 225

def isRobot(ip, browser, url)
  @robotPatterns.each do |rp|
    if Regexp.new(rp["ip"]) =~ ip &&
       Regexp.new(rp["browser"]) =~ browser
      return rp["name"]
    end
  end
  return 'Unknown' if url == '/robots.txt'
  return nil
end

#loadSettingsObject



126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# File 'lib/GlobalSettings.rb', line 126

def loadSettings
  qs = Qt::Settings.new()
  qs.setPath("ClickSpotterProject", "ClickSpotter")
  qs.beginGroup("/clickspotter");
  ok = Qt::Boolean.new
  @persistentSettings.each do |name, value|
    if value.class == Fixnum
      val = Qt::Integer.new(value)
      newValue = qs.readNumEntry("/#{name}", val, ok)
    elsif value.class == String
      newValue = qs.readEntry("/#{name}", value, ok)
    elsif value.class == FalseClass || value.class == TrueClass
      val = Qt::Integer.new(value ? 1 : 0)
      newValue = qs.readNumEntry("/#{name}", val, ok) != 0
    elsif value.class == Array || value.class == Hash
      data = qs.readEntry("/#{name}", YAML.dump(value), ok)
      newValue = YAML.load(data) if data && ok
    else
      raise "#{name} has unsupported type #{value.class()}"
    end
    @persistentSettings[name] = newValue if ok
  end
  data = qs.readEntry('/ServerLogFiles', nil, ok)
  @serverLogFiles = YAML.load(data) if data && ok
  @serverLogFiles.each do |sl|
    if sl.name == @loadOnStartLog
      @currentLogFile = sl
      break;
    end
  end
  qs.endGroup()
end

#logFileObject



220
221
222
223
# File 'lib/GlobalSettings.rb', line 220

def logFile
  return nil unless @currentLogFile
  @currentLogFile.logFile
end

#readEntryList(qs, name, list) ⇒ Object



178
179
180
181
182
183
184
185
186
187
# File 'lib/GlobalSettings.rb', line 178

def readEntryList(qs, name, list)
  i = 0
  ok = Qt::Boolean.new
  while true
    value = qs.readEntry("#{name}_#{i}", nil, ok)
    break if not !ok.nil?
    list.push(value) if
    i += 1
  end
end

#saveSettingsObject



159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
# File 'lib/GlobalSettings.rb', line 159

def saveSettings
  qs = Qt::Settings.new()
  qs.setPath("ClickSpotterProject", "ClickSpotter")
  qs.beginGroup("/clickspotter");
  @persistentSettings.each do |name, value|
    if value.class == Fixnum || value.class == String
      qs.writeEntry("/#{name}", value)
    elsif value.class == FalseClass || value.class == TrueClass
      qs.writeEntry("/#{name}", value ? 1 : 0)
    elsif value.class == Array || value.class == Hash
      qs.writeEntry("/#{name}", YAML.dump(value))
    end
  end
  qs.writeEntry('/ServerLogFiles', YAML.dump(@serverLogFiles))
  qs.endGroup()
  qs.sync
  qs.dispose
end

#serverNamesObject



209
210
211
# File 'lib/GlobalSettings.rb', line 209

def serverNames
  @currentLogFile.hostNames
end

#setAsCurrentLogFile(name) ⇒ Object



201
202
203
# File 'lib/GlobalSettings.rb', line 201

def setAsCurrentLogFile(name)
  @currentLogFile = @serverLogFiles.find { |sl| sl.name == name }
end

#setSetting(name, value) ⇒ Object



105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/GlobalSettings.rb', line 105

def setSetting(name, value)
  if !@persistentSettings.has_key?(name)
    raise "Unknown setting #{name}"
  end
  vClass = @persistentSettings[name].class
  unless ((vClass == FalseClass || vClass == TrueClass) &&
          (value.class != FalseClass || value.class != TrueClass)) ||
         vClass == value.class
    raise "Bad setting type for #{name}!  " +
          "#{@persistentSettings[name].class()} != #{value.class()}"
  end
  @persistentSettings[name] = value
end

#writeEntryList(qs, name, list) ⇒ Object



189
190
191
192
193
194
195
# File 'lib/GlobalSettings.rb', line 189

def writeEntryList(qs, name, list)
  i = 0
  list.each do |value|
    qs.writeEntry("/#{name}_#{i}", value)
    i += 1
  end
end