acd0891721fd2007c00486bcadff82e29b955ae5
1 <?php
3 class phoneGeneric extends plugin
4 {
5 /* CLI vars */
6 var $cli_summary= "Manage phone 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", "goFonHardware");
26 function phonegeneric ($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 phone 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('phone.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=phones,ou=systems,".$this->base;
105 /* must: cn, macAddress, ipHostNumber */
106 if ($this->cn == "" && chkacl ($this->acl, "cn") == ""){
107 $message[]= "The required field 'Phone name' is not set.";
108 }
109 if ($this->cn == "0" && chkacl ($this->acl, "cn") == ""){
110 $message[]= "The 'Phone name' '0' is reserved and cannot be used.";
111 }
112 if ($this->macAddress == "" && chkacl ($this->acl, "macAddress") == ""){
113 $message[]= "The required field 'MAC-Address' is not set.";
114 }
115 if ($this->ipHostNumber == "" && chkacl ($this->acl, "ipHostNumber") == ""){
116 $message[]= "The required field 'IP-Address' is not set.";
117 }
119 $ui= get_userinfo();
120 $acl= get_permissions ($this->dn, $ui->subtreeACL);
121 $acl= get_module_permission($acl, "phone", $this->dn);
122 if (chkacl($acl, "create") != ""){
123 $message[]= _("You have no permissions to create a phone on this 'Base'.");
124 }
126 if ($this->orig_dn != $this->dn){
127 $ldap= $this->config->get_ldap_link();
128 $ldap->cd ($this->base);
129 $ldap->search ("(cn=".$this->cn.")", array("cn"));
130 if ($ldap->count() != 0){
131 while ($attrs= $ldap->fetch()){
132 if ($attrs['dn'] != $this->orig_dn){
133 $message[]= sprintf (_("There is already an entry '%s' in the base choosen by you"), $this->cn);
134 break;
135 }
136 }
137 }
138 }
140 return ($message);
141 }
144 /* Save to LDAP */
145 function save()
146 {
147 plugin::save();
149 /* Remove all empty values */
150 if ($this->orig_dn == 'new'){
151 $attrs= array();
152 foreach ($this->attrs as $key => $val){
153 if (is_array($val) && count($val) == 0){
154 continue;
155 }
156 $attrs[$key]= $val;
157 }
158 $this->attrs= $attrs;
159 }
161 /* Write back to ldap */
162 $ldap= $this->config->get_ldap_link();
163 if ($this->orig_dn == 'new'){
164 $ldap->cd($this->config->current['BASE']);
165 $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
166 $ldap->cd($this->dn);
167 $ldap->add($this->attrs);
168 $this->handle_post_events("add");
169 } else {
170 if ($this->orig_dn != $this->dn){
171 $this->move($this->orig_dn, $this->dn);
172 }
174 $ldap->cd($this->dn);
175 $ldap->modify($this->attrs);
176 $this->handle_post_events("modify");
177 }
178 show_ldap_error($ldap->get_error());
180 /* Optionally execute a command after we're done */
181 $this->postcreate();
182 }
184 }
186 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
187 ?>