Attempting to make global update to httpd.conf user files

glarkin

Verified User
Joined
Apr 27, 2004
Messages
28
Hi All,

I just created a domain_create_post.sh script in our DA installation that will automatically create a URL alias named "/stats" where each account's web stats data lives. That is working well for all accounts created from here forward.

Now I would like to go back an add this alias for all existing accounts. I have written a shell script for our Redhat 9 box that will call a Perl in-place substitution for each account that doesn't already have the /stats URL set up.

The script seems to work fine, but the odd thing is - something is reverting the change on me, and I can't figure out what it is. Does DA detect when the httpd.conf files have been changed "out from under it" and change them back?

The input to my shell script is like the following:


user1/httpd.conf
user2/httpd.conf
user3/httpd.conf


The script itself is this:


#!/bin/sh

# This script will add the stats URL to any site that does not
# already have it.

if [ -f /tmp/nostats.txt ]; then
for CONF in `head -1 /tmp/nostats.txt`; do
export username=`echo $CONF | cut -f1 -d/`
export domain=`cat $username/domains.list`

echo Adding stats URL to user $username...
perl -i.bak /usr/local/directadmin/scripts/custom/add_stats_url.pl /usr/local/directadmin/data/users/$username/httpd.conf
done

# Restart Apache
echo "action=rewrite&value=httpd" >> /usr/local/directadmin/data/task.queue
else
echo Cannot find the /tmp/nostats.txt file
exit 1
fi


And finally, the Perl script that is called is here:


$/="\0";
$_=<>;

my $statsLine = "\nAlias /stats /home/" . $ENV{'username'} . "/domains/" . $ENV{'domain'} . "/stats/";
s#^(<VirtualHost.*?)$#$1$statsLine#gm;

print;


As I said, this all seems to work fine for about 2 minutes, and then something changes the httpd.conf files back to what they were before.

If anyone has any idea why that's happening, please let me know. I don't think there is any way to do something like this with the API, so that's why I went for it at the file level.

Thank you,
Greg
 
Hi all,

I'll respond to my own question here because I found an alternate way to do this. I modified my script to use curl to call the DA URL responsible for updating the custom Apache configuration. It's not an API call, but all I needed to do was find out the name of the textarea widget and URL-encode my data.

One other thing to note is that curl is using the ${HOME}/.netrc file for auto-login to the DA UI. Check the curl man page for the format of that file.

Here is the modified script in case anyone is interested:


#!/bin/sh

# This script will add the stats URL to any site that does not
# already have it.

if [ -f /tmp/nostats.txt ]; then
for CONF in `cat /tmp/nostats.txt`; do
username=`echo $CONF | cut -f1 -d/`
for DOMAIN in `cat $username/domains.list`; do
echo Adding stats URL to domain $DOMAIN
curl -n -d config=Alias+%2Fstats+%2Fhome%2F%7CUSER%7C%2Fdomains%2F%7CDOMAIN%7C%2Fstats%2F http://myhost.domain.com:2222/CMD_CUSTOM_HTTPD?domain=$DOMAIN
done
done

# Restart Apache
echo "action=rewrite&value=httpd" >> /usr/local/directadmin/data/task.queue
else
echo Cannot find the /tmp/nostats.txt file
exit 1
fi


Hope that helps someone out,
Greg
 
And I'll answer the question to say that yes, DA uses it's own template. If you're going to make a change, make it to the template.

Jeff
 
Hi Jeff,

Thanks for the information, I guess I over-engineered that solution!

Regards,
Greg
 
"I just created a domain_create_post.sh script in our DA installation that will automatically create a URL alias named "/stats" where each account's web stats data lives. That is working well for all accounts created from here forward."

Why not share the script :)
 
rldev said:
"I just created a domain_create_post.sh script in our DA installation that will automatically create a URL alias named "/stats" where each account's web stats data lives. That is working well for all accounts created from here forward."

Why not share the script :)

Hi rldev,

As Jeff noted above, there's a much easier way to do what I did. All I needed to do was copy the following files from /usr/local/directadmin/data/templates to /usr/local/directadmin/data/templates/custom:

virtual_host2.conf
virtual_host2_secure.conf
virtual_host2_secure_sub.conf
virtual_host2_sub.conf
virtual_host.conf
virtual_host_secure.conf
virtual_host_secure_sub.conf
virtual_host_sub.conf

Then I can simply add my URL Alias directive (Alias /stats /home/|USER|/domains/|DOMAIN|/stats/) to the appropriate location in each file.

That would be a lot easier, as it turns out!

Hope that helps,
Greg
 
Back
Top