Code

Added additional check to delete block
[gosa.git] / setup / class_setupStep_Config2.inc
index 30dd7f931cacdd233eb14bc44ef6f573d99fff19..553bdef897dd05cc3c310e2162e882864fd6f6e2 100644 (file)
 */
 
 
-class setup_step_6 extends setup_step
+class Step_Config2 extends setup_step
 {
-  var $strict         = TRUE;
   var $governmentmode = FALSE;
   var $sambaidmapping = FALSE;
-  var $minid          = 100;       
-  var $account_expiration  =FALSE;
+  var $header_image = "images/ldapserver.png";
 
-  var $generic_settings  = array( "idgen"         => "{%sn}-{%givenName[2-4]}",
-                                  "idgen_active"  => FALSE,
-                                  "minid"         => "100",
-                                  "minid_active"  => FALSE,
+  var $cyrusunixstyle = FALSE;
+  var $mail       = "none";
+  var $mail_methods   = array();
+  var $mail_settings = array("vacationdir"        => "/etc/gosa/vacation",
+                             "vacationdir_active" => FALSE);
+
+  var $generic_settings  = array( "enableCopyPaste" => false,
+                                  "enableDNS"      => false,
+                                  "enableDHCP"      => false,
                                   "wws_ou"        => "ou=winstations",
                                   "wws_ou_active" => FALSE,
                                   "snapshot_active"     => FALSE,
                                   "snapshot_base"       => "ou=snapshots,%base%",
-                                  "snapshot_ldap_base"  => "%base%",
-                                  "snapshot_user"       => "cn=ldapadmin,%base%",
+                                  "snapshot_user"       => "%admin%",
                                   "snapshot_password"   => "",
                                   "snapshot_server"     => "%connection%");
 
   var $samba_settings    = array( "samba_sid"        => "0-815-4711",
                                   "samba_sid_active" => FALSE,
                                   "samba_rid"        => 1000,
+                                  "smbhash"          => 'SMBHASH',
                                   "samba_rid_active" => FALSE); 
-  var $attributes = array("strict","governmentmode","sambaidmapping","account_expiration");
 
-  function setup_step_6()
+  var $sambaDomain_found    = FALSE;
+  var $use_netatalk         = FALSE;
+  var $enableFAI_management = FALSE;
+
+  var $timezone       = "Europe/Berlin";
+  var $timezones      = array();
+
+  var $attributes = array("governmentmode","sambaidmapping","cyrusunixstyle","mail","use_netatalk","enableFAI_management","timezone");
+  var $called = FALSE;
+
+  function Step_Config2()
   {
     $this->update_strings();
+    $tmp = $this->get_available_mail_classes();
+    foreach($tmp['name'] as $name){
+      $this->mail_methods[$name] = $name;
+    }
+
+    /* Look for samba password generation method */
+    if(file_exists("/usr/bin/mkntpasswd")){
+      $pwdhash  = "/usr/bin/mkntpasswd";
+    } elseif (preg_match("/^Usage: mkntpwd /", shell_exec ("mkntpwd 2>&1"))){
+      $pwdhash= "mkntpwd";
+    } else {
+      $pwdhash= 'perl -MCrypt::SmbHash -e "print join(q[:], ntlmgen \$ARGV[0]), $/;"';
+    }
+
+    $this->timezones = _get_tz_zones();
+    $this->samba_settings['smbhash'] = $pwdhash;
   }
 
  
   function update_strings()
   {
     $this->s_title      = _("GOsa settings 2/3");
-    $this->s_title_long = _("GOsa generic settings, page 2/3");
-    $this->s_info       = _("This dialog allows you to setup GOsa behaviour");
+    $this->s_title_long = _("GOsa settings 2/3");
+    $this->s_info       = _("Customize special parameters");
   }
 
  
   function execute()
   {
+    /* On first call check for rid/sid base */
+    $cv = $this->parent->captured_values;
+    $ldap = new LDAP($cv['admin'],
+        $cv['password'],
+        $cv['connection'],
+        FALSE,
+        $cv['tls']);
+
+    $ldap->cd($cv['base']);
+    $ldap->search("(objectClass=sambaDomain)",array("dn"));
+    if($ldap->count()){
+      $this->sambaDomain_found =TRUE;
+    }else{
+      $this->sambaDomain_found =FALSE;
+    }
+
+    if(!$this->called){
+      if(!$this->sambaDomain_found){
+        $this->samba_settings['samba_sid_active'] = TRUE;
+        $this->samba_settings['samba_rid_active'] = TRUE;
+      }
+  
+      /* Check if we can enable netatalk plugin */
+      $tmp = $ldap->get_objectclasses();
+      if(is_array($tmp) && isset($tmp['apple-user'])) {
+        $this->use_netatalk = TRUE;
+      }
+
+      /* Check the FAI schema is used */
+      if(is_array($tmp) && isset($tmp['FAIclass'])){
+#        $this->enableFAI_management = TRUE;
+      }
+
+      if(is_array($tmp) && isset($tmp['dhcpClass'])){
+        $this->generic_settings['enableDHCP'] = TRUE;
+      }
+
+      if(is_array($tmp) && isset($tmp['dNSZone'])){
+        $this->generic_settings['enableDNS'] = TRUE;
+      }
+
+      $this->called = TRUE;
+    }
+
     /* Update snapshot values, with already collected values */
     foreach($this->generic_settings as $key => $value){
-      foreach(array("snapshot_ldap_base","snapshot_base","snapshot_user","snapshot_server") as $attr){
+      foreach(array("snapshot_base","snapshot_user","snapshot_server") as $attr){
         foreach($this->parent->captured_values as $replace_name => $replace_value){
           if(is_string($replace_value))  {
             $this->generic_settings[$attr] = preg_replace("/%".$replace_name."%/",$replace_value,$this->generic_settings[$attr]);
@@ -75,71 +147,77 @@ class setup_step_6 extends setup_step
     }
 
     $smarty = get_smarty();
+    $smarty->assign("sambaDomain_found",$this->sambaDomain_found);
     $smarty->assign("generic_settings",$this->generic_settings);
+    $smarty->assign("mail_settings",$this->mail_settings);
+    $smarty->assign("mail_methods",$this->mail_methods);
     $smarty->assign("samba_settings",$this->samba_settings);
-    $smarty->assign("warnings" ,$this->check());
-    $smarty->assign("warnings_cnt" ,count($this->check()));
     $smarty->assign("bool",array(FALSE => _("No"), TRUE => _("Yes")));
         foreach($this->attributes as $attr){
       $smarty->assign($attr,$this->$attr);
     }
-    return($smarty -> fetch (get_template_path("../setup/setup_step6.tpl")));
+    $smarty->assign("timezone"     ,$this->timezone);
+    $smarty->assign("timezones"    ,$this->timezones);
+    return($smarty -> fetch (get_template_path("../setup/setup_config2.tpl")));
   }
 
   function save_object()
   {
     if(isset($_POST['step6_posted'])){
 
+      if(isset($_POST['timezone']) && isset($this->timezones['TIMEZONES'][$_POST['timezone']])){
+        $this->timezone = $_POST['timezone'];
+      }
+
       /* Get attributes */
       foreach($this->attributes as $attr){
         if(isset($_POST[$attr])){
-          $this->$attr = validate($_POST[$attr]);
+          $this->$attr = validate(get_post($attr));
         }
       }
 
-      if(isset($_POST['minid_active'])){
-        $this->generic_settings['minid_active'] = TRUE;
-        if(isset($_POST['minid'])){
-          $this->generic_settings['minid'] = $_POST['minid'];
+      /* Mail settings */
+      if(isset($_POST['vacationdir_active'])){
+        $this->mail_settings['vacationdir_active'] = TRUE;
+        if(isset($_POST['vacationdir'])){
+          $this->mail_settings['vacationdir'] = get_post('vacationdir');
         }
       }else{
-        $this->generic_settings['minid_active'] = FALSE;
+        $this->mail_settings['vacationdir_active'] = FALSE;
+      }
+
+      if(isset($_POST['enableCopyPaste'])){
+        $this->generic_settings['enableCopyPaste'] = get_post('enableCopyPaste');
+      }
+      if(isset($_POST['enableDNS'])){
+        $this->generic_settings['enableDNS'] = get_post('enableDNS');
+      }
+      if(isset($_POST['enableDHCP'])){
+        $this->generic_settings['enableDHCP'] = get_post('enableDHCP');
       }
 
       if(isset($_POST['wws_ou_active'])){
         $this->generic_settings['wws_ou_active'] = TRUE;
         if(isset($_POST['wws_ou'])){
-          $this->generic_settings['wws_ou'] = $_POST['wws_ou'];
+          $this->generic_settings['wws_ou'] = get_post('wws_ou');
         }
       }else{
         $this->generic_settings['wws_ou_active'] = FALSE;
       }
 
-      /* Generic settings */
-      if(isset($_POST['idgen_active'])){
-        $this->generic_settings['idgen_active'] = TRUE;
-        if(isset($_POST['idgen'])){
-          $this->generic_settings['idgen'] = $_POST['idgen'];
-        }
-      }else{
-        $this->generic_settings['idgen_active'] = FALSE;
-      }
       if(isset($_POST['snapshot_active'])){
         $this->generic_settings['snapshot_active'] = TRUE;
         if(isset($_POST['snapshot_base'])){
-          $this->generic_settings['snapshot_base'] = $_POST['snapshot_base'];
+          $this->generic_settings['snapshot_base'] = get_post('snapshot_base');
         }
         if(isset($_POST['snapshot_user'])){
-          $this->generic_settings['snapshot_user'] = $_POST['snapshot_user'];
+          $this->generic_settings['snapshot_user'] = get_post('snapshot_user');
         }
         if(isset($_POST['snapshot_password'])){
-          $this->generic_settings['snapshot_password'] = $_POST['snapshot_password'];
+          $this->generic_settings['snapshot_password'] = get_post('snapshot_password');
         }
         if(isset($_POST['snapshot_server'])){
-          $this->generic_settings['snapshot_server'] = $_POST['snapshot_server'];
-        }
-        if(isset($_POST['snapshot_ldap_base'])){
-          $this->generic_settings['snapshot_ldap_base'] = $_POST['snapshot_ldap_base'];
+          $this->generic_settings['snapshot_server'] = get_post('snapshot_server');
         }
       }else{
         $this->generic_settings['snapshot_active'] = FALSE;
@@ -149,7 +227,7 @@ class setup_step_6 extends setup_step
       if(isset($_POST['samba_sid_active'])){
         $this->samba_settings['samba_sid_active'] = TRUE;
         if(isset($_POST['samba_sid'])){
-          $this->samba_settings['samba_sid'] = $_POST['samba_sid'];
+          $this->samba_settings['samba_sid'] = get_post('samba_sid');
         }
       }else{
         $this->samba_settings['samba_sid_active'] = FALSE;
@@ -157,12 +235,19 @@ class setup_step_6 extends setup_step
       if(isset($_POST['samba_rid_active'])){
         $this->samba_settings['samba_rid_active'] = TRUE;
         if(isset($_POST['samba_rid'])){
-          $this->samba_settings['samba_rid'] = $_POST['samba_rid'];
+          $this->samba_settings['samba_rid'] = get_post('samba_rid');
         }
       }else{
         $this->samba_settings['samba_rid_active'] = FALSE;
       }
+      if(isset($_POST['smbhash'])){
+        $this->samba_settings['smbhash'] = get_post('smbhash');
+      }
 
+      if(!$this->sambaDomain_found){
+        $this->samba_settings['samba_sid_active'] = TRUE;
+        $this->samba_settings['samba_rid_active'] = TRUE;
+      }
     }
 
     $tmp = $this->check();
@@ -177,11 +262,6 @@ class setup_step_6 extends setup_step
   function check()
   {
     $message = array();
-    
-    if(isset($this->generic_settings['minid_active']) && !is_numeric($this->generic_settings['minid'])){
-      $message[] = sprintf(_("The specified value for '%s' must be a numeric value"),_("GID / UID min id"));
-    }
-  
     return($message);
   }
   
@@ -190,12 +270,36 @@ class setup_step_6 extends setup_step
   function get_attributes()
   {
     $tmp = setup_step::get_attributes();
-    foreach(array("samba_settings","generic_settings") as $attr){
+    foreach(array("samba_settings","generic_settings","mail_settings") as $attr){
       $tmp[$attr]= $this->$attr;
     }
     return($tmp);
   }
 
+/* Returns the classnames auf the mail classes */
+  function get_available_mail_classes()
+  {
+    $dir = opendir( "../include");
+    $methods = array();
+    $suffix = "class_mail-methods-";
+    $lensuf = strlen($suffix);
+    $prefix = ".inc";
+    $lenpre = strlen($prefix);
+    $i = 0;
+    while (($file = readdir($dir)) !== false){
+
+      if(stristr($file,$suffix)) {
+        $lenfile = strlen($file);
+        $methods['name'][$i] = substr($file,$lensuf,($lenfile-$lensuf)-$lenpre);
+        $methods['file'][$i] = $file;
+        $methods[$i]['file'] = $file;
+        $methods[$i]['name'] = substr($file,$lensuf,($lenfile-$lensuf)-$lenpre);
+        $i++;
+      }
+    }
+    return($methods);
+  }
+
 }
 
 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: