def authwrapper(request, *args, **kwargs): server, port, use_ssl = get_siptrack_server() if 'st_session_id' in request.session: object_store = siptracklib.connect( server, port=port, use_ssl=use_ssl, session_id=request.session['st_session_id']) if object_store.transport.cmd.hello() == 1: request.object_store = object_store try: return func(request, *args, **kwargs) except siptracklib.errors.PermissionDenied: pm = PageManager(request, 'stweb/views/perm.html') pm.render_var['request'] = request pm.render_var['pm'] = pm pm.render_var['referer'] = request.META.get( 'HTTP_REFERER', None) return pm.render() function = 'siptrackweb.views.root.login' request.session['login_prev_url'] = request.get_full_path().encode( 'utf-8') if 'searchstring' in request.POST: request.session['login_prev_url'] = '%s?searchstring=%s' % ( request.session['login_prev_url'], request.POST['searchstring'].encode('utf-8')) return HttpResponseRedirect(reverse(function, args=None))
def __init__(self, request, render_path, section = None): self.request = request server, port, use_ssl = get_siptrack_server() self.object_store = object_store = siptracklib.connect(server, port = port, use_ssl = use_ssl, session_id = request.session['st_session_id']) self.render_path = render_path self.render_var = {} self.forms = {} self.view_tree = self.object_store.view_tree # Skip this for now, it is not great for performance reasons. # self.render_var['view_list'] = \ # self.view_tree.listChildren(include = ['view']) self.render_var['searchform'] = forms.ViewSearchForm() self.render_var['username'] = request.session.get('username') self.render_var['administrator'] = request.session.get('administrator') self.render_var['write_access'] = True self.render_var['user_oid'] = request.session.get('user_oid') self.render_var['section'] = section if request.session.get('verbose', False) is True: self.render_var['verbose'] = True self.tagged_oid = None if request.session.get('tagged_oid') is not None: self._taggedOIDSetup(request.session.get('tagged_oid'))
def __init__(self, request, render_path, section = None): self.request = request server, port, use_ssl = get_siptrack_server() self.object_store = object_store = siptracklib.connect(server, port = port, use_ssl = use_ssl, session_id = request.session['st_session_id']) self.render_path = render_path self.render_var = {} self.forms = {} self.view_tree = self.object_store.view_tree # Skip this for now, it is not great for performance reasons. # self.render_var['view_list'] = \ # self.view_tree.listChildren(include = ['view']) self.render_var['searchform'] = forms.ViewSearchForm() self.render_var['username'] = request.session['username'] self.render_var['administrator'] = request.session['administrator'] self.render_var['write_access'] = True self.render_var['section'] = section if request.session.get('verbose', False) is True: self.render_var['verbose'] = True self.tagged_oid = None if request.session.get('tagged_oid') is not None: self._taggedOIDSetup(request.session.get('tagged_oid'))
def main(): args = parser.parse_args() if args.configuration: config.readfp(args.configuration) else: config.read( [ './siptrack.conf', './siptrack_local.conf', '/etc/siptrack.conf' ] ) 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'] ) # Take the first matching user user = st.view_tree.user_manager.getUserByName(args.user)[0] # Get the users connected subkeys connected_subkeys = [ x.password_key.oid for x in user.listChildren(include=['sub key']) ] if args.password: user_password = getpass('{user}\'s password: '******'name').encode('utf-8') if key_oid in connected_subkeys: # Key is already connected if args.verbose: print('{key} key is already connected'.format(key=key_name)) continue elif args.verbose: print('Connecting {key} to {user}'.format( key=key_name, user=user.username )) pw_key = st.getOID(key_oid) key_password = getpass('{key} Password: '.format(key=key_name)) user.connectPasswordKey(pw_key, user_password, key_password)
def valid_login(request, username, password): server, port, use_ssl = get_siptrack_server() try: st = siptracklib.connect(server, username, password, port = port, use_ssl = use_ssl) except siptracklib.errors.InvalidLoginError: return False request.session['st_session_id'] = st.transport.session_id request.session['username'] = username session_user = st.getSessionUser() request.session['administrator'] = session_user.administrator return True
def st_connect(): args = parser.parse_args() config.readfp(args.configuration) st = siptracklib.connect( config.get('siptrack', 'hostname'), config.get('siptrack', 'username'), config.get('siptrack', 'password'), config.get('siptrack', 'port'), use_ssl=config.getboolean('siptrack', 'ssl') ) return(st)
def main(): args = parser.parse_args() if args.configuration: config.readfp(args.configuration) else: config.read( [ './siptrack.conf', './siptrack_local.conf', '/etc/siptrack.conf' ] ) 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'] ) # Take the first matching user user = st.view_tree.user_manager.getUserByName(args.user)[0] subkey_data = [] for subkey in user.listChildren(include=['sub key']): pw_key = subkey.password_key _data = {pw_key.oid: {}} _data[pw_key.oid]['name'] = pw_key.attributes.get('name', '') subkey_data.append(_data) print(dumps(subkey_data))
def authwrapper(request, *args, **kwargs): server, port, use_ssl = get_siptrack_server() if 'st_session_id' in request.session: object_store = siptracklib.connect(server, port = port, use_ssl = use_ssl, session_id = request.session['st_session_id']) if object_store.transport.cmd.hello() == 1: request.object_store = object_store try: return func(request, *args, **kwargs) except siptracklib.errors.PermissionDenied: pm = PageManager(request, 'stweb/views/perm.html') pm.render_var['request'] = request pm.render_var['pm'] = pm pm.render_var['referer'] = request.META.get('HTTP_REFERER', None) return pm.render() function = 'siptrackweb.views.root.login' request.session['login_prev_url'] = request.get_full_path().encode('utf-8') if 'searchstring' in request.POST: request.session['login_prev_url'] = '%s?searchstring=%s' % ( request.session['login_prev_url'], request.POST['searchstring'].encode('utf-8')) return HttpResponseRedirect(reverse(function, args = None))
help=('Attribute value to search for, takes wildcards like fnmatch. ' 'Default will list any non-empty name attribute.') ) args = parser.parse_args() config.readfp(args.configuration) # Only list object class types and exit if args.list_object_types: print(object_classes) exit(0) st = siptracklib.connect( config.get('siptrack', 'hostname'), config.get('siptrack', 'username'), config.get('siptrack', 'password'), config.get('siptrack', 'port'), use_ssl=config.getboolean('siptrack', 'ssl') ) # Use the base view defined in the configuration st_view = st.view_tree.getChildByName( config.get('siptrack', 'base_view'), include=['view'] ) # Siptrack device tree st_dt = st_view.listChildren(include=['device tree'])[0] if args.device_path: st_root = get_category_by_path(st_dt, args.device_path)
def main(): args = parser.parse_args() # Override configuration with file provided on cli if args.config_file: config.readfp(args.config_file) if args.verbose == 2: print('Connecting to {0}'.format( config.get('vcenter', 'hostname') )) try: si = SmartConnect( host=config.get('vcenter', 'hostname'), user=config.get('vcenter', 'username'), pwd=config.get('vcenter', 'password'), port=int(config.get('vcenter', 'port')) ) except Exception as e: print( 'Could not connect to vcenter server: {0}'.format( str(e) ), file=stderr ) exit(-1) atexit.register(Disconnect, si) st = siptracklib.connect( config.get('siptrack', 'hostname'), config.get('siptrack', 'username'), config.get('siptrack', 'password'), use_ssl=False ) # Find the root for siptrack operations st_view = st.view_tree.getChildByName( config.get('import', 'base_view'), include=['view'] ) st_dt = st_view.listChildren(include=['device tree'])[0] _st_com = st_dt # Find the last component of the device category path for com in args.device_path.split(args.path_separator): _st_com = _st_com.getChildByName(com.encode('utf-8')) if not _st_com: if args.verbose: print('Device path not found, exiting', file=stderr) exit(1) st_root_category = _st_com # Find the network tree to use st_nt = st_view.getChildByName( # Siptrack is picky about the unicode attribute values config.get('import', 'network_tree').decode('utf-8'), include=['network tree'] ) # Create network tree if not found if not st_nt: if args.verbose: print('Could not find network tree {0}, creating it'.format( config.get('import', 'network_tree') )) if args.dry_run: print('Dry-run, skipping creation of network tree') else: st_nt = st_view.add('network tree', 'ipv4') st_nt.attributes['name'] = config.get('import', 'network_tree') content = si.RetrieveContent() # Loop through each parent entity recursively for child in content.rootFolder.childEntity: traverse_entities(st_root_category, st_dt, st_nt, child)