Plugin development: working with VirtualHosts and CUSTOM tokens

bertvandepoel

Verified User
Joined
Apr 7, 2023
Messages
32
Location
Brussels, Belgium
We've been working on some customised caching stuff for some of our customers who have issues with underperforming websites. We'd like to integrate this nicely into DirectAdmin using a plugin so they can enable and disable it for specific websites. In practice this means adding some ProxyPass rules and an extra vhost for thos sites that are being directed through caching. I'm finding it quite challenging however to control VirtualHosts in DirectAdmin. I can't seem to find any API to make changes to specific vhosts and in general it doesn't seem to be a very accessible part of DA.

I've managed to make a very basic PoC using CUSTOM tokens under the Customize httpd configuration option. I have a few practical questions however, so I was hoping some of my fellow forum members could help with this:
1. To prevent redirection loop, I need to let the website know when https is being used. I currently use 'RequestHeader set X-Forwarded-Proto "https"' in CUSTOM2. Is there a way to add a check similar to |*if SUB|
2. I currently have a full vhost inside CUSTOM1. This means that some of the generated parts I'm doing manually, which is not ideal if the PHP version gets changed or something along those lines. Is there a way to just generate an extra vhost on top of :80 and :443 on yet another port but beyond that identical apart from some added headers?
3. Is there an API call to set these CUSTOM tokens? I didn't seem to find one immediately
4. I noticed there's an API you can call to get all the domains of a user, but is there also a way to get them grouped together per vhost (so all pointers and the main domain together)?
5. Is anyone aware of any good examples/tutorials to create nice DirectAdmin interfaces? I'd like what I'm creating to look good but the plugin development docs seem really scattered and chaotic.

Any help to any of these questions is much appreciated. I really hope I will pull this off!
 

- CMD_API_CUSTOM_HTTPD

To add/remove custom httpd settings via the api.

I won't give instructions on how to use it. It will be up to you to learn how to work with it. I would suggest that you use a browser console and see what requests are sent from Evolution skin to a Directadmin server, when you do the things in a browser. Then you will need to use what you find in your plugin.
 

- CMD_API_CUSTOM_HTTPD

To add/remove custom httpd settings via the api.

I won't give instructions on how to use it. It will be up to you to learn how to work with it. I would suggest that you use a browser console and see what requests are sent from Evolution skin to a Directadmin server, when you do the things in a browser. Then you will need to use what you find in your plugin.
That's plenty. It's not my first rodeo with a GET/POST API, so I should be fine, thanks a ton! Now just a solution for question 2 and I have all necessary info. 4 and 5 are "nice to haves" let's say. Thanks and have a great weekend Alex!
 
No too sure I get the idea. So can not say anything for sure. For Apache you probably could use |CUSTOM4| with the following code:

Code:
</VirtualHost>
<VirtualHost |IP|:|CUSTOM_PORT| |MULTI_IP|>
...
... YOUR CODE IS HERE ....

Will it help?
 
The problem mostly is the default, autogenerated content of the Vhost like the docroot, log locations, Directory/FilesMatch stuff. I'd prefer to get those from DirectAdmin somehow, if I could, instead of reconstructing and partially hardcoding it.
 
This means that some of the generated parts I'm doing manually, which is not ideal if the PHP version gets changed or something along those lines.
Can you show your simple coding, which part you talking about that's could do conflic in future ?
 
Can you show your simple coding, which part you talking about that's could do conflic in future ?
I mean this autogenerated stuff by DirectAdmin that's part of the vhost:

DocumentRoot /home/placeholderbe/domains/placeholder.be/public_html/web4
UseCanonicalName OFF
<IfModule !mod_ruid2.c>
SuexecUserGroup placeholderbe placeholderbe
</IfModule>

<Directory /home/placeholderbe/domains/placeholder.be/public_html/web4>
AllowOverride AuthConfig FileInfo Indexes Limit Options=Indexes,IncludesNOEXEC,MultiViews,SymLinksIfOwnerMatch,FollowSymLinks,None
Options -ExecCGI -Includes +IncludesNOEXEC
<FilesMatch "\.(inc|php|phtml|phps|php)$">
<If "-f %{REQUEST_FILENAME}">
#ProxyErrorOverride on
AddHandler "proxy:unix:/usr/local/php73/sockets/placeholderbe.sock|fcgi://localhost" .inc .php .phtml
</If>
</FilesMatch>
<FilesMatch "\.(php53|php54|php55|php56|php70|php71|php72|php73|php74|php80|php81|php82)$">
Order Allow,Deny
Deny from all
</FilesMatch>
</Directory>
RewriteEngine on
RewriteOptions inherit
 
ok, but I still not found any issued when PHP get change.

This is just example from post #6, since between main domain and subdomain have difference template, we need condition checking.

you can copy virtualhost section template from "./directadmin/data/templates/virtual_host2_secure.conf"
"./directadmin/data/templates/virtual_host2_sub_secure.conf"
p.s. do not copy "</VirtualHost>".


and place into CUSTOM4 token. like this
Code:
</VirtualHost>
|*if SUB=""|
#template from "virtual_host2_secure.conf"
|*endif|

|*if SUB|
#template from "virtual_host2_secure_sub.conf"
|*endif|

and change anything you want like port, remove something that's doesn't necessary.
 
My concern was stuff like the AddHandler line which gets changed based on the selected PHP version but in the file you linked I see I can use this:
AddHandler "proxy:unix:/usr/local/php|PHP1_RELEASE|/sockets/|USER|.sock|fcgi://localhost" .inc .php .phtml
Thanks for your help, that does help me along with my second question!
 
Back
Top