当前位置: 首页 > 淘宝 > 正文

企业网中nextcloud与iRedmail邮件系统的配合

目前实践中常用的优秀的邮件解决方案是iRedmail,优秀的群件解决方案是Kolab。

iRedmail是“围绕”roundcube 的一套邮件方案。配置一个完善的邮件系统并不容易,iredmail基本上将这个问题解决的比较彻底,因此邮件系统的蓝本就是以iRedmail为基准,iRedmail用的是SoGO群件组价(sogo自己也有邮件界面)。

kolab是“围绕”roundcube的一套群件方案,也内建了邮件系统支持(postfix+cyrus imap+roundcube+kolab),和iRedmail理念类似,但更强调群件和协作,围绕roundcube功能进行了扩展,是全PHP的Web解决方案。

iRedmail使用最广泛的邮件方案组件:postfix(SMTP)+dovecot(IMAP/POP3)+roundcube(webmail)+sogo(群件),配套的是Nginx,MariaDB。

本文主要是基于iRedmail解决方案来作为邮件基础设施,如何与nextcloud网盘进行集成。如果和nextcloud在同一台服务器进行安装,注意和nextcloud安装容易冲突的是:

nextcloud要求的php版本是7,而iRedmail后强行安装OS中的php5版本,解决方法是卸载php5,然后再安装PHP7
对于MariaDB则不会进行重装。
只支持Nginx,因此需要将nextcloud支持nginx,见前文
webmail实际上只是一个MUA程序,可以同时使用多个,只要用不同路径访问即可。
那么nextcloud和邮件系统在企业中如何配套使用呢,如在nextcloud中使用邮件功能或者是在邮件系统中使用nextcloud网盘功能。注意,基础邮件服务是iRedmail的Postfix和Dovecot等提供的,基础网盘服务是nextcloud服务提供的。nextcloud只是一个web邮件客户端界面,而roundcubemail只是一个网盘客户端界面。

一、nextcloud中的webmail

  1. nextcloud官方mail app
    官方mail非常简单,只能收发邮件,但最大的好处是和nextcloud的功能有基本集成,可以直接上传nextcloud云文档或者链接。

也不需要管理员界面,每个nextcloud账户中,自己配对应的邮箱账户,记录密码。

邮件账号配置

邮件首页

mail app编写邮件

上传nextcloud中的文件为附件

  1. nextcloud app商店中的RainLoop
    rainloop是一个和roundcube基本同等的webmail,支持插件。rainloop app对rainloop进行了简单的封装,按照nextcloud应用的基本管理,和nextcloud做到界面框架上的集成,并且可以进行账户绑定,从而直接在nextcloud框架下进行操作。但是没有提供更多的功能上的配合,例如直接上传nextcloud云文档或者链接,直接分享链接等等。

rainloop有管理员界面,可以统一配置邮件服务器。

Rainloop admin settings can be reached only by the Nextcloud administrator. Open the Nextcloud admin panel (“Admin” in the upper-right corner dropdown menu) and go to “Additionnal settings”. There, click on the “Go to RainLoop Webmail admin panel” link. Alternatively, you may use the following link: https://path.to.nextcloud/index.php/apps/rainloop/app/?admin.

Rainloop admin settings include all settings that will apply to all Rainloop users (default login rules, branding, management of plugins, security rules and domains).

管理员界面

设置邮件账户
用户的设置菜单中-》其它设置,可以配置:

用户设置RainLoop账户
二、roundcube与nextcloud的集成

  1. 集成模式
    有两种模式,一种是将nextcloud嵌入到roundcube中成为roundcube的一个主功能(如同AddressBook);另外一种模式是将roundcube嵌入到nextcloud中作为其一个app。

(一)roundcube 插件访问nextcloud文件

参考https://github.com/texxasrulez/roundcube-plugin-nextcloud,直接在roundcube中打开nextcloud,并通过Roundrive plugin在邮件中使用nextcloud附件。
roundrive是最合适的解决方案,Roundrive主要是使用flysystem lib (https://github.com/thephpleague/flysystem),这是一帮PHP爱好者开发的文件API,可以统一接口存取本地文件、ftp、S3/google, webDAV等文件系统,Roundrive主要使用的是webDAV功能。我也将其进行了汉化,汉化文件https://download.csdn.net/download/McwoLF/19668655。

(二)roundcube作为nextcloud 应用

参考https://github.com/flionet89/Nextcloud-roundcube,是在nextcloud中的应用,和Rainloop应用一样,在nextcloud中嵌入的roundcube邮件界面,实现下面的整合(但没有nextcloud云盘功能整合)。

自动登录
SSL开关
显示隐藏Roundcube主工具栏
默认路径

  1. roundrive插件
    rounddrive是模仿了kolab-files扩展进行开发的(https://git.kolab.org/diffusion/RPK/browse/master/plugins/kolab_files/)。

Roundrive有两个版本,上面的是flionet89改进的版本!还有M-m开发的另一个版本比较粗糙。这里以flionet89版本进行操作,有很多的坑,解决过的有:

[1] 配置文件 config.inc.php修改为适合安装的实际例子

<?php
// Show the drive task ?
$rcmail_config['show_drive_task'] = true;
 
// Configuration WebDAV example: 'https://example.ex/remote.php/dav/files/'
$rcmail_config['driver_webdav_url'] = 'https://192.168.10.51/nextcloud/remote.php/dav/files/';
 
// Prefix ex for nextcloud 21
$rcmail_config['driver_webdav_prefix'] = '/nextcloud/remote.php/dav/files/';
 
// Romove domin suffix for login. If need!
$rcmail_config['rm_domain'] = '@example.com';


[2] 用户名的问题,实际上要求rc和nc的用户名是相同的。

这里很多小的考虑点,需要通过/var/logs/nginx/access.log和/opt/www/nextcloud/data/nextcloud.log两个日志反复测试

因为rc的实际用户名是有 @example.com域名的,而一般在nc中建立是没有域名的,因此修改了代码(plugins/roundrive/lib/roundrive_files_engine.php),见注释

public function __construct($plugin)
{
    $this->plugin  = $plugin;
    $this->rc      = $plugin->rc;
    $this->timeout = $this->rc->config->get('session_lifetime') * 60;
    $u = $this->rc->user->get_username();
    $d = $this->rc->config->get('rm_domain');
    $format_u=str_replace($d,'',$u);
    $settings = array(
            'userName' => $this->rc->user->get_username(),
            'password' => $this->rc->get_user_password(),
            'baseUri' =>  $this->rc->config->get('driver_webdav_url') . $format_u,
    );
//$log = date('Y-m-d H:i:s') . ' ' . print_r($settings, true);
//file_put_contents(__DIR__ . '/log.txt', $log . PHP_EOL, FILE_APPEND);
    $client = new Client($settings);
    $adapter = new WebDAVAdapter($client, $this->rc->config->get('driver_webdav_prefix'). $format_u);
    $this->filesystem = new Filesystem($adapter);
}

[3] flysystem 使用davclient库来源于sabre(https://sabre.io/dav/davclient/) ,sabre提供了webdav、caldav等专业方案。

第一次运行的时候,日志中没有错误,也可以从API获取目录列表 https://192.168.10.51/mail/?task=roundrive&_action=file_api&method=folder_list&=1622703213461,但显示是空白。

{"status":"OK","result":["\u6587\u4ef6","\u6587\u4ef6\/Documents","\u6587\u4ef6\/Photos","\u6587\u4ef6\/Templates"],"req_id":null}


后来,调试代码发现两个问题:1是roundrive默认只配了Larry模板,因此将用户设置改成Larry模板就开源列出目录了;2 但此时的TaskBar的files图标是disable的,后来发现可能是不支持新版本的roundcube。

修改/lib/roundrive_files_engine.php 将ui( )函数中,大概130行左右,add taskbar button,增加 ‘type’ => ‘link’, 即可

        // add taskbar button
        if (empty($_REQUEST['framed']) && $this->rc->config->get('show_drive_task', true)) {
            $this->plugin->add_button(array(
                'type'       => 'link',
                'command'    => 'roundrive',
                'class'      => 'button-files',
                'classsel'   => 'button-files button-selected',
                'innerclass' => 'button-inner',
                'label'      => 'roundrive.files',
                ), 'taskbar');
        }

这是如果不显示设置,会被认为是button类型,最后programe/include/rcmail_output_html.php中约1752行,( if ($attrib[‘command’]) { $attrib[‘disabled’] = ‘disabled’; } )会被disable,比较下面的客户端代码才看出和其它功能按钮的不同。

<a class="button-mail button-selected" id="rcmbtn107" role="button" href="./?_task=mail" onclick="return rcmail.command('switch-task','mail',this,event)" tabindex="-1" aria-disabled="true"><span class="button-inner">邮件</span><span class="tooltip">邮件</span></a>
		
<a class="button-addressbook" id="rcmbtn108" role="button" href="./?_task=addressbook" onclick="return rcmail.command('switch-task','addressbook',this,event)" tabindex="0" aria-disabled="false"><span class="button-inner">联系人</span><span class="tooltip">联系人</span></a>	
	
<button class="button-files" type="button" id="rcmbtn104" onclick="return rcmail.command('switch-task','roundrive',this,event)" value="文件">文件</button>
 
<a class="button-settings" id="rcmbtn109" role="button" href="./?_task=settings" onclick="return rcmail.command('switch-task','settings',this,event)" tabindex="0" aria-disabled="false"><span class="button-inner">设置</span><span class="tooltip">设置</span></a>
  1. 在roundcube中使用webdav目录
    使用效果如下,还是非常方便。

【注】目前存在的问题是删除和上传没有实现!

(1 )Taskbar-文件

打开webdav,管理自己的云盘账户。

查看WebDav云盘资源
(2)写邮件中添加附件。

从W+ebDav云添加附件
(3)收取的邮件中附件保存在webdav中。

将邮件附件存到WebDav云盘中
三、认证集成

  1. 使用外部imap认证(external user authentication)
    这种方式使用一个external user authentication应用,支持IMAP, SMB, FTP, WebDAV, HTTP BasicAuth, SSH and XMPP等外部用户库,使用oc_users_external表(只有用户名和displayname,密码由外部用户库保存),例如直接使用imap作为认证源,实现用邮件账户进行登录。

  'user_backends' => array(
    array(
        'class' => 'OC_User_IMAP',
        'arguments' => array(
            '127.0.0.1', 143, null, 'example.com', true, false
        ),
     ),
   ),
  1. 参数解释:
This connects to the IMAP server on IP 127.0.0.1.
The default port is 143. However, note that parameter order matters and if you want to restrict the domain (4th parameter), you need to also specify the port (2nd parameter) and sslmode (3rd parameter; set to null for insecure connection). 
If a domain name (e.g. example.com) is specified, then this makes sure that only users from this domain will be allowed to login. 
If the fifth parameter is set to true, after successfull login the domain part will be striped and the rest used as username in Nextcloud. e.g. '[email protected]' will be 'username' in Nextcloud. 
The sixth parameter toggles whether on creation of the user, it is added to a group corresponding to the name of the domain part of the address.

文档见:https://github.com/nextcloud/user_external

但是,实际上作用不是非常明显,因为验证的不是很快。

  1. User and Group SQL Backends和User Backend Using Raw SQL
    User and Group SQL Backends应用

地址:https://github.com/nextcloud/user_sql,这个是官方的外部数据库后台验证,支持Mysql/MariaDB和PostgreSQL数据库。

使用外部数据库保存nextcloud用户和组,包括修改密码。以及和nextcloud同步用户邮箱等信息。

还有一个类似的应用是:User Backend Using Raw SQL
地址:https://github.com/PanCakeConnaisseur/user_backend_sql_raw/blob/master/README.md

允许直接定义SQL语句,实现认证、创建、删除用户、修改密码等,支持PostgreSQL and MariaDB/MySQL数据库。

默认还是使用官方的,考虑的非常周全。如果遇到实在难于集成的情况,可以自己直接写SQL语句。

  1. 使用邮箱账户访问nextcloud
    下面示例使用User and Group SQL Backends(user_sql),通过iRedmail的邮件账户进行用户管理。

首先来看,iRedmail中的用户认证,实际上是用dovecot进行认证,dovecot支持的密码算法见:https://doc.dovecot.org/configuration_manual/authentication/password_schemes/

iRedmail安装默认使用的是{SSHA512}算法,比以前版本{CRYPT}+Salt要简单,加密强度更大。

iRedmail中vmail库是邮件系统数据库,其中mailbox就是用户账户表,表数据如下:


iRedmail用户数据库
安装User Backend Using Raw SQL应用后,在admin账户中,设置->管理可以看到SQL Backends子菜单,如下2图:

上半部分是关于数据库连接的配置参数和选项,这里面最关键的就是Hash algorithm算法,选择对应的算法SSHA512!

其它的是一些登录和同步参数,详细的介绍参考https://github.com/nextcloud/user_sql

SQL Backends配置-选项
下半部分则是关于表格字段映射的(对应iRedmail数据库中mailbox的字段格式,如下表):

因为iRedmail管理面板并没有用户组和通讯录的概念,这些是在roundcube数据库中配置的,所以group table和User Group table可以使用roundcube数据库表,这里暂时空着。

SQL Backends配置-表格映射
保存之后,使用个人邮箱账户就可以登录nextcloud了。例如有邮箱[email protected],在nextcloud登录界面用户名使用:[email protected]就可以直接登录。如果没有对应的nextcloud账户,系统会自动建立一个。其WebDAV地址格式:

https://mx.example.com/nextcloud/remote.php/dav/files/[email protected]/
  1. LDAP统一认证

很多企业都建有LDAP目录服务用于统一身份认证,如果邮件系统和nextcloud系统都使用LDAP目录作为认证服务,自然就可以实现统一认证。

具体可参考《统一认证–nextcloud和iRedMail》等。

四、 关于日志与排查问题
关于日志,使用开源软件,最大的好处是自由,最大的问题也是自由。有无数的坑需要规避,很多需要自己动手,而找到问题原因是最重要的,这就需要对日志比较了解

nextcloud日志位置是:nextcloud/data/nextcloud.log

iredadmin的配置和日志文件位置见:https://docs.iredmail.org/file.locations.html#iredadmin

例如:iredmail的日志在CentOS下是:/var/log/messages.

RainLoop日志:配置文件在/nextcloud/data/rainloop-storage/data/default/configs/application.ini中(https://github.com/pierre-alain-b/rainloop-nextcloud/blob/master/README.mrd)

[logs]
enable = On

————————————————

本文固定链接: https://www.eoowo.com/?p=1425 | 火星博客

该日志由 Rainer 于2021年11月23日发表在 淘宝 分类下, 你可以发表评论,并在保留原文地址及作者的情况下引用到你的网站或博客。
原创文章转载请注明: 企业网中nextcloud与iRedmail邮件系统的配合 | 火星博客

企业网中nextcloud与iRedmail邮件系统的配合:等您坐沙发呢!

发表评论

CAPTCHAis initialing...
快捷键:Ctrl+Enter