· 6 years ago · Feb 08, 2020, 03:08 PM
1-- -------- Mozilla Firefox
2-- -------- Made by GravityScore and 1lann
3
4-- -------- Original Idea from Rednet Explorer v2.4.1
5-- -------- Rednet Explorer made by xXm0dzXx/CCFan11
6
7
8-- -------- Ideas:
9-- - Multiple servers running simultaneously
10
11
12-- -------- To Do:
13-- - Search to support blacklist/whitelist/antivirus/verified
14-- - Do not delete old-startup, but rename old-startup1, old-startup2 ...
15-- - Control-T to return to home
16
17
18-- -------- Constants
19
20-- Version
21local firefoxVersion = "1.4.0"
22local browserAgentTemplate = "Mozilla Firefox " .. firefoxVersion
23browserAgent = ""
24
25-- Server Identification
26local serverID = "ctcraft"
27local serverList = {ccnet = "CCServers", immibis = "turtle.dig()", ctcraft = "CTCraft",
28 noodle = "Noodle", ["firefox-14"] = "Experimental"}
29
30-- Updating
31local override = false
32local autoupdate = "false"
33local incognito = "false"
34local debugging = false
35
36-- Dropbox URLs
37local firefoxURL = "http://dl.dropbox.com/u/97263369/" .. serverID .. "/firefox-stable.lua"
38local databaseURL = "http://dl.dropbox.com/u/97263369/" .. serverID .. "/firefox-database.txt"
39local serverURL = "http://dl.dropbox.com/u/97263369/" .. serverID .. "/firefox-server.lua"
40local customEditURL = "http://dl.dropbox.com/u/97263369/" .. serverID .. "/custom-edit.lua"
41
42-- Events
43local openURLBarEvent = "firefox_open_url_bar_event"
44local websiteLoadEvent = "firefox_website_loaded_event"
45
46-- Webpage Variables
47local website = ""
48local homepage = ""
49local history = {}
50local searchBarHistory = {}
51local exitApp = false
52
53-- Prevent API Overrides
54local function copyTable(oldTable)
55 local newTable = {}
56 for k,v in pairs(oldTable) do
57 newTable[k] = v
58 end
59 return newTable
60end
61
62local fparallel = copyTable(parallel)
63local fstring = copyTable(string)
64local frednet = copyTable(rednet)
65local ftable = copyTable(table)
66local fhttp = copyTable(http)
67local ftextutils = copyTable(textutils)
68local fos = copyTable(os)
69local fterm = copyTable(term)
70local fshell = copyTable(shell)
71local ffs = copyTable(fs)
72local fio = copyTable(io)
73local ftostring = tostring
74local ftonumber = tonumber
75local fpcall = pcall
76local fperipheral = copyTable(peripheral)
77local fsleep = sleep
78local fprint = print
79local fwrite = write
80
81-- Data Locations
82local rootFolder = "/.Firefox_Data"
83local cacheFolder = rootFolder .. "/cache"
84local serverFolder = rootFolder .. "/servers"
85local serverSoftwareLocation = rootFolder .. "/server_software"
86local customEditLocation = rootFolder .. "/custom_edit"
87local settingsLocation = rootFolder .. "/settings"
88local historyLocation = rootFolder .. "/history"
89local firefoxLocation = "/" .. fshell.getRunningProgram()
90
91local userBlacklist = rootFolder .. "/user_blacklist"
92local userWhitelist = rootFolder .. "/user_whitelist"
93local globalDatabase = rootFolder .. "/database"
94
95-- Firefox 1.3 Support
96local runningWebsite = ""
97
98
99-- -------- Prompt Software
100
101function prompt(list, dir, startCurSel, notControl)
102 -- Functions
103 local function drawArrows(word, x, y)
104 fterm.setCursorPos(x, y)
105 fwrite("[")
106 fterm.setCursorPos(x + 1 + fstring.len(word), y)
107 fwrite("]")
108 end
109
110 local function removeArrows(word, x, y)
111 fterm.setCursorPos(x, y)
112 fwrite(" ")
113 fterm.setCursorPos(x + 1 + fstring.len(word), y)
114 fwrite(" ")
115 end
116
117 -- Variables
118 local curSel = 1
119 if startCurSel ~= nil then
120 curSel = startCurSel
121 end
122 local nc = false
123 if notControl == true then nc = true end
124 local c1 = 200
125 local c2 = 208
126 if dir == "horizontal" then c1 = 203 c2 = 205 end
127
128 -- Draw
129 for i = 1, #list do
130 if list[i][2] == -1 then
131 local w, h = fterm.getSize()
132 list[i][2] = math.floor(w/2 - list[i][1]:len()/2)
133 end
134 fterm.setCursorPos(list[i][2], list[i][3])
135 fwrite(list[i][1])
136 end
137 drawArrows(list[curSel][1], list[curSel][2] - 1, list[curSel][3])
138
139 -- Selection
140 while not(exitApp) do
141 local event, key = fos.pullEvent("key")
142 removeArrows(list[curSel][1], list[curSel][2] - 1, list[curSel][3])
143 if key == c1 then
144 if curSel ~= 1 then curSel = curSel - 1 end
145 elseif key == c2 then
146 if curSel ~= #list then curSel = curSel + 1 end
147 elseif key == 28 then
148 return list[curSel][1]
149 elseif key == 29 or key == 157 then
150 if not(nc) then
151 fos.queueEvent(openURLBarEvent)
152 return nil
153 end
154 end
155 drawArrows(list[curSel][1], list[curSel][2] - 1, list[curSel][3])
156 end
157end
158
159function scrollingPrompt(list, disLen, xStart, yStart)
160 -- Functions
161 local function drawItems(items)
162 for i = 1, #items do
163 fterm.setCursorPos(xStart, i + yStart)
164 fterm.clearLine(i + 4)
165 fwrite("[ ] " .. items[i])
166 end
167 end
168
169 local function updateDisplayList(items, disLoc, disLen)
170 local ret = {}
171 for i = 1, disLen do
172 local item = items[i + disLoc - 1]
173 if item ~= nil then ftable.insert(ret, item) end
174 end
175 return ret
176 end
177
178 local function drawArrows(word, x, y)
179 fterm.setCursorPos(x + 1, y)
180 fwrite("x")
181 end
182
183 local function removeArrows(word, x, y)
184 fterm.setCursorPos(x + 1, y)
185 fwrite(" ")
186 end
187
188 -- Variables
189 local disLoc = 1
190 local disList = updateDisplayList(list, 1, disLen)
191 local curSel = 1
192 drawItems(disList)
193 drawArrows(list[1], xStart, yStart + 1)
194
195 -- Selection
196 while true do
197 local event, key = fos.pullEvent("key")
198 removeArrows(list[curSel + disLoc - 1], xStart, curSel + yStart)
199 if key == 200 then
200 if curSel ~= 1 then
201 curSel = curSel - 1
202 else
203 if disLoc ~= 1 then
204 disLoc = disLoc - 1
205 disList = updateDisplayList(list, disLoc, disLen)
206 drawItems(disList)
207 end
208 end
209 elseif key == 208 then
210 if curSel ~= #disList then
211 curSel = curSel + 1
212 else
213 if disLoc + curSel - 1 ~= #list then
214 disLoc = disLoc + 1
215 disList = updateDisplayList(list, disLoc, disLen)
216 drawItems(disList)
217 end
218 end
219 elseif key == 28 then
220 return list[curSel + disLoc - 1], false
221 elseif key == 29 or key == 157 then
222 fos.queueEvent(openURLBarEvent)
223 return "", true
224 end
225 drawArrows(list[curSel + disLoc - 1], xStart, curSel + yStart)
226 end
227end
228
229
230-- -------- Drawing Utilities
231
232local function titleForPage(site)
233 -- Preset titles
234 local siteTitles = {{"firefox", "Mozilla Firefox"}, {"update", "Update Firefox"},
235 {"upgrade", "Update Firefox"}, {"search", "Firefox Serach"},
236 {"history", "Firefox History"}, {"server", "Server Management"},
237 {"settings", "Firefox Settings"}, {"credits", "Firefox Credits"},
238 {"whatsnew", "What's New"}, {"exit", nil}, {"", "All Sites"}}
239
240 -- Search
241 for i = 1, #siteTitles do
242 if fstring.lower(siteTitles[i][1]) == fstring.lower(site) then
243 return siteTitles[i][2]
244 end
245 end
246
247 return nil
248end
249
250function clearPage(url)
251 -- URL
252 local w, h = fterm.getSize()
253 local title = titleForPage(url)
254 fterm.clear()
255 fterm.setCursorPos(2, 1)
256 fwrite("rdnt://" .. url)
257
258 -- Title
259 if title ~= nil then
260 fterm.setCursorPos(w - fstring.len(" " .. title), 1)
261 fwrite(" " .. title)
262 end
263
264 -- Line
265 fterm.setCursorPos(1, 1)
266 fwrite(fstring.rep("-", w))
267 fprint(" ")
268end
269
270function centerPrint(text)
271 local w, h = fterm.getSize()
272 local x, y = fterm.getCursorPos()
273 fterm.setCursorPos(math.ceil((w + 1)/2 - text:len()/2), y)
274 fprint(text)
275end
276
277local function centerWrite(text)
278 local w, h = fterm.getSize()
279 local x, y = fterm.getCursorPos()
280 fterm.setCursorPos(math.ceil((w + 1)/2 - text:len()/2), y)
281 fwrite(text)
282end
283
284function leftPrint(text)
285 local x, y = fterm.getCursorPos()
286 fterm.setCursorPos(4, y)
287 fwrite(text)
288end
289
290function rightPrint(text)
291 local x, y = fterm.getCursorPos()
292 local w, h = fterm.getSize()
293 fterm.setCursorPos(w - text:len() - 1, y)
294 fwrite(text)
295end
296
297
298-- -------- Filesystem Management
299
300local function getDropbox(url, file)
301 fsleep(0.01)
302 while not(exitApp) do
303 -- Request
304 fhttp.request(url)
305 fsleep(0.0000000001)
306 while not(exitApp) do
307 local event, _, response = fos.pullEvent()
308 if event == "http_failure" then
309 break
310 elseif event == "http_success" then
311 if response ~= nil then
312 -- Put into file
313 local text = response:readAll()
314 local f = fio.open(file, "w")
315 fsleep(0.01)
316 f:write(text)
317 fsleep(0.01)
318 f:close()
319 response:close()
320 return "true"
321 else
322 return "false"
323 end
324 end
325 end
326 end
327end
328
329local function upgradeFilesystem()
330 if fs.exists("/.FirefoxData") then
331 -- Shift
332 fs.delete("/.temp_whitelist")
333 if fs.exists("/.FirefoxData/firefox_whitelist") then
334 fs.move("/.FirefoxData/firefox_whitelist", "/.temp_whitelist")
335 end
336 fs.delete("/.temp_blacklist")
337 if fs.exists("/.FirefoxData/firefox_blacklist") then
338 fs.move("/.FirefoxData/firefox_blacklist", "/.temp_blacklist")
339 end
340 fs.delete("/.temp_server_prefs")
341 if fs.exists("/.FirefoxData/fireServerPref") then
342 fs.move("/.FirefoxData/fireServerPref", "/.temp_server_prefs")
343 end
344
345 -- Delete
346 fs.delete("/.FirefoxData")
347 fs.makeDir(rootFolder)
348 fs.makeDir(serverFolder)
349
350 -- Move
351 if fs.exists("/.temp_whitelist") then
352 if fs.exists(userWhitelist) then fs.delete(userWhitelist) end
353 fs.move("/.temp_whitelist", userWhitelist)
354 end
355 if fs.exists("/.temp_blacklist") then
356 if fs.exists(userBlacklist) then fs.delete(userBlacklist) end
357 fs.move("/.temp_blacklist", userBlacklist)
358 end
359 if fs.exists("/.temp_server_prefs") then
360 local f = fio.open("/.temp_server_prefs", "r")
361 local serverName = f:read("*l")
362 f:close()
363 if fs.exists("/" .. serverName) and fs.isDir("/" .. serverName) then
364 fs.move("/" .. serverName, serverFolder .. "/" .. serverName)
365 end
366 end
367 end
368end
369
370local function resetFilesystem()
371 -- Folders
372 if not(fs.exists(rootFolder)) then
373 fs.makeDir(rootFolder)
374 elseif not(fs.isDir(rootFolder)) then
375 fs.move(rootFolder, "/Old_Firefox_Data_File")
376 fs.makeDir(rootFolder)
377 end
378 if not(fs.exists(cacheFolder)) then fs.makeDir(cacheFolder) end
379 if not(fs.exists(serverFolder)) then fs.makeDir(serverFolder) end
380
381 -- Settings
382 if not(fs.exists(settingsLocation)) then
383 local f = fio.open(settingsLocation, "w")
384 f:write(textutils.serialize({auto = "true", incog = "false", home = "firefox"}))
385 f:close()
386 end
387
388 -- Server software
389 if not(fs.exists(serverSoftwareLocation)) then
390 getDropbox(serverURL, serverSoftwareLocation)
391 end
392
393 -- Custom Edit
394 if not(fs.exists(customEditLocation)) then
395 getDropbox(customEditURL, customEditLocation)
396 end
397
398 -- History
399 if not(fs.exists(historyLocation)) then
400 local f = fio.open(historyLocation, "w")
401 f:write(textutils.serialize({}))
402 f:close()
403 end
404
405 -- Databases
406 fs.delete(globalDatabase)
407 for _, v in ipairs({globalDatabase, userWhitelist, userBlacklist}) do
408 if not(fs.exists(v)) then
409 local f = fio.open(v, "w")
410 f:write("")
411 f:close()
412 end
413 end
414end
415
416
417-- -------- Updating Utilities
418
419local function updateClient()
420 local updateLocation = rootFolder .. "/firefox-update"
421
422 -- Get files and contents
423 getDropbox(firefoxURL, updateLocation)
424 local f1 = fio.open(updateLocation, "r")
425 local f2 = fio.open(firefoxLocation, "r")
426 local update = f1:read("*a")
427 local current = f2:read("*a")
428 f1:close()
429 f2:close()
430
431 -- Update
432 if current ~= update then
433 fs.delete(firefoxLocation)
434 fs.move(updateLocation, firefoxLocation)
435 fshell.run(firefoxLocation)
436 error()
437 else
438 fs.delete(updateLocation)
439 end
440end
441
442local function appendToHistory(item)
443 if incognito == "false" then
444 -- Clean up item
445 local a = item:gsub("^%s*(.-)%s*$", "%1"):lower()
446 if a == "home" then
447 a = homepage
448 end
449
450 -- Append to overall history
451 if a ~= "exit" and a ~= "history" and history[1] ~= a then
452 ftable.insert(history, 1, a)
453 local f = fio.open(historyLocation, "w")
454 f:write(textutils.serialize(history))
455 f:close()
456 end
457
458 -- Append to search bar history
459 if searchBarHistory[#searchBarHistory] ~= a then
460 ftable.insert(searchBarHistory, a)
461 end
462 end
463end
464
465
466------ Website Verification
467
468local blacklistDatabase = {}
469local whitelistDatabase = {}
470local verifiedDatabase = {}
471local antivirusDefinitions = {}
472
473local function reloadDatabases()
474 -- Get
475 getDropbox(databaseURL, globalDatabase)
476 local f = fio.open(globalDatabase, "r")
477
478 -- Blacklist
479 blacklistDatabase = {}
480 local l = f:read("*l")
481 while l ~= "START-WHITELIST" do
482 l = f:read("*l")
483 if l ~= nil and l ~= "" and l ~= "\n" and l ~= "START-BLACKLIST" and
484 l ~= "START-WHITELIST" then
485 l = l:gsub("^%s*(.-)%s*$", "%1"):lower()
486 ftable.insert(blacklistDatabase, l)
487 end
488 end
489
490 -- Whitelist
491 whitelistDatabase = {}
492 l = ""
493 while l ~= "START-VERIFIED" do
494 l = f:read("*l")
495 if l ~= nil and l ~= "" and l ~= "\n" and l ~= "START-VERIFIED" and
496 l ~= "START-WHITELIST" and l:find("| |") then
497 l = l:gsub("^%s*(.-)%s*$", "%1"):lower()
498 local a, b = l:find("| |")
499 local n = l:sub(1, a - 1)
500 local id = l:sub(b + 1, -1)
501 ftable.insert(whitelistDatabase, {n, id})
502 end
503 end
504
505 -- Verified
506 verifiedDatabase = {}
507 l = ""
508 while l ~= "START-DEFINITIONS" do
509 l = f:read("*l")
510 if l ~= nil and l ~= "" and l ~= "\n" and l ~= "START-VERIFIED" and
511 l ~= "START-DEFINITIONS" and l:find("| |") then
512 l = l:gsub("^%s*(.-)%s*$", "%1"):lower()
513 local a, b = l:find("| |")
514 local n = l:sub(1, a - 1)
515 local id = l:sub(b + 1, -1)
516 ftable.insert(verifiedDatabase, {n, id})
517 end
518 end
519
520 -- Definitions
521 antivirusDefinitions = {}
522 l = ""
523 while l ~= "END-DATABASE" do
524 l = f:read("*l")
525 if l ~= nil and l ~= "" and l ~= "\n" and l ~= "START-VERIFIED" and
526 l ~= "END-DATABASE" then
527 l = l:gsub("^%s*(.-)%s*$", "%1")
528 ftable.insert(antivirusDefinitions, l)
529 end
530 end
531
532 f:close()
533
534 -- User Blacklist
535 if not(fs.exists(userBlacklist)) then
536 local bf = fio.open(userBlacklist, "w")
537 bf:write("\n")
538 bf:close()
539 else
540 local f = fio.open(userBlacklist, "r")
541 for line in f:lines() do
542 if line ~= nil and line ~= "" and line ~= "\n" then
543 ftable.insert(blacklistDatabase, line:gsub("^%s*(.-)%s*$", "%1"):lower())
544 end
545 end
546 f:close()
547 end
548
549 -- User Whitelist
550 if not(fs.exists(userWhitelist)) then
551 local f = fio.open(userWhitelist, "w")
552 f:write("\n")
553 f:close()
554 else
555 local switch = "url"
556 local f = fio.open(userWhitelist, "r")
557
558 for l in f:lines() do
559 if l ~= nil and l ~= "" and l ~= "\n" then
560 l = l:gsub("^%s*(.-)%s*$", "%1"):lower()
561 local a, b = l:find("| |")
562 local n = l:sub(1, a - 1)
563 local id = l:sub(b + 1, -1)
564 ftable.insert(whitelistDatabase, {n, id})
565 end
566 end
567
568 f:close()
569 end
570end
571
572local function verifyAgainstWhitelist(site, id)
573 for i = 1, #whitelistDatabase do
574 if whitelistDatabase[i][1] == site and whitelistDatabase[i][2] == ftostring(id) then
575 return true
576 end
577 end
578
579 return false
580end
581
582local function verifyAgainstVerified(site, id)
583 for i = 1, #verifiedDatabase do
584 if verifiedDatabase[i][1] == site and verifiedDatabase[i][2] == ftostring(id) then
585 return true
586 end
587 end
588
589 return false
590end
591
592local function verifyAgainstBlacklist(id)
593 for i = 1, #blacklistDatabase do
594 if blacklistDatabase[i] == ftostring(id) then
595 return true
596 end
597 end
598
599 return false
600end
601
602local function verifyAgainstAntivirus(checkData)
603 local a = checkData
604 a = a:gsub(" ", ""):gsub("\n", ""):gsub("\t", "")
605 for i = 1, #antivirusDefinitions do
606 local b = antivirusDefinitions[i]
607 if b ~= "" and b ~= "\n" and b ~= nil then
608 if fstring.find(a, b, 1, true) then
609 return true
610 end
611 end
612 end
613
614 return false
615end
616
617local function blacklistRedirectionBots()
618 local suspected = {}
619 for i = 1, 5 do
620 local alphabet = {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n",
621 "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "."}
622 local name = ""
623 for i = 1, math.random(6, 17) do
624 name = name .. alphabet[math.random(1, 27)]
625 end
626 frednet.broadcast(name)
627
628 clock = fos.clock()
629 while fos.clock() - clock < 0.01 do
630 local id = frednet.receive(0.01)
631 if id ~= nil and verifyAgainstBlacklist(id) == false then
632 local inSuspected = false
633 for i = 1, #suspected do
634 if suspected[i][1] == id then
635 suspected[i][2] = suspected[i][2] + 1
636 inSuspected = true
637 end
638 end
639
640 if not(inSuspected) then
641 ftable.insert(suspected, {id, 1})
642 break
643 end
644 end
645 end
646 end
647
648 for i = 1, #suspected do
649 if suspected[i][2] > 2 then
650 local f = fio.open(userBlacklist, "a")
651 f:write(ftostring(suspected[i][1]) .. "\n")
652 f:close()
653
654 ftable.insert(blacklistDatabase, suspected[i][1])
655 end
656 end
657end
658
659local function updateDatabases()
660 while not(exitApp) do
661 fos.pullEvent(websiteLoadEvent)
662 reloadDatabases()
663 end
664end
665
666
667-- -------- Built-In Websites
668
669local function webpageHome(site)
670 -- Title
671 local w, h = fterm.getSize()
672 fprint("\n")
673 centerPrint(" _,-='\"-.__ /\\_/\\ ")
674 centerPrint(" -.} =._,.-==-._., @ @._,")
675 centerPrint(" -.__ __,-. ) _,.-' ")
676 centerPrint(" \" G..m-\"^m m' ")
677 fprint(" ")
678 leftPrint(" Welcome to Mozilla Firefox " .. firefoxVersion)
679
680 -- Useful websites
681 fterm.setCursorPos(1, 13)
682 leftPrint(" rdnt://firefox")
683 rightPrint("Welcome Page \n")
684 leftPrint(" rdnt://search")
685 rightPrint("Search \n")
686 leftPrint(" rdnt://history")
687 rightPrint("History \n")
688 leftPrint(" rdnt://credits")
689 rightPrint("Credits \n")
690 leftPrint(" rdnt://exit")
691 rightPrint("Exit \n")
692end
693
694local function webpageSearch(site)
695 -- Title and input
696 centerPrint("Firefox Search Engine")
697 fprint("\n")
698 centerPrint("Enter 'firefox' to View Built-In Sites")
699 fprint(" ")
700 leftPrint("Search: ")
701 local input = read():gsub("^%s*(.-)%s*$", "%1"):lower()
702
703 -- Organise results
704 local results = {}
705 if input == "firefox" then
706 results = {"firefox", "update", "search",
707 "whatsnew", "history", "settings",
708 "server", "credits", "exit"}
709 end
710
711 -- Get items
712 frednet.broadcast("frednet.api.ping.searchengine")
713 while not(exitApp) do
714 local _, i = frednet.receive(0)
715 if i then
716 if input == "" then
717 ftable.insert(results, i)
718 else
719 if fstring.find(i, input) then
720 ftable.insert(results, i)
721 end
722 end
723 else
724 break
725 end
726 end
727
728 -- Draw
729 clearPage(site)
730 centerPrint("Firefox Search Engine")
731 if #results ~= 0 then
732 -- Organise
733 local nResults = {}
734 for i = 1, #results do
735 ftable.insert(nResults, "rdnt://" .. results[i]:gsub("^%s*(.-)%s*$", "%1"):lower())
736 end
737
738 -- Prompt and redirect
739 local ssite, ex = scrollingPrompt(nResults, 14, 4, 4)
740 if not(ex) then
741 redirect(ssite:gsub("rdnt://", ""))
742 end
743 else
744 -- No items
745 fprint("\n")
746 centerPrint("No Search Results Found")
747 end
748end
749
750local function webpageHistory(site)
751 -- Title
752 centerPrint("Firefox History")
753
754 if #history ~= 0 then
755 -- Organise
756 local nHistory = {"Clear History"}
757 for i = 1, #history do
758 ftable.insert(nHistory, "rdnt://" .. history[i])
759 end
760
761 -- Prompt
762 local web, ex = scrollingPrompt(nHistory, 14, 4, 4)
763 if not(ex) then
764 if web == "Clear History" then
765 -- Reset history
766 history = {}
767 searchBarHistory = {}
768 local f = fio.open(historyLocation, "w")
769 f:write(textutils.serialize(history))
770 f:close()
771
772 -- Draw
773 clearPage(site)
774 centerPrint("Firefox History")
775 fprint("\n")
776 centerPrint("History Cleared")
777 fsleep(1.1)
778 redirect("history")
779 else
780 -- Redirect
781 redirect(web:gsub("rdnt://", ""))
782 end
783 end
784 else
785 -- No Items
786 fprint("\n")
787 centerPrint("No Items In History")
788 end
789end
790
791local function webpageUpdate(site)
792 -- Title
793 fprint("\n")
794 centerPrint("Firefox Force Update")
795
796 -- Prompt for update
797 local w, h = fterm.getSize()
798 local opt = prompt({{"Continue", math.floor(w/4 - fstring.len("Continue")/2), 10},
799 {"Cancel", math.ceil(w/4 - fstring.len("Cancel")/2 + w/2), 10}},
800 "horizontal")
801 if opt == "Continue" then
802 -- Clear
803 clearPage(site)
804 fprint("\n")
805 centerPrint("Firefox Force Update")
806 fprint("\n\n\n")
807
808 -- Update file
809 centerPrint("Updating Firefox...")
810 getDropbox(firefoxURL, "/.temp_firefox")
811 fsleep(0.2)
812
813 -- Draw
814 clearPage(site)
815 fprint("\n")
816 centerPrint("Firefox Force Update")
817 fprint("\n\n")
818 centerPrint("Firefox Has Been Updated")
819
820 -- Delete temp file
821 fs.delete(firefoxLocation)
822 fs.move("/.temp_firefox", firefoxLocation)
823 prompt({{"Exit Firefox", -1, 14}}, "vertical", 1, true)
824
825 -- Exit
826 redirect("exit")
827 elseif opt == "Cancel" then
828 -- Draw
829 clearPage(site)
830 fprint("\n")
831 centerPrint("Firefox Force Update")
832 fprint("\n\n\n")
833 centerPrint("Update Cancelled")
834 end
835end
836
837local function webpageNewSite(site)
838 centerPrint("Firefox Server Management")
839
840 local l = fs.list(serverFolder)
841 local s = {"New Server"}
842 for i = 1, #l do
843 if fs.isDir(serverFolder .. "/" .. l[i]) then
844 ftable.insert(s, l[i])
845 end
846 end
847 local server, ex = scrollingPrompt(s, 14, 4, 4)
848 if not(ex) then
849 if server == "New Server" then
850 -- Get URL
851 clearPage(site)
852 centerPrint("Firefox Server Management")
853 fprint("\n\n")
854 leftPrint("Server URL:\n")
855 leftPrint(" rdnt://")
856 local url = read():lower():gsub(" ", "")
857 fprint("\n")
858 if url ~= "" then
859 if url:find("/") then
860 leftPrint("Server URL Invalid\n")
861 leftPrint("Contains Illegal '/'\n")
862 fsleep(1.4)
863 elseif url:find("| |") then
864 leftPrint("Server URL Invalid\n")
865 leftPrint("Contains Illegal '| |'\n")
866 fsleep(1.4)
867 else
868 leftPrint("Creating Server: " .. url)
869 fsleep(0.35)
870
871 local serverLoc = serverFolder .. "/" .. url
872 fs.makeDir(serverLoc)
873 local homeF = fio.open(serverLoc .. "/home", "w")
874 homeF:write("fprint(\" \")\ncenterPrint(\"Welcome To " .. url .. "\")")
875 homeF:close()
876 end
877 else
878 leftPrint("Server URL Empty!")
879 leftPrint("Could Not Create Server")
880 end
881 redirect("server")
882 else
883 local redir = false
884 while not(exitApp) do
885 clearPage(site)
886 local serverPath = serverFolder .. "/" .. server
887 server = server:gsub("^%s*(.-)%s*$", "%1"):lower()
888 centerPrint("Firefox Server Management")
889 fprint(" ")
890 leftPrint("Server: " .. server)
891
892 local opt = prompt({{"Start Server", 5, 8}, {"Run On Startup", 5, 10},
893 {"Edit Pages", 5, 12}, {"Delete Server", 5, 14},
894 {"Back", 5, 16}}, "vertical")
895 if opt == "Start Server" then
896 fshell.run(serverSoftwareLocation, server, serverPath)
897 frednet.open("top")
898 redir = true
899 break
900 elseif opt == "Run On Startup" then
901 fs.delete("/old-startup")
902 if fs.exists("/startup") then fs.move("/startup", "/old-startup") end
903 local f = fio.open("/startup", "w")
904 f:write("fshell.run(\"" .. serverSoftwareLocation .. "\", \"" .. server ..
905 "\", \"" .. serverPath .. "\")")
906 f:close()
907
908 clearPage(site)
909 centerPrint("Firefox Server Management")
910 fprint("\n\n")
911 centerPrint("Server Will Run on Startup")
912 fsleep(0.9)
913 elseif opt == "Edit Pages" then
914 while not(exitApp) do
915 clearPage(site)
916 centerPrint("Firefox Server Management")
917 fprint(" ")
918 leftPrint("Server Pages:")
919
920 local pages = {"Back", "New...", "Rename...", "Copy File...", "Delete..."}
921 local a = fs.list(serverPath)
922 for i = 1, #a do
923 if fs.isDir(serverPath .. "/" .. a[i]) then
924 a[i] = "[Directory] " .. a[i]
925 end
926 ftable.insert(pages, a[i])
927 end
928
929 local page, ex = scrollingPrompt(pages, 12, 4, 6)
930 if not(ex) then
931 if page == "Back" then
932 break
933 elseif page == "New..." then
934 fterm.setCursorPos(1, 5)
935 fterm.clearLine()
936 local w, h = fterm.getSize()
937 local o = prompt({{"File", math.floor(w/4 -
938 fstring.len("File")/2), 5}, {"Folder",
939 math.ceil(w/4 - fstring.len("Folder")/2 + w/2), 5}}, "horizontal")
940 if o == nil then
941 return
942 end
943 fterm.setCursorPos(1, 5)
944 fterm.clearLine()
945 leftPrint("Name: ")
946 local name = read():gsub(" ", ""):lower()
947 if o == "File" then
948 local f = fio.open(serverPath .. "/" .. name, "w")
949 f:write(" ")
950 f:close()
951 elseif o == "Folder" then
952 fs.makeDir(serverPath .. "/" .. name)
953 end
954 elseif page == "Rename..." then
955 clearPage(site)
956 centerPrint("Firefox Server Management")
957 fprint(" ")
958 leftPrint("Select Page to Rename:")
959 local p = {"Cancel"}
960 for i = 1, #a do
961 if fs.isDir(serverPath .. "/" .. a[i]) then
962 a[i] = "[Directory] " .. a[i]
963 end
964 ftable.insert(p, a[i])
965 end
966
967 local a, ex = scrollingPrompt(p, 12, 4, 6)
968 if not(ex) then
969 if a ~= nil and a ~= "Cancel" then
970 fterm.setCursorPos(1, 5)
971 fterm.clearLine()
972 fterm.setCursorPos(1, 5)
973 leftPrint("New Name: ")
974 local name = read():gsub(" ", ""):lower()
975 a = a:gsub("[Directory] ", "")
976 fs.move(serverPath .. "/" .. a, serverPath .. "/" .. name)
977 end
978 else
979 return
980 end
981 elseif page == "Copy File..." then
982 fterm.setCursorPos(1, 5)
983 fterm.clearLine()
984 leftPrint("File To Copy: /")
985 local file = "/" .. read()
986 fterm.setCursorPos(1, 5)
987 fterm.clearLine()
988 if fs.exists(file) then
989 leftPrint("Name: ")
990 local na = read():gsub(" ", ""):lower()
991 if fs.exists(serverPath .. "/" .. na) then
992 fs.delete(serverPath .. "/" .. na)
993 end
994 fs.copy(file, serverPath .. "/" .. na)
995 else
996 leftPrint("File Does Not Exist!")
997 fsleep(1.1)
998 end
999 elseif page == "Delete..." then
1000 clearPage(site)
1001 centerPrint("Firefox Server Management")
1002 fprint(" ")
1003 leftPrint("Select Page to Delete:")
1004 local p = {"Cancel"}
1005 for i = 1, #a do
1006 if fs.isDir(serverPath .. "/" .. a[i]) then
1007 a[i] = "[Directory] " .. a[i]
1008 end
1009 ftable.insert(p, a[i])
1010 end
1011
1012 local a, ex = scrollingPrompt(p, 12, 4, 6)
1013 if not(ex) then
1014 if a ~= nil and a ~= "Cancel" then
1015 a = a:gsub("[Directory] ", "")
1016 fs.delete(serverPath .. "/" .. a)
1017 end
1018 else
1019 return
1020 end
1021 elseif page ~= nil and not(fs.isDir(serverPath .. "/" .. page)) then
1022 fterm.clear()
1023 fshell.run(customEditLocation, serverPath .. "/" .. page)
1024 end
1025 else
1026 return
1027 end
1028 end
1029 elseif opt == "Delete Server" then
1030 clearPage(site)
1031 centerPrint("Firefox Server Management")
1032 local w, h = fterm.getSize()
1033 local opt = prompt({{"Delete Server",
1034 math.floor(w/4 - fstring.len("Delete Server")/2), 9},
1035 {"Cancel", math.ceil(w/4 - fstring.len("Cancel")/2 + w/2),
1036 9}}, "horizontal")
1037 if opt == "Delete Server" then
1038 clearPage(site)
1039 centerPrint("Firefox Server Management")
1040 fprint("\n\n")
1041 centerPrint("Deleted Server")
1042 fsleep(1.1)
1043 fs.delete(serverPath)
1044 elseif opt == "Cancel" then
1045 clearPage(site)
1046 centerPrint("Firefox Server Management")
1047 fprint("\n\n")
1048 centerPrint("Cancelled Delete Operation")
1049 fsleep(1.1)
1050 end
1051 redir = true
1052 break
1053 elseif opt == "Back" then
1054 redir = true
1055 break
1056 elseif opt == nil then
1057 return
1058 end
1059 end
1060
1061 if redir then redirect("server") end
1062 end
1063 end
1064end
1065
1066local function webpageWhatsNew(site)
1067 -- Draw what's new
1068 fprint(" ")
1069 centerPrint("What's New in Firefox " .. firefoxVersion)
1070 fprint(" ")
1071 leftPrint("- Added Viewable History\n")
1072 leftPrint("- Added Incognito Mode\n")
1073 leftPrint("- Added Multiple Server Management\n")
1074 leftPrint("- Added Settings\n")
1075 leftPrint("- Added Reset Browser Button\n")
1076 leftPrint("- Added Customizable Homepage\n")
1077 leftPrint("- Added Auto-Search\n")
1078 leftPrint("- Re-Wrote Search Page\n")
1079 leftPrint("- Re-Designed Logo\n")
1080 leftPrint("- Removed Sites Page\n")
1081 leftPrint("- Removed Get ID Page \n")
1082 leftPrint("- Removed Refesh\n")
1083 leftPrint("- Added More Easter Eggs :D\n")
1084end
1085
1086local function webpageSettings(site)
1087 local selected = 1
1088 while not(exitApp) do
1089 -- Clear
1090 clearPage(site)
1091 centerPrint("Firefox Settings")
1092 fprint(" ")
1093 leftPrint("Designed For: " .. serverList[serverID])
1094
1095 -- Load different options
1096 local t1 = "Automatic Updating - Off"
1097 if autoupdate == "true" then t1 = "Automatic Updating - On" end
1098 local t2 = "Incognito Mode - Off"
1099 if incognito == "true" then t2 = "Incognito Mode - On" end
1100 local t3 = "Homepage - rdnt://" .. homepage
1101
1102 -- Prompt the user
1103 local opt = prompt({{t1, 5, 8}, {t2, 5, 10}, {t3, 5, 12}, {"Reset Firefox", -1, 17}},
1104 "vertical", selected)
1105
1106 -- Respond depending on option
1107 if opt == nil then
1108 break
1109 elseif opt == t1 then
1110 if autoupdate == "true" then
1111 autoupdate = "false"
1112 else
1113 autoupdate = "true"
1114 end
1115 selected = 1
1116 elseif opt == t2 then
1117 if incognito == "true" then
1118 incognito = "false"
1119 else
1120 incognito = "true"
1121 end
1122 selected = 2
1123 elseif opt == t3 then
1124 fterm.setCursorPos(5, 12)
1125 fwrite("rdnt://")
1126 homepage = read():gsub("^%s*(.-)%s*$", "%1"):lower()
1127 selected = 3
1128 elseif opt == "Reset Firefox" then
1129 -- Clear
1130 clearPage(site)
1131 fprint(" ")
1132 centerPrint("Firefox Settings")
1133
1134 -- Prompt
1135 local w, h = fterm.getSize()
1136 local a = prompt({{"Reset", math.floor(w/4 - fstring.len("Continue")/2), 9},
1137 {"Cancel", math.ceil(w/4 - fstring.len("Continue")/2 + w/2), 9}},
1138 "horizontal")
1139
1140 -- Depending on option
1141 if a == "Reset" then
1142 -- Delete root folder
1143 fs.delete(rootFolder)
1144
1145 -- Draw
1146 clearPage(site)
1147 fprint(" ")
1148 centerPrint("Firefox Settings")
1149 fprint("\n\n")
1150 centerPrint("Firefox Has Been Reset")
1151 fprint(" ")
1152 centerPrint("Press Any Key To Exit")
1153 fos.pullEvent("key")
1154 redirect("exit")
1155 elseif a == "Cancel" then
1156 -- Draw
1157 clearPage(site)
1158 fprint(" ")
1159 centerPrint("Firefox Settings")
1160 fprint("\n\n")
1161 centerPrint("Reset Cancelled")
1162 fsleep(1.6)
1163 end
1164 selected = 1
1165 end
1166
1167 -- Save settings
1168 local f = fio.open(settingsLocation, "w")
1169 f:write(textutils.serialize({auto = autoupdate, incog = incognito, home = homepage}))
1170 f:close()
1171 end
1172end
1173
1174local function webpageCredits()
1175 -- Draw Credits
1176 fprint(" ")
1177 centerPrint("Firefox Credits")
1178 fprint(" ")
1179 centerPrint("Coded By:")
1180 centerPrint("1lann and GravityScore")
1181 fprint(" ")
1182 centerPrint("Logo By:")
1183 centerPrint("Magnetic Hamster")
1184 fprint("\n")
1185 centerPrint("Originally Based Off:")
1186 centerPrint("Rednet Explorer 2.4.1")
1187 fprint(" ")
1188 centerPrint("Rednet Explorer Made By:")
1189 centerPrint("xXm0dzXx/CCFan11")
1190end
1191
1192local function loadWebpage(site)
1193 clearPage(site)
1194 fprint("\n")
1195 centerPrint("Connecting To Website...")
1196 peripheral = fperipheral
1197 browserAgent = browserAgentTemplate
1198
1199 blacklistRedirectionBots()
1200
1201 -- Get website
1202 local id, content, valid = nil
1203 local clock = fos.clock()
1204 frednet.broadcast(site)
1205 while fos.clock() - clock < 0.01 do
1206 -- Get
1207 id, content = frednet.receive(0.01)
1208
1209 if id ~= nil then
1210 -- Validity check
1211 local av = verifyAgainstAntivirus(content)
1212 local bl = verifyAgainstBlacklist(id)
1213 local wl = verifyAgainstWhitelist(site, id)
1214 local vf = verifyAgainstVerified(site, id)
1215 valid = ""
1216 if bl and not(wl) then
1217 valid = "blacklist"
1218 elseif av and not(vf) then
1219 valid = "antivirus"
1220 break
1221 else
1222 valid = "true"
1223 break
1224 end
1225 end
1226 end
1227
1228 local cacheLoc = (cacheFolder .. "/" .. site:gsub("/", "$slazh$"))
1229 if valid ~= nil then
1230 -- Run page
1231 if valid == "blacklist" then
1232 clearPage(site)
1233 fprint("\n")
1234 centerPrint(" ______ __")
1235 centerPrint(" / ____/_____ _____ ____ _____ / /")
1236 centerPrint(" / __/ / ___// ___// __ \\ / ___// / ")
1237 centerPrint(" / /___ / / / / / /_/ // / /_/ ")
1238 centerPrint("/_____//_/ /_/ \\____//_/ (_) ")
1239 fprint("\n")
1240 centerPrint("Could Not Connect To Website!")
1241 fprint(" ")
1242 centerPrint("The Website Could be Blocked, or Down")
1243 elseif valid == "antivirus" then
1244 clearPage(site)
1245 fprint("\n")
1246 centerPrint(" ___ __ __ __")
1247 centerPrint(" / | / /___ _____ / /_ / /")
1248 centerPrint(" / /| | / // _ \\ / ___// __// / ")
1249 centerPrint(" / ___ | / // __// / / /_ /_/ ")
1250 centerPrint("/_/ |_|/_/ \\___//_/ \\__/(_) ")
1251 fprint("\n")
1252 centerPrint("Warning!")
1253 fprint(" ")
1254 centerPrint("This Website Has Been Detected")
1255 centerPrint("As Malicious!")
1256
1257 local w, h = fterm.getSize()
1258 local opt = prompt({{"Cancel", math.floor(w/4 - fstring.len("Cancel")/2), 17},
1259 {"Load Page", math.ceil(w/4 - fstring.len("Load Page")/2 + w/2), 17}},
1260 "horizontal")
1261 if opt == "Cancel" then
1262 fs.delete(cacheLoc)
1263 clearPage(site)
1264 fprint("\n")
1265 centerPrint(" ______ __")
1266 centerPrint(" / ____/_____ _____ ____ _____ / /")
1267 centerPrint(" / __/ / ___// ___// __ \\ / ___// / ")
1268 centerPrint(" / /___ / / / / / /_/ // / /_/ ")
1269 centerPrint("/_____//_/ /_/ \\____//_/ (_) ")
1270 fprint("\n")
1271 centerPrint("Could Not Connect To Website!")
1272 fprint(" ")
1273 centerPrint("Antivirus Cancelled Loading")
1274 elseif opt == "Load Page" then
1275 valid = "true"
1276 end
1277 end
1278
1279 if valid == "true" then
1280 local f = fio.open(cacheLoc, "w")
1281 f:write(content)
1282 f:close()
1283 clearPage(site)
1284 fshell.run(cacheLoc)
1285 end
1286 else
1287 if fs.exists(cacheLoc) and site ~= "" then
1288 clearPage(site)
1289 fprint("\n")
1290 centerPrint(" ______ ")
1291 centerPrint(" / ____/____ _ _____ __ __ ___ ")
1292 centerPrint(" / / / __ '// ___// /_/ // _ \\")
1293 centerPrint("/ /___ / /_/ // /__ / __ // __/")
1294 centerPrint("\\____/ \\__,_/ \\___//_/ /_/ \\___/ ")
1295 fprint("\n")
1296 centerPrint("Could Not Connect To Website!")
1297 fprint(" ")
1298 centerPrint("A Cache Version Was Found")
1299 local w, h = fterm.getSize()
1300 local opt = prompt({{"Load Cache", math.floor(w/4 - fstring.len("Load Cache")/2), 17},
1301 {"Delete Cache", 20, 17},
1302 {"Cancel", math.ceil(w/4 - fstring.len("Cancel")/2 + w/2), 17}},
1303 "horizontal")
1304 if opt == "Load Cache" then
1305 clearPage(site)
1306 fshell.run(cacheLoc)
1307 elseif opt == "Delete Cache" then
1308 fs.delete(cacheLoc)
1309 clearPage(site)
1310 fprint("\n")
1311 centerPrint(" ______ ")
1312 centerPrint(" / ____/____ _ _____ __ __ ___ ")
1313 centerPrint(" / / / __ '// ___// /_/ // _ \\")
1314 centerPrint("/ /___ / /_/ // /__ / __ // __/")
1315 centerPrint("\\____/ \\__,_/ \\___//_/ /_/ \\___/ ")
1316 fprint("\n")
1317 centerPrint("Deleted Cached Page!")
1318 fsleep(1.8)
1319
1320 clearPage(site)
1321 fprint("\n")
1322 centerPrint(" ______ __")
1323 centerPrint(" / ____/_____ _____ ____ _____ / /")
1324 centerPrint(" / __/ / ___// ___// __ \\ / ___// / ")
1325 centerPrint(" / /___ / / / / / /_/ // / /_/ ")
1326 centerPrint("/_____//_/ /_/ \\____//_/ (_) ")
1327 fprint("\n")
1328 centerPrint("Could Not Connect To Website!")
1329 fprint(" ")
1330 centerPrint("The Address Could Not Be Found")
1331 elseif opt == "Cancel" then
1332 clearPage(site)
1333 fprint("\n")
1334 centerPrint(" ______ __")
1335 centerPrint(" / ____/_____ _____ ____ _____ / /")
1336 centerPrint(" / __/ / ___// ___// __ \\ / ___// / ")
1337 centerPrint(" / /___ / / / / / /_/ // / /_/ ")
1338 centerPrint("/_____//_/ /_/ \\____//_/ (_) ")
1339 fprint("\n")
1340 centerPrint("Could Not Connect To Website!")
1341 fprint(" ")
1342 centerPrint("Cached Version Was Not Loaded")
1343 end
1344 else
1345 -- Get search results
1346 local input = site:gsub("^%s*(.-)%s*$", "%1"):lower()
1347 local results = {}
1348
1349 frednet.broadcast("frednet.api.ping.searchengine")
1350 while not(exitApp) do
1351 local _, i = frednet.receive(0)
1352 if i then
1353 if input == "" then
1354 ftable.insert(results, i)
1355 else
1356 if fstring.find(i, input) then
1357 ftable.insert(results, i)
1358 end
1359 end
1360 else
1361 break
1362 end
1363 end
1364
1365 -- Display
1366 if #results ~= 0 then
1367 clearPage(site)
1368 centerPrint("Search Results")
1369 local nResults = {}
1370 for i = 1, #results do
1371 ftable.insert(nResults, "rdnt://" .. results[i]:gsub("^%s*(.-)%s*$", "%1"):lower())
1372 end
1373
1374 local site, ex = scrollingPrompt(nResults, 14, 4, 4)
1375 if not(ex) then
1376 redirect(site:gsub("rdnt://", ""))
1377 end
1378 elseif site == "" then
1379 clearPage(site)
1380 centerPrint("Search Results")
1381 fprint("\n\n")
1382 centerPrint("No Websites Online")
1383 else
1384 clearPage(site)
1385 fprint("\n")
1386 centerPrint(" ______ __")
1387 centerPrint(" / ____/_____ _____ ____ _____ / /")
1388 centerPrint(" / __/ / ___// ___// __ \\ / ___// / ")
1389 centerPrint(" / /___ / / / / / /_/ // / /_/ ")
1390 centerPrint("/_____//_/ /_/ \\____//_/ (_) ")
1391 fprint("\n")
1392 centerPrint("Could Not Connect To Website!")
1393 fprint(" ")
1394 centerPrint("The Address Could Not Be Found")
1395 end
1396 end
1397 end
1398end
1399
1400
1401-- -------- Website Management
1402
1403local function enterURL()
1404 -- Clear
1405 fterm.setCursorPos(2, 1)
1406 fterm.clearLine()
1407 fwrite("rdnt://")
1408
1409 -- Read
1410 local ret = read(nil, searchBarHistory):gsub("^%s*(.-)%s*$", "%1"):lower()
1411 appendToHistory(ret)
1412 if ret:len() > 32 then
1413 ret = fstring.sub(ret, 1, 39) .. "..."
1414 end
1415
1416 return ret
1417end
1418
1419local function renderWebpage(site)
1420 -- Render site
1421 runningWebsite = site
1422 browserAgent = browserAgentTemplate
1423 fos.queueEvent(websiteLoadEvent)
1424 if site == "firefox" then webpageHome(site)
1425 elseif site == "search" then webpageSearch(site)
1426 elseif site == "history" then webpageHistory(site)
1427 elseif site == "update" then webpageUpdate(site)
1428 elseif site == "server" then webpageNewSite(site)
1429 elseif site == "newsite" then redirect("server")
1430 elseif site == "whatsnew" then webpageWhatsNew(site)
1431 elseif site == "settings" then webpageSettings(site)
1432 elseif site == "credits" then webpageCredits(site)
1433 elseif site == "getinfo" then
1434 -- Title
1435 clearPage(site)
1436 fprint(" ")
1437 centerPrint("Get Website Information")
1438 fprint("\n\n")
1439 leftPrint("Enter URL: ")
1440 local url = read():gsub("^%s*(.-)%s*$", "%1"):lower()
1441
1442 -- Get website
1443 local id, content, valid = nil
1444 local av, bl, wl, vf = nil
1445 local clock = fos.clock()
1446 frednet.broadcast(url)
1447 while fos.clock() - clock < 0.05 do
1448 -- Get
1449 id, content = frednet.receive(0.05)
1450
1451 if id ~= nil then
1452 -- Validity check
1453 av = verifyAgainstAntivirus(content)
1454 bl = verifyAgainstBlacklist(id)
1455 wl = verifyAgainstWhitelist(url, id)
1456 vf = verifyAgainstVerified(url, id)
1457 valid = ""
1458 if bl and not(wl) then
1459 valid = "blacklist"
1460 elseif av and not(vf) then
1461 valid = "antivirus"
1462 else
1463 valid = "true"
1464 break
1465 end
1466 end
1467 end
1468
1469 if valid ~= nil then
1470 -- Print information
1471 clearPage(site)
1472 fprint(" ")
1473 centerPrint("Get Website Information")
1474 fprint("\n")
1475 leftPrint("Site: " .. url .. "\n")
1476 fprint(" ")
1477 leftPrint("ID: " .. id .. "\n")
1478 if bl then
1479 leftPrint("Site Is Blacklisted\n")
1480 end if wl then
1481 leftPrint("Site Is Whitelisted\n")
1482 end
1483 fprint(" ")
1484 if av then
1485 leftPrint("Site Triggered Antivirus\n")
1486 end if vf then
1487 leftPrint("Site Is Verified\n")
1488 end
1489 else
1490 -- Not Found
1491 clearPage(site)
1492 fprint(" ")
1493 centerPrint("Get Website Information")
1494 fprint("\n")
1495 centerPrint("Page Not Found")
1496 end
1497 elseif site == "kittez" or site == "kitten" or site == "kitteh" then
1498 -- Easter Egg :D
1499 fterm.clear()
1500 fterm.setCursorPos(1, 2)
1501 centerPrint(" .__....._ _.....__, ")
1502 centerPrint(" .\": o :': ;': o :\". ")
1503 centerPrint(" '. '-' .'. .'. '-' .' ")
1504 centerPrint(" '---' '---' ")
1505 centerPrint(" ")
1506 centerPrint(" _...----... ... ... ...----..._ ")
1507 centerPrint(" .-'__..-\"\"'---- '. '\"' .' ----'\"\"-..__'-. ")
1508 centerPrint("'.-' _.--\"\"\"' '-._.-' '\"\"\"--._ '-.'")
1509 centerPrint("' .-\"' : '\"-. '")
1510 centerPrint(" ' '. _.'\"'._ .' ' ")
1511 centerPrint(" '. ,.-'\" \"'-., .' ")
1512 centerPrint(" '. .' ")
1513 centerPrint(" '-._ _.-' ")
1514 centerPrint(" '\"'--.....--'\"' ")
1515 fprint(" ")
1516 centerPrint("Firefox Kitteh Is Not Amused...")
1517 centerPrint("An Easter Egg Brought to You By GravityScore :D")
1518 fsleep(6)
1519 fterm.clear()
1520 fterm.setCursorPos(1, 1)
1521 fos.shutdown()
1522 elseif site == "exit" then
1523 -- Exit client
1524 fterm.clear()
1525 fterm.setCursorPos(1, 1)
1526 centerPrint("Thank You for Using Mozilla Firefox " .. firefoxVersion)
1527 centerPrint("Made by 1lann and GravityScore")
1528 return "exit"
1529 else
1530 -- Load the site
1531 loadWebpage(site)
1532 end
1533end
1534
1535function redirect(site)
1536 -- Convert site
1537 local url = site:gsub("^%s*(.-)%s*$", "%1"):lower()
1538 if site == "home" then
1539 url = homepage
1540 end
1541
1542 -- Load site
1543 appendToHistory(url)
1544 clearPage(url)
1545 local opt = renderWebpage(url)
1546 if opt == "exit" then
1547 exitApp = true
1548 error()
1549 end
1550end
1551
1552local function manageWebpages()
1553 while not(exitApp) do
1554 -- Render Page
1555 clearPage(website)
1556 local opt = renderWebpage(website)
1557 if opt == "exit" then
1558 exitApp = true
1559 error()
1560 end
1561
1562 -- Wait for URL bar open
1563 fos.pullEvent(openURLBarEvent)
1564 local url = enterURL()
1565 if url == "home" then
1566 website = homepage
1567 else
1568 website = url
1569 end
1570 end
1571end
1572
1573local function waitForURLEnter()
1574 while not(exitApp) do
1575 -- Wait for URL Bar Open
1576 _, key = fos.pullEvent("key")
1577 if key == 29 or key == 157 then
1578 fos.queueEvent(openURLBarEvent)
1579 end
1580 end
1581end
1582
1583
1584-- -------- Firefox 1.3 Support
1585
1586function cfprint(text)
1587 centerPrint(text)
1588end
1589
1590function reDirect(site)
1591 redirect(site)
1592end
1593
1594function clearArea()
1595 clearPage(runningWebsite)
1596end
1597
1598
1599-- -------- Main
1600
1601local function startup()
1602 -- Logo
1603 fterm.clear()
1604 fterm.setCursorPos(1, 3)
1605 centerPrint(" _ _ __ __ ")
1606 centerPrint("--------- / | / | ____ ____ __ / // /___")
1607 centerPrint("-------- / |/ | / //_ / / // // // |")
1608 centerPrint("------- / /| /| | / / / / /_ / // // // - |")
1609 centerPrint("------ /_/ |/ |_|/___/ /___//_//_//_//_/|_|")
1610 centerPrint("----- _____ __ ____ ____ ___ ______ __ ")
1611 centerPrint("---- / ___// // __ \\ / __// __// /\\ \\/ / ")
1612 centerPrint("--- / /__ / // _ / / __// __// / / > < ")
1613 centerPrint("-- / ___//_//_/ \\_\\/___//_/ /___/ /_/\\_\\ ")
1614 centerPrint("- / / ")
1615 centerPrint(" /_/ Doing Good is Part of Our Code ")
1616 fprint("\n\n")
1617 centerWrite("Cleaning up Firefox Data folder...")
1618 -- Filesystem
1619 upgradeFilesystem()
1620 resetFilesystem()
1621
1622 -- Databases
1623 term.clearLine()
1624 centerWrite("Downloading Databases...")
1625 reloadDatabases()
1626
1627 -- Load settings
1628 term.clearLine()
1629 centerWrite("Loading Settings...")
1630 local f1 = fio.open(settingsLocation, "r")
1631 local set = textutils.unserialize(f1:read("*l"))
1632 homepage = set.home
1633 website = homepage
1634 if not override then
1635-- autoupdate = set.auto
1636 incognito = set.incog
1637 end
1638 browserAgent = browserAgentTemplate
1639 f1:close()
1640
1641 local f2 = fio.open(historyLocation, "r")
1642 history = textutils.unserialize(f2:read("*l"))
1643 f2:close()
1644
1645 term.clearLine()
1646 centerWrite("Checking for Updates...")
1647 -- Update
1648-- if autoupdate == "true" then
1649-- updateClient()
1650-- fsleep(0.1)
1651-- else
1652-- fsleep(0.65)
1653-- end
1654 -- Start websites
1655 if debugging then
1656 fparallel.waitForAny(manageWebpages, waitForURLEnter, updateDatabases)
1657 else
1658 while not(exitApp) do
1659 fterm.setCursorBlink(false)
1660 fpcall(fparallel.waitForAny(manageWebpages, waitForURLEnter, updateDatabases))
1661 end
1662 end
1663end
1664
1665-- Open Rednet
1666frednet.open("top")
1667
1668-- Start App
1669startup()
1670
1671-- Close Rednet
1672frednet.close("top")