Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- dofile("tab2file") -- 2 new functions to write and read ini-like files
- cls = function()
- term.clear()
- term.setCursorPos(1,1)
- end
- main = function()
- cls()
- if fs.exists("sec.config") then
- sec = file2tab("sec.config")
- else
- sec = {}
- sec.open = 1
- sec.shutdown = 1
- sec.net = 0
- tab2file(sec,"sec.config")
- end
- print("1. Browse\n2. Security\n3. Exit")
- local ans = read()
- if ans == "1" then
- return browser()
- elseif ans == "2" then
- return security()
- elseif ans == "3" then
- return
- else
- return main()
- end
- end
- security = function()
- cls()
- print("1. File opening: "..tonumber(sec.file))
- print("2. Shutdown: "..tonumber(sec.shutdown))
- print("3. Rednet access: "..tonumber(sec.net))
- print("4. Exit")
- local num = {sec.file, sec.shutdown, sec.net}
- local ans = tonumber(read())
- if num[ans] then
- if sec[ans] == 1 then
- sec[ans] = 0
- else
- sec[ans] = 1
- end
- tab2file(sec,"sec.config")
- return security()
- elseif ans == 4 then
- return main()
- else
- return security()
- end
- end
- browser = function()
- write("URL: ")
- local ans = read()
- sleep(1)
- _,_,id = string.find(ans, "^(%d+)$")
- if id == nil then
- _,_,id,path = string.find(ans, "^(%d+)/([/%w]+)$")
- else
- path = ""
- end
- if id == nil then
- print("Incorrect request")
- sleep(1)
- cls()
- return browser()
- end
- rednet.send(tonumber(id),path)
- _, mes = rednet.receive()
- file = fs.open("page.tmp","w")
- file.write(mes)
- file.close()
- sec = file2tab("sec.config")
- local old = {}
- old.open = fs.open
- old.shutdown = os.shutdown
- old.reboot = os.reboot
- old.send = rednet.send
- old.broadcast = rednet.broadcast
- old.pullEventRaw = os.pullEventRaw
- old.write = term.write
- local restore = function()
- fs.open = old.open
- os.shutdown = old.shutdown
- os.reboot = old.reboot
- rednet.send = old.send
- rednet.broadcast = old.broadcast
- os.pullEventRaw = old.pullEventRaw
- term.write = old.write
- end
- local l_error = error -- backup of error() for confirmation
- if sec.file == 1 then
- local firstfile = true -- for "page.tmp" opening in dofile()
- fs.open = function(file,mode)
- if firstfile == false then
- print("Attempt to open file "..file.." at mode "..mode..". Proceed?")
- if read() == "y" then
- return old.open(file,mode)
- else
- return nil
- end
- else
- firstfile = false
- return old.open(file,mode)
- end
- end
- end
- if sec.shutdown == 1 then
- os.shutdown = function()
- print("Attempt to shutdown host. Emergency exit.")
- if l_error ~= error then
- print("ATTEMPT TO BYPASS EMERGENCY EXIT SYSTEM! IMMEDIATE EXIT!")
- error = l_error
- error("security breach attempt")
- end
- error("shutdown attempt")
- end
- os.reboot = function()
- print("Attempt to reboot system. Emergency exit.")
- if l_error ~= error then
- print("ATTEMPT TO BYPASS EMERGENCY EXIT SYSTEM! IMMEDIATE EXIT!")
- error = l_error
- error("security breach attempt")
- end
- error("reboot attempt")
- end
- end
- if sec.net == 1 then
- rednet.send = function(id,mes)
- print("Attempt to send rednet message \""..mes.."\" to host "..tostring(id)..". Proceed?")
- if read() == "y" then
- return old.send(id,mes)
- else
- return nil
- end
- end
- rednet.broadcast = function(mes)
- print("Attempt to send rednet message \""..mes.."\" to broadcasting channel. Proceed?")
- if read() == "y" then
- return old.broadcast(mes)
- else
- return nil
- end
- end
- end
- os.pullEventRaw = function(type)
- if l_error ~= error then
- print("ATTEMPT TO BYPASS EMERGENCY EXIT SYSTEM! IMMEDIATE EXIT!")
- error = l_error
- error("security breach attempt")
- end
- if type == nil then
- res = {old.pullEventRaw()}
- if res[1] == "key" and res[2] == 59 then
- error("break key pressed")
- end
- return unpack(res)
- else
- while true do
- res = {old.pullEventRaw()}
- if res[1] == "key" and res[2] == 59 then
- error("break key pressed")
- end
- if res[1] == type then
- return unpack(res)
- end
- end
- end
- end
- local save = ""
- term.write = function(text)
- save = save..text
- old.write(text)
- end
- local getSave = function()
- return save
- end
- k, mes = pcall(function() dofile("page.tmp") end)
- restore()
- print()
- if k == true then
- print("Program exited correctly.")
- else
- print("Performed emergency exit because of error.")
- print("Error message: "..tostring(mes))
- end
- print("Press E to exit, S to save page and exit")
- while true do
- local c
- _, c = os.pullEventRaw("char")
- if c == "e" then
- break
- elseif c == "s" then
- print("Enter file name: ")
- path = read()
- file = fs.open(path,"w")
- file.write(getSave())
- file.close()
- print("Saved")
- break
- end
- end
- return main()
- end
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement