Created
June 24, 2011 17:00
-
-
Save saml/1045199 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/python | |
| import urllib2 | |
| import urllib | |
| import base64 | |
| import json | |
| import pprint | |
| def curl(url, username=None, password=None, method='GET', data=None): | |
| '''simple HTTP util. similar to curl | |
| data should be dict. | |
| when username and password are given, it uses basic auth.''' | |
| if method == 'POST' and data is None: | |
| #force POST by putting data | |
| data = {} | |
| #print('%s %s %s:%s' % (method, url, username, password)) | |
| req = urllib2.Request(url, urllib.urlencode(data) if data is not None else None) | |
| if username is not None and password is not None: | |
| #use basic auth | |
| cred = ('%s:%s' % (username, password)).replace('\n', '') | |
| encoded = base64.encodestring(cred) | |
| req.add_header('Authorization', 'Basic ' + encoded) | |
| return urllib2.urlopen(req) | |
| class Component(object): | |
| def __init__(self, d): | |
| self.d = d | |
| self.props = {} | |
| for x in d['data'][0]['props']: | |
| if x['key'] == 'Properties': | |
| for kv in x['value']: | |
| k,v = kv.split(' = ') | |
| self.props[k] = v | |
| def is_servlet(self): | |
| for k in self.props.keys(): | |
| if k.startswith('sling.servlet'): | |
| return True | |
| return False | |
| for i in range(1,1000): | |
| url = "http://localhost:4502/system/console/components/%d.json" % i | |
| try: | |
| f = curl(url, 'admin', 'admin') | |
| d = json.load(f) | |
| c = Component(d) | |
| if c.is_servlet(): | |
| pprint.pprint(c.props) | |
| except: | |
| print('bad: %s' % url) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment