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();
13 /* Needed values and lists */
14 var $base= "";
15 var $cn= "";
16 var $macAddress= "";
17 var $ipHostNumber= "";
18 var $description= "";
19 var $orig_dn= "";
21 /* attribute list for save action */
22 var $attributes= array("cn", "description", "macAddress", "ipHostNumber");
23 var $objectclasses= array("top", "device", "ipHost", "ieee802Device");
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 }
38 /* Save dn for later references */
39 $this->orig_dn= $this->dn;
40 }
42 function execute()
43 {
44 /* Do we represent a valid phone? */
45 if (!$this->is_account && $this->parent == NULL){
46 $display= "<img src=\"images/stop.png\" align=center> <b>".
47 _("This 'dn' has no network features.")."</b>";
48 return($display);
49 }
51 /* Fill templating stuff */
52 $smarty= get_smarty();
53 $smarty->assign("bases", $this->config->idepartments);
55 /* Assign attributes */
56 foreach ($this->attributes as $attr){
57 $smarty->assign($attr."ACL", chkacl($this->acl, $attr));
58 $smarty->assign("$attr", $this->$attr);
59 }
60 $smarty->assign("base_select", $this->base);
62 /* Show main page */
63 $smarty->assign("netconfig", dirname(__FILE__)."/network.tpl");
64 return($smarty->fetch (get_template_path('component.tpl', TRUE)));
65 }
67 function remove_from_parent()
68 {
69 $ldap= $this->config->get_ldap_link();
70 $ldap->rmdir($this->dn);
71 show_ldap_error($ldap->get_error());
72 $this->handle_post_events("remove");
74 /* Delete references to object groups */
75 $ldap->cd ($this->config->current['BASE']);
76 $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".$this->dn."))", array("cn"));
77 while ($ldap->fetch()){
78 $og= new ogroup($this->config, $ldap->getDN());
79 unset($og->member[$this->dn]);
80 $og->save ();
81 }
83 }
86 /* Save data to object */
87 function save_object()
88 {
89 plugin::save_object();
91 /* Save base, since this is no LDAP attribute */
92 if (isset($_POST['base']) && chkacl($this->acl, "create") == ""){
93 $this->base= $_POST['base'];
94 }
95 }
98 /* Check supplied data */
99 function check()
100 {
101 $message= array();
102 $this->dn= "cn=".$this->cn.",ou=netdevices,ou=systems,".$this->base;
104 /* must: cn, macAddress */
105 if ($this->cn == "" && chkacl ($this->acl, "cn") == ""){
106 $message[]= "The required field 'Component name' is not set.";
107 }
108 if ($this->macAddress == "" && chkacl ($this->acl, "macAddresscn") == ""){
109 $message[]= "The required field 'MAC-address' is not set.";
110 }
112 $ui= get_userinfo();
113 $acl= get_permissions ($this->dn, $ui->subtreeACL);
114 $acl= get_module_permission($acl, "component", $this->dn);
115 if (chkacl($acl, "create") != ""){
116 $message[]= _("You have no permissions to create a component on this 'Base'.");
117 }
119 if ($this->orig_dn != $this->dn){
120 $ldap= $this->config->get_ldap_link();
121 $ldap->cd ($this->base);
122 $ldap->search ("(cn=".$this->cn.")", array("cn"));
123 if ($ldap->count() != 0){
124 while ($attrs= $ldap->fetch()){
125 if ($attrs['dn'] != $this->orig_dn){
126 $message[]= sprintf (_("There is already an entry '%s' in the base choosen by you"), $this->cn);
127 break;
128 }
129 }
130 }
131 }
133 return ($message);
134 }
137 /* Save to LDAP */
138 function save()
139 {
140 plugin::save();
142 /* Remove all empty values */
143 if ($this->orig_dn == 'new'){
144 $attrs= array();
145 foreach ($this->attrs as $key => $val){
146 if (is_array($val) && count($val) == 0){
147 continue;
148 }
149 $attrs[$key]= $val;
150 }
151 $this->attrs= $attrs;
152 }
154 /* Write back to ldap */
155 $ldap= $this->config->get_ldap_link();
156 if ($this->orig_dn == 'new'){
157 $ldap->cd($this->config->current['BASE']);
158 $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
159 $ldap->cd($this->dn);
160 $ldap->add($this->attrs);
161 $this->handle_post_events("add");
162 } else {
163 if ($this->orig_dn != $this->dn){
164 $this->move($this->orig_dn, $this->dn);
165 }
167 $ldap->cd($this->dn);
168 $ldap->modify($this->attrs);
169 $this->handle_post_events("modify");
170 }
171 show_ldap_error($ldap->get_error());
173 /* Optionally execute a command after we're done */
174 $this->postcreate();
175 }
177 }
179 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
180 ?>