Guest User

Computercraft sandBox

a guest
Apr 17th, 2013
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.06 KB | None | 0 0
  1.  
  2. --Lists
  3. local BlackList = {}
  4. local WhiteList = {}
  5.  
  6. --Securety Functions
  7. local FS_oldOpen = fs.open
  8. local FS_oldDelete = fs.delete
  9. local FS_oldCopy = fs.copy
  10. local FS_oldMove = fs.move
  11. local FS_oldMakeDir = fs.makeDir
  12. local IO_oldOpen = io.open
  13. local OS_oldLoadApit = os.loadAPI
  14. local OS_oldUnloadApi = os.unloadAPI
  15. local OS_oldShutdown = os.shutdown
  16. local OS_oldReboot = os.reboot
  17. local OS_oldSleep = os.sleep
  18. local OS_oldRun = os.run
  19. --local SHELL_oldSetDir = shell.setDir
  20. local SHELL_oldSetAlias = shell.setAlias
  21. local SHELL_oldClearAlias = shell.clearAlias
  22. local SHELL_oldRun = shell.run
  23. local SHELL_oldExit = shell.exit
  24.  
  25. fs.open = function(file, mode)
  26.     programName = shell.getRunningProgram()
  27.     slc, saveslc = drawWarningScreen("Securety Break!", programName, "fs.open()")
  28.     if slc == 0 then -- Allow
  29.         if saveslc == true then --Save
  30.             addWhitelist(programName)
  31.         end
  32.         FS_oldOpen(file,mode)  
  33.     else -- Deny
  34.         if saveslc == true then--Save
  35.             addBlacklist(programName)
  36.         end
  37.     end
  38. end
  39.  
  40. fs.delete = function(file)
  41.     noResponse = true
  42.     programName = shell.getRunningProgram()
  43.     while noResponse == true do
  44.    
  45.     end
  46. end
  47.  
  48. fs.copy = function(file1, file2)
  49.     noResponse = true
  50.     programName = shell.getRunningProgram()
  51.     while noResponse == true do
  52.    
  53.     end
  54. end
  55.  
  56. fs.move = function(file1, file2)
  57.     noResponse = true
  58.     programName = shell.getRunningProgram()
  59.     while noResponse == true do
  60.    
  61.     end
  62. end
  63.  
  64. fs.makeDir = function(dir)
  65.     noResponse = true
  66.     programName = shell.getRunningProgram()
  67.     while noResponse == true do
  68.    
  69.     end
  70. end
  71.  
  72. io.open = function(file, mode)
  73.     noResponse = true
  74.     programName = shell.getRunningProgram()
  75.     while noResponse == true do
  76.    
  77.     end
  78. end
  79.  
  80. os.loadAPI = function(file)
  81.     noResponse = true
  82.     programName = shell.getRunningProgram()
  83.     while noResponse == true do
  84.    
  85.     end
  86. end
  87.  
  88. os.unloadAPI = function(file)
  89.     noResponse = true
  90.     programName = shell.getRunningProgram()
  91.     while noResponse == true do
  92.    
  93.     end
  94. end
  95.  
  96. os.shutdown = function()
  97.     noResponse = true
  98.     programName = shell.getRunningProgram()
  99.     while noResponse == true do
  100.    
  101.     end
  102. end
  103.  
  104. os.reboot = function()
  105.     noResponse = true
  106.     programName = shell.getRunningProgram()
  107.     while noResponse == true do
  108.    
  109.     end
  110. end
  111.  
  112. os.sleep = function(sec)
  113.     noResponse = true
  114.     programName = shell.getRunningProgram()
  115.     while noResponse == true do
  116.    
  117.     end
  118. end
  119.  
  120. os.run = function(_sCommand, ...)
  121.     noResponse = true
  122.     programName = shell.getRunningProgram()
  123.     while noResponse == true do
  124.    
  125.     end
  126. end
  127.  
  128. shell.setDir = function(dir)
  129.     noResponse = true
  130.     programName = shell.getRunningProgram()
  131.     while noResponse == true do
  132.    
  133.     end
  134. end
  135.  
  136. shell.setAlias = function(file, name)
  137.     noResponse = true
  138.     programName = shell.getRunningProgram()
  139.     while noResponse == true do
  140.    
  141.     end
  142. end
  143.  
  144. shell.clearAlias = function()
  145.     noResponse = true
  146.     programName = shell.getRunningProgram()
  147.     while noResponse == true do
  148.    
  149.     end
  150. end
  151.  
  152. shell.run = function(_sCommand, ...)
  153.     noResponse = true
  154.     programName = shell.getRunningProgram()
  155.     while noResponse == true do
  156.    
  157.     end
  158. end
  159. shell.exit = function()
  160.  
  161. end
  162.  
  163. --sandbox Functions
  164.  
  165. function drawWarningScreen(title, name, command)
  166.     slc = 0
  167.     response = false
  168.     saveslc = false
  169.     width, height = term.getSize()
  170.     while response == false do
  171.         --Window
  172.         term.setCursorPos((width / 2) - (30 / 2), (height / 2) - (12 / 2) + 0)
  173.         print("+-----------------------------+")
  174.         term.setCursorPos((width / 2) - (30 / 2), (height / 2) - (12 / 2) + 1)
  175.         print("|                             |")
  176.         term.setCursorPos((width / 2) - (30 / 2), (height / 2) - (12 / 2) + 2)
  177.         print("|                             |")
  178.         term.setCursorPos((width / 2) - (30 / 2), (height / 2) - (12 / 2) + 3)
  179.         print("|                             |")
  180.         term.setCursorPos((width / 2) - (30 / 2), (height / 2) - (12 / 2) + 4)
  181.         print("|                             |")
  182.         term.setCursorPos((width / 2) - (30 / 2), (height / 2) - (12 / 2) + 5)
  183.         print("|                             |")
  184.         term.setCursorPos((width / 2) - (30 / 2), (height / 2) - (12 / 2) + 6)
  185.         print("|                             |")
  186.         term.setCursorPos((width / 2) - (30 / 2), (height / 2) - (12 / 2) + 7)
  187.         print("|                             |")
  188.         term.setCursorPos((width / 2) - (30 / 2), (height / 2) - (12 / 2) + 8)
  189.         print("|                             |")
  190.         term.setCursorPos((width / 2) - (30 / 2), (height / 2) - (12 / 2) + 9)
  191.         print("|                             |")
  192.         term.setCursorPos((width / 2) - (30 / 2), (height / 2) - (12 / 2) + 10)
  193.         print("|                             |")
  194.         term.setCursorPos((width / 2) - (30 / 2), (height / 2) - (12 / 2) + 11)
  195.         print("+-----------------------------+")
  196.        
  197.         --Window Content
  198.         term.setCursorPos((width / 2) - (30 / 2) + 1, (height / 2) - (12 / 2) + 0)
  199.         print(title)
  200.         term.setCursorPos((width / 2) - (30 / 2) + 1, (height / 2) - (12 / 2) + 2)
  201.         print("The program: ".. resolveProgrammName(name))
  202.         term.setCursorPos((width / 2) - (30 / 2) + 1, (height / 2) - (12 / 2) + 3)
  203.         print("Trye'd to run: ".. command)
  204.        
  205.         if slc == 0 then
  206.             term.setCursorPos((width / 2) - (30 / 2) + 1, (height / 2) - (12 / 2) + 9)
  207.             print("[Allow] Deny ")
  208.         elseif slc == 1 then
  209.             term.setCursorPos((width / 2) - (30 / 2) + 1, (height / 2) - (12 / 2) + 9)
  210.             print(" Allow [Deny]")
  211.         else
  212.         end
  213.        
  214.             term.setCursorPos((width / 2) - (30 / 2) + 1, (height / 2) - (12 / 2) + 10)
  215.             if saveslc == true then
  216.                 print("(X) Save Selection")
  217.             else
  218.                 print("( ) Save Selection")
  219.             end
  220.        
  221.         event, param =  os.pullEventRaw("key")
  222.        
  223.         if param == 203 then --Links
  224.             if slc <= 1 then
  225.                 slc = slc - 1
  226.             end    
  227.         elseif param == 205 then --Rechts
  228.             if slc >= 0 then
  229.                 slc = slc + 1
  230.             end
  231.         elseif param == 28 then --Eingabe
  232.             response = true
  233.         elseif param == 57 then
  234.             if saveslc == true then
  235.                 saveslc = false
  236.             else
  237.                 saveslc = true
  238.             end
  239.         else
  240.         end
  241.        
  242.     end
  243.    
  244.     return slc , saveslc
  245. end
  246.  
  247. resolveProgrammName = function(path)
  248.     arr = split(path, "/")
  249.     return arr[#arr]
  250. end
  251.  
  252. function split(str, pat)
  253.    local t = {}  -- NOTE: use {n = 0} in Lua-5.0
  254.    local fpat = "(.-)" .. pat
  255.    local last_end = 1
  256.    local s, e, cap = str:find(fpat, 1)
  257.    while s do
  258.       if s ~= 1 or cap ~= "" then
  259.      table.insert(t,cap)
  260.       end
  261.       last_end = e+1
  262.       s, e, cap = str:find(fpat, last_end)
  263.    end
  264.    if last_end <= #str then
  265.       cap = str:sub(last_end)
  266.       table.insert(t, cap)
  267.    end
  268.    return t
  269. end
  270.  
  271. addBlacklist = function(file)
  272.     exists = false
  273.     for i, v in pairs(BlackList) do
  274.         if v == file then
  275.             exists = true
  276.         end
  277.     end
  278.     if exists == false then
  279.         table.insert(BlackList, file)
  280.     end
  281.     saveBlacklist(".SandBox/Blacklist.db")
  282. end
  283.  
  284. saveBlacklist = function(file)
  285.  
  286. end
  287.  
  288. loadBlacklist = function(file)
  289.  
  290. end
  291.  
  292. addWhitelist = function(file)
  293.     exists = false
  294.     for i, v in pairs(WhiteList) do
  295.         if v == file then
  296.             exists = true
  297.         end
  298.     end
  299.     if exists == false then
  300.         table.insert(WhiteList, file)
  301.     end
  302.     saveBlacklist(".SandBox/Whitelist.db")
  303. end
  304.  
  305. saveWhitelist = function(file)
  306.  
  307. end
  308.  
  309. loadWhitelist = function(file)
  310.  
  311. end
Advertisement
Add Comment
Please, Sign In to add comment