[WEB] Show plugin permissions
#7
(10-08-2015, 07:09 AM)xoft Wrote: Heh, the web handler structure seems familiar, I suppose You cloned it off one of my plugins - Gallery, GalExport, or my additions to the Core? Smile

heh, yeah. I was lazy & tierd at that time, sorryTongue And thanks for the warm welcome Smile


(10-08-2015, 06:17 AM)NiLSPACE Wrote:
cPluginManager:ForEachPlugin(
	function(a_Plugin)
		if (not cFile:Exists(a_Plugin:GetLocalFolder() .. "/Info.lua")) then
			-- The plugin doesn\'t have a Info.lua file
			return false
		end
		
		local PluginInfoLoader = loadfile(a_Plugin:GetLocalFolder() .. "/Info.lua")
		local LoaderEnv = {}
		
		-- This way the function can\'t overwrite any of the functions in this environment.
		-- And we can extract the g_PluginInfo variable
		setfenv(PluginInfoLoader, LoaderEnv)
		
		local PluginInfo = LoaderEnv["g_PluginInfo"]
		local PluginName = PluginInfo.Name -- You can also use a_Plugin:GetName() of course.
		
		-- For each command like usually.
		for CommandString, CommandInfo in pairs(PluginInfo.Commands) do
			ins(Row, "<tr></td><td valign=\'top\'>" .. CommandString .. "<br/></td><td valign=\'top\'>" .. (CommandInfo.Permission or "") .. "<br/></td><td valign=\'top\'>" .. (CommandInfo.HelpString or "") .. "<br/></td><td valign=\'top\'></tr>")
		end
	end
)
Keep in mind that I haven't tested this Wink It could fail miserably.

I believe the prettifier escaped some single quotes. You probably need to fix that before testing Wink

The code should work, but its just the setfenv(function, table) that isn't working properly, It always prints an empty tableTongue


I also made a failstate, so it doesn't puke out errors.
local function GetPlugins()

	local Row = {}
	-- Lets grab all plugin permission, commands and help string
	cPluginManager:ForEachPlugin(
		function(a_Plugin)
			if (not cFile:IsFile(a_Plugin:GetLocalFolder() .. "/Info.lua")) then
				-- The plugin doesn\'t have a Info.lua file
				return false
			end
			
			local PluginInfoLoader = loadfile(a_Plugin:GetLocalFolder() .. "/Info.lua")
			local LoaderEnv = {}
			
			-- This way the function can\'t overwrite any of the functions in this environment.
			-- And we can extract the g_PluginInfo variable
			setfenv(PluginInfoLoader, LoaderEnv)
			
			local PluginInfo = LoaderEnv["g_PluginInfo"]
			
			-- Instead of puking out errors, lets do a failstate
			-- by making everything "Invalid"
			if PluginInfo == nil then
				ins(LoaderEnv, {
					["g_PluginInfo"] =
					{
						Name = "Invalid",
						Commands = {
							["/example"] = 
							{
								Permission = "example.core",
								Handler = HandleInvalid,
								HelpString = "Invalid",
							},

							["/another_example"] = 
							{
								Permission = "example.another",
								Handler = HandleInvalid,
								HelpString = "Another Invalid",
							},
						}
					}
				})
				PluginInfo = LoaderEnv[1]["g_PluginInfo"]
			end
			
			local PluginName = PluginInfo.Name -- You can also use a_Plugin:GetName() of course.
			
			-- For each command like usually.
			for CommandString, CommandInfo in pairs(PluginInfo.Commands) do
				ins(Row, "<tr></td><td valign=\'top\'>" .. CommandString .. "<br/></td><td valign=\'top\'>" .. (CommandInfo.Permission or "") .. "<br/></td><td valign=\'top\'>" .. (CommandInfo.HelpString or "") .. "<br/></td><td valign=\'top\'></tr>")
			end
		end
	)
	
	return con(Row)
end
Reply
Thanks given by:


Messages In This Thread
[WEB] Show plugin permissions - by JonnyBoy0719 - 10-08-2015, 04:46 AM
RE: [WEB] Show plugin permissions - by NiLSPACE - 10-08-2015, 05:03 AM
RE: [WEB] Show plugin permissions - by NiLSPACE - 10-08-2015, 06:17 AM
RE: [WEB] Show plugin permissions - by xoft - 10-08-2015, 07:07 AM
RE: [WEB] Show plugin permissions - by xoft - 10-08-2015, 07:09 AM
RE: [WEB] Show plugin permissions - by JonnyBoy0719 - 10-08-2015, 09:13 AM
RE: [WEB] Show plugin permissions - by NiLSPACE - 10-08-2015, 04:36 PM
RE: [WEB] Show plugin permissions - by NiLSPACE - 10-08-2015, 08:58 PM
RE: [WEB] Show plugin permissions - by xoft - 10-08-2015, 09:13 PM
RE: [WEB] Show plugin permissions - by NiLSPACE - 10-08-2015, 09:15 PM
RE: [WEB] Show plugin permissions - by NiLSPACE - 10-08-2015, 10:27 PM
RE: [WEB] Show plugin permissions - by xoft - 10-08-2015, 11:08 PM
RE: [WEB] Show plugin permissions - by NiLSPACE - 10-09-2015, 12:22 AM
RE: [WEB] Show plugin permissions - by NiLSPACE - 10-13-2015, 05:28 PM
RE: [WEB] Show plugin permissions - by chrobione - 12-11-2015, 10:56 AM
RE: [WEB] Show plugin permissions - by chrobione - 12-11-2015, 06:11 PM



Users browsing this thread: 1 Guest(s)