From ad43e637bd51b5b288856fee9a69da851ba07779 Mon Sep 17 00:00:00 2001 From: thomascube Date: Tue, 26 Feb 2008 18:08:19 +0000 Subject: Add SMTP test to installer script --- installer/config.php | 15 ++++++---- installer/index.php | 3 +- installer/rcube_install.php | 6 ++-- installer/styles.css | 2 +- installer/test.php | 67 ++++++++++++++++++++++++++++++++++++++++++++- 5 files changed, 82 insertions(+), 11 deletions(-) (limited to 'installer') diff --git a/installer/config.php b/installer/config.php index 0697cc124..c110276aa 100644 --- a/installer/config.php +++ b/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 @@ echo $select_mdnreq->show(intval($RCI->getprop('mdn_requests')));

Database settings for read/write operations:

'mysql', 'MySQLi' => 'mysqli', 'PgSQL' => 'pgsql', 'SQLite' => 'sqlite'); @@ -182,17 +185,17 @@ $input_dbname = new textfield(array('name' => '_dbname', 'size' => 20, 'id' => " $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 '
'; -echo $input_dbhost->show($_POST['_dbhost'] ? $_POST['_dbhost'] : $dsnw['host']); +echo $input_dbhost->show($_POST['_dbhost'] ? $_POST['_dbhost'] : $dsnw['hostspec']); echo '
'; -echo $input_dbname->show($_POST['_dbname'] ? $_POST['_dbname'] : preg_replace('/^\//', '', $dsnw['path'])); +echo $input_dbname->show($_POST['_dbname'] ? $_POST['_dbname'] : $dsnw['database']); echo '
'; -echo $input_dbuser->show($_POST['_dbuser'] ? $_POST['_dbuser'] : $dsnw['user']); +echo $input_dbuser->show($_POST['_dbuser'] ? $_POST['_dbuser'] : $dsnw['username']); echo '
'; -echo $input_dbpass->show($_POST['_dbpass'] ? $_POST['_dbpass'] : $dsnw['pass']); +echo $input_dbpass->show($_POST['_dbpass'] ? $_POST['_dbpass'] : $dsnw['password']); echo '
'; ?> diff --git a/installer/index.php b/installer/index.php index d62f6cb9d..aab406e98 100644 --- a/installer/index.php +++ b/installer/index.php @@ -64,7 +64,8 @@ else { diff --git a/installer/rcube_install.php b/installer/rcube_install.php index f2ab394a1..8ff220357 100644 --- a/installer/rcube_install.php +++ b/installer/rcube_install.php @@ -27,6 +27,7 @@ class rcube_install 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 @@ class rcube_install * 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; } diff --git a/installer/styles.css b/installer/styles.css index 1290696f8..0260b6741 100644 --- a/installer/styles.css +++ b/installer/styles.css @@ -137,7 +137,7 @@ dd div { margin-top: 0.3em; } -label { +dd label { padding-left: 0.5em; } diff --git a/installer/test.php b/installer/test.php index b782a5c44..0f499eba3 100644 --- a/installer/test.php +++ b/installer/test.php @@ -123,7 +123,72 @@ if ($db_working) { ?> -

[@todo Add tests for IMAP and SMTP settings]

+

Test SMTP settings

+ +

+Server: getprop('smtp_server', 'PHP mail()'); ?>
+Port: getprop('smtp_port'); ?>
+User: getprop('smtp_user', '(none)'); ?>
+Password: getprop('smtp_pass', '(none)'); ?>
+

+ +Trying to send email...
'; + + 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 '

'; + +?> + + + + + + +
+ +

+ + +

[@todo Add tests for IMAP settings]

-- cgit v1.2.3