Exemple #1
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.')
Exemple #2
0
def help(helpfile):
    if helpfile == "":
        print(files.readall("/usr/share/helps/cmdall.txt"))
    else:
        if files.isfile("/usr/share/helps/commands/" + helpfile + ".txt"):
            print(
                files.readall("/usr/share/helps/commands/" + helpfile +
                              ".txt"))
        else:
            print(files.readall("/usr/share/helps/cmdall.txt"))
Exemple #3
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)
Exemple #4
0
def ls(path, options):
    if options == "":
        if files.isdir(path):
            if permissions.check(files.output(path), "r",
                                 files.readall("/proc/info/su")):
                list = files.list(path)
                list.sort()
                for i in list:
                    if files.isdir(path + "/" + i):
                        print(colors.get_path() + i + "/" +
                              colors.get_colors())
                    else:
                        print(i)
            else:
                colors.show("ls", "perm", "")
        else:
            colors.show("ls", "fail", path + ": directory not found.")
    elif options == "-p":
        if files.isdir(path):
            if permissions.check(files.output(path), "r",
                                 files.readall("/proc/info/su")):
                list = files.list(path)
                list.sort()
                for i in list:
                    if files.isdir(path + "/" + i):
                        perm = permissions.get_permissions(path + "/" + i)
                        print(perm + "\t" + colors.get_path() + i + "/" +
                              colors.get_colors())
                    else:
                        perm = permissions.get_permissions(path + "/" + i)
                        print(perm + "\t" + i)
            else:
                colors.show("ls", "perm", "")
        else:
            colors.show("ls", "fail", path + ": directory not found.")
    elif options == "-n":
        if files.isdir(path):
            if permissions.check(files.output(path), "r",
                                 files.readall("/proc/info/su")):
                list = files.list(path)
                list.sort()
                for i in list:
                    if files.isdir(path + "/" + i):
                        perm = permissions.get_permissions(path + "/" + i)
                        perm = str(permissions.show_number(perm))
                        print(perm + "\t" + colors.get_path() + i + "/" +
                              colors.get_colors())
                    else:
                        perm = permissions.get_permissions(path + "/" + i)
                        perm = str(permissions.show_number(perm))
                        print(perm + "\t" + i)
            else:
                colors.show("ls", "perm", "")
        else:
            colors.show("ls", "fail", path + ": directory not found.")
Exemple #5
0
def unset(name):
    select = files.readall("/proc/info/sel")
    if not select.startswith("/proc/"):
        if permissions.check(files.output(select), "w",
                             files.readall("/proc/info/su")):
            control.remove_record(name, select)
            colors.show('', 'ok',
                        "Unset '" + name + "' in '" + select + ' controller.')
        else:
            colors.show("unset", "perm", "")
    else:
        control.remove_record(name, select)
Exemple #6
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()
Exemple #7
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)
Exemple #8
0
def readall(name):
    su = files.readall("/proc/info/su")
    if permissions.check(files.output(name), "r", su):
        if files.isfile(name):
            file = open(files.input(name), "rb")
            check_bin = str(file.read())
            file.close()
            if check_bin.__contains__("\\x00"):
                return check_bin
            else:
                return files.readall(name)
        else:
            colors.show("libabr.file.readall", "fail",
                        name + ": file not found.")
    else:
        colors.show("libabr.file.readall", "perm", "")
Exemple #9
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", "")
Exemple #10
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", "")
Exemple #11
0
def isdir(name):
    su = files.readall("/proc/info/su")
    if permissions.check(files.output(name), "r", su):
        return files.isdir(name)
    else:
        colors.show("libabr.file.isdir", "perm", "")
        return None
Exemple #12
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.")
Exemple #13
0
def read_record (name,filename):
    strv = files.readall(filename)
    strv = strv.split("\n")

    for i in strv:
        if i.startswith(name):
            i = i.split(": ")
            if i[0]==(name):
                return i[1]
Exemple #14
0
def mkdir(name):
    su = files.readall("/proc/info/su")
    if permissions.check(files.output(name), "w", su):
        if isfile(name):
            colors.show("libabr.file.mkdir", "fail", name + ": is a file.")
        else:
            files.makedirs(name)
    else:
        colors.show("libabr.file.mkdir", "perm", "")
Exemple #15
0
def chmod (mod,filename):
    perm_user = int(mod[0])
    perm_others = int(mod[1])
    perm_guest = int(mod[2])
    if permissions.check_owner (files.output(filename),files.readall("/proc/info/su")):
        owner = permissions.get_owner (files.output(filename))
        permissions.create (files.output(filename),perm_user,perm_others,perm_guest,owner)
        colors.show ('','ok','Change mode of \''+filename+'\' to '+mod+'.')
    else:
        colors.show ("chmod","perm","")
Exemple #16
0
def append(name, text):
    su = files.readall("/proc/info/su")
    if permissions.check(files.output(name), "w", su):
        if isdir(name):
            colors.show("libabr.file.append", "fail",
                        name + ": is a directory.")
        else:
            files.append(name, text)
    else:
        colors.show("libabr.file.append", "perm", "")
Exemple #17
0
def sel (database_name):
    if files.isfile(database_name):
        if permissions.check (files.output(database_name),"r",files.readall("/proc/info/su")):
            files.write("/proc/info/sel", database_name)
            files.create("/proc/selected")
            colors.show('', 'ok', "Select '" + database_name + "' controller.")
        else:
            colors.show ("sel","perm","")
    else:
        colors.show("sel", "fail", database_name + ": controller not found.")
Exemple #18
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")])
Exemple #19
0
def chown(new_owner, name):
    permowner = permissions.check_owner(files.output(name),
                                        files.readall("/proc/info/su"))
    perm = permissions.get_permissions(files.output(name))

    num = permissions.show_number(perm)
    num = str(num)
    user_p = int(num[0])
    others_p = int(num[1])
    guest_p = int(num[2])

    if permowner == True:
        if new_owner == "":
            permissions.create(files.output(name), user_p, others_p, guest_p,
                               files.readall("/proc/info/su"))
        else:
            permissions.create(files.output(name), user_p, others_p, guest_p,
                               new_owner)
    else:
        colors.show("chown", "perm", "")
Exemple #20
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)
Exemple #21
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", "")
Exemple #22
0
def cd(path):
    if permissions.check(files.output(path), "r",
                         files.readall("/proc/info/su")):
        if path == '..':
            pwd = files.readall('/proc/info/pwd')
            pwd = pwd.split('/')
            lens = len(pwd) - 1
            pwd.pop(lens)

            strv = ''

            for i in pwd:
                strv += "/" + i

            pwd = files.output_shell(strv)
            files.write("/proc/info/pwd", pwd)
        elif files.isdir(path):
            files.write("/proc/info/pwd", files.output_shell(path))
        else:
            colors.show("cd", "fail", path + ": directory not found.")
    else:
        colors.show("cd", "perm", "")
Exemple #23
0
def clean():
    if permissions.check_root(files.readall("/proc/info/su")):
        if files.isdir("/app/cache"):
            files.removedirs("/app/cache")
            files.mkdir("/app/cache")
            files.mkdir("/app/cache/gets")
            files.mkdir("/app/cache/archives")
            files.mkdir("/app/cache/archives/code")
            files.mkdir("/app/cache/archives/control")
            files.mkdir("/app/cache/archives/data")
            files.mkdir("/app/cache/archives/build")
    else:
        colors.show("libpa.clean", "perm", "")
Exemple #24
0
def system(cmd):
    prompt = ['./' + files.readall("/proc/info/boot"), 'exec']
    cmdln = cmd.split(" ")
    if '' in cmdln:
        cmdln.remove('')

    for i in cmdln:
        prompt.append(i)

    cmd = ''
    for j in prompt:
        cmd += " " + j

    sub.call(cmd, shell=True)
Exemple #25
0
def cp(src, dest):
    ## check src ##
    if files.isdir(src):
        if files.isfile(dest):
            colors.show("cp", "fail", dest + ": dest is a file.")
        else:
            if permissions.check(files.output(src), "r",
                                 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)

                else:
                    colors.show("cp", "perm", "")
            else:
                colors.show("cp", "perm", "")
    elif files.isfile(src):
        if files.isdir(dest):
            colors.show("cp", "fail", dest + ": dest is a directory.")
        else:
            if permissions.check(files.output(src), "r",
                                 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)
                else:
                    colors.show("cp", "perm", "")
            else:
                colors.show("cp", "perm", "")
    else:
        colors.show("cp", "fail", src + ": source not found.")
Exemple #26
0
def check(filename):
    perm = permissions.get_permissions(files.output(filename))
    numperm = permissions.show_number(perm)
    r = permissions.check(files.output(filename), "r",
                          files.readall("/proc/info/su"))
    w = permissions.check(files.output(filename), "w",
                          files.readall("/proc/info/su"))
    x = permissions.check(files.output(filename), "x",
                          files.readall("/proc/info/su"))

    bold = colors.color(1, colors.get_bgcolor(), colors.get_fgcolor())

    print("   Seleted path: " + bold + files.output(filename) +
          colors.get_colors())
    print("     Permission: " + bold + perm + colors.get_colors())
    print(" Permission Num: " + bold + str(numperm) + colors.get_colors())
    if r == True:
        print("           Read: " + bold + colors.get_ok() + "Yes" +
              colors.get_colors())
    else:
        print("           Read: " + bold + colors.get_fail() + "No" +
              colors.get_colors())

    if w == True:
        print("          Write: " + bold + colors.get_ok() + "Yes" +
              colors.get_colors())
    else:
        print("          Write: " + bold + colors.get_fail() + "No" +
              colors.get_colors())

    if x == True:
        print("        Execute: " + bold + colors.get_ok() + "Yes" +
              colors.get_colors())
    else:
        print("        Execute: " + bold + colors.get_fail() + "No" +
              colors.get_colors())
Exemple #27
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.")
Exemple #28
0
def zip (src,dest):
    su = files.readall("/proc/info/su") ## Get user data base
    if permissions.check (files.output(src),"r",su): ## Check this user permissions
        if permissions.check (files.output(dest+".zip"),"r",su): ## Check read only permission
            if files.isdir (src): ## Check source dir exists
                if files.isdir (dest+".zip"): ## Check dest dir exists
                    colors.show("libabr.archive.zip", "fail", dest+".zip" + ": dest is a directory.")
                else:
                    shutil.make_archive(files.input(dest),"zip",files.input(src)) ## Create archive
            elif files.isfile (src):
                colors.show("libabr.archive.zip", "fail",src+ ": source is a file.") ## Show error for permissions
            else:
                colors.show("libabr.archive.zip", "fail",src+ ": source not found.")
        else:
            colors.show("libabr.archive.zip", "perm", "")
    else:
        colors.show ("libabr.archive.zip","perm","")
Exemple #29
0
def gzip(src, dest):
    su = files.readall("/proc/info/su")
    if permissions.check(files.output(src), "r", su):
        if permissions.check(files.output(dest + ".gz"), "r", su):
            if files.isdir(src):
                if files.isdir(dest + ".gz"):
                    colors.show("libabr.archive.xzip", "fail", dest + ".gz" + ": dest is a directory.")
                else:
                    shutil.make_archive(files.input(dest), "gz", files.input(src))
            elif files.isfile(src):
                colors.show("libabr.archive.gzip", "fail", src + ": source is a file.")
            else:
                colors.show("libabr.archive.gzip", "fail", src + ": source not found.")
        else:
            colors.show("libabr.archive.gzip", "perm", "")
    else:
        colors.show("libabr.archive.gzip", "perm", "")
Exemple #30
0
def build(name):
    if permissions.check_root(files.readall("/proc/info/su")):
        if not files.isfile(name + "/control/manifest"):
            colors.show("libpa.build", "fail", "cannot create archive package")
            clean()
            sys.exit(0)

        if not files.isdir(name + "/data"): files.mkdir(name + "/data")
        if not files.isdir(name + "/code"): files.mkdir(name + "/code")

        ## Remove cache archives ##
        if files.isdir('/app/cache/archives/code'):
            files.removedirs('/app/cache/archives/code')
        if files.isdir('/app/cache/archives/control'):
            files.removedirs('/app/cache/archives/control')
        if files.isdir('/app/cache/archives/data'):
            files.removedirs('/app/cache/archives/data')

        ## Copy dir ##
        files.copydir(name + '/data', '/app/cache/archives/data')
        files.copydir(name + '/code', '/app/cache/archives/code')
        files.copydir(name + '/control', '/app/cache/archives/control')

        ## Compile codes ##
        if files.isfile("/app/cache/archives/control/compile"):
            listcodes = control.read_list(
                "/app/cache/archives/control/compile")
            for i in listcodes:
                i = i.split(":")
                files.compile("/app/cache/archives/code/" + i[0],
                              "/app/cache/archives/data/" + i[1])

        ## Pack archives ##
        shutil.make_archive(files.input("/app/cache/archives/build/data"),
                            "xztar", files.input('/app/cache/archives/data'))
        shutil.make_archive(files.input("/app/cache/archives/build/control"),
                            "xztar",
                            files.input('/app/cache/archives/control'))
        shutil.make_archive(files.input(name), "zip",
                            files.input("/app/cache/archives/build"))

        files.cut(name + ".zip", name + ".pa")
        ## Unlock the cache ##
    else:
        colors.show("libpa.build", "perm", "")