Changeset 7143

Show
Ignore:
Timestamp:
10/26/08 03:31:29 (3 years ago)
Author:
xrobau
Message:

This is actually functional now. It works! Still need to implement the 'overrides', but basic call routing is now working. I need someone to send me a list of US and UK (and anywhere else) exchanges, their number ranges, and their geographical locations, so I can implement this for more than just Australia.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • contributed_modules/modules/cidroute/agi-bin/cidrouting.agi

    r7138 r7143  
    7474 
    7575// Just incase something insane goes wrong wtih the sql query, we grab the die_freepbx function 
    76 // and redirect it to agi->debug.. This SHOULDN'T exist here, unless it's moved into db_connect.php 
    77 // which I really don't expect it to be, but hey. Better safe than sorry. 
     76// and redirect it to agi->debug.. This SHOULDN'T exist here, unless for some insane reason  
     77// that function has been it's moved into db_connect.php.  I really don't expect it to be, but 
     78// hey. Better safe than sorry. 
    7879 
    7980if (!function_exists("die_freepbx")) { 
     
    8586$res = sql("select dest from cidroute_override where number='".$cidnum."'", "getRow"); 
    8687if (isset($res[0])) { 
    87   debug("Override: Found a result - {$res[0]}", 1); 
    88   exit; 
     88  if (strlen($res[0]) != 0) { 
     89    debug("CIDRouting: (Override) Found a result {$res[0]}", 2); 
     90    dial($res[0]); 
     91    exit; 
     92  } else { 
     93    debug("** ERROR: CIDRouting: (Override) Found a result, but it's EMPTY", 0); 
     94    exit; 
     95  } 
    8996} else { 
    90   debug("Override: No results", 1); 
     97  debug("CIDRouting: (Override) No results", 3); 
    9198} 
    9299 
     
    96103if (isset($res[0])) { 
    97104  if (strlen($res[0]) != 0) { 
    98     debug("Lookup: Found a result - {$res[0]}", 1); 
    99     exit
     105    debug("CIDRouting: (Lookup) Found a result - {$res[0]}", 2); 
     106    dial($res[0])
    100107  } else { 
    101     debug("Found a result, but it's EMPTY", 1); 
     108    debug("** ERROR: CIDRouting: (Lookup) Found a result, but it's EMPTY", 0); 
    102109  } 
    103110} else { 
    104   debug("Lookup: No results", 1); 
     111  debug("CIDRouting: (Lookup) No results - continuing on with standard dialplan", 1); 
    105112} 
    106  
    107  
    108  
    109  
    110113 
    111114// All the useful tools here.. 
     
    147150} 
    148151 
     152function goto($res) { 
     153  global $AGI; 
    149154 
    150  
     155  $arr=explode(",", $res); 
     156  $AGI->exec_dial($arr[0], $arr[1], $arr[2]); 
     157
     158   
     159?> 
  • contributed_modules/modules/cidroute/functions.inc.php

    r7133 r7143  
    3636//   will be re-licenced under v2 of the GPL. 
    3737 
     38 
     39// Stick this in the DID page. 
    3840function cidroute_hook_core($viewing_itemid, $target_menuid) { 
    3941  $html = ''; 
     
    6264} 
    6365 
     66function cidroute_hookGet_config($engine) { 
     67  global $ext;   
     68  switch($engine) { 
     69    case "asterisk": 
     70      $trunks = cidroute_get_trunks(); 
     71      // Returns ("12345/", "23456/", "/"); 
     72      if(is_array($trunks)) { 
     73        foreach($trunks as $trunk) { 
     74          $arr = explode("/", $trunk[0]); 
     75          print_r($arr); 
     76          if (empty($arr[0])) { 
     77            $dest = "_."; 
     78          } else { 
     79            $dest = $arr[0]; 
     80          } 
     81          if (empty($arr[1])) { 
     82            $cid = "";  
     83          } else { 
     84            $cid = "/".$arr[1]; 
     85          } 
     86          $context = "ext-did-0002"; 
     87                                        $exten = "$dest$cid"; 
     88          $ext->splice($context, $exten, 1, new ext_agi('cidrouting.agi')); 
    6489 
    65 function cidroute_hookProcess_core($viewing_itemid, $request) { 
    66    
    67   if (!isset($request['action'])) 
    68     return; 
    69   global $db; 
    70   switch ($request['action']) { 
    71     case 'addIncoming': 
    72       $results = sql(sprintf('INSERT INTO cidroute_config (trunk, enabled) VALUES ("%s", %d)',  
    73         $db->escapeSimple($request['extdisplay']), $request['cidroute'])); 
    74     break; 
    75     case 'delIncoming': 
    76       $results = sql(sprintf("DELETE FROM cidroute_config WHERE trunk = '%s'", 
    77         $db->escapeSimple($request['extdisplay'])));  
    78     break; 
    79     case 'edtIncoming': // deleting and adding as in core module 
    80       $results = sql(sprintf("DELETE FROM cidroute_config WHERE trunk = '%s'", 
    81         $db->escapeSimple($request['extdisplay'])));  
    82       $results = sql(sprintf('INSERT INTO cidroute_config (trunk, enabled) VALUES ("%s", %d)',  
    83         $db->escapeSimple($request['extdisplay']), $request['cidroute'])); 
     90        } 
     91      } 
    8492    break; 
    8593  } 
    8694} 
    8795 
    88  
    89 function cidroute_hookGet_config($engine) { 
    90   global $ext;   
    91 //  switch($engine) { 
    92 //    case "asterisk": 
    93 //      $pairing = cidroute_did_list(); 
    94 //      if(is_array($pairing)) { 
    95 //        foreach($pairing as $item) { 
    96 //          if ($item['cidroute_id'] != 0) { 
    97 // 
    98 //            // Code from modules/core/functions.inc.php core_get_config inbound routes 
    99 //            $exten = trim($item['extension']); 
    100 //            $cidnum = trim($item['cidnum']); 
    101 //             
    102 //            if ($cidnum != '' && $exten == '') { 
    103 //              $exten = '_.'; 
    104 //              $pricid = ($item['pricid']) ? true:false; 
    105 //            } else if (($cidnum != '' && $exten != '') || ($cidnum == '' && $exten == '')) { 
    106 //              $pricid = true; 
    107 //            } else { 
    108 //              $pricid = false; 
    109 //            } 
    110 //            $context = ($pricid) ? "ext-did-0001":"ext-did-0002"; 
    111 // 
    112 //            $exten = (empty($exten)?"s":$exten); 
    113 //            $exten = $exten.(empty($cidnum)?"":"/".$cidnum); //if a CID num is defined, add it 
    114 // 
    115 //            $ext->splice($context, $exten, 1, new ext_gosub('1', 'cidroute_'.$item['cidroute_id'], 'cidroute')); 
    116 //           
    117 //          } 
    118 //        } 
    119 //      } 
    120 //    break; 
    121 //  } 
     96function cidroute_get_trunks() { 
     97  $res = sql("select trunk from cidroute_config where enabled='1'", "getAll"); 
     98  if (is_array($res)) { 
     99    foreach ($res as $r) { 
     100      $arr[]=$r[0]; 
     101    } 
     102    return $res; 
     103  } 
     104  return null; 
    122105} 
    123  
    124 /* 
    125 //  Generates dialplan for cidroute, call from retrieve_conf 
    126 */ 
    127  
    128 function cidroute_get_config($engine) { 
    129   global $ext;  
    130   global $asterisk_conf; 
    131 //  switch($engine) { 
    132 //    case "asterisk": 
    133 //      $sources = cidroute_list(); 
    134 //      if(is_array($sources)) { 
    135 //        foreach($sources as $item) { 
    136 // 
    137 //          // Search for number in the cache, if found lookupcidnum and return 
    138 //          if ($item['cidroute_id'] != 0)  { 
    139 //            if ($item['cache'] == 1 && $item['sourcetype'] != 'internal') { 
    140 //              $ext->add('cidroute', 'cidroute_'.$item['cidroute_id'], '', new ext_gotoif('$[${DB_EXISTS(cidname/${CALLERID(num)})} = 1]', 'cidroute,cidroute_return,1')); 
    141 //            } 
    142 //          } 
    143 // 
    144 //          switch($item['sourcetype']) { 
    145 // 
    146 //            case "internal": 
    147 //              $ext->add('cidroute', 'cidroute_'.$item['cidroute_id'], '', new ext_lookupcidname('')); 
    148 //            break; 
    149 // 
    150 //            case "enum": 
    151 //              $ext->add('cidroute', 'cidroute_'.$item['cidroute_id'], '', new ext_txtcidname('${CALLERID(num)}')); 
    152 //              $ext->add('cidroute', 'cidroute_'.$item['cidroute_id'], '', new ext_setvar('CALLERID(name)', '${TXTCIDNAME}')); 
    153 //            break; 
    154 // 
    155 //            case "http": 
    156 //              if (!empty($item['http_username']) && !empty($item['http_password'])) 
    157 //                $auth = sprintf('%s:%s@', $item['http_username'], $item['http_password']); 
    158 //              else 
    159 //                $auth = ''; 
    160 //                 
    161 //              if (!empty($item['http_port'])) 
    162 //                $host = sprintf('%s:%d', $item['http_host'], $item['http_port']); 
    163 //              else 
    164 //                $host = $item['http_host'].':80'; 
    165 // 
    166 //              if (substr($item['http_path'], 0, 1) == '/') 
    167 //                $path = substr($item['http_path'], 1); 
    168 //              else 
    169 //                $path = $item['http_path']; 
    170 //                 
    171 //              $query = str_replace('[NUMBER]', '${CALLERID(num)}', $item['http_query']); 
    172 //              $url = sprintf('http://%s%s/%s?%s', $auth, $host, $path, $query); 
    173 //              $curl = sprintf('${CURL(%s)}', $url); 
    174 //               
    175 //              $ext->add('cidroute', 'cidroute_'.$item['cidroute_id'], '', new ext_setvar('CALLERID(name)', $curl)); 
    176 //            break; 
    177 // 
    178 //            case "mysql": 
    179 //              //Escaping MySQL query - thanks to http://www.asteriskgui.com/index.php?get=utilities-mysqlscape 
    180 // 
    181 //              $replacements = array ( 
    182 //                  '\\' => '\\\\', 
    183 //                  '"' => '\\"', 
    184 //                  '\'' => '\\\'', 
    185 //                  ' ' => '\\ ', 
    186 //                  ',' => '\\,', 
    187 //                  '(' => '\\(', 
    188 //                  ')' => '\\)', 
    189 //                  '.' => '\\.', 
    190 //                  '|' => '\\|' 
    191 //              ); 
    192 //               
    193 //              $query = str_replace(array_keys($replacements), array_values($replacements), $item['mysql_query']); 
    194 //              $query = str_replace('[NUMBER]', '${CALLERID(num)}', $query); 
    195 // 
    196 //              $ext->add('cidroute', 'cidroute_'.$item['cidroute_id'], '', new ext_mysql_connect('connid', $item['mysql_host'],  $item['mysql_username'],  $item['mysql_password'],  $item['mysql_dbname']));               
    197 //              $ext->add('cidroute', 'cidroute_'.$item['cidroute_id'], '', new ext_mysql_query('resultid', 'connid', $query)); 
    198 //              $ext->add('cidroute', 'cidroute_'.$item['cidroute_id'], '', new ext_mysql_fetch('fetchid', 'resultid', 'CALLERID(name)')); 
    199 //              $ext->add('cidroute', 'cidroute_'.$item['cidroute_id'], '', new ext_mysql_clear('resultid'));              
    200 //              $ext->add('cidroute', 'cidroute_'.$item['cidroute_id'], '', new ext_mysql_disconnect('connid')); 
    201 //            break; 
    202 // 
    203 //            // TODO: implement SugarCRM lookup, look at code snippet at http://nerdvittles.com/index.php?p=82 
    204 //            case "sugarcrm": 
    205 //              $ext->add('cidroute', 'cidroute_'.$item['cidroute_id'], '', new ext_noop('SugarCRM not yet implemented')); 
    206 //              $ext->add('cidroute', 'cidroute_'.$item['cidroute_id'], '', new ext_return('')); 
    207 //            break; 
    208 //          } 
    209 // 
    210 //          // Put numbers in the cache 
    211 //          if ($item['cidroute_id'] != 0)  { 
    212 //            if ($item['cache'] == 1 && $item['sourcetype'] != 'internal') { 
    213 //              $ext->add('cidroute', 'cidroute_'.$item['cidroute_id'], '', new ext_db_put('cidname', '${CALLERID(num)}', '${CALLERID(name)}' )); 
    214 //            } 
    215 //            $ext->add('cidroute', 'cidroute_'.$item['cidroute_id'], '', new ext_return('')); 
    216 //          } 
    217 //        } 
    218 // 
    219 //        $ext->add('cidroute', 'cidroute_return', '', new ext_lookupcidname('')); 
    220 //        $ext->add('cidroute', 'cidroute_return', '', new ext_return('')); 
    221 //      } 
    222 //    break; 
    223 //  } 
    224 
    225  
     106   
     107   
    226108 
    227109function cidroute_list() { 
     
    233115  } 
    234116  return isset($dests)?$dests:null; 
    235 } 
    236  
    237 function cidroute_get($id){ 
    238 //  $results = sql("SELECT * FROM cidroute WHERE cidroute_id = '$id'","getRow",DB_FETCHMODE_ASSOC); 
    239   return isset($results)?$results:null; 
    240117} 
    241118 
     
    314191} 
    315192 
    316 function cidroute_delmaps($post){ 
    317   global $db; 
    318   if (isset($post['myselect'])) { 
    319     // Javascript combo box didn't work.. 
    320     $res = $post['myselect']; 
    321   } elseif (isset($post['myselect_right'])) { 
    322     $res = $post['myselect_right']; 
    323   } else { 
    324     return; 
    325   } 
    326   foreach ($res as $r) { 
    327     $arr = explode("|", $r); 
    328     $q = "delete from cidroute_matches where min_numb='".$arr[0]."' and max_numb='".$arr[1]."'"; 
    329     sql($q); 
    330   }  
    331 } 
    332  
    333 // ensures post vars is valid 
    334 function cidroute_chk($post){ 
    335   // TODO: Add sanity checks on $_POST 
    336   return true; 
    337 } 
    338193?>