[stunnel-users] launch stunnel server daemon from php?

Wesley Kenzie wkenzie at gmail.com
Tue May 6 00:01:31 CEST 2008


Thanks, Brian.

The following php script works fine to start up the polipo web proxy cache
program.  /etc/polipo/standard.conf contains some standard config file
settings.  The command line parameters proxyPort, socksParentProxy, pidFile,
and logFile are additional config settings passed to the polipo executable.
<?php
      //
      $exec_command = 'polipo -c /etc/polipo/standard.conf proxyPort=8123
socksParentProxy=localhost:9050 pidFile=/var/lib/polipo/9050.pid
logFile=/var/log/polipo/9050.log ';
      $exec_output = '';
      $exec_result_string = @exec($exec_command, $exec_output,
$exec_result_int);
      $exec_output_lines = count($exec_output);
      if (@openlog('', LOG_NDELAY | LOG_PID | LOG_PERROR, LOG_LOCAL0)) {
        $log_datetime = date('Y-m-d H:i:s');
        @syslog(LOG_INFO, "polipo started on port 8123 at " .
$log_datetime);
        @closelog();
      }
?>

 The following php script does not work.  It hangs and has to be
interrupted.  If I run the same command from the shell as root it works
fine.  I have tried changing the foreground = yes to foreground = no and
removing the & character at the end of the $exec_command but neither works.
<?php
      //
      $exec_command = '/usr/local/bin/stunnel /etc/stunnel/test.conf &';
      $exec_output = '';
      $exec_result_string = @exec($exec_command, $exec_output,
$exec_result_int);
      $exec_output_lines = count($exec_output);
      if (@openlog('', LOG_NDELAY | LOG_PID | LOG_PERROR, LOG_LOCAL0)) {
        $log_datetime = date('Y-m-d H:i:s');
        @syslog(LOG_INFO, "stunnel started at " . $log_datetime);
        @closelog();
      }
?>
/etc/stunnel/test.conf is as follows:
setuid = apache
setgid = apache
pid = /var/lib/stunnel/test.pid
output = /var/log/stunnel/test.log
foreground = yes
syslog = yes

[stunnelTest]
accept = 7199
connect = 8123
client = no
transparent = no



On Mon, May 5, 2008 at 11:15 AM, Brian Hatch <bri at stunnel.org> wrote:

> Around 2008-05-02 12:19 -0700, Wesley Kenzie implored:
>
> > I am having problems launching stunnel from a php "exec" command.  I
> would
> > like to have it launch as a server daemon and then have the exec command
> > return control to the php script.  The best I have been able to do is
> launch
> > it in foreground with a command like "/usr/local/bin/stunnel
> > /etc/stunnel/test.conf &" but control never returns to the php script.
> >
> > I do not want to use inetd mode, and would prefer to specify command
> line
> > arguments, but I see they are no longer available in version 4.
>
>
> Can you show code that works for other excutables, but not stunnel,
> plus your configuration file?
>
> Stunnel will stop when it has no more input to send to the remote
> end.  It could be that stunnel is hanging because its input isn't
> closed, so it assumes it's not 'done' yet.
>
>
>
> --
> Brian Hatch                  Deja moo (n)
>   Systems and                - The feeling that you've
>   Security Engineer            heard that bull before.
> http://www.ifokr.org/bri/
>
> Every message PGP signed
>
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.2.1 (GNU/Linux)
>
> iD8DBQFIH06zVkMj8/ymYEsRAjNmAKCeECb09c13cV9rz3Yx1SMf4W49KQCcDWBb
> +q2h5JnGr6jmfHuvG8F7q0U=
> =OOxW
> -----END PGP SIGNATURE-----
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.stunnel.org/pipermail/stunnel-users/attachments/20080505/7f3ea881/attachment.html>


More information about the stunnel-users mailing list