ispman/lib/ISPMan ApacheMan.pm,1.41,1.42

[email protected]
Newsgroups gmane.comp.isp.ispman.cvs
Message-ID <[email protected]>
Update of /cvsroot/ispman/ispman/lib/ISPMan
In directory sc8-pr-cvs1:/tmp/cvs-serv8628

Modified Files:
	ApacheMan.pm 
Log Message:
adding routing suggestHostForVhost

This can be called if no webhost is defined.
This can exist when calling from Controlpanel or CLI etc.

The first choice is to use ispmanDomainDefaultWebHost 
or if that is not defined then use the first host in the httpgroup.



Index: ApacheMan.pm
===================================================================
RCS file: /cvsroot/ispman/ispman/lib/ISPMan/ApacheMan.pm,v
retrieving revision 1.41
retrieving revision 1.42
diff -u -d -r1.41 -r1.42
--- ApacheMan.pm	11 Jan 2004 21:46:21 -0000	1.41
+++ ApacheMan.pm	14 Jan 2004 01:03:39 -0000	1.42
@@ -72,6 +72,7 @@
 addVhostProcess
 addVirtualHostDirectoriesProcess
 changeVhostPassword
+suggestHostForVhost
 );
 $VERSION = '0.01';
 
@@ -266,7 +267,17 @@
    
    my $documentrootoptions=$self->as_arrayref($r->param("ispmanVhostDocumentRootOption"));
    my $scriptdiroptions=$self->as_arrayref($r->param("ispmanVhostScriptDirOption"));;
-   my $webhosts=$self->as_arrayref($r->param("webHost"));
+   my $webhosts=$self->as_arrayref($r->param("webHost"));
+   if ($self->isEmpty($webhosts)){
+	   # This can happen. For example from CCP
+		if (my $_webhost=$self->suggestHostForVhost($domain)){
+			$webhosts=$self->as_arrayref($_webhost);
+		}	   
+   } else {
+	   # Atif 2003/01/13
+	   # Should there be a check and stop here?
+   }
+   
 
 
    if ($r->param("ispmanVhostServerAlias")) {
@@ -328,8 +339,9 @@
 
    # write data to LDAP
    if (! $self->addNewEntryWithData($dn, $data)){ return 0};
-
-   for (@$webhosts){
+	
+   for (@$webhosts){
+	   
        # add new A-record for webhost
        # NOTICE: for multiple webhosts this will create multiple a-records which
        #         will act as simple round-robin loadbalancing.
@@ -508,12 +520,42 @@
 	my $self=shift;
 	my ($domain, $vhost, $process, $param)=@_;
 	my $vhostInfo=$self->getVhostInfo($vhost, $domain);
-        my @webHosts=$self->as_array($vhostInfo->{'webHost'});
+	my @webHosts=$self->as_array($vhostInfo->{'webHost'});
+	
+	unless (@webHosts){
+		# No webHosts defined.
+		
+		my $_webhost;
+				 
+		if ($_webhost=$self->suggestHostForVhost($domain)){
+			push @webHosts, $_webhost;
+		} else {
+			print "No host in webserver is the group found. \nYou cannot add vhosts untill you define some hosts in the httpgroup\n";
+			return;
+		}
+	}
+
  
-        foreach (@webHosts){
-                $self->addProcessToHost($domain, $_, $process, $param);
+	foreach (@webHosts){
+		$self->addProcessToHost($domain, $_, $process, $param);
 	}	
 }
+
+sub suggestHostForVhost {
+	my $self=shift;
+	
+	my ($domain)=@_;
+
+	my $_webhost;
+			 
+	if ($_webhost=$self->getDomainAttribute($domain, "ispmanDomainDefaultWebHost")){
+		return  $_webhost;
+	}elsif ($_webhost=$self->getHostGroupFirstMember('httpgroup')) {
+		return  $_webhost;
+	} else {
+		return 0;
+	}
+}
 
 sub addVirtualHostDirectoriesProcess {
    # The admin can choose where the files for this vhost live.




-------------------------------------------------------
This SF.net email is sponsored by: Perforce Software.
Perforce is the Fast Software Configuration Management System offering
advanced branching capabilities and atomic changes on 50+ platforms.
Free Eval! http://www.perforce.com/perforce/loadprog.html
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.