Advertisement
shadowkat1010

Untitled

Dec 23rd, 2012
439
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 88.58 KB | None | 0 0
  1.  
  2. --
  3. -- Firewolf Website Browser
  4. -- Made by GravityScore and 1lann
  5. --
  6. -- Original Concept From RednetExplorer 2.4.1
  7. -- RednetExplorer Made by ComputerCraftFan11
  8. --
  9.  
  10.  
  11. -- Features:
  12. -- - Debug mode
  13. -- - Proper support for NDF-OS
  14. -- - Support for normal computers
  15. -- - Christmas Theme
  16. -- - Christmas startup icon
  17. -- * Live Search List Updating
  18.  
  19.  
  20. -- -------- Variables
  21.  
  22. -- Version
  23. local version = "2.3"
  24. local browserAgentTemplate = "Firewolf " .. version
  25. browserAgent = browserAgentTemplate
  26. local tArgs = {...}
  27.  
  28. -- Server Identification
  29. local serverID = "other"
  30. local serverList = {blackwolf = "BlackWolf", geevancraft = "GeevanCraft",
  31. experimental = "Experimental", other = "Other"}
  32.  
  33. -- Updating
  34. local autoupdate = "true"
  35. local incognito = "false"
  36.  
  37. -- Geometry
  38. local w, h = term.getSize()
  39.  
  40. -- Debugging
  41. local debugFile = nil
  42.  
  43. -- Environment
  44. local oldEnv = {}
  45. local env = {}
  46. local backupEnv = {}
  47. local api = {}
  48.  
  49. -- Themes
  50. local theme = {}
  51.  
  52. -- Databases
  53. local blacklist = {}
  54. local whitelist = {}
  55. local definitions = {}
  56. local verifiedDownloads = {}
  57.  
  58. -- Website loading
  59. local website = ""
  60. local homepage = ""
  61. local timeout = 0.08
  62. local openAddressBar = true
  63. local loadingRate = 0
  64. local curSites = {}
  65.  
  66. -- Protocols
  67. local curProtocol = {}
  68. local protocols = {}
  69.  
  70. -- History
  71. local history = {}
  72. local addressBarHistory = {}
  73.  
  74. -- Events
  75. local event_loadWebsite = "firewolf_loadWebsiteEvent"
  76. local event_exitWebsite = "firewolf_exitWebsiteEvent"
  77. local event_exitApp = "firewolf_exitAppEvent"
  78. local event_redirect = "firewolf_redirectEvent"
  79.  
  80. -- Download URLs
  81. local firewolfURL = "https://raw.github.com/1lann/firewolf/master/entities/" .. serverID .. ".lua"
  82. local databaseURL = "https://raw.github.com/1lann/firewolf/master/databases/" .. serverID ..
  83. "-database.txt"
  84. local serverURL = "https://raw.github.com/1lann/firewolf/master/server/server-release.lua"
  85. if serverID == "experimental" then
  86. serverURL = "https://raw.github.com/1lann/firewolf/master/server/server-experimental.lua"
  87. end
  88. local availableThemesURL = "https://raw.github.com/1lann/firewolf/master/themes/available.txt"
  89.  
  90. -- Data Locations
  91. local rootFolder = "/.Firewolf_Data"
  92. local cacheFolder = rootFolder .. "/cache"
  93. local serverFolder = rootFolder .. "/servers"
  94. local themeLocation = rootFolder .. "/theme"
  95. local defaultThemeLocation = rootFolder .. "/default_theme"
  96. local availableThemesLocation = rootFolder .. "/available_themes"
  97. local serverSoftwareLocation = rootFolder .. "/server_software"
  98. local settingsLocation = rootFolder .. "/settings"
  99. local historyLocation = rootFolder .. "/history"
  100. local firewolfLocation = "/" .. shell.getRunningProgram()
  101.  
  102. local userBlacklist = rootFolder .. "/user_blacklist"
  103. local userWhitelist = rootFolder .. "/user_whitelist"
  104. local globalDatabase = rootFolder .. "/database"
  105.  
  106.  
  107. -- -------- Firewolf API
  108.  
  109. api.clearPage = function(site, color, redraw)
  110. -- Site titles
  111. local titles = {firewolf = "Firewolf Homepage", server = "Server Management",
  112. history = "Firewolf History", help = "Help Page", downloads = "Downloads Center",
  113. settings = "Firewolf Settings", credits = "Firewolf Credits", getinfo = "Website Information",
  114. nomodem = "No Modem Attached!", crash = "Website Has Crashed!", overspeed = "Too Fast!"}
  115. local title = titles[site]
  116.  
  117. -- Clear
  118. local c = color
  119. if c == nil then c = colors.black end
  120. term.setBackgroundColor(c)
  121. term.setTextColor(colors[theme["address-bar-text"]])
  122. if redraw ~= true then term.clear() end
  123.  
  124. -- URL bar
  125. term.setCursorPos(2, 1)
  126. term.setBackgroundColor(colors[theme["address-bar-background"]])
  127. term.clearLine()
  128. term.setCursorPos(2, 1)
  129. local a = site
  130. if a:len() > w - 9 then a = a:sub(1, 39) .. "..." end
  131. write("rdnt://" .. a)
  132. if title ~= nil then
  133. term.setCursorPos(w - title:len(), 1)
  134. write(title)
  135. end
  136.  
  137. term.setBackgroundColor(colors.black)
  138. term.setTextColor(colors.white)
  139. print("")
  140. end
  141.  
  142. api.centerPrint = function(text)
  143. local w, h = term.getSize()
  144. local x, y = term.getCursorPos()
  145. term.setCursorPos(math.ceil((w + 1)/2 - text:len()/2), y)
  146. print(text)
  147. end
  148.  
  149. api.centerWrite = function(text)
  150. local w, h = term.getSize()
  151. local x, y = term.getCursorPos()
  152. term.setCursorPos(math.ceil((w + 1)/2 - text:len()/2), y)
  153. write(text)
  154. end
  155.  
  156. api.leftPrint = function(text)
  157. local x, y = term.getCursorPos()
  158. term.setCursorPos(4, y)
  159. print(text)
  160. end
  161.  
  162. api.leftWrite = function(text)
  163. local x, y = term.getCursorPos()
  164. term.setCursorPos(4, y)
  165. write(text)
  166. end
  167.  
  168. api.rightPrint = function(text)
  169. local x, y = term.getCursorPos()
  170. local w, h = term.getSize()
  171. term.setCursorPos(w - text:len() - 1, y)
  172. print(text)
  173. end
  174.  
  175. api.rightWrite = function(text)
  176. local x, y = term.getCursorPos()
  177. local w, h = term.getSize()
  178. term.setCursorPos(w - text:len() - 1, y)
  179. write(text)
  180. end
  181.  
  182. api.redirect = function(url)
  183. os.queueEvent(event_redirect, url:gsub("rdnt://", ""))
  184. end
  185.  
  186. api.prompt = function(list, dir)
  187. if term.isColor() then
  188. for _, v in pairs(list) do
  189. if v.bg then term.setBackgroundColor(v.bg) end
  190. if v.tc then term.setTextColor(v.tc) end
  191. if v[2] == -1 then v[2] = math.ceil((w + 1)/2 - (v[1]:len() + 6)/2) end
  192.  
  193. term.setCursorPos(v[2], v[3])
  194. write("[- " .. v[1])
  195. term.setCursorPos(v[2] + v[1]:len() + 3, v[3])
  196. write(" -]")
  197. end
  198.  
  199. while true do
  200. local e, but, x, y = os.pullEvent()
  201. if e == "mouse_click" then
  202. for _, v in pairs(list) do
  203. if x >= v[2] and x <= v[2] + v[1]:len() + 5 and y == v[3] then
  204. return v[1]
  205. end
  206. end
  207. elseif e == event_exitWebsite then
  208. return nil
  209. end
  210. end
  211. else
  212. for _, v in pairs(list) do
  213. term.setBackgroundColor(colors.black)
  214. term.setTextColor(colors.white)
  215. if v[2] == -1 then v[2] = math.ceil((w + 1)/2 - (v[1]:len() + 4)/2) end
  216.  
  217. term.setCursorPos(v[2], v[3])
  218. write(" " .. v[1])
  219. term.setCursorPos(v[2] + v[1]:len() + 2, v[3])
  220. write(" ")
  221. end
  222.  
  223. local key1 = 200
  224. local key2 = 208
  225. if dir == "horizontal" then
  226. key1 = 203
  227. key2 = 205
  228. end
  229.  
  230. local curSel = 1
  231. term.setCursorPos(list[curSel][2], list[curSel][3])
  232. write("[")
  233. term.setCursorPos(list[curSel][2] + list[curSel][1]:len() + 3, list[curSel][3])
  234. write("]")
  235.  
  236. while true do
  237. local e, key = os.pullEvent()
  238. term.setCursorPos(list[curSel][2], list[curSel][3])
  239. write(" ")
  240. term.setCursorPos(list[curSel][2] + list[curSel][1]:len() + 3, list[curSel][3])
  241. write(" ")
  242. if e == "key" and key == key1 and curSel > 1 then
  243. curSel = curSel - 1
  244. elseif e == "key" and key == key2 and curSel < #list then
  245. curSel = curSel + 1
  246. elseif e == "key" and key == 28 then
  247. return list[curSel][1]
  248. elseif e == event_exitWebsite then
  249. return nil
  250. end
  251. term.setCursorPos(list[curSel][2], list[curSel][3])
  252. write("[")
  253. term.setCursorPos(list[curSel][2] + list[curSel][1]:len() + 3, list[curSel][3])
  254. write("]")
  255. end
  256. end
  257. end
  258.  
  259. api.scrollingPrompt = function(list, x, y, len, width)
  260. local wid = width
  261. if wid == nil then wid = w - 3 end
  262.  
  263. local function updateDisplayList(items, loc, len)
  264. local ret = {}
  265. for i = 1, len do
  266. local item = items[i + loc - 1]
  267. if item ~= nil then table.insert(ret, item) end
  268. end
  269. return ret
  270. end
  271.  
  272. if term.isColor() then
  273. local function draw(a)
  274. for i, v in ipairs(a) do
  275. term.setCursorPos(1, y + i - 1)
  276. api.centerWrite(string.rep(" ", wid + 2))
  277. term.setCursorPos(x, y + i - 1)
  278. write("[ " .. v:sub(1, wid - 5))
  279. term.setCursorPos(wid + x - 2, y + i - 1)
  280. write(" ]")
  281. end
  282. end
  283.  
  284. local loc = 1
  285. local disList = updateDisplayList(list, loc, len)
  286. draw(disList)
  287.  
  288. while true do
  289. local e, but, clx, cly = os.pullEvent()
  290. if e == "key" and but == 200 and loc > 1 then
  291. loc = loc - 1
  292. disList = updateDisplayList(list, loc, len)
  293. draw(disList)
  294. elseif e == "key" and but == 208 and loc + len - 1 < #list then
  295. loc = loc + 1
  296. disList = updateDisplayList(list, loc, len)
  297. draw(disList)
  298. elseif e == "mouse_scroll" and but > 0 and loc + len - 1 < #list then
  299. loc = loc + but
  300. disList = updateDisplayList(list, loc, len)
  301. draw(disList)
  302. elseif e == "mouse_scroll" and but < 0 and loc > 1 then
  303. loc = loc + but
  304. disList = updateDisplayList(list, loc, len)
  305. draw(disList)
  306. elseif e == "mouse_click" then
  307. for i, v in ipairs(disList) do
  308. if clx >= x and clx <= x + wid and cly == i + y - 1 then
  309. return v
  310. end
  311. end
  312. elseif e == event_exitWebsite then
  313. return nil
  314. end
  315. end
  316. else
  317. local function draw(a)
  318. for i, v in ipairs(a) do
  319. term.setCursorPos(1, y + i - 1)
  320. api.centerWrite(string.rep(" ", wid + 2))
  321. term.setCursorPos(x, y + i - 1)
  322. write("[ ] " .. v:sub(1, wid - 5))
  323. end
  324. end
  325.  
  326. local loc = 1
  327. local curSel = 1
  328. local disList = updateDisplayList(list, loc, len)
  329. draw(disList)
  330. term.setCursorPos(x + 1, y + curSel - 1)
  331. write("x")
  332.  
  333. while true do
  334. local e, key = os.pullEvent()
  335. term.setCursorPos(x + 1, y + curSel - 1)
  336. write(" ")
  337. if e == "key" and key == 200 then
  338. if curSel > 1 then
  339. curSel = curSel - 1
  340. elseif loc > 1 then
  341. loc = loc - 1
  342. disList = updateDisplayList(list, loc, len)
  343. draw(disList)
  344. end
  345. elseif e == "key" and key == 208 then
  346. if curSel < #disList then
  347. curSel = curSel + 1
  348. elseif loc + len - 1 < #list then
  349. loc = loc + 1
  350. disList = updateDisplayList(list, loc, len)
  351. draw(disList)
  352. end
  353. elseif e == "key" and key == 28 then
  354. return list[curSel + loc - 1]
  355. elseif e == event_exitWebsite then
  356. return nil
  357. end
  358. term.setCursorPos(x + 1, y + curSel - 1)
  359. write("x")
  360. end
  361. end
  362. end
  363.  
  364. api.clearArea = function() api.clearPage(website) end
  365. api.cPrint = function(text) api.centerPrint(text) end
  366. api.cWrite = function(text) api.centerWrite(text) end
  367. api.lPrint = function(text) api.leftPrint(text) end
  368. api.lWrite = function(text) api.leftWrite(text) end
  369. api.rPrint = function(text) api.rightPrint(text) end
  370. api.rWrite = function(text) api.rightWrite(text) end
  371.  
  372.  
  373. -- Set Environment
  374. for k, v in pairs(getfenv(0)) do env[k] = v end
  375. for k, v in pairs(getfenv(1)) do env[k] = v end
  376. for k, v in pairs(env) do oldEnv[k] = v end
  377. for k, v in pairs(api) do env[k] = v end
  378. for k, v in pairs(env) do backupEnv[k] = v end
  379. setfenv(1, env)
  380.  
  381.  
  382. -- -------- Utilities
  383.  
  384. local function debugLog(n, ...)
  385. local lArgs = {...}
  386. if debugFile then
  387. debugFile:write("\n" .. n .. " : ")
  388. for k, v in pairs(lArgs) do
  389. if type(v) == "string" or type(v) == "number" or type(v) == nil then
  390. f:write(tostring(v) .. ", ")
  391. else f:write("type-" .. type(v) .. ", ") end
  392. end
  393. end
  394. end
  395.  
  396. local function modRead(replaceChar, his, maxLen, stopAtMaxLen, liveUpdates, exitOnControl)
  397. term.setCursorBlink(true)
  398. local line = ""
  399. local hisPos = nil
  400. local pos = 0
  401. if replaceChar then replaceChar = replaceChar:sub(1, 1) end
  402. local w, h = term.getSize()
  403. local sx, sy = term.getCursorPos()
  404.  
  405. local function redraw(repl)
  406. local scroll = 0
  407. if line:len() >= maxLen then scroll = line:len() - maxLen end
  408.  
  409. term.setCursorPos(sx, sy)
  410. local a = repl or replaceChar
  411. if a then term.write(string.rep(a, line:len() - scroll))
  412. else term.write(line:sub(scroll + 1)) end
  413. term.setCursorPos(sx + pos - scroll, sy)
  414. end
  415.  
  416. while true do
  417. local e, but, x, y, p4, p5 = os.pullEvent()
  418. if e == "char" and not(stopAtMaxLen == true and line:len() >= maxLen) then
  419. line = line:sub(1, pos) .. but .. line:sub(pos + 1, -1)
  420. pos = pos + 1
  421. redraw()
  422. elseif e == "key" then
  423. if but == keys.enter then
  424. break
  425. elseif but == keys.left then
  426. if pos > 0 then pos = pos - 1 redraw() end
  427. elseif but == keys.right then
  428. if pos < line:len() then pos = pos + 1 redraw() end
  429. elseif (but == keys.up or but == keys.down) and his then
  430. redraw(" ")
  431. if but == keys.up then
  432. if hisPos == nil and #his > 0 then hisPos = #his
  433. elseif hisPos > 1 then hisPos = hisPos - 1 end
  434. elseif but == keys.down then
  435. if hisPos == #his then hisPos = nil
  436. elseif hisPos ~= nil then hisPos = hisPos + 1 end
  437. end
  438.  
  439. if hisPos then
  440. line = his[hisPos]
  441. pos = line:len()
  442. else
  443. line = ""
  444. pos = 0
  445. end
  446. redraw()
  447. if liveUpdates then
  448. local a, data = liveUpdates(line, "update_history", nil, nil, nil, nil, nil)
  449. if a == true and data == nil then
  450. term.setCursorBlink(false)
  451. return line
  452. elseif a == true and data ~= nil then
  453. term.setCursorBlink(false)
  454. return data
  455. end
  456. end
  457. elseif but == keys.backspace and pos > 0 then
  458. redraw(" ")
  459. line = line:sub(1, pos - 1) .. line:sub(pos + 1, -1)
  460. pos = pos - 1
  461. redraw()
  462. if liveUpdates then
  463. local a, data = liveUpdates(line, "delete", nil, nil, nil, nil, nil)
  464. if a == true and data == nil then
  465. term.setCursorBlink(false)
  466. return line
  467. elseif a == true and data ~= nil then
  468. term.setCursorBlink(false)
  469. return data
  470. end
  471. end
  472. elseif but == keys.home then
  473. pos = 0
  474. redraw()
  475. elseif but == keys.delete and pos < line:len() then
  476. redraw(" ")
  477. line = line:sub(1, pos) .. line:sub(pos + 2, -1)
  478. redraw()
  479. if liveUpdates then
  480. local a, data = liveUpdates(line, "delete", nil, nil, nil, nil, nil)
  481. if a == true and data == nil then
  482. term.setCursorBlink(false)
  483. return line
  484. elseif a == true and data ~= nil then
  485. term.setCursorBlink(false)
  486. return data
  487. end
  488. end
  489. elseif but == keys["end"] then
  490. pos = line:len()
  491. redraw()
  492. elseif (but == 29 or but == 157) and not(exitOnControl) then
  493. term.setCursorBlink(false)
  494. return nil
  495. end
  496. end if liveUpdates then
  497. local a, data = liveUpdates(line, e, but, x, y, p4, p5)
  498. if a == true and data == nil then
  499. term.setCursorBlink(false)
  500. return line
  501. elseif a == true and data ~= nil then
  502. term.setCursorBlink(false)
  503. return data
  504. end
  505. end
  506. end
  507.  
  508. term.setCursorBlink(false)
  509. if line ~= nil then line = line:gsub("^%s*(.-)%s*$", "%1") end
  510. return line
  511. end
  512.  
  513.  
  514. -- -------- Themes
  515.  
  516. local defaultTheme = {["address-bar-text"] = "white", ["address-bar-background"] = "gray",
  517. ["top-box"] = "red", ["bottom-box"] = "orange", ["text-color"] = "white", ["background"] = "gray"}
  518. local originalTheme = {["address-bar-text"] = "white", ["address-bar-background"] = "black",
  519. ["top-box"] = "black", ["bottom-box"] = "black", ["text-color"] = "white", ["background"] = "black"}
  520.  
  521. local ownThemeFileContent = [[
  522. address-bar-text=
  523. address-bar-background=
  524. top-box=
  525. bottom-box=
  526. background=
  527. text-color=
  528.  
  529. ]]
  530.  
  531. local function loadTheme(path)
  532. if fs.exists(path) and not(fs.isDir(path)) then
  533. local a = {}
  534. local f = io.open(path, "r")
  535. local l = f:read("*l")
  536. while l ~= nil do
  537. l = l:gsub("^%s*(.-)%s*$", "%1")
  538. if l ~= "" and l ~= nil and l ~= "\n" then
  539. local b = l:find("=")
  540. if a and b then
  541. local c = l:sub(1, b - 1)
  542. local d = l:sub(b + 1, -1)
  543. if c == "" or d == "" then return nil
  544. else a[c] = d end
  545. else return nil end
  546. end
  547. l = f:read("*l")
  548. end
  549. f:close()
  550.  
  551. return a
  552. else
  553. return nil
  554. end
  555. end
  556.  
  557.  
  558. -- -------- Download API
  559.  
  560. function urlDownload(url)
  561. clearPage(website, colors[theme["background"]])
  562. print("\n\n")
  563. term.setTextColor(colors[theme["text-color"]])
  564. term.setBackgroundColor(colors[theme["top-box"]])
  565. centerPrint(string.rep(" ", 47))
  566. centerWrite(string.rep(" ", 47))
  567. centerPrint("Processing Download Request...")
  568. centerPrint(string.rep(" ", 47))
  569.  
  570. openAddressBar = false
  571. local res = http.get(url)
  572. openAddressBar = true
  573. local data = nil
  574. if res then
  575. data = res.readAll()
  576. res.close()
  577. else
  578. term.setCursorPos(1, 5)
  579. centerWrite(string.rep(" ", 47))
  580. centerPrint("Download Failed!")
  581. centerPrint("Please report this to the website owner!")
  582. centerPrint(string.rep(" ", 47))
  583. openAddressBar = false
  584. sleep(1.1)
  585. openAddressBar = true
  586.  
  587. clearPage(website, colors.black)
  588. term.setCursorPos(1, 2)
  589. return nil
  590. end
  591.  
  592. clearPage(website, colors[theme["background"]])
  593. print("")
  594. term.setBackgroundColor(colors[theme["top-box"]])
  595. centerPrint(string.rep(" ", 47))
  596. centerWrite(string.rep(" ", 47))
  597. centerPrint("Download Files")
  598. centerPrint(string.rep(" ", 47))
  599. print("")
  600.  
  601. local a = website
  602. if a:find("/") then a = a:sub(1, a:find("/") - 1) end
  603.  
  604. term.setBackgroundColor(colors[theme["bottom-box"]])
  605. for i = 1, 10 do centerPrint(string.rep(" ", 47)) end
  606. term.setCursorPos(1, 8)
  607. centerPrint(" The website: ")
  608. centerPrint(" rdnt://" .. a .. string.rep(" ", w - a:len() - 16))
  609. centerPrint(" Is attempting to download a file to this ")
  610. centerPrint(" computer! ")
  611.  
  612. local opt = prompt({{"Download", 6, 14}, {"Cancel", w - 16, 14}}, "horizontal")
  613. if opt == "Download" then
  614. clearPage(website, colors[theme["background"]])
  615. print("")
  616. term.setTextColor(colors[theme["text-color"]])
  617. term.setBackgroundColor(colors[theme["top-box"]])
  618. centerPrint(string.rep(" ", 47))
  619. centerWrite(string.rep(" ", 47))
  620. centerPrint("Download Files")
  621. centerPrint(string.rep(" ", 47))
  622. print("")
  623.  
  624. term.setBackgroundColor(colors[theme["bottom-box"]])
  625. for i = 1, 10 do centerPrint(string.rep(" ", 47)) end
  626. local a = tostring(math.random(1000, 9999))
  627. term.setCursorPos(5, 8)
  628. write("This is for security purposes: " .. a)
  629. term.setCursorPos(5, 9)
  630. write("Enter the 4 numbers above: ")
  631. local b = modRead(nil, nil, 4, true)
  632. if b == nil then
  633. os.queueEvent(event_exitWebsite)
  634. return
  635. end
  636.  
  637. if b == a then
  638. term.setCursorPos(5, 11)
  639. write("Save As: /")
  640. local c = modRead(nil, nil, w - 18, false)
  641. if c ~= "" and c ~= nil then
  642. c = "/" .. c
  643. local f = io.open(c, "w")
  644. f:write(data)
  645. f:close()
  646. term.setCursorPos(5, 13)
  647. centerWrite("Download Successful! Continuing to Website...")
  648. openAddressBar = false
  649. sleep(1.1)
  650. openAddressBar = true
  651.  
  652. clearPage(website, colors.black)
  653. term.setCursorPos(1, 2)
  654. return c
  655. elseif c == nil then
  656. os.queueEvent(event_exitWebsite)
  657. return
  658. end
  659. else
  660. term.setCursorPos(5, 13)
  661. centerWrite("Incorrect! Cancelling Download...")
  662. openAddressBar = false
  663. sleep(1.1)
  664. openAddressBar = true
  665. end
  666. elseif opt == "Cancel" then
  667. term.setCursorPos(1, 15)
  668. centerWrite("Download Canceled!")
  669. openAddressBar = false
  670. sleep(1.1)
  671. openAddressBar = true
  672. elseif opt == nil then
  673. os.queueEvent(event_exitWebsite)
  674. return
  675. end
  676.  
  677. clearPage(website, colors.black)
  678. term.setCursorPos(1, 2)
  679. return nil
  680. end
  681.  
  682. function pastebinDownload(code)
  683. return urlDownload("http://pastebin.com/raw.php?i=" .. code)
  684. end
  685.  
  686.  
  687. -- -------- Filesystem
  688.  
  689. local function download(url, path)
  690. for i = 1, 3 do
  691. local response = http.get(url)
  692. if response then
  693. local data = response.readAll()
  694. response.close()
  695. local f = io.open(path, "w")
  696. f:write(data)
  697. f:close()
  698. return true
  699. end
  700. end
  701.  
  702. return false
  703. end
  704.  
  705. local function migrateFilesystem()
  706. -- Migrate from old version
  707. if fs.exists("/.Firefox_Data") then
  708. fs.move("/.Firefox_Data", rootFolder)
  709. fs.delete(rootFolder .. "/server_software")
  710. fs.delete(serverSoftwareLocation)
  711. end
  712.  
  713. fs.delete(serverSoftwareLocation)
  714. end
  715.  
  716. local function resetFilesystem()
  717. -- Folders
  718. if not(fs.exists(rootFolder)) then fs.makeDir(rootFolder)
  719. elseif not(fs.isDir(rootFolder)) then fs.move(rootFolder, "/old-firewolf-data-file") end
  720. if not(fs.exists(serverFolder)) then fs.makeDir(serverFolder) end
  721. if not(fs.exists(cacheFolder)) then fs.makeDir(cacheFolder) end
  722.  
  723. -- Settings
  724. if not(fs.exists(settingsLocation)) then
  725. local f = io.open(settingsLocation, "w")
  726. f:write(textutils.serialize({auto = "true", incog = "false", home = "firewolf"}))
  727. f:close()
  728. end
  729.  
  730. -- History
  731. if not(fs.exists(historyLocation)) then
  732. local f = io.open(historyLocation, "w")
  733. f:write(textutils.serialize({}))
  734. f:close()
  735. end
  736.  
  737. -- Server Software
  738. if not(fs.exists(serverSoftwareLocation)) then
  739. download(serverURL, serverSoftwareLocation)
  740. end
  741.  
  742. -- Themes
  743. if term.isColor() then
  744. if autoupdate == "true" then
  745. fs.delete(availableThemesLocation)
  746. fs.delete(defaultThemeLocation)
  747. end if not(fs.exists(availableThemesLocation)) then
  748. download(availableThemesURL, availableThemesLocation)
  749. end if not(fs.exists(defaultThemeLocation)) then
  750. local f = io.open(availableThemesLocation, "r")
  751. local a = f:read("*l")
  752. f:close()
  753. a = a:sub(1, a:find("| |") - 1)
  754. download(a, defaultThemeLocation)
  755. end if not(fs.exists(themeLocation)) then
  756. fs.copy(defaultThemeLocation, themeLocation)
  757. end
  758. end
  759.  
  760. -- Databases
  761. fs.delete(globalDatabase)
  762. for _, v in pairs({globalDatabase, userWhitelist, userBlacklist}) do
  763. if not(fs.exists(v)) then
  764. local f = io.open(v, "w")
  765. f:write("")
  766. f:close()
  767. end
  768. end
  769.  
  770. return nil
  771. end
  772.  
  773. local function updateClient()
  774. local updateLocation = rootFolder .. "/update"
  775. fs.delete(updateLocation)
  776.  
  777. -- Update
  778. download(firewolfURL, updateLocation)
  779. local a = io.open(updateLocation, "r")
  780. local b = io.open(firewolfLocation, "r")
  781. local new = a:read("*a")
  782. local cur = b:read("*a")
  783. a:close()
  784. b:close()
  785.  
  786. if cur ~= new then
  787. fs.delete(firewolfLocation)
  788. fs.move(updateLocation, firewolfLocation)
  789. shell.run(firewolfLocation)
  790. error()
  791. else
  792. fs.delete(updateLocation)
  793. end
  794. end
  795.  
  796. local function appendToHistory(site)
  797. if incognito == "false" then
  798. if site == "home" or site == "homepage" then
  799. site = homepage
  800. end if site ~= "exit" and site ~= "" and site ~= "history" and site ~= history[1] then
  801. table.insert(history, 1, site)
  802. local f = io.open(historyLocation, "w")
  803. f:write(textutils.serialize(history))
  804. f:close()
  805. end if site ~= addressBarHistory[#addressBarHistory] then
  806. table.insert(addressBarHistory, site)
  807. end
  808. end
  809. end
  810.  
  811.  
  812. -- -------- Databases
  813.  
  814. local function loadDatabases()
  815. -- Get
  816. fs.delete(globalDatabase)
  817. download(databaseURL, globalDatabase)
  818. local f = io.open(globalDatabase, "r")
  819. local l = f:read("*l"):gsub("^%s*(.-)%s*$", "%1")
  820.  
  821. -- Blacklist ([id])
  822. blacklist = {}
  823. while l ~= "START-WHITELIST" do
  824. l = f:read("*l"):gsub("^%s*(.-)%s*$", "%1")
  825. if l ~= "" and l ~= "\n" and l ~= nil and l ~= "START-BLACKLIST" then
  826. table.insert(blacklist, l)
  827. end
  828. end
  829.  
  830. -- Whitelist ([site name]| |[id])
  831. whitelist = {}
  832. while l ~= "START-DOWNLOADS" do
  833. l = f:read("*l"):gsub("^%s*(.-)%s*$", "%1")
  834. if l ~= "" and l ~= "\n" and l ~= nil and l ~= "START-DOWNLOADS" then
  835. local a, b = l:find("| |")
  836. table.insert(whitelist, {l:sub(1, a - 1), l:sub(b + 1, -1)})
  837. end
  838. end
  839.  
  840. -- Downloads ([url])
  841. downloads = {}
  842. while l ~= "START-DEFINITIONS" do
  843. l = f:read("*l"):gsub("^%s*(.-)%s*$", "%1")
  844. if l ~= "" and l ~= "\n" and l ~= nil and l ~= "START-DEFINITIONS" then
  845. table.insert(downloads, l)
  846. end
  847. end
  848.  
  849. -- Definitions ([definition]| |[offence name])
  850. definitions = {}
  851. while l ~= "END-DATABASE" do
  852. l = f:read("*l"):gsub("^%s*(.-)%s*$", "%1")
  853. if l ~= "" and l ~= "\n" and l ~= nil and l ~= "END-DATABASE" then
  854. local a, b = l:find("| |")
  855. table.insert(definitions, {l:sub(1, a - 1), l:sub(b + 1, -1)})
  856. end
  857. end
  858. f:close()
  859.  
  860. -- User Blacklist
  861. if not(fs.exists(userBlacklist)) then
  862. local bf = fio.open(userBlacklist, "w")
  863. bf:write("\n")
  864. bf:close()
  865. else
  866. local bf = io.open(userBlacklist, "r")
  867. local l = bf:read("*l")
  868. while l ~= nil do
  869. if l ~= nil and l ~= "" and l ~= "\n" then
  870. l = l:gsub("^%s*(.-)%s*$", "%1")
  871. table.insert(blacklist, l)
  872. end
  873. l = bf:read("*l")
  874. end
  875. f:close()
  876. end
  877.  
  878. -- User Whitelist
  879. if not(fs.exists(userWhitelist)) then
  880. local wf = io.open(userWhitelist, "w")
  881. wf:write("\n")
  882. wf:close()
  883. else
  884. local wf = io.open(userWhitelist, "r")
  885. local l = wf:read("*l")
  886. while l ~= nil do
  887. if l ~= nil and l ~= "" and l ~= "\n" then
  888. l = l:gsub("^%s*(.-)%s*$", "%1")
  889. local a, b = l:find("| |")
  890. table.insert(whitelist, {l:sub(1, a - 1), l:sub(b + 1, -1)})
  891. end
  892. l = wf:read("*l")
  893. end
  894. f:close()
  895. end
  896. end
  897.  
  898. local function verify(database, ...)
  899. local args = {...}
  900. if database == "blacklist" and #args >= 1 then
  901. -- id
  902. local found = false
  903. for _, v in pairs(blacklist) do
  904. if tostring(args[1]) == v then found = true end
  905. end
  906.  
  907. return found
  908. elseif database == "whitelist" and #args >= 2 then
  909. -- id, site
  910. local found = false
  911. for _, v in pairs(whitelist) do
  912. if v[2] == tostring(args[1]) and v[1] == tostring(args[2]) then
  913. found = true
  914. end
  915. end
  916.  
  917. return found
  918. elseif database == "antivirus" and #args >= 1 then
  919. -- content
  920. local a = verify("antivirus offences", args[1])
  921. if #a == 0 then return false
  922. else return true end
  923. elseif database == "antivirus offences" and #args >= 1 then
  924. -- content
  925. local c = args[1]:gsub(" ", ""):gsub("\n", ""):gsub("\t", "")
  926. local a = {}
  927. for _, v in pairs(definitions) do
  928. local b = false
  929. for _, c in pairs(a) do
  930. if c == v[2] then b = true end
  931. end
  932.  
  933. if c:find(v[1], 1, true) and not(b) then
  934. table.insert(a, v[2])
  935. end
  936. end
  937. table.sort(a)
  938.  
  939. return a
  940. else
  941. return nil
  942. end
  943. end
  944.  
  945.  
  946. -- -------- Protocols
  947.  
  948. protocols.http = {}
  949. protocols.rdnt = {}
  950.  
  951. protocols.rdnt.getSearchResults = function(input)
  952. local results = {}
  953. local resultIDs = {}
  954.  
  955. rednet.broadcast("rednet.api.ping.searchengine")
  956. local startClock = os.clock()
  957. while os.clock() - startClock < 1 do
  958. local id, i = rednet.receive(timeout)
  959. if id then
  960. local bl, wl = verify("blacklist", id), verify("whitelist", id, i)
  961. if not(i:find(" ")) and i:len() < 40 and (not(bl) or (bl and wl)) then
  962. if not(resultIDs[tostring(id)]) then
  963. resultIDs[tostring(id)] = 1
  964. else
  965. resultIDs[tostring(id)] = resultIDs[tostring(id)] + 1
  966. end
  967.  
  968. local x = false
  969. for y = 1, #results do
  970. if results[y]:lower() == i:lower() then
  971. x = true
  972. end
  973. end
  974.  
  975. if not(x) and resultIDs[tostring(id)] <= 5 then
  976. if not i:find("rdnt://") then i = ("rdnt://" .. i) end
  977. if input == "" then
  978. table.insert(results, i)
  979. elseif string.find(i, input) and i ~= input then
  980. table.insert(results, i)
  981. end
  982. end
  983. end
  984. else
  985. break
  986. end
  987. end
  988.  
  989. table.sort(results)
  990. table.sort(results, function(a, b)
  991. local _, ac = a:gsub("rdnt://", ""):gsub(input:lower(), "")
  992. local _, bc = b:gsub("rdnt://", ""):gsub(input:lower(), "")
  993. return ac > bc
  994. end)
  995. return results
  996. end
  997.  
  998. protocols.rdnt.getWebsite = function(site)
  999. local id, content, status = nil, nil, nil
  1000. local clock = os.clock()
  1001. rednet.broadcast(site)
  1002. while os.clock() - clock < timeout do
  1003. id, content = rednet.receive(timeout)
  1004. if id then
  1005. local bl = verify("blacklist", id)
  1006. local av = verify("antivirus", content)
  1007. local wl = verify("whitelist", id, site)
  1008. status = nil
  1009. if (bl and not(wl)) or site == "" or site == "." or site == ".." then
  1010. -- Ignore
  1011. elseif av and not(wl) then
  1012. status = "antivirus"
  1013. break
  1014. else
  1015. status = "safe"
  1016. break
  1017. end
  1018. end
  1019. end
  1020.  
  1021. return id, content, status
  1022. end
  1023.  
  1024. protocols.http.getSearchResults = function(input)
  1025. return {}
  1026. end
  1027.  
  1028. protocols.http.getWebsite = function(site)
  1029. return nil
  1030. end
  1031.  
  1032.  
  1033. -- -------- Built-In Websites
  1034.  
  1035. local pages = {}
  1036. local errPages = {}
  1037.  
  1038. pages.firewolf = function(site)
  1039. clearPage(site, colors[theme["background"]])
  1040. print("")
  1041. term.setTextColor(colors[theme["text-color"]])
  1042. term.setBackgroundColor(colors[theme["top-box"]])
  1043. centerPrint(string.rep(" ", 43))
  1044. centerPrint(" _,-='\"-.__ /\\_/\\ ")
  1045. centerPrint(" -.} =._,.-==-._., @ @._, ")
  1046. centerPrint(" -.__ __,-. ) _,.-' ")
  1047. centerPrint(" Firewolf " .. version .. " \" G..m-\"^m m' ")
  1048. centerPrint(string.rep(" ", 43))
  1049.  
  1050. term.setBackgroundColor(colors[theme["bottom-box"]])
  1051. term.setCursorPos(1, 10)
  1052. centerPrint(string.rep(" ", 43))
  1053. centerPrint(" rdnt://firewolf Homepage ")
  1054. centerPrint(" rdnt://history History ")
  1055. centerPrint(" rdnt://downloads Downloads Center ")
  1056. centerPrint(" rdnt://server Server Management ")
  1057. centerPrint(" rdnt://help Help Page ")
  1058. centerPrint(" rdnt://settings Settings ")
  1059. centerPrint(" rdnt://exit Exit ")
  1060. centerPrint(string.rep(" ", 43))
  1061.  
  1062. while true do
  1063. local e, but, x, y = os.pullEvent()
  1064. if e == "mouse_click" and x >= 7 and x <= 45 then
  1065. if y == 11 then redirect("firewolf") return
  1066. elseif y == 12 then redirect("history") return
  1067. elseif y == 13 then redirect("downloads") return
  1068. elseif y == 14 then redirect("server") return
  1069. elseif y == 15 then redirect("help") return
  1070. elseif y == 16 then redirect("settings") return
  1071. elseif y == 17 then redirect("exit") return
  1072. end
  1073. elseif e == event_exitWebsite then
  1074. os.queueEvent(event_exitWebsite)
  1075. return
  1076. end
  1077. end
  1078. end
  1079.  
  1080. pages.firefox = function(site)
  1081. redirect("firewolf")
  1082. end
  1083.  
  1084. pages.history = function(site)
  1085. clearPage(site, colors[theme["background"]])
  1086. term.setTextColor(colors[theme["text-color"]])
  1087. term.setBackgroundColor(colors[theme["top-box"]])
  1088. print("")
  1089. centerPrint(string.rep(" ", 47))
  1090. centerWrite(string.rep(" ", 47))
  1091. centerPrint("Firewolf History")
  1092. centerPrint(string.rep(" ", 47))
  1093. print("")
  1094. term.setBackgroundColor(colors[theme["bottom-box"]])
  1095.  
  1096. if #history > 0 then
  1097. for i = 1, 12 do
  1098. centerPrint(string.rep(" ", 47))
  1099. end
  1100.  
  1101. local a = {"Clear History"}
  1102. for i, v in ipairs(history) do
  1103. table.insert(a, "rdnt://" .. v)
  1104. end
  1105. local opt = scrollingPrompt(a, 6, 8, 10, 40)
  1106. if opt == "Clear History" then
  1107. history = {}
  1108. addressBarHistory = {}
  1109. local f = io.open(historyLocation, "w")
  1110. f:write(textutils.serialize(history))
  1111. f:close()
  1112.  
  1113. clearPage(site, colors[theme["background"]])
  1114. term.setTextColor(colors[theme["text-color"]])
  1115. term.setBackgroundColor(colors[theme["top-box"]])
  1116. print("")
  1117. centerPrint(string.rep(" ", 47))
  1118. centerWrite(string.rep(" ", 47))
  1119. centerPrint("Firewolf History")
  1120. centerPrint(string.rep(" ", 47))
  1121. print("\n")
  1122. term.setBackgroundColor(colors[theme["bottom-box"]])
  1123. centerPrint(string.rep(" ", 47))
  1124. centerWrite(string.rep(" ", 47))
  1125. centerPrint("Cleared history.")
  1126. centerPrint(string.rep(" ", 47))
  1127. openAddressBar = false
  1128. sleep(1.1)
  1129.  
  1130. redirect("history")
  1131. openAddressBar = true
  1132. return
  1133. elseif opt then
  1134. redirect(opt:gsub("rdnt://", ""))
  1135. return
  1136. elseif opt == nil then
  1137. os.queueEvent(event_exitWebsite)
  1138. return
  1139. end
  1140. else
  1141. print("")
  1142. centerPrint(string.rep(" ", 47))
  1143. centerWrite(string.rep(" ", 47))
  1144. centerPrint("No Items in History!")
  1145. centerPrint(string.rep(" ", 47))
  1146. end
  1147. end
  1148.  
  1149. pages.downloads = function(site)
  1150. clearPage(site, colors[theme["background"]])
  1151. term.setTextColor(colors[theme["text-color"]])
  1152. term.setBackgroundColor(colors[theme["top-box"]])
  1153. print("")
  1154. centerPrint(string.rep(" ", 47))
  1155. centerWrite(string.rep(" ", 47))
  1156. centerPrint("Download Center")
  1157. centerPrint(string.rep(" ", 47))
  1158. print("")
  1159.  
  1160. term.setBackgroundColor(colors[theme["bottom-box"]])
  1161. for i = 1, 5 do
  1162. centerPrint(string.rep(" ", 47))
  1163. end
  1164. local opt = prompt({{"Themes", 7, 8}, {"Plugins", 7, 10}}, "vertical")
  1165. if opt == "Themes" and term.isColor() then
  1166. while true do
  1167. local themes = {}
  1168. local c = {"Make my Own", "Load my Own"}
  1169. local f = io.open(availableThemesLocation, "r")
  1170. local l = f:read("*l")
  1171. while l ~= nil do
  1172. l = l:gsub("^%s*(.-)%s*$", "%1")
  1173. local a, b = l:find("| |")
  1174. table.insert(themes, {l:sub(1, a - 1), l:sub(b + 1, -1)})
  1175. table.insert(c, l:sub(b + 1, -1))
  1176. l = f:read("*l")
  1177. end
  1178. f:close()
  1179. clearPage(site, colors[theme["background"]])
  1180. term.setTextColor(colors[theme["text-color"]])
  1181. term.setBackgroundColor(colors[theme["top-box"]])
  1182. print("")
  1183. centerPrint(string.rep(" ", 47))
  1184. centerWrite(string.rep(" ", 47))
  1185. centerPrint("Download Center - Themes")
  1186. centerPrint(string.rep(" ", 47))
  1187. print("")
  1188. term.setBackgroundColor(colors[theme["bottom-box"]])
  1189. for i = 1, 12 do centerPrint(string.rep(" ", 47)) end
  1190. local t = scrollingPrompt(c, 4, 8, 10, 44)
  1191. if t == nil then
  1192. os.queueEvent(event_exitWebsite)
  1193. return
  1194. elseif t == "Make my Own" then
  1195. term.setCursorPos(6, 18)
  1196. write("Path: /")
  1197. local n = modRead(nil, nil, 35)
  1198. if n ~= "" and n ~= nil then
  1199. n = "/" .. n
  1200. local f = io.open(n, "w")
  1201. f:write(ownThemeFileContent)
  1202. f:close()
  1203.  
  1204. term.setCursorPos(1, 18)
  1205. centerWrite(string.rep(" ", 47))
  1206. term.setCursorPos(6, 18)
  1207. write("File Created!")
  1208. openAddressBar = false
  1209. sleep(1.1)
  1210. openAddressBar = true
  1211. elseif n == nil then
  1212. os.queueEvent(event_exitWebsite)
  1213. return
  1214. end
  1215. elseif t == "Load my Own" then
  1216. term.setCursorPos(6, 18)
  1217. write("Path: /")
  1218. local n = modRead(nil, nil, 35)
  1219. if n ~= "" and n ~= nil then
  1220. n = "/" .. n
  1221. term.setCursorPos(1, 18)
  1222. centerWrite(string.rep(" ", 47))
  1223.  
  1224. if fs.exists(n) and not(fs.isDir(n)) then
  1225. theme = loadTheme(n)
  1226. if theme ~= nil then
  1227. fs.delete(themeLocation)
  1228. fs.copy(n, themeLocation)
  1229. term.setCursorPos(6, 18)
  1230. write("Theme File Loaded! :D")
  1231. else
  1232. term.setCursorPos(6, 18)
  1233. write("Theme File is Corrupt! D:")
  1234. theme = loadTheme(themeLocation)
  1235. end
  1236. openAddressBar = false
  1237. sleep(1.1)
  1238. openAddressBar = true
  1239. elseif not(fs.exists(n)) then
  1240. term.setCursorPos(6, 18)
  1241. write("File does not exist!")
  1242. openAddressBar = false
  1243. sleep(1.1)
  1244. openAddressBar = true
  1245. elseif fs.isDir(n) then
  1246. term.setCursorPos(6, 18)
  1247. write("File is a directory!")
  1248. openAddressBar = false
  1249. sleep(1.1)
  1250. openAddressBar = true
  1251. end
  1252. elseif n == nil then
  1253. os.queueEvent(event_exitWebsite)
  1254. return
  1255. end
  1256. else
  1257. local url = ""
  1258. for _, v in pairs(themes) do if v[2] == t then url = v[1] break end end
  1259. term.setCursorPos(1, 4)
  1260. term.setBackgroundColor(colors[theme["top-box"]])
  1261. centerWrite(string.rep(" ", 47))
  1262. centerWrite("Download Center - Downloading...")
  1263. fs.delete(rootFolder .. "/temp_theme")
  1264. download(url, rootFolder .. "/temp_theme")
  1265. theme = loadTheme(rootFolder .. "/temp_theme")
  1266. if theme == nil then
  1267. theme = loadTheme(themeLocation)
  1268. fs.delete(rootFolder .. "/temp_theme")
  1269. centerWrite(string.rep(" ", 47))
  1270. centerWrite("Download Center - Theme Is Corrupt! D:")
  1271. openAddressBar = false
  1272. sleep(1.1)
  1273. openAddressBar = true
  1274. else
  1275. fs.delete(themeLocation)
  1276. fs.copy(rootFolder .. "/temp_theme", themeLocation)
  1277. fs.delete(rootFolder .. "/temp_theme")
  1278. centerWrite(string.rep(" ", 47))
  1279. centerWrite("Download Center - Done! :D")
  1280. openAddressBar = false
  1281. sleep(1.1)
  1282. openAddressBar = true
  1283. redirect("home")
  1284. return
  1285. end
  1286. end
  1287. end
  1288. elseif opt == "Themes" and not(term.isColor()) then
  1289. clearPage(site, colors[theme["background"]])
  1290. term.setTextColor(colors[theme["text-color"]])
  1291. term.setBackgroundColor(colors[theme["top-box"]])
  1292. print("")
  1293. centerPrint(string.rep(" ", 47))
  1294. centerWrite(string.rep(" ", 47))
  1295. centerPrint("Download Center")
  1296. centerPrint(string.rep(" ", 47))
  1297. print("\n")
  1298.  
  1299. centerPrint(string.rep(" ", 47))
  1300. centerWrite(string.rep(" ", 47))
  1301. centerPrint("Themes are not available on normal")
  1302. centerWrite(string.rep(" ", 47))
  1303. centerPrint("computers! :(")
  1304. centerPrint(string.rep(" ", 47))
  1305. elseif opt == "Plugins" then
  1306. clearPage(site, colors[theme["background"]])
  1307. term.setTextColor(colors[theme["text-color"]])
  1308. term.setBackgroundColor(colors[theme["top-box"]])
  1309. print("")
  1310. centerPrint(string.rep(" ", 47))
  1311. centerWrite(string.rep(" ", 47))
  1312. centerPrint("Download Center - Plugins")
  1313. centerPrint(string.rep(" ", 47))
  1314. print("\n")
  1315.  
  1316. term.setBackgroundColor(colors[theme["bottom-box"]])
  1317. centerPrint(string.rep(" ", 47))
  1318. centerWrite(string.rep(" ", 47))
  1319. centerPrint("Comming Soon! (hopefully :P)")
  1320. centerPrint(string.rep(" ", 47))
  1321. centerPrint(string.rep(" ", 47))
  1322. centerPrint(string.rep(" ", 47))
  1323.  
  1324. local opt = prompt({{"Back", -1, 11}}, "vertical")
  1325. if opt == nil then
  1326. os.queueEvent(event_exitWebsite)
  1327. return
  1328. elseif opt == "Back" then
  1329. redirect("downloads")
  1330. end
  1331. elseif opt == nil then
  1332. os.queueEvent(event_exitWebsite)
  1333. return
  1334. end
  1335. end
  1336.  
  1337. pages.server = function(site)
  1338. local function editPages(server)
  1339. -- Edit
  1340. openAddressBar = false
  1341. local oldLoc = shell.dir()
  1342. local commandHis = {}
  1343. local dir = serverFolder .. "/" .. server
  1344. term.setBackgroundColor(colors.black)
  1345. term.setTextColor(colors.white)
  1346. term.clear()
  1347. term.setCursorPos(1, 1)
  1348. print("")
  1349. print("Server Shell Editing")
  1350. print("Type 'exit' to return to Firewolf.")
  1351. print("")
  1352.  
  1353. local allowed = {"cd", "move", "mv", "cp", "copy", "drive", "delete", "rm", "edit",
  1354. "eject", "exit", "help", "id", "mkdir", "monitor", "rename", "alias", "clear",
  1355. "paint", "firewolf", "lua", "redstone", "rs", "redprobe", "redpulse",
  1356. "programs", "redset", "reboot", "hello", "label", "list", "ls", "easter"}
  1357.  
  1358. while true do
  1359. shell.setDir(serverFolder .. "/" .. server)
  1360. term.setBackgroundColor(colors.black)
  1361. if term.isColor() then term.setTextColor(colors.yellow)
  1362. else term.setTextColor(colors.white) end
  1363. write("> ")
  1364. term.setTextColor(colors.white)
  1365. local line = read(nil, commandHis)
  1366. table.insert(commandHis, line)
  1367.  
  1368. local words = {}
  1369. for m in string.gmatch(line, "[^ \t]+") do
  1370. local a = m:gsub("^%s*(.-)%s*$", "%1")
  1371. table.insert(words, a)
  1372. end
  1373.  
  1374. local com = words[1]
  1375. if com == "exit" then
  1376. break
  1377. elseif com == "firewolf" or (com == "easter" and words[2] == "egg") then
  1378. -- Easter egg
  1379. elseif com then
  1380. local a = false
  1381. for _, v in pairs(allowed) do
  1382. if com == v then a = true break end
  1383. end
  1384.  
  1385. if a then
  1386. term.setBackgroundColor(colors.black)
  1387. term.setTextColor(colors.white)
  1388. shell.run(com, unpack(words, 2))
  1389. else
  1390. term.setTextColor(colors.red)
  1391. print("Program Not Allowed!")
  1392. end
  1393. end
  1394. end
  1395. shell.setDir(oldLoc)
  1396.  
  1397. openAddressBar = true
  1398. redirect("server")
  1399. return
  1400. end
  1401.  
  1402. local function newServer()
  1403. -- New server
  1404. term.setBackgroundColor(colors[theme["background"]])
  1405. for i = 1, 12 do
  1406. term.setCursorPos(3, i + 6)
  1407. write(string.rep(" ", 47))
  1408. end
  1409.  
  1410. term.setBackgroundColor(colors[theme["bottom-box"]])
  1411. term.setCursorPos(1, 8)
  1412. for i = 1, 8 do centerPrint(string.rep(" ", 47)) end
  1413. term.setCursorPos(5, 9)
  1414. write("Name: ")
  1415. local name = modRead(nil, nil, 37)
  1416. if name == nil then
  1417. os.queueEvent(event_exitWebsite)
  1418. return
  1419. end
  1420. term.setCursorPos(5, 11)
  1421. write("URL:")
  1422. term.setCursorPos(8, 12)
  1423. write("rdnt://")
  1424. local url = modRead(nil, nil, 28, true)
  1425. if url == nil then
  1426. os.queueEvent(event_exitWebsite)
  1427. return
  1428. end
  1429. url = url:gsub(" ", "")
  1430.  
  1431. local a = {"/", "| |", " ", "@", "!", "$", "#", "%", "^", "&", "*", "(", ")",
  1432. "[", "]", "{", "}", "\\", "\"", "'", ":", ";", "?", "<", ">", ",", "`", "~"}
  1433. local b = false
  1434. for k, v in pairs(a) do
  1435. if url:find(v, 1, true) then
  1436. term.setCursorPos(5, 13)
  1437. write("URL Contains Illegal '" .. v .. "'!")
  1438. openAddressBar = false
  1439. sleep(1.1)
  1440. openAddressBar = true
  1441. b = true
  1442. break
  1443. elseif name == "" or url == "" then
  1444. term.setCursorPos(5, 13)
  1445. write("URL or Name Is Empty!")
  1446. openAddressBar = false
  1447. sleep(1.1)
  1448. openAddressBar = true
  1449. b = true
  1450. break
  1451. elseif fs.exists(serverFolder .. "/" .. url) then
  1452. term.setCursorPos(5, 13)
  1453. write("Server Already Exists!")
  1454. openAddressBar = false
  1455. sleep(1.1)
  1456. openAddressBar = true
  1457. b = true
  1458. break
  1459. end
  1460. end
  1461.  
  1462. if not(b) then
  1463. fs.makeDir(serverFolder .. "/" .. url)
  1464. local f = io.open(serverFolder .. "/" .. url .. "/home", "w")
  1465. f:write("print(\"\")\ncenterPrint(\"Welcome To " .. name .. "!\")\n")
  1466. f:close()
  1467.  
  1468. term.setCursorPos(5, 13)
  1469. write("Successfully Created Server! :D")
  1470. end
  1471. end
  1472.  
  1473. clearPage(site, colors[theme["background"]])
  1474. term.setTextColor(colors[theme["text-color"]])
  1475. term.setBackgroundColor(colors[theme["top-box"]])
  1476. print("")
  1477. centerPrint(string.rep(" ", 47))
  1478. centerWrite(string.rep(" ", 47))
  1479. centerPrint("Firewolf Server Management")
  1480. centerPrint(string.rep(" ", 47))
  1481. print("")
  1482.  
  1483. local servers = {}
  1484. for _, v in pairs(fs.list(serverFolder)) do
  1485. if fs.isDir(serverFolder .. "/" .. v) then table.insert(servers, v) end
  1486. end
  1487.  
  1488. if term.isColor() then
  1489. term.setBackgroundColor(colors[theme["bottom-box"]])
  1490. for i = 1, 12 do
  1491. term.setCursorPos(3, i + 6)
  1492. write(string.rep(" ", 24))
  1493. term.setCursorPos(29, i + 6)
  1494. write(string.rep(" ", 21))
  1495. end
  1496.  
  1497. local function draw(l, sel)
  1498. term.setBackgroundColor(colors[theme["bottom-box"]])
  1499. term.setCursorPos(4, 8)
  1500. write("[- New Server -]")
  1501. for i, v in ipairs(l) do
  1502. term.setCursorPos(3, i + 8)
  1503. write(string.rep(" ", 24))
  1504. term.setCursorPos(4, i + 8)
  1505. local nv = v
  1506. if nv:len() > 18 then nv = nv:sub(1, 15) .. "..." end
  1507. if i == sel then
  1508. write("[ " .. nv .. " ]")
  1509. else
  1510. write(" " .. nv)
  1511. end
  1512. end
  1513.  
  1514. term.setCursorPos(30, 8)
  1515. write(string.rep(" ", 19))
  1516. term.setCursorPos(30, 8)
  1517. if l[sel] then
  1518. local nl = l[sel]
  1519. if nl:len() > 19 then nl = nl:sub(1, 16) .. "..." end
  1520. write(nl)
  1521. else write("No Server Selected!") end
  1522. term.setCursorPos(30, 10)
  1523. write("[- Start -]")
  1524. term.setCursorPos(30, 12)
  1525. write("[- Edit -]")
  1526. term.setCursorPos(30, 14)
  1527. write("[- Run on Boot -]")
  1528. term.setCursorPos(30, 16)
  1529. write("[- Delete -]")
  1530. end
  1531.  
  1532. local function updateDisplayList(items, loc, len)
  1533. local ret = {}
  1534. for i = 1, len do
  1535. local item = items[i + loc - 1]
  1536. if item ~= nil then table.insert(ret, item) end
  1537. end
  1538. return ret
  1539. end
  1540.  
  1541. local sel = 1
  1542. local loc = 1
  1543. local len = 10
  1544. local disList = updateDisplayList(servers, loc, len)
  1545. draw(disList, sel)
  1546.  
  1547. while true do
  1548. local e, but, x, y = os.pullEvent()
  1549. if e == "key" and but == 200 and #servers > 0 and loc > 1 then
  1550. -- Up
  1551. loc = loc - 1
  1552. disList = updateDisplayList(servers, loc, len)
  1553. draw(disList, sel)
  1554. elseif e == "key" and but == 208 and #servers > 0 and loc + len - 1 < #servers then
  1555. -- Down
  1556. loc = loc + 1
  1557. disList = updateDisplayList(servers, loc, len)
  1558. draw(disList, sel)
  1559. elseif e == "mouse_click" then
  1560. if x >= 4 and x <= 25 then
  1561. if y == 8 then
  1562. newServer()
  1563. redirect("server")
  1564. return
  1565. elseif #servers > 0 then
  1566. for i, v in ipairs(disList) do
  1567. if y == i + 8 then
  1568. sel = i
  1569. draw(disList, sel)
  1570. end
  1571. end
  1572. end
  1573. elseif x >= 30 and x <= 40 and y == 10 and #servers > 0 then
  1574. -- Start
  1575. term.clear()
  1576. term.setCursorPos(1, 1)
  1577. term.setBackgroundColor(colors.black)
  1578. term.setTextColor(colors.white)
  1579. openAddressBar = false
  1580. setfenv(1, oldEnv)
  1581. shell.run(serverSoftwareLocation, disList[sel], serverFolder .. "/" .. disList[sel])
  1582. setfenv(1, env)
  1583. openAddressBar = true
  1584. errPages.checkForModem()
  1585.  
  1586. redirect("server")
  1587. return
  1588. elseif x >= 30 and x <= 39 and y == 12 and #servers > 0 then
  1589. editPages(disList[sel])
  1590. redirect("server")
  1591. return
  1592. elseif x >= 30 and x <= 46 and y == 14 and #servers > 0 then
  1593. -- Startup
  1594. fs.delete("/old-startup")
  1595. if fs.exists("/startup") then fs.move("/startup", "/old-startup") end
  1596. local f = io.open("/startup", "w")
  1597. f:write("shell.run(\"" .. serverSoftwareLocation .. "\", \"" ..
  1598. disList[sel] .. "\", \"" .. serverFolder .. "/" .. disList[sel] .. "\")")
  1599. f:close()
  1600.  
  1601. term.setBackgroundColor(colors[theme["bottom-box"]])
  1602. term.setCursorPos(32, 15)
  1603. write("Will Run on Boot!")
  1604. openAddressBar = false
  1605. sleep(1.1)
  1606. openAddressBar = true
  1607. term.setCursorPos(32, 15)
  1608. write(string.rep(" ", 18))
  1609. elseif x >= 30 and x <= 41 and y == 16 and #servers > 0 then
  1610. -- Delete
  1611. fs.delete(serverFolder .. "/" .. disList[sel])
  1612. redirect("server")
  1613. return
  1614. end
  1615. elseif e == event_exitWebsite then
  1616. os.queueEvent(event_exitWebsite)
  1617. return
  1618. end
  1619. end
  1620. else
  1621. local a = {"New Server"}
  1622. for _, v in pairs(servers) do table.insert(a, v) end
  1623. local server = scrollingPrompt(a, 4, 8, 10)
  1624. if server == nil then
  1625. os.queueEvent(event_exitWebsite)
  1626. return
  1627. elseif server == "New Server" then
  1628. newServer()
  1629. else
  1630. term.setCursorPos(30, 8)
  1631. write(server)
  1632. local opt = prompt({{"Start", 30, 10}, {"Edit", 30, 12}, {"Run on Boot", 30, 13},
  1633. {"Delete", 30, 14}, {"Back", 30, 16}})
  1634. if opt == "Start" then
  1635. -- Start
  1636. term.clear()
  1637. term.setCursorPos(1, 1)
  1638. term.setBackgroundColor(colors.black)
  1639. term.setTextColor(colors.white)
  1640. openAddressBar = false
  1641. setfenv(1, oldEnv)
  1642. shell.run(serverSoftwareLocation, server, serverFolder .. "/" .. server)
  1643. setfenv(1, env)
  1644. openAddressBar = true
  1645. errPages.checkForModem()
  1646. elseif opt == "Edit" then
  1647. editPages(server)
  1648. elseif opt == "Run on Boot" then
  1649. fs.delete("/old-startup")
  1650. if fs.exists("/startup") then fs.move("/startup", "/old-startup") end
  1651. local f = io.open("/startup", "w")
  1652. f:write("shell.run(\"" .. serverSoftwareLocation .. "\", \"" ..
  1653. server .. "\", \"" .. serverFolder .. "/" .. server .. "\")")
  1654. f:close()
  1655.  
  1656. term.setCursorPos(32, 17)
  1657. write("Will Run on Boot!")
  1658. openAddressBar = false
  1659. sleep(1.1)
  1660. openAddressBar = true
  1661. elseif opt == "Delete" then
  1662. fs.delete(serverFolder .. "/" .. server)
  1663. elseif opt == "Back" then
  1664. -- Do nothing
  1665. elseif opt == nil then
  1666. os.queueEvent(event_exitWebsite)
  1667. return
  1668. end
  1669. end
  1670.  
  1671. redirect("server")
  1672. return
  1673. end
  1674. end
  1675.  
  1676. pages.help = function(site)
  1677. clearPage(site, colors[theme["background"]])
  1678. term.setTextColor(colors[theme["text-color"]])
  1679. term.setBackgroundColor(colors[theme["top-box"]])
  1680. print("\n")
  1681. centerPrint(string.rep(" ", 47))
  1682. centerWrite(string.rep(" ", 47))
  1683. centerPrint("Firewolf Help")
  1684. centerPrint(string.rep(" ", 47))
  1685. print("")
  1686.  
  1687. term.setBackgroundColor(colors[theme["bottom-box"]])
  1688. for i = 1, 7 do centerPrint(string.rep(" ", 47)) end
  1689. local opt = prompt({{"Getting Started", 7, 9}, {"Making a Theme", 7, 11},
  1690. {"API Documentation", 7, 13}}, "vertical")
  1691. local pages = {}
  1692. if opt == "Getting Started" then
  1693. pages[1] = {title = "Getting Started - Intoduction", content = {
  1694. "Hey there!",
  1695. "",
  1696. "Firewolf is an app that allows you to create",
  1697. "and visit websites! Each site has name (the",
  1698. "URL) which you can type into the address bar",
  1699. "above, and then visit the site.",
  1700. }} pages[2] = {title = "Getting Started - Searching", content = {
  1701. "The address bar can be also be used to",
  1702. "search for sites, by simply typing in the",
  1703. "search term.",
  1704. "",
  1705. "To view all sites, just open it and hit",
  1706. "enter (leave the field blank)."
  1707. }} pages[3] = {title = "Getting Started - Built-In Websites", content = {
  1708. "Firewolf has a set of built-in websites",
  1709. "available for use:",
  1710. "",
  1711. "rdnt://firewolf Normal hompage",
  1712. "rdnt://history Your history",
  1713. "rdnt://downloads Download themes and plugins",
  1714. "rdnt://server Create websites",
  1715. "rdnt://help Help and documentation"
  1716. }} pages[4] = {title = "Getting Started - Built-In Websites", content = {
  1717. "More built-in websites:",
  1718. "",
  1719. "rdnt://settings Firewolf settings",
  1720. "rdnt://update Force update Firewolf",
  1721. "rdnt://getinfo Get website info",
  1722. "rdnt://credits View the credits",
  1723. "rdnt://exit Exit the app"
  1724. }}
  1725. elseif opt == "Making a Theme" then
  1726. pages[1] = {title = "Making a Theme - Introduction", content = {
  1727. "Firewolf themes are files that tell Firewolf",
  1728. "to color things certain colors.",
  1729. "Several themes can already be downloaded for",
  1730. "Firewolf from the Download Center.",
  1731. "",
  1732. "You can also make your own theme, use it in",
  1733. "your copy of Firewolf, and submit it to the",
  1734. "Firewolf Download Center!"
  1735. }} pages[2] = {title = "Making a Theme - Example", content = {
  1736. "A theme file consists of several lines of",
  1737. "text. Here is the default theme file:",
  1738. "",
  1739. "address-bar-text=white",
  1740. "address-bar-background=gray",
  1741. "top-box=red",
  1742. "bottom-box=orange",
  1743. "background=gray",
  1744. "text-color=white"
  1745. }} pages[3] = {title = "Making a Theme - Explanation", content = {
  1746. "On each line of the example, something is",
  1747. "given a color, like on the last line, the",
  1748. "text of the page is told to be white.",
  1749. "",
  1750. "The color specified after the = is the same",
  1751. "as when you call colors.[color name].",
  1752. "For example, specifying red after the =",
  1753. "colors that object red."
  1754. }} pages[4] = {title = "Making a Theme - Have a Go", content = {
  1755. "To make a theme, go to rdnt://downloads,",
  1756. "click on the themes section, and click on",
  1757. "'Create my Own'.",
  1758. "",
  1759. "Enter a theme name, then exit Firewolf and",
  1760. "edit the newly create file in the root",
  1761. "folder. Specify the colors for the keys,",
  1762. "and return to the themes section of the",
  1763. "downloads center. Click 'Load my Own'."
  1764. }} pages[5] = {title = "Making a Theme - Submitting", content = {
  1765. "To submit a theme to the Downloads Center,",
  1766. "send GravityScore a message on the CCForums",
  1767. "that contains your theme file and name.",
  1768. "",
  1769. "He will message you back saying whether your",
  1770. "theme has been added, or if anything needs to",
  1771. "be changed before it is added."
  1772. }}
  1773. elseif opt == "API Documentation" then
  1774. pages[1] = {title = "API Documentation - 1", content = {
  1775. "The Firewolf API is a bunch of global",
  1776. "functions that aim to simplify your life when",
  1777. "designing and coding websites.",
  1778. "",
  1779. "The functions are documented on the next few",
  1780. "pages."
  1781. }} pages[2] = {title = "API Documentation - 2", content = {
  1782. "centerPrint(text) cPrint(text)",
  1783. " - Prints text in the center of the screen",
  1784. "",
  1785. "centerWrite(text) cWrite(text)",
  1786. " - Writes text in the center of the screen",
  1787. "",
  1788. "leftPrint(text) lPrint(text)",
  1789. " - Prints text to the left of the screen"
  1790. }} pages[3] = {title = "API Documentation - 3", content = {
  1791. "leftWrite(text) lWrite(text)",
  1792. " - Writes text to the left of the screen",
  1793. "",
  1794. "rightPrint(text) rPrint(text)",
  1795. " - Prints text to the right of the screen",
  1796. "",
  1797. "rightWrite(text) rWrite(text)",
  1798. " - Writes text to the right of the screen"
  1799. }} pages[4] = {title = "API Documentation - 4", content = {
  1800. "prompt(list, direction)",
  1801. " - Prompts the user to choose an option",
  1802. " from a list formatted like:",
  1803. " { { \"Option 1\", [x], [y] }, ... }",
  1804. " - Returns the name of the selected option",
  1805. " - Example:",
  1806. " option = prompt({{\"Option 1\", 4, 2},",
  1807. " {\"Option 2\", 4, 4}})"
  1808. }} pages[5] = {title = "API Documentation - 5", content = {
  1809. "scrollingPrompt(list, x, y, width, height)",
  1810. " - Prompts the user to choose an option",
  1811. " from a scrolling list of options",
  1812. " - Returns the name of the selected option",
  1813. " - Example:",
  1814. " option = scrollingPrompt({\"1\", \"2\",",
  1815. " \"3\", \"4\"}, 4, 2, 41, 12)"
  1816. }} pages[6] = {title = "API Documentation - 6", content = {
  1817. "redirect(site)",
  1818. " - Redirects to site",
  1819. "",
  1820. "pastebinDownload(code)",
  1821. " - Prompts user to download from Pastebin",
  1822. " - Returns the path the user selected to",
  1823. " download the file to"
  1824. }} pages[7] = {title = "API Documentation - 7", content = {
  1825. "urlDownload(url)",
  1826. " - Prompts the user to download a raw file",
  1827. " from a URL",
  1828. " - Returns the path the user selected to",
  1829. " download the file to"
  1830. }}
  1831. elseif opt == nil then
  1832. os.queueEvent(event_exitWebsite)
  1833. return
  1834. end
  1835.  
  1836. local function drawPage(page)
  1837. clearPage(site, colors[theme["background"]])
  1838. term.setTextColor(colors[theme["text-color"]])
  1839. term.setBackgroundColor(colors[theme["top-box"]])
  1840. print("")
  1841. centerPrint(string.rep(" ", 47))
  1842. centerWrite(string.rep(" ", 47))
  1843. centerPrint(page.title)
  1844. centerPrint(string.rep(" ", 47))
  1845. print("")
  1846.  
  1847. term.setBackgroundColor(colors[theme["bottom-box"]])
  1848. for i = 1, 12 do centerPrint(string.rep(" ", 47)) end
  1849. for i, v in ipairs(page.content) do
  1850. term.setCursorPos(4, i + 7)
  1851. write(v)
  1852. end
  1853. end
  1854.  
  1855. local curPage = 1
  1856. local a = {{"Prev", 26, 18}, {"Next", 38, 18}, {"Back", 14, 18}}
  1857. drawPage(pages[curPage])
  1858.  
  1859. while true do
  1860. local b = {a[3]}
  1861. if curPage == 1 then table.insert(b, a[2])
  1862. elseif curPage == #pages then table.insert(b, a[1])
  1863. else table.insert(b, a[1]) table.insert(b, a[2]) end
  1864.  
  1865. local opt = prompt(b, "horizontal")
  1866. if opt == "Prev" then
  1867. curPage = curPage - 1
  1868. elseif opt == "Next" then
  1869. curPage = curPage + 1
  1870. elseif opt == "Back" then
  1871. break
  1872. elseif opt == nil then
  1873. os.queueEvent(event_exitWebsite)
  1874. return
  1875. end
  1876.  
  1877. drawPage(pages[curPage])
  1878. end
  1879.  
  1880. redirect("help")
  1881. end
  1882.  
  1883. pages.settings = function(site)
  1884. while true do
  1885. clearPage(site, colors[theme["background"]])
  1886. print("\n")
  1887. term.setTextColor(colors[theme["text-color"]])
  1888. term.setBackgroundColor(colors[theme["top-box"]])
  1889. centerPrint(string.rep(" ", 43))
  1890. centerWrite(string.rep(" ", 43))
  1891. centerPrint("Firewolf Settings")
  1892. centerWrite(string.rep(" ", 43))
  1893. if not(fs.exists("/.var/settings")) then centerPrint("Designed For: " .. serverList[serverID])
  1894. else centerPrint("Designed For: NDF-OS") end
  1895. centerPrint(string.rep(" ", 43))
  1896. print("")
  1897.  
  1898. local a = "Automatic Updating - On"
  1899. if autoupdate == "false" then a = "Automatic Updating - Off" end
  1900. local b = "Record History - On"
  1901. if incognito == "true" then b = "Record History - Off" end
  1902. local c = "Homepage - rdnt://" .. homepage
  1903.  
  1904. term.setBackgroundColor(colors[theme["bottom-box"]])
  1905. for i = 1, 9 do centerPrint(string.rep(" ", 43)) end
  1906. local opt = prompt({{a, 7, 10}, {b, 7, 12}, {c, 7, 14}, {"Reset Firewolf", 7, 16}}, "vertical")
  1907. if opt == a then
  1908. if autoupdate == "true" then autoupdate = "false"
  1909. elseif autoupdate == "false" then autoupdate = "true" end
  1910. elseif opt == b then
  1911. if incognito == "true" then incognito = "false"
  1912. elseif incognito == "false" then incognito = "true" end
  1913. elseif opt == c then
  1914. term.setCursorPos(9, 15)
  1915. write("rdnt://")
  1916. local a = modRead(nil, nil, 30)
  1917. if a == nil then
  1918. os.queueEvent(event_exitWebsite)
  1919. return
  1920. end
  1921. if a ~= "" then homepage = a end
  1922. elseif opt == "Reset Firewolf" then
  1923. clearPage(site, colors[theme["background"]])
  1924. term.setTextColor(colors[theme["text-color"]])
  1925. term.setBackgroundColor(colors[theme["top-box"]])
  1926. print("")
  1927. centerPrint(string.rep(" ", 43))
  1928. centerWrite(string.rep(" ", 43))
  1929. centerPrint("Reset Firewolf")
  1930. centerPrint(string.rep(" ", 43))
  1931. print("")
  1932. term.setBackgroundColor(colors[theme["bottom-box"]])
  1933. for i = 1, 12 do centerPrint(string.rep(" ", 43)) end
  1934. local opt = prompt({{"Reset History", 7, 8}, {"Reset Servers", 7, 9},
  1935. {"Reset Theme", 7, 10}, {"Reset Cache", 7, 11}, {"Reset Databases", 7, 12},
  1936. {"Reset Settings", 7, 13}, {"Back", 7, 14}, {"Reset All", 7, 16}}, "vertical")
  1937.  
  1938. openAddressBar = false
  1939. if opt == "Reset All" then
  1940. fs.delete(rootFolder)
  1941. elseif opt == "Reset History" then
  1942. fs.delete(historyLocation)
  1943. elseif opt == "Reset Servers" then
  1944. fs.delete(serverFolder)
  1945. fs.delete(serverSoftwareLocation)
  1946. elseif opt == "Reset Cache" then
  1947. fs.delete(cacheFolder)
  1948. elseif opt == "Reset Databases" then
  1949. fs.delete(userWhitelist)
  1950. fs.delete(userBlacklist)
  1951. fs.delete(globalDatabase)
  1952. elseif opt == "Reset Settings" then
  1953. fs.delete(settingsLocation)
  1954. elseif opt == "Reset Theme" then
  1955. fs.delete(themeLocation)
  1956. fs.copy(defaultThemeLocation, themeLocation)
  1957. elseif opt == "Back" then
  1958. openAddressBar = true
  1959. redirect("settings")
  1960. return
  1961. elseif opt == nil then
  1962. openAddressBar = true
  1963. os.queueEvent(event_exitWebsite)
  1964. return
  1965. end
  1966.  
  1967. clearPage(site, colors[theme["background"]])
  1968. term.setBackgroundColor(colors[theme["top-box"]])
  1969. print("")
  1970. centerPrint(string.rep(" ", 43))
  1971. centerWrite(string.rep(" ", 43))
  1972. centerPrint("Reset Firewolf")
  1973. centerPrint(string.rep(" ", 43))
  1974. print("")
  1975. term.setCursorPos(1, 10)
  1976. term.setBackgroundColor(colors[theme["bottom-box"]])
  1977. centerPrint(string.rep(" ", 43))
  1978. centerWrite(string.rep(" ", 43))
  1979. centerPrint("Firewolf has been reset.")
  1980. centerWrite(string.rep(" ", 43))
  1981. if term.isColor() then centerPrint("Click to exit...")
  1982. else centerPrint("Press any key to exit...") end
  1983. centerPrint(string.rep(" ", 43))
  1984. while true do
  1985. local e = os.pullEvent()
  1986. if e == "mouse_click" or e == "key" then return true end
  1987. end
  1988. elseif opt == nil then
  1989. os.queueEvent(event_exitWebsite)
  1990. return
  1991. end
  1992.  
  1993. -- Save
  1994. local f = io.open(settingsLocation, "w")
  1995. f:write(textutils.serialize({auto = autoupdate, incog = incognito, home = homepage}))
  1996. f:close()
  1997. end
  1998. end
  1999.  
  2000. pages.update = function(site)
  2001. clearPage(site, colors[theme["background"]])
  2002. print("\n")
  2003. term.setTextColor(colors[theme["text-color"]])
  2004. term.setBackgroundColor(colors[theme["top-box"]])
  2005. centerPrint(string.rep(" ", 43))
  2006. centerWrite(string.rep(" ", 43))
  2007. centerPrint("Force Update Firewolf")
  2008. centerPrint(string.rep(" ", 43))
  2009.  
  2010. print("\n")
  2011. term.setBackgroundColor(colors[theme["bottom-box"]])
  2012. centerPrint(string.rep(" ", 43))
  2013. centerPrint(string.rep(" ", 43))
  2014. centerPrint(string.rep(" ", 43))
  2015.  
  2016. local opt = prompt({{"Update", 7, 10}, {"Cancel", 34, 10}}, "horizontal")
  2017. if opt == "Update" then
  2018. openAddressBar = false
  2019. term.setCursorPos(1, 10)
  2020. centerWrite(string.rep(" ", 43))
  2021. centerWrite("Updating...")
  2022.  
  2023. local updateLocation = rootFolder .. "/update"
  2024. fs.delete(updateLocation)
  2025. download(firewolfURL, updateLocation)
  2026. centerWrite(string.rep(" ", 43))
  2027. centerPrint("Done!")
  2028. centerWrite(string.rep(" ", 43))
  2029. if term.isColor() then centerPrint("Click to exit...")
  2030. else centerPrint("Press any key to exit...") end
  2031. centerPrint(string.rep(" ", 43))
  2032. sleep(1.1)
  2033. fs.delete(firewolfLocation)
  2034. fs.move(updateLocation, firewolfLocation)
  2035.  
  2036. return true
  2037. elseif opt == "Cancel" then
  2038. redirect("home")
  2039. return
  2040. elseif opt == nil then
  2041. os.queueEvent(event_exitWebsite)
  2042. return
  2043. end
  2044. end
  2045.  
  2046. pages.credits = function(site)
  2047. clearPage(site, colors[theme["background"]])
  2048. print("\n")
  2049. term.setTextColor(colors[theme["text-color"]])
  2050. term.setBackgroundColor(colors[theme["top-box"]])
  2051. centerPrint(string.rep(" ", 43))
  2052. centerWrite(string.rep(" ", 43))
  2053. centerPrint("Firewolf Credits")
  2054. centerPrint(string.rep(" ", 43))
  2055. print("\n")
  2056. term.setBackgroundColor(colors[theme["bottom-box"]])
  2057. centerPrint(string.rep(" ", 43))
  2058. centerWrite(string.rep(" ", 43))
  2059. centerPrint("Coded by: GravityScore and")
  2060. centerWrite(string.rep(" ", 43))
  2061. centerPrint(" 1lann")
  2062. centerPrint(string.rep(" ", 43))
  2063. centerWrite(string.rep(" ", 43))
  2064. centerPrint("Based off: RednetExplorer 2.4.1")
  2065. centerWrite(string.rep(" ", 43))
  2066. centerPrint(" Made by ComputerCraftFan11")
  2067. centerPrint(string.rep(" ", 43))
  2068. end
  2069.  
  2070. --pages.getinfo = function(site)
  2071. -- clearPage(site, colors[theme["background"]])
  2072. -- print("\n")
  2073. -- term.setTextColor(colors[theme["text-color"]])
  2074. -- term.setBackgroundColor(colors[theme["top-box"]])
  2075. -- centerPrint(string.rep(" ", 43))
  2076. -- centerWrite(string.rep(" ", 43))
  2077. -- centerPrint("Retrieve Website Information")
  2078. -- centerPrint(string.rep(" ", 43))
  2079. -- print("\n")
  2080. --
  2081. -- term.setBackgroundColor(colors[theme["bottom-box"]])
  2082. -- centerPrint(string.rep(" ", 43))
  2083. -- centerPrint(string.rep(" ", 43))
  2084. -- centerWrite(string.rep(" ", 43))
  2085. -- local x, y = term.getCursorPos()
  2086. -- term.setCursorPos(7, y - 1)
  2087. -- write("rdnt://")
  2088. -- local a = modRead(nil, nil, 31)
  2089. -- if a == nil then
  2090. -- os.queueEvent(event_exitWebsite)
  2091. -- return
  2092. -- end
  2093. -- local id, content, status = getWebsite(a)
  2094. --
  2095. -- if id ~= nil then
  2096. -- term.setCursorPos(1, 10)
  2097. -- centerPrint(" rdnt://" .. a .. string.rep(" ", 34 - a:len()))
  2098. -- for i = 1, 5 do
  2099. -- centerPrint(string.rep(" ", 43))
  2100. -- end
  2101. --
  2102. -- if verify("blacklist", id) then
  2103. -- centerPrint(" Triggers Blacklist" .. string.rep(" ", 43 - 20)) end
  2104. -- if verify("whitelist", id, site) then
  2105. -- centerPrint(" Triggers Whitelist" .. string.rep(" ", 43 - 20)) end
  2106. -- if verify("antivirus", content) then
  2107. -- centerPrint(" Triggers Antivirus" .. string.rep(" ", 43 - 20)) end
  2108. -- centerPrint(string.rep(" ", 43))
  2109. -- local opt = prompt({{"Save Source", 7, 12}, {"Visit Site", 7, 14}}, "vertical")
  2110. -- if opt == "Save Source" then
  2111. -- term.setCursorPos(9, 13)
  2112. -- write("Save As: /")
  2113. -- local loc = modRead(nil, nil, 24)
  2114. -- if loc ~= nil and loc ~= "" then
  2115. -- loc = "/" .. loc
  2116. -- local f = io.open(loc, "w")
  2117. -- f:write(content)
  2118. -- f:close()
  2119. -- term.setCursorPos(1, 13)
  2120. -- centerWrite(string.rep(" ", 43))
  2121. -- elseif loc == nil then
  2122. -- os.queueEvent(event_exitWebsite)
  2123. -- return
  2124. -- end
  2125. -- elseif opt == "Visit Site" then
  2126. -- redirect(a)
  2127. -- return
  2128. -- elseif opt == nil then
  2129. -- os.queueEvent(event_exitWebsite)
  2130. -- return
  2131. -- end
  2132. -- else
  2133. -- term.setCursorPos(1, 10)
  2134. -- centerWrite(string.rep(" ", 43))
  2135. -- centerPrint("Webpage Not Found! D:")
  2136. -- end
  2137. --end
  2138.  
  2139. pages.kitteh = function(site)
  2140. openAddressBar = false
  2141. term.setTextColor(colors[theme["text-color"]])
  2142. term.setBackgroundColor(colors[theme["background"]])
  2143. term.clear()
  2144. term.setCursorPos(1, 3)
  2145. centerPrint(" .__....._ _.....__, ")
  2146. centerPrint(" .\": o :': ;': o :\". ")
  2147. centerPrint(" '. '-' .'. .'. '-' .' ")
  2148. centerPrint(" '---' '---' ")
  2149. centerPrint(" ")
  2150. centerPrint(" _...----... ... ... ...----..._ ")
  2151. centerPrint(" .-'__..-\"\"'---- '. '\"' .' ----'\"\"-..__'-. ")
  2152. centerPrint("'.-' _.--\"\"\"' '-._.-' '\"\"\"--._ '-.'")
  2153. centerPrint("' .-\"' : '\"-. '")
  2154. centerPrint(" ' '. _.'\"'._ .' ' ")
  2155. centerPrint(" '. ,.-'\" \"'-., .' ")
  2156. centerPrint(" '. .' ")
  2157. centerPrint(" '-._ _.-' ")
  2158. centerPrint(" '\"'--.....--'\"' ")
  2159. print("")
  2160. centerPrint("Firewolf Kitteh is Not Amused...")
  2161. sleep(6)
  2162. os.shutdown()
  2163. end
  2164.  
  2165. errPages.overspeed = function()
  2166. website = "overspeed"
  2167. clearPage("overspeed", colors[theme["background"]])
  2168. print("\n")
  2169. term.setTextColor(colors[theme["text-color"]])
  2170. term.setBackgroundColor(colors[theme["top-box"]])
  2171. centerPrint(string.rep(" ", 43))
  2172. centerWrite(string.rep(" ", 43))
  2173. centerPrint("Warning! D:")
  2174. centerPrint(string.rep(" ", 43))
  2175. print("")
  2176.  
  2177. term.setBackgroundColor(colors[theme["bottom-box"]])
  2178. centerPrint(string.rep(" ", 43))
  2179. centerPrint(" Website browsing sleep limit reached! ")
  2180. centerPrint(string.rep(" ", 43))
  2181. centerPrint(" To prevent Firewolf from spamming ")
  2182. centerPrint(" rednet, Firewolf has stopped loading ")
  2183. centerPrint(" the page. ")
  2184. centerPrint(string.rep(" ", 43))
  2185. centerPrint(string.rep(" ", 43))
  2186. centerPrint(string.rep(" ", 43))
  2187. openAddressBar = false
  2188. for i = 1, 5 do
  2189. term.setCursorPos(1, 14)
  2190. centerWrite(string.rep(" ", 43))
  2191. if 6 - i == 1 then centerWrite("Please wait 1 second...")
  2192. else centerWrite("Please wait " .. tostring(6 - i) .. " seconds...") end
  2193. sleep(1)
  2194. end
  2195. openAddressBar = true
  2196.  
  2197. term.setCursorPos(1, 14)
  2198. centerWrite(string.rep(" ", 43))
  2199. centerWrite("You may now browse normally...")
  2200. end
  2201.  
  2202. errPages.crash = function(err)
  2203. clearPage("crash", colors[theme["background"]])
  2204. print("")
  2205. term.setTextColor(colors[theme["text-color"]])
  2206. term.setBackgroundColor(colors[theme["top-box"]])
  2207. centerPrint(string.rep(" ", 43))
  2208. centerWrite(string.rep(" ", 43))
  2209. centerPrint("The Website Has Crashed! D:")
  2210. centerPrint(string.rep(" ", 43))
  2211. print("")
  2212.  
  2213. term.setBackgroundColor(colors[theme["bottom-box"]])
  2214. centerPrint(string.rep(" ", 43))
  2215. centerWrite(string.rep(" ", 43))
  2216. centerPrint("It looks like the website has crashed!")
  2217. centerWrite(string.rep(" ", 43))
  2218. centerPrint("Report this error to the website owner:")
  2219. centerPrint(string.rep(" ", 43))
  2220. term.setBackgroundColor(colors[theme["background"]])
  2221. print("")
  2222. print(" " .. err)
  2223. print("")
  2224.  
  2225. term.setBackgroundColor(colors[theme["bottom-box"]])
  2226. centerPrint(string.rep(" ", 43))
  2227. centerWrite(string.rep(" ", 43))
  2228. centerPrint("You may now browse normally!")
  2229. centerPrint(string.rep(" ", 43))
  2230. end
  2231.  
  2232. errPages.checkForModem = function()
  2233. rednet.open("top")
  2234. rednet.open("bottom")
  2235. rednet.open("left")
  2236. rednet.open("right")
  2237. rednet.open("front")
  2238. rednet.open("back")
  2239. return true
  2240. end
  2241.  
  2242. errPages.blacklistRedirectionBots = function()
  2243. local suspected = {}
  2244. local alphabet = {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n",
  2245. "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "."}
  2246. local name = ""
  2247. for i = 1, math.random(1,3) do
  2248. name = ""
  2249. for d = 1, math.random(6, 17) do
  2250. name = name .. alphabet[math.random(1, 27)]
  2251. end
  2252. rednet.broadcast(name)
  2253. sleep(timeout)
  2254. end
  2255.  
  2256. for i = 1, 4 do
  2257. name = ""
  2258. for d = 1, math.random(6, 17) do
  2259. name = name .. alphabet[math.random(1, 27)]
  2260. end
  2261.  
  2262. local finishCheck = false
  2263. rednet.broadcast(name)
  2264. clock = os.clock()
  2265. for i = 1, 5 do
  2266. while os.clock() - clock < timeout do
  2267. local id = rednet.receive(timeout)
  2268. if id ~= nil and not(verify("blacklist", id)) then
  2269. name = ""
  2270. for d = 1, math.random(6, 17) do
  2271. name = name .. alphabet[math.random(1, 27)]
  2272. end
  2273.  
  2274. local inSuspected = false
  2275. for b = 1, #suspected do
  2276. if suspected[b][1] == id then
  2277. suspected[b][2] = suspected[b][2] + 1
  2278. inSuspected = true
  2279. end
  2280. end
  2281.  
  2282. if not(inSuspected) then
  2283. table.insert(suspected, {id, 1})
  2284. break
  2285. end
  2286. elseif id == nil then
  2287. finishCheck = true
  2288. break
  2289. end
  2290. end
  2291. if finishCheck then break end
  2292. end
  2293. if finishCheck then break end
  2294. end
  2295.  
  2296. for i = 1, #suspected do
  2297. if suspected[i][2] > 2 then
  2298. local f = io.open(userBlacklist, "a")
  2299. f:write(tostring(suspected[i][1]) .. "\n")
  2300. f:close()
  2301. table.insert(blacklist, tostring(suspected[i][1]))
  2302. end
  2303. end
  2304. end
  2305.  
  2306. local function loadSite(site)
  2307. local function runSite(cacheLoc)
  2308. -- Clear
  2309. clearPage(site, colors.black)
  2310. term.setBackgroundColor(colors.black)
  2311. term.setTextColor(colors.white)
  2312.  
  2313. -- Setup environment
  2314. local curBackgroundColor = colors.black
  2315. local nenv = {}
  2316. for k, v in pairs(getfenv(0)) do nenv[k] = v end
  2317. for k, v in pairs(getfenv(1)) do nenv[k] = v end
  2318. nenv.term = {}
  2319. nenv.os = {}
  2320. nenv.shell = {}
  2321.  
  2322. nenv.term.getSize = function()
  2323. local wid, hei = env.term.getSize()
  2324. return wid, hei - 1
  2325. end
  2326.  
  2327. nenv.term.setCursorPos = function(x, y)
  2328. return env.term.setCursorPos(x, y + 1)
  2329. end
  2330.  
  2331. nenv.term.getCursorPos = function()
  2332. local x, y = env.term.getCursorPos()
  2333. return x, y + 1
  2334. end
  2335.  
  2336. nenv.term.clear = function()
  2337. return api.clearPage(website, curBackgroundColor)
  2338. end
  2339.  
  2340. nenv.term.setBackgroundColor = function(col)
  2341. curBackgroundColor = col
  2342. return env.getBackgroundColor(col)
  2343. end
  2344.  
  2345. nenv.term.getBackgroundColor = function()
  2346. return curBackgroundColor
  2347. end
  2348.  
  2349. local oldScroll = term.scroll
  2350. term.scroll = function(n)
  2351. local x, y = env.term.getCursorPos()
  2352. oldScroll(n)
  2353. clearPage(website, curBackgroundColor, true)
  2354. env.term.setCursorPos(x, y)
  2355. end
  2356.  
  2357. nenv.redirect = function(url)
  2358. api.redirect(url)
  2359. env.error()
  2360. end
  2361.  
  2362. nenv.shell.run = function(file, ...)
  2363. if file == "clear" then
  2364. api.clearPage(website, curBackgroundColor)
  2365. env.term.setCursorPos(1, 2)
  2366. else
  2367. env.shell.run(file, unpack({...}))
  2368. end
  2369. end
  2370.  
  2371. nenv.os.pullEvent = function(a)
  2372. while true do
  2373. local e, p1, p2, p3, p4, p5 = env.os.pullEventRaw()
  2374. if e == event_exitWebsite then
  2375. os.queueEvent(event_exitWebsite)
  2376. env.error(event_exitWebsite)
  2377. elseif e == "terminate" then
  2378. env.error()
  2379. end
  2380.  
  2381. if e ~= event_exitWebsite and e ~= event_redirect and e ~= event_exitApp
  2382. and e ~= event_loadWebsite then
  2383. if a then
  2384. if e == a then return e, p1, p2, p3, p4, p5 end
  2385. else return e, p1, p2, p3, p4, p5 end
  2386. end
  2387. end
  2388. end
  2389.  
  2390. -- Run
  2391. local fn, err = loadfile(cacheLoc)
  2392. if fn and err == nil then
  2393. setfenv(fn, nenv)
  2394. _, err = pcall(fn)
  2395. setfenv(1, env)
  2396. end
  2397.  
  2398. -- Catch website error
  2399. if err and not(err:find(event_exitWebsite)) then errPages.crash(err) end
  2400. end
  2401.  
  2402. -- Draw
  2403. openAddressBar = false
  2404. clearPage(site, colors[theme["background"]])
  2405. term.setTextColor(colors[theme["text-color"]])
  2406. term.setBackgroundColor(colors[theme["background"]])
  2407. print("\n\n")
  2408. centerPrint("Connecting...")
  2409.  
  2410. -- Redirection bots
  2411. errPages.blacklistRedirectionBots()
  2412. loadingRate = loadingRate + 1
  2413.  
  2414. -- Get website
  2415. local id, content, status = curProtocol.getWebsite(site)
  2416.  
  2417. -- Display website
  2418. local cacheLoc = cacheFolder .. "/" .. site:gsub("/", "$slazh$")
  2419. if id ~= nil then
  2420. openAddressBar = true
  2421. if status == "antivirus" then
  2422. local offences = verify("antivirus offences", content)
  2423. if #offences > 0 then
  2424. clearPage(site, colors[theme["background"]])
  2425. print("")
  2426. term.setTextColor(colors[theme["text-color"]])
  2427. term.setBackgroundColor(colors[theme["top-box"]])
  2428. centerPrint(string.rep(" ", 47))
  2429. centerWrite(string.rep(" ", 47))
  2430. centerPrint("Antivirus Triggered!")
  2431. centerPrint(string.rep(" ", 47))
  2432. print("")
  2433.  
  2434. term.setBackgroundColor(colors[theme["bottom-box"]])
  2435. centerPrint(string.rep(" ", 47))
  2436. centerPrint(" The antivirus has been triggered on this ")
  2437. centerPrint(" website! Do you want to give this website ")
  2438. centerPrint(" permissions to: ")
  2439. for i = 1, 8 do centerPrint(string.rep(" ", 47)) end
  2440. for i, v in ipairs(offences) do
  2441. if i > 3 then term.setCursorPos(w - 21, i + 8)
  2442. else term.setCursorPos(6, i + 11) end
  2443. write("[ " .. v)
  2444. end
  2445.  
  2446. local opt = prompt({{"Allow", 6, 17}, {"Cancel", w - 16, 17}}, "horizontal")
  2447. if opt == "Allow" then
  2448. status = "safe"
  2449. elseif opt == "Cancel" then
  2450. clearPage(site, colors[theme["background"]])
  2451. print("")
  2452. term.setTextColor(colors[theme["text-color"]])
  2453. term.setBackgroundColor(colors[theme["top-box"]])
  2454. centerPrint(string.rep(" ", 47))
  2455. centerWrite(string.rep(" ", 47))
  2456. centerPrint("O Noes!")
  2457. centerPrint(string.rep(" ", 47))
  2458. print("")
  2459.  
  2460. term.setBackgroundColor(colors[theme["bottom-box"]])
  2461. centerPrint(string.rep(" ", 47))
  2462. centerPrint(" ______ __ ")
  2463. centerPrint(" / ____/_____ _____ ____ _____ / / ")
  2464. centerPrint(" / __/ / ___// ___// __ \\ / ___// / ")
  2465. centerPrint(" / /___ / / / / / /_/ // / /_/ ")
  2466. centerPrint(" /_____//_/ /_/ \\____//_/ (_) ")
  2467. centerPrint(string.rep(" ", 47))
  2468. centerPrint(" Could not connect to the website! The ")
  2469. centerPrint(" website was not given enough permissions to ")
  2470. centerPrint(" execute properly! ")
  2471. centerPrint(string.rep(" ", 47))
  2472. elseif opt == nil then
  2473. os.queueEvent(event_exitWebsite)
  2474. return
  2475. end
  2476. else
  2477. status = "safe"
  2478. end
  2479. end
  2480.  
  2481. if status == "safe" and site ~= "" then
  2482. local f = io.open(cacheLoc, "w")
  2483. f:write(content)
  2484. f:close()
  2485. runSite(cacheLoc)
  2486. return
  2487. end
  2488. else
  2489. if fs.exists(cacheLoc) and site ~= "" and site ~= "." and site ~= ".." and
  2490. not(verify("blacklist", site)) then
  2491. openAddressBar = true
  2492. clearPage(site, colors[theme["background"]])
  2493. print("")
  2494. term.setTextColor(colors[theme["text-color"]])
  2495. term.setBackgroundColor(colors[theme["top-box"]])
  2496. centerPrint(string.rep(" ", 47))
  2497. centerWrite(string.rep(" ", 47))
  2498. centerPrint("Cache Exists!")
  2499. centerPrint(string.rep(" ", 47))
  2500. print("")
  2501.  
  2502. term.setBackgroundColor(colors[theme["bottom-box"]])
  2503. centerPrint(string.rep(" ", 47))
  2504. centerPrint(" ______ __ __ ")
  2505. centerPrint(" / ____/____ _ _____ / /_ ___ / / ")
  2506. centerPrint(" / / / __ '// ___// __ \\ / _ \\ / / ")
  2507. centerPrint(" / /___ / /_/ // /__ / / / // __/ /_/ ")
  2508. centerPrint(" \\____/ \\__,_/ \\___//_/ /_/ \\___/ (_) ")
  2509. centerPrint(string.rep(" ", 47))
  2510. centerPrint(" Could not connect to the website! It may be ")
  2511. centerPrint(" down, or not exist! A cached version was ")
  2512. centerPrint(" found! ")
  2513. centerPrint(string.rep(" ", 47))
  2514. centerPrint(string.rep(" ", 47))
  2515.  
  2516. local opt = prompt({{"Load Cache", 6, 17}, {"Cancel", w - 16, 17}}, "horizontal")
  2517. if opt == "Load Cache" then
  2518. runSite(cacheLoc)
  2519. return
  2520. elseif opt == "Cancel" then
  2521. clearPage(site, colors[theme["background"]])
  2522. print("\n")
  2523. term.setTextColor(colors[theme["text-color"]])
  2524. term.setBackgroundColor(colors[theme["top-box"]])
  2525. centerPrint(string.rep(" ", 47))
  2526. centerWrite(string.rep(" ", 47))
  2527. centerPrint("O Noes!")
  2528. centerPrint(string.rep(" ", 47))
  2529. print("")
  2530.  
  2531. term.setBackgroundColor(colors[theme["bottom-box"]])
  2532. centerPrint(string.rep(" ", 47))
  2533. centerPrint(" ______ __ ")
  2534. centerPrint(" / ____/_____ _____ ____ _____ / / ")
  2535. centerPrint(" / __/ / ___// ___// __ \\ / ___// / ")
  2536. centerPrint(" / /___ / / / / / /_/ // / /_/ ")
  2537. centerPrint(" /_____//_/ /_/ \\____//_/ (_) ")
  2538. centerPrint(string.rep(" ", 47))
  2539. centerPrint(" Could not connect to the website! The ")
  2540. centerPrint(" cached version was not loaded! ")
  2541. centerPrint(string.rep(" ", 47))
  2542. elseif opt == nil then
  2543. os.queueEvent(event_exitWebsite)
  2544. return
  2545. end
  2546. else
  2547. local res = curProtocol.getSearchResults(site)
  2548.  
  2549. openAddressBar = true
  2550. if #res > 0 then
  2551. clearPage(site, colors[theme["background"]])
  2552. print("")
  2553. term.setTextColor(colors[theme["text-color"]])
  2554. term.setBackgroundColor(colors[theme["top-box"]])
  2555. centerPrint(string.rep(" ", 47))
  2556. centerWrite(string.rep(" ", 47))
  2557. if #res == 1 then centerPrint("1 Search Result")
  2558. else centerPrint(#res .. " Search Results") end
  2559. centerPrint(string.rep(" ", 47))
  2560. print("")
  2561.  
  2562. term.setBackgroundColor(colors[theme["bottom-box"]])
  2563. for i = 1, 12 do centerPrint(string.rep(" ", 47)) end
  2564. local opt = scrollingPrompt(res, 4, 8, 10, 43)
  2565. if opt then
  2566. redirect(opt:gsub("rdnt://", ""))
  2567. return
  2568. else
  2569. os.queueEvent(event_exitWebsite)
  2570. return
  2571. end
  2572. elseif site == "" and #res == 0 then
  2573. clearPage(site, colors[theme["background"]])
  2574. print("\n\n")
  2575. term.setTextColor(colors[theme["text-color"]])
  2576. term.setBackgroundColor(colors[theme["top-box"]])
  2577. centerPrint(string.rep(" ", 47))
  2578. centerWrite(string.rep(" ", 47))
  2579. centerPrint("No Websites are Currently Online! D:")
  2580. centerPrint(string.rep(" ", 47))
  2581. else
  2582. clearPage(site, colors[theme["background"]])
  2583. print("\n")
  2584. term.setTextColor(colors[theme["text-color"]])
  2585. term.setBackgroundColor(colors[theme["top-box"]])
  2586. centerPrint(string.rep(" ", 47))
  2587. centerWrite(string.rep(" ", 47))
  2588. centerPrint("O Noes!")
  2589. centerPrint(string.rep(" ", 47))
  2590. print("")
  2591. term.setBackgroundColor(colors[theme["bottom-box"]])
  2592. centerPrint(string.rep(" ", 47))
  2593. centerPrint(" ______ __ ")
  2594. centerPrint(" / ____/_____ _____ ____ _____ / / ")
  2595. centerPrint(" / __/ / ___// ___// __ \\ / ___// / ")
  2596. centerPrint(" / /___ / / / / / /_/ // / /_/ ")
  2597. centerPrint(" /_____//_/ /_/ \\____//_/ (_) ")
  2598. centerPrint(string.rep(" ", 47))
  2599. if verify("blacklist", id) then
  2600. centerPrint(" Could not connect to the website! It has ")
  2601. centerPrint(" been blocked by a database admin! ")
  2602. else
  2603. centerPrint(" Could not connect to the website! It may ")
  2604. centerPrint(" be down, or not exist! ")
  2605. end
  2606. centerPrint(string.rep(" ", 47))
  2607. end
  2608. end
  2609. end
  2610. end
  2611.  
  2612.  
  2613. -- -------- Websites
  2614.  
  2615. local function websiteMain()
  2616. -- Variables
  2617. local loadingClock = os.clock()
  2618.  
  2619. -- Main loop
  2620. while true do
  2621. -- Reset
  2622. setfenv(1, backupEnv)
  2623. browserAgent = browserAgentTemplate
  2624. clearPage(website)
  2625. w, h = term.getSize()
  2626. term.setBackgroundColor(colors.black)
  2627. term.setTextColor(colors.white)
  2628.  
  2629. -- Exit
  2630. if website == "exit" then
  2631. os.queueEvent(event_exitApp)
  2632. return
  2633. end
  2634.  
  2635. -- Perform Checks
  2636. local skip = false
  2637. local oldWebsite = website
  2638. if not(errPages.checkForModem()) then
  2639. os.queueEvent(event_exitApp)
  2640. return
  2641. end
  2642. website = oldWebsite
  2643. if os.clock() - loadingClock > 5 then
  2644. loadingRate = 0
  2645. loadingClock = os.clock()
  2646. elseif loadingRate >= 8 then
  2647. errPages.overspeed()
  2648. loadingClock = os.clock()
  2649. loadingRate = 0
  2650. skip = true
  2651. end if not(skip) then
  2652. appendToHistory(website)
  2653.  
  2654. -- Render site
  2655. clearPage(website)
  2656. term.setBackgroundColor(colors.black)
  2657. term.setTextColor(colors.white)
  2658. if pages[website] then
  2659. local ex = pages[website](website)
  2660. if ex == true then
  2661. os.queueEvent(event_exitApp)
  2662. return
  2663. end
  2664. else
  2665. loadSite(website)
  2666. end
  2667. end
  2668.  
  2669. -- Wait
  2670. os.pullEvent(event_exitWebsite)
  2671. os.pullEvent(event_loadWebsite)
  2672. end
  2673. end
  2674.  
  2675.  
  2676. -- -------- Address Bar
  2677.  
  2678. local function retrieveSearchResults()
  2679. curSites = curProtocol.getSearchResults("")
  2680. while true do
  2681. local e = os.pullEvent()
  2682. if website ~= "exit" and e == event_loadWebsite then
  2683. curSites = curProtocol.getSearchResults("")
  2684. elseif e == event_exitApp then
  2685. os.queueEvent(event_exitApp)
  2686. return
  2687. end
  2688. end
  2689. end
  2690.  
  2691. local function addressBarRead()
  2692. local len = 4
  2693. local list = {}
  2694.  
  2695. local function draw(l)
  2696. local ox, oy = term.getCursorPos()
  2697. for i = 1, len do
  2698. term.setTextColor(colors[theme["address-bar-text"]])
  2699. term.setBackgroundColor(colors[theme["address-bar-background"]])
  2700. term.setCursorPos(1, i + 1)
  2701. write(string.rep(" ", w))
  2702. end
  2703. if theme["address-bar-base"] then term.setBackgroundColor(colors[theme["address-bar-base"]])
  2704. else term.setBackgroundColor(colors[theme["bottom-box"]]) end
  2705. term.setCursorPos(1, len + 2)
  2706. write(string.rep(" ", w))
  2707. term.setBackgroundColor(colors[theme["address-bar-background"]])
  2708.  
  2709. for i, v in ipairs(l) do
  2710. term.setCursorPos(2, i + 1)
  2711. write(v)
  2712. end
  2713. term.setCursorPos(ox, oy)
  2714. end
  2715.  
  2716. local function onLiveUpdate(cur, e, but, x, y, p4, p5)
  2717. if e == "char" or e == "update_history" or e == "delete" then
  2718. list = {}
  2719. for _, v in pairs(curSites) do
  2720. if #list < len and v:gsub("rdnt://", ""):find(cur:lower(), 1, true) then
  2721. table.insert(list, v)
  2722. end
  2723. end
  2724. table.sort(list)
  2725. table.sort(list, function(a, b)
  2726. local _, ac = a:gsub("rdnt://", ""):gsub(cur:lower(), "")
  2727. local _, bc = b:gsub("rdnt://", ""):gsub(cur:lower(), "")
  2728. return ac > bc
  2729. end)
  2730. draw(list)
  2731. return false, nil
  2732. elseif e == "mouse_click" then
  2733. for i = 1, len do
  2734. if y == i + 1 then
  2735. return true, list[i]:gsub("rdnt://", "")
  2736. end
  2737. end
  2738. end
  2739. end
  2740.  
  2741. onLiveUpdate("", "delete", nil, nil, nil, nil, nil)
  2742. return modRead(nil, addressBarHistory, 41, false, onLiveUpdate)
  2743. end
  2744.  
  2745. local function addressBarMain()
  2746. while true do
  2747. local e, but, x, y = os.pullEvent()
  2748. if (e == "key" and (but == 29 or but == 157)) or
  2749. (e == "mouse_click" and y == 1) then
  2750. if openAddressBar then
  2751. -- Exit
  2752. os.queueEvent(event_exitWebsite)
  2753.  
  2754. -- Read
  2755. term.setBackgroundColor(colors[theme["address-bar-background"]])
  2756. term.setTextColor(colors[theme["address-bar-text"]])
  2757. term.setCursorPos(2, 1)
  2758. term.clearLine()
  2759. write("rdnt://")
  2760. local oldWebsite = website
  2761. website = addressBarRead()
  2762. if website == nil then
  2763. website = oldWebsite
  2764. elseif website == "home" or website == "homepage" then
  2765. website = homepage
  2766. end
  2767.  
  2768. -- Load
  2769. os.queueEvent(event_loadWebsite)
  2770. end
  2771. elseif e == event_redirect then
  2772. if openAddressBar then
  2773. -- Redirect
  2774. os.queueEvent(event_exitWebsite)
  2775. if but == "home" or but == "homepage" then website = homepage
  2776. else website = but end
  2777. os.queueEvent(event_loadWebsite)
  2778. end
  2779. elseif e == event_exitApp then
  2780. os.queueEvent(event_exitApp)
  2781. break
  2782. end
  2783. end
  2784. end
  2785.  
  2786.  
  2787. -- -------- Main
  2788.  
  2789. -- centerPrint([[ ______ ____ ____ ______ ]])
  2790. -- centerPrint([[ ------- / ____// _// __ \ / ____/ ]])
  2791. -- centerPrint([[ ------ / /_ / / / /_/ // __/ ]])
  2792. -- centerPrint([[ ----- / __/ _/ / / _ _// /___ ]])
  2793. -- centerPrint([[ ---- / / /___//_/ |_|/_____/ ]])
  2794. -- centerPrint([[ --- / / _ __ ____ __ ______ ]])
  2795. -- centerPrint([[ -- /_/ | | / // __ \ / / / ____/ ]])
  2796. -- centerPrint([[ | | /| / // / / // / / /_ ]])
  2797. -- centerPrint([[ | |/ |/ // /_/ // /___ / __/ ]])
  2798. -- centerPrint([[ |__/|__/ \____//_____//_/ ]])
  2799.  
  2800. local function main()
  2801. -- Logo
  2802. term.setBackgroundColor(colors[theme["background"]])
  2803. term.setTextColor(colors[theme["text-color"]])
  2804. term.clear()
  2805. term.setCursorPos(1, 2)
  2806. term.setBackgroundColor(colors[theme["top-box"]])
  2807. centerPrint(string.rep(" ", 47))
  2808. centerPrint([[ _...._ ]])
  2809. centerPrint([[ .::o:::::. ]])
  2810. centerPrint([[ .:::'''':o:. ]])
  2811. centerPrint([[ :o:_ _::: ]])
  2812. centerPrint([[ `:(_>()<_):' ]])
  2813. centerPrint([[ `'//\\'' ]])
  2814. centerPrint([[ // \\ ]])
  2815. centerPrint([[ /' '\ ]])
  2816. centerPrint([[ ]])
  2817. centerPrint([[ Merry Christmas! -The Firewolf Team ]])
  2818. centerPrint(string.rep(" ", 47))
  2819. print("\n")
  2820. term.setBackgroundColor(colors[theme["bottom-box"]])
  2821.  
  2822. -- Download Files
  2823. centerPrint(string.rep(" ", 47))
  2824. centerWrite(string.rep(" ", 47))
  2825. centerPrint("Downloading Required Files...")
  2826. centerWrite(string.rep(" ", 47))
  2827. migrateFilesystem()
  2828. resetFilesystem()
  2829.  
  2830. -- Download Databases
  2831. local x, y = term.getCursorPos()
  2832. term.setCursorPos(1, y - 1)
  2833. centerWrite(string.rep(" ", 47))
  2834. centerWrite("Downloading Databases...")
  2835. loadDatabases()
  2836.  
  2837. -- Load Settings
  2838. centerWrite(string.rep(" ", 47))
  2839. centerWrite("Loading Data...")
  2840. local f = io.open(settingsLocation, "r")
  2841. local a = textutils.unserialize(f:read("*l"))
  2842. autoupdate = a.auto
  2843. incognito = a.incog
  2844. homepage = a.home
  2845. curProtocol = protocols.rdnt
  2846. f:close()
  2847.  
  2848. -- Load history
  2849. local b = io.open(historyLocation, "r")
  2850. history = textutils.unserialize(b:read("*l"))
  2851. b:close()
  2852.  
  2853. -- Update
  2854. centerWrite(string.rep(" ", 47))
  2855. centerWrite("Checking For Updates...")
  2856. if autoupdate == "true" then updateClient() end
  2857.  
  2858. -- Modem
  2859. if not(errPages.checkForModem()) then return end
  2860. website = homepage
  2861.  
  2862. -- Run
  2863. parallel.waitForAll(websiteMain, addressBarMain, retrieveSearchResults)
  2864. end
  2865.  
  2866. local function startup()
  2867. -- HTTP API
  2868. if not(http) then
  2869. term.setTextColor(colors[theme["text-color"]])
  2870. term.setBackgroundColor(colors[theme["background"]])
  2871. term.clear()
  2872. term.setCursorPos(1, 2)
  2873. term.setBackgroundColor(colors[theme["top-box"]])
  2874. api.centerPrint(string.rep(" ", 47))
  2875. api.centerWrite(string.rep(" ", 47))
  2876. api.centerPrint("HTTP API Not Enabled! D:")
  2877. api.centerPrint(string.rep(" ", 47))
  2878. print("")
  2879.  
  2880. term.setBackgroundColor(colors[theme["bottom-box"]])
  2881. api.centerPrint(string.rep(" ", 47))
  2882. api.centerPrint(" Firewolf is unable to run without the HTTP ")
  2883. api.centerPrint(" API Enabled! Please enable it in the CC ")
  2884. api.centerPrint(" Config! ")
  2885. api.centerPrint(string.rep(" ", 47))
  2886.  
  2887. api.centerPrint(string.rep(" ", 47))
  2888. api.centerWrite(string.rep(" ", 47))
  2889. if term.isColor() then api.centerPrint("Click to exit...")
  2890. else api.centerPrint("Press any key to exit...") end
  2891. api.centerPrint(string.rep(" ", 47))
  2892.  
  2893. while true do
  2894. local e, but, x, y = os.pullEvent()
  2895. if e == "mouse_click" or e == "key" then break end
  2896. end
  2897.  
  2898. return false
  2899. end
  2900.  
  2901. -- Turtle
  2902. if turtle then
  2903. term.clear()
  2904. term.setCursorPos(1, 2)
  2905. api.centerPrint("Advanced Comptuer Required!")
  2906. print("\n")
  2907. api.centerPrint("This version of Firewolf requires")
  2908. api.centerPrint("an Advanced Comptuer to run!")
  2909. print("")
  2910. api.centerPrint("Turtles may not be used to run")
  2911. api.centerPrint("Firewolf! :(")
  2912. print("")
  2913. api.centerPrint("Press any key to exit...")
  2914.  
  2915. os.pullEvent("key")
  2916. return false
  2917. end
  2918.  
  2919. -- Run
  2920. local _, err = pcall(main)
  2921. if err ~= nil then
  2922. term.setTextColor(colors[theme["text-color"]])
  2923. term.setBackgroundColor(colors[theme["background"]])
  2924. term.clear()
  2925. term.setCursorPos(1, 2)
  2926. term.setBackgroundColor(colors[theme["top-box"]])
  2927. api.centerPrint(string.rep(" ", 47))
  2928. api.centerWrite(string.rep(" ", 47))
  2929. api.centerPrint("Firewolf has Crashed! D:")
  2930. api.centerPrint(string.rep(" ", 47))
  2931. print("")
  2932. term.setBackgroundColor(colors[theme["background"]])
  2933. print("")
  2934. print(" " .. err)
  2935. print("")
  2936.  
  2937. term.setBackgroundColor(colors[theme["bottom-box"]])
  2938. api.centerPrint(string.rep(" ", 47))
  2939. api.centerPrint(" Please report this error to 1lann or ")
  2940. api.centerPrint(" GravityScore so we are able to fix it! ")
  2941. api.centerPrint(" If this problem persists, try deleting ")
  2942. api.centerPrint(" " .. rootFolder .. " ")
  2943. api.centerPrint(string.rep(" ", 47))
  2944. api.centerWrite(string.rep(" ", 47))
  2945. if term.isColor() then api.centerPrint("Click to exit...")
  2946. else api.centerPrint("Press any key to exit...") end
  2947. api.centerPrint(string.rep(" ", 47))
  2948.  
  2949. while true do
  2950. local e, but, x, y = os.pullEvent()
  2951. if e == "mouse_click" or e == "key" then break end
  2952. end
  2953.  
  2954. return false
  2955. end
  2956.  
  2957. return true
  2958. end
  2959.  
  2960. -- Theme
  2961. if not(term.isColor()) then
  2962. theme = originalTheme
  2963. else
  2964. theme = loadTheme(themeLocation)
  2965. if theme == nil then theme = defaultTheme end
  2966. end
  2967.  
  2968. -- Debugging
  2969. if #tArgs > 0 and tArgs[1] == "debug" then
  2970. term.setTextColor(colors[theme["text-color"]])
  2971. term.setBackgroundColor(colors[theme["background"]])
  2972. term.clear()
  2973. term.setCursorPos(1, 4)
  2974. api.centerPrint(string.rep(" ", 43))
  2975. api.centerWrite(string.rep(" ", 43))
  2976. api.centerPrint("Debug Mode Enabled...")
  2977. api.centerPrint(string.rep(" ", 43))
  2978.  
  2979. if fs.exists("/firewolf-log") then debugFile = io.open("/firewolf-log", "a")
  2980. else debugFile = io.open("/firewolf-log", "w") end
  2981. debugFile:write("\n-- [" .. textutils.formatTime(os.time()) .. "] New Log --")
  2982. sleep(1.8)
  2983. end
  2984.  
  2985. -- Start
  2986. startup()
  2987.  
  2988. -- Exit Message
  2989. if term.isColor() then
  2990. term.setBackgroundColor(colors.black)
  2991. term.setTextColor(colors.white)
  2992. end
  2993. term.setCursorBlink(false)
  2994. term.clear()
  2995.  
  2996. if not(fs.exists("/.var/settings")) then
  2997. term.setCursorPos(1, 1)
  2998. api.centerPrint("Thank You for Using Firewolf " .. version)
  2999. api.centerPrint("Made by 1lann and GravityScore")
  3000. term.setCursorPos(1, 3)
  3001. else
  3002. term.setBackgroundColor(colors[theme["background"]])
  3003. term.setTextColor(colors[theme["text-color"]])
  3004. term.clear()
  3005. term.setCursorPos(1, 5)
  3006. term.setBackgroundColor(colors[theme["top-box"]])
  3007. print("")
  3008. api.centerPrint("Thank You for Using Firewolf " .. version)
  3009. api.centerPrint("Made by 1lann and GravityScore")
  3010. print("")
  3011. if term.isColor() then api.centerPrint("Click to exit...")
  3012. else api.centerPrint("Press any key to exit...") end
  3013.  
  3014. while true do
  3015. local e = os.pullEvent()
  3016. if e == "mouse_click" or e == "key" then break end
  3017. end
  3018. end
  3019.  
  3020. -- Close
  3021. for _, v in pairs(rs.getSides()) do rednet.close(v) end
  3022. if debugFile then debugFile:close() end
  3023.  
  3024. -- Reset Environment
  3025. setfenv(1, oldEnv)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement