From 7d061eb579c35a2f71d795d1241d13376599bd54 Mon Sep 17 00:00:00 2001 From: opensides Date: Sun, 4 Nov 2007 14:02:21 +0000 Subject: [PATCH 1/1] - Cleaned and debugged code first part - standardize naming of files gosa way ;-) git-svn-id: https://oss.gonicus.de/repositories/gosa/branches/2.5-plugins@7727 594d385d-05f5-0310-b6e9-bd551577e9d8 --- ...host.inc => class_servApacheEditVhost.inc} | 13 ++-- ...cheVhost.inc => class_servApacheVhost.inc} | 31 ++++----- vhost-apache2/src/functions_apache.inc | 65 ++++++++++--------- .../{apache_vhost.tpl => servApacheVhost.tpl} | 2 - ..._editVhost.tpl => servApacheVhostEdit.tpl} | 0 5 files changed, 55 insertions(+), 56 deletions(-) rename vhost-apache2/src/{class_apacheEditVhost.inc => class_servApacheEditVhost.inc} (97%) rename vhost-apache2/src/{class_apacheVhost.inc => class_servApacheVhost.inc} (91%) rename vhost-apache2/src/{apache_vhost.tpl => servApacheVhost.tpl} (67%) rename vhost-apache2/src/{apache_editVhost.tpl => servApacheVhostEdit.tpl} (100%) diff --git a/vhost-apache2/src/class_apacheEditVhost.inc b/vhost-apache2/src/class_servApacheEditVhost.inc similarity index 97% rename from vhost-apache2/src/class_apacheEditVhost.inc rename to vhost-apache2/src/class_servApacheEditVhost.inc index 3eb455307..0f8672c5d 100644 --- a/vhost-apache2/src/class_apacheEditVhost.inc +++ b/vhost-apache2/src/class_servApacheEditVhost.inc @@ -1,6 +1,6 @@ $value){ - /* Delete record if requested */ + /* Delete vhosts if requested */ if((preg_match("/RemoveRecord_/",$name))&&($once)){ $once = false; $id= preg_replace("/RemoveRecord_/","",$name); @@ -289,8 +289,7 @@ class apacheVhostEdit extends plugin $oneup = " "; $onedown = " "; $onedel = " - "; - user_error(print_r($recs,true)); + "; foreach($recs as $key => $rec){ $div ->AddEntry(array( array("string"=>$rec), @@ -329,7 +328,7 @@ class apacheVhostEdit extends plugin $smarty->assign("apacheScriptAlias", $div->DrawList()); /* Display template */ - $display.= $smarty->fetch(get_template_path('apache_editVhost.tpl', TRUE)); + $display.= $smarty->fetch(get_template_path('servApacheVhostEdit.tpl', TRUE)); return($display); } @@ -365,7 +364,7 @@ class apacheVhostEdit extends plugin */ } - if(!is_domain($this->apacheServerName) || empty($this->apacheServerName)){ + if(is_domain($this->apacheServerName) || empty($this->apacheServerName)){ $message[] =sprintf(_("Please choose a valid Virtual Host Name.")); } diff --git a/vhost-apache2/src/class_apacheVhost.inc b/vhost-apache2/src/class_servApacheVhost.inc similarity index 91% rename from vhost-apache2/src/class_apacheVhost.inc rename to vhost-apache2/src/class_servApacheVhost.inc index 90bf51bbe..495da7485 100644 --- a/vhost-apache2/src/class_apacheVhost.inc +++ b/vhost-apache2/src/class_servApacheVhost.inc @@ -13,7 +13,7 @@ class servapache extends plugin var $orig_dn = ""; - var $APACHE2initially_was_account; + var $APACHEinitially_was_account; function servapache ($config, $dn= NULL, $parent= NULL) @@ -26,14 +26,14 @@ class servapache extends plugin */ $this->Vhosts = getVhostEntries($config,$dn); - /* If there is at least one entry in this -> types, we have APACHE2 enabled + /* If there is at least one entry in this -> types, we have apache vhosts enabled */ if(count($this->Vhosts) == 0){ $this->is_account = false; }else{ $this->is_account = true; } - $this->APACHE2initially_was_account = $this->is_account; + $this->APACHEinitially_was_account = $this->is_account; } @@ -102,27 +102,27 @@ class servapache extends plugin /* Add empty new vhost */ - if(isset($_POST['AddVhost']) && chkacl($this->acl,"servapache2") == ""){ - $this->dialog = new apacheEditVhost($this->config,$this->dn); + if(isset($_POST['AddVhost']) && chkacl($this->acl,"servapache") == ""){ + $this->dialog = new servapacheVhostEdit($this->config,$this->dn); } /* Check for edit vhost request */ $once = false; foreach( $_POST as $name => $value){ - user_error(print_r($this->Vhosts,true)); + //user_error(print_r($this->Vhosts,true)); /* check all post for edit request */ - if(preg_match("/^editVhost_/",$name)&&!$once && chkacl($this->acl,"servapache2") == ""){ + if(preg_match("/^editVhost_/",$name)&&!$once && chkacl($this->acl,"servapache") == ""){ $once =true; $tmp = preg_replace("/^editVhost_/","",$name); $tmp = base64_decode(preg_replace("/_.*$/","",$tmp)); - $this->dialog= new apacheEditVhost($this->config,$this->dn,$this->Vhosts[$tmp]); + $this->dialog= new servapacheVhostEdit($this->config,$this->dn,$this->Vhosts[$tmp]); } /* check posts for delete vhost */ - if(preg_match("/^delVhost_/",$name)&&!$once && chkacl($this->acl,"servapache2") == ""){ + if(preg_match("/^delVhost_/",$name)&&!$once && chkacl($this->acl,"servapache") == ""){ $once =true; $tmp = preg_replace("/^delVhost_/","",$name); @@ -158,12 +158,12 @@ class servapache extends plugin )); } - $smarty->assign("servapache2ACL",chkacl($this->acl,"servapache2")); + $smarty->assign("servapacheACL",chkacl($this->acl,"servapache")); /* Display tempalte */ $smarty->assign("VhostList",$VhostList->DrawList()); - $display.= $smarty->fetch(get_template_path('apache_vhost.tpl', TRUE)); + $display.= $smarty->fetch(get_template_path('servApacheVhost.tpl', TRUE)); return($display); } @@ -201,7 +201,7 @@ class servapache extends plugin } } - /* Only show 2 apache2 in the error message + /* Only show 2 apache in the error message */ if(count($used)> 2) { $str .=" ... "; @@ -231,12 +231,11 @@ class servapache extends plugin } - /* Remove apache service */ function remove_from_parent() { - if($this->APACHE2initially_was_account){ + if($this->APACHEinitially_was_account){ $bool = true; foreach($this->Vhosts as $key => $vhost){ $bool= $bool & $this->RemoveVhost($key); @@ -250,7 +249,6 @@ class servapache extends plugin } - /* Save to LDAP */ function save() { @@ -296,10 +294,9 @@ class servapache extends plugin */ foreach($tmp['add'] as $dn => $attrs){ $ldap->cd($dn); - user_error(print_r($dn,true)); +// user_error(print_r($dn,true)); $ldap->cat($dn, array('dn')); if(count($ldap->fetch())){ - user_error("MODIFY".print_r($attrs,true)); $ldap->cd($dn); $ldap->modify ($attrs); }else{ diff --git a/vhost-apache2/src/functions_apache.inc b/vhost-apache2/src/functions_apache.inc index 9f11882f1..be0b3f026 100644 --- a/vhost-apache2/src/functions_apache.inc +++ b/vhost-apache2/src/functions_apache.inc @@ -13,7 +13,7 @@ function getVhostEntries($config,$HostDn,$silent = false) $ldap->cat($HostDn); $host_attr = $ldap->fetch(); - /* Create tempalte for all fetched zone Data + /* Create template for all fetched vhosts Data */ $VhostBase = array(); $VhostBase['exists'] = false; @@ -23,7 +23,7 @@ function getVhostEntries($config,$HostDn,$silent = false) $Vhosts = array(); - /* Get & Parse all zone entries + /* Get & Parse all vhosts entries */ $ldap->ls("(&(objectClass=apacheConfig)(apacheServerName=*))",$HostDn,array("*")); $tmp_res = array(); @@ -31,7 +31,7 @@ function getVhostEntries($config,$HostDn,$silent = false) $tmp_res[] = $attrs; } - /* Parse fetched zones + /* Parse fetched vhosts */ foreach($tmp_res as $attrs){ @@ -47,7 +47,7 @@ function getVhostEntries($config,$HostDn,$silent = false) $Vhosts[$apacheServerName]["apacheConfig"] = $attrs["apacheConfig"][0]; } - /* Set initial zone name, to be able to detect if this entry was renamed + /* Set initial vhosts name, to be able to detect if this entry was renamed */ $Vhosts[$apacheServerName]['InitialApacheServerName'] = $apacheServerName; $Vhosts[$apacheServerName]['apacheServerName'] = $apacheServerName; @@ -72,7 +72,7 @@ function getVhostEntries($config,$HostDn,$silent = false) } -/* This function compares two dns zone objects and returns an +/* This function compares two apache vhosts objects and returns an * array with following indexes * - delete, for vhost entries which must be deleted (only if vhost entries is removed) * - rename, if a dn must be renamed, for example, the apacheServerName has changed @@ -86,26 +86,26 @@ function getVhostEntriesDiff($config,$newVhosts,$HostDn) $add = array(); $del = array(); - /* Generate a template for zones with default values + /* Generate a template for vhosts with default values */ $zoneBase = array(); $zoneBase['objectClass'] = array("top","apacheConfig"); $zoneBase['apacheServerName'] = ""; /* Contains all renamed apacheServerNames - * For zone entry udpdates + * For vhosts entry udpdates */ $PrePareVhostEntries = array(); - /* Walk through all zones and detect renamed/added/deleted zones ... + /* Walk through all vhosts and detect renamed/added/deleted vhosts ... */ foreach($newVhosts as $name => $zone){ - /* This zone was renamed + /* This vhosts was renamed */ if((!empty($zone['InitialApacheServerName'])) && ($zone['InitialApacheServerName'] != $zone['apacheServerName'])){ - /* Move old zone to new position + /* Move old vhosts to new position */ $oldDn = "apacheServerName=".$zone['InitialApacheServerName'].",".$HostDn; $newDn = "apacheServerName=".$zone['apacheServerName'].",".$HostDn; @@ -113,7 +113,7 @@ function getVhostEntriesDiff($config,$newVhosts,$HostDn) $move [$oldDn] = $newDn; } - /* Get old zone if available + /* Get old vhosts if available */ $oldVhost=array(); if(isset($oldVhosts[$zone['InitialApacheServerName']])){ @@ -122,31 +122,36 @@ function getVhostEntriesDiff($config,$newVhosts,$HostDn) } } - /* Create forward zone entry and put it in our add queue + /* Create vhosts entry and put it in our add queue */ $newDn = "apacheServerName=".$zone['apacheServerName'].",".$HostDn; $obj = $zoneBase; $obj['apacheServerName'] = $zone['apacheServerName']; - $obj['apacheDocumentRoot'] = $zone['apacheDocumentRoot']; - $obj['apacheServerAdmin'] = $zone['apacheServerAdmin']; - + $obj['apacheDocumentRoot'] = $zone['apacheDocumentRoot']; + $obj['apacheServerAdmin'] = $zone['apacheServerAdmin']; - foreach($zone['apacheServerAlias'] as $rec){ - $obj['apacheServerAlias'][] = $rec; - } - foreach($zone['apacheScriptAlias'] as $rec){ - $obj['apacheScriptAlias'][] = $rec; + if(!empty($zone['apacheServerAlias'])) { + + foreach($zone['apacheServerAlias'] as $rec){ + $obj['apacheServerAlias'][] = $rec; + } } - - /* Append udpated Vhost Forward Entry to our add queue + + if(!empty($zone['apacheScriptAlias'])) { + foreach($zone['apacheScriptAlias'] as $rec){ + $obj['apacheScriptAlias'][] = $rec; + } + } + + /* Append udpated Vhost Entry to our add queue */ $add[$newDn] = $obj; - /* Remove currently managed zone from oldVhosts. - * this gives us the ability to detect removed zones + /* Remove currently managed vhosts from oldVhosts. + * this gives us the ability to detect removed vhosts */ if(isset($oldVhosts[$zone['InitialApacheServerName']])){ - unset($oldVhosts[$zone['InitialApacheServerName']]); + unset($oldVhosts[$zone['InitialApacheServerName']]); } } @@ -174,7 +179,7 @@ function getVhostEntriesDiff($config,$newVhosts,$HostDn) } $ret = array("del" => $del , "move" => $move , "add" => $add,"vhostUpdates"=>$zoneUpdates); - user_error(print_r($ret,true)); +// user_error(print_r($ret,true)); return($ret); } @@ -184,7 +189,7 @@ function getVhostDN($config,$apacheServerNameMix) { $ret = ""; if(!strstr($apacheServerNameMix, '/')) { - print_red(sprintf(_("Undefined zone name '%s'. Vhost name must look like this 'server/zone.com'."),$apacheServerNameMix)); + print_red(sprintf(_("Undefined vhost name '%s'. Vhost name must look like this 'server/zone.com'."),$apacheServerNameMix)); return($ret); } @@ -213,7 +218,7 @@ function getVhostDN($config,$apacheServerNameMix) } -/* returns all available zones +/* returns all available vhosts * array[reverseName] = apacheServerName; */ function getAvailableVhosts($config) @@ -222,7 +227,7 @@ function getAvailableVhosts($config) $ldap = $config->get_ldap_link(); $ldap->cd ($config->current['BASE']); - /* Search for zones ... + /* Search for vhosts ... */ $ldap->search("(&(objectClass=apacheConfig)(apacheServerName=*))",array("apacheServerName")); @@ -241,5 +246,5 @@ function getAvailableVhosts($config) } return($zones); } - + ?> diff --git a/vhost-apache2/src/apache_vhost.tpl b/vhost-apache2/src/servApacheVhost.tpl similarity index 67% rename from vhost-apache2/src/apache_vhost.tpl rename to vhost-apache2/src/servApacheVhost.tpl index d8eec5d7f..a1449753b 100644 --- a/vhost-apache2/src/apache_vhost.tpl +++ b/vhost-apache2/src/servApacheVhost.tpl @@ -4,8 +4,6 @@ {$VhostList} - - diff --git a/vhost-apache2/src/apache_editVhost.tpl b/vhost-apache2/src/servApacheVhostEdit.tpl similarity index 100% rename from vhost-apache2/src/apache_editVhost.tpl rename to vhost-apache2/src/servApacheVhostEdit.tpl -- 2.30.2