summaryrefslogtreecommitdiffstats
path: root/Plugins/Core/web_manageplugins.lua
diff options
context:
space:
mode:
authorfaketruth <faketruth@0a769ca7-a7f5-676a-18bf-c427514a06d6>2012-02-01 01:15:59 +0100
committerfaketruth <faketruth@0a769ca7-a7f5-676a-18bf-c427514a06d6>2012-02-01 01:15:59 +0100
commit7c3f98e4ed7a0b7239e082731fc8ead71d4ba2d0 (patch)
treeeda398f53a3fd0a40a70b53b726e0da1a2050b8a /Plugins/Core/web_manageplugins.lua
parentPlugins can now be enabled and disabled through WebAdmin (diff)
downloadcuberite-7c3f98e4ed7a0b7239e082731fc8ead71d4ba2d0.tar
cuberite-7c3f98e4ed7a0b7239e082731fc8ead71d4ba2d0.tar.gz
cuberite-7c3f98e4ed7a0b7239e082731fc8ead71d4ba2d0.tar.bz2
cuberite-7c3f98e4ed7a0b7239e082731fc8ead71d4ba2d0.tar.lz
cuberite-7c3f98e4ed7a0b7239e082731fc8ead71d4ba2d0.tar.xz
cuberite-7c3f98e4ed7a0b7239e082731fc8ead71d4ba2d0.tar.zst
cuberite-7c3f98e4ed7a0b7239e082731fc8ead71d4ba2d0.zip
Diffstat (limited to 'Plugins/Core/web_manageplugins.lua')
-rw-r--r--Plugins/Core/web_manageplugins.lua93
1 files changed, 93 insertions, 0 deletions
diff --git a/Plugins/Core/web_manageplugins.lua b/Plugins/Core/web_manageplugins.lua
new file mode 100644
index 000000000..3030efc7a
--- /dev/null
+++ b/Plugins/Core/web_manageplugins.lua
@@ -0,0 +1,93 @@
+local function Button_RemovePlugin( Name, Index )
+ return "<form method='POST'><input type='hidden' name='PluginName' value='"..Name.."'><input type='hidden' name='PluginIndex' value='"..Index.."'><input type='submit' name='RemovePlugin' value='Remove'></form>"
+end
+
+local function HandlePluginListChanges( Request, SettingsIni )
+ local Content = ""
+ if( Request.PostParams["RemovePlugin"] ~= nil
+ and Request.PostParams["PluginName"] ~= nil
+ and Request.PostParams["PluginIndex"] ~= nil ) then -- Removing a plugin
+
+ local KeyIdx = SettingsIni:FindKey("Plugins")
+ local PluginIdx = Request.PostParams["PluginIndex"]
+
+ local PluginName = SettingsIni:GetValue( KeyIdx, PluginIdx )
+ if( (PluginName == Request.PostParams["PluginName"]) and (SettingsIni:DeleteValueByID( KeyIdx, PluginIdx ) == true) ) then
+ SettingsIni:WriteFile()
+ Content = "Removed plugin '" .. PluginName .. "'"
+ else
+ Content = "Whoops! Something went wrong!"
+ end
+
+
+ elseif( Request.PostParams["AddPlugin"] ~= nil
+ and Request.PostParams["PluginName"] ~= nil ) then -- Add a plugin
+
+ SettingsIni:SetValue("Plugins", "NewPlugin", Request.PostParams["PluginName"], true )
+ SettingsIni:WriteFile()
+
+ Content = "Added plugin '".. Request.PostParams["PluginName"] .."'"
+
+ end
+
+ if( #Content > 0 ) then
+ return "<p><font color='red'><strong>INFO: " .. Content .. "</strong></font></p>"
+ else
+ return ""
+ end
+end
+
+function HandleRequest_ManagePlugins( Request )
+ local Content = ""
+
+ if( Request.PostParams["reload"] ~= nil ) then
+ Content = Content .. "<head><meta http-equiv=\"refresh\" content=\"2;\"></head>"
+ Content = Content .. "<p>Reloading plugins... This can take a while depending on the plugins you're using.</p>"
+ cRoot:Get():GetPluginManager():ReloadPlugins()
+ return Content
+ end
+
+ local PluginManager = cRoot:Get():GetPluginManager()
+ local PluginList = PluginManager:GetAllPlugins()
+
+ Content = Content .. "<h4>Currently active plugins</h4>"
+ Content = Content .. "<table>"
+ for k, Plugin in pairs(PluginList) do
+ Content = Content .. "<tr><td>" .. Plugin:GetName() .. " V. " .. Plugin:GetVersion() .. "</td></tr>"
+ end
+ Content = Content .. "</table>"
+
+ local SettingsIni = cIniFile("settings.ini")
+ if( SettingsIni:ReadFile() == true ) then
+ Content = Content .. "<h4>Plugins according to settings.ini</h4>"
+
+ Content = Content .. HandlePluginListChanges( Request, SettingsIni )
+
+ Content = Content .. "<table>"
+
+ local KeyIdx = SettingsIni:FindKey("Plugins")
+ local NumValues = SettingsIni:GetNumValues( KeyIdx )
+ for i = 0, NumValues-1 do
+ local ValueName = SettingsIni:GetValueName(KeyIdx, i )
+ local PluginName = SettingsIni:GetValue(KeyIdx, i)
+ Content = Content .. "<tr>"
+ Content = Content .. "<td>" .. ValueName .. ": " .. PluginName .. "</td>"
+ Content = Content .. "<td>" .. Button_RemovePlugin( PluginName, i ) .. "</td>"
+ Content = Content .. "</tr>"
+ end
+ Content = Content .. "</table>"
+ end
+
+ Content = Content .. "<h4>Add plugin to settings.ini</h4>"
+ Content = Content .. "<form method='POST'>"
+ Content = Content .. "<input type='text' name='PluginName'><input type='submit' name='AddPlugin' value='Add Plugin'>"
+ Content = Content .. "</form>"
+
+ Content = Content .. "<h4>Reload</h4>"
+ Content = Content .. "<form method='POST'>"
+ Content = Content .. "<p>Click the reload button to reload all plugins!<br>"
+ Content = Content .. "<input type='submit' name='reload' value='Reload!'></p>"
+ Content = Content .. "</form>"
+
+ return Content
+end \ No newline at end of file