Code

a8bba757db0842fab9b8a694c1051292f0b517e4
[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);
116     $this->netConfigDNS->cn= $this->cn;
117     $smarty->assign("netconfig", $this->netConfigDNS->execute());
119     /* Display sub dialog from network settings */
120     if($this->netConfigDNS->dialog){
121       $this->dialog = TRUE;
122       return($this->netConfigDNS->execute());
123     }else{ 
124       $this->dialog = FALSE;
125     }
127     /* Show main page */
128     return($smarty->fetch (get_template_path('wingeneric.tpl', TRUE)));
129   }
131   function remove_from_parent()
132   {
133     $this->netConfigDNS->acl = $this->acl;
134     $this->netConfigDNS->remove_from_parent();
135     $ldap= $this->config->get_ldap_link();
136     $ldap->rmdir($this->dn);
137     show_ldap_error($ldap->get_error(), _("Removing Samba workstation failed"));
138     $this->handle_post_events("remove");
140     /* Delete references to object groups */
141     $ldap->cd ($this->config->current['BASE']);
142     $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".@LDAP::prepare4filter($this->dn)."))", array("cn"));
143     while ($ldap->fetch()){
144       $og= new ogroup($this->config, $ldap->getDN());
145       unset($og->member[$this->dn]);
146       $og->save ();
147     }
148   }
151   /* Save data to object */
152   function save_object()
153   {
154     plugin::save_object();
155     $this->netConfigDNS->save_object();
156     /* Save base, since this is no LDAP attribute */
157     if (isset($_POST['base']) && chkacl($this->acl, "create") == ""){
158       $this->base= $_POST['base'];
159     }
160   }
163   /* Check supplied data */
164   function check()
165   {
166     /* Call common method to give check the hook */
167     $message= plugin::check();
168     $message= array_merge($message, $this->netConfigDNS->check());
169     $this->dn= "cn=".$this->cn.",ou=netdevices,ou=systems,".$this->base;
171     $ui= get_userinfo();
172     $acl= get_permissions ($this->dn, $ui->subtreeACL);
173     $acl= get_module_permission($acl, "component", $this->dn);
174     if (chkacl($acl, "create") != ""){
175       $message[]= _("You have no permissions to create a component on this 'Base'.");
176     }
178     if ($this->orig_dn != $this->dn){
179       $ldap= $this->config->get_ldap_link();
180       $ldap->cd ($this->base);
181       $ldap->search ("(cn=".$this->cn.")", array("cn"));
182       if ($ldap->count() != 0){
183         while ($attrs= $ldap->fetch()){
184           if(preg_match("/cn=dhcp,/",$attrs['dn'])){
185             continue;
186           }
187           if ($attrs['dn'] != $this->orig_dn){
188             $message[]= sprintf (_("There is already an entry '%s' in the base choosen by you"), $this->cn);
189             break;
190           }
191         }
192       }
193     }
195     return ($message);
196   }
199   /* Save to LDAP */
200   function save()
201   {
202     $this->netConfigDNS->acl = $this->acl;
203     plugin::save();
205     /* Remove all empty values */
206     if ($this->orig_dn == 'new'){
207       $attrs= array();
208       foreach ($this->attrs as $key => $val){
209         if (is_array($val) && count($val) == 0){
210           continue;
211         }
212         $attrs[$key]= $val;
213       }
214       $this->attrs= $attrs;
215     }
217     /* Write back to ldap */
218     $ldap= $this->config->get_ldap_link();
219     if ($this->orig_dn == 'new'){
220       $ldap->cd($this->config->current['BASE']);
221       $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
222       $ldap->cd($this->dn);
223       $ldap->add($this->attrs);
224       $this->handle_post_events("add");
225     } else {
226       if ($this->orig_dn != $this->dn){
227         $this->move($this->orig_dn, $this->dn);
228       }
230       $ldap->cd($this->dn);
231       $this->cleanup();
232       $ldap->modify ($this->attrs); 
234       $this->handle_post_events("modify");
235     }
237     $this->netConfigDNS->cn = preg_replace("/\\\$\$/","",$this->cn);
238     $this->netConfigDNS->save($this->dn);
239     show_ldap_error($ldap->get_error(), _("Saving Samba workstation failed"));
241     /* Optionally execute a command after we're done */
242     $this->postcreate();
243   }
247 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
248 ?>