From 6d1f9cc869d62f17230b3174f320bad4f2d1c435 Mon Sep 17 00:00:00 2001 From: onefang Date: Sat, 4 Jan 2020 17:28:24 +1000 Subject: Work with CGI PHP. --- cgi/README | 16 ++++++++++++++++ cgi/php.cgi | 7 +++++++ cgi/php.ini | 10 ++++++++++ conf/common.inc.php | 3 --- conf/config.php | 4 ++++ 5 files changed, 37 insertions(+), 3 deletions(-) create mode 100644 cgi/README create mode 100755 cgi/php.cgi create mode 100644 cgi/php.ini diff --git a/cgi/README b/cgi/README new file mode 100644 index 0000000..734e4f0 --- /dev/null +++ b/cgi/README @@ -0,0 +1,16 @@ +These are for the case of running under a web server that doesn't support +PHP directly. In the case that prompted this, thttpd is the server +software. It'll likely work for others as well, none have been tested. + +To install this - + +* Copy both files to your web servers document root. +* php.cgi should be executable. +* add php.cgi to the base of your urls for PHP pages, so - + http://example.com/my/php/project/index.php + becomes - + http://example.com/php.cgi/my/php/project/index.php + Or for a typical apt-panopticon install - + http//:example.com/php.cgi/apt-panopticon/apt-panopticon_cgp/index.php +* For apt-panopticon, pass --cgi to it, so it'll construct URLs properly. +* Your PHP code may need to be adjusted, cgp has already been adjusted. diff --git a/cgi/php.cgi b/cgi/php.cgi new file mode 100755 index 0000000..746ba82 --- /dev/null +++ b/cgi/php.cgi @@ -0,0 +1,7 @@ +#!/bin/bash + +# Wrap PHP for web servers that can only do PHP via CGI. +export DOCUMENT_ROOT=$(pwd) +export SCRIPT_FILENAME="$PATH_TRANSLATED" +export SCRIPT_NAME=$(basename $PATH_TRANSLATED) +exec /usr/bin/php-cgi --php-ini ${DOCUMENT_ROOT}/php.ini diff --git a/cgi/php.ini b/cgi/php.ini new file mode 100644 index 0000000..7c53490 --- /dev/null +++ b/cgi/php.ini @@ -0,0 +1,10 @@ +[PHP] + +; cgi.force_redirect is necessary to provide security running PHP as a CGI under +; most web servers. Left undefined, PHP turns this on by default. You can +; turn it off here AT YOUR OWN RISK +; **You CAN safely turn this off for IIS, in fact, you MUST.** +; ** Seems the same thing applies to thttpd, you MUST turn it off. ** +; http://php.net/cgi.force-redirect +;cgi.force_redirect = 1 +cgi.force_redirect = 0 diff --git a/conf/common.inc.php b/conf/common.inc.php index 506134d..07a7475 100644 --- a/conf/common.inc.php +++ b/conf/common.inc.php @@ -2,9 +2,6 @@ require_once 'config.php'; -$CONFIG['webdir'] = preg_replace('/\/[a-z\.]+$/', '', $_SERVER['SCRIPT_FILENAME']); -$CONFIG['weburl'] = preg_replace('/(?<=\/)[a-z\.]+$/', '', $_SERVER['SCRIPT_NAME']); - if (!ini_get('date.timezone')) { date_default_timezone_set($CONFIG['default_timezone']); } diff --git a/conf/config.php b/conf/config.php index eae3307..23a3a90 100644 --- a/conf/config.php +++ b/conf/config.php @@ -3,6 +3,10 @@ # collectd version $CONFIG['version'] = 5; +# Do this here, so it can be overriden, usually in case part of the path is a script for wrapping PHP. +$CONFIG['webdir'] = preg_replace('/\/[a-z\.]+$/', '', $_SERVER['SCRIPT_FILENAME']); +$CONFIG['weburl'] = preg_replace('/(?<=\/)[a-z\.]+$/', '', $_SERVER['SCRIPT_NAME']); + # collectd's datadir $CONFIG['datadir'] = '../apt-panopticon/rrd'; -- cgit v1.1