forked from RedHatGov/ansible-scan-jboss
-
Notifications
You must be signed in to change notification settings - Fork 0
/
scan-jboss.py
executable file
·137 lines (123 loc) · 4.93 KB
/
scan-jboss.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#!/usr/bin/env python
import multiprocessing
import os
import re
import shutil
import socket
import zipfile
"""Scans for deployed JBoss instances by searching for the
jboss-modules.jar and run.jar files and then extracting the
pom.properties file and MANIFEST.MF, respectively. The installed
JBoss instance is determined using the version property."""
__author__ = 'Rich Lucente, Jason Callaway'
__email__ = '[email protected]'
__license__ = 'Apache License Version 2.0'
__version__ = '0.1'
__status__ = 'alpha'
work_dir = '/tmp'
search_root = ['/etc', '/home', '/var', '/usr', '/opt']
#search_root = ['/Users/rlucente/demo/eap-test']
# This script finds and classifies JBoss AS instances by specific community and
# enterprise releases.
#
# Classification is simple: search for jboss-modules.jar and run.jar files and
# then extract the version from the pom.properties and MANIFEST.MF,
# respectively, to determine which distribution contained the jar.
#
# NB: This script is up to date through EAP 6.4 CP04 and WildFly 10.0.0.CR3.
classifications = {
'JBoss_4_0_0': 'JBossAS-4',
'JBoss_4_0_1_SP1': 'JBossAS-4',
'JBoss_4_0_2': 'JBossAS-4',
'JBoss_4_0_3_SP1': 'JBossAS-4',
'JBoss_4_0_4_GA': 'JBossAS-4',
'Branch_4_0': 'JBossAS-4',
'JBoss_4_2_0_GA': 'JBossAS-4',
'JBoss_4_2_1_GA': 'JBossAS-4',
'JBoss_4_2_2_GA': 'JBossAS-4',
'JBoss_4_2_3_GA': 'JBossAS-4',
'JBoss_5_0_0_GA': 'JBossAS-5',
'JBoss_5_0_1_GA': 'JBossAS-5',
'JBoss_5_1_0_GA': 'JBossAS-5',
'JBoss_6.0.0.Final': 'JBossAS-6',
'JBoss_6.1.0.Final': 'JBossAS-6',
'1.0.1.GA': 'JBossAS-7',
'1.0.2.GA': 'JBossAS-7',
'1.1.1.GA': 'JBossAS-7',
'1.2.0.CR1': 'JBossAS-7',
'1.2.0.Final': 'WildFly-8',
'1.2.2.Final': 'WildFly-8',
'1.2.4.Final': 'WildFly-8',
'1.3.0.Beta3': 'WildFly-8',
'1.3.0.Final': 'WildFly-8',
'1.3.3.Final': 'WildFly-8',
'1.3.4.Final': 'WildFly-9',
'1.4.2.Final': 'WildFly-9',
#'1.4.3.Final': 'WildFly-9',
'1.4.3.Final': 'WildFly-10',
'1.4.4.Final': 'WildFly-10',
'JBPAPP_4_2_0_GA': 'EAP-4.2',
'JBPAPP_4_2_0_GA_C': 'EAP-4.2',
'JBPAPP_4_3_0_GA': 'EAP-4.3',
'JBPAPP_4_3_0_GA_C': 'EAP-4.3',
'JBPAPP_5_0_0_GA': 'EAP-5.0.0',
'JBPAPP_5_0_1': 'EAP-5.0.1',
'JBPAPP_5_1_0': 'EAP-5.1.0',
'JBPAPP_5_1_1': 'EAP-5.1.1',
'JBPAPP_5_1_2': 'EAP-5.1.2',
'JBPAPP_5_2_0': 'EAP-5.2.0',
'1.1.2.GA-redhat-1': 'EAP-6.0.0',
'1.1.3.GA-redhat-1': 'EAP-6.0.1',
'1.2.0.Final-redhat-1': 'EAP-6.1.0',
'1.2.2.Final-redhat-1': 'EAP-6.1.1',
'1.3.0.Final-redhat-2': 'EAP-6.2',
#'1.3.3.Final-redhat-1': 'EAP-6.2',
'1.3.3.Final-redhat-1': 'EAP-6.3',
'1.3.4.Final-redhat-1': 'EAP-6.3',
'1.3.5.Final-redhat-1': 'EAP-6.3',
'1.3.6.Final-redhat-1': 'EAP-6.4',
'1.3.7.Final-redhat-1': 'EAP-6.4'
}
mod_file = 'META-INF/maven/org.jboss.modules/jboss-modules/pom.properties'
run_file = 'META-INF/MANIFEST.MF'
found_versions = []
for search_dir in search_root:
for dirpath, dirs, files in os.walk(search_dir):
for name in files:
filename = os.path.join(dirpath, name)
# Find every occurrence of the modules jar in the search roots
# (excluding redundant copies from patching).
if 'jboss-modules.jar' in filename and not '.installation/patches' in filename:
zf = zipfile.ZipFile(filename)
zf.extract(mod_file, work_dir)
pom_file = open(work_dir + '/' + mod_file, 'r')
zf.close()
for line in pom_file:
if 'version' in line:
version = line.split('=')[1]
version = version.splitlines()[0]
if version in classifications:
found_versions.append(classifications[version])
else:
found_versions.append('Unknown-JBoss-Release: ' + version)
pom_file.close()
shutil.rmtree(work_dir + '/META-INF')
# Find every occurrence of the run jar in the search roots.
if 'run.jar' in filename:
zf = zipfile.ZipFile(filename)
zf.extract(run_file, work_dir)
manifest_file = open(work_dir + '/' + run_file, 'r')
zf.close()
for line in manifest_file:
if 'Implementation-Version' in line:
line = re.sub('..*[CS]V[SN]Tag.', '', line)
line = re.sub('[\r\n]', '', line)
version = line.split(' ')[0]
if version in classifications:
found_versions.append(classifications[version])
else:
found_versions.append('Unknown-JBoss-Release: ' + version)
print('hostname=' + socket.gethostname()),
print('cores=' + str(multiprocessing.cpu_count())),
print('release='),
print(sorted(set(found_versions)))