Ejemplo n.º 1
0
def udel(input_username, user):
    ## Check not exists user account ##
    if input_username == user:
        colors.show("udel", "fail",
                    input_username + ": cannot remove switched user.")
    else:
        if permissions.check_root(user):
            if not files.isfile("/etc/users/" + input_username):
                colors.show("udel", "fail",
                            input_username + ": user not found.")
            else:
                if input_username == "root":
                    colors.show("udel", "fail",
                                input_username + ": is a permanet user.")
                else:
                    hashname = hashlib.sha3_256(str(input_username).encode(
                    )).hexdigest()  ## Create hashname
                    username = control.read_record(
                        "username", "/etc/users/" + input_username)

                    if not hashname == username:
                        colors.show("udel", "fail",
                                    input_username + ": user not found.")
                    else:
                        files.remove("/etc/users/" + input_username)
                        if files.isdir('/desk/' + input_username):
                            files.removedirs("/desk/" + input_username)
                        colors.show(
                            '', 'ok',
                            "Remove '" + input_username + "' user account.")
        else:
            colors.show("udel", "perm", "")
Ejemplo n.º 2
0
def new(user, code):
    colors.show('', 'ok', 'Switching a new process ...')
    if files.isfile("/proc/selected"): files.remove("/proc/selected")
    if user == "guest":
        sub.call(['./' + boot, 'user', 'guest'])
    else:
        sub.call(['./' + boot, 'user', user, code])
Ejemplo n.º 3
0
def remove_record (name,filename):
    all = files.readall(filename)
    record = read_record(name, filename)
    files.remove(filename)
    if not (record == None):
        all = all.replace(name + ": " + record, "")
    files.write(filename, all)
Ejemplo n.º 4
0
def endall():
    if files.isfile("/proc/info/sp"): files.remove("/proc/info/sp")
    list = files.list("/proc")
    list.remove("id")
    list.remove("info")
    for i in list:
        files.remove("/proc/" + str(i))
Ejemplo n.º 5
0
def endall():
    files.remove('/proc/id/desktop')
    colors.show('desktop','ok-endid','')
    colors.show('kernel',"poweroff","")
    listid = files.list ("/proc/id")
    for i in listid:
        if files.isfile('/proc/id/'+i):
            files.remove('/proc/id/'+i)
Ejemplo n.º 6
0
def check(switch):
    if not files.isfile("/proc/" + str(switch)):
        colors.show("/proc/" + str(switch), "ok-endswitch", "")
        colors.show("", "poweroff", "")
        sys.exit(0)
    else:
        if files.isfile("/proc/info/sp"): files.remove("/proc/info/sp")
        files.write("/proc/info/sp", str(switch))
Ejemplo n.º 7
0
def unsel():
    select = files.readall("/proc/info/sel")
    if select == "/proc/" + files.readall("/proc/info/sp"):
        colors.show("unsel", "warning", "controller has already selected.")
    else:
        files.write("/proc/info/sel",
                    "/proc/" + files.readall("/proc/info/sp"))
        if files.isfile("/proc/selected"): files.remove("/proc/selected")
        colors.show('', 'ok', 'Select the switched process as a controller.')
Ejemplo n.º 8
0
def shutdown():
    colors.show('', 'ok', 'Shutdowning the clouding system ...')
    if files.isdir("/desk/guest"):
        files.removedirs("/desk/guest")
    if files.isdir("/tmp"):
        files.removedirs("/tmp")
        files.mkdir("/tmp")
    if files.isfile("/proc/selected"): files.remove("/proc/selected")
    process.endall()
Ejemplo n.º 9
0
def reboot():
    colors.show('', 'ok', 'Rebooting the clouding system ...')
    if files.isfile("/proc/selected"): files.remove("/proc/selected")
    colors.show("kernel", "reboot", "")
    if files.isdir("/desk/guest"):
        files.removedirs("/desk/guest")
    if files.isdir("/tmp"):
        files.removedirs("/tmp")
        files.mkdir("/tmp")
    process.endall()
    sub.call(['./' + files.readall("/proc/info/boot")])
Ejemplo n.º 10
0
def remove(name):
    su = files.readall("/proc/info/su")
    if permissions.check(files.output(name), "w", su):
        if isfile(name):
            files.remove(name)
        elif isdir(name):
            files.removedirs(name)
        else:
            colors.show("libabr.file.remove", "fail",
                        name + ": file or directory not found.")
    else:
        colors.show("libabr.file.remove", "perm", "")
Ejemplo n.º 11
0
def shut():
    colors.show('', 'ok', 'Closing the switched process ...')
    if files.isfile("/proc/selected"): files.remove("/proc/selected")
    process.end(int(files.readall("/proc/info/sp")))

    if files.readall("/proc/info/su") == "0":
        if files.isdir("/desk/guest"):
            files.removedirs("/desk/guest")
        if files.isdir("/tmp"):
            files.removedirs("/tmp")
            files.mkdir("/tmp")
        if files.isfile("/proc/selected"): files.remove("/proc/selected")
        process.endall()
Ejemplo n.º 12
0
def download(packname):
    if permissions.check_root(files.readall("/proc/info/su")):
        mirror = files.readall('/app/mirrors/' + packname.lower())

        ## Download the file ##
        url = mirror
        r = requests.get(url, allow_redirects=True)

        ## Check permissions ##
        open(files.input('/app/cache/gets/' + packname.lower() + '.pa'),
             'wb').write(r.content)

        ## Remove temporary ##
        files.remove('/app/cache/gets/' + packname + '.pa')
    else:
        colors.show("libpa.download", "perm", "")
Ejemplo n.º 13
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.")
Ejemplo n.º 14
0
def rm(names):
    for i in names:
        if files.isdir(i):
            if permissions.check(files.output(i), "w",
                                 files.readall("/proc/info/su")):
                files.removedirs(i)
                colors.show('', 'ok', "Remove '" + i + "' directory.")
            else:
                colors.show("rm", "perm", "")
                sys.exit(0)
        elif files.isfile(i):
            if permissions.check(files.output(i), "w",
                                 files.readall("/proc/info/su")):
                files.remove(i)
                colors.show('', 'ok', "Remove '" + i + "' file.")
            else:
                colors.show("rm", "perm", "")
                sys.exit(0)
        else:
            colors.show("rm", "fail", i + ": file or directory not found.")
            sys.exit(0)
Ejemplo n.º 15
0
def su(input_username, user):
    if files.isfile("/proc/selected"): files.remove("/proc/selected")
    if user == input_username:
        colors.show("su", "warning", user + " has already switched.")
    elif input_username == "guest":
        enable_cli = control.read_record("enable_cli", "/etc/guest")
        if enable_cli == "Yes":
            colors.show('', 'ok',
                        "Switching '" + input_username + "' user account.")
            os.system("./" + files.readall("/proc/info/boot") + " user guest")
        else:
            colors.show(input_username, "fail", "user not found.")

    elif files.isfile("/etc/users/" + input_username):
        hashname = hashlib.sha3_256(str(input_username).encode()).hexdigest()
        username = control.read_record("username",
                                       "/etc/users/" + input_username)
        if hashname == username:
            input_password = getpass.getpass('Enter ' + input_username +
                                             '\'s password: '******'', 'ok',
                    "Switching '" + input_username + "' user account ...")
                os.system("./" + files.readall("/proc/info/boot") + " user " +
                          input_username + " " + input_password)
            else:
                colors.show("su", "fail", input_username + ": wrong password.")
        else:
            colors.show("su", "fail", input_username + " user not found.")
    else:
        colors.show("su", "fail", input_username + " user not found.")
Ejemplo n.º 16
0
def end(switch):
    if files.isfile("/proc/info/sp"): files.remove("/proc/info/sp")
    if files.isfile("/proc/" + str(switch)):
        files.remove("/proc/" + str(switch))
        sys.exit(0)
Ejemplo n.º 17
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)
Ejemplo n.º 18
0
def logout():
    colors.show('', 'ok', 'Logging out from all users ...')
    if files.isfile("/proc/selected"): files.remove("/proc/selected")
    process.endall()
    sub.call(['./' + files.readall("/proc/info/boot"), 'login'])
Ejemplo n.º 19
0
def remove(name):
    if permissions.check_root(files.readall("/proc/info/su")):

        location = "/app/packages/" + name.lower() + ".manifest"

        if not files.isfile(location):
            colors.show("libpa.remove", "fail", name + ": package not found")
            clean()
            sys.exit(0)

        ## Database control ##

        list = "/app/packages/" + name.lower() + ".list"
        preinstall = "/app/packages/" + name.lower() + ".preinstall"
        postinstall = "/app/packages/" + name.lower() + ".postinstall"
        preremove = "/app/packages/" + name.lower() + ".preremove"
        postremove = "/app/packages/" + name.lower() + ".postremove"
        compile = "/app/packages/" + name.lower() + ".compile"
        depends = "/app/packages/" + name.lower() + ".depends"

        ## Create preremove and postremove copies ##

        if files.isfile(preremove):
            files.copy(preremove, "/app/cache/archives/control/preremove.py")
        if files.isfile(postremove):
            files.copy(postremove, "/app/cache/archives/control/postremove.py")

        ## Run pre remove script ##

        if files.isfile("/app/cache/archives/control/preremove.py"):
            files.compile("/app/cache/archives/control/preremove.py",
                          '/usr/bin/preremove.pyc')
            core.system("preremove")
            files.remove('/usr/bin/preremove.pyc')

        ## Remove depends ##

        if files.isfile(depends):
            depends = control.read_list(depends)
            for i in depends:
                remove(i)

        ####################

        unpack = control.read_record("unpack", location)

        ## Unpacked removal ##
        filelist = control.read_list(list)

        for i in filelist:
            if files.isdir(unpack + "/" + i):
                files.removedirs(unpack + "/" + i)
            elif files.isfile(unpack + "/" + i):
                files.remove(unpack + "/" + i)

        ## Database removal ##

        if files.isfile(location): files.remove(location)
        if files.isfile(compile): files.remove(compile)
        if files.isfile(list): files.remove(list)
        if files.isfile(preinstall): files.remove(preinstall)
        if files.isfile(postinstall): files.remove(postinstall)
        if files.isfile(preremove): files.remove(preremove)
        if files.isfile(postremove): files.remove(postremove)
        if files.isfile(depends): files.remove(depends)

        ## Remove source code ##
        if files.isdir('/usr/src/' + name):
            files.removedirs('/usr/src/' + name)

        ## Run postremove script ##

        if files.isfile("/app/cache/archives/control/postremove.py"):
            files.compile('/app/cache/archives/control/postremove.py',
                          '/usr/bin/postremove.pyc')
            core.system("postremove")
            files.remove('/usr/bin/postremove.pyc')

    else:
        colors.show("libpa.remove", "perm", "")
Ejemplo n.º 20
0
def remove_mirror(name):
    if permissions.check_root(files.readall("/proc/info/su")):
        files.remove('/app/mirrors/' + name)
    else:
        colors.show("libpa.remove_mirror", "perm", "")
Ejemplo n.º 21
0
def unpack(name):
    if permissions.check_root(files.readall("/proc/info/su")):
        ## unpack package ##
        shutil.unpack_archive(files.input(name),
                              files.input("/app/cache/archives/build"), "zip")

        shutil.unpack_archive(
            files.input("/app/cache/archives/build/data.tar.xz"),
            files.input("/app/cache/archives/data"), "xztar")
        shutil.unpack_archive(
            files.input("/app/cache/archives/build/control.tar.xz"),
            files.input("/app/cache/archives/control"), "xztar")

        ## Get database of this package ##
        name = control.read_record(
            "name", "/app/cache/archives/control/manifest").lower()
        unpack = control.read_record("unpack",
                                     "/app/cache/archives/control/manifest")
        depends = control.read_record("depends",
                                      "/app/cache/archives/control/manifest")

        if not (depends == None):
            depends.split(",")

        ## Search for tree dependency ##

        if not depends == None:
            for i in depends:
                if not files.isfile("/app/packages/" + i + ".manifest"):
                    core.system('paye -i ' + name)

        ## Write dependency ##

        if not depends == None:
            for i in depends:
                files.create("/app/packages/" + i + ".depends")
                files.write("/app/packages/" + i + ".depends", name + "\n")

        ## Run preinstall script ##

        if files.isfile('/app/cache/archives/control/preinstall.py'):
            files.compile('/app/cache/archives/control/preinstall.py',
                          '/usr/bin/preinstall.pyc')
            core.system('preinstall')  # Run it
            files.remove('/usr/bin/preinstall.pyc')

            ## Copy preinstall script ##

            files.copy('/app/cache/archives/control/preinstall.py',
                       '/app/packages/' + name + ".preinstall")

        ## Setting up ##

        if files.isfile("/app/cache/archives/control/list"):
            files.copy("/app/cache/archives/control/list",
                       "/app/packages/" + name + ".list")
        if files.isfile("/app/cache/archives/control/manifest"):
            files.copy("/app/cache/archives/control/manifest",
                       "/app/packages/" + name + ".manifest")

        ## Unpack data again ##
        shutil.unpack_archive(
            files.input("/app/cache/archives/build/data.tar.xz"),
            files.input(unpack), "xztar")

        ## After install ##

        ## Run postinstall script ##

        if files.isfile('/app/cache/archives/control/postinstall.py'):
            files.compile('/app/cache/archives/control/postinstall.py',
                          '/usr/bin/postinstall.pyc')
            core.system('postinstall')  # Run it
            files.remove('/usr/bin/postinstall.pyc')

            ## Copy preinstall script ##

            files.copy('/app/cache/archives/control/postinstall.py',
                       '/app/packages/' + name + ".postinstall")

        ## Copy other scripts ##
        if files.isfile('/app/cache/archives/control/preremove.py'):
            files.copy('/app/cache/archives/control/preremove.py',
                       '/app/packages/' + name + ".preremove")

        if files.isfile('/app/cache/archives/control/postremove.py'):
            files.copy('/app/cache/archives/control/postremove.py',
                       '/app/packages/' + name + ".postremove")

        ## Unlock the cache ##
    else:
        colors.show("libpa.unpack", "perm", "")
Ejemplo n.º 22
0
#######################################################################################
#  In the name of God, the Compassionate, the Merciful
#  Pyabr (c) 2020 Pasand team. GNU General Public License v3.0
#
#  Offical website:         http://itpasand.com
#  Telegram or Gap channel: @pyabr
#  Telegram or Gap group:   @pyabr_community
#  Git source:              github.com/pasandteam/pyabr
#
#######################################################################################

import sys, os, hashlib, subprocess as sub
from libnam import files, control, permissions, colors, process

boot = files.readall("/proc/info/boot")


def new(user, code):
    colors.show('', 'ok', 'Switching a new process ...')
    if files.isfile("/proc/selected"): files.remove("/proc/selected")
    if user == "guest":
        sub.call(['./' + boot, 'user', 'guest'])
    else:
        sub.call(['./' + boot, 'user', user, code])


new(control.read_record("username", "/tmp/su.tmp"),
    control.read_record("code", "/tmp/su.tmp"))
if files.isfile("/tmp/su.tmp"):
    files.remove("/tmp/su.tmp")
Ejemplo n.º 23
0
def end (id):

    if files.isfile ('/proc/id/'+id):
        ## Remove id ##
        colors.show(id,'ok-end','')
        files.remove ("/proc/id/"+id)