def submit( self ): """ Returns flatten list of components (services, agents) installed on hosts returned by getHosts function """ checkUserCredentials() DN = getUserDN() group = getSelectedGroup() callback = list() request = self.request() if not 'Hostname' in request: return { "success" : "false" , "error" : "Name of the host is absent" } host = request[ 'Hostname' ] client = SystemAdministratorClient( host , None , delegatedDN=DN , delegatedGroup=group ) result = client.getOverallStatus() gLogger.debug( "Result of getOverallStatus(): %s" % result ) if not result[ "OK" ]: return { "success" : "false" , "error" : result[ "Message" ] } overall = result[ "Value" ] for record in self.flatten( overall ): record[ "Host" ] = host callback.append( record ) return { "success" : "true" , "result" : callback }
def __sendMessage(self): """ This function is used to send a mail to specific group of DIRAC user Expected parameters from request are group, title, body """ gLogger.info("Start message broadcasting") checkUserCredentials() dn = getUserDN() if not dn: error = "Certificate is not loaded in the browser or DN is absent" gLogger.error("Service response: %s" % error) return {"success": "false", "error": error} username = getUsername() if username == "anonymous": error = "Sending an anonymous message is forbidden" gLogger.error("Service response: %s" % error) return {"success": "false", "error": error} gLogger.info("DN: %s" % dn) email = gConfig.getValue("/Registry/Users/%s/Email" % username, "") gLogger.debug("/Registry/Users/%s/Email - '%s'" % (username, email)) emil = email.strip() if not email: error = "Can't find value for option /Registry/Users/%s/Email" % user gLogger.error("Service response: %s" % error) return {"success": "false", "error": error} test = ["group", "title", "body"] for i in test: if not i in request.params: error = "The required parameter %s is absent in request" % i gLogger.error("Service response: %s" % error) return {"success": "false", "error": error} group = request.params["group"] users = gConfig.getValue("/Registry/Groups/%s/Users" % group, []) if not len(users) > 0: error = "No users for %s group found" % group gLogger.error("Service response: %s" % error) return {"success": "false", "error": error} sendDict = self.getMailDict(users) if not len(sendDict) > 0: error = "Can't get a mail address for users in %s group" % group gLogger.debug("Service response: %s" % error) return {"success": "false", "error": error} gLogger.debug("Final dictionary with mails to be used %s" % sendDict) title = self.checkUnicode(request.params["title"]) gLogger.debug("email title: %s" % title) body = self.checkUnicode(request.params["body"]) gLogger.debug("email body: %s" % body) self.__messageLog(user, group, title, body) return self.sendMail(sendDict, title, body, email)
def display(self): checkUserCredentials() dn = getUserDN() user = getUsername() group = getSelectedGroup() gLogger.always("User: %s, Group: %s, DN: %s" % (user, group, dn)) templates = ["reg_%s.mako" % i for i in ["done", "form", "info"]] html = [ "reg_%s.html" % i for i in ["footer", "header", "conditions", "form", "done"] ] files = templates + html basedir = os.path.join(rootPath, "Web", "dirac", "templates") for i in files: f = os.path.join(basedir, i) if not os.path.exists(f): gLogger.error("File does not exists: %s" % f) return render("web/External.mako") if dn and user == "anonymous": upc = UserProfileClient("Registration", getRPCClient) result = upc.retrieveVar(dn) if result["OK"]: c.sent = result["Value"] return render("/reg_done.mako") else: return render("/reg_form.mako") if not dn or dn == "": return render("/reg_info.mako") if "site" not in request.params: c.select = gConfig.getValue("/Website/DefaultExternalURL", "http://diracgrid.org") return render("web/External.mako") # No idea what this code should do... if request.params.has_key("site") and len(request.params["site"]) > 0: if str(request.params["site"]) != "All": c.select = str(request.params["site"]) gLogger.debug("Request's body:") for key in request.params.keys(): if not key == "site" and len(request.params[key]) > 0: c.select = c.select + "&" + key + "=" + request.params[ key] try: gLogger.debug("%s - %s" % (key, request.params[key])) except Exception, x: gLogger.error("Exception: %s" % str(x)) pass
def display(self): checkUserCredentials() dn = getUserDN() user = getUsername() group = getSelectedGroup() gLogger.always( "User: %s, Group: %s, DN: %s" % ( user , group , dn ) ) templates = [ "reg_%s.mako" % i for i in [ "done" , "form" , "info" ] ] html = [ "reg_%s.html" % i for i in [ "footer" , "header" , "conditions" , "form" , "done" ] ] files = templates + html basedir = os.path.join( rootPath , "Web" , "dirac" , "templates" ) for i in files: f = os.path.join( basedir , i ) if not os.path.exists( f ): gLogger.error( "File does not exists: %s" % f ) return render( "web/External.mako" ) if dn and user == "anonymous": upc = UserProfileClient( "Registration" , getRPCClient ) result = upc.retrieveVar( dn ) if result[ "OK" ]: c.sent = result[ "Value" ] return render( "/reg_done.mako" ) else: return render("/reg_form.mako") if not dn or dn == "": return render("/reg_info.mako") if "site" not in request.params: c.select = gConfig.getValue( "/Website/DefaultExternalURL", "http://diracgrid.org" ) return render( "web/External.mako" ) # No idea what this code should do... if request.params.has_key( "site" ) and len( request.params[ "site" ] ) > 0: if str( request.params[ "site" ] ) != "All": c.select = str( request.params[ "site" ] ) gLogger.debug("Request's body:") for key in request.params.keys(): if not key == "site" and len(request.params[key]) > 0: c.select = c.select + "&" + key + "=" + request.params[key] try: gLogger.debug("%s - %s" % (key,request.params[key])) except Exception,x: gLogger.error("Exception: %s" % str(x)) pass
def registerUser(self): """ This function is used to notify DIRAC admins about user registration request The logic is simple: 0) Check if request from this e-mail has already registered or not 1) Send mail to VO admin of requested VO 2) Send mail to users in group with UserAdministrator property 3) Send mail to users indicated in /Website/UserRegistrationAdmin option """ gLogger.info("Start processing a registration request") checkUserCredentials() # Check for having a DN but no username dn = getUserDN() if not dn: error = "Certificate is not loaded in the browser or DN is absent" gLogger.error("Service response: %s" % error) return {"success": "false", "error": error} username = getUsername() if not username == "anonymous": error = "You are already registered in DIRAC with username: %s" % username gLogger.error("Service response: %s" % error) return {"success": "false", "error": error} gLogger.info("DN: %s" % dn) if not "email" in request.params: error = "Can not get your email address from the request" gLogger.debug("Service response: %s" % error) return {"success": "false", "error": error} userMail = request.params["email"] result = self.isRequested(userMail) gLogger.debug(result) if result["OK"]: return render("/reg_done.mako") result = self.registerRequest(dn, userMail) gLogger.debug(result) if not result["OK"]: return {"success": "false", "error": result["Message"]} vo = fromChar(request.params["vo"]) if not vo: error = "You should indicate a VirtualOrganization for membership" gLogger.debug("Service response: %s" % error) return {"success": "false", "error": error} gLogger.info("User want to be register in VO(s): %s" % vo) body = str() for i in request.params: if not i in ["registration_request", "email", "vo"]: text = self.checkUnicode(request.params[i]) info = "%s - %s" % (i, text) body = body + info + "\n" body = body + "DN - " + dn gLogger.debug("email body: %s" % body) adminList = self.__getAdminList(vo) if not len(adminList) > 0: error = "Can't get in contact with administrators about your request\n" error = error + "Most likely this DIRAC instance is not configured yet" gLogger.debug("Service response: %s" % error) return {"success": "false", "error": error} adminList = uniqueElements(adminList) gLogger.info("Chosen admin(s): %s" % adminList) sendDict = self.getMailDict(adminList) if not len(sendDict) > 0: error = "Can't get in contact with administrators about your request\n" error = error + "Most likely this DIRAC instance is not configured yet" gLogger.debug("Service response: %s" % error) return {"success": "false", "error": error} gLogger.debug("Final dictionary with mails to be used %s" % sendDict) if socket.gethostname().find('.') >= 0: hostname = socket.gethostname() else: hostname = socket.gethostbyaddr(socket.gethostname())[0] title = "New user has sent registration request to %s" % hostname return self.sendMail(sendDict, title, body, userMail)
def registerUser( self ): """ This function is used to notify DIRAC admins about user registration request The logic is simple: 0) Check if request from this e-mail has already registered or not 1) Send mail to VO admin of requested VO 2) Send mail to users in group with UserAdministrator property 3) Send mail to users indicated in /Website/UserRegistrationAdmin option """ gLogger.info("Start processing a registration request") checkUserCredentials() # Check for having a DN but no username dn = getUserDN() if not dn: error = "Certificate is not loaded in the browser or DN is absent" gLogger.error( "Service response: %s" % error ) return { "success" : "false" , "error" : error } username = getUsername() if not username == "anonymous": error = "You are already registered in DIRAC with username: %s" % username gLogger.error( "Service response: %s" % error ) return { "success" : "false" , "error" : error } gLogger.info( "DN: %s" % dn ) if not "email" in request.params: error = "Can not get your email address from the request" gLogger.debug( "Service response: %s" % error ) return { "success" : "false" , "error" : error } userMail = request.params[ "email" ] result = self.isRequested( userMail ) gLogger.debug( result ) if result[ "OK" ]: return render( "/reg_done.mako" ) result = self.registerRequest( dn , userMail ) gLogger.debug( result ) if not result[ "OK" ]: return { "success" : "false" , "error" : result[ "Message" ] } vo = fromChar( request.params[ "vo" ] ) if not vo: error = "You should indicate a VirtualOrganization for membership" gLogger.debug( "Service response: %s" % error ) return { "success" : "false" , "error" : error } gLogger.info( "User want to be register in VO(s): %s" % vo ) body = str() for i in request.params: if not i in [ "registration_request" , "email" , "vo" ]: text = self.checkUnicode( request.params[ i ] ) info = "%s - %s" % ( i , text ) body = body + info + "\n" body = body + "DN - " + dn gLogger.debug( "email body: %s" % body ) adminList = self.__getAdminList( vo ) if not len( adminList ) > 0: error = "Can't get in contact with administrators about your request\n" error = error + "Most likely this DIRAC instance is not configured yet" gLogger.debug( "Service response: %s" % error ) return { "success" : "false" , "error" : error } adminList = uniqueElements( adminList ) gLogger.info( "Chosen admin(s): %s" % adminList ) sendDict = self.getMailDict( adminList ) if not len( sendDict ) > 0: error = "Can't get in contact with administrators about your request\n" error = error + "Most likely this DIRAC instance is not configured yet" gLogger.debug( "Service response: %s" % error ) return { "success" : "false" , "error" : error } gLogger.debug( "Final dictionary with mails to be used %s" % sendDict ) if socket.gethostname().find( '.' ) >= 0: hostname = socket.gethostname() else: hostname = socket.gethostbyaddr( socket.gethostname() )[ 0 ] title = "New user has sent registration request to %s" % hostname return self.sendMail( sendDict , title , body , userMail )
def __sendMessage( self ): """ This function is used to send a mail to specific group of DIRAC user Expected parameters from request are group, title, body """ gLogger.info("Start message broadcasting") checkUserCredentials() dn = getUserDN() if not dn: error = "Certificate is not loaded in the browser or DN is absent" gLogger.error( "Service response: %s" % error ) return { "success" : "false" , "error" : error } username = getUsername() if username == "anonymous": error = "Sending an anonymous message is forbidden" gLogger.error( "Service response: %s" % error ) return { "success" : "false" , "error" : error } gLogger.info( "DN: %s" % dn ) email = gConfig.getValue( "/Registry/Users/%s/Email" % username , "" ) gLogger.debug( "/Registry/Users/%s/Email - '%s'" % ( username , email ) ) emil = email.strip() if not email: error = "Can't find value for option /Registry/Users/%s/Email" % user gLogger.error( "Service response: %s" % error ) return { "success" : "false" , "error" : error } test = [ "group" , "title" , "body" ] for i in test: if not i in request.params: error = "The required parameter %s is absent in request" % i gLogger.error( "Service response: %s" % error ) return { "success" : "false" , "error" : error } group = request.params[ "group" ] users = gConfig.getValue( "/Registry/Groups/%s/Users" % group , [] ) if not len( users ) > 0: error = "No users for %s group found" % group gLogger.error( "Service response: %s" % error ) return { "success" : "false" , "error" : error } sendDict = self.getMailDict( users ) if not len( sendDict ) > 0: error = "Can't get a mail address for users in %s group" % group gLogger.debug( "Service response: %s" % error ) return { "success" : "false" , "error" : error } gLogger.debug( "Final dictionary with mails to be used %s" % sendDict ) title = self.checkUnicode( request.params[ "title" ] ) gLogger.debug( "email title: %s" % title ) body = self.checkUnicode( request.params[ "body" ] ) gLogger.debug( "email body: %s" % body ) self.__messageLog( user , group , title , body ) return self.sendMail( sendDict , title , body , email )
def registerUser( self ): """ This function is used to notify DIRAC admins about user registration request The logic is simple: 0) Check if request from this e-mail has already registered or not 1) Send mail to VO admin of requested VO 2) Send mail to users in group with UserAdministrator property 3) Send mail to users indicated in /Website/UserRegistrationAdmin option """ gLogger.info("Start processing a registration request") checkUserCredentials() # Check for having a DN but no username dn = getUserDN() if not dn: error = "Certificate is not loaded in the browser or DN is absent" gLogger.error( "Service response: %s" % error ) return { "success" : "false" , "error" : error } username = getUsername() if not username == "anonymous": error = "You are already registered in DIRAC with username: %s" % username gLogger.error( "Service response: %s" % error ) return { "success" : "false" , "error" : error } gLogger.info( "DN: %s" % dn ) if not request.params.has_key( "email" ): error = "Can not get your email address from the request" gLogger.debug( "Service response: %s" % error ) return { "success" : "false" , "error" : error } userMail = request.params[ "email" ] if self.alreadyRequested( userMail ): error = "Request associated with %s already registered" % userMail gLogger.debug( "Service response: %s" % error ) return { "success" : "false" , "error" : error } vo = fromChar( request.params[ "vo" ] ) if not vo: error = "You should indicate a VirtualOrganization for membership" gLogger.debug( "Service response: %s" % error ) return { "success" : "false" , "error" : error } gLogger.info( "User want to be register in VO(s): %s" % vo ) body = str() for i in request.params: if not i in [ "registration_request" , "email" , "vo" ]: info = self.__checkUnicode( i , request.params[ i ] ) body = body + info + "\n" body = body + "DN - " + dn gLogger.debug( "email body: %s" % body ) adminList = self.__getAdminList( vo ) if not len( adminList ) > 0: error = "Can't get in contact with administrators about your request\n" error = error + "Most likely this DIRAC instance is not configured yet" gLogger.debug( "Service response: %s" % error ) return { "success" : "false" , "error" : error } adminList = uniqueElements( adminList ) gLogger.info( "Chosen admin(s): %s" % adminList ) sendDict = self.__getMailDict( adminList ) if not len(sendDict) > 0: error = "Can't get in contact with administrators about your request\n" error = error + "Most likely this DIRAC instance is not configured yet" gLogger.debug( "Service response: %s" % error ) return { "success" : "false" , "error" : error } gLogger.debug( "Final dictionary with mails to be used %s" % sendDict ) return self.__sendAMail( sendDict , body , userMail )