buttercheetah

CC Tablet

Apr 9th, 2022 (edited)
538
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.97 KB | None | 0 0
  1. local modem = peripheral.find("modem") or error("No modem attached", 0)
  2.  
  3. local osv = "1.1"
  4. function checkforupdate ()
  5.   local request = http.get("http://misc.iefi.xyz/minecraft/api/version/")
  6.   local body = request.readAll()
  7.   if (body == osv) then
  8.     print("OS is up to date")
  9.   else
  10.     print("update available")
  11.   end
  12. end
  13. function getnewannouncements ()
  14.   local request = http.get("http://misc.iefi.xyz/minecraft/api/anouncement/")
  15.   local body = request.readAll()
  16.   if (body == "") then
  17.     io.write()
  18.   else
  19.     print(body)
  20.   end
  21. end
  22. function adminstuff ()
  23.   tmprun2 = "True"
  24.   while (tmprun2 == "True") do
  25.     shell.run("clear")
  26.     print("select and option")
  27.     print("1) Make new OS Current Version")
  28.     print("2) Make new OS an input version")
  29.     print("3) New Announcement")
  30.     print("4) New user")
  31.     print("5) back")
  32.     local choice = read()
  33.     if (choice == "1") then
  34.       local request = http.post("http://misc.iefi.xyz/minecraft/api/setversion/", tostring(osv))
  35.       local body = request.readAll()
  36.       print(body)
  37.       os.sleep(5)
  38.     elseif (choice == "2") then
  39.       print("current OS version:" .. osv)
  40.       print("enter new OS version")
  41.       local temp = read()
  42.       local request = http.post("http://misc.iefi.xyz/minecraft/api/setversion/", tostring(temp))
  43.       local body = request.readAll()
  44.     elseif (choice == "3") then
  45.       print("enter new Announcement")
  46.       local temp = read()
  47.       local request = http.post("http://misc.iefi.xyz/minecraft/api/setanouncement/", tostring(temp))
  48.       local body = request.readAll()
  49.     elseif (choice == "4") then
  50.       print("enter new user's IGN")
  51.       local temp = read()
  52.       local request = http.post("http://misc.iefi.xyz/minecraft/api/newuser/", tostring(temp))
  53.       print(request.readAll())
  54.       os.sleep(2)
  55.       local request = http.post("http://misc.iefi.xyz/minecraft/api/createuser/", tostring(temp))
  56.       print(request.readAll())
  57.       os.sleep(2)
  58.       local request = http.post("http://misc.iefi.xyz/minecraft/api/applypurchase/", tostring(temp .. "|Opened Account|0"))
  59.       local body = request.readAll()
  60.       os.sleep(2)
  61.     elseif (choice == "5") then
  62.       tmprun2 = "False"
  63.     end
  64.   end
  65. end
  66. network = nil
  67. function getandprintnetwork ()
  68.     network = nil
  69.     shell.run("clear")
  70.     print("Attempting to connect")
  71.     while network == nil do
  72.         modem.open(2) -- Open 43 so we can receive replies
  73.         modem.transmit(1, 2, "wifissidget")
  74.         local event, side, channel, replyChannel, distance
  75.         local timeout = os.startTimer(5)
  76.         while true do
  77.             osevent = {os.pullEvent()}
  78.             if osevent[1] == "modem_message" then
  79.                 local channel = osevent[3]
  80.                 local replychannel = osevent[5]
  81.                 network = osevent[5]
  82.                 local distance = osevent[6]
  83.                 print(distance)  
  84.                 if channel == 2 then
  85.                     print(tostring(network))
  86.                     break
  87.                 end
  88.             elseif osevent[1] == "timer"  then
  89.                 break
  90.             end
  91.         end
  92.         if network == nil then
  93.             print("No network found. retrying in 5 seconds")
  94.             os.sleep(5)
  95.         end
  96.     end
  97. end
  98. local tname = ""
  99. runcheck = "True"
  100. while (runcheck == "True") do
  101.   getandprintnetwork()
  102.   shell.run("clear")
  103.   print("WiFi:" .. network)
  104.   print("Welcome!")
  105.   print("Please enter your username")
  106.   local username = read()
  107.   print("Please enter your password")
  108.   local password = read('*')
  109.   local request = http.post("http://misc.iefi.xyz/minecraft/api/login/", tostring(username .. "|" .. password))
  110.   local body = request.readAll()
  111.   if (body == "True") then
  112.     print("Login Succsesfull")
  113.     os.sleep(1)
  114.     tname = username
  115.     runcheck = "False"
  116.   else
  117.     print("User doesnt exist\nor password incorect")
  118.     os.sleep(2)
  119.   end
  120.  
  121. end
  122. while (1 == 1) do
  123.   getandprintnetwork()
  124.   shell.run("clear")
  125.   print("Welcome " .. tname)
  126.   print("WiFi:" .. network)
  127.   checkforupdate()
  128.   getnewannouncements()
  129.   print("1) Shops (WIP)")
  130.   print("2) Mobile Banking")
  131.   print("3) settings")
  132.   local usersel = read()
  133.   if (usersel == "admin") then
  134.     adminstuff()
  135.   elseif (usersel == "1") then
  136.     local tmprun4 = "True"
  137.     while (tmprun4 == "True") do
  138.       shell.run("clear")
  139.       print("Welcome " .. tname)
  140.       print("9) back")
  141.       local choice = read()
  142.       if (choice == "9") then
  143.         tmprun4 = "False"
  144.       end
  145.     end
  146.   elseif (usersel == "2") then
  147.     local function getuserbal ()
  148.       local request = http.post("http://misc.iefi.xyz/minecraft/api/getbal/", tname)
  149.       local body = request.readAll()
  150.       return tonumber(body)
  151.     end
  152.     local tmprun2 = "True"
  153.     while (tmprun2 == "True") do
  154.       local cbal = getuserbal()
  155.       shell.run("clear")
  156.       print("Account balance: " .. tostring(cbal))
  157.       print("1) Send money to another account")
  158.       print("2) return")
  159.       local choice = read()
  160.       if (choice == "1") then
  161.         if (cbal > tonumber(0)) then
  162.           print("Please input name of other account!")
  163.           local oac = read()
  164.           print("Please Input amount to transfer!\nNOTE:ONLY ENTER NUMBERS! If letters are written, many things may break.")
  165.           local transfer = read()
  166.           local request = http.put("http://misc.iefi.xyz/minecraft/api/getbal/", oac)
  167.           local body = request.readAll()
  168.           if (body == "False") then
  169.             print("Error: user doesnt exist")
  170.             os.sleep(2)
  171.           else
  172.             local request = http.post("http://misc.iefi.xyz/minecraft/api/applypurchase/", tostring(tname .. "|Balance Transfer to " .. oac .. "|" .. -tonumber(transfer)))
  173.             local body = request.readAll()
  174.             local request = http.post("http://misc.iefi.xyz/minecraft/api/applypurchase/", tostring(oac .. "|Balance Transfer from" .. tname .. "|" .. tonumber(transfer)))
  175.             local body = request.readAll()
  176.           end
  177.         else
  178.           print("Your balance is in the negative!")
  179.           os.sleep(5)
  180.         end
  181.       elseif (choice == "2") then
  182.         tmprun2 = "False"
  183.       end
  184.     end
  185.   elseif (usersel == "3") then
  186.     shell.run("clear")
  187.     local request = http.get("http://misc.iefi.xyz/minecraft/api/version/")
  188.     local body = request.readAll()
  189.     if (body == osv) then
  190.         print("OS is up to date")
  191.     else
  192.         print("Current OS:" .. osv .. "\nAvailable OS:" .. body)
  193.     end
  194.     print("\n1)update OS\n2)Reboot\n3)Shutdown\n4)Change password\n5)Back")
  195.     local usersel2 = read()
  196.     if (usersel2 == "1") then
  197.         shell.run("rm tabletos")
  198.         shell.run("wget https://raw.githubusercontent.com/buttercheetah/Computer-Craft-Lua-Programs/main/Tablet.lua tabletos")
  199.         shell.run("reboot")
  200.     elseif (usersel2 == "2") then
  201.         shell.run("reboot")
  202.     elseif (usersel2 == "3") then
  203.         shell.run("shutdown")
  204.     elseif (usersel2 == "4") then
  205.         print("Please input old password")
  206.         local oldpass = read()
  207.         print("Please input new password")
  208.         local newpass = read()
  209.         local request = http.post("http://misc.iefi.xyz/minecraft/api/clogin/", tostring(tname .. "|" .. oldpass .. "|" .. newpass))
  210.         print(request.readAll())
  211.         os.sleep(3)
  212.     end
  213.   end
  214. end
Add Comment
Please, Sign In to add comment