Code

Added RDN support for users
[gosa.git] / plugins / admin / systems / 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;
33   /* attribute list for save action */
34   var $ignore_account= TRUE;
35   var $attributes   = array("cn", "description","shadowLastChange",
36                             "uidNumber","gidNumber","loginShell","gecos","shadowMin","shadowWarning",
37                             "shadowInactive","uid","cn","sn","givenName","homeDirectory","sambaSID",
38                             "sambaPrimaryGroupSID","displayName", "sambaPwdMustChange",
39                             "sambaNTPassword","sambaPwdLastSet","sambaAcctFlags");
40   var $objectclasses= array("posixAccount","person","organizationalPerson","inetOrgPerson","gosaAccount","shadowAccount","sambaSamAccount","top");
43   function wingeneric ($config, $dn= NULL, $parent= NULL)
44   {
45     plugin::plugin ($config, $dn, $parent);
46     $this->netConfigDNS = new termDNS($this->config,$this->dn,$this->objectclasses);
47     $this->netConfigDNS->acl = $this->acl;
49     /* Set base */
50     if ($this->dn == "new"){
51       $ui= get_userinfo();
52       $this->base= dn2base($ui->dn);
53       $this->cn= "";
54     } else {
55       $this->base= preg_replace ("/^[^,]+,".normalizePreg(get_winstations_ou())."/", "", $this->dn);
56     }
58     /* Save dn for later references */
59     $this->orig_dn= $this->dn;
61     $this->cn= preg_replace("/\\\$\$/","",$this->cn);
62   }
64   function execute()
65   {
66     $this->netConfigDNS->acl = $this->acl;
68     /* Call parent execute */
69     plugin::execute();
71     /* Do we represent a valid phone? */
72     if (!$this->is_account && $this->parent == NULL){
73       $display= "<img alt=\"\" src=\"images/stop.png\" align=middle>&nbsp;<b>".
74         _("This 'dn' has no network features.")."</b>";
75       return($display);
76     }
78     /* Base select dialog */
79     $once = true;
80     foreach($_POST as $name => $value){
81       if(preg_match("/^chooseBase/",$name) && $once){
82         $once = false;
83         $this->dialog = new baseSelectDialog($this->config);
84         $this->dialog->setCurrentBase($this->base);
85       }
86     }
88     /* Dialog handling */
89     if(is_object($this->dialog)){
90       /* Must be called before save_object */
91       $this->dialog->save_object();
93       if($this->dialog->isClosed()){
94         $this->dialog = false;
95       }elseif($this->dialog->isSelected()){
96         $this->base = $this->dialog->isSelected();
97         $this->dialog= false;
98       }else{
99         return($this->dialog->execute());
100       }
101     }
103     /* Fill templating stuff */
104     $smarty= get_smarty();
106     // Undefined index in wingeneric.tpl ... 
107     $smarty->assign("bases", $this->config->idepartments);
109     /* Assign attributes */
110     foreach ($this->attributes as $attr){
111       $smarty->assign($attr."ACL", chkacl($this->acl, $attr));
112       $smarty->assign("$attr", $this->$attr);
113     }
114     
115     $smarty->assign("base_select", $this->base);
117     /* Show main page */
118     $this->netConfigDNS->cn= $this->cn;
119     $smarty->assign("netconfig", $this->netConfigDNS->execute());
120     return($smarty->fetch (get_template_path('wingeneric.tpl', TRUE)));
121   }
123   function remove_from_parent()
124   {
125     $this->netConfigDNS->acl = $this->acl;
126     $this->netConfigDNS->remove_from_parent();
127     $ldap= $this->config->get_ldap_link();
128     $ldap->rmdir($this->dn);
129     show_ldap_error($ldap->get_error(), _("Removing Samba workstation failed"));
130     $this->handle_post_events("remove");
132     /* Delete references to object groups */
133     $ldap->cd ($this->config->current['BASE']);
134     $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".$this->dn."))", array("cn"));
135     while ($ldap->fetch()){
136       $og= new ogroup($this->config, $ldap->getDN());
137       unset($og->member[$this->dn]);
138       $og->save ();
139     }
140   }
143   /* Save data to object */
144   function save_object()
145   {
146     plugin::save_object();
147     $this->netConfigDNS->save_object();
148     /* Save base, since this is no LDAP attribute */
149     if (isset($_POST['base']) && chkacl($this->acl, "create") == ""){
150       $this->base= $_POST['base'];
151     }
152   }
155   /* Check supplied data */
156   function check()
157   {
158     /* Call common method to give check the hook */
159     $message= plugin::check();
160     $message= array_merge($message, $this->netConfigDNS->check());
161     $this->dn= "cn=".$this->cn.",ou=netdevices,ou=systems,".$this->base;
163     $ui= get_userinfo();
164     $acl= get_permissions ($this->dn, $ui->subtreeACL);
165     $acl= get_module_permission($acl, "component", $this->dn);
166     if (chkacl($acl, "create") != ""){
167       $message[]= _("You have no permissions to create a component on this 'Base'.");
168     }
170     if ($this->orig_dn != $this->dn){
171       $ldap= $this->config->get_ldap_link();
172       $ldap->cd ($this->base);
173       $ldap->search ("(cn=".$this->cn.")", array("cn"));
174       if ($ldap->count() != 0){
175         while ($attrs= $ldap->fetch()){
176           if ($attrs['dn'] != $this->orig_dn){
177             $message[]= sprintf (_("There is already an entry '%s' in the base choosen by you"), $this->cn);
178             break;
179           }
180         }
181       }
182     }
184     return ($message);
185   }
188   /* Save to LDAP */
189   function save()
190   {
191     $this->netConfigDNS->acl = $this->acl;
192     plugin::save();
194     /* Remove all empty values */
195     if ($this->orig_dn == 'new'){
196       $attrs= array();
197       foreach ($this->attrs as $key => $val){
198         if (is_array($val) && count($val) == 0){
199           continue;
200         }
201         $attrs[$key]= $val;
202       }
203       $this->attrs= $attrs;
204     }
206     /* Write back to ldap */
207     $ldap= $this->config->get_ldap_link();
208     if ($this->orig_dn == 'new'){
209       $ldap->cd($this->config->current['BASE']);
210       $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
211       $ldap->cd($this->dn);
212       $ldap->add($this->attrs);
213       $this->handle_post_events("add");
214     } else {
215       if ($this->orig_dn != $this->dn){
216         $this->move($this->orig_dn, $this->dn);
217       }
219       $ldap->cd($this->dn);
220       $this->cleanup();
221       $ldap->modify ($this->attrs); 
223       $this->handle_post_events("modify");
224     }
226     $this->netConfigDNS->cn = preg_replace("/\\\$\$/","",$this->cn);
227     $this->netConfigDNS->save($this->dn);
228     show_ldap_error($ldap->get_error(), _("Saving Samba workstation failed"));
230     /* Optionally execute a command after we're done */
231     $this->postcreate();
232   }
236 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
237 ?>