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 $str = $this->netConfigDNS->execute();
146 if(is_object($this->netConfigDNS->dialog)){
147 return($str);
148 }
149 $smarty->assign("netconfig", $str);
150 return($smarty->fetch (get_template_path('wingeneric.tpl', TRUE)));
151 }
153 function remove_from_parent()
154 {
155 $this->netConfigDNS->remove_from_parent();
156 $ldap= $this->config->get_ldap_link();
157 $ldap->rmdir($this->dn);
158 new log("remove","winworkstation/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
159 show_ldap_error($ldap->get_error(), sprintf(_("Removing of system wingeneric/generic with dn '%s' failed."),$this->dn));
160 $this->handle_post_events("remove");
162 /* Delete references to object groups */
163 $ldap->cd ($this->config->current['BASE']);
164 $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".$this->dn."))", array("cn"));
165 while ($ldap->fetch()){
166 $og= new ogroup($this->config, $ldap->getDN());
167 unset($og->member[$this->dn]);
168 $og->save ();
169 }
170 }
173 /* Save data to object */
174 function save_object()
175 {
176 /* Create a base backup and reset the
177 base directly after calling plugin::save_object();
178 Base will be set seperatly a few lines below */
179 $base_tmp = $this->base;
180 plugin::save_object();
181 $this->base = $base_tmp;
183 $this->netConfigDNS->save_object();
185 /* Set new base if allowed */
186 $tmp = $this->get_allowed_bases();
187 if(isset($_POST['base'])){
188 if(isset($tmp[$_POST['base']])){
189 $this->base= $_POST['base'];
190 }
191 }
192 }
195 /* Check supplied data */
196 function check()
197 {
198 /* Call common method to give check the hook */
199 $message= plugin::check();
200 $message= array_merge($message, $this->netConfigDNS->check());
201 $this->dn= "cn=".$this->cn.",ou=netdevices,ou=systems,".$this->base;
203 /* Set new acl base */
204 if($this->dn == "new") {
205 $this->set_acl_base($this->base);
206 }
208 if(!$this->acl_is_createable() && $this->dn == "new"){
209 $message[]= _("You have no permissions to create a component on this 'Base'.");
210 }
212 if ($this->orig_dn != $this->dn){
213 $ldap= $this->config->get_ldap_link();
214 $ldap->cd ($this->base);
215 $ldap->search ("(cn=".$this->cn.")", array("cn"));
216 if ($ldap->count() != 0){
217 while ($attrs= $ldap->fetch()){
218 if(preg_match("/cn=dhcp,/",$attrs['dn'])){
219 continue;
220 }
221 if ($attrs['dn'] != $this->orig_dn){
222 $message[]= sprintf (_("There is already an entry '%s' in the base choosen by you"), $this->cn);
223 break;
224 }
225 }
226 }
227 }
229 return ($message);
230 }
233 /* Save to LDAP */
234 function save()
235 {
236 plugin::save();
238 /* Remove all empty values */
239 if ($this->orig_dn == 'new'){
240 $attrs= array();
241 foreach ($this->attrs as $key => $val){
242 if (is_array($val) && count($val) == 0){
243 continue;
244 }
245 $attrs[$key]= $val;
246 }
247 $this->attrs= $attrs;
248 }
250 if(($this->gosaUnitTag) && (!in_array_ics("gosaAdministrativeUnitTag",$this->attrs['objectClass']))){
251 $this->attrs['objectClass'][] = "gosaAdministrativeUnitTag";
252 }
254 /* Write back to ldap */
255 $ldap= $this->config->get_ldap_link();
256 if ($this->orig_dn == 'new'){
257 $ldap->cd($this->config->current['BASE']);
258 $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
259 $ldap->cd($this->dn);
260 $ldap->add($this->attrs);
261 new log("create","winworkstation/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
262 $this->handle_post_events("add");
263 } else {
264 if ($this->orig_dn != $this->dn){
265 $this->move($this->orig_dn, $this->dn);
266 }
268 $ldap->cd($this->dn);
269 $this->cleanup();
270 $ldap->modify ($this->attrs);
271 new log("modify","winworkstation/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
272 $this->handle_post_events("modify");
273 }
275 $this->netConfigDNS->cn = preg_replace("/\\\$\$/","",$this->cn);
276 $this->netConfigDNS->save();
277 show_ldap_error($ldap->get_error(), sprintf(_("Saving of system wingeneric/generic with dn '%s' failed."),$this->dn));
279 /* Optionally execute a command after we're done */
280 $this->postcreate();
281 }
283 /* Return plugin informations for acl handling
284 #FIXME FAIscript seams to ununsed within this class... */
285 function plInfo()
286 {
287 return (array(
288 "plShortName" => _("Win generic"),
289 "plDescription" => _("Windows workstation generic"),
290 "plSelfModify" => FALSE,
291 "plDepends" => array(),
292 "plPriority" => 0,
293 "plSection" => array("administration"),
294 "plCategory" => array("winworkstation" => array("description" => _("Win workstation"),
295 "objectClass" => "gotoWorkstation")),
296 "plProvidedAcls"=> array(
297 "cn" => _("Workstation name"),
298 "description" => _("Description"))
299 ));
300 }
303 }
305 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
306 ?>