Code

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