Exemple #1
0
    def check_system(self, uid=None):
        """return an error string if there are problems"""
        if uid:
            rtuid, rtpw = get_bibcat_from_prefs(uid)
        else:
            # Assume default RT user
            rtuid = CFG_BIBCATALOG_SYSTEM_RT_DEFAULT_USER
            rtpw = CFG_BIBCATALOG_SYSTEM_RT_DEFAULT_PWD

        if not rtuid and not rtpw:
            return "No valid RT user login specified"

        if not CFG_BIBCATALOG_SYSTEM == "RT":
            return "CFG_BIBCATALOG_SYSTEM is not RT though this is an RT module"
        if not CFG_BIBCATALOG_SYSTEM_RT_CLI:
            return "CFG_BIBCATALOG_SYSTEM_RT_CLI not defined or empty"
        if not os.path.exists(CFG_BIBCATALOG_SYSTEM_RT_CLI):
            return "CFG_BIBCATALOG_SYSTEM_RT_CLI " + CFG_BIBCATALOG_SYSTEM_RT_CLI + " file does not exists"

        # Check that you can execute the binary.. this is a safe call unless someone can fake CFG_BIBCATALOG_SYSTEM_RT_CLI (unlikely)
        dummy, myout, myerr = run_shell_command(CFG_BIBCATALOG_SYSTEM_RT_CLI + " help")
        helpfound = False
        if myerr.count("help") > 0:
            helpfound = True
        if not helpfound:
            return (
                "Execution of CFG_BIBCATALOG_SYSTEM_RT_CLI "
                + CFG_BIBCATALOG_SYSTEM_RT_CLI
                + " help did not produce output 'help'"
            )

        if not CFG_BIBCATALOG_SYSTEM_RT_URL:
            return "CFG_BIBCATALOG_SYSTEM_RT_URL not defined or empty"
        # Construct URL, split RT_URL at //
        if not CFG_BIBCATALOG_SYSTEM_RT_URL.startswith("http://") and not CFG_BIBCATALOG_SYSTEM_RT_URL.startswith(
            "https://"
        ):
            return "CFG_BIBCATALOG__SYSTEM_RT_URL does not start with 'http://' or 'https://'"
        httppart, siteandpath = CFG_BIBCATALOG_SYSTEM_RT_URL.split("//")
        # Assemble by http://user:password@RT_URL
        bibcatalog_rt_server = httppart + "//" + rtuid + ":" + rtpw + "@" + siteandpath

        # set as env var
        os.environ["RTUSER"] = rtuid
        os.environ["RTSERVER"] = bibcatalog_rt_server

        # try to talk to RT server
        # this is a safe call since rtpw is the only variable in it, and it is escaped
        rtpw = escape_shell_arg(rtpw)
        dummy, myout, myerr = run_shell_command(
            "echo " + rtpw + " | " + CFG_BIBCATALOG_SYSTEM_RT_CLI + " ls \"Subject like 'F00'\""
        )
        if len(myerr) > 0:
            return "could not connect to " + bibcatalog_rt_server + " " + myerr
        # finally, check that there is some sane output like tickets or 'No matching result'
        saneoutput = (myout.count("matching") > 0) or (myout.count("1") > 0)
        if not saneoutput:
            return CFG_BIBCATALOG_SYSTEM_RT_CLI + " returned " + myout + " instead of 'matching' or '1'"
        return ""
Exemple #2
0
    def check_system(self, uid=None):
        """return an error string if there are problems"""
        if uid:
            rtuid, rtpw = get_bibcat_from_prefs(uid)
        else:
            # Assume default RT user
            rtuid = CFG_BIBCATALOG_SYSTEM_RT_DEFAULT_USER
            rtpw = CFG_BIBCATALOG_SYSTEM_RT_DEFAULT_PWD

        if not rtuid and not rtpw:
            return "No valid RT user login specified"

        if not CFG_BIBCATALOG_SYSTEM == 'RT':
            return "CFG_BIBCATALOG_SYSTEM is not RT though this is an RT module"
        if not CFG_BIBCATALOG_SYSTEM_RT_CLI:
            return "CFG_BIBCATALOG_SYSTEM_RT_CLI not defined or empty"
        if not os.path.exists(CFG_BIBCATALOG_SYSTEM_RT_CLI):
            return "CFG_BIBCATALOG_SYSTEM_RT_CLI " + CFG_BIBCATALOG_SYSTEM_RT_CLI + " file does not exists"

        # Check that you can execute the binary.. this is a safe call unless someone can fake CFG_BIBCATALOG_SYSTEM_RT_CLI (unlikely)
        dummy, myout, myerr = run_shell_command(CFG_BIBCATALOG_SYSTEM_RT_CLI +
                                                " help")
        helpfound = False
        if myerr.count("help") > 0:
            helpfound = True
        if not helpfound:
            return "Execution of CFG_BIBCATALOG_SYSTEM_RT_CLI " + CFG_BIBCATALOG_SYSTEM_RT_CLI + " help did not produce output 'help'"

        if not CFG_BIBCATALOG_SYSTEM_RT_URL:
            return "CFG_BIBCATALOG_SYSTEM_RT_URL not defined or empty"
        # Construct URL, split RT_URL at //
        if not CFG_BIBCATALOG_SYSTEM_RT_URL.startswith('http://') and \
           not CFG_BIBCATALOG_SYSTEM_RT_URL.startswith('https://'):
            return "CFG_BIBCATALOG__SYSTEM_RT_URL does not start with 'http://' or 'https://'"
        httppart, siteandpath = CFG_BIBCATALOG_SYSTEM_RT_URL.split("//")
        # Assemble by http://user:password@RT_URL
        bibcatalog_rt_server = httppart + "//" + rtuid + ":" + rtpw + "@" + siteandpath

        #set as env var
        os.environ["RTUSER"] = rtuid
        os.environ["RTSERVER"] = bibcatalog_rt_server

        #try to talk to RT server
        #this is a safe call since rtpw is the only variable in it, and it is escaped
        rtpw = escape_shell_arg(rtpw)
        dummy, myout, myerr = run_shell_command("echo " + rtpw + " | " +
                                                CFG_BIBCATALOG_SYSTEM_RT_CLI +
                                                " ls \"Subject like 'F00'\"")
        if len(myerr) > 0:
            return "could not connect to " + bibcatalog_rt_server + " " + myerr
        #finally, check that there is some sane output like tickets or 'No matching result'
        saneoutput = (myout.count('matching') > 0) or (myout.count('1') > 0)
        if not saneoutput:
            return CFG_BIBCATALOG_SYSTEM_RT_CLI + " returned " + myout + " instead of 'matching' or '1'"
        return ""
 def check_system(self, uid):
     """return an error string if there are problems"""
     user_pref = invenio.webuser.get_user_preferences(uid)
     if not user_pref.has_key('bibcatalog_username'):
         return "user " + str(uid) + " has no bibcatalog_username"
     rtuid = user_pref['bibcatalog_username']
     if not user_pref.has_key('bibcatalog_password'):
         return "user " + str(uid) + " has no bibcatalog_password"
     rtpw = user_pref['bibcatalog_password']
     if not CFG_BIBCATALOG_SYSTEM == 'RT':
         return "CFG_BIBCATALOG_SYSTEM is not RT though this is an RT module"
     if not CFG_BIBCATALOG_SYSTEM_RT_CLI:
         return "CFG_BIBCATALOG_SYSTEM_RT_CLI not defined or empty"
     if not os.path.exists(CFG_BIBCATALOG_SYSTEM_RT_CLI):
         return "CFG_BIBCATALOG_SYSTEM_RT_CLI " + CFG_BIBCATALOG_SYSTEM_RT_CLI + " file does not exists"
     #check that you can execute it.. this is a safe call unless someone can fake CFG_BIBCATALOG_SYSTEM_RT_CLI (unlikely)
     dummy, myout, myerr = run_shell_command(CFG_BIBCATALOG_SYSTEM_RT_CLI +
                                             " help")
     helpfound = False
     if myerr.count("help") > 0:
         helpfound = True
     if not helpfound:
         return "Execution of CFG_BIBCATALOG_SYSTEM_RT_CLI " + CFG_BIBCATALOG_SYSTEM_RT_CLI + " help did not produce output 'help'"
     if not CFG_BIBCATALOG_SYSTEM_RT_URL:
         return "CFG_BIBCATALOG_SYSTEM_RT_URL not defined or empty"
     #construct.. split RT_URL at //
     if not CFG_BIBCATALOG_SYSTEM_RT_URL.startswith('http://') and \
        not CFG_BIBCATALOG_SYSTEM_RT_URL.startswith('https://'):
         return "CFG_BIBCATALOG__SYSTEM_RT_URL does not start with 'http://' or 'https://'"
     httppart, siteandpath = CFG_BIBCATALOG_SYSTEM_RT_URL.split("//")
     BIBCATALOG_RT_SERVER = httppart + "//" + rtuid + ":" + rtpw + "@" + siteandpath
     #set as env var
     os.environ["RTUSER"] = rtuid
     os.environ["RTSERVER"] = BIBCATALOG_RT_SERVER
     #try to talk to RT server
     #this is a safe call since rtpw is the only variable in it, and it is escaped
     rtpw = escape_shell_arg(rtpw)
     dummy, myout, myerr = run_shell_command("echo " + rtpw + " | " +
                                             CFG_BIBCATALOG_SYSTEM_RT_CLI +
                                             " ls \"Subject like 'F00'\"")
     if len(myerr) > 0:
         return "could not connect to " + BIBCATALOG_RT_SERVER + " " + myerr
     #finally, check that there is some sane output like tickets or 'No matching result'
     saneoutput = (myout.count('matching') > 0) or (myout.count('1') > 0)
     if not saneoutput:
         return CFG_BIBCATALOG_SYSTEM_RT_CLI + " returned " + myout + " instead of 'matching' or '1'"
     if not CFG_BIBCATALOG_QUEUES:
         return "CFG_BIBCATALOG_QUEUES not defined or empty"
     (username, dummy) = get_bibcat_from_prefs(uid)
     if (username is None):
         return "Cannot find user preference bibcatalog_username for uid " + str(
             uid)
     return ""
 def check_system(self, uid):
     """return an error string if there are problems"""
     user_pref = invenio.webuser.get_user_preferences(uid)
     if not user_pref.has_key('bibcatalog_username'):
         return "user " + str(uid) + " has no bibcatalog_username"
     rtuid = user_pref['bibcatalog_username']
     if not user_pref.has_key('bibcatalog_password'):
         return "user " + str(uid) + " has no bibcatalog_password"
     rtpw = user_pref['bibcatalog_password']
     if not CFG_BIBCATALOG_SYSTEM == 'RT':
         return "CFG_BIBCATALOG_SYSTEM is not RT though this is an RT module"
     if not CFG_BIBCATALOG_SYSTEM_RT_CLI:
         return "CFG_BIBCATALOG_SYSTEM_RT_CLI not defined or empty"
     if not os.path.exists(CFG_BIBCATALOG_SYSTEM_RT_CLI):
         return "CFG_BIBCATALOG_SYSTEM_RT_CLI " + CFG_BIBCATALOG_SYSTEM_RT_CLI + " file does not exists"
     #check that you can execute it.. this is a safe call unless someone can fake CFG_BIBCATALOG_SYSTEM_RT_CLI (unlikely)
     dummy, myout, myerr = run_shell_command(CFG_BIBCATALOG_SYSTEM_RT_CLI + " help")
     helpfound = False
     if myerr.count("help") > 0:
         helpfound = True
     if not helpfound:
         return "Execution of CFG_BIBCATALOG_SYSTEM_RT_CLI " + CFG_BIBCATALOG_SYSTEM_RT_CLI + " help did not produce output 'help'"
     if not CFG_BIBCATALOG_SYSTEM_RT_URL:
         return "CFG_BIBCATALOG_SYSTEM_RT_URL not defined or empty"
     #construct.. split RT_URL at //
     if not CFG_BIBCATALOG_SYSTEM_RT_URL.startswith('http://') and \
        not CFG_BIBCATALOG_SYSTEM_RT_URL.startswith('https://'):
         return "CFG_BIBCATALOG__SYSTEM_RT_URL does not start with 'http://' or 'https://'"
     httppart, siteandpath = CFG_BIBCATALOG_SYSTEM_RT_URL.split("//")
     BIBCATALOG_RT_SERVER = httppart + "//" + rtuid + ":" + rtpw + "@" + siteandpath
     #set as env var
     os.environ["RTUSER"] = rtuid
     os.environ["RTSERVER"] = BIBCATALOG_RT_SERVER
     #try to talk to RT server
     #this is a safe call since rtpw is the only variable in it, and it is escaped
     rtpw = escape_shell_arg(rtpw)
     dummy, myout, myerr = run_shell_command("echo "+rtpw+" | " + CFG_BIBCATALOG_SYSTEM_RT_CLI + " ls \"Subject like 'F00'\"")
     if len(myerr) > 0:
         return "could not connect to " + BIBCATALOG_RT_SERVER + " " + myerr
     #finally, check that there is some sane output like tickets or 'No matching result'
     saneoutput = (myout.count('matching') > 0) or (myout.count('1') > 0)
     if not saneoutput:
         return CFG_BIBCATALOG_SYSTEM_RT_CLI + " returned " + myout + " instead of 'matching' or '1'"
     if not CFG_BIBCATALOG_QUEUES:
         return "CFG_BIBCATALOG_QUEUES not defined or empty"
     (username, dummy) = get_bibcat_from_prefs(uid)
     if (username is None):
         return "Cannot find user preference bibcatalog_username for uid "+str(uid)
     return ""
    def check_system(self, uid=None):
        """return an error string if there are problems"""
        if not CFG_BIBCATALOG_SYSTEM == 'RT':
            return "CFG_BIBCATALOG_SYSTEM is not RT though this is an RT module"

        if not CFG_BIBCATALOG_SYSTEM_RT_URL:
            return "CFG_BIBCATALOG_SYSTEM_RT_URL not defined or empty"
        # Construct URL, split RT_URL at //
        if not CFG_BIBCATALOG_SYSTEM_RT_URL.startswith('http://') and \
           not CFG_BIBCATALOG_SYSTEM_RT_URL.startswith('https://'):
            return "CFG_BIBCATALOG__SYSTEM_RT_URL does not start with 'http://' or 'https://'"

        try:
            self._get_instance()
        except Exception as err:
            return "could not connect to %s: %s" % (CFG_BIBCATALOG_SYSTEM_RT_URL, err)
        return ""