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