Changeset 14150

Show
Ignore:
Timestamp:
06/18/12 11:52:43 (1 year ago)
Author:
mbrevda
Message:

fax code cleanup; advanced setting wrtietimeout manager support; add port option to backups; closes #5871; #5823;

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • modules/branches/2.10/backup/functions.inc/class.backup.php

    r14037 r14150  
    9393 
    9494  function init() { 
    95     //$this->b['_dirpath']  = $this->amp_conf['ASTSPOOLDIR'] . '/backup/' . $this->b['_dirname']; 
     95    $this->b['_dirpath']  = $this->amp_conf['ASTSPOOLDIR'] . '/backup/' . $this->b['_dirname']; 
    9696    $this->b['_tmpdir']   = $this->amp_conf['ASTSPOOLDIR'] . '/tmp/backup-' . $this->b['id']; 
    9797    $this->b['_tmpfile']  = $this->amp_conf['ASTSPOOLDIR'] . '/tmp/' . $this->b['_file'] . '.tgz'; 
     
    360360          $cmd[] = $s['key']; 
    361361          $cmd[] = $s['user'] . '\@' . $s['host']; 
     362          $cmd[] = '-p ' . $s['port']; 
    362363          $cmd[] = 'mkdir -p ' . $s['path']  
    363364              . '/' . $this->b['_dirname']; 
     
    369370          $cmd[] = fpbx_which('scp'); 
    370371          $cmd[] = '-o StrictHostKeyChecking=no -i'; 
     372          $cmd[] = '-P ' . $s['port']; 
    371373          $cmd[] = $s['key']; 
    372374          $cmd[] = $this->b['_tmpfile']; 
     
    511513        $cmd[] = $data['key']; 
    512514        $cmd[] = $data['user'] . '\@' . $data['host']; 
     515        $cmd[] = '-p ' . $data['port']; 
    513516        $cmd[] = 'ls -1 ' . $data['path'] . '/' . $this->b['_dirname']; 
    514517        exec(implode(' ', $cmd), $dir); 
     
    568571          $cmd[] = $data['key']; 
    569572          $cmd[] = $data['user'] . '\@' . $data['host']; 
     573          $cmd[] = '-p ' . $data['port']; 
    570574          $cmd[] = 'rm ' . $data['path'] . '/' . '/' . $this->b['_dirname'] . '/' . $file; 
    571575          exec(implode(' ', $cmd)); 
  • modules/branches/2.10/core/page.advancedsettings.php

    r13399 r14150  
    3636        case 'AMPMGRUSER': 
    3737          fpbx_ami_update($var['value'], false); 
     38        break; 
     39        case 'ASTMGRWRITETIMEOUT': 
     40          fpbx_ami_update(false, false, true); 
    3841        break; 
    3942      } 
  • modules/branches/2.10/fax/bin/fax2mail.php

    r13919 r14150  
    77} 
    88 
    9 exec('/bin/hostname', $hostname); 
    10 $var['hostname']  = $hostname[0]; 
     9$var['hostname']  = gethostname(); 
    1110$var['from']    = sql('SELECT value FROM fax_details WHERE `key` = "sender_address"','getOne'); 
    1211$var['from']    = $var['from'] ? $var['from'] : 'fax@freepbx.pbx'; 
     
    1413$var        = array_merge($var, get_opt()); 
    1514$var['callerid']  = $var['callerid'] === true ? '' : $var['callerid'];//prevent callerid from being blank 
     15$var['keep_file'] = $var['delete'] == 'true' ? false : true; 
    1616 
    17 //double check some ofthe options 
     17//double check some of the options 
    1818foreach ($var as $k => $v) { 
    1919  switch ($k) { 
     
    4242 
    4343//if file is a tif, try to convert it to a pdf 
    44 $var['file'] = fax_tiff2pdf($var['file']) == true  
    45       ? substr($var['file'], 0, strrpos($var['file'], '.')) . '.pdf'  
    46       : $var['file']; 
     44$var['file'] = fax_file_convert('tif2pdf', $var['file'], '', $var['keep_file']); 
    4745 
    4846$msg = 'Enclosed, please find a new fax '; 
  • modules/branches/2.10/fax/functions.inc.php

    r13956 r14150  
    140140function fax_delete_incoming($extdisplay){ 
    141141  global $db; 
    142   $opts=explode('/', $extdisplay);$extension=$opts['0'];$cidnum=$opts['1']; //set vars 
    143   sql("DELETE FROM fax_incoming WHERE cidnum = '".$db->escapeSimple($cidnum)."' and extension = '".$db->escapeSimple($extension)."'"); 
     142  $opts   = explode('/', $extdisplay); 
     143  $extension  = $opts['0']; 
     144  $cidnum   = $opts['1']; //set vars 
     145  sql("DELETE FROM fax_incoming WHERE cidnum = '" 
     146    . $db->escapeSimple($cidnum) 
     147    . "' and extension = '" 
     148    . $db->escapeSimple($extension) 
     149    . "'"); 
    144150} 
    145151 
    146152function fax_delete_user($faxext) { 
    147153       global $db; 
    148        $faxext=$db->escapeSimple($faxext); 
    149        sql('DELETE FROM fax_users where user = "'.$faxext.'"'); 
     154       $faxext = $db->escapeSimple($faxext); 
     155       sql('DELETE FROM fax_users where user = "' . $faxext . '"'); 
    150156} 
    151157 
     
    256262        $ext->add($context, $exten, '', new ext_noop('Receiving Fax for: ${FAX_FOR}, From: ${CALLERID(all)}')); 
    257263        $ext->add($context, $exten, '', new ext_set('FAX_RX_EMAIL', $row['faxemail']));      
    258         $ext->add($context, $exten, 'receivefax', new ext_goto('receivefax','s')); 
     264       $ext->add($context, $exten, 'receivefax', new ext_goto('receivefax','s')); 
    259265      } 
    260266    } 
     
    315321    $ext->add($context, $exten, '', new ext_noop_trace('PROCESSING FAX with status: [${FAXSTATUS}] for: [${FAX_RX_EMAIL}], From: [${CALLERID(all)}]')); 
    316322    $ext->add($context, $exten, 'process', new ext_gotoif('$[${LEN(${FAX_RX_EMAIL})} = 0]','noemail')); 
    317     $ext->add($context, $exten, '', new ext_system('${ASTVARLIBDIR}/bin/fax2mail.php --to "${FAX_RX_EMAIL}" --dest "${FROM_DID}" --callerid \'${CALLERID(all)}\' --file ${ASTSPOOLDIR}/fax/${UNIQUEID}.tif --exten "${FAX_FOR}"')); 
     323  //delete is a variable so that other modules can prevent it should then need to prosses the file further 
     324  $ext->add($context, $exten, 'delete_opt', new ext_set('DELETE_AFTER_SEND', 'true')); 
     325    $ext->add($context, $exten, '', new ext_system('${ASTVARLIBDIR}/bin/fax2mail.php --to "${FAX_RX_EMAIL}" --dest "${FROM_DID}" --callerid \'${CALLERID(all)}\' --file ${ASTSPOOLDIR}/fax/${UNIQUEID}.tif --exten "${FAX_FOR}" --delete "${DELETE_AFTER_SEND}"')); 
    318326 
    319327    $ext->add($context, $exten, 'end', new ext_macro('hangupcall')); 
     
    391399} 
    392400 
    393 function fax_get_user($faxext){ 
     401function fax_get_user($faxext = ''){ 
    394402  global $db; 
    395   if($faxext){ 
    396     $sql="SELECT * FROM fax_users WHERE user = '".$faxext."'"; 
    397     $settings = $db->getRow($sql, DB_FETCHMODE_ASSOC); 
    398   }else{ 
    399     $sql="SELECT * FROM fax_users"; 
    400     $settings = $db->getAll($sql, DB_FETCHMODE_ASSOC); 
    401   } 
    402   if(!is_array($settings)){$settings=array();}//make sure were retuning an array (even if its blank) 
     403  if ($faxext) { 
     404    $sql    = "SELECT * FROM fax_users WHERE user = ?"; 
     405    $settings = $db->getRow($sql, array($faxext), DB_FETCHMODE_ASSOC); 
     406  } else { 
     407    $sql    = "SELECT * FROM fax_users"; 
     408    $settings = $db->getAll($sql, DB_FETCHMODE_ASSOC); 
     409  } 
     410  db_e($settings); 
     411   
     412  //make sure were retuning an array (even if its blank) 
     413  if (!is_array($settings)) { 
     414    $settings = array(); 
     415  } 
     416   
    403417  return $settings; 
    404418} 
     
    427441  if(!$extension && !$cidnum){//set $extension,$cidnum if we dont already have them 
    428442    if ($extdisplay) { 
    429       $opts=explode('/', $extdisplay); 
    430       $extension=$opts['0']; 
    431       $cidnum=$opts['1']
     443      $opts    = explode('/', $extdisplay); 
     444      $extension = $opts['0']; 
     445      $cidnum    = isset($opts['1']) ? $opts['1'] : ''
    432446    } else { 
    433447      $extension = $cidnum = ''; 
     
    625639} 
    626640 
    627 function fax_save_user($faxext,$faxenabled,$faxemail)
     641function fax_save_user($faxext,$faxenabled,$faxemail = '')
    628642  global $db; 
    629   $faxext=$db->escapeSimple($faxext); 
    630   $faxenabled=$db->escapeSimple($faxenabled); 
    631   $faxemail=$db->escapeSimple($faxemail); 
    632   sql('REPLACE INTO fax_users (user, faxenabled, faxemail) VALUES ("'.$faxext.'","'.$faxenabled.'","'.$faxemail.'")'); 
     643  $sql = 'REPLACE INTO fax_users (user, faxenabled, faxemail) VALUES (?, ?, ?)'; 
     644  $ret = $db->query($sql, array($faxext, $faxenabled, $faxemail)); 
     645  db_e($ret); 
     646 
     647  return true; 
    633648} 
    634649 
    635650function fax_sip_faxdetect(){ 
    636651  global $asterisk_conf; 
    637   return true; 
     652   return true; 
    638653} 
    639654 
     
    662677} 
    663678 
    664 function fax_tiff2pdf($file){ 
    665   exec('which tiff2pdf', $t2p); 
    666   $t2p = $t2p[0]; 
    667   if (!$t2p) { 
     679/** 
     680 * Converts a file to different format 
     681 * @param string - conversion type in the format of 'from2to' 
     682 * @param string - path to origional file 
     683 * @param string - path to save new file 
     684 * @param bool - wether to keep or delete the orgional file 
     685 * 
     686 * @return string - path to fresh pdf 
     687 * 
     688 * Supported conversions: 
     689 *  - pdf2tiff 
     690 *  - tif2pdf 
     691 *  - ps2tif 
     692 */ 
     693function fax_file_convert($type, $in, $out = '', $keep_orig = false, $opts = array()) { 
     694  global $amp_conf; 
     695  //ensure file exists 
     696  if (!is_file($in)) { 
    668697    return false; 
    669698  } 
    670699   
    671   //make pdf 
    672   $cmd = $t2p . ' -z -c "Converted by FreePBX" -a "www.freepbx.org" -o '  
    673         .  substr($file, 0, strrpos($file, '.')) . '.pdf' . ' ' . $file; 
    674   exec($cmd, $o, $error); 
    675  
    676   return $error === 0 ? true : false; 
     700  //set out filename if not specified 
     701  if (!$out) { 
     702    switch ($type) { 
     703      case 'pdf2tif': 
     704      case 'ps2tif': 
     705        $ext = '.tif'; 
     706        break; 
     707      case 'tif2pdf': 
     708        $ext = '.pdf'; 
     709        break; 
     710    } 
     711    $pathinfo = pathinfo($in); 
     712    $out = $pathinfo['dirname'] 
     713          . '/' 
     714          . $pathinfo['filename'] 
     715          . $ext; 
     716  } 
     717   
     718  //if file exists, assume its been converted already 
     719  if (file_exists($out)) { 
     720    return $out; 
     721  } 
     722   
     723  //ensure cli command exists 
     724  switch ($type) { 
     725    case 'pdf2tif': 
     726    case 'ps2tif': 
     727      $gs = fpbx_which('gs'); 
     728      if (!$gs) { 
     729        dbug('gs not found, not converting ' . $in); 
     730        return $in; 
     731      } 
     732      $gs = $gs . ' -q -dNOPAUSE -dBATCH -sPAPERSIZE=letter '; 
     733      break; 
     734    case 'tif2pdf': 
     735      $tiff2pdf = fpbx_which('tiff2pdf'); 
     736      if (!$tiff2pdf) { 
     737        dbug('tiff2pdf not found, not converting ' . $in); 
     738        return $in; 
     739      } 
     740      break; 
     741  } 
     742 
     743  //convert! 
     744  switch ($type) { 
     745    case 'pdf2tif': 
     746    case 'ps2tif': 
     747      $cmd = $gs 
     748        . '-sDEVICE=tiffg4 ' 
     749        . '-sOutputFile=' . $out . ' ' . $in; 
     750      break; 
     751    case 'tif2pdf': 
     752      $cmd = $tiff2pdf 
     753          . ' -z ' 
     754          . '-c "PBXact by Schmooze Communications" ' 
     755          . '-a "' . $amp_conf['PDFAUTHOR'] . '" ' 
     756          . (isset($opts['title']) ? '-t "' . $opts['title'] . '" ' : '') 
     757          . '-o ' . $out . ' ' . $in; 
     758      break; 
     759    default: 
     760      break; 
     761  } 
     762 
     763  exec($cmd, $ret, $status); 
     764   
     765  //remove original 
     766  if ($status === 0 && !$keep_orig) { 
     767    unlink($in); 
     768  } 
     769   
     770  return $status === 0 ? $out : $in; 
     771
     772 
     773/** 
     774 * Get info on a tiff file. Require tiffinfo 
     775 * @param string - absolute path to file 
     776 * @param string - specifc option to receive 
     777 * 
     778 * @return mixed - if $opt & exists returns a string, else bool false, 
     779 * otherwise an array of details 
     780 */ 
     781function fax_tiffinfo($file, $opt = '') { 
     782  //ensure file exists 
     783  if (!is_file($file)) { 
     784    return false; 
     785  } 
     786   
     787  $tiffinfo = fpbx_which('tiffinfo'); 
     788  $info   = array(); 
     789   
     790  if (!$tiffinfo) { 
     791    return false; 
     792  } 
     793  exec($tiffinfo . ' ' . $file, $output); 
     794   
     795  if ($output && strpos($output[0], 'Not a TIFF or MDI file') === 0) { 
     796    return false; 
     797  } 
     798   
     799  foreach ($output as $out) { 
     800    $o = explode(':', $out, 2); 
     801    $info[trim($o[0])] = isset($o[1]) ? trim($o[1]) : ''; 
     802  } 
     803   
     804  if (!$info) { 
     805    return false; 
     806  } 
     807   
     808  //special case prossesing 
     809  //Page Number: defualt format = 0-0. Use only first set of digits, increment by 1 
     810  $info['Page Number'] = explode('-', $info['Page Number']); 
     811  $info['Page Number'] = $info['Page Number'][0] + 1; 
     812   
     813  if ($opt) { 
     814    return isset($info[$opt]) ? $info[$opt] : false; 
     815  } 
     816   
     817  return $info; 
    677818} 
    678819?> 
  • modules/branches/2.10/fax/install.php

    r13091 r14150  
    272272  out(_("already done")); 
    273273} 
     274 
     275$set['value'] = 'www.freepbx.org'; 
     276$set['defaultval'] =& $set['value']; 
     277$set['readonly'] = 1; 
     278$set['hidden'] = 1; 
     279$set['module'] = ''; 
     280$set['category'] = 'Styling and Logos'; 
     281$set['emptyok'] = 0; 
     282$set['name'] = 'tiff2pdf Author'; 
     283$set['description'] = "Author to pass to tiff2pdf's -a option"; 
     284$set['type'] = CONF_TYPE_TEXT; 
     285$freepbx_conf =& freepbx_conf::create(); 
     286$freepbx_conf->define_conf_setting('PDFAUTHOR', $set, true); 
    274287?> 
  • modules/branches/2.10/findmefollow/functions.inc.php

    r14132 r14150  
    544544// extensions and users. 
    545545// 
    546 if ($amp_conf['FOLLOWME_AUTO_CREATE']) { 
     546if (isset($amp_conf['FOLLOWME_AUTO_CREATE']) && $amp_conf['FOLLOWME_AUTO_CREATE']) { 
    547547  function findmefollow_configprocess() { 
    548548    global $amp_conf;