Code

Added server service acls
[gosa.git] / plugins / admin / systems / class_goFonServer.inc
1 <?php
3 class goFonServer extends plugin{
4         
5   var $cli_summary      = "This pluign is used within the ServerService Pluign \nand indicates that this server supports asterisk management.";
6   var $cli_description  = "Some longer text\nfor help";
7   var $cli_parameters   = array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
9   /* This plugin only writes its objectClass */
10   var $objectclasses    = array("goFonServer");
11   var $attributes       = array("goFonAdmin", "goFonPassword","goFonAreaCode", "goFonCountryCode");
12   var $StatusFlag       = "goFonServerStatus";
13  
14   /* This class can't be assigned twice so it conflicts with itsself */
15   var $conflicts        = array("goFonServer");
17   var $DisplayName      = "";
18   var $dn               = NULL;
19   var $cn               ="";
20   var $acl;
22   var $goFonServerStatus  = "";
23   var $goFonPassword      = "";
24   var $goFonAdmin         = "";
25   var $goFonAreaCode      = "";
26   var $goFonCountryCode   = "";
27    
28  
29   function goFonServer($config,$dn)
30   {
31     plugin::plugin($config,$dn);
32     $this->DisplayName = _("VoIP service");
33   }
36   function execute()
37   { 
38     $smarty = get_smarty(); 
39     foreach($this->attributes as $attr){
40       $smarty->assign($attr,$this->$attr);
41       $smarty->assign($attr."ACL",chkacl($this->acl,$attr));
42     }
43     return($smarty->fetch(get_template_path("goFonServer.tpl",TRUE,dirname(__FILE__))));
44   }
47   function getListEntry()
48   {
49     $this->updateStatusState();
50     $flag = $this->StatusFlag;
51     $fields['Status']     = $this->$flag;
52     $fields['Message']    = _("Asterisk management");
53     $fields['AllowStart'] = true;
54     $fields['AllowStop']  = true;
55     $fields['AllowRestart'] = true;
56     $fields['AllowRemove']= true;
57     $fields['AllowEdit']  = true;
58     return($fields);
59   }
62   function remove_from_parent()
63   {
64     plugin::remove_from_parent();
66     /* Remove status flag, it is not a memeber of 
67         this->attributes, so ensure that it is deleted too */
68     if(!empty($this->StatusFlag)){
69       $this->attrs[$this->StatusFlag] = array();
70     }
72     /* Check if this is a new entry ... add/modify */
73     $ldap = $this->config->get_ldap_link();
74     $ldap->cat($this->dn,array("objectClass"));
75     if($ldap->count()){
76       $ldap->cd($this->dn);
77       $ldap->modify($this->attrs);
78     }else{
79       $ldap->cd($this->dn);
80       $ldap->add($this->attrs);
81     }
82     show_ldap_error($ldap->get_error(), sprintf(_("Removing server services/gofon with dn '%s' failed."),$this->dn));
83     $this->handle_post_events("remove");
84   }
87   function save()
88   {
89     plugin::save();
90     /* Check if this is a new entry ... add/modify */
91     $ldap = $this->config->get_ldap_link();
92     $ldap->cat($this->dn,array("objectClass"));
93     if($ldap->count()){
94       $ldap->cd($this->dn);
95       $ldap->modify($this->attrs);
96     }else{
97       $ldap->cd($this->dn);
98       $ldap->add($this->attrs);
99     }
100     show_ldap_error($ldap->get_error(), sprintf(_("Saving server services/gofon with dn '%s' failed."),$this->dn));
101     if($this->initially_was_account){
102       $this->handle_post_events("modify");
103     }else{
104       $this->handle_post_events("add");
105     }
106   }
109   /* Directly save new status flag */
110   function setStatus($value)
111   {
112     if($value == "none") return;
113     if(!$this->initially_was_account) return;
114     $ldap = $this->config->get_ldap_link();
115     $ldap->cd($this->dn);
116     $ldap->cat($this->dn,array("objectClass"));
117     if($ldap->count()){
119       $tmp = $ldap->fetch();
120       for($i = 0; $i < $tmp['objectClass']['count']; $i ++){
121         $attrs['objectClass'][] = $tmp['objectClass'][$i];
122       }
123       $flag = $this->StatusFlag;
124       $attrs[$flag] = $value;
125       $this->$flag = $value;
126       $ldap->modify($attrs);
127       show_ldap_error($ldap->get_error(), sprintf(_("Set status flag for server services/gofon with dn '%s' failed."),$this->dn));
128       $this->action_hook();
129     }
130   }
133   function check()
134   { 
135     $message = plugin::check();
136     if (empty($this->goFonAdmin)){
137       $message[]= sprintf(_("The attribute DB user is empty or contains invalid characters."), $attr);
138     }
139     if (empty($this->goFonPassword)){
140       $message[]= sprintf(_("The attribute password is empty or contains invalid characters."), $attr);
141     }
142     if (empty($this->goFonAreaCode)){
143       $message[]= sprintf(_("The attribute local dial prefix is empty or contains invalid characters."), $attr);
144     }
145     if (empty($this->goFonCountryCode)){
146       $message[]= sprintf(_("The attribute country dial prefix is empty or contains invalid characters."), $attr);
147     }
148     return($message);
149   }
150   
152   function save_object()
153   {
154     if(isset($_POST['goFonServerPosted'])){
155       plugin::save_object();
156     }
157   } 
159   
160    function action_hook($add_attrs= array())
161   {
162     /* Find postcreate entries for this class */
163     $command= search_config($this->config->data['MENU'], get_class($this), "ACTION_HOOK");
164     if ($command == "" && isset($this->config->data['TABS'])){
165       $command= search_config($this->config->data['TABS'], get_class($this), "ACTION_HOOK");
166     }
167     if ($command != ""){
168       /* Walk through attribute list */
169       foreach ($this->attributes as $attr){
170         if (!is_array($this->$attr)){
171           $command= preg_replace("/%$attr/", $this->$attr, $command);
172         }
173       }
174       $command= preg_replace("/%dn/", $this->dn, $command);
175       /* Additional attributes */
176       foreach ($add_attrs as $name => $value){
177         $command= preg_replace("/%$name/", $value, $command);
178       }
180       /* If there are still some %.. in our command, try to fill these with some other class vars */
181       if(preg_match("/%/",$command)){
182         $attrs = get_object_vars($this);
183         foreach($attrs as $name => $value){
184           if(!is_string($value)) continue;
185           $command= preg_replace("/%$name/", $value, $command);
186         }
187       }
189       if (check_command($command)){
190         @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__,
191             $command, "Execute");
193         exec($command);
194       } else {
195         $message= sprintf(_("Command '%s', specified as ACTION_HOOK for plugin '%s' doesn't seem to exist."), $command, get_class($this));
196         print_red ($message);
197       }
198     }
199   }
200  
201   /* Get updates for status flag */
202   function updateStatusState()
203   {
204     if(empty($this->StatusFlag)) return;
206     $attrs = array();
207     $flag = $this->StatusFlag;
208     $ldap = $this->config->get_ldap_link();
209     $ldap->cd($this->cn);
210     $ldap->cat($this->dn,array($flag));
211     if($ldap->count()){
212       $attrs = $ldap->fetch();
213     }
214     if(isset($attrs[$flag][0])){
215       $this->$flag = $attrs[$flag][0];
216     }
217   }
219   
220   /* Return plugin informations for acl handling */
221   function plInfo()
222   {
223     return (array(
224           "plShortName"   => _("GoFon server"),
225           "plDescription" => _("GoFon server service"),
226           "plSelfModify"  => FALSE,
227           "plDepends"     => array(),
228           "plPriority"    => 0,
229           "plSection"     => array("administration"),
230           "plCategory"    => array("server"),
232           "plProvidedAcls"=> array(
233               "goFonAdmin"      => _("Admin"), 
234               "goFonPassword"   => _("Password"),
235               "goFonAreaCode"   => _("Area code"), 
236               "goFonCountryCode"=> _("Country code"))
237           ));
238   }
240 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
241 ?>