From 71134ce29a80e89edd69f3504d180025ba7b8025 Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Tue, 10 Sep 2013 17:31:15 +0000 Subject: [PATCH] change cli detection to use php_sapi_name() --- admin/admin-cli.php | 2 +- doc/fix_depricated.php | 4 ++-- doc/rpm-build/checkout-build-archives.php | 2 +- doc/rpm-build/post_install.php | 2 +- emailadmin/doc/dovecot_checkpassword_ads.php | 2 +- emailadmin/doc/postfix_tcp_map_ads.php | 2 +- filemanager/cli.php | 2 +- setup/doc/chown.php | 2 +- setup/setup-cli.php | 2 +- svn-helper.php | 2 +- 10 files changed, 11 insertions(+), 11 deletions(-) diff --git a/admin/admin-cli.php b/admin/admin-cli.php index 791bef6810..c5be2c7380 100755 --- a/admin/admin-cli.php +++ b/admin/admin-cli.php @@ -13,7 +13,7 @@ chdir(dirname(__FILE__)); // to enable our relative pathes to work -if (isset($_SERVER['HTTP_HOST'])) // security precaution: forbit calling admin-cli as web-page +if (php_sapi_name() !== 'cli') // security precaution: forbit calling admin-cli as web-page { die('

admin-cli.php must NOT be called as web-page --> exiting !!!

'); } diff --git a/doc/fix_depricated.php b/doc/fix_depricated.php index 3be382d768..41bf1b45f1 100755 --- a/doc/fix_depricated.php +++ b/doc/fix_depricated.php @@ -14,7 +14,7 @@ * @version $Id$ */ -if (isset($_SERVER['HTTP_HOST'])) // security precaution: forbit calling as web-page +if (php_sapi_name() !== 'cli') // security precaution: forbit calling as web-page { die('

fix_depricated.php must NOT be called as web-page --> exiting !!!

'); } @@ -119,7 +119,7 @@ function fix_depricated($file,$replace_file=false) // fix call to not longer existing PDO method $result->fetchSingle() $lines = str_replace('->fetchSingle(','->fetchColumn(',$lines); - + // fix calls to deprecated call_user_method(_array)?(method,object[,args]) if (preg_match('/call_user_method(_array)?\(/',$lines,$matches)) { diff --git a/doc/rpm-build/checkout-build-archives.php b/doc/rpm-build/checkout-build-archives.php index 89bd800c0c..5673925dce 100755 --- a/doc/rpm-build/checkout-build-archives.php +++ b/doc/rpm-build/checkout-build-archives.php @@ -9,7 +9,7 @@ * @version $Id$ */ -if (isset($_SERVER['HTTP_HOST'])) // security precaution: forbit calling setup-cli as web-page +if (php_sapi_name() !== 'cli') // security precaution: forbit calling setup-cli as web-page { die('

checkout-build-archives.php must NOT be called as web-page --> exiting !!!

'); } diff --git a/doc/rpm-build/post_install.php b/doc/rpm-build/post_install.php index a3e94551de..bb2cf5e685 100755 --- a/doc/rpm-build/post_install.php +++ b/doc/rpm-build/post_install.php @@ -9,7 +9,7 @@ * @version $Id$ */ -if (isset($_SERVER['HTTP_HOST'])) // security precaution: forbit calling post_install as web-page +if (php_sapi_name() !== 'cli') // security precaution: forbit calling post_install as web-page { die('

rpm_post_install.php must NOT be called as web-page --> exiting !!!

'); } diff --git a/emailadmin/doc/dovecot_checkpassword_ads.php b/emailadmin/doc/dovecot_checkpassword_ads.php index 1826355fad..7edcead3f6 100755 --- a/emailadmin/doc/dovecot_checkpassword_ads.php +++ b/emailadmin/doc/dovecot_checkpassword_ads.php @@ -40,7 +40,7 @@ */ // protect from being called via HTTP -if (isset($_SERVER['HTTP_HOST'])) die('This is a command line only script!'); +if (php_sapi_name() !== 'cli') die('This is a command line only script!'); // uncomment to write to log-file, otherwise errors go to stderr //$log = '/var/log/dovecot_checkpassword.log'; diff --git a/emailadmin/doc/postfix_tcp_map_ads.php b/emailadmin/doc/postfix_tcp_map_ads.php index 97a8a62a9c..d44f38d587 100755 --- a/emailadmin/doc/postfix_tcp_map_ads.php +++ b/emailadmin/doc/postfix_tcp_map_ads.php @@ -71,7 +71,7 @@ */ // protect from being called via HTTP -if (isset($_SERVER['HTTP_HOST'])) die('This is a command line only script!'); +if (php_sapi_name() !== 'cli') die('This is a command line only script!'); // our defaults $default_host = 'localhost'; diff --git a/filemanager/cli.php b/filemanager/cli.php index f35e1661d9..153ac3025d 100755 --- a/filemanager/cli.php +++ b/filemanager/cli.php @@ -17,7 +17,7 @@ chdir(dirname(__FILE__)); // to enable our relative pathes to work error_reporting(error_reporting() & ~E_NOTICE); -if (isset($_SERVER['HTTP_HOST'])) // security precaution: forbit calling ls as web-page +if (php_sapi_name() !== 'cli') // security precaution: forbit calling filemanager/cli.php as web-page { die('

'.basename(__FILE__).' must NOT be called as web-page --> exiting !!!

'); } diff --git a/setup/doc/chown.php b/setup/doc/chown.php index 634388bedb..b1eb10d636 100755 --- a/setup/doc/chown.php +++ b/setup/doc/chown.php @@ -13,7 +13,7 @@ chdir(dirname(__FILE__)); // to enable our relative pathes to work -if (isset($_SERVER['HTTP_HOST'])) // security precaution: forbit calling as web-page +if (php_sapi_name() !== 'cli') // security precaution: forbit calling as web-page { die('

setup/doc/chown.php must NOT be called as web-page --> exiting !!!

'); } diff --git a/setup/setup-cli.php b/setup/setup-cli.php index 8f14d9ac01..a6f5168333 100755 --- a/setup/setup-cli.php +++ b/setup/setup-cli.php @@ -13,7 +13,7 @@ chdir(dirname(__FILE__)); // to enable our relative pathes to work -if (isset($_SERVER['HTTP_HOST'])) // security precaution: forbit calling setup-cli as web-page +if (php_sapi_name() !== 'cli') // security precaution: forbit calling setup-cli as web-page { die('

setup-cli.php must NOT be called as web-page --> exiting !!!

'); } diff --git a/svn-helper.php b/svn-helper.php index 30cb9950b0..e36ec44990 100755 --- a/svn-helper.php +++ b/svn-helper.php @@ -10,7 +10,7 @@ * @version $Id$ */ -if (isset($_SERVER['HTTP_HOST'])) die("This is a commandline ONLY tool!\n"); +if (php_sapi_name() !== 'cli') die("This is a commandline ONLY tool!\n"); if ($_SERVER['argc'] <= 1) die(' Usage: ./svn-helper.php