• Introducing WebPros Cloud - a fully managed infrastructure platform purpose-built to simplify the deployment of WebPros products !  WebPros Cloud enables you to easily deliver WebPros solutions — without the complexity of managing the infrastructure.
    Join the pilot program today!
  • Support for BIND DNS has been removed from Plesk for Windows due to security and maintenance risks.
    If a Plesk for Windows server is still using BIND, the upgrade to Plesk Obsidian 18.0.70 will be unavailable until the administrator switches the DNS server to Microsoft DNS.

Question Developing a new extension; Facing problems with filesystem functions

Hi Plesk Guys,

I am developing an extension for Plesk that will do the following (among other things).

- create files in "$HOME/.extension/files.json"
- download files to "$HOME/.extension/tmp/files.zip"
- extract "$HOME/.extension/tmp/files.zip" to "$HOME/.extension/tmp/files/"
- copy directories from "$HOME/.extension/tmp/files/" to "$DOCUMENT_ROOT/files/"

It will run in both "root" and "non-root" (regular user) mode.

I have implemented all of the above using "pm_ServerFileManager()" (for "root" mode) and "pm_FileManager" (for "non-root" mode).

Reference:
- Extensions API Documentation - Plesk 17.0
- Extensions API Documentation - Plesk 17.0

As the methods in these two classes are limited, I am facing problems w.r.t. filesystem operations (in both "root" and "non-root" mode).

Example: I cannot detect the mime type of the downloaded file.

Most of the "Filesystem" family of functions (PHP: File System Related Extensions - Manual) of PHP do not work within an extension. A few among them that I have tried are "finfo_open" (PHP: finfo_open - Manual) and "mime_content_type" (PHP: mime_content_type - Manual) and "glob" (PHP: glob - Manual). I have also tried using the "file" command but they do not work (except inside "/tmp/") due to lack of permissions (in both "root" and "non-root" mode).

$ file -b --mime-type $HOME/.extension/tmp/files.zip
cannot open `$HOME/.extension/tmp/files.zip' (Permission denied)

In this case, the file "$HOME/.extension/tmp/files.zip" has "user : psacln" ownership with "770" permissions.

$ file -b --mime-type /tmp/files.zip
application/zip

In this case, the file "/tmp/files.zip" has "psaadm : psaadm" ownership with "770" permissions.

Question 1: How do I make the "pm_*_FileManager" class use "psaadm" group instead of "psacln" group? To clarify, files created using the "pm_*_FileManager" have "user : psacln" ownership and files created using executable commands have "psaadm : psaadm" ownership.

They are not interoperable.

Example: This is the error I get when trying to copy "/tmp/files.zip" (psaadm : psaadm) to "$HOME" (user : psacln),

filemng failed: filemng: Error occurred during /bin/cp command.
#0 /opt/psa/admin/plib/Service/Driver/Filesystem/Plesk/Unix.php(333): Service_Agent->execAndGetResponse('filemng', Array, NULL, Array)
#1 /opt/psa/admin/plib/Service/Driver/Filesystem/Plesk/Unix.php(80): Service_Driver_Filesystem_Plesk_Unix->_execAndGetResponse(Array)
#2 /opt/psa/admin/plib/FileManager.php(287): Service_Driver_Filesystem_Plesk_Unix->cp('user', '/tmp/phpinfo', '/var/www/vhosts/...')
#3 /opt/psa/admin/plib/pm/FileManager.php(127): FileManager->cp_wrapper('/tmp/phpinfo', '/var/www/vhosts/...')
#4 /opt/psa/admin/plib/modules/extension/sources/index.php(861): pm_FileManager->copyFile('/tmp/phpinfo', '/var/www/vhosts/...')
#5 /opt/psa/admin/plib/modules/extension/sources/index.php(898): Extension->others()
#6 /opt/psa/admin/htdocs/modules/extension/index.php(5): require_once('/opt/psa/admin/...')
#7 {main}

If they were interoperable, I could easily do the following:

- copy the original file in question from "$HOME" or "$DOCUMENT_ROOT" to "/tmp/" (using the corresponding "pm_*_FileManager" class)
- execute all commands in "/tmp/" (where even the PHP functions such as "glob()" work as expected)
- copy the modified files (or the extracted output) from "/tmp/" back to "$HOME" or "$DOCUMENT_ROOT"

Question 2: How can I execute a command as a specific user? i.e.: How can I make Plesk execute a command as "user" or even "root" (when it runs as "psaadm")? It must be possible because "pm_ServerFileManager" and "pm_FileManager" make it happen (when observing the ownership of newly created files).

Let me know if you have a way out for me.
 
Back
Top