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);
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 /* Fill templating stuff */
55 $smarty= get_smarty();
56 $smarty->assign("bases", $this->config->idepartments);
58 /* Assign attributes */
59 foreach ($this->attributes as $attr){
60 $smarty->assign($attr."ACL", chkacl($this->acl, $attr));
61 $smarty->assign("$attr", $this->$attr);
62 }
63 $smarty->assign("base_select", $this->base);
65 /* Show main page */
66 $smarty->assign("netconfig", $this->netConfigDNS->execute());
67 return($smarty->fetch (get_template_path('component.tpl', TRUE)));
68 }
70 function remove_from_parent()
71 {
72 $ldap= $this->config->get_ldap_link();
73 $this->netConfigDNS->remove_from_parent();
74 $ldap->rmdir($this->dn);
75 show_ldap_error($ldap->get_error());
76 $this->handle_post_events("remove");
78 /* Delete references to object groups */
79 $ldap->cd ($this->config->current['BASE']);
80 $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".$this->dn."))", array("cn"));
81 while ($ldap->fetch()){
82 $og= new ogroup($this->config, $ldap->getDN());
83 unset($og->member[$this->dn]);
84 $og->save ();
85 }
86 }
89 /* Save data to object */
90 function save_object()
91 {
92 plugin::save_object();
94 $this->netConfigDNS->save_object();
96 /* Save base, since this is no LDAP attribute */
97 if (isset($_POST['base']) && chkacl($this->acl, "create") == ""){
98 $this->base= $_POST['base'];
99 }
100 }
103 /* Check supplied data */
104 function check()
105 {
106 $message= array();
108 $message = array_merge($message,$this->netConfigDNS->check());
110 $this->dn= "cn=".$this->cn.",ou=netdevices,ou=systems,".$this->base;
112 if ($this->cn == "" && chkacl ($this->acl, "cn") == ""){
113 $message[]= _("The required field 'Component name' is not set.");
114 }
116 $ui= get_userinfo();
117 $acl= get_permissions ($this->dn, $ui->subtreeACL);
118 $acl= get_module_permission($acl, "component", $this->dn);
119 if (chkacl($acl, "create") != ""){
120 $message[]= _("You have no permissions to create a component on this 'Base'.");
121 }
123 if ($this->orig_dn != $this->dn){
124 $ldap= $this->config->get_ldap_link();
125 $ldap->cd ($this->base);
126 $ldap->search ("(cn=".$this->cn.")", array("cn"));
127 if ($ldap->count() != 0){
128 while ($attrs= $ldap->fetch()){
129 if ($attrs['dn'] != $this->orig_dn){
130 $message[]= sprintf (_("There is already an entry '%s' in the base choosen by you"), $this->cn);
131 break;
132 }
133 }
134 }
135 }
137 return ($message);
138 }
141 /* Save to LDAP */
142 function save()
143 {
144 plugin::save();
146 /* Remove all empty values */
147 if ($this->orig_dn == 'new'){
148 $attrs= array();
149 foreach ($this->attrs as $key => $val){
150 if (is_array($val) && count($val) == 0){
151 continue;
152 }
153 $attrs[$key]= $val;
154 }
155 $this->attrs= $attrs;
156 }
158 /* Write back to ldap */
159 $ldap= $this->config->get_ldap_link();
160 if ($this->orig_dn == 'new'){
161 $ldap->cd($this->config->current['BASE']);
162 $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
163 $ldap->cd($this->dn);
164 $ldap->add($this->attrs);
165 $this->handle_post_events("add");
166 } else {
167 if ($this->orig_dn != $this->dn){
168 $this->move($this->orig_dn, $this->dn);
169 }
171 $ldap->cd($this->dn);
172 $this->cleanup();
173 $ldap->modify ($this->attrs);
175 $this->handle_post_events("modify");
176 }
178 $this->netConfigDNS->cn = $this->cn;
179 $this->netConfigDNS->save($this->dn);
181 show_ldap_error($ldap->get_error());
183 /* Optionally execute a command after we're done */
184 $this->postcreate();
185 }
187 }
189 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
190 ?>