xXm0dzXx

Spam Block

Nov 11th, 2012
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.96 KB | None | 0 0
  1. local x,y = term.getSize()
  2. local currentURL = "home"
  3. local hasModem = true
  4. local theme = "default"
  5. local rednetType = "Rednet"
  6. local ip = http.get("http://whatthehellismyip.com/?ipraw").readAll()
  7. browserAgent = "rex_renewed"
  8.  
  9. local WebsiteDatabase = "http://nexusindustries.x10.mx/Websites/folder/" --Folder with all the sites
  10. local ApiPath = "http://nexusindustries.x10.mx/Websites/mcmain.php" --Path API is stored
  11.  
  12. local function cPrint(text)
  13. x2,y2 = term.getCursorPos()
  14. term.setCursorPos(math.ceil((x / 2) - (text:len() / 2)), y2)
  15. write(text.. "\n")
  16. end
  17.  
  18. local function homePage()
  19. cPrint("__________ _______________ ___")
  20. cPrint("\\______ \\\\_ _____/\\ \\/ /")
  21. cPrint(" | _/ | __)_ \\ / ")
  22. cPrint(" | | \\ | \\ / \\ ")
  23. cPrint(" |____|_ //_______ //___/\\ \\")
  24. cPrint(" \\/ \\/ \\_/")
  25. cPrint("~~=> Renewed <=~~")
  26. print()
  27. cPrint("Default sites: ")
  28. cPrint("rdnt://home Default Homepage")
  29. cPrint("rdnt://settings Settings ")
  30. cPrint("rdnt://newsite Website Maker ")
  31. print()
  32. cPrint("rdnt://exit")
  33. cPrint("Check out")
  34. cPrint("play.geevancraft.com")
  35. end
  36.  
  37. function rnetHost()
  38. term.clear()
  39. term.setCursorPos(1,1)
  40. cPrint("Rednet Explorer Online Servers")
  41. write("Domain (ex: YourDomain.com): rnet://")
  42. domain = read()
  43. write("Path to file: ")
  44. path = read()
  45. if fs.exists(path) then
  46. file = fs.open(path, "r")
  47. if file then
  48. data = file.readAll()
  49. file.close()
  50. if not data then
  51. print("Failed to read " ..path)
  52. return
  53. end
  54. local response = http.post(
  55. ApiPath,
  56. "type=upload&"..
  57. "user=guest&"..
  58. "pass=guest&"..
  59. "name=".. textutils.urlEncode(domain) .. "&"..
  60. "data=" ..textutils.urlEncode(data)
  61. )
  62.  
  63. if response then
  64. local sResponse = response.readAll()
  65. response.close()
  66. print("Done!")
  67. print("Log: ")
  68. sleep(0.5)
  69. if string.find(sResponse, "success") then
  70. print("Uploading " ..shell.resolve(path).. " complete!")
  71. print("Errors: 0")
  72. print("\nGo to " ..domain.. " to check the site!")
  73. else
  74. print("Failed : " ..sResponse)
  75. print()
  76. if sResponse == "Write_lock" then
  77. print("The write_lock error means you have been locked out from uploading because are a hacker, a troll, or a spammer that is trying to upload a file to mess up my database and you are gonna be hunted down and killed (not IRL) by my team :)\n\nFYI, your IP has been traced.")
  78. end
  79. end
  80. else
  81. print("Failed to connect to database.")
  82. end
  83. else
  84. print("Failed to open " ..path)
  85. end
  86. else
  87. print(path.. " doesn't exist.")
  88. end
  89. end
  90.  
  91. local function newButton( currentID, id, text, fez )
  92. if not fez then
  93. term.clearLine()
  94. end
  95. if currentID == id then
  96. cPrint("[ " ..text.. " ]")
  97. else
  98. cPrint(text)
  99. end
  100. end
  101.  
  102. local function settings()
  103. local currentID = 1
  104. local function settingMenu()
  105. term.setCursorPos(1,5)
  106. cPrint("Configuration")
  107. print()
  108. newButton( currentID, 1, "Download Settings (" ..rednetType.. ")" )
  109. newButton( currentID, 2, "Homepage" )
  110. newButton( currentID, 3, "Extensions (NYI)" )
  111. newButton( currentID, 4, "Theme (" ..theme.. ")" )
  112. print()
  113. newButton( currentID, 5, "Exit" )
  114. end
  115.  
  116. while true do
  117. settingMenu()
  118. local event, key = os.pullEvent("key")
  119. if key == keys.up then
  120. if currentID ~= 1 then
  121. currentID = currentID -1
  122. end
  123. elseif key == keys.down then
  124. if currentID ~= 5 then
  125. currentID = currentID +1
  126. end
  127. elseif key == keys.enter then
  128. if currentID == 1 then
  129. if rednetType == "Rednet" then
  130. rednetType = "HTTP"
  131. elseif rednetType == "HTTP" then
  132. rednetType = "rnet"
  133. elseif rednetType == "rnet" then
  134. rednetType = "Rednet"
  135. end
  136.  
  137. loadWebpage( "settings" )
  138. elseif currentID == 2 then
  139. local newID = 1
  140. local currentTheme = ""
  141. local function settingMenu()
  142. term.clear()
  143. term.setCursorPos(1,1)
  144. cPrint("Homepage")
  145. file = fs.open( ".rexsettings", "r" )
  146. cPrint( "rdnt://" ..file.readLine() )
  147. currentTheme = file.readLine()
  148. file.close()
  149. print()
  150. newButton( newID, 1, "Change" )
  151. newButton( newID, 2, "Done" )
  152. end
  153.  
  154. while true do
  155. settingMenu()
  156. local event, key = os.pullEvent("key")
  157. if key == keys.up then
  158. newID = 1
  159. elseif key == keys.down then
  160. newID = 2
  161. elseif key == keys.enter then
  162. if newID == 1 then
  163. term.setCursorPos(1,2)
  164. term.clearLine()
  165. write("rdnt://")
  166. local address = read()
  167. file = fs.open( ".rexsettings", "w" )
  168. file.write( address.. "\n" )
  169. file.write( currentTheme )
  170. file.close()
  171. else
  172. loadWebpage("settings")
  173. end
  174. end
  175. end
  176. elseif currentID == 3 then
  177. elseif currentID == 4 then
  178. if theme == "default" then
  179. theme = "old"
  180. elseif theme == "old" then
  181. theme = "edit"
  182. elseif theme == "edit" then
  183. theme = "default"
  184. end
  185.  
  186. file = fs.open( ".rexsettings", "r" )
  187. local humpage = file.readLine()
  188. file.close()
  189. file = fs.open( ".rexsettings", "w" )
  190. file.write( humpage.. "\n" )
  191. file.write( theme )
  192. file.close()
  193. loadWebpage( "settings" )
  194. elseif currentID == 5 then
  195. break
  196. end
  197. end
  198. end
  199.  
  200. loadWebpage( "home" )
  201. end
  202.  
  203. local function newButton2( currentID, id, text )
  204. term.clearLine()
  205. if currentID == id then
  206. print("[>] " ..text)
  207. else
  208. print("[ ] " ..text)
  209. end
  210. end
  211.  
  212. function newServer()
  213. print("Welcome to Rednet Servers!")
  214. print("Before we begin, please enter the URL of the website you want: ")
  215. write("\nrdnt://")
  216. newURL = read()
  217. rednet.broadcast( newURL )
  218. local id,message = rednet.receive( 0.5 )
  219. if message then
  220. print( "A website with this URL is already owned by " ..id.. ", continue? (Y/N)" )
  221. if string.lower( read() ) ~= "y" then
  222. return
  223. end
  224. end
  225.  
  226. function drawFooter()
  227. term.clear()
  228. term.setCursorPos(1,1)
  229. write("Hosting rdnt://" ..newURL)
  230. local x,y = term.getSize()
  231. for i=1,x do
  232. term.setCursorPos(i,2)
  233. write("-")
  234. end
  235. end
  236.  
  237. function drawBrowser()
  238. term.setCursorPos(1,3)
  239. if fs.exists( "." ..newURL ) and fs.isDir( "." ..newURL ) then
  240. if fs.exists( "." ..newURL.. "/index" ) then
  241. else
  242. file = fs.open( "." ..newURL.. "/index", "w" )
  243. file.write( "print(\"This site has not yet been configured.\")" )
  244. file.close()
  245. end
  246. else
  247. fs.makeDir( "." ..newURL )
  248. file = fs.open( "." ..newURL.. "/index", "w" )
  249. file.write( "print(\"This site has not yet been configured.\")" )
  250. file.close()
  251. end
  252.  
  253. local filePath = fs.list( "." ..newURL )
  254. for i=1,#filePath do
  255. newButton2( currentID, i, filePath[i] )
  256. end
  257. end
  258.  
  259. local status = "[Delete]New Edit"
  260. currentID = 1
  261. while true do
  262. drawFooter()
  263. drawBrowser()
  264. term.setCursorPos(1,y)
  265. term.clearLine()
  266. write(status)
  267. local event, key, message = os.pullEvent()
  268. if event == "rednet_message" then
  269. if message == newURL then
  270. file = fs.open( "." ..newURL.. "/index", "r" )
  271. rednet.send( key, file.readAll() )
  272. file.close()
  273. elseif fs.exists( "." ..message ) then
  274. file = fs.open( "." ..message, "r" )
  275. if file then
  276. rednet.send( key, file.readAll() )
  277. file.close()
  278. end
  279. end
  280. elseif event == "key" then
  281. if key == keys.left then
  282. if status == " Delete[New]Edit" then
  283. status = "[Delete]New Edit"
  284. elseif status == " Delete New[Edit]" then
  285. status = " Delete[New]Edit"
  286. end
  287. elseif key == keys.right then
  288. if status == " Delete[New]Edit" then
  289. status = " Delete New[Edit]"
  290. elseif status == "[Delete]New Edit" then
  291. status = " Delete[New]Edit"
  292. end
  293. elseif key == keys.up then
  294. if currentID ~= 1 then
  295. currentID = currentID -1
  296. end
  297. elseif key == keys.down then
  298. if currentID ~= #fs.list( "." ..newURL ) then
  299. currentID = currentID +1
  300. end
  301. elseif key == keys.enter then
  302. if status == "[Delete]New Edit" then
  303. local filePath = fs.list( "." ..newURL )
  304. fs.delete( "." ..newURL.. "/" ..filePath[ currentID ] )
  305. currentID = 1
  306. elseif status == " Delete[New]Edit" then
  307. term.setCursorPos(1,y)
  308. term.clearLine()
  309. write("URL: rdnt://" ..newURL.. "/")
  310. local fileName = read()
  311. local number = 1
  312. local origName = fileName
  313.  
  314. while fs.exists( "." ..newURL.. "/" ..fileName ) do
  315. fileName = origName.. " [" ..number.. "]"
  316. number = number +1
  317. end
  318.  
  319. file = fs.open( "." ..newURL.. "/" ..fileName, "w" )
  320. file.close()
  321. else
  322. local filePath = fs.list( "." ..newURL )
  323. shouldIendThis = false
  324.  
  325. function a()
  326. while true do
  327. local timer = os.startTimer( 0.5 )
  328. local event, key, message = os.pullEvent()
  329. if event == "rednet_message" then
  330. if message == newURL then
  331. file = fs.open( "." ..newURL.. "/index", "r" )
  332. rednet.send( key, file.readAll() )
  333. file.close()
  334. elseif fs.exists( "." ..message ) then
  335. file = fs.open( "." ..message, "r" )
  336. if file then
  337. rednet.send( key, file.readAll() )
  338. file.close()
  339. end
  340. elseif message == "rednet.api.ping.searchengine" then
  341. rednet.send( key, newURL )
  342. end
  343. elseif shouldIendThis then
  344. break
  345. end
  346. end
  347. end
  348.  
  349. function b()
  350. shell.run( "edit", "." ..newURL.. "/" ..filePath[ currentID ] )
  351. shouldIendThis = true
  352. end
  353.  
  354. parallel.waitForAny( a, b )
  355. drawFooter()
  356. end
  357. end
  358. end
  359. end
  360. end
  361.  
  362. function loadWebpage( url, id )
  363. if not url then
  364. url = currentURL
  365. end
  366. currentURL = url
  367.  
  368. term.clear()
  369. term.setCursorPos(1,1)
  370.  
  371. if theme == "default" then
  372. if rednetType == "HTTP" then
  373. print("http://" ..currentURL)
  374. elseif rednetType == "rnet" then
  375. print("rnet://" ..currentURL)
  376. else
  377. print("rdnt://" ..currentURL)
  378. end
  379.  
  380. for i=1,x do
  381. term.setCursorPos(i,2)
  382. write("-")
  383. end
  384. term.setCursorPos(1,3)
  385. elseif theme == "old" then
  386. cPrint("Rednet Explorer")
  387. if rednetType == "HTTP" then
  388. cPrint("http://" ..currentURL )
  389. elseif rednetType == "rnet" then
  390. cPrint("rnet://" ..currentURL )
  391. else
  392. cPrint("rdnt://" ..currentURL)
  393. end
  394. term.setCursorPos(1,4)
  395. elseif theme == "edit" then
  396. term.setCursorPos(1,y)
  397. write("Press CTRL to access menu")
  398. end
  399.  
  400. if url == "home" then
  401. homePage()
  402. elseif url == "newsite" then
  403. if rednetType == "rnet" then
  404. rnetHost()
  405. else
  406. newServer()
  407. end
  408. elseif url == "settings" then
  409. settings()
  410. elseif url == "exit" then
  411. error()
  412. else
  413. if rednetType == "HTTP" then
  414. http.request( "http://" ..url )
  415. readTimedOut = os.startTimer(3)
  416. local text = ""
  417. while true do
  418. local event, body, url = os.pullEvent()
  419. if event == "http_success" then
  420. text = url.readAll()
  421. break
  422. elseif event == "http_failed" then
  423. text = "Failed to load"
  424. break
  425. elseif event == "timer" and body == readTimedOut then
  426. text = "Read timed out"
  427. break
  428. end
  429. end
  430.  
  431. print( text )
  432. elseif rednetType == "rnet" then
  433. local response = http.post(
  434. ApiPath,
  435. "user=guest&"..
  436. "pass=guest&"..
  437. "type=download&"..
  438. "data=blank&"..
  439. "name=".. textutils.urlEncode(url)
  440. )
  441.  
  442. if response then
  443. local body = response.readAll()
  444. response.close()
  445. if body == nil or body == "" or string.find(body, "auth_error") or string.find(body, "file_not_found") then
  446. print("Unable to load webpage.")
  447. print("\nThe website you have requested was unable to work. If you beleive this is a error please contact your rednet service providers. (RSP)")
  448. print("\nThis may be the result of the list below: ")
  449. print("1) The site you requested is down.")
  450. print("2) The site you requested is corrupted.")
  451. print("3) The site you requested forgot to put a modem")
  452. print("4) You have no modem")
  453. print("5) This message is faked, and you have a virus now.")
  454. else
  455. fs.delete(".downloadedWebsite")
  456. webpage = fs.open(".downloadedWebsite", "w")
  457. webpage.write(body)
  458. webpage.close()
  459. shell.run(".downloadedWebsite")
  460. end
  461. end
  462. else
  463. if id then
  464. fs.delete(".downloadedWebsite")
  465. file = fs.open(".downloadedWebsite", "w")
  466. file.write( id )
  467. file.close()
  468. shell.run(".downloadedWebsite")
  469. else
  470. if hasModem then
  471. if id then
  472. rednet.send( id, url )
  473. else
  474. rednet.broadcast( url )
  475. end
  476.  
  477. local timer = os.startTimer(0)
  478. local messages = {}
  479. local ids = {}
  480. repeat
  481. local event, key, message = os.pullEvent()
  482. if event == "rednet_message" then
  483. if ids[key] then
  484. ids[key] = ids[key] +1
  485. else
  486. ids[key] = 1
  487. end
  488.  
  489. messages[#messages+1] = {
  490. ["id"] = key,
  491. ["code"] = message,
  492. }
  493. end
  494. until event == "timer" and key == timer
  495.  
  496. local newmessages = {}
  497. for i,v in pairs( ids ) do
  498. if v < 4 then
  499. newmessages[i] = v
  500. end
  501. end
  502.  
  503. messages = newmessages
  504. if #messages == 1 then
  505. fs.delete(".downloadedWebsite")
  506. file = fs.open(".downloadedWebsite", "w")
  507. file.write( messages[1]["code"] )
  508. file.close()
  509. shell.run(".downloadedWebsite")
  510. elseif #messages == 0 then
  511. print("Unable to load webpage.")
  512. print("\nThe website you have requested was unable to work. If you beleive this is a error please contact your rednet service providers. (RSP)")
  513. print("\nThis may be the result of the list below: ")
  514. print("1) The site you requested is down.")
  515. print("2) The site you requested is corrupted.")
  516. print("3) The site you requested forgot to put a modem")
  517. print("4) You have no modem")
  518. print("5) This message is faked, and you have a virus now.")
  519. else
  520. local id = 0
  521. local valvez = true
  522. id = messages[1]["id"]
  523. for i=2,#messages do
  524. if messages[i]["id"] ~= id then
  525. valvez = false
  526. end
  527. end
  528.  
  529. if valvez then
  530. fs.delete(".downloadedWebsite")
  531. file = fs.open(".downloadedWebsite", "w")
  532. file.write( messages[1]["code"] )
  533. file.close()
  534. shell.run(".downloadedWebsite")
  535. else
  536. local x1, y1 = term.getCursorPos()
  537. local currentID = 1
  538. while true do
  539. term.setCursorPos(1,y1)
  540. cPrint("+---Conflict Warning---+")
  541. cPrint("| 2 or more hosts have |")
  542. cPrint("| been found, please |")
  543. cPrint("| select the correct ID|")
  544. cPrint("+----------------------+")
  545. for i=1,#messages do
  546. local xx, yy = term.getCursorPos()
  547. cPrint("| |")
  548. term.setCursorPos(xx, yy)
  549. newButton( currentID, i, "#" ..messages[i]["id"], true )
  550. end
  551.  
  552. cPrint("+----------------------+")
  553.  
  554. local event, key = os.pullEvent("key")
  555. if key == keys.up then
  556. if currentID ~= 1 then
  557. currentID = currentID -1
  558. end
  559. elseif key == keys.down then
  560. if currentID ~= #messages then
  561. currentID = currentID +1
  562. end
  563. elseif key == keys.enter then
  564. local code = messages[currentID]["code"]
  565. loadWebpage( url, code )
  566. break
  567. end
  568. end
  569. end
  570. end
  571. else
  572. print("\nUnable to connect because no modem has been detected on your computer. Please attatch a modem and restart this program. ")
  573. end
  574. end
  575. end
  576. end
  577.  
  578. if theme == "default" then
  579. term.setCursorPos(x-#("Press CTRL to brows"), 1)
  580. write("Press CTRL to browse")
  581. elseif theme == "old" then
  582. term.setCursorPos(x-#("Press CTRL to explor"), y)
  583. write("Press CTRL to explore")
  584. end
  585.  
  586. repeat
  587. local _, key = os.pullEvent("key")
  588. until key == 29 or key == 157
  589.  
  590. if theme == "default" then
  591. term.setCursorPos(1,1)
  592. term.clearLine()
  593.  
  594. if rednetType == "HTTP" then
  595. write("http://")
  596. elseif rednetType == "rnet" then
  597. write("rnet://")
  598. else
  599. write("rdnt://")
  600. end
  601. elseif theme == "old" or theme == "edit" then
  602. term.setCursorPos(1,2)
  603. term.clearLine()
  604.  
  605. if rednetType == "HTTP" then
  606. write("http://")
  607. elseif rednetType == "rnet" then
  608. write("rnet://")
  609. else
  610. write("rdnt://")
  611. end
  612. end
  613.  
  614. loadWebpage( read() )
  615. end
  616.  
  617. local function openModems()
  618. for i,v in pairs( rs.getSides() ) do
  619. if rednet.open( v ) then
  620. return true
  621. end
  622. end
  623. end
  624.  
  625. openModems()
  626.  
  627. if fs.exists(".rexsettings") then
  628. file = fs.open(".rexsettings", "r")
  629. currentURL = file.readLine()
  630. theme = file.readLine()
  631. file.close()
  632. else
  633. file = fs.open(".rexsettings", "w")
  634. file.write( "home\n" )
  635. file.write( "default" )
  636. file.close()
  637. end
  638.  
  639. ---API/Compatibility---
  640. centerPrint = cPrint
  641. reDirect = loadWebpage
  642. loadPage = loadWebpage
  643. ---API/Compatibility---
  644.  
  645. loadWebpage()
Advertisement
Add Comment
Please, Sign In to add comment