Advertisement
Techmo

PythonOS4

Feb 12th, 2014
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 10.65 KB | None | 0 0
  1. __author__ = 'Brad'
  2. import time
  3. import os
  4. import platform
  5. import subprocess
  6. import smtplib
  7. import base64
  8. from Crypto.Cipher import AES
  9.  
  10. #external file applications
  11. from eret import errorcodes
  12.  
  13. def cls():
  14.     os.system("clear")
  15. def mail():
  16.     print("PythonOS Email Client v0.3")
  17.     print("--------------------------")
  18.     gmail_user = raw_input("Enter your email: ")
  19.     gmail_pwd = raw_input("Enter your email password: ")
  20.     FROM = gmail_user
  21.     TO = [raw_input("Enter recipient email: ")] #must be a list
  22.     SUBJECT = raw_input("Enter email subject: ")
  23.     TEXT = raw_input("Enter message: ")
  24.  
  25.      # Prepare actual message
  26.     message = """\From: %s\nTo: %s\nSubject: %s\n\n%s
  27.    """ % (FROM, ", ".join(TO), SUBJECT, TEXT)
  28.     try:
  29.         #server = smtplib.SMTP(SERVER)
  30.         server = smtplib.SMTP("smtp.gmail.com", 587) #or port 465 doesn't seem to work!
  31.         server.ehlo()
  32.         server.starttls()
  33.         server.login(gmail_user, gmail_pwd)
  34.         server.sendmail(FROM, TO, message)
  35.         #server.quit()
  36.         server.close()
  37.         print 'successfully sent the mail'
  38.     except:
  39.         print (errorcodes(2))
  40.     osScreen2()
  41. def count():
  42.     cls()
  43.     cend = float(raw_input("Count to what number?: "))
  44.     cls()
  45.     crate = float(raw_input("Count by?: "))
  46.     cls()
  47.     cstart = float(raw_input("Count from?: "))
  48.     cls()
  49.     choice = raw_input("Write to file?(Y/N): ").lower()
  50.     cls()
  51.     if choice == "y":
  52.         fname = raw_input("Enter the name of the file to write to: ")
  53.         cls()
  54.         open(fname, "w").close()
  55.         cfile = open(fname, "r+")
  56.     x = cstart
  57.     while x <= cend:
  58.         if choice == "y":
  59.             cfile.write(str(x) + ", ")
  60.             cfile.flush()
  61.         else:
  62.             print(x)
  63.         print(x)
  64.         x += crate
  65.     osScreen2()
  66. def calculator():
  67.     cls()
  68.     function = raw_input("add, subtract, multiply, or divide?: ")
  69.     if function == "add":
  70.         cls()
  71.         print("Insert first number: ")
  72.         x = float(raw_input())
  73.         cls()
  74.         print("Insert second number: ")
  75.         y = float(raw_input())
  76.         cls()
  77.         add = float(x) + float(y)
  78.         print(str(x) + " + " + str(y) + " = " + str(add))
  79.     elif function == "subtract":
  80.         cls()
  81.         x = float(raw_input("Insert first number: "))
  82.         cls()
  83.         y = float(raw_input("Insert second number: "))
  84.         cls()
  85.         add = float(x) - float(y)
  86.         print(str(x) + " - " + str(y) + " = " + str(add))
  87.     elif function == "multiply":
  88.         cls()
  89.         x = int(raw_input("Insert first factor: "))
  90.         cls()
  91.         y = int(raw_input("Insert second factor: "))
  92.         cls()
  93.         add = float(x) * float(y)
  94.         print(str(x) + " x " + str(y) + " = " + str(add))
  95.     elif function == "divide":
  96.         cls()
  97.         x = float(raw_input("Insert numerator: "))
  98.         cls()
  99.         y = float(raw_input("Insert denominator: "))
  100.         cls()
  101.         add = float(x) / float(y)
  102.         print(str(x) + " / " + str(y) + " = " + str(add))
  103.     else:
  104.         print("invalid operation")
  105.         calculator()
  106.     osScreen2()
  107. def view():
  108.     name = raw_input("Insert the name of the file you would like to open(inlude any extensions): ")
  109.  
  110.     if name == "pass.txt" or name == "state.txt":
  111.             print(errorcodes(1))
  112.             view()
  113.  
  114.     else:
  115.         try:
  116.             fdata = open(name, "r+").read()
  117.         except IOError:
  118.             cls()
  119.             print("Invalid file name")
  120.             time.sleep(2)
  121.             cls()
  122.             view()
  123.         cls()
  124.         print("The file contains:")
  125.         print("")
  126.         print(fdata)
  127.         osScreen2()
  128. def rstusr():
  129.     cls()
  130.     f1 = open("usr.txt", "r+")
  131.     username = f1.read()
  132.     us1 = raw_input("Enter your old username: ")
  133.     if us1 == username:
  134.         cls()
  135.         dp = raw_input("Enter your new username: ")
  136.         open("usr.txt", 'w').close()
  137.         f3 = open("usr.txt", "r+")
  138.         f3.write(dp)
  139.         f3.flush()
  140.         cls()
  141.         print("Username Reset")
  142.         time.sleep(1)
  143.         cls()
  144.         osScreen2()
  145.     else:
  146.         cls()
  147.         print("Username does not exist")
  148.         time.sleep(1)
  149.         osScreen()
  150.  
  151. def new():
  152.     name = raw_input("Insert name of new file (use .txt if you want a text file): ")
  153.     if name == "pass.txt" or name == "state.txt":
  154.         print(errorcodes(1))
  155.         new()
  156.     else:
  157.         open(name, "w").close()
  158.         file1 = open(name, "r+")
  159.         cls()
  160.         print("PyEdit v0.1.1")
  161.         print("Enter text to be written to file then press 'Enter'")
  162.         print(" ")
  163.         print(" ")
  164.         data = raw_input()
  165.         file1.write(data)
  166.         file1.flush()
  167.         file1.close()
  168.         osScreen2()
  169.  
  170.  
  171. # the say command-------------------------
  172. def say():
  173.     sent = raw_input("Say what?: ")
  174.     print(sent)
  175.     osScreen2()
  176. def cpuname():
  177.     if platform.system() == "Windows":
  178.         return platform.processor()
  179.     elif platform.system() == "Darwin":
  180.         return subprocess.check_output(['/usr/sbin/sysctl', "-n", "machdep.cpu.brand_string"]).strip()
  181.     elif platform.system() == "Linux":
  182.         command = "cat /proc/cpuinfo"
  183.         return subprocess.check_output(command, shell=True).strip()
  184.     return ""
  185. def sysinfo():
  186.     print("OS name: " + platform.release())
  187.     print("OS type: " + platform.system())
  188.     print("OS version: " + platform.version())
  189.     print("CPU: " + cpuname())
  190.     print("CPU type: " + platform.machine())
  191.     print("Python version: " + platform.python_version())
  192.     print("Network name: " + platform.node())
  193.     osScreen2()
  194. #--------------------------the resetpw command--------------------------
  195. def pwreset():
  196.     cls()
  197.     f1 = open("pass.enc", "r+")
  198.     password = f1.read()
  199.     ps = raw_input("Enter your old password: ")
  200.     PADDING = '{'
  201.     DecodeAES = lambda c, e: c.decrypt(base64.b64decode(e)).rstrip(PADDING)
  202.     key = 'hj%4jfd 7&gh17g*'
  203.     cipher = AES.new(key)
  204.     decoded = DecodeAES(cipher, password)
  205.     if decoded == ps:
  206.         cls()
  207.         dp = raw_input("Enter your new password: ")
  208.         BLOCK_SIZE = 16
  209.         PADDING ='{'
  210.         pad = lambda s: s + (BLOCK_SIZE - len(s) % BLOCK_SIZE) * PADDING
  211.         EncodeAES = lambda c, s: base64.b64encode(c.encrypt(pad(s)))
  212.         key = 'hj%4jfd 7&gh17g*'
  213.         cipher = AES.new(key)
  214.         encodedpass = EncodeAES(cipher, dp)
  215.         open("pass.txt", 'w').close()
  216.         f2 = open("pass.enc", "r+")
  217.         f2.write(encodedpass)
  218.         f2.flush()
  219.         open("state.txt", "w").close()
  220.         oss = open("state.txt", "r+")
  221.         oss.write("osState: 0")
  222.         cls()
  223.         print("Password Reset")
  224.         time.sleep(1)
  225.         cls()
  226.         osScreen2()
  227.     else:
  228.         cls()
  229.         print("Passcode Incorrect")
  230.         time.sleep(1)
  231.         osScreen()
  232. #--------------------------------------------------------------------------
  233. #---------------the coms command-------------------------------------------
  234. def commands():
  235.     print("commands: exit, mail, resetpw, rstusr,  coms, clearsc, say, calc, new, view, sysinf, count")
  236. # -------------------the loading account screen ----------------------------
  237. def loadOS():
  238.     cls()
  239.     print("loading your POS account.")
  240.     time.sleep(1)
  241.     cls()
  242.     print("loading your POS account..")
  243.     time.sleep(1)
  244.     cls()
  245.     print("loading your POS account...")
  246.     time.sleep(1)
  247.     osScreen()
  248. #------------------------------------------------------------------------------
  249. #---------------the command interpreter----------------------------------------
  250. def osScreen():
  251.     cls()
  252.     print("POS V 0.2.3 on " + platform.system() + " version: " + platform.version())
  253.     print("for a list of commands type 'coms'")
  254.     osScreen2()
  255. def osScreen2():
  256.     command = raw_input("> ")
  257.     if command == "exit":
  258.         exit()
  259.     elif command == "resetpw":
  260.         pwreset()
  261.         osScreen2()
  262.     elif command == "coms":
  263.         commands()
  264.         osScreen2()
  265.     elif command == "mail":
  266.         mail()
  267.     elif command == "count":
  268.         count()
  269.     elif command == "clearsc":
  270.         cls()
  271.         osScreen2()
  272.     elif command == "say":
  273.         say()
  274.     elif command == "rstusr":
  275.         rstusr()
  276.     elif command == "calc":
  277.         calculator()
  278.     elif command == "sysinf":
  279.         sysinfo()
  280.     elif command == "new":
  281.         new()
  282.     elif command == "view":
  283.         view()
  284.     else:
  285.         print("Unknown command")
  286.         osScreen2()
  287. def first():
  288.     try:
  289.         f1 = open("pass.enc")
  290.         pass1 = f1.read()
  291.         f1.close()
  292.         PADDING = '{'
  293.         DecodeAES = lambda c, e: c.decrypt(base64.b64decode(e)).rstrip(PADDING)
  294.         key = 'hj%4jfd 7&gh17g*'
  295.         cipher = AES.new(key)
  296.         decoded = DecodeAES(cipher, pass1)
  297.         print("Welcome to POS")
  298.         print("--------------")
  299.         state = open("state.txt", "r+")
  300.         st = state.read()
  301.         if st == "osState: 1":
  302.             print("WARNING: using default os passcode")
  303.             print("----------------------------------")
  304.         us = raw_input("Enter Username: ")
  305.         if us in open("usr.txt").read():
  306.             cls()
  307.             print("Welcome to POS")
  308.             print("--------------")
  309.             if st == "osState: 1":
  310.                 print("WARNING: using default os passcode")
  311.                 print("----------------------------------")
  312.             password = raw_input("Enter Password: ")
  313.  
  314.             if password == decoded:
  315.                 loadOS()
  316.             else:
  317.                 cls()
  318.                 print("Code Incorrect")
  319.                 time.sleep(3)
  320.                 first()
  321.         else:
  322.             cls()
  323.             print("User does not exist")
  324.             time.sleep(3)
  325.             cls()
  326.             first()
  327.     except IOError:
  328.         print("Creating system files...")
  329.         time.sleep(3)
  330.         cls()
  331.         open("pass.enc", "w").close()
  332.         p1 = open("pass.enc", "r+")
  333.         etext = "password"
  334.         BLOCK_SIZE = 16
  335.         PADDING ='{'
  336.         pad = lambda s: s + (BLOCK_SIZE - len(s) % BLOCK_SIZE) * PADDING
  337.         EncodeAES = lambda c, s: base64.b64encode(c.encrypt(pad(s)))
  338.         key = 'hj%4jfd 7&gh17g*'
  339.         cipher = AES.new(key)
  340.         encoded = EncodeAES(cipher, etext)
  341.         p1.write(encoded)
  342.         p1.flush()
  343.         open("usr.txt", "w").close()
  344.         p1 = open("usr.txt", "r+")
  345.         p1.write("user")
  346.         p1.flush()
  347.         open("state.txt", "w").close()
  348.         f1 = open("state.txt", "r+")
  349.         f1.write("osState: 1")
  350.         f1.flush()
  351.         print("done")
  352.         time.sleep(1)
  353.         cls()
  354.         first()
  355. first()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement