Template if-then-else usage

dlong500

Verified User
Joined
Nov 16, 2004
Messages
80
I've seen the KB article here (http://www.directadmin.com/features.php?id=430) regarding if-then-else statements in templates. What I'm not clear about is if there is any support for AND operators, like:
Code:
|*if DOMAIN="example.com" AND SUB="webmail"|
Code for webmail.example.com
|*endif|

In my limited testing it doesn't appear to like the above format. Also, what about nested if-then statements? It doesn't seem to like them either in my testing, but I haven't been very thorough yet so it could have been a combination of other factors causing it to fail.

Finally, a really nice feature would be to have the option to preview the resultant httpd.conf files generated by the templates BEFORE making them live (and maybe even have apache check them for syntax errors?).
 
Ok, upon further testing I can confirm that nested if-then statements will not work. This is a major problem for me since I am trying to have a particular site with a completely custom virtualhost section (Django with mod_wsgi).

The way things currently are I cannot insert an if-then-else statement in a custom virtual_host2.conf file that does one thing for my Django site and another for all other sites because there are already existing if-then statements for all the PHP related settings.

How do I just make it so I can have a completely different virtualhost section for this one site?
 

I saw that too, but unfortunately it doesn't seem to allow for full php scripting capabilities like if then statements unless I'm doing something wrong. After rewriting the httpd.conf files I would still see the script tags in the resultant files (and obviously Apache didn't like that). If someone can give an example of how they have successfully used any method of nested if-then statements in a template I would greatly appreciate it.
 
Will you give an example in words or drawn on picture, what you're trying to achieve?

What I'd like is something like the following (based on if the template if-then tags could be nested):
Code:
|?DOCROOT=`HOME`/domains/`DOMAIN`/public_html|
|?OPEN_BASEDIR_PATH=`HOME`/:/tmp:/var/tmp:/usr/local/lib/php/|
<VirtualHost |IP|:|PORT_80| |MULTI_IP|>
|CUSTOM|
|?CGI=ScriptAlias /cgi-bin/ `DOCROOT`/`SUB`/cgi-bin/|
    ServerName www.|SUB|.|DOMAIN|
    ServerAlias www.|SUB|.|DOMAIN| |SUB|.|DOMAIN| |SERVER_ALIASES|
    ServerAdmin |ADMIN|
    DocumentRoot |DOCROOT|/|SUB|
    |CGI|

    |USECANONICALNAME|
    CustomLog /var/log/httpd/domains/|DOMAIN|.|SUB|.bytes bytes
    CustomLog /var/log/httpd/domains/|DOMAIN|.|SUB|.log combined
    ErrorLog /var/log/httpd/domains/|DOMAIN|.|SUB|.error.log

|*if DOMAIN="example.com"|
    #Code for WSGI Python app
|*else|
    #Code for all other websites    
    RMode config
    RUidGid |USER| |GROUP|
    RGroups apache
    <Directory |DOCROOT|/|SUB|>
        Options +Includes -Indexes
    |*if CLI="1"|
        php_admin_flag engine |PHP|
        <IfModule !mod_php6.c>
            php_admin_flag safe_mode |SAFE_MODE|
        </IfModule>
        php_admin_value sendmail_path '/usr/sbin/sendmail -t -i -f |USER|@|DOMAIN|'
    |*endif|
    |*if OPEN_BASEDIR="ON"|
        php_admin_value open_basedir |OPEN_BASEDIR_PATH|
    |*endif|
    |*if SUPHP="1"|
        suPHP_Engine |PHP|
        suPHP_UserGroup |USER| |GROUP|
    |*endif|
    </Directory>
|*endif|
|HANDLERS|
|MIMETYPES|

</VirtualHost>

or, the same example but with php code:
Code:
|?DOCROOT=`HOME`/domains/`DOMAIN`/public_html|
|?OPEN_BASEDIR_PATH=`HOME`/:/tmp:/var/tmp:/usr/local/lib/php/|
<VirtualHost |IP|:|PORT_80| |MULTI_IP|>
|CUSTOM|
|?CGI=ScriptAlias /cgi-bin/ `DOCROOT`/`SUB`/cgi-bin/|
    ServerName www.|SUB|.|DOMAIN|
    ServerAlias www.|SUB|.|DOMAIN| |SUB|.|DOMAIN| |SERVER_ALIASES|
    ServerAdmin |ADMIN|
    DocumentRoot |DOCROOT|/|SUB|
    |CGI|

    |USECANONICALNAME|
    CustomLog /var/log/httpd/domains/|DOMAIN|.|SUB|.bytes bytes
    CustomLog /var/log/httpd/domains/|DOMAIN|.|SUB|.log combined
    ErrorLog /var/log/httpd/domains/|DOMAIN|.|SUB|.error.log

<? if("|DOMAIN|"="example.com") { ?>
    #Code for WSGI Python app
<? } else { ?>
    #Code for all other websites
    RMode config
    RUidGid |USER| |GROUP|
    RGroups apache
    <Directory |DOCROOT|/|SUB|>
        Options +Includes -Indexes
    |*if CLI="1"|
        php_admin_flag engine |PHP|
        <IfModule !mod_php6.c>
            php_admin_flag safe_mode |SAFE_MODE|
        </IfModule>
        php_admin_value sendmail_path '/usr/sbin/sendmail -t -i -f |USER|@|DOMAIN|'
    |*endif|
    |*if OPEN_BASEDIR="ON"|
        php_admin_value open_basedir |OPEN_BASEDIR_PATH|
    |*endif|
    |*if SUPHP="1"|
        suPHP_Engine |PHP|
        suPHP_UserGroup |USER| |GROUP|
    |*endif|
    </Directory>
<? } ?>
|HANDLERS|
|MIMETYPES|

</VirtualHost>

Neither of those options work. I know I could go completely outside of DA and add my own custom section to the apache conf files but I'd still like DA to manage all the other stuff for the site.
 
See an example from content_main.html

cat /usr/local/directadmin/data/skins/enhanced/admin/content_main.html


PHP:
|$/usr/local/bin/php
<?php
$data = <<<END
|PLUGIN_1_ADMIN_TXT|
END;
if (strlen($data) > 1)
{
echo <<<END
|PLUGIN_1_ADMIN_TXT|<br>
|PLUGIN_3_ADMIN_TXT|<br>
|PLUGIN_5_ADMIN_TXT|<br>
|PLUGIN_7_ADMIN_TXT|<br>
|PLUGIN_9_ADMIN_TXT|
END;
}
?>
DONE|


PM me for a quote, if you need my private help to configure your httpd templates
 
Thanks zEitEr, that's awesome. Thanks also for the reference to the skins. I looked around at some of the templates and didn't see anything like that.

I'll try it out soon.
 
I'm having the same problem so I'm very curious about your final solution dlong500, can you post your solution?
 
I actually ended up putting my Python sites on a different server so I didn't get into template modification too much, but the info zEitEr provided should work fine (especially since he pointed out a DA file that already uses it).
 
I actually ended up putting my Python sites on a different server so I didn't get into template modification too much, but the info zEitEr provided should work fine (especially since he pointed out a DA file that already uses it).

Ok, so you one let's say server1 you have a specific httpd.conf template (for for example your PHP websites) and on server2 you have an other specific httpd.conf (for Python websites)?

I was thinking about the same solution (to optimize a DA VPS for PHP serving and optimize a separate DA VPS for Python serving)
 
Ok, so you one let's say server1 you have a specific httpd.conf template (for for example your PHP websites) and on server2 you have an other specific httpd.conf (for Python websites)?
Actually, in this case my other server that I use for Python sites is not a DirectAdmin server. I had oodles of problems getting WSGI working correctly with the DA provided software, so I just went with a vanilla Debian and installed all necessary components through aptitude. Since I haven't really needed WSGI for clients so far this setup works for me.

I may try to revisit WSGI on a DA server again at some point...
 
Back
Top