目前正在整合 roundcube 1.0.5 的邮件系统和其他系统,想取消登录过程,发现了这个,先赞一个!
原文地址: http://blog.philippheckel.com/2008/05/16/roundcube-login-via-php-script/
Roundcube is an AJAX/PHP based e-mail application which is really flexible and easy to use in comparison to other free web based solutions.
For the customer interface of Silversun, I wanted to use RC as the internal web mail application and therefore had to embed it into my system. To avoid that the customer has to log in twice (customer interface and Roundcube), I had to simulate the login request with a PHP script.
Contents
A lot has changed over the years. As of now (July 2013), the class does exist for over 5 years. Here’s what happened in this time:
To perform the Roundcube login via a web site, it is necessary to turn off the check_ip/ip_check option in the main.inc.php file, because our script (= server IP address) will send the login data and pass it to RC instead of the user’s browser (= user IP address).
This small class only consists of four functions and it shouldn’t be necessary to modify it in order to get the login to work.
The class provides four public methods:
The script below demonstrates how the class can be used. If the client is already logged in, it simply redirects the browser to the Roundcube application. If not, it performs a login and then redirects to Roundcube.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
<?php
include "RoundcubeLogin.class.php";
// Create RC login object.
// Note: The first parameter is the URL-path of the RC inst.,
// NOT the file-system path. Trailing slash REQUIRED.
// e.g. http://host.com/path/to/roundcube/ --> "/path/to/roundcube/"
$rcl = new RoundcubeLogin("/roundcube/", $debug);
// Override hostname, port or SSL-setting if necessary:
// $rcl->setHostname("example.localhost");
// $rcl->setPort(443);
// $rcl->setSSL(true);
try {
// If we are already logged in, simply redirect
if ($rcl->isLoggedIn())
$rcl->redirect();
// If not, try to login and simply redirect on success
$rcl->login("some-email-address", "plain-text-password");
if ($rcl->isLoggedIn())
$rcl->redirect();
// If the login fails, display an error message
die("ERROR: Login failed due to a wrong user/pass combination.");
}
catch (RoundcubeLoginException $ex) {
echo "ERROR: Technical problem, ".$ex->getMessage();
$rcl->dumpDebugStack(); exit;
}
?>
|
If you’re having problems with the RoundcubeLogin.class.php class (plain text) itself, try using the rclogin.php-file (plain text) for debugging: open the file in your browser (http://myhost/roundcube/rclogin.php), and take a look at the output. TheRoundcubeLogin-class performs a series of request/response cycles and parses the output to figure out if you’re logged in.
Known issues:
1
|
$rcl = new RoundcubeLogin("/roundcube/");
|
1
2
3
4
|
<h1 id="Bad-Request">Bad Request</h1>
<p>Your browser sent a request that this server could not understand.<br />
Reason: You're speaking plain HTTP to an SSL-enabled server port.<br />
Instead
use the HTTPS scheme to access this URL, please.
|
The reason for this exception is that the hostname in the fsockopen() has been called without an “ssl://”-prefix. In the class you can fix this by calling $rcl->setSSL(true).
Please feel free to post your comment or suggestions. That’s the only way to ensure that it works with all versions.