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
def quacamole_account(email): print("Setup Guacamole account") c = Guacamole(os.environ.get("GUACAMOLE_HOST", "localhost") + ":" + os.environ.get("GUACAMOLE_PORT", "80"), os.environ.get("GUACAMOLE_USER", "guadmin"), os.environ.get("GUACAMOLE_PASS", "guadmin"), method='http', url_path='/guacamole', default_datasource=None, verify=True) # (delete)/create user in Guacamole registry with actual password... connection = os.environ.get("GUACAMOLE_CONNECTION", 1) try: c.delete_user(email) except: pass c.add_user( payload={ "username": email, # "password":password, "attributes": { "disabled": "", "expired": "", "access-window-start": "", "access-window-end": "", "valid-from": "", "valid-until": "", "timezone": "" } }) c.grant_permission(email, payload=[{ "op": "add", "path": "/connectionPermissions/{}".format(connection), "value": "READ" }])