From a764a8a8a6989dc710986345b1a9eecfa3850aee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20N=C3=BCcke?= Date: Mon, 2 Dec 2013 17:17:49 +0100 Subject: [PATCH] trying to get a little bit of... structure into image names; cleaned up some shell stuff; added pastebin downloader --- assets/opencomputers/lang/de_DE.lang | 39 +++--- assets/opencomputers/lang/en_US.lang | 30 +++-- assets/opencomputers/lua/rom/bin/lua.lua | 2 +- assets/opencomputers/lua/rom/bin/pastebin.lua | 57 +++++++++ assets/opencomputers/lua/rom/lib/event.lua | 5 +- .../opencomputers/lua/rom/lib/filesystem.lua | 7 +- assets/opencomputers/lua/rom/lib/os.lua | 8 +- assets/opencomputers/lua/rom/lib/shell.lua | 116 +++++++++--------- .../items/{gpu0.png => card_graphics0.png} | Bin .../items/{gpu1.png => card_graphics1.png} | Bin .../items/{gpu2.png => card_graphics2.png} | Bin .../items/{lancard.png => card_lan.png} | Bin .../items/{rscard.png => card_redstone.png} | Bin .../items/{wlancard.png => card_wlan.png} | Bin .../{pcb.png => circuit_board_printed.png} | Bin ...ircuit_board.png => circuit_board_raw.png} | Bin assets/opencomputers/textures/items/disc.png | Bin 208 -> 0 bytes assets/opencomputers/textures/items/disk.png | Bin 508 -> 208 bytes .../textures/items/disk_floppy.png | Bin 0 -> 508 bytes .../items/{hdd0.png => disk_harddrive0.png} | Bin .../items/{hdd1.png => disk_harddrive1.png} | Bin .../items/{hdd2.png => disk_harddrive2.png} | Bin .../items/{arrow_keys.png => keys_arrow.png} | Bin .../{button_group.png => keys_group.png} | Bin .../items/{numpad.png => keys_numpad.png} | Bin .../textures/items/{ram0.png => memory0.png} | Bin .../textures/items/{ram1.png => memory1.png} | Bin .../textures/items/{ram2.png => memory2.png} | Bin .../items/{chipset0.png => microchip0.png} | Bin .../items/{chipset1.png => microchip1.png} | Bin .../items/{chipset2.png => microchip2.png} | Bin .../{crafting.png => upgrade_crafting.png} | Bin .../{generator.png => upgrade_generator.png} | Bin li/cil/oc/Items.scala | 18 +-- li/cil/oc/common/block/Case.scala | 7 +- li/cil/oc/common/block/Screen.scala | 7 +- li/cil/oc/common/item/Alu.scala | 2 +- li/cil/oc/common/item/ArrowKeys.scala | 2 +- li/cil/oc/common/item/ButtonGroup.scala | 2 +- .../item/{Card.scala => CardBase.scala} | 4 +- li/cil/oc/common/item/Crafting.scala | 2 +- .../oc/common/item/{Disc.scala => Disk.scala} | 6 +- li/cil/oc/common/item/FloppyDisk.scala | 2 +- li/cil/oc/common/item/Generator.scala | 2 +- li/cil/oc/common/item/GraphicsCard.scala | 4 +- li/cil/oc/common/item/HardDiskDrive.scala | 2 +- li/cil/oc/common/item/Memory.scala | 2 +- .../item/{Chip.scala => Microchip.scala} | 8 +- li/cil/oc/common/item/NetworkCard.scala | 2 +- li/cil/oc/common/item/Numpad.scala | 2 +- .../oc/common/item/PrintedCircuitBoard.scala | 2 +- li/cil/oc/common/item/RawCircuitBoard.scala | 2 +- li/cil/oc/common/item/RedstoneCard.scala | 2 +- .../oc/common/item/WirelessNetworkCard.scala | 2 +- .../component/WirelessNetworkCard.scala | 56 ++++++--- reference.conf | 10 +- 56 files changed, 245 insertions(+), 167 deletions(-) create mode 100644 assets/opencomputers/lua/rom/bin/pastebin.lua rename assets/opencomputers/textures/items/{gpu0.png => card_graphics0.png} (100%) rename assets/opencomputers/textures/items/{gpu1.png => card_graphics1.png} (100%) rename assets/opencomputers/textures/items/{gpu2.png => card_graphics2.png} (100%) rename assets/opencomputers/textures/items/{lancard.png => card_lan.png} (100%) rename assets/opencomputers/textures/items/{rscard.png => card_redstone.png} (100%) rename assets/opencomputers/textures/items/{wlancard.png => card_wlan.png} (100%) rename assets/opencomputers/textures/items/{pcb.png => circuit_board_printed.png} (100%) rename assets/opencomputers/textures/items/{raw_circuit_board.png => circuit_board_raw.png} (100%) delete mode 100644 assets/opencomputers/textures/items/disc.png create mode 100644 assets/opencomputers/textures/items/disk_floppy.png rename assets/opencomputers/textures/items/{hdd0.png => disk_harddrive0.png} (100%) rename assets/opencomputers/textures/items/{hdd1.png => disk_harddrive1.png} (100%) rename assets/opencomputers/textures/items/{hdd2.png => disk_harddrive2.png} (100%) rename assets/opencomputers/textures/items/{arrow_keys.png => keys_arrow.png} (100%) rename assets/opencomputers/textures/items/{button_group.png => keys_group.png} (100%) rename assets/opencomputers/textures/items/{numpad.png => keys_numpad.png} (100%) rename assets/opencomputers/textures/items/{ram0.png => memory0.png} (100%) rename assets/opencomputers/textures/items/{ram1.png => memory1.png} (100%) rename assets/opencomputers/textures/items/{ram2.png => memory2.png} (100%) rename assets/opencomputers/textures/items/{chipset0.png => microchip0.png} (100%) rename assets/opencomputers/textures/items/{chipset1.png => microchip1.png} (100%) rename assets/opencomputers/textures/items/{chipset2.png => microchip2.png} (100%) rename assets/opencomputers/textures/items/{crafting.png => upgrade_crafting.png} (100%) rename assets/opencomputers/textures/items/{generator.png => upgrade_generator.png} (100%) rename li/cil/oc/common/item/{Card.scala => CardBase.scala} (76%) rename li/cil/oc/common/item/{Disc.scala => Disk.scala} (75%) rename li/cil/oc/common/item/{Chip.scala => Microchip.scala} (58%) diff --git a/assets/opencomputers/lang/de_DE.lang b/assets/opencomputers/lang/de_DE.lang index cbfde9276..29561c878 100644 --- a/assets/opencomputers/lang/de_DE.lang +++ b/assets/opencomputers/lang/de_DE.lang @@ -2,9 +2,9 @@ oc:block.Adapter.name=Adapter oc:block.Cable.name=Kabel oc:block.Capacitor.name=Kondensator -oc:block.CaseAdvanced.name=Hochwertiges Gehäuse -oc:block.CaseBasic.name=Einfaches Gehäuse -oc:block.CaseProfessional.name=Professionelles Gehäuse +oc:block.Case0.name=Einfaches Gehäuse +oc:block.Case1.name=Hochwertiges Gehäuse +oc:block.Case2.name=Ausgezeichnetes Gehäuse oc:block.Charger.name=Ladestation oc:block.DiskDrive.name=Diskettenlaufwerk oc:block.Keyboard.name=Tastatur @@ -13,33 +13,37 @@ oc:block.PowerDistributor.name=Stromverteiler oc:block.Robot.name=Roboter oc:block.RobotAfterimage.name=Roboter oc:block.Router.name=Router -oc:block.ScreenAdvanced.name=Hochwertiger Bildschirm -oc:block.ScreenBasic.name=Einfacher Bildschirm -oc:block.ScreenProfessional.name=Professioneller Bildschirm +oc:block.Screen0.name=Einfacher Bildschirm +oc:block.Screen1.name=Hochwertiger Bildschirm +oc:block.Screen2.name=Ausgezeichneter Bildschirm # Items +oc:item.ALU.name=Arithmetisch-logische Einheit (ALU) oc:item.Analyzer.name=Messgerät -oc:item.ArithmeticLogicUnit.name=Arithmetisch-logische Einheit (ALU) oc:item.ArrowKeys.name=Pfeiltasten oc:item.ButtonGroup.name=Tastengruppe -oc:item.CircuitBoard.name=Basis Platte +oc:item.CardBase.name=Kartenbasis +oc:item.CircuitBoard.name=Leiterplatte oc:item.ControlUnit.name=Steuerwerk (CU) oc:item.CPU.name=Hauptprozessor (CPU) -oc:item.Card.name=Karte -oc:item.Crafting.name=Crafting +oc:item.Crafting.name=Crafting Upgrade oc:item.CuttingWire.name=Schneidedraht -oc:item.FloppyDisk.name=Diskette -oc:item.Generator.name=Generator -oc:item.GraphicsCardAdvanced.name=Hochwertige Grafikkarte -oc:item.GraphicsCardBasic.name=Einfache Grafikkarte -oc:item.GraphicsCardProfessional.name=Professionelle Grafikkarte +oc:item.Disk.name=Platte +oc:item.Floppy.name=Diskette +oc:item.Generator.name=Generator Upgrade +oc:item.GraphicsCard0.name=Einfache Grafikkarte +oc:item.GraphicsCard1.name=Hochwertige Grafikkarte +oc:item.GraphicsCard2.name=Ausgezeichnete Grafikkarte oc:item.HardDiskDrive.name=Festplatte oc:item.IronNugget.name=Eisennugget oc:item.Memory.name=Speicher +oc:item.Microchip0.name=Einfacher Microchip +oc:item.Microchip1.name=Hochwertiger Microchip +oc:item.Microchip2.name=Ausgezeichneter Microchip oc:item.NetworkCard.name=Netzwerkkarte oc:item.NumPad.name=Ziffernblock -oc:item.PrintedCircuitBoard.name=Leiterplatte (PCB) -oc:item.RawCircuitBoard.name=Rohe Basis Platte +oc:item.PrintedCircuitBoard.name=Gedruckte Leiterplatte (PCB) +oc:item.RawCircuitBoard.name=Leiterplattenrohling oc:item.RedstoneCard.name=Redstonekarte oc:item.Transistor.name=Transistor oc:item.WirelessNetworkCard.name=Drahtlosnetzwerkkarte @@ -52,6 +56,7 @@ oc:gui.Analyzer.RobotName=Name oc:gui.Analyzer.RobotOwner=Besitzer oc:gui.Analyzer.StoredEnergy=Gespeicherte Energie oc:gui.Analyzer.TotalEnergy=Insgesamt gespeicherte Energie +oc:gui.Analyzer.Users=Benutzer oc:gui.Robot.Power=Energie oc:gui.Robot.TurnOff=Ausschalten oc:gui.Robot.TurnOn=Einschalten diff --git a/assets/opencomputers/lang/en_US.lang b/assets/opencomputers/lang/en_US.lang index 273cf59fa..4a254cbe7 100644 --- a/assets/opencomputers/lang/en_US.lang +++ b/assets/opencomputers/lang/en_US.lang @@ -6,9 +6,9 @@ oc:block.Adapter.name=Adapter oc:block.Cable.name=Cable oc:block.Capacitor.name=Capacitor -oc:block.CaseAdvanced.name=Advanced Case -oc:block.CaseBasic.name=Basic Case -oc:block.CaseProfessional.name=Professional Case +oc:block.Case0.name=Basic Case +oc:block.Case1.name=Advanced Case +oc:block.Case2.name=Superior Case oc:block.Charger.name=Charger oc:block.DiskDrive.name=Disk Drive oc:block.Keyboard.name=Keyboard @@ -17,29 +17,33 @@ oc:block.PowerDistributor.name=Power Distributor oc:block.Robot.name=Robot oc:block.RobotAfterimage.name=Robot oc:block.Router.name=Router -oc:block.ScreenAdvanced.name=Advanced Screen -oc:block.ScreenBasic.name=Basic Screen -oc:block.ScreenProfessional.name=Professional Screen +oc:block.Screen0.name=Basic Screen +oc:block.Screen1.name=Advanced Screen +oc:block.Screen2.name=Superior Screen # Items +oc:item.ALU.name=Arithmetic Logic Unit (ALU) oc:item.Analyzer.name=Analyzer -oc:item.ArithmeticLogicUnit.name=Arithmetic Logic Unit (ALU) oc:item.ArrowKeys.name=Arrow Keys oc:item.ButtonGroup.name=Button Group +oc:item.CardBase.name=Card Base oc:item.CircuitBoard.name=Circuit Board oc:item.ControlUnit.name=Control Unit (CU) oc:item.CPU.name=Central Processing Unit (CPU) -oc:item.Card.name=Card -oc:item.Crafting.name=Crafting +oc:item.Crafting.name=Crafting Upgrade oc:item.CuttingWire.name=Cutting Wire +oc:item.Disk.name=Disk Platter oc:item.FloppyDisk.name=Floppy Disk -oc:item.Generator.name=Generator -oc:item.GraphicsCardAdvanced.name=Advanced Graphics Card -oc:item.GraphicsCardBasic.name=Basic Graphics Card -oc:item.GraphicsCardProfessional.name=Professional Graphics Card +oc:item.Generator.name=Generator Upgrade +oc:item.GraphicsCard0.name=Basic Graphics Card +oc:item.GraphicsCard1.name=Advanced Graphics Card +oc:item.GraphicsCard2.name=Superior Graphics Card oc:item.HardDiskDrive.name=Hard Disk Drive oc:item.IronNugget.name=Iron Nugget oc:item.Memory.name=Memory +oc:item.Microchip0.name=Simple Microchip +oc:item.Microchip1.name=Advanced Microchip +oc:item.Microchip2.name=Superior Microchip oc:item.NetworkCard.name=Network Card oc:item.NumPad.name=Numeric Keypad oc:item.PrintedCircuitBoard.name=Printed Circuit Board (PCB) diff --git a/assets/opencomputers/lua/rom/bin/lua.lua b/assets/opencomputers/lua/rom/bin/lua.lua index e77fdde4f..770903c9d 100644 --- a/assets/opencomputers/lua/rom/bin/lua.lua +++ b/assets/opencomputers/lua/rom/bin/lua.lua @@ -16,7 +16,7 @@ while term.isAvailable() do local expression = load("return " .. command, "=stdin", "t", env) local code = expression or statement if code then - local result = table.pack(shell.execute(code)) + local result = table.pack(pcall(code)) if not result[1] or result.n > 1 then print(table.unpack(result, 2, result.n)) end diff --git a/assets/opencomputers/lua/rom/bin/pastebin.lua b/assets/opencomputers/lua/rom/bin/pastebin.lua new file mode 100644 index 000000000..82766d634 --- /dev/null +++ b/assets/opencomputers/lua/rom/bin/pastebin.lua @@ -0,0 +1,57 @@ +local args, options = shell.parse(...) +if #args < 2 then + print("Usage: pastebin [-f] ") + print(" -f: Force overwriting existing files.") + return +end + +local m = component.modem +if not m or not m.isWireless() then + print("no primary wireless modem found") + return +end + +if not m.isHttpEnabled() then + print("http support is not enabled") + return +end + +local id = args[1] +local filename = shell.resolve(args[2]) + +if fs.exists(filename) then + if not options.f or not os.remove(filename) then + print("file already exists") + return + end +end + +local url = "http://pastebin.com/raw.php?i=" .. id +local result, reason = m.send(url) +if not result then + print("failed sending request: " .. reason) + return +end + +local f, reason = io.open(filename, "w") +if not f then + print("failed opening file for writing: " .. reason) + return +end + +repeat + local _, responseUrl, result, reason = event.pull("http_response") + if responseUrl == url then + if not result and reason then + print("failed fetching data: " .. reason) + f:close() + return + end + if result then + f:write(result) + end + end +until not result + +f:close() +print("saved data to " .. filename) diff --git a/assets/opencomputers/lua/rom/lib/event.lua b/assets/opencomputers/lua/rom/lib/event.lua index 76e3dd202..98391adea 100644 --- a/assets/opencomputers/lua/rom/lib/event.lua +++ b/assets/opencomputers/lua/rom/lib/event.lua @@ -1,4 +1,5 @@ local event, listeners, timers = {}, {}, {} +local lastInterrupt = -math.huge local function matches(signal, name, filter) if name and not (type(signal[1]) == "string" and signal[1]:match(name)) @@ -144,6 +145,7 @@ function event.pull(...) end tick() if event.shouldInterrupt() then + lastInterrupt = os.uptime() error("interrupted", 0) end if not (seconds or hasFilter) or matches(signal, name, filter) then @@ -153,7 +155,8 @@ function event.pull(...) end function event.shouldInterrupt() - return keyboard.isControlDown() and + return os.uptime() - lastInterrupt > 1 and + keyboard.isControlDown() and keyboard.isAltDown() and keyboard.isKeyDown(keyboard.keys.c) end diff --git a/assets/opencomputers/lua/rom/lib/filesystem.lua b/assets/opencomputers/lua/rom/lib/filesystem.lua index c45601f17..514d81a15 100644 --- a/assets/opencomputers/lua/rom/lib/filesystem.lua +++ b/assets/opencomputers/lua/rom/lib/filesystem.lua @@ -153,6 +153,11 @@ function filesystem.mount(fs, path) end end +function filesystem.path(path) + local parts = segments(path) + return table.concat(parts, "/", 1, #parts - 1) .. "/" +end + function filesystem.name(path) local parts = segments(path) return parts[#parts] @@ -410,7 +415,7 @@ local function onComponentAdded(_, address, componentType) name = filesystem.concat("/mnt", name) filesystem.mount(proxy, name) if isAutorunEnabled then - shell.execute(filesystem.concat(name, "autorun"), proxy) + os.execute(filesystem.concat(name, "autorun"), proxy) end end end diff --git a/assets/opencomputers/lua/rom/lib/os.lua b/assets/opencomputers/lua/rom/lib/os.lua index 1c7546ed5..a791765e3 100644 --- a/assets/opencomputers/lua/rom/lib/os.lua +++ b/assets/opencomputers/lua/rom/lib/os.lua @@ -18,15 +18,11 @@ os.execute = function(command) for part in tail:gmatch("%S+") do table.insert(args, part) end - return shell.execute(head, table.unpack(args)) + return shell.execute(head, _ENV, table.unpack(args)) end function os.exit() - local result, reason = shell.kill(coroutine.running()) - if result then - coroutine.yield() -- never returns - end - error(reason, 2) + error("terminated", 0) end os.remove = fs.remove diff --git a/assets/opencomputers/lua/rom/lib/shell.lua b/assets/opencomputers/lua/rom/lib/shell.lua index f2cdb8b67..2a2758492 100644 --- a/assets/opencomputers/lua/rom/lib/shell.lua +++ b/assets/opencomputers/lua/rom/lib/shell.lua @@ -1,8 +1,8 @@ local shell = {} local cwd = "/" local path = {"/bin/", "/usr/bin/", "/home/bin/"} -local aliases = {dir="ls", move="mv", rename="mv", copy="cp", del="rm", - md="mkdir", cls="clear", more="less", rs="redstone", +local aliases = {dir="ls", list="ls", move="mv", rename="mv", copy="cp", + del="rm", md="mkdir", cls="clear", more="less", rs="redstone", view="edit -r"} local running = {} @@ -77,65 +77,6 @@ function shell.setWorkingDirectory(dir) end end -function shell.execute(program, ...) - if type(program) ~= "function" then - local where, reason = shell.resolve(program, "lua") - if not where then - return nil, reason - end - local code, reason = loadfile(where, "t", setmetatable({}, {__index=_ENV})) - if not code then - return nil, reason - end - program = code - end - local co, args, result = coroutine.create(program), table.pack(true, ...), nil - running[co] = true - while running[co] and args[1] do - result = table.pack(coroutine.resume(co, table.unpack(args, 2, args.n))) - if coroutine.status(co) ~= "dead" then - -- Emulate CC behavior by making yields a filtered event.wait. - if type(result[2]) == "string" then - args = table.pack(pcall(event.pull, table.unpack(result, 2, result.n))) - else - args = {true, n=1} - end - else - break - end - end - running[co] = nil - if not args[1] then - return false, "interrupted" - end - return table.unpack(result, 1, result.n) -end - -function shell.kill(co) - if running[co] ~= nil then - running[co] = nil - return true - end - return nil, "not a program thread" -end - -function shell.parse(...) - local params = table.pack(...) - local args = {} - local options = {} - for i = 1, params.n do - local param = params[i] - if unicode.sub(param, 1, 1) == "-" then - for j = 2, unicode.len(param) do - options[unicode.sub(param, j, j)] = true - end - else - table.insert(args, param) - end - end - return args, options -end - function shell.getPath() return table.concat(path, ":") end @@ -170,6 +111,59 @@ function shell.resolve(path, ext) end end +function shell.execute(program, env, ...) + checkArg(1, program, "string") + local filename, reason = shell.resolve(program, "lua") + if not filename then + return nil, reason + end + local code, reason = loadfile(filename, "t", setmetatable({}, {__index=env})) + if not code then + return nil, reason + end + local co, args, result = coroutine.create(code), table.pack(true, ...), nil + table.insert(running, filename) + -- Emulate CC behavior by making yields a filtered event.pull() + repeat + result = table.pack(coroutine.resume(co, table.unpack(args, 2, args.n))) + if coroutine.status(co) == "dead" then + break + end + if type(result[2]) == "string" then + args = table.pack(pcall(event.pull, table.unpack(result, 2, result.n))) + else + args = {true, n=1} + end + until not args[1] + table.remove(running) + if not args[1] then + return false, args[2] + end + return table.unpack(result, 1, result.n) +end + +function shell.parse(...) + local params = table.pack(...) + local args = {} + local options = {} + for i = 1, params.n do + local param = params[i] + if unicode.sub(param, 1, 1) == "-" then + for j = 2, unicode.len(param) do + options[unicode.sub(param, j, j)] = true + end + else + table.insert(args, param) + end + end + return args, options +end + +function shell.running(level) + level = level or 1 + return running[1 + (#running - level)] +end + ------------------------------------------------------------------------------- _G.shell = shell diff --git a/assets/opencomputers/textures/items/gpu0.png b/assets/opencomputers/textures/items/card_graphics0.png similarity index 100% rename from assets/opencomputers/textures/items/gpu0.png rename to assets/opencomputers/textures/items/card_graphics0.png diff --git a/assets/opencomputers/textures/items/gpu1.png b/assets/opencomputers/textures/items/card_graphics1.png similarity index 100% rename from assets/opencomputers/textures/items/gpu1.png rename to assets/opencomputers/textures/items/card_graphics1.png diff --git a/assets/opencomputers/textures/items/gpu2.png b/assets/opencomputers/textures/items/card_graphics2.png similarity index 100% rename from assets/opencomputers/textures/items/gpu2.png rename to assets/opencomputers/textures/items/card_graphics2.png diff --git a/assets/opencomputers/textures/items/lancard.png b/assets/opencomputers/textures/items/card_lan.png similarity index 100% rename from assets/opencomputers/textures/items/lancard.png rename to assets/opencomputers/textures/items/card_lan.png diff --git a/assets/opencomputers/textures/items/rscard.png b/assets/opencomputers/textures/items/card_redstone.png similarity index 100% rename from assets/opencomputers/textures/items/rscard.png rename to assets/opencomputers/textures/items/card_redstone.png diff --git a/assets/opencomputers/textures/items/wlancard.png b/assets/opencomputers/textures/items/card_wlan.png similarity index 100% rename from assets/opencomputers/textures/items/wlancard.png rename to assets/opencomputers/textures/items/card_wlan.png diff --git a/assets/opencomputers/textures/items/pcb.png b/assets/opencomputers/textures/items/circuit_board_printed.png similarity index 100% rename from assets/opencomputers/textures/items/pcb.png rename to assets/opencomputers/textures/items/circuit_board_printed.png diff --git a/assets/opencomputers/textures/items/raw_circuit_board.png b/assets/opencomputers/textures/items/circuit_board_raw.png similarity index 100% rename from assets/opencomputers/textures/items/raw_circuit_board.png rename to assets/opencomputers/textures/items/circuit_board_raw.png diff --git a/assets/opencomputers/textures/items/disc.png b/assets/opencomputers/textures/items/disc.png deleted file mode 100644 index 09b989b92772a518f1f6a27db3764af8d9364193..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 208 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!63?wyl`GbL!WQl7;NpOBzNqJ&XDuZK6ep0G} zXKrG8YEWuoN@d~6R2!fop#Yx{*KgmxJ$(4^#EBE1KY!k_W5@sh|F3($PzK7fl?3?( z1G)eIGi=_!WIs^E$uA&&Xn5Q{B4If4w{-8-sN$i;C$K&n%#644$rjF6*2UngDxY BPcZ-h diff --git a/assets/opencomputers/textures/items/disk.png b/assets/opencomputers/textures/items/disk.png index 58cf5bafbcabd1c3d3332c0ff15ce4185b0126ec..09b989b92772a518f1f6a27db3764af8d9364193 100644 GIT binary patch delta 143 zcmV;A0C4~O1JD7GNq-VhOjJeo_V(f7;mF9y^Yin#xVZoS|JO_CBLDyZ26R$RQ~&?} z|Nj89zofqa002TsL_t(|+N_Q-5&$3w!%EQqf7t?qcg}W8$^qI>^iM3{3R5_l8o@xP x1g7ew%%CQwG=;f$m}&>CdxfD-uO9&h06Sd-BsG*tY5)KL00>D%PDHLkV1oBQLJI%@ delta 445 zcmcb>_=kCdXZ@l8pAgso|Nm=hYP!0*nwy*3+S)QOFhoT~xwyD!Yim0>IVB|}J$m#g zBO~L_pFf6%hW7UM|Ni~c*Vn&)|Ni60k5f}qO-xME)6?VP;vym=9UUE`BBKHV0z5oC z?%lg*Wo4zKqZ1k$YGY%Qm6i4P?_XzU=U=~m-M)Q0B_+k%yWac3g9pjU$;QUUnVFeC zfByXa`}eI|x6I7UG&D5s-o5MN;}aDb33T6*lb<#M-DOr1BY~dP~v<&_nYsZ13Zjwi7RpfToW0h z&Uv2;m-(w3-Ei--*#2AAjh*};*b#*m2H@CI51qw$+MY*`RXlrXbIXNXI zB|UodC?g}|&!0brhKBa`_W%C<)7RI(fB*jD$B$D}Q%y`v($mx9;^HDABOM(bqavdM z0s=fdJnr4QXJuujqoWfV8fs%>la-bA_wQe4XXjtPe%-!(J0&H>+uQrWg9pjU$;QUU znVFeCfByXa`}eI|x6I7UG&D5s-o5MN;}aDb33T3)lb<#Mon=-M context.signal("http_response", address, Unit, Option(e.getMessage).getOrElse(e.toString)) + case e: FileNotFoundException => + context.signal("http_response", address, Unit, "not found: " + Option(e.getMessage).getOrElse(e.toString)) + case e: Throwable => + context.signal("http_response", address, Unit, Option(e.getMessage).getOrElse(e.toString)) } }) result(true) @@ -111,20 +131,9 @@ class WirelessNetworkCard(val owner: TileEntity) extends NetworkCard { } } - private def isValidInternetRequest(address: String) = { + private def isHttpRequest(address: String) = { try { - val url = new URL(address) - val protocol = url.getProtocol - if (!protocol.matches("^https?$")) { - throw new Exception() - } - val host = Matcher.quoteReplacement(url.getHost) - if (Settings.get.httpHostWhitelist.length > 0 && !Settings.get.httpHostWhitelist.exists(host.matches)) { - throw new Exception() - } - if (Settings.get.httpHostBlacklist.exists(host.matches)) { - throw new Exception() - } + new URL(address) true } catch { @@ -132,6 +141,21 @@ class WirelessNetworkCard(val owner: TileEntity) extends NetworkCard { } } + private def checkAddress(address: String) { + val url = new URL(address) + val protocol = url.getProtocol + if (!protocol.matches("^https?$")) { + throw new FileNotFoundException("unsupported protocol") + } + val host = Matcher.quoteReplacement(url.getHost) + if (Settings.get.httpHostWhitelist.length > 0 && !Settings.get.httpHostWhitelist.exists(host.matches)) { + throw new FileNotFoundException("domain is not whitelisted") + } + if (Settings.get.httpHostBlacklist.exists(host.matches)) { + throw new FileNotFoundException("domain is blacklisted") + } + } + // ----------------------------------------------------------------------- // override def update() { diff --git a/reference.conf b/reference.conf index 6e8493b63..c467d5587 100644 --- a/reference.conf +++ b/reference.conf @@ -428,9 +428,9 @@ opencomputers { # All entries are regular expression patterns, but they will only be # applied to the host name (domain) of a given URL. blacklist: [ - "127\\.0\\.0\\.1" - "10\\.\\d+\\.\\d+\\.\\d+" - "192\\.\\d+\\.\\d+\\.\\d+" + "^127\\.0\\.0\\.1$" + "^10\\.\\d+\\.\\d+\\.\\d+$" + "^192\\.\\d+\\.\\d+\\.\\d+$" ] # This is a list of whitelisted domain names. Requests may only be made to @@ -441,8 +441,8 @@ opencomputers { # All entries are regular expression patterns, but they will only be # applied to the host name (domain) of a given URL. whitelist: [ - "gist\\.github\\.com" - "pastebin\\.com" + "^gist\\.github\\.com$" + "^(:?www\\.)?pastebin\\.com$" ] }