From: Chris W. <ch...@an...> - 2010-03-03 08:20:15
|
I ended up setting a flag if something is changed. Here's the final version that seems to be working great so far: sub update_apache_vhosts { my ($site) = @_; my $conf_path = $site->{'directory'} . '/lasso/fastcgi.conf'; my @servernames = split(/\0/, $site->{'servername'}); 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'}); my($changed,$match1,$match2) = 0; foreach $inc(@includes) { if($inc eq $conf_path) { $match1 = 1; } } foreach $servername(@servernames) { if($servername eq $sn) { $match2 = 1; } } # If Include is not present, but servernames match if($match1 == 0 && $match2 == 1) { push(@includes, $conf_path); $changed = 1; # If include is present, but no match on servername } elsif($match1 == 1 && $match2 == 0) { delete $includes[$inc]; $changed = 1; } apache::save_directive("Include", \@includes, $v->{'members'}, $conf); if($changed) { flush_file_lines($v->{'file'}); } } } On 03.03.10 01:37, Pitchumani Guruswamy wrote: > Does forcing the loading of the file through file open help? > > > > ======== > > From: Chris Wik <ch...@an... <mailto:ch...@an...>> > Subject: Re: [webmin-devel] Integrate with Apache module? > To: Webmin development list <web...@li... > <mailto:web...@li...>> > Message-ID: <4B8...@an... <mailto:4B8...@an...>> > Content-Type: text/plain; charset=ISO-8859-1 > > 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 <http://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? > > Thanks -- Chris Wik Anu Internet Services Ltd |