· 6 years ago · Feb 08, 2020, 02:58 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 frednet.open("left")
899 frednet.open("right")
900 frednet.open("back")
901 frednet.open("front")
902 frednet.open("bottom")
903 redir = true
904 break
905 elseif opt == "Run On Startup" then
906 fs.delete("/old-startup")
907 if fs.exists("/startup") then fs.move("/startup", "/old-startup") end
908 local f = fio.open("/startup", "w")
909 f:write("fshell.run(\"" .. serverSoftwareLocation .. "\", \"" .. server ..
910 "\", \"" .. serverPath .. "\")")
911 f:close()
912
913 clearPage(site)
914 centerPrint("Firefox Server Management")
915 fprint("\n\n")
916 centerPrint("Server Will Run on Startup")
917 fsleep(0.9)
918 elseif opt == "Edit Pages" then
919 while not(exitApp) do
920 clearPage(site)
921 centerPrint("Firefox Server Management")
922 fprint(" ")
923 leftPrint("Server Pages:")
924
925 local pages = {"Back", "New...", "Rename...", "Copy File...", "Delete..."}
926 local a = fs.list(serverPath)
927 for i = 1, #a do
928 if fs.isDir(serverPath .. "/" .. a[i]) then
929 a[i] = "[Directory] " .. a[i]
930 end
931 ftable.insert(pages, a[i])
932 end
933
934 local page, ex = scrollingPrompt(pages, 12, 4, 6)
935 if not(ex) then
936 if page == "Back" then
937 break
938 elseif page == "New..." then
939 fterm.setCursorPos(1, 5)
940 fterm.clearLine()
941 local w, h = fterm.getSize()
942 local o = prompt({{"File", math.floor(w/4 -
943 fstring.len("File")/2), 5}, {"Folder",
944 math.ceil(w/4 - fstring.len("Folder")/2 + w/2), 5}}, "horizontal")
945 if o == nil then
946 return
947 end
948 fterm.setCursorPos(1, 5)
949 fterm.clearLine()
950 leftPrint("Name: ")
951 local name = read():gsub(" ", ""):lower()
952 if o == "File" then
953 local f = fio.open(serverPath .. "/" .. name, "w")
954 f:write(" ")
955 f:close()
956 elseif o == "Folder" then
957 fs.makeDir(serverPath .. "/" .. name)
958 end
959 elseif page == "Rename..." then
960 clearPage(site)
961 centerPrint("Firefox Server Management")
962 fprint(" ")
963 leftPrint("Select Page to Rename:")
964 local p = {"Cancel"}
965 for i = 1, #a do
966 if fs.isDir(serverPath .. "/" .. a[i]) then
967 a[i] = "[Directory] " .. a[i]
968 end
969 ftable.insert(p, a[i])
970 end
971
972 local a, ex = scrollingPrompt(p, 12, 4, 6)
973 if not(ex) then
974 if a ~= nil and a ~= "Cancel" then
975 fterm.setCursorPos(1, 5)
976 fterm.clearLine()
977 fterm.setCursorPos(1, 5)
978 leftPrint("New Name: ")
979 local name = read():gsub(" ", ""):lower()
980 a = a:gsub("[Directory] ", "")
981 fs.move(serverPath .. "/" .. a, serverPath .. "/" .. name)
982 end
983 else
984 return
985 end
986 elseif page == "Copy File..." then
987 fterm.setCursorPos(1, 5)
988 fterm.clearLine()
989 leftPrint("File To Copy: /")
990 local file = "/" .. read()
991 fterm.setCursorPos(1, 5)
992 fterm.clearLine()
993 if fs.exists(file) then
994 leftPrint("Name: ")
995 local na = read():gsub(" ", ""):lower()
996 if fs.exists(serverPath .. "/" .. na) then
997 fs.delete(serverPath .. "/" .. na)
998 end
999 fs.copy(file, serverPath .. "/" .. na)
1000 else
1001 leftPrint("File Does Not Exist!")
1002 fsleep(1.1)
1003 end
1004 elseif page == "Delete..." then
1005 clearPage(site)
1006 centerPrint("Firefox Server Management")
1007 fprint(" ")
1008 leftPrint("Select Page to Delete:")
1009 local p = {"Cancel"}
1010 for i = 1, #a do
1011 if fs.isDir(serverPath .. "/" .. a[i]) then
1012 a[i] = "[Directory] " .. a[i]
1013 end
1014 ftable.insert(p, a[i])
1015 end
1016
1017 local a, ex = scrollingPrompt(p, 12, 4, 6)
1018 if not(ex) then
1019 if a ~= nil and a ~= "Cancel" then
1020 a = a:gsub("[Directory] ", "")
1021 fs.delete(serverPath .. "/" .. a)
1022 end
1023 else
1024 return
1025 end
1026 elseif page ~= nil and not(fs.isDir(serverPath .. "/" .. page)) then
1027 fterm.clear()
1028 fshell.run(customEditLocation, serverPath .. "/" .. page)
1029 end
1030 else
1031 return
1032 end
1033 end
1034 elseif opt == "Delete Server" then
1035 clearPage(site)
1036 centerPrint("Firefox Server Management")
1037 local w, h = fterm.getSize()
1038 local opt = prompt({{"Delete Server",
1039 math.floor(w/4 - fstring.len("Delete Server")/2), 9},
1040 {"Cancel", math.ceil(w/4 - fstring.len("Cancel")/2 + w/2),
1041 9}}, "horizontal")
1042 if opt == "Delete Server" then
1043 clearPage(site)
1044 centerPrint("Firefox Server Management")
1045 fprint("\n\n")
1046 centerPrint("Deleted Server")
1047 fsleep(1.1)
1048 fs.delete(serverPath)
1049 elseif opt == "Cancel" then
1050 clearPage(site)
1051 centerPrint("Firefox Server Management")
1052 fprint("\n\n")
1053 centerPrint("Cancelled Delete Operation")
1054 fsleep(1.1)
1055 end
1056 redir = true
1057 break
1058 elseif opt == "Back" then
1059 redir = true
1060 break
1061 elseif opt == nil then
1062 return
1063 end
1064 end
1065
1066 if redir then redirect("server") end
1067 end
1068 end
1069end
1070
1071local function webpageWhatsNew(site)
1072 -- Draw what's new
1073 fprint(" ")
1074 centerPrint("What's New in Firefox " .. firefoxVersion)
1075 fprint(" ")
1076 leftPrint("- Added Viewable History\n")
1077 leftPrint("- Added Incognito Mode\n")
1078 leftPrint("- Added Multiple Server Management\n")
1079 leftPrint("- Added Settings\n")
1080 leftPrint("- Added Reset Browser Button\n")
1081 leftPrint("- Added Customizable Homepage\n")
1082 leftPrint("- Added Auto-Search\n")
1083 leftPrint("- Re-Wrote Search Page\n")
1084 leftPrint("- Re-Designed Logo\n")
1085 leftPrint("- Removed Sites Page\n")
1086 leftPrint("- Removed Get ID Page \n")
1087 leftPrint("- Removed Refesh\n")
1088 leftPrint("- Added More Easter Eggs :D\n")
1089end
1090
1091local function webpageSettings(site)
1092 local selected = 1
1093 while not(exitApp) do
1094 -- Clear
1095 clearPage(site)
1096 centerPrint("Firefox Settings")
1097 fprint(" ")
1098 leftPrint("Designed For: " .. serverList[serverID])
1099
1100 -- Load different options
1101 local t1 = "Automatic Updating - Off"
1102 if autoupdate == "true" then t1 = "Automatic Updating - On" end
1103 local t2 = "Incognito Mode - Off"
1104 if incognito == "true" then t2 = "Incognito Mode - On" end
1105 local t3 = "Homepage - rdnt://" .. homepage
1106
1107 -- Prompt the user
1108 local opt = prompt({{t1, 5, 8}, {t2, 5, 10}, {t3, 5, 12}, {"Reset Firefox", -1, 17}},
1109 "vertical", selected)
1110
1111 -- Respond depending on option
1112 if opt == nil then
1113 break
1114 elseif opt == t1 then
1115 if autoupdate == "true" then
1116 autoupdate = "false"
1117 else
1118 autoupdate = "true"
1119 end
1120 selected = 1
1121 elseif opt == t2 then
1122 if incognito == "true" then
1123 incognito = "false"
1124 else
1125 incognito = "true"
1126 end
1127 selected = 2
1128 elseif opt == t3 then
1129 fterm.setCursorPos(5, 12)
1130 fwrite("rdnt://")
1131 homepage = read():gsub("^%s*(.-)%s*$", "%1"):lower()
1132 selected = 3
1133 elseif opt == "Reset Firefox" then
1134 -- Clear
1135 clearPage(site)
1136 fprint(" ")
1137 centerPrint("Firefox Settings")
1138
1139 -- Prompt
1140 local w, h = fterm.getSize()
1141 local a = prompt({{"Reset", math.floor(w/4 - fstring.len("Continue")/2), 9},
1142 {"Cancel", math.ceil(w/4 - fstring.len("Continue")/2 + w/2), 9}},
1143 "horizontal")
1144
1145 -- Depending on option
1146 if a == "Reset" then
1147 -- Delete root folder
1148 fs.delete(rootFolder)
1149
1150 -- Draw
1151 clearPage(site)
1152 fprint(" ")
1153 centerPrint("Firefox Settings")
1154 fprint("\n\n")
1155 centerPrint("Firefox Has Been Reset")
1156 fprint(" ")
1157 centerPrint("Press Any Key To Exit")
1158 fos.pullEvent("key")
1159 redirect("exit")
1160 elseif a == "Cancel" then
1161 -- Draw
1162 clearPage(site)
1163 fprint(" ")
1164 centerPrint("Firefox Settings")
1165 fprint("\n\n")
1166 centerPrint("Reset Cancelled")
1167 fsleep(1.6)
1168 end
1169 selected = 1
1170 end
1171
1172 -- Save settings
1173 local f = fio.open(settingsLocation, "w")
1174 f:write(textutils.serialize({auto = autoupdate, incog = incognito, home = homepage}))
1175 f:close()
1176 end
1177end
1178
1179local function webpageCredits()
1180 -- Draw Credits
1181 fprint(" ")
1182 centerPrint("Firefox Credits")
1183 fprint(" ")
1184 centerPrint("Coded By:")
1185 centerPrint("1lann and GravityScore")
1186 fprint(" ")
1187 centerPrint("Logo By:")
1188 centerPrint("Magnetic Hamster")
1189 fprint("\n")
1190 centerPrint("Originally Based Off:")
1191 centerPrint("Rednet Explorer 2.4.1")
1192 fprint(" ")
1193 centerPrint("Rednet Explorer Made By:")
1194 centerPrint("xXm0dzXx/CCFan11")
1195end
1196
1197local function loadWebpage(site)
1198 clearPage(site)
1199 fprint("\n")
1200 centerPrint("Connecting To Website...")
1201 peripheral = fperipheral
1202 browserAgent = browserAgentTemplate
1203
1204 blacklistRedirectionBots()
1205
1206 -- Get website
1207 local id, content, valid = nil
1208 local clock = fos.clock()
1209 frednet.broadcast(site)
1210 while fos.clock() - clock < 0.01 do
1211 -- Get
1212 id, content = frednet.receive(0.01)
1213
1214 if id ~= nil then
1215 -- Validity check
1216 local av = verifyAgainstAntivirus(content)
1217 local bl = verifyAgainstBlacklist(id)
1218 local wl = verifyAgainstWhitelist(site, id)
1219 local vf = verifyAgainstVerified(site, id)
1220 valid = ""
1221 if bl and not(wl) then
1222 valid = "blacklist"
1223 elseif av and not(vf) then
1224 valid = "antivirus"
1225 break
1226 else
1227 valid = "true"
1228 break
1229 end
1230 end
1231 end
1232
1233 local cacheLoc = (cacheFolder .. "/" .. site:gsub("/", "$slazh$"))
1234 if valid ~= nil then
1235 -- Run page
1236 if valid == "blacklist" then
1237 clearPage(site)
1238 fprint("\n")
1239 centerPrint(" ______ __")
1240 centerPrint(" / ____/_____ _____ ____ _____ / /")
1241 centerPrint(" / __/ / ___// ___// __ \\ / ___// / ")
1242 centerPrint(" / /___ / / / / / /_/ // / /_/ ")
1243 centerPrint("/_____//_/ /_/ \\____//_/ (_) ")
1244 fprint("\n")
1245 centerPrint("Could Not Connect To Website!")
1246 fprint(" ")
1247 centerPrint("The Website Could be Blocked, or Down")
1248 elseif valid == "antivirus" then
1249 clearPage(site)
1250 fprint("\n")
1251 centerPrint(" ___ __ __ __")
1252 centerPrint(" / | / /___ _____ / /_ / /")
1253 centerPrint(" / /| | / // _ \\ / ___// __// / ")
1254 centerPrint(" / ___ | / // __// / / /_ /_/ ")
1255 centerPrint("/_/ |_|/_/ \\___//_/ \\__/(_) ")
1256 fprint("\n")
1257 centerPrint("Warning!")
1258 fprint(" ")
1259 centerPrint("This Website Has Been Detected")
1260 centerPrint("As Malicious!")
1261
1262 local w, h = fterm.getSize()
1263 local opt = prompt({{"Cancel", math.floor(w/4 - fstring.len("Cancel")/2), 17},
1264 {"Load Page", math.ceil(w/4 - fstring.len("Load Page")/2 + w/2), 17}},
1265 "horizontal")
1266 if opt == "Cancel" then
1267 fs.delete(cacheLoc)
1268 clearPage(site)
1269 fprint("\n")
1270 centerPrint(" ______ __")
1271 centerPrint(" / ____/_____ _____ ____ _____ / /")
1272 centerPrint(" / __/ / ___// ___// __ \\ / ___// / ")
1273 centerPrint(" / /___ / / / / / /_/ // / /_/ ")
1274 centerPrint("/_____//_/ /_/ \\____//_/ (_) ")
1275 fprint("\n")
1276 centerPrint("Could Not Connect To Website!")
1277 fprint(" ")
1278 centerPrint("Antivirus Cancelled Loading")
1279 elseif opt == "Load Page" then
1280 valid = "true"
1281 end
1282 end
1283
1284 if valid == "true" then
1285 local f = fio.open(cacheLoc, "w")
1286 f:write(content)
1287 f:close()
1288 clearPage(site)
1289 fshell.run(cacheLoc)
1290 end
1291 else
1292 if fs.exists(cacheLoc) and site ~= "" then
1293 clearPage(site)
1294 fprint("\n")
1295 centerPrint(" ______ ")
1296 centerPrint(" / ____/____ _ _____ __ __ ___ ")
1297 centerPrint(" / / / __ '// ___// /_/ // _ \\")
1298 centerPrint("/ /___ / /_/ // /__ / __ // __/")
1299 centerPrint("\\____/ \\__,_/ \\___//_/ /_/ \\___/ ")
1300 fprint("\n")
1301 centerPrint("Could Not Connect To Website!")
1302 fprint(" ")
1303 centerPrint("A Cache Version Was Found")
1304 local w, h = fterm.getSize()
1305 local opt = prompt({{"Load Cache", math.floor(w/4 - fstring.len("Load Cache")/2), 17},
1306 {"Delete Cache", 20, 17},
1307 {"Cancel", math.ceil(w/4 - fstring.len("Cancel")/2 + w/2), 17}},
1308 "horizontal")
1309 if opt == "Load Cache" then
1310 clearPage(site)
1311 fshell.run(cacheLoc)
1312 elseif opt == "Delete Cache" then
1313 fs.delete(cacheLoc)
1314 clearPage(site)
1315 fprint("\n")
1316 centerPrint(" ______ ")
1317 centerPrint(" / ____/____ _ _____ __ __ ___ ")
1318 centerPrint(" / / / __ '// ___// /_/ // _ \\")
1319 centerPrint("/ /___ / /_/ // /__ / __ // __/")
1320 centerPrint("\\____/ \\__,_/ \\___//_/ /_/ \\___/ ")
1321 fprint("\n")
1322 centerPrint("Deleted Cached Page!")
1323 fsleep(1.8)
1324
1325 clearPage(site)
1326 fprint("\n")
1327 centerPrint(" ______ __")
1328 centerPrint(" / ____/_____ _____ ____ _____ / /")
1329 centerPrint(" / __/ / ___// ___// __ \\ / ___// / ")
1330 centerPrint(" / /___ / / / / / /_/ // / /_/ ")
1331 centerPrint("/_____//_/ /_/ \\____//_/ (_) ")
1332 fprint("\n")
1333 centerPrint("Could Not Connect To Website!")
1334 fprint(" ")
1335 centerPrint("The Address Could Not Be Found")
1336 elseif opt == "Cancel" then
1337 clearPage(site)
1338 fprint("\n")
1339 centerPrint(" ______ __")
1340 centerPrint(" / ____/_____ _____ ____ _____ / /")
1341 centerPrint(" / __/ / ___// ___// __ \\ / ___// / ")
1342 centerPrint(" / /___ / / / / / /_/ // / /_/ ")
1343 centerPrint("/_____//_/ /_/ \\____//_/ (_) ")
1344 fprint("\n")
1345 centerPrint("Could Not Connect To Website!")
1346 fprint(" ")
1347 centerPrint("Cached Version Was Not Loaded")
1348 end
1349 else
1350 -- Get search results
1351 local input = site:gsub("^%s*(.-)%s*$", "%1"):lower()
1352 local results = {}
1353
1354 frednet.broadcast("frednet.api.ping.searchengine")
1355 while not(exitApp) do
1356 local _, i = frednet.receive(0)
1357 if i then
1358 if input == "" then
1359 ftable.insert(results, i)
1360 else
1361 if fstring.find(i, input) then
1362 ftable.insert(results, i)
1363 end
1364 end
1365 else
1366 break
1367 end
1368 end
1369
1370 -- Display
1371 if #results ~= 0 then
1372 clearPage(site)
1373 centerPrint("Search Results")
1374 local nResults = {}
1375 for i = 1, #results do
1376 ftable.insert(nResults, "rdnt://" .. results[i]:gsub("^%s*(.-)%s*$", "%1"):lower())
1377 end
1378
1379 local site, ex = scrollingPrompt(nResults, 14, 4, 4)
1380 if not(ex) then
1381 redirect(site:gsub("rdnt://", ""))
1382 end
1383 elseif site == "" then
1384 clearPage(site)
1385 centerPrint("Search Results")
1386 fprint("\n\n")
1387 centerPrint("No Websites Online")
1388 else
1389 clearPage(site)
1390 fprint("\n")
1391 centerPrint(" ______ __")
1392 centerPrint(" / ____/_____ _____ ____ _____ / /")
1393 centerPrint(" / __/ / ___// ___// __ \\ / ___// / ")
1394 centerPrint(" / /___ / / / / / /_/ // / /_/ ")
1395 centerPrint("/_____//_/ /_/ \\____//_/ (_) ")
1396 fprint("\n")
1397 centerPrint("Could Not Connect To Website!")
1398 fprint(" ")
1399 centerPrint("The Address Could Not Be Found")
1400 end
1401 end
1402 end
1403end
1404
1405
1406-- -------- Website Management
1407
1408local function enterURL()
1409 -- Clear
1410 fterm.setCursorPos(2, 1)
1411 fterm.clearLine()
1412 fwrite("rdnt://")
1413
1414 -- Read
1415 local ret = read(nil, searchBarHistory):gsub("^%s*(.-)%s*$", "%1"):lower()
1416 appendToHistory(ret)
1417 if ret:len() > 32 then
1418 ret = fstring.sub(ret, 1, 39) .. "..."
1419 end
1420
1421 return ret
1422end
1423
1424local function renderWebpage(site)
1425 -- Render site
1426 runningWebsite = site
1427 browserAgent = browserAgentTemplate
1428 fos.queueEvent(websiteLoadEvent)
1429 if site == "firefox" then webpageHome(site)
1430 elseif site == "search" then webpageSearch(site)
1431 elseif site == "history" then webpageHistory(site)
1432 elseif site == "update" then webpageUpdate(site)
1433 elseif site == "server" then webpageNewSite(site)
1434 elseif site == "newsite" then redirect("server")
1435 elseif site == "whatsnew" then webpageWhatsNew(site)
1436 elseif site == "settings" then webpageSettings(site)
1437 elseif site == "credits" then webpageCredits(site)
1438 elseif site == "getinfo" then
1439 -- Title
1440 clearPage(site)
1441 fprint(" ")
1442 centerPrint("Get Website Information")
1443 fprint("\n\n")
1444 leftPrint("Enter URL: ")
1445 local url = read():gsub("^%s*(.-)%s*$", "%1"):lower()
1446
1447 -- Get website
1448 local id, content, valid = nil
1449 local av, bl, wl, vf = nil
1450 local clock = fos.clock()
1451 frednet.broadcast(url)
1452 while fos.clock() - clock < 0.05 do
1453 -- Get
1454 id, content = frednet.receive(0.05)
1455
1456 if id ~= nil then
1457 -- Validity check
1458 av = verifyAgainstAntivirus(content)
1459 bl = verifyAgainstBlacklist(id)
1460 wl = verifyAgainstWhitelist(url, id)
1461 vf = verifyAgainstVerified(url, id)
1462 valid = ""
1463 if bl and not(wl) then
1464 valid = "blacklist"
1465 elseif av and not(vf) then
1466 valid = "antivirus"
1467 else
1468 valid = "true"
1469 break
1470 end
1471 end
1472 end
1473
1474 if valid ~= nil then
1475 -- Print information
1476 clearPage(site)
1477 fprint(" ")
1478 centerPrint("Get Website Information")
1479 fprint("\n")
1480 leftPrint("Site: " .. url .. "\n")
1481 fprint(" ")
1482 leftPrint("ID: " .. id .. "\n")
1483 if bl then
1484 leftPrint("Site Is Blacklisted\n")
1485 end if wl then
1486 leftPrint("Site Is Whitelisted\n")
1487 end
1488 fprint(" ")
1489 if av then
1490 leftPrint("Site Triggered Antivirus\n")
1491 end if vf then
1492 leftPrint("Site Is Verified\n")
1493 end
1494 else
1495 -- Not Found
1496 clearPage(site)
1497 fprint(" ")
1498 centerPrint("Get Website Information")
1499 fprint("\n")
1500 centerPrint("Page Not Found")
1501 end
1502 elseif site == "kittez" or site == "kitten" or site == "kitteh" then
1503 -- Easter Egg :D
1504 fterm.clear()
1505 fterm.setCursorPos(1, 2)
1506 centerPrint(" .__....._ _.....__, ")
1507 centerPrint(" .\": o :': ;': o :\". ")
1508 centerPrint(" '. '-' .'. .'. '-' .' ")
1509 centerPrint(" '---' '---' ")
1510 centerPrint(" ")
1511 centerPrint(" _...----... ... ... ...----..._ ")
1512 centerPrint(" .-'__..-\"\"'---- '. '\"' .' ----'\"\"-..__'-. ")
1513 centerPrint("'.-' _.--\"\"\"' '-._.-' '\"\"\"--._ '-.'")
1514 centerPrint("' .-\"' : '\"-. '")
1515 centerPrint(" ' '. _.'\"'._ .' ' ")
1516 centerPrint(" '. ,.-'\" \"'-., .' ")
1517 centerPrint(" '. .' ")
1518 centerPrint(" '-._ _.-' ")
1519 centerPrint(" '\"'--.....--'\"' ")
1520 fprint(" ")
1521 centerPrint("Firefox Kitteh Is Not Amused...")
1522 centerPrint("An Easter Egg Brought to You By GravityScore :D")
1523 fsleep(6)
1524 fterm.clear()
1525 fterm.setCursorPos(1, 1)
1526 fos.shutdown()
1527 elseif site == "exit" then
1528 -- Exit client
1529 fterm.clear()
1530 fterm.setCursorPos(1, 1)
1531 centerPrint("Thank You for Using Mozilla Firefox " .. firefoxVersion)
1532 centerPrint("Made by 1lann and GravityScore")
1533 return "exit"
1534 else
1535 -- Load the site
1536 loadWebpage(site)
1537 end
1538end
1539
1540function redirect(site)
1541 -- Convert site
1542 local url = site:gsub("^%s*(.-)%s*$", "%1"):lower()
1543 if site == "home" then
1544 url = homepage
1545 end
1546
1547 -- Load site
1548 appendToHistory(url)
1549 clearPage(url)
1550 local opt = renderWebpage(url)
1551 if opt == "exit" then
1552 exitApp = true
1553 error()
1554 end
1555end
1556
1557local function manageWebpages()
1558 while not(exitApp) do
1559 -- Render Page
1560 clearPage(website)
1561 local opt = renderWebpage(website)
1562 if opt == "exit" then
1563 exitApp = true
1564 error()
1565 end
1566
1567 -- Wait for URL bar open
1568 fos.pullEvent(openURLBarEvent)
1569 local url = enterURL()
1570 if url == "home" then
1571 website = homepage
1572 else
1573 website = url
1574 end
1575 end
1576end
1577
1578local function waitForURLEnter()
1579 while not(exitApp) do
1580 -- Wait for URL Bar Open
1581 _, key = fos.pullEvent("key")
1582 if key == 29 or key == 157 then
1583 fos.queueEvent(openURLBarEvent)
1584 end
1585 end
1586end
1587
1588
1589-- -------- Firefox 1.3 Support
1590
1591function cfprint(text)
1592 centerPrint(text)
1593end
1594
1595function reDirect(site)
1596 redirect(site)
1597end
1598
1599function clearArea()
1600 clearPage(runningWebsite)
1601end
1602
1603
1604-- -------- Main
1605
1606local function startup()
1607 -- Logo
1608 fterm.clear()
1609 fterm.setCursorPos(1, 3)
1610 centerPrint(" _ _ __ __ ")
1611 centerPrint("--------- / | / | ____ ____ __ / // /___")
1612 centerPrint("-------- / |/ | / //_ / / // // // |")
1613 centerPrint("------- / /| /| | / / / / /_ / // // // - |")
1614 centerPrint("------ /_/ |/ |_|/___/ /___//_//_//_//_/|_|")
1615 centerPrint("----- _____ __ ____ ____ ___ ______ __ ")
1616 centerPrint("---- / ___// // __ \\ / __// __// /\\ \\/ / ")
1617 centerPrint("--- / /__ / // _ / / __// __// / / > < ")
1618 centerPrint("-- / ___//_//_/ \\_\\/___//_/ /___/ /_/\\_\\ ")
1619 centerPrint("- / / ")
1620 centerPrint(" /_/ Doing Good is Part of Our Code ")
1621 fprint("\n\n")
1622 centerWrite("Cleaning up Firefox Data folder...")
1623 -- Filesystem
1624 upgradeFilesystem()
1625 resetFilesystem()
1626
1627 -- Databases
1628 term.clearLine()
1629 centerWrite("Downloading Databases...")
1630 reloadDatabases()
1631
1632 -- Load settings
1633 term.clearLine()
1634 centerWrite("Loading Settings...")
1635 local f1 = fio.open(settingsLocation, "r")
1636 local set = textutils.unserialize(f1:read("*l"))
1637 homepage = set.home
1638 website = homepage
1639 if not override then
1640-- autoupdate = set.auto
1641 incognito = set.incog
1642 end
1643 browserAgent = browserAgentTemplate
1644 f1:close()
1645
1646 local f2 = fio.open(historyLocation, "r")
1647 history = textutils.unserialize(f2:read("*l"))
1648 f2:close()
1649
1650 term.clearLine()
1651 centerWrite("Checking for Updates...")
1652 -- Update
1653-- if autoupdate == "true" then
1654-- updateClient()
1655-- fsleep(0.1)
1656-- else
1657-- fsleep(0.65)
1658-- end
1659 -- Start websites
1660 if debugging then
1661 fparallel.waitForAny(manageWebpages, waitForURLEnter, updateDatabases)
1662 else
1663 while not(exitApp) do
1664 fterm.setCursorBlink(false)
1665 fpcall(fparallel.waitForAny(manageWebpages, waitForURLEnter, updateDatabases))
1666 end
1667 end
1668end
1669
1670-- Open Rednet
1671frednet.open("top")
1672
1673-- Start App
1674startup()
1675
1676-- Close Rednet
1677frednet.close("top")