4c850812879a4e54194c56de1bca65ee42ddda26
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 $macAddress= "";
18 var $ipHostNumber= "";
19 var $description= "";
20 var $orig_dn= "";
22 /* attribute list for save action */
23 var $attributes= array("cn", "description", "macAddress", "ipHostNumber");
24 var $objectclasses= array("top", "device", "ipHost", "ieee802Device");
26 function componentgeneric ($config, $dn= NULL)
27 {
28 plugin::plugin ($config, $dn);
30 /* Set base */
31 if ($this->dn == "new"){
32 $ui= get_userinfo();
33 $this->base= dn2base($ui->dn);
34 $this->cn= "";
35 } else {
36 $this->base= preg_replace ("/^[^,]+,[^,]+,[^,]+,/", "", $this->dn);
37 }
39 /* Save dn for later references */
40 $this->orig_dn= $this->dn;
41 }
43 function execute()
44 {
45 /* Do we represent a valid phone? */
46 if (!$this->is_account && $this->parent == NULL){
47 $display= "<img alt=\"\" src=\"images/stop.png\" align=middle> <b>".
48 _("This 'dn' has no network features.")."</b>";
49 return($display);
50 }
52 /* Fill templating stuff */
53 $smarty= get_smarty();
54 $smarty->assign("bases", $this->config->idepartments);
56 /* Assign attributes */
57 foreach ($this->attributes as $attr){
58 $smarty->assign($attr."ACL", chkacl($this->acl, $attr));
59 $smarty->assign("$attr", $this->$attr);
60 }
61 $smarty->assign("base_select", $this->base);
63 /* Show main page */
64 $smarty->assign("netconfig", dirname(__FILE__)."/network.tpl");
65 return($smarty->fetch (get_template_path('component.tpl', TRUE)));
66 }
68 function remove_from_parent()
69 {
70 $ldap= $this->config->get_ldap_link();
71 $ldap->rmdir($this->dn);
72 show_ldap_error($ldap->get_error());
73 $this->handle_post_events("remove");
75 /* Delete references to object groups */
76 $ldap->cd ($this->config->current['BASE']);
77 $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".$this->dn."))", array("cn"));
78 while ($ldap->fetch()){
79 $og= new ogroup($this->config, $ldap->getDN());
80 unset($og->member[$this->dn]);
81 $og->save ();
82 }
84 }
87 /* Save data to object */
88 function save_object()
89 {
90 plugin::save_object();
92 /* Save base, since this is no LDAP attribute */
93 if (isset($_POST['base']) && chkacl($this->acl, "create") == ""){
94 $this->base= $_POST['base'];
95 }
96 }
99 /* Check supplied data */
100 function check()
101 {
102 $message= array();
103 $this->dn= "cn=".$this->cn.",ou=netdevices,ou=systems,".$this->base;
105 /* must: cn, macAddress, ipHostNumber */
106 if ($this->cn == "" && chkacl ($this->acl, "cn") == ""){
107 $message[]= _("The required field 'Component name' is not set.");
108 }
109 if ($this->macAddress == "" && chkacl ($this->acl, "macAddress") == ""){
110 $message[]= _("The required field 'MAC-address' is not set.");
111 }
112 if ($this->ipHostNumber == "" && chkacl ($this->acl, "ipHostNumber") == ""){
113 $message[]= _("The required field 'IP-address' 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 $ldap->modify($this->attrs);
173 $this->handle_post_events("modify");
174 }
175 show_ldap_error($ldap->get_error());
177 /* Optionally execute a command after we're done */
178 $this->postcreate();
179 }
181 }
183 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
184 ?>