PHP web app plugin

trimpass

Verified User
Joined
May 11, 2017
Messages
18
Hello,

I have a PHP Web application written using Slim Framework. I want to add this to DA as a plugin. I have referred plugin development docs and also sample plugin progam 'hello_word.tar.gz', but it didn't help me much. How should I proceed further? Any suggestions?
Thanks in advance
 
Hello,

First of all you should prepare correct folder structure and take care of parsing GET, POST variables as they do not exist by default. Then headers, if your PHP application send custom headers it won't work an usual way, it should be rewritten.

What else? Well permissions... which user you want to run the plugin. It's important to give minimal required permissions.

Routing... you will probably need to re-write routing in your APP, as directadmin does require that you user its own format for URLs.

If you have specific questions please feel free to ask them here. I know how to write plugins for Directadmin and Slim Framework isn't any kind of unknown to me either. :)
 
Thanks for the reply.
Sorry for the late response.
The application uses Apache and PHP. I want to add this application as plugin to the DA. When admin logs in and opens the application it(php) should run as admin and when a user logs in and opens the plugin it(php) should run as the currently logged in user.
Now i have placed the application source in /var/myapp/sources. Created a apache conf file with Alias /myapp /var/myapp/sources. I don't know how to proceed further. Please help.
 
Check the links from the post #2
I followed the link and created plugin. Now I facing issues with routing. Only home page of the plugin loads without css and js and all other routes show 404. Does slim framework routing not work in DA plugin system?
you will probably need to re-write routing in your APP, as directadmin does require that you user its own format for URLs

Is there any documentation on this? Or Do you know how to do this?
 
Last edited:
I'm not sure whether or not there is a full documentation on the matter which would cover all aspects of creating plugins.

All static files for a plugin can be loaded only via a special links, you can not load them with the same URLs as in web (Apache/Nginx).

I'd suggest that you install CSF/LFD or any other plugin and learn how it works, that would be the easiest way.

As for slim you will need to read official docs on the matter.
 
Hello,

Thanks for the replay. Now that I have successfully added the plugin and it works!(partially). I am facing two issues.
1. PHP is running as CLI in the plugin. I can see Server API = Command Line Interface in phpinfo(). I want to run php as other than CLI in my plugin.
2. $_SERVER['SCRIPT_NAME'] returns absolute path i.e /usr/local/directadmin/plugins/myplugin/user/index.html instead of /CMD_PLUGINS/myplugin/index.raw and because of that some of the routes are not working!

Can you please help on this?
 
1. Well, I'm not even sure Directadmin can use PHP other than as CLI. Feel free to open a ticket with Directadmin developers and ask them directly here https://tickets.directadmin.com/


2. I guess you need to use REQUEST_URI:

'SCRIPT_NAME'
Contains the current script's path. This is useful for pages which need to point to themselves. The __FILE__constant contains the full path and filename of the current (i.e. included) file.

'REQUEST_URI'
The URI which was given in order to access this page; for instance, '/index.html'.

http://php.net/manual/en/reserved.variables.server.php
 
Hello,

I am facing issues with headers. Slim framework(on the server side of the plugin application) sends headers but the plugin client receives on body, headers are not received. Only plain html displayed in the browser. What could be the error? Does DA plugin do not support headers?
 
adam12 thanks for the reply.
I am using raw plugin style. Still headers are not working. There is no issue from from the slim it sends response with proper headers. If I add echo "HTTP/1.1 200 OK" it works properly. But that is not I want. I want the headers to work normally, no hard coding. Unfortunately there are no docs available for DA plugin s? Do you know any workaround?
 
I don't know any workarounds. Maybe you could have Slim return a default status header of 200, unless told otherwise.

If you can return the 'Status: 200 OK' header and it works, I'd go with that. If it doesn't, maybe you can open a ticket with DirectAdmin and see if they consider it a bug (I would, tho they don't say they follow CGI specs).

You could always ask them if they'd consider a feature request for a default status header of 200 if the script succeeded without a status header returned.
 
With Directadmin you are not allowed to use PHP header() function. You still should use PHP echo() to send headers even if you don't want it. That's how Directadmin is working and there is no way to bypass it... unless you persuade Directadmin developers to change per your request.
 
Thanks for the answer! I didn't know that. Anyway I will use echo statements. Now a small issue in sending status code. I use slim framework version 1.5. I am doing it like this:
echo "HTTP/1.1 " . $app->response ()->status();
But $app->response ()->status() always showing 200. Even when it is a 404 or 500 it still shows 200. You said you have experience in slim frame work. Can you please tell how to get current response status in slim?
 
With Directadmin it is always HTTP/200, as the plugin in Directadmin won't get executed in other cases. Why would you need to return another HTTP code in Directadmin?
 
In case of a internal server error the plugin application script stops and displays a specific error page. This is done inside a jQuery ajax post where it uses textStatus to determine success/ error. In case of always Http/200 the textStatus return success even with the case of 500 server error and the script execution continues which leads to the success page. This is the reason why I want to return other HTTP codes.
 
I did not deal with this case during directadmin plugins development and did not test it on my end either, but let's see... HTTP/200 is the default one:

The PSR 7 Response object’s default status code is 200(OK).

https://www.slimframework.com/docs/objects/response.html


And since PHP application works under PHP-CLI (when running as Directadmin plugin) without a web-server's environment (there is no HTTP thingies in CLI mode) it can not detect any response status, hence it returns 200 in all cases:

http://php.net/manual/en/features.commandline.php
 
With so called "internal server error" from PHP the plugin will show an empty screen, i.e. return 0-sized body without any HTTP/500 status at all as far as I remember.
 
Back
Top