Re: [webmin-devel] Integrate with Apache module?

Chris Wik <[email protected]> Wed, 03 Mar 2010 09:19:51 +0100
Newsgroups gmane.comp.web.webmin.devel
Message-ID <[email protected]>
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 <[email protected] <mailto:[email protected]>>
> Subject: Re: [webmin-devel] Integrate with Apache module?
> To: Webmin development list <[email protected]
> <mailto:[email protected]>>
> Message-ID: <[email protected] <mailto:[email protected]>>
> 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

------------------------------------------------------------------------------
Download Intel&#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
-
Forwarded by the Webmin development list at [email protected]
To remove yourself from this list, go to
http://lists.sourceforge.net/lists/listinfo/webadmin-devel