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");
48 function wingeneric ($config, $dn= NULL, $parent= NULL)
49 {
50 plugin::plugin ($config, $dn, $parent);
51 $this->netConfigDNS = new termDNS($this->config,$this->dn,$this->objectclasses);
52 /* Set base */
53 if ($this->dn == "new"){
54 $ui= get_userinfo();
55 $this->base= dn2base($ui->dn);
56 $this->cn= "";
57 } else {
58 $this->base= preg_replace ("/^[^,]+,[^,]+,[^,]+,/", "", $this->dn);
59 }
61 /* Save dn for later references */
62 $this->orig_dn= $this->dn;
63 }
65 function execute()
66 {
67 /* Call parent execute */
68 plugin::execute();
70 /* Do we represent a valid phone? */
71 if (!$this->is_account && $this->parent == NULL){
72 $display= "<img alt=\"\" src=\"images/stop.png\" align=middle> <b>".
73 _("This 'dn' has no network features.")."</b>";
74 return($display);
75 }
77 /* Base select dialog */
78 $once = true;
79 foreach($_POST as $name => $value){
80 if(preg_match("/^chooseBase/",$name) && $once){
81 $once = false;
82 $this->dialog = new baseSelectDialog($this->config);
83 $this->dialog->setCurrentBase($this->base);
84 }
85 }
87 /* Dialog handling */
88 if(is_object($this->dialog)){
89 /* Must be called before save_object */
90 $this->dialog->save_object();
92 if($this->dialog->isClosed()){
93 $this->dialog = false;
94 }elseif($this->dialog->isSelected()){
95 $this->base = $this->dialog->isSelected();
96 $this->dialog= false;
97 }else{
98 return($this->dialog->execute());
99 }
100 }
102 /* Fill templating stuff */
103 $smarty= get_smarty();
105 // Undefined index in wingeneric.tpl ...
106 $smarty->assign("bases", $this->config->idepartments);
108 /* Assign attributes */
109 foreach ($this->attributes as $attr){
110 $smarty->assign($attr."ACL", chkacl($this->acl, $attr));
111 $smarty->assign("$attr", $this->$attr);
112 }
114 $smarty->assign("base_select", $this->base);
116 /* Show main page */
117 $this->netConfigDNS->cn= $this->cn;
118 $smarty->assign("netconfig", $this->netConfigDNS->execute());
119 return($smarty->fetch (get_template_path('wingeneric.tpl', TRUE)));
120 }
122 function remove_from_parent()
123 {
124 $this->netConfigDNS->remove_from_parent();
125 $ldap= $this->config->get_ldap_link();
126 $ldap->rmdir($this->dn);
127 show_ldap_error($ldap->get_error(), _("Removing Samba workstation failed"));
128 $this->handle_post_events("remove");
130 /* Delete references to object groups */
131 $ldap->cd ($this->config->current['BASE']);
132 $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".$this->dn."))", array("cn"));
133 while ($ldap->fetch()){
134 $og= new ogroup($this->config, $ldap->getDN());
135 unset($og->member[$this->dn]);
136 $og->save ();
137 }
138 }
141 /* Save data to object */
142 function save_object()
143 {
144 plugin::save_object();
145 $this->netConfigDNS->save_object();
146 /* Save base, since this is no LDAP attribute */
147 if (isset($_POST['base']) && chkacl($this->acl, "create") == ""){
148 $this->base= $_POST['base'];
149 }
150 }
153 /* Check supplied data */
154 function check()
155 {
156 /* Call common method to give check the hook */
157 $message= plugin::check();
158 $message= array_merge($message, $this->netConfigDNS->check());
159 $this->dn= "cn=".$this->cn.",ou=netdevices,ou=systems,".$this->base;
161 $ui= get_userinfo();
162 $acl= get_permissions ($this->dn, $ui->subtreeACL);
163 $acl= get_module_permission($acl, "component", $this->dn);
164 if (chkacl($acl, "create") != ""){
165 $message[]= _("You have no permissions to create a component on this 'Base'.");
166 }
168 if ($this->orig_dn != $this->dn){
169 $ldap= $this->config->get_ldap_link();
170 $ldap->cd ($this->base);
171 $ldap->search ("(cn=".$this->cn.")", array("cn"));
172 if ($ldap->count() != 0){
173 while ($attrs= $ldap->fetch()){
174 if ($attrs['dn'] != $this->orig_dn){
175 $message[]= sprintf (_("There is already an entry '%s' in the base choosen by you"), $this->cn);
176 break;
177 }
178 }
179 }
180 }
182 return ($message);
183 }
186 /* Save to LDAP */
187 function save()
188 {
189 plugin::save();
191 /* Remove all empty values */
192 if ($this->orig_dn == 'new'){
193 $attrs= array();
194 foreach ($this->attrs as $key => $val){
195 if (is_array($val) && count($val) == 0){
196 continue;
197 }
198 $attrs[$key]= $val;
199 }
200 $this->attrs= $attrs;
201 }
203 /* Write back to ldap */
204 $ldap= $this->config->get_ldap_link();
205 if ($this->orig_dn == 'new'){
206 $ldap->cd($this->config->current['BASE']);
207 $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
208 $ldap->cd($this->dn);
209 $ldap->add($this->attrs);
210 $this->handle_post_events("add");
211 } else {
212 if ($this->orig_dn != $this->dn){
213 $this->move($this->orig_dn, $this->dn);
214 }
216 $ldap->cd($this->dn);
217 $this->cleanup();
218 $ldap->modify ($this->attrs);
220 $this->handle_post_events("modify");
221 }
223 $this->netConfigDNS->cn = $this->cn;
224 $this->netConfigDNS->save($this->dn);
225 show_ldap_error($ldap->get_error(), _("Saving Samba workstation failed"));
227 /* Optionally execute a command after we're done */
228 $this->postcreate();
229 }
231 }
233 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
234 ?>