Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F224815
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
15 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/bin/dumpschema.php b/bin/dumpschema.php
index cbadb00f6..9557c4b15 100644
--- a/bin/dumpschema.php
+++ b/bin/dumpschema.php
@@ -1,97 +1,101 @@
+#!/usr/bin/env php
<?php
/*
- #!/usr/bin/php
+-----------------------------------------------------------------------+
| bin/dumpschema.php |
| |
| This file is part of the RoundCube Webmail client |
| Copyright (C) 2005-2008, RoundCube Dev. - Switzerland |
| Licensed under the GNU GPL |
| |
| PURPOSE: |
| Dumps database schema in XML format using MDB2_Schema |
| |
+-----------------------------------------------------------------------+
| Author: Thomas Bruederli <roundcube@gmail.com> |
+-----------------------------------------------------------------------+
$Id$
*/
+if (php_sapi_name() != 'cli') {
+ die('Not on the "shell" (php-cli).');
+}
+
define('INSTALL_PATH', realpath(dirname(__FILE__) . '/..') . '/' );
require INSTALL_PATH.'program/include/iniset.php';
/** callback function for schema dump **/
function print_schema($dump)
{
foreach ((array)$dump as $part)
echo $dump . "\n";
}
$config = new rcube_config();
// don't allow public access if not in devel_mode
if (!$config->get('devel_mode') && $_SERVER['REMOTE_ADDR']) {
header("HTTP/1.0 401 Access denied");
die("Access denied!");
}
$options = array(
'use_transactions' => false,
'log_line_break' => "\n",
'idxname_format' => '%s',
'debug' => false,
'quote_identifier' => true,
'force_defaults' => false,
'portability' => false,
);
$dsnw = $config->get('db_dsnw');
$dsn_array = MDB2::parseDSN($dsnw);
// set options for postgres databases
if ($dsn_array['phptype'] == 'pgsql') {
$options['disable_smart_seqname'] = true;
$options['seqname_format'] = '%s';
}
$schema =& MDB2_Schema::factory($dsnw, $options);
$schema->db->supported['transactions'] = false;
// send as text/xml when opened in browser
if ($_SERVER['REMOTE_ADDR'])
header('Content-Type: text/xml');
if (PEAR::isError($schema)) {
$error = $schema->getMessage() . ' ' . $schema->getUserInfo();
}
else {
$dump_config = array(
// 'output_mode' => 'file',
'output' => 'print_schema',
);
$definition = $schema->getDefinitionFromDatabase();
$definition['charset'] = 'utf8';
if (PEAR::isError($definition)) {
$error = $definition->getMessage() . ' ' . $definition->getUserInfo();
}
else {
$operation = $schema->dumpDatabase($definition, $dump_config, MDB2_SCHEMA_DUMP_STRUCTURE);
if (PEAR::isError($operation)) {
$error = $operation->getMessage() . ' ' . $operation->getUserInfo();
}
}
}
$schema->disconnect();
if ($error && !$_SERVER['REMOTE_ADDR'])
fputs(STDERR, $error);
?>
diff --git a/bin/msgexport.sh b/bin/msgexport.sh
index b15da1feb..7dd56e9ea 100755
--- a/bin/msgexport.sh
+++ b/bin/msgexport.sh
@@ -1,172 +1,175 @@
-#!/usr/bin/php
+#!/usr/bin/env php
<?php
+if (php_sapi_name() != 'cli') {
+ die('Not on the "shell" (php-cli).');
+}
define('INSTALL_PATH', realpath(dirname(__FILE__) . '/..') . '/' );
ini_set('memory_limit', -1);
require_once INSTALL_PATH.'program/include/iniset.php';
/**
* Parse commandline arguments into a hash array
*/
function get_opt($aliases=array())
{
$args = array();
for ($i=1; $i<count($_SERVER['argv']); $i++)
{
$arg = $_SERVER['argv'][$i];
if (substr($arg, 0, 2) == '--')
{
$sp = strpos($arg, '=');
$key = substr($arg, 2, $sp - 2);
$value = substr($arg, $sp+1);
}
else if ($arg{0} == '-')
{
$key = substr($arg, 1);
$value = $_SERVER['argv'][++$i];
}
else
continue;
$args[$key] = preg_replace(array('/^["\']/', '/["\']$/'), '', $value);
if ($alias = $aliases[$key])
$args[$alias] = $args[$key];
}
return $args;
}
function print_usage()
{
print "Usage: msgexport -h imap-host -u user-name -m mailbox name\n";
print "--host IMAP host\n";
print "--user IMAP user name\n";
print "--mbox Folder name, set to '*' for all\n";
print "--file Output file\n";
}
function vputs($str)
{
$out = $GLOBALS['args']['file'] ? STDOUT : STDERR;
fwrite($out, $str);
}
function progress_update($pos, $max)
{
$percent = round(100 * $pos / $max);
vputs(sprintf("%3d%% [%-51s] %d/%d\033[K\r", $percent, @str_repeat('=', $percent / 2) . '>', $pos, $max));
}
function export_mailbox($mbox, $filename)
{
global $IMAP;
$IMAP->set_mailbox($mbox);
vputs("Getting message list of {$mbox}...");
vputs($IMAP->messagecount()." messages\n");
if ($filename)
{
if (!($out = fopen($filename, 'w')))
{
vputs("Cannot write to output file\n");
return;
}
vputs("Writing to $filename\n");
}
else
$out = STDOUT;
for ($count = $IMAP->messagecount(), $i=1; $i <= $count; $i++)
{
$headers = $IMAP->get_headers($i, null, false);
$from = current($IMAP->decode_address_list($headers->from, 1, false));
fwrite($out, sprintf("From %s %s UID %d\n", $from['mailto'], $headers->date, $headers->uid));
fwrite($out, iil_C_FetchPartHeader($IMAP->conn, $IMAP->mailbox, $i, null));
fwrite($out, iil_C_HandlePartBody($IMAP->conn, $IMAP->mailbox, $i, null, 1));
fwrite($out, "\n\n\n");
progress_update($i, $count);
}
vputs("\ncomplete.\n");
if ($filename)
fclose($out);
}
// get arguments
$args = get_opt(array('h' => 'host', 'u' => 'user', 'p' => 'pass', 'm' => 'mbox', 'f' => 'file')) + array('host' => 'localhost', 'mbox' => 'INBOX');
if ($_SERVER['argv'][1] == 'help')
{
print_usage();
exit;
}
else if (!$args['host'])
{
vputs("Missing required parameters.\n");
print_usage();
exit;
}
// prompt for username if not set
if (empty($args['user']))
{
vputs("IMAP user: ");
$args['user'] = trim(fgets(STDIN));
}
// prompt for password
vputs("Password: ");
$args['pass'] = trim(fgets(STDIN));
// parse $host URL
$a_host = parse_url($args['host']);
if ($a_host['host'])
{
$host = $a_host['host'];
$imap_ssl = (isset($a_host['scheme']) && in_array($a_host['scheme'], array('ssl','imaps','tls'))) ? TRUE : FALSE;
$imap_port = isset($a_host['port']) ? $a_host['port'] : ($imap_ssl ? 993 : 143);
}
else
{
$host = $args['host'];
$imap_port = 143;
}
// instantiate IMAP class
$IMAP = new rcube_imap(null);
// try to connect to IMAP server
if ($IMAP->connect($host, $args['user'], $args['pass'], $imap_port, $imap_ssl))
{
vputs("IMAP login successful.\n");
$filename = null;
$mailboxes = $args['mbox'] == '*' ? $IMAP->list_mailboxes(null) : array($args['mbox']);
foreach ($mailboxes as $mbox)
{
if ($args['file'])
$filename = preg_replace('/\.[a-z0-9]{3,4}$/i', '', $args['file']) . asciiwords($mbox) . '.mbox';
else if ($args['mbox'] == '*')
$filename = asciiwords($mbox) . '.mbox';
if ($args['mbox'] == '*' && in_array(strtolower($mbox), array('junk','spam','trash')))
continue;
export_mailbox($mbox, $filename);
}
}
else
{
vputs("IMAP login failed.\n");
}
-?>
\ No newline at end of file
+?>
diff --git a/bin/msgimport.sh b/bin/msgimport.sh
index fa5678cec..a5161e026 100755
--- a/bin/msgimport.sh
+++ b/bin/msgimport.sh
@@ -1,149 +1,152 @@
-#!/usr/bin/php
+#!/usr/bin/env php
<?php
+if (php_sapi_name() != 'cli') {
+ die('Not on the "shell" (php-cli).');
+}
define('INSTALL_PATH', realpath(dirname(__FILE__) . '/..') . '/' );
ini_set('memory_limit', -1);
require_once INSTALL_PATH.'program/include/iniset.php';
/**
* Parse commandline arguments into a hash array
*/
function get_opt($aliases=array())
{
$args = array();
for ($i=1; $i<count($_SERVER['argv']); $i++)
{
$arg = $_SERVER['argv'][$i];
if (substr($arg, 0, 2) == '--')
{
$sp = strpos($arg, '=');
$key = substr($arg, 2, $sp - 2);
$value = substr($arg, $sp+1);
}
else if ($arg{0} == '-')
{
$key = substr($arg, 1);
$value = $_SERVER['argv'][++$i];
}
else
continue;
$args[$key] = preg_replace(array('/^["\']/', '/["\']$/'), '', $value);
if ($alias = $aliases[$key])
$args[$alias] = $args[$key];
}
return $args;
}
function print_usage()
{
print "Usage: msgimport -h imap-host -u user-name -m mailbox -f message-file\n";
print "--host IMAP host\n";
print "--user IMAP user name\n";
print "--mbox Target mailbox\n";
print "--file Message file to upload\n";
}
// get arguments
$args = get_opt(array('h' => 'host', 'u' => 'user', 'p' => 'pass', 'm' => 'mbox', 'f' => 'file')) + array('host' => 'localhost', 'mbox' => 'INBOX');
if ($_SERVER['argv'][1] == 'help')
{
print_usage();
exit;
}
else if (!($args['host'] && $args['file']))
{
print "Missing required parameters.\n";
print_usage();
exit;
}
else if (!is_file($args['file']))
{
print "Cannot read message file\n";
exit;
}
// prompt for username if not set
if (empty($args['user']))
{
//fwrite(STDOUT, "Please enter your name\n");
echo "IMAP user: ";
$args['user'] = trim(fgets(STDIN));
}
// prompt for password
if (empty($args['pass']))
{
echo "Password: ";
$args['pass'] = trim(fgets(STDIN));
// clear password input
echo chr(8)."\rPassword: ".str_repeat("*", strlen($args['pass']))."\n";
}
// parse $host URL
$a_host = parse_url($args['host']);
if ($a_host['host'])
{
$host = $a_host['host'];
$imap_ssl = (isset($a_host['scheme']) && in_array($a_host['scheme'], array('ssl','imaps','tls'))) ? TRUE : FALSE;
$imap_port = isset($a_host['port']) ? $a_host['port'] : ($imap_ssl ? 993 : 143);
}
else
{
$host = $args['host'];
$imap_port = 143;
}
// instantiate IMAP class
$IMAP = new rcube_imap(null);
// try to connect to IMAP server
if ($IMAP->connect($host, $args['user'], $args['pass'], $imap_port, $imap_ssl))
{
print "IMAP login successful.\n";
print "Uploading messages...\n";
$count = 0;
$message = $lastline = '';
$fp = fopen($args['file'], 'r');
while (($line = fgets($fp)) !== false)
{
if (preg_match('/^From\s+/', $line) && $lastline == '')
{
if (!empty($message))
{
if ($IMAP->save_message($args['mbox'], rtrim($message)))
$count++;
else
die("Failed to save message to {$args['mbox']}\n");
$message = '';
}
continue;
}
$message .= $line;
$lastline = rtrim($line);
}
if (!empty($message) && $IMAP->save_message($args['mbox'], rtrim($message)))
$count++;
// upload message from file
if ($count)
print "$count messages successfully added to {$args['mbox']}.\n";
else
print "Adding messages failed!\n";
}
else
{
print "IMAP login failed.\n";
}
-?>
\ No newline at end of file
+?>
diff --git a/bin/update.sh b/bin/update.sh
index a9a917c8c..c93d92dec 100755
--- a/bin/update.sh
+++ b/bin/update.sh
@@ -1,115 +1,117 @@
-#!/usr/bin/php
+#!/usr/bin/env php
<?php
-
+if (php_sapi_name() != 'cli') {
+ die('Not on the "shell" (php-cli).');
+}
define('INSTALL_PATH', realpath(dirname(__FILE__) . '/..') . '/' );
require_once INSTALL_PATH . 'program/include/iniset.php';
require_once INSTALL_PATH . 'installer/rcube_install.php';
$RCI = rcube_install::get_instance();
$RCI->load_config();
if ($RCI->configured) {
if ($messages = $RCI->check_config()) {
$err = 0;
// list missing config options
if (is_array($messages['missing'])) {
echo "WARNING: Missing config options:\n";
echo "(These config options should be present in the current configuration)\n";
foreach ($messages['missing'] as $msg) {
echo "- '" . $msg['prop'] . ($msg['name'] ? "': " . $msg['name'] : "'") . "\n";
$err++;
}
echo "\n";
}
// list old/replaced config options
if (is_array($messages['replaced'])) {
echo "WARNING: Replaced config options:\n";
echo "(These config options have been replaced or renamed)\n";
foreach ($messages['replaced'] as $msg) {
echo "- '" . $msg['prop'] . "' was replaced by '" . $msg['replacement'] . "'\n";
$err++;
}
echo "\n";
}
// list obsolete config options (just a notice)
if (is_array($messages['obsolete'])) {
echo "NOTICE: Obsolete config options:\n";
echo "(You still have some obsolete or inexistent properties set. This isn't a problem but should be noticed)\n";
foreach ($messages['obsolete'] as $msg) {
echo "- '" . $msg['prop'] . ($msg['name'] ? "': " . $msg['name'] : "'") . "\n";
$err++;
}
echo "\n";
}
// ask user to update config files
if ($err) {
echo "Do you want me to fix your local configuration? (y/N)\n";
$input = trim(fgets(STDIN));
// positive: let's merge the local config with the defaults
if (strtolower($input) == 'y') {
$copy1 = $copy2 = $write1 = $write2 = false;
// backup current config
echo ". backing up the current config files...\n";
$copy1 = copy(RCMAIL_CONFIG_DIR . '/main.inc.php', RCMAIL_CONFIG_DIR . '/main.old.php');
$copy2 = copy(RCMAIL_CONFIG_DIR . '/db.inc.php', RCMAIL_CONFIG_DIR . '/db.old.php');
if ($copy1 && $copy2) {
$RCI->merge_config();
echo ". writing " . RCMAIL_CONFIG_DIR . "/main.inc.php...\n";
$write1 = file_put_contents(RCMAIL_CONFIG_DIR . '/main.inc.php', $RCI->create_config('main', true));
echo ". writing " . RCMAIL_CONFIG_DIR . "/main.db.php...\n";
$write2 = file_put_contents(RCMAIL_CONFIG_DIR . '/db.inc.php', $RCI->create_config('db', true));
}
// Success!
if ($write1 && $write2) {
echo "Done.\n";
echo "Your configuration files are now up-tp-date!\n";
}
else {
echo "Failed to write config files!\n";
echo "Grant write privileges to the current user or update the files manually according to the above messages.\n";
}
}
else {
echo "Please update your config files manually according to the above messages.\n";
}
}
// check dependencies based on the current configuration
if (is_array($messages['dependencies'])) {
echo "WARNING: Dependency check failed!\n";
echo "(Some of your configuration settings require other options to be configured or additional PHP modules to be installed)\n";
foreach ($messages['dependencies'] as $msg) {
echo "- " . $msg['prop'] . ': ' . $msg['explain'] . "\n";
}
echo "Please fix your config files and run this script again!\n";
echo "See ya.\n";
}
}
else {
echo "This instance of RoundCube is up-to-date.\n";
echo "Have fun!\n";
}
}
else {
echo "This instance of RoundCube is not yet configured!\n";
echo "Open http://url-to-roundcube/installer/ in your browser and follow the instuctions.\n";
}
echo "\n";
-?>
\ No newline at end of file
+?>
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Sat, Mar 1, 12:37 PM (56 m, 25 s)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
167000
Default Alt Text
(15 KB)
Attached To
Mode
R3 roundcubemail
Attached
Detach File
Event Timeline
Log In to Comment