From: Michael M Slusarz Date: Wed, 26 Jan 2011 18:26:01 +0000 (-0700) Subject: Move IMP CLI scripts to bin/ X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=b4b12d8204dcd0fddbfb8109e3791039d7a9e655;p=horde.git Move IMP CLI scripts to bin/ --- diff --git a/imp/bin/bounce_spam b/imp/bin/bounce_spam new file mode 100755 index 000000000..2bdbb644e --- /dev/null +++ b/imp/bin/bounce_spam @@ -0,0 +1,66 @@ +#!/usr/bin/env php + + * @category Horde + * @license http://www.fsf.org/copyleft/gpl.html GPL + * @package IMP + */ + +require_once dirname(__FILE__) . '/../lib/Application.php'; +Horde_Registry::appInit('imp', array( + 'authentication' => false, + 'cli' => true +)); + +/** Configuration **/ + +/** + * Location of the bounce template. + * The following strings will be replaced in the template: + * %TO% - The spammer's e-mail address. + * %TARGET% - The target's e-mail address. + */ +$bounce_template = IMP_BASE . '/config/bounce.txt'; + +/** End Configuration **/ + +/* If there's no bounce template file then abort */ +if (!file_exists($bounce_template)) { + $cli->fatal('Bounce template does not exist.'); +} + +/* Read the message content. */ +$data = $cli->readStdin(); + +/* Who's the spammer? */ +$headers = Horde_Mime_Headers::parseHeaders($data); +$return_path = Horde_Mime_Address::bareAddress($headers->getValue('return-path')); + +/* Who's the target? */ +$delivered_to = Horde_Mime_Address::bareAddress($headers->getValue('delivered-to')); + +/* Read the bounce template and construct the mail */ +$bounce = str_replace( + array('%TO%', '%TARGET%'), + array($return_path, $delivered_to), + file_get_contents($bounce_template) +); + +/* Send the mail */ +$sendmail = "/usr/sbin/sendmail -t -f ''"; +$fd = popen($sendmail, 'w'); +fputs($fd, preg_replace("/\n$/", "\r\n", $bounce . $data)); +pclose($fd); diff --git a/imp/bin/query_imap_cache b/imp/bin/query_imap_cache new file mode 100755 index 000000000..5a78bb759 --- /dev/null +++ b/imp/bin/query_imap_cache @@ -0,0 +1,295 @@ +#!/bin/env php + + * @category Horde + * @license http://www.fsf.org/copyleft/gpl.html GPL + * @package IMP + */ + +require_once dirname(__FILE__) . '/../lib/Application.php'; +Horde_Registry::appInit('imp', array('cli' => true)); + +$c = new Console_Getopt(); +$argv = $c->readPHPArgv(); +array_shift($argv); +$options = $c->getopt2($argv, '', array('user=', 'pass=', 'server=')); +if (PEAR::isError($options)) { + $cli->fatal("Invalid arguments.\n"); +} + +$pass = $server = $user = null; +foreach ($options[0] as $val) { + switch ($val[0]) { + case '--user': + $user = $val[1]; + break; + + case '--pass': + $pass = $val[1]; + break; + + case '--server': + $server = $val[1]; + break; + } +} + +$imp_imap = $injector->getInstance('IMP_Injector_Factory_Imap')->create(); + +if (is_null($server)) { + /* Set first entry to 1, not 0. */ + $sconfig = $slookup = array(''); + $i = 1; + + foreach ($imp_imap->loadServerConfig() as $key => $val) { + $sconfig[$i] = $val['name'] . ' [' . $key . ']'; + $slookup[$i++] = $key; + } + + unset($sconfig[0]); + + while (is_null($server)) { + $server = $cli->prompt('Server:', $sconfig); + } + $server = $slookup[$server]; +} else { + $cli->message('Server: ' . $server); +} + +if (is_null($user)) { + while (is_null($user)) { + $user = $cli->prompt('Username:'); + if (!strlen($user)) { + $user = null; + } + } +} else { + $cli->message('Username: ' . $user); +} + +while (is_null($pass)) { + $pass = $cli->passwordPrompt('Password:'); + if (!strlen($pass)) { + $pass = null; + } +} + +$cli->writeln(); + +$ob = $imp_imap->createImapObject($user, $pass, $server); +if (!$ob) { + $cli->fatal('Could not create Imap Client object.'); +} + +if ($ob->cache) { + $cli->fatal('Caching not setup for this server.'); +} else { + $driver = $ob->getParam('cache'); + if (!isset($driver['cacheob'])) { + $cli->message('Caching has been disabled for this server.', 'cli.error'); + exit; + } + $cli->message('Cache driver used: ' . get_class($driver['cacheob'])); +} + +try { + $ob->login(); + $cli->message('Successfully logged in to IMAP server.'); + + $mboxes = $ob->listMailboxes('*', Horde_Imap_Client::MBOX_ALL, array('flat' => true, 'sort' => true)); + $cli->message('User mailbox count: ' . count($mboxes)); +} catch (Horde_Imap_Client_Exception $e) { + $cli->fatal('IMAP error: ' . $e->getMessage()); +} + +$opts = array( + 1 => 'Summary Statistics (All Mailboxes)', + 2 => 'Detailed Statistics (All Mailboxes)', + 3 => 'Detailed Statistics (Single Mailbox)', + 4 => 'Summary Statistics (Single UID)', + 5 => 'Detailed Statistics (Single UID)', + 6 => 'Expire All Mailboxes', + 7 => 'Expire Mailbox', + 8 => 'Expire specific UIDs', + 0 => 'Exit' +); + +$use_lzf = (!empty($conf['cache']['compress']) && Horde_Util::extensionExists('lzf')); + +while (true) { + $cli->writeln(); + + $action = $cli->prompt('Action:', $opts); + switch ($action) { + case 0: + exit; + + case 1: + $mbox_list = array(); + $msg_cnt = $search_cnt = 0; + + foreach ($mboxes as $val) { + if ($res = $ob->cache->get($val)) { + $mbox_list[$val] = array( + 'msgs' => count($res) + ); + $msg_cnt += $mbox_list[$val]['msgs']; + + if ($res = $ob->cache->getMetaData($val, null, array('HICsearch'))) { + $mbox_list[$val]['search'] = count($res['HICsearch']) - 1; + $search_cnt += $mbox_list[$val]['search']; + } + } + } + + $cli->writeln(); + $cli->message($cli->bold('Cached mailboxes:') . ' ' . count($mbox_list)); + $cli->message($cli->bold('Cached messages:') . ' ' . $msg_cnt); + $cli->message($cli->bold('Cached searches:') . ' ' . $search_cnt); + break; + + case 2: + case 3: + if ($action == 3) { + $prompt = $cli->prompt('Mailbox:'); + if (!strlen($prompt)) { + break; + } + $mbox_list = array($prompt); + } else { + $mbox_list = $mboxes; + } + + foreach ($mbox_list as $mbox) { + if ($res = $ob->cache->get($mbox)) { + $cli->writeln(); + + $cli->message('Mailbox: ' . $cli->green($mbox)); + $cli->message('Cached messages: ' . count($res) . ' [' . $ob->utils->toSequenceString($res) . ']'); + + $lzf_size = $total_size = 0; + foreach ($ob->cache->get($mbox, $res, null) as $val) { + $data = serialize($val); + $total_size += strlen($data); + if ($use_lzf) { + $lzf_size += strlen(lzf_compress($data)); + } + } + + $cli->message('Approximate size (bytes): ' . $total_size); + if (!empty($lzf_size)) { + $cli->message('Approximate size - LZF (bytes): ' . $lzf_size . ' [' . $cli->red(100 - round($lzf_size / $total_size * 100, 1) . '% savings') . ']'); + } + + if ($res = $ob->cache->getMetaData($mbox)) { + try { + $status = $ob->status($mbox, Horde_Imap_Client::STATUS_UIDVALIDITY | Horde_Imap_Client::STATUS_HIGHESTMODSEQ); + } catch (Horde_Imap_Client_Exception $e) { + $cli->writeln(); + $cli->message('IMAP error: ' . $e->getMessage(), 'cli.error'); + } + $cli->message('UIDVALIDITY: ' . $res['uidvalid'] . ' [Server value: ' . (($status['uidvalidity'] != $res['uidvalid']) ? $cli->red($status['uidvalidity']) : $status['uidvalidity']) . ']'); + if (isset($res['HICmodseq'])) { + $cli->message('Highest MODSEQ seen: ' . $res['HICmodseq'] . ' [Server value: ' . (($status['highestmodseq'] != $res['HICmodseq']) ? $cli->red($status['highestmodseq']) : $status['highestmodseq']) . ']'); + } + if (isset($res['HICsearch'])) { + $cli->message('Cached searches: ' . (count($res['HICsearch']) - 1)); + } + } + } elseif ($action == 3) { + $cli->writeln(); + $cli->message(sprintf('No cache information found for "%s".', $mbox), 'cli.error'); + } + } + break; + + case 4: + case 5: + $mbox = $cli->prompt('Mailbox:'); + if (!strlen($mbox)) { + break; + } + $uid = $cli->prompt('UID:'); + if (!strlen($uid)) { + break; + } + if ($res = $ob->cache->get($mbox, array($uid), null)) { + $cli->writeln(); + $cli->message(sprintf('Message information [%s:%d]', $mbox, $uid)); + $cli->message('Cached fields: ' . implode(', ', array_keys($res[$uid]))); + + $data = serialize($res[$uid]); + $cli->message('Approximate size (bytes): ' . strlen($data)); + + if ($use_lzf) { + $lzf_size += strlen(lzf_compress($data)); + $cli->message('Approximate size - LZF (bytes): ' . $lzf_size . ' [' . $cli->red(100 -round($lzf_size / $total_size * 100, 1) . '% savings') . ']'); + } + + if ($action == 5) { + $cli->writeln(); + $cli->writeln(print_r($res[$uid], true)); + } + } else { + $cli->writeln(); + $cli->message(sprintf('No cache information found for "%s:%d".', $mbox, $uid), 'cli.error'); + } + break; + + case 6: + case 7: + if ($action == 7) { + $prompt = $cli->prompt('Mailbox:'); + if (!strlen($prompt)) { + break; + } + $mbox_list = array($prompt); + } else { + $mbox_list = $mboxes; + } + + if ($cli->prompt('Delete mailbox cache(s)?', array('1' => 'No', '2' => 'Yes'), 1) == 2) { + $cli->writeln(); + foreach ($mbox_list as $val) { + $ob->cache->deleteMailbox($val); + $cli->message('Deleted cache: ' . $val, 'cli.success'); + } + } + break; + + case 8: + $mbox = $cli->prompt('Mailbox:'); + if (!strlen($mbox)) { + break; + } + $uids = $cli->prompt('UIDs (IMAP sequence string format):'); + if (!strlen($uids)) { + break; + } + $uids = $ob->utils->fromSequenceString($uids); + if (empty($uids)) { + $cli->writeln(); + $cli->message('No UIDs found', 'cli.error'); + break; + } + + $cli->writeln(); + + try { + $ob->cache->deleteMsgs($mbox, $uids); + $cli->message(sprintf('Deleted %d UIDs from cache.', count($uids)), 'cli.success'); + } catch (Horde_Imap_Client_Exception $e) { + $cli->writeln(); + $cli->message('Failed deleting UIDs. Error: ' . $e->getMessage(), 'cli.error'); + } + break; + } +} diff --git a/imp/scripts/.htaccess b/imp/scripts/.htaccess deleted file mode 100644 index 3a4288278..000000000 --- a/imp/scripts/.htaccess +++ /dev/null @@ -1 +0,0 @@ -Deny from all diff --git a/imp/scripts/bounce_spam.php b/imp/scripts/bounce_spam.php deleted file mode 100755 index 2bdbb644e..000000000 --- a/imp/scripts/bounce_spam.php +++ /dev/null @@ -1,66 +0,0 @@ -#!/usr/bin/env php - - * @category Horde - * @license http://www.fsf.org/copyleft/gpl.html GPL - * @package IMP - */ - -require_once dirname(__FILE__) . '/../lib/Application.php'; -Horde_Registry::appInit('imp', array( - 'authentication' => false, - 'cli' => true -)); - -/** Configuration **/ - -/** - * Location of the bounce template. - * The following strings will be replaced in the template: - * %TO% - The spammer's e-mail address. - * %TARGET% - The target's e-mail address. - */ -$bounce_template = IMP_BASE . '/config/bounce.txt'; - -/** End Configuration **/ - -/* If there's no bounce template file then abort */ -if (!file_exists($bounce_template)) { - $cli->fatal('Bounce template does not exist.'); -} - -/* Read the message content. */ -$data = $cli->readStdin(); - -/* Who's the spammer? */ -$headers = Horde_Mime_Headers::parseHeaders($data); -$return_path = Horde_Mime_Address::bareAddress($headers->getValue('return-path')); - -/* Who's the target? */ -$delivered_to = Horde_Mime_Address::bareAddress($headers->getValue('delivered-to')); - -/* Read the bounce template and construct the mail */ -$bounce = str_replace( - array('%TO%', '%TARGET%'), - array($return_path, $delivered_to), - file_get_contents($bounce_template) -); - -/* Send the mail */ -$sendmail = "/usr/sbin/sendmail -t -f ''"; -$fd = popen($sendmail, 'w'); -fputs($fd, preg_replace("/\n$/", "\r\n", $bounce . $data)); -pclose($fd); diff --git a/imp/scripts/query-imap-cache.php b/imp/scripts/query-imap-cache.php deleted file mode 100755 index 19d294e02..000000000 --- a/imp/scripts/query-imap-cache.php +++ /dev/null @@ -1,295 +0,0 @@ -#!/bin/env php - - * @category Horde - * @license http://www.fsf.org/copyleft/gpl.html GPL - * @package IMP - */ - -require_once dirname(__FILE__) . '/../lib/Application.php'; -Horde_Registry::appInit('imp', array('cli' => true)); - -$c = new Console_Getopt(); -$argv = $c->readPHPArgv(); -array_shift($argv); -$options = $c->getopt2($argv, '', array('user=', 'pass=', 'server=')); -if (PEAR::isError($options)) { - $cli->fatal("Invalid arguments.\n"); -} - -$pass = $server = $user = null; -foreach ($options[0] as $val) { - switch ($val[0]) { - case '--user': - $user = $val[1]; - break; - - case '--pass': - $pass = $val[1]; - break; - - case '--server': - $server = $val[1]; - break; - } -} - -$imp_imap = $injector->getInstance('IMP_Injector_Factory_Imap')->create(); - -if (is_null($server)) { - /* Set first entry to 1, not 0. */ - $sconfig = $slookup = array(''); - $i = 1; - - foreach ($imp_imap->loadServerConfig() as $key => $val) { - $sconfig[$i] = $val['name'] . ' [' . $key . ']'; - $slookup[$i++] = $key; - } - - unset($sconfig[0]); - - while (is_null($server)) { - $server = $cli->prompt('Server:', $sconfig); - } - $server = $slookup[$server]; -} else { - $cli->message('Server: ' . $server); -} - -if (is_null($user)) { - while (is_null($user)) { - $user = $cli->prompt('Username:'); - if (!strlen($user)) { - $user = null; - } - } -} else { - $cli->message('Username: ' . $user); -} - -while (is_null($pass)) { - $pass = $cli->passwordPrompt('Password:'); - if (!strlen($pass)) { - $pass = null; - } -} - -$cli->writeln(); - -$ob = $imp_imap->createImapObject($user, $pass, $server); -if (!$ob) { - $cli->fatal('Could not create Imap Client object.'); -} - -if ($ob->cache) { - $cli->fatal('Caching not setup for this server.'); -} else { - $driver = $ob->getParam('cache'); - if (!isset($driver['cacheob'])) { - $cli->message('Caching has been disabled for this server.', 'cli.error'); - exit; - } - $cli->message('Cache driver used: ' . get_class($driver['cacheob'])); -} - -try { - $ob->login(); - $cli->message('Successfully logged in to IMAP server.'); - - $mboxes = $ob->listMailboxes('*', Horde_Imap_Client::MBOX_ALL, array('flat' => true, 'sort' => true)); - $cli->message('User mailbox count: ' . count($mboxes)); -} catch (Horde_Imap_Client_Exception $e) { - $cli->fatal('IMAP error: ' . $e->getMessage()); -} - -$opts = array( - 1 => 'Summary Statistics (All Mailboxes)', - 2 => 'Detailed Statistics (All Mailboxes)', - 3 => 'Detailed Statistics (Single Mailbox)', - 4 => 'Summary Statistics (Single UID)', - 5 => 'Detailed Statistics (Single UID)', - 6 => 'Expire All Mailboxes', - 7 => 'Expire Mailbox', - 8 => 'Expire specific UIDs', - 0 => 'Exit' -); - -$use_lzf = (!empty($conf['cache']['compress']) && Horde_Util::extensionExists('lzf')); - -while (true) { - $cli->writeln(); - - $action = $cli->prompt('Action:', $opts); - switch ($action) { - case 0: - exit; - - case 1: - $mbox_list = array(); - $msg_cnt = $search_cnt = 0; - - foreach ($mboxes as $val) { - if ($res = $ob->cache->get($val)) { - $mbox_list[$val] = array( - 'msgs' => count($res) - ); - $msg_cnt += $mbox_list[$val]['msgs']; - - if ($res = $ob->cache->getMetaData($val, null, array('HICsearch'))) { - $mbox_list[$val]['search'] = count($res['HICsearch']) - 1; - $search_cnt += $mbox_list[$val]['search']; - } - } - } - - $cli->writeln(); - $cli->message($cli->bold('Cached mailboxes:') . ' ' . count($mbox_list)); - $cli->message($cli->bold('Cached messages:') . ' ' . $msg_cnt); - $cli->message($cli->bold('Cached searches:') . ' ' . $search_cnt); - break; - - case 2: - case 3: - if ($action == 3) { - $prompt = $cli->prompt('Mailbox:'); - if (!strlen($prompt)) { - break; - } - $mbox_list = array($prompt); - } else { - $mbox_list = $mboxes; - } - - foreach ($mbox_list as $mbox) { - if ($res = $ob->cache->get($mbox)) { - $cli->writeln(); - - $cli->message('Mailbox: ' . $cli->green($mbox)); - $cli->message('Cached messages: ' . count($res) . ' [' . $ob->utils->toSequenceString($res) . ']'); - - $lzf_size = $total_size = 0; - foreach ($ob->cache->get($mbox, $res, null) as $val) { - $data = serialize($val); - $total_size += strlen($data); - if ($use_lzf) { - $lzf_size += strlen(lzf_compress($data)); - } - } - - $cli->message('Approximate size (bytes): ' . $total_size); - if (!empty($lzf_size)) { - $cli->message('Approximate size - LZF (bytes): ' . $lzf_size . ' [' . $cli->red(100 - round($lzf_size / $total_size * 100, 1) . '% savings') . ']'); - } - - if ($res = $ob->cache->getMetaData($mbox)) { - try { - $status = $ob->status($mbox, Horde_Imap_Client::STATUS_UIDVALIDITY | Horde_Imap_Client::STATUS_HIGHESTMODSEQ); - } catch (Horde_Imap_Client_Exception $e) { - $cli->writeln(); - $cli->message('IMAP error: ' . $e->getMessage(), 'cli.error'); - } - $cli->message('UIDVALIDITY: ' . $res['uidvalid'] . ' [Server value: ' . (($status['uidvalidity'] != $res['uidvalid']) ? $cli->red($status['uidvalidity']) : $status['uidvalidity']) . ']'); - if (isset($res['HICmodseq'])) { - $cli->message('Highest MODSEQ seen: ' . $res['HICmodseq'] . ' [Server value: ' . (($status['highestmodseq'] != $res['HICmodseq']) ? $cli->red($status['highestmodseq']) : $status['highestmodseq']) . ']'); - } - if (isset($res['HICsearch'])) { - $cli->message('Cached searches: ' . (count($res['HICsearch']) - 1)); - } - } - } elseif ($action == 3) { - $cli->writeln(); - $cli->message(sprintf('No cache information found for "%s".', $mbox), 'cli.error'); - } - } - break; - - case 4: - case 5: - $mbox = $cli->prompt('Mailbox:'); - if (!strlen($mbox)) { - break; - } - $uid = $cli->prompt('UID:'); - if (!strlen($uid)) { - break; - } - if ($res = $ob->cache->get($mbox, array($uid), null)) { - $cli->writeln(); - $cli->message(sprintf('Message information [%s:%d]', $mbox, $uid)); - $cli->message('Cached fields: ' . implode(', ', array_keys($res[$uid]))); - - $data = serialize($res[$uid]); - $cli->message('Approximate size (bytes): ' . strlen($data)); - - if ($use_lzf) { - $lzf_size += strlen(lzf_compress($data)); - $cli->message('Approximate size - LZF (bytes): ' . $lzf_size . ' [' . $cli->red(100 -round($lzf_size / $total_size * 100, 1) . '% savings') . ']'); - } - - if ($action == 5) { - $cli->writeln(); - $cli->writeln(print_r($res[$uid], true)); - } - } else { - $cli->writeln(); - $cli->message(sprintf('No cache information found for "%s:%d".', $mbox, $uid), 'cli.error'); - } - break; - - case 6: - case 7: - if ($action == 7) { - $prompt = $cli->prompt('Mailbox:'); - if (!strlen($prompt)) { - break; - } - $mbox_list = array($prompt); - } else { - $mbox_list = $mboxes; - } - - if ($cli->prompt('Delete mailbox cache(s)?', array('1' => 'No', '2' => 'Yes'), 1) == 2) { - $cli->writeln(); - foreach ($mbox_list as $val) { - $ob->cache->deleteMailbox($val); - $cli->message('Deleted cache: ' . $val, 'cli.success'); - } - } - break; - - case 8: - $mbox = $cli->prompt('Mailbox:'); - if (!strlen($mbox)) { - break; - } - $uids = $cli->prompt('UIDs (IMAP sequence string format):'); - if (!strlen($uids)) { - break; - } - $uids = $ob->utils->fromSequenceString($uids); - if (empty($uids)) { - $cli->writeln(); - $cli->message('No UIDs found', 'cli.error'); - break; - } - - $cli->writeln(); - - try { - $ob->cache->deleteMsgs($mbox, $uids); - $cli->message(sprintf('Deleted %d UIDs from cache.', count($uids)), 'cli.success'); - } catch (Horde_Imap_Client_Exception $e) { - $cli->writeln(); - $cli->message('Failed deleting UIDs. Error: ' . $e->getMessage(), 'cli.error'); - } - break; - } -}