Code

SETUP: Added ldap accessibility check to migration step
[gosa.git] / setup / class_setupStep_Migrate.inc
1 <?php
3 /*
4    This code is part of GOsa (https://gosa.gonicus.de)
5    Copyright (C) 2007 Fabian Hickert
7    This program is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 2 of the License, or
10    (at your option) any later version.
12    This program is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
17    You should have received a copy of the GNU General Public License
18    along with this program; if not, write to the Free Software
19    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20 */
23 class Step_Migrate extends setup_step
24 {
25   var $languages      = array();
26   var $attributes     = array();
27   var $header_image   = "images/monitoring.png";
28   var $checks         = array();
30   function Step_Migrate()
31   {
32     $this->update_strings(); 
33     $this->initialize_checks();
34   }
36   function update_strings()
37   {
38     $this->s_title      = _("LDAP inspection");
39     $this->s_title_long = _("LDAP inspection");
40     $this->s_info       = _("Analyze your current LDAP for GOsa compatibility");
41   }
42  
43   function initialize_checks()
44   {
45     $this->checks = array();
46     $this->checks['permissions']['TITLE']     = _("Checking permissions on ldap database");
47     $this->checks['permissions']['STATUS']    = FALSE;
48     $this->checks['permissions']['STATUS_MSG']= "";
49     $this->checks['permissions']['CHK_FUNC']  = "check_ldap_permissions";
50     $this->checks['permissions']['ERROR_MSG'] = _("The specified user '%s' does not have full access to your ldap database.");
51   }
54   /* Check ldap accessibility 
55    * Create and remove a dummy object, 
56    *  to ensure that we have the necessary permissions
57    */
58   function check_ldap_permissions()
59   {
60     $cv = $this->parent->captured_values;
61     $ldap = new LDAP($cv['admin'],
62                      $cv['password'],
63                      $cv['connection'],
64                      FALSE,
65                      $cv['tls']);
66     $name     = "GOsa_setup_text_entry_".session_id().rand(0,999999);
67     $dn       = "ou=".$name.",".$cv['base'];
68     $testEntry= array();
69     $testEntry['objectClass'][]= "top";
70     $testEntry['objectClass'][]= "organizationalUnit";
71     $testEntry['objectClass'][]= "gosaDepartment";
72     $testEntry['description']= "Created by GOsa setup, this object can be removed.";
73     $testEntry['ou']  = $name;
74  
75     $ldap->cd ($dn);
76     $res = $ldap->add($testEntry);
77     if(!$res){
78       $this->checks['permissions']['STATUS']    = FALSE;
79       $this->checks['permissions']['STATUS_MSG']= _("Failed");
80       $this->checks['permissions']['ERROR_MSG'] = 
81         sprintf(_("The specified user '%s' does not have full access to your ldap database."),$cv['admin']);
82       return(false);
83     }
85     $res = $ldap->rmDir($dn);
86     if(!$res){
87       $this->checks['permissions']['STATUS']    = FALSE;
88       $this->checks['permissions']['STATUS_MSG']= _("Failed");
89       $this->checks['permissions']['ERROR_MSG'] = 
90         sprintf(_("The specified user '%s' does not have full access to your ldap database."),$cv['admin']);
91       return(false);
92     }
94     $this->checks['permissions']['STATUS']    = TRUE;
95     $this->checks['permissions']['STATUS_MSG']= _("Ok");
96     $this->checks['permissions']['ERROR_MSG'] = "";
97     return(true);
98   } 
101   function check_visible_organizationalUnits()
102   {
104   }
107   function execute()
108   {
109     $smarty = get_smarty();
110     $smarty->assign("checks",$this->checks);
111     return($smarty->fetch(get_template_path("setup_migrate.tpl",TRUE,dirname(__FILE__))));
112   }
114   function save_object()
115   {
116     $this->is_completed = TRUE;
118     $once = TRUE;
119     foreach($_POST as $name => $value){
120         
121       if(preg_match("/^retry_/",$name) && $once){
122         $once   = FALSE;
123         $check  = preg_replace("/^retry_/","",$name);
124         $func = $this->checks[$check]['CHK_FUNC'];
125         $this->checks[$check]['STATUS']=$this->$func();
126       }
127     }
128   }
131 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
132 ?>