Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- ndisk_terminal.lua
- -- Admin Terminal for NDisk
- -- Run this ON THE SERVER to manually manage files.
- -- It shares the same API instance (and chunklocation.txt) that the server uses.
- -- Try to use global ndisk if available (when running in server's multishell)
- -- Otherwise load it ourselves
- local ndisk = _G.ndisk or dofile("ndisk_api.lua")
- print("NDisk Admin Terminal")
- print("Loading API...")
- if not _G.ndisk then
- ndisk.init()
- end
- local function printHelp()
- print("Available commands:")
- print(" list [path] - List files")
- print(" read <path> - Read a file")
- print(" write <path> - Write a file (manual input)")
- print(" delete <path> - Delete a file")
- print(" space - Show free space")
- print(" nodes - Rediscover/Show nodes")
- print(" help - Show this menu")
- print(" exit - Exit terminal")
- end
- print("Ready. Type 'help' for commands.")
- while true do
- write("ndisk> ")
- local input = read()
- local command = {}
- for word in input:gmatch("%S+") do
- table.insert(command, word)
- end
- local cmd = command[1]
- local arg1 = command[2]
- if cmd == "list" then
- local path = arg1 or ""
- local items = ndisk.list(path)
- print("Listing '"..path.."':")
- if #items == 0 then print(" (No files found)") end
- for _, item in ipairs(items) do
- print(" " .. item)
- end
- elseif cmd == "read" and arg1 then
- local content, err = ndisk.read(arg1)
- if content then
- print("--- BEGIN FILE ---")
- print(content)
- print("--- END FILE ---")
- else
- print("Error: " .. (err or "Unknown error"))
- end
- elseif cmd == "write" and arg1 then
- print("Enter content for '"..arg1.."' (Type 'EOF' on a new line to finish):")
- local content = ""
- while true do
- local line = read()
- if line == "EOF" then break end
- content = content .. line .. "\n"
- end
- local success, err = ndisk.write(arg1, content)
- if success then
- print("File written successfully.")
- else
- print("Error: " .. (err or "Unknown error"))
- end
- elseif cmd == "delete" and arg1 then
- print("Deleting '"..arg1.."'...")
- local success, err = ndisk.delete(arg1)
- if success then
- print("Deleted.")
- else
- print("Error: " .. (err or "Unknown error"))
- end
- elseif cmd == "space" then
- local space = ndisk.getFreeSpace()
- print("Total Cluster Free Space: " .. space .. " bytes")
- elseif cmd == "nodes" then
- print("Refreshing node list...")
- -- ndisk.init() triggers discovery if needed, but we can force it
- -- if we expose a refresh function.
- -- If ndisk_api doesn't expose refresh, we just re-init or accept current state.
- -- Assuming standard usage:
- print("Nodes are managed automatically by the API.")
- elseif cmd == "help" then
- printHelp()
- elseif cmd == "exit" then
- break
- else
- print("Unknown command.")
- printHelp()
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment