Ejemplo n.º 1
0
    def getConnectionManageRefresh(self, guacHostname, username, password,
                                   url_path, method):
        logging.debug("getConnectionManageStatus(): instantiated")
        self.writeStatus = ConnectionManage.CONNECTION_MANAGE_REFRESHING
        try:
            self.lock.acquire()
            self.usersConnsStatus.clear()
            guacConn = Guacamole(guacHostname,
                                 username=username,
                                 password=password,
                                 url_path=url_path,
                                 method=method)
            #username, connName/VMName, userStatus (admin/etc.), connStatus (connected/not)
            users = guacConn.get_users()

            connIDsNames = {}
            activeConns = {}
            allConnections = guacConn.get_connections()
            if 'childConnections' in allConnections:
                for conn in guacConn.get_connections()['childConnections']:
                    connIDsNames[conn['identifier']] = conn['name']
            guac_activeConns = guacConn.get_active_connections()
            for conn in guac_activeConns:
                activeConns[(
                    guac_activeConns[conn]["username"],
                    guac_activeConns[conn]["connectionIdentifier"])] = True

            for user in users:
                #user status first
                perm = guacConn.get_permissions(user)
                user_perm = "not_found"
                if "READ" in perm['userPermissions'][user]:
                    user_perm = "Non-Admin"
                if "ADMINISTER" in perm['userPermissions'][user]:
                    user_perm = "Admin"
                #next, get the list of connections and the names of those connections and their status associated with those connections
                for connID in perm['connectionPermissions']:
                    active = "not_connected"
                    #if the connection is in an active state (exists in our activeConns dict), then state it as such
                    if (user, connID) in activeConns:
                        active = "connected"
                    self.usersConnsStatus[(user, connIDsNames[connID])] = {
                        "user_status": user_perm,
                        "connStatus": active
                    }

        except Exception as e:
            logging.error(
                "Error in getConnectionManageStatus(). Did not remove connection or relation!"
            )
            exc_type, exc_value, exc_traceback = sys.exc_info()
            trace_back = traceback.extract_tb(exc_traceback)
            #traceback.print_exception(exc_type, exc_value, exc_traceback)
            return None
        finally:
            self.lock.release()
            self.writeStatus = ConnectionManage.CONNECTION_MANAGE_COMPLETE
Ejemplo n.º 2
0
    def runClearAllConnections(self, guacHostname, username, password,
                               url_path, method):
        self.writeStatus = ConnectionManage.CONNECTION_MANAGE_REMOVING
        #sample guacConn = Guacamole(192.168.99.102',username='******',password='******',url_path='/guacamole',method='http')
        logging.debug("runClearAllConnections(): guacHostname: " +
                      str(guacHostname) + " username/pass: "******" url_path: " + url_path + " method: " + str(method))
        guacConn = Guacamole(guacHostname,
                             username=username,
                             password=password,
                             url_path=url_path,
                             method=method)
        if guacConn == None:
            logging.error("Error with guac connection... skipping: " +
                          str(guacHostname) + " " + str(username))
            self.writeStatus = ConnectionManage.CONNECTION_MANAGE_COMPLETE
            return -1

        # Get list of all users
        usernames = guacConn.get_users()
        for username in usernames:
            logging.debug("Removing Username: "******"runClearAllConnections(): Error in runClearAllConnections(): when trying to remove user."
                )
                exc_type, exc_value, exc_traceback = sys.exc_info()
                #traceback.print_exception(exc_type, exc_value, exc_traceback)
        # Remove All Connections
        connections = guacConn.get_connections()
        logging.debug("Retrieved Connections: " + str(connections))
        if "childConnections" in connections:
            for connection in connections["childConnections"]:
                logging.debug("Removing Connection: " + str(connection))
                try:
                    guacConn.delete_connection(connection["identifier"])
                except Exception:
                    logging.error(
                        "runClearAllConnections(): Error in runClearAllConnections(): when trying to remove connection."
                    )
                    exc_type, exc_value, exc_traceback = sys.exc_info()
                    #traceback.print_exception(exc_type, exc_value, exc_traceback)
        self.writeStatus = ConnectionManage.CONNECTION_MANAGE_COMPLETE