Dee Lowndes
2004-Oct-08 06:45 UTC
[Asterisk-Users] Reload Asterisk from php or perl script
Hi, I am looking for a basic script that can reload asterisk from php or perl via a web browser. I have tried exec( asterisk -rx reload ) and shell_exec( <same cmd> ) with php but there seems to be a permission issue with asterisk that stops these working. I was just wondering if anyone has a way around this with perl or php. Thanks, Dee
Justin B. Newman
2004-Oct-08 06:54 UTC
[Asterisk-Users] Reload Asterisk from php or perl script
On 10/8/2004, "Dee Lowndes" <dee@asyouneed.com> wrote:>Hi, > > I am looking for a basic script that can reload asterisk from >php or perl via a web browser. > >I have tried exec( asterisk -rx reload ) and shell_exec( <same cmd> ) >with php but there seems to be a permission issue with asterisk that >stops these working. I was just wondering if anyone has a way around >this with perl or php. >Dee, If Asterisk is running as a different user than your web server, then you're not going to be able to use those scripts "outta the box". Running Asterisk as the same user as your web server would probably be considered a horribly insecure configuration, at best. The alternative is to explore options for allowing your webserver to run programs as different userid's. If you're running Apache, this page may help: http://httpd.apache.org/docs/suexec.html Good luck! Yours, -jbn Justin B Newman BinFone Telecom (Offering SIP and IAX termination and origination at http://www.binfone.com)
Just connect to the manager port over a socket and do it.. what you recommend with sudo is WRONG WRONG WRONG and BAD BAD BAD bkw> -----Original Message----- > From: asterisk-users-bounces@lists.digium.com [mailto:asterisk-users- > bounces@lists.digium.com] On Behalf Of Peter Osborne > Sent: Friday, October 08, 2004 9:38 AM > To: asterisk-users@lists.digium.com > Cc: Dee Lowndes > Subject: Re: [Asterisk-Users] Reload Asterisk from php or perl script > > On Friday 08 October 2004 10:14, Dee Lowndes wrote: > > I am using apache but I would rather avoid this option if possible. > > > > Any other ideas? > > > > Dee > > You could install sudo, then add a line in your /etc/sudoers like this: > > www-data ALL= NOPASSWD: /usr/bin/asterisk > > (this assumes apache runs under the username www-data) > > Then add "sudo" in from of the command you are trying to exec and it will > be > executed as root. Obviously there are some security issues with doing > this, > but it will do the job. You could write a shell script that runs you > asterisk > command and then allow sudo for the script rather than asterisk itself, > that > would provide a little more security. > > Pete > _______________________________________________ > Asterisk-Users mailing list > Asterisk-Users@lists.digium.com > http://lists.digium.com/mailman/listinfo/asterisk-users > To UNSUBSCRIBE or update options visit: > http://lists.digium.com/mailman/listinfo/asterisk-users
Robert Jackson
2004-Oct-08 07:55 UTC
[Asterisk-Users] Reload Asterisk from php or perl script
> -----Original Message----- > From: Dee Lowndes [mailto:dee@asyouneed.com] > Sent: Friday, October 08, 2004 9:45 AM > To: asterisk-users@lists.digium.com > Subject: [Asterisk-Users] Reload Asterisk from php or perl script > > > Hi, > > I am looking for a basic script that can reload > asterisk from php or perl via a web browser. > > I have tried exec( asterisk -rx reload ) and shell_exec( > <same cmd> ) with php but there seems to be a permission > issue with asterisk that stops these working. I was just > wondering if anyone has a way around this with perl or php. >There isn't a super simple easy way to do it. (At least not that I have found.) So, since asterisk can do anything, I created an inbound DID that executes a perl based AGI. Not pretty, but I can call into my * box from anywhere enter a pin number and either reload *, restart *, or reboot the entire box. Just an idea, Robert Jackson
Donny Kavanagh
2004-Oct-08 07:56 UTC
[Asterisk-Users] Reload Asterisk from php or perl script
Shoudn't you be able to use the Manager API to connect to Asterisk over a socket and issue a reload that way. This way you don't have to worry about permissions what so ever, other then connection php will make. The wiki is here http://www.voip-info.org/wiki-Asterisk+Manager+API It gives this example which should be exactly what you want <?php $socket = fsockopen("192.168.0.53","5038", $errno, $errstr, $timeout); fputs($socket, "Action: Login\r\n"); fputs($socket, "UserName: admin\r\n"); fputs($socket, "Secret: blabla\r\n\r\n"); fputs($socket, "Action: Command\r\n"); fputs($socket, "Command: reload\r\n\r\n"); $wrets=fgets($socket,128); ?> Donny -----Original Message----- From: Justin B. Newman [mailto:justin.newman@binhost.com] Sent: Friday, October 08, 2004 9:54 AM To: Asterisk Users Mailing List - Non-Commercial Discussion Subject: Re: [Asterisk-Users] Reload Asterisk from php or perl script On 10/8/2004, "Dee Lowndes" <dee@asyouneed.com> wrote:>Hi, > > I am looking for a basic script that can reload asterisk from >php or perl via a web browser. > >I have tried exec( asterisk -rx reload ) and shell_exec( <same cmd> ) >with php but there seems to be a permission issue with asterisk that >stops these working. I was just wondering if anyone has a way around >this with perl or php. >Dee, If Asterisk is running as a different user than your web server, then you're not going to be able to use those scripts "outta the box". Running Asterisk as the same user as your web server would probably be considered a horribly insecure configuration, at best. The alternative is to explore options for allowing your webserver to run programs as different userid's. If you're running Apache, this page may help: http://httpd.apache.org/docs/suexec.html Good luck! Yours, -jbn Justin B Newman BinFone Telecom (Offering SIP and IAX termination and origination at http://www.binfone.com) _______________________________________________ Asterisk-Users mailing list Asterisk-Users@lists.digium.com http://lists.digium.com/mailman/listinfo/asterisk-users To UNSUBSCRIBE or update options visit: http://lists.digium.com/mailman/listinfo/asterisk-users
Matteo Brancaleoni
2004-Oct-11 00:03 UTC
[Asterisk-Users] Reload Asterisk from php or perl script
Hi,> I am looking for a basic script that can reload asterisk from > php or perl via a web browser. > > I have tried exec( asterisk -rx reload ) and shell_exec( <same cmd> ) > with php but there seems to be a permission issue with asterisk that > stops these working. I was just wondering if anyone has a way around > this with perl or php.besides I prefer to use the manager, cause is more secure, easy, etc, another way to reload from php is to call the script with a wrapper in perl, like: test.php is the script that does fancy things and contains something like "asterisk -rx reload" somewhere, and /or writes * config files, blah blah... the "test" perl script would be something like: #********** cut here #!/usr/bin/perl # Perl wrapper to execute a PHP script setuid # Requires PHP CLI use File::Basename; # Make UID = EUID (so that PHP can run system()s and execs() setuid) $< = $>; # Set this to the path, so that we can't get poisoned $ENV{'PATH'} = "/var/lib/asterisk/scripts"; $ENV{'BASH_ENV'} = "/var/lib/asterisk/scripts"; # Open the PHP script $data = basename($0); if ($data =~ /^([-\@\w.]+)$/) { $data = $1; # $data now untainted } else { die "Bad data in $data"; # log this somewhere } system($data.".php"); #********** cut here and call /var/lib/asterisk/scripts/test btw, the manager is better :) Matteo. -- **************************************** Matteo Brancaleoni System Administrator mbrancaleoni@espia.it **************************************** EspiA Srl - e*solution provider Via Pascoli, 37 20129 Milano - Italy SIP:matteo@sip.voismart.it Tel. +39 0270633354 Fax. +39 0245487890 IAXTEL: 17005662458 http://www.espia.it ****************************************