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:
Spoiler
1. Install the server or install firebox and use "Firebox/host" to run2. 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
Spoiler
1. 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
Spoiler
v0.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).