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)
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))
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.')
def remove_item (name,filename): items = read_list(filename) strv = "" for i in items: if i == name: strv = strv + "\n" else: strv = strv + "\n" + i files.write(filename,strv)
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.")
def write(name, text): su = files.readall("/proc/info/su") if permissions.check(files.output(name), "w", su): if isdir(name): colors.show("libabr.file.write", "fail", name + ": is a directory.") else: files.write(name, text) else: colors.show("libabr.file.write", "perm", "")
def start (id): ## Check exists ## if files.isfile ('/proc/id/'+id): pass colors.show (id,'ok-start','') ## Create id ## files.create ("/proc/id/"+id) ## Check desktop shortcut ## if files.isfile ("/usr/share/applications/"+id): files.copy ("/usr/share/applications/"+id+".desk","/proc/id/"+id) # Copy all informations about this GUI application ## Set default id ## files.write ("/proc/info/id",id)
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", "")
def processor(): j = 0 if not files.isfile("/proc/" + str(0)): files.create("/proc/" + str(0)) j = j + 1 else: list = files.list("/proc") list.remove('id') list.remove('info') for i in list: if files.isfile("/proc/" + i): files.create("/proc/" + str(int(i) + 1)) j = j + 1 else: files.create("/proc/" + i) if files.isfile("/proc/1"): files.write("/proc/info/sp", str(j)) return j else: files.write("/proc/info/sp", str(j - 1)) return j - 1
if thisuser == "guest": colors.show("sudo", 'fail', 'cannot use sudo command in guest user.') sys.exit(0) ## Check sudoers account ## if not thisuser == "root": sudoers = files.readall('/etc/sudoers') if not sudoers.__contains__(thisuser): colors.show('sudo', 'fail', thisuser + ": user is'nt sudoers account.") sys.exit() ## Send /etc/users/root to /proc/info/su username ## files.write("/proc/info/su", 'root') prompt = ['./' + files.readall('/proc/info/boot'), 'exec'] for i in sys.argv[1:]: prompt.append(i) subprocess.call(prompt) files.write("/proc/info/su", thisuser) elif sys.argv[1] == '-a': ## Check root ## if not permissions.check_root(files.readall("/proc/info/su")): colors.show("sudo", "perm", "") sys.exit(0) ## Check user exists or no ##
def cat(name, option): ## Read files ## if option == '' or option == '-r': if files.isfile(name): if permissions.check(files.output(name), "r", files.readall("/proc/info/su")): file = open(files.input(name), "rb") check_bin = str(file.read()) file.close() if check_bin.__contains__("\\x00"): print(check_bin) else: print(files.readall(name)) else: colors.show("cat", "perm", "") elif files.isdir(name): colors.show("cat", "fail", name + ": is a directory.") else: colors.show("cat", "fail", name + ": file not found.") ## Create files ## elif option == '-c': if files.isdir(name): colors.show("cat", "fail", name + ": is a directory.") else: if permissions.check(files.output(name), "w", files.readall("/proc/info/su")): files.create(name) else: colors.show("cat", "perm", "") ## Write into files ## elif option == '-w': if files.isdir(name): colors.show("cat", "fail", name + ": is a directory.") else: if permissions.check(files.output(name), "w", files.readall("/proc/info/su")): ## Set EOF if cmdln[3:] == []: EOF = 'EOF' else: EOF = cmdln[3] # WRITE COMMAND LINE texts = '' while True: cmd = input('> ') if cmd == EOF: break else: if texts == '': texts = cmd else: texts = texts + '\n' + cmd ## WRITE INTO FILE files.write(cmdln[2], texts) else: colors.show("cat", "perm", "") ## Write into files ## elif option == '-a': if files.isdir(name): colors.show("cat", "fail", name + ": is a directory.") else: if permissions.check(files.output(name), "w", files.readall("/proc/info/su")): ## Set EOF if cmdln[3] == []: EOF = 'EOF' else: EOF = cmdln[3] # WRITE COMMAND LINE texts = '' while True: cmd = input('> ') if cmd == EOF: break else: if texts == '': texts = cmd else: texts = texts + '\n' + cmd ## WRITE INTO FILE files.append(cmdln[2], texts) else: colors.show("cat", "perm", "")
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", "")
def add_mirror(name, mirror): if permissions.check_root(files.readall("/proc/info/su")): files.write('/app/mirrors/' + name, mirror) else: colors.show("libpa.add_mirror", "perm", "")
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)
colors.show(argv[1], "fail", "command not found.") sys.exit() ################################################################################### colors.show("kernel", "poweron", "") ################## Switch configure ########################## switch = process.processor() # Switch the process process.check(switch) # Check the switched process if switch == None: switch = 0 files.write("/proc/info/sel", "/proc/" + str(switch)) select = files.readall("/proc/info/sel") colors.show("/proc/" + str(switch), "ok-switch", "") #################################################################################################### ## @core/hostname ## if files.isfile("/etc/hostname"): files.copy("/etc/hostname", "/proc/info/host") hostname = files.readall("/etc/hostname") colors.show("hostname", "ok-start", "") else: colors.show("hostname", "fail-start", "") colors.show("kernel", "stop", "")
def switch (id): if files.isfile ('/proc/id/'+id): colors.show (id,'ok-id','') files.write ("/proc/info/id",id)
# # Offical website: http://itpasand.com # Telegram or Gap channel: @pyabr # Telegram or Gap group: @pyabr_community # Git source: github.com/pasandteam/pyabr # ####################################################################################### ## import modules ## import sys from libnam import permissions, files,control ,colors ## entry ## ## Check root ## if not permissions.check_root (files.readall("/proc/info/su")): colors.show ("upv","perm","") sys.exit(0) sel = files.readall ('/proc/info/sel') ## Get selector ## List all controls ## listc = control.read_list (sel) for i in listc: if not i.__contains__(':'): pass else: spliter = i.split (': ') files.write ('/proc/info/'+spliter[0],spliter[1])