ispman/lib/ISPMan ApacheMan.pm,1.57,1.58
Joerg Delker <[email protected]>
| Newsgroups | gmane.comp.isp.ispman.cvs |
|---|---|
| Message-ID | <[email protected]> |
Update of /cvsroot/ispman/ispman/lib/ISPMan
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21297/lib/ISPMan
Modified Files:
ApacheMan.pm
Log Message:
moving vhost creation logic from ApacheMan.pm to new vhost.ldif.template to allow easier customisations
Index: ApacheMan.pm
===================================================================
RCS file: /cvsroot/ispman/ispman/lib/ISPMan/ApacheMan.pm,v
retrieving revision 1.57
retrieving revision 1.58
diff -u -d -r1.57 -r1.58
--- ApacheMan.pm 26 Apr 2004 20:49:00 -0000 1.57
+++ ApacheMan.pm 27 Apr 2004 22:19:11 -0000 1.58
@@ -259,43 +259,47 @@
sub addVhost{
my $self=shift;
my $r=shift;
+
+ # filter vhostname for invalid chars
my $ispmanVhostName=$r->param("ispmanVhostName");
$ispmanVhostName=lc($ispmanVhostName);
$ispmanVhostName=~s/[^a-zA-Z0-9\.-]//g;
- my ($vhostIp,$vhostPort)=split ":", $r->param("ispmanVhostIpAddress");
$r->param("ispmanVhostName", $ispmanVhostName);
+
+ my ($vhostIp,$vhostPort)=split ":", $r->param("ispmanVhostIpAddress");
my $domain=$r->param("ispmanDomain");
+
+ # save domain info for use in template
my $domain_info=$self->getDomainInfo($domain);
+ $r->param("domain_info",$domain_info);
+
+ # determine DN for new vhost
my $dn=$self->getVhostDN($domain, $ispmanVhostName);
$r->param("dn", $dn);
+ # check vhost limit
my $domainMaxVhosts = $self->getDomainAttribute($domain,"ispmanMaxVhosts");
my $domainVhostCount = $self->getVhostCount($domain);
-
if ($domainMaxVhosts>0 && $domainVhostCount >= $domainMaxVhosts) {
$self->{'message'}="Max vhosts limit exceeded. <br>Your limit is $domainMaxVhosts <br>You cannot create any more vhosts.";
print $self->{'message'};
return;
}
-
- $self->prepareBranchForDN($self->getVhostsBranchDN($domain));
-
- my $documentrootoptions=$self->as_arrayref($r->param("ispmanVhostDocumentRootOption"));
- my $scriptdiroptions=$self->as_arrayref($r->param("ispmanVhostScriptDirOption"));;
- my $webhosts=$self->as_arrayref($r->param("webHost"));
- if ($self->isEmpty($webhosts)){
+ # check for defined webhosts
+ my @webhosts=$self->as_array($r->param("webHost"));
+ if ($#webhosts<0){
# This can happen. For example from CCP
- $webhosts=$self->getDefaultWebHost($domain);
+ @webhosts=$self->as_array($self->getDefaultWebHost($domain));
+ $r->param("webHost",@webhosts);
}
-
- unless ($webhosts){
+ if ($#webhosts<0){
print "The webhost for $ispmanVhostName cannot be determined!<br>Please check DefaultFileHost for domain $domain!\n";
return;
}
-
+ # seperate alias entry
if ($r->param("ispmanVhostServerAlias")) {
my $serveralias=[split(/\s\s*/, $r->param("ispmanVhostServerAlias"))];
$r->param("ispmanVhostServerAlias", $serveralias) if $serveralias;
@@ -303,66 +307,23 @@
$r->param("ispmanVhostServerAlias", " ");
}
- my $data;
- $data ={
- "objectClass" => $self->{'Config'}{'ispmanVhostObjectclasses'},
- "ispmanVhostName" => $r->param("ispmanVhostName"),
- "cn" => (join '.', ($r->param("ispmanVhostName"), $domain)),
- 'uidNumber' => $self->getUid(),
- 'gidNumber' => $domain_info->{'gidNumber'},
- "ispmanDomain" => $domain,
- "loginShell" => $self->getConf('loginShell'),
- "uid" => (join '.' , ($r->param("ispmanVhostName"), $r->param("ispmanDomain"))),
- "homeDirectory" => $r->param("homeDirectory") ||
- (join "/",($domain_info->{'homeDirectory'},
- "vhosts",
- $r->param("ispmanVhostName"))),
- "userPassword" => $self->encryptPassWithMethod($r->param("userPassword"),$self->getConf('userPassHashMethod')),
- "ispmanVhostServerAlias" => $r->param("ispmanVhostServerAlias") || "",
- "FTPStatus" => $r->param("FTPStatus") || "",
- "ispmanVhostStats" => $r->param("ispmanVhostStats") || "",
- "FTPQuotaMBytes" => $r->param("FTPQuotaMBytes") || "",
- "ispmanVhostDocumentRootOption" => $documentrootoptions || "",
- "ispmanVhostScriptDirOption" => $scriptdiroptions || ""
- };
-
- $data->{"ispmanVhostExtraConf"} = $r->param("ispmanVhostExtraConf") if $r->param("ispmanVhostExtraConf");
- $data->{"ispmanVhostDocumentRoot"} = $r->param("ispmanVhostDocumentRoot") || "htdocs";
- $data->{"ispmanVhostScriptDir"} = $r->param("ispmanVhostScriptDir") || "cgi-bin";
- $data->{"ispmanVhostIpAddress"} = $r->param("ispmanVhostIpAddress") || $self->getConf("apacheVhostsIP") || "*";
- $data->{"webHost"} = $webhosts;
- $data->{"fileHost"} = $r->param("fileHost") || $domain_info->{'ispmanDomainDefaultFileServer'};
- $data->{"DestinationAddress"} = $r->param("fileHost") || $domain_info->{'ispmanDomainDefaultFileServer'};
-
- my $substmap={
- vhost => $r->param("ispmanVhostName"),
- domain => $r->param("ispmanDomain")};
-
- # process ispmanVhostLogdir
- if ($r->param("ispmanVhostLogdir")) {
- $data->{"ispmanVhostLogdir"} = $r->param("ispmanVhostLogdir");
- } else {
- $data->{"ispmanVhostLogdir"} = $self->substitute($self->getConf('apacheLogsDirectory'),$substmap);
- }
-
- # process ispmanVhostStatdir
- if ($r->param("ispmanVhostStatdir")) {
- $data->{"ispmanVhostStatdir"} = $r->param("ispmanVhostStatdir");
- } else {
- $data->{"ispmanVhostStatdir"} = $self->substitute($self->getConf('apacheStatDirectory'),$substmap);
- }
+ # prepare DIT for new vhost DN
+ $self->prepareBranchForDN($self->getVhostsBranchDN($domain));
- # write data to LDAP
- if (! $self->addNewEntryWithData($dn, $data)){ return 0};
+ # write data to LDAP via template
+ $self->addDataFromLdif("templates/vhost.ldif.template", $r);
+ # read back vhost entry to fill processes
+ my $vhost_info=$self->getVhostInfo($dn);
+
# add new A-record for webhost(s) if domain is primary
if ($domain_info->{'ispmanDomainType'} eq "primary"){
- if ($#$webhosts==0){
+ if ($#webhosts==0){
# only single webhost is defined
# (ispmanVhostIpAddress overrides webhost ip)
my $ip=(($r->param("ispmanVhostIpAddress") eq "*") ?
- $self->getHostIp(@$webhosts[0]) : $vhostIp);
+ $self->getHostIp($webhosts[0]) : $vhostIp);
$self->addVhostDNSRecord($r->param("ispmanDomain"),
$r->param("ispmanVhostName"),
$ip);
@@ -380,7 +341,7 @@
# this will create multiple a-records which
# will act as simple round-robin loadbalancing.
# Change them manually for proper hardware loadbalancing!
- for (@$webhosts){
+ for (@webhosts){
$self->addVhostDNSRecord($r->param("ispmanDomain"),
$r->param("ispmanVhostName"),
$self->getHostIp($_));
@@ -390,7 +351,7 @@
}
# add process for each webhost
- for (@$webhosts){
+ for (@webhosts){
$self->addProcessToHost($r->param("ispmanDomain"),
$_,
"AddVirtualHost",
@@ -404,13 +365,13 @@
"AddVirtualHostDirectories",
join ",", (
$r->param("ispmanVhostName"),
- $data->{'homeDirectory'},
- $data->{"ispmanVhostDocumentRoot"},
- $data->{"ispmanVhostScriptDir"},
- $data->{'uidNumber'},
- $data->{'gidNumber'},
- $data->{"ispmanVhostLogdir"},
- $data->{"ispmanVhostStatdir"}
+ $vhost_info->{'homeDirectory'},
+ $vhost_info->{"ispmanVhostDocumentRoot"},
+ $vhost_info->{"ispmanVhostScriptDir"},
+ $vhost_info->{'uidNumber'},
+ $vhost_info->{'gidNumber'},
+ $vhost_info->{"ispmanVhostLogdir"},
+ $vhost_info->{"ispmanVhostStatdir"}
));
return 1;
}
-------------------------------------------------------
This SF.Net email is sponsored by: Oracle 10g
Get certified on the hottest thing ever to hit the market... Oracle 10g.
Take an Oracle 10g class now, and we'll give you the exam FREE.
http://ads.osdn.com/?ad_id=3149&alloc_id=8166&op=click