Feature #43

Parse amportal.conf for DB connection id/pw

Added by tshif almost 3 years ago. Updated over 2 years ago.

Status:Closed Start:05/08/2009
Priority:Normal Due date:
Assigned to:boolah % Done:

100%

Category:-
Target version:Concurrent Calls 2.0.4

Description

This code is used in several modules. You may wish to look at it as you create your own solution.

require_once 'DB.php';

define("AMP_CONF", "/etc/amportal.conf");

$amp_conf = parse_amportal_conf(AMP_CONF);
if (count($amp_conf) == 0) {
fatal("FAILED");
}

function parse_amportal_conf($filename) {
$file = file($filename);
foreach ($file as $line) {
if (preg_match("/^\s*([a-zA-Z0-9_]+)\s*=\s*(.*)\s*([;#].*)?/",$line,$matches)) {
$conf[ $matches1 ] = $matches2;
}
}
return $conf;
}

// DataBase config
$dbConf['user'] = $amp_conf['AMPDBUSER'];
$dbConf['pass'] = $amp_conf['AMPDBPASS'];
$dbConf['name'] = $amp_conf['AMPENGINE'];

PBXIAF Forum user JAMES provided this example:
(http://pbxinaflash.com/forum/showpost.php?p=26594&postcount=29)

$ampconfraw=trim(file_get_contents('amportal.conf'));
$ampconfraw = preg_replace('/#.+/', '', $ampconfraw);
preg_match_all('/(.+)\=(.+)/', $ampconfraw, $ampconfs);
$settings = array_combine($ampconfs1, $ampconfs2);

$dbServer = ($settings[CDRDBHOST]?$settings[CDRDBHOST]:$settings[AMPDBHOST]) ;
$dbUser = ($settings[CDRDBUSER]?$settings[CDRDBUSER]:$settings[AMPDBUSER]);
$dbPass = ($settings[CDRDBPASS]?$settings[CDRDPASS]:$settings[AMPDBPASS]);
$database = ($settings[CDRDBNAME]?$settings[CDRDBHOST]:"asteriskcdrdb");

History

Updated by boolah almost 3 years ago

  • Status changed from New to Closed
  • % Done changed from 0 to 100

This should now be included in revision 10. Thanks to both Tony and James for the code!

Updated by tshif over 2 years ago

  • Target version changed from Concurrent Calls Future Versions to Concurrent Calls 2.0.4

Also available in: Atom PDF