/[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.10, Mon Sep 18 14:40:24 2006 UTC revision 1.11, Sat May 31 23:06:48 2008 UTC
# Line 1  Line 1 
1  <?php  <?php
2  // $Id: asterisk_common.inc,v 1.9 2006/09/16 14:41:12 thehunmonkgroup Exp $  // $Id: asterisk_common.inc,v 1.10 2006/09/18 14:40:24 thehunmonkgroup Exp $
3    
4  /**  /**
5   * @file   * @file
# Line 75  function asterisk_validate_host($user, $ Line 75  function asterisk_validate_host($user, $
75              $ini_array = parse_ini_file($ini_file, TRUE);              $ini_array = parse_ini_file($ini_file, TRUE);
76              // Validate the user's password.              // Validate the user's password.
77              if (trim($ini_array['general']['pass']) == $pass) {              if (trim($ini_array['general']['pass']) == $pass) {
78                $return = TRUE;                $return['success'] = TRUE;
79              }              }
80                else {
81                  $return['error'] = 'Invalid password';
82                }
83              }
84              else {
85                $return['error'] = 'No configuration file exists for user.';
86            }            }
87            break;            break;
88          }          }
89        }        }
90          $return['error'] = 'Invalid username.';
91        closedir($dh);        closedir($dh);
92      }      }
93        else {
94          $return['error'] = "Can't read server account directory.";
95        }
96      }
97      else {
98        $return['error'] = 'Invalid server account directory.';
99    }    }
100    
101    return $return;    return $return;
# Line 107  function asterisk_validate_user_director Line 120  function asterisk_validate_user_director
120        $this_directory = $user_directory . DIRECTORY_SEPARATOR . $directory;        $this_directory = $user_directory . DIRECTORY_SEPARATOR . $directory;
121        if (!is_dir($this_directory)) {        if (!is_dir($this_directory)) {
122          if (!mkdir($this_directory, 0700)) {          if (!mkdir($this_directory, 0700)) {
123            $return = FALSE;            $return['error'] = "Can't create user support directory $this_directory.";
124            break;            break;
125          }          }
126        }        }
127      }      }
128    }    }
129    else {    else {
130      $return = FALSE;      $return['error'] = "Can't find previously created user directory $user_directory.";
131    }    }
132    
133    return $return;    return $return;
# Line 137  function asterisk_write_call_file($user, Line 150  function asterisk_write_call_file($user,
150    $tmpfname = tempnam($tempdir, 'drupal-record');    $tmpfname = tempnam($tempdir, 'drupal-record');
151    
152    if (asterisk_write_file($callfile, $tmpfname)) {    if (asterisk_write_file($callfile, $tmpfname)) {
153        chmod($tmpfname, 0644);
154        $outgoing = CALL_SPOOL_DIR . DIRECTORY_SEPARATOR . basename($tmpfname);
155      // Move (NOT copy or create in) to outgoing spool.      // Move (NOT copy or create in) to outgoing spool.
156      if (rename($tmpfname, CALL_SPOOL_DIR . DIRECTORY_SEPARATOR . basename($tmpfname))) {      if (rename($tmpfname, $outgoing)) {
157        $return = TRUE;        $return = TRUE;
158      }      }
159      else {      else {
160          $return['error'] = "Can't move call file to spool $outgoing.";
161        unlink($tmpfname);        unlink($tmpfname);
162      }      }
163    }    }
164      else {
165        $return['error'] = "Can't write call file to user cache $tempdir.";
166      }
167    
168    return $return;    return $return;
169  }  }
# Line 329  function write_ini_file($path, $content_ Line 347  function write_ini_file($path, $content_
347   */   */
348  function asterisk_check_files($user, $pass, $filetypes) {  function asterisk_check_files($user, $pass, $filetypes) {
349    
350    $return = array();    $return = asterisk_validate_host($user, $pass);
351    
352    if (asterisk_validate_host($user, $pass)) {    if (isset($return['success'])) {
353      if (asterisk_validate_user_directories($user)) {      $return = asterisk_validate_user_directories($user);
354        if ($return === TRUE) {
355        foreach ($filetypes as $type => $files) {        foreach ($filetypes as $type => $files) {
356          switch ($type) {          switch ($type) {
357            case 'playback_file':            case 'playback_file':
# Line 364  function asterisk_check_files($user, $pa Line 383  function asterisk_check_files($user, $pa
383   */   */
384  function asterisk_process_new_calls($user, $pass, $calls) {  function asterisk_process_new_calls($user, $pass, $calls) {
385    
386    $return = array();    $return = asterisk_validate_host($user, $pass);
387    
388    if (asterisk_validate_host($user, $pass)) {    if (isset($return['success'])) {
389      if (asterisk_validate_user_directories($user)) {      $return = asterisk_validate_user_directories($user);
390        if ($return === TRUE) {
391        foreach ($calls as $type => $files) {        foreach ($calls as $type => $files) {
392          switch ($type) {          switch ($type) {
393            case 'playback_file':            case 'playback_file':
394              foreach ($files as $key => $file) {              foreach ($files as $key => $file) {
395                  $result = asterisk_process_playback_message($user, $file);                  $result = asterisk_process_playback_message($user, $file);
396                  if ($result) {                  if ($result === TRUE) {
397                  $return['playback_file'][$key] = TRUE;                  $return['playback_file'][$key] = TRUE;
398                }                }
399                  else {
400                    $return = $result;
401                  }
402              }              }
403    
404              break;              break;
405            case 'callfile';            case 'callfile';
406              foreach ($files as $key => $file) {              foreach ($files as $key => $file) {
407                  $result = asterisk_write_call_file($user, $file);                  $result = asterisk_write_call_file($user, $file);
408                  if ($result) {                  if ($result === TRUE) {
409                  $return['callfile'][$key] = TRUE;                  $return['callfile'][$key] = TRUE;
410                }                }
411                  else {
412                    $return = $result;
413                  }
414              }              }
415    
416              break;              break;
# Line 407  function asterisk_process_new_calls($use Line 433  function asterisk_process_new_calls($use
433   */   */
434  function asterisk_send_message($user, $pass, $message_key) {  function asterisk_send_message($user, $pass, $message_key) {
435    
436    $return = FALSE;    $return = asterisk_validate_host($user, $pass);
437    
438    if (asterisk_validate_host($user, $pass)) {    if (isset($return['success'])) {
439      if (asterisk_validate_user_directories($user)) {      $return = asterisk_validate_user_directories($user);
440        if ($return === TRUE) {
441        $return = asterisk_retrieve_user_message($user, $message_key);        $return = asterisk_retrieve_user_message($user, $message_key);
442      }      }
443    }    }
# Line 428  function asterisk_send_message($user, $p Line 455  function asterisk_send_message($user, $p
455   */   */
456  function asterisk_test_connection($user, $pass) {  function asterisk_test_connection($user, $pass) {
457    
458    $return = FALSE;    $return = asterisk_validate_host($user, $pass);
   
   if (asterisk_validate_host($user, $pass)) {  
     $return = TRUE;  
   }  
459    
460    return $return;    return $return;
461  }  }
# Line 459  function _asterisk_methods() { Line 482  function _asterisk_methods() {
482      array(      array(
483        'asterisk.test.Connection',        'asterisk.test.Connection',
484        'asterisk_test_connection',        'asterisk_test_connection',
485        array('boolean', 'string', 'string'),        array('struct', 'string', 'string'),
486        t('tests the connection to the Asterisk XML-RPC server.')        t('tests the connection to the Asterisk XML-RPC server.')
487      ),      ),
488      array(      array(

Legend:
Removed from v.1.10  
changed lines
  Added in v.1.11

  ViewVC Help
Powered by ViewVC 1.1.2