Changeset 12982

Show
Ignore:
Timestamp:
11/30/11 03:35:47 (1 year ago)
Author:
p_lindheimer
Message:

move most of static vars out of local channel, do checks for busy and self in agi, simplify page modes, other cleanup, still not done but works and checking in so changes are not lost

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • modules/branches/2.10/paging/agi-bin/page.agi

    r12977 r12982  
    99 
    1010$get = array( 
     11    'ALERTINFO', 
     12    'CALLINFO', 
     13    'SIPURI', 
     14    'VXML_URL', 
     15    'DOPTIONS', 
     16    'DTIME', 
    1117    'AMPUSER', 
    1218    'PAGE_CONF', 
    1319    'PAGE_CONF_OPTS', 
    1420    'PAGE_MEMBERS', 
     21    'PAGEMODE', 
    1522    'STREAM' 
    1623); 
     
    2027} 
    2128 
    22 $vars['PAGE_MEMBERS'] = unserialize(base64_decode($vars['PAGE_MEMBERS'])); 
    2329$vars['STREAM'] = $vars['STREAM'] ? $vars['STREAM'] : 'beep'; 
    2430 
    25 dbug('vars', $vars); 
     31// TODO: this deals with the mainstream ones. We could check in the dialplan if there are any others outside of these and only in that case evoke the 
     32//       new custom macro that gets generated to otherwise deal with these??? 
     33// 
     34 
     35if ($vars['ALERTINFO'] != '') { 
     36  $pass['ALERTINFO'] = $vars['ALERTINFO']; 
     37
     38if ($vars['CALLINFO'] != '') { 
     39  $pass['CALLINFO'] = $vars['CALLINFO']; 
     40
     41if ($vars['SIPURI'] != '') { 
     42  $pass['SIPURI'] = $vars['SIPURI']; 
     43
     44if ($vars['VXML_URL'] != '') { 
     45  $pass['VXML_URL'] = $vars['VXML_URL']; 
     46
     47if ($vars['DOPTIONS'] != '') { 
     48  $pass['DOPTIONS'] = $vars['DOPTIONS']; 
     49
     50if ($vars['DTIME'] != '') { 
     51  $pass['DTIME'] = $vars['DTIME']; 
     52
     53$base_vars = '__FORWARD_CONTEXT=block-cf,AMPUSER=' .  __pad_string($vars['AMPUSER']); 
     54foreach ($pass as $key => $val) { 
     55  $base_vars .= ',' . $key . '=' . __pad_string($val); 
     56
     57 
     58//dbug('vars', $vars); 
    2659 
    2760/* TODO: run through the list here first and check for: 
    28  *       extension -- current device doing the page and yank them out if so 
    29  *       if not force page -- check if target extension (or is it device) is busy if so pull out of list 
    3061 *       future - check if each specific extension needs modifications to auto-answer channel variables 
    3162 *                so the conditional assignments can be skipped 
    32  * 
    33  *       extension will have to be changed to the raw extension and more intelligence added to here to 
    34  *       properly accomodated the above, and then changes to the auto-answer macro, etc. 
    3563 */ 
    3664 
    37 foreach ($vars['PAGE_MEMBERS'] as $ext) {  
    38   /*if (strstr($ext, $vars['AMPUSER'] . '@ext-paging')) { 
     65$page_members = explode('-',$vars['PAGE_MEMBERS']); 
     66 
     67foreach ($page_members as $pm) { 
     68  $pagemode = 'PAGE'; 
     69  $pass_vars = $base_vars; 
     70  // don't page ourselves ever 
     71  if ($pm == $vars['AMPUSER']) { 
    3972    continue; 
    40   }*/ 
     73  } 
     74  // if not force mode, don't page busy extension (NOT_INUSE or ONHOLD are ok to page) 
     75  if ($vars['PAGEMODE'] == 'PAGE') { 
     76    $ext_state = agi_get_var("EXTENSION_STATE($pm)"); 
     77    if ($ext_state != 'NOT_INUSE' && $ext_state != 'ONHOLD') { 
     78      continue; 
     79    } 
     80  } elseif ($vars['PAGEMODE'] == 'SPAGE') { 
     81    $ext_state = agi_get_var("EXTENSION_STATE($pm)"); 
     82    // if not idle but in a state we can try spying, then try 
     83    if ($ext_state != 'NOT_INUSE' && $ext_state != 'ONHOLD') { 
     84      $device = $agi->database_get("DEVICE","$pm/dial"); 
     85      $device = $device['data']; 
     86      $type = explode('/',$device,2); 
     87      if (strtolower($type[0]) != 'sip') { 
     88        continue; 
     89      } 
     90      switch ($ext_state) { 
     91      case "INUSE": 
     92      case "BUSY": 
     93      case "RINGINUSE": 
     94      case "HOLDINUSE": 
     95        // Try SPY 
     96        $pagemode = 'SPAGE'; 
     97        $pass_vars .= ',' . 'SP_DEVICE=' . __pad_string($device); 
     98      break; 
     99      default: 
     100        // State is not amicable to spy or normal (such as RINGING) so skip it 
     101        continue; 
     102      break; 
     103      } 
     104    } 
     105  } 
     106 
    41107  $astman->Originate(array( 
    42               'Channel'   => $ext, 
    43               'CallerID'    => $vars['calleridname'] . ' <' . $vars['callerid'] . '>', 
    44               'Async'     => 'true', 
    45               'Variable'      => 'AMPUSER=' . $vars['AMPUSER'], 
    46               'Application' => ($amp_conf['ASTCONFAPP'] == 'app_confbridge'  
    47                         ? 'ConfBridge' : 'MeetMe'), 
    48               'Data'      => $vars['PAGE_CONF'] . ',' . $vars['PAGE_CONF_OPTS'] . ',,' 
    49               )); 
     108    'Channel'     => "Local/$pagemode" . "$pm@app-paging", 
     109    'CallerID'    => $vars['calleridname'] . ' <' . $vars['callerid'] . '>', 
     110    'Async'       => 'true', 
     111    'Variable'    => $pass_vars, 
     112    'Application' => ($amp_conf['ASTCONFAPP'] == 'app_confbridge' ? 'ConfBridge' : 'MeetMe'), 
     113    'Data'        => $vars['PAGE_CONF'] . ',' . $vars['PAGE_CONF_OPTS'] . ',,' 
     114  )); 
    50115} 
    51116 
     117//TODO: is PAGE_CONF_OPTS correct for both meetme and conf_bridge? 
     118// 
    52119$beep = array( 
    53120    'Channel'   => 'Local/s@app-page-stream', 
    54121    'CallerID'    => 'Playback Stream', 
    55122    'Async'     => 'true', 
    56     'Variable'    => array( 
    57               'PAGE_CONF=' . $vars['PAGE_CONF'], 
    58               'PAGE_CONF_OPTS=xq', 
    59               ), 
     123    'Variable'    => 'PAGE_CONF=' . __pad_string($vars['PAGE_CONF']) . ',' .  'PAGE_CONF_OPTS=xq', 
    60124    'Application' => 'Playback', 
    61125    'Data'      => $vars['STREAM'] 
    62126); 
    63 dbug($beep); 
     127//dbug($beep); 
    64128$astman->Originate($beep); 
    65129 
     
    102166  return ''; 
    103167} 
     168 
     169function __pad_string($string) { 
     170  return str_replace(array('\\',',','='),array('\\\\','\\,','\\='),$string); 
     171} 
    104172?> 
  • modules/branches/2.10/paging/functions.inc.php

    r12977 r12982  
    1111 
    1212function paging_get_config($engine) { 
    13   global $db, $ext, $chan_dahdi, $version, $amp_conf; 
     13  global $db; 
     14  global $ext;  
     15  global $chan_dahdi; 
     16  global $version; 
     17  global $amp_conf; 
    1418  switch($engine) { 
    1519    case "asterisk": 
     
    3539      $callinfo  = 'Call-Info: <uri>\;answer-after=0'; 
    3640      $sipuri    = 'intercom=true'; 
    37       $doptions = '';//'A(beep)'; 
     41      //$doptions = 'A(beep)'; 
    3842      $vxml_url = ''; 
    3943      $dtime = '5'; 
     
    324328      //auto answer stuff 
    325329      //set autoanswer variables 
    326       $ext->add($apppaging, '_AUTOASWER.', '', new ext_setvar('_SIPURI', '')); 
     330      foreach ($custom_vars as $key => $value) { 
     331        $ext->add($apppaging, '_AUTOASWER.', '', new ext_setvar('_'.ltrim($key,'_'), $value)); 
     332      } 
     333      $ext->add($apppaging, '_AUTOASWER.', '', new ext_macro('autoanswer','${EXTEN:9}')); 
     334      $ext->add($apppaging, '_AUTOASWER.', '', new ext_return()); 
     335 
     336      // Setup Variables before AGI script 
     337      // 
     338      $ext->add($apppaging, 'ssetup', '', new ext_set('_SIPURI', '')); 
    327339      if (isset($alertinfo) && trim($alertinfo) != "") { 
    328               $ext->add($apppaging, '_AUTOASWER.', '', new ext_setvar('_ALERTINFO', $alertinfo)); 
     340      $ext->add($apppaging, 'ssetup', '', new ext_set('_ALERTINFO', $alertinfo)); 
    329341      } 
    330342       
    331343      if (isset($callinfo) && trim($callinfo) != "") { 
    332               $ext->add($apppaging, '_AUTOASWER.', '', new ext_setvar('_CALLINFO', $callinfo)); 
     344      $ext->add($apppaging, 'ssetup', '', new ext_set('_CALLINFO', $callinfo)); 
    333345      } 
    334346      if (isset($sipuri) && trim($sipuri) != "") { 
    335               $ext->add($apppaging, '_AUTOASWER.', '', new ext_setvar('_SIPURI', $sipuri)); 
     347      $ext->add($apppaging, 'ssetup', '', new ext_set('_SIPURI', $sipuri)); 
    336348      } 
    337349      if (isset($vxml_url) && trim($vxml_url) != "") { 
    338               $ext->add($apppaging, '_AUTOASWER.', '', new ext_setvar('_VXML_URL', $vxml_url)); 
     350      $ext->add($apppaging, 'ssetup', '', new ext_set('_VXML_URL', $vxml_url)); 
    339351      } 
    340352      if (isset($doptions) && trim($doptions) != "") { 
    341               $ext->add($apppaging, '_AUTOASWER.', '', new ext_setvar('_DOPTIONS', $doptions)); 
    342       } 
    343       $ext->add($apppaging, '_AUTOASWER.', '', new ext_setvar('_DTIME', $dtime)); 
    344       $ext->add($apppaging, '_AUTOASWER.', '', new ext_setvar('_ANSWERMACRO', '')); 
    345       foreach ($custom_vars as $key => $value) { 
    346               $ext->add($apppaging, '_AUTOASWER.', '', new ext_setvar('_'.ltrim($key,'_'), $value)); 
    347       } 
    348       $ext->add($apppaging, '_AUTOASWER.', '', new ext_setvar('__FORWARD_CONTEXT', 'block-cf')); 
    349       $ext->add($apppaging, '_AUTOASWER.', '', new ext_macro('autoanswer','${EXTEN:9}')); 
    350       $ext->add($apppaging, '_AUTOASWER.', '', new ext_return()); 
    351        
    352       // Normal page version 
    353       $ext->add($apppaging, "_PAGE.", '', new ext_gotoif('$[ "${AMPUSER}" = "${EXTEN:4}" ]','skipself')); 
    354       $ext->add($apppaging, "_PAGE.", 'AVAIL', new ext_chanisavail('${DB(DEVICE/${EXTEN:4}/dial)}', 'js')); 
    355       $ext->add($apppaging, "_PAGE.", '', new ext_gotoif('$["${DB(DND/${DB(DEVICE/${EXTEN:4}/user)})}" = "YES"]', 'skipself'));      
     353        $ext->add($apppaging, 'ssetup', '', new ext_set('_DOPTIONS', $doptions)); 
     354      } 
     355      $ext->add($apppaging, 'ssetup', '', new ext_set('_DTIME', $dtime)); 
     356      $ext->add($apppaging, 'ssetup', '', new ext_set('_ANSWERMACRO', '')); 
     357 
     358      $page_opts = $amp_conf['ASTCONFAPP'] == 'app_confbridge' ? '1qs' : '1doqsx'; 
     359      $ext->add($apppaging, 'ssetup', '', new ext_set('PAGE_CONF_OPTS', $page_opts . (!$thisgroup['duplex'] ? 'm' : ''))); 
     360      $ext->add($apppaging, 'ssetup', '', new ext_set('PAGE_CONF', '${EPOCH}${RAND(100,999)}')); 
     361      $ext->add($apppaging, 'ssetup', '', new ext_return()); 
     362         
     363      // Normal page version (now used for Force also) 
    356364      $ext->add($apppaging, "_PAGE.", 'SKIPCHECK', new ext_gosub('AUTOASWER${EXTEN:4},1')); 
    357365      $ext->add($apppaging, "_PAGE.", '', new ext_dial('${DIAL}','${DTIME},${DOPTIONS}')); 
    358366      $ext->add($apppaging, "_PAGE.", 'skipself', new ext_hangup()); 
    359       $ext->add($apppaging, "_PAGE.", '', new ext_hangup(''), 'AVAIL',101); 
    360367 
    361368      // Try ChanSpy Version 
    362       $ext->add($apppaging, "_SPAGE.", '', new ext_gotoif('$[ "${AMPUSER}" = "${EXTEN:5}" ]','skipself')); 
    363       $ext->add($apppaging, "_SPAGE.", 'AVAIL', new ext_chanisavail('${DB(DEVICE/${EXTEN:5}/dial)}', 'js')); 
    364       $ext->add($apppaging, "_SPAGE.", '', new ext_gotoif('$["${DB(DND/${DB(DEVICE/${EXTEN:5}/user)})}" = "YES"]', 'chanspy'));      
    365       $ext->add($apppaging, "_SPAGE.", 'SKIPCHECK', new ext_gosub('AUTOASWER${EXTEN:5},1')); 
    366       $ext->add($apppaging, "_SPAGE.", '', new ext_dial('${DIAL}','${DTIME},${DOPTIONS}')); 
    367       $ext->add($apppaging, "_SPAGE.", 'chanspy', new ext_execif('$["${CUT(DB(DEVICE/${EXTEN:5}/dial),/,1)}" = "SIP"]', 'ChanSpy','${DB(DEVICE/${EXTEN:5}/dial)}-,qW')); 
    368       $ext->add($apppaging, "_SPAGE.", '', new ext_noop_trace('Comparison: ${EXTEN:5}, "${CUT(DB(DEVICE/${EXTEN:5}/dial),/,1)}" = "SIP"',9)); 
    369       $ext->add($apppaging, "_SPAGE.", 'skipself', new ext_hangup()); 
    370       $ext->add($apppaging, "_SPAGE.", '', new ext_hangup(''), 'AVAIL',101); 
    371  
    372  
    373       // Force page version 
    374       $ext->add($apppaging, "_FPAGE.", '', new ext_gotoif('$[ "${AMPUSER}" = "${EXTEN:5}" ]','skipself')); 
    375       $ext->add($apppaging, "_FPAGE.", 'SKIPCHECK', new ext_gosub('AUTOASWER${EXTEN:5},1')); 
    376       $ext->add($apppaging, "_FPAGE.", '', new ext_dial('${DIAL}','${DTIME},${DOPTIONS}')); 
    377       $ext->add($apppaging, "_FPAGE.", 'skipself', new ext_hangup()); 
    378        
     369      $ext->add($apppaging, "_SPAGE.", 'chanspy', new ext_chanspy('${SP_DEVICE}-','qW')); 
     370      $ext->add($apppaging, "_SPAGE.", '', new ext_hangup()); 
     371 
     372      $apppagegroups = 'app-pagegroups'; 
    379373      // Now get a list of all the paging groups... 
    380374      $sql = "SELECT page_group, force_page, duplex FROM paging_config"; 
     
    382376      foreach ($paging_groups as $thisgroup) { 
    383377        $grp=trim($thisgroup['page_group']); 
    384         switch ($thisgroup['force_page']) { 
    385         case 1: 
    386           $pagemode = 'FPAGE'; 
    387           break; 
    388         case 2: 
    389           $pagemode = 'SPAGE'; 
    390           break; 
    391         case 0: 
    392         default: 
    393           $pagemode = 'PAGE'; 
    394           break; 
    395         } 
     378        switch ($thisgroup['force_page']) { 
     379        case 1: 
     380          $pagemode = 'FPAGE'; 
     381        break; 
     382        case 2: 
     383          $pagemode = 'SPAGE'; 
     384        break; 
     385        case 0: 
     386        default: 
     387          $pagemode = 'PAGE'; 
     388        break; 
     389        } 
     390 
    396391        $sql = "SELECT ext FROM paging_groups WHERE page_number='$grp'"; 
    397         $all_exts = $db->getAll($sql); 
    398         $dialstr=''; 
    399          
     392        $all_exts = $db->getCol($sql); 
     393           
    400394        // Create the paging context that is used in the paging application for each phone to auto-answer 
    401395        //add ext-paging with goto's to our app-paging context and a hint for the page 
    402396        $extpaging = 'ext-paging'; 
    403         $ext->add($extpaging, $grp, '', new ext_goto($apppaging . ',' . $grp . ',1')); 
     397        $ext->add($extpaging, $grp, '', new ext_goto($apppagegroups . ',' . $grp . ',1')); 
    404398        $ext->addInclude('from-internal-noxfer-additional',$extpaging); 
    405399        $ext->addHint($extpaging, $grp, 'Custom:PAGE' . $grp); 
    406          
     400         
    407401        //app-page dialplan 
    408         foreach($all_exts as $local_dial) { 
    409           if (strtoupper(substr($local_dial[0],-1)) == "X") { 
    410             $local_dial[0] = rtrim($local_dial[0],"xX"); 
    411           } 
    412           $page_memebers[] = "LOCAL/$pagemode".trim($local_dial[0])."@".$apppaging; 
    413  
    414         } 
    415          
    416         $ext->add($apppaging, $grp, '', new ext_macro('user-callerid')); 
    417         $ext->add($apppaging, $grp, '', new ext_setvar('_PAGEGROUP', $grp)); 
    418         $ext->add($apppaging, $grp, '', new ext_setvar('PAGE${PAGEGROUP}ADMIN', 'TRUE')); 
    419          
    420         //if page group it in use, got to busy 
    421         $ext->add($apppaging, $grp, 'busy-check',  
    422           new ext_gotoif('$[${TRYLOCK(apppaging'. $grp .')}]', '', 'busy')); 
    423          
     402           
     403        $ext->add($apppagegroups, $grp, '', new ext_macro('user-callerid')); 
     404        $ext->add($apppagegroups, $grp, '', new ext_set('_PAGEGROUP', $grp)); 
     405           
     406        //if page group it in use, goto to busy 
     407        $ext->add($apppagegroups, $grp, '', new ext_gotoif('$[${TRYLOCK(apppagegroups'. $grp .')}]', '', 'busy')); 
     408           
    424409        //set blf to in use 
    425         $ext->add($apppaging, $grp, 'devstate',  
    426           new ext_setvar('DEVICE_STATE(Custom:PAGE' . $grp .')', 'INUSE')); 
    427          
    428         $ext->add($apppaging, $grp, '', new ext_answer('')); 
    429         $ext->add($apppaging, $grp, '', new ext_set('PAGE_CONF', '${EPOCH}${RAND(100,999)}')); 
    430         $page_opts = $amp_conf['ASTCONFAPP'] == 'app_meetme' ? '1doqsx' : '1qs'; 
    431         $ext->add($apppaging, $grp, '',  
    432           new ext_set('PAGE_CONF_OPTS', $page_opts . (!$thisgroup['duplex'] ? 'm' : ''))); 
    433         $ext->add($apppaging, $grp, '', new ext_set('PAGE_MEMBERS', base64_encode(serialize($page_memebers)))); 
    434         $ext->add($apppaging, $grp, 'agi', new ext_agi('page.agi'));       
    435         unset($page_memebers); 
    436         $ext->add($apppaging, $grp, 'page', new ext_meetme('${PAGE_CONF}', 'doqwxAG')); 
    437         $ext->add($apppaging, $grp, '', new ext_hangup()); 
    438         $ext->add($apppaging, $grp, 'busy', new ext_set('PAGE${PAGEGROUP}BUSY', 'TRUE')); 
    439         $ext->add($apppaging, $grp, 'play-busy', new ext_busy(3)); 
    440         $ext->add($apppaging, $grp, 'busy-hang', new ext_goto('ext-paging,h,1')); 
    441          
     410        $ext->add($apppagegroups, $grp, 'devstate', new ext_setvar('DEVICE_STATE(Custom:PAGE' . $grp .')', 'INUSE')); 
     411           
     412        $ext->add($apppagegroups, $grp, '', new ext_answer('')); 
     413        $ext->add($apppagegroups, $grp, '', new ext_gosub('1','ssetup', $apppaging)); 
     414        $ext->add($apppagegroups, $grp, '', new ext_set('PAGEMODE', $pagemode)); 
     415        $ext->add($apppagegroups, $grp, '', new ext_set('PAGE_MEMBERS', implode('-',$all_exts))); 
     416        $ext->add($apppagegroups, $grp, 'agi', new ext_agi('page.agi'));       
     417 
     418        //we cant use originate from the dialplan as the dialplan command is not asynchronous 
     419        //we would like to though... 
     420        //this code here as a sign of hope -MB 
     421        /*foreach ($page_members as $member) { 
     422            $ext->add($apppagegroups, $grp, 'page', new ext_originate($member,'app','meetme', '${PAGE_CONF}\,${PAGE_CONF_OPTS}')); 
     423        }*/          
     424        $ext->add($apppagegroups, $grp, 'page', new ext_meetme('${PAGE_CONF}', 'doqwxAG')); 
     425        $ext->add($apppagegroups, $grp, '', new ext_hangup()); 
     426        $ext->add($apppagegroups, $grp, 'busy', new ext_set('PAGE${PAGEGROUP}BUSY', 'TRUE')); 
     427        $ext->add($apppagegroups, $grp, 'play-busy', new ext_busy(3)); 
     428        $ext->add($apppagegroups, $grp, 'busy-hang', new ext_goto('ext-paging,h,1')); 
    442429      } 
    443430      //h 
    444       $ext->add($apppaging, 'h', '',  
    445         new ext_execif('$[' 
    446                 . '$["${PAGE${PAGEGROUP}ADMIN}" = "TRUE"]' 
    447                 . ' & $[${ISNULL(${PAGE${PAGEGROUP}BUSY})}]' 
    448                 . ']',  
    449                 'Set', 'DEVICE_STATE(Custom:PAGE${PAGEGROUP})=NOT_INUSE')); 
     431      $ext->add($apppagegroups, 'h', '',  
     432        new ext_execif('$[${ISNULL(${PAGE${PAGEGROUP}BUSY})}]', 'Set', 'DEVICE_STATE(Custom:PAGE${PAGEGROUP})=NOT_INUSE')); 
    450433       
    451434      //page playback 
     
    536519  $results = $db->getAll($sql); 
    537520  if(DB::IsError($results))  
    538     $results = null
     521    $results = array()
    539522  foreach ($results as $val) 
    540523    $tmparray[] = $val[0]; 
     
    550533  $sql = "SELECT * FROM paging_config WHERE page_group='$grp'"; 
    551534  $results = $db->getRow($sql, DB_FETCHMODE_ASSOC); 
    552   if(!$results || DB::IsError($results)) { 
    553     return false
     535  if(DB::IsError($results)) { 
     536    $results = null
    554537  } 
    555538  $sql = "SELECT * FROM admin WHERE variable='default_page_grp' AND value='$grp'";