Advertisement
Guest User

Untitled

a guest
Apr 13th, 2016
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local tArgs = { ... }
  2. local passwordread
  3.  
  4. local function clear()
  5. term.clear()
  6. term.setCursorPos(1, 1)
  7. end
  8.  
  9. function findModem()
  10.   for _, v in pairs( rs.getSides() ) do
  11.         if peripheral.isPresent( v ) and peripheral.getType( v ) == "modem" then
  12.           rednet.open(v)
  13.         end
  14.   end
  15. end
  16.  
  17. if #tArgs < 1 then
  18. clear()
  19. term.setTextColor(colors.white)
  20. print("Usage: ")
  21. print("email create")
  22. print("email send")
  23. print("email download")
  24. print("email delete")
  25. print("email admin")
  26. print("email update")
  27. term.setTextColor(colors.white)
  28. return
  29. end
  30.  
  31. local Args = shell.resolve( tArgs[1] )
  32. if Args == "create" then
  33. term.clear()
  34. term.setCursorPos(1, 1)
  35. term.setTextColor(colors.lightBlue)
  36. print("ComputerCraft Email Setup")
  37. write("New Username: ")
  38. UserName = read().."@Cc.com"
  39. print()
  40. write("New Password: ")
  41. pass1 = read("*")
  42. print()
  43. write("Repeat Password: ")
  44. pass2 = read("*")
  45. if pass1 == pass2 then
  46. if fs.exists("/disk/"..UserName) then
  47. clear()
  48. term.setTextColor(colors.red)
  49. print("The email address "..UserName.." is in use!")
  50. term.setTextColor(colors.white)
  51. return
  52. end
  53. w = fs.open("/disk/"..UserName, "w")
  54. w.writeLine(pass1)
  55. w.writeLine(os.getComputerID())
  56. w.close()
  57. print()
  58. clear()
  59. term.setTextColor(colors.green)
  60. print("Successfully created "..UserName.."!")
  61. term.setTextColor(colors.white)
  62. os.sleep(3)
  63. os.reboot()
  64. else
  65. clear()
  66. term.setTextColor(colors.red)
  67. print("The password did not match!")
  68. term.setTextColor(colors.white)
  69. return
  70. end
  71. elseif Args == "send" then
  72. term.setTextColor(colors.yellow)
  73. print("If you're stuck here press and hold CTRL + R to reboot your pc (this error can be caused by an network error).")
  74. findModem()
  75. rednet.broadcast("getid")
  76. id, msg = rednet.receive()
  77. clear()
  78. term.setTextColor(colors.lightBlue)
  79. print("ComputerCraft Email Sender")
  80. print("Please login with your email account")
  81. print()
  82. write("Email Address: ")
  83. mail = read()
  84. print()
  85. if not fs.exists("/disk/"..mail) then
  86. clear()
  87. term.setTextColor(colors.red)
  88. print("Email Address is not valid!")
  89. term.setTextColor(colors.white)
  90. return
  91. elseif mail == nil or mail == "" then
  92. clear()
  93. term.setTextColor(colors.red)
  94. print("Email Address is not valid!")
  95. term.setTextColor(colors.white)
  96. return
  97. end
  98. write("Password: ")
  99. pass = read("*")
  100. print()
  101. r = fs.open("/disk/"..mail, "r")
  102. passwordread = r.readLine()
  103. r.close()
  104. if pass ~= passwordread then
  105. clear()
  106. term.setTextColor(colors.red)
  107. print("The password is incorrect!")
  108. term.setTextColor(colors.white)
  109. return
  110. end
  111. clear()
  112. write("Receiver Email Address: ")
  113. sendmail = read()
  114. print()
  115. print("Message to "..sendmail.." (Type ^Z to end the message)")
  116. local Message = {}
  117. local lenght
  118. local nownr
  119. nownr = 1
  120. local nr
  121. nr = 1
  122. while true do
  123. messagesend = read()
  124. if messagesend == "^Z" then
  125. rednet.send(id, "receive")
  126. os.sleep(.5)
  127. rednet.send(id, sendmail)
  128. os.sleep(.5)
  129. rednet.send(id, "receive2")
  130. os.sleep(0.2)
  131. rednet.send(id, mail)
  132. lenght = table.getn(Message)
  133. while nownr ~= lenght + 1 do
  134. os.sleep(0.1)
  135. rednet.send(id, Message[nownr])
  136. nownr = nownr + 1
  137. end
  138. rednet.send(id, "end8765432190")
  139. clear()
  140. term.setTextColor(colors.green)
  141. print("The email has been sent to "..sendmail..".")
  142. term.setTextColor(colors.white)
  143. return
  144. else
  145. Message[nr] = messagesend
  146. nr = nr + 1
  147. end
  148. end
  149. elseif Args == "download" then
  150. term.setTextColor(colors.yellow)
  151. print("If you're stuck here press and hold CTRL + R to reboot your pc (this can be caused by an network error).")
  152. findModem()
  153. rednet.broadcast("getid")
  154. id, msg = rednet.receive()
  155. clear()
  156. term.setTextColor(colors.lightBlue)
  157. print("ComputerCraft Email Download")
  158. print("Please login with your email account to download your mail")
  159. print()
  160. write("Email Address: ")
  161. mail = read()
  162. print()
  163. if not fs.exists("/disk/"..mail) then
  164. clear()
  165. term.setTextColor(colors.red)
  166. print("Email Address is not valid!")
  167. term.setTextColor(colors.white)
  168. return
  169. elseif mail == nil or mail == "" then
  170. clear()
  171. term.setTextColor(colors.red)
  172. print("Email Address is not valid!")
  173. term.setTextColor(colors.white)
  174. return
  175. end
  176. write("Password: ")
  177. pass = read("*")
  178. print()
  179. r = fs.open("/disk/"..mail, "r")
  180. passwordread = r.readLine()
  181. r.close()
  182. if pass ~= passwordread then
  183. clear()
  184. term.setTextColor(colors.red)
  185. print("The password is incorrect!")
  186. term.setTextColor(colors.white)
  187. return
  188. end
  189. rednet.send(id, "receive")
  190. os.sleep(0.5)
  191. rednet.send(id, mail)
  192. os.sleep(0.5)
  193. rednet.send(id, "download")
  194. o = fs.open("mail", "w")
  195. id, mailmsg = rednet.receive()
  196. o.writeLine(mailmsg)
  197. o.close()
  198. x = fs.open("/disk/startup", "w")
  199. x.writeLine('fs.delete("/mail")')
  200. x.writeLine('fs.delete("/disk/startup")')
  201. x.close()
  202. shell.run("edit mail")
  203. term.setTextColor(colors.green)
  204. print("The mail has been read!")
  205. os.sleep(3)
  206. os.reboot()
  207. elseif Args == "delete" then
  208. term.clear()
  209. term.setCursorPos(1, 1)
  210. term.setTextColor(colors.lightBlue)
  211. print("ComputerCraft Email Remove")
  212. print("Please login with your email account to delete it")
  213. print()
  214. write("Email Address: ")
  215. mail = read()
  216. print()
  217. if not fs.exists("/disk/"..mail) then
  218. clear()
  219. term.setTextColor(colors.red)
  220. print("Email Address is not valid!")
  221. term.setTextColor(colors.white)
  222. return
  223. elseif mail == nil or mail == "" then
  224. clear()
  225. term.setTextColor(colors.red)
  226. print("Email Address is not valid!")
  227. term.setTextColor(colors.white)
  228. return
  229. end
  230. write("Password: ")
  231. pass = read("*")
  232. print()
  233. r = fs.open("/disk/"..mail, "r")
  234. passwordread = r.readLine()
  235. r.close()
  236. if pass ~= passwordread then
  237. clear()
  238. term.setTextColor(colors.red)
  239. print("The password is incorrect!")
  240. term.setTextColor(colors.white)
  241. return
  242. end
  243. if string.lower(mail) == "admin@cc.com" then
  244. term.setTextColor(colors.red)
  245. print("You cannot delete the admin account!")
  246. term.setTextColor(colors.white)
  247. return
  248. end
  249. clear()
  250. term.setTextColor(colors.red)
  251. print("Are you sure with the removal of the account "..mail.."? [Yes/No]")
  252. answ = read()
  253. if string.lower(answ) == "yes" then
  254. clear()
  255. term.setTextColor(colors.green)
  256. print(mail.." has been removed!")
  257. os.sleep(3)
  258. writer = fs.open("/startup", "w")
  259. writer.writeLine('fs.delete("/disk/'..mail..'")')
  260. writer.writeLine('fs.delete("startup")')
  261. writer.close()
  262. os.reboot()
  263. else
  264. clear()
  265. end
  266. elseif Args == "admin" then
  267. term.clear()
  268. term.setCursorPos(1, 1)
  269. term.setTextColor(colors.yellow)
  270. print("ComputerCraft Email Admin")
  271. print("Please login with your admin account")
  272. print()
  273. write("Email Address: ")
  274. mail = read()
  275. print()
  276. if not fs.exists("/disk/"..mail) then
  277. clear()
  278. term.setTextColor(colors.red)
  279. print("Email Address is not valid!")
  280. term.setTextColor(colors.white)
  281. return
  282. elseif mail == nil or mail == "" then
  283. clear()
  284. term.setTextColor(colors.red)
  285. print("Email Address is not valid!")
  286. term.setTextColor(colors.white)
  287. return
  288. end
  289. write("Password: ")
  290. pass = read("*")
  291. print()
  292. r = fs.open("/disk/"..mail, "r")
  293. passwordread = r.readLine()
  294. typ = r.readLine()
  295. r.close()
  296. if pass ~= passwordread or typ ~= "admin" then
  297. clear()
  298. term.setTextColor(colors.red)
  299. print("The password is incorrect or the type is invalid!")
  300. term.setTextColor(colors.white)
  301. return
  302. end
  303. clear()
  304. term.setTextColor(colors.yellow)
  305. print("ComputerCraft Email Admin")
  306. while true do
  307. term.setTextColor(colors.yellow)
  308. write("> ")
  309. term.setTextColor(colors.white)
  310. cmd = read()
  311. if cmd == "help" then
  312. print("Available commands: ")
  313. print("help")
  314. print("delete")
  315. print("list")
  316. print("clear")
  317. print("exit")
  318. elseif cmd == "send" then
  319. term.setTextColor(colors.red)
  320. print("This command is available in non-admin mode!")
  321. elseif cmd == "create" then
  322. term.setTextColor(colors.red)
  323. print("This command is available in non-admin mode!")
  324. elseif cmd == "download" then
  325. term.setTextColor(colors.red)
  326. print("This command is available in non-admin mode!")
  327. elseif cmd == "update" then
  328. term.setTextColor(colors.red)
  329. print("This command is available in non-admin mode!")
  330. elseif cmd == "admin" then
  331. term.setTextColor(colors.red)
  332. print("Admin mode is already active!")
  333. elseif cmd == "delete" then
  334. clear()
  335. term.setTextColor(colors.yellow)
  336. print("Admin credentials")
  337. print()
  338. write("Email Address: ")
  339. mail = read()
  340. print()
  341. if not fs.exists("/disk/"..mail) then
  342. clear()
  343. term.setTextColor(colors.red)
  344. print("Email Address is not valid!")
  345. term.setTextColor(colors.white)
  346. return
  347. elseif mail == nil or mail == "" then
  348. clear()
  349. term.setTextColor(colors.red)
  350. print("Email Address is not valid!")
  351. term.setTextColor(colors.white)
  352. return
  353. end
  354. write("Password: ")
  355. pass = read("*")
  356. print()
  357. r = fs.open("/disk/"..mail, "r")
  358. passwordread = r.readLine()
  359. typ = r.readLine()
  360. r.close()
  361. if pass ~= passwordread or typ ~= "admin" then
  362. clear()
  363. term.setTextColor(colors.red)
  364. print("The password is incorrect or the type is invalid!")
  365. term.setTextColor(colors.white)
  366. return
  367. end
  368. clear()
  369. term.setTextColor(colors.red)
  370. print("ComputerCraft Admin Email Account Remover")
  371. print("YOU WILL NOT BE ASKED FOR CONFIRMATION!")
  372. print()
  373. write("Email Address: ")
  374. term.setTextColor(colors.white)
  375. mailadr = read()
  376. if string.lower(mailadr) == "admin@cc.com" then
  377. term.setTextColor(colors.red)
  378. print("This account cannot be deleted!")
  379. elseif fs.exists("/disk/"..mailadr) then
  380. fs.delete("/disk/"..mailadr)
  381. term.setTextColor(colors.green)
  382. print(mailadr.." has been deleted.")
  383. else
  384. term.setTextColor(colors.red)
  385. print("This account doesn't exist!")
  386. end
  387. elseif cmd == "exit" then
  388. os.reboot()
  389. elseif cmd == "clear" then
  390. clear()
  391. elseif cmd == "list" then
  392. term.setTextColor(colors.lime)
  393. print("List of email accounts: ")
  394. term.setTextColor(colors.blue)
  395. for i = 1, table.getn(fs.list("/disk")) do
  396. if fs.list("/disk")[i] ~= "email" and fs.list("/disk")[i] ~= "install" then
  397. print(fs.list("/disk")[i])
  398. end
  399. end
  400. else
  401. term.setTextColor(colors.red)
  402. print("No such command")
  403. end
  404. end
  405. elseif Args == "update" then
  406. clear()
  407. term.setTextColor(colors.lightBlue)
  408. print("ComputerCraft Email Updater")
  409. print("Creating backup folder...")
  410. os.sleep(.3)
  411. fs.makeDir("/temp")
  412. print("Moving program to backup folder...")
  413. if fs.exists("/email") then
  414. os.sleep(0.1)
  415. fs.move("email", "/temp/email")
  416. end
  417. print("Downloading and installing new program...")
  418. os.sleep(0.5)
  419. shell.run("pastebin", "get Z5UQsBGd /email")
  420. print("Finalizing...")
  421. os.sleep(1.5)
  422. if fs.exists("/email") then
  423. fs.delete("/temp/email")
  424. fs.delete("/temp")
  425. term.setTextColor(colors.green)
  426. print("Update Completed")
  427. os.sleep(3)
  428. clear()
  429. shell.run("email", "firstuse")
  430. else
  431. term.setTextColor(colors.red)
  432. print("Finalizing failed!")
  433. term.setTextColor(colors.white)
  434. fs.move("/temp/email", "email")
  435. fs.delete("/temp")
  436. end
  437. elseif Args == "firstuse" then
  438. term.setTextColor(colors.white)
  439. print("All email commands")
  440. print()
  441. print("email create   -- creates a mail account")
  442. print("email send     -- send a mail")
  443. print("email download -- receive your mails")
  444. print("email delete   -- delete your mail account")
  445. print("email admin    -- admin only!")
  446. print("email update   -- updates the program")
  447. else
  448. term.setTextColor(colors.red)
  449. print("Usage: ")
  450. print("email create")
  451. print("email send")
  452. print("email download")
  453. print("email delete")
  454. print("email admin")
  455. print("email update")
  456. term.setTextColor(colors.white)
  457. return
  458. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement