root/modules/branches/2.7/blacklist/functions.inc.php

Revision 10816, 9.5 kB (checked in by p_lindheimer, 2 years ago)

fixes #4726 don't require the extensions.class.php file, retrieve_conf does it

  • Property svn:mime-type set to text/plain
  • Property svn:eol-style set to native
Line 
1 <?php /* $Id */
2 //This file is part of FreePBX.
3 //
4 //    FreePBX is free software: you can redistribute it and/or modify
5 //    it under the terms of the GNU General Public License as published by
6 //    the Free Software Foundation, either version 2 of the License, or
7 //    (at your option) any later version.
8 //
9 //    FreePBX is distributed in the hope that it will be useful,
10 //    but WITHOUT ANY WARRANTY; without even the implied warranty of
11 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 //    GNU General Public License for more details.
13 //
14 //    You should have received a copy of the GNU General Public License
15 //    along with FreePBX.  If not, see <http://www.gnu.org/licenses/>.
16 //
17 //  Copyright (C) 2006 Magnus Ullberg (magnus@ullberg.us)
18 //
19
20 function blacklist_get_config($engine) {
21   global $ext;
22   global $version;
23   global $astman;
24   switch($engine) {
25     case "asterisk":
26
27       $id = "app-blacklist";
28       $ext->addInclude('from-internal-additional', $id); // Add the include from from-internal
29
30       $id = "app-blacklist-check";
31       $c = "s";
32       // LookupBlackList doesn't seem to match empty astdb entry for "blacklist/", so we
33       // need to check for the setting and if set, send to the blacklisted area
34       // The gotoif below is not a typo.  For some reason, we've seen the CID number set to Unknown or Unavailable
35       // don't generate the dialplan if they are not using the function
36       //
37       if ($astman->database_get("blacklist","blocked") == '1') {
38         $ext->add($id, $c, '', new ext_gotoif('$["${CALLERID(number)}" = "Unknown"]','check-blocked'));
39         $ext->add($id, $c, '', new ext_gotoif('$["${CALLERID(number)}" = "Unavailable"]','check-blocked'));
40         $ext->add($id, $c, '', new ext_gotoif('$["foo${CALLERID(number)}" = "foo"]','check-blocked','check'));
41         $ext->add($id, $c, 'check-blocked', new ext_gotoif('$["${DB(blacklist/blocked)}" = "1"]','blacklisted'));
42       }
43
44       if (version_compare($version, "1.6", "ge")) {
45         $ext->add($id, $c, 'check', new ext_gotoif('$["${BLACKLIST()}"="1"]', 'blacklisted'));
46       } else {
47         $ext->add($id, $c, 'check', new ext_lookupblacklist(''));
48         $ext->add($id, $c, '', new ext_gotoif('$["${LOOKUPBLSTATUS}"="FOUND"]', 'blacklisted'));
49       }
50       $ext->add($id, $c, '', new ext_setvar('CALLED_BLACKLIST','1'));
51       $ext->add($id, $c, '', new ext_return(''));
52       $ext->add($id, $c, 'blacklisted', new ext_answer(''));
53       $ext->add($id, $c, '', new ext_wait(1));
54       $ext->add($id, $c, '', new ext_zapateller(''));
55       $ext->add($id, $c, '', new ext_playback('ss-noservice'));
56       $ext->add($id, $c, '', new ext_hangup(''));
57
58       $modulename = 'blacklist';
59
60       if (is_array($featurelist = featurecodes_getModuleFeatures($modulename))) {
61         foreach($featurelist as $item) {
62           $featurename = $item['featurename'];
63           $fname = $modulename.'_'.$featurename;
64           if (function_exists($fname)) {
65             $fcc = new featurecode($modulename, $featurename);
66             $fc = $fcc->getCodeActive();
67             unset($fcc);
68
69             if ($fc != '') {
70               $fname($fc);
71             }
72           } else {
73             $ext->add('from-internal-additional', 'debug', '', new ext_noop($modulename.": No func $fname"));
74             var_dump($item);
75           }
76         }
77       }
78
79       break;
80   }
81 }
82
83 function blacklist_blacklist_add($fc) {
84   global $ext;
85
86   $ext->add('app-blacklist', $fc, '', new ext_goto('1', 's', 'app-blacklist-add'));
87
88   $id = "app-blacklist-add";
89   $c = "s";
90   $ext->add($id, $c, '', new ext_answer);
91   $ext->add($id, $c, '', new ext_wait(1));
92   $ext->add($id, $c, '', new ext_set('NumLoops', 0));
93   $ext->add($id, $c, 'start', new ext_playback('enter-num-blacklist'));
94   $ext->add($id, $c, '', new ext_digittimeout(5));
95   $ext->add($id, $c, '', new ext_responsetimeout(60));
96   $ext->add($id, $c, '', new ext_read('blacknr', 'then-press-pound'));
97   $ext->add($id, $c, '', new ext_saydigits('${blacknr}'));
98   $ext->add($id, $c, '', new ext_playback('if-correct-press&digits/1'));
99   $ext->add($id, $c, '', new ext_noop('Waiting for input'));
100   $ext->add($id, $c, 'end', new ext_waitexten(60));
101   $ext->add($id, $c, '', new ext_playback('sorry-youre-having-problems&goodbye'));
102   $c = "1";
103   $ext->add($id, $c, '', new ext_gotoif('$[ "${blacknr}" != ""]','','app-blacklist-add-invalid,s,1'));
104   $ext->add($id, $c, '', new ext_set('DB(blacklist/${blacknr})', 1));
105   $ext->add($id, $c, '', new ext_playback('num-was-successfully&added'));
106   $ext->add($id, $c, '', new ext_wait(1));
107   $ext->add($id, $c, '', new ext_hangup);
108
109   $id = "app-blacklist-add-invalid";
110   $c = "s";
111   $ext->add($id, $c, '', new ext_set('NumLoops','$[${NumLoops} + 1]'));
112   $ext->add($id, $c, '', new ext_playback('pm-invalid-option'));
113   $ext->add($id, $c, '', new ext_gotoif('$[${NumLoops} < 3]','app-blacklist-add,s,start'));
114   $ext->add($id, $c, '', new ext_playback('goodbye'));
115   $ext->add($id, $c, '', new ext_hangup);
116
117 }
118
119 function blacklist_blacklist_remove($fc) {
120   global $ext;
121
122   $ext->add('app-blacklist', $fc, '', new ext_goto('1', 's', 'app-blacklist-remove'));
123
124   $id = "app-blacklist-remove";
125   $c = "s";
126   $ext->add($id, $c, '', new ext_answer);
127   $ext->add($id, $c, '', new ext_wait(1));
128   $ext->add($id, $c, '', new ext_playback('entr-num-rmv-blklist'));
129   $ext->add($id, $c, '', new ext_digittimeout(5));
130   $ext->add($id, $c, '', new ext_responsetimeout(60));
131   $ext->add($id, $c, '', new ext_read('blacknr', 'then-press-pound'));
132   $ext->add($id, $c, '', new ext_saydigits('${blacknr}'));
133   $ext->add($id, $c, '', new ext_playback('if-correct-press&digits/1'));
134   $ext->add($id, $c, '', new ext_noop('Waiting for input'));
135   $ext->add($id, $c, 'end', new ext_waitexten(60));
136   $ext->add($id, $c, '', new ext_playback('sorry-youre-having-problems&goodbye'));
137   $c = "1";
138   $ext->add($id, $c, '', new ext_dbdel('blacklist/${blacknr}'));
139   $ext->add($id, $c, '', new ext_playback('num-was-successfully&removed'));
140   $ext->add($id, $c, '', new ext_wait(1));
141   $ext->add($id, $c, '', new ext_hangup);
142 }
143
144 function blacklist_blacklist_last($fc) {
145   global $ext;
146
147   $ext->add('app-blacklist', $fc, '', new ext_goto('1', 's', 'app-blacklist-last'));
148
149   $id = "app-blacklist-last";
150   $c = "s";
151   $ext->add($id, $c, '', new ext_answer);
152   $ext->add($id, $c, '', new ext_wait(1));
153   $ext->add($id, $c, '', new ext_setvar('lastcaller', '${DB(CALLTRACE/${CALLERID(number)})}'));
154   $ext->add($id, $c, '', new ext_gotoif('$[ $[ "${lastcaller}" = "" ] | $[ "${lastcaller}" = "unknown" ] ]', 'noinfo'));
155   $ext->add($id, $c, '', new ext_playback('privacy-to-blacklist-last-caller&telephone-number'));
156   $ext->add($id, $c, '', new ext_saydigits('${lastcaller}'));
157   $ext->add($id, $c, '', new ext_setvar('TIMEOUT(digit)', '3'));
158   $ext->add($id, $c, '', new ext_setvar('TIMEOUT(response)', '7'));
159   $ext->add($id, $c, '', new ext_playback('if-correct-press&digits/1'));
160   $ext->add($id, $c, '', new ext_goto('end'));
161   $ext->add($id, $c, 'noinfo', new ext_playback('unidentified-no-callback'));
162   $ext->add($id, $c, '', new ext_hangup);
163   $ext->add($id, $c, '', new ext_noop('Waiting for input'));
164   $ext->add($id, $c, 'end', new ext_waitexten(60));
165   $ext->add($id, $c, '', new ext_playback('sorry-youre-having-problems&goodbye'));
166   $c = "1";
167   $ext->add($id, $c, '', new ext_set('DB(blacklist/${lastcaller})', 1));
168   $ext->add($id, $c, '', new ext_playback('num-was-successfully'));
169   $ext->add($id, $c, '', new ext_playback('added'));
170   $ext->add($id, $c, '', new ext_wait(1));
171   $ext->add($id, $c, '', new ext_hangup);
172 }
173
174 function blacklist_hookGet_config($engine) {
175   global $ext;
176   switch($engine) {
177     case "asterisk":
178       // Code from modules/core/functions.inc.php core_get_config inbound routes
179       $didlist = core_did_list();
180       if (is_array($didlist)) {
181         foreach ($didlist as $item) {
182
183           $exten = trim($item['extension']);
184           $cidnum = trim($item['cidnum']);
185            
186           if ($cidnum != '' && $exten == '') {
187             $exten = 's';
188             $pricid = ($item['pricid']) ? true:false;
189           } else if (($cidnum != '' && $exten != '') || ($cidnum == '' && $exten == '')) {
190             $pricid = true;
191           } else {
192             $pricid = false;
193           }
194           $context = ($pricid) ? "ext-did-0001":"ext-did-0002";
195
196           $exten = (empty($exten)?"s":$exten);
197           $exten = $exten.(empty($cidnum)?"":"/".$cidnum); //if a CID num is defined, add it
198
199           $ext->splice($context, $exten, 1, new ext_gosub('1', 's', 'app-blacklist-check'));
200         }
201       } // else no DID's defined. Not even a catchall.
202       break;
203   }
204 }
205
206 function blacklist_list() {
207   global $amp_conf;
208   global $astman;
209
210         if ($astman) {
211     $list = $astman->database_show();
212     foreach ($list as $k => $v) {
213       if (substr($k, 1, 9) == 'blacklist')
214       {
215         $numbers[substr($k, 11)] = substr($k, 11);
216       }
217     }
218
219     if (isset($numbers) && is_array($numbers))
220       natcasesort($numbers);
221
222     return isset($numbers)?$numbers:null;
223         } else {
224                 fatal("Cannot connect to Asterisk Manager with ".$amp_conf["AMPMGRUSER"]."/".$amp_conf["AMPMGRPASS"]);
225         }
226 }
227
228 function blacklist_del($number){
229   global $amp_conf;
230   global $astman;
231
232   if ($astman) {
233     $astman->database_del("blacklist",$number);
234   } else {
235     fatal("Cannot connect to Asterisk Manager with ".$amp_conf["AMPMGRUSER"]."/".$amp_conf["AMPMGRPASS"]);
236   }
237 }
238
239 function blacklist_add($post){
240   global $amp_conf;
241   global $astman;
242
243   if(!blacklist_chk($post))
244     return false;
245
246   extract($post);
247   if ($astman) {
248     $astman->database_put("blacklist",$number, '1');
249     // Remove filtering for blocked/unknown cid
250     $astman->database_del("blacklist","blocked");
251     // Add it back if it's checked
252     if($post['blocked'] == "1")  {
253       $astman->database_put("blacklist","blocked", "1");
254       needreload();
255     }
256   } else {
257     fatal("Cannot connect to Asterisk Manager with ".$amp_conf["AMPMGRUSER"]."/".$amp_conf["AMPMGRPASS"]);
258   }
259 }
260
261
262 // ensures post vars is valid
263 function blacklist_chk($post){
264   return true;
265 }
266
267 ?>
Note: See TracBrowser for help on using the browser.