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->dn,$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 @log::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 @log::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 ($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 @log::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 @log::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($this->dn);
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 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 }
296 }
298 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
299 ?>