Code

- Cleaned and debugged code first part
authoropensides <opensides@594d385d-05f5-0310-b6e9-bd551577e9d8>
Sun, 4 Nov 2007 14:02:21 +0000 (14:02 +0000)
committeropensides <opensides@594d385d-05f5-0310-b6e9-bd551577e9d8>
Sun, 4 Nov 2007 14:02:21 +0000 (14:02 +0000)
- 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

vhost-apache2/src/apache_editVhost.tpl [deleted file]
vhost-apache2/src/apache_vhost.tpl [deleted file]
vhost-apache2/src/class_apacheEditVhost.inc [deleted file]
vhost-apache2/src/class_apacheVhost.inc [deleted file]
vhost-apache2/src/class_servApacheEditVhost.inc [new file with mode: 0644]
vhost-apache2/src/class_servApacheVhost.inc [new file with mode: 0644]
vhost-apache2/src/functions_apache.inc
vhost-apache2/src/servApacheVhost.tpl [new file with mode: 0644]
vhost-apache2/src/servApacheVhostEdit.tpl [new file with mode: 0644]

diff --git a/vhost-apache2/src/apache_editVhost.tpl b/vhost-apache2/src/apache_editVhost.tpl
deleted file mode 100644 (file)
index c8e5d05..0000000
+++ /dev/null
@@ -1,120 +0,0 @@
-<h2>{t}Generic{/t}</h2>
-<table summary="" width="100%">
-       <tr>
-               <td style="width:50%;vertical-align:top;border-right:1px        solid   #b0b0b0;">
-                       <table summary="">
-                               <tr>
-                                       <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>
-                                       <td><input type="text" name="apacheDocumentRoot" value="{$apacheDocumentRoot}">
-                                       </td>
-                               </tr>
-                               <tr>
-                                       <td>{t}Admin Mail address{/t}{$must}
-                                       </td>
-                                       <td><input type="text" name="apacheServerAdmin" value="{$apacheServerAdmin}">
-                                       </td>
-                               </tr>
-                       </table>
-               </td>
-               <td style="vertical-align:top;">
-                       <table summary="" width="100%">
-                               <tr>
-                                       <td style="vertical-align:top;width:100%;border-right:1px       solid   #b0b0b0;">
-                                               <h2>{t}Server Alias{/t}</h2>
-                                               <table width="100%">    
-                                                       <tr>
-                                                               <td>
-                                                                       {$apacheServerAlias}
-                                                               </td>
-                                                       </tr>
-                                                       <tr>
-                                                               <td>
-                                                                       <table width="100%">
-                                                                               <tr>
-                                                                                       <td  style="vertical-align:top;width:30%;">
-                                                                                               <h2>{t}URL Alias{/t}</h2>
-                                                                                       </td>
-                                                                                       <td>
-                                                                                               <h2>{t}Directory Path{/t}</h2>
-                                                                                       </td>
-                                                                               </tr>
-                                                                               <tr>
-                                                                                       <td style="vertical-align:top;width:30%;">
-                                                                                               <input type="text"              name="StrSAAlias" value="">
-                                                                                       </td>
-                                                                                       <td>
-                                                                                               <input type="text"              name="StrSADir" value="">
-                                                                                               <input type="submit"    name="AddSARecord" value="{t}Add{/t}">
-                                                                                       </td>
-                                                                               </tr>
-                                                                       </table>
-                                                               </td>
-                                                       </tr>
-                                               </table>
-                                       </td>
-                               </tr>
-                       </table>
-               </td>
-       </tr>
-</table>
-
-<p class="seperator">&nbsp;</p>
-<br>
-
-<table summary="" width="100%">
-       <tr>
-               <td style="vertical-align:top;width:50%;border-right:1px        solid   #b0b0b0;">
-                       <h2>{t}Script Alias{/t}</h2>
-                       <table width="100%">    
-                               <tr>
-                                       <td>
-                                               {$apacheScriptAlias}
-                                       </td>
-                               </tr>
-                               <tr>
-                                       <td>
-                                               <table width="100%">
-                                                       <tr>
-                                                               <td  style="vertical-align:top;width:30%;">
-                                                                       <h2>{t}Alias Directory{/t}</h2>
-                                                               </td>
-                                                               <td>
-                                                                       <h2>{t}Script Directory{/t}</h2>
-                                                               </td>
-                                                       </tr>
-                                                       <tr>
-                                                               <td style="vertical-align:top;width:30%;">
-                                                                       <input type="text"              name="StrSCAlias" value="">
-                                                               </td>
-                                                               <td>
-                                                                       <input type="text"              name="StrSCDir" value="">
-                                                                       <input type="submit"    name="AddSCRecord" value="{t}Add{/t}">
-                                                               </td>
-                                                       </tr>
-                                               </table>
-                                       </td>
-                               </tr>
-                       </table>
-               </td>
-               <td style="vertical-align:top;">
-               </td>
-       </tr>
-</table>
-<div style="text-algin:right;" align="right">
-       <p>
-               <input type="submit" name="SaveVhostChanges" value="{t}Save{/t}">
-               <input type="submit" name="CancelVhostChanges" value="{t}Cancel{/t}">
-       </p>
-</div>
-<script language="JavaScript" type="text/javascript">
-  <!-- // First input field on page
-  document.mainform.apacheServerName.focus();
-  -->
-</script>
diff --git a/vhost-apache2/src/apache_vhost.tpl b/vhost-apache2/src/apache_vhost.tpl
deleted file mode 100644 (file)
index d8eec5d..0000000
+++ /dev/null
@@ -1,16 +0,0 @@
-<h2>{t}Apache VHosts{/t}</h2>
-<table summary="" width="100%">
-<tr>
-       <td style="width:100%;vertical-align:top;">
-               {$VhostList}
-               <input type="submit" name="AddVhost" value="{t}Add{/t}" {$servapacheACL}>
-<!--           <input type="submit" name="EditVhost" value="{t}Edit{/t}" {$servapacheACL}>-->
-<!--           <input type="submit" name="RemoveVhost" value="{t}Remove{/t}" {$servapacheACL}>-->
-       </td>
-</tr>
-</table>
-<script language="JavaScript" type="text/javascript">
-  <!-- // First input field on page
-  document.mainform.AddVhost.focus();
-  -->
-</script>
diff --git a/vhost-apache2/src/class_apacheEditVhost.inc b/vhost-apache2/src/class_apacheEditVhost.inc
deleted file mode 100644 (file)
index 3eb4553..0000000
+++ /dev/null
@@ -1,455 +0,0 @@
-<?php
-
-class apacheVhostEdit extends plugin
-{
-  /* attribute list for save action */
-  var $ignore_account= TRUE;
-  
-  var $attributes      = array("apacheServerName","apacheDocumentRoot","apacheServerAlias",
-       "apacheServerAdmin","apacheScriptAlias","apacheSuexecUid","apacheSuexecGid");
-      
-  var $objectclasses  = array("whatever");
-
-  
-  var $apacheServerName                = "";
-  var $apacheDocumentRoot      = "";
-  var $apacheServerAdmin       = "";
-  var $apacheSuexecUid         = "";
-  var $apacheSuexecGid         = "";
-    
-  var $apacheServerAlias                = array();
-  var $apacheScriptAlias                = array();
-
-  var $OldApacheServerName              = ""; // To detect changes made with this edit
-  var $InitialApacheServerName          = "";
-
-  var $Records                  = array();
-  
-  var $dialog                   = false;
-
-  var $isNew                    = true;
-  var $cn;
-  var $VhostObject               = array();
-
-  function apacheVhostEdit ($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];
-        }
-      }
-
-      if(!isset($attrs['apacheServerAlias'])) $this->apacheServerAlias  = array();
-      if(!isset($attrs['apacheScriptAlias'])) $this->apacheScriptAlias  = array();
-
-    }
-  }
-
-  /* Transports the given Arraykey one position up*/
-  function ArrayUp($atr,$attrs)
-  {
-    $ret = $attrs;
-    $pos = $atr ;
-    $cn = count($attrs);
-    if(!(($pos == -1)||($pos == 1)||($pos >$cn))){
-      $before = array_slice($attrs,0,($pos-2));
-      $mitte  = array_reverse(array_slice($attrs,($pos-2),2));
-      $unten  = array_slice($attrs,$pos);
-      $ret = array();
-      $ret = $this->combineArrays($before,$mitte,$unten);
-    }
-    return($ret);
-  }
-
-
-  /* Transports the given Arraykey one position down*/
-  function ArrayDown($atr,$attrs)
-  {
-    $ret = $attrs;
-    $pos = $atr ;
-    $cn = count($attrs);
-    if(!(($pos == -1)||($pos == $cn))){
-      $before = array_slice($attrs,0,($pos-1));
-      $mitte  = array_reverse(array_slice($attrs,($pos-1),2));
-      $unten  = array_slice($attrs,($pos+1));
-      $ret = array();
-      $ret = $this->combineArrays($before,$mitte,$unten);
-    }
-    return($ret);
-  }
-
-  /* Combine new array */
-  function combineArrays($ar0,$ar1,$ar2)
-  {
-    $ret = array();
-    if(is_array($ar0))
-    foreach($ar0 as $ar => $a){
-        $ret[]=$a;
-    }
-    if(is_array($ar1))
-    foreach($ar1 as $ar => $a){
-        $ret[]=$a;
-    }
-    if(is_array($ar2))
-    foreach($ar2 as $ar => $a){
-        $ret[]=$a;
-    }
-    return($ret);
-  }
-  
-  function getpos($atr,$attrs)
-  {
-    $i = 0;
-    foreach($attrs as $attr => $name)    {
-      $i++;
-      if($attr == $atr){
-        return($i);
-      }
-    }
-    return(-1);
-  }
-
-
-  function execute()
-  {
-    /* Call parent execute */
-    plugin::execute();
-
-
-    /* Fill templating stuff */
-    $smarty= get_smarty();
-    $display= "";
-
-    /* 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())){
-        $msgs = $this->dialog->check();
-        foreach($msgs as $msg){
-          print_red($msg);
-        }
-      }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){
-      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);
-      }
-      if((preg_match("/^SAdown_/",$name)) && ($once)){
-        $once = false;
-        
-        $id = preg_replace("/^SAdown_/","",$name);
-        $id = preg_replace("/_.*$/","",$id);
-        $id = base64_decode($id);
-  
-        $this->apacheServerAlias = $this->ArrayDown(($id+1),$this->apacheServerAlias);
-      }
-      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; 
-      }
-
-      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);
-      }
-      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);
-      }
-      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; 
-      }
-      
-    }
-
-    if((isset($_POST['AddSARecord'])) && (!empty($_POST['StrSAAlias'])) && (!empty($_POST['StrSADir']))){
-      $this->apacheServerAlias[] = trim($_POST['StrSAAlias']." ".$_POST['StrSADir']);      
-    }
-    
-       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 record 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);
-
-    $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'>"; 
-    user_error(print_r($recs,true));
-    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());
-
-    $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'>"; 
-    
-    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 */
-    $display.= $smarty->fetch(get_template_path('apache_editVhost.tpl', TRUE));
-    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];
-      }
-    }
-
-  }
-
-
-  /* Check supplied data */
-  function check()
-  {
-    /* Call common method to give check the hook */
-    $message= plugin::check();
-        
-    /* 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(!is_domain($this->apacheServerName) || empty($this->apacheServerName)){
-      $message[] =sprintf(_("Please choose a valid Virtual Host Name."));
-    }
-
-    if(!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)){
-      $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.");
-    }
-
-    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);
-       }
-    }
-    
-       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);
-       }
-    }
-    
-    return ($message);
-  }
-
-  /* This funtion returns all used apacheServerNames */
-  function getUsedServerNames()
-  {
-    $ret = array();
-    $ldap = $this->config->get_ldap_link();
-    $ldap->cd($this->config->current['BASE']);
-    $ldap->search("(&(objectClass=apacheConfig)(apacheServerName=*))",array("apacheServerName"));
-    while($attr = $ldap->fetch()){
-        $ret[$attr['apacheServerName'][0]]="";
-    }
-    return($ret);
-  }
-
-  /* Save to LDAP */
-  function save()
-  {
-    $ret =array();
-    foreach($this->attributes as $name){
-      $ret[$name] = $this->$name;
-    }
-
-    /* Create SA records 
-     */
-    foreach($this->apacheServerAlias as $key => $rec){
-      $rec['value']= $key." ".$rec['value'];
-      $this->Records [] = $rec;
-    }
-    
-  /* Create SC records 
-     */
-    foreach($this->apacheScriptAlias as $key => $rec){
-      $rec['value']= $key." ".$rec['value'];
-      $this->Records [] = $rec;
-    }
-
-    $ret['RECORDS'] = $this->Records; 
-
-    $ret['InitialApacheServerName']   =  $this->InitialApacheServerName;
-
-    return($ret);
-  }
-
-}
-
-?>
diff --git a/vhost-apache2/src/class_apacheVhost.inc b/vhost-apache2/src/class_apacheVhost.inc
deleted file mode 100644 (file)
index 90bf51b..0000000
+++ /dev/null
@@ -1,314 +0,0 @@
-<?php
-
-class servapache extends plugin
-{
-  /* attribute list for save action */
-  var $ignore_account   = FALSE;
-  var $attributes       = array(); 
-  var $objectclasses    = array("whatever");
-
-  var $RecordTypes      = array();
-  var $Vhosts            = array();
-  var $dialog           = NULL;
-
-  var $orig_dn          = "";
-
-  var $APACHE2initially_was_account;
-
-
-  function servapache ($config, $dn= NULL, $parent= NULL)
-  {
-    plugin::plugin ($config, $dn, $parent);
-
-    $this->orig_dn = $dn;
-
-    /* Get all vhost Informations
-     */
-    $this->Vhosts = getVhostEntries($config,$dn);
-
-    /* If there is at least one entry in this -> types, we have APACHE2 enabled 
-     */
-    if(count($this->Vhosts) == 0){
-      $this->is_account = false;
-    }else{
-      $this->is_account = true;
-    }
-    $this->APACHE2initially_was_account = $this->is_account;
-  }
-
-
-  function execute()
-  {
-    /* Call parent execute 
-     */
-    plugin::execute();
-
-    /* Fill templating stuff 
-     */
-    $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)){
-      $this->dialog->save_object();
-
-      /* Check for errors  
-       */
-      if(count($this->dialog->check())){
-        foreach($this->dialog->check() as $msgs){
-          print_red($msgs); 
-        }
-      }else{
-        /* add new/edited vhost 
-         */
-        $ret = $this->dialog->save();
-        if(!$this->dialog->isNew){
-          unset($this->Vhosts[$this->dialog->OldApacheServerName]);
-        }
-        $this->Vhosts[$ret['apacheServerName']] = $ret;
-        $this->dialog = NULL;
-      }
-    }
-
-    /* Cancel vhost edit / new 
-     */
-    if(isset($_POST['CancelVhostChanges'])){
-      $this->dialog = NULL;
-    }
-
-    /* Add empty new vhost 
-     */
-    if(isset($_POST['AddVhost']) && chkacl($this->acl,"servapache2") == ""){
-      $this->dialog = new apacheEditVhost($this->config,$this->dn);
-    }
-
-    /* Check for edit vhost request 
-     */
-    $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 && chkacl($this->acl,"servapache2") == ""){
-        $once =true;
-        $tmp = preg_replace("/^editVhost_/","",$name);
-        $tmp = base64_decode(preg_replace("/_.*$/","",$tmp));
-        $this->dialog= new apacheEditVhost($this->config,$this->dn,$this->Vhosts[$tmp]);
-      }
-
-      /* check posts for delete vhost 
-       */
-      if(preg_match("/^delVhost_/",$name)&&!$once && chkacl($this->acl,"servapache2") == ""){
-
-        $once =true;
-        $tmp = preg_replace("/^delVhost_/","",$name);
-        $tmp = base64_decode(preg_replace("/_.*$/","",$tmp));
-     
-        /* Initiate deletion
-         */ 
-        $this->RemoveVhost($tmp); 
-      }
-    }
-
-    /* Show dialog 
-     */
-    if($this->dialog!= NULL){
-      $this->dialog->save_object();
-      $this->dialog->parent = $this;
-      return($this->dialog->execute());
-    }
-
-    /* Create Listbox with existing Vhosts 
-     */
-    $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'>";
-    foreach($this->Vhosts as $vhost => $values ){
-      $VhostList->AddEntry(array(
-            array("string" => $vhost),
-            array("string" => str_replace("%s",base64_encode($vhost),$editImg))
-            ));
-    }    
-  
-    $smarty->assign("servapache2ACL",chkacl($this->acl,"servapache2"));
-  
-    /* Display tempalte 
-     */
-    $smarty->assign("VhostList",$VhostList->DrawList());
-    $display.= $smarty->fetch(get_template_path('apache_vhost.tpl', TRUE));
-    return($display);
-  }
-
-
-  /* Delete specified vhost
-   */
-  function RemoveVhost($id)
-  {
-    $vhosts =  $this->getUsedServerNames();
-  
-    $vhostname = "";
-    if(isset($this->Vhosts[$id]['InitialApacheServerName'])){
-      $vhostname= $this->Vhosts[$id]['InitialApacheServerName'];
-    }
-
-    $used = array();
-
-    /* Add Records which use this apacheServerName
-     */
-    if(isset($vhosts[$vhostname])){
-      $used = array_merge($used,$vhosts[$vhostname]);
-    }
-
-
-    /* There are still entries using this configuration
-     *  Abort deletion
-     */ 
-    if(count($used)){
-      $i = 2;
-      $str ="";
-      foreach($used as $dn){
-        if($i > 0 ){
-          $i --;
-          $str.=$dn." ";
-        }
-      }
-
-      /*  Only show 2 apache2 in the error message 
-       */
-      if(count($used)> 2) {
-        $str .=" ... ";
-      }
-      print_red(sprintf(_("Can't delete the selected vhost, because it is still in use by these entry/entries '%s'"),trim($str)));
-
-    }else{
-      unset($this->Vhosts[$id]);
-      return(true);
-    }
-    return(false);
-  } 
-
-
-  /* This function returns all used Vhostnames 
-   */
-  function getUsedServerNames()
-  {
-    $ret = array();
-    $ldap = $this->config->get_ldap_link();
-    $ldap->cd($this->config->current['BASE']);
-    $ldap->search("(&(objectClass=apacheConfig)(apacheServerName=*))",array("apacheServerName"));
-    while($attr = $ldap->fetch()){
-      $ret[$attr['apacheServerName'][0]][] = $attr['dn'];
-    }
-    return($ret);
-  }
-
-
-
-    /* Remove apache service
-   */
-  function remove_from_parent()
-  {
-    if($this->APACHE2initially_was_account){
-      $bool = true;
-      foreach($this->Vhosts as $key => $vhost){
-        $bool= $bool & $this->RemoveVhost($key);
-      }
-
-      if($bool){
-        $this->save();
-      }
-      return($bool);
-    }
-  }
-
-
-
-  /* Save to LDAP */
-  function save()
-  {
-    $ldap = $this->config->get_ldap_link();
-    $ldap->cd($this->config->current['BASE']);  
-  
-    /* Get differences 
-     */
-
-    $old_dn =  $this->orig_dn;
-    if($old_dn == "new"){
-      $old_dn = $this->dn;
-    }
-
-    $tmp = getVhostEntriesDiff($this->config,$this->Vhosts,$old_dn);
-
-    /* Updated vhost entries if reverser or forward name has changed  
-     * Must be done before moving entries, else the given dn is invalid
-     */
-    if(isset($tmp['vhostUpdates'])){
-      foreach($tmp['vhostUpdates'] as $dn => $attrs){
-        $ldap->cd($dn);
-        $ldap->modify($attrs);
-        show_ldap_error("Vhost:".$ldap->get_error(), _("Updating Apache service failed"));
-      }
-    }
-
-    /* Delete apache vhost
-     */
-    foreach($tmp['del'] as $dn => $del){
-      $ldap->cd($dn);
-      $ldap->rmdir_recursive($dn);
-      show_ldap_error($ldap->get_error(), _("Removing Apache entries failed"));
-    }
-
-    /* move follwoing entries
-     */
-    foreach($tmp['move'] as $src => $dst){
-      $this->recursive_move($src,$dst);
-    }
-
-    /* Add || Update new apache entries
-     */
-    foreach($tmp['add'] as $dn => $attrs){
-      $ldap->cd($dn);
-      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{
-        $ldap->cd($dn);
-        $ldap->add($attrs);
-      }
-      show_ldap_error($ldap->get_error(), _("Saving apache entries failed"));
-    }
-  }
-}
-// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
-?>
diff --git a/vhost-apache2/src/class_servApacheEditVhost.inc b/vhost-apache2/src/class_servApacheEditVhost.inc
new file mode 100644 (file)
index 0000000..0f8672c
--- /dev/null
@@ -0,0 +1,454 @@
+<?php
+
+class servapacheVhostEdit extends plugin
+{
+  /* attribute list for save action */
+  var $ignore_account= TRUE;
+  
+  var $attributes      = array("apacheServerName","apacheDocumentRoot","apacheServerAlias",
+       "apacheServerAdmin","apacheScriptAlias","apacheSuexecUid","apacheSuexecGid");
+      
+  var $objectclasses  = array("whatever");
+
+  
+  var $apacheServerName                = "";
+  var $apacheDocumentRoot      = "";
+  var $apacheServerAdmin       = "";
+  var $apacheSuexecUid         = "";
+  var $apacheSuexecGid         = "";
+    
+  var $apacheServerAlias                = array();
+  var $apacheScriptAlias                = array();
+
+  var $OldApacheServerName              = ""; // To detect changes made with this edit
+  var $InitialApacheServerName          = "";
+
+  var $Records                  = array();
+  
+  var $dialog                   = false;
+
+  var $isNew                    = true;
+  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];
+        }
+      }
+
+      if(!isset($attrs['apacheServerAlias'])) $this->apacheServerAlias  = array();
+      if(!isset($attrs['apacheScriptAlias'])) $this->apacheScriptAlias  = array();
+
+    }
+  }
+
+  /* Transports the given Arraykey one position up*/
+  function ArrayUp($atr,$attrs)
+  {
+    $ret = $attrs;
+    $pos = $atr ;
+    $cn = count($attrs);
+    if(!(($pos == -1)||($pos == 1)||($pos >$cn))){
+      $before = array_slice($attrs,0,($pos-2));
+      $mitte  = array_reverse(array_slice($attrs,($pos-2),2));
+      $unten  = array_slice($attrs,$pos);
+      $ret = array();
+      $ret = $this->combineArrays($before,$mitte,$unten);
+    }
+    return($ret);
+  }
+
+
+  /* Transports the given Arraykey one position down*/
+  function ArrayDown($atr,$attrs)
+  {
+    $ret = $attrs;
+    $pos = $atr ;
+    $cn = count($attrs);
+    if(!(($pos == -1)||($pos == $cn))){
+      $before = array_slice($attrs,0,($pos-1));
+      $mitte  = array_reverse(array_slice($attrs,($pos-1),2));
+      $unten  = array_slice($attrs,($pos+1));
+      $ret = array();
+      $ret = $this->combineArrays($before,$mitte,$unten);
+    }
+    return($ret);
+  }
+
+  /* Combine new array */
+  function combineArrays($ar0,$ar1,$ar2)
+  {
+    $ret = array();
+    if(is_array($ar0))
+    foreach($ar0 as $ar => $a){
+        $ret[]=$a;
+    }
+    if(is_array($ar1))
+    foreach($ar1 as $ar => $a){
+        $ret[]=$a;
+    }
+    if(is_array($ar2))
+    foreach($ar2 as $ar => $a){
+        $ret[]=$a;
+    }
+    return($ret);
+  }
+  
+  function getpos($atr,$attrs)
+  {
+    $i = 0;
+    foreach($attrs as $attr => $name)    {
+      $i++;
+      if($attr == $atr){
+        return($i);
+      }
+    }
+    return(-1);
+  }
+
+
+  function execute()
+  {
+    /* Call parent execute */
+    plugin::execute();
+
+
+    /* Fill templating stuff */
+    $smarty= get_smarty();
+    $display= "";
+
+    /* 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())){
+        $msgs = $this->dialog->check();
+        foreach($msgs as $msg){
+          print_red($msg);
+        }
+      }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){
+      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);
+      }
+      if((preg_match("/^SAdown_/",$name)) && ($once)){
+        $once = false;
+        
+        $id = preg_replace("/^SAdown_/","",$name);
+        $id = preg_replace("/_.*$/","",$id);
+        $id = base64_decode($id);
+  
+        $this->apacheServerAlias = $this->ArrayDown(($id+1),$this->apacheServerAlias);
+      }
+      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; 
+      }
+
+      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);
+      }
+      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);
+      }
+      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; 
+      }
+      
+    }
+
+    if((isset($_POST['AddSARecord'])) && (!empty($_POST['StrSAAlias'])) && (!empty($_POST['StrSADir']))){
+      $this->apacheServerAlias[] = trim($_POST['StrSAAlias']." ".$_POST['StrSADir']);      
+    }
+    
+       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);
+
+    $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'>";
+    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());
+
+    $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'>"; 
+    
+    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 */
+    $display.= $smarty->fetch(get_template_path('servApacheVhostEdit.tpl', TRUE));
+    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];
+      }
+    }
+
+  }
+
+
+  /* Check supplied data */
+  function check()
+  {
+    /* Call common method to give check the hook */
+    $message= plugin::check();
+        
+    /* 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(is_domain($this->apacheServerName) || empty($this->apacheServerName)){
+      $message[] =sprintf(_("Please choose a valid Virtual Host Name."));
+    }
+
+    if(!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)){
+      $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.");
+    }
+
+    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);
+       }
+    }
+    
+       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);
+       }
+    }
+    
+    return ($message);
+  }
+
+  /* This funtion returns all used apacheServerNames */
+  function getUsedServerNames()
+  {
+    $ret = array();
+    $ldap = $this->config->get_ldap_link();
+    $ldap->cd($this->config->current['BASE']);
+    $ldap->search("(&(objectClass=apacheConfig)(apacheServerName=*))",array("apacheServerName"));
+    while($attr = $ldap->fetch()){
+        $ret[$attr['apacheServerName'][0]]="";
+    }
+    return($ret);
+  }
+
+  /* Save to LDAP */
+  function save()
+  {
+    $ret =array();
+    foreach($this->attributes as $name){
+      $ret[$name] = $this->$name;
+    }
+
+    /* Create SA records 
+     */
+    foreach($this->apacheServerAlias as $key => $rec){
+      $rec['value']= $key." ".$rec['value'];
+      $this->Records [] = $rec;
+    }
+    
+  /* Create SC records 
+     */
+    foreach($this->apacheScriptAlias as $key => $rec){
+      $rec['value']= $key." ".$rec['value'];
+      $this->Records [] = $rec;
+    }
+
+    $ret['RECORDS'] = $this->Records; 
+
+    $ret['InitialApacheServerName']   =  $this->InitialApacheServerName;
+
+    return($ret);
+  }
+
+}
+
+?>
diff --git a/vhost-apache2/src/class_servApacheVhost.inc b/vhost-apache2/src/class_servApacheVhost.inc
new file mode 100644 (file)
index 0000000..495da74
--- /dev/null
@@ -0,0 +1,311 @@
+<?php
+
+class servapache extends plugin
+{
+  /* attribute list for save action */
+  var $ignore_account   = FALSE;
+  var $attributes       = array(); 
+  var $objectclasses    = array("whatever");
+
+  var $RecordTypes      = array();
+  var $Vhosts            = array();
+  var $dialog           = NULL;
+
+  var $orig_dn          = "";
+
+  var $APACHEinitially_was_account;
+
+
+  function servapache ($config, $dn= NULL, $parent= NULL)
+  {
+    plugin::plugin ($config, $dn, $parent);
+
+    $this->orig_dn = $dn;
+
+    /* Get all vhost Informations
+     */
+    $this->Vhosts = getVhostEntries($config,$dn);
+
+    /* 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->APACHEinitially_was_account = $this->is_account;
+  }
+
+
+  function execute()
+  {
+    /* Call parent execute 
+     */
+    plugin::execute();
+
+    /* Fill templating stuff 
+     */
+    $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)){
+      $this->dialog->save_object();
+
+      /* Check for errors  
+       */
+      if(count($this->dialog->check())){
+        foreach($this->dialog->check() as $msgs){
+          print_red($msgs); 
+        }
+      }else{
+        /* add new/edited vhost 
+         */
+        $ret = $this->dialog->save();
+        if(!$this->dialog->isNew){
+          unset($this->Vhosts[$this->dialog->OldApacheServerName]);
+        }
+        $this->Vhosts[$ret['apacheServerName']] = $ret;
+        $this->dialog = NULL;
+      }
+    }
+
+    /* Cancel vhost edit / new 
+     */
+    if(isset($_POST['CancelVhostChanges'])){
+      $this->dialog = NULL;
+    }
+
+    /* Add empty new vhost 
+     */
+    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));
+      /* check all post for edit request 
+       */
+      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 servapacheVhostEdit($this->config,$this->dn,$this->Vhosts[$tmp]);
+      }
+
+      /* check posts for delete vhost 
+       */
+      if(preg_match("/^delVhost_/",$name)&&!$once && chkacl($this->acl,"servapache") == ""){
+
+        $once =true;
+        $tmp = preg_replace("/^delVhost_/","",$name);
+        $tmp = base64_decode(preg_replace("/_.*$/","",$tmp));
+     
+        /* Initiate deletion
+         */ 
+        $this->RemoveVhost($tmp); 
+      }
+    }
+
+    /* Show dialog 
+     */
+    if($this->dialog!= NULL){
+      $this->dialog->save_object();
+      $this->dialog->parent = $this;
+      return($this->dialog->execute());
+    }
+
+    /* Create Listbox with existing Vhosts 
+     */
+    $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'>";
+    foreach($this->Vhosts as $vhost => $values ){
+      $VhostList->AddEntry(array(
+            array("string" => $vhost),
+            array("string" => str_replace("%s",base64_encode($vhost),$editImg))
+            ));
+    }    
+  
+    $smarty->assign("servapacheACL",chkacl($this->acl,"servapache"));
+  
+    /* Display tempalte 
+     */
+    $smarty->assign("VhostList",$VhostList->DrawList());
+    $display.= $smarty->fetch(get_template_path('servApacheVhost.tpl', TRUE));
+    return($display);
+  }
+
+
+  /* Delete specified vhost
+   */
+  function RemoveVhost($id)
+  {
+    $vhosts =  $this->getUsedServerNames();
+  
+    $vhostname = "";
+    if(isset($this->Vhosts[$id]['InitialApacheServerName'])){
+      $vhostname= $this->Vhosts[$id]['InitialApacheServerName'];
+    }
+
+    $used = array();
+
+    /* Add Records which use this apacheServerName
+     */
+    if(isset($vhosts[$vhostname])){
+      $used = array_merge($used,$vhosts[$vhostname]);
+    }
+
+
+    /* There are still entries using this configuration
+     *  Abort deletion
+     */ 
+    if(count($used)){
+      $i = 2;
+      $str ="";
+      foreach($used as $dn){
+        if($i > 0 ){
+          $i --;
+          $str.=$dn." ";
+        }
+      }
+
+      /*  Only show 2 apache in the error message 
+       */
+      if(count($used)> 2) {
+        $str .=" ... ";
+      }
+      print_red(sprintf(_("Can't delete the selected vhost, because it is still in use by these entry/entries '%s'"),trim($str)));
+
+    }else{
+      unset($this->Vhosts[$id]);
+      return(true);
+    }
+    return(false);
+  } 
+
+
+  /* This function returns all used Vhostnames 
+   */
+  function getUsedServerNames()
+  {
+    $ret = array();
+    $ldap = $this->config->get_ldap_link();
+    $ldap->cd($this->config->current['BASE']);
+    $ldap->search("(&(objectClass=apacheConfig)(apacheServerName=*))",array("apacheServerName"));
+    while($attr = $ldap->fetch()){
+      $ret[$attr['apacheServerName'][0]][] = $attr['dn'];
+    }
+    return($ret);
+  }
+
+
+    /* Remove apache service
+   */
+  function remove_from_parent()
+  {
+    if($this->APACHEinitially_was_account){
+      $bool = true;
+      foreach($this->Vhosts as $key => $vhost){
+        $bool= $bool & $this->RemoveVhost($key);
+      }
+
+      if($bool){
+        $this->save();
+      }
+      return($bool);
+    }
+  }
+
+
+  /* Save to LDAP */
+  function save()
+  {
+    $ldap = $this->config->get_ldap_link();
+    $ldap->cd($this->config->current['BASE']);  
+  
+    /* Get differences 
+     */
+
+    $old_dn =  $this->orig_dn;
+    if($old_dn == "new"){
+      $old_dn = $this->dn;
+    }
+
+    $tmp = getVhostEntriesDiff($this->config,$this->Vhosts,$old_dn);
+
+    /* Updated vhost entries if reverser or forward name has changed  
+     * Must be done before moving entries, else the given dn is invalid
+     */
+    if(isset($tmp['vhostUpdates'])){
+      foreach($tmp['vhostUpdates'] as $dn => $attrs){
+        $ldap->cd($dn);
+        $ldap->modify($attrs);
+        show_ldap_error("Vhost:".$ldap->get_error(), _("Updating Apache service failed"));
+      }
+    }
+
+    /* Delete apache vhost
+     */
+    foreach($tmp['del'] as $dn => $del){
+      $ldap->cd($dn);
+      $ldap->rmdir_recursive($dn);
+      show_ldap_error($ldap->get_error(), _("Removing Apache entries failed"));
+    }
+
+    /* move follwoing entries
+     */
+    foreach($tmp['move'] as $src => $dst){
+      $this->recursive_move($src,$dst);
+    }
+
+    /* Add || Update new apache entries
+     */
+    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);
+        $ldap->modify ($attrs);
+      }else{
+        $ldap->cd($dn);
+        $ldap->add($attrs);
+      }
+      show_ldap_error($ldap->get_error(), _("Saving apache entries failed"));
+    }
+  }
+}
+// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
+?>
index 9f11882f16a796dc28437c20524c88d27b33b28a..be0b3f026d47f552e3a4e9f63dd130383716ef6f 100644 (file)
@@ -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 zone
+  /* Parse fetched vhost
    */
   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/servApacheVhost.tpl b/vhost-apache2/src/servApacheVhost.tpl
new file mode 100644 (file)
index 0000000..a144975
--- /dev/null
@@ -0,0 +1,14 @@
+<h2>{t}Apache VHosts{/t}</h2>
+<table summary="" width="100%">
+<tr>
+       <td style="width:100%;vertical-align:top;">
+               {$VhostList}
+               <input type="submit" name="AddVhost" value="{t}Add{/t}" {$servapacheACL}>
+       </td>
+</tr>
+</table>
+<script language="JavaScript" type="text/javascript">
+  <!-- // First input field on page
+  document.mainform.AddVhost.focus();
+  -->
+</script>
diff --git a/vhost-apache2/src/servApacheVhostEdit.tpl b/vhost-apache2/src/servApacheVhostEdit.tpl
new file mode 100644 (file)
index 0000000..c8e5d05
--- /dev/null
@@ -0,0 +1,120 @@
+<h2>{t}Generic{/t}</h2>
+<table summary="" width="100%">
+       <tr>
+               <td style="width:50%;vertical-align:top;border-right:1px        solid   #b0b0b0;">
+                       <table summary="">
+                               <tr>
+                                       <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>
+                                       <td><input type="text" name="apacheDocumentRoot" value="{$apacheDocumentRoot}">
+                                       </td>
+                               </tr>
+                               <tr>
+                                       <td>{t}Admin Mail address{/t}{$must}
+                                       </td>
+                                       <td><input type="text" name="apacheServerAdmin" value="{$apacheServerAdmin}">
+                                       </td>
+                               </tr>
+                       </table>
+               </td>
+               <td style="vertical-align:top;">
+                       <table summary="" width="100%">
+                               <tr>
+                                       <td style="vertical-align:top;width:100%;border-right:1px       solid   #b0b0b0;">
+                                               <h2>{t}Server Alias{/t}</h2>
+                                               <table width="100%">    
+                                                       <tr>
+                                                               <td>
+                                                                       {$apacheServerAlias}
+                                                               </td>
+                                                       </tr>
+                                                       <tr>
+                                                               <td>
+                                                                       <table width="100%">
+                                                                               <tr>
+                                                                                       <td  style="vertical-align:top;width:30%;">
+                                                                                               <h2>{t}URL Alias{/t}</h2>
+                                                                                       </td>
+                                                                                       <td>
+                                                                                               <h2>{t}Directory Path{/t}</h2>
+                                                                                       </td>
+                                                                               </tr>
+                                                                               <tr>
+                                                                                       <td style="vertical-align:top;width:30%;">
+                                                                                               <input type="text"              name="StrSAAlias" value="">
+                                                                                       </td>
+                                                                                       <td>
+                                                                                               <input type="text"              name="StrSADir" value="">
+                                                                                               <input type="submit"    name="AddSARecord" value="{t}Add{/t}">
+                                                                                       </td>
+                                                                               </tr>
+                                                                       </table>
+                                                               </td>
+                                                       </tr>
+                                               </table>
+                                       </td>
+                               </tr>
+                       </table>
+               </td>
+       </tr>
+</table>
+
+<p class="seperator">&nbsp;</p>
+<br>
+
+<table summary="" width="100%">
+       <tr>
+               <td style="vertical-align:top;width:50%;border-right:1px        solid   #b0b0b0;">
+                       <h2>{t}Script Alias{/t}</h2>
+                       <table width="100%">    
+                               <tr>
+                                       <td>
+                                               {$apacheScriptAlias}
+                                       </td>
+                               </tr>
+                               <tr>
+                                       <td>
+                                               <table width="100%">
+                                                       <tr>
+                                                               <td  style="vertical-align:top;width:30%;">
+                                                                       <h2>{t}Alias Directory{/t}</h2>
+                                                               </td>
+                                                               <td>
+                                                                       <h2>{t}Script Directory{/t}</h2>
+                                                               </td>
+                                                       </tr>
+                                                       <tr>
+                                                               <td style="vertical-align:top;width:30%;">
+                                                                       <input type="text"              name="StrSCAlias" value="">
+                                                               </td>
+                                                               <td>
+                                                                       <input type="text"              name="StrSCDir" value="">
+                                                                       <input type="submit"    name="AddSCRecord" value="{t}Add{/t}">
+                                                               </td>
+                                                       </tr>
+                                               </table>
+                                       </td>
+                               </tr>
+                       </table>
+               </td>
+               <td style="vertical-align:top;">
+               </td>
+       </tr>
+</table>
+<div style="text-algin:right;" align="right">
+       <p>
+               <input type="submit" name="SaveVhostChanges" value="{t}Save{/t}">
+               <input type="submit" name="CancelVhostChanges" value="{t}Cancel{/t}">
+       </p>
+</div>
+<script language="JavaScript" type="text/javascript">
+  <!-- // First input field on page
+  document.mainform.apacheServerName.focus();
+  -->
+</script>