[prev in list] [next in list] [prev in thread] [next in thread] 

List:       webmin-devel
Subject:    Re: [webmin-devel] Integrate with Apache module?
From:       "Jamie Cameron" <jcameron () webmin ! com>
Date:       2010-03-03 18:13:03
Message-ID: 1267639983.27787 () webmin ! com
[Download RAW message or body]

Cool, looks good to me!

On 03/Mar/2010 00:19 Chris Wik <chris@anu.net> wrote ..
> 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 <chris@anu.net <mailto:chris@anu.net>>
> > Subject: Re: [webmin-devel] Integrate with Apache module?
> > To: Webmin development list <webadmin-devel@lists.sourceforge.net
> > <mailto:webadmin-devel@lists.sourceforge.net>>
> > Message-ID: <4B8DA789.7000709@anu.net <mailto:4B8DA789.7000709@anu.net>>
> > 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 webmin-devel@webmin.com
> To remove yourself from this list, go to
> http://lists.sourceforge.net/lists/listinfo/webadmin-devel

------------------------------------------------------------------------------
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 webmin-devel@webmin.com
To remove yourself from this list, go to
http://lists.sourceforge.net/lists/listinfo/webadmin-devel
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic