diff options
Diffstat (limited to 'bin')
-rwxr-xr-x | bin/deluser.sh | 103 | ||||
-rwxr-xr-x | bin/installto.sh | 2 | ||||
-rwxr-xr-x | bin/makedoc.sh | 10 | ||||
-rwxr-xr-x | bin/msgexport.sh | 2 | ||||
-rwxr-xr-x | bin/transifexpull.sh | 6 | ||||
-rwxr-xr-x | bin/update.sh | 9 | ||||
-rwxr-xr-x | bin/updatedb.sh | 66 |
7 files changed, 124 insertions, 74 deletions
diff --git a/bin/deluser.sh b/bin/deluser.sh new file mode 100755 index 000000000..f12ec9032 --- /dev/null +++ b/bin/deluser.sh @@ -0,0 +1,103 @@ +#!/usr/bin/env php +<?php + +/* + +-----------------------------------------------------------------------+ + | bin/deluser.sh | + | | + | This file is part of the Roundcube Webmail client | + | Copyright (C) 2014, 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: | + | Utility script to remove all data related to a certain user | + | from the local database. | + +-----------------------------------------------------------------------+ + | Author: Thomas Bruederli <thomas@roundcube.net> | + +-----------------------------------------------------------------------+ +*/ + +define('INSTALL_PATH', realpath(dirname(__FILE__) . '/..') . '/' ); + +require_once INSTALL_PATH . 'program/include/clisetup.php'; + +function print_usage() +{ + print "Usage: deluser.sh [--host=mail_host] username\n"; + print "--host=HOST The IMAP hostname or IP the given user is related to\n"; +} + +function _die($msg, $usage=false) +{ + fputs(STDERR, $msg . "\n"); + if ($usage) print_usage(); + exit(1); +} + +$rcmail = rcmail::get_instance(); + +// get arguments +$args = rcube_utils::get_opt(array('h' => 'host')); +$username = trim($args[0]); + +if (empty($username)) { + _die("Missing required parameters", true); +} + +if (empty($args['host'])) { + $hosts = $rcmail->config->get('default_host', ''); + if (is_string($hosts)) { + $args['host'] = $hosts; + } + else if (is_array($hosts) && count($hosts) == 1) { + $args['host'] = reset($hosts); + } + else { + _die("Specify a host name", true); + } + + // host can be a URL like tls://192.168.12.44 + $host_url = parse_url($args['host']); + if ($host_url['host']) { + $args['host'] = $host_url['host']; + } +} + +// connect to DB +$db = $rcmail->get_dbh(); +$db->db_connect('w'); + +if (!$db->is_connected() || $db->is_error()) { + _die("No DB connection\n" . $db->is_error()); +} + +// find user in loca database +$user = rcube_user::query($username, $args['host']); + +if (!$user) { + die("User not found.\n"); +} + +// let plugins cleanup their own user-related data +$plugin = $rcmail->plugins->exec_hook('user_delete', array('user' => $user, 'username' => $username, 'host' => $args['host'])); + +if ($plugin['abort']) { + _die("User deletion aborted by plugin"); +} + +// deleting the user record should be sufficient due to ON DELETE CASCADE foreign key references +// but not all database backends actually support this so let's do it by hand +foreach (array('identities','contacts','contactgroups','dictionaries','cache','cache_index','cache_messages','cache_thread','searches','users') as $table) { + $db->query('DELETE FROM ' . $db->table_name($table) . ' WHERE user_id=?', $user->ID); +} + +if ($db->is_error()) { + _die("DB error occurred: " . $db->is_error()); +} +else { + echo "Successfully deleted user $user->ID\n"; +} + diff --git a/bin/installto.sh b/bin/installto.sh index 269a5dc06..fbd951bdf 100755 --- a/bin/installto.sh +++ b/bin/installto.sh @@ -71,7 +71,7 @@ if (strtolower($input) == 'y') { if (!$err) { echo "Running update script at target...\n"; - system("cd $target_dir && bin/update.sh --version=$oldversion"); + system("cd $target_dir && php bin/update.sh --version=$oldversion"); echo "All done.\n"; } } diff --git a/bin/makedoc.sh b/bin/makedoc.sh index 2a34254cb..3602c3a65 100755 --- a/bin/makedoc.sh +++ b/bin/makedoc.sh @@ -1,7 +1,7 @@ #!/bin/sh TITLE="Roundcube Webmail" -PACKAGES="Core" +PACKAGES="Webmail" INSTALL_PATH="`dirname $0`/.." PATH_PROJECT=$INSTALL_PATH/program/include @@ -16,11 +16,9 @@ then fi OUTPUTFORMAT=HTML -CONVERTER=frames -TEMPLATE=earthli -PRIVATE=off +TEMPLATE=responsive-twig # make documentation -$BIN_PHPDOC -d $PATH_PROJECT,$PATH_FRAMEWORK -t $PATH_DOCS -ti "$TITLE" -dn $PACKAGES \ --o $OUTPUTFORMAT:$CONVERTER:$TEMPLATE -pp $PRIVATE +$BIN_PHPDOC -d $PATH_PROJECT,$PATH_FRAMEWORK -t $PATH_DOCS --title "$TITLE" --defaultpackagename $PACKAGES \ + --template=$TEMPLATE diff --git a/bin/msgexport.sh b/bin/msgexport.sh index e98e5fee2..f68688b67 100755 --- a/bin/msgexport.sh +++ b/bin/msgexport.sh @@ -58,7 +58,7 @@ function export_mailbox($mbox, $filename) $from = current(rcube_mime::decode_address_list($headers->from, 1, false)); fwrite($out, sprintf("From %s %s UID %d\n", $from['mailto'], $headers->date, $headers->uid)); - fwrite($out, $IMAP->print_raw_body($headers->uid)); + $IMAP->get_raw_body($headers->uid, $out); fwrite($out, "\n\n\n"); progress_update($i+1, $count); diff --git a/bin/transifexpull.sh b/bin/transifexpull.sh index ba26a07f1..7415c02fd 100755 --- a/bin/transifexpull.sh +++ b/bin/transifexpull.sh @@ -36,3 +36,9 @@ done for file in $PWD/../plugins/*/localization/*.inc; do do_clean $file done + +# remove empty localization files +for file in $PWD/../program/localization/*/labels.inc; do grep -q -E '\$labels' $file || rm $file; done +for file in $PWD/../program/localization/*/messages.inc; do grep -q -E '\$messages' $file || rm $file; done +for file in $PWD/../plugins/*/localization/*.inc; do grep -q -E '\$(labels|messages)' $file || rm $file; done + diff --git a/bin/update.sh b/bin/update.sh index 8bfb9d603..91af6413d 100755 --- a/bin/update.sh +++ b/bin/update.sh @@ -22,7 +22,6 @@ define('INSTALL_PATH', realpath(dirname(__FILE__) . '/..') . '/' ); 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', 'y' => 'accept')); @@ -36,7 +35,7 @@ if (!$opts['version']) { $opts['version'] = RCMAIL_VERSION; } -$RCI = rcube_install::get_instance(); +$RCI = rcmail_install::get_instance(); $RCI->load_config(); if ($RCI->configured) { @@ -147,7 +146,7 @@ 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"; + echo "Please check the 'mime_magic' config option or the finfo functions of PHP and run this script again.\n"; } if ($RCI->check_mime_extensions()) { echo "WARNING: Mimetype to file extension mapping doesn't work properly!\n"; @@ -157,7 +156,7 @@ if ($RCI->configured) { // check database schema if ($RCI->config['db_dsnw']) { echo "Executing database schema update.\n"; - system(INSTALL_PATH . "bin/updatedb.sh --package=roundcube --version=" . $opts['version'] + system("php " . INSTALL_PATH . "bin/updatedb.sh --package=roundcube --version=" . $opts['version'] . " --dir=" . INSTALL_PATH . DIRECTORY_SEPARATOR . "SQL", $res); $success = !$res; @@ -165,7 +164,7 @@ if ($RCI->configured) { // index contacts for fulltext searching if ($opts['version'] && version_compare(version_parse($opts['version']), '0.6.0', '<')) { - system(INSTALL_PATH . 'bin/indexcontacts.sh'); + system("php " . INSTALL_PATH . 'bin/indexcontacts.sh'); } if ($success) { diff --git a/bin/updatedb.sh b/bin/updatedb.sh index 1f5e18434..daee6e835 100755 --- a/bin/updatedb.sh +++ b/bin/updatedb.sh @@ -45,6 +45,8 @@ if (!file_exists($opts['dir'])) { $RC = rcube::get_instance(); $DB = rcube_db::factory($RC->config->get('db_dsnw')); +$DB->set_debug((bool)$RC->config->get('sql_debug')); + // Connect to database $DB->db_connect('w'); if (!$DB->is_connected()) { @@ -146,20 +148,9 @@ function update_db_schema($package, $version, $file) global $DB; // read DDL file - if ($lines = file($file)) { - $sql = ''; - foreach ($lines as $line) { - if (preg_match('/^--/', $line) || trim($line) == '') - continue; - - $sql .= $line . "\n"; - if (preg_match('/(;|^GO)$/', trim($line))) { - @$DB->query(fix_table_names($sql)); - $sql = ''; - if ($error = $DB->is_error()) { - return $error; - } - } + if ($sql = file_get_contents($file)) { + if (!$DB->exec_script($sql)) { + return $DB->is_error(); } } @@ -185,51 +176,4 @@ 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; -} - ?> |