thomascube
2008-02-26 ad43e637bd51b5b288856fee9a69da851ba07779
Add SMTP test to installer script

5 files modified
93 ■■■■ changed files
installer/config.php 15 ●●●●● patch | view | raw | blame | history
installer/index.php 3 ●●●● patch | view | raw | blame | history
installer/rcube_install.php 6 ●●●●● patch | view | raw | blame | history
installer/styles.css 2 ●●● patch | view | raw | blame | history
installer/test.php 67 ●●●●● patch | view | raw | blame | history
installer/config.php
@@ -5,6 +5,7 @@
ini_set('display_errors', 1);
require_once 'include/rcube_html.inc';
$RCI->load_config();
$RCI->load_defaults();
if (!empty($_POST['submit'])) {
@@ -167,6 +168,8 @@
<p>Database settings for read/write operations:</p>
<?php
require_once 'DB.php';
$supported_dbs = array('MySQL' => 'mysql', 'MySQLi' => 'mysqli',
    'PgSQL' => 'pgsql', 'SQLite' => 'sqlite');
@@ -182,17 +185,17 @@
$input_dbuser = new textfield(array('name' => '_dbuser', 'size' => 20, 'id' => "cfgdbuser"));
$input_dbpass = new textfield(array('name' => '_dbpass', 'size' => 20, 'id' => "cfgdbpass"));
$dsnw = parse_url($RCI->getprop('db_dsnw'));
$dsnw = DB::parseDSN($RCI->getprop('db_dsnw'));
echo $select_dbtype->show($_POST['_dbtype'] ? $_POST['_dbtype'] : $dsnw['scheme']);
echo $select_dbtype->show($_POST['_dbtype'] ? $_POST['_dbtype'] : $dsnw['phptype']);
echo '<label for="cfgdbtype">Database type</label><br />';
echo $input_dbhost->show($_POST['_dbhost'] ? $_POST['_dbhost'] : $dsnw['host']);
echo $input_dbhost->show($_POST['_dbhost'] ? $_POST['_dbhost'] : $dsnw['hostspec']);
echo '<label for="cfgdbhost">Database server</label><br />';
echo $input_dbname->show($_POST['_dbname'] ? $_POST['_dbname'] : preg_replace('/^\//', '', $dsnw['path']));
echo $input_dbname->show($_POST['_dbname'] ? $_POST['_dbname'] : $dsnw['database']);
echo '<label for="cfgdbname">Database name</label><br />';
echo $input_dbuser->show($_POST['_dbuser'] ? $_POST['_dbuser'] : $dsnw['user']);
echo $input_dbuser->show($_POST['_dbuser'] ? $_POST['_dbuser'] : $dsnw['username']);
echo '<label for="cfgdbuser">Database user name (needs write permissions)</label><br />';
echo $input_dbpass->show($_POST['_dbpass'] ? $_POST['_dbpass'] : $dsnw['pass']);
echo $input_dbpass->show($_POST['_dbpass'] ? $_POST['_dbpass'] : $dsnw['password']);
echo '<label for="cfgdbpass">Database password</label><br />';
?>
installer/index.php
@@ -64,7 +64,8 @@
</div>
<div id="footer">
  Installer by the RoundCube Dev Team. Copyright &copy; 2008 - Published under the GNU Public License
  Installer by the RoundCube Dev Team. Copyright &copy; 2008 - Published under the GNU Public License;&nbsp;
  Icons by <a href="http://famfamfam.com">famfamfam</a>
</div>
</body>
</html>
installer/rcube_install.php
@@ -27,6 +27,7 @@
  var $failures = 0;
  var $config = array();
  var $last_error = null;
  var $email_pattern = '([a-z0-9][a-z0-9\-\.\+\_]*@[a-z0-9]([a-z0-9\-][.]?)*[a-z0-9])';
  
  /**
   * Constructor
@@ -88,16 +89,17 @@
   * Getter for a certain config property
   *
   * @param string Property name
   * @param string Default value
   * @return string The property value
   */
  function getprop($name)
  function getprop($name, $default = null)
  {
    $value = isset($_REQUEST["_$name"]) ? $_REQUEST["_$name"] : $this->config[$name];
    
    if ($name == 'des_key' && !isset($_REQUEST["_$name"]))
      $value = self::random_key(24);
    
    return $value;
    return $value !== null ? $value : $default;
  }
  
  
installer/styles.css
@@ -137,7 +137,7 @@
  margin-top: 0.3em;
}
label {
dd label {
  padding-left: 0.5em;
}
installer/test.php
@@ -123,7 +123,72 @@
?>
<p>[@todo Add tests for IMAP and SMTP settings]</p>
<h3>Test SMTP settings</h3>
<p>
Server: <?php echo $RCI->getprop('smtp_server', 'PHP mail()'); ?><br />
Port: <?php echo $RCI->getprop('smtp_port'); ?><br />
User: <?php echo $RCI->getprop('smtp_user', '(none)'); ?><br />
Password: <?php echo $RCI->getprop('smtp_pass', '(none)'); ?><br />
</p>
<?php
if (isset($_POST['sendmail']) && !empty($_POST['_from']) && !empty($_POST['_to'])) {
  require_once 'lib/rc_mail_mime.inc';
  require_once 'include/rcube_smtp.inc';
  echo '<p>Trying to send email...<br />';
  if (preg_match('/^' . $RCI->email_pattern . '$/i', trim($_POST['_from'])) &&
      preg_match('/^' . $RCI->email_pattern . '$/i', trim($_POST['_to']))) {
    $recipients = trim($_POST['_to']);
    $headers = array(
      'From' => trim($_POST['_from']),
      'To'  => $recipients,
      'Subject' => 'Test message from RoundCube',
    );
    $body = 'This is a test to confirm that RoundCube can send email.';
    $mail_object  = new rc_mail_mime();
    $send_headers = $mail_object->headers($headers);
    $smtp_response = array();
    $status = smtp_mail($headers['From'], $recipients,
        ($foo = $mail_object->txtHeaders($send_headers)),
        $body, $smtp_response);
    if ($status) {
        $RCI->pass('SMTP send');
    }
    else {
        $RCI->fail('SMTP send', join('; ', $smtp_response));
    }
  }
  else {
    $RCI->fail('SMTP send', 'Invalid sender or recipient');
  }
}
echo '</p>';
?>
<table>
<tbody>
  <tr><td><label for="sendmailfrom">Sender</label></td><td><input type="text" name="_from" value="" id="sendmailfrom" /></td></tr>
  <tr><td><label for="sendmailto">Recipient</label></td><td><input type="text" name="_to" value="" id="sendmailto" /></td></tr>
</tbody>
</table>
<p><input type="submit" name="sendmail" value="Send test mail" /></p>
<p>[@todo Add tests for IMAP settings]</p>
</form>