source: subversion/trunk/roundcubemail/installer/rcube_install.php @ 5781

Last change on this file since 5781 was 5781, checked in by thomasb, 16 months ago

Merged devel-framework branch (r5746:5779) back into trunk

File size: 22.6 KB
Line 
1<?php
2
3/*
4 +-----------------------------------------------------------------------+
5 | rcube_install.php                                                     |
6 |                                                                       |
7 | This file is part of the Roundcube Webmail package                    |
8 | Copyright (C) 2008-2011, The Roundcube Dev Team                       |
9 | Licensed under the GNU Public License                                 |
10 +-----------------------------------------------------------------------+
11
12 $Id:  $
13
14*/
15
16
17/**
18 * Class to control the installation process of the Roundcube Webmail package
19 *
20 * @category Install
21 * @package  Roundcube
22 * @author Thomas Bruederli
23 */
24class rcube_install
25{
26  var $step;
27  var $is_post = false;
28  var $failures = 0;
29  var $config = array();
30  var $configured = false;
31  var $last_error = null;
32  var $db_map = array('pgsql' => 'postgres', 'mysqli' => 'mysql', 'sqlsrv' => 'mssql');
33  var $email_pattern = '([a-z0-9][a-z0-9\-\.\+\_]*@[a-z0-9]([a-z0-9\-][.]?)*[a-z0-9])';
34  var $bool_config_props = array();
35
36  var $obsolete_config = array('db_backend', 'double_auth');
37  var $replaced_config = array(
38    'skin_path' => 'skin',
39    'locale_string' => 'language',
40    'multiple_identities' => 'identities_level',
41    'addrbook_show_images' => 'show_images',
42    'imap_root' => 'imap_ns_personal',
43    'pagesize' => 'mail_pagesize',
44    'default_imap_folders' => 'default_folders',
45  );
46
47  // these config options are required for a working system
48  var $required_config = array(
49    'db_dsnw', 'db_table_contactgroups', 'db_table_contactgroupmembers',
50    'des_key', 'session_lifetime',
51  );
52
53  /**
54   * Constructor
55   */
56  function rcube_install()
57  {
58    $this->step = intval($_REQUEST['_step']);
59    $this->is_post = $_SERVER['REQUEST_METHOD'] == 'POST';
60  }
61 
62  /**
63   * Singleton getter
64   */
65  function get_instance()
66  {
67    static $inst;
68   
69    if (!$inst)
70      $inst = new rcube_install();
71   
72    return $inst;
73  }
74 
75  /**
76   * Read the default config files and store properties
77   */
78  function load_defaults()
79  {
80    $this->_load_config('.php.dist');
81  }
82
83
84  /**
85   * Read the local config files and store properties
86   */
87  function load_config()
88  {
89    $this->config = array();
90    $this->_load_config('.php');
91    $this->configured = !empty($this->config);
92  }
93
94  /**
95   * Read the default config file and store properties
96   * @access private
97   */
98  function _load_config($suffix)
99  {
100    if (is_readable($main_inc = RCMAIL_CONFIG_DIR . '/main.inc' . $suffix)) {
101      include($main_inc);
102      if (is_array($rcmail_config))
103        $this->config += $rcmail_config;
104    }
105    if (is_readable($db_inc = RCMAIL_CONFIG_DIR . '/db.inc'. $suffix)) {
106      include($db_inc);
107      if (is_array($rcmail_config))
108        $this->config += $rcmail_config;
109    }
110  }
111 
112 
113  /**
114   * Getter for a certain config property
115   *
116   * @param string Property name
117   * @param string Default value
118   * @return string The property value
119   */
120  function getprop($name, $default = '')
121  {
122    $value = $this->config[$name];
123   
124    if ($name == 'des_key' && !$this->configured && !isset($_REQUEST["_$name"]))
125      $value = rcube_install::random_key(24);
126   
127    return $value !== null && $value !== '' ? $value : $default;
128  }
129
130
131  /**
132   * Take the default config file and replace the parameters
133   * with the submitted form data
134   *
135   * @param string Which config file (either 'main' or 'db')
136   * @return string The complete config file content
137   */
138  function create_config($which, $force = false)
139  {
140    $out = @file_get_contents(RCMAIL_CONFIG_DIR . "/{$which}.inc.php.dist");
141
142    if (!$out)
143      return '[Warning: could not read the config template file]';
144
145    foreach ($this->config as $prop => $default) {
146
147      $is_default = !isset($_POST["_$prop"]);
148      $value      = !$is_default || $this->bool_config_props[$prop] ? $_POST["_$prop"] : $default;
149
150      // convert some form data
151      if ($prop == 'debug_level' && !$is_default) {
152        if (is_array($value)) {
153          $val = 0;
154          foreach ($value as $dbgval)
155            $val += intval($dbgval);
156          $value = $val;
157        }
158      }
159      else if ($which == 'db' && $prop == 'db_dsnw' && !empty($_POST['_dbtype'])) {
160        if ($_POST['_dbtype'] == 'sqlite')
161          $value = sprintf('%s://%s?mode=0646', $_POST['_dbtype'], $_POST['_dbname']{0} == '/' ? '/' . $_POST['_dbname'] : $_POST['_dbname']);
162        else if ($_POST['_dbtype'])
163          $value = sprintf('%s://%s:%s@%s/%s', $_POST['_dbtype'], 
164            rawurlencode($_POST['_dbuser']), rawurlencode($_POST['_dbpass']), $_POST['_dbhost'], $_POST['_dbname']);
165      }
166      else if ($prop == 'smtp_auth_type' && $value == '0') {
167        $value = '';
168      }
169      else if ($prop == 'default_host' && is_array($value)) {
170        $value = rcube_install::_clean_array($value);
171        if (count($value) <= 1)
172          $value = $value[0];
173      }
174      else if ($prop == 'mail_pagesize' || $prop == 'addressbook_pagesize') {
175        $value = max(2, intval($value));
176      }
177      else if ($prop == 'smtp_user' && !empty($_POST['_smtp_user_u'])) {
178        $value = '%u';
179      }
180      else if ($prop == 'smtp_pass' && !empty($_POST['_smtp_user_u'])) {
181        $value = '%p';
182      }
183      else if ($prop == 'default_folders') {
184            $value = array();
185            foreach ($this->config['default_folders'] as $_folder) {
186              switch ($_folder) {
187              case 'Drafts': $_folder = $this->config['drafts_mbox']; break;
188              case 'Sent':   $_folder = $this->config['sent_mbox']; break;
189              case 'Junk':   $_folder = $this->config['junk_mbox']; break;
190              case 'Trash':  $_folder = $this->config['trash_mbox']; break;
191          }
192            if (!in_array($_folder, $value))
193              $value[] = $_folder;
194        }
195      }
196      else if (is_bool($default)) {
197        $value = (bool)$value;
198      }
199      else if (is_numeric($value)) {
200        $value = intval($value);
201      }
202
203      // skip this property
204      if (!$force && !$this->configured && ($value == $default))
205        continue;
206
207      // save change
208      $this->config[$prop] = $value;
209
210      // replace the matching line in config file
211      $out = preg_replace(
212        '/(\$rcmail_config\[\''.preg_quote($prop).'\'\])\s+=\s+(.+);/Uie',
213        "'\\1 = ' . rcube_install::_dump_var(\$value, \$prop) . ';'",
214        $out);
215    }
216
217    return trim($out);
218  }
219
220
221  /**
222   * Check the current configuration for missing properties
223   * and deprecated or obsolete settings
224   *
225   * @return array List with problems detected
226   */
227  function check_config()
228  {
229    $this->config = array();
230    $this->load_defaults();
231    $defaults = $this->config;
232   
233    $this->load_config();
234    if (!$this->configured)
235      return null;
236   
237    $out = $seen = array();
238    $required = array_flip($this->required_config);
239   
240    // iterate over the current configuration
241    foreach ($this->config as $prop => $value) {
242      if ($replacement = $this->replaced_config[$prop]) {
243        $out['replaced'][] = array('prop' => $prop, 'replacement' => $replacement);
244        $seen[$replacement] = true;
245      }
246      else if (!$seen[$prop] && in_array($prop, $this->obsolete_config)) {
247        $out['obsolete'][] = array('prop' => $prop);
248        $seen[$prop] = true;
249      }
250    }
251   
252    // iterate over default config
253    foreach ($defaults as $prop => $value) {
254      if (!isset($seen[$prop]) && !isset($this->config[$prop]) && isset($required[$prop]))
255        $out['missing'][] = array('prop' => $prop);
256    }
257
258    // check config dependencies and contradictions
259    if ($this->config['enable_spellcheck'] && $this->config['spellcheck_engine'] == 'pspell') {
260      if (!extension_loaded('pspell')) {
261        $out['dependencies'][] = array('prop' => 'spellcheck_engine',
262          'explain' => 'This requires the <tt>pspell</tt> extension which could not be loaded.');
263      }
264      else if (!empty($this->config['spellcheck_languages'])) {
265        foreach ($this->config['spellcheck_languages'] as $lang => $descr)
266          if (!pspell_new($lang))
267            $out['dependencies'][] = array('prop' => 'spellcheck_languages',
268              'explain' => "You are missing pspell support for language $lang ($descr)");
269      }
270    }
271   
272    if ($this->config['log_driver'] == 'syslog') {
273      if (!function_exists('openlog')) {
274        $out['dependencies'][] = array('prop' => 'log_driver',
275          'explain' => 'This requires the <tt>sylog</tt> extension which could not be loaded.');
276      }
277      if (empty($this->config['syslog_id'])) {
278        $out['dependencies'][] = array('prop' => 'syslog_id',
279          'explain' => 'Using <tt>syslog</tt> for logging requires a syslog ID to be configured');
280      }
281    }
282   
283    // check ldap_public sources having global_search enabled
284    if (is_array($this->config['ldap_public']) && !is_array($this->config['autocomplete_addressbooks'])) {
285      foreach ($this->config['ldap_public'] as $ldap_public) {
286        if ($ldap_public['global_search']) {
287          $out['replaced'][] = array('prop' => 'ldap_public::global_search', 'replacement' => 'autocomplete_addressbooks');
288          break;
289        }
290      }
291    }
292   
293    return $out;
294  }
295 
296 
297  /**
298   * Merge the current configuration with the defaults
299   * and copy replaced values to the new options.
300   */
301  function merge_config()
302  {
303    $current = $this->config;
304    $this->config = array();
305    $this->load_defaults();
306
307    foreach ($this->replaced_config as $prop => $replacement) {
308      if (isset($current[$prop])) {
309        if ($prop == 'skin_path')
310          $this->config[$replacement] = preg_replace('#skins/(\w+)/?$#', '\\1', $current[$prop]);
311        else if ($prop == 'multiple_identities')
312          $this->config[$replacement] = $current[$prop] ? 2 : 0;
313        else
314          $this->config[$replacement] = $current[$prop];
315      }
316      unset($current[$prop]);
317    }
318   
319    foreach ($this->obsolete_config as $prop) {
320      unset($current[$prop]);
321    }
322   
323    // add all ldap_public sources having global_search enabled to autocomplete_addressbooks
324    if (is_array($current['ldap_public'])) {
325      foreach ($current['ldap_public'] as $key => $ldap_public) {
326        if ($ldap_public['global_search']) {
327          $this->config['autocomplete_addressbooks'][] = $key;
328          unset($current['ldap_public'][$key]['global_search']);
329        }
330      }
331    }
332   
333    if ($current['keep_alive'] && $current['session_lifetime'] < $current['keep_alive'])
334      $current['session_lifetime'] = max(10, ceil($current['keep_alive'] / 60) * 2);
335
336    $this->config  = array_merge($this->config, $current);
337
338    foreach ((array)$current['ldap_public'] as $key => $values) {
339      $this->config['ldap_public'][$key] = $current['ldap_public'][$key];
340    }
341  }
342 
343  /**
344   * Compare the local database schema with the reference schema
345   * required for this version of Roundcube
346   *
347   * @param boolean True if the schema schould be updated
348   * @return boolean True if the schema is up-to-date, false if not or an error occured
349   */
350  function db_schema_check($DB, $update = false)
351  {
352    if (!$this->configured)
353      return false;
354   
355    // read reference schema from mysql.initial.sql
356    $db_schema = $this->db_read_schema(INSTALL_PATH . 'SQL/mysql.initial.sql');
357    $errors = array();
358   
359    // check list of tables
360    $existing_tables = $DB->list_tables();
361
362    foreach ($db_schema as $table => $cols) {
363      $table = !empty($this->config['db_table_'.$table]) ? $this->config['db_table_'.$table] : $table;
364      if (!in_array($table, $existing_tables)) {
365        $errors[] = "Missing table '".$table."'";
366      }
367      else {  // compare cols
368        $db_cols = $DB->list_cols($table);
369        $diff = array_diff(array_keys($cols), $db_cols);
370        if (!empty($diff))
371          $errors[] = "Missing columns in table '$table': " . join(',', $diff);
372      }
373    }
374   
375    return !empty($errors) ? $errors : false;
376  }
377
378  /**
379   * Utility function to read database schema from an .sql file
380   */
381  private function db_read_schema($schemafile)
382  {
383    $lines = file($schemafile);
384    $table_block = false;
385    $schema = array();
386    foreach ($lines as $line) {
387      if (preg_match('/^\s*create table `?([a-z0-9_]+)`?/i', $line, $m)) {
388        $table_block = $m[1];
389      }
390      else if ($table_block && preg_match('/^\s*`?([a-z0-9_-]+)`?\s+([a-z]+)/', $line, $m)) {
391        $col = $m[1];
392        if (!in_array(strtoupper($col), array('PRIMARY','KEY','INDEX','UNIQUE','CONSTRAINT','REFERENCES','FOREIGN'))) {
393          $schema[$table_block][$col] = $m[2];
394        }
395      }
396    }
397   
398    return $schema;
399  }
400 
401 
402  /**
403   * Compare the local database schema with the reference schema
404   * required for this version of Roundcube
405   *
406   * @param boolean True if the schema schould be updated
407   * @return boolean True if the schema is up-to-date, false if not or an error occured
408   */
409  function mdb2_schema_check($update = false)
410  {
411    if (!$this->configured)
412      return false;
413   
414    $options = array(
415      'use_transactions' => false,
416      'log_line_break' => "\n",
417      'idxname_format' => '%s',
418      'debug' => false,
419      'quote_identifier' => true,
420      'force_defaults' => false,
421      'portability' => true
422    );
423   
424    $dsnw = $this->config['db_dsnw'];
425    $schema = MDB2_Schema::factory($dsnw, $options);
426    $schema->db->supported['transactions'] = false;
427   
428    if (PEAR::isError($schema)) {
429      $this->raise_error(array('code' => $schema->getCode(), 'message' => $schema->getMessage() . ' ' . $schema->getUserInfo()));
430      return false;
431    }
432    else {
433      $definition = $schema->getDefinitionFromDatabase();
434      $definition['charset'] = 'utf8';
435     
436      if (PEAR::isError($definition)) {
437        $this->raise_error(array('code' => $definition->getCode(), 'message' => $definition->getMessage() . ' ' . $definition->getUserInfo()));
438        return false;
439      }
440     
441      // load reference schema
442      $dsn_arr = MDB2::parseDSN($this->config['db_dsnw']);
443
444      $ref_schema = INSTALL_PATH . 'SQL/' . $dsn_arr['phptype'] . '.schema.xml';
445     
446      if (is_readable($ref_schema)) {
447        $reference = $schema->parseDatabaseDefinition($ref_schema, false, array(), $schema->options['fail_on_invalid_names']);
448       
449        if (PEAR::isError($reference)) {
450          $this->raise_error(array('code' => $reference->getCode(), 'message' => $reference->getMessage() . ' ' . $reference->getUserInfo()));
451        }
452        else {
453          $diff = $schema->compareDefinitions($reference, $definition);
454         
455          if (empty($diff)) {
456            return true;
457          }
458          else if ($update) {
459            // update database schema with the diff from the above check
460            $success = $schema->alterDatabase($reference, $definition, $diff);
461           
462            if (PEAR::isError($success)) {
463              $this->raise_error(array('code' => $success->getCode(), 'message' => $success->getMessage() . ' ' . $success->getUserInfo()));
464            }
465            else
466              return true;
467          }
468          echo '<pre>'; var_dump($diff); echo '</pre>';
469          return false;
470        }
471      }
472      else
473        $this->raise_error(array('message' => "Could not find reference schema file ($ref_schema)"));
474        return false;
475    }
476   
477    return false;
478  }
479 
480 
481  /**
482   * Getter for the last error message
483   *
484   * @return string Error message or null if none exists
485   */
486  function get_error()
487  {
488      return $this->last_error['message'];
489  }
490 
491 
492  /**
493   * Return a list with all imap hosts configured
494   *
495   * @return array Clean list with imap hosts
496   */
497  function get_hostlist()
498  {
499    $default_hosts = (array)$this->getprop('default_host');
500    $out = array();
501   
502    foreach ($default_hosts as $key => $name) {
503      if (!empty($name))
504        $out[] = rcube_parse_host(is_numeric($key) ? $name : $key);
505    }
506   
507    return $out;
508  }
509
510  /**
511   * Create a HTML dropdown to select a previous version of Roundcube
512   */
513  function versions_select($attrib = array())
514  {
515    $select = new html_select($attrib);
516    $select->add(array(
517        '0.1-stable', '0.1.1',
518        '0.2-alpha', '0.2-beta', '0.2-stable',
519        '0.3-stable', '0.3.1',
520        '0.4-beta', '0.4.2',
521        '0.5-beta', '0.5', '0.5.1',
522        '0.6-beta', '0.6',
523        '0.7-beta', '0.7', '0.7.1'
524    ));
525    return $select;
526  }
527
528  /**
529   * Return a list with available subfolders of the skin directory
530   */
531  function list_skins()
532  {
533    $skins = array();
534    $skindir = INSTALL_PATH . 'skins/';
535    foreach (glob($skindir . '*') as $path) {
536      if (is_dir($path) && is_readable($path)) {
537        $skins[] = substr($path, strlen($skindir));
538      }
539    }
540    return $skins;
541  }
542 
543  /**
544   * Display OK status
545   *
546   * @param string Test name
547   * @param string Confirm message
548   */
549  function pass($name, $message = '')
550  {
551    echo Q($name) . ':&nbsp; <span class="success">OK</span>';
552    $this->_showhint($message);
553  }
554 
555 
556  /**
557   * Display an error status and increase failure count
558   *
559   * @param string Test name
560   * @param string Error message
561   * @param string URL for details
562   */
563  function fail($name, $message = '', $url = '')
564  {
565    $this->failures++;
566   
567    echo Q($name) . ':&nbsp; <span class="fail">NOT OK</span>';
568    $this->_showhint($message, $url);
569  }
570
571
572  /**
573   * Display an error status for optional settings/features
574   *
575   * @param string Test name
576   * @param string Error message
577   * @param string URL for details
578   */
579  function optfail($name, $message = '', $url = '')
580  {
581    echo Q($name) . ':&nbsp; <span class="na">NOT OK</span>';
582    $this->_showhint($message, $url);
583  }
584 
585 
586  /**
587   * Display warning status
588   *
589   * @param string Test name
590   * @param string Warning message
591   * @param string URL for details
592   */
593  function na($name, $message = '', $url = '')
594  {
595    echo Q($name) . ':&nbsp; <span class="na">NOT AVAILABLE</span>';
596    $this->_showhint($message, $url);
597  }
598 
599 
600  function _showhint($message, $url = '')
601  {
602    $hint = Q($message);
603   
604    if ($url)
605      $hint .= ($hint ? '; ' : '') . 'See <a href="' . Q($url) . '" target="_blank">' . Q($url) . '</a>';
606     
607    if ($hint)
608      echo '<span class="indent">(' . $hint . ')</span>';
609  }
610 
611 
612  static function _clean_array($arr)
613  {
614    $out = array();
615   
616    foreach (array_unique($arr) as $k => $val) {
617      if (!empty($val)) {
618        if (is_numeric($k))
619          $out[] = $val;
620        else
621          $out[$k] = $val;
622      }
623    }
624   
625    return $out;
626  }
627 
628 
629  static function _dump_var($var, $name=null) {
630    // special values
631    switch ($name) {
632    case 'syslog_facility':
633      $list = array(32 => 'LOG_AUTH', 80 => 'LOG_AUTHPRIV', 72 => ' LOG_CRON',
634                    24 => 'LOG_DAEMON', 0 => 'LOG_KERN', 128 => 'LOG_LOCAL0',
635                    136 => 'LOG_LOCAL1', 144 => 'LOG_LOCAL2', 152 => 'LOG_LOCAL3',
636                    160 => 'LOG_LOCAL4', 168 => 'LOG_LOCAL5', 176 => 'LOG_LOCAL6',
637                    184 => 'LOG_LOCAL7', 48 => 'LOG_LPR', 16 => 'LOG_MAIL',
638                    56 => 'LOG_NEWS', 40 => 'LOG_SYSLOG', 8 => 'LOG_USER', 64 => 'LOG_UUCP');
639      if ($val = $list[$var])
640        return $val;
641      break;
642    }
643
644
645    if (is_array($var)) {
646      if (empty($var)) {
647        return 'array()';
648      }
649      else {  // check if all keys are numeric
650        $isnum = true;
651        foreach ($var as $key => $value) {
652          if (!is_numeric($key)) {
653            $isnum = false;
654            break;
655          }
656        }
657       
658        if ($isnum)
659          return 'array(' . join(', ', array_map(array('rcube_install', '_dump_var'), $var)) . ')';
660      }
661    }
662   
663    return var_export($var, true);
664  }
665 
666 
667  /**
668   * Initialize the database with the according schema
669   *
670   * @param object rcube_db Database connection
671   * @return boolen True on success, False on error
672   */
673  function init_db($DB)
674  {
675    $engine = isset($this->db_map[$DB->db_provider]) ? $this->db_map[$DB->db_provider] : $DB->db_provider;
676   
677    // read schema file from /SQL/*
678    $fname = INSTALL_PATH . "SQL/$engine.initial.sql";
679    if ($sql = @file_get_contents($fname)) {
680      $this->exec_sql($sql, $DB);
681    }
682    else {
683      $this->fail('DB Schema', "Cannot read the schema file: $fname");
684      return false;
685    }
686   
687    if ($err = $this->get_error()) {
688      $this->fail('DB Schema', "Error creating database schema: $err");
689      return false;
690    }
691
692    return true;
693  }
694 
695 
696  /**
697   * Update database with SQL statements from SQL/*.update.sql
698   *
699   * @param object rcube_db Database connection
700   * @param string Version to update from
701   * @return boolen True on success, False on error
702   */
703  function update_db($DB, $version)
704  {
705    $version = strtolower($version);
706    $engine = isset($this->db_map[$DB->db_provider]) ? $this->db_map[$DB->db_provider] : $DB->db_provider;
707   
708    // read schema file from /SQL/*
709    $fname = INSTALL_PATH . "SQL/$engine.update.sql";
710    if ($lines = @file($fname, FILE_SKIP_EMPTY_LINES)) {
711      $from = false; $sql = '';
712      foreach ($lines as $line) {
713        $is_comment = preg_match('/^--/', $line);
714        if (!$from && $is_comment && preg_match('/from version\s([0-9.]+[a-z-]*)/', $line, $m)) {
715          $v = strtolower($m[1]);
716          if ($v == $version || version_compare($version, $v, '<='))
717            $from = true;
718        }
719        if ($from && !$is_comment)
720          $sql .= $line. "\n";
721      }
722     
723      if ($sql)
724        $this->exec_sql($sql, $DB);
725    }
726    else {
727      $this->fail('DB Schema', "Cannot read the update file: $fname");
728      return false;
729    }
730   
731    if ($err = $this->get_error()) {
732      $this->fail('DB Schema', "Error updating database: $err");
733      return false;
734    }
735
736    return true;
737  }
738 
739 
740  /**
741   * Execute the given SQL queries on the database connection
742   *
743   * @param string SQL queries to execute
744   * @param object rcube_db Database connection
745   * @return boolen True on success, False on error
746   */
747  function exec_sql($sql, $DB)
748  {
749    $buff = '';
750    foreach (explode("\n", $sql) as $line) {
751      if (preg_match('/^--/', $line) || trim($line) == '')
752        continue;
753       
754      $buff .= $line . "\n";
755      if (preg_match('/(;|^GO)$/', trim($line))) {
756        $DB->query($buff);
757        $buff = '';
758        if ($DB->is_error())
759          break;
760      }
761    }
762   
763    return !$DB->is_error();
764  }
765 
766 
767  /**
768   * Handler for Roundcube errors
769   */
770  function raise_error($p)
771  {
772      $this->last_error = $p;
773  }
774 
775 
776  /**
777   * Generarte a ramdom string to be used as encryption key
778   *
779   * @param int Key length
780   * @return string The generated random string
781   * @static
782   */
783  function random_key($length)
784  {
785    $alpha = 'ABCDEFGHIJKLMNOPQERSTUVXYZabcdefghijklmnopqrtsuvwxyz0123456789+*%&?!$-_=';
786    $out = '';
787   
788    for ($i=0; $i < $length; $i++)
789      $out .= $alpha{rand(0, strlen($alpha)-1)};
790   
791    return $out;
792  }
793 
794}
795
Note: See TracBrowser for help on using the repository browser.