Reloading retrieve_conf failed

17 posts / 0 new
Last post
Randy
Randy's picture
Reloading retrieve_conf failed

After installing FreePBX I am not able to use 'Apply Configuration Changes' succesfully. FreePBX is running, just like Asterisk. The problem is I can't effectuate the changes I entered in FreePBX. Doing that I started with Reload failed because retrieve_conf encountered an error: 126. After changing some filepermissions I ended up with Reload failed because retrieve_conf encountered an error: 255. The notification log on the dashboard isn't helpful. It only gives the above messages.

During the installation I encountered several problems, most of them solved by changing the filepermissions or installing extra software components. Now I think there is one step to take to finish the installation completely and get a fully functional system.
I don't think the FreePBX-software itself is failing. I suspect the combination of an existing Asterisk configuration on Suse extended by an install of FreePBX with a non-standard webroot.

Is there anyone who can give a few checkpoints?
What are the files and permissions to look for?

Basic configuration:
openSUSE 10.2
Asterisk 1.4.4
FreePBX 2.3.0RC1.1
Serverroot: http://localhost/asterisk (/srv/www/htdocs/asterisk)

dzone
dzone's picture
Same failure here

We are having the same problem in similar circumstances. We had a Centos4.5 box with Asterisk 1.4.10.1 already running, and we have just built everything to get FreePBX RC1 going.

We're close, but no cigar. For some reason the retrieve_conf fails just as you have described above. If we find a fix I will post it.

Rick Ross
DZone - fresh links for developers
http://www.dzone.com

final_target
final_target's picture
Reloading retrieve_conf failed

hi,
I had the same too, and solved it by reinstalling "framework-2.3.0.3.tgz" module, now it work properly. u can DL it from:
http://www.freepbx.org/trac/browser/modules/release/2.4

p_lindheimer
p_lindheimer's picture
Reloading retrieve_conf failed

Run retrieve_conf from the command line to see if you can get any more specific information:

cd /var/lib/asterisk/bin # or equivalent location on your distro
su - asterisk ./retrieve_conf

and see if any more details are provided as to where you are failing.

nigina
nigina's picture
hello, i had try to open

hello,

i had try to open ./retrieve_conf in terminal but it cannot be open. so i try to open in text editor and this is the result :

#!/usr/bin/php -q

<?php
if (! function_exists("_")) {
    function
_($str) {
        return
$str;
    }
}

ini_set('error_reporting', E_ALL & ~E_NOTICE);

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

//define("ASTERISK_CONF", "/etc/asterisk/asterisk.conf");
define("WARNING_BANNER", _(";--------------------------------------------------------------------------------;\n; Do NOT edit this file as it is auto-generated by FreePBX. All modifications to ;\n; this file must be done via the web gui. There are alternative files to make    ;\n; custom modifications, details at: <a href="http://freepbx.org/configuration_files" rel="nofollow">http://freepbx.org/configuration_files</a>       ;\n;--------------------------------------------------------------------------------;\n;\n\n"));

// Emulate gettext extension functions if gettext is not available
if (!function_exists('_')) {
    function
_($str) {
        return
$str;
    }
}

function
out($text) {
    echo
$text."\n";
}

function
outn($text) {
    echo
$text;
}

function
error($text) {
    echo
"[ERROR] ".$text."\n";
}

function
fatal($text, $extended_text="", $type="FATAL") {
    global
$db;

    echo
"[$type] ".$text." ".$extended_text."\n";

    if(!
DB::isError($db)) {
       
$nt = notifications::create($db);
       
$nt->add_critical('retrieve_conf', $type, $text, $extended_text);
    }

    exit(
1);
}

function
debug($text) {
    global
$debug;
   
    if (
$debug) echo "[DEBUG-preDB] ".$text."\n";
}

function
showHelp() {
   
out(_("Optional parameters:"));
   
out(_("  --help, -h, -?           Show this help"));
   
out(_("  --debug                  Enable debug output"));
   
out(_("  --dry-run                Don't actually do anything"));
}


// bootstrap retrieve_conf by getting the AMPWEBROOT since that is currently where the necessary
// functions.inc.php resides, and then use that parser to properly parse the file and get all
// the defaults as needed.
//
function parse_amportal_conf_bootstrap($filename) {
   
$file = file($filename);
    foreach (
$file as $line) {
        if (
preg_match("/^\s*([\w]+)\s*=\s*"?([\w\/\:\.\*\%-]*)"?\s*([;#].*)?/",$line,$matches)) {
           
$conf[ $matches[1] ] = $matches[2];
        }
    }
    if ( !isset(
$conf["AMPWEBROOT"]) || ($conf["AMPWEBROOT"] == "")) {
       
$conf["AMPWEBROOT"] = "/var/www/html";
    } else {
       
$conf["AMPWEBROOT"] = rtrim($conf["AMPWEBROOT"],'/');
    }

    return
$conf;
}

/** Adds a trailing slash to a directory, if it doesn't already have one
*/
function addslash($dir) {
    return ((
$dir[ strlen($dir)-1 ] == '/') ? $dir : $dir.'/');
}


/********************************************************************************************************************/

// **** Make sure we have STDIN etc

// from  ben-php dot net at efros dot com   at  php.net/install.unix.commandline
if (version_compare(phpversion(),'4.3.0','<') || !defined("STDIN")) {
   
define('STDIN',fopen("php://stdin","r"));
   
define('STDOUT',fopen("php://stdout","r"));
   
define('STDERR',fopen("php://stderr","r"));
   
register_shutdown_function( create_function( '' , 'fclose(STDIN); fclose(STDOUT); fclose(STDERR); return true;' ) );
}
  
// **** Make sure we have PEAR's DB.php, and include it

outn(_("Checking for PEAR DB.."));
if (! @ include(
'DB.php')) {
   
out(_("FAILED"));
   
fatal(_("PEAR Missing"),sprintf(_("PEAR must be installed (requires DB.php). Include path: %s "), ini_get("include_path")));
}
out(_("OK"));


// **** Make sure we have PEAR's GetOpts.php, and include it

outn(_("Checking for PEAR Console::Getopt.."));
if (! @ include(
"Console/Getopt.php")) {
   
out(_("FAILED"));
   
fatal(_("PEAR Getopt.php Missing"),sprintf(_("PEAR must be installed (requires Console/Getopt.php). Include path: %s"), ini_get("include_path")));
}
out(_("OK"));


// **** Parse out command-line options

$shortopts = "h?u:p:";
$longopts = array("help","debug","dry-run","run-install","amportalconf=");

$args = Console_Getopt::getopt(Console_Getopt::readPHPArgv(), $shortopts, $longopts);
if (
is_object($args)) {
   
// assume it's PEAR_ERROR
   
out($args->message);
    exit(
255);
}

$debug = false;
$dryrun = false;
$run_install = false;

foreach (
$args[0] as $arg) {
    switch (
$arg[0]) {
        case
"--help": case "h": case "?":
           
showHelp();
            exit(
10);
        break;
        case
"--dry-run":
           
out(_("Dry-run only, no files will be written"));
           
$dryrun = true;
        break;
        case
"--debug":
           
$debug = true;
           
debug(_("Debug mode enabled"));
        break;
        case
"--run-install":
           
$run_install = true;
           
out(_("Running module install.php and install.sql scripts"));
        break;
        case
"--amportalconf":
           
$amportalconf = $arg[1];
           
out(sprintf(_("Using %s configuration file"), $amportalconf));
        break;
    }
}

// **** Check for amportal.conf

outn(sprintf(_("Checking for %s "), $amportalconf)._(".."));
if (!
file_exists($amportalconf)) {
   
fatal(_("amportal.conf access problem: "),sprintf(_("The %s file does not exist, or is inaccessible"), $amportalconf));
}
out(_("OK"));

// **** read amportal.conf

outn(sprintf(_("Bootstrapping %s .."), $amportalconf));
$amp_conf = parse_amportal_conf_bootstrap($amportalconf);
if (
count($amp_conf) == 0) {
   
fatal(_("amportal.conf parsing failure"),sprintf(_("no entries found in %s"), $amportalconf));
}
out(_("OK"));

outn(sprintf(_("Parsing %s .."), $amportalconf));
require_once(
$amp_conf['AMPWEBROOT']."/admin/functions.inc.php");
$amp_conf = parse_amportal_conf($amportalconf);
if (
count($amp_conf) == 0) {
   
fatal(_("amportal.conf parsing failure"),sprintf(_("no entries found in %s"), $amportalconf));
}
out(_("OK"));

$asterisk_conf_file = $amp_conf["ASTETCDIR"]."/asterisk.conf";
outn(sprintf(_("Parsing %s .."), $asterisk_conf_file));
$asterisk_conf = parse_asterisk_conf($asterisk_conf_file);
if (
count($asterisk_conf) == 0) {
   
fatal(_("asterisk.conf parsing failure"),sprintf(_("no entries found in %s"), $asterisk_conf_file));
}
out(_("OK"));

// **** Connect to database

outn(_("Connecting to database.."));

# the engine to be used for the SQL queries,
# if none supplied, backfall to mysql
$db_engine = "mysql";
if (isset(
$amp_conf["AMPDBENGINE"])){
   
$db_engine = $amp_conf["AMPDBENGINE"];
}

// **** Create symlinks array
$symlink_dirs = array();
$symlink_dirs['sounds'] = $amp_conf['ASTVARLIBDIR'].'/sounds';
$symlink_dirs['bin']    = $amp_conf['AMPBIN'];
$symlink_dirs['etc']    = $amp_conf['ASTETCDIR'];
$symlink_dirs['images'] = $amp_conf['AMPWEBROOT']."/admin/images";

$cp_errors = "";
$cp_dirs = array();
$cp_dirs['agi-bin'] = $amp_conf['ASTAGIDIR'];

switch (
$db_engine)
{
    case
"pgsql":
    case
"mysql":
       
/* datasource in in this style:
        dbengine://username:<a href="mailto:password@host">password@host</a>/database */
   
       
$db_user = $amp_conf["AMPDBUSER"];
       
$db_pass = $amp_conf["AMPDBPASS"];
       
$db_host = $amp_conf["AMPDBHOST"];
       
$db_name = $amp_conf["AMPDBNAME"];
   
       
$datasource = $db_engine.'://'.$db_user.':'.$db_pass.'@'.$db_host.'/'.$db_name;
       
$db = DB::connect($datasource); // attempt connection
       
break;
   
    case
"sqlite":
       
die_freepbx("SQLite2 support is deprecated. Please use sqlite3 only.");
        break;
   
    case
"sqlite3":
        if (!isset(
$amp_conf["AMPDBFILE"]))
           
fatal("You must setup properly AMPDBFILE in $amportalconf");
           
        if (isset(
$amp_conf["AMPDBFILE"]) == "")
           
fatal("AMPDBFILE in $amportalconf cannot be blank");

       
/* on centos this extension is not loaded by default */
       
if (! extension_loaded('sqlite3.so')  && ! extension_loaded('SQLITE3'))
           
dl('sqlite3.so');

        if (! @require_once(
'DB/sqlite3.php') )
        {
           
die_freepbx("Your PHP installation has no PEAR/SQLite3 support. Please install php-sqlite3 and php-pear.");
        }

        require_once(
'DB/sqlite3.php');
       
$datasource = "sqlite3:///" . $amp_conf["AMPDBFILE"] . "?mode=0666";
       
$db = DB::connect($datasource);
        break;

    default:
       
fatal( "Unknown SQL engine: [$db_engine]");
}

if(
DB::isError($db)) {
   
out(_("FAILED"));
   
debug($db->userinfo);
   
fatal(_("database connection failure"),("failed trying to connect to the configured database"));
   
}
out(_("OK"));

// Define the notification class for logging to the dashboard
//
$nt = notifications::create($db);

/*
*/
// Check and increase php memory_limit if needed and if allowed on the system
//
$current_memory_limit = rtrim(ini_get('memory_limit'),'M');
$proper_memory_limit = '100';
if (
$current_memory_limit < $proper_memory_limit) {
    if (
ini_set('memory_limit',$proper_memory_limit.'M') !== false) {
       
$nt->add_notice('core', 'MEMLIMIT', _("Memory Limit Changed"), sprintf(_("Your memory_limit, %sM, is set too low and has been increased to %sM. You may want to change this in you php.ini config file"),$current_memory_limit,$proper_memory_limit));
    } else {
       
$nt->add_warning('core', 'MEMERR', _("Low Memory Limit"), sprintf(_("Your memory_limit, %sM, is set too low and may cause problems. FreePBX is not able to change this on your system. You should increase this to %sM in you php.ini config file"),$current_memory_limit,$proper_memory_limit));
    }
} else {
   
$nt->delete('core', 'MEMLIMIT');
}

//TODO : make this engine-neutral
outn(_("Connecting to Asterisk manager interface.."));
// connect to asterisk manager
require_once($amp_conf['AMPWEBROOT'].'/admin/common/php-asmanager.php');
$astman = new AGI_AsteriskManager();
if (!
$res = $astman->connect("127.0.0.1:".$amp_conf["ASTMANAGERPORT"], $amp_conf["AMPMGRUSER"] , $amp_conf["AMPMGRPASS"])) {
   
out(_("FAILED"));
   
fatal(_("Asterisk Manager Connection Failure"),sprintf(_("Failed to connect to the Asterisk manager through port: %s"), $amp_conf['ASTMANAGERPORT']));
}
out(_("OK"));

//include common functions
require_once($amp_conf['AMPWEBROOT']."/admin/extensions.class.php");
freepbx_log("retrieve_conf", "devel-debug", "Started retrieve_conf, DB Connection OK");

// query for our modules
// var_dump( $db );
$modules = module_getinfo();

//Putting the core module last, to move outbound-allroutes
// last in from-internals-additional
if (array_key_exists('core', $modules)) {
       
$core_tmp = $modules['core'];
        unset(
$modules['core']);
       
$modules['core'] = $core_tmp;
}

// include any module global functions
if(is_array($modules)){
    foreach(
$modules as $key => $module) {
       
//only use this module if it's enabled (status=2)
       
if (isset($module['status']) && $module['status'] == MODULE_STATUS_ENABLED) {
           
// Make sure the module is installed and up to date
           
if ($run_install) module_install($key);
           
// active_modules array used in genConf function
           
$active_modules[] = $key;
           
//include module functions
           
if (is_file($amp_conf['AMPWEBROOT']."/admin/modules/{$key}/functions.inc.php")) {
               
freepbx_log('retrieve_conf', 'devel-debug', 'Including '.$amp_conf['AMPWEBROOT']."/admin/modules/{$key}/functions.inc.php");
                include_once(
$amp_conf['AMPWEBROOT']."/admin/modules/{$key}/functions.inc.php");
               
freepbx_log('retrieve_conf', 'devel-debug', $amp_conf['AMPWEBROOT']."/admin/modules/{$key}/functions.inc.php processed OK");
            }

           
// create symlinks for files in appropriate sub directories
            // don't symlink framework files, it is a special case module that happens to have
            // some conflicting names
            //
           
if ($key != 'framework') {
               
symlink_subdirs( $amp_conf['AMPWEBROOT'].'/admin/modules/'.$key );
               
cp_subdirs( $amp_conf['AMPWEBROOT'].'/admin/modules/'.$key );
            }
        }
    }
}
// Now also make sure to symlink the CDR images which is not a proper module
//
symlink_subdirs( $amp_conf['AMPWEBROOT'].'/admin/cdr/');

// create an object of the extensions class
require_once($amp_conf['AMPWEBROOT']."/admin/extensions.class.php");
$ext = new extensions;

// create objects for any module classes
// currently only 1 class can be declared per module, not sure if that will be an issue
if(isset($active_modules) && is_array($active_modules)){
    foreach(
$active_modules as $active_module) {
       
freepbx_log('retrieve_conf', 'devel-debug', "Creating ".$active_module."_conf class");
       
$classname = $active_module."_conf";
        if(
class_exists($classname)) {
            ${
$classname} = new $classname;
        }
    }
}

$engineinfo = engine_getinfo();
if(
$engineinfo['version'] == 0){
   
freepbx_log('retrieve_conf', 'fatal', "Failed to get engine information (engine_getinfo: {$engineinfo['engine']})");
   
fatal(_("Failed to get engine_info"),_("retreive_conf failed to get engine information and cannot configure up a softwitch with out it. Error: {$engineinfo['engine']}"));
}
// was setting these variables before, assume we still need them
$engine = $engineinfo['engine'];
$version = $engineinfo['version'];
$chan_dahdi = ast_with_dahdi();

// Check for and report any extension conflicts
//

$extens_ok = true;
$dests_ok = true;

$nt = notifications::create($db);

$my_hash = array_flip($active_modules);
$my_prob_extens = framework_list_extension_conflicts($my_hash);

if (empty(
$my_prob_extens)) {
   
$nt->delete('retrieve_conf', 'XTNCONFLICT');
} else {
   
$previous = null;
   
$str = null;
   
$count = 0;
    foreach (
$my_prob_extens as $extens) {
        foreach (
$extens as $exten => $details) {
            if (
$exten != $previous) {
               
$str .=  "Extension: $exten:<br />";
               
$count++;
            }
           
$str .= sprintf("%8s: %s<br />",$details['status'], $details['description']);
           
$previous = $exten;
        }
    }
   
$nt->add_error('retrieve_conf', 'XTNCONFLICT', sprintf(_("There are %s conflicting extensions"),$count), $str);
   
$extens_ok = false;
}

// Check for and report any bogus destinations
//
$my_probs = framework_list_problem_destinations($my_hash, !$amp_conf['CUSTOMASERROR']);

if (empty(
$my_probs)) {
   
$nt->delete('retrieve_conf', 'BADDEST');
} else {
   
$results = array();
   
$count = 0;
   
$str = null;
    foreach (
$my_probs as $problem) {
       
//print_r($problem);
       
$results[$problem['status']][] = $problem['description'];
       
$count++;
    }
    foreach (
$results as $status => $subjects) {
       
$str .= sprintf(_("DEST STATUS: %s%s"),$status,"\n");
        foreach (
$subjects as $subject) {
           
//$str .= $subject."<br />";
           
$str .= "   ".$subject."\n";
        }
    }
   
$nt->add_error('retrieve_conf', 'BADDEST', sprintf(_("There are %s bad destinations"),$count), $str);
   
$dests_ok = false;
}

if ((!
$exten_ok && $amp_conf['XTNCONFLICTABORT']) || (!$dest_ok && $amp_conf['BADDESTABORT'])) {
   
out(_("Aborting reload because extension conflicts or bad destinations"));
    exit(
20);
}

// run all of the *_get_config and _hookGet_config functions, which will populate the appropriate objects
if(isset($active_modules) && is_array($active_modules)){
    foreach(
$active_modules as $module) {
       
$funcname = $module."_get_config";
        if (
function_exists($funcname)) {
           
freepbx_log('retrieve_conf', 'devel-debug', 'Calling '.$funcname.'()');
           
$funcname($engine);
        }
    }
    foreach(
$active_modules as $module) {
       
$funcname = $module."_hookGet_config";
        if (
function_exists($funcname)) {
           
freepbx_log('retrieve_conf', 'devel-debug', 'Calling '.$funcname.'()');
           
$funcname($engine);
        }
    }
}

// extensions_additional.conf
// create the from-internal-additional context so other can add to it
$ext->add('from-internal-additional', 'h', '', new ext_hangup(''));
//echo $ext->get_filename();
//echo $ext->generateConf();
write_file($ext->get_filename(),$ext->generateConf());

// now we write out our conf files for modules
// check for any objects for each of the active modules
// ** conferences is an example of a module that write a conf
if(isset($active_modules) && is_array($active_modules)){
    foreach(
$active_modules as $active_module) {
       
$classname = $active_module."_conf";
        if(
class_exists($classname) && get_class(${$classname}) !== false) {
           
//echo ${$classname}->get_filename();
            //echo ${$classname}->generateConf();
           
            // if the module returns an array, it wants to write multiple files
            // ** pinsets is an example of a module that does this
           
if (is_array(${$classname}->get_filename())) {
                foreach(${
$classname}->get_filename() as $modconf) {
                   
freepbx_log('retrieve_conf', 'devel-debug', 'generateConf from '.$classname.'->'.$modconf.'');
                    if (isset(${
$classname}->use_warning_banner)) {
                       
write_file($modconf,${$classname}->generateConf($modconf),${$classname}->use_warning_banner);
                    } else {
                       
write_file($modconf,${$classname}->generateConf($modconf));
                    }
                }
            } else {
               
freepbx_log('retrieve_conf', 'devel-debug', 'generateConf from '.$classname);
                if (isset(${
$classname}->use_warning_banner)) {
                   
write_file(${$classname}->get_filename(),${$classname}->generateConf(),${$classname}->use_warning_banner);
                } else {
                   
write_file(${$classname}->get_filename(),${$classname}->generateConf());
                }
            }
        }
    }
}


function
write_file($filename,$contents,$use_warning_banner=true) {
    global
$asterisk_conf;
   
freepbx_log('retrieve_conf', 'devel-debug', 'Writing '.$filename);
    if (isset(
$filename) && !empty($filename)) {
        if (
$fd = fopen(addslash($asterisk_conf['astetcdir']).$filename, "w")) {
            if (
$use_warning_banner) {
               
fwrite($fd, WARNING_BANNER );
            }
           
fwrite($fd, $contents);
           
fclose($fd);
        }
    }
}

/* file_exists_wrapper()
* wrapper for file_exists() with the following additonal functionality.
* if the file is a symlink, it will check if the link exists and if not
* it will try to remove this file. It returns a false (file does not exists)
* if the file is successfully removed, true if not. If not a symlink, just
* returns file_exists()
*/
function file_exists_wrapper($string) {
    if (
is_link($string)) {
       
$linkinfo = readlink($string);
        if (
$linkinfo === false) {
           
//TODO: throw error?
           
return !unlink($string);
        } else {
            if (
file_exists($linkinfo)) {
                return
true;
            } else {
                return !
unlink($string);
            }
        }
    } else {
        return
file_exists($string);
    }
}

function
symlink_subdirs($moduledir) {
    global
$symlink_dirs;
   
$symlink_errors = false;

   
$nt = notifications::create($db);

   
$error_modules = '';
    foreach (
$symlink_dirs as $subdir => $targetdir) {
       
$dir = addslash($moduledir).$subdir;
        if (
is_dir($dir)) {
           
$d = opendir($dir);
            while (
$file = readdir($d)) {
                if (
$file[0] != '.') {
                   
$src = addslash($dir).$file;
                   
$dest = addslash($targetdir).$file;
                    if (
file_exists_wrapper($dest)) {
                        if (!
is_link($dest)) {
                           
freepbx_log('retrieve-conf', 'error', $dest.' already exists, and is not a symlink!');
                           
$error_modules .= "<br />&nbsp;&nbsp;&nbsp;".$dest;
                           
$symlink_errors = true;
                        } else if (
readlink($dest) != $src) {
                           
// TODO : is this the proper handling? should we just overwrite..?
                           
freepbx_log('retrieve-conf', 'error', $dest.' already exists, and is linked to something else!');
                           
$error_modules .= "<br />&nbsp;&nbsp;&nbsp;".$dest;
                           
$symlink_errors = true;
                        } else {
                           
freepbx_log('retrieve-conf', 'devel-debug', $dest.' already points to '.$src.' - OK');
                        }
                    } else {
//                        // symlink, unlike copy, doesn't overwrite - have to delete first
//                        if (is_link($dest) || file_exists($dest)) {
//                            unlink($dest);
//                        }
                       
if (symlink($src, $dest)) {
                           
freepbx_log('retrieve-conf', 'devel-debug', 'Symlinked '.$src.' to '.$dest);
                        } else {
                           
freepbx_log('retreive-conf', 'devel-debug', 'Cannot symlink '.$src.' to '.$dest.'. Check Permissions?');
                        }
                    }
                }
            }
           
closedir($d);
        }
    }
    if (
$error_modules) {
       
$nt->add_error('retrieve_conf', 'SYMLINK', _("Symlink from modules failed"), sprintf(_("retrieve_conf failed to sym link: %s<br \>This can result in FATAL failures to your PBX. If the target file exists, the symlink will not occur and you should rename the target file to allow the automatic sym link to occur and remove this error, unless this is an intentional customization."),$error_modules));
    } else {
       
$nt->delete('retrieve_conf', 'SYMLINK');
    }
}

// wrap copy with error handler
//
function err_copy($source, $dest) {
   
$ret = false;
   
set_error_handler("report_errors");
    if (
copy($source, $dest)) {
       
$ret = chmod($dest,0754);
    }
   
restore_error_handler();
    return
$ret;
}

// wrap unlink with error handler
//
function err_unlink($dest) {
   
set_error_handler("report_errors");
   
$ret = unlink($dest);
   
restore_error_handler();
    return
$ret;
}

function
cp_subdirs($moduledir) {
    global
$cp_errors;
    global
$cp_dirs;

   
$cp_errors = "";
    foreach (
$cp_dirs as $subdir => $targetdir) {
       
$dir = addslash($moduledir).$subdir;
        if (
is_dir($dir)) {
           
$d = opendir($dir);
            while (
$file = readdir($d)) {
                if (
$file[0] != '.') {
                   
$sourcefile = addslash($dir).$file;
                   
$targetfile = addslash($targetdir).$file;

                    if (
file_exists_wrapper($targetfile)) {
                        if (
is_link($targetfile)) {
                            if (
err_unlink($targetfile)) {
                               
freepbx_log('retrieve-conf', 'devel-debug', "$targetfile was symbolic link, unlink successful");
                            } else {
                               
freepbx_log('retrieve-conf', 'error', "$targetfile is a symblolic link, failed to unlink!");
                                break;
                            }
                        }
                    }
                   
// OK, now either the file is a regular file or isn't there, so proceed
                    //
                   
if (err_copy($sourcefile,$targetfile)) {
                       
freepbx_log('retrieve-conf', 'devel-debug', "$targetfile successfully copied");
                       
// copy was successful, make sure it has execute permissions
                       
chmod($targetfile,0754);
                    } else {
                       
freepbx_log('retrieve-conf', 'error', "$targetfile failed to copy from module directory");
                    }
                }
            }
           
closedir($d);
        }
    }
   
$nt = notifications::create($db);
    if (
$cp_errors) {
       
$nt->add_error('retrieve_conf', 'CPAGIBIN', _("Failed to copy from module agi-bin"), sprintf(_("Retrieve conf failed to copy file(s) from a module's agi-bin dir: %s"),$cp_errors));
    } else {
       
$nt->delete('retrieve_conf', 'CPAGIBIN');
    }
}

function
report_errors($errno, $errstr, $errfile, $errline) {
    global
$cp_errors;
    switch(
$db_engine) {
        case
"sqlite3":
           
$escaped_string = sqlite_real_escape($errstr);
            break;
        case
"mysql":
           
$escaped_string = mysql_real_escape_string($errstr);
            break;
        case
"pgsql":
           
$escaped_string = pgsql_escape_string($errstr);
            break;
    }
   
freepbx_log('retrieve-conf', 'error', "php reported: '$escaped_string' after copy or unlink attempt!");
   
$cp_errors .= $errstr."\n";
}

/** Check if there is a job running, if one is found then all is good, if one is not found, it will be added and a
*  notification will be sent.
*/
function install_cron_scheduler() {
    global
$amp_conf;
    global
$nt;

   
// crontab appears to return an error when no entries, os only fail if error returned AND a list of entries.
    // Don't know if this will ever happen, but a failure and a list could indicate something wrong.
    //
   
$outlines = array();
   
exec("/usr/bin/crontab -l", $outlines, $ret);
    if (
$ret && count($outlines)) {
       
$nt->add_error('retrieve_conf', 'CRONMGR', _("Failed to check crontab for cron manager"), sprintf(_("crontab returned %s error code when checking for crontab entries to start freepbx-cron-scheduler.php crontab manager"),$ret));
    } else {
       
$nt->delete('retrieve_conf', 'CRONMGR');
       
$outlines2 = preg_grep("/freepbx-cron-scheduler.php/",$outlines);
       
$cnt = count($outlines2);
        switch (
$cnt) {
            case
0:
               
/** grab any other cronjobs that are running as asterisk and NOT associated with backups
                 *  this code was taken from the backup module for the most part. But seems to work...
                 */
               
$outlines = array();
               
exec("/usr/bin/crontab -l | grep -v ^#\ DO\ NOT | grep -v ^#\ \( |  grep -v freepbx-cron-scheduler.php", $outlines, $ret);
               
$crontab_entry = "";
                foreach (
$outlines as $line) {
                   
$crontab_entry .= $line."\n";
                }
               
// schedule to run hourly, at a random time. The random time is explicit to accomodate things like module_admin online update checking
                // since we will want a random access to the server. In the case of module_admin, that will also be scheduled randomly within the hour
                // that it is to run
                //
               
$crontab_entry .= rand(0,59)." * * * * ".$amp_conf['AMPBIN']."/freepbx-cron-scheduler.php";
               
system("/bin/echo '$crontab_entry' | /usr/bin/crontab -");
                break;
            case
1:
               
// already running, nothing to do
               
break;
            default:
               
// error, there should never be more than one running
               
echo "TODO: deal with error here\n";
               
$nt->add_error('retrieve_conf', 'CRONMGR', _("Multiple freepbx-cron-scheduler.php running"), sprintf(_("There were %s freepbx-cron-scheduler.php instances running. There should be only 1."),$cnt));
        }
    }
}

// script to write op_server.cfg file from mysql
//
if(!$amp_conf['FOPDISABLE'])  {
  if (!@include(
"retrieve_op_conf_from_mysql.php")) {
       
error(_("error running retrieve_op_conf_from_mysql.php"));
  }
 
/*
    $script = $amp_conf['AMPBIN'].'/retrieve_op_conf_from_mysql.php';
    if (is_executable($script)) {
        $script .= ' '.$amportalconf.' '.rtrim($asterisk_conf['astetcdir'],DIRECTORY_SEPARATOR);
        $output = array();
        exec($script, $output, $ret);
        if ($ret) {
            error(sprintf(_("retrieve_op_conf_from_mysql.php returned with an error code %s"),$ret));
        }
    } else {
        error(_("retrieve_op_conf_from_mysql.php does not exist or is not executable"));
    }
  */
}
// generate configuration files
//
// Leave the legacy scripts in for a little while to help with odd-ball upgrade scenarios if they haven't gotten
// a module upgraded yet. In particular Queues
//
if (!isset($core_conf) || !is_a($core_conf, "core_conf")) {
    include_once(
"libfreepbx.confgen.php");
   
generate_configurations_sip($version);
   
generate_configurations_iax($version);
   
generate_configurations_zap($version);
}
if (!isset(
$queues_conf) || !is_a($queues_conf, "queues_conf")) {
    include_once(
"libfreepbx.confgen.php");
   
generate_configurations_queues($version);
}
   
// Check and install the freepbx-cron-scheduler.php manager
//
install_cron_scheduler();


// run retrieve_conf_post_custom
// If the following file exists, it will be run. This allows customization to be run automatically after the normal
// processing. Caution should be taken using this as it is only deisgned for expert usage. Errors in the code will
// have bad consequences and can cripple the system.
//
if (isset($amp_conf['AMPLOCALBIN'])) {
$post_custom = $amp_conf['AMPLOCALBIN'].'/retrieve_conf_post_custom';
    if (
file_exists($post_custom)) {
       
outn(sprintf(_("Found script %s, executing.."), $post_custom));
        include(
$post_custom);
       
out(_("OK"));
    }
}

/* As of Asterisk 1.4.16 or there abouts, a missing #include file will make the reload fail. So
   we need to make sure that we have such for everything that is in our configs. We will simply
     look for the #include statements and touch the files vs. trying to inventory everything we may
     need and then forgetting something.
*/

$output = array();
exec("grep '#include' ".$amp_conf['ASTETCDIR']."/*.conf | sed 's/;.*//; s/#include//'",$output,$retcode);
if (
$retcode != 0) {
   
error("Error code $retcode: trying to search for missing #include files");
}

foreach(
$output as $file) {
    if (
trim($file) == '') {
        continue;
    }
   
$parse1 = explode(':',$file);
   
$parse2 = explode(';',$parse1[1]);
   
$rawfile = trim($parse2[0]);
    if (
$rawfile == '') {
        continue;
    }

   
$target = ($rawfile[0] == '/') ? $rawfile : $amp_conf['ASTETCDIR']."/$rawfile";

    if (!
file_exists($target)) {
       
$output = array();
       
exec("touch $target", $output, $retcode);
        if (
$retcode != 0) {
           
error("Error code $retcode: trying to create empty file $target");
        }
    }
}


// **** Set reload flag for AMP admin
needreload();
if (isset(
$amp_conf["AMPWEBADDRESS"]) && $amp_conf["AMPWEBADDRESS"])
{
   
out(sprintf(_("Please update your modules and reload Asterisk by visiting %s"), "http://".$amp_conf["AMPWEBADDRESS"]."/admin"));
}
else
{
   
out(_("Please update your modules and reload Asterisk by browsing to your server."));
}
   
$nt->delete('retrieve_conf', 'FATAL');
?>

hope you can give some idea,tq.

Randy
Randy's picture
Reloading retrieve_conf failed

Thanks for the hint.
Using "su - asterisk ./retrieve_conf" didn't show any traces, even using tail. However, when i did run ./retrieve_conf as root i got the following line:

PHP Fatal error: Call to undefined function _() in /var/lib/asterisk/bin/retrieve_conf on line 10

This line says:
define("WARNING_BANNER", "; "._("do not edit this file, this is an auto-generated file by freepbx\n")."; "._("all modifications must be done from the web gui")."\n\n\n");

To lazy to figure out what was wrong with the line I simply commented it out and rerun the script (again as root). Now it showed

[code]Checking for PEAR DB..OK
Checking for PEAR Console::Getopt..OK
Checking for /etc/amportal.conf ..OK
Bootstrapping /etc/amportal.conf ..OK
Parsing /etc/amportal.conf ..OK
Parsing /etc/asterisk/asterisk.conf ..OK
Connecting to database..OK
Connecting to Asterisk manager interface..OK
Added to globals: ASTETCDIR = /etc/asterisk
Added to globals: ASTMODDIR = /usr/lib/asterisk/modules
Added to globals: ASTVARLIBDIR = /var/lib/asterisk
Added to globals: ASTAGIDIR = /var/lib/asterisk/agi-bin
Added to globals: ASTSPOOLDIR = /var/spool/asterisk
Added to globals: ASTRUNDIR = /var/run/asterisk
Added to globals: ASTLOGDIR = /var/log/asterisk
Added to globals: CWINUSEBUSY = true
Added to globals: AMPMGRUSER = admin
Added to globals: AMPMGRPASS = amp111
Please update your modules and reload Asterisk by visiting http://192.168.1.2/admin

The problems seems te solved. It's now possible to do 'Apply Configuration Changes' in FreePBX. I think I still didn't solved the real problem, but for now it works for me.
There are a few points left:
- I still don't know why the script failed.
- It's not possible for me to run the scripts as the user asterisk.
- The last line of output generated by the script shows the wrong url because it uses AMPWEBADDRESS instead of AMPWEBROOT.

p_lindheimer
p_lindheimer's picture
Reloading retrieve_conf failed

can you try the following patch:

Index: retrieve_conf
===================================================================
--- retrieve_conf (revision 4852)
+++ retrieve_conf (working copy)
@@ -1,6 +1,13 @@
#!/usr/bin/php -q

<?php
+
+if (! function_exists("_")) {
+ function _($str) {
+ return $str;
+ }
+}
+
ini_set('error_reporting', E_ALL & ~E_NOTICE);

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

You appear not to have the localization environment setup (the _() function) and this will fix that. As far as not being able to run as asterisk, that is problematic and you will want to get to root cause on that.

But please try the above patch as you have pointed out a valid bug that should be addressed which is to define the function if it is not in your environment.

dzone
dzone's picture
Re: Same failure here

dzone wrote:

We're close, but no cigar. For some reason the retrieve_conf fails just as you have described above. If we find a fix I will post it.

OK, it turns out this problem was all about permissions for us. Our apache is running as daemon/daemon, and it is not a desirable option for us to run apache on this machine as asterisk/asterisk.

It would be great if you could somehow supply the user/group under which apache is running and have FreePBX use those. We thought that possibly we could take advantage of suEXEC to help with this, but it didn't help.

We added daemon to the asterisk group, and we have had to add g+w to a lot of files and directories, but now it is mostly ok. The biggest problem is that many of the files/dirs being created by FreePBX and Asterisk are not group-writeable.

Rick

p_lindheimer
p_lindheimer's picture
Reloading retrieve_conf failed

the problem is with Asterisk and how it sets permissions on some voicemail files (600). Until we get to the point where we have a daemon (in the plans) it needs to run as asterisk or you will have problems with some functionality.

However - did the above patch fix the _() problem for you, feedback would be appreciated.

Randy
Randy's picture
Reloading retrieve_conf failed

The posted patch is ok.
The generated output file now contains the lines:
; do not edit this file, this is an auto-generated file by freepbx
; all modifications must be done from the web gui

carlcarr
carlcarr's picture
Reload failed because retrieve_conf encountered an error: 255

I am still getting the error message after applying the patch. FreePBX notice: retrieve_conf failed, config not appliedReload failed because retrieve_conf encountered an error: 255
Added ago
(freepbx.RCONFFAIL)

I tried su - asterisk ./retrieve_conf but I am getting an error on line 3 and line 11. This happened right after the upgrade this morning.

UPDATE NOTICE: There are 3 modules available for online upgrades framework 2.4.0beta1.1 (current: 2.4.0beta1.0) parking 2.4.0.2 (current: 2.4.0.1) core 2.4.0beta1.2 (current: 2.4.0beta1.1)

carlcarr
carlcarr's picture
Cannot download the latest framework update

Downloading framework 0 of (0%)Error(s) downloading framework:
Error opening http://mirror.freepbx.org/modules/release/2.4/framework-2.4.0beta1.2.tgz for reading

--------------------------------------------------------------------------------

p_lindheimer
p_lindheimer's picture
bad timing - try again, make

bad timing - try again, make sure it had been 10 minutes since the last time you tried.

carlcarr
carlcarr's picture
All is fine now

Hello Philippe,

All is working now after the upgrade. - Thank you for being a part of FreePBX. I cetainly appreciate your hard work and devotion. I am not a guru but, I am willing to help out where I can if you need any assistance.

Carl

jdaustin
jdaustin's picture
I got this error and

I got this error and determined that PHP was running out of memory.
I increased this line and it worked fine after that:

#memory_limit = 16M ; Maximum amount of memory a script may consume
memory_limit = 64M ; Maximum amount of memory a script may consume

eseixas
eseixas's picture
Use of uninitialized value in string

When i run the /var/lib/asterisk/bin/retrieve_conf i'm getting this message:

Checking for PEAR DB..OK
Checking for PEAR Console::Getopt..OK
Checking for /etc/amportal.conf ..OK
Bootstrapping /etc/amportal.conf ..OK
Parsing /etc/amportal.conf ..OK
Parsing /etc/asterisk/asterisk.conf ..OK
Connecting to database..OK
Connecting to Asterisk manager interface..OK
Added to globals: ASTETCDIR = /etc/asterisk
Added to globals: ASTMODDIR = /usr/lib/asterisk/modules
Added to globals: ASTVARLIBDIR = /var/lib/asterisk
Added to globals: ASTAGIDIR = /var/lib/asterisk/agi-bin
Added to globals: ASTSPOOLDIR = /var/spool/asterisk
Added to globals: ASTRUNDIR = /var/run/asterisk
Added to globals: ASTLOGDIR = /var/log/asterisk
Added to globals: CWINUSEBUSY = true
Use of uninitialized value in string eq at /var/lib/asterisk/bin/retrieve_op_conf_from_mysql.pl line 415.

Any idea ?

fskrotzki
fskrotzki's picture
Not enough details to even

Not enough details to even guess. What version of FreePBX are you running? have you looked at the file at around line 415 to see what it is doing? Did it just suddenly start happening? is this a new install? what was changed previous to this?

In that the code for this file had some big changes (a hundred or so lines added) to it when 2.4.0.0 came out or right after it not possible to just guess.