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", "")
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 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 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 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", "")
## 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 ## if files.isfile('/etc/users/' + sys.argv[2]): hashname = hashlib.sha3_256(sys.argv[2].encode()).hexdigest() username = control.read_record('username', '/etc/users/' + sys.argv[2]) if hashname == username: files.append('/etc/sudoers', sys.argv[2] + "\n") colors.show('', 'ok', 'Add \'' + sys.argv[2] + '\' user account in sudoers.') else: colors.show('sudo', 'fail', sys.argv[2] + ": user not found.") else: colors.show('sudo', 'fail', sys.argv[2] + ": user not found.")
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 remove_mirror(name): if permissions.check_root(files.readall("/proc/info/su")): files.remove('/app/mirrors/' + name) else: colors.show("libpa.remove_mirror", "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 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", "")