diff --git a/src/platform/glassfish/authenticate.py b/src/platform/glassfish/authenticate.py index 6c1de18..b3804a3 100644 --- a/src/platform/glassfish/authenticate.py +++ b/src/platform/glassfish/authenticate.py @@ -25,7 +25,7 @@ def checkAuth(ip, port, title): if title == GINTERFACES.GAD: - url = 'https://{0}:{1}/management/domain'.format(ip, port) + url = 'http://{0}:{1}/management/domain'.format(ip, port) # check with given auth if state.usr_auth: diff --git a/src/platform/glassfish/auxiliary/list_wars.py b/src/platform/glassfish/auxiliary/list_wars.py index 3dff1f8..d5b0324 100644 --- a/src/platform/glassfish/auxiliary/list_wars.py +++ b/src/platform/glassfish/auxiliary/list_wars.py @@ -41,6 +41,12 @@ def run(self, fingerengine, fingerprint): LOG.ERROR) return + if fingerprint.version in ['3.0']: + base = base.replace('https', 'http') + uri = '/management/domain/applications/application' + return self._parse_old(base + uri, cookie) + + response = utility.requests_get(base+uri, auth=cookie, headers=headers) if response.status_code is 200: @@ -52,3 +58,24 @@ def run(self, fingerengine, fingerprint): utility.Msg("Discovered %d deployed apps" % len(data['properties'])) for entry in data['properties'].keys(): utility.Msg(' /%s' % entry) + + def _parse_old(self, url, cookie): + """ Of course 3.0 doesn't expose list-applications ... + """ + + headers = { + "Accept" : "application/json", + "X-Requested-By" : "requests" + } + + response = utility.requests_get(url, auth=cookie, headers=headers) + if response.status_code is 200: + + data = json.loads(response.content) + if not u"Child Resources" in data.keys(): + utility.Msg("No apps found") + return + + for entry in data[u"Child Resources"]: + splt = entry.rsplit('/',1 )[1] + utility.Msg(" /%s" % splt) diff --git a/src/platform/glassfish/deployers/admin_upload.py b/src/platform/glassfish/deployers/admin_upload.py index d7fa91b..a5088b7 100644 --- a/src/platform/glassfish/deployers/admin_upload.py +++ b/src/platform/glassfish/deployers/admin_upload.py @@ -3,16 +3,20 @@ from src.module.deploy_utils import parse_war_path from os.path import abspath from log import LOG +import state import utility import json -versions = ['3.1', '4.0'] +versions = ['3.0', '3.1', '4.0'] title = GINTERFACES.GAD def deploy(fingerengine, fingerprint): """ Upload via the exposed REST API """ + if fingerprint.version in ['3.1', '4.0']: + state.ssl = True + war_file = fingerengine.options.deploy war_path = abspath(war_file) war_name = parse_war_path(war_file) @@ -29,19 +33,39 @@ def deploy(fingerengine, fingerprint): return utility.Msg("Preparing to deploy {0}...".format(war_file)) - base = 'https://{0}:{1}/management/domain/applications/application'\ - .format(dip, fingerprint.port) + base = 'http://{0}:{1}'.format(dip, fingerprint.port) + uri = '/management/domain/applications/application' data = { - "id" : open(war_path, 'rb'), + 'id' : open(war_path, 'rb'), 'force' : 'true' } - response = utility.requests_post(base, files=data, + response = utility.requests_post(base + uri, files=data, auth=cookie, headers=headers) if response.status_code is 200: - utility.Msg("Deployed {0} to :8080/{0}".format(war_name), LOG.SUCCESS) + + if fingerprint.version in ['3.0']: + + # GF 3.0 ignores context-root and appends a random character string to + # the name. We need to fetch it, then set it as our random_int for + # invoke support. There's also no list-wars in here... + url = base + '/management/domain/applications/application' + response = utility.requests_get(url, auth=cookie, headers=headers) + if response.status_code is 200: + + data = json.loads(response.content) + for entry in data[u"Child Resources"]: + if war_name in entry: + rand = entry.rsplit('/', 1)[1] + rand = rand.split(war_name)[1] + fingerengine.random_int = str(rand) + + utility.Msg("Deployed {0} to :8080/{0}{1}".format(war_name, rand), + LOG.SUCCESS) + else: + utility.Msg("Deployed {0} to :8080/{0}".format(war_name), LOG.SUCCESS) else: utility.Msg("Failed to deploy {0} (HTTP {1})".format(war_name, response.status_code), diff --git a/src/platform/glassfish/fingerprints/Glass3Admin.py b/src/platform/glassfish/fingerprints/Glass3Admin.py new file mode 100644 index 0000000..97d87b1 --- /dev/null +++ b/src/platform/glassfish/fingerprints/Glass3Admin.py @@ -0,0 +1,8 @@ +from src.platform.glassfish.interfaces import ManagerInterface + + +class FPrint(ManagerInterface): + + def __init__(self): + super(FPrint, self).__init__() + self.version = '3.0' diff --git a/src/platform/glassfish/fingerprints/GlassHeaders.py b/src/platform/glassfish/fingerprints/GlassHeaders.py index abdb454..e0ca5bf 100644 --- a/src/platform/glassfish/fingerprints/GlassHeaders.py +++ b/src/platform/glassfish/fingerprints/GlassHeaders.py @@ -20,6 +20,7 @@ def check(self, ip, port = None): """ versions = { + "Oracle GlassFish Server 3.0" : "3.0", "GlassFish Server Open Source Edition 3.1" : "3.1", "GlassFish Server Open Source Edition 4.0" : "4.0" } diff --git a/src/platform/glassfish/interfaces.py b/src/platform/glassfish/interfaces.py index a096ede..e90b323 100644 --- a/src/platform/glassfish/interfaces.py +++ b/src/platform/glassfish/interfaces.py @@ -37,7 +37,7 @@ def check(self, ip, port = None): response = utility.requests_get(url) if response.status_code == 404: - data = findall("Edition (.*?) *", response.content) + data = findall("Edition|Server (.*?) *", response.content) if len(data) > 0 and self.version in data[0]: # diff --git a/src/platform/glassfish/undeployer.py b/src/platform/glassfish/undeployer.py index e821e38..f6757c4 100644 --- a/src/platform/glassfish/undeployer.py +++ b/src/platform/glassfish/undeployer.py @@ -2,6 +2,7 @@ from src.platform.glassfish.interfaces import GINTERFACES from src.module.deploy_utils import parse_war_path from log import LOG +import state import utility titles = [GINTERFACES.GAD] @@ -9,7 +10,10 @@ def undeploy(fingerengine, fingerprint): """ Undeploying is quite simple via the exposed REST API """ - base = 'https://{0}:{1}'.format(fingerengine.options.ip, + if fingerprint.version in ['3.1', '4.0']: + state.ssl = True + + base = 'http://{0}:{1}'.format(fingerengine.options.ip, fingerprint.port) context = parse_war_path(fingerengine.options.undeploy) cookie = checkAuth(fingerengine.options.ip, fingerprint.port, @@ -27,8 +31,19 @@ def undeploy(fingerengine, fingerprint): utility.Msg("Preparing to undeploy %s..." % context) uri = '/management/domain/applications/application/%s' % context - response = utility.requests_delete(base + uri, auth=cookie, - headers=headers) + if fingerprint.version in ['3.0']: + + # GF 3.0 doesnt appear to support the DELETE verb + data = { + "operation" : "__deleteoperation" + } + + response = utility.requests_post(base + uri, auth=cookie, + headers=headers, + data=data) + else: + response = utility.requests_delete(base + uri, auth=cookie, + headers=headers) if response.status_code is 200: utility.Msg("'%s' undeployed successfully" % context, LOG.SUCCESS)