Re: [asterisk-users] Using PHP to reload extensions
My pleasure :) It's rare I have an opportunity to help someone on here. Lee Jenkins wrote: Mojo with Horan Company, LLC wrote: No, because then asterisk would be presented three arguments: '-rx', 'extensions', and 'reload' -- as 'extensions' is not a command by itself, and the 'reload' appears superfluous to asterisk, this would not work as desired. Asterisk needs to be presented two arguments - the first is '-rx', the second is extensions reload (needs additional quoting to contain the space) which is actually a parameter to the '-x' switch just used. $output = shell_exec(asterisk -rx 'extensions reload') is right. Generally, the difference between single quotes and double quotes is that with double quotes, PHP is allowed to make $variable substitution while with single quotes, it is not. Mojo Nice. Thanks for the tip, Mojo. --- Warm Regards, Lee ___ --Bandwidth and Colocation Provided by http://www.api-digital.com-- asterisk-users mailing list To UNSUBSCRIBE or update options visit: http://lists.digium.com/mailman/listinfo/asterisk-users ___ --Bandwidth and Colocation Provided by http://www.api-digital.com-- asterisk-users mailing list To UNSUBSCRIBE or update options visit: http://lists.digium.com/mailman/listinfo/asterisk-users
Re: [asterisk-users] Using PHP to reload extensions
Mojo with Horan Company, LLC wrote: No, because then asterisk would be presented three arguments: '-rx', 'extensions', and 'reload' -- as 'extensions' is not a command by itself, and the 'reload' appears superfluous to asterisk, this would not work as desired. Asterisk needs to be presented two arguments - the first is '-rx', the second is extensions reload (needs additional quoting to contain the space) which is actually a parameter to the '-x' switch just used. $output = shell_exec(asterisk -rx 'extensions reload') is right. Generally, the difference between single quotes and double quotes is that with double quotes, PHP is allowed to make $variable substitution while with single quotes, it is not. Mojo Nice. Thanks for the tip, Mojo. --- Warm Regards, Lee ___ --Bandwidth and Colocation Provided by http://www.api-digital.com-- asterisk-users mailing list To UNSUBSCRIBE or update options visit: http://lists.digium.com/mailman/listinfo/asterisk-users
Re: [asterisk-users] Using PHP to reload extensions
Ciao Tzafrir, The only real benefit is if you can limit the permissions you give to that specific manager user. But there's a limit to ohw useful this can be. Even write=command alone allows changing the dialplan ('dialplan add' / 'dialplan remove') and running an arbitrary command as the asterisk user (originate a call to the application System). Maybe it could be good to limit in manager.conf which commands can be executed by each user. In this way, we could give more granular permissions, at the price of a slightly more complex manager.conf syntax. HND, -- Dr. Andrea Spadaccini Multimedia Technologies Institute - MTI S.r.l. Web: www.x-voice.it - Tel: +39 (0) 95 7224945 ___ --Bandwidth and Colocation Provided by http://www.api-digital.com-- asterisk-users mailing list To UNSUBSCRIBE or update options visit: http://lists.digium.com/mailman/listinfo/asterisk-users
Re: [asterisk-users] Using PHP to reload extensions
On Wed, Oct 03, 2007 at 09:10:58PM -0500, Moises Silva wrote: If you are running the script from a web server, the script gets executed with the web server process permissions, hence, probably does not have access to /var/run/asterisk.ctl. You can give permissions to your web server, or better yet, dont execute the command using shell_exec, better open a socket connection to the Asterisk manager and execute Action: Command Command: extensions reload Not that, in essense, this permits the web server's user to control Asterisk as well - the web server's user must be able to read the password from somewhere. The only real benefit is if you can limit the permissions you give to that specific manager user. But there's a limit to ohw useful this can be. Even write=command alone allows changing the dialplan ('dialplan add' / 'dialplan remove') and running an arbitrary command as the asterisk user (originate a call to the application System). -- Tzafrir Cohen icq#16849755 jabber:[EMAIL PROTECTED] +972-50-7952406 mailto:[EMAIL PROTECTED] http://www.xorcom.com iax:[EMAIL PROTECTED]/tzafrir ___ --Bandwidth and Colocation Provided by http://www.api-digital.com-- asterisk-users mailing list To UNSUBSCRIBE or update options visit: http://lists.digium.com/mailman/listinfo/asterisk-users
Re: [asterisk-users] Using PHP to reload extensions
No, because then asterisk would be presented three arguments: '-rx', 'extensions', and 'reload' -- as 'extensions' is not a command by itself, and the 'reload' appears superfluous to asterisk, this would not work as desired. Asterisk needs to be presented two arguments - the first is '-rx', the second is extensions reload (needs additional quoting to contain the space) which is actually a parameter to the '-x' switch just used. $output = shell_exec(asterisk -rx 'extensions reload') is right. Generally, the difference between single quotes and double quotes is that with double quotes, PHP is allowed to make $variable substitution while with single quotes, it is not. Mojo Lee Jenkins wrote: I'm not a PHP guy, but shouldn't the double quote be surrounding the entire shell command like this? $output = shell_exec('asterisk -rx extensions reload'); ___ --Bandwidth and Colocation Provided by http://www.api-digital.com-- asterisk-users mailing list To UNSUBSCRIBE or update options visit: http://lists.digium.com/mailman/listinfo/asterisk-users
Re: [asterisk-users] Using PHP to reload extensions
Hello, I am trying to use PHP to reload the extensions in an Asterisk installation. I keep getting this error: Easiest way without compromising security or changing permissions. Use the AMI. 1. Download phpagi (Just google it) 2. Use it to connect to the Manager interface 3. Use it to issue: Action: Command Command: reload Here's the two functions I've been using. Add a new user to manager.conf with the appropriate permissions and this should work fine. Hope that helps, -Michael function extensions_reload() { return asterisk_exec(dialplan reload); } function asterisk_exec($cmd, $output=NULL) { $token = md5(uniqid(rand())); $errno = 0; $errstr = 0; $fp = fsockopen(localhost, 5038, $errno, $errstr, 20); if (!$fp) { return 1; } fputs($fp, Action: login\r\n); fputs($fp, Username: newusername\r\n); fputs($fp, Secret: newpassword\r\n); fputs($fp, Events: off\r\n\r\n); usleep(500); fputs($fp, Action: COMMAND\r\n); fputs($fp, command: $cmd\r\n); fputs($fp, ActionID: $token\r\n\r\n); usleep(500); $out = fread($fp, 38000); while(strpos($out,--END COMMAND--)==0) { $out .= fread($fp, 38000); } fclose ($fp); $out = substr($out, strpos($out, ActionID)); $out = substr($out, strpos($out, \n) + 1); $out = substr($out, 0, strpos($out, --END COMMAND--) - 1); $output = $out; return 0; } ___ --Bandwidth and Colocation Provided by http://www.api-digital.com-- asterisk-users mailing list To UNSUBSCRIBE or update options visit: http://lists.digium.com/mailman/listinfo/asterisk-users
Re: [asterisk-users] Using PHP to reload extensions
Michael Munger wrote: I am trying to use PHP to reload the extensions in an Asterisk installation. I keep getting this error: Unable to connect to remote asterisk (does /var/run/asterisk.ctl exist?) when I run the script by visiting the URL; however, if I run the script from the command line, it runs just fine (works perfect, actually). I think it is permissions related. Does anyone have any ideas? php $output = shell_exec('asterisk -rxextensions reload'); echo $output; ? I guess your web server does not run as root and thus is not allowed to invoke asterisk. (Try echo shell_exec('id'); or echo get_current_user(); in PHP.) A possible solution (although not nice): Add www-data ALL=(ALL) NOPASSWD: ALL to /etc/sudoers (depending on your distribution etc. the Apache user might be www-data / apache / ...) and in the PHP script run shell_exec('sudo asterisk -rx extensions reload'); Regards, Philipp Kempgen -- amooma GmbH - Bachstr. 126 - 56566 Neuwied - http://www.amooma.de Let's use IT to solve problems and not to create new ones. Asterisk? - http://www.das-asterisk-buch.de My pick of the month: rfc 2822 3.6.5 Geschäftsführer: Stefan Wintermeyer Handelsregister: Neuwied B 14998 ___ --Bandwidth and Colocation Provided by http://www.api-digital.com-- asterisk-users mailing list To UNSUBSCRIBE or update options visit: http://lists.digium.com/mailman/listinfo/asterisk-users
Re: [asterisk-users] Using PHP to reload extensions
If you are running the script from a web server, the script gets executed with the web server process permissions, hence, probably does not have access to /var/run/asterisk.ctl. You can give permissions to your web server, or better yet, dont execute the command using shell_exec, better open a socket connection to the Asterisk manager and execute Action: Command Command: extensions reload Regards On 10/3/07, Michael Munger [EMAIL PROTECTED] wrote: I am trying to use PHP to reload the extensions in an Asterisk installation. I keep getting this error: Unable to connect to remote asterisk (does /var/run/asterisk.ctl exist?) when I run the script by visiting the URL; however, if I run the script from the command line, it runs just fine (works perfect, actually). I think it is permissions related. Does anyone have any ideas? php $output = shell_exec('asterisk -rxextensions reload'); echo $output; ? Yours, Michael Munger, dCAP 404-438-2128 [EMAIL PROTECTED] ___ --Bandwidth and Colocation Provided by http://www.api-digital.com-- asterisk-users mailing list To UNSUBSCRIBE or update options visit: http://lists.digium.com/mailman/listinfo/asterisk-users -- Within C++, there is a much smaller and cleaner language struggling to get out. ___ --Bandwidth and Colocation Provided by http://www.api-digital.com-- asterisk-users mailing list To UNSUBSCRIBE or update options visit: http://lists.digium.com/mailman/listinfo/asterisk-users
Re: [asterisk-users] Using PHP to reload extensions
Michael Munger wrote: I am trying to use PHP to reload the extensions in an Asterisk installation. I keep getting this error: Unable to connect to remote asterisk (does /var/run/asterisk.ctl exist?) when I run the script by visiting the URL; however, if I run the script from the command line, it runs just fine (works perfect, actually). I think it is permissions related. Does anyone have any ideas? php $output = shell_exec('asterisk -rxextensions reload'); echo $output; ? Yours, Michael Munger, dCAP 404-438-2128 [EMAIL PROTECTED] mailto:[EMAIL PROTECTED] If running a script from a browser, it is usually run as nobody, from the command line it is whatever user you are, probably root. Thanks, Steve Totaro ___ --Bandwidth and Colocation Provided by http://www.api-digital.com-- asterisk-users mailing list To UNSUBSCRIBE or update options visit: http://lists.digium.com/mailman/listinfo/asterisk-users
Re: [asterisk-users] Using PHP to reload extensions
Michael Munger wrote: I am trying to use PHP to reload the extensions in an Asterisk installation. I keep getting this error: Unable to connect to remote asterisk (does /var/run/asterisk.ctl exist?) when I run the script by visiting the URL; however, if I run the script from the command line, it runs just fine (works perfect, actually). I think it is permissions related. Does anyone have any ideas? php $output = shell_exec('asterisk -rxextensions reload'); echo $output; ? I'm not a PHP guy, but shouldn't the double quote be surrounding the entire shell command like this? $output = shell_exec('asterisk -rx extensions reload'); Lee ___ --Bandwidth and Colocation Provided by http://www.api-digital.com-- asterisk-users mailing list To UNSUBSCRIBE or update options visit: http://lists.digium.com/mailman/listinfo/asterisk-users
Re: [asterisk-users] Using PHP to reload extensions
Steve Totaro wrote: Michael Munger wrote: I am trying to use PHP to reload the extensions in an Asterisk installation. I keep getting this error: Unable to connect to remote asterisk (does /var/run/asterisk.ctl exist?) when I run the script by visiting the URL; however, if I run the script from the command line, it runs just fine (works perfect, actually). I think it is permissions related. Does anyone have any ideas? php $output = shell_exec('asterisk -rxextensions reload'); echo $output; ? Yours, Michael Munger, dCAP 404-438-2128 [EMAIL PROTECTED] mailto:[EMAIL PROTECTED] If running a script from a browser, it is usually run as nobody, from the command line it is whatever user you are, probably root. Thanks, Steve Totaro Easiest way without compromising security or changing permissions. Use the AMI. 1. Download phpagi (Just google it) 2. Use it to connect to the Manager interface 3. Use it to issue: Action: Command Command: reload phpagi actually has a method in the manager class to do this. Just use the Command function with a parameter of reload More here: http://forums.digium.com/viewtopic.php?p=17773sid=5f0e99c1da924a959285fcb3f81feae6 ___ --Bandwidth and Colocation Provided by http://www.api-digital.com-- asterisk-users mailing list To UNSUBSCRIBE or update options visit: http://lists.digium.com/mailman/listinfo/asterisk-users