Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 14c5f9c

Browse files
author
watsonian
committed
Moved files around in prepartion for releasing gem.
1 parent df71bd1 commit 14c5f9c

12 files changed

Lines changed: 293 additions & 425 deletions

LICENSE

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Copyright (c) 2009 watsonian
2+
3+
Permission is hereby granted, free of charge, to any person obtaining
4+
a copy of this software and associated documentation files (the
5+
"Software"), to deal in the Software without restriction, including
6+
without limitation the rights to use, copy, modify, merge, publish,
7+
distribute, sublicense, and/or sell copies of the Software, and to
8+
permit persons to whom the Software is furnished to do so, subject to
9+
the following conditions:
10+
11+
The above copyright notice and this permission notice shall be
12+
included in all copies or substantial portions of the Software.
13+
14+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.rdoc

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
= web-util-scripts
2+
3+
Description goes here.
4+
5+
== Note on Patches/Pull Requests
6+
7+
* Fork the project.
8+
* Make your feature addition or bug fix.
9+
* Add tests for it. This is important so I don't break it in a
10+
future version unintentionally.
11+
* Commit, do not mess with rakefile, version, or history.
12+
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
13+
* Send me a pull request. Bonus points for topic branches.
14+
15+
== Copyright
16+
17+
Copyright (c) 2010 watsonian. See LICENSE for details.

Rakefile

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
require 'rubygems'
2+
require 'rake'
3+
4+
begin
5+
require 'jeweler'
6+
Jeweler::Tasks.new do |gem|
7+
gem.name = "web-util-scripts"
8+
gem.summary = %Q{A collection of scripts to for troubleshooting web applications.}
9+
gem.description = %Q{A collection of scripts to for troubleshooting web applications.}
10+
gem.email = "[email protected]"
11+
gem.homepage = "http://github.com/watsonian/web-util-scripts"
12+
gem.authors = ["watsonian"]
13+
gem.add_dependency "database_sleuth", ">= 1.0.0"
14+
gem.add_development_dependency "rspec", ">= 1.2.9"
15+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
16+
end
17+
Jeweler::GemcutterTasks.new
18+
rescue LoadError
19+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
20+
end
21+
22+
require 'rake/testtask'
23+
Rake::TestTask.new(:test) do |test|
24+
test.libs << 'lib' << 'test'
25+
test.pattern = 'test/**/test_*.rb'
26+
test.verbose = true
27+
end
28+
29+
begin
30+
require 'rcov/rcovtask'
31+
Rcov::RcovTask.new do |test|
32+
test.libs << 'test'
33+
test.pattern = 'test/**/test_*.rb'
34+
test.verbose = true
35+
end
36+
rescue LoadError
37+
task :rcov do
38+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
39+
end
40+
end
41+
42+
task :test => :check_dependencies
43+
44+
task :default => :test
45+
46+
require 'rake/rdoctask'
47+
Rake::RDocTask.new do |rdoc|
48+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
49+
50+
rdoc.rdoc_dir = 'rdoc'
51+
rdoc.title = "web-util-scripts #{version}"
52+
rdoc.rdoc_files.include('README*')
53+
rdoc.rdoc_files.include('lib/**/*.rb')
54+
end

rboptimize renamed to bin/rboptimize

Lines changed: 3 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -1,127 +1,10 @@
11
#!/usr/bin/env ruby
22

3+
require 'rubygems'
34
require 'mysql'
45
require 'optparse'
56
require 'ostruct'
6-
7-
class DatabaseFinder
8-
attr_accessor :application, :locations, :exists_at, :located_at, :regex, :dbname, :dbuser, :dbpass, :dbhost
9-
10-
@@supported_applications = [:joomla, :wordpress, :drupal, :phpbb, :gallery, :zencart, :mediawiki]
11-
12-
@@app_metadata = {}
13-
@@app_metadata[:drupal] = {
14-
:locations => ["sites/default/settings.php"],
15-
:regex => {
16-
:dbname => Regexp.new("^\\$db_url.*?\\/\\/.*?\\/(.*?)'"),
17-
:dbuser => Regexp.new("^\\$db_url.*?\\/\\/(.*)?:.*?'"),
18-
:dbpass => Regexp.new("^\\$db_url.*?\\/\\/.*?:(.*)?@.*?'"),
19-
:dbhost => Regexp.new("^\\$db_url.*?\\/\\/.*?@(.*)?\\/.*?'"),
20-
},
21-
}
22-
@@app_metadata[:gallery] = {
23-
:locations => ["config.php"],
24-
:regex => {
25-
:dbname => Regexp.new("\\$storeConfig\\['database'.*?'(.*?)'"),
26-
:dbuser => Regexp.new("\\$storeConfig\\['username'.*?'(.*?)'"),
27-
:dbpass => Regexp.new("\\$storeConfig\\['password'.*?'(.*?)'"),
28-
:dbhost => Regexp.new("\\$storeConfig\\['hostname'.*?'(.*?)'"),
29-
},
30-
}
31-
@@app_metadata[:joomla] = {
32-
:locations => ["configuration.php"],
33-
:regex => {
34-
:dbname => Regexp.new("\\$db\\s*=\\s*'(.*?)'"),
35-
:dbuser => Regexp.new("\\$user\\s*=\\s*'(.*?)'"),
36-
:dbpass => Regexp.new("\\$password\\s*=\\s*'(.*?)'"),
37-
:dbhost => Regexp.new("\\$host\\s*=\\s*'(.*?)'"),
38-
},
39-
}
40-
@@app_metadata[:mediawiki] = {
41-
:locations => ["LocalSettings.php"],
42-
:regex => {
43-
:dbname => Regexp.new("\\$wgDBname\\s*=\\s*'(.*?)'"),
44-
:dbuser => Regexp.new("\\$wgDBuser\\s*=\\s*'(.*?)'"),
45-
:dbpass => Regexp.new("\\$wgDBpassword\\s*=\\s*'(.*?)'"),
46-
:dbhost => Regexp.new("\\$wgDBserver\\s*=\\s*'(.*?)'"),
47-
},
48-
}
49-
@@app_metadata[:phpbb] = {
50-
:locations => ["config.php"],
51-
:regex => {
52-
:dbname => Regexp.new("dbname\\s*=\\s*'(.*?)'"),
53-
:dbuser => Regexp.new("dbuser\\s*=\\s*'(.*?)'"),
54-
:dbpass => Regexp.new("dbpasswd\\s*=\\s*'(.*?)'"),
55-
:dbhost => Regexp.new("dbhost\\s*=\\s*'(.*?)'"),
56-
},
57-
}
58-
@@app_metadata[:wordpress] = {
59-
:locations => ["wp-config.php"],
60-
:regex => {
61-
:dbname => Regexp.new("DB_NAME'.*?'(.*?)'"),
62-
:dbuser => Regexp.new("DB_USER'.*?'(.*?)'"),
63-
:dbpass => Regexp.new("DB_PASSWORD'.*?'(.*?)'"),
64-
:dbhost => Regexp.new("DB_HOST'.*?'(.*?)'"),
65-
},
66-
}
67-
@@app_metadata[:zencart] = {
68-
:locations => ["includes/configure.php"],
69-
:regex => {
70-
:dbname => Regexp.new("DB_DATABASE'.*?'(.*?)'"),
71-
:dbuser => Regexp.new("DB_SERVER_USERNAME'.*?'(.*?)'"),
72-
:dbpass => Regexp.new("DB_SERVER_PASSWORD'.*?'(.*?)'"),
73-
:dbhost => Regexp.new("DB_SERVER'.*?'(.*?)'"),
74-
},
75-
}
76-
77-
def initialize(app)
78-
@exists_at = []
79-
@dbname = nil
80-
@dbuser = nil
81-
@dbpass = nil
82-
@dbhost = nil
83-
self.application = app
84-
self.locations = @@app_metadata[@application][:locations]
85-
@regex = @@app_metadata[@application][:regex]
86-
end
87-
88-
def application=(app)
89-
a = String(app).downcase.to_sym
90-
if @@supported_applications.include?(a)
91-
instance_variable_set(:@application, a)
92-
else
93-
raise "That application is not supported yet."
94-
end
95-
end
96-
97-
def find_db_info
98-
locate_files
99-
@exists_at.each do |file|
100-
# puts "Searching '#{file}' for db connection info..."
101-
File.foreach(file) do |line|
102-
@dbname ||= @regex[:dbname].match(line)[1] if @regex[:dbname] === line
103-
@dbuser ||= @regex[:dbuser].match(line)[1] if @regex[:dbuser] === line
104-
@dbpass ||= @regex[:dbpass].match(line)[1] if @regex[:dbpass] === line
105-
@dbhost ||= @regex[:dbhost].match(line)[1] if @regex[:dbhost] === line
106-
@located_at = file if @dbname
107-
end
108-
end
109-
end
110-
111-
def manual_connection_string
112-
"mysql -u #{@dbuser} -p#{@dbpass} -h #{@dbhost} #{@dbname}"
113-
end
114-
115-
private
116-
def locate_files
117-
@locations.each do |loc|
118-
if File.exists?(loc)
119-
@exists_at << loc
120-
end
121-
end
122-
end
123-
end
124-
7+
require 'database_sleuth'
1258

1269
def fetch_args(args)
12710
options = OpenStruct.new
@@ -227,7 +110,7 @@ end
227110
def optimize_tables!
228111
@@options ||= fetch_args(ARGV)
229112

230-
df = DatabaseFinder.new(@@options.app_type)
113+
df = DatabaseSleuth.new(@@options.app_type)
231114
df.find_db_info
232115

233116
puts "Connect manually with:"

rbparse renamed to bin/rbparse

Lines changed: 1 addition & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -2,62 +2,7 @@
22

33
require 'optparse'
44
require 'ostruct'
5-
6-
class ApacheLogParser
7-
def self.parse(filename, rules={}, &block)
8-
rules = process_rules(rules)
9-
parse_file(filename, rules, &block)
10-
end
11-
12-
private
13-
def self.parse_line(line)
14-
m = line.match(/^(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}).*?(([0-9]{1,2})\/(.*?)\/([0-9]{4})):(([0-9]{2}):[0-9]{2}:[0-9]{2})\s*(.*?)\]\s*"([\w]*)\s(.*?)\s.*?"\s([0-9]{3})\s(.*?)\s*"(.*?)"\s*"(.*?)"/)
15-
if m
16-
{:ip => m[1],
17-
:date => m[2],
18-
:day => m[3].to_i,
19-
:month => m[4],
20-
:year => m[5].to_i,
21-
:time => m[6],
22-
:hour => m[7].to_i,
23-
:zone => m[8],
24-
:method => m[9],
25-
:resource => m[10],
26-
:status => m[11].to_i,
27-
:size => m[12],
28-
:referer => m[13],
29-
:user_agent => m[14]}
30-
else
31-
{}
32-
end
33-
end
34-
35-
def self.parse_file(filename, rules={}, &block)
36-
File.foreach(filename) do |line|
37-
parsed = parse_line(line)
38-
if rules.any?
39-
# stop parsing the file if we're past the designated hour range
40-
break if rules[:hour] && Array(parsed[:hour]).last > Array(rules[:hour]).last
41-
42-
# go to the next line if there are any rules that are not matched by this line
43-
next if rules.reject{|k,v| Array(v).include?(parsed[k]) }.any?
44-
end
45-
yield parsed
46-
end
47-
end
48-
49-
def self.process_rules(rules)
50-
#default_options = {:date => Time.now.strftime("#{"%02d" % rules[:day] || "%d"}/%h/%Y")}
51-
#rules = default_options.merge(rules)
52-
if rules[:date]
53-
rules[:day], rules[:month], rules[:year] = rules[:date].split("/")
54-
rules[:day] = rules[:day].to_i
55-
rules[:year] = rules[:year].to_i
56-
end
57-
rules
58-
end
59-
end
60-
5+
require '../lib/apache_log_parser'
616

627
class CLIGraph
638
def self.draw(dataset, title, options={})

0 commit comments

Comments
 (0)