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->MACisMust = FALSE;
54 /* Set base */
55 if ($this->dn == "new"){
56 $ui= get_userinfo();
57 $this->base= dn2base($ui->dn);
58 $this->cn= "";
59 } else {
60 $this->base= preg_replace ("/^[^,]+,".normalizePreg(get_winstations_ou())."/", "", $this->dn);
61 }
63 $this->cn= preg_replace("/\\\$\$/","",$this->cn);
65 /* Save dn for later references */
66 $this->orig_dn= $this->dn;
67 $this->orig_base= $this->base;
68 $this->orig_cn= $this->cn;
69 }
72 function set_acl_base($base)
73 {
74 plugin::set_acl_base($base);
75 $this->netConfigDNS->set_acl_base($base);
76 }
78 function set_acl_category($cat)
79 {
80 plugin::set_acl_category($cat);
81 $this->netConfigDNS->set_acl_category($cat);
82 }
85 function execute()
86 {
87 /* Call parent execute */
88 plugin::execute();
90 if($this->is_account && !$this->view_logged){
91 $this->view_logged = TRUE;
92 new log("view","winworkstation/".get_class($this),$this->dn);
93 }
96 /* Do we represent a valid phone? */
97 if (!$this->is_account && $this->parent === NULL){
98 $display= "<img alt=\"\" src=\"images/small-error.png\" align=middle> <b>".
99 msgPool::noValidExtension(_("network"))."</b>";
100 return($display);
101 }
103 /* Base select dialog */
104 $once = true;
105 foreach($_POST as $name => $value){
106 if(preg_match("/^chooseBase/",$name) && $once){
107 $once = false;
108 $this->dialog = new baseSelectDialog($this->config,$this);
109 $this->dialog->setCurrentBase($this->base);
110 }
111 }
113 /* Dialog handling */
114 if(is_object($this->dialog)){
115 /* Must be called before save_object */
116 $this->dialog->save_object();
118 if($this->dialog->isClosed()){
119 $this->dialog = false;
120 }elseif($this->dialog->isSelected()){
122 /* A new base was selected, check if it is a valid one */
123 $tmp = $this->get_allowed_bases();
124 if(isset($tmp[$this->dialog->isSelected()])){
125 $this->base = $this->dialog->isSelected();
126 }
128 $this->dialog= false;
129 }else{
130 return($this->dialog->execute());
131 }
132 }
134 /* Fill templating stuff */
135 $smarty= get_smarty();
136 $smarty->assign("bases", $this->config->idepartments);
138 /* Assign attributes */
139 foreach ($this->attributes as $attr){
140 $smarty->assign("$attr", $this->$attr);
141 }
143 $smarty->assign("base_select", $this->base);
145 /* Show main page */
146 $str = $this->netConfigDNS->execute();
147 if(is_object($this->netConfigDNS->dialog)){
148 return($str);
149 }
150 $smarty->assign("netconfig", $str);
151 return($smarty->fetch (get_template_path('wingeneric.tpl', TRUE,dirname(__FILE__))));
152 }
154 function remove_from_parent()
155 {
156 $this->netConfigDNS->remove_from_parent();
157 $ldap= $this->config->get_ldap_link();
158 $ldap->rmdir($this->dn);
159 new log("remove","winworkstation/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
160 if (!$ldap->success()){
161 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_DEL, get_class()));
162 }
163 $this->handle_post_events("remove");
165 /* Delete references to object groups */
166 $ldap->cd ($this->config->current['BASE']);
167 $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".LDAP::prepare4filter($this->dn)."))", array("cn"));
168 while ($ldap->fetch()){
169 $og= new ogroup($this->config, $ldap->getDN());
170 unset($og->member[$this->dn]);
171 $og->save ();
172 }
173 }
176 /* Save data to object */
177 function save_object()
178 {
179 /* Create a base backup and reset the
180 base directly after calling plugin::save_object();
181 Base will be set seperatly a few lines below */
182 $base_tmp = $this->base;
183 plugin::save_object();
184 $this->base = $base_tmp;
186 $this->netConfigDNS->save_object();
188 /* Set new base if allowed */
189 $tmp = $this->get_allowed_bases();
190 if(isset($_POST['base'])){
191 if(isset($tmp[$_POST['base']])){
192 $this->base= $_POST['base'];
193 }
194 }
195 }
198 /* Check supplied data */
199 function check()
200 {
201 /* Call common method to give check the hook */
202 $message= plugin::check();
203 $message= array_merge($message, $this->netConfigDNS->check());
204 $this->dn= "cn=".$this->uid.",".get_ou('winstations').$this->base;
206 if(!$this->acl_is_createable()){
207 $message[]= msgPool::permCreate();
208 }
210 if ($this->orig_dn != $this->dn){
211 $ldap= $this->config->get_ldap_link();
212 $ldap->cd ($this->base);
213 $ldap->search ("(cn=".$this->cn.")", array("cn"));
214 if ($ldap->count() != 0){
215 while ($attrs= $ldap->fetch()){
216 if(preg_match("/cn=dhcp,/",$attrs['dn'])){
217 continue;
218 }
219 if ($attrs['dn'] != $this->orig_dn){
220 $message[]= msgPool::duplicated(_("Name"));
221 break;
222 }
223 }
224 }
225 }
227 /* Check if we are allowed to create or move this object
228 */
229 if($this->orig_dn == "new" && !$this->acl_is_createable($this->base)){
230 $message[] = msgPool::permCreate();
231 }elseif($this->orig_dn != "new" && $this->base != $this->orig_base && !$this->acl_is_moveable($this->base)){
232 $message[] = msgPool::permMove();
233 }
235 return ($message);
236 }
239 /* Save to LDAP */
240 function save()
241 {
242 plugin::save();
244 /* Remove all empty values */
245 if ($this->orig_dn == 'new'){
246 $attrs= array();
247 foreach ($this->attrs as $key => $val){
248 if (is_array($val) && count($val) == 0){
249 continue;
250 }
251 $attrs[$key]= $val;
252 }
253 $this->attrs= $attrs;
254 }
256 if(($this->gosaUnitTag) && (!in_array_ics("gosaAdministrativeUnitTag",$this->attrs['objectClass']))){
257 $this->attrs['objectClass'][] = "gosaAdministrativeUnitTag";
258 }
260 /* Write back to ldap */
261 $ldap= $this->config->get_ldap_link();
262 if ($this->orig_dn == 'new'){
263 $ldap->cd($this->config->current['BASE']);
264 $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
265 $ldap->cd($this->dn);
266 $ldap->add($this->attrs);
267 new log("create","winworkstation/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
268 $this->handle_post_events("add");
269 } else {
270 if ($this->orig_dn != $this->dn){
271 $this->move($this->orig_dn, $this->dn);
272 }
274 $ldap->cd($this->dn);
275 $this->cleanup();
276 $ldap->modify ($this->attrs);
277 new log("modify","winworkstation/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
278 $this->handle_post_events("modify");
279 }
281 $this->netConfigDNS->cn = preg_replace("/\\\$\$/","",$this->cn);
282 $this->netConfigDNS->save();
283 if (!$ldap->success()){
284 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, 0, get_class()));
285 }
287 /* Optionally execute a command after we're done */
288 $this->postcreate();
289 }
291 /* Return plugin informations for acl handling
292 #FIXME FAIscript seams to ununsed within this class... */
293 static function plInfo()
294 {
295 return (array(
296 "plShortName" => _("Win generic"),
297 "plDescription" => _("Windows workstation generic"),
298 "plSelfModify" => FALSE,
299 "plDepends" => array(),
300 "plPriority" => 0,
301 "plSection" => array("administration"),
302 "plCategory" => array("winworkstation" => array("description" => _("Win workstation"),
303 "objectClass" => "gotoWorkstation")),
304 "plProvidedAcls"=> array(
305 "cn" => _("Workstation name"),
306 "description" => _("Description"))
307 ));
308 }
311 }
313 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
314 ?>