1 <?php
3 class goFonServer extends goService{
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";
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 var $view_logged =FALSE;
29 var $orig_dn = "";
31 function goFonServer(&$config,$dn)
32 {
33 goService::goService($config,$dn);
34 $this->DisplayName = _("VoIP service");
36 $this->orig_dn = $dn;
37 }
40 function execute()
41 {
42 if($this->is_account && !$this->view_logged){
43 $this->view_logged = TRUE;
44 new log("view","server/".get_class($this),$this->dn);
45 }
47 $smarty = get_smarty();
48 foreach($this->attributes as $attr){
49 $smarty->assign($attr,$this->$attr);
50 }
52 /* Assign acls */
53 $tmp = $this->plInfo();
54 foreach($tmp['plProvidedAcls'] as $name => $translation){
55 $smarty->assign($name."ACL",$this->getacl($name));
56 }
58 return($smarty->fetch(get_template_path("goFonServer.tpl",TRUE,dirname(__FILE__))));
59 }
62 function getListEntry()
63 {
64 $fields = goService::getListEntry();
65 $fields['Message'] = _("VoIP service - Asterisk management");
66 $fields['AllowEdit'] = true;
67 return($fields);
68 }
70 function check()
71 {
72 $message = plugin::check();
73 if (empty($this->goFonAdmin)){
74 $message[]= _("The attribute DB user is empty or contains invalid characters.");
75 }
76 if (empty($this->goFonPassword)){
77 $message[]= _("The attribute password is empty or contains invalid characters.");
78 }
79 if (empty($this->goFonAreaCode)){
80 $message[]= _("The attribute local dial prefix is empty or contains invalid characters.");
81 }
82 if (empty($this->goFonCountryCode)){
83 $message[]= _("The attribute country dial prefix is empty or contains invalid characters.");
84 }
85 return($message);
86 }
89 function save_object()
90 {
91 if(isset($_POST['goFonServerPosted'])){
92 plugin::save_object();
93 }
94 }
97 function allow_remove()
98 {
99 /* Check if we are able to remove the asterisk database. If the database is still in use skip */
100 if($this->is_account){
101 $ldap = $this->config->get_ldap_link();
102 $ldap->cd($this->config->current['BASE']);
103 $ldap->search("(&(goFonHomeServer=".$this->dn.")(|(uid=*)(cn=*)))",array("dn","uid","cn","goFonHomeServer"));
104 if($ldap->count()){
106 /* Number of entries shown in warning */
107 $i = 3;
108 $str = "";
109 while(($attrs = $ldap->fetch()) && $i >= 0){
110 $i --;
111 if(isset($attrs['uid'][0])){
112 $str .= $attrs['uid'][0]." ";
113 }else{
114 $str .= $attrs['cn'][0]." ";
115 }
116 }
118 /* Some entries found */
119 if($i != 3){
120 return(sprintf(_("You can't remove the asterisk database extension, it is still in use by these objects '%s'."),trim($str)));
121 }
122 }
123 }
124 }
127 function save()
128 {
129 goService::save();
130 /* Update goFonAccounts if server was is renamed.
131 Set attribute goFonHomeServer to current dn
132 */
133 if(in_array("goFonServer",$this->objectclasses)){
134 if($this->orig_dn != "new" && $this->orig_dn != $this->dn){
135 $ldap = $this->config->get_ldap_link();
136 $ldap->cd($this->config->current['BASE']);
137 $ldap->search("(&(goFonHomeServer=".$this->orig_dn.")(|(objectClass=goFonAccount)(objectClass=goFonConference)))",array("goFonHomeServer"));
138 $dns = array();
139 while($attrs = $ldap->fetch()){
140 $dns[] = $attrs['dn'];
141 }
142 foreach($dns as $dn){
143 $ldap->cd($dn);
144 $ldap->modify(array("goFonHomeServer" => $this->dn));
145 if (!$ldap->success()){
146 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $dn, LDAP_MOD, get_class()));
147 }
148 }
149 }
151 /* Updated config list of gofon servers */
152 if($this->orig_dn == "new" || $this->orig_dn != $this->dn){
153 $config = session::get('config');
154 $config->load_servers();
155 session::set('config',$config);
156 }
157 }
158 }
161 /* Return plugin informations for acl handling */
162 static function plInfo()
163 {
164 return (array(
165 "plShortName" => _("VoIP service"),
166 "plDescription" => _("VoIP - asterisk management")." ("._("Services").")",
167 "plSelfModify" => FALSE,
168 "plDepends" => array(),
169 "plPriority" => 92,
170 "plSection" => array("administration"),
171 "plCategory" => array("server"),
173 "plProvidedAcls"=> array(
174 "start" => _("Start"),
175 "stop" => _("Stop"),
176 "restart" => _("Restart"),
178 "goFonAdmin" => _("Admin"),
179 "goFonPassword" => _("Password"),
180 "goFonAreaCode" => _("Area code"),
181 "goFonCountryCode"=> _("Country code"))
182 ));
183 }
184 }
185 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
186 ?>