Exemple #1
0
    def checkstatic(self, serverConfig):
        staticPath = serverConfig['STATIC_PATH']
        from os.path import exists
        from os import mkdir

        if exists(staticPath):
            from utils.showMessage import showGood
            showGood(
                goodRule="Static Found",
                Message=
                f"The static path your provided '{staticPath}' has been found")
        else:
            from utils.showMessage import showError, askForInput, showGood
            showError(
                exceptionRule="Path Error",
                Message=
                "We couldn't validate the static path you provided. make sure you're running it from the home dir."
            )

            userInput = askForInput(
                userMessage=
                "If you're sure you did run this tool from the home dir, would you like to create the static folder? "
            )
            if userInput.lower() == "y" or userInput.lower() == "yes":
                mkdir(staticPath)
                showGood(
                    goodRule="Folder Created",
                    Message=f"The static folder '{staticPath}' has been created"
                )
            else:
                pass
Exemple #2
0
    def createuser(self, serverConfig):
        from utils.dbConnections import appendData, getdbname, search
        from utils.showMessage import showGood, askForInput, coloredMessage, showError
        from config.db import __DEFAULT_DB_NAME__, __DEFAULT_DB_TABLE__

        from getpass import getpass
        from hashlib import sha256
        from os.path import exists

        if exists(getdbname(__DEFAULT_DB_NAME__)):
            FIRST_NAME = askForInput("First name: ")
            SECOND_NAME = askForInput("Second name: ")
            EMAIL = askForInput("Email: ")
            PHONE = askForInput("Phone: ")

            __DEFAULT_DB_USERNAME__ = askForInput("Username: "******"DB error",
                          Message="The username you selected already exists")
                exit()

            DB_PASSWORD = getpass(coloredMessage('Password: '******'blue'))
            DB_PASSWORD_AGAIN = getpass(
                coloredMessage('Password Confirmation: ', 'blue'))

            if DB_PASSWORD == DB_PASSWORD_AGAIN:
                pass
            else:
                showError(exceptionRule="Password Error",
                          Message="The passwords you entered doesn't match")
                exit()

            PASSWORD_BYTES = DB_PASSWORD.encode('UTF-8')

            PASSWORD_HASH = sha256(PASSWORD_BYTES).hexdigest()
            PASSWORD_HASH = str(PASSWORD_HASH)

            appendData(dbname=__DEFAULT_DB_NAME__,
                       tablename=__DEFAULT_DB_TABLE__,
                       dbConfig=[
                           FIRST_NAME, SECOND_NAME, __DEFAULT_DB_USERNAME__,
                           PASSWORD_HASH, EMAIL, PHONE, None
                       ])
            showGood(
                goodRule="\nUser created",
                Message=
                f"{__DEFAULT_DB_USERNAME__} has been added into the database: {__DEFAULT_DB_NAME__}"
            )
        else:
            showError(
                exceptionRule="Path Error",
                Message=
                "The database hasn't been created, please run migrate to create it."
            )
Exemple #3
0
 def cleanlogs(self, serverConfig):
     from utils.logsController import cleanServerLogs
     if cleanServerLogs():
         from utils.showMessage import showGood
         showGood(
             goodRule="Cleaned",
             Message="Logs has been cleaned and now the logs data is empty."
         )
     else:
         pass
Exemple #4
0
    def migrate(self, serverConfig):
        from utils.dbConnections import createDB, createTable
        from utils.showMessage import showGood, showError
        from config.db import __DEFAULT_DB_NAME__, __DEFAULT_DB_TABLE__, __DEFAULT_DB_CONFIG__

        try:
            createDB(dbname=__DEFAULT_DB_NAME__)
            showGood(
                goodRule="DB created",
                Message=f"{__DEFAULT_DB_NAME__} has been created successfully")
        except Exception as e:
            showError(exceptionRule="DB error", Message=f"{str(e)}")

        try:
            createTable(dbname=__DEFAULT_DB_NAME__,
                        tablename=__DEFAULT_DB_TABLE__,
                        dbConfig=__DEFAULT_DB_CONFIG__)
            showGood(
                goodRule="DB updated",
                Message=f"{__DEFAULT_DB_NAME__} has been updated successfully")
        except Exception as e:
            showError(exceptionRule="DB error", Message=f"{str(e)}")
Exemple #5
0
def serveServer(serverPort, defaultDocument):
    httpServer = HTTPServer(('', serverPort), serverHandler)
    showGood(
        goodRule="Server Created",
        Message=f"The Server is Running Successfully On Port {serverPort}")
    httpServer.serve_forever()