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])
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
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)
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 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", "")
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 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()
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","")
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)
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", "")
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")])
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", "")
def uinfo(input_username): enable_cli = control.read_record("enable_cli", "/etc/guest") if not (input_username == "guest" and enable_cli == "Yes"): if files.isfile("/etc/users/" + input_username): ## Get information from user database ## first_name = control.read_record("first_name", "/etc/users/" + input_username) last_name = control.read_record("last_name", "/etc/users/" + input_username) company = control.read_record("company", "/etc/users/" + input_username) birthday = control.read_record("birthday", "/etc/users/" + input_username) gender = control.read_record("gender", "/etc/users/" + input_username) blood_type = control.read_record("blood_type", "/etc/users/" + input_username) phone = control.read_record("phone", "/etc/users/" + input_username) website = control.read_record("website", "/etc/users/" + input_username) email = control.read_record("email", "/etc/users/" + input_username) ## Show it on screen ## bold = colors.color(1, colors.get_bgcolor(), colors.get_fgcolor()) if not (first_name == None or first_name == ""): print("\t First name: " + bold + first_name + colors.get_colors()) if not (last_name == None or last_name == ""): print("\t Last name: " + bold + last_name + colors.get_colors()) if not (company == None or company == ""): print("\t Company: " + bold + company + colors.get_colors()) if not (birthday == None or birthday == ""): print("\t Birthday: " + bold + birthday + colors.get_colors()) if not (gender == None or gender == ""): print("\t Gender: " + bold + gender + colors.get_colors()) if not (blood_type == None or blood_type == ""): print("\t BloodType: " + bold + blood_type + colors.get_colors()) if not (phone == None or phone == ""): print("\t Phone number: " + bold + phone + colors.get_colors()) if not (website == None or website == ""): print("\t Website: " + bold + website + colors.get_colors()) if not (email == None or email == ""): print("\tEmail address: " + bold + email + colors.get_colors()) else: colors.show("uinfo", "fail", input_username + ": user not found.")
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)
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", "")
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()
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", "")
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", "")
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","")
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.")
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", "")
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","")
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", "")
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 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", "")
def compile(src, dest): su = files.readall("/proc/info/su") if permissions.check(files.output(src), "r", su): if isfile(src): if permissions.check(files.output(dest), "w", su): if files.isdir(dest): colors.show("libabr.file.compile", "fail", dest + ": dest is a directory.") else: files.compile(src, dest) else: colors.show("libabr.file.compile", "perm", "") elif isdir(src): colors.show("libabr.file.compile", "fail", src + ": source is a directory.") else: colors.show("libabr.file.compile", "fail", src + ": source not found.") else: colors.show("libabr.file.compile", "perm", "")
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)
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 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.")
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", "") if sys.argv[1:] == []: colors.show("chown", "fail", "no inputs.") else: if sys.argv[2:] == []: chown("", sys.argv[1]) colors.show( '', 'ok', 'Change owership of \'' + sys.argv[1] + '\' to ' + files.readall("/proc/info/su") + '.') else: chown(sys.argv[1], sys.argv[2]) colors.show( '', 'ok', 'Change owership of \'' + sys.argv[1] + '\' to ' + sys.argv[2] + '.')