Code

Added logging to some classes
[gosa.git] / plugins / admin / systems / class_winGeneric.inc
1 <?php
3 class wingeneric extends plugin
4 {
5   /* CLI vars */
6   var $cli_summary        = "Manage component base objects";
7   var $cli_description    = "Some longer text\nfor help";
8   var $cli_parameters     = array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
10   /* Generic terminal attributes */
11   var $interfaces= array();
13   /* Needed values and lists */
14   var $base= "";
15   var $cn= "";
16   var $description= "";
17   var $orig_dn= "";
18   var $shadowLastChange="";
19   var $uidNumber="";
20   var $gidNumber="";
21   var $loginShell="";
22   var $gecos="";
23   var $shadowMin="";
24   var $shadowWarning="";
25   var $shadowInactive="";
26   var $uid="";
27   var $sn="";
28   var $givenName="";
29   var $homeDirectory="";
30   var $sambaSID="";
31   var $sambaPrimaryGroupSID="";
32   var $displayName="";
33   var $sambaPwdMustChange="";
34   var $sambaNTPassword="";
35   var $sambaPwdLastSet="";
36   var $sambaAcctFlags="";
37   var $netConfigDNS;
38   /* attribute list for save action */
39   var $ignore_account= TRUE;
40   var $attributes   = array("cn", "description","shadowLastChange",
41                             "uidNumber","gidNumber","loginShell","gecos","shadowMin","shadowWarning",
42                             "shadowInactive","uid","cn","sn","givenName","homeDirectory","sambaSID",
43                             "sambaPrimaryGroupSID","displayName", "sambaPwdMustChange",
44                             "sambaNTPassword","sambaPwdLastSet","sambaAcctFlags");
45   var $objectclasses= array("posixAccount","person","organizationalPerson","inetOrgPerson","gosaAccount","shadowAccount","sambaSamAccount","top");
48   function wingeneric ($config, $dn= NULL, $parent= NULL)
49   {
50     plugin::plugin ($config, $dn, $parent);
51     $this->netConfigDNS = new termDNS($this->config,$this->dn,$this->objectclasses);
52     /* Set base */
53     if ($this->dn == "new"){
54       $ui= get_userinfo();
55       $this->base= dn2base($ui->dn);
56       $this->cn= "";
57     } else {
58       $this->base= preg_replace ("/^[^,]+,".normalizePreg(get_winstations_ou())."/", "", $this->dn);
59     }
61     /* Save dn for later references */
62     $this->orig_dn= $this->dn;
64     $this->cn= preg_replace("/\\\$\$/","",$this->cn);
66     if($this->is_account){
67       @log::log("view","winworkstation/".get_class($this),$this->dn);
68     }
69   }
72   function set_acl_base($base)
73   {
74     plugin::set_acl_base($base);
75     $this->netConfigDNS->set_acl_base($base);
76   }
78   function set_acl_category($cat)
79   {
80     plugin::set_acl_category($cat);
81     $this->netConfigDNS->set_acl_category($cat);
82   }
85   function execute()
86   {
87         /* Call parent execute */
88         plugin::execute();
90     /* Do we represent a valid phone? */
91     if (!$this->is_account && $this->parent == NULL){
92       $display= "<img alt=\"\" src=\"images/stop.png\" align=middle>&nbsp;<b>".
93         _("This 'dn' has no network features.")."</b>";
94       return($display);
95     }
97     /* Base select dialog */
98     $once = true;
99     foreach($_POST as $name => $value){
100       if(preg_match("/^chooseBase/",$name) && $once){
101         $once = false;
102         $this->dialog = new baseSelectDialog($this->config,$this);
103         $this->dialog->setCurrentBase($this->base);
104       }
105     }
107     /* Dialog handling */
108     if(is_object($this->dialog)){
109       /* Must be called before save_object */
110       $this->dialog->save_object();
112       if($this->dialog->isClosed()){
113         $this->dialog = false;
114       }elseif($this->dialog->isSelected()){
116         /* A new base was selected, check if it is a valid one */
117         $tmp = $this->get_allowed_bases();
118         if(isset($tmp[$this->dialog->isSelected()])){
119           $this->base = $this->dialog->isSelected();
120         }
122         $this->dialog= false;
123       }else{
124         return($this->dialog->execute());
125       }
126     }
128     /* Fill templating stuff */
129     $smarty= get_smarty();
131     // Undefined index in wingeneric.tpl ... 
132     $smarty->assign("bases", $this->config->idepartments);
134     /* Assign attributes */
135     foreach ($this->attributes as $attr){
136       $smarty->assign("$attr", $this->$attr);
137     }
138     
139     $smarty->assign("base_select", $this->base);
141     /* Show main page */
142     $smarty->assign("netconfig", $this->netConfigDNS->execute());
143     return($smarty->fetch (get_template_path('wingeneric.tpl', TRUE)));
144   }
146   function remove_from_parent()
147   {
148     $this->netConfigDNS->remove_from_parent();
149     $ldap= $this->config->get_ldap_link();
150     $ldap->rmdir($this->dn);
151     @log::log("remove","winworkstation/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
152     show_ldap_error($ldap->get_error(), sprintf(_("Removing of system wingeneric/generic with dn '%s' failed."),$this->dn));
153     $this->handle_post_events("remove");
155     /* Delete references to object groups */
156     $ldap->cd ($this->config->current['BASE']);
157     $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".$this->dn."))", array("cn"));
158     while ($ldap->fetch()){
159       $og= new ogroup($this->config, $ldap->getDN());
160       unset($og->member[$this->dn]);
161       $og->save ();
162     }
163   }
166   /* Save data to object */
167   function save_object()
168   {
169     /* Create a base backup and reset the
170        base directly after calling plugin::save_object();
171        Base will be set seperatly a few lines below */
172     $base_tmp = $this->base;
173     plugin::save_object();
174     $this->base = $base_tmp;
176     $this->netConfigDNS->save_object();
178     /* Set new base if allowed */
179     $tmp = $this->get_allowed_bases();
180     if(isset($_POST['base'])){
181       if(isset($tmp[$_POST['base']])){
182         $this->base= $_POST['base'];
183       }
184     }
185   }
188   /* Check supplied data */
189   function check()
190   {
191     /* Call common method to give check the hook */
192     $message= plugin::check();
193     $message= array_merge($message, $this->netConfigDNS->check());
194     $this->dn= "cn=".$this->cn.",ou=netdevices,ou=systems,".$this->base;
195     
196     /* Set new acl base */
197     if($this->dn == "new") {
198       $this->set_acl_base($this->base);
199     }
201     if(!$this->acl_is_createable() && $this->dn == "new"){
202       $message[]= _("You have no permissions to create a component on this 'Base'.");
203     }
205     if ($this->orig_dn != $this->dn){
206       $ldap= $this->config->get_ldap_link();
207       $ldap->cd ($this->base);
208       $ldap->search ("(cn=".$this->cn.")", array("cn"));
209       if ($ldap->count() != 0){
210         while ($attrs= $ldap->fetch()){
211           if ($attrs['dn'] != $this->orig_dn){
212             $message[]= sprintf (_("There is already an entry '%s' in the base choosen by you"), $this->cn);
213             break;
214           }
215         }
216       }
217     }
219     return ($message);
220   }
223   /* Save to LDAP */
224   function save()
225   {
226     plugin::save();
228     /* Remove all empty values */
229     if ($this->orig_dn == 'new'){
230       $attrs= array();
231       foreach ($this->attrs as $key => $val){
232         if (is_array($val) && count($val) == 0){
233           continue;
234         }
235         $attrs[$key]= $val;
236       }
237       $this->attrs= $attrs;
238     }
240     if(($this->gosaUnitTag) && (!in_array_ics("gosaAdministrativeUnitTag",$this->attrs['objectClass']))){
241       $this->attrs['objectClass'][] = "gosaAdministrativeUnitTag";
242     }
244     /* Write back to ldap */
245     $ldap= $this->config->get_ldap_link();
246     if ($this->orig_dn == 'new'){
247       $ldap->cd($this->config->current['BASE']);
248       $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
249       $ldap->cd($this->dn);
250       $ldap->add($this->attrs);
251       @log::log("create","winworkstation/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
252       $this->handle_post_events("add");
253     } else {
254       if ($this->orig_dn != $this->dn){
255         $this->move($this->orig_dn, $this->dn);
256       }
258       $ldap->cd($this->dn);
259       $this->cleanup();
260       $ldap->modify ($this->attrs); 
261       @log::log("modify","winworkstation/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
262       $this->handle_post_events("modify");
263     }
265     $this->netConfigDNS->cn =  preg_replace("/\\\$\$/","",$this->cn);
266     $this->netConfigDNS->save($this->dn);
267     show_ldap_error($ldap->get_error(), sprintf(_("Saving of system wingeneric/generic with dn '%s' failed."),$this->dn));
269     /* Optionally execute a command after we're done */
270     $this->postcreate();
271   }
273   /* Return plugin informations for acl handling
274   #FIXME FAIscript seams to ununsed within this class... */
275   function plInfo()
276   {
277     return (array(
278           "plShortName"   => _("Win generic"),
279           "plDescription" => _("Windows workstation generic"),
280           "plSelfModify"  => FALSE,
281           "plDepends"     => array(),
282           "plPriority"    => 0,
283           "plSection"     => array("administration"),
284           "plCategory"    => array("winworkstation" => array("description"  => _("Win workstation"),
285                                                           "objectClass"  => "gotoWorkstation")),
286           "plProvidedAcls"=> array(
287             "cn"                  => _("Workstation name"),
288             "description"         => _("Description"))
289           ));
290   }
295 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
296 ?>