Roundcube login via PHP script
目前正在整合 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
Updates
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:
- November 2008: After the comment of Matias, I reviewed the code and fixed some issues. Now it should work properly even with the newest Roundcube version (0.2-beta). The class file itself contains installation instructions. Please read them carefully.
- March 2009: Just tested the script with version 0.2.1 and it works like a charm, at least for my installation.
- December 2009: Diego just confirmed (via e-mail) that the script also works for 0.3.1 without modification.
- May 2010: I just tested the scripts with Roundcube 0.4-beta, and it still works without modification. I also added the sectionDebugging make it easier to figure out what’s wrong.
- March 2011: After Alex’ comment, I adjusted a small part of the script. It should now also work with Roundcube 0.5.1. It now handles the new request token correctly. The pre-0.5.1 script is still available for download here:RoundcubeLogin.pre-0.5.1.class.php (plain text).
- April 2012: I have updated the script again. It now works with 0.7.2. Issues were PHP’s multiple-cookie handling, the sessauth-cookie as well as the user agent checks by RC. The pre-0.6 version is still available for download here:RoundcubeLogin.pre-0.6.class.php (plain text).
- May 2013: According to Reznor’s comment, the script still works with 0.9.0.
- July 2013: The class is currently used in the Roundcube ownCloud Plugin by Martin Reinhardt. There have been some issues with the altered version. Make sure to update to the newest version or report bugs here.
- July 2013: After many user issues with SSL-hosted Roundcube installations, I finally got around to fix the SSL issues once and for all. The class now detects whether RC is running with SSL/TLS and set hostname, port and connection type accordingly. If that does not work, you can use setHostname(), setPort() and setSSL to adjust these settings to your environment. The old class is still available here: RoundcubeLogin.pre-0.9.2.class.php (plain text).
1. Prepare RC
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).
2. The RoundcubeLogin class
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.
- RoundcubeLogin.class.php (plain text)
Provides the functionality to login, logout and check the login status. - rclogin.php (plain text)
A small script to test if everything works as expected.
The class provides four public methods:
- login($username, $password)
Perform a login to the Roundcube mail system.
Note: If the client is already logged in, the script will re-login the user (logout/login). To prevent this behaviour, use theisLoggedIn()-function.
Returns: TRUE if the login suceeds, FALSE if the user/pass-combination is wrong
Throws: May throw a RoundcubeLoginException if Roundcube sends an unexpected answer (that might happen if a new Roundcube version behaves differently) - isLoggedIn()
Checks whether the client/browser is logged in and has a valid Roundcube session.
Returns: TRUE if the user is logged in, FALSE otherwise.
Throws: May also throw a RoundcubeLoginException (see above). - logout()
Performs a logout on the current Roundcube session.
Returns: TRUE if the logout was a success, FALSE otherwise.
Throws: May also throw a RoundcubeLoginException (see above). - redirect()
Simply redirects to Roundcube. - setHostname($hostname)
Set hostname manually. Note that the hostname must point to the local machine. It does not work for remote machines. - setPort($port)
Set port manually. Uses server port by default (auto detected). - setSSL($enableSSL)
Enable or disable SSL for this connection. This value impacts the connection string for fsockopen(). If enabled, the prefix “ssl://” is attached. If NULL is set, the value of the $_SERVER['HTTPS'] variable is used.
3. Sample usage
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.
PHP
|
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;
}
?>
|
4. Debugging
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:
- No Roundcube installation found at ‘…’
This error message is thrown if the path-value in the RoundcubeLogin constructur was not set correctly. It must be set to the part of the URL that represents the path, e.g. in case of http://myhost/roundcube/ you must create the object like this:PHP
1$rcl = new RoundcubeLogin("/roundcube/"); - Unable to determine login-status due to technical problems.
This error can occur in the methods login(), logout() and isLoggedIn(). The RoundcubeLogin-class expects Roundcube to send certain headers in response to the login/logout-requests. If those headers could not be found, this error is thrown. Possible reasons are:- New RC version
- Cookies must be enabled
- ip_check/check_ip option in the main.inc.php must be false
- Unable to determine the login status. Unable to continue due to technical problems.
This error occurs if the script cannot determine if you are logged in or not, because the returned HTML code neither contains the login-form (= logged out) nor the message DIV (= logged in). This might happen if Roundcube changed the HTML-code. - Test script “rclogin.php” says “400 Bad Request”: When you run the test script you get an error like this:
XHTML
1234<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).
5. I’m open for suggestions
Please feel free to post your comment or suggestions. That’s the only way to ensure that it works with all versions.
Roundcube login via PHP script的更多相关文章
- QQ Auto Login Visual Basic Script
QQ_Auto_Login.vbs: Dim QQPath QQPath="C:\Program Files (x86)\Tencent\QQ\Bin\QQ.exe" Set ba ...
- SQL Server 服务器器信息备份(一)--login新建脚本备份
前言 若你的企业使用SQL Server数据库镜像为容灾技术. 那你一定做过在镜像切换之前要新建Login,而且若Login密码不同,要修改链接数据库的字符串,在切换完之后则仍需要给数据库重新赋予权限 ...
- 发布时一键添加html中的css标签和script标签版本号来防止浏览器缓存
AppendFileVersion 是一个VSIX插件支持vs2015意以上版本 是我用来发布时一键添加html中的css标签和script标签版本号来防止浏览器缓存 分享给大家! download ...
- 一个Login页面全面了解session与cookie
背景 做了四年的前端开发,对外一直说自己是web开发,那么身为一个web开发怎能不知道session与cookie以及其管理方式呢~ Login涉及技术栈:Nodejs,MongoDB,Express ...
- 迁移MSSQL实例的所有login(包含密码)
迁移数据库的时候肯定会涉及到login的迁移(包含数据库除外). 而一般我们迁移login的时候,可能会使用在某个login上右键生成脚本这样的做法.但是这样生成的脚本不能把密码也生成出来. 而且你只 ...
- How to use ftp in a shell script
转载How to use ftp in a shell script How to use ftp in a shell script Bruce EdigerBruce Ediger's home ...
- JavaWeb网上图书商城完整项目--day02-14.登录功能的login页面处理
1.现在注册成功之后,我们来到登录页面,登录页面在于 在登录页面.我们也需要向注册页面一样对登录的用户名.密码 验证码等在jsp页面中进行校验,校验我们单独放置一个login.js文件中进行处理,然后 ...
- react入门(1)
这篇文章也不能算教程咯,就算是自己学习整理的笔记把. 关于react一些相关的简介.优势之类的,随便百度一下一大堆,我就不多说了,可以去官网(http://reactjs.cn/)看一下. 这片主要讲 ...
- Django实现表单验证、CSRF、cookie和session、缓存、数据库多表操作(双下划綫)
通常验证用户输入是否合法的话,是前端js和后端共同验证的,这是因为前端js是可以被禁用的,假如被禁用了,那就没法用js实现验证合法与否了,也就是即使用户输入的不合法,但是也没提示,用户也不知道怎么输入 ...
随机推荐
- (一)问候 Log4j 你好
第一节: Log4j 简介 Log4j -------- log for java(java的日志) 是java主流的日志框架,提供各种类型,各种存储,各种格式,多样化的日志服务: 在爬虫领域,主要用 ...
- cve-2010-3333 Microsoft Office Open XML文件格式转换器栈缓冲区溢出漏洞 分析
用的是泉哥的POC来调的这个漏洞 0x0 漏洞调试 Microsoft Office Open XML文件格式转换器栈缓冲区溢出漏洞 Microsoft Office 是微软发布的非常流行的办公 ...
- 中断、轮询、事件驱动、消息驱动、数据流驱动(Flow-Driven)?
轮询.事件驱动.消息驱动.流式驱动 ---数据流驱动 Unidirectional Architecture? 中断.事件.消息这样一种机制来实现更好的在多任务系统里运行... 阻塞,非阻塞同步,异步 ...
- shell实现增加删除Linux系统用户脚本(密码为随机)
README shell环境下运行脚本,根据需求选择相应的功能. List \t\t create the userlist 这一步是必须执行的,脚本会识别本地当前目录下的文件 Useradd \t\ ...
- 【LOJ】#2538. 「PKUWC2018」Slay the Spire
题解 由于强化卡都是大于1的,我们分析一下就会发现,尽可能多的用强化卡,至少用一张攻击卡,一定是每组卡牌的最优选择 所以我们把攻击卡和强化卡从大到小排序 我们设\(g[i][j]\)表示前i张卡牌里选 ...
- USACO 6.5 Checker Challenge
Checker Challenge Examine the 6x6 checkerboard below and note that the six checkers are arranged on ...
- 更快的速度、更好的服务——易普优APS云排程
众所周知软件执行效率受制于硬件性能,市面上的APS产品多为单机版本,企业要应用好APS,保证紧急插单.计划下发全程无忧,用户电脑硬件性能是不容忽视的一大瓶颈.APS的直接用户是车间管理人员.计划员,而 ...
- 9-4 Unidirectional TSP uva116 (DP)
题意:给一个n行m列矩阵 从第一列任意一个位置出发 每次往右 右上 右下三个方向走一格 直到最后一列 输出所类和的最小值和路径!! 最小值相同则输出字典序最小路径 很像一开始介绍的三角形dp ...
- thinkphp中导入和使用阿里云OSSsdk
照做绝对行,在ThinkPHP中,第三方库都放在ThinkPHP/Library/Vendor/路径下. 1.下载OSS PHP SDK:https://help.aliyun.com/documen ...
- OSPF详解
OSPF 详解 (1) [此博文包含图片] (2013-02-04 18:02:33) 转载 ▼ 标签: 端的 第二 以太 第一个 正在 目录 序言 初学乍练 循序渐进学习OSPF 朱皓 入门之前 了 ...