Blogs

Blogs

Pandora's Box for Liferay: LFM Portlet

Part 2 of this series is a short, but sweet one. This portlet was born out of a very specific customer requirement: the need to be able to see log files for some user that have Liferay web access, but no actual OS level access to the server itself. We first looked at using the Liferay Log Viewer portlet that is available in the Liferay Marketplace and while it partly covered the requirement it wasn't a real good fit.

So that's why we first developed a simple Control Panel portlet that allowes an administrator to just download files from a fixed set of directories: the Tomcat log directory and the Liferay log directory. While this perfectly satisfied the requirement of the customer it got me thinking: wouldn't it be nice if you could traverse the file tree a bit more and also execute some additional file actions like editing a file or even creating a new file?

So that's how the LFM Portlet, the Liferay File Manager Portlet, was born. The quickly thrown together version you can find on Github, https://github.com/planetsizebrain/liferay-pandora-box/tree/master/lfm-portlet, allows you to do the following things:

  • view a file
  • edit a file
  • upload/download a file
  • delete a file/directory
  • add a new (empty) file
  • add a new directory
  • touch a file (aka trigger a redeploy when done on a web.xml)
  • whatever you want to add wink (the code is available on Github)

So now it not only allows you to download a log file, but you can even change a config file if you want or perform a cleanup and redeploy of a module for which a hot deploy went wrong.

Because the portlet does everything with the user the JVM/Liferay was started with, you, or any user you give permission to use the portlet, can see everything on the file system the OS user is able to see. this means you'll be able to delete your Liferay or even mess up your data directory. So be careful who you give access to and think twice when using certain functions and always keep the following Spiderman quote in mind:

There are some additional resource actions, that can be used to limit what certain users can do, but they only work on a global level and not on specific files or directories:

There's also one little extra (just because I wanted to try out Zeno Rocha's clipboard.js): when you click on the little symbol after the path, on top of the datatable, it will copy the actual path to your clipboard.

Blogs
Hi.
Very useful portlet.
Is it possible to make it compatible with 6.1.1?
There's isn't a lot in the portlet that depends on a specific Liferay version. So you should just be able to take the code, change the Liferay version in the descriptors like liferay-plugin-package.properties, liferay-hook.xml, etc... and change the JSF bridge to the appropriate version for the Liferay version you want and build it.