fbd5412c3d0762e4bb1209072f40e00312ac2438
1 <?php
3 class componentGeneric 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();
12 var $ignore_account= TRUE;
14 /* Needed values and lists */
15 var $base= "";
16 var $cn= "";
17 var $description= "";
18 var $orig_dn= "";
20 /* attribute list for save action */
21 var $attributes= array("cn", "description");
22 var $objectclasses= array("top", "device", "ipHost", "ieee802Device");
23 var $netConfigDNS;
25 function componentgeneric ($config, $dn= NULL)
26 {
27 plugin::plugin ($config, $dn);
29 /* Set base */
30 if ($this->dn == "new"){
31 $ui= get_userinfo();
32 $this->base= dn2base($ui->dn);
33 $this->cn= "";
34 } else {
35 $this->base= preg_replace ("/^[^,]+,[^,]+,[^,]+,/", "", $this->dn);
36 }
37 $this->netConfigDNS = new termDNS($this->config,$this->dn,$this->objectclasses, true);
38 /* Save dn for later references */
39 $this->orig_dn= $this->dn;
40 }
42 function execute()
43 {
44 /* Call parent execute */
45 plugin::execute();
47 /* Do we represent a valid phone? */
48 if (!$this->is_account && $this->parent == NULL){
49 $display= "<img alt=\"\" src=\"images/stop.png\" align=middle> <b>".
50 _("This 'dn' has no network features.")."</b>";
51 return($display);
52 }
54 /* Base select dialog */
55 $once = true;
56 foreach($_POST as $name => $value){
57 if(preg_match("/^chooseBase/",$name) && $once){
58 $once = false;
59 $this->dialog = new baseSelectDialog($this->config);
60 $this->dialog->setCurrentBase($this->base);
61 }
62 }
64 /* Dialog handling */
65 if(is_object($this->dialog)){
66 /* Must be called before save_object */
67 $this->dialog->save_object();
69 if($this->dialog->isClosed()){
70 $this->dialog = false;
71 }elseif($this->dialog->isSelected()){
72 $this->base = $this->dialog->isSelected();
73 $this->dialog= false;
74 }else{
75 return($this->dialog->execute());
76 }
77 }
79 /* Fill templating stuff */
80 $smarty= get_smarty();
81 $smarty->assign("bases", $this->config->idepartments);
83 /* Assign attributes */
84 foreach ($this->attributes as $attr){
85 $smarty->assign($attr."ACL", chkacl($this->acl, $attr));
86 $smarty->assign("$attr", $this->$attr);
87 }
88 $smarty->assign("base_select", $this->base);
90 /* Show main page */
91 $smarty->assign("netconfig", $this->netConfigDNS->execute());
92 return($smarty->fetch (get_template_path('component.tpl', TRUE)));
93 }
95 function remove_from_parent()
96 {
97 $ldap= $this->config->get_ldap_link();
98 $this->netConfigDNS->remove_from_parent();
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 }
111 }
114 /* Save data to object */
115 function save_object()
116 {
117 plugin::save_object();
119 $this->netConfigDNS->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 /* Call common method to give check the hook */
132 $message= plugin::check();
133 $message= array_merge($message,$this->netConfigDNS->check());
135 $this->dn= "cn=".$this->cn.",ou=netdevices,ou=systems,".$this->base;
137 if ($this->cn == "" && chkacl ($this->acl, "cn") == ""){
138 $message[]= _("The required field 'Component name' is not set.");
139 }
141 /* To check for valid ip*/
142 if($this->netConfigDNS->ipHostNumber == ""){
143 $message[]= _("The required field IP address is empty.");
144 } else {
145 if (!is_ip($this->netConfigDNS->ipHostNumber)){
146 $message[]= _("The field IP address contains an invalid address.");
147 }
148 }
150 $ui= get_userinfo();
151 $acl= get_permissions ($this->dn, $ui->subtreeACL);
152 $acl= get_module_permission($acl, "component", $this->dn);
153 if (chkacl($acl, "create") != ""){
154 $message[]= _("You have no permissions to create a component on this 'Base'.");
155 }
157 if ($this->orig_dn != $this->dn){
158 $ldap= $this->config->get_ldap_link();
159 $ldap->cd ($this->base);
160 $ldap->search ("(cn=".$this->cn.")", array("cn"));
161 if ($ldap->count() != 0){
162 while ($attrs= $ldap->fetch()){
163 if ($attrs['dn'] != $this->orig_dn){
164 $message[]= sprintf (_("There is already an entry '%s' in the base choosen by you"), $this->cn);
165 break;
166 }
167 }
168 }
169 }
171 return ($message);
172 }
175 /* Save to LDAP */
176 function save()
177 {
178 plugin::save();
180 /* Remove all empty values */
181 if ($this->orig_dn == 'new'){
182 $attrs= array();
183 foreach ($this->attrs as $key => $val){
184 if (is_array($val) && count($val) == 0){
185 continue;
186 }
187 $attrs[$key]= $val;
188 }
189 $this->attrs= $attrs;
190 }
192 /* If this is a new Object IP & Mac aren't set.
193 IP & Mac are msut attributes, so we set this values by here. */
194 if($this->orig_dn == 'new'){
195 $this->attrs['ipHostNumber'] = $this->netConfigDNS->ipHostNumber;
196 $this->attrs['macAddress'] = $this->netConfigDNS->macAddress;
197 }
199 /* Write back to ldap */
200 $ldap= $this->config->get_ldap_link();
201 if ($this->orig_dn == 'new'){
202 $ldap->cd($this->config->current['BASE']);
203 $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
204 $ldap->cd($this->dn);
205 $ldap->add($this->attrs);
206 $this->handle_post_events("add");
207 } else {
208 if ($this->orig_dn != $this->dn){
209 $this->move($this->orig_dn, $this->dn);
210 }
212 $ldap->cd($this->dn);
213 $this->cleanup();
214 $ldap->modify ($this->attrs);
216 $this->handle_post_events("modify");
217 }
219 $this->netConfigDNS->cn = $this->cn;
220 $this->netConfigDNS->save($this->dn);
222 show_ldap_error($ldap->get_error());
224 /* Optionally execute a command after we're done */
225 $this->postcreate();
226 }
228 }
230 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
231 ?>