Beispiel #1
0
def check_for_software_updates(flash_message=False):
    """Check for a new release of Invenio.

    :return: True if you have latest version, else False if you need to upgrade
             or None if server was not reachable.
    """
    from invenio.config import CFG_VERSION
    from invenio.base.i18n import _
    try:
        find = re.compile('Invenio v[0-9]+.[0-9]+.[0-9]+(\-rc[0-9])?'
                          ' is released')

        release_notes = 'https://raw.githubusercontent.com/' \
            'inveniosoftware/invenio/master/RELEASE-NOTES'

        webFile = urllib.request.urlopen(release_notes)

        temp = ""
        version = ""
        version1 = ""
        while 1:
            temp = webFile.readline()
            match1 = find.match(temp)
            try:
                version = match1.group()
                break
            except Exception:
                pass
            if not temp:
                break

        webFile.close()
        submatch = re.compile('[0-9]+.[0-9]+.[0-9]+(\-rc[0-9])?')
        version1 = submatch.search(version)
        web_version = version1.group().split(".")

        local_version = CFG_VERSION.split(".")

        if (web_version[0] > local_version[0] or
                web_version[0] == local_version[0] and
                web_version[1] > local_version[1] or
                web_version[0] == local_version[0] and
                web_version[1] == local_version[1] and
                web_version[2] > local_version[2]):
            if flash_message:
                flash(_('A newer version of Invenio is available for '
                        'download. You may want to visit '
                        '<a href="%(wiki)s">%()s</a>',
                        wiki='<a href=\"http://invenio-software.org/wiki/'
                             '/Installation/Download'), 'warning')

            return False
    except Exception as e:
        print(e)
        if flash_message:
            flash(_('Cannot download or parse release notes '
                    'from %(release_notes)s', release_notes=release_notes),
                  'error')
        return None
    return True
Beispiel #2
0
def check_for_software_updates(flash_message=False):
    """Check for a new release of Invenio.

    @return: True if you have latest version, else False if you need to upgrade,
             or None if server was not reachable.
    """
    from invenio.config import CFG_VERSION
    from invenio.webinterface_handler_flask_utils import _
    try:
        find = re.compile('Invenio v[0-9]+.[0-9]+.[0-9]+(\-rc[0-9])?'
                          ' is released')

        webFile = urllib.urlopen("http://invenio-software.org/repo"
                                 "/invenio/tree/RELEASE-NOTES")

        temp = ""
        version = ""
        version1 = ""
        while 1:
            temp = webFile.readline()
            match1 = find.match(temp)
            try:
                version = match1.group()
                break
            except:
                pass
            if not temp:
                break

        webFile.close()
        submatch = re.compile('[0-9]+.[0-9]+.[0-9]+(\-rc[0-9])?')
        version1 = submatch.search(version)
        web_version = version1.group().split(".")

        local_version = CFG_VERSION.split(".")

        if (web_version[0] > local_version[0]
                or web_version[0] == local_version[0]
                and web_version[1] > local_version[1]
                or web_version[0] == local_version[0] and web_version[1]
                == local_version[1] and web_version[2] > local_version[2]):
            if flash_message:
                flash(
                    _('A newer version of Invenio is available for '
                      'download. You may want to visit %s') %
                    ('<a href=\"http://invenio-software.org/wiki'
                     '/Installation/Download\">http://invenio-software.org'
                     '/wiki/Installation/Download</a>'), 'warning')

            return False
    except Exception as e:
        print e
        if flash_message:
            flash(
                _('Cannot download or parse release notes from http://'
                  'invenio-software.org/repo/invenio/tree/RELEASE-NOTES'),
                'error')
        return None
    return True
Beispiel #3
0
def superuser_account_warnings():
    """Check to see whether admin accounts have default / blank password etc. Returns a list"""
    warning_array = []

    #Try and connect to the mysql database with the default invenio password
    try:
        conn = MySQLdb.connect (host = CFG_DATABASE_HOST,
                                user = "******",
                                passwd = "my123p$ss",
                                db = "mysql")
        conn.close()
        warning_array.append("warning_mysql_password_equal_to_invenio_password")
    except:
        pass

    #Try and connect to the invenio database with the default invenio password
    try:
        conn = MySQLdb.connect (host = CFG_DATABASE_HOST,
                                user = "******",
                                passwd = "my123p$ss",
                                db = CFG_DATABASE_NAME)
        conn.close ()
        warning_array.append("warning_invenio_password_equal_to_default")
    except:
        pass

    #Check if the admin password is empty
    res = run_sql("SELECT password, email from user where nickname = 'admin'")
    if res:
        res1 = run_sql("SELECT email from user where nickname = 'admin' and password = AES_ENCRYPT(%s,'')", (res[0][1], ))
    else:
        # no account nick-named `admin' exists; keep on going
        res1 = []

    for user in res1:
        warning_array.append("warning_empty_admin_password")

    #Check if the admin email has been changed from the default
    if (CFG_SITE_ADMIN_EMAIL == "*****@*****.**" or CFG_SITE_SUPPORT_EMAIL == "*****@*****.**") and CFG_CERN_SITE == 0:
        warning_array.append("warning_site_support_email_equal_to_default")

    #Check for a new release of Invenio
    try:
        find = re.compile('Invenio v[0-9]+.[0-9]+.[0-9]+(\-rc[0-9])? is released')

        webFile = urllib.urlopen("http://invenio-software.org/repo/invenio/tree/RELEASE-NOTES")

        temp = ""
        version = ""
        version1 = ""
        while 1:
            temp = webFile.readline()
            match1 = find.match(temp)
            try:
                version = match1.group()
                break
            except:
                pass
            if not temp:
                break

        webFile.close()
        submatch = re.compile('[0-9]+.[0-9]+.[0-9]+(\-rc[0-9])?')
        version1 = submatch.search(version)
        web_version = version1.group().split(".")

        local_version = CFG_VERSION.split(".")

        if web_version[0] > local_version[0]:
            warning_array.append("note_new_release_available")
        elif web_version[0] == local_version[0] and web_version[1] > local_version[1]:
            warning_array.append("note_new_release_available")
        elif web_version[0] == local_version[0] and web_version[1] == local_version[1] and web_version[2] > local_version[2]:
            warning_array.append("note_new_release_available")
    except:
        warning_array.append("error_cannot_download_release_notes")

    return warning_array
Beispiel #4
0
def superuser_account_warnings():
    """Check to see whether admin accounts have default / blank password etc. Returns a list"""
    warning_array = []

    #Try and connect to the mysql database with the default invenio password
    try:
        conn = MySQLdb.connect (host = CFG_DATABASE_HOST,
                                user = "******",
                                passwd = "my123p$ss",
                                db = "mysql")
        conn.close()
        warning_array.append("warning_mysql_password_equal_to_invenio_password")
    except:
        pass

    #Try and connect to the invenio database with the default invenio password
    try:
        conn = MySQLdb.connect (host = CFG_DATABASE_HOST,
                                user = "******",
                                passwd = "my123p$ss",
                                db = CFG_DATABASE_NAME)
        conn.close ()
        warning_array.append("warning_invenio_password_equal_to_default")
    except:
        pass

    #Check if the admin password is empty
    res = run_sql("SELECT password, email from user where nickname = 'admin'")
    if res:
        res1 = run_sql("SELECT email from user where nickname = 'admin' and password = AES_ENCRYPT(%s,'')", (res[0][1], ))
    else:
        # no account nick-named `admin' exists; keep on going
        res1 = []

    for user in res1:
        warning_array.append("warning_empty_admin_password")

    #Check if the admin email has been changed from the default
    if (CFG_SITE_ADMIN_EMAIL == "*****@*****.**" or CFG_SITE_SUPPORT_EMAIL == "*****@*****.**") and CFG_CERN_SITE == 0:
        warning_array.append("warning_site_support_email_equal_to_default")

    #Check for a new release of Invenio
    try:
        find = re.compile('Invenio v[0-9]+.[0-9]+.[0-9]+(\-rc[0-9])? is released')

        webFile = urllib.urlopen("http://invenio-software.org/repo/invenio/tree/RELEASE-NOTES")

        temp = ""
        version = ""
        version1 = ""
        while 1:
            temp = webFile.readline()
            match1 = find.match(temp)
            try:
                version = match1.group()
                break
            except:
                pass
            if not temp:
                break

        webFile.close()
        submatch = re.compile('[0-9]+.[0-9]+.[0-9]+(\-rc[0-9])?')
        version1 = submatch.search(version)
        web_version = version1.group().split(".")

        local_version = CFG_VERSION.split(".")

        if web_version[0] > local_version[0]:
            warning_array.append("note_new_release_available")
        elif web_version[0] == local_version[0] and web_version[1] > local_version[1]:
            warning_array.append("note_new_release_available")
        elif web_version[0] == local_version[0] and web_version[1] == local_version[1] and web_version[2] > local_version[2]:
            warning_array.append("note_new_release_available")
    except:
        warning_array.append("error_cannot_download_release_notes")

    return warning_array