From 8842abdfb6fa86665e7114bf83759f7a5c6dd288 Mon Sep 17 00:00:00 2001 From: hickert Date: Wed, 4 Jun 2008 11:11:31 +0000 Subject: [PATCH] Updated apache service git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@11206 594d385d-05f5-0310-b6e9-bd551577e9d8 --- .../services/apache2/class_apacheUtils.inc | 7 - .../apache2/class_servApacheEditVhost.inc | 277 +++++++++--------- .../apache2/class_servApacheVhost.inc | 34 ++- .../services/apache2/servApacheVhostEdit.tpl | 6 +- 4 files changed, 166 insertions(+), 158 deletions(-) diff --git a/gosa-plugins/apache2/admin/systems/services/apache2/class_apacheUtils.inc b/gosa-plugins/apache2/admin/systems/services/apache2/class_apacheUtils.inc index 5439cac35..7271ddc1c 100644 --- a/gosa-plugins/apache2/admin/systems/services/apache2/class_apacheUtils.inc +++ b/gosa-plugins/apache2/admin/systems/services/apache2/class_apacheUtils.inc @@ -248,13 +248,6 @@ class apacheUtils extends plugin } return($zones); } - - /* Simple is domain check, it checks if the given string looks like "string.string.string" - or string.string */ - public static function GetVhostsDomain($str) - { - return(preg_match("/[^\.\/]+\.[^\.\/]+$/",$str)); - } } ?> diff --git a/gosa-plugins/apache2/admin/systems/services/apache2/class_servApacheEditVhost.inc b/gosa-plugins/apache2/admin/systems/services/apache2/class_servApacheEditVhost.inc index 60d64b9c5..19fba7af3 100644 --- a/gosa-plugins/apache2/admin/systems/services/apache2/class_servApacheEditVhost.inc +++ b/gosa-plugins/apache2/admin/systems/services/apache2/class_servApacheEditVhost.inc @@ -1,4 +1,25 @@ OldApacheServerName = ""; $this->isNew = true; - $this->InitialApacheServerName = "";//$attrs['InitialApacheServerName']; }else{ $this->VhostObject = $attrs; - $this->OldApacheServerName = $attrs['apacheServerName']; - $this->InitialApacheServerName = $attrs['InitialApacheServerName']; - $this->isNew = false; - foreach($this->attributes as $value){ if(isset($attrs[$value])){ $this->$value = $attrs[$value]; @@ -57,7 +72,6 @@ class servapacheVhostEdit extends plugin if(!isset($attrs['apacheServerAlias'])) $this->apacheServerAlias = array(); if(!isset($attrs['apacheScriptAlias'])) $this->apacheScriptAlias = array(); - } } @@ -136,53 +150,62 @@ class servapacheVhostEdit extends plugin $smarty= get_smarty(); $display= ""; - /* Open Vhost Entry Edit Dialog +// Outdated? + +# /* Open Vhost Entry Edit Dialog +# */ +# if(!count($this->VhostObject)){ +# $smarty->assign("AllowVhostEdit" , false); +# }else{ +# $smarty->assign("AllowVhostEdit" , true); +# if(isset($_POST['EditVhostEntries'])){ +# $this->dialog= new apacheVhostEditEntries($this->config,$this->dn,$this->VhostObject); +# } +# } +# +# /* Save Vhost Entry Edit Dialog +# */ +# if(isset($_POST['SaveVhostEntryChanges'])){ +# $this->dialog->save_object(); +# if(count($this->dialog->check())){ +# msg_dialog::displayChecks($this->dialog->check()); +# }else{ +# $this->dialog->save(); +# $this->dialog = false; +# } +# } +# +# /* Cancel Vhost Entrie Edit Dialog +# */ +# if(isset($_POST['CancelVhostEntryChanges'])){ +# $this->dialog = false; +# } +# +# /* Display any type of open dialogs +# */ +# if($this->dialog){ +# $this->dialog->save_object(); +# return($this->dialog->execute()); +# } +# + + /* Check posts */ - if(!count($this->VhostObject)){ - $smarty->assign("AllowVhostEdit" , false); - }else{ - $smarty->assign("AllowVhostEdit" , true); - if(isset($_POST['EditVhostEntries'])){ - $this->dialog= new apacheVhostEditEntries($this->config,$this->dn,$this->VhostObject); - } - } - - /* Save Vhost Entry Edit Dialog - */ - if(isset($_POST['SaveVhostEntryChanges'])){ - $this->dialog->save_object(); - if(count($this->dialog->check())){ - msg_dialog::displayChecks($this->dialog->check()); - }else{ - $this->dialog->save(); - $this->dialog = false; - } - } - - /* Cancel Vhost Entrie Edit Dialog - */ - if(isset($_POST['CancelVhostEntryChanges'])){ - $this->dialog = false; - } - - /* Display any type of open dialogs - */ - if($this->dialog){ - $this->dialog->save_object(); - return($this->dialog->execute()); - } - $once =true; foreach($_POST as $name => $value){ + + /* Move Server Aliases one position up + */ if((preg_match("/^SAup_/",$name)) && ($once)){ $once = false; - $id = preg_replace("/^SAup_/","",$name); $id = preg_replace("/_.*$/","",$id); $id = base64_decode($id); - $this->apacheServerAlias = $this->ArrayUp(($id+1),$this->apacheServerAlias); } + + /* Move Server Aliases one position down + */ if((preg_match("/^SAdown_/",$name)) && ($once)){ $once = false; @@ -192,136 +215,116 @@ class servapacheVhostEdit extends plugin $this->apacheServerAlias = $this->ArrayDown(($id+1),$this->apacheServerAlias); } + + /* Delete a "Server Alias" + */ if((preg_match("/^SAdel_/",$name)) && ($once)){ $once = false; - $id = preg_replace("/^SAdel_/","",$name); $id = preg_replace("/_.*$/","",$id); $id = base64_decode($id); - unset($this->apacheServerAlias[$id]); - $tmp =array(); foreach($this->apacheServerAlias as $entry){ $tmp[] = $entry; } - $this->apacheServerAlias = $tmp; } + /* Move "Script Alias" one position up + */ if((preg_match("/^SCup_/",$name)) && ($once)){ $once = false; - $id = preg_replace("/^SCup_/","",$name); $id = preg_replace("/_.*$/","",$id); $id = base64_decode($id); - $this->apacheScriptAlias = $this->ArrayUp(($id+1),$this->apacheScriptAlias); } + + /* Move "Script Alias" one position down + */ if((preg_match("/^SCdown_/",$name)) && ($once)){ $once = false; - $id = preg_replace("/^SCdown_/","",$name); $id = preg_replace("/_.*$/","",$id); $id = base64_decode($id); - $this->apacheScriptAlias = $this->ArrayDown(($id+1),$this->apacheScriptAlias); } + + /* Remove "Script Alias" + */ if((preg_match("/^SCdel_/",$name)) && ($once)){ $once = false; - $id = preg_replace("/^SCdel_/","",$name); $id = preg_replace("/_.*$/","",$id); $id = base64_decode($id); - unset($this->apacheScriptAlias[$id]); - $tmp =array(); foreach($this->apacheScriptAlias as $entry){ $tmp[] = $entry; } - $this->apacheScriptAlias = $tmp; } - } + /* Add a new "Server Alias" + */ if((isset($_POST['AddSARecord'])) && (!empty($_POST['StrSAAlias'])) && (!empty($_POST['StrSADir']))){ $this->apacheServerAlias[] = trim($_POST['StrSAAlias']." ".$_POST['StrSADir']); } + /* Add a new "Script Alias" + */ if((isset($_POST['AddSCRecord'])) && (!empty($_POST['StrSCAlias'])) && (!empty($_POST['StrSCDir']))){ $this->apacheScriptAlias[] = trim($_POST['StrSCAlias']." ".$_POST['StrSCDir']); } - /* Handle Post events */ - $once = true; - foreach($_POST as $name => $value){ - - /* Delete vhosts if requested */ - if((preg_match("/RemoveRecord_/",$name))&&($once)){ - $once = false; - $id= preg_replace("/RemoveRecord_/","",$name); - unset($this->Records[$id]); - } - } - - /* Add new Vhostrecord */ - /* if(isset($_POST['AddNewRecord'])){ - $this->Records[] = array("type"=>"aRecord","value"=>""); - }*/ - /* Fill in values */ foreach($this->attributes as $name){ $smarty->assign($name,$this->$name); } /* Set apacheServerNames without server suffix */ - $smarty->assign("apacheServerName",$this->apacheServerName); + $smarty->assign("apacheServerName",$this->apacheServerName); + $smarty->assign("NotNew", false); + + /* Create Server Aliases divlist + */ $div = new divSelectBox("apacheServerAlias"); $div->setHeight(120); $recs = $this->apacheServerAlias; - $oneup = " "; - $onedown = " "; - $onedel = " - "; + $oneup = " "; + $onedown = " "; + $onedel = ""; foreach($recs as $key => $rec){ $div ->AddEntry(array( array("string"=>$rec), -/* array("string"=>$key, - "attach"=>"style='width:20px;'"),*/ array("string"=>str_replace("%s",base64_encode($key),$oneup.$onedown.$onedel), "attach"=>"style='width:70px;border-right:0px;'") )); } - - $smarty->assign("NotNew", false); - $smarty->assign("apacheServerAlias", $div->DrawList()); + + /* Create Server Aliases divlist + */ $div = new DivSelectBox("apacheScriptAlias"); $div->setHeight(120); $recs = $this->apacheScriptAlias; - $oneup = " "; - $onedown = " "; - $onedel = " - "; + $oneup = " "; + $onedown = " "; + $onedel = ""; foreach($recs as $key => $rec){ $div ->AddEntry(array( array("string"=>$rec), -/* array("string"=>$key, - "attach"=>"style='width:20px;'"),*/ array("string"=>str_replace("%s",base64_encode($key),$oneup.$onedown.$onedel), "attach"=>"style='width:70px;border-right:0px;'") )); } - - $smarty->assign("NotNew", false); - $smarty->assign("apacheScriptAlias", $div->DrawList()); /* Display template */ @@ -329,20 +332,16 @@ class servapacheVhostEdit extends plugin return($display); } + function remove_from_parent() { } + /* Save data to object */ function save_object() { - //plugin::save_object(); - foreach($this->attributes as $attr){ - if(isset($_POST[$attr])){ - $this->$attr = $_POST[$attr]; - } - } - + plugin::save_object(); } @@ -355,55 +354,54 @@ class servapacheVhostEdit extends plugin /* Check if apacheServerName is already in use */ $usedVhosts = $this->getUsedServerNames(); if(($this->isNew == true)||($this->apacheServerName != $this->InitialApacheServerName)){ -/* if((isset($usedVhosts[$this->apacheServerName]))&&($this->apacheServerName != $this->InitialApacheServerName)){ - $message[] =_("This apacheServerName is already in use"); + if((isset($usedVhosts[$this->apacheServerName]))&&($this->apacheServerName != $this->InitialApacheServerName)){ + $message[] = msgPool::duplicated(_("Name")); } -*/ } - if(!apacheUtils::GetVhostsDomain($this->apacheServerName) || empty($this->apacheServerName)){ - $message[] =sprintf(_("Please choose a valid Virtual Host Name.")); + /* Check given virtual server name + */ + if(!tests::is_domain($this->apacheServerName) || empty($this->apacheServerName)){ + $message[] = msgPool::invalid(_("Virtual host name"),$this->apacheServerName,"", + _("Only lowercase strings are allowed as Virtual Host Name.")." "._("e.g. example.com")); } + /* check if there is a valid document root given + */ if(!tests::is_path($this->apacheDocumentRoot) || empty($this->apacheDocumentRoot)){ - $message[] = _("Please choose a valid Path as Virtual Host Document Root."); + $message[] = msgPool::invalid(_("Document root"),$this->apacheDocumentRoot); } - + + /* Check given mail address + */ if(!tests::is_email($this->apacheServerAdmin) || empty($this->apacheServerAdmin)){ - $message[] = _("Please choose a valid Email Account as Admin Mail address."); - } - - if($this->apacheServerName != strtolower($this->apacheServerName)){ - $message[] = _("Only lowercase strings are allowed as Virtual Host Name."); - } - - if($this->apacheDocumentRoot != strtolower($this->apacheDocumentRoot)){ - $message[] = _("Only lowercase strings are allowed as Virtual Host Document Root."); - } - - if($this->apacheServerAdmin != strtolower($this->apacheServerAdmin)){ - $message[] = _("Only lowercase strings are allowed as Admin Mail address."); + $message[] = msgPool::invalid(_("Admin mail address"),$this->apacheServerAdmin); } + /* Check server aliases + */ foreach($this->apacheServerAlias as $key => $line){ - $apacheServerAlias_ar=split(" ",$line); - $url=$apacheServerAlias_ar[0]; - if(!is_path($url)){ - $message[] = sprintf(_("Please choose a valid Path as URL Alias Path in line: %s"),$line); - } + $apacheServerAlias_ar=split(" ",$line); + $url=$apacheServerAlias_ar[1]; + if(!tests::is_path($url)){ + $message[] = msgPool::invalid(_("Server alias")); + } } - - foreach($this->apacheScriptAlias as $key => $line){ - $apacheScriptAlias_ar=split(" ",$line); - $url=$apacheScriptAlias_ar[0]; - if(!is_path($url)){ - $message[] = sprintf(_("Please choose a valid Path as URL Alias Path in line: %s"),$line); - } + + /* Check script aliases + */ + foreach($this->apacheScriptAlias as $key => $line){ + $apacheScriptAlias_ar=split(" ",$line); + $url=$apacheScriptAlias_ar[1]; + if(!tests::is_path($url)){ + $message[] = msgPool::invalid(_("Script alias")); + } } - + return ($message); } + /* This funtion returns all used apacheServerNames */ function getUsedServerNames() { @@ -417,6 +415,7 @@ class servapacheVhostEdit extends plugin return($ret); } + /* Save to LDAP */ function save() { @@ -431,8 +430,8 @@ class servapacheVhostEdit extends plugin $rec['value']= $key." ".$rec['value']; $this->Records [] = $rec; } - - /* Create SC records + + /* Create SC records */ foreach($this->apacheScriptAlias as $key => $rec){ $rec['value']= $key." ".$rec['value']; @@ -440,12 +439,10 @@ class servapacheVhostEdit extends plugin } $ret['RECORDS'] = $this->Records; - $ret['InitialApacheServerName'] = $this->InitialApacheServerName; - return($ret); } } - +// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: ?> diff --git a/gosa-plugins/apache2/admin/systems/services/apache2/class_servApacheVhost.inc b/gosa-plugins/apache2/admin/systems/services/apache2/class_servApacheVhost.inc index 3cb51cd74..51c7c4d16 100644 --- a/gosa-plugins/apache2/admin/systems/services/apache2/class_servApacheVhost.inc +++ b/gosa-plugins/apache2/admin/systems/services/apache2/class_servApacheVhost.inc @@ -1,5 +1,26 @@ $value){ - //user_error(print_r($this->Vhosts,true)); + /* check all post for edit request */ if(preg_match("/^editVhost_/",$name)&& !$once && $this->acl_is_writeable("VirtualHosts")){ @@ -123,11 +144,11 @@ class servapache extends goService */ $VhostList = new divSelectBox("apacheConfigs"); $VhostList -> SetHeight(254); - + /* Add entries to divlist */ - $editImg = " - "; + $editImg = " + "; foreach($this->Vhosts as $vhost => $values ){ $VhostList->AddEntry(array( array("string" => $vhost), @@ -135,7 +156,6 @@ class servapache extends goService )); } - /* Assign ACL to smarty */ $info = $this->plInfo(); @@ -176,7 +196,7 @@ class servapache extends goService } - /* Remove apache service + /* Remove apache service */ function remove_from_parent() { @@ -209,7 +229,6 @@ class servapache extends goService } $tmp = apacheUtils::getVhostEntriesDiff($this->config,$this->Vhosts,$old_dn); - print_a($tmp); /* Updated vhost entries if reverser or forward name has changed * Must be done before moving entries, else the given dn is invalid @@ -245,7 +264,6 @@ class servapache extends goService */ foreach($tmp['add'] as $dn => $attrs){ $ldap->cd($dn); -// user_error(print_r($dn,true)); $ldap->cat($dn, array('dn')); if(count($ldap->fetch())){ $ldap->cd($dn); diff --git a/gosa-plugins/apache2/admin/systems/services/apache2/servApacheVhostEdit.tpl b/gosa-plugins/apache2/admin/systems/services/apache2/servApacheVhostEdit.tpl index 3044f9d1b..9f08e8db1 100644 --- a/gosa-plugins/apache2/admin/systems/services/apache2/servApacheVhostEdit.tpl +++ b/gosa-plugins/apache2/admin/systems/services/apache2/servApacheVhostEdit.tpl @@ -4,19 +4,19 @@ - - - -- 2.30.2
{t}Virtual Host Name{/t}{$must} + {t}Virtual host name{/t}{$must}
{t}Virtual Host Document Root{/t}{$must} + {t}Document root{/t}{$must}
{t}Admin Mail address{/t}{$must} + {t}Admin mail address{/t}{$must}