ffd87eb9c02448ecf32d5be4a65bd7f2bd62ba3b
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)
49 {
50 plugin::plugin ($config, $dn);
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 $smarty->assign("netconfig", $this->netConfigDNS->execute());
118 return($smarty->fetch (get_template_path('wingeneric.tpl', TRUE)));
119 }
121 function remove_from_parent()
122 {
123 $this->netConfigDNS->remove_from_parent();
124 $ldap= $this->config->get_ldap_link();
125 $ldap->rmdir($this->dn);
126 show_ldap_error($ldap->get_error(), _("Removing Samba workstation failed"));
127 $this->handle_post_events("remove");
129 /* Delete references to object groups */
130 $ldap->cd ($this->config->current['BASE']);
131 $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".$this->dn."))", array("cn"));
132 while ($ldap->fetch()){
133 $og= new ogroup($this->config, $ldap->getDN());
134 unset($og->member[$this->dn]);
135 $og->save ();
136 }
137 }
140 /* Save data to object */
141 function save_object()
142 {
143 plugin::save_object();
144 $this->netConfigDNS->save_object();
145 /* Save base, since this is no LDAP attribute */
146 if (isset($_POST['base']) && chkacl($this->acl, "create") == ""){
147 $this->base= $_POST['base'];
148 }
149 }
152 /* Check supplied data */
153 function check()
154 {
155 /* Call common method to give check the hook */
156 $message= plugin::check();
157 $message= array_merge($message, $this->netConfigDNS->check());
158 $this->dn= "cn=".$this->cn.",ou=netdevices,ou=systems,".$this->base;
160 $ui= get_userinfo();
161 $acl= get_permissions ($this->dn, $ui->subtreeACL);
162 $acl= get_module_permission($acl, "component", $this->dn);
163 if (chkacl($acl, "create") != ""){
164 $message[]= _("You have no permissions to create a component on this 'Base'.");
165 }
167 if ($this->orig_dn != $this->dn){
168 $ldap= $this->config->get_ldap_link();
169 $ldap->cd ($this->base);
170 $ldap->search ("(cn=".$this->cn.")", array("cn"));
171 if ($ldap->count() != 0){
172 while ($attrs= $ldap->fetch()){
173 if ($attrs['dn'] != $this->orig_dn){
174 $message[]= sprintf (_("There is already an entry '%s' in the base choosen by you"), $this->cn);
175 break;
176 }
177 }
178 }
179 }
181 return ($message);
182 }
185 /* Save to LDAP */
186 function save()
187 {
188 plugin::save();
190 /* Remove all empty values */
191 if ($this->orig_dn == 'new'){
192 $attrs= array();
193 foreach ($this->attrs as $key => $val){
194 if (is_array($val) && count($val) == 0){
195 continue;
196 }
197 $attrs[$key]= $val;
198 }
199 $this->attrs= $attrs;
200 }
202 /* Write back to ldap */
203 $ldap= $this->config->get_ldap_link();
204 if ($this->orig_dn == 'new'){
205 $ldap->cd($this->config->current['BASE']);
206 $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
207 $ldap->cd($this->dn);
208 $ldap->add($this->attrs);
209 $this->handle_post_events("add");
210 } else {
211 if ($this->orig_dn != $this->dn){
212 $this->move($this->orig_dn, $this->dn);
213 }
215 $ldap->cd($this->dn);
216 $this->cleanup();
217 $ldap->modify ($this->attrs);
219 $this->handle_post_events("modify");
220 }
222 $this->netConfigDNS->cn = $this->cn;
223 $this->netConfigDNS->save($this->dn);
224 show_ldap_error($ldap->get_error(), _("Saving Samba workstation failed"));
226 /* Optionally execute a command after we're done */
227 $this->postcreate();
228 }
230 }
232 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
233 ?>