Advertisement
infiniteblock

Untitled

Apr 21st, 2020
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.29 KB | None | 0 0
  1. -- Load API
  2. os.loadAPI("sha256")
  3. os.loadAPI("gui")
  4.  
  5. local textStart = gui.textStart
  6. local diskSide = "bottom"
  7. local serverId = 3
  8. local withdrawId = 14
  9. local version = "GAB-0.1"
  10. local url = "http://147.135.59.131/index.php"
  11.  
  12. -- Import GUI functions
  13. local drawHeader, drawButtons, drawButton, drawError, center = gui.drawHeader, gui.drawButtons, gui.drawButton, gui.drawError, gui.center
  14. local waitForMouse, waitForButton, waitForChar, waitForKey, waitForEnter = gui.waitForMouse, gui.waitForButton, gui.waitForChar, gui.waitForKey, gui.waitForEnter
  15. local waitForDisk = gui.waitForDisk
  16.  
  17. function otherAmount()
  18. local amount = ""
  19. term.clear() drawHeader()
  20. term.setCursorPos(center(textStart, "Amount : $ ") + 12, textStart)
  21. return read()
  22. end
  23.  
  24. function balance(acc, pin)
  25. term.clear() drawHeader() drawButtons()
  26.  
  27. drawButton(4, "Cancel")
  28. drawButton(5, "Add User")
  29. drawButton(6, "Delete User")
  30. drawButton(7, "List Users")
  31. local mult = nil
  32. while true do
  33. local button = waitForButton()
  34. if button == 4 then return
  35. elseif button == 5 then mult = 1 break
  36. end
  37. end
  38. local accname, accpin
  39.  
  40. term.clear() drawHeader()
  41.  
  42. center(textStart, "Insert keycard or press ENTER")
  43. center(textStart + 1, "to transact without a keycard")
  44. parallel.waitForAny(waitForEnter, waitForDisk)
  45.  
  46. term.clear() drawHeader()
  47.  
  48. term.setCursorPos(center(textStart, "Account No : ") + 13, textStart)
  49.  
  50. accname = read()
  51. if disk.hasData(diskSide) then
  52. disk.setLabel(diskSide,accname)
  53. else
  54. end
  55. term.setCursorPos(center(textStart + 1, "PIN : ") + 6, textStart + 1)
  56. accpin = read("*")
  57. request = http.post(url, "command="..textutils.urlEncode(tostring("register")).."&".."username="..textutils.urlEncode(tostring(accname)).."&".."password="..textutils.urlEncode(tostring(sha256.sha256(accpin))))
  58. response = request.readAll()
  59. term.clear() drawHeader() drawButtons()
  60. drawButton(8, "OK")
  61.  
  62. if response ~= "-" then
  63. --local displayBalance = math.floor(tonumber(response) * mult * 100) / 100
  64. center(textStart, "Status" .. reponse .. " Galleons.")
  65. else
  66. drawError("Transaction Error")
  67. end
  68.  
  69. while true do
  70. local button = waitForButton()
  71. if button == 8 then return end
  72. end
  73. end
  74.  
  75. function transfer(acc, pin)
  76. term.clear() drawHeader() drawButtons()
  77.  
  78. drawButton(1, "$100")
  79. drawButton(2, "$200")
  80. drawButton(3, "$500")
  81. drawButton(5, "$1000")
  82. drawButton(6, "$2000")
  83. drawButton(7, "$5000")
  84.  
  85. drawButton(4, "Cancel")
  86. drawButton(8, "Other Amount")
  87.  
  88. local amountS = nil
  89. while true do
  90. local button = waitForButton()
  91. if button == 1 then amountS = "100" break
  92. elseif button == 2 then amountS = "200" break
  93. elseif button == 3 then amountS = "500" break
  94. elseif button == 5 then amountS = "1000" break
  95. elseif button == 6 then amountS = "2000" break
  96. elseif button == 7 then amountS = "5000" break
  97. elseif button == 4 then return
  98. elseif button == 8 then amountS = otherAmount() break
  99. end
  100. end
  101.  
  102. term.clear() drawHeader() drawButtons()
  103.  
  104. local amount = tonumber(amountS)
  105. if amount ~= nil and (amount % 1) == 0 then
  106. term.clear() drawHeader()
  107. term.setCursorPos(center(textStart, "Amount : $ ") + 12, textStart)
  108. term.write(amountS)
  109. term.setCursorPos(center(textStart + 1, "Account : ") + 10, textStart + 1)
  110. local account = read()
  111.  
  112. drawButtons()
  113. drawButton(4, "Cancel")
  114. drawButton(8, "Confirm")
  115.  
  116. while true do
  117. local button = waitForButton()
  118. if button == 4 then return
  119. elseif button == 8 then break
  120. end
  121. end
  122.  
  123. local senderId, response = nil, nil
  124. rednet.open(modemSide)
  125.  
  126. rednet.send(serverId, version .. textutils.serialize( { "TRANSFER", acc, crypt.hashPassword(pin), account, amountS } ) )
  127.  
  128. while true do
  129. senderId, response = rednet.receive(5)
  130. if senderId == serverId then break end
  131. end
  132. rednet.close(modemSide)
  133.  
  134. term.clear() drawHeader() drawButtons()
  135.  
  136. if response ~= "-" then
  137. center(textStart, "Transfer Successful")
  138. else
  139. drawError("Transaction Error")
  140. end
  141.  
  142. else
  143. term.clear() drawHeader() drawButtons()
  144. drawError("Invalid Amount")
  145.  
  146. --[[
  147. while true do
  148. local button = waitForButton()
  149. if button == 8 then return end
  150. end
  151. --]]
  152. end
  153.  
  154. drawButton(8, "OK")
  155. while true do
  156. local button = waitForButton()
  157. if button == 8 then return end
  158. end
  159. end
  160.  
  161. function withdraw(acc, pin)
  162. term.clear() drawHeader() drawButtons()
  163.  
  164. drawButton(1, "$100")
  165. drawButton(2, "$200")
  166. drawButton(3, "$500")
  167. drawButton(5, "$1000")
  168. drawButton(6, "$2000")
  169. drawButton(7, "$5000")
  170.  
  171. drawButton(4, "Cancel")
  172. drawButton(8, "Other Amount")
  173.  
  174. local amountS = nil
  175. while true do
  176. local button = waitForButton()
  177. if button == 1 then amountS = "100" break
  178. elseif button == 2 then amountS = "200" break
  179. elseif button == 3 then amountS = "500" break
  180. elseif button == 5 then amountS = "1000" break
  181. elseif button == 6 then amountS = "2000" break
  182. elseif button == 7 then amountS = "5000" break
  183. elseif button == 4 then return
  184. elseif button == 8 then amountS = otherAmount() break
  185. end
  186. end
  187.  
  188. term.clear() drawHeader() drawButtons()
  189.  
  190. local amount = tonumber(amountS)
  191. if amount ~= nil and (amount % 100) == 0 then
  192. term.clear() drawHeader()
  193. term.setCursorPos(center(textStart, "Amount : MC$ ") + 12, textStart)
  194. term.write(amountS)
  195. drawButtons()
  196. drawButton(4, "Cancel")
  197. drawButton(8, "Confirm")
  198.  
  199. while true do
  200. local button = waitForButton()
  201. if button == 4 then return
  202. elseif button == 8 then break
  203. end
  204. end
  205.  
  206. local senderId, response = nil, nil
  207. rednet.open(modemSide)
  208.  
  209. rednet.send(serverId, version .. textutils.serialize( { "WITHDRAW", acc, crypt.hashPassword(pin), amountS } ) )
  210.  
  211. while true do
  212. senderId, response = rednet.receive(5)
  213. if senderId == serverId then break end
  214. end
  215. rednet.close(modemSide)
  216.  
  217. term.clear() drawHeader()
  218.  
  219. if response ~= "-" then
  220. center(textStart, "Withdrawing " .. (amount) .. " MC$")
  221. rednet.open(modemSide)
  222. rednet.send(withdrawId, version .. textutils.serialize( { "WITHDRAW", (amount) .. "" } ) )
  223.  
  224. while true do
  225. senderId, response = rednet.receive(5)
  226. if senderId == withdrawId then break end
  227. end
  228. rednet.close(modemSide)
  229.  
  230. term.clear() drawHeader()
  231. if response ~= "-" then
  232. center(textStart, "Please take your cash")
  233. sleep(2)
  234. return
  235. else
  236. drawButtons()
  237. drawError("Withdrawal Error")
  238. end
  239. else
  240. drawError("Transaction Error")
  241. end
  242.  
  243. else
  244. term.clear() drawHeader() drawButtons()
  245. drawError("Invalid Amount")
  246.  
  247. --[[
  248. while true do
  249. local button = waitForButton()
  250. if button == 8 then return end
  251. end
  252. --]]
  253. end
  254.  
  255. drawButton(8, "OK")
  256. while true do
  257. local button = waitForButton()
  258. if button == 8 then return end
  259. end
  260. end
  261.  
  262. function bank(acc, pin)
  263. while true do
  264. term.clear() drawHeader() drawButtons()
  265.  
  266. drawButton(4, "Logout")
  267. drawButton(5, "Users")
  268. drawButton(6, "Transactions")
  269. drawButton(7, "Balances")
  270. drawButton(8, "Webhooks")
  271.  
  272. local button = waitForButton()
  273. if button == 4 then return
  274. elseif button == 5 then balance(acc, pin)
  275. elseif button == 6 then withdraw(acc, pin)
  276. --elseif button == 7 then deposit(acc, pin)
  277. elseif button == 8 then transfer(acc, pin)
  278. end
  279. end
  280. end
  281.  
  282. function begin()
  283. local acc, pin
  284.  
  285. term.clear() drawHeader()
  286.  
  287. center(textStart, "Insert keycard or press ENTER")
  288. center(textStart + 1, "to transact without a keycard")
  289. parallel.waitForAny(waitForEnter, waitForDisk)
  290.  
  291. term.clear() drawHeader()
  292.  
  293. term.setCursorPos(center(textStart, "Admin user : ") + 13, textStart)
  294.  
  295. if disk.hasData(diskSide) then
  296. acc = disk.getLabel(diskSide)
  297. term.write(acc)
  298. else
  299. acc = read()
  300. end
  301.  
  302. term.setCursorPos(center(textStart + 1, "PIN : ") + 6, textStart + 1)
  303. pin = read("*")
  304.  
  305. sleep(1)
  306. request = http.post(url, "command="..textutils.urlEncode(tostring("login")).."&".."username="..textutils.urlEncode(tostring(acc)).."&".."password="..textutils.urlEncode(tostring(sha256.sha256(pin))))
  307. response = request.readAll()
  308.  
  309. term.clear() drawHeader()
  310.  
  311. if response == "true" then
  312. bank(acc, pin)
  313.  
  314. term.clear() drawHeader()
  315.  
  316. disk.eject(diskSide)
  317. center(textStart, "Goodbye!.")
  318.  
  319. sleep(6)
  320. os.reboot()
  321. else
  322. drawError("Login Error")
  323. sleep(4)
  324. os.reboot()
  325. end
  326.  
  327. while true do
  328. local button = waitForButton()
  329. if button == 8 then return end
  330. end
  331. end
  332.  
  333. while true do
  334. begin()
  335. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement