Code

Updated gotomasses in trunk
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Fri, 24 Aug 2007 09:51:13 +0000 (09:51 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Fri, 24 Aug 2007 09:51:13 +0000 (09:51 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@7129 594d385d-05f5-0310-b6e9-bd551577e9d8

plugins/addons/gotomasses/class_goto_task.inc
plugins/addons/gotomasses/class_target_list.inc
plugins/addons/gotomasses/goto_task.tpl

index 19e018d872d6442361972fe4040fde03b13cdea7..b905318ff60161dd4fb83ef933d73d49d1af5851 100644 (file)
@@ -14,6 +14,13 @@ class goto_task extends plugin
   var $Month    = "*";
   var $Weekday  = "*";
   var $Action   = "install";
+
+  var $Zone     = "";
+  var $Section  = "";
+
+  var $Zones    = array();
+  var $Sections = array();
+
   var $Comment  = "";
   var $OGroup   = "keep_current";
   var $OGroups  = array();
@@ -21,8 +28,10 @@ class goto_task extends plugin
   var $Initial_Target   = array();
   var $Actions  = array();
   var $new      = FALSE;
-  var $attributes     = array("OGroup","Minute","Hour","Day","Month","Weekday","Action","Comment","Target","Initial_Target");
+  var $attributes     = array("Zone","Section","OGroup","Minute","Hour","Day","Month","Weekday","Action","Comment","Target","Initial_Target");
 
+  var $configure_dhcp = FALSE;
+  var $configure_dns = FALSE;
 
   function goto_task($config,$parent,$data = array())
   {
@@ -32,7 +41,6 @@ class goto_task extends plugin
     /* Intialize plugin */
     $this->config = $config;
     if(count($data)){
-    
       $tmp = $this->get_array_values();
       foreach($this->attributes as $attr){
         if(!isset($data[$attr])){
@@ -45,6 +53,20 @@ class goto_task extends plugin
       $this->new = TRUE;
     }
 
+    if(!empty($this->Zone) && !preg_match("/^\"\"$/",$this->Zone)){
+      $this->configure_dns = TRUE;
+    }
+    if(!empty($this->Section) && !preg_match("/^\"\"$/",$this->Section)){
+      $this->configure_dhcp = TRUE;
+    }
+
+    /* Set dns and dhcp attributes */
+    foreach(getAvailableZones($this->config) as $zone){
+      $name = preg_replace("#^[^/]+/#","",$zone);
+      $this->Zones[$name] = $zone; 
+    }
+    $this->Sections = $this->get_dhcp_sections();
+
     /* Create ogroup select list */
     $this->OGroups = array("\"\""     => "["._("Keep current")."]");
     $this->OGroups = array_merge($this->OGroups,$this->parent->get_object_groups());
@@ -88,12 +110,20 @@ class goto_task extends plugin
         $MAC = $_POST['task_MAC'];
         $NAME= "";
         $IP  = "";
+        $DNS   = "";
+        $DHCP  = "";
         if(isset($_POST['task_Name'])){
           $NAME = $_POST['task_Name'];
         }
         if(isset($_POST['task_IP']) && is_ip($_POST['task_IP'])){
           $IP = $_POST['task_IP'];
         }
+        if(isset($_POST['configure_dns']) && isset($_POST['Zone']) && isset($this->Zones[$_POST['Zone']])){
+          $DNS = $_POST['Zone'];
+        }
+        if(isset($_POST['configure_dhcp']) && isset($_POST['Section']) && isset($this->Sections[$_POST['Section']])){
+          $DHCP = $_POST['Section'];
+        }
         if(is_mac($MAC)){
           $this->Initial_Target[] = array("MAC"=>$MAC,"IP"=>$IP,"NAME"=>$NAME);
         }
@@ -110,15 +140,15 @@ class goto_task extends plugin
           $line = fgets($fp,512);
           $tmp = preg_split("/(,|;)/",$line);
 
-          $MAC = $IP = $NAME = "";
+          $MAC = $IP = $NAME
           if(isset($tmp[0])){
-            $MAC = $tmp[0];
+            $MAC = trim($tmp[0]);
           }
           if(isset($tmp[1])){
-            $IP = $tmp[1];
+            $IP = trim($tmp[1]);
           }
           if(isset($tmp[2])){
-            $NAME = $tmp[2];
+            $NAME = trim($tmp[2]);
           }
           if(is_mac($MAC)){
             $this->Initial_Target[] = array("MAC"=>$MAC,"IP"=>$IP,"NAME"=>$NAME);
@@ -177,14 +207,14 @@ class goto_task extends plugin
     /* Add entries to divlist */
     if($this->Action == "initial_install"){
       $divlist->SetHeader(array(
-                            array("string" => _("Target systems")),
+                            array("string" => _("Target systems") ,"attach" => "style='width:120px;'"),
                             array("string" => _("IP")      , "attach" => "style='width:90px;'"),
                             array("string" => _("Name")    , "attach" => "style='width:150px;'"),
                             array("string" => _("Actions") , "attach" => "style='width:44px;border-right:0px;text-align:right;'")));
       foreach($this->Initial_Target as $key => $target){
-        $field1 = array("string" => $target['MAC']  );
+        $field1 = array("string" => $target['MAC']  ,"attach" => "style='width:120px;'");
         $field2 = array("string" => $target['IP']   ,"attach" => "style='width:90px;'");
-        $field3 = array("string" => $target['NAME'] ,"attach" => "style='width:150px;'");
+        $field3 = array("string" =>  $target['NAME'] ,"attach" => "style='width:150px;'");
         $divlist->AddEntry(array($field1,$field2,$field3,preg_replace("/%KEY%/",$key,$field_del)));
       } 
     }else{
@@ -203,6 +233,15 @@ class goto_task extends plugin
       $smarty->assign($attr,$this->$attr);
     }
 
+    $smarty->assign("Zones", $this->Zones);
+    $smarty->assign("Sections", $this->Sections);
+
+    $smarty->assign("Zone", $this->Zone);
+    $smarty->assign("Section", $this->Section);
+
+    $smarty->assign("configure_dhcp", $this->configure_dhcp);
+    $smarty->assign("configure_dns", $this->configure_dns);
+
     $tmp = $this->get_array_values();
     $smarty->assign("JS"      , $_SESSION['js']);
     $smarty->assign("Minutes" , $tmp['Minute']);
@@ -217,6 +256,62 @@ class goto_task extends plugin
     return ($smarty->fetch (get_template_path('goto_task.tpl', TRUE)));
   }
 
+
+  function create_tree($arr,$base,$current = "")
+  {
+    $ret = array();
+    foreach($arr as $r => $name){
+      $base_part = str_replace($base,"",$r);
+      if(preg_match("/^[a-z]*=".normalizePreg($name)."(|,)$/i",$base_part)){
+        $ret[$r] = $current.$name;
+        $tmp = $this->create_tree($arr,$r,$current.".&nbsp;");
+        foreach($tmp as $sub_key => $sub_name){
+          $ret[$sub_key] = $sub_name;
+        }
+      }
+    }
+    return($ret);
+  }
+
+
+
+  function get_dhcp_sections()
+  {
+    $ldap = $this->config->get_ldap_link();
+    $ldap->cd($this->config->current['BASE']);
+    $ldap->search("(objectClass=dhcpService)",array("dhcpPrimaryDN"));
+
+    $tmp   = array();
+    $tmp2  = array();
+
+    $dhcp_dns = array();
+    while($attr = $ldap->fetch()){
+      $dhcp_dns[$attr['dn']] = $attr['dhcpPrimaryDN'][0];
+    }
+
+    foreach($dhcp_dns as $key => $pri_dns){
+      $ldap->cat($pri_dns,array("cn"));
+      $tmp = $ldap->fetch();
+      $dhcp_dns[$key] = $tmp['cn'][0];
+    }
+
+    foreach($dhcp_dns as $dn => $cn){
+      $ldap->cd($dn);
+      $ldap->search("(|(objectClass=dhcpService)(objectClass=dhcpGroup)".
+                    "(objectClass=dhcpSubnet)(objectClass=dhcpSharedNetwork))",array("cn"));
+      $tmp = array();
+      while($attr = $ldap->fetch()){
+        $tmp[$attr['dn']] = $attr['cn'][0];
+      }
+      $tmp2 = $this->create_tree($tmp,preg_replace("/^[^,]+,/i","",$dn),"(".$cn.")&nbsp;");
+    }
+    $ret = array();
+    foreach($tmp2 as $key => $label){
+      $ret[$tmp[$key]] = $label;
+    }
+    return($ret);
+  }
+
   
   /* check given values */
   function check()
@@ -234,10 +329,10 @@ class goto_task extends plugin
       }
     }
     if(count($this->Target) == 0 && $this->Action != "initial_install"){
-      $message[] = sprintf(_("You must specify at least one traget"));
+      $message[] = sprintf(_("You must specify at least one target"));
     }
     if(count($this->Initial_Target) == 0 && $this->Action == "initial_install"){
-      $message[] = sprintf(_("You must specify at least one traget"));
+      $message[] = sprintf(_("You must specify at least one target"));
     }
     return($message);
   }
@@ -254,10 +349,30 @@ class goto_task extends plugin
   {
     if(isset($_POST['goto_task_posted'])){
       plugin::save_object();
+
+      if(isset($_POST['configure_dns'])){
+        $this->configure_dns = TRUE;
+        if(isset($_POST['Zone'])){
+          $this->Zone = get_post("Zone");
+        }
+      }else{
+        $this->Zone = "\"\"";
+        $this->configure_dns = FALSE;
+      }
+
+      if(isset($_POST['configure_dhcp'])){
+        $this->configure_dhcp = TRUE;
+        if(isset($_POST['Section'])){
+          $this->Section = get_post("Section");
+        }
+      }else{
+        $this->configure_dhcp = FALSE;
+        $this->Section = "\"\"";
+      }
     }
   }  
 
-  
+
   /* Check if given target is vald.
    * It must either be a valid MAC address or an existing object group
    */
@@ -281,6 +396,12 @@ class goto_task extends plugin
     foreach($this->attributes as $attr){
       $tmp[$attr] = $this->$attr;
     }
+    if(!$this->configure_dns){
+      $tmp['Zone'] = "\"\"";
+    }
+    if(!$this->configure_dhcp){
+      $tmp['Section'] = "\"\"";
+    }
     return($tmp);
   }
 
index 4c1e79e726bdfb267b40ee999914b67230a32d96..248f594280957e1d64d42449bebdcbf56d3d57da 100644 (file)
@@ -45,7 +45,7 @@ class target_list extends MultiSelectWindow
     $this->AddHeader(array("string" => _("Object name"), "attach" => "style=''"));
 
     /* Text ,Value, Name, Is selected */
-    $this->AddCheckBox("ogroups",       _("Select to see object groups"),  _("Show object object groups"), true);
+    $this->AddCheckBox("ogroups",       _("Select to see object groups"),  _("Show object groups"), true);
     $this->AddCheckBox("servers",       _("Select to see servers")  ,   _("Show servers"), true);
     $this->AddCheckBox("workstations",  _("Select to see workstations"),_("Show workstations"), true);
 
index 9de2a0c630f9ba1d214138c3dcdaa76878f115e1..799d910b30901915ba803aa523b8c25b0237740e 100644 (file)
                                                {/render}
                                        </td>
                                </tr>
+                               <tr>
+                                       <td><input class='center' {if $configure_dns} checked {/if} id='configure_dns'
+                                               type='checkbox' name='configure_dns' value='1' onClick="changeState('Zone');">
+                                               <label for='configure_dns'>{t}Configure DNS{/t}</label>
+                                       </td>
+                                       <td>
+                                               <select name="Zone" id="Zone" {if !$configure_dns} disabled {/if}>
+                                                       {html_options options=$Zones selected=$Zone}
+                                               </select>
+                                       </td>
+                               </tr>
+                               <tr>
+                                       <td><input class='center' {if $configure_dhcp} checked {/if} id='configure_dhcp' 
+                                                       type='checkbox' name='configure_dhcp' value='1' onClick="changeState('Section');">
+                                               <label for='configure_dhcp'>{t}Configure DHCP{/t}</label>
+                                       </td>
+                                       <td>
+                                               <select name="Section" id="Section" {if !$configure_dhcp} disabled {/if}>
+                                                       {html_options options=$Sections selected=$Section}
+                                               </select>
+                                       </td>
+                               </tr>
+                               <tr>
+                                       <td><input class='center' {if $configure_dns} checked {/if} id='configure_dns'
+                                               type='checkbox' name='configure_dns' value='1' onClick="changeState('Zone');">
+                                               <label for='configure_dns'>{t}Configure DNS{/t}</label>
+                                       </td>
+                                       <td>
+                                               <select name="Zone" id="Zone" {if !$configure_dns} disabled {/if}>
+                                                       {html_options options=$Zones selected=$Zone}
+                                               </select>
+                                       </td>
+                               </tr>
+                               <tr>
+                                       <td><input class='center' {if $configure_dhcp} checked {/if} id='configure_dhcp' 
+                                                       type='checkbox' name='configure_dhcp' value='1' onClick="changeState('Section');">
+                                               <label for='configure_dhcp'>{t}Configure DHCP{/t}</label>
+                                       </td>
+                                       <td>
+                                               <select name="Section" id="Section" {if !$configure_dhcp} disabled {/if}>
+                                                       {html_options options=$Sections selected=$Section}
+                                               </select>
+                                       </td>
+                               </tr>
                        </table>
                </td>
                <td style='vertical-align:top'>
        </tr>
        <tr>
                <td colspan="2">
-            <table  summary="" style="border:1px solid #B0B0B0;width:100%; " id="t_test_scrolltable" cellspacing=0 cellpadding=0>
+            <table  summary="" style="border:1px solid #B0B0B0;width:100%; " cellspacing=0 cellpadding=0>
                 <tr>
                     <td>
                                                {render acl=$TargetACL}
                                </tr>
                        </table>
                </td>
-               <td>
+               <td style='vertical-align:top'>
                        <table>
                                <tr><td>{t}CVS import from file{/t}</td></tr>
                                <tr>