Code

Removed CLI
[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         _("This 'dn' has no network features.")."</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     show_ldap_error($ldap->get_error(), sprintf(_("Removing of system wingeneric/generic with dn '%s' failed."),$this->dn));
153     $this->handle_post_events("remove");
155     /* Delete references to object groups */
156     $ldap->cd ($this->config->current['BASE']);
157     $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".LDAP::prepare4filter($this->dn)."))", array("cn"));
158     while ($ldap->fetch()){
159       $og= new ogroup($this->config, $ldap->getDN());
160       unset($og->member[$this->dn]);
161       $og->save ();
162     }
163   }
166   /* Save data to object */
167   function save_object()
168   {
169     /* Create a base backup and reset the
170        base directly after calling plugin::save_object();
171        Base will be set seperatly a few lines below */
172     $base_tmp = $this->base;
173     plugin::save_object();
174     $this->base = $base_tmp;
176     $this->netConfigDNS->save_object();
178     /* Set new base if allowed */
179     $tmp = $this->get_allowed_bases();
180     if(isset($_POST['base'])){
181       if(isset($tmp[$_POST['base']])){
182         $this->base= $_POST['base'];
183       }
184     }
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->cn.",".get_ou('componentou').$this->base;
195     
196     /* Set new acl base */
197     if($this->dn == "new") {
198       $this->set_acl_base($this->base);
199     }
201     if(!$this->acl_is_createable() && $this->dn == "new"){
202       $message[]= _("You have no permissions to create a component on this 'Base'.");
203     }
205     if ($this->orig_dn != $this->dn){
206       $ldap= $this->config->get_ldap_link();
207       $ldap->cd ($this->base);
208       $ldap->search ("(cn=".$this->cn.")", array("cn"));
209       if ($ldap->count() != 0){
210         while ($attrs= $ldap->fetch()){
211           if(preg_match("/cn=dhcp,/",$attrs['dn'])){
212             continue;
213           }
214           if ($attrs['dn'] != $this->orig_dn){
215             $message[]= sprintf (_("There is already an entry '%s' in the base choosen by you"), $this->cn);
216             break;
217           }
218         }
219       }
220     }
222     return ($message);
223   }
226   /* Save to LDAP */
227   function save()
228   {
229     plugin::save();
231     /* Remove all empty values */
232     if ($this->orig_dn == 'new'){
233       $attrs= array();
234       foreach ($this->attrs as $key => $val){
235         if (is_array($val) && count($val) == 0){
236           continue;
237         }
238         $attrs[$key]= $val;
239       }
240       $this->attrs= $attrs;
241     }
243     if(($this->gosaUnitTag) && (!in_array_ics("gosaAdministrativeUnitTag",$this->attrs['objectClass']))){
244       $this->attrs['objectClass'][] = "gosaAdministrativeUnitTag";
245     }
247     /* Write back to ldap */
248     $ldap= $this->config->get_ldap_link();
249     if ($this->orig_dn == 'new'){
250       $ldap->cd($this->config->current['BASE']);
251       $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
252       $ldap->cd($this->dn);
253       $ldap->add($this->attrs);
254       new log("create","winworkstation/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
255       $this->handle_post_events("add");
256     } else {
257       if ($this->orig_dn != $this->dn){
258         $this->move($this->orig_dn, $this->dn);
259       }
261       $ldap->cd($this->dn);
262       $this->cleanup();
263       $ldap->modify ($this->attrs); 
264       new log("modify","winworkstation/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
265       $this->handle_post_events("modify");
266     }
268     $this->netConfigDNS->cn =  preg_replace("/\\\$\$/","",$this->cn);
269     $this->netConfigDNS->save();
270     show_ldap_error($ldap->get_error(), sprintf(_("Saving of system wingeneric/generic with dn '%s' failed."),$this->dn));
272     /* Optionally execute a command after we're done */
273     $this->postcreate();
274   }
276   /* Return plugin informations for acl handling
277   #FIXME FAIscript seams to ununsed within this class... */
278   static function plInfo()
279   {
280     return (array(
281           "plShortName"   => _("Win generic"),
282           "plDescription" => _("Windows workstation generic"),
283           "plSelfModify"  => FALSE,
284           "plDepends"     => array(),
285           "plPriority"    => 0,
286           "plSection"     => array("administration"),
287           "plCategory"    => array("winworkstation" => array("description"  => _("Win workstation"),
288                                                           "objectClass"  => "gotoWorkstation")),
289           "plProvidedAcls"=> array(
290             "cn"                  => _("Workstation name"),
291             "description"         => _("Description"))
292           ));
293   }
298 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
299 ?>