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

Revision 7570, 9.7 kB (checked in by ethans, 4 years ago)

Strange, saw a system that had CID number set to Unknown. Added a conditional to the dialplan to accomodate.

  • 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 if( !class_exists('extension') ) {
21   require('extensions.class.php');
22 }
23 function blacklist_get_config($engine) {
24         global $ext;
25         global $version;
26         switch($engine) {
27                 case "asterisk":
28
29           $id = "app-blacklist";
30           $ext->addInclude('from-internal-additional', $id); // Add the include from from-internal
31
32           $id = "app-blacklist-check";
33           $c = "s";
34           // LookupBlackList doesn't seem to match empty astdb entry for "blacklist/", so we
35           // need to check for the setting and if set, send to the blacklisted area
36           // The gotoif below is not a typo.  For some reason, we've seen the CID number set to Unknown
37                       $ext->add($id, $c, '', new ext_gotoif('$["${CALLERID(number)}" = "Unknown"]','check-blocked'));
38                       $ext->add($id, $c, '', new ext_gotoif('$["${CALLERID(number)}" = ""]','check-blocked','check'));
39                       $ext->add($id, $c, 'check-blocked', new ext_gotoif('$["${DB(blacklist/blocked)}" = "1"]','blacklisted'));
40
41                       if (version_compare($version, "1.6", "ge")) {
42                              $ext->add($id, $c, 'check', new ext_gotoif('$["${BLACKLIST()}"="1"]', 'blacklisted'));
43                       } else {
44                              $ext->add($id, $c, 'check', new ext_lookupblacklist(''));
45                              $ext->add($id, $c, '', new ext_gotoif('$["${LOOKUPBLSTATUS}"="FOUND"]', 'blacklisted'));
46                       }
47                       $ext->add($id, $c, '', new ext_return(''));
48                       $ext->add($id, $c, 'blacklisted', new ext_answer(''));
49                       $ext->add($id, $c, '', new ext_wait(1));
50                       $ext->add($id, $c, '', new ext_zapateller(''));
51                       $ext->add($id, $c, '', new ext_playback('ss-noservice'));
52                       $ext->add($id, $c, '', new ext_hangup(''));
53
54           $modulename = 'blacklist';
55
56                         if (is_array($featurelist = featurecodes_getModuleFeatures($modulename))) {
57                                 foreach($featurelist as $item) {
58                                         $featurename = $item['featurename'];
59                                         $fname = $modulename.'_'.$featurename;
60                                         if (function_exists($fname)) {
61                                                 $fcc = new featurecode($modulename, $featurename);
62                                                 $fc = $fcc->getCodeActive();
63                                                 unset($fcc);
64
65                                                 if ($fc != '')
66                                                         $fname($fc);
67                                         } else {
68                                                 $ext->add('from-internal-additional', 'debug', '', new ext_noop($modulename.": No func $fname"));
69                                                 var_dump($item);
70                                         }
71                                 }
72                         }
73
74                       break;
75         }
76 }
77
78 function blacklist_blacklist_add($fc) {
79   global $ext;
80
81   $ext->add('app-blacklist', $fc, '', new ext_goto('1', 's', 'app-blacklist-add'));
82
83   $id = "app-blacklist-add";
84   $c = "s";
85   $ext->add($id, $c, '', new ext_answer);
86   $ext->add($id, $c, '', new ext_wait(1));
87   $ext->add($id, $c, '', new ext_playback('enter-num-blacklist'));
88   $ext->add($id, $c, '', new ext_digittimeout(5));
89   $ext->add($id, $c, '', new ext_responsetimeout(60));
90   $ext->add($id, $c, '', new ext_read('blacknr', 'then-press-pound'));
91   $ext->add($id, $c, '', new ext_saydigits('${blacknr}'));
92   $ext->add($id, $c, '', new ext_playback('if-correct-press&digits/1'));
93   $ext->add($id, $c, '', new ext_noop('Waiting for input'));
94   $ext->add($id, $c, 'end', new ext_waitexten(60));
95   $ext->add($id, $c, '', new ext_playback('sorry-youre-having-problems&goodbye'));
96   $c = "1";
97   $ext->add($id, $c, '', new ext_set('DB(blacklist/${blacknr})', 1));
98   $ext->add($id, $c, '', new ext_playback('num-was-successfully&added'));
99   $ext->add($id, $c, '', new ext_wait(1));
100   $ext->add($id, $c, '', new ext_hangup);
101 }
102
103 function blacklist_blacklist_remove($fc) {
104   global $ext;
105
106   $ext->add('app-blacklist', $fc, '', new ext_goto('1', 's', 'app-blacklist-remove'));
107
108   $id = "app-blacklist-remove";
109   $c = "s";
110   $ext->add($id, $c, '', new ext_answer);
111   $ext->add($id, $c, '', new ext_wait(1));
112   $ext->add($id, $c, '', new ext_playback('entr-num-rmv-blklist'));
113   $ext->add($id, $c, '', new ext_digittimeout(5));
114   $ext->add($id, $c, '', new ext_responsetimeout(60));
115   $ext->add($id, $c, '', new ext_read('blacknr', 'then-press-pound'));
116   $ext->add($id, $c, '', new ext_saydigits('${blacknr}'));
117   $ext->add($id, $c, '', new ext_playback('if-correct-press&digits/1'));
118   $ext->add($id, $c, '', new ext_noop('Waiting for input'));
119   $ext->add($id, $c, 'end', new ext_waitexten(60));
120   $ext->add($id, $c, '', new ext_playback('sorry-youre-having-problems&goodbye'));
121   $c = "1";
122   $ext->add($id, $c, '', new ext_dbdel('blacklist/${blacknr}'));
123   $ext->add($id, $c, '', new ext_playback('num-was-successfully&removed'));
124   $ext->add($id, $c, '', new ext_wait(1));
125   $ext->add($id, $c, '', new ext_hangup);
126 }
127
128 function blacklist_blacklist_last($fc) {
129   global $ext;
130
131   $ext->add('app-blacklist', $fc, '', new ext_goto('1', 's', 'app-blacklist-last'));
132
133   $id = "app-blacklist-last";
134   $c = "s";
135   $ext->add($id, $c, '', new ext_answer);
136   $ext->add($id, $c, '', new ext_wait(1));
137   $ext->add($id, $c, '', new ext_setvar('lastcaller', '${DB(CALLTRACE/${CALLERID(number)})}'));
138   $ext->add($id, $c, '', new ext_gotoif('$[ $[ "${lastcaller}" = "" ] | $[ "${lastcaller}" = "unknown" ] ]', 'noinfo'));
139   $ext->add($id, $c, '', new ext_playback('privacy-to-blacklist-last-caller&telephone-number'));
140   $ext->add($id, $c, '', new ext_saydigits('${lastcaller}'));
141   $ext->add($id, $c, '', new ext_setvar('TIMEOUT(digit)', '3'));
142   $ext->add($id, $c, '', new ext_setvar('TIMEOUT(response)', '7'));
143   $ext->add($id, $c, '', new ext_playback('if-correct-press&digits/1'));
144   $ext->add($id, $c, '', new ext_goto('end'));
145   $ext->add($id, $c, 'noinfo', new ext_playback('unidentified-no-callback'));
146   $ext->add($id, $c, '', new ext_hangup);
147   $ext->add($id, $c, '', new ext_noop('Waiting for input'));
148   $ext->add($id, $c, 'end', new ext_waitexten(60));
149   $ext->add($id, $c, '', new ext_playback('sorry-youre-having-problems&goodbye'));
150   $c = "1";
151   $ext->add($id, $c, '', new ext_set('DB(blacklist/${lastcaller})', 1));
152   $ext->add($id, $c, '', new ext_playback('num-was-successfully'));
153   $ext->add($id, $c, '', new ext_playback('added'));
154   $ext->add($id, $c, '', new ext_wait(1));
155   $ext->add($id, $c, '', new ext_hangup);
156 }
157
158 function blacklist_hookGet_config($engine) {
159   global $ext;
160   switch($engine) {
161     case "asterisk":
162       // Code from modules/core/functions.inc.php core_get_config inbound routes
163       $didlist = core_did_list();
164       if (is_array($didlist)) {
165         foreach ($didlist as $item) {
166
167           $exten = trim($item['extension']);
168           $cidnum = trim($item['cidnum']);
169            
170           if ($cidnum != '' && $exten == '') {
171             $exten = 's';
172             $pricid = ($item['pricid']) ? true:false;
173           } else if (($cidnum != '' && $exten != '') || ($cidnum == '' && $exten == '')) {
174             $pricid = true;
175           } else {
176             $pricid = false;
177           }
178           $context = ($pricid) ? "ext-did-0001":"ext-did-0002";
179
180           $exten = (empty($exten)?"s":$exten);
181           $exten = $exten.(empty($cidnum)?"":"/".$cidnum); //if a CID num is defined, add it
182
183           $ext->splice($context, $exten, 1, new ext_gosub('1', 's', 'app-blacklist-check'));
184         }
185       } // else no DID's defined. Not even a catchall.
186       break;
187   }
188 }
189
190 function blacklist_list() {
191   global $amp_conf;
192   global $astman;
193
194         if ($astman) {
195     $list = $astman->database_show();
196     foreach ($list as $k => $v) {
197       if (substr($k, 1, 9) == 'blacklist')
198       {
199         $numbers[substr($k, 11)] = substr($k, 11);
200       }
201     }
202
203     if (isset($numbers) && is_array($numbers))
204       natcasesort($numbers);
205
206     return isset($numbers)?$numbers:null;
207         } else {
208                 fatal("Cannot connect to Asterisk Manager with ".$amp_conf["AMPMGRUSER"]."/".$amp_conf["AMPMGRPASS"]);
209         }
210 }
211
212 function blacklist_del($number){
213   global $amp_conf;
214   global $astman;
215
216   if ($astman) {
217     $astman->database_del("blacklist",$number);
218   } else {
219     fatal("Cannot connect to Asterisk Manager with ".$amp_conf["AMPMGRUSER"]."/".$amp_conf["AMPMGRPASS"]);
220   }
221 }
222
223 function blacklist_add($post){
224   global $amp_conf;
225   global $astman;
226
227   if(!blacklist_chk($post))
228     return false;
229
230   extract($post);
231   if ($astman) {
232     $astman->database_put("blacklist",$number, '1');
233     // Remove filtering for blocked/unknown cid
234     $astman->database_del("blacklist","blocked");
235     // Add it back if it's checked
236     if($post['blocked'] == "1")  {
237       $astman->database_put("blacklist","blocked", "1");
238       needreload();
239     }
240   } else {
241     fatal("Cannot connect to Asterisk Manager with ".$amp_conf["AMPMGRUSER"]."/".$amp_conf["AMPMGRPASS"]);
242   }
243 }
244
245
246 // ensures post vars is valid
247 function blacklist_chk($post){
248   return true;
249 }
250
251 ?>
Note: See TracBrowser for help on using the browser.