Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #File must be named 'kernel.py'
- #Must be in the same directory as 'interp.py' and 'eret.py'
- #You must have pycrypto installed on your computer
- #Python version must be python 2.7
- #Run this file to start the os
- #This script is made to run on a unix terminal. the clear screen commands may not match.
- __author__ = 'Brad'
- import time
- import os
- import platform
- import subprocess
- import smtplib
- import base64
- from Crypto.Cipher import AES
- #external file applications
- from eret import errorcodes
- from interp import interpret
- def cls():
- print("\x1B[2J")
- def mail():
- print("PythonOS Email Client v0.3")
- print("--------------------------")
- gmail_user = raw_input("Enter your email: ")
- gmail_pwd = raw_input("Enter your email password: ")
- FROM = gmail_user
- TO = [raw_input("Enter recipient email: ")] #must be a list
- SUBJECT = raw_input("Enter email subject: ")
- TEXT = raw_input("Enter message: ")
- # Prepare actual message
- message = """\From: %s\nTo: %s\nSubject: %s\n\n%s
- """ % (FROM, ", ".join(TO), SUBJECT, TEXT)
- try:
- #server = smtplib.SMTP(SERVER)
- server = smtplib.SMTP("smtp.gmail.com", 587) #or port 465 doesn't seem to work!
- server.ehlo()
- server.starttls()
- server.login(gmail_user, gmail_pwd)
- server.sendmail(FROM, TO, message)
- #server.quit()
- server.close()
- print 'successfully sent the mail'
- except:
- print (errorcodes(2))
- osScreen2()
- def calculator():
- cls()
- function = raw_input("add, subtract, multiply, or divide?: ")
- if function == "add":
- cls()
- print("Insert first number: ")
- x = float(raw_input())
- cls()
- print("Insert second number: ")
- y = float(raw_input())
- cls()
- add = float(x) + float(y)
- print(str(x) + " + " + str(y) + " = " + str(add))
- elif function == "subtract":
- cls()
- x = float(raw_input("Insert first number: "))
- cls()
- y = float(raw_input("Insert second number: "))
- cls()
- add = float(x) - float(y)
- print(str(x) + " - " + str(y) + " = " + str(add))
- elif function == "multiply":
- cls()
- x = int(raw_input("Insert first factor: "))
- cls()
- y = int(raw_input("Insert second factor: "))
- cls()
- add = float(x) * float(y)
- print(str(x) + " x " + str(y) + " = " + str(add))
- elif function == "divide":
- cls()
- x = float(raw_input("Insert numerator: "))
- cls()
- y = float(raw_input("Insert denominator: "))
- cls()
- add = float(x) / float(y)
- print(str(x) + " / " + str(y) + " = " + str(add))
- else:
- print("invalid operation")
- calculator()
- osScreen2()
- #---------------the coms command-------------------------------------------
- def commands():
- print("commands: exit, mail, resetpw, rstusr, coms, clearsc, say, calc, new, view, sysinf, count")
- # -------------------the loading account screen ----------------------------
- def loadOS():
- cls()
- print("loading your POS account.")
- time.sleep(1)
- cls()
- print("loading your POS account..")
- time.sleep(1)
- cls()
- print("loading your POS account...")
- time.sleep(1)
- osScreen()
- #------------------------------------------------------------------------------
- #---------------the command interpreter----------------------------------------
- def osScreen():
- cls()
- print("POS V 0.2.3 on " + platform.system() + " version: " + platform.version())
- print("for a list of commands type 'coms'")
- osScreen2()
- def osScreen2():
- try:
- interpret(raw_input(">"))
- osScreen2()
- except:
- print("invalid syntax")
- osScreen2()
- def first():
- try:
- f1 = open("pass.enc")
- pass1 = f1.read()
- f1.close()
- PADDING = '{'
- DecodeAES = lambda c, e: c.decrypt(base64.b64decode(e)).rstrip(PADDING)
- key = 'hj%4jfd 7&gh17g*'
- cipher = AES.new(key)
- decoded = DecodeAES(cipher, pass1)
- print("Welcome to POS")
- print("--------------")
- if decoded == "password":
- print("WARNING: using default os passcode")
- print("----------------------------------")
- us = raw_input("Enter Username: ")
- if us in open("usr.txt").read():
- cls()
- print("Welcome to POS")
- print("--------------")
- if decoded == "password":
- print("WARNING: using default os passcode")
- print("----------------------------------")
- password = raw_input("Enter Password: ")
- if password == decoded:
- loadOS()
- else:
- cls()
- print("Code Incorrect")
- time.sleep(3)
- first()
- else:
- cls()
- print("User does not exist")
- time.sleep(3)
- cls()
- first()
- except IOError:
- print("Creating system files...")
- time.sleep(3)
- cls()
- open("pass.enc", "w").close()
- p1 = open("pass.enc", "r+")
- etext = "password"
- BLOCK_SIZE = 16
- PADDING ='{'
- pad = lambda s: s + (BLOCK_SIZE - len(s) % BLOCK_SIZE) * PADDING
- EncodeAES = lambda c, s: base64.b64encode(c.encrypt(pad(s)))
- key = 'hj%4jfd 7&gh17g*'
- cipher = AES.new(key)
- encoded = EncodeAES(cipher, etext)
- p1.write(encoded)
- p1.flush()
- open("usr.txt", "w").close()
- p1 = open("usr.txt", "r+")
- p1.write("user")
- p1.flush()
- open("state.txt", "w").close()
- f1 = open("state.txt", "r+")
- f1.write("osState: 1")
- f1.flush()
- print("done")
- time.sleep(1)
- cls()
- first()
- first()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement