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;
37 /* attribute list for save action */
38 var $ignore_account= TRUE;
39 var $attributes = array("cn", "description","shadowLastChange",
40 "uidNumber","gidNumber","loginShell","gecos","shadowMin","shadowWarning",
41 "shadowInactive","uid","cn","sn","givenName","homeDirectory","sambaSID",
42 "sambaPrimaryGroupSID","displayName", "sambaPwdMustChange",
43 "sambaNTPassword","sambaPwdLastSet","sambaAcctFlags");
44 var $objectclasses= array("posixAccount","person","organizationalPerson","inetOrgPerson","gosaAccount","shadowAccount","sambaSamAccount","top");
46 var $view_logged = FALSE;
48 function wingeneric (&$config, $dn= NULL, $parent= NULL)
49 {
50 plugin::plugin ($config, $dn, $parent);
51 $this->netConfigDNS = new termDNS($this->config,$this,$this->objectclasses);
52 $this->netConfigDNS->objectclasses=array("ipHost");
53 $this->netConfigDNS->MACisMust = FALSE;
55 /* Set base */
56 if ($this->dn == "new"){
57 $ui= get_userinfo();
58 $this->base= dn2base($ui->dn);
59 $this->cn= "";
60 } else {
61 $this->base= preg_replace ("/^[^,]+,".normalizePreg(get_winstations_ou())."/", "", $this->dn);
62 }
64 $this->cn= preg_replace("/\\\$\$/","",$this->cn);
66 /* Save dn for later references */
67 $this->orig_dn= $this->dn;
68 $this->orig_base= $this->base;
69 $this->orig_cn= $this->cn;
70 }
73 function set_acl_base($base)
74 {
75 plugin::set_acl_base($base);
76 $this->netConfigDNS->set_acl_base($base);
77 }
79 function set_acl_category($cat)
80 {
81 plugin::set_acl_category($cat);
82 $this->netConfigDNS->set_acl_category($cat);
83 }
86 function execute()
87 {
88 /* Call parent execute */
89 plugin::execute();
91 if($this->is_account && !$this->view_logged){
92 $this->view_logged = TRUE;
93 new log("view","winworkstation/".get_class($this),$this->dn);
94 }
97 /* Do we represent a valid phone? */
98 if (!$this->is_account && $this->parent === NULL){
99 $display= "<img alt=\"\" src=\"images/small-error.png\" align=middle> <b>".
100 msgPool::noValidExtension(_("network"))."</b>";
101 return($display);
102 }
104 /* Base select dialog */
105 $once = true;
106 foreach($_POST as $name => $value){
107 if(preg_match("/^chooseBase/",$name) && $once){
108 $once = false;
109 $this->dialog = new baseSelectDialog($this->config,$this);
110 $this->dialog->setCurrentBase($this->base);
111 }
112 }
114 /* Dialog handling */
115 if(is_object($this->dialog)){
116 /* Must be called before save_object */
117 $this->dialog->save_object();
119 if($this->dialog->isClosed()){
120 $this->dialog = false;
121 }elseif($this->dialog->isSelected()){
123 /* A new base was selected, check if it is a valid one */
124 $tmp = $this->get_allowed_bases();
125 if(isset($tmp[$this->dialog->isSelected()])){
126 $this->base = $this->dialog->isSelected();
127 }
129 $this->dialog= false;
130 }else{
131 return($this->dialog->execute());
132 }
133 }
135 /* Fill templating stuff */
136 $smarty= get_smarty();
137 $smarty->assign("bases", $this->config->idepartments);
139 /* Assign attributes */
140 foreach ($this->attributes as $attr){
141 $smarty->assign("$attr", $this->$attr);
142 }
144 $smarty->assign("base_select", $this->base);
146 /* Show main page */
147 $str = $this->netConfigDNS->execute();
148 if(is_object($this->netConfigDNS->dialog)){
149 return($str);
150 }
151 $smarty->assign("netconfig", $str);
152 return($smarty->fetch (get_template_path('wingeneric.tpl', TRUE,dirname(__FILE__))));
153 }
155 function remove_from_parent()
156 {
157 $this->netConfigDNS->remove_from_parent();
158 $ldap= $this->config->get_ldap_link();
159 $ldap->rmdir($this->dn);
160 new log("remove","winworkstation/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
161 if (!$ldap->success()){
162 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_DEL, get_class()));
163 }
164 $this->handle_post_events("remove");
166 /* Delete references to object groups */
167 $ldap->cd ($this->config->current['BASE']);
168 $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".LDAP::prepare4filter($this->dn)."))", array("cn"));
169 while ($ldap->fetch()){
170 $og= new ogroup($this->config, $ldap->getDN());
171 unset($og->member[$this->dn]);
172 $og->save ();
173 }
174 }
177 /* Save data to object */
178 function save_object()
179 {
180 /* Create a base backup and reset the
181 base directly after calling plugin::save_object();
182 Base will be set seperatly a few lines below */
183 $base_tmp = $this->base;
184 plugin::save_object();
185 $this->base = $base_tmp;
187 $this->netConfigDNS->save_object();
189 /* Set new base if allowed */
190 $tmp = $this->get_allowed_bases();
191 if(isset($_POST['base'])){
192 if(isset($tmp[$_POST['base']])){
193 $this->base= $_POST['base'];
194 }
195 }
196 }
199 /* Check supplied data */
200 function check()
201 {
202 /* Call common method to give check the hook */
203 $message= plugin::check();
204 $message= array_merge($message, $this->netConfigDNS->check());
205 $this->dn= "cn=".$this->uid.",".get_ou('sambaMachineAccountRDN').$this->base;
207 if(!$this->acl_is_createable()){
208 $message[]= msgPool::permCreate();
209 }
211 if ($this->orig_dn != $this->dn){
212 $ldap= $this->config->get_ldap_link();
213 $ldap->cd ($this->base);
214 $ldap->search ("(cn=".$this->cn.")", array("cn"));
215 if ($ldap->count() != 0){
216 while ($attrs= $ldap->fetch()){
217 if(preg_match("/cn=dhcp,/",$attrs['dn'])){
218 continue;
219 }
220 if ($attrs['dn'] != $this->orig_dn){
221 $message[]= msgPool::duplicated(_("Name"));
222 break;
223 }
224 }
225 }
226 }
228 /* Check if we are allowed to create or move this object
229 */
230 if($this->orig_dn == "new" && !$this->acl_is_createable($this->base)){
231 $message[] = msgPool::permCreate();
232 }elseif($this->orig_dn != "new" && $this->base != $this->orig_base && !$this->acl_is_moveable($this->base)){
233 $message[] = msgPool::permMove();
234 }
236 return ($message);
237 }
240 /* Save to LDAP */
241 function save()
242 {
243 plugin::save();
245 /* Remove all empty values */
246 if ($this->orig_dn == 'new'){
247 $attrs= array();
248 foreach ($this->attrs as $key => $val){
249 if (is_array($val) && count($val) == 0){
250 continue;
251 }
252 $attrs[$key]= $val;
253 }
254 $this->attrs= $attrs;
255 }
257 if(($this->gosaUnitTag) && (!in_array_ics("gosaAdministrativeUnitTag",$this->attrs['objectClass']))){
258 $this->attrs['objectClass'][] = "gosaAdministrativeUnitTag";
259 }
261 /* Write back to ldap */
262 $ldap= $this->config->get_ldap_link();
263 if ($this->orig_dn == 'new'){
264 $ldap->cd($this->config->current['BASE']);
265 $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
266 $ldap->cd($this->dn);
267 $ldap->add($this->attrs);
268 new log("create","winworkstation/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
269 $this->handle_post_events("add");
270 } else {
271 if ($this->orig_dn != $this->dn){
272 $this->move($this->orig_dn, $this->dn);
273 }
275 $ldap->cd($this->dn);
276 $this->cleanup();
277 $ldap->modify ($this->attrs);
278 new log("modify","winworkstation/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
279 $this->handle_post_events("modify");
280 }
282 $this->netConfigDNS->cn = preg_replace("/\\\$\$/","",$this->cn);
283 $this->netConfigDNS->save();
284 if (!$ldap->success()){
285 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, 0, get_class()));
286 }
288 /* Optionally execute a command after we're done */
289 $this->postcreate();
290 }
292 /* Return plugin informations for acl handling
293 #FIXME FAIscript seams to ununsed within this class... */
294 static function plInfo()
295 {
296 return (array(
297 "plShortName" => _("Win generic"),
298 "plDescription" => _("Windows workstation generic"),
299 "plSelfModify" => FALSE,
300 "plDepends" => array(),
301 "plPriority" => 0,
302 "plSection" => array("administration"),
303 "plCategory" => array("winworkstation" => array("description" => _("Win workstation"),
304 "objectClass" => "gotoWorkstation")),
305 "plProvidedAcls"=> array(
306 "cn" => _("Workstation name"),
307 "description" => _("Description"))
308 ));
309 }
312 }
314 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
315 ?>