Advertisement
Techmo

PythonOS_5_kernel.py

Feb 26th, 2014
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.90 KB | None | 0 0
  1. #File must be named 'kernel.py'
  2. #Must be in the same directory as 'interp.py' and 'eret.py'
  3. #You must have pycrypto installed on your computer
  4. #Python version must be python 2.7
  5. #Run this file to start the os
  6. #This script is made to run on a unix terminal. the clear screen commands may not match.
  7. __author__ = 'Brad'
  8. import time
  9. import os
  10. import platform
  11. import subprocess
  12. import smtplib
  13. import base64
  14. from Crypto.Cipher import AES
  15.  
  16. #external file applications
  17. from eret import errorcodes
  18. from interp import interpret
  19.  
  20. def cls():
  21.     print("\x1B[2J")
  22. def mail():
  23.     print("PythonOS Email Client v0.3")
  24.     print("--------------------------")
  25.     gmail_user = raw_input("Enter your email: ")
  26.     gmail_pwd = raw_input("Enter your email password: ")
  27.     FROM = gmail_user
  28.     TO = [raw_input("Enter recipient email: ")] #must be a list
  29.     SUBJECT = raw_input("Enter email subject: ")
  30.     TEXT = raw_input("Enter message: ")
  31.  
  32.      # Prepare actual message
  33.     message = """\From: %s\nTo: %s\nSubject: %s\n\n%s
  34.    """ % (FROM, ", ".join(TO), SUBJECT, TEXT)
  35.     try:
  36.         #server = smtplib.SMTP(SERVER)
  37.         server = smtplib.SMTP("smtp.gmail.com", 587) #or port 465 doesn't seem to work!
  38.         server.ehlo()
  39.         server.starttls()
  40.         server.login(gmail_user, gmail_pwd)
  41.         server.sendmail(FROM, TO, message)
  42.         #server.quit()
  43.         server.close()
  44.         print 'successfully sent the mail'
  45.     except:
  46.         print (errorcodes(2))
  47.     osScreen2()
  48.  
  49. def calculator():
  50.     cls()
  51.     function = raw_input("add, subtract, multiply, or divide?: ")
  52.     if function == "add":
  53.         cls()
  54.         print("Insert first number: ")
  55.         x = float(raw_input())
  56.         cls()
  57.         print("Insert second number: ")
  58.         y = float(raw_input())
  59.         cls()
  60.         add = float(x) + float(y)
  61.         print(str(x) + " + " + str(y) + " = " + str(add))
  62.     elif function == "subtract":
  63.         cls()
  64.         x = float(raw_input("Insert first number: "))
  65.         cls()
  66.         y = float(raw_input("Insert second number: "))
  67.         cls()
  68.         add = float(x) - float(y)
  69.         print(str(x) + " - " + str(y) + " = " + str(add))
  70.     elif function == "multiply":
  71.         cls()
  72.         x = int(raw_input("Insert first factor: "))
  73.         cls()
  74.         y = int(raw_input("Insert second factor: "))
  75.         cls()
  76.         add = float(x) * float(y)
  77.         print(str(x) + " x " + str(y) + " = " + str(add))
  78.     elif function == "divide":
  79.         cls()
  80.         x = float(raw_input("Insert numerator: "))
  81.         cls()
  82.         y = float(raw_input("Insert denominator: "))
  83.         cls()
  84.         add = float(x) / float(y)
  85.         print(str(x) + " / " + str(y) + " = " + str(add))
  86.     else:
  87.         print("invalid operation")
  88.         calculator()
  89.     osScreen2()
  90.  
  91.  
  92.  
  93. #---------------the coms command-------------------------------------------
  94. def commands():
  95.     print("commands: exit, mail, resetpw, rstusr,  coms, clearsc, say, calc, new, view, sysinf, count")
  96. # -------------------the loading account screen ----------------------------
  97. def loadOS():
  98.     cls()
  99.     print("loading your POS account.")
  100.     time.sleep(1)
  101.     cls()
  102.     print("loading your POS account..")
  103.     time.sleep(1)
  104.     cls()
  105.     print("loading your POS account...")
  106.     time.sleep(1)
  107.     osScreen()
  108. #------------------------------------------------------------------------------
  109. #---------------the command interpreter----------------------------------------
  110. def osScreen():
  111.     cls()
  112.     print("POS V 0.2.3 on " + platform.system() + " version: " + platform.version())
  113.     print("for a list of commands type 'coms'")
  114.     osScreen2()
  115. def osScreen2():
  116.     try:
  117.         interpret(raw_input(">"))
  118.         osScreen2()
  119.     except:
  120.         print("invalid syntax")
  121.         osScreen2()
  122. def first():
  123.     try:
  124.         f1 = open("pass.enc")
  125.         pass1 = f1.read()
  126.         f1.close()
  127.         PADDING = '{'
  128.         DecodeAES = lambda c, e: c.decrypt(base64.b64decode(e)).rstrip(PADDING)
  129.         key = 'hj%4jfd 7&gh17g*'
  130.         cipher = AES.new(key)
  131.         decoded = DecodeAES(cipher, pass1)
  132.         print("Welcome to POS")
  133.         print("--------------")
  134.         if decoded == "password":
  135.             print("WARNING: using default os passcode")
  136.             print("----------------------------------")
  137.         us = raw_input("Enter Username: ")
  138.         if us in open("usr.txt").read():
  139.             cls()
  140.             print("Welcome to POS")
  141.             print("--------------")
  142.             if decoded == "password":
  143.                 print("WARNING: using default os passcode")
  144.                 print("----------------------------------")
  145.             password = raw_input("Enter Password: ")
  146.  
  147.             if password == decoded:
  148.                 loadOS()
  149.             else:
  150.                 cls()
  151.                 print("Code Incorrect")
  152.                 time.sleep(3)
  153.                 first()
  154.         else:
  155.             cls()
  156.             print("User does not exist")
  157.             time.sleep(3)
  158.             cls()
  159.             first()
  160.     except IOError:
  161.         print("Creating system files...")
  162.         time.sleep(3)
  163.         cls()
  164.         open("pass.enc", "w").close()
  165.         p1 = open("pass.enc", "r+")
  166.         etext = "password"
  167.         BLOCK_SIZE = 16
  168.         PADDING ='{'
  169.         pad = lambda s: s + (BLOCK_SIZE - len(s) % BLOCK_SIZE) * PADDING
  170.         EncodeAES = lambda c, s: base64.b64encode(c.encrypt(pad(s)))
  171.         key = 'hj%4jfd 7&gh17g*'
  172.         cipher = AES.new(key)
  173.         encoded = EncodeAES(cipher, etext)
  174.         p1.write(encoded)
  175.         p1.flush()
  176.         open("usr.txt", "w").close()
  177.         p1 = open("usr.txt", "r+")
  178.         p1.write("user")
  179.         p1.flush()
  180.         open("state.txt", "w").close()
  181.         f1 = open("state.txt", "r+")
  182.         f1.write("osState: 1")
  183.         f1.flush()
  184.         print("done")
  185.         time.sleep(1)
  186.         cls()
  187.         first()
  188. first()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement