|
From: Jamie C. <jca...@we...> - 2010-03-03 00:09:36
|
On 02/Mar/2010 16:04 Chris Wik <ch...@an...> wrote ..
> On 02.03.10 22:03, Jamie Cameron wrote:
> > Yes, absolutely - you can use code like this :
> >
> > foreign_require("apache");
> > $conf = apache::get_config();
> > @vhosts = apache::find_directive_struct("VirtualHost", $conf);
> > foreach $v (@vhosts) {
> > $sn = apache::find_directive("ServerName", $v->{'members'});
> > if ($sn eq "whatever.com") {
> > @includes = apache::find_directive("Include", $v->{'members'});
> > push(@includes, "/path/to/file.lasso");
> > apache::save_directive("Include", \@includes, $v->{'members'}, $conf);
> > flush_file_lines($v->{'file'});
> > }
> > }
>
> I'm stuck, hopefully something stupid you can easily spot..
>
> I'm getting 'Failed to save Site : flush_file_lines called on non-loaded
> file /etc/httpd/conf.d/ssl.conf' when running:
>
>
> sub update_apache_vhosts {
> my ($site) = @_;
> my $conf_path = $site->{'directory'} . '/lasso/fastcgi.conf';
>
> # servernames from ui_select (multiple) on edit form
> my @servernames = split(/\0/, $site->{'servername'});
>
> foreach $servername(@servernames) {
> foreign_require("apache");
> $conf = apache::get_config();
> @vhosts = apache::find_directive_struct("VirtualHost", $conf);
> foreach $v (@vhosts) {
> $sn = apache::find_directive("ServerName", $v->{'members'});
> @includes = apache::find_directive("Include", $v->{'members'});
> if ($sn eq $servername) {
> push(@includes, $conf_path);
> } else {
> delete $includes[$conf_path];
> }
> apache::save_directive("Include", \@includes, $v->{'members'}, $conf);
> flush_file_lines($v->{'file'});
> }
> }
> }
>
> Any ideas?
You don't want to call flush_file_lines unless you have actually added to or removed
something from the @includes list.
- Jamie
|