Code

Added translation tags to property description.
[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->objectclasses=array("ipHost","ieee802Device");
55     $this->netConfigDNS->MACisMust = FALSE;
56     $this->netConfigDNS->IPisMust = FALSE;
58     /* Set base */
59     if ($this->dn == "new"){
60       $ui = get_userinfo();
61       $this->base= dn2base(session::global_is_set("CurrentMainBase")?"cn=dummy,".session::global_get("CurrentMainBase"):$ui->dn);
62       $this->cn= "";
63     } elseif(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", $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     /* Write back to ldap */
257     $ldap= $this->config->get_ldap_link();
258     if ($this->orig_dn == 'new'){
259       $ldap->cd($this->config->current['BASE']);
260       $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
261       $ldap->cd($this->dn);
262       $ldap->add($this->attrs);
263       new log("create","winworkstation/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
264       $this->handle_post_events("add");
265     } else {
266       if ($this->orig_dn != $this->dn){
267         $this->move($this->orig_dn, $this->dn);
268       }
270       $ldap->cd($this->dn);
271       $this->cleanup();
272       $ldap->modify ($this->attrs); 
273       new log("modify","winworkstation/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
274       $this->handle_post_events("modify");
275     }
277     $this->netConfigDNS->cn =  preg_replace("/\\\$\$/","",$this->uid);
278     $this->netConfigDNS->save();
279     if (!$ldap->success()){
280       msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, 0, get_class()));
281     }
282   }
284   /* Return plugin informations for acl handling
285   #FIXME FAIscript seams to ununsed within this class... */
286   static function plInfo()
287   {
288       return (array(
289                   "plShortName"   => _("Win generic"),
290                   "plDescription" => _("Windows workstation generic"),
291                   "plSelfModify"  => FALSE,
292                   "plDepends"     => array(),
293                   "plPriority"    => 0,
294                   "plSection"     => array("administration"),
295                   "plCategory"    => array("winworkstation" => array("description"  => _("Win workstation"),
296                           "objectClass"  => "gotoWorkstation")),
297                   "plProperties" =>
298                   array(
299                       array(
300                           "name"          => "sambaMachineAccountRDN",
301                           "type"          => "rdn",
302                           "default"       => "ou=winstation,",
303                           "description"   => _("The 'sambaMachineAccountRDN' statement defines the location where new windows workstations will be created. The default is 'ou=winstation,'."),
304                           "check"         => "gosaProperty::isRdn",
305                           "migrate"       => "migrate_sambaMachineAccountRDN",
306                           "group"         => "plugin",
307                           "mandatory"     => FALSE
308                           )
309                       ),
311           "plProvidedAcls"=> array(
312             "cn"                  => _("Name"),
313             "base"                => _("Base"),
314             "description"         => _("Description"))
315           ));
316   }
321 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
322 ?>