1 <?php
3 class goFonServer extends plugin{
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 = "";
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();
65 /* Check if this is a new entry ... add/modify */
66 $ldap = $this->config->get_ldap_link();
67 $ldap->cat($this->dn,array("objectClass"));
68 if($ldap->count()){
69 $ldap->cd($this->dn);
70 $ldap->modify($this->attrs);
71 }else{
72 $ldap->cd($this->dn);
73 $ldap->add($this->attrs);
74 }
75 show_ldap_error($ldap->get_error());
76 $this->handle_post_events("remove");
77 }
80 function save()
81 {
82 plugin::save();
83 /* Check if this is a new entry ... add/modify */
84 $ldap = $this->config->get_ldap_link();
85 $ldap->cat($this->dn,array("objectClass"));
86 if($ldap->count()){
87 $ldap->cd($this->dn);
88 $ldap->modify($this->attrs);
89 }else{
90 $ldap->cd($this->dn);
91 $ldap->add($this->attrs);
92 }
93 show_ldap_error($ldap->get_error());
94 if($this->initially_was_account){
95 $this->handle_post_events("modify");
96 }else{
97 $this->handle_post_events("add");
98 }
99 }
102 /* Directly save new status flag */
103 function setStatus($value)
104 {
105 if($value == "none") return;
106 if(!$this->initially_was_account) return;
107 $ldap = $this->config->get_ldap_link();
108 $ldap->cd($this->dn);
109 $ldap->cat($this->dn,array("objectClass"));
110 if($ldap->count()){
112 $tmp = $ldap->fetch();
113 for($i = 0; $i < $tmp['objectClass']['count']; $i ++){
114 $attrs['objectClass'][] = $tmp['objectClass'][$i];
115 }
116 $flag = $this->StatusFlag;
117 $attrs[$flag] = $value;
118 $this->$flag = $value;
119 $ldap->modify($attrs);
120 show_ldap_error($ldap->get_error());
121 $this->action_hook();
122 }
123 }
126 function check()
127 {
128 $message = plugin::check();
129 if (empty($this->goFonAdmin)){
130 $message[]= sprintf(_("The attribute DB user is empty or contains invalid characters."), $attr);
131 }
132 if (empty($this->goFonPassword)){
133 $message[]= sprintf(_("The attribute password is empty or contains invalid characters."), $attr);
134 }
135 if (empty($this->goFonAreaCode)){
136 $message[]= sprintf(_("The attribute local dial prefix is empty or contains invalid characters."), $attr);
137 }
138 if (empty($this->goFonCountryCode)){
139 $message[]= sprintf(_("The attribute country dial prefix is empty or contains invalid characters."), $attr);
140 }
141 return($message);
142 }
145 function save_object()
146 {
147 if(isset($_POST['goFonServerPosted'])){
148 plugin::save_object();
149 }
150 }
153 function action_hook($add_attrs= array())
154 {
155 /* Find postcreate entries for this class */
156 $command= search_config($this->config->data['MENU'], get_class($this), "ACTION_HOOK");
157 if ($command == "" && isset($this->config->data['TABS'])){
158 $command= search_config($this->config->data['TABS'], get_class($this), "ACTION_HOOK");
159 }
160 if ($command != ""){
161 /* Walk through attribute list */
162 foreach ($this->attributes as $attr){
163 if (!is_array($this->$attr)){
164 $command= preg_replace("/%$attr/", $this->$attr, $command);
165 }
166 }
167 $command= preg_replace("/%dn/", $this->dn, $command);
168 /* Additional attributes */
169 foreach ($add_attrs as $name => $value){
170 $command= preg_replace("/%$name/", $value, $command);
171 }
173 /* If there are still some %.. in our command, try to fill these with some other class vars */
174 if(preg_match("/%/",$command)){
175 $attrs = get_object_vars($this);
176 foreach($attrs as $name => $value){
177 if(!is_string($value)) continue;
178 $command= preg_replace("/%$name/", $value, $command);
179 }
180 }
182 if (check_command($command)){
183 @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__,
184 $command, "Execute");
186 exec($command);
187 } else {
188 $message= sprintf(_("Command '%s', specified as ACTION_HOOK for plugin '%s' doesn't seem to exist."), $command, get_class($this));
189 print_red ($message);
190 }
191 }
192 }
194 /* Get updates for status flag */
195 function updateStatusState()
196 {
197 if(empty($this->StatusFlag)) return;
199 $attrs = array();
200 $flag = $this->StatusFlag;
201 $ldap = $this->config->get_ldap_link();
202 $ldap->cd($this->cn);
203 $ldap->cat($this->dn,array($flag));
204 if($ldap->count()){
205 $attrs = $ldap->fetch();
206 }
207 if(isset($attrs[$flag][0])){
208 $this->$flag = $attrs[$flag][0];
209 }
210 }
211 }
212 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
213 ?>