Changeset 76 in subversion


Ignore:
Timestamp:
Nov 6, 2005 2:26:45 PM (8 years ago)
Author:
roundcube
Message:

Added localized messages to client and check form input

Location:
trunk/roundcubemail
Files:
18 edited

Legend:

Unmodified
Added
Removed
  • trunk/roundcubemail/CHANGELOG

    r75 r76  
    6161 
    6262 
    63 2005/11/02 
     632005/11/06 
    6464---------- 
    6565- Added Finnish, Romanian and Chinese translation 
     
    7272- Added more XSS protection (Bug #1308236) 
    7373- Added tab indexes for compose form 
    74  
     74- Added 'changed' col to contacts table 
     75- Support for 160-bit session hashes 
     76- Added input check for contacts and identities (Patch #1346523) 
     77- Added messages/warning to compose step (Patch #1323895) 
  • trunk/roundcubemail/INSTALL

    r67 r76  
    44 
    551. Decompress and put this folder somewhere inside your document root 
    6 2. Make sure that the following directories are writable by the webserver 
     62. Make sure that the following directories (and the files within) 
     7   are writable by the webserver 
    78   - /temp 
    89   - /logs 
    9 3. Create a new database and a database user for RoundCube 
     103. Create a new database and a database user for RoundCube (see DATABASE SETUP) 
    10114. Create database tables using the queries in file 'SQL/*.initial.sql' 
     12   (* stands for your database type) 
    11135. Rename the files config/*.inc.php.dist to config/*.inc.php 
    12146. Modify the files in config/* to suit your local environment 
    13157. Done! 
     16 
     17 
     18DATABASE SETUP 
     19============== 
     20 
     21* MySQL 
     22------- 
     23Setting up the mysql database can be done by creating an empty database, 
     24importing the table layout and granting the proper permissions to the 
     25roundcube user. Here is an example of that procedure: 
     26 
     27# mysql 
     28> create database 'roundcubemail'; 
     29> GRANT ALL PRIVILEGES ON roundcubemail.* TO roundcube@localhost 
     30        IDENTIFIED BY 'password'; 
     31> quit 
     32# mysql roundcubemail < SQL/mysql.initial.sql 
     33 
     34* SQLite 
     35-------- 
     36Sqlite requires specifically php5 (sqlite in php4 currently doesn't 
     37work with roundcube), and you need sqlite 2 (preferably 2.8) to setup 
     38the sqlite db (sqlite 3.x also doesn't work at the moment). Here is 
     39an example how you can setup the sqlite.db for roundcube: 
     40 
     41# sqlite -init SQL/sqlite.initial.sql sqlite.db 
     42 
     43Make sure your configuration points to the sqlite.db file and that the 
     44webserver can write to the file. 
    1445 
    1546 
  • trunk/roundcubemail/program/include/main.inc

    r71 r76  
    249249  else 
    250250    rcmail_set_locale($sess_user_lang); 
     251   
     252  // add some basic label to client 
     253  rcube_add_label('loading'); 
    251254  }   
    252255 
     
    402405 
    403406 
     407// overwrite action variable   
     408function rcmail_overwrite_action($action) 
     409  { 
     410  global $OUTPUT, $JS_OBJECT_NAME; 
     411  $GLOBALS['_action'] = $action; 
     412 
     413  $OUTPUT->add_script(sprintf("\n%s.set_env('action', '%s');", $JS_OBJECT_NAME, $action));   
     414  } 
     415 
     416 
    404417function show_message($message, $type='notice') 
    405418  { 
     
    488501 
    489502  return $sa_languages; 
     503  } 
     504 
     505 
     506// add a localized label to the client environment 
     507function rcube_add_label() 
     508  { 
     509  global $OUTPUT, $JS_OBJECT_NAME; 
     510   
     511  $arg_list = func_get_args(); 
     512  foreach ($arg_list as $i => $name) 
     513    $OUTPUT->add_script(sprintf("%s.add_label('%s', '%s');", 
     514                                $JS_OBJECT_NAME, 
     515                                $name, 
     516                                rep_specialchars_output(rcube_label($name), 'js')));   
    490517  } 
    491518 
  • trunk/roundcubemail/program/include/rcube_db.inc

    r70 r76  
    221221    } 
    222222 
    223         function quoteIdentifier ( $str ) 
     223 
     224    function quote($input, $type=null) 
     225    { 
     226                if (!$this->db_handle) 
     227                        $this->db_connect('r'); 
     228 
     229                return $this->db_handle->quote($input); 
     230    } 
     231     
     232 
     233        function quoteIdentifier($str) 
    224234        { 
    225235                if (!$this->db_handle) 
     
    228238                return $this->db_handle->quoteIdentifier($str); 
    229239        } 
     240         
     241        function quote_identifier($str) 
     242        { 
     243                return $this->quoteIdentifier($str); 
     244        } 
     245 
    230246         
    231247        function unixtimestamp($field) 
  • trunk/roundcubemail/program/include/rcube_mdb2.inc

    r71 r76  
    103103 
    104104    // Query database 
    105      
    106105    function query() 
    107  
    108     { 
    109  
     106    { 
    110107                $params = func_get_args(); 
    111  
    112108                $query = array_shift($params); 
    113109 
    114                  
    115  
    116110                return $this->_query($query, 0, 0, $params); 
    117  
    118     } 
    119  
    120     
     111    } 
     112 
    121113 
    122114        function limitquery() 
    123  
    124115    { 
    125116 
    126117                $params = func_get_args(); 
    127  
    128118                $query = array_shift($params); 
    129  
    130119                $offset = array_shift($params); 
    131  
    132120                $numrows = array_shift($params); 
    133121 
    134                  
    135  
    136122                return $this->_query($query, $offset, $numrows, $params); 
    137  
    138123    } 
    139124     
     
    169154    } 
    170155 
     156 
    171157    function num_rows($res_id=NULL) 
    172158    { 
     
    182168    } 
    183169 
     170 
    184171    function affected_rows($res_id=NULL) 
    185172    { 
     
    189176        return $this->db_handle->affectedRows(); 
    190177    } 
     178 
    191179 
    192180    function insert_id($sequence = '') 
     
    213201    } 
    214202 
    215         function quoteIdentifier ( $str ) 
    216  
     203 
     204    function quote($input, $type=null) 
     205    { 
     206                if (!$this->db_handle) 
     207                        $this->db_connect('r'); 
     208 
     209                return $this->db_handle->quote($input, $type); 
     210    } 
     211 
     212 
     213        function quoteIdentifier($str) 
    217214        { 
    218  
    219215                if (!$this->db_handle) 
    220  
    221216                        $this->db_connect('r'); 
    222217 
    223                          
    224  
    225218                return $this->db_handle->quoteIdentifier($str); 
    226  
    227219        } 
    228          
     220 
     221        function quote_identifier($str) 
     222        { 
     223                return $this->quoteIdentifier($str); 
     224        } 
     225 
     226 
    229227        function unixtimestamp($field) 
    230  
    231228        { 
    232  
    233229                switch($this->db_provider) 
    234  
    235230                        { 
    236  
    237231                        case 'pgsql': 
    238  
    239232                                return "EXTRACT (EPOCH FROM $field)"; 
    240  
    241233                                break; 
    242234 
    243235                        default: 
    244  
    245236                                return "UNIX_TIMESTAMP($field)"; 
    246  
    247237                        } 
    248  
    249238        } 
    250          
     239 
     240 
    251241    function _add_result($res, $query) 
    252242    { 
  • trunk/roundcubemail/program/js/app.js

    r73 r76  
    77 | Licensed under the GNU GPL                                            | 
    88 |                                                                       | 
    9  | Modified: 2005/11/01 (roundcube)                                      | 
     9 | Modified: 2005/11/06 (roundcube)                                      | 
    1010 |                                                                       | 
    1111 +-----------------------------------------------------------------------+ 
     
    2020  { 
    2121  this.env = new Object(); 
     22  this.labels = new Object(); 
    2223  this.buttons = new Object(); 
    2324  this.gui_objects = new Object(); 
     
    4950      this.env[name] = value;     
    5051    }; 
     52 
     53 
     54  // add a localized label to the client environment 
     55  this.add_label = function(key, value) 
     56    { 
     57    this.labels[key] = value; 
     58    }; 
     59 
    5160 
    5261  // add a button to the button list 
     
    514523      case 'save': 
    515524        if (this.gui_objects.editform) 
     525          { 
     526          var input_pagesize = rcube_find_object('_pagesize'); 
     527          var input_name  = rcube_find_object('_name'); 
     528          var input_email = rcube_find_object('_email'); 
     529 
     530          // user prefs 
     531          if (input_pagesize && input_pagesize.value == '') 
     532            { 
     533            alert(this.get_label('nopagesizewarning')); 
     534            input_pagesize.focus(); 
     535            break; 
     536            } 
     537          // contacts/identities 
     538          else 
     539            { 
     540            if (input_name && input_name.value == '') 
     541              { 
     542              alert(this.get_label('nonamewarning')); 
     543              input_name.focus(); 
     544              break; 
     545              } 
     546            else if (input_email && !rcube_check_email(input_email.value)) 
     547              { 
     548              alert(this.get_label('noemailwarning')); 
     549              input_email.focus(); 
     550              break; 
     551              } 
     552            } 
     553 
    516554          this.gui_objects.editform.submit(); 
     555          } 
    517556        break; 
    518557 
     
    640679        var input_subject = rcube_find_object('_subject'); 
    641680        var input_message = rcube_find_object('_message'); 
    642          
    643         if (input_to.value!='' && input_message.value!='') 
     681 
     682        // check for empty recipient 
     683        if (input_to && !rcube_check_email(input_to.value, true)) 
    644684          { 
    645           this.set_busy(true, 'sendingmessage'); 
    646           var form = this.gui_objects.messageform; 
    647           form.submit(); 
     685          alert(this.get_label('norecipientwarning')); 
     686          input_to.focus(); 
     687          break; 
    648688          } 
    649            
     689 
     690        // display localized warning for missing subject 
     691        if (input_subject && input_subject.value == '') 
     692          { 
     693          var subject = prompt(this.get_label('nosubjectwarning'), this.get_label('nosubject')); 
     694 
     695          // user hit cancel, so don't send 
     696          if (!subject && subject !== '') 
     697            { 
     698            input_subject.focus(); 
     699            break; 
     700            } 
     701          else 
     702            { 
     703            input_subject.value = subject ? subject : this.get_label('nosubject');             
     704            } 
     705          } 
     706 
     707        // check for empty body 
     708        if (input_message.value=='') 
     709          { 
     710          if (!confirm(this.get_label('nobodywarning'))) 
     711            { 
     712            input_message.focus(); 
     713            break; 
     714            } 
     715          } 
     716 
     717        // all checks passed, send message 
     718        this.set_busy(true, 'sendingmessage'); 
     719        var form = this.gui_objects.messageform; 
     720        form.submit(); 
    650721        break; 
    651722 
     
    761832    { 
    762833    if (a && message) 
    763       this.display_message('Loading...', 'loading', true); 
     834      { 
     835      var msg = this.get_label(message); 
     836      if (msg==message)         
     837        msg = 'Loading...'; 
     838 
     839      this.display_message(msg, 'loading', true); 
     840      } 
    764841    else if (!a && this.busy) 
    765842      this.hide_message(); 
     
    781858 
    782859 
     860  // return a localized string 
     861  this.get_label = function(name) 
     862    { 
     863    if (this.labels[name]) 
     864      return this.labels[name]; 
     865    else 
     866      return name; 
     867    }; 
     868 
     869 
     870  // switch to another application task 
    783871  this.switch_task = function(task) 
    784872    { 
  • trunk/roundcubemail/program/js/common.js

    r50 r76  
    77 | Licensed under the GNU GPL                                            | 
    88 |                                                                       | 
    9  | Modified:2005/10/21 (roundcube)                                       | 
     9 | Modified:2005/11/06 (roundcube)                                       | 
    1010 |                                                                       | 
    1111 +-----------------------------------------------------------------------+ 
     
    265265 
    266266 
     267// check if input is a valid email address 
     268function rcube_check_email(input, inline) 
     269  { 
     270  if (input && window.RegExp) 
     271    { 
     272    var reg_str = '([a-z0-9][-a-z0-9\.\+_]*)\@([a-z0-9]([-a-z0-9][\.]?)*[a-z0-9]\.[a-z]{2,9})'; 
     273    var reg1 = inline ? new RegExp(reg_str, 'i') : new RegExp('^'+reg_str+'$', 'i'); 
     274    var reg2 = /[\._\-\@]{2}/; 
     275    return reg1.test(input) && !reg2.test(input) ? true : false; 
     276    } 
     277  return false; 
     278  } 
     279   
    267280 
    268281// find a value in a specific array and returns the index 
  • trunk/roundcubemail/program/localization/de/labels.inc

    r62 r76  
    120120$labels['highest'] = 'Höchste'; 
    121121 
     122$labels['nosubject']  = '(kein Betreff)'; 
     123 
    122124$labels['showimages'] = 'Bilder anzeigen'; 
    123125 
  • trunk/roundcubemail/program/localization/de/messages.inc

    r50 r76  
    3333$messages['mailboxempty'] = 'Ordner ist leer'; 
    3434 
    35 $messages['loadingdata'] = 'Daten werden geladen...'; 
     35$messages['loading'] = $messages['loadingdata'] = 'Daten werden geladen...'; 
     36 
     37$messages['sendingmessage'] = 'Nachricht wird gesendet...'; 
    3638 
    3739$messages['messagesent'] = 'Nachricht erfolgreich gesendet'; 
     
    5355$messages['errorsaving'] = 'Beim Speichern ist ein Fehler aufgetreten'; 
    5456 
     57$messages['formincomplete']    = 'Das Formular wurde nicht vollständig ausgefüllt'; 
     58 
     59$messages['noemailwarning']    = 'Bitte geben Sie eine gültige E-Mail-Adresse ein'; 
     60 
     61$messages['nonamewarning']     = 'Bitte geben Sie einen Namen ein'; 
     62 
     63$messages['nopagesizewarning'] = 'Bitte geben Sie eine Einträge pro Seite ein'; 
     64 
     65$messages['norecipientwarning'] = 'Bitte geben Sie mindestens einen Empfänger an'; 
     66 
     67$messages['nosubjectwarning']  = 'Die Betreffzeile ist leer. Möchten Sie jetzt einen Betreff eingeben?'; 
     68 
     69$messages['nobodywarning'] = 'Diese Nachricht ohne Inhalt senden?'; 
    5570 
    5671?> 
  • trunk/roundcubemail/program/localization/en/labels.inc

    r62 r76  
    120120$labels['highest'] = 'Highest'; 
    121121 
     122$labels['nosubject']  = '(no subject)'; 
     123 
    122124$labels['showimages'] = 'Display images'; 
    123125 
  • trunk/roundcubemail/program/localization/en/messages.inc

    r26 r76  
    3333$messages['mailboxempty'] = 'Mailbox is empty'; 
    3434 
     35$messages['loading'] = 'Loading...'; 
     36 
    3537$messages['loadingdata'] = 'Loading data...'; 
     38 
     39$messages['sendingmessage'] = 'Sending message...'; 
    3640 
    3741$messages['messagesent'] = 'Message sent successfully'; 
     
    5761$messages['errordeleting'] = 'Could not delete the message'; 
    5862 
     63$messages['errordeleting'] = 'Could not delete the message'; 
     64 
     65$messages['formincomplete']    = 'The form was not completely filled out'; 
     66 
     67$messages['noemailwarning']    = 'Please enter a valid email address'; 
     68 
     69$messages['nonamewarning']     = 'Please enter a name'; 
     70 
     71$messages['nopagesizewarning'] = 'Please enter a page size'; 
     72 
     73$messages['norecipientwarning'] = 'Please enter at least one recipient'; 
     74 
     75$messages['nosubjectwarning']  = 'The "Subject" field is empty. Would you like to enter one now?'; 
     76 
     77$messages['nobodywarning'] = 'Send this message without text?'; 
     78 
    5979 
    6080?> 
  • trunk/roundcubemail/program/steps/addressbook/edit.inc

    r58 r76  
    3232   
    3333  $CONTACT_RECORD = $DB->fetch_assoc(); 
    34    
     34 
    3535  if (is_array($CONTACT_RECORD)) 
    3636    $OUTPUT->add_script(sprintf("%s.set_env('cid', '%s');", $JS_OBJECT_NAME, $CONTACT_RECORD['contact_id'])); 
     
    4545  if (!$CONTACT_RECORD && $GLOBALS['_action']!='add') 
    4646    return rcube_label('contactnotfound'); 
     47 
     48  // add some labels to client 
     49  rcube_add_label('noemailwarning'); 
     50  rcube_add_label('nonamewarning'); 
    4751 
    4852  list($form_start, $form_end) = get_form_tags($attrib); 
  • trunk/roundcubemail/program/steps/addressbook/save.inc

    r75 r76  
    2424 
    2525 
     26// check input 
     27if (empty($_POST['_name']) || empty($_POST['_email'])) 
     28  { 
     29  show_message('formincomplete', 'warning'); 
     30  rcmail_overwrite_action($_POST['_cid'] ? 'show' : 'add'); 
     31  return; 
     32  } 
     33 
     34 
    2635// update an existing contact 
    2736if ($_POST['_cid']) 
     
    3544      continue; 
    3645     
    37     $a_write_sql[] = sprintf("%s='%s'", $col, addslashes(strip_tags($_POST[$fname]))); 
     46    $a_write_sql[] = sprintf("%s=%s", $DB->quoteIdentifier($col), $DB->quote(strip_tags($_POST[$fname]))); 
    3847    } 
    3948 
     
    8897    // show error message 
    8998    show_message('errorsaving', 'error'); 
    90     $_action = 'show'; 
     99    rcmail_overwrite_action('show'); 
    91100    } 
    92101  } 
     
    96105  { 
    97106  $a_insert_cols = $a_insert_values = array(); 
     107   
     108  // check for existing contacts 
     109  $sql_result = $DB->query("SELECT 1 FROM ".get_table_name('contacts')." 
     110                            WHERE  user_id=? 
     111                            AND    email=? 
     112                            AND    del<>'1'", 
     113                           $_SESSION['user_id'], 
     114                           $_POST['_email']); 
     115 
     116  // show warning message 
     117  if ($DB->num_rows($sql_result)) 
     118    { 
     119    show_message('contactexists', 'warning'); 
     120    $_action = 'add'; 
     121    return; 
     122    } 
    98123 
    99124  foreach ($a_save_cols as $col) 
     
    104129     
    105130    $a_insert_cols[] = $col; 
    106     $a_insert_values[] = sprintf("'%s'", addslashes(strip_tags($_POST[$fname]))); 
     131    $a_insert_values[] = $DB->quote(strip_tags($_POST[$fname])); 
    107132    } 
    108133     
     
    110135    { 
    111136    $DB->query("INSERT INTO ".get_table_name('contacts')." 
    112                 (user_id, changedm ".join(', ', $a_insert_cols).") 
     137                (user_id, changed, ".join(', ', $a_insert_cols).") 
    113138                VALUES (?, now(), ".join(', ', $a_insert_values).")", 
    114139                $_SESSION['user_id']); 
     
    154179    // show error message 
    155180    show_message('errorsaving', 'error'); 
    156     $_action = 'add'; 
     181    rcmail_overwrite_action('add'); 
    157182    } 
    158183  } 
  • trunk/roundcubemail/program/steps/mail/compose.inc

    r74 r76  
    3131if (!is_array($_SESSION['compose'])) 
    3232  $_SESSION['compose'] = array('id' => uniqid(rand())); 
     33 
     34 
     35// add some labels to client 
     36rcube_add_label('nosubject', 'norecipientwarning', 'nosubjectwarning', 'nobodywarning', 'sendingmessage'); 
    3337 
    3438 
  • trunk/roundcubemail/program/steps/mail/sendmail.inc

    r73 r76  
    2929if (!isset($_SESSION['compose']['id'])) 
    3030  { 
    31   $_action = 'list'; 
     31  rcmail_overwrite_action('list'); 
    3232  return; 
    3333  } 
     
    6666 
    6767 
     68if (empty($_POST['_to']) && empty($_POST['_subject']) && $_POST['_message']) 
     69  { 
     70  show_message("sendingfailed", 'error');  
     71  rcmail_overwrite_action('compose'); 
     72  return; 
     73  } 
     74 
     75 
    6876$mailto_regexp = array('/,\s*[\r\n]+/', '/[\r\n]+/', '/,\s*$/m'); 
    6977$mailto_replace = array(' ', ', ', ''); 
     
    207215if (!$sent) 
    208216  { 
    209   $_action = 'compose'; 
    210   $OUTPUT->add_script(sprintf("\n%s.set_env('action', '%s');", $JS_OBJECT_NAME, $_action)); 
    211217  show_message("sendingfailed", 'error');  
     218  rcmail_overwrite_action('compose'); 
    212219  return; 
    213220  } 
  • trunk/roundcubemail/program/steps/settings/edit_identity.inc

    r58 r76  
    4848  if (!$IDENTITY_RECORD && $GLOBALS['_action']!='add-identity') 
    4949    return rcube_label('notfound'); 
     50 
     51  // add some labels to client 
     52  rcube_add_label('noemailwarning'); 
     53  rcube_add_label('nonamewarning'); 
     54 
    5055 
    5156  list($form_start, $form_end) = get_form_tags($attrib, 'save-identity', array('name' => '_iid', 'value' => $IDENTITY_RECORD['identity_id'])); 
  • trunk/roundcubemail/program/steps/settings/func.inc

    r58 r76  
    3535  global $DB, $CONFIG, $sess_user_lang; 
    3636 
     37  // add some labels to client 
     38  rcube_add_label('nopagesizewarning'); 
     39   
    3740  list($form_start, $form_end) = get_form_tags($attrib, 'save-prefs'); 
    3841  unset($attrib['form']); 
  • trunk/roundcubemail/program/steps/settings/save_identity.inc

    r69 r76  
    2323 
    2424 
     25// check input 
     26if (empty($_POST['_name']) || empty($_POST['_email'])) 
     27  { 
     28  show_message('formincomplete', 'warning'); 
     29  rcmail_overwrite_action('edit-identitiy'); 
     30  return; 
     31  } 
     32 
     33 
    2534// update an existing contact 
    2635if ($_POST['_iid']) 
     
    3443      continue; 
    3544 
    36     $a_write_sql[] = sprintf("`%s`='%s'", $col, addslashes(strip_tags($_POST[$fname]))); 
     45    $a_write_sql[] = sprintf("%s=%s", $DB->quoteIdentifier($col), $DB->quote(strip_tags($_POST[$fname]))); 
    3746    } 
    3847 
     
    5766    $DB->query("UPDATE ".get_table_name('identities')." 
    5867                SET ".$DB->quoteIdentifier('default')."='0' 
    59                 WHERE  identity_id!=? 
    60                 AND    user_id=? 
     68                WHERE  user_id=? 
     69                AND    identity_id<>? 
    6170                AND    del<>'1'", 
    62                 $_POST['_iid'], 
    63                 $_SESSION['user_id']); 
     71                $_SESSION['user_id'], 
     72                $_POST['_iid']); 
    6473     
    6574    if ($_POST['_framed']) 
     
    7281    { 
    7382    // show error message 
    74  
     83    show_message('errorsaving', 'error'); 
     84    rcmail_overwrite_action('edit-identitiy'); 
    7585    } 
    7686  } 
     
    8898     
    8999    $a_insert_cols[] = $DB->quoteIdentifier($col); 
    90     $a_insert_values[] = sprintf("'%s'", addslashes(strip_tags($_POST[$fname]))); 
     100    $a_insert_values[] = $DB->quote(strip_tags($_POST[$fname])); 
    91101    } 
    92102     
     
    114124    { 
    115125    // show error message 
     126    show_message('errorsaving', 'error'); 
     127    rcmail_overwrite_action('edit-identitiy'); 
    116128    } 
    117129  } 
     
    119131 
    120132// go to next step 
    121 if ($_POST['_framed']) 
    122   $_action = 'edit-identitiy'; 
    123 else 
    124   $_action = 'identities'; 
    125    
    126  
    127 // overwrite action variable   
    128 $OUTPUT->add_script(sprintf("\n%s.set_env('action', '%s');", $JS_OBJECT_NAME, $_action));   
     133rcmail_overwrite_action($_POST['_framed'] ? 'edit-identitiy' : 'identities'); 
    129134 
    130135?> 
Note: See TracChangeset for help on using the changeset viewer.