diff options
Diffstat (limited to 'bin')
-rwxr-xr-x | bin/cleandb.sh | 5 | ||||
-rwxr-xr-x | bin/decrypt.sh | 8 | ||||
-rwxr-xr-x | bin/gc.sh | 27 | ||||
-rwxr-xr-x | bin/indexcontacts.sh | 11 | ||||
-rwxr-xr-x | bin/installto.sh | 6 | ||||
-rwxr-xr-x | bin/jsshrink.sh | 2 | ||||
-rwxr-xr-x | bin/jsunshrink.sh | 2 | ||||
-rwxr-xr-x | bin/moduserprefs.sh | 4 | ||||
-rwxr-xr-x | bin/msgimport.sh | 7 | ||||
-rwxr-xr-x | bin/update.sh | 4 | ||||
-rwxr-xr-x | bin/updatecss.sh | 122 | ||||
-rwxr-xr-x | bin/updatedb.sh | 76 |
12 files changed, 235 insertions, 39 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..8e1ab1fbf 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)); diff --git a/bin/jsshrink.sh b/bin/jsshrink.sh index 1d77ff388..c79f90405 100755 --- a/bin/jsshrink.sh +++ b/bin/jsshrink.sh @@ -56,7 +56,7 @@ if [ $# -gt 0 ]; then fi # default: compress application scripts -for fn in app common googiespell list; do +for fn in app common googiespell list treelist; do if [ -r "$JS_DIR/${fn}.js.src" ]; then echo "$JS_DIR/${fn}.js.src already exists, not overwriting" else diff --git a/bin/jsunshrink.sh b/bin/jsunshrink.sh index 9d7755092..ef1bb47a1 100755 --- a/bin/jsunshrink.sh +++ b/bin/jsunshrink.sh @@ -6,7 +6,7 @@ if [ ! -d "$JS_DIR" ]; then exit 1 fi -for fn in app common googiespell list; do +for fn in app common googiespell list treelist; do if [ -r "$JS_DIR/${fn}.js.src" ]; then mv "$JS_DIR/${fn}.js.src" "$JS_DIR/${fn}.js" echo "Reverted $JS_DIR/${fn}.js" 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 be952cc2f..05956b933 100755 --- a/bin/update.sh +++ b/bin/update.sh @@ -32,9 +32,11 @@ if (!$opts['version']) { echo "What version are you upgrading from? Type '?' if you don't know.\n"; if (($input = trim(fgets(STDIN))) && preg_match('/^[0-9.]+[a-z-]*$/', $input)) $opts['version'] = $input; + else + $opts['version'] = RCMAIL_VERSION; } -if ($opts['version'] && version_compare(version_parse($opts['version']), version_parse(RCMAIL_VERSION), '>')) +if ($opts['version'] && version_compare(version_parse($opts['version']), version_parse(RCMAIL_VERSION), '>=')) die("Nothing to be done here. Bye!\n"); 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 4b922ea83..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,19 +48,18 @@ $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) -if (in_array('system', (array)$DB->list_tables())) { +if (in_array($DB->table_name('system'), (array)$DB->list_tables())) { $DB->query("SELECT " . $DB->quote_identifier('value') ." FROM " . $DB->quote_identifier($DB->table_name('system')) ." WHERE " . $DB->quote_identifier('name') ." = ?", $opts['package'] . '-version'); $row = $DB->fetch_array(); - $version = $row[0]; + $version = preg_replace('/[^0-9]/', '', $row[0]); } // DB version not found, but release version is specified @@ -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) { @@ -150,7 +147,7 @@ function update_db_schema($package, $version, $file) $sql .= $line . "\n"; if (preg_match('/(;|^GO)$/', trim($line))) { - @$DB->query($sql); + @$DB->query(fix_table_names($sql)); $sql = ''; if ($error = $DB->is_error()) { return $error; @@ -181,4 +178,51 @@ function update_db_schema($package, $version, $file) return $DB->is_error(); } +function fix_table_names($sql) +{ + 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); + + // 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; +} + ?> |