コード例 #1
0
    def run(self):
        if self.run_modal(self.ok, self.cancel):
            if self.password.get_string_value() != self.confirm.get_string_value():
                mforms.Utilities.show_error("Reset Password", "The password and its confirmation do not match. Please try again.", "OK", "", "")
                return self.run()
            
            con = self._conn.shallow_copy()
            old_multi_statements = con.parameterValues.get("CLIENT_MULTI_STATEMENTS")
            old_script = con.parameterValues.get("preInit")
            con.parameterValues["CLIENT_MULTI_STATEMENTS"] = 1
            con.parameterValues["preInit"] = "SET PASSWORD = '******'" % escape_sql_string(self.password.get_string_value())
            #con.parameterValues["preInit"] = "ALTER USER '%s'@'%s' IDENTIFIED BY '%s'" % (con.parameterValues["userName"], con.hostIdentifier.replace("Mysql@", ""), escape_sql_string(self.password.get_string_value()))
            #change_pw = "ALTER USER '%s'@'%s' IDENTIFIED BY '%s'" % (con.parameterValues["userName"], con.hostIdentifier.replace("Mysql@", ""), escape_sql_string(self.password.get_string_value())) 
            retry = False
            result = 1

            c = MySQLConnection(con, password=self.old_password.get_string_value())
            # connect to server so that preInitScript will do the password reset work
            try:
                log_info("About to connecto to MySQL Server to change expired password")
                c.connect()
            except MySQLError, e:
                if mforms.Utilities.show_error("Reset Password", str(e), "Retry", "Cancel", "") == mforms.ResultOk:
                    retry = True
                result = 0

            if retry:
                return self.run()

            return result
コード例 #2
0
    def run(self):
        if self.run_modal(self.ok, self.cancel):
            if self.password.get_string_value(
            ) != self.confirm.get_string_value():
                mforms.Utilities.show_error(
                    "Reset Password",
                    "The password and its confirmation do not match. Please try again.",
                    "OK", "", "")
                return self.run()

            con = self._conn
            old_multi_statements = con.parameterValues.get(
                "CLIENT_MULTI_STATEMENTS")
            old_script = con.parameterValues.get("preInit")
            con.parameterValues["CLIENT_MULTI_STATEMENTS"] = 1
            con.parameterValues[
                "preInit"] = "SET PASSWORD = PASSWORD('%s')" % escape_sql_string(
                    self.password.get_string_value())

            retry = False
            result = 1

            c = MySQLConnection(con,
                                password=self.old_password.get_string_value())
            # connect to server so that preInitScript will do the password reset work
            try:
                c.connect()
            except MySQLError, e:
                if mforms.Utilities.show_error("Reset Password", str(e),
                                               "Retry", "Cancel",
                                               "") == mforms.ResultOk:
                    retry = True
                result = 0
            finally:
コード例 #3
0
def get_db_connection(server_instance_settings):
    if server_instance_settings.connection:
        db_connection = MySQLConnection(server_instance_settings.connection)
        ignore_error = False
        error_location = None
        the_error = None
        try:
            db_connection.connect()
        except MySQLError, exc:
         # errors that probably just mean the server is down can be ignored (ex 2013)
         # errors from incorrect connect parameters should raise an exception
         # ex 1045: bad password
            if exc.code in (1045,):
                raise exc
            elif exc.code in (2013,):
                ignore_error = True
            error_location = exc.location
            the_error = str(exc)

            if not ignore_error:
                if Utilities.show_warning("Could not connect to MySQL Server at %s" % error_location,
                        "%s\nYou can continue but some functionality may be unavailable." % the_error,
                        "Continue Anyway", "Cancel", "") != mforms.ResultOk:
                    raise MySQLError("", 0, "")
        return db_connection
コード例 #4
0
ファイル: wb_admin_grt.py プロジェクト: Balramkewat/kizze
    def run(self):
        if self.run_modal(self.ok, self.cancel):
            if self.password.get_string_value(
            ) != self.confirm.get_string_value():
                mforms.Utilities.show_error(
                    "Reset Password",
                    "The password and its confirmation do not match. Please try again.",
                    "OK", "", "")
                return self.run()

            con = self._conn.shallow_copy()

            con.parameterValues["CLIENT_MULTI_STATEMENTS"] = 1
            if self.legacy.get_active():
                con.parameterValues[
                    "preInit"] = "SET PASSWORD = PASSWORD('%s')" % escape_sql_string(
                        self.password.get_string_value())
            else:
                con.parameterValues[
                    "preInit"] = "SET PASSWORD = '******'" % escape_sql_string(
                        self.password.get_string_value())
            retry = False
            result = 1

            c = MySQLConnection(con,
                                password=self.old_password.get_string_value())
            # connect to server so that preInitScript will do the password reset work
            try:
                log_info(
                    "About to connecto to MySQL Server to change expired password"
                )
                c.connect()
                mforms.Utilities_store_password(
                    c.connect_info.hostIdentifier,
                    c.connect_info.parameterValues.userName,
                    self.password.get_string_value())
            except MySQLError as e:
                if mforms.Utilities.show_error("Reset Password", str(e),
                                               "Retry", "Cancel",
                                               "") == mforms.ResultOk:
                    retry = True
                result = 0
            except Exception as e:
                print("Error handling expired password: %s" % str(e))

            if retry:
                return self.run()

            return result
        return 0
コード例 #5
0
def connect(connection, password):
    try:
        con = get_connection(connection)
        try:
            con.ping()
        except Exception:
            grt.send_info("Reconnecting to %s..." % connection.hostIdentifier)
            con.disconnect()
            con.connect()
            grt.send_info("Connection restablished")
    except NotConnectedError:
        con = MySQLConnection(connection, password = password)
        grt.send_info("Connecting to %s..." % connection.hostIdentifier)
        con.connect()
        grt.send_info("Connected")
        _connections[connection.__id__] = con
    return 1
コード例 #6
0
    def run(self):
        if self.run_modal(self.ok, self.cancel):
            con = self._conn
            old_multi_statements = con.parameterValues.get(
                "CLIENT_MULTI_STATEMENTS")
            old_script = con.parameterValues.get("preInit")
            con.parameterValues["CLIENT_MULTI_STATEMENTS"] = 1
            con.parameterValues[
                "preInit"] = "SET PASSWORD = PASSWORD('%s')" % escape_sql_string(
                    self.password.get_string_value())

            retry = False
            result = 1

            c = MySQLConnection(con,
                                password=self.old_password.get_string_value())
            # connect to server so that preInitScript will do the password reset work
            try:
                c.connect()
            except MySQLError, e:
                if mforms.Utilities.show_error("Reset Password", str(e),
                                               "Retry", "Cancel",
                                               "") == mforms.ResultOk:
                    retry = True
                result = 0

            if old_script is not None:
                con.parameterValues["preInit"] = old_script
            else:
                del con.parameterValues["preInit"]
            if old_multi_statements is not None:
                con.parameterValues[
                    "CLIENT_MULTI_STATEMENTS"] = old_multi_statements
            else:
                del con.parameterValues["CLIENT_MULTI_STATEMENTS"]

            if retry:
                return self.run()

            return result
コード例 #7
0
def connect(connection, password):
    try:
        con = get_connection(connection)
        try:
            con.ping()
        except Exception:
            grt.send_info("Reconnecting to %s..." % connection.hostIdentifier)
            con.disconnect()
            con.connect()
            grt.send_info("Connection restablished")
    except NotConnectedError:
        con = MySQLConnection(connection, password=password)
        host_identifier = connection.hostIdentifier
        grt.send_info("Connecting to %s..." % host_identifier)
        con.connect()
        _connections[connection.__id__] = con
        version = "Unknown version"
        result = execute_query(connection, "SHOW VARIABLES LIKE 'version'")
        if result and result.nextRow():
            version = result.stringByIndex(2)
        grt.send_info("Connected to %s, %s" % (host_identifier, version))
    return 1
コード例 #8
0
    def server_polling_thread(self):
        try:
            password = self.get_mysql_password()
            self.poll_connection = MySQLConnection(
                self.server_profile.db_connection_params, password=password)
            self.poll_connection.connect()
        except MySQLError as err:
            log_error("Error creating SQL connection for monitoring: %r\n" %
                      err)
            self.poll_connection = None
            mforms.Utilities.driver_shutdown()
            return None

        log_debug("Monitoring thread running...\n")
        time.sleep(self.status_variable_poll_interval)
        try:
            # runs in a separate thread to fetch status variables
            while self.running:
                log_debug3("Poll server status\n")
                variables = {}
                result = self.poll_connection.executeQuery(
                    "SHOW GLOBAL STATUS")
                while result and result.nextRow():
                    variables[result.stringByName(
                        "Variable_name")] = result.stringByName("Value")

                self.status_variables, self.status_variables_time = variables, time.time(
                )

                time.sleep(self.status_variable_poll_interval)
        except QueryError:
            log_error("Error in monitoring thread: %s\n" %
                      traceback.format_exc())

        log_debug("Monitoring thread done.\n")
        self.poll_connection.disconnect()
        self.poll_connection = None
        mforms.Utilities.driver_shutdown()
コード例 #9
0
    def connect_sql(self):  # from GUI thread only, throws MySQLError
        if not self.is_sql_connected():
            password = self.get_mysql_password()

            connection = MySQLConnection(
                self.server_profile.db_connection_params,
                self.sql_status_callback,
                password=password)
            try:
                connection.connect()
            except grt.UserInterrupt:
                log_debug("Cancelled connection\n")
                return

            self.sql = SQLQueryExecutor(connection)

            if self.is_sql_connected():
                # perform some server capabilities checking
                self.query_server_info()
            else:
                log_error("Failed to connect to MySQL server\n")
        else:
            log_debug("Already connected to MySQL server\n")