With the addition of the
custom package items, you can now use these items to control other areas of your system. For this example, we'll have these items control the content of a User httpd.conf file.
1)The first step is to add a custom package item. See
this guide on how to do that. For this example, use a checkbox. Give the variable a name called
myval
2)Next, we need to have this option do something. By default, the item is only stored in the user.conf file.. it won't do anything.
To have it do something, create the script
/usr/local/directadmin/scripts/custom/user_create_post.sh. Inside that file, add this code:
#!/bin/sh
if [ "$myval" = "yes" ]; then
echo "CustomApache code" >> /usr/local/directadmin/data/users/$username/domains/$domain.cust_httpd
echo "action=rewrite&value=httpd&user=$username" >> /usr/local/directadmin/data/task.queue
fi
exit 0;
Which will insert the "CustomApache code" into the |CUSTOM| token in the virtual_host2*.conf template files.
The templates offer even more degrees of flexibility with the use of
if-then-else statements and variables. For example, if you
edit the global templates to have some code.... but you only want the code available for some Users or domains, you can if-then-else along with variables. For this example, if the variable MYVAL=yes is set, then we'll insert code into the httpd.conf, eg, in the virtual_host2*.conf files, after the |CUSTOM| token :
|*if MYVAL="yes"|
CustomApache code
|*endif|
Then, in step
2) above, instead of adding using this
echo "CustomApache code" >> /usr/local/directadmin/data/users/$username/domains/$domain.cust_httpd
you'd use this instead
echo "|?MYVAL=yes|" >> /usr/local/directadmin/data/users/$username/domains/$domain.cust_httpd
which get's inserted into the |CUSTOM| token, thus setting the variable.. so that once your if-then-else statement happens, the value=yes, and you're good to go.
You can then turn domain on or off from:
Admin Level -> Custom httpd config -> domain
by adding or removing the
|MYVAL=yes| code from the text area.
This can also still be managed via the packages, but you'd also need to create user_modify_post.sh, to add or remove the domain.com.cust_httpd file, based on what value is set.