Skip to content

Commit

Permalink
Remove code execution functionality from admin2 (#453)
Browse files Browse the repository at this point in the history
  • Loading branch information
jlillis committed Nov 14, 2023
1 parent cca3a05 commit c4bc73a
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 65 deletions.
1 change: 0 additions & 1 deletion [admin]/admin2/admin_definitions.lua
Expand Up @@ -39,7 +39,6 @@ enum(
"EVENT_MESSAGE",
"EVENT_BANS",
"EVENT_NETWORK",
"EVENT_EXECUTE",
"EVENT_PROXY",
"EVENT_ADMIN_CHAT",
"EVENT_ADMIN_OPEN",
Expand Down
38 changes: 1 addition & 37 deletions [admin]/admin2/client/main/admin_resources.lua
Expand Up @@ -51,21 +51,11 @@ function aResourcesTab.Create(tab)
aResourcesTab.Description = guiCreateLabel(0.39, 0.23, 0.60, 0.10, "Description: -", true, aResourcesTab.MainTab)
guiLabelSetHorizontalAlign(aResourcesTab.Description, "left", true)
guiCreateHeader(0.38, 0.32, 0.20, 0.04, "Resource settings:", true, aResourcesTab.MainTab)
aResourcesTab.Settings = guiCreateGridList(0.38, 0.36, 0.61, 0.38, true, aResourcesTab.MainTab)
aResourcesTab.Settings = guiCreateGridList(0.38, 0.36, 0.61, 0.62, true, aResourcesTab.MainTab)
guiGridListAddColumn(aResourcesTab.Settings, "Name", 0.44)
guiGridListAddColumn(aResourcesTab.Settings, "Current", 0.24)
guiGridListAddColumn(aResourcesTab.Settings, "Default", 0.24)
guiGridListSetSortingEnabled(aResourcesTab.Settings, false)
guiCreateHeader(0.38, 0.75, 0.20, 0.04, "Execute code:", true, aResourcesTab.MainTab)
aResourcesTab.Command = guiCreateMemo(0.38, 0.80, 0.50, 0.18, "", true, aResourcesTab.MainTab)
guiHandleInput(aResourcesTab.Command)
aResourcesTab.ExecuteClient =
guiCreateButton(0.89, 0.80, 0.10, 0.04, "Client", true, aResourcesTab.MainTab, "execute")
aResourcesTab.ExecuteServer =
guiCreateButton(0.89, 0.85, 0.10, 0.04, "Server", true, aResourcesTab.MainTab, "execute")
aResourcesTab.ExecuteAdvanced =
guiCreateLabel(0.2, 0.4, 1.0, 0.50, "For advanced users only.", true, aResourcesTab.Command)
guiLabelSetColor(aResourcesTab.ExecuteAdvanced, 255, 0, 0)
-- EVENTS
addEventHandler(EVENT_SYNC, root, aResourcesTab.onClientSync)
Expand Down Expand Up @@ -167,32 +157,6 @@ function aResourcesTab.onClientClick(button)
elseif (source == aResourcesTab.ResourceRefresh) then
guiGridListClear(aResourcesTab.ResourceList)
sync(SYNC_RESOURCES)
elseif (source == aResourcesTab.ExecuteClient) then
local code = guiGetText(aResourcesTab.Command)
if ((code) and (code ~= "")) then
local results = {pcall(assert(loadstring("return " .. code)))}
if (results[1]) then
for i = 2, #results do
local value = results[i]
local type = type(value)
if (isElement(type)) then
type = getElementType(value)
end
outputChatBox((i - 1) .. ": " .. tostring(value) .. "[" .. type .. "]", 10, 220, 10)
end
else
outputChatBox("Error: " .. tostring(results[2]), 220, 10, 10)
end
end
elseif (source == aResourcesTab.ExecuteServer) then
local code = guiGetText(aResourcesTab.Command)
if ((code) and (code ~= "")) then
triggerServerEvent("aExecute", localPlayer, code, true)
end
elseif (source == aResourcesTab.Command) then
guiSetVisible(aResourcesTab.ExecuteAdvanced, false)
elseif (source == aResourcesTab.ExecuteAdvanced) then
guiSetVisible(aResourcesTab.ExecuteAdvanced, false)
elseif source == aResourcesTab.View then
local type = guiComboBoxGetItemText(source, source.selected)
if type == "All" then
Expand Down
27 changes: 0 additions & 27 deletions [admin]/admin2/server/admin_server.lua
Expand Up @@ -445,33 +445,6 @@ addEventHandler(
end
)
addEvent("aExecute", true)
addEventHandler(
"aExecute",
root,
function(action, echo)
if (hasObjectPermissionTo(source, "command.execute")) then
local result = loadstring("return " .. action)()
if (echo == true) then
local restring = ""
if (type(result) == "table") then
for k, v in pairs(result) do
restring = restring .. tostring(v) .. ", "
end
restring = string.sub(restring, 1, -3)
restring = "Table (" .. restring .. ")"
elseif (type(result) == "userdata") then
restring = "Element (" .. getElementType(result) .. ")"
else
restring = tostring(result)
end
outputChatBox("Command executed! Result: " .. restring, source, 0, 0, 255)
end
outputServerLog("ADMIN: " .. getPlayerName(source) .. " executed command: " .. action)
end
end
)
addEvent("aAdminChat", true)
addEventHandler(
"aAdminChat",
Expand Down

0 comments on commit c4bc73a

Please sign in to comment.