fmbiete / Z-Push-contrib

Z-Push fork with changes that I will try to contrib
GNU Affero General Public License v3.0
134 stars 62 forks source link

Docker: Run z-push-admin.php from a container #169

Closed fmbiete closed 9 years ago

fmbiete commented 9 years ago

If we try to run z-push-admin.php from a container we get an error, because we are missing some env variables (TERM & LOGNAME).

[zpush@715a6655afde z-push]$ php ./z-push-admin.php -a list              
ERROR: This script should not be called in a browser.
HOSTNAME=715a6655afde
LC_ALL=en_US.UTF-8
LS_COLORS=
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
PWD=/var/www/z-push
LANG=en_US.UTF-8
container_uuid=715a6655-afde-cfcf-aa68-c05600a9cd0d
SHLVL=1
HOME=/home/zpush
LANGUAGE=en_US.UTF-8
LESSOPEN=||/usr/bin/lesspipe.sh %s
_=/usr/bin/env
OLDPWD=/var/www

z-push-admin.php

static public function CheckEnv() {
        if (!isset($_SERVER["TERM"]) || !isset($_SERVER["LOGNAME"]))
            self::$errormessage = "This script should not be called in a browser.";

        if (!function_exists("getopt"))
            self::$errormessage = "PHP Function getopt not found. Please check your PHP version and settings.";
    }

A solution would be check if php_sapi_name() == "cli"

http://php.net/manual/en/function.php-sapi-name.php http://docs.hhvm.com/manual/en/function.php-sapi-name.php

fmbiete commented 9 years ago

Fixed as ee57662fbcd54f6311db242dbcacfeba54585fad