Exemplo n.º 1
0
def cut(src, dest):
    su = files.readall("/proc/info/su")
    if permissions.check(files.output(src), "r", su) and permissions.check(
            files.output(src), "w", su):
        if isfile(src):
            if permissions.check(files.output(dest), "w", su):
                if files.isdir(dest):
                    colors.show("libabr.file.cut", "fail",
                                dest + ": dest is a directory.")
                else:
                    perm = permissions.get_permissions(files.output(src))
                    control.write_record(files.output(dest), perm,
                                         "/etc/permtab")
                    files.cut(src, dest)
            else:
                colors.show("libabr.file.cut", "perm", "")
        elif isdir(src):
            if permissions.check(files.output(dest), "w", su):
                if files.isfile(dest):
                    colors.show("libabr.file.cut", "fail",
                                dest + ": dest is a file.")
                else:
                    perm = permissions.get_permissions(files.output(src))
                    control.write_record(files.output(dest), perm,
                                         "/etc/permtab")
                    files.cutdir(src, dest)
            else:
                colors.show("libabr.file.cut", "perm", "")
        else:
            colors.show("libabr.file.cut", "fail", src + ": source not found.")
    else:
        colors.show("libabr.file.cut", "perm", "")
Exemplo n.º 2
0
def set (name,value):
    select = files.readall("/proc/info/sel")
    if not select.startswith ("/proc/"):
        if permissions.check(files.output(select),"w",files.readall("/proc/info/su")):
            control.write_record(name, value, select)
            colors.show('', 'ok', "Set '" + name + "' as '"+value+"'.")
        else:
            colors.show ("set","perm","")
    else:
        control.write_record(name,value,select)
Exemplo n.º 3
0
def getv():
    select = files.readall("/proc/info/sel")
    if not select.startswith("/proc/"):
        if permissions.check(files.output(select), "w",
                             files.readall("/proc/info/su")):
            listinfo = files.list("/proc/info")
            for i in listinfo:
                control.write_record(i, files.readall("/proc/info/" + i),
                                     select)
        else:
            colors.show("getv", "perm", "")
    else:
        listinfo = files.list("/proc/info")
        for i in listinfo:
            control.write_record(i, files.readall("/proc/info/" + i), select)
    colors.show('', 'ok',
                'Insert informations into \'' + select + "\' controller.")
Exemplo n.º 4
0
def mv(src, dest):
    if files.isdir(src):
        if files.isfile(dest):
            colors.show("mv", "fail", dest + ": dest is a file.")
        else:
            if permissions.check(
                    files.output(src), "r",
                    files.readall("/proc/info/su")) and permissions.check(
                        files.output(src), "w",
                        files.readall("/proc/info/su")):
                if permissions.check(files.output(dest), "w",
                                     files.readall("/proc/info/su")):
                    perm = permissions.get_permissions(files.output(src))
                    control.write_record(files.output(dest), perm,
                                         "/etc/permtab")
                    files.copydir(src, dest)
                    files.removedirs(src)
                else:
                    colors.show("mv", "perm", "")
            else:
                colors.show("mv", "perm", "")
    elif files.isfile(src):
        if files.isdir(dest):
            colors.show("mv", "fail", dest + ": dest is a directory.")
        else:
            if permissions.check(
                    files.output(src), "r",
                    files.readall("/proc/info/su")) and permissions.check(
                        files.output(src), "w",
                        files.readall("/proc/info/su")):
                if permissions.check(files.output(dest), "w",
                                     files.readall("/proc/info/su")):
                    perm = permissions.get_permissions(files.output(src))
                    control.write_record(files.output(dest), perm,
                                         "/etc/permtab")
                    files.copy(src, dest)
                    files.remove(src)
                else:
                    colors.show("mv", "perm", "")
            else:
                colors.show("mv", "perm", "")
    else:
        colors.show("mv", "fail", src + ": source not found.")
Exemplo n.º 5
0
def uadd (input_username,user):
    if permissions.check_root(user):
        ## Check exists user ##
        if files.isfile("/etc/users/" + input_username) or input_username == "root":
            colors.show("uadd", "fail", input_username + ": user exists.")
        elif input_username == "guest":
            colors.show("uadd", "fail", "cannot create user account with guest username.")
        else:
            while True:
                password = getpass.getpass ('Enter a new password: '******'Confirm the new password: '******'\tEnter your first name []: ')
            last_name =         input ('\tEnter your last name []: ')
            company =           input ('\tEnter your company name []: ')
            birthday =          input ('\tEnter your birthday []: ')
            gender =            input ('\tChoose your gender [Male/Female/Other]: ')
            blood_type =        input ('\tChoose your blood type [O/A/B/AB]: ')
            phone =             input ('\tEnter your phone number []: ')
            website =           input ('\tEnter your website address []: ')
            email =             input ('\tEnter your email address []: ')

            hashname = hashlib.sha3_256(str(input_username).encode()).hexdigest()
            hashcode = hashlib.sha3_512(str(password).encode()).hexdigest()

            files.create ("/etc/users/"+input_username)
            control.write_record ("username",hashname,'/etc/users/'+input_username)
            control.write_record ("code",hashcode,'/etc/users/'+input_username)

            ## Add informations ##
            if not (first_name == None or first_name == ""):
                control.write_record("first_name", first_name, '/etc/users/' + input_username)
            if not (last_name == None or last_name == ""):
                control.write_record("last_name", last_name, '/etc/users/' + input_username)
            if not (company == None or company == ""):
                control.write_record ("company",company,'/etc/users/'+input_username)
            if not (birthday == None or birthday == ""):
                control.write_record("birthday", birthday, '/etc/users/' + input_username)
            if not (gender == None or gender == ""):
                control.write_record("gender", gender, '/etc/users/' + input_username)
            if not (blood_type == None or blood_type == ""):
                control.write_record("blood_type", blood_type, '/etc/users/' + input_username)
            if not (phone == None or phone == ""):
                control.write_record("phone", phone, '/etc/users/' + input_username)
            if not (website == None or website == ""):
                control.write_record("website", website, '/etc/users/' + input_username)
            if not (email == None or email == ""):
                control.write_record ("email",email,'/etc/users/'+input_username)

            permissions.create ("/desk/"+input_username,7,1,0,input_username) ## Create permission for another user

            colors.show('', 'ok', "Add '" + input_username + "' user account.")
    else:
        colors.show ("uadd","perm","")
Exemplo n.º 6
0
def create(name, user, others, guest, owner):
    if files.isfile(name) or files.isdir(name):
        ## Learned by Guru99 2020 ##
        ## Set user permissions section
        if user == 0:
            user = "******"
        elif user == 1:
            user = "******"
        elif user == 2:
            user = "******"
        elif user == 3:
            user = "******"
        elif user == 4:
            user = "******"
        elif user == 5:
            user = "******"
        elif user == 6:
            user = "******"
        elif user == 7:
            user = "******"
        else:
            user = "******"

        ## Set other users permissions section
        if others == 0:
            others = "---"
        elif others == 1:
            others = "--x"
        elif others == 2:
            others = "-w-"
        elif others == 3:
            others = "-wx"
        elif others == 4:
            others = "r--"
        elif others == 5:
            others = "r-x"
        elif others == 6:
            others = "rw-"
        elif others == 7:
            others = "rwx"
        else:
            others = "rwx"

        ## Set guest user permissions section
        if guest == 0:
            guest = "---"
        elif guest == 1:
            guest = "--x"
        elif guest == 2:
            guest = "-w-"
        elif guest == 3:
            guest = "-wx"
        elif guest == 4:
            guest = "r--"
        elif guest == 5:
            guest = "r-x"
        elif guest == 6:
            guest = "rw-"
        elif guest == 7:
            guest = "rwx"
        else:
            guest = "rwx"

        if files.isdir(name):
            control.write_record(
                name, "d" + user + others + guest + "/" + owner,
                "/etc/permtab")  # Write permissions for this directory
        else:
            control.write_record(
                name, "-" + user + others + guest + "/" + owner,
                "/etc/permtab")  # Write permissions for this file
Exemplo n.º 7
0
def shell():
    print()

    if user == "root":
        files.write("/proc/info/pwd", "/root")
    else:
        files.write("/proc/info/pwd", "/desk/" + user)

    select = files.readall("/proc/info/sel")  # Change selected database

    while True:
        if not files.isfile("/proc/selected"):
            files.write("/proc/info/sel",
                        "/proc/" + str(switch))  ## Write this controller
        ## Check the switched process ##
        process.check(switch)  # Check the switched process

        files.write("/proc/info/sp", str(switch))  # Write switched process

        if files.isfile("/tmp/su.tmp"): files.remove("/tmp/su.tmp")

        ## User configure check ##
        files.write("/proc/info/su", user)  # Write user name in info processor
        if not user == "guest":
            hashname = hashlib.sha3_256(str(user).encode()).hexdigest()
            username = control.read_record("username", "/etc/users/" + user)
            hashcode = hashlib.sha3_512(str(code).encode()).hexdigest()
            password = control.read_record("code", "/etc/users/" + user)

            if not (hostname == username) and not (password == hashcode):
                colors.show("shell", "fail-start", "")
                colors.show("kernel", "stop", "")
                sys.exit(0)
        ## PWD path setting up at all ##
        if not user == "root":
            if not files.isdir("/desk/" + user):
                files.mkdir("/desk/" + user)  # Create home folder

        ## Prompt data base ##

        show_username = control.read_record("show_username", "/etc/prompt")
        show_hostname = control.read_record("show_hostname", "/etc/prompt")
        show_path = control.read_record("show_path", "/etc/prompt")
        root_symbol = control.read_record("root", "/etc/prompt")
        user_symbol = control.read_record("user", "/etc/prompt")

        ## Setting up prompt data base 2 ##

        color_uh = ""
        color_path = ""
        prompt_symbol = ""

        if user == "root":
            prompt_symbol = root_symbol
            color_uh = colors.get_colors()
            color_path = colors.get_colors()
        else:
            prompt_symbol = user_symbol
            color_uh = colors.get_ok()
            color_path = colors.get_path()

        ## Setting up space of prompt ##

        if show_username == "Yes":
            space_username = user
        else:
            space_username = ""

        if show_hostname == "Yes":
            space_hostname = hostname
        else:
            space_hostname = ""

        if show_path == "Yes":
            space_path = files.readall("/proc/info/pwd")
        else:
            space_path = ""

        if show_hostname == "Yes" and show_username == "Yes":
            space1 = "@"
        else:
            space1 = ""

        if (show_hostname == "Yes"
                or show_username == "Yes") and show_path == "Yes":
            space2 = ":"
        else:
            space2 = ""

        ## Shell prompt ##

        cmd = input(color_uh + space_username + space1 + space_hostname +
                    colors.get_colors() + space2 + color_path + space_path +
                    colors.get_colors() + prompt_symbol + " ")

        cmdln = cmd.split(" ")

        strcmdln = ""

        for i in cmdln:
            if str(i).startswith("$"):
                select = files.readall("/proc/info/sel")
                var = control.read_record(str(i).replace("$", ""), select)
                if var == None:
                    strcmdln = strcmdln + " " + i
                else:
                    strcmdln = strcmdln + " " + var
            else:
                strcmdln = strcmdln + " " + i

        ## Command line ##
        cmdln = strcmdln.split(" ")
        cmdln.remove('')

        ## All commands run in here ##

        ## New command ##
        if cmdln[0] == "new":
            files.create("/tmp/su.tmp")
            control.write_record("username", user, "/tmp/su.tmp")
            control.write_record("code", code, "/tmp/su.tmp")

        ## Other commands ##
        if (cmdln == [] or cmdln[0] == "" or cmdln[0] == " "
                or cmd.startswith("#") or cmd.startswith("//")
                or (cmd.startswith("/*") and cmd.endswith("*/"))
                or (cmd.startswith("\'\'\'") and cmd.endswith("\'\'\'"))
                or cmd.startswith(";")):
            continue
        else:
            ## Run commands ##
            # os.system('./'+kernel_file+" exec "+cmd)# Credit learned with https://pymotw.com/2/subprocess/

            ## Prompt ##
            prompt = ['./' + kernel_file, 'exec', cmdln[0]]

            ## Arguments ##
            for i in cmdln[1:]:
                prompt.append(i)

            ## Call the kernel ##
            sub.call(prompt)