Code

Updated apache service
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Wed, 4 Jun 2008 11:11:31 +0000 (11:11 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Wed, 4 Jun 2008 11:11:31 +0000 (11:11 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@11206 594d385d-05f5-0310-b6e9-bd551577e9d8

gosa-plugins/apache2/admin/systems/services/apache2/class_apacheUtils.inc
gosa-plugins/apache2/admin/systems/services/apache2/class_servApacheEditVhost.inc
gosa-plugins/apache2/admin/systems/services/apache2/class_servApacheVhost.inc
gosa-plugins/apache2/admin/systems/services/apache2/servApacheVhostEdit.tpl

index 5439cac35a04a0af1817a52c04fe01849a810029..7271ddc1c23177987fb6f0edf5f6b6476a113041 100644 (file)
@@ -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));
-       }
 }
 
 ?>
index 60d64b9c58b43bd2a14271ffeccab317000c472e..19fba7af31b6d2fae48eec60684bf7679b4ed42b 100644 (file)
@@ -1,4 +1,25 @@
 <?php
+/*
+ * This code is part of GOsa (http://www.gosa-project.org)
+ * Copyright (C) 2003-2008 GONICUS GmbH
+ *
+ * ID: $$Id: class_gosaSupportDaemon.inc 10788 2008-05-06 11:15:57Z $$
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
 
 class servapacheVhostEdit extends plugin
 {
@@ -6,11 +27,10 @@ class servapacheVhostEdit extends plugin
   var $ignore_account= TRUE;
   
   var $attributes      = array("apacheServerName","apacheDocumentRoot","apacheServerAlias",
-       "apacheServerAdmin","apacheScriptAlias","apacheSuexecUid","apacheSuexecGid");
+               "apacheServerAdmin","apacheScriptAlias","apacheSuexecUid","apacheSuexecGid");
       
   var $objectclasses  = array("whatever");
 
-  
   var $apacheServerName                = "";
   var $apacheDocumentRoot      = "";
   var $apacheServerAdmin       = "";
@@ -31,24 +51,19 @@ class servapacheVhostEdit extends plugin
   var $cn;
   var $VhostObject               = array();
 
+
   function servapacheVhostEdit ($config, $dn= NULL,$attrs = array())
   {
     plugin::plugin ($config, $dn);
     if(!count($attrs)){
       $this->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    = "<input name='SAup_%s'    type='image' src='images/sort_up.png'    title='"._("Up")."'      class='center'>&nbsp;"; 
-    $onedown  = "<input name='SAdown_%s'  type='image' src='images/sort_down.png'  title='"._("Down")."'    class='center'>&nbsp;"; 
-    $onedel   = "<img src='images/empty.png' width='20' class='center'>
-                 <input name='SAdel_%s'   type='image' src='images/edittrash.png'  title='"._("Delete")."'  class='center'>";
+    $oneup    = "<input name='SAup_%s'    type='image' src='images/lists/sort-up.png'    title='"._("Up")."'      class='center'>&nbsp;"; 
+    $onedown  = "<input name='SAdown_%s'  type='image' src='images/lists/sort-down.png'  title='"._("Down")."'    class='center'>&nbsp;"; 
+    $onedel   = "<input name='SAdel_%s'   type='image' src='images/lists/trash.png'      title='"._("Delete")."'  class='center'>";
     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    = "<input name='SCup_%s'    type='image' src='images/sort_up.png'    title='"._("Up")."'      class='center'>&nbsp;"; 
-    $onedown  = "<input name='SCdown_%s'  type='image' src='images/sort_down.png'  title='"._("Down")."'    class='center'>&nbsp;"; 
-    $onedel   = "<img src='images/empty.png' width='20' class='center'>
-                 <input name='SCdel_%s'   type='image' src='images/edittrash.png'  title='"._("Delete")."'  class='center'>"; 
+    $oneup    = "<input name='SCup_%s'    type='image' src='images/lists/sort-up.png'    title='"._("Up")."'      class='center'>&nbsp;"; 
+    $onedown  = "<input name='SCdown_%s'  type='image' src='images/lists/sort-down.png'  title='"._("Down")."'    class='center'>&nbsp;"; 
+    $onedel   = "<input name='SCdel_%s'   type='image' src='images/lists/trash.png'      title='"._("Delete")."'  class='center'>"; 
     
     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.")."&nbsp;"._("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:
 ?>
index 3cb51cd74385f7f415ff25205296434eaf00e0e2..51c7c4d1677d5a2b9ee7383477c32c8cc2b111f1 100644 (file)
@@ -1,5 +1,26 @@
 <?php
 
+/*
+ * This code is part of GOsa (http://www.gosa-project.org)
+ * Copyright (C) 2003-2008 GONICUS GmbH
+ *
+ * ID: $$Id: class_gosaSupportDaemon.inc 10788 2008-05-06 11:15:57Z hickert $$
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
 class servapache extends goService
 {
   /* attribute list for save action */
@@ -87,7 +108,7 @@ class servapache extends goService
      */
     $once = false;
     foreach( $_POST as $name => $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 = "<input type='image' src='images/edit.png' name='editVhost_%s'>
-      <input type='image' src='images/edittrash.png' name='delVhost_%s'>";
+    $editImg = "<input type='image' src='images/lists/edit.png' name='editVhost_%s'>
+      <input type='image' src='images/lists/trash.png' name='delVhost_%s'>";
     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);
index 3044f9d1b577b018d5fc38b05ad227cd99bb488d..9f08e8db1c154c9452af2e3192fa4264a3622337 100644 (file)
@@ -4,19 +4,19 @@
                <td style="width:50%;vertical-align:top;border-right:1px        solid   #b0b0b0;">
                        <table summary="">
                                <tr>
-                                       <td>{t}Virtual Host Name{/t}{$must}
+                                       <td>{t}Virtual host name{/t}{$must}
                                        </td>
                                        <td><input type="text" name="apacheServerName" value="{$apacheServerName}" {if $NotNew} disabled {/if}>
                                        </td>
                                </tr>
                                <tr>
-                                       <td>{t}Virtual Host Document Root{/t}{$must}
+                                       <td>{t}Document root{/t}{$must}
                                        </td>
                                        <td><input type="text" name="apacheDocumentRoot" value="{$apacheDocumentRoot}">
                                        </td>
                                </tr>
                                <tr>
-                                       <td>{t}Admin Mail address{/t}{$must}
+                                       <td>{t}Admin mail address{/t}{$must}
                                        </td>
                                        <td><input type="text" name="apacheServerAdmin" value="{$apacheServerAdmin}">
                                        </td>