2 messages in com.mysql.lists.eventum-develdownload_emails.php web invocation fe...| From | Sent On | Attachments |
|---|---|---|
| Jeffrey D. Wheelhouse | 01 Mar 2005 22:59 | |
| Joao Prado Maia | 07 Mar 2005 12:55 |
| Subject: | download_emails.php web invocation feature patch![]() |
|---|---|
| From: | Jeffrey D. Wheelhouse (jdw_...@wheelhouse.org) |
| Date: | 03/01/2005 10:59:32 PM |
| List: | com.mysql.lists.eventum-devel |
I don't want to run the cron daemon in the same server context as the Eventum web server. All of the supplied periodic scripts work just fine when invoked over the web except for download_emails.php, which takes command line arguments. This patch modifies download_emails.php as follows:
1) It now detects whether it is invoked from the command line or the web and gets its arguments appropriately.
2) The positive check for --fix-lock has been moved forward, which eliminates the need to negative check for it in a couple of other places.
In order to invoke it over the web, download_emails.php is called with dummy GET variables (parameters are parsed in order of appearance, as with the command line, and the key value is ignored).
Here is an example with wget:
wget -qO- 'http://issues.example.com/misc/download_emails.php?x=username&y=mail.example.com'
This wget line can then be invoked by cron from anywhere. Additionally, the download_emails.php functionality is exposed to the web, which is potentially interesting (or potentially bad, if proper access controls are not in place).
This is working well here, but no idea if it's of interest to anyone else.
Thanks, Jeff
$ diff -wbBu download_emails.php.org download_emails.php --- download_emails.php.org Tue Mar 1 23:49:38 2005 +++ download_emails.php Tue Mar 1 23:21:40 2005 @@ -42,24 +42,13 @@ exit; }
-// check for the required parameters -if (@count($HTTP_SERVER_VARS['argv']) < 3 && @$HTTP_SERVER_VARS['argv'][1] != '--fix-lock') { - echo "Error: Wrong number of parameters given. Expected parameters related to the email account:\n"; - echo " 1 - username\n"; - echo " 2 - hostname\n"; - echo " 3 - mailbox (only required if IMAP account)\n"; - echo "Example: php -q download_emails.php user example.com INBOX\n"; - exit; -} +// Choose args depending on whether invoked on the web or by cron. +if (isset($_GET)) $argv = array_merge( array($HTTP_SERVER_VARS['SCRIPT_FILENAME']), array_values($_GET) ); +else $argv = @$HTTP_SERVER_VARS['argv']; +$argc = count($argv);
-// get the account ID since we need it for locking. -$account_id = Email_Account::getAccountID(@$HTTP_SERVER_VARS["argv"][1], @$HTTP_SERVER_VARS["argv"][2], @$HTTP_SERVER_VARS["argv"][3]); -if ($account_id == 0 && !in_array('--fix-lock', @$HTTP_SERVER_VARS['argv'])) { - echo "Error: Could not find a email account with the parameter provided. Please verify your email account settings and try again.\n"; - exit; -} - -if (in_array('--fix-lock', @$HTTP_SERVER_VARS['argv'])) { +// --fix-lock variant invocation +if (in_array('--fix-lock', $argv)) { // if there is no account id, unlock all accounts if (empty($account_id)) { $prj_ids = array_keys(Project::getAll()); @@ -76,6 +65,23 @@ exit; }
+// check for the required parameters +if ($argc < 3) { + echo "Error: Wrong number of parameters given. Expected parameters related to the email account:\n"; + echo " 1 - username\n"; + echo " 2 - hostname\n"; + echo " 3 - mailbox (only required if IMAP account)\n"; + echo "Example: php -q download_emails.php user example.com INBOX\n"; + exit; +} + +// get the account ID since we need it for locking. +$account_id = Email_Account::getAccountID($argv[1], $argv[2], @$argv[3]); +if ($account_id == 0) { + echo "Error: Could not find a email account with the parameter provided. Please verify your email account settings and try again.\n"; + exit; +} + // check if there is another instance of this script already running if (!Lock::acquire('download_emails_' . $account_id)) { echo "Error: Another instance of the script is still running for the specified account. " .
-- Jeff Wheelhouse jd...@wheelhouse.org




