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