From c3806a9dc07e4bf45491e7120a1c931332f2e555 Mon Sep 17 00:00:00 2001 From: tokul Date: Fri, 7 Jul 2006 12:53:50 +0000 Subject: [PATCH] using popen instead of shell_exec. shell_exec is disabled in safe mode. default configuration moved to functions.php file_exists() test is no longer used because it is not accurate (#1499134) and requires full path to fortune program. git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@11361 7612ce4b-ef26-0410-bec9-ea0150e637f0 --- .../{config_default.php => config_sample.php} | 17 +++---- plugins/fortune/functions.php | 45 +++++++++---------- plugins/fortune/setup.php | 1 - 3 files changed, 25 insertions(+), 38 deletions(-) rename plugins/fortune/{config_default.php => config_sample.php} (51%) diff --git a/plugins/fortune/config_default.php b/plugins/fortune/config_sample.php similarity index 51% rename from plugins/fortune/config_default.php rename to plugins/fortune/config_sample.php index 950d8837..eb8fc566 100644 --- a/plugins/fortune/config_default.php +++ b/plugins/fortune/config_sample.php @@ -1,7 +1,7 @@ \ No newline at end of file +$fortune_command = '/usr/games/fortune -s'; diff --git a/plugins/fortune/functions.php b/plugins/fortune/functions.php index d62dd885..dddfdabd 100644 --- a/plugins/fortune/functions.php +++ b/plugins/fortune/functions.php @@ -11,14 +11,10 @@ */ /** - * Declare configuration globals + * Declare configuration global and set default value */ -global $fortune_location, $fortune_options; - -/** - * Load default config - */ -include_once(SM_PATH . 'plugins/fortune/config_default.php'); +global $fortune_command; +$fortune_command = '/usr/games/fortune -s'; /** * Load site config @@ -35,33 +31,33 @@ if (file_exists(SM_PATH . 'config/fortune_config.php')) { * @since 1.5.1 */ function fortune_function() { - global $fortune_visible, $color, $fortune_location, $fortune_options; + global $fortune_visible, $color, $fortune_command; if (!$fortune_visible) { return; } - $exist = file_exists($fortune_location); - - if ($fortune_options!='') { - $fortune_command=$fortune_location . ' ' . $fortune_options; - } else { - $fortune_command=$fortune_location; - } - - echo "
\n". + echo "
\n". "
\n". "
\n"; echo '
'; - if (!$exist) { - printf(_("%s is not found."),$fortune_location); - } else { - echo "
" . _("Today's Fortune") . "
\n" .
-            htmlspecialchars(shell_exec($fortune_command)) .
-            "
\n"; + + /* open handle and get all command output*/ + $handle = popen($fortune_command,'r'); + $fortune = ''; + while ($read = fread($handle,1024)) { + $fortune .= $read; } + /* if pclose return != 0, popen command failed. Yes, I know that it is broken when --enable-sigchild is used */ + if (pclose($handle)) { + // %s shows executed fortune cookie command. + $fortune = sprintf(_("Unable to execute \"%s\"."),$fortune_command); + } + echo "
" . _("Today's Fortune") . "
\n" .
+            htmlspecialchars($fortune) .
+            "
\n"; - echo '
'; + echo ''; } /** @@ -91,4 +87,3 @@ function fortune_function_load() { $fortune_visible = getPref($data_dir, $username, 'fortune_visible'); } -?> \ No newline at end of file diff --git a/plugins/fortune/setup.php b/plugins/fortune/setup.php index fb7609c9..e8581351 100644 --- a/plugins/fortune/setup.php +++ b/plugins/fortune/setup.php @@ -48,4 +48,3 @@ function fortune_load() { include_once(SM_PATH . 'plugins/fortune/functions.php'); fortune_function_load(); } -?> \ No newline at end of file -- 2.25.1