class AdministratorCredentials(QtWidgets.QDialog) :
    """
    Class to manage the dialog to get the property number
    
    @author: Roy Nielsen
    """
    
    creds = QtCore.pyqtSignal('QString', 'QString')
    
    def __init__(self, conf, parent=None) :
        """
        Initialization method
        
        @author: Roy Nielsen
        """
        super(AdministratorCredentials, self).__init__(parent)
        
        self.ui = Ui_AdministratorCredentials()
        self.ui.setupUi(self)
        self.conf = conf
        
        self.logger = self.conf.getLogger()
        self.mu = ManageUser(logger=self.logger)
        self.rw = RunWith(self.logger)

        self.username = ""
        self.password = ""
        self.cmd = ""
        self.tmpDir = ""

        #####
        # Set up signals and slots
        self.ui.authUserButton.clicked.connect(self.isPassValid)
        self.ui.cancelButton.clicked.connect(self.rejectApp)

        self.logger.log(lp.DEBUG, "Finished initializing AdministratorCredentials Class...")

    def rejectApp(self) :
        """
        Reject slot, print a message before sending the reject signal...
        
        Author: Roy Nielsen
        """
        QtWidgets.QMessageBox.warning(self, "Warning", "You hit Cancel, exiting program.", QtWidgets.QMessageBox.Ok)
        QtCore.QCoreApplication.instance().quit()

    def isPassValid(self) :
        """
        Set the admin username and password values of the class.
        
        Author: Roy Nielsen
        """
        self.logger.log(lp.DEBUG, "Entering isPassValid in admin_creds...")
        #####
        # Grab the QString out of the QLineEdit field
        myuser = self.ui.adminName.text()

        #####
        # Convert myuser into a string
        self.username = "******" % myuser

        #####
        # Grab the QString out of the QLineEdit field
        mypass = self.ui.passwordLineEdit.text()
        
        #####
        # Convert mypass into a string
        self.password = "******" % mypass
        
        result = self.mu.authenticate(self.username, self.password)
        self.logger.log(lp.DEBUG, str(self.username) + " is an admin...")
    
        if result :
            self.logger.log(lp.DEBUG, "Authentication success...")
            self.creds.emit(self.username, self.password)
            self.accept()
        else :
            #####
            # User is an admin, report invalid password and try again...
            self.logger.log(lp.DEBUG, "Authentication test FAILURE...")
            QtWidgets.QMessageBox.warning(self, "Warning", "...Incorrect Password, please try again.", QtWidgets.QMessageBox.Ok)
        self.logger.log(lp.DEBUG, "Finished isPassValid...")
Exemple #2
0
class AdministratorCredentials(QDialog) :
    """
    Class to manage the dialog to get the property number
    
    @author: Roy Nielsen
    """
    def __init__(self, args, message_level="debug", parent=None) :
        """
        Initialization method
        
        @author: Roy Nielsen
        """
        super(AdministratorCredentials, self).__init__(parent)
        self.ui = Ui_AdministratorCredentials()
        self.ui.setupUi(self)
        self.args = args
        
        self.message_level = message_level
        self.username = ""
        self.password = ""
        self.cmd = ""
        self.tmpDir = ""

        self.progress_bar = QProgressDialog()
        self.progress_bar.setMinimum(0)
        self.progress_bar.setMaximum(0)
        self.progress_bar.setLabelText("Checking Password...")

        #####
        # Set up signals and slots
        self.connect(self.ui.authUserButton, SIGNAL("clicked()"), self.isPassValid)
        self.connect(self.ui.cancelButton, SIGNAL("clicked()"), self.rejectApp)

        #####
        # Commented out putting in the current logged in user as the default
        # user - to make more Mac-like
        #user = getpass.getuser()
        #self.ui.adminName.setText(user)

        log_message("Finished initializing AdministratorCredentials Class...", "debug", self.message_level)


    def rejectApp(self) :
        """
        Reject slot, print a message before sending the reject signal...
        
        Author: Roy Nielsen
        """
        QMessageBox.warning(self, "Warning", "You hit Cancel, exiting program.", QMessageBox.Ok)
        self.reject()


    def isPassValid(self) :
        """
        Set the admin username and password values of the class.
        
        Author: Roy Nielsen
        """
        log_message("Entering isPassValid in admin_creds...", "verbose", self.message_level)
        #####
        # Grab the QString out of the QLineEdit field
        myuser = self.ui.adminName.text()

        #####
        # Convert myuser into a string
        self.username = "******" % myuser

        #####
        # Grab the QString out of the QLineEdit field
        mypass = self.ui.passwordLineEdit.text()
        
        #####
        # Convert mypass into a string
        self.password = "******" % mypass
        
        self.progress_bar.show()
        self.progress_bar.raise_()
        if isUserOnLocalSystem(self.username, self.message_level) :
            log_message("User: "******" is a valid user...", "verbose", self.message_level)
            if checkIfUserIsAdmin(self.username, self.message_level) :
                log_message("User: "******" is a valid admin...", "verbose", self.message_level)
                result = False

                result = authenticate(self.username, self.password, self.message_level)
        
                self.progress_bar.hide()
    
                if result :
                    log_message("Authentication success...", "debug", self.message_level)
                    #####
                    # Got a valid user, with valid password, call stonix with
                    # runAsWithSudo - stonixPath is a link to the stonix app that is
                    # in the resources directory
                    stonixPath = os.path.join(getResourcesDir(), "stonix")
    
                    #####
                    # Set up progress bar
                    self.progress_bar.setLabelText("Running Stonix...")
    
                    stonixFullPath = os.path.join(getResourcesDir(), "stonix.app/Contents/MacOS/stonix")
                    self.hide()
                    
                    #####
                    # Attempt fork here, so we don't have the wrapper and stonix
                    # running and in the Dock at the same time.
                    child_pid = os.fork()
                    if child_pid == 0 :
                        print "Child Process: PID# %s" % os.getpid()
                        if self.args:
                            command = ["\"" + stonixFullPath + "\""] + self.args
                        else:
                            command = ["\"" + stonixFullPath + "\"", "-G", "-dv"]
                            
                        runAsWithSudo(self.username, self.password, command, self.message_level)
                    else:
                        print "Exiting parent process: PID# %s" % os.getpid()

                    self.progress_bar.hide()
    
                    QCoreApplication.quit()
                else :
                    #####
                    # User is an admin, report invalid password and try again...
                    self.progress_bar.hide()
                    log_message("Authentication test FAILURE...", "normal", self.message_level)
                    QMessageBox.warning(self, "Warning", "...Incorrect Password, please try again.", QMessageBox.Ok)                
    
            else :
                #####
                # Report user is not an admin
                self.progress_bar.hide()
                log_message("User: \"" + str(self.username) + "\" is not a " + \
                            "valid admin on this system", "normal", \
                            self.message_level)
                QMessageBox.warning(self, "Warning", "\"" + str(self.username) + \
                                          "\" is not a valid admin for this " + \
                                          "system, please try again.", \
                                          QMessageBox.Ok)
        else :
            self.progress_bar.hide()
            log_message("User: \"" + str(self.username) + "\" is not a valid " + \
                        "user on this system.", "normal", self.message_level)
            QMessageBox.warning(self, "Warning", "\"" + str(self.username) + \
                                      "\" is not a valid user on this " + \
                                      "system, please try again.", \
                                      QMessageBox.Ok)

        log_message("Finished isPassValid...", "verbose", self.message_level)
Exemple #3
0
class AdministratorCredentials(QDialog):
    """
    Class to manage the dialog to get the property number
    
    @author: Roy Nielsen
    """
    def __init__(self, args, message_level="debug", parent=None):
        """
        Initialization method
        
        @author: Roy Nielsen
        """
        super(AdministratorCredentials, self).__init__(parent)
        self.ui = Ui_AdministratorCredentials()
        self.ui.setupUi(self)
        self.args = args

        self.message_level = message_level
        self.username = ""
        self.password = ""
        self.cmd = ""
        self.tmpDir = ""

        self.progress_bar = QProgressDialog()
        self.progress_bar.setMinimum(0)
        self.progress_bar.setMaximum(0)
        self.progress_bar.setLabelText("Checking Password...")

        #####
        # Set up signals and slots
        self.connect(self.ui.authUserButton, SIGNAL("clicked()"),
                     self.isPassValid)
        self.connect(self.ui.cancelButton, SIGNAL("clicked()"), self.rejectApp)

        #####
        # Commented out putting in the current logged in user as the default
        # user - to make more Mac-like
        #user = getpass.getuser()
        #self.ui.adminName.setText(user)

        log_message("Finished initializing AdministratorCredentials Class...",
                    "debug", self.message_level)

    def rejectApp(self):
        """
        Reject slot, print a message before sending the reject signal...
        
        Author: Roy Nielsen
        """
        QMessageBox.warning(self, "Warning",
                            "You hit Cancel, exiting program.", QMessageBox.Ok)
        self.reject()

    def isPassValid(self):
        """
        Set the admin username and password values of the class.
        
        Author: Roy Nielsen
        """
        log_message("Entering isPassValid in admin_creds...", "verbose",
                    self.message_level)
        #####
        # Grab the QString out of the QLineEdit field
        myuser = self.ui.adminName.text()

        #####
        # Convert myuser into a string
        self.username = "******" % myuser

        #####
        # Grab the QString out of the QLineEdit field
        mypass = self.ui.passwordLineEdit.text()

        #####
        # Convert mypass into a string
        self.password = "******" % mypass

        self.progress_bar.show()
        self.progress_bar.raise_()
        if isUserOnLocalSystem(self.username, self.message_level):
            log_message("User: "******" is a valid user...",
                        "verbose", self.message_level)
            if checkIfUserIsAdmin(self.username, self.message_level):
                log_message(
                    "User: "******" is a valid admin...",
                    "verbose", self.message_level)
                result = False

                result = authenticate(self.username, self.password,
                                      self.message_level)

                self.progress_bar.hide()

                if result:
                    log_message("Authentication success...", "debug",
                                self.message_level)
                    #####
                    # Got a valid user, with valid password, call stonix with
                    # runAsWithSudo - stonixPath is a link to the stonix app that is
                    # in the resources directory
                    stonixPath = os.path.join(getResourcesDir(), "stonix")

                    #####
                    # Set up progress bar
                    self.progress_bar.setLabelText("Running Stonix...")

                    stonixFullPath = os.path.join(
                        getResourcesDir(), "stonix.app/Contents/MacOS/stonix")
                    self.hide()

                    #####
                    # Attempt fork here, so we don't have the wrapper and stonix
                    # running and in the Dock at the same time.
                    child_pid = os.fork()
                    if child_pid == 0:
                        print "Child Process: PID# %s" % os.getpid()
                        if self.args:
                            command = ["\"" + stonixFullPath + "\""
                                       ] + self.args
                        else:
                            command = [
                                "\"" + stonixFullPath + "\"", "-G", "-dv"
                            ]

                        runAsWithSudo(self.username, self.password, command,
                                      self.message_level)
                    else:
                        print "Exiting parent process: PID# %s" % os.getpid()

                    self.progress_bar.hide()

                    QCoreApplication.quit()
                else:
                    #####
                    # User is an admin, report invalid password and try again...
                    self.progress_bar.hide()
                    log_message("Authentication test FAILURE...", "normal",
                                self.message_level)
                    QMessageBox.warning(
                        self, "Warning",
                        "...Incorrect Password, please try again.",
                        QMessageBox.Ok)

            else:
                #####
                # Report user is not an admin
                self.progress_bar.hide()
                log_message("User: \"" + str(self.username) + "\" is not a " + \
                            "valid admin on this system", "normal", \
                            self.message_level)
                QMessageBox.warning(self, "Warning", "\"" + str(self.username) + \
                                          "\" is not a valid admin for this " + \
                                          "system, please try again.", \
                                          QMessageBox.Ok)
        else:
            self.progress_bar.hide()
            log_message("User: \"" + str(self.username) + "\" is not a valid " + \
                        "user on this system.", "normal", self.message_level)
            QMessageBox.warning(self, "Warning", "\"" + str(self.username) + \
                                      "\" is not a valid user on this " + \
                                      "system, please try again.", \
                                      QMessageBox.Ok)

        log_message("Finished isPassValid...", "verbose", self.message_level)