Cuberite Forum
[WEB] Show plugin permissions - Printable Version

+- Cuberite Forum (https://forum.cuberite.org)
+-- Forum: Plugins (https://forum.cuberite.org/forum-1.html)
+--- Forum: Plugin Releases (https://forum.cuberite.org/forum-2.html)
+--- Thread: [WEB] Show plugin permissions (/thread-2150.html)

Pages: 1 2 3


[WEB] Show plugin permissions - JonnyBoy0719 - 10-08-2015

Did a simple plugin that shows all permissions (if the plugin have a info.lua file with the proper information) with the commands and help string. I made this plugin so it would be easier for me to assign permissions to each group. c:

At this moment there is no pages, so the list just goes on. I will however create that later on, when i get more time.

Preview Image
[Image: vFrxLkA.png]

You can download the plugin from my GitHub page below Smile
https://github.com/jonnyboy0719/Cuberite-Web-Permissions


RE: [WEB] Show plugin permissions - NiLSPACE - 10-08-2015

Ooh, that's a great idea. Perhaps you could categorize all the permissions. Something like:
WorldEdit
  • worldedit.butcher
    ..



RE: [WEB] Show plugin permissions - JonnyBoy0719 - 10-08-2015

(10-08-2015, 05:03 AM)NiLSPACE Wrote: Ooh, that's a great idea. Perhaps you could categorize all the permissions. Something like:
WorldEdit
  • worldedit.butcher
    ..

Yeah, that what i did first, before i redid my code (everything was manualTongue). Currently using the same function/hook thing that help.lua uses. No idea if i can somehow retrieve Name from g_PluginInfo.


RE: [WEB] Show plugin permissions - NiLSPACE - 10-08-2015

Looking at the code you aren't actually using g_PluginInfo. You're looping through all the known commands and getting the info from there. As of yet every plugin I've seen uses "<PluginName>.<Permission>" in their permissions. You could thus get the name by using something like this:
local PluginName = a_CBPermission:match("^.-%.")
This would of course mean that you'd mostly have lowercase plugin names like "worldedit" instead of "WorldEdit" (unless a plugin has permissions that look weird)

If you would actually use the Info.lua file you would use something like this:
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


RE: [WEB] Show plugin permissions - xoft - 10-08-2015

That's a great idea, thanks! (And welcome to the forum, by the way Smile )
Keep in mind that there are plugins that use subcommands ("/time set" etc.), your plugin may want to parse those as well.

As a side idea, it would be even better to allow the admin to assign the permission to a permission-group, somehow. My first idea: add an Assign button in each permission's row and the page that it displays would have a list of all permission groups and a button to add the permission or add as restriction. Some special care would be needed if the group already contained a parent permission, such as "core.*"; it would make sense to disable adding any "core.something" permission to such a group (but still makes sense to add it as a restriction).


RE: [WEB] Show plugin permissions - xoft - 10-08-2015

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


RE: [WEB] Show plugin permissions - JonnyBoy0719 - 10-08-2015

(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



RE: [WEB] Show plugin permissions - JonnyBoy0719 - 10-08-2015

Modified the function GetPlugins() a tiny bit, added a "Info Counter", basically it counts everytime it finds a Info.lua file, if none were found (counter is still on 0) it won't show the failsafe, since that will be empty, but will instead tell the player that none of the enabled plugins have a info.lua file :3


RE: [WEB] Show plugin permissions - NiLSPACE - 10-08-2015

I don't really think the failsafe is needed. If the Info.lua exists but is invalid then the plugin might not even be loaded.

That got me thinking, this plugin also shows permissions from plugins that aren't loaded. If you want to remove those you might want to put
if (not a_Plugin:IsLoaded()) then
   return false
end
At the top of the ForEachPlugin callback.


Also, I found out why the LoaderEnv table is empty. I forgot to actually call the loader Wink If you'd use "PluginInfoLoader()" after the setfenv function it works normally.


RE: [WEB] Show plugin permissions - JonnyBoy0719 - 10-08-2015

Thanks for the help NiLSPACETongue


I have also removed some code and redid some areas, this is how it currently looks (Add Permission button doesn't work yet, but i will get onto it)

https://youtu.be/dyaF_Mflv4Q