This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Left4Cake's profile picture

Firebox now with a DNS server for world hosted sites [Web Browser]

Started by Left4Cake, 21 September 2012 - 12:17 AM
Left4Cake #1
Posted 21 September 2012 - 02:17 AM
Firebox beta 1.0.1
with 40 sites on the my web server.

Adv computer not needed to use but some downloads may require it.

Credits
Zacpier - appstore on "google.com/play"
ComputerCraftfan11 - Rednet on "rednet.org"
Zaggy1024 - Sidescroller Minecraft WIP on "minecraft.net"
MysticT- Gchat on "google.com/talk"
GravityScore - Lightshot on "fraps.com"
GravityScore - Thunderbird on "gmail.com"
GravityScore - ccleverbot on "cleverbot.com"
PossieTV- Redbook on "redbook.com"
nitrogenfingers - Npaintpro on "getpaint.net"
*If/When this list get too long I will be placed in a spoiler.

I saw a few other and wanted to take my own crack at it.
This program download programs as temp and runs them, as well as host web sites that can be accessed directly, thou relays, or thou a Domain Name Server, as well as download pages from http. (witch can take advantage of my Html Reader for a sort of half-baked real browser)

My goal is to try to get as many real site sort of copied into a computercraft like fashion.




How to use Web server

Client either see the Client DNS instruction for connect directly with 192.168.1.id

Server:
Spoiler1. Install the server or install firebox and use "Firebox/host" to run
2. Make a http directroy.
3. Place an "index" in http file as a web page. (all pages are just lua programs.)
4. Place an "error" file in http for when a page dose not exist. (server will display a default message if it is not present.)
5. Run the server.


How to use DNS
Client: Simply set the dns variable to the id of the DNS server or a Server relay connected to the DNS server
Now connect to it using rdnt:// before the address.

DNS Sever : see spoiler
Spoiler1. Install the Firebox or the Dedicated DNS server onto your DNS computer.

2. Edit DNSids = {} and DNSdomains = {} so that DNSids[x] is the computer id for the computer at the domain name (for example "www.test.com") matches with DNSdomains[x]

Two example are below:

DNSids = {5, 6, 89}
DNSdomains = {"www.test.com", "www.bob.com", "www.games.com"}



DNSids = {}
DNSdomains = {}
DNSids[1] = 5
DNSdomains[1]  = "www.test.com"

DNSids2[2] = 6
DNSdomains[2]  = "www.bob.com"

DNSids[3] = 89
DNSdomains[3] = "www.games.com"

3. Run Firebox with the agument hostDNS or run the Dectacted DNS server. (modem shoud be on right side unless you changed rednet.open("right") in the code.

V 1.0.1

- Added "Firebox = shell.getRunningProgram()" so that "rdnt://" could use shell.run(Firebox, "rdnt://www.exapmleurl.com")

V 1.0.0

- Added DNS Functionally
- Connected to a url on the DNS server works with "rdnt://"

Full client

Now on pastbin:
http://pastebin.com/4LXcjgDb
-or-
pastebin get 4LXcjgDb firebox

Note: As with the real internet use caution when visiting web sites.

Spoiler


local tArgs = { ... }
local favorits = { }

--configrable variables
Firebox = shell.getRunningProgram()
edit = "edit" -- textviewing programe for http;
server = nil -- for redbook
install = "" -- for all downloads
dns = 202 -- id of DNS server
DNSids = {201}
DNSdomains = {"www.test.com"}
-- end

if #tArgs < 1 then
   print( "Do you want to 1 enter a url, 2:select from 'firebox_fave'" )
   input = read()
   shell.run( "clear" )
   if input == "2" then
	if(fs.exists("firebox_fave")) then
	local fave = fs.open("firebox_fave", "r")
		   max = 0
		   while true do
		 local line = fave.readLine()
		 if line == nil then --if reached end of file
  break end
		   table.insert(favorits, line)
		   max = max + 1
  end
fave.close()
				i = 0
		   print( "Use the arrows and enter to chose.  " )
		   while true do
		   i = i + 1
		   if favorits[i] == nil then break end
		   print( "  " .. i .. ": " .. favorits[i])
		   end
		   pointer = 1
		   term.setCursorPos(1, pointer + 1)
		   print( "->" )
		   while true do
				   local evt, arg1, arg2 = os.pullEvent()
				   term.setCursorPos(1, pointer + 1)
				   print( "  " )
				   if arg1 == 200 and pointer > 1 then
						   pointer = pointer - 1
				   elseif arg1 == 208 and pointer < max then
						   pointer = pointer + 1
				   end
				   term.setCursorPos(1, pointer + 1)
				   print( "->" )
				   if arg1 == 28 then break end
		   end
		   url = favorits[pointer]

   else
   print("'firebox_fave' dose not exist")
   print("To create a favorits list then store each url on its own line in firebox/fave")
   print("")
   print( "Enter a url or type host to host a server." )
   url = read()
   end
   else
		   print( "Enter a url or type host to host a server." )
		   url = read()
   end
else
  url = tArgs[1]
end
if string.find(url, "192.168.1.") then
-- Connect to rednet
rednetip = string.gsub(url, "192.168.1.", "") * 1
rednet.open("right")
shell.run( "clear" )
rednet.send(rednetip, "http/index")
file = io.open("temp", "w")
id, msg = rednet.receive(20)
if msg == nil then
		print( "The server did not sent a message back. It must not like you." )
else
		file:write(msg)
		file:close()
		response = nil
		shell.run( "temp" )
end
elseif url == "host" then
shell.run( "clear" )
print ( "Server ready to serve." )
rednet.open("right")
print ( "Opening the portholes" )
while true do
  id, message  = rednet.receive()
  if fs.exists(message) then
		  file = io.open( message )
		  filedata = file:read()
		  file:close()
		  rednet.send(id, filedata)
		  print ( "Send that old trash to 192.168.1." .. id )
  elseif fs.exists("http/error") then
		  file = io.open("http/error")
		  filedata = file:read()
		  file:close()
		  rednet.send(id, filedata)
		  print ( "Send that old trash to 192.168.1." .. id )
  else
		  rednet.send(id, "print( \"Error, This server (192.168.1." .. id .. ") could not sent you your request.\")")
		  print ( "Failed to give 192.168.1." .. id  .. " his present." )
  end
end
elseif string.find(url, "http://") then
--Connect to internet
				local response = http.get(url)
		 if response then
			   while response do
				local sResponse = response.readAll()
				   response.close()
				   shell.run( "clear" )
				   cache = shell.resolve( "temp" )
				   local file = fs.open( cache, "w" )
				   file.write( sResponse )
				   file.close()
				   response = nil
				   shell.run( edit, "temp" )
				  end
				else
		 -- if page is not reseved
			print( "Error, Could not load page." )
				end
elseif string.find(url, "rdnt://") then
--Connect to Rednet DNS
rednetDomain = string.gsub(url, "rdnt://", "")
rednet.open("right")
shell.run( "clear" )
rednet.send(dns, rednetDomain)
file = io.open("temp", "w")
id, msg = rednet.receive(20)
if msg == nil then
	   print( "The Domain Name Server did not sent a message back. It must have got it self in a fight with the website you are trying to connect to." )
else
	   file:write(msg)
	   file:close()
	   response = nil
	   shell.run( "temp" )
end
elseif string.find(url, "hostDNS") then
--Host a DNS server
rednet.open("right")
print ( "DNS ready to serve." )
while true do
client, message  = rednet.receive()
		print( "192.168.1." .. client .. " whats to connect to " .. message )
i = 1

devidingCharater = string.find(message, "/")
length  = string.len(message)
message = string.lower(message)
Domainname = string.sub(message, devidingCharater, length - devidingCharater)
subDomain = string.sub(message, devidingCharater, length)

print("request:" .. message)
print("Domainname:" .. Domainname)

print("subDomain:" .. subDomain)
while DNSids[i] do
if(message == DNSdomains[i]) then
rednet.send(DNSids[i], "http/" .. subDomain)
	   print( "Trying to find 192.168.1." .. client .. " to 192.168.1." .. DNSids[i])
	   id, msg = rednet.receive(20)
	   if msg == nil then
			   print( "All as been lost." )
	   else
			   rednet.send(client, msg)  
			   print( "Found him. Matching up." )
		 end
end
i = i + 1
end
end

else
-- Connect to Craftnet
		 --  root = "http://localhost/minecraft/"
		   root = "http://www.lozengia.com/tmas/Downloads/Minecraft/firebox/"
		local response = http.get(root .. url)
		if response then
		-- if page is reseved
		   while response do
				   local sResponse = response.readAll()
				   response.close()
				   shell.run( "clear" )
				   cache = shell.resolve( "temp" )
				   local file = fs.open( cache, "w" )
				   file.write( sResponse )
				   file.close()
				   response = nil
				   shell.run( "temp" )
		   end
		   shell.run( "clear" )
		else
		-- if page is not reseved
		   print( "Error, Could not load page." )
		end
end

Dedicated server

print ( "Server ready to serve." )
rednet.open("right")
print ( "Opening the portholes" )
while true do
  id, message  = rednet.receive()
  if fs.exists(message) then
		  file = io.open( message )
		  filedata = file:read()
		  file:close()
		  rednet.send(id, filedata)
		  print ( "Send that old trash to 192.168.1." .. id )
  elseif fs.exists("http/error") then
		  file = io.open("http/error")
		  filedata = file:read()
		  file:close()
		  rednet.send(id, filedata)
		  print ( "Send that old trash to 192.168.1." .. id )
  else
		  rednet.send(id, "print( \"Error, could not sent you your request.\")")
		  print ( "Failed to give 192.168.1." .. id  .. "his present." )
  end
end

Dedicated DNS server


DNSids = {201}
DNSdomains = {"www.test.com"}
-- end

rednet.open("right")
print ( "DNS ready to serve." )
while true do
client, message  = rednet.receive()
	   print( "192.168.1." .. client .. " whats to connect to " .. message )
i = 1

devidingCharater = string.find(message, "/")
print("request:" .. message)
if devidingCharater then
length  = string.len(message)
message = string.lower(message)
Domainname = string.sub(message, 1, devidingCharater - 1)
subDomain = string.sub(message, devidingCharater + 1, length)

else
Domainname = message
subDomain = ""
end
print("Domainname:" .. Domainname)
print("subDomain:" .. subDomain)

while DNSids[i] do
if(Domainname == DNSdomains[i]) then
if subDomain == "" then
rednet.send(DNSids[i], "http/index")
else
rednet.send(DNSids[i], "http/" .. subDomain)
end
	   print( "Trying to find 192.168.1." .. client .. " to 192.168.1." .. DNSids[i])
	   id, msg = rednet.receive(20)
	   if msg == nil then
			   print( "All as been lost." )
	   else
			   rednet.send(client, msg)  
			   print( "Found him. Matching up." )
		end
end
i = i + 1
end
end

Server relay

local tArgs = { ... }
shell.run( "clear" )
if #tArgs < 1 then
	print( "Relay want to serve, but first what ip do you want?" )
	url = read()
else
   url = tArgs[1]
end
rednetip = string.gsub(url, "192.168.1.", "") * 1
rednet.open("right")
print ( "Relay ready to serve." )
while true do
	client, message  = rednet.receive()
	print( "192.168.1." .. client .. " whats to connect." )
	rednet.send(rednetip, message)
	print( "Trying to find 192.168.1." .. client .. " a freind." )
	id, msg = rednet.receive(20)
	if msg == nil then
		print( "All as been lost." )
	else
		rednet.send(client, msg)  
		print( "Found him. Matching up." )
	end
end


Spoilerv0.4.4

- Added configrable variables to the code
- You can change edit to equal the text programe you want http source to open in.
- You can change the server ID redbook tries to use when going to "redbook.com"
- You can change where downloaded files go with the install variable.

V 0.4.3

- Added http:// funtion. If you type in an http:// url. (exp. http://www.google.com) It will download its source code and open it in edit.

V0.4.1

- Chaned Favorits loaction from firefox/face to firebox_fave
- Fixed the favorites list so that it tell you how to make it if there is not one present
- Fixed favorites so you can still type a url if the favorites is not present.
- Fixed bug in the serving hosting involving not escaping a string properly.

V 0.4

- Changes the local connect to that when connect the client sends a message requesting for "http/index" and the server opens it based on that allowing people to create local sites that open to different pages.
- Change the server to try to open "http/error" if the page request is not found.
- The server will send back a print message if "http/error" is not found
- added server relays witch can be set to a server to bounce the connection between servers and clients. However you must connect to the relays ip and not the servers.

V 0.3
Added the abilty to host server and to connect to site hosted on other computers. Just type 192.168.1.id* to connect. Alowing useres to create an intranet. Put file in you want to be loaded in http/index.

*id is the computers id.

V 0.2
add option to load url's from a favorites list from "firebox/fave" (no edit function yet)


V 0.1
- This program with download a page as temp and then run it.


You can change root to your own web server if you would rather host your own "internet"

How you can help

A "website"
Until I can pay for my own web server you will have to send stuff to me. It can be a plain lua script or you can also use php. If you are using php you can install xammp to test it on your own computer. (set root in firebox to "http://localhost/<root directory of files>") Just send me the code in a pm, and I will try to respond as soon as I am able. (repeat xammp dose not upload anything its a web server so you can test any php you want to use on your own.)


an rss feed
Anyone can just make a request for me to include a site rss feed. it is not that hard.

images
Need both ascii and .nfp images for "google images" Ascii images need to be able to fit on the screen and have to have a non space charater starting each line. .nfp images don't need to be within the screens size, but if its more then 49x19 only people with npaintpro can see the whole thing.

A "steam game"
I have a demake of steam. If you would like to send any of your lua games to be downloadable from it that would be awesome. However if the game has multiple file then you will need to make some sort of down-loader and send me that instead.

A "YouTube video"
ok, this is the largest stretch of a website clone out of all of them. Basically there is an ASCII version of YouTube. My website converts 50x19 .png images to ASCII art and then will send back on frame at a time. There can also be a text file containing some dioluge that gets printed on the bottom. If you want to send me one of these send a .zip or .rar file named what you want the "video" to be called and it must contain only .png images and .txt files. The images must be 50x19 (or maybe smaller) and the name of the files must be "1.png 2.png 3.png 3.txt 4.png 5.png…" In the example only 3.txt had a subtitle in it. "Videos" longer then about 100 frames tend to crash a bit and "videos" over about 300 frame can crash the system. So yeah the whole thing is clunky but what did you expect from ComputerCraft YouTube. :-P


A "Netflix video"

See ascii video player for detailes. Netflix just download the "videos" to be played by it.

and if you do go to http://www.lozengia....ecraft/firebox/ just keep in mind that you are only looking at the lua and not the php, also it look better if you "view scorce" in what ever browser you are using.

Update [outdated] (Sep/23/2012): You can download the site that are on my websever in there raw php form here. However it dose not include "lozengia.com" because that site call for function off my site that arn't the best written and are to much of a hassle for me to include. (plus would further require all sorts of unrelated stuff to get it to work).
tommyroyall #2
Posted 22 September 2012 - 08:44 PM
Perhaps I could make some APIs for running sites of which you have in this? :P/>/>
Is there any way that I could upload files to this for testing?
Left4Cake #3
Posted 22 September 2012 - 11:41 PM
I don't own the web server. So I can't just give people straight up accesses. (I can personalty act as a middle man of sort for it but that the closest it get until I can pay for my own.)

However if you only want to test you could install xammp on your own machine and set the root variable in the program to htp://localhost/"where ever you put things".

But I would be more then happy to accept any contribution you would be willing to send.
Exerro #4
Posted 25 September 2012 - 06:39 PM
can i make a suggestion? make it possible for users to host websites on a pc and then other users be able to look at the website from a different pc with rednet
Cranium #5
Posted 25 September 2012 - 06:43 PM
I have suggested this before for other browsers, but I think it bears repeating. If you could incorporate THIS into your browser, it would be super awesome.
Left4Cake #6
Posted 25 September 2012 - 11:12 PM
can i make a suggestion? make it possible for users to host websites on a pc and then other users be able to look at the website from a different pc with rednet

You know I have an idea for that. I would might consider treating it like a lan connection. (so you would type. 192.168.1.# to connect to a given pc hosting something.) The main reason for this would really be just to avoid conflation with the web based and rednet based sites.

I have suggested this before for other browsers, but I think it bears repeating. If you could incorporate THIS into your browser, it would be super awesome.

I love the idea but is that possible with out some sort of HTCPCPapi. I am not sure the HTTPapi can do that.
Cranium #7
Posted 25 September 2012 - 11:22 PM
I'm thinking that if you set up the "ip" addresses, you could give the funny errors if you have problems connecting to them. My favorite is "error 418: I'm a teapot."
rickydaan #8
Posted 27 September 2012 - 01:46 PM
Imma sing me in dude!! Wheres the actual sign in button?
tommyroyall #9
Posted 27 September 2012 - 09:58 PM
How can I put pages that I've made up there?

I was wondering if I could have a folder with which to run some test files of mine. I want to write a client-side interpreter for files of which I read from this :P/>/>.
Left4Cake #10
Posted 28 September 2012 - 12:59 AM
Imma sing me in dude!! Wheres the actual sign in button?
How can I put pages that I've made up there?

I was wondering if I could have a folder with which to run some test files of mine. I want to write a client-side interpreter for files of which I read from this :P/>/>.

For the time being I cant give out log ins since I am running off my Dads server right now. However I did just get a job and when I can I will try to get a server that people can submit stuff too. (in fact if anyone has any recommendations for a hosting serves that lets me create alt logins that can only access cretin directories that would help.)

In the mean time if you would like to test something download xammp, (unless its lua only then its just like any program for CC) and set the "root" variable in firebox to /localhost/"where ever you put it" Just as long as you only use lua + php anything that works with xammp should work on the server. Send me a pm with the program with the "domain name". My only restriction is that if it share a name with a major site. ("steampowered.com", "google.com", "facebook.com", "hulu.com" ect.) that it either 1) does the same thing as it, or 2) pull information from it. Even viruss are fine, its add to the real web experions. (however you will be on the bottom of the google list for sure. :-P)
Noodle #11
Posted 28 September 2012 - 03:24 AM
I saw it, I used it, I like it!
Why do people always use multiple messages to send info in rednet?
Just use matching and formatting to transfer messages.
Exerro #12
Posted 28 September 2012 - 07:58 PM
Do you need any help btw? I did want to make an internet system but found it a bit too hard so it would be great if i could help with this one and get some of my ideas out there…
Left4Cake #13
Posted 29 September 2012 - 12:07 AM
I saw it, I used it, I like it!
Why do people always use multiple messages to send info in rednet?
Just use matching and formatting to transfer messages.

Well this is my first time using rednet. So any help with that would be nice.

Do you need any help btw? I did want to make an internet system but found it a bit too hard so it would be great if i could help with this one and get some of my ideas out there…

I was kind of hoping to host community content. What exactly do you have in mind.
Exerro #14
Posted 29 September 2012 - 11:48 AM
I saw it, I used it, I like it!
Why do people always use multiple messages to send info in rednet?
Just use matching and formatting to transfer messages.

Well this is my first time using rednet. So any help with that would be nice.

Do you need any help btw? I did want to make an internet system but found it a bit too hard so it would be great if i could help with this one and get some of my ideas out there…

I was kind of hoping to host community content. What exactly do you have in mind.

each pc is connected to a LAN that is connected to satteliites (wireless turtles). the pcs can communicate with eachother through the lan and then they can also communicate long distances through the sattellites. Also with different info going through 1 rednet message i use -:- to separate each item
Left4Cake #15
Posted 29 September 2012 - 01:45 PM
each pc is connected to a LAN that is connected to satteliites (wireless turtles). the pcs can communicate with eachother through the lan and then they can also communicate long distances through the sattellites. Also with different info going through 1 rednet message i use -:- to separate each item

Wow, never would of come up with that my self. If you can do that would be great. I always headed how other people internet programs were tethered to the range of just one PC.
tommyroyall #16
Posted 29 September 2012 - 03:37 PM
I was kind of hoping to host community content. What exactly do you have in mind.

So, I could use xammp to upload to this?
Left4Cake #17
Posted 29 September 2012 - 05:19 PM
I was kind of hoping to host community content. What exactly do you have in mind.

So, I could use xammp to upload to this?

I point of xammp is to allow you to test your program if you want to use php with it. (since you need some sort of server to interpret it) Since until I get somethings worked out money wise its a manual process on my part and I don't want to be middle man in a "i need to see if I fixed line 15" process.
Left4Cake #18
Posted 03 January 2013 - 12:27 PM
Made a minor update to the client and uploaded a few more sites to the database.
Northfleet #19
Posted 14 March 2013 - 06:31 AM
Add pornhub.com, LOL. :lol:/>
Left4Cake #20
Posted 18 March 2013 - 02:56 PM
Add pornhub.com, LOL. :lol:/>

The funny thing is I really could.
rhysjack7 #21
Posted 15 April 2013 - 08:32 AM
Please Can I Include It In CraftdowsOS Because I Have An Icon For It
Left4Cake #22
Posted 16 April 2013 - 03:02 AM
I don't mind. As long as you don't mind me possibly deciding to make CraftdowsOS downloadable with Firebox.

​Edit: Also added DNS functionality to it.
mtwiscool #23
Posted 18 April 2013 - 06:55 AM
can't get relay to work
Left4Cake #24
Posted 18 April 2013 - 08:34 AM
can't get relay to work

(pm [12:17 PM] he relay code does not seem to work on wired modem)

What exactly are you doing. I image you put the modem/wire on a side other then the right with out changing rednet.open("right") in the code.

If that so either put it wire/modem on the right side or change "right" to what ever side its on.

I also have every little (but not no) experience with wired modems, but I believe you may have to turn them on by right clicking.
mtwiscool #25
Posted 18 April 2013 - 08:46 AM
heres a screenshot of the relay:


any way to make the relay work?
Left4Cake #26
Posted 18 April 2013 - 09:25 AM
Did you change the variables correctly. The relay asks for the id, but if you are using the DNS you have to change dns to the variable of the realy, or if your drectly connecting then you have to type in 192.168.1.relaysid.
mtwiscool #27
Posted 18 April 2013 - 09:33 AM
can please post a screenshot of what you are doing with the id.
Left4Cake #28
Posted 23 April 2013 - 03:33 AM
Firebox (client)
You will need to change the 202 to the id of either the DNS server or the relay.

dns = 202 -- id of DNS server

DNServer (either Firebox or Dedicated)
You will need to change these so that DNSids and DNSdomains contain the id of the rednet server and the domain name you want, making sure that they are in the same corrispiding value in the array. So DNSids[1] should be matched with DNSdomains[1].

(note: if the DNS needs to connect to a relay to reach the rednet server put in the id for the relay)

DNSids = {201}
DNSdomains = {"www.test.com"}

If you are using Firebox and not the dectiacted server you will want this startup

shell.run("Firebox", "hostDNS")

Relay
The relay is option unless the computers are out of range of the DNS server. Simply run this command replacing DNS with the id of the DNServer.

shell.run("relay", "192.162.1.DNS")


Rednet server
Other then the modem you only need to do the following

Also you will want the home page to be the program ("http/index") and the this page is missing page to be ("http/error") on the server. It is simmler to a realy web site where in if you put a program called ("http/test") then people can get to it by typing rdnt://www.testwebsite.com/test like wise you could put in link with

shell.run(Firebox, "rdnt://www.testwebsite.com/test")
Not that above "link" will only work if that have a version of firebox that define the variable Firebox as the location of Firebox.
Zudo #29
Posted 21 May 2013 - 12:03 PM
Holy sh*t dude, use <quote></quote> (with square brackets, obviously) to enclose your many-lined code :P/>
Left4Cake #30
Posted 21 May 2013 - 04:23 PM
Holy sh*t dude, use <quote></quote> (with square brackets, obviously) to enclose your many-lined code :P/>

Yeah, when it first started it could all fit in a single screen, guess I let it go out of hand.