Skip to content

Instantly share code, notes, and snippets.

@stemid
Created December 16, 2016 12:18
Show Gist options
  • Save stemid/0ec9d4d60aa3788d4c1d57e773f7c66e to your computer and use it in GitHub Desktop.
Save stemid/0ec9d4d60aa3788d4c1d57e773f7c66e to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
from __future__ import print_function
try:
from configparser import RawConfigParser
except ImportError:
from ConfigParser import RawConfigParser
from json import dumps
from argparse import ArgumentParser, FileType
from pprint import pprint
import siptracklib
parser = ArgumentParser()
config = RawConfigParser()
parser.add_argument(
'-v', '--verbose',
action='count',
default=False,
dest='verbose',
help='Verbose output, use more v\'s to increase level'
)
parser.add_argument(
'-c', '--configuration', '--config',
type=FileType('r'),
help='Configuration with siptrack connection credentials'
)
def main():
args = parser.parse_args()
if args.configuration:
config.readfp(args.configuration)
st = siptracklib.connect(
config.get('siptrack', 'hostname'),
config.get('siptrack', 'username'),
config.get('siptrack', 'password'),
config.getint('siptrack', 'port'),
use_ssl=config.getboolean('siptrack', 'ssl')
)
st_view = st.view_tree.getChildByName(
config.get('siptrack', 'base_view'),
include=['view']
)
# Enumerate users in user_manager
user_manager = st.view_tree.user_manager
for user in user_manager.listChildren(include=['user active directory']):
key_names = []
for subkey in user.listChildren(include=['sub key']):
try:
pk = subkey.password_key
except siptracklib.errors.NonExistent:
continue
pk_name = pk.attributes.get('name')
key_names.append(pk_name)
print(u'{user}: {keys}'.format(
user=user.username,
keys=', '.join(key_names)
))
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment