Code

msgPool
[gosa.git] / gosa-plugins / samba / admin / systems / samba / 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");
42   var $view_logged = FALSE;
44   function wingeneric (&$config, $dn= NULL, $parent= NULL)
45   {
46     plugin::plugin ($config, $dn, $parent);
47     $this->netConfigDNS = new termDNS($this->config,$this,$this->objectclasses);
48     /* Set base */
49     if ($this->dn == "new"){
50       $ui= get_userinfo();
51       $this->base= dn2base($ui->dn);
52       $this->cn= "";
53     } else {
54       $this->base= preg_replace ("/^[^,]+,".normalizePreg(get_winstations_ou())."/", "", $this->dn);
55     }
57     /* Save dn for later references */
58     $this->orig_dn= $this->dn;
60     $this->cn= preg_replace("/\\\$\$/","",$this->cn);
61   }
64   function set_acl_base($base)
65   {
66     plugin::set_acl_base($base);
67     $this->netConfigDNS->set_acl_base($base);
68   }
70   function set_acl_category($cat)
71   {
72     plugin::set_acl_category($cat);
73     $this->netConfigDNS->set_acl_category($cat);
74   }
77   function execute()
78   {
79     /* Call parent execute */
80     plugin::execute();
82     if($this->is_account && !$this->view_logged){
83       $this->view_logged = TRUE;
84       new log("view","winworkstation/".get_class($this),$this->dn);
85     }
88     /* Do we represent a valid phone? */
89     if (!$this->is_account && $this->parent === NULL){
90       $display= "<img alt=\"\" src=\"images/stop.png\" align=middle>&nbsp;<b>".
91         msgPool::noValidExtension(_("network"))."</b>";
92       return($display);
93     }
95     /* Base select dialog */
96     $once = true;
97     foreach($_POST as $name => $value){
98       if(preg_match("/^chooseBase/",$name) && $once){
99         $once = false;
100         $this->dialog = new baseSelectDialog($this->config,$this);
101         $this->dialog->setCurrentBase($this->base);
102       }
103     }
105     /* Dialog handling */
106     if(is_object($this->dialog)){
107       /* Must be called before save_object */
108       $this->dialog->save_object();
110       if($this->dialog->isClosed()){
111         $this->dialog = false;
112       }elseif($this->dialog->isSelected()){
114         /* A new base was selected, check if it is a valid one */
115         $tmp = $this->get_allowed_bases();
116         if(isset($tmp[$this->dialog->isSelected()])){
117           $this->base = $this->dialog->isSelected();
118         }
120         $this->dialog= false;
121       }else{
122         return($this->dialog->execute());
123       }
124     }
126     /* Fill templating stuff */
127     $smarty= get_smarty();
128     $smarty->assign("bases", $this->config->idepartments);
130     /* Assign attributes */
131     foreach ($this->attributes as $attr){
132       $smarty->assign("$attr", $this->$attr);
133     }
134     
135     $smarty->assign("base_select", $this->base);
137     /* Show main page */
138     $str = $this->netConfigDNS->execute();
139     if(is_object($this->netConfigDNS->dialog)){
140       return($str);
141     }
142     $smarty->assign("netconfig", $str);
143     return($smarty->fetch (get_template_path('wingeneric.tpl', TRUE,dirname(__FILE__))));
144   }
146   function remove_from_parent()
147   {
148     $this->netConfigDNS->remove_from_parent();
149     $ldap= $this->config->get_ldap_link();
150     $ldap->rmdir($this->dn);
151     new log("remove","winworkstation/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
152     if (!$ldap->success()){
153       msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_DEL, get_class()));
154     }
155     $this->handle_post_events("remove");
157     /* Delete references to object groups */
158     $ldap->cd ($this->config->current['BASE']);
159     $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".LDAP::prepare4filter($this->dn)."))", array("cn"));
160     while ($ldap->fetch()){
161       $og= new ogroup($this->config, $ldap->getDN());
162       unset($og->member[$this->dn]);
163       $og->save ();
164     }
165   }
168   /* Save data to object */
169   function save_object()
170   {
171     /* Create a base backup and reset the
172        base directly after calling plugin::save_object();
173        Base will be set seperatly a few lines below */
174     $base_tmp = $this->base;
175     plugin::save_object();
176     $this->base = $base_tmp;
178     $this->netConfigDNS->save_object();
180     /* Set new base if allowed */
181     $tmp = $this->get_allowed_bases();
182     if(isset($_POST['base'])){
183       if(isset($tmp[$_POST['base']])){
184         $this->base= $_POST['base'];
185       }
186     }
187   }
190   /* Check supplied data */
191   function check()
192   {
193     /* Call common method to give check the hook */
194     $message= plugin::check();
195     $message= array_merge($message, $this->netConfigDNS->check());
196     $this->dn= "cn=".$this->cn.",".get_ou('componentou').$this->base;
197     
198     /* Set new acl base */
199     if($this->dn == "new") {
200       $this->set_acl_base($this->base);
201     }
203     if(!$this->acl_is_createable() && $this->dn == "new"){
204       $message[]= msgPool::permCreate();
205     }
207     if ($this->orig_dn != $this->dn){
208       $ldap= $this->config->get_ldap_link();
209       $ldap->cd ($this->base);
210       $ldap->search ("(cn=".$this->cn.")", array("cn"));
211       if ($ldap->count() != 0){
212         while ($attrs= $ldap->fetch()){
213           if(preg_match("/cn=dhcp,/",$attrs['dn'])){
214             continue;
215           }
216           if ($attrs['dn'] != $this->orig_dn){
217             $message[]= msgPool::duplicated(_("Name"));
218             break;
219           }
220         }
221       }
222     }
224     return ($message);
225   }
228   /* Save to LDAP */
229   function save()
230   {
231     plugin::save();
233     /* Remove all empty values */
234     if ($this->orig_dn == 'new'){
235       $attrs= array();
236       foreach ($this->attrs as $key => $val){
237         if (is_array($val) && count($val) == 0){
238           continue;
239         }
240         $attrs[$key]= $val;
241       }
242       $this->attrs= $attrs;
243     }
245     if(($this->gosaUnitTag) && (!in_array_ics("gosaAdministrativeUnitTag",$this->attrs['objectClass']))){
246       $this->attrs['objectClass'][] = "gosaAdministrativeUnitTag";
247     }
249     /* Write back to ldap */
250     $ldap= $this->config->get_ldap_link();
251     if ($this->orig_dn == 'new'){
252       $ldap->cd($this->config->current['BASE']);
253       $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
254       $ldap->cd($this->dn);
255       $ldap->add($this->attrs);
256       new log("create","winworkstation/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
257       $this->handle_post_events("add");
258     } else {
259       if ($this->orig_dn != $this->dn){
260         $this->move($this->orig_dn, $this->dn);
261       }
263       $ldap->cd($this->dn);
264       $this->cleanup();
265       $ldap->modify ($this->attrs); 
266       new log("modify","winworkstation/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
267       $this->handle_post_events("modify");
268     }
270     $this->netConfigDNS->cn =  preg_replace("/\\\$\$/","",$this->cn);
271     $this->netConfigDNS->save();
272     if (!$ldap->success()){
273       msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, 0, get_class()));
274     }
276     /* Optionally execute a command after we're done */
277     $this->postcreate();
278   }
280   /* Return plugin informations for acl handling
281   #FIXME FAIscript seams to ununsed within this class... */
282   static function plInfo()
283   {
284     return (array(
285           "plShortName"   => _("Win generic"),
286           "plDescription" => _("Windows workstation generic"),
287           "plSelfModify"  => FALSE,
288           "plDepends"     => array(),
289           "plPriority"    => 0,
290           "plSection"     => array("administration"),
291           "plCategory"    => array("winworkstation" => array("description"  => _("Win workstation"),
292                                                           "objectClass"  => "gotoWorkstation")),
293           "plProvidedAcls"=> array(
294             "cn"                  => _("Workstation name"),
295             "description"         => _("Description"))
296           ));
297   }
302 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
303 ?>