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 $macAddress= "";
17 var $ipHostNumber= "";
18 var $description= "";
19 var $orig_dn= "";
20 var $shadowLastChange="";
21 var $uidNumber="";
22 var $gidNumber="";
23 var $loginShell="";
24 var $gecos="";
25 var $shadowMin="";
26 var $shadowWarning="";
27 var $shadowInactive="";
28 var $uid="";
29 var $sn="";
30 var $givenName="";
31 var $homeDirectory="";
32 var $sambaSID="";
33 var $sambaPrimaryGroupSID="";
34 var $displayName="";
35 var $sambaPwdCanChange2="";
36 var $sambaPwdMustChange="";
37 var $sambaNTPassword="";
38 var $sambaPwdLastSet="";
39 var $sambaAcctFlags="";
41 /* attribute list for save action */
42 var $ignore_account= TRUE;
43 var $attributes = array("cn", "description", "macAddress", "ipHostNumber","shadowLastChange",
44 "uidNumber","gidNumber","loginShell","gecos","shadowMin","shadowWarning",
45 "shadowInactive","uid","cn","sn","givenName","homeDirectory","sambaSID",
46 "sambaPrimaryGroupSID","displayName", "sambaPwdCanChange2","sambaPwdMustChange",
47 "sambaNTPassword","sambaPwdLastSet","sambaAcctFlags");
48 var $objectclasses= array("posixAccount","person","organizationalPerson","inetOrgPerson","gosaAccount","shadowAccount","sambaSamAccount","top", "device", "ipHost", "ieee802Device");
51 function wingeneric ($config, $dn= NULL)
52 {
53 plugin::plugin ($config, $dn);
55 /* Set base */
56 if ($this->dn == "new"){
57 $ui= get_userinfo();
58 $this->base= dn2base($ui->dn);
59 $this->cn= "";
60 } else {
61 $this->base= preg_replace ("/^[^,]+,[^,]+,[^,]+,/", "", $this->dn);
62 }
64 /* Save dn for later references */
65 $this->orig_dn= $this->dn;
66 }
68 function execute()
69 {
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 /* Fill templating stuff */
78 $smarty= get_smarty();
79 $smarty->assign("bases", $this->config->idepartments);
81 /* Assign attributes */
82 foreach ($this->attributes as $attr){
83 $smarty->assign($attr."ACL", chkacl($this->acl, $attr));
84 $smarty->assign("$attr", $this->$attr);
85 }
87 /* Show Asterisk for required attribute ipHostNumber and macAddress */
88 $smarty->assign("staticAddress", "<font class=\"must\">*</font>");
90 $smarty->assign("base_select", $this->base);
92 /* Show main page */
93 $smarty->assign("netconfig", dirname(__FILE__)."/network.tpl");
94 return($smarty->fetch (get_template_path('wingeneric.tpl', TRUE)));
95 }
97 function remove_from_parent()
98 {
99 $ldap= $this->config->get_ldap_link();
100 $ldap->rmdir($this->dn);
101 show_ldap_error($ldap->get_error());
102 $this->handle_post_events("remove");
104 /* Delete references to object groups */
105 $ldap->cd ($this->config->current['BASE']);
106 $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".$this->dn."))", array("cn"));
107 while ($ldap->fetch()){
108 $og= new ogroup($this->config, $ldap->getDN());
109 unset($og->member[$this->dn]);
110 $og->save ();
111 }
113 }
116 /* Save data to object */
117 function save_object()
118 {
119 plugin::save_object();
121 /* Save base, since this is no LDAP attribute */
122 if (isset($_POST['base']) && chkacl($this->acl, "create") == ""){
123 $this->base= $_POST['base'];
124 }
125 }
128 /* Check supplied data */
129 function check()
130 {
131 $message= array();
132 $this->dn= "cn=".$this->cn.",ou=netdevices,ou=systems,".$this->base;
134 /* must: cn, macAddress */
135 if ($this->cn == "" && chkacl ($this->acl, "cn") == ""){
136 $message[]= _("The required field 'Component name' is not set.");
137 }
138 if ($this->macAddress == "" && chkacl ($this->acl, "macAddress") == ""){
139 $message[]= _("The required field 'MAC-address' is not set.");
140 }
141 if ($this->ipHostNumber == "" && chkacl ($this->acl, "ipHostNumber") == ""){
142 $message[]= _("The required field 'IP-address' is not set.");
143 }
145 $ui= get_userinfo();
146 $acl= get_permissions ($this->dn, $ui->subtreeACL);
147 $acl= get_module_permission($acl, "component", $this->dn);
148 if (chkacl($acl, "create") != ""){
149 $message[]= _("You have no permissions to create a component on this 'Base'.");
150 }
152 if ($this->orig_dn != $this->dn){
153 $ldap= $this->config->get_ldap_link();
154 $ldap->cd ($this->base);
155 $ldap->search ("(cn=".$this->cn.")", array("cn"));
156 if ($ldap->count() != 0){
157 while ($attrs= $ldap->fetch()){
158 if ($attrs['dn'] != $this->orig_dn){
159 $message[]= sprintf (_("There is already an entry '%s' in the base choosen by you"), $this->cn);
160 break;
161 }
162 }
163 }
164 }
166 return ($message);
167 }
170 /* Save to LDAP */
171 function save()
172 {
173 plugin::save();
175 /* Remove all empty values */
176 if ($this->orig_dn == 'new'){
177 $attrs= array();
178 foreach ($this->attrs as $key => $val){
179 if (is_array($val) && count($val) == 0){
180 continue;
181 }
182 $attrs[$key]= $val;
183 }
184 $this->attrs= $attrs;
185 }
187 /* Write back to ldap */
188 $ldap= $this->config->get_ldap_link();
189 if ($this->orig_dn == 'new'){
190 $ldap->cd($this->config->current['BASE']);
191 $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
192 $ldap->cd($this->dn);
193 $ldap->add($this->attrs);
194 $this->handle_post_events("add");
195 } else {
196 if ($this->orig_dn != $this->dn){
197 $this->move($this->orig_dn, $this->dn);
198 }
200 $ldap->cd($this->dn);
201 $ldap->modify($this->attrs);
202 $this->handle_post_events("modify");
203 }
204 show_ldap_error($ldap->get_error());
206 /* Optionally execute a command after we're done */
207 $this->postcreate();
208 }
210 }
212 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
213 ?>