squirrelmail-webmail  1.4.22
About: SquirrelMail is a standards-based webmail package with strong MIME support, address books, and folder manipulation (written in PHP4).
  Fossies Dox: squirrelmail-webmail-1.4.22.tar.gz  ("inofficial" and yet experimental doxygen-generated source code documentation)  

sqspell_functions.php
Go to the documentation of this file.
1 <?php
28 function sqspell_makePage($title, $scriptsrc, $body){
29  global $color, $SQSPELL_VERSION;
30 
31  if (! sqgetGlobalVar('MOD', $MOD, SQ_GET) ) {
32  $MOD = 'options_main';
33  }
34 
35  displayPageHeader($color, 'None');
36  echo "&nbsp;<br />\n";
40  if($scriptsrc) {
41  echo "<script type=\"text/javascript\" src=\"js/$scriptsrc\"></script>\n";
42  }
43  echo html_tag( 'table', '', 'center', '', 'width="95%" border="0" cellpadding="2" cellspacing="0"' ) . "\n"
44  . html_tag( 'tr', "\n" .
45  html_tag( 'td', '<strong>' . $title .'</strong>', 'center', $color[9] )
46  ) . "\n"
47  . html_tag( 'tr', "\n" .
48  html_tag( 'td', '<hr />', 'left' )
49  ) . "\n"
50  . html_tag( 'tr', "\n" .
51  html_tag( 'td', $body, 'left' )
52  ) . "\n";
57  if ($MOD != "options_main"){
58  echo html_tag( 'tr', "\n" .
59  html_tag( 'td', '<hr />', 'left' )
60  ) . "\n"
61  . html_tag( 'tr', "\n" .
62  html_tag( 'td', '<a href="sqspell_options.php">'
63  . _("Back to &quot;SpellChecker Options&quot; page")
64  . '</a>',
65  'center' )
66  ) . "\n";
67  }
71  echo html_tag( 'tr', "\n" .
72  html_tag( 'td', '<hr />', 'left' )
73  ) . "\n"
74  . html_tag( 'tr',
75  html_tag( 'td', 'SquirrelSpell ' . $SQSPELL_VERSION, 'center', $color[9] )
76  ) . "\n</table>\n";
77  echo '</body></html>';
78 }
79 
95 function sqspell_makeWindow($onload, $title, $scriptsrc, $body){
96  global $color, $SQSPELL_VERSION;
97 
98  displayHtmlHeader($title,
99  ($scriptsrc ? "\n<script type=\"text/javascript\" src=\"js/$scriptsrc\"></script>\n" : ''));
100 
101  echo "<body text=\"$color[8]\" bgcolor=\"$color[4]\" link=\"$color[7]\" "
102  . "vlink=\"$color[7]\" alink=\"$color[7]\"";
106  if ($onload) {
107  echo " onload=\"$onload\"";
108  }
112  echo ">\n"
113  . html_tag( 'table', "\n" .
114  html_tag( 'tr', "\n" .
115  html_tag( 'td', '<strong>' . $title . '</strong>', 'center', $color[9] )
116  ) . "\n" .
117  html_tag( 'tr', "\n" .
118  html_tag( 'td', '<hr />', 'left' )
119  ) . "\n" .
120  html_tag( 'tr', "\n" .
121  html_tag( 'td', $body, 'left' )
122  ) . "\n" .
123  html_tag( 'tr', "\n" .
124  html_tag( 'td', '<hr />', 'left' )
125  ) . "\n" .
126  html_tag( 'tr', "\n" .
127  html_tag( 'td', 'SquirrelSpell ' . $SQSPELL_VERSION, 'center', $color[9] )
128  ) ,
129  '', '', 'width="100%" border="0" cellpadding="2"' )
130  . "</body>\n</html>\n";
131 }
132 
147 function sqspell_crypto($mode, $ckey, $input){
152  if (!function_exists('mcrypt_generic')) {
153  return 'PANIC';
154  }
158  $td = mcrypt_module_open(MCRYPT_Blowfish, "", MCRYPT_MODE_ECB, "");
159  $iv = mcrypt_create_iv(mcrypt_enc_get_iv_size ($td), MCRYPT_RAND);
160  mcrypt_generic_init($td, $ckey, $iv);
166  switch ($mode){
167  case 'encrypt':
168  $crypto = mcrypt_generic($td, $input);
169  break;
170  case 'decrypt':
171  $crypto = mdecrypt_generic($td, $input);
176  if (!strstr($crypto, "# SquirrelSpell")){
177  $crypto='PANIC';
178  }
179  break;
180  }
184  mcrypt_generic_deinit ($td);
185  mcrypt_module_close ($td);
186  return $crypto;
187 }
188 
200 function sqspell_upgradeWordsFile($words_string){
207  $new_words_string =
208  substr_replace($words_string,
209  "# SquirrelSpell User Dictionary $SQSPELL_VERSION\n# "
210  . "Last Revision: " . date("Y-m-d")
211  . "\n# LANG: $SQSPELL_APP_DEFAULT\n# $SQSPELL_APP_DEFAULT",
212  0, strpos($words_string, "\n")) . "# End\n";
213  sqspell_writeWords($new_words_string);
214  return $new_words_string;
215 }
216 
226 function sqspell_getSettings($words){
232  if (sizeof($SQSPELL_APP) > 1){
237  if(!$words){
238  $words=sqspell_getWords();
239  }
240  if ($words){
246  preg_match("/# LANG: (.*)/i", $words, $matches);
247  $langs=explode(", ", $matches[1]);
248  } else {
253  $langs[0]=$SQSPELL_APP_DEFAULT;
254  }
255  } else {
260  $langs[0]=$SQSPELL_APP_DEFAULT;
261  }
262  return $langs;
263 }
264 
276 function sqspell_getLang($words, $lang){
277  $start=strpos($words, "# $lang\n");
283  if (!$start) return '';
289  $end=strpos($words, "#", $start+1);
290  $lang_words = substr($words, $start, $end-$start);
291  return $lang_words;
292 }
293 
304 function sqspell_getWords(){
306  $words="";
307  if (file_exists($SQSPELL_WORDS_FILE)){
311  $fp=fopen($SQSPELL_WORDS_FILE, 'r');
312  $words=fread($fp, filesize($SQSPELL_WORDS_FILE));
313  fclose($fp);
314  }
320  if ($words && !strstr($words, "# SquirrelSpell")){
329  sqgetGlobalVar('key', $key, SQ_COOKIE);
330  sqgetGlobalVar('onetimepad', $onetimepad, SQ_SESSION);
331 
332  sqgetGlobalVar('old_key', $old_key, SQ_POST);
333 
334  if ($old_key != '') {
335  $clear_key=$old_key;
336  } else {
340  $clear_key = OneTimePadDecrypt($key, $onetimepad);
341  }
345  $words=sqspell_crypto("decrypt", $clear_key, $words);
349  if ($words=="PANIC"){
359  $msg = html_tag( 'p', "\n" .
360  '<strong>' . _("ATTENTION:") . '</strong><br />'
361  . _("SquirrelSpell was unable to decrypt your personal dictionary. This is most likely due to the fact that you have changed your mailbox password. In order to proceed, you will have to supply your old password so that SquirrelSpell can decrypt your personal dictionary. It will be re-encrypted with your new password after this. If you haven't encrypted your dictionary, then it got mangled and is no longer valid. You will have to delete it and start anew. This is also true if you don't remember your old password -- without it, the encrypted data is no longer accessible.") ,
362  'left' ) . "\n"
363  . '<blockquote>' . "\n"
364  . '<form method="post" onsubmit="return AYS()">' . "\n"
365  . '<input type="hidden" name="MOD" value="crypto_badkey">' . "\n"
366  . html_tag( 'p', "\n" .
367  '<input type="checkbox" name="delete_words" value="ON">'
368  . _("Delete my dictionary and start a new one") . '<br />'
369  . _("Decrypt my dictionary with my old password:")
370  . '<input name="old_key" size=\"10\">' ,
371  'left' ) . "\n"
372  . '</blockquote>' . "\n"
373  . html_tag( 'p', "\n" .
374  '<input type="submit" value="'
375  . _("Proceed") . ' &gt;&gt;">' ,
376  'center' ) . "\n"
377  . '</form>' . "\n";
381  $msg .= "<script type='text/javascript'><!--\n"
382  . "var ui_choice = \"" . _("You must make a choice") ."\";\n"
383  . "var ui_candel = \"" . _("You can either delete your dictionary or type in the old password. Not both.") . "\";\n"
384  . "var ui_willdel = \"" . _("This will delete your personal dictionary file. Proceed?") . "\";\n"
385  . "//--></script>\n";
391  global $SCRIPT_NAME;
392  if (strstr($SCRIPT_NAME, "sqspell_options")){
393  sqspell_makePage(_("Error Decrypting Dictionary"),
394  "decrypt_error.js", $msg);
395  } else {
396  sqspell_makeWindow(null, _("Error Decrypting Dictionary"),
397  "decrypt_error.js", $msg);
398  }
399  exit;
400  } else {
405  $SQSPELL_CRYPTO=true;
406  }
407  } else {
412  $SQSPELL_CRYPTO=false;
413  }
418  if (strstr($words, "Dictionary v0.2")){
419  $words=sqspell_upgradeWordsFile($words);
420  }
421  return $words;
422 }
423 
431 function sqspell_writeWords($words){
437  if (!$words){
438  $words=sqspell_makeDummy();
439  }
440  if ($SQSPELL_CRYPTO){
445  sqgetGlobalVar('key', $key, SQ_COOKIE);
446  sqgetGlobalVar('onetimepad', $onetimepad, SQ_SESSION);
447 
448  $clear_key=OneTimePadDecrypt($key, $onetimepad);
452  $save_words = sqspell_crypto("encrypt", $clear_key, $words);
453  if ($save_words == 'PANIC'){
462  }
463  } else {
464  $save_words = $words;
465  }
469  $fp=fopen($SQSPELL_WORDS_FILE, "w");
470  fwrite($fp, $save_words);
471  fclose($fp);
472  chmod($SQSPELL_WORDS_FILE, 0600);
473 }
474 
482  global $SQSPELL_WORDS_FILE;
483  if (file_exists($SQSPELL_WORDS_FILE)){
484  unlink($SQSPELL_WORDS_FILE);
485  }
486 }
493 function sqspell_makeDummy(){
495  $words = "# SquirrelSpell User Dictionary $SQSPELL_VERSION\n"
496  . "# Last Revision: " . date('Y-m-d')
497  . "\n# LANG: $SQSPELL_APP_DEFAULT\n# End\n";
498  return $words;
499 }
500 
511 function sqspell_ckMOD($rMOD){
512  if (strstr($rMOD, '.')
513  || strstr($rMOD, '/')
514  || strstr($rMOD, '%')
515  || strstr($rMOD, "\\")){
516  echo _("Invalid URL");
517  exit;
518  }
519 }
520 
$body
if(isset($ldap_server) && $ldap_server[0] &&! extension_loaded('ldap')) $body
Definition: bug_report.php:106
sqspell_upgradeWordsFile
sqspell_upgradeWordsFile($words_string)
Definition: sqspell_functions.php:200
sqgetGlobalVar
sqgetGlobalVar($name, &$value, $search=SQ_INORDER)
Definition: global.php:344
$SQSPELL_APP
$SQSPELL_APP
Definition: sqspell_config.php:29
html_tag
html_tag( $tag, $val='', $align='', $bgcolor='', $xtra='')
Definition: html.php:27
SQ_SESSION
const SQ_SESSION
Definition: global.php:18
displayPageHeader
displayPageHeader($color, $mailbox, $xtra='', $session=false)
Definition: page_header.php:105
OneTimePadDecrypt
OneTimePadDecrypt($string, $epad)
Definition: strings.php:460
sqspell_ckMOD
sqspell_ckMOD($rMOD)
Definition: sqspell_functions.php:511
sqspell_makeWindow
sqspell_makeWindow($onload, $title, $scriptsrc, $body)
Definition: sqspell_functions.php:95
$end
$end
Definition: message_details_bottom.php:90
sqspell_writeWords
sqspell_writeWords($words)
Definition: sqspell_functions.php:431
sqspell_getSettings
sqspell_getSettings($words)
Definition: sqspell_functions.php:226
$SQSPELL_CRYPTO
$SQSPELL_CRYPTO
Definition: sqspell_interface.php:35
sqspell_makeDummy
sqspell_makeDummy()
Definition: sqspell_functions.php:493
SQ_GET
const SQ_GET
Definition: global.php:16
$SQSPELL_VERSION
$SQSPELL_VERSION
Definition: sqspell_functions.php:526
sqspell_getWords
sqspell_getWords()
Definition: sqspell_functions.php:304
$SQSPELL_WORDS_FILE
$SQSPELL_WORDS_FILE
Definition: sqspell_config.php:32
displayHtmlHeader
displayHtmlHeader( $title='SquirrelMail', $xtra='', $do_hook=TRUE)
Definition: page_header.php:21
SQ_POST
const SQ_POST
Definition: global.php:17
$SQSPELL_APP_DEFAULT
$SQSPELL_APP_DEFAULT
Definition: sqspell_config.php:31
exit
exit
Definition: help.php:128
_
_($str)
Definition: gettext.php:160
sqspell_makePage
sqspell_makePage($title, $scriptsrc, $body)
Definition: sqspell_functions.php:28
sqspell_crypto
sqspell_crypto($mode, $ckey, $input)
Definition: sqspell_functions.php:147
sqspell_deleteWords
sqspell_deleteWords()
Definition: sqspell_functions.php:475
$color
$color
Definition: load_prefs.php:28
sqspell_getLang
sqspell_getLang($words, $lang)
Definition: sqspell_functions.php:276
SQ_COOKIE
const SQ_COOKIE
Definition: global.php:19