Code

plProperty updates
[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;
36   var $baseSelector;
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");
47   var $view_logged = FALSE;
49   function wingeneric (&$config, $dn= NULL, $parent= NULL)
50   {
51     plugin::plugin ($config, $dn, $parent);
52     $this->netConfigDNS = new termDNS($this->config,$this,$this->objectclasses,FALSE,"uid");
53     $this->netConfigDNS->cn =  preg_replace("/\\\$\$/","",$this->uid);
54     $this->netConfigDNS->MACisMust = FALSE;
55     $this->netConfigDNS->IPisMust = FALSE;
57     /* Set base */
58     if ($this->dn == "new"){
59       $ui = get_userinfo();
60       $this->base= dn2base(session::global_is_set("CurrentMainBase")?"cn=dummy,".session::global_get("CurrentMainBase"):$ui->dn);
61       $this->cn= "";
62     } elseif(class_available("ArpNewDevice") &&
63                 preg_match("/".preg_quote(get_ou("ArpNewDevice", "systemIncomingRDN"), '/')."/i", $this->dn)){
64       $this->base= preg_replace ("/^[^,]+,".preg_quote(get_ou("ArpNewDevice", "systemIncomingRDN"), '/')."/i", "", $this->dn);
65     } else {
66       $this->base= preg_replace ("/^[^,]+,".preg_quote(get_winstations_ou(), '/')."/i", "", $this->dn);
67     }
69     $this->cn= preg_replace("/\\\$\$/","",$this->cn);
71     /* Save dn for later references */
72     $this->orig_dn= $this->dn;
73     $this->orig_base= $this->base;
74     $this->orig_cn= $this->cn;
76     /* Instanciate base selector */
77     $this->baseSelector= new baseSelector($this->get_allowed_bases(), $this->base);
78     $this->baseSelector->setSubmitButton(false);
79     $this->baseSelector->setHeight(300);
80     $this->baseSelector->update(true);
81   }
84   function set_acl_base($base)
85   {
86     plugin::set_acl_base($base);
87     $this->netConfigDNS->set_acl_base($base);
88   }
91   function set_acl_category($cat)
92   {
93     plugin::set_acl_category($cat);
94     $this->netConfigDNS->set_acl_category($cat);
95   }
98   function execute()
99   {
100     /* Call parent execute */
101     plugin::execute();
103     if($this->is_account && !$this->view_logged){
104       $this->view_logged = TRUE;
105       new log("view","winworkstation/".get_class($this),$this->dn);
106     }
109     /* Do we represent a valid phone? */
110     if (!$this->is_account && $this->parent === NULL){
111       $display= "<img alt=\"\" src=\"images/small-error.png\" align=middle>&nbsp;<b>".
112         msgPool::noValidExtension(_("network"))."</b>";
113       return($display);
114     }
116     /* Fill templating stuff */
117     $smarty= get_smarty();
119     
120     $tmp = $this->plInfo();
121     foreach($tmp['plProvidedAcls'] as $name => $translated){
122       $smarty->assign($name."ACL",$this->getacl($name));
123     }
125     /* Assign attributes */
126     foreach ($this->attributes as $attr){
127       $smarty->assign("$attr", set_post($this->$attr));
128     }
129     
130     $smarty->assign("base", $this->baseSelector->render());
132     /* Show main page */
133     $str = $this->netConfigDNS->execute();
134     if(is_object($this->netConfigDNS->dialog)){
135       return($str);
136     }
137     $smarty->assign("netconfig", $str);
138     return($smarty->fetch (get_template_path('wingeneric.tpl', TRUE,dirname(__FILE__))));
139   }
141   function remove_from_parent()
142   {
143     $this->netConfigDNS->remove_from_parent();
144     $ldap= $this->config->get_ldap_link();
145     $ldap->rmdir($this->dn);
146     new log("remove","winworkstation/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
147     if (!$ldap->success()){
148       msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_DEL, get_class()));
149     }
150     $this->handle_post_events("remove");
152     /* Delete references to object groups */
153     $ldap->cd ($this->config->current['BASE']);
154     $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".LDAP::prepare4filter($this->dn)."))", array("cn"));
155     while ($ldap->fetch()){
156       $og= new ogroup($this->config, $ldap->getDN());
157       unset($og->member[$this->dn]);
158       $og->save ();
159     }
160   }
163   /* Save data to object */
164   function save_object()
165   {
166     /* Create a base backup and reset the
167        base directly after calling plugin::save_object();
168        Base will be set seperatly a few lines below */
169     $base_tmp = $this->base;
170     plugin::save_object();
171     $this->base = $base_tmp;
173     $this->netConfigDNS->save_object();
175     /* Refresh base */
176     if ($this->acl_is_moveable($this->base)){
177       if (!$this->baseSelector->update()) {
178         msg_dialog::display(_("Error"), msgPool::permMove(), ERROR_DIALOG);
179       }
180       if ($this->base != $this->baseSelector->getBase()) {
181         $this->base= $this->baseSelector->getBase();
182         $this->is_modified= TRUE;
183       }
184     }
186   }
189   /* Check supplied data */
190   function check()
191   {
192     /* Call common method to give check the hook */
193     $message= plugin::check();
194     $message= array_merge($message, $this->netConfigDNS->check());
195     $this->dn= "cn=".$this->uid.",".get_ou("wingeneric", "sambaMachineAccountRDN").$this->base;
197     if(!$this->acl_is_createable()){
198       $message[]= msgPool::permCreate();
199     }
201     if ($this->orig_dn != $this->dn){
202       $ldap= $this->config->get_ldap_link();
203       $ldap->cd ($this->base);
204       $ldap->search ("(cn=".$this->cn.")", array("cn"));
205       if ($ldap->count() != 0){
206         while ($attrs= $ldap->fetch()){
207           if(preg_match("/cn=dhcp,/",$attrs['dn'])){
208             continue;
209           }
210           if ($attrs['dn'] != $this->orig_dn){
211             $message[]= msgPool::duplicated(_("Name"));
212             break;
213           }
214         }
215       }
216     }
218     // Check if a wrong base was supplied
219     if(!$this->baseSelector->checkLastBaseUpdate()){
220       $message[]= msgPool::check_base();;
221     }
223     /* Check if we are allowed to create or move this object
224      */
225     if($this->orig_dn == "new" && !$this->acl_is_createable($this->base)){
226       $message[] = msgPool::permCreate();
227     }elseif($this->orig_dn != "new" && $this->base != $this->orig_base && !$this->acl_is_moveable($this->base)){
228       $message[] = msgPool::permMove();
229     }
231     return ($message);
232   }
235   /* Save to LDAP */
236   function save()
237   {
238     plugin::save();
240     /* Remove all empty values */
241     if ($this->orig_dn == 'new'){
242       $attrs= array();
243       foreach ($this->attrs as $key => $val){
244         if (is_array($val) && count($val) == 0){
245           continue;
246         }
247         $attrs[$key]= $val;
248       }
249       $this->attrs= $attrs;
250     }
252     if(($this->gosaUnitTag) && (!in_array_ics("gosaAdministrativeUnitTag",$this->attrs['objectClass']))){
253       $this->attrs['objectClass'][] = "gosaAdministrativeUnitTag";
254     }
256     $curOcs = $this->attrs['objectClass'];
257     $this->cleanup();
259     // Prepare list of object classes
260     $ocs = array();
261     if(!empty($this->netConfigDNS->macAddress)){
262         $ocs [] = 'ieee802Device';
263     }else{
264         $curOcs = array_remove_entries(array('ieee802Device'), $curOcs);
265         $this->attrs['macAddress'] = array();
266     } 
267     if(!empty($this->netConfigDNS->ipHostNumber)){
268         $ocs [] = 'ipHost';
269     }else{
270         $curOcs = array_remove_entries(array('ipHost'), $curOcs);
271         $this->attrs['ipHostNumber'] = array();
272     } 
274     $this->attrs['objectClass']=$curOcs;
276     /* Write back to ldap */
277     $ldap= $this->config->get_ldap_link();
278     if ($this->orig_dn == 'new'){
279       $ldap->cd($this->config->current['BASE']);
280       $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
281       $ldap->cd($this->dn);
282       $ldap->add($this->attrs);
283       new log("create","winworkstation/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
284       $this->handle_post_events("add");
285     } else {
286       if ($this->orig_dn != $this->dn){
287         $this->move($this->orig_dn, $this->dn);
288       }
290       $ldap->cd($this->dn);
291       $ldap->modify ($this->attrs); 
292       new log("modify","winworkstation/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
293       $this->handle_post_events("modify");
294     }
296     if (!$ldap->success()){
297       msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, 0, get_class()));
298     }
300     // Prepare list of object classes
301     $ocs = array();
302     if(!empty($this->netConfigDNS->macAddress)){
303         $ocs [] = 'ieee802Device';
304     } 
305     if(!empty($this->netConfigDNS->ipHostNumber)){
306         $ocs [] = 'ipHost';
307     } 
309     $this->netConfigDNS->objectclasses=$ocs;
310     $this->netConfigDNS->cn =  preg_replace("/\\\$\$/","",$this->uid);
311     $this->netConfigDNS->save();
312   }
314   /* Return plugin informations for acl handling
315   #FIXME FAIscript seams to ununsed within this class... */
316   static function plInfo()
317   {
318       return (array(
319                   "plShortName"   => _("Win generic"),
320                   "plDescription" => _("Windows workstation generic"),
321                   "plSelfModify"  => FALSE,
322                   "plDepends"     => array(),
323                   "plPriority"    => 0,
324                   "plSection"     => array("administration"),
325                   "plCategory"    => array("winworkstation" => array("description"  => _("Win workstation"),
326                           "objectClass"  => "gotoWorkstation")),
328                   "plRequirements"=> array(
329                       'ldapSchema' => array(
330                           'posixAccount' => '',
331                           'organizationalPerson' => '',
332                           'person' => '',
333                           'inetOrgPerson' => '',
334                           'gosaAccount' => '>=2.7',
335                           'shadowAccount' => '',
336                           'sambaSamAccount' => ''
337                           ),
338                       'onFailureDisablePlugin' => array(get_class())
339                       ),
342                   "plProperties" =>
343                   array(
344                       array(
345                           "name"          => "sambaMachineAccountRDN",
346                           "type"          => "rdn",
347                           "default"       => "ou=winstations,ou=systems,",
348                           "description"   => _("RDN for samba machine account storage."),
349                           "check"         => "gosaProperty::isRdn",
350                           "migrate"       => "migrate_sambaMachineAccountRDN",
351                           "group"         => "plugin",
352                           "mandatory"     => FALSE
353                           )
354                       ),
356           "plProvidedAcls"=> array(
357             "cn"                  => _("Name"),
358             "base"                => _("Base"),
359             "description"         => _("Description"))
360           ));
361   }
366 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
367 ?>