Merge branch 'master' of https://git.kmlabz.com/BiztProtoBois/server
	
		
			
	
		
	
	
		
	
		
			All checks were successful
		
		
	
	
		
			
				
	
				continuous-integration/drone/push Build is passing
				
			
		
		
	
	
				
					
				
			
		
			All checks were successful
		
		
	
	continuous-integration/drone/push Build is passing
				
			This commit is contained in:
		@@ -1,10 +1,12 @@
 | 
			
		||||
import os, sys
 | 
			
		||||
import json
 | 
			
		||||
import logging
 | 
			
		||||
import os
 | 
			
		||||
import shutil
 | 
			
		||||
import sys
 | 
			
		||||
from base64 import b64encode
 | 
			
		||||
 | 
			
		||||
from Crypto.Hash import SHA256
 | 
			
		||||
from Crypto.Protocol.KDF import bcrypt, bcrypt_check
 | 
			
		||||
import json
 | 
			
		||||
import shutil
 | 
			
		||||
import logging
 | 
			
		||||
 | 
			
		||||
auth_logger = logging.getLogger('AUTH APPLICATION ')
 | 
			
		||||
auth_logger.root.setLevel(logging.INFO)
 | 
			
		||||
@@ -30,7 +32,7 @@ class Authetication:
 | 
			
		||||
                json.dump(data, outfile)
 | 
			
		||||
 | 
			
		||||
    def login(self, username: str, password: str) -> str:
 | 
			
		||||
        with open(Authetication.CONFIG_DIRECTORY_LOCATION + '\\config.txt') as json_file:
 | 
			
		||||
        with open(self.CONFIG_DIRECTORY_LOCATION + '\\config.txt') as json_file:
 | 
			
		||||
            data = json.load(json_file)
 | 
			
		||||
 | 
			
		||||
        for user in data['user']:
 | 
			
		||||
@@ -46,7 +48,7 @@ class Authetication:
 | 
			
		||||
        return user['homeDir']
 | 
			
		||||
 | 
			
		||||
    def checkUserExists(self, username: str) -> bool:
 | 
			
		||||
        with open(Authetication.CONFIG_DIRECTORY_LOCATION + '\\config.txt') as json_file:
 | 
			
		||||
        with open(self.CONFIG_DIRECTORY_LOCATION + '\\config.txt') as json_file:
 | 
			
		||||
            data = json.load(json_file)
 | 
			
		||||
 | 
			
		||||
        for user in data['user']:
 | 
			
		||||
@@ -67,7 +69,7 @@ class Authetication:
 | 
			
		||||
        b64pwd = b64encode(SHA256.new(bytePass).digest())
 | 
			
		||||
        bcrypt_hash = bcrypt(b64pwd, 12)
 | 
			
		||||
 | 
			
		||||
        with open(Authetication.CONFIG_DIRECTORY_LOCATION + '\\config.txt') as json_file:
 | 
			
		||||
        with open(self.CONFIG_DIRECTORY_LOCATION + '\\config.txt') as json_file:
 | 
			
		||||
            data = json.load(json_file)
 | 
			
		||||
 | 
			
		||||
        user = {
 | 
			
		||||
 
 | 
			
		||||
@@ -1,2 +1,80 @@
 | 
			
		||||
#!/usr/bin/env python3
 | 
			
		||||
 | 
			
		||||
import os
 | 
			
		||||
import re
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class Executor:
 | 
			
		||||
    """This class executes commands recieved by the server"""
 | 
			
		||||
 | 
			
		||||
    def __init__(self, currentDiectory: str, baseDir: str = ""):
 | 
			
		||||
        self.currentDirectory = currentDiectory
 | 
			
		||||
        if baseDir == "":
 | 
			
		||||
            self.baseDir = self.currentDirectory
 | 
			
		||||
        else:
 | 
			
		||||
            self.baseDir = baseDir
 | 
			
		||||
 | 
			
		||||
    def sanitizeDirectory(self, inDirectory: str) -> str:
 | 
			
		||||
        return re.sub('[^a-zA-Z0-9]', '', inDirectory)
 | 
			
		||||
 | 
			
		||||
    def sanitizeFile(self, inFile: str) -> str:
 | 
			
		||||
        return re.sub('[^a-zA-Z0-9].[^a-zA-Z0-9]', '', inFile)
 | 
			
		||||
 | 
			
		||||
    def createDirectory(self, dirName: str) -> str:
 | 
			
		||||
        dirName = self.sanitizeDirectory(dirName)
 | 
			
		||||
        actualDirName = os.path.join(self.currentDirectory, dirName)
 | 
			
		||||
        os.mkdir(actualDirName)
 | 
			
		||||
        return actualDirName
 | 
			
		||||
 | 
			
		||||
    def removeDirectory(self, dirName: str) -> str:
 | 
			
		||||
        dirName = self.sanitizeDirectory(dirName)
 | 
			
		||||
        actualDirName = os.path.join(self.currentDirectory, dirName)
 | 
			
		||||
        os.rmdir(actualDirName)
 | 
			
		||||
        return actualDirName
 | 
			
		||||
 | 
			
		||||
    def getCurrentDirectory(self) -> str:
 | 
			
		||||
        return self.currentDirectory
 | 
			
		||||
 | 
			
		||||
    def setCurrentDirectory(self, dirName: str) -> str:
 | 
			
		||||
        if dirName == "..":
 | 
			
		||||
            if self.currentDirectory == self.baseDir:
 | 
			
		||||
                return self.currentDirectory
 | 
			
		||||
            else:
 | 
			
		||||
                directories = self.currentDirectory.split("/")
 | 
			
		||||
                strdirectory = ""
 | 
			
		||||
                for dir in directories:
 | 
			
		||||
                    strdirectory += dir + "/"
 | 
			
		||||
                    strdirectory = strdirectory[:-3]
 | 
			
		||||
                self.currentDirectory = strdirectory
 | 
			
		||||
                return self.currentDirectory
 | 
			
		||||
        else:
 | 
			
		||||
            dirName = self.sanitizeDirectory(dirName)
 | 
			
		||||
            self.currentDirectory = os.path.join(self.currentDirectory, dirName)
 | 
			
		||||
            return self.currentDirectory
 | 
			
		||||
 | 
			
		||||
    def listCurrentDirectoryContent(self) -> str:
 | 
			
		||||
        contents = os.listdir(self.currentDirectory)
 | 
			
		||||
        strdirectory = ""
 | 
			
		||||
        for content in contents:
 | 
			
		||||
            strdirectory += content + ", "
 | 
			
		||||
        strdirectory = strdirectory[:-1]
 | 
			
		||||
        return strdirectory
 | 
			
		||||
 | 
			
		||||
    def putFileInCurrentDirectory(self, filename: str, content) -> str:
 | 
			
		||||
        filename = self.sanitizeFile(filename)
 | 
			
		||||
        currenctfile = os.path.join(self.currentDirectory, filename)
 | 
			
		||||
        f = open(currenctfile, "wb")
 | 
			
		||||
        f.write(content)
 | 
			
		||||
        f.close()
 | 
			
		||||
        return currenctfile
 | 
			
		||||
 | 
			
		||||
    def getFileInCurrentDirectory(self, file: str):
 | 
			
		||||
        file = self.sanitizeFile(file)
 | 
			
		||||
        currentfile = os.path.join(self.currentDirectory, file)
 | 
			
		||||
        return open(currentfile, "r")
 | 
			
		||||
 | 
			
		||||
    def removeFileInCurrentDirectory(self, file: str) -> str:
 | 
			
		||||
        file = self.sanitizeFile(file)
 | 
			
		||||
        currentfile = os.path.join(self.currentDirectory, file)
 | 
			
		||||
        os.remove(currentfile)
 | 
			
		||||
        return currentfile
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user