Code

Updated apache stuff - Works, but not cleanup.
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Tue, 3 Jun 2008 13:22:42 +0000 (13:22 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Tue, 3 Jun 2008 13:22:42 +0000 (13:22 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@11176 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/servApacheVhost.tpl

index a9538f3517c9df64a470f0a90eef3ce62bfeecfc..5439cac35a04a0af1817a52c04fe01849a810029 100644 (file)
@@ -5,7 +5,7 @@ class apacheUtils extends plugin
 
        /* This function returns the vhost entries specified for given host
         */
-       function getVhostEntries($config,$HostDn,$silent = false)
+       public static function getVhostEntries($config,$HostDn,$silent = false)
        {
 
          $ldap = $config->get_ldap_link();
@@ -80,7 +80,7 @@ class apacheUtils extends plugin
         *   - rename, if a dn must be renamed, for example, the apacheServerName has changed
         *   - add,    if there is a new vhost entries created    
         */
-       function getVhostEntriesDiff($config,$newVhosts,$HostDn)
+       public static function getVhostEntriesDiff($config,$newVhosts,$HostDn)
        {
          $oldVhosts = apacheUtils::getVhostEntries($config,$HostDn,true);
 
@@ -251,7 +251,7 @@ class apacheUtils extends plugin
          
        /* Simple is domain check, it checks if the given string looks like "string.string.string"
           or string.string */
-       function GetVhostsDomain($str)
+       public static function GetVhostsDomain($str)
        {
          return(preg_match("/[^\.\/]+\.[^\.\/]+$/",$str));
        }
index 64045327a618cb79e2e428517ac54fa280435c81..60d64b9c58b43bd2a14271ffeccab317000c472e 100644 (file)
@@ -152,10 +152,7 @@ class servapacheVhostEdit extends plugin
     if(isset($_POST['SaveVhostEntryChanges'])){
       $this->dialog->save_object();
       if(count($this->dialog->check())){
-        $msgs = $this->dialog->check();
-        foreach($msgs as $msg){
-          print_red($msg);
-        }
+         msg_dialog::displayChecks($this->dialog->check());
       }else{
         $this->dialog->save();
         $this->dialog = false;
@@ -282,7 +279,7 @@ class servapacheVhostEdit extends plugin
     /* Set apacheServerNames without server suffix */
       $smarty->assign("apacheServerName",$this->apacheServerName);
 
-    $div = new DivSelectBox("apacheServerAlias");
+    $div = new divSelectBox("apacheServerAlias");
     $div->setHeight(120);
     $recs = $this->apacheServerAlias;
 
@@ -328,7 +325,7 @@ class servapacheVhostEdit extends plugin
     $smarty->assign("apacheScriptAlias",  $div->DrawList());    
     
     /* Display template */
-    $display.= $smarty->fetch(get_template_path('servApacheVhostEdit.tpl', TRUE));
+    $display.= $smarty->fetch(get_template_path('servApacheVhostEdit.tpl', TRUE, dirname(__FILE__)));
     return($display);
   }
 
@@ -368,11 +365,11 @@ class servapacheVhostEdit extends plugin
       $message[] =sprintf(_("Please choose a valid Virtual Host Name."));
     }
 
-    if(!is_path($this->apacheDocumentRoot) || empty($this->apacheDocumentRoot)){
+    if(!tests::is_path($this->apacheDocumentRoot) || empty($this->apacheDocumentRoot)){
       $message[] = _("Please choose a valid Path as Virtual Host Document Root.");
     }
     
-       if(!is_email($this->apacheServerAdmin) || empty($this->apacheServerAdmin)){
+       if(!tests::is_email($this->apacheServerAdmin) || empty($this->apacheServerAdmin)){
       $message[] = _("Please choose a valid Email Account as Admin Mail address.");
     }
 
index 868c7a8134162204922e1efe558d27b6e61e6e96..3cb51cd74385f7f415ff25205296434eaf00e0e2 100644 (file)
@@ -8,9 +8,8 @@ class servapache extends goService
   var $objectclasses    = array("whatever");
 
   var $RecordTypes      = array();
-  var $Vhosts            = array();
+  var $Vhosts           = array();
   var $dialog           = NULL;
-
   var $orig_dn          = "";
 
   var $APACHEinitially_was_account;
@@ -34,6 +33,9 @@ class servapache extends goService
       $this->is_account = true;
     }
     $this->APACHEinitially_was_account = $this->is_account;
+
+    /* Set service name */
+    $this->DisplayName = _("Apache service");
   }
 
 
@@ -48,29 +50,6 @@ class servapache extends goService
     $smarty= get_smarty();
     $display= "";
 
-    /* Do we need to flip is_account state? 
-     */
-    if (isset($_POST['modify_state'])){
-
-      /* Only change account state if allowed */
-      if($this->is_account && $this->acl == "#all#"){
-        $this->is_account= !$this->is_account;
-        $this->is_modified = true;
-      }elseif(!$this->is_account && chkacl($this->acl,"create") == ""){
-        $this->is_account= !$this->is_account;
-        $this->is_modified = true;
-      }
-    }
-
-    if ($this->is_account){
-      $display= $this->show_header(_("Remove Apache service"),
-          _("This server has Apache features enabled. You can disable them by clicking below."));
-    } else {
-      $display= $this->show_header(_("Add Apache service"),
-          _("This server has Apache features disabled. You can enable them by clicking below."));
-      return ($display);
-    }
-
     /* Edited or Added vhost 
      */
     if((isset($_POST['SaveVhostChanges'])) && is_object($this->dialog)){
@@ -79,9 +58,7 @@ class servapache extends goService
       /* Check for errors  
        */
       if(count($this->dialog->check())){
-        foreach($this->dialog->check() as $msgs){
-          print_red($msgs); 
-        }
+        msg_dialog::displayChecks($this->dialog->check());
       }else{
         /* add new/edited vhost 
          */
@@ -102,7 +79,7 @@ class servapache extends goService
 
     /* Add empty new vhost 
      */
-    if(isset($_POST['AddVhost']) && chkacl($this->acl,"servapache") == ""){
+    if(isset($_POST['AddVhost']) && $this->acl_is_writeable("VirtualHosts")){
       $this->dialog = new servapacheVhostEdit($this->config,$this->dn);
     }
 
@@ -113,7 +90,7 @@ class servapache extends goService
        //user_error(print_r($this->Vhosts,true));
       /* check all post for edit request 
        */
-      if(preg_match("/^editVhost_/",$name)&&!$once && chkacl($this->acl,"servapache") == ""){
+      if(preg_match("/^editVhost_/",$name)&& !$once && $this->acl_is_writeable("VirtualHosts")){
         $once =true;
         $tmp = preg_replace("/^editVhost_/","",$name);
         $tmp = base64_decode(preg_replace("/_.*$/","",$tmp));
@@ -122,7 +99,7 @@ class servapache extends goService
 
       /* check posts for delete vhost 
        */
-      if(preg_match("/^delVhost_/",$name)&&!$once && chkacl($this->acl,"servapache") == ""){
+      if(preg_match("/^delVhost_/",$name)&&!$once && $this->acl_is_writeable("VirtualHosts")){
 
         $once =true;
         $tmp = preg_replace("/^delVhost_/","",$name);
@@ -157,13 +134,20 @@ class servapache extends goService
             array("string" => str_replace("%s",base64_encode($vhost),$editImg))
             ));
     }    
-  
-    $smarty->assign("servapacheACL",chkacl($this->acl,"servapache"));
+
+
+    /* Assign ACL to smarty 
+     */    
+    $info = $this->plInfo();
+    foreach($info['plProvidedAcls'] as $name => $desc){
+      $smarty->assign($name."ACL",$this->getacl($name));
+    }
+
   
     /* Display template 
      */
     $smarty->assign("VhostList",$VhostList->DrawList());
-    $display.= $smarty->fetch(get_template_path('servApacheVhost.tpl', TRUE));
+    $display.= $smarty->fetch(get_template_path('servApacheVhost.tpl', TRUE , dirname(__FILE__)));
     return($display);
   }
 
@@ -225,6 +209,7 @@ 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
@@ -233,7 +218,10 @@ class servapache extends goService
       foreach($tmp['vhostUpdates'] as $dn => $attrs){
         $ldap->cd($dn);
         $ldap->modify($attrs);
-        show_ldap_error("Vhost:".$ldap->get_error(), _("Updating Apache service failed"));
+
+        if (!$ldap->success()){
+          msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class()));
+        }
       }
     }
 
@@ -242,7 +230,9 @@ class servapache extends goService
     foreach($tmp['del'] as $dn => $del){
       $ldap->cd($dn);
       $ldap->rmdir_recursive($dn);
-      show_ldap_error($ldap->get_error(), _("Removing Apache entries failed"));
+      if (!$ldap->success()){
+        msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_DEL, get_class()));
+      }
     }
 
     /* move follwoing entries
@@ -264,9 +254,44 @@ class servapache extends goService
         $ldap->cd($dn);
         $ldap->add($attrs);
       }
-      show_ldap_error($ldap->get_error(), _("Saving apache entries failed"));
+      if (!$ldap->success()){
+        msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_ADD, get_class()));
+      }
     }
   }
+
+
+  /*! \brief Returns the required information about this plugin for the 
+             service list 
+      @return Array  With information for the service plugin.
+    */
+  function getListEntry()
+  {
+    $fields = goService::getListEntry();
+    $fields['Message']    = _("Apache service");
+    $fields['AllowEdit']  = false;
+    return($fields);
+  }
+
+
+  /*  \brief Return plugin information used by the ACL handling.
+      @return Array ACL infos.
+   */  
+  static function plInfo()
+  {
+    return (array(
+          "plShortName"   => _("Apache service"),
+          "plDescription" => _("Apache virtual host service")." ("._("Services").")",
+          "plSelfModify"  => FALSE,
+          "plDepends"     => array(),
+          "plPriority"    => 88,
+          "plSection"     => array("administration"),
+          "plCategory"    => array("server"),
+
+          "plProvidedAcls"=> array(
+              "VirtualHost"           => _("Virtual hosts"))
+            ));
+  }
 }
 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
 ?>
index a1449753b2b3f736bd88b340c33dfaf531e2e284..30385f9bf0b9106435080a1f5e5757e9eb993e21 100644 (file)
@@ -3,7 +3,10 @@
 <tr>
        <td style="width:100%;vertical-align:top;">
                {$VhostList}
-               <input type="submit" name="AddVhost" value="{t}Add{/t}" {$servapacheACL}>
+
+               {render acl=$VirtualHostACL}
+               <input type="submit" name="AddVhost" value="{t}Add{/t}">
+               {/render}
        </td>
 </tr>
 </table>
   document.mainform.AddVhost.focus();
   -->
 </script>
+<input type="hidden" name="servapache" value="1">
+
+<p class="seperator">&nbsp;</p>
+<br>
+<div style="width:100%; text-align:right;">
+    <input type='submit' name='SaveService' value='{msgPool type=saveButton}'>
+    &nbsp;
+    <input type='submit' name='CancelService' value='{msgPool type=cancelButton}'>
+</div>
+