2463ca1173fd6aa6d51cc818c293de483c675bdb
1 <?php
3 class componentGeneric extends plugin
4 {
5 /* Generic terminal attributes */
6 var $interfaces= array();
7 var $ignore_account= TRUE;
9 /* Needed values and lists */
10 var $base= "";
11 var $cn= "";
12 var $description= "";
13 var $orig_dn= "";
15 /* attribute list for save action */
16 var $attributes= array("cn", "description");
17 var $objectclasses= array("top", "device", "ipHost", "ieee802Device");
18 var $netConfigDNS;
20 function componentgeneric ($config, $dn= NULL, $parent= NULL)
21 {
22 plugin::plugin ($config, $dn, $parent);
24 /* Set base */
25 if ($this->dn == "new"){
26 $ui= get_userinfo();
27 $this->base= dn2base($ui->dn);
28 $this->cn= "";
29 } else {
30 $this->base= preg_replace ("/^[^,]+,[^,]+,[^,]+,/", "", $this->dn);
31 }
32 $this->netConfigDNS = new termDNS($this->config,$this->dn,$this->objectclasses, true);
33 $this->netConfigDNS->acl = $this->acl;
35 /* Save dn for later references */
36 $this->orig_dn= $this->dn;
37 }
39 function execute()
40 {
41 $this->netConfigDNS->acl = $this->acl;
43 /* Call parent execute */
44 plugin::execute();
46 /* Do we represent a valid phone? */
47 if (!$this->is_account && $this->parent == NULL){
48 $display= "<img alt=\"\" src=\"images/stop.png\" align=middle> <b>".
49 _("This 'dn' has no network features.")."</b>";
50 return($display);
51 }
53 /* Base select dialog */
54 $once = true;
55 foreach($_POST as $name => $value){
56 if(preg_match("/^chooseBase/",$name) && $once){
57 $once = false;
58 $this->dialog = new baseSelectDialog($this->config);
59 $this->dialog->setCurrentBase($this->base);
60 }
61 }
63 /* Dialog handling */
64 if(is_object($this->dialog)){
65 /* Must be called before save_object */
66 $this->dialog->save_object();
68 if($this->dialog->isClosed()){
69 $this->dialog = false;
70 }elseif($this->dialog->isSelected()){
71 $this->base = $this->dialog->isSelected();
72 $this->dialog= false;
73 }else{
74 return($this->dialog->execute());
75 }
76 }
78 /* Fill templating stuff */
79 $smarty= get_smarty();
80 $smarty->assign("bases", $this->config->idepartments);
82 /* Assign attributes */
83 foreach ($this->attributes as $attr){
84 $smarty->assign($attr."ACL", chkacl($this->acl, $attr));
85 $smarty->assign("$attr", $this->$attr);
86 }
87 $smarty->assign("base_select", $this->base);
88 $smarty->assign("baseACL", chkacl($this->acl,"base"));
90 /* Show main page */
91 $this->netConfigDNS->cn= $this->cn;
92 $smarty->assign("netconfig", $this->netConfigDNS->execute());
93 return($smarty->fetch (get_template_path('component.tpl', TRUE)));
94 }
96 function remove_from_parent()
97 {
98 $this->netConfigDNS->acl = $this->acl;
99 $ldap= $this->config->get_ldap_link();
100 $this->netConfigDNS->remove_from_parent();
101 $ldap->rmdir($this->dn);
102 show_ldap_error($ldap->get_error(), _("Removing generic component failed"));
103 $this->handle_post_events("remove",array("macAddress" => $this->netConfigDNS->macAddress,"ipHostNumber" => $this->netConfigDNS->ipHostNumber));
105 /* Delete references to object groups */
106 $ldap->cd ($this->config->current['BASE']);
107 $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".$this->dn."))", array("cn"));
108 while ($ldap->fetch()){
109 $og= new ogroup($this->config, $ldap->getDN());
110 unset($og->member[$this->dn]);
111 $og->save ();
112 }
113 }
116 /* Save data to object */
117 function save_object()
118 {
119 plugin::save_object();
121 $this->netConfigDNS->save_object();
123 /* Save base, since this is no LDAP attribute */
124 if (isset($_POST['base']) && chkacl($this->acl, "create") == ""){
125 $this->base= $_POST['base'];
126 }
127 }
130 /* Check supplied data */
131 function check()
132 {
133 /* Call common method to give check the hook */
134 $message= plugin::check();
135 $message= array_merge($message,$this->netConfigDNS->check());
137 $this->dn= "cn=".$this->cn.",ou=netdevices,ou=systems,".$this->base;
139 if ($this->cn == "" && chkacl ($this->acl, "cn") == ""){
140 $message[]= _("The required field 'Component name' is not set.");
141 }
143 /* To check for valid ip*/
144 if($this->netConfigDNS->ipHostNumber == ""){
145 $message[]= _("The required field IP address is empty.");
146 } else {
147 if (!is_ip($this->netConfigDNS->ipHostNumber)){
148 $message[]= _("The field IP address contains an invalid address.");
149 }
150 }
152 $ui= get_userinfo();
153 $acl= get_permissions ($this->dn, $ui->subtreeACL);
154 $acl= get_module_permission($acl, "component", $this->dn);
155 if (chkacl($acl, "create") != ""){
156 $message[]= _("You have no permissions to create a component on this 'Base'.");
157 }
159 if ($this->orig_dn != $this->dn){
160 $ldap= $this->config->get_ldap_link();
161 $ldap->cd ($this->base);
162 $ldap->search ("(cn=".$this->cn.")", array("cn"));
163 if ($ldap->count() != 0){
164 while ($attrs= $ldap->fetch()){
165 if ($attrs['dn'] != $this->orig_dn){
166 $message[]= sprintf (_("There is already an entry '%s' in the base choosen by you"), $this->cn);
167 break;
168 }
169 }
170 }
171 }
173 return ($message);
174 }
177 /* Save to LDAP */
178 function save()
179 {
180 $this->netConfigDNS->acl = $this->acl;
181 plugin::save();
183 /* Remove all empty values */
184 if ($this->orig_dn == 'new'){
185 $attrs= array();
186 foreach ($this->attrs as $key => $val){
187 if (is_array($val) && count($val) == 0){
188 continue;
189 }
190 $attrs[$key]= $val;
191 }
192 $this->attrs= $attrs;
193 }
195 /* If this is a new Object IP & Mac aren't set.
196 IP & Mac are msut attributes, so we set this values by here. */
197 if($this->orig_dn == 'new'){
198 $this->attrs['ipHostNumber'] = $this->netConfigDNS->ipHostNumber;
199 $this->attrs['macAddress'] = $this->netConfigDNS->macAddress;
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",array("macAddress" => $this->netConfigDNS->macAddress,"ipHostNumber" => $this->netConfigDNS->ipHostNumber));
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",array("macAddress" => $this->netConfigDNS->macAddress,"ipHostNumber" => $this->netConfigDNS->ipHostNumber));
220 }
222 $this->netConfigDNS->cn = $this->cn;
223 $this->netConfigDNS->save($this->dn);
225 show_ldap_error($ldap->get_error(), _("Saving generic component failed"));
226 }
227 }
229 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
230 ?>