miko 0.0.3 → 0.0.4

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.
Files changed (6) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +8 -6
  3. data/bin/miko +45 -19
  4. data/lib/miko/version.rb +1 -1
  5. data/lib/miko.rb +193 -208
  6. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 172f3d99658f1ade75394e945cf6f1e5e99dbaa3
4
- data.tar.gz: 0f8cc88dec1daf571a09d9ea56c43dd3a3b4285a
3
+ metadata.gz: 5c505ce9bb9e9dfbfb265dada89ff4b1f6bb606a
4
+ data.tar.gz: a52570ad304b1e4bf6153629a1fae11ea7f32759
5
5
  SHA512:
6
- metadata.gz: 75c8055fcefa751250f4be7f5d1b956584118d93a8c3ca924005b84fec3523f75f9d9d7efda85418d42208b9c267eeae9c6d188d9916e7e8297de0e950501b86
7
- data.tar.gz: 3c93ff7eaa451a2649666b2690ef492edd707c959a686c71e1facbbeb90e4a84c8666d7c60dc0f6e3b34c466e8400467aed40985b42a80be31864d17e4dc7432
6
+ metadata.gz: dd195c05462e324c690fc37fd4af164c8c776c259e9a97bfd592096be7e08234b8acf6c03b7b0e6c91b43c2259bebb3f43d0f92773000d64d2d0cc635eaad2c8
7
+ data.tar.gz: 529f50254dfc9df9e53415b752119f353789e3b0e923b8ef5f6b27ba2e3823990b1c4e18a8a7ab5dc63d4c6623e64b27c39218e6b30efddfe207796d9fe7c5fe
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
- # Miko
1
+ # Miko 0.0.4
2
2
 
3
- Search for script installations under a cPanel account
3
+ Search for script installations versions under a account.
4
4
 
5
5
  Supported scripts ( so far ):
6
6
  - Wordpress
@@ -11,14 +11,16 @@ Supported scripts ( so far ):
11
11
  - SMF Forum
12
12
  - MyBB
13
13
  - Moodle
14
- - Prestashop
15
14
 
16
15
  ## Installation
17
-
18
- gem install miko
16
+ `` gem install miko ``
19
17
 
20
18
  ## Usage
21
- ``$ miko USERNAME``
19
+ You can try to scan for the user accoutn using the "-u"/"--user" flag which translates to /home/USER/ or use "-d"/"--directory" flag to specify an exact directoy you want to scan.
20
+ Usage: miko [OPTIONS]
21
+ -u, --user USER Username - translates into /home/USER/
22
+ -d, --directory DIRECTORY Specify directory instead username
23
+ -h, --help Display Help
22
24
 
23
25
  ## Contributing
24
26
 
data/bin/miko CHANGED
@@ -1,26 +1,52 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  $LOAD_PATH << File.join(File.dirname(__FILE__), '../lib')
4
- require "find"
5
- require "fileutils"
4
+ require 'find'
5
+ require 'fileutils'
6
6
  require 'miko'
7
+ require 'optparse'
7
8
 
8
- if ARGV.empty?
9
- puts "USAGE: miko USER"
10
- else
11
- c = Miko.new( ARGV[0] )
12
-
13
- begin
14
- c.run
15
-
16
- if c.found.empty?
17
- puts "No scripts found"
18
- else
19
- puts "Scripts detected"
20
- c.found.sort.each { |script| puts script }
21
- end
22
- rescue Exception => e
23
- puts e
24
- end
9
+ options = {}
10
+ optparse = OptionParser.new do |opts|
11
+ opts.banner = "Usage: miko [OPTIONS]"
12
+
13
+ opts.on( "-u user", "--user USER", "Username - translates into /home/USER/") do |user|
14
+ options[:user] = user
15
+ end
16
+
17
+ opts.on( "-d dir", "--directory DIRECTORY", "Specify directory instead username") do |dir|
18
+ options[:directory] = dir
19
+ end
20
+
21
+ opts.on( "-h", "--help", "Display Help") do
22
+ puts opts
23
+ exit
24
+ end
25
25
  end
26
26
 
27
+
28
+ begin
29
+ optparse.parse!
30
+ if options[:user].nil? and options[:directory].nil?
31
+ puts optparse
32
+ exit
33
+ end
34
+
35
+ c = Miko.new( options )
36
+
37
+ begin
38
+ c.run
39
+ if c.found.empty?
40
+ puts "No scripts detected"
41
+ else
42
+ puts "Scrips detected"
43
+ c.found.sort.each{ | script| puts script }
44
+ end
45
+ rescue Exception => e
46
+ puts e
47
+ end
48
+ rescue OptionParser::InvalidOption, OptionParser::MissingArgument
49
+ puts $!.to_s
50
+ puts optparse
51
+ exit
52
+ end
data/lib/miko/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Miko
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
data/lib/miko.rb CHANGED
@@ -1,211 +1,196 @@
1
1
 
2
2
  class Miko
3
- attr_accessor :user
4
- attr_accessor :directory
5
- attr_accessor :found
6
- attr_accessor :path
7
- #
8
- # Start the class
9
- def initialize( user )
10
- @user = user
11
- @directory = "/home/#{@user}/public_html"
12
- @found = []
13
- end
14
-
15
- def run
16
- if File.directory?(@directory )
17
- find_installs
18
- else
19
- raise "Directory doesn't exist"
20
- end
21
- end
22
-
23
- private
24
- def find_installs
25
- Find.find( @directory ) do |path|
26
- @path = path
27
- if File.readable?(path)
28
- if path =~ /.*\/version\.php$/
29
- find_wordpress_joomla
30
- find_moodle
31
- elsif path =~ /.*\/bootstrap.inc$/
32
- find_drupal
33
- elsif path =~ /.*\/modules\/system\/system.module$/
34
- find_drupal
35
- elsif path =~ /.*\/index.php$/
36
- find_smf_version
37
- elsif path =~ /.*\/app\/Mage.php$/
38
- find_magento_version
39
- elsif path =~ /.*\/styles\/prosilver\/template\/template.cfg$/
40
- find_phpbb_version
41
- elsif path =~/.*\/inc\/class_core.php$/
42
- find_mybb_version
43
- end
44
- else
45
- raise "Problem accessing #{path}"
46
- end
47
- end
48
- end
49
-
50
- def output( acct_home, version,script )
51
- if !version.nil?
52
- if !version.empty?
53
- @found << "#{script} #{version}\t=>\t#{acct_home}"
54
- end
55
- end
56
- end
57
- ##
58
- ## Wp and Joomla share the same filename for its version file
59
- def find_wordpress_joomla
60
- version = ""
61
- acct_home = ""
62
- script = ""
63
-
64
- File.open( @path, "r" ).each_line do |line|
65
- if ( line["wp_version ="] )
66
- version = line.split(" ")[2][/([\d.]+)/]
67
- acct_home = path.gsub("/wp-includes/version.php", "")
68
- script = "Wordpress"
69
- elsif ( line["public $RELEASE"] )
70
- version = line.split(" ")[3][/([\d.]+)/]
71
- acct_home = path.gsub("libraries/cms/version/version.php", "")
72
- script = "Joomla"
73
- elsif (line["var $RELEASE"] )
74
- version = line.split(" ")[3][/([\d.]+)/]
75
- acct_home = path.gsub("libraries/joomla/version.php", "")
76
- script = "Joomla"
77
- elsif (line["public $DEV_LEVEL" ])
78
- elsif (line["var $DEV_LEVEL"] )
79
- version << "." << line.split(" ")[3][/[0-9]/].to_s
80
- end
81
- end
82
- output( acct_home, version, script )
83
- end
84
-
85
- ##
86
- ## Find Drupal version
87
- def find_drupal
88
- version = ""
89
- acct_home = ""
90
- script = ""
91
-
92
- File.open( @path, "r").each_line do |line|
93
- if (line["define('VERSION"] )
94
- version = line.split(" ")[1][/([\d.]+)/]
95
-
96
- ## Drupal 6 / Drupal7 compatability
97
- if path =~ /.*\/modules\/system\/system.module$/
98
- acct_home = path.gsub("modules/system/system.module", "")
99
- else
100
- acct_home = path.gsub("includes/bootstrap.inc", "")
101
- end
102
-
103
- script = "Drupal"
104
- end
105
- end
106
- output( acct_home, version, script)
107
- end
108
-
109
- def find_smf_version
110
- version = ""
111
- acct_home = ""
112
- script = ""
113
-
114
- File.open( @path, "r").each_line do |line|
115
- if ( line["$forum_version"] )
116
- version = line.split("=")[1][/([\d.]+)/]
117
- acct_home = path.gsub("index.php", "")
118
- script = "SMF Forum"
119
- end
120
- end
121
- output( acct_home, version, script)
122
- end
123
-
124
- def find_magento_version
125
- acct_home = ""
126
- script = ""
127
- major = ""
128
- minor = ""
129
- revision = ""
130
- patch = ""
131
- stability = false
132
- number = ""
133
-
134
- File.open( @path, "r").each_line do |line|
135
- if ( line[/'major'.*=>.*/])
136
- major = line[/[0-9]/]
137
- script = "Magento"
138
- acct_home = path.gsub("app/Mage.php", "")
139
- elsif ( line[/'minor'.*=>.*/] )
140
- minor = line[/[0-9]/]
141
- elsif ( line[/'revision'.*=>.*/] )
142
- revision = line[/[0-9]/]
143
- elsif ( line[/'patch'.*=>.*/] )
144
- patch = line[/[0-9]/]
145
- elsif ( line[/'stability'.*=>.*/] )
146
- stability = line.split("=>")[1][/[a-z]+/]
147
- elsif ( line[/'number'.*=>.*/] )
148
- number = line.split("=>")[1][/[0-9]+/]
149
- end
150
- end
151
- if !stability.nil?
152
- version = "#{major}.#{minor}.#{revision}.#{patch}-#{stability}#{number}"
153
- else
154
- version = "#{major}.#{minor}.#{revision}.#{patch}"
155
- end
156
- output( acct_home, version, script)
157
- end
158
-
159
- ##
160
- ## phpBB version
161
- ## Versions are inside the CHANGELOG or the subsilver template
162
- def find_phpbb_version
163
- acct_home = ""
164
- script = ""
165
- version = ""
166
-
167
- File.open( @path, "r").each_line do |line|
168
- if ( line["version ="] )
169
- version = line.split("=")[1][/([\d.]+)/]
170
- acct_home = path.gsub("styles/prosilver/template/template.cfg", "")
171
- script = "phpBB"
172
- end
173
- end
174
- output( acct_home, version, script)
175
- end
176
-
177
- def find_mybb_version
178
- acct_home = ""
179
- script = ""
180
- version = ""
181
-
182
- File.open( @path, "r").each_line do |line|
183
- if ( line["public $version ="] )
184
- version = line.split("=")[1][/([\d.]+)/]
185
- acct_home = path.gsub("inc/class_core.php", "")
186
- script = "MyBB"
187
-
188
- end
189
- end
190
-
191
- output( acct_home, version, script)
192
- end
193
-
194
-
195
- def find_moodle
196
- acct_home = ""
197
- script = ""
198
- version = ""
199
-
200
- File.open(@path, "r").each_line do |line|
201
- if ( line["$release "] )
202
- version = line.split("=")[1].gsub("'", "").split(";")[0]
203
- acct_home = path.gsub("version.php", "")
204
- script = "Moodle"
205
- end
206
-
207
- end
208
-
209
- output( acct_home, version, script)
210
- end
3
+ attr_accessor :user
4
+ attr_accessor :directory
5
+ attr_accessor :found
6
+ attr_accessor :path
7
+
8
+ def initialize( option )
9
+ unless option[:user].nil?
10
+ @user = option[:user]
11
+ @directory = "/home/#{option[:user]}/public_html"
12
+ end
13
+
14
+ unless option[:directory].nil?
15
+ @directory = option[:directory]
16
+ end
17
+ @found = []
18
+ end
19
+
20
+ def run
21
+ if File.directory?(@directory )
22
+ find_installs
23
+ else
24
+ raise "Directory doesn't exist"
25
+ end
26
+ end
27
+
28
+ private
29
+ def find_installs
30
+ Find.find( @directory ) do |path|
31
+ @path = path
32
+ if File.readable?(path)
33
+ if path =~ /.*\/version\.php$/
34
+ find_wordpress_joomla
35
+ find_moodle
36
+ elsif path =~ /.*\/bootstrap.inc$/
37
+ find_drupal
38
+ elsif path =~ /.*\/modules\/system\/system.module$/
39
+ find_drupal
40
+ elsif path =~ /.*\/index.php$/
41
+ find_smf_version
42
+ elsif path =~ /.*\/app\/Mage.php$/
43
+ find_magento_version
44
+ elsif path =~ /.*\/styles\/prosilver\/template\/template.cfg$/
45
+ find_phpbb_version
46
+ elsif path =~/.*\/inc\/class_core.php$/
47
+ find_mybb_version
48
+ end
49
+ else
50
+ puts "Problem accessing #{path}"
51
+ end
52
+ end
53
+ end
54
+
55
+
56
+ def output( acct_home, version,script )
57
+ unless version.nil? or version.empty?
58
+ @found << "#{script} #{version}\t=>\t#{acct_home}"
59
+ end
60
+ end
61
+
62
+ ##
63
+ ## Wp and Joomla share the same filename for its version file
64
+ def find_wordpress_joomla
65
+ File.open( @path, "r" ).each_line do |line|
66
+ if ( line["wp_version ="] )
67
+ version = line.split(" ")[2][/([\d.]+)/]
68
+ acct_home = path.gsub("/wp-includes/version.php", "")
69
+ script = "Wordpress"
70
+ elsif ( line["public $RELEASE"] )
71
+ version = line.split(" ")[3][/([\d.]+)/]
72
+ acct_home = path.gsub("libraries/cms/version/version.php", "")
73
+ script = "Joomla"
74
+ elsif (line["var $RELEASE"] )
75
+ version = line.split(" ")[3][/([\d.]+)/]
76
+ acct_home = path.gsub("libraries/joomla/version.php", "")
77
+ script = "Joomla"
78
+ elsif (line["public $DEV_LEVEL" ])
79
+ elsif (line["var $DEV_LEVEL"] )
80
+ version << "." << line.split(" ")[3][/[0-9]/].to_s
81
+ end
82
+ # Output ony when we has a defined variable
83
+ unless defined?(version).nil?
84
+ output( acct_home, version, script )
85
+ end
86
+ end
87
+ end
88
+
89
+ ## Find Drupal version
90
+ def find_drupal
91
+ File.open( @path, "r").each_line do |line|
92
+ if (line["define('VERSION"] )
93
+ version = line.split(" ")[1][/([\d.]+)/]
94
+ ## Drupal 6 / Drupal7 compatability
95
+ if path =~ /.*\/modules\/system\/system.module$/
96
+ acct_home = path.gsub("modules/system/system.module", "")
97
+ else
98
+ acct_home = path.gsub("includes/bootstrap.inc", "")
99
+ end
100
+ script = "Drupal"
101
+ end
102
+ unless defined?(version).nil?
103
+ output( acct_home, version, script)
104
+ end
105
+ end
106
+ end
107
+
108
+ def find_smf_version
109
+ File.open( @path, "r").each_line do |line|
110
+ if ( line["$forum_version"] )
111
+ version = line.split("=")[1][/([\d.]+)/]
112
+ acct_home = path.gsub("index.php", "")
113
+ script = "SMF Forum"
114
+ end
115
+ unless defined?(version).nil?
116
+ output( acct_home, version, script)
117
+ end
118
+ end
119
+ end
120
+
121
+ def find_magento_version
122
+ File.open( @path, "r").each_line do |line|
123
+ if ( line[/'major'.*=>.*/])
124
+ major = line[/[0-9]/]
125
+ script = "Magento"
126
+ acct_home = path.gsub("app/Mage.php", "")
127
+
128
+ sec = File.read(@path)
129
+ minor = sec[/'minor'.*=>.*/][/\d/]
130
+ revision = sec[/'revision'.*=>.*/][/\d/]
131
+ patch = sec[/'patch'.*=>.*/][/\d/]
132
+ stability = sec[/'stability'.*=>.*/].split("=>")[1][/[a-z]+/]
133
+ number = sec[/'number'.*=>.*/][/\d/]
134
+
135
+ if stability.nil?
136
+ version = "#{major}.#{minor}.#{revision}.#{patch}"
137
+ else
138
+ version = "#{major}.#{minor}.#{revision}.#{patch}-#{stability}#{number}"
139
+ end
140
+ end
141
+
142
+ ## Ship it
143
+ unless defined?(version).nil?
144
+ output( acct_home, version, script)
145
+ end
146
+
147
+ end
148
+ end
149
+
150
+ ##
151
+ ## phpBB version
152
+ ## Versions are inside the CHANGELOG or the subsilver template
153
+ def find_phpbb_version
154
+ File.open( @path, "r").each_line do |line|
155
+ if ( line["version ="] )
156
+ version = line.split("=")[1][/([\d.]+)/]
157
+ acct_home = path.gsub("styles/prosilver/template/template.cfg", "")
158
+ script = "phpBB"
159
+ end
160
+
161
+ unless defined?(version).nil?
162
+ output( acct_home, version, script)
163
+ end
164
+ end
165
+
166
+ end
167
+
168
+ def find_mybb_version
169
+ File.open( @path, "r").each_line do |line|
170
+ if ( line["public $version ="] )
171
+ version = line.split("=")[1][/([\d.]+)/]
172
+ acct_home = path.gsub("inc/class_core.php", "")
173
+ script = "MyBB"
174
+ end
175
+
176
+ unless defined?(version).nil?
177
+ output( acct_home, version, script)
178
+ end
179
+ end
180
+
181
+ end
182
+
183
+
184
+ def find_moodle
185
+ File.open(@path, "r").each_line do |line|
186
+ if ( line["$release "] )
187
+ version = line.split("=")[1].gsub("'", "").split(";")[0]
188
+ acct_home = @path.gsub("version.php", "")
189
+ script = "Moodle"
190
+ end
191
+ unless defined?(version).nil?
192
+ output( acct_home, version, script)
193
+ end
194
+ end
195
+ end
211
196
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: miko
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Antun Krasic
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-06-02 00:00:00.000000000 Z
11
+ date: 2013-06-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -75,7 +75,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
75
75
  version: '0'
76
76
  requirements: []
77
77
  rubyforge_project:
78
- rubygems_version: 2.0.0
78
+ rubygems_version: 2.0.2
79
79
  signing_key:
80
80
  specification_version: 4
81
81
  summary: Locates popular script installations under account