Asterisk config files not updated - $asterisk_conf['astetcdir'] empty

Yesterday I tried to make changes to one of my connections and pressed the “orange” button. No changes saved because the asterisk config files in /etc/asterisk were not updated. After many hours I’m stuck with the following observations:

When I run “retrieve_conf --debug” I get the following error messages:

[DEBUG-retrieve_conf] (devel-debug) Writing extensions_additional.conf PHP Warning: fopen(/extensions_additional.conf): failed to open stream: Permission denied in /var/lib/asterisk/bin/retrieve_conf on line 502 [DEBUG-retrieve_conf] (devel-debug) generateConf from queues_conf->queues_additional.conf [DEBUG-retrieve_conf] (devel-debug) Writing queues_additional.conf PHP Warning: fopen(/queues_additional.conf): failed to open stream: Permission denied in /var/lib/asterisk/bin/retrieve_conf on line 502 [DEBUG-retrieve_conf] (devel-debug) generateConf from queues_conf->queues_general_additional.conf [DEBUG-retrieve_conf] (devel-debug) Writing queues_general_additional.conf PHP Warning: fopen(/queues_general_additional.conf): failed to open stream: Permission denied in /var/lib/asterisk/bin/retrieve_conf on line 502

The problem seems to be that $asterisk_conf[‘astetcdir’] on line 502 returns an empty string. This results in the asterisk user tries to write to the Linux root directory. Since the asterisk user doesn’t have access to / permission denied is thrown. (By doing a su from the asterisk user, the files are written to /)

My question to the group is why is this suddenly happening? Is it my upgrade to CentoOS 5.3? Is it the upgrade of FreePBX to 2.5.1.5? I’m running PIAF 1.4 with all the latest scripts and fixes.

Anyone have a suggestion to what I can do to fix this problem with the empty string returned from $asterisk_conf[‘astetcdir’]?

Look in /etc/amportal.conf, does it contain at least:

AMPDBUSER=asteriskuser
AMPDBPASS=amp109
AMPDBNAME=asterisk
ASTETCDIR=/etc/asterisk
ASTMODDIR=/usr/lib/asterisk/modules
ASTVARLIBDIR=/var/lib/asterisk
ASTAGIDIR=/var/lib/asterisk/agi-bin
ASTSPOOLDIR=/var/spool/asterisk
ASTRUNDIR=/var/run/asterisk
ASTLOGDIR=/var/log/asterisk

If not, then add the above. If you have changed password in the past, then put your password instead of the default ‘amp109’.

I’ve not made any changes except for turning on logging. The content of my amportal.conf file is:

#Piaf specific section AMPDBUSER=asteriskuser AMPDBPASS=amp109 AMPDBNAME=asterisk ASTETCDIR=/etc/asterisk ASTMODDIR=/usr/lib/asterisk/modules ASTVARLIBDIR=/var/lib/asterisk ASTAGIDIR=/var/lib/asterisk/agi-bin ASTSPOOLDIR=/var/spool/asterisk ASTRUNDIR=/var/run/asterisk ASTLOGDIR=/var/log/asterisk AMPDISABLELOG=false

Before the update to CentOS 5.3 and FreePBX 2.5.1.5 my system was working without problems. However my most recent change to my setup was May 19 and so I cannot pinpoint exactly when this broke.

Try this in a shell:

amportal chown

This will restore all permissions.

Good suggestion and I suspect that there is something like this that has been changed with the CentOS 5.3 upgrade. What is strange is that the following code in retrieve_conf is returning null:

$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")); out(sprintf(_("The asterisk etc dir %s .."), $asterisk_conf['astetcdir']));

You can see that I’ve added an extra debugging statement. It return an empty string after the parse. This is why all subsequent functions depending upon this value is failing. The output from the run of retrieve_conf is:

[[email protected] bin]$ retrieve_conf --debug Checking for PEAR DB..OK Checking for PEAR Console::Getopt..OK [DEBUG-preDB] Debug mode enabled Checking for /etc/amportal.conf ..OK Bootstrapping /etc/amportal.conf ..OK Parsing /etc/amportal.conf ..OK Parsing /etc/asterisk/asterisk.conf ..OK The asterisk etc dir .. Connecting to database..OK Connecting to Asterisk manager interface..OK

OK, something might be wrong with your amportal.conf.

Add one more debug line to retrieve_conf:

$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));
}
print_r($asterisk_conf);
out(_("OK"));
out(sprintf(_("The asterisk etc dir %s .."), $asterisk_conf['astetcdir']));

Note the print_r. Now do a

retrieve_conf --dry-run

And look for something like:

Parsing /etc/asterisk/asterisk.conf ..Array
(
    [astetcdir] => /etc/asterisk
    [astmoddir] => /usr/lib/asterisk/modules
    [astvarlibdir] => /var/lib/asterisk
    [astagidir] => /var/lib/asterisk/agi-bin
    [astspooldir] => /var/spool/asterisk
    [astrundir] => /var/run/asterisk
    [astlogdir] => /var/log/asterisk
)
OK

If the above is not what you see, then I suggest that you recreate your amportal.conf. Verify that amportal.conf is set to asterisk both as owner and group.

This looks promising, all the index entries on my system is in UPPER case:

[AMPDBNAME] => asterisk [ASTETCDIR] => /etc/asterisk [ASTMODDIR] => /usr/lib/asterisk/modules [ASTVARLIBDIR] => /var/lib/asterisk [ASTAGIDIR] => /var/lib/asterisk/agi-bin [ASTSPOOLDIR] => /var/spool/asterisk [ASTRUNDIR] => /var/run/asterisk [ASTLOGDIR] => /var/log/asterisk

It looks like this code is now not working:

$convert = array( 'astetcdir' => 'ASTETCDIR', 'astmoddir' => 'ASTMODDIR', 'astvarlibdir' => 'ASTVARLIBDIR', 'astagidir' => 'ASTAGIDIR', 'astspooldir' => 'ASTSPOOLDIR', 'astrundir' => 'ASTRUNDIR', 'astlogdir' => 'ASTLOGDIR' );

with this active portion:

// Now that we parsed asterisk.conf, we need to make sure $amp_conf is consistent // so just set it to what we found, since this is what asterisk will use anyhow. // foreach ($convert as $ast_conf_key => $amp_conf_key) { if (isset($conf[$ast_conf_key])) { $amp_conf[$amp_conf_key] = $conf[$ast_conf_key]; } }

I think I found the bug in /var/www/html/admin/functions.inc.php

If you look at the return statement it returns the amportal.conf file and not the asterisk.conf file. I believe the error is in

return $amp_conf;

If you want to return the asterisk.conf file the correct statment would be:

return $conf;

Is this correct? If yes, how do I go about fixing this in the code base?

I don’t think you found a bug. This is the first time ever I have heard of this error and I think that there is something wrong with your setup.
Check your php version and your php.ini file.

I run Centos 5.3 with no errors at all.

What I do know is that on May 19 the system worked as intended. After that time the regular updates have been run i.e. yum, PIAF fixes and download of new FreePBX modules. Other than that, no changes.

After I made the change to the code and fixed the return statement, the parse_asterisk_conf function returns the parsed asterisk.conf file where all the identifiers are in lower case and my system works again. Without it returns the amportal.conf file.

When I look at the logic in the function, this makes sense as well. One explanation could be that previously the string match function used in retrieve_conf didn’t differentiate between uppercase and lower case. That would explain it.

My system is now working and I’ll be happy to share with you more details that can help explain what’s going on here.

actimin,

the parse_asterisk_conf in functions.inc.php returns $conf, not $amp_conf. Have a look at SVN and do a log of that file, that should not have been touched for ‘ever.’ (Do an ‘svn blame’ and you can see when that line may have been last changed.

Either you or something outside of FreePBX changed that, or for some reason Tom changed it in one of his PIAF update scripts. I can’t imagine Tom would do that for any reason, but since his scripts are compiled and can’t be viewed, there is no way to know other than asking him (probably over in the PIAF forum).

Hi Philippe,

Thank you for the information. Before this problem FreePBX was a “black box” to me, so no, I would not know how to change the return statement in question. It was your guys excellent support that allowed me to dive into the problem and determine what was wrong.

I’m waiting for an account on the PIAF forum and I will post this thread there to get some more clarity. I checked the FreePBX source code and it correctly returns $conf, so the change must have been induced somewhere else.

Regards,
Per

I hope your account gets activated quickly so you can pursue this with them. They have been known to be slow at times to get an account activated but bare with them, it will happen.

I too am getting the the parse_asterisk_conf() call error, except in my case it originates out of using the CALLBACK function.

[[email protected] etc]#  /var/lib/asterisk/bin/callback                

Checking for PEAR Console::Getopt..OK
Reading /etc/amportal.conf..OK
PHP Fatal error:  Call to undefined function parse_asterisk_conf() in /var/www/html/admin/common/php-asmanager.php on line 33
[[email protected] etc]# 

I too was working for quite a while and more recently noticed the failure. I noticed it because I was testing everything after taking the bump up to 2.6.0.beta2.0. I too did accept the yum updates from a week or so a go.

There definitely is a problem lurking in this region of the scripts base.

With thanks,
/S

can you please start a new thread on your issue wrt to callback and that error on the beta forum so that we can have a look and pursue it. If appropriate, please file a bug report also.

Already have a post in the 2.6.0.Beta forum.

I’ve been googling and found this very similar error and added my ditto to it.

If the root issue(s) is/are, in fact, unrelated in any way, then I apologize. No thread-jack or mis-posting was intended.

/S

none taken, let me find, don’t bother googling it is new and I’ll have a fix momentarily