/[drupal]/contributions/modules/asterisk/drupal_integration/asterisk_common.inc
ViewVC logotype

Diff of /contributions/modules/asterisk/drupal_integration/asterisk_common.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.12, Mon Jun 2 03:01:33 2008 UTC revision 1.13, Mon Jun 2 08:27:31 2008 UTC
# Line 1  Line 1 
1  <?php  <?php
2  // $Id: asterisk_common.inc,v 1.11 2008/05/31 23:06:48 thehunmonkgroup Exp $  // $Id: asterisk_common.inc,v 1.12 2008/06/02 03:01:33 thehunmonkgroup Exp $
3    
4  /**  /**
5   * @file   * @file
# Line 521  function asterisk_debug_to_file($content Line 521  function asterisk_debug_to_file($content
521    fclose($fh);    fclose($fh);
522    return $ret;    return $ret;
523  }  }
   
 /**  
  * Functions listed below are not working.  In the future, they may be added as features  
  * or removed altogether.  
  */  
   
 /**  
  * Executes an asterisk system call  
  * @param $server  
  *   Information pertaining to the server from which this call originated  
  * @param $call  
  *   The call array which will be used to generate the call file  
  */  
 /*function asterisk_system_call($server, $call) {  
   global $asterisk, $confdir;  
   $vars = $call['vars'];  
   if (!is_object($vars['user'])) {  
     (object) $vars['user'];  
   }  
   if ($vars['op']) {  
     switch ($vars['op']) {  
   
       // iax.conf, sip.conf, voicemail.conf stuff  
       case 'update-user':  
       case 'create-user':  
         asterisk_update_asterisk_user($server, $vars['user'], 'iax');  
         asterisk_update_asterisk_user($server, $vars['user'], 'sip');  
         asterisk_update_asterisk_user($server, $vars['user'], 'vm');  
         break;  
       case 'delete-user':  
         asterisk_delete_asterisk_user($server, $vars['user'], 'iax');  
         asterisk_delete_asterisk_user($server, $vars['user'], 'sip');  
         asterisk_delete_asterisk_user($server, $vars['user'], 'vm');  
         break;  
     }  
     // recreate the include file helpers  
     asterisk_recreate_files($confdir);  
   
     // reload the asterisk server  
     system("$asterisk -rx reload");  
   }  
 }*/  
   
 /**  
  * For old asterisk installations that do not support #include configuration globbing  
  * We use is for new asterisk installations too! (works there as well)  
  */  
 /*function asterisk_recreate_files($confdir) {  
   $dh = opendir($confdir);  
   $iax_conf_include = '';  
   $sip_conf_include = '';  
   $vm_conf_include  = '[drupal]'.chr(10);  
   while (FALSE !== ($file = readdir($dh))) {  
     if ($file != '.' && $file != '..') {  
       if (is_file($confdir.DIRECTORY_SEPARATOR.$file.DIRECTORY_SEPARATOR.'iax.conf')) {  
         $iax_conf_include .= "#include drupal/$file/iax.conf\n";  
       }  
       if (is_file($confdir.DIRECTORY_SEPARATOR.$file.DIRECTORY_SEPARATOR.'sip.conf')) {  
         $sip_conf_include .= "#include drupal/$file/sip.conf\n";  
       }  
       if (is_file($confdir.DIRECTORY_SEPARATOR.$file.DIRECTORY_SEPARATOR.'vm.conf')) {  
         $vm_conf_include .= file_get_contents($confdir.DIRECTORY_SEPARATOR.$file.DIRECTORY_SEPARATOR.'vm.conf');  
       }  
     }  
   }  
   asterisk_write_file($iax_conf_include, $confdir.DIRECTORY_SEPARATOR.'iax.conf');  
   asterisk_write_file($sip_conf_include, $confdir.DIRECTORY_SEPARATOR.'sip.conf');  
   asterisk_write_file($vm_conf_include, $confdir.DIRECTORY_SEPARATOR.'voicemail.conf');  
 }*/  
   
 /**  
  * Updates an asterisk iax or sip user  
  */  
 /*function asterisk_update_asterisk_user($server, $user, $type = 'iax') {  
   
   global $confdir;  
   
   if (!$user->uid) {  
     return;  
   }  
   
   $uri = parse_url($server['url']);  
   $host = $uri['host'];  
   
   // create the configuration directory  
   $user_confdir = $confdir.DIRECTORY_SEPARATOR.$user->uid.'-'.$host;  
   if (!is_dir($user_confdir)) {  
     mkdir($user_confdir);  
   }  
   
   // create the configuration file  
   switch ($type) {  
     case 'iax':  
       $conf = asterisk_create_iax_conf($server, $user);  
       break;  
     case 'sip':  
       $conf = asterisk_create_sip_conf($server, $user);  
       break;  
     case 'vm':  
       $conf = asterisk_create_voicemail_conf($server, $user);  
       break;  
     default:  
       // lets not do anything if we don't know what's going on  
       return;  
   }  
   // write the configuration file  
   asterisk_write_file($conf, $user_confdir.DIRECTORY_SEPARATOR.$type.'.conf');  
 }*/  
   
 /**  
  * Deletes the iax configuration for a single user  
  */  
 /*function asterisk_delete_asterisk_user($server, $user, $type) {  
   global $confdir;  
   
   // sanity check  
   if (!$user->uid) {  
     return;  
   }  
   
   $uri = parse_url($server['url']);  
   $host = $uri['host'];  
   
   // delete the configuration files  
   $user_confdir = $confdir.DIRECTORY_SEPARATOR.$user->uid.$host;  
   
   unlink ($user_confdir.DIRECTORY_SEPARATOR.$type.'.conf');  
 }*/  
   
  /**  
  * Create an sip.conf include for one user  
  * @param $user  
  *   object The user object to create the sip configuration for  
  * @return  
  *   string A string containing the iax.conf configuration include  
  */  
 /*function asterisk_create_sip_conf($server, $user) {  
   
   $uri = parse_url($server['url']);  
   $host = $uri['host'];  
   
   $conf  = ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;\n";  
   $conf .= ";{$user->name} (uid:{$user->uid}, host:$host)\n";  
   $conf .= ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;\n";  
   $conf .= ";Created by Drupal\n";  
   $conf .= "[{$user->name}-{$host}]\n";  
   $conf .= "type=friend\n";  
   $conf .= "secret={$user->pin}\n";  
   $conf .= "host=dynamic\n";  
   $conf .= "callerid=\"{$user->name}\" <{$user->uid}-{$host}>\n";  
   $conf .= "disallow=all\n";  
   $conf .= "allow=gsm\n";  
   $conf .= "allow=ulaw\n";  
   $conf .= "context=drupal\n";  
   $conf .= "transfer=yes\n";  
   $conf .= "canreinvite=yes\n";  
   $conf .= "dtmfmode=rfc2833\n\n";  
   //$sipconf .= "qualify=yes\n";  
   //$sipconf .= "nat=no\n\n";  
   
   return $conf;  
 }*/  
   
 /**  
  * Create an iax.conf include for one user  
  * @param $user  
  *   object The user object to create the iax configuration for  
  * @return  
  *   string A string containing the iax.conf configuration include  
  */  
 /*function asterisk_create_iax_conf($server, $user) {  
   
   $uri = parse_url($server['url']);  
   $host = $uri['host'];  
   
   $conf  = ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;\n";  
   $conf .= ";{$user->name} (uid:{$user->uid}, host:$host)\n";  
   $conf .= ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;\n";  
   $conf .= ";Created by Drupal\n";  
   $conf .= "[{$user->name}-{$host}]\n";  
   $conf .= "type=friend\n";  
   $conf .= "host=dynamic\n";  
   $conf .= "callerid=\"{$user->name}\" <{$user->uid}-{$host}>\n";  
   $conf .= "context=drupal\n";  
   $conf .= "secret={$user->pin}\n";  
   $conf .= "\n";  
   
   return $conf;  
 }*/  
   
 /**  
  * Create an voicemail.conf include for one user  
  * @param $user  
  *   object The user object to create the iax configuration for  
  * @return  
  *   string A string containing the voicemail.conf configuration include  
  */  
 /*function asterisk_create_voicemail_conf($server, $user) {  
   $uri = parse_url($server['url']);  
   $host =  $uri['host'];  
   // XXX to be changed to $serverid$uid  
   $voicemail_conf = "{$user->name}-{$host} => {$user->pin}, {$user->name}, {$user->mail}\n";  
   return $voicemail_conf;  
 }*/  
   
 /**  
  * Check if the specified user id and phone pin match the one of a user in the system  
  *  
  * @param  
  *   string the URL to the xmlrpc.php file that will process the call in the server  
  * @param  
  *   integer user id  
  * @param  
  *   string phone pin  
  * @return  
  *   boolean True in case the user is valid.  Returns False otherwise or in case of error.  
  */  
 /*function asterisk_check_user($server_url, $uid, $phone_pin) {  
   
   // reset error handler  
   asterisk_error_reset();  
   
   $rc = xmlrpc($server_url,  
                'asterisk.isUserValid',  
                $uid,  
                $phone_pin);  
   
   if (!$rc->is_error) {  
     return $rc;  
   }  
   else {  
     // if xmlrpc call fails...  
     asterisk_error( "XMLRPC error checking user id and phone pin: " . xmlrpc_error_msg());  
     return FALSE;  
   }  
 }*/  
   
 /*  
  * Fetches site lists from each queried server. This list is cached.  
  */  
 /*function asterisk_make_site_list($root_servers) {  
   global $tempdir;  
   
   $max_age = 60;  
   $servers = array();  
   
   // implement caching  
   $cache = $tempdir.DIRECTORY_SEPARATOR.'drupal-sitelist.cache';  
   
   // check if cache exists  
   if (is_readable($cache) && filesize($cache)) {  
     // check if the file is fresh  
     if ((time() - filemtime($cache)) < $max_age) {  
       // return the cached data  
       return unserialize(file_get_contents($cache));  
     }  
   }  
   // if there is no cache (or its old) then query each configured server for a list  
   foreach ($root_servers as $root_server) {  
   
     $child_servers = xmlrpc($root_server['url'], 'asterisk.getSiteList', $root_server['name'], $root_server['pass']);  
   
     if (is_array($child_servers)) {  
   
       foreach ($child_servers as $key => $server) {  
   
         $servers[$key]['url'] = $server['url'];  
         $servers[$key]['name'] = $server['name'];  
         $servers[$key]['pass'] = $server['pass'];  
       }  
     }  
   }  
   // cache the results  
   $fh = fopen($cache, 'w');  
   fwrite($fh, serialize($servers));  
   fclose($fh);  
   
   return $servers;  
 }*/  

Legend:
Removed from v.1.12  
changed lines
  Added in v.1.13

  ViewVC Help
Powered by ViewVC 1.1.2