Code

IP is not a must field for winstations anymore
[gosa.git] / gosa-plugins / samba / admin / systems / samba / class_winGeneric.inc
1 <?php
3 class wingeneric extends plugin
4 {
5   /* Generic terminal attributes */
6   var $interfaces= array();
8   /* Needed values and lists */
9   var $base= "";
10   var $cn= "";
11   var $description= "";
12   var $orig_dn= "";
13   var $shadowLastChange="";
14   var $uidNumber="";
15   var $gidNumber="";
16   var $loginShell="";
17   var $gecos="";
18   var $shadowMin="";
19   var $shadowWarning="";
20   var $shadowInactive="";
21   var $uid="";
22   var $sn="";
23   var $givenName="";
24   var $homeDirectory="";
25   var $sambaSID="";
26   var $sambaPrimaryGroupSID="";
27   var $displayName="";
28   var $sambaPwdMustChange="";
29   var $sambaNTPassword="";
30   var $sambaPwdLastSet="";
31   var $sambaAcctFlags="";
32   var $netConfigDNS;
34   var $orig_cn;
35   var $orig_base;
37   /* attribute list for save action */
38   var $ignore_account= TRUE;
39   var $attributes   = array("cn", "description","shadowLastChange",
40                             "uidNumber","gidNumber","loginShell","gecos","shadowMin","shadowWarning",
41                             "shadowInactive","uid","cn","sn","givenName","homeDirectory","sambaSID",
42                             "sambaPrimaryGroupSID","displayName", "sambaPwdMustChange",
43                             "sambaNTPassword","sambaPwdLastSet","sambaAcctFlags");
44   var $objectclasses= array("posixAccount","person","organizationalPerson","inetOrgPerson","gosaAccount","shadowAccount","sambaSamAccount","top");
46   var $view_logged = FALSE;
48   function wingeneric (&$config, $dn= NULL, $parent= NULL)
49   {
50     plugin::plugin ($config, $dn, $parent);
51     $this->netConfigDNS = new termDNS($this->config,$this,$this->objectclasses);
52     $this->netConfigDNS->objectclasses=array("ipHost","ieee802Device");
53     $this->netConfigDNS->MACisMust = FALSE;
54     $this->netConfigDNS->IPisMust = FALSE;
56     /* Set base */
57     if ($this->dn == "new"){
58       $ui= get_userinfo();
59       $this->base= dn2base($ui->dn);
60       $this->cn= "";
61     } else {
62       $this->base= preg_replace ("/^[^,]+,".preg_quote(get_winstations_ou(), '/')."/", "", $this->dn);
63     }
65     $this->cn= preg_replace("/\\\$\$/","",$this->cn);
67     /* Save dn for later references */
68     $this->orig_dn= $this->dn;
69     $this->orig_base= $this->base;
70     $this->orig_cn= $this->cn;
71   }
74   function set_acl_base($base)
75   {
76     plugin::set_acl_base($base);
77     $this->netConfigDNS->set_acl_base($base);
78   }
81   function set_acl_category($cat)
82   {
83     plugin::set_acl_category($cat);
84     $this->netConfigDNS->set_acl_category($cat);
85   }
88   function execute()
89   {
90     /* Call parent execute */
91     plugin::execute();
93     if($this->is_account && !$this->view_logged){
94       $this->view_logged = TRUE;
95       new log("view","winworkstation/".get_class($this),$this->dn);
96     }
99     /* Do we represent a valid phone? */
100     if (!$this->is_account && $this->parent === NULL){
101       $display= "<img alt=\"\" src=\"images/small-error.png\" align=middle>&nbsp;<b>".
102         msgPool::noValidExtension(_("network"))."</b>";
103       return($display);
104     }
106     /* Base select dialog */
107     $once = true;
108     foreach($_POST as $name => $value){
109       if(preg_match("/^chooseBase/",$name) && $once){
110         $once = false;
111         $this->dialog = new baseSelectDialog($this->config,$this);
112         $this->dialog->setCurrentBase($this->base);
113       }
114     }
116     /* Dialog handling */
117     if(is_object($this->dialog)){
118       /* Must be called before save_object */
119       $this->dialog->save_object();
121       if($this->dialog->isClosed()){
122         $this->dialog = false;
123       }elseif($this->dialog->isSelected()){
125         /* A new base was selected, check if it is a valid one */
126         $tmp = $this->get_allowed_bases();
127         if(isset($tmp[$this->dialog->isSelected()])){
128           $this->base = $this->dialog->isSelected();
129         }
131         $this->dialog= false;
132       }else{
133         return($this->dialog->execute());
134       }
135     }
137     /* Fill templating stuff */
138     $smarty= get_smarty();
139     $smarty->assign("bases"   , $this->get_allowed_bases());
140     
141     $tmp = $this->plInfo();
142     foreach($tmp['plProvidedAcls'] as $name => $translated){
143       $smarty->assign($name."ACL",$this->getacl($name));
144     }
146     /* Assign attributes */
147     foreach ($this->attributes as $attr){
148       $smarty->assign("$attr", $this->$attr);
149     }
150     
151     $smarty->assign("base_select", $this->base);
153     /* Show main page */
154     $str = $this->netConfigDNS->execute();
155     if(is_object($this->netConfigDNS->dialog)){
156       return($str);
157     }
158     $smarty->assign("netconfig", $str);
159     return($smarty->fetch (get_template_path('wingeneric.tpl', TRUE,dirname(__FILE__))));
160   }
162   function remove_from_parent()
163   {
164     $this->netConfigDNS->remove_from_parent();
165     $ldap= $this->config->get_ldap_link();
166     $ldap->rmdir($this->dn);
167     new log("remove","winworkstation/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
168     if (!$ldap->success()){
169       msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_DEL, get_class()));
170     }
171     $this->handle_post_events("remove");
173     /* Delete references to object groups */
174     $ldap->cd ($this->config->current['BASE']);
175     $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".LDAP::prepare4filter($this->dn)."))", array("cn"));
176     while ($ldap->fetch()){
177       $og= new ogroup($this->config, $ldap->getDN());
178       unset($og->member[$this->dn]);
179       $og->save ();
180     }
181   }
184   /* Save data to object */
185   function save_object()
186   {
187     /* Create a base backup and reset the
188        base directly after calling plugin::save_object();
189        Base will be set seperatly a few lines below */
190     $base_tmp = $this->base;
191     plugin::save_object();
192     $this->base = $base_tmp;
194     $this->netConfigDNS->save_object();
196     /* Set new base if allowed */
197     $tmp = $this->get_allowed_bases();
198     if(isset($_POST['base'])){
199       if(isset($tmp[$_POST['base']])){
200         $this->base= $_POST['base'];
201       }
202     }
203   }
206   /* Check supplied data */
207   function check()
208   {
209     /* Call common method to give check the hook */
210     $message= plugin::check();
211     $message= array_merge($message, $this->netConfigDNS->check());
212     $this->dn= "cn=".$this->uid.",".get_ou('sambaMachineAccountRDN').$this->base;
214     if(!$this->acl_is_createable()){
215       $message[]= msgPool::permCreate();
216     }
218     if ($this->orig_dn != $this->dn){
219       $ldap= $this->config->get_ldap_link();
220       $ldap->cd ($this->base);
221       $ldap->search ("(cn=".$this->cn.")", array("cn"));
222       if ($ldap->count() != 0){
223         while ($attrs= $ldap->fetch()){
224           if(preg_match("/cn=dhcp,/",$attrs['dn'])){
225             continue;
226           }
227           if ($attrs['dn'] != $this->orig_dn){
228             $message[]= msgPool::duplicated(_("Name"));
229             break;
230           }
231         }
232       }
233     }
235     /* Check if we are allowed to create or move this object
236      */
237     if($this->orig_dn == "new" && !$this->acl_is_createable($this->base)){
238       $message[] = msgPool::permCreate();
239     }elseif($this->orig_dn != "new" && $this->base != $this->orig_base && !$this->acl_is_moveable($this->base)){
240       $message[] = msgPool::permMove();
241     }
243     return ($message);
244   }
247   /* Save to LDAP */
248   function save()
249   {
250     plugin::save();
252     /* Remove all empty values */
253     if ($this->orig_dn == 'new'){
254       $attrs= array();
255       foreach ($this->attrs as $key => $val){
256         if (is_array($val) && count($val) == 0){
257           continue;
258         }
259         $attrs[$key]= $val;
260       }
261       $this->attrs= $attrs;
262     }
264     if(($this->gosaUnitTag) && (!in_array_ics("gosaAdministrativeUnitTag",$this->attrs['objectClass']))){
265       $this->attrs['objectClass'][] = "gosaAdministrativeUnitTag";
266     }
268     /* Write back to ldap */
269     $ldap= $this->config->get_ldap_link();
270     if ($this->orig_dn == 'new'){
271       $ldap->cd($this->config->current['BASE']);
272       $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
273       $ldap->cd($this->dn);
274       $ldap->add($this->attrs);
275       new log("create","winworkstation/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
276       $this->handle_post_events("add");
277     } else {
278       if ($this->orig_dn != $this->dn){
279         $this->move($this->orig_dn, $this->dn);
280       }
282       $ldap->cd($this->dn);
283       $this->cleanup();
284       $ldap->modify ($this->attrs); 
285       new log("modify","winworkstation/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
286       $this->handle_post_events("modify");
287     }
289     $this->netConfigDNS->cn =  preg_replace("/\\\$\$/","",$this->cn);
290     $this->netConfigDNS->save();
291     if (!$ldap->success()){
292       msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, 0, get_class()));
293     }
295     /* Optionally execute a command after we're done */
296     $this->postcreate();
297   }
299   /* Return plugin informations for acl handling
300   #FIXME FAIscript seams to ununsed within this class... */
301   static function plInfo()
302   {
303     return (array(
304           "plShortName"   => _("Win generic"),
305           "plDescription" => _("Windows workstation generic"),
306           "plSelfModify"  => FALSE,
307           "plDepends"     => array(),
308           "plPriority"    => 0,
309           "plSection"     => array("administration"),
310           "plCategory"    => array("winworkstation" => array("description"  => _("Win workstation"),
311                                                           "objectClass"  => "gotoWorkstation")),
312           "plProvidedAcls"=> array(
313             "cn"                  => _("Name"),
314             "base"                => _("Base"),
315             "description"         => _("Description"))
316           ));
317   }
322 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
323 ?>