summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
Diffstat (limited to 'bin')
-rwxr-xr-xbin/cleandb.sh5
-rwxr-xr-xbin/decrypt.sh8
-rwxr-xr-xbin/gc.sh27
-rwxr-xr-xbin/indexcontacts.sh11
-rwxr-xr-xbin/installto.sh8
-rwxr-xr-xbin/moduserprefs.sh4
-rwxr-xr-xbin/msgimport.sh7
-rwxr-xr-xbin/update.sh89
-rwxr-xr-xbin/updatecss.sh122
-rwxr-xr-xbin/updatedb.sh66
10 files changed, 269 insertions, 78 deletions
diff --git a/bin/cleandb.sh b/bin/cleandb.sh
index ecf258320..ea905c873 100755
--- a/bin/cleandb.sh
+++ b/bin/cleandb.sh
@@ -34,8 +34,9 @@ $RCMAIL = rcmail::get_instance();
$db = $RCMAIL->get_dbh();
$db->db_connect('w');
-if (!$db->is_connected() || $db->is_error())
- die("No DB connection\n");
+if (!$db->is_connected() || $db->is_error()) {
+ rcube::raise_error("No DB connection", false, true);
+}
if (!empty($_SERVER['argv'][1]))
$days = intval($_SERVER['argv'][1]);
diff --git a/bin/decrypt.sh b/bin/decrypt.sh
index 95fdefc42..ff7c43038 100755
--- a/bin/decrypt.sh
+++ b/bin/decrypt.sh
@@ -19,7 +19,7 @@
+-----------------------------------------------------------------------+
*/
-/*-
+/**
* If http_received_header_encrypt is configured, the IP address and the
* host name of the added Received: header is encrypted with 3DES, to
* protect information that some could consider sensitve, yet their
@@ -28,8 +28,8 @@
* Such an encrypted Received: header might look like:
*
* Received: from DzgkvJBO5+bw+oje5JACeNIa/uSI4mRw2cy5YoPBba73eyBmjtyHnQ==
- * [my0nUbjZXKtl7KVBZcsvWOxxtyVFxza4]
- * with HTTP/1.1 (POST); Thu, 14 May 2009 19:17:28 +0200
+ * [my0nUbjZXKtl7KVBZcsvWOxxtyVFxza4]
+ * with HTTP/1.1 (POST); Thu, 14 May 2009 19:17:28 +0200
*
* In this example, the two encrypted components are the sender host name
* (DzgkvJBO5+bw+oje5JACeNIa/uSI4mRw2cy5YoPBba73eyBmjtyHnQ==) and the IP
@@ -48,7 +48,7 @@
*
* If (most likely binary) junk is shown, then
* - either the encryption password has, between the time the mail was sent
- * and `now', changed, or
+ * and 'now', changed, or
* - you are dealing with counterfeit header data.
*/
diff --git a/bin/gc.sh b/bin/gc.sh
new file mode 100755
index 000000000..1ee610741
--- /dev/null
+++ b/bin/gc.sh
@@ -0,0 +1,27 @@
+#!/usr/bin/env php
+<?php
+/*
+ +-----------------------------------------------------------------------+
+ | bin/gc.sh |
+ | |
+ | This file is part of the Roundcube Webmail client |
+ | Copyright (C) 2013, The Roundcube Dev Team |
+ | |
+ | Licensed under the GNU General Public License version 3 or |
+ | any later version with exceptions for skins & plugins. |
+ | See the README file for a full license statement. |
+ | |
+ | PURPOSE: |
+ | Trigger garbage collecting routines manually (e.g. via cronjob) |
+ | |
+ +-----------------------------------------------------------------------+
+ | Author: Thomas Bruederli <roundcube@gmail.com> |
+ +-----------------------------------------------------------------------+
+*/
+
+define('INSTALL_PATH', realpath(dirname(__FILE__) . '/..') . '/' );
+
+require INSTALL_PATH.'program/include/clisetup.php';
+
+$rcmail = rcube::get_instance();
+$rcmail->gc();
diff --git a/bin/indexcontacts.sh b/bin/indexcontacts.sh
index a9a5a952a..c85a535a7 100755
--- a/bin/indexcontacts.sh
+++ b/bin/indexcontacts.sh
@@ -30,17 +30,18 @@ $RCMAIL = rcmail::get_instance();
$db = $RCMAIL->get_dbh();
$db->db_connect('w');
-if (!$db->is_connected() || $db->is_error())
- die("No DB connection\n");
+if (!$db->is_connected() || $db->is_error()) {
+ rcube::raise_error("No DB connection", false, true);
+}
// iterate over all users
-$sql_result = $db->query("SELECT user_id FROM " . $RCMAIL->config->get('db_table_users', 'users')." WHERE 1=1");
+$sql_result = $db->query("SELECT user_id FROM " . $db->table_name('users') . " ORDER BY user_id");
while ($sql_result && ($sql_arr = $db->fetch_assoc($sql_result))) {
echo "Indexing contacts for user " . $sql_arr['user_id'] . "...";
-
+
$contacts = new rcube_contacts($db, $sql_arr['user_id']);
$contacts->set_pagesize(9999);
-
+
$result = $contacts->list_records();
while ($result->count && ($row = $result->next())) {
unset($row['words']);
diff --git a/bin/installto.sh b/bin/installto.sh
index e6cf79d7d..269a5dc06 100755
--- a/bin/installto.sh
+++ b/bin/installto.sh
@@ -26,17 +26,17 @@ require_once INSTALL_PATH . 'program/include/clisetup.php';
$target_dir = unslashify($_SERVER['argv'][1]);
if (empty($target_dir) || !is_dir(realpath($target_dir)))
- die("Invalid target: not a directory\nUsage: installto.sh <TARGET>\n");
+ rcube::raise_error("Invalid target: not a directory\nUsage: installto.sh <TARGET>", false, true);
// read version from iniset.php
$iniset = @file_get_contents($target_dir . '/program/include/iniset.php');
if (!preg_match('/define\(.RCMAIL_VERSION.,\s*.([0-9.]+[a-z-]*)/', $iniset, $m))
- die("No valid Roundcube installation found at $target_dir\n");
+ rcube::raise_error("No valid Roundcube installation found at $target_dir", false, true);
$oldversion = $m[1];
if (version_compare(version_parse($oldversion), version_parse(RCMAIL_VERSION), '>='))
- die("Installation at target location is up-to-date!\n");
+ rcube::raise_error("Installation at target location is up-to-date!", false, true);
echo "Upgrading from $oldversion. Do you want to continue? (y/N)\n";
$input = trim(fgets(STDIN));
@@ -50,7 +50,7 @@ if (strtolower($input) == 'y') {
break;
}
}
- foreach (array('index.php','.htaccess','config/main.inc.php.dist','config/db.inc.php.dist','CHANGELOG','README.md','UPGRADING','LICENSE') as $file) {
+ foreach (array('index.php','.htaccess','config/defaults.inc.php','CHANGELOG','README.md','UPGRADING','LICENSE') as $file) {
if (!system("rsync -av " . INSTALL_PATH . "$file $target_dir/$file")) {
$err = true;
break;
diff --git a/bin/moduserprefs.sh b/bin/moduserprefs.sh
index b8ba98578..9bbc885a6 100755
--- a/bin/moduserprefs.sh
+++ b/bin/moduserprefs.sh
@@ -2,7 +2,7 @@
<?php
/*
+-----------------------------------------------------------------------+
- | bin/moduserprefs.sh |
+ | bin/moduserprefs.sh |
| |
| This file is part of the Roundcube Webmail client |
| Copyright (C) 2012, The Roundcube Dev Team |
@@ -61,7 +61,7 @@ if ($args['user'])
$query = 'user_id=' . intval($args['user']);
// iterate over all users
-$sql_result = $db->query("SELECT * FROM " . $rcmail->config->get('db_table_users', 'users')." WHERE $query");
+$sql_result = $db->query("SELECT * FROM " . $db->table_name('users') . " WHERE $query");
while ($sql_result && ($sql_arr = $db->fetch_assoc($sql_result))) {
echo "Updating prefs for user " . $sql_arr['user_id'] . "...";
diff --git a/bin/msgimport.sh b/bin/msgimport.sh
index 41bcd7e53..1fcc34680 100755
--- a/bin/msgimport.sh
+++ b/bin/msgimport.sh
@@ -33,8 +33,7 @@ else if (!($args['host'] && $args['file']))
}
else if (!is_file($args['file']))
{
- print "Cannot read message file\n";
- exit;
+ rcube::raise_error("Cannot read message file.", false, true);
}
// prompt for username if not set
@@ -87,7 +86,7 @@ if ($IMAP->connect($host, $args['user'], $args['pass'], $imap_port, $imap_ssl))
if ($IMAP->save_message($args['mbox'], rtrim($message)))
$count++;
else
- die("Failed to save message to {$args['mbox']}\n");
+ rcube::raise_error("Failed to save message to {$args['mbox']}", false, true);
$message = '';
}
continue;
@@ -108,7 +107,7 @@ if ($IMAP->connect($host, $args['user'], $args['pass'], $imap_port, $imap_ssl))
}
else
{
- print "IMAP login failed.\n";
+ rcube::raise_error("IMAP login failed.", false, true);
}
?>
diff --git a/bin/update.sh b/bin/update.sh
index 05956b933..71e2c630a 100755
--- a/bin/update.sh
+++ b/bin/update.sh
@@ -5,7 +5,7 @@
| bin/update.sh |
| |
| This file is part of the Roundcube Webmail client |
- | Copyright (C) 2010-2011, The Roundcube Dev Team |
+ | Copyright (C) 2010-2013, The Roundcube Dev Team |
| |
| Licensed under the GNU General Public License version 3 or |
| any later version with exceptions for skins & plugins. |
@@ -25,7 +25,7 @@ require_once INSTALL_PATH . 'program/include/clisetup.php';
require_once INSTALL_PATH . 'installer/rcube_install.php';
// get arguments
-$opts = rcube_utils::get_opt(array('v' => 'version'));
+$opts = rcube_utils::get_opt(array('v' => 'version', 'y' => 'accept'));
// ask user if no version is specified
if (!$opts['version']) {
@@ -36,32 +36,16 @@ if (!$opts['version']) {
$opts['version'] = RCMAIL_VERSION;
}
-if ($opts['version'] && version_compare(version_parse($opts['version']), version_parse(RCMAIL_VERSION), '>='))
- die("Nothing to be done here. Bye!\n");
-
-
$RCI = rcube_install::get_instance();
$RCI->load_config();
if ($RCI->configured) {
$success = true;
-
- if ($messages = $RCI->check_config()) {
+
+ if (($messages = $RCI->check_config()) || $RCI->legacy_config) {
$success = false;
$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";
@@ -86,31 +70,42 @@ if ($RCI->configured) {
echo "\n";
}
+ if (!$err && $RCI->legacy_config) {
+ echo "WARNING: Your configuration needs to be migrated!\n";
+ echo "We changed the configuration files structure and your two config files main.inc.php and db.inc.php have to be merged into one single file.\n";
+ $err++;
+ }
+
// 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));
+ if (!$opts['accept']) {
+ 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;
-
+ if ($opts['accept'] || strtolower($input) == 'y') {
+ $error = $written = 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) {
+ echo ". backing up the current config file(s)...\n";
+
+ foreach (array('config', 'main', 'db') as $file) {
+ if (file_exists(RCMAIL_CONFIG_DIR . '/' . $file . '.inc.php')) {
+ if (!copy(RCMAIL_CONFIG_DIR . '/' . $file . '.inc.php', RCMAIL_CONFIG_DIR . '/' . $file . '.old.php')) {
+ $error = true;
+ }
+ }
+ }
+
+ if (!$error) {
$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));
+ echo ". writing " . RCMAIL_CONFIG_DIR . "/config.inc.php...\n";
+ $written = file_put_contents(RCMAIL_CONFIG_DIR . '/config.inc.php', $RCI->create_config());
}
-
+
// Success!
- if ($write1 && $write2) {
+ if ($written) {
echo "Done.\n";
echo "Your configuration files are now up-to-date!\n";
@@ -119,9 +114,15 @@ if ($RCI->configured) {
foreach ($messages['missing'] as $msg)
echo "- '" . $msg['prop'] . ($msg['name'] ? "': " . $msg['name'] : "'") . "\n";
}
+
+ if ($RCI->legacy_config) {
+ foreach (array('main', 'db') as $file) {
+ @unlink(RCMAIL_CONFIG_DIR . '/' . $file . '.inc.php');
+ }
+ }
}
else {
- echo "Failed to write config files!\n";
+ echo "Failed to write config file(s)!\n";
echo "Grant write privileges to the current user or update the files manually according to the above messages.\n";
}
}
@@ -143,6 +144,16 @@ if ($RCI->configured) {
}
}
+ // check file type detection
+ if ($RCI->check_mime_detection()) {
+ echo "WARNING: File type detection doesn't work properly!\n";
+ echo "Please check the 'mime_magic' config option or the finfo functions of PHP andrun this script again.\n";
+ }
+ if ($RCI->check_mime_extensions()) {
+ echo "WARNING: Mimetype to file extension mapping doesn't work properly!\n";
+ echo "Please check the 'mime_types' config option and run this script again.\n";
+ }
+
// check database schema
if ($RCI->config['db_dsnw']) {
echo "Executing database schema update.\n";
@@ -153,7 +164,7 @@ if ($RCI->configured) {
}
// index contacts for fulltext searching
- if (version_compare(version_parse($opts['version']), '0.6.0', '<')) {
+ if ($opts['version'] && version_compare(version_parse($opts['version']), '0.6.0', '<')) {
system(INSTALL_PATH . 'bin/indexcontacts.sh');
}
diff --git a/bin/updatecss.sh b/bin/updatecss.sh
new file mode 100755
index 000000000..53d237c77
--- /dev/null
+++ b/bin/updatecss.sh
@@ -0,0 +1,122 @@
+#!/usr/bin/env php
+<?php
+/*
+ +-----------------------------------------------------------------------+
+ | bin/updatecss.sh |
+ | |
+ | This file is part of the Roundcube Webmail client |
+ | Copyright (C) 2010-2013, The Roundcube Dev Team |
+ | |
+ | Licensed under the GNU General Public License version 3 or |
+ | any later version with exceptions for skins & plugins. |
+ | See the README file for a full license statement. |
+ | |
+ | PURPOSE: |
+ | Update cache-baster marks for css background images |
+ +-----------------------------------------------------------------------+
+ | Author: Aleksander Machniak <alec@alec.pl> |
+ +-----------------------------------------------------------------------+
+*/
+
+define('INSTALL_PATH', realpath(dirname(__FILE__) . '/..') . '/' );
+
+require_once INSTALL_PATH . 'program/include/clisetup.php';
+
+// get arguments
+$opts = rcube_utils::get_opt(array(
+ 'd' => 'dir',
+));
+
+if (empty($opts['dir'])) {
+ print "Skin directory not specified (--dir). Using skins/ and plugins/*/skins/.\n";
+
+ $dir = INSTALL_PATH . 'skins';
+ $dir_p = INSTALL_PATH . 'plugins';
+ $skins = glob("$dir/*", GLOB_ONLYDIR);
+ $skins_p = glob("$dir_p/*/skins/*", GLOB_ONLYDIR);
+
+ $dirs = array_merge($skins, $skins_p);
+}
+// Check if directory exists
+else if (!file_exists($opts['dir'])) {
+ rcube::raise_error("Specified directory doesn't exist.", false, true);
+}
+else {
+ $dirs = array($opts['dir']);
+}
+
+foreach ($dirs as $dir) {
+ $img_dir = $dir . '/images';
+ if (!file_exists($img_dir)) {
+ continue;
+ }
+
+ $files = get_files($dir);
+ $images = get_images($img_dir);
+ $find = array();
+ $replace = array();
+
+ // build regexps array
+ foreach ($images as $path => $sum) {
+ $path_ex = str_replace('.', '\\.', $path);
+ $find[] = "#url\(['\"]?images/$path_ex(\?v=[a-f0-9-\.]+)?['\"]?\)#";
+ $replace[] = "url(images/$path?v=$sum)";
+ }
+
+ foreach ($files as $file) {
+ $file = $dir . '/' . $file;
+ print "File: $file\n";
+ $content = file_get_contents($file);
+ $content = preg_replace($find, $replace, $content, -1, $count);
+ if ($count) {
+ file_put_contents($file, $content);
+ }
+ }
+}
+
+
+function get_images($dir)
+{
+ $images = array();
+ $dh = opendir($dir);
+
+ while ($file = readdir($dh)) {
+ if (preg_match('/^(.+)\.(gif|ico|png|jpg|jpeg)$/', $file, $m)) {
+ $filepath = "$dir/$file";
+ $images[$file] = substr(md5_file($filepath), 0, 4) . '.' . filesize($filepath);
+ print "Image: $filepath ({$images[$file]})\n";
+ }
+ else if ($file != '.' && $file != '..' && is_dir($dir . '/' . $file)) {
+ foreach (get_images($dir . '/' . $file) as $img => $sum) {
+ $images[$file . '/' . $img] = $sum;
+ }
+ }
+ }
+
+ closedir($dh);
+
+ return $images;
+}
+
+function get_files($dir)
+{
+ $files = array();
+ $dh = opendir($dir);
+
+ while ($file = readdir($dh)) {
+ if (preg_match('/^(.+)\.(css|html)$/', $file, $m)) {
+ $files[] = $file;
+ }
+ else if ($file != '.' && $file != '..' && is_dir($dir . '/' . $file)) {
+ foreach (get_files($dir . '/' . $file) as $f) {
+ $files[] = $file . '/' . $f;
+ }
+ }
+ }
+
+ closedir($dh);
+
+ return $files;
+}
+
+?>
diff --git a/bin/updatedb.sh b/bin/updatedb.sh
index 1c7e1c7a1..b4ed8b7ba 100755
--- a/bin/updatedb.sh
+++ b/bin/updatedb.sh
@@ -31,18 +31,15 @@ $opts = rcube_utils::get_opt(array(
));
if (empty($opts['dir'])) {
- echo "ERROR: Database schema directory not specified (--dir).\n";
- exit(1);
+ rcube::raise_error("Database schema directory not specified (--dir).", false, true);
}
if (empty($opts['package'])) {
- echo "ERROR: Database schema package name not specified (--package).\n";
- exit(1);
+ rcube::raise_error("Database schema package name not specified (--package).", false, true);
}
// Check if directory exists
if (!file_exists($opts['dir'])) {
- echo "ERROR: Specified database schema directory doesn't exist.\n";
- exit(1);
+ rcube::raise_error("Specified database schema directory doesn't exist.", false, true);
}
$RC = rcube::get_instance();
@@ -51,8 +48,7 @@ $DB = rcube_db::factory($RC->config->get('db_dsnw'));
// Connect to database
$DB->db_connect('w');
if (!$DB->is_connected()) {
- echo "Error connecting to database: " . $DB->is_error() . ".\n";
- exit(1);
+ rcube::raise_error("Error connecting to database: " . $DB->is_error(), false, true);
}
// Read DB schema version from database (if 'system' table exists)
@@ -90,6 +86,7 @@ if (!$version && $opts['version']) {
'0.7.1' => 2011111600,
'0.7.2' => 2011111600,
'0.7.3' => 2011111600,
+ '0.7.4' => 2011111600,
'0.8-beta' => 2011121400,
'0.8-rc' => 2011121400,
'0.8.0' => 2011121400,
@@ -97,6 +94,8 @@ if (!$version && $opts['version']) {
'0.8.2' => 2011121400,
'0.8.3' => 2011121400,
'0.8.4' => 2011121400,
+ '0.8.5' => 2011121400,
+ '0.8.6' => 2011121400,
'0.9-beta' => 2012080700,
);
@@ -110,8 +109,7 @@ if (empty($version)) {
$dir = $opts['dir'] . DIRECTORY_SEPARATOR . $DB->db_provider;
if (!file_exists($dir)) {
- echo "DDL Upgrade files for " . $DB->db_provider . " driver not found.\n";
- exit(1);
+ rcube::raise_error("DDL Upgrade files for " . $DB->db_provider . " driver not found.", false, true);
}
$dh = opendir($dir);
@@ -129,13 +127,12 @@ foreach ($result as $v) {
$error = update_db_schema($opts['package'], $v, $dir . DIRECTORY_SEPARATOR . "$v.sql");
if ($error) {
- echo "\nError in DDL upgrade $v: $error\n";
- exit(1);
+ echo "[FAILED]\n";
+ rcube::raise_error("Error in DDL upgrade $v: $error", false, true);
}
echo "[OK]\n";
}
-exit(0);
function update_db_schema($package, $version, $file)
{
@@ -183,15 +180,48 @@ function update_db_schema($package, $version, $file)
function fix_table_names($sql)
{
- global $DB;
+ global $DB, $RC, $dir;
+ static $tables;
+ static $sequences;
+
+ $prefix = $RC->config->get('db_prefix');
+ $engine = $DB->db_provider;
+
+ if (empty($prefix)) {
+ return $sql;
+ }
+
+ if ($tables === null) {
+ $tables = array();
+ $sequences = array();
+
+ // read complete schema (initial) file
+ $filename = "$dir/../$engine.initial.sql";
+ $schema = @file_get_contents($filename);
- foreach (array('users','identities','contacts','contactgroups','contactgroupmembers','session','cache','cache_index','cache_index','cache_messages','dictionary','searches','system') as $table) {
- $real_table = $DB->table_name($table);
- if ($real_table != $table) {
- $sql = preg_replace("/([^a-z0-9_])$table([^a-z0-9_])/i", "\\1$real_table\\2", $sql);
+ // find table names
+ if (preg_match_all('/CREATE TABLE (\[dbo\]\.|IF NOT EXISTS )?[`"\[\]]*([^`"\[\] \r\n]+)/i', $schema, $matches)) {
+ foreach ($matches[2] as $table) {
+ $tables[$table] = $prefix . $table;
+ }
+ }
+ // find sequence names
+ if ($engine == 'postgres' && preg_match_all('/CREATE SEQUENCE (IF NOT EXISTS )?"?([^" \n\r]+)/i', $schema, $matches)) {
+ foreach ($matches[2] as $sequence) {
+ $sequences[$sequence] = $prefix . $sequence;
+ }
}
}
+ // replace table names
+ foreach ($tables as $table => $real_table) {
+ $sql = preg_replace("/([^a-zA-Z0-9_])$table([^a-zA-Z0-9_])/", "\\1$real_table\\2", $sql);
+ }
+ // replace sequence names
+ foreach ($sequences as $sequence => $real_sequence) {
+ $sql = preg_replace("/([^a-zA-Z0-9_])$sequence([^a-zA-Z0-9_])/", "\\1$real_sequence\\2", $sql);
+ }
+
return $sql;
}