From 983d87e44356c4cfc8f8908ec365006323a4dbe0 Mon Sep 17 00:00:00 2001 From: Alexander Harkness Date: Sat, 27 Jul 2013 16:24:03 +0100 Subject: Added correct core plugin --- MCServer/Plugins/Core/web_manageplugins.lua | 157 ++++++++++++++++++++++++++++ 1 file changed, 157 insertions(+) create mode 100644 MCServer/Plugins/Core/web_manageplugins.lua (limited to 'MCServer/Plugins/Core/web_manageplugins.lua') diff --git a/MCServer/Plugins/Core/web_manageplugins.lua b/MCServer/Plugins/Core/web_manageplugins.lua new file mode 100644 index 000000000..543638183 --- /dev/null +++ b/MCServer/Plugins/Core/web_manageplugins.lua @@ -0,0 +1,157 @@ +local function Button_RemovePlugin( Name, Index ) + return "
" +end + +local function Button_EnablePlugin( Name ) + return [[
]] +end + +local function Button_DisablePlugin( Name ) + return [[
]] +end + +local function FindPluginID( SettingsIni, PluginName ) + local KeyIdx = SettingsIni:FindKey("Plugins") + local NumValues = SettingsIni:GetNumValues( KeyIdx ) + + for i = 0, NumValues-1 do + LOGINFO( SettingsIni:GetValue(KeyIdx, i) ) + if( SettingsIni:GetValue(KeyIdx, i) == PluginName ) then + return i + end + end + + return nil +end + +local function RemovePluginFromIni( SettingsIni, PluginName ) + local KeyIdx = SettingsIni:FindKey("Plugins") + local PluginIdx = FindPluginID( SettingsIni, PluginName ) + + if( PluginIdx == nil ) then + LOGINFO("Got nil! NOOOO") + return false + end + + local Name = SettingsIni:GetValue( KeyIdx, PluginIdx ) + if( Name ~= PluginName ) then + LOGINFO("not the same name T_T '" .. Name .. "' '" .. PluginName .. "'") + end + if( (Name == PluginName) and (SettingsIni:DeleteValueByID( KeyIdx, PluginIdx ) == true) ) then + return SettingsIni:WriteFile() + end + + return false +end + +local function AddPluginToIni( SettingsIni, PluginName ) + RemovePluginFromIni( SettingsIni, PluginName ) -- Make sure there are no duplicates + + if( SettingsIni:SetValue("Plugins", "Plugin", PluginName, true ) == true ) then + return SettingsIni:WriteFile() + end + + return false +end + +local function HandlePluginListChanges( Request, SettingsIni ) + local Content = "" + + if( Request.PostParams["EnablePlugin"] ~= nil + and Request.PostParams["PluginName"] ~= nil ) then + + local PluginName = Request.PostParams["PluginName"] + + local PM = cRoot:Get():GetPluginManager() + if( PM:LoadPlugin( PluginName ) == false ) then + Content = "Could not enable '".. PluginName .."'!" + end + + if( AddPluginToIni( SettingsIni, PluginName ) == true ) then + Content = "Enabled plugin '".. PluginName .."'" + else + Content = "Enabled plugin '".. PluginName .."' but could not add it to settings.ini" + end + + + elseif( Request.PostParams["DisablePlugin"] ~= nil + and Request.PostParams["PluginName"] ~= nil ) then + + local PluginName = Request.PostParams["PluginName"] + + local PM = cRoot:Get():GetPluginManager() + PM:DisablePlugin( PluginName ) + + if( RemovePluginFromIni( SettingsIni, PluginName ) == true ) then + Content = "Disabled plugin '".. PluginName .."'" + else + Content = "Disabled plugin '".. PluginName .."' but could not remove it from settings.ini" + end + + + + end + + if( #Content > 0 ) then + return "

INFO: " .. Content .. "

" + else + return "" + end +end + +function HandleRequest_ManagePlugins( Request ) + local Content = "" + + if( Request.PostParams["reload"] ~= nil ) then + Content = Content .. "" + Content = Content .. "

Reloading plugins... This can take a while depending on the plugins you're using.

" + cRoot:Get():GetPluginManager():ReloadPlugins() + return Content + end + + local SettingsIni = cIniFile("settings.ini") + if( SettingsIni:ReadFile() == true ) then + Content = Content .. HandlePluginListChanges( Request, SettingsIni ) + else + Content = Content .. "Cannot find/modify settings.ini" + end + + local PluginManager = cRoot:Get():GetPluginManager() + PluginManager:FindPlugins() -- Refreshes the plugin list + local PluginList = PluginManager:GetAllPlugins() + + Content = Content .. "

Currently installed plugins

" + Content = Content .. "" + ActivePluginsName = {} + ActivePluginVersion = {} + InactivePlugins = {} + for k, Plugin in pairs(PluginList) do + if( Plugin ) then + table.insert( ActivePluginsName, k ) + table.insert( ActivePluginVersion, Plugin:GetVersion() ) + else + table.insert( InactivePlugins, k ) + end + end + table.sort( ActivePluginsName ) + table.sort( InactivePlugins ) + for i = 1, #ActivePluginsName do + Content = Content .. "" + Content = Content .. "" + Content = Content .. "" + end + for i = 1, #InactivePlugins do + Content = Content .. "" + Content = Content .. "" + Content = Content .. "" + end + Content = Content .. "
".. ActivePluginsName[i] .."" .. ActivePluginsName[i] .. " V. " .. ActivePluginVersion[i] .. "" .. Button_DisablePlugin(ActivePluginsName[i]) .. "
".. InactivePlugins[i] .."" .. Button_EnablePlugin(InactivePlugins[i]) .. "
" + + Content = Content .. "

Reload

" + Content = Content .. "
" + Content = Content .. "

Click the reload button to reload all plugins according to settings.ini!" + Content = Content .. "

" + Content = Content .. "
" + + return Content +end \ No newline at end of file -- cgit v1.2.3