[Asterisk-Users] Reload Asterisk from php or perl script

Matteo Brancaleoni mbrancaleoni at espia.it
Mon Oct 11 00:03:22 MST 2004


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 at espia.it
****************************************
EspiA Srl - e*solution provider
Via Pascoli, 37
20129 Milano - Italy
SIP:matteo at sip.voismart.it
Tel. +39 0270633354
Fax. +39 0245487890
IAXTEL: 17005662458
http://www.espia.it
****************************************




More information about the asterisk-users mailing list