2012-01-27 18:47:32 -05:00
|
|
|
local function HTMLDeleteButton( name )
|
2012-01-30 19:38:18 -05:00
|
|
|
return "<form method=\"POST\"><input type=\"hidden\" name=\"whitelist-delete\" value=\"".. name .."\"><input type=\"submit\" value=\"Remove from whitelist\"></form>"
|
2012-01-27 18:47:32 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
function HandleRequest_WhiteList( Request )
|
|
|
|
local UpdateMessage = ""
|
2012-01-30 19:38:18 -05:00
|
|
|
if( Request.PostParams:get("whitelist-add") ~= "" ) then
|
|
|
|
local PlayerName = Request.PostParams:get("whitelist-add")
|
2012-01-27 18:47:32 -05:00
|
|
|
|
|
|
|
if( WhiteListIni:GetValueB("WhiteList", PlayerName, false) == true ) then
|
|
|
|
UpdateMessage = "<b>".. PlayerName.."</b> is already on the whitelist"
|
|
|
|
else
|
|
|
|
WhiteListIni:SetValueB("WhiteList", PlayerName, true )
|
|
|
|
UpdateMessage = "Added <b>" .. PlayerName .. "</b> to whitelist."
|
|
|
|
WhiteListIni:WriteFile()
|
|
|
|
end
|
2012-01-30 19:38:18 -05:00
|
|
|
elseif( Request.PostParams:get("whitelist-delete") ~= "" ) then
|
|
|
|
local PlayerName = Request.PostParams:get("whitelist-delete")
|
2012-01-27 18:47:32 -05:00
|
|
|
WhiteListIni:DeleteValue( "WhiteList", PlayerName )
|
|
|
|
UpdateMessage = "Removed <b>" .. PlayerName .. "</b> from whitelist."
|
|
|
|
WhiteListIni:WriteFile()
|
2012-01-30 19:38:18 -05:00
|
|
|
elseif( Request.PostParams:get("whitelist-reload") ~= "" ) then
|
2012-01-27 18:47:32 -05:00
|
|
|
WhiteListIni:Erase() -- Empty entire loaded ini first, otherwise weird shit goes down
|
|
|
|
WhiteListIni:ReadFile()
|
|
|
|
UpdateMessage = "Loaded from disk"
|
|
|
|
elseif( Request.Params:get("whitelist-setenable") ~= "" ) then
|
|
|
|
local Enabled = Request.Params:get("whitelist-setenable");
|
|
|
|
local CreateNewValue = false;
|
|
|
|
if( WhiteListIni:FindValue( WhiteListIni:FindKey("WhiteListSettings"), "WhiteListOn" ) == cIniFile.noID ) then -- Find out whether the value is in the ini
|
|
|
|
CreateNewValue = true
|
|
|
|
end
|
|
|
|
|
|
|
|
if( Enabled == "1" ) then
|
|
|
|
WhiteListIni:SetValueB("WhiteListSettings", "WhiteListOn", true, CreateNewValue )
|
|
|
|
else
|
|
|
|
WhiteListIni:SetValueB("WhiteListSettings", "WhiteListOn", false, CreateNewValue )
|
|
|
|
end
|
|
|
|
WhiteListIni:WriteFile()
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
local Content = ""
|
|
|
|
|
|
|
|
local WhiteListEnabled = WhiteListIni:GetValueB("WhiteListSettings", "WhiteListOn", false)
|
|
|
|
if( WhiteListEnabled == false ) then
|
|
|
|
Content = Content .. "<p>Whitelist is currently disabled! Click <a href='?whitelist-setenable=1'>here</a> to enable.</p>"
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
Content = Content .. "<h4>Whitelisted players</h4>"
|
|
|
|
Content = Content .. "<table>"
|
|
|
|
local KeyNum = WhiteListIni:FindKey("WhiteList")
|
|
|
|
local NumValues = WhiteListIni:GetNumValues(KeyNum)
|
|
|
|
if( NumValues > 0 ) then
|
|
|
|
for Num = 0, NumValues-1 do
|
|
|
|
if( WhiteListIni:GetValue(KeyNum, Num, "0") == "1" ) then
|
|
|
|
local PlayerName = WhiteListIni:GetValueName(KeyNum, Num )
|
|
|
|
Content = Content .. "<tr><td>" .. PlayerName .. "</td><td>" .. HTMLDeleteButton( PlayerName ) .. "</td></tr>"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
else
|
|
|
|
Content = Content .. "<tr><td>None</td></tr>"
|
|
|
|
end
|
|
|
|
Content = Content .. "</table>"
|
|
|
|
Content = Content .. "<br><h4>Add player to whitelist</h4>"
|
2012-01-30 19:38:18 -05:00
|
|
|
Content = Content .. "<form method=\"POST\">"
|
2012-01-27 18:47:32 -05:00
|
|
|
Content = Content .. "<input type=\"text\" name=\"whitelist-add\"><input type=\"submit\" value=\"Add player\">"
|
|
|
|
Content = Content .. "</form>"
|
2012-01-30 19:38:18 -05:00
|
|
|
Content = Content .. "<form method=\"POST\">"
|
2012-01-27 18:47:32 -05:00
|
|
|
Content = Content .. "<input type=\"submit\" name=\"whitelist-reload\" value=\"Reload from disk\">"
|
|
|
|
Content = Content .. "</form>"
|
|
|
|
Content = Content .. "<br>"..UpdateMessage
|
|
|
|
|
|
|
|
if( WhiteListEnabled == true ) then
|
|
|
|
Content = Content .. "<br><br><p>Whitelist is currently enabled, click <a href='?whitelist-setenable=0'>here</a> to disable.</p>"
|
|
|
|
end
|
|
|
|
|
|
|
|
return Content
|
|
|
|
end
|