1 <?php
3 class wingeneric extends plugin
4 {
5 /* CLI vars */
6 var $cli_summary = "Manage component base objects";
7 var $cli_description = "Some longer text\nfor help";
8 var $cli_parameters = array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
10 /* Generic terminal attributes */
11 var $interfaces= array();
13 /* Needed values and lists */
14 var $base= "";
15 var $cn= "";
16 var $description= "";
17 var $orig_dn= "";
18 var $shadowLastChange="";
19 var $uidNumber="";
20 var $gidNumber="";
21 var $loginShell="";
22 var $gecos="";
23 var $shadowMin="";
24 var $shadowWarning="";
25 var $shadowInactive="";
26 var $uid="";
27 var $sn="";
28 var $givenName="";
29 var $homeDirectory="";
30 var $sambaSID="";
31 var $sambaPrimaryGroupSID="";
32 var $displayName="";
33 var $sambaPwdMustChange="";
34 var $sambaNTPassword="";
35 var $sambaPwdLastSet="";
36 var $sambaAcctFlags="";
37 var $netConfigDNS;
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);
53 /* Set base */
54 if ($this->dn == "new"){
55 $ui= get_userinfo();
56 $this->base= dn2base($ui->dn);
57 $this->cn= "";
58 } else {
59 $this->base= preg_replace ("/^[^,]+,".normalizePreg(get_winstations_ou())."/", "", $this->dn);
60 }
62 /* Save dn for later references */
63 $this->orig_dn= $this->dn;
65 $this->cn= preg_replace("/\\\$\$/","",$this->cn);
66 }
69 function set_acl_base($base)
70 {
71 plugin::set_acl_base($base);
72 $this->netConfigDNS->set_acl_base($base);
73 }
75 function set_acl_category($cat)
76 {
77 plugin::set_acl_category($cat);
78 $this->netConfigDNS->set_acl_category($cat);
79 }
82 function execute()
83 {
84 /* Call parent execute */
85 plugin::execute();
87 if($this->is_account && !$this->view_logged){
88 $this->view_logged = TRUE;
89 new log("view","winworkstation/".get_class($this),$this->dn);
90 }
93 /* Do we represent a valid phone? */
94 if (!$this->is_account && $this->parent === NULL){
95 $display= "<img alt=\"\" src=\"images/stop.png\" align=middle> <b>".
96 _("This 'dn' has no network features.")."</b>";
97 return($display);
98 }
100 /* Base select dialog */
101 $once = true;
102 foreach($_POST as $name => $value){
103 if(preg_match("/^chooseBase/",$name) && $once){
104 $once = false;
105 $this->dialog = new baseSelectDialog($this->config,$this);
106 $this->dialog->setCurrentBase($this->base);
107 }
108 }
110 /* Dialog handling */
111 if(is_object($this->dialog)){
112 /* Must be called before save_object */
113 $this->dialog->save_object();
115 if($this->dialog->isClosed()){
116 $this->dialog = false;
117 }elseif($this->dialog->isSelected()){
119 /* A new base was selected, check if it is a valid one */
120 $tmp = $this->get_allowed_bases();
121 if(isset($tmp[$this->dialog->isSelected()])){
122 $this->base = $this->dialog->isSelected();
123 }
125 $this->dialog= false;
126 }else{
127 return($this->dialog->execute());
128 }
129 }
131 /* Fill templating stuff */
132 $smarty= get_smarty();
134 // Undefined index in wingeneric.tpl ...
135 $smarty->assign("bases", $this->config->idepartments);
137 /* Assign attributes */
138 foreach ($this->attributes as $attr){
139 $smarty->assign("$attr", $this->$attr);
140 }
142 $smarty->assign("base_select", $this->base);
144 /* Show main page */
145 $smarty->assign("netconfig", $this->netConfigDNS->execute());
146 return($smarty->fetch (get_template_path('wingeneric.tpl', TRUE)));
147 }
149 function remove_from_parent()
150 {
151 $this->netConfigDNS->remove_from_parent();
152 $ldap= $this->config->get_ldap_link();
153 $ldap->rmdir($this->dn);
154 new log("remove","winworkstation/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
155 show_ldap_error($ldap->get_error(), sprintf(_("Removing of system wingeneric/generic with dn '%s' failed."),$this->dn));
156 $this->handle_post_events("remove");
158 /* Delete references to object groups */
159 $ldap->cd ($this->config->current['BASE']);
160 $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".$this->dn."))", array("cn"));
161 while ($ldap->fetch()){
162 $og= new ogroup($this->config, $ldap->getDN());
163 unset($og->member[$this->dn]);
164 $og->save ();
165 }
166 }
169 /* Save data to object */
170 function save_object()
171 {
172 /* Create a base backup and reset the
173 base directly after calling plugin::save_object();
174 Base will be set seperatly a few lines below */
175 $base_tmp = $this->base;
176 plugin::save_object();
177 $this->base = $base_tmp;
179 $this->netConfigDNS->save_object();
181 /* Set new base if allowed */
182 $tmp = $this->get_allowed_bases();
183 if(isset($_POST['base'])){
184 if(isset($tmp[$_POST['base']])){
185 $this->base= $_POST['base'];
186 }
187 }
188 }
191 /* Check supplied data */
192 function check()
193 {
194 /* Call common method to give check the hook */
195 $message= plugin::check();
196 $message= array_merge($message, $this->netConfigDNS->check());
197 $this->dn= "cn=".$this->cn.",ou=netdevices,ou=systems,".$this->base;
199 /* Set new acl base */
200 if($this->dn == "new") {
201 $this->set_acl_base($this->base);
202 }
204 if(!$this->acl_is_createable() && $this->dn == "new"){
205 $message[]= _("You have no permissions to create a component on this 'Base'.");
206 }
208 if ($this->orig_dn != $this->dn){
209 $ldap= $this->config->get_ldap_link();
210 $ldap->cd ($this->base);
211 $ldap->search ("(cn=".$this->cn.")", array("cn"));
212 if ($ldap->count() != 0){
213 while ($attrs= $ldap->fetch()){
214 if(preg_match("/cn=dhcp,/",$attrs['dn'])){
215 continue;
216 }
217 if ($attrs['dn'] != $this->orig_dn){
218 $message[]= sprintf (_("There is already an entry '%s' in the base choosen by you"), $this->cn);
219 break;
220 }
221 }
222 }
223 }
225 return ($message);
226 }
229 /* Save to LDAP */
230 function save()
231 {
232 plugin::save();
234 /* Remove all empty values */
235 if ($this->orig_dn == 'new'){
236 $attrs= array();
237 foreach ($this->attrs as $key => $val){
238 if (is_array($val) && count($val) == 0){
239 continue;
240 }
241 $attrs[$key]= $val;
242 }
243 $this->attrs= $attrs;
244 }
246 if(($this->gosaUnitTag) && (!in_array_ics("gosaAdministrativeUnitTag",$this->attrs['objectClass']))){
247 $this->attrs['objectClass'][] = "gosaAdministrativeUnitTag";
248 }
250 /* Write back to ldap */
251 $ldap= $this->config->get_ldap_link();
252 if ($this->orig_dn == 'new'){
253 $ldap->cd($this->config->current['BASE']);
254 $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
255 $ldap->cd($this->dn);
256 $ldap->add($this->attrs);
257 new log("create","winworkstation/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
258 $this->handle_post_events("add");
259 } else {
260 if ($this->orig_dn != $this->dn){
261 $this->move($this->orig_dn, $this->dn);
262 }
264 $ldap->cd($this->dn);
265 $this->cleanup();
266 $ldap->modify ($this->attrs);
267 new log("modify","winworkstation/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
268 $this->handle_post_events("modify");
269 }
271 $this->netConfigDNS->cn = preg_replace("/\\\$\$/","",$this->cn);
272 $this->netConfigDNS->save();
273 show_ldap_error($ldap->get_error(), sprintf(_("Saving of system wingeneric/generic with dn '%s' failed."),$this->dn));
275 /* Optionally execute a command after we're done */
276 $this->postcreate();
277 }
279 /* Return plugin informations for acl handling
280 #FIXME FAIscript seams to ununsed within this class... */
281 function plInfo()
282 {
283 return (array(
284 "plShortName" => _("Win generic"),
285 "plDescription" => _("Windows workstation generic"),
286 "plSelfModify" => FALSE,
287 "plDepends" => array(),
288 "plPriority" => 0,
289 "plSection" => array("administration"),
290 "plCategory" => array("winworkstation" => array("description" => _("Win workstation"),
291 "objectClass" => "gotoWorkstation")),
292 "plProvidedAcls"=> array(
293 "cn" => _("Workstation name"),
294 "description" => _("Description"))
295 ));
296 }
299 }
301 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
302 ?>