495741d68dd76e183a4ace3eaafa3de556e05427
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 $sambaPwdMustChange="";
36 var $sambaNTPassword="";
37 var $sambaPwdLastSet="";
38 var $sambaAcctFlags="";
40 /* attribute list for save action */
41 var $ignore_account= TRUE;
42 var $attributes = array("cn", "description", "macAddress", "ipHostNumber","shadowLastChange",
43 "uidNumber","gidNumber","loginShell","gecos","shadowMin","shadowWarning",
44 "shadowInactive","uid","cn","sn","givenName","homeDirectory","sambaSID",
45 "sambaPrimaryGroupSID","displayName", "sambaPwdMustChange",
46 "sambaNTPassword","sambaPwdLastSet","sambaAcctFlags");
47 var $objectclasses= array("posixAccount","person","organizationalPerson","inetOrgPerson","gosaAccount","shadowAccount","sambaSamAccount","top", "device", "ipHost", "ieee802Device");
50 function wingeneric ($config, $dn= NULL)
51 {
52 plugin::plugin ($config, $dn);
54 /* Set base */
55 if ($this->dn == "new"){
56 $ui= get_userinfo();
57 $this->base= dn2base($ui->dn);
58 $this->cn= "";
59 } else {
60 $this->base= preg_replace ("/^[^,]+,[^,]+,[^,]+,/", "", $this->dn);
61 }
63 /* Save dn for later references */
64 $this->orig_dn= $this->dn;
65 }
67 function execute()
68 {
69 /* Do we represent a valid phone? */
70 if (!$this->is_account && $this->parent == NULL){
71 $display= "<img alt=\"\" src=\"images/stop.png\" align=middle> <b>".
72 _("This 'dn' has no network features.")."</b>";
73 return($display);
74 }
76 /* Fill templating stuff */
77 $smarty= get_smarty();
78 $smarty->assign("bases", $this->config->idepartments);
80 /* Assign attributes */
81 foreach ($this->attributes as $attr){
82 $smarty->assign($attr."ACL", chkacl($this->acl, $attr));
83 $smarty->assign("$attr", $this->$attr);
84 }
86 /* Show Asterisk for required attribute ipHostNumber and macAddress */
87 $smarty->assign("staticAddress", "<font class=\"must\">*</font>");
89 $smarty->assign("base_select", $this->base);
91 /* Show main page */
92 $smarty->assign("netconfig", dirname(__FILE__)."/network.tpl");
93 return($smarty->fetch (get_template_path('wingeneric.tpl', TRUE)));
94 }
96 function remove_from_parent()
97 {
98 $ldap= $this->config->get_ldap_link();
99 $ldap->rmdir($this->dn);
100 show_ldap_error($ldap->get_error());
101 $this->handle_post_events("remove");
103 /* Delete references to object groups */
104 $ldap->cd ($this->config->current['BASE']);
105 $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".$this->dn."))", array("cn"));
106 while ($ldap->fetch()){
107 $og= new ogroup($this->config, $ldap->getDN());
108 unset($og->member[$this->dn]);
109 $og->save ();
110 }
112 }
115 /* Save data to object */
116 function save_object()
117 {
118 plugin::save_object();
120 /* Save base, since this is no LDAP attribute */
121 if (isset($_POST['base']) && chkacl($this->acl, "create") == ""){
122 $this->base= $_POST['base'];
123 }
124 }
127 /* Check supplied data */
128 function check()
129 {
130 $message= array();
131 $this->dn= "cn=".$this->cn.",ou=netdevices,ou=systems,".$this->base;
133 /* must: cn, macAddress */
134 if ($this->cn == "" && chkacl ($this->acl, "cn") == ""){
135 $message[]= _("The required field 'Component name' is not set.");
136 }
137 if ($this->macAddress == "" && chkacl ($this->acl, "macAddress") == ""){
138 $message[]= _("The required field 'MAC-address' is not set.");
139 }
140 if ($this->ipHostNumber == "" && chkacl ($this->acl, "ipHostNumber") == ""){
141 $message[]= _("The required field 'IP-address' is not set.");
142 }
144 $ui= get_userinfo();
145 $acl= get_permissions ($this->dn, $ui->subtreeACL);
146 $acl= get_module_permission($acl, "component", $this->dn);
147 if (chkacl($acl, "create") != ""){
148 $message[]= _("You have no permissions to create a component on this 'Base'.");
149 }
151 if ($this->orig_dn != $this->dn){
152 $ldap= $this->config->get_ldap_link();
153 $ldap->cd ($this->base);
154 $ldap->search ("(cn=".$this->cn.")", array("cn"));
155 if ($ldap->count() != 0){
156 while ($attrs= $ldap->fetch()){
157 if ($attrs['dn'] != $this->orig_dn){
158 $message[]= sprintf (_("There is already an entry '%s' in the base choosen by you"), $this->cn);
159 break;
160 }
161 }
162 }
163 }
165 return ($message);
166 }
169 /* Save to LDAP */
170 function save()
171 {
172 plugin::save();
174 /* Remove all empty values */
175 if ($this->orig_dn == 'new'){
176 $attrs= array();
177 foreach ($this->attrs as $key => $val){
178 if (is_array($val) && count($val) == 0){
179 continue;
180 }
181 $attrs[$key]= $val;
182 }
183 $this->attrs= $attrs;
184 }
186 /* Write back to ldap */
187 $ldap= $this->config->get_ldap_link();
188 if ($this->orig_dn == 'new'){
189 $ldap->cd($this->config->current['BASE']);
190 $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
191 $ldap->cd($this->dn);
192 $ldap->add($this->attrs);
193 $this->handle_post_events("add");
194 } else {
195 if ($this->orig_dn != $this->dn){
196 $this->move($this->orig_dn, $this->dn);
197 }
199 $ldap->cd($this->dn);
200 $ldap->modify($this->attrs);
201 $this->handle_post_events("modify");
202 }
203 show_ldap_error($ldap->get_error());
205 /* Optionally execute a command after we're done */
206 $this->postcreate();
207 }
209 }
211 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
212 ?>