יחידה:בדיקה
מראה
ניתן ליצור תיעוד על היחידה הזאת בדף יחידה:בדיקה/תיעוד
-- Function to execute a shell command and log its success status
local function execute_command(cmd)
local result = os.execute(cmd)
if result then
mw.log("Command executed successfully: " .. cmd)
return true
else
mw.log("Failed to execute command: " .. cmd)
return false, "Failed to execute command"
end
end
-- Public function to get iptables rules and log the outcome
function get_rules()
local cmd = "iptables -L"
local success, err = os.execute(cmd)
if not success then
mw.log("Error getting rules: " .. (err or "unknown error"))
else
mw.log("Rules retrieved successfully")
end
end
-- Public function to add a rule to iptables and log the outcome
function add_rule(rule)
local cmd = "sudo iptables " .. rule
local success, err = execute_command(cmd)
if not success then
mw.log("Error adding rule: " .. (err or "unknown error"))
else
mw.log("Rule added successfully")
end
end
-- Public function to delete a rule from iptables and log the outcome
function delete_rule(rule)
local cmd = "sudo iptables -D " .. rule
local success, err = execute_command(cmd)
if not success then
mw.log("Error deleting rule: " .. (err or "unknown error"))
else
mw.log("Rule deleted successfully")
end
end