bennet0496/nextcloud_attachments

将大附件上传到Nextcloud并自动创建分享链接

安装: 253

依赖: 0

建议者: 0

安全: 0

星星: 4

关注者: 2

分支: 3

开放问题: 1

类型:roundcube-plugin

v1.4.2.2 2024-08-05 07:59 UTC

This package is auto-updated.

Last update: 2024-09-27 19:33:50 UTC


README

将大附件上传到Nextcloud并自动创建分享链接。当文件大小超过$config['max_message_size']/1.33时,将自动上传到配置的nextcloud服务器,并在电子邮件正文中创建链接。如果用户在Nextcloud中启用了2FA,插件将要求登录以创建应用程序密码。

此插件适用于用户在电子邮件和Nextcloud上具有相同登录名的环境,例如公司安装。

Screenshots

配置

插件本身有一些核心设置。服务器、用户名策略和子文件夹。

<?php
// Full URL to the Nextcloud server 
// e.g. https://example.com/nextcloud if in subpath
// or https://cloud.example.com if in root
$config["nextcloud_attachment_server"] = "";

// Username resolving strategy from internal Roundcube
// username which usually is the email address e.g. user@example.com or IMAP User
// Placeholders are replaced as following
// %s => verbatim RC username as reported by rcmail->get_user_name(). Depending on config loginuser@domain or login
// %i => username used to login to imap. usually equal to %s (since 1.3)
// %e => user email (since 1.3)
// %l, %u => email localpart (%u is for backward compatibility to <1.3) (since 1.3)
// %d => email domain (since 1.3)
// %h => IMAP Host (since 1.3)
$config["nextcloud_attachment_username"] = "%u";

// Name for the sub folder to upload to
// Defaults to "Mail Attachments"
// Can't be sub folder of sub folder like folder/sub
$config["nextcloud_attachment_folder"] = "Mail Attachments";

// Don't try the email password at all, because we know it won't work
// e.g. due to mandatory 2FA
// Defaults to false, i.e. try the password
// Since version 1.3
$config["nextcloud_attachment_dont_try_mail_password"] = false;

然而,它也依赖于通用配置

// Message size limit. Note that SMTP server(s) may use a different value.
// This limit is verified when user attaches files to a composed message.
// Size in bytes (possible unit suffix: K, M, G)
$config['max_message_size'] = '25M';

大于此大小的文件将/必须上传到Nextcloud,因此您应将其设置为所需值。通过以下两个附加选项,您可以控制插件的行为。是否像Google Mail一样自动,无需任何其他用户输入,还是像Outlook.com一样,当硬限制$config['max_message_size']达到时,通过软限制建议用户上传并强制执行

// Limit to show a warning at for large attachments.
// has to be smaller then $config['max_message_size']
// set to null to disable
$config["nextcloud_attachment_softlimit"] = "12M";

// Behavior if $config['max_message_size'] is hit.
// "prompt" to show dialog a la outlook or apple
// "upload" to automatically upload without asking a la google
// Defaults to "prompt"
$config["nextcloud_attachment_behavior"] = "prompt";

记住,您需要修改php.ini中的post_max_sizeupload_max_filesize以允许一般的大文件上传

启用插件时,请确保将其放在其他任何附件插件(如filesystem_attachments)之前。例如。

$config['plugins'] = array('nextcloud_attachments', /*...*/ 'filesystem_attachments', /*...*/ 'vcard_attachments' /*...*/);

Nextcloud暴力破解保护

默认情况下,此插件会检查是否可以使用邮件凭据进行Nextcloud登录。如果许多用户无法使用他们的邮件凭据登录Nextcloud,例如,由于2FA的广泛采用或大量用户被拒绝使用Nextcloud(通过LDAP组或类似方式),这不可避免地会导致Nextcloud锁定Roundcube服务器,因为它将这些登录视为暴力破解尝试。

从版本1.3开始,您可以禁用尝试邮件密码的行为

// Don't try the email password at all, because we know it won't work
// e.g. due to mandatory 2FA
// Defaults to false, i.e. try the password
// Since version 1.3
$config["nextcloud_attachment_dont_try_mail_password"] = false;

但是,您可能还希望考虑将您的Roundcube服务器添加到Nextcloud服务器的暴力破解允许列表中。为此,您必须启用暴力破解设置应用,然后作为管理员,在设置和安全中添加您的服务器IP到允许列表。

排除用户

您还可以排除用户与插件交互的能力,这在他们无法使用云服务、配额较小、无法共享链接或任何其他原因使他们无法共享文件链接时可能很有用。

有4种排除用户的方法。最简单的方法是直接排除列表

$config["nextcloud_attachment_exclude_users_in_addr_books"] = ["demo@example.com", "demouser"];

如果他们的IMAP(登录)用户名、电子邮件或映射用户名与列表中的条目匹配,他们将无法使用此插件(版本<1.3仅匹配登录用户名)。

其他3种策略(仅在版本 >=1.3 中可用)涉及使用地址簿,这本质上允许从LDAP检索状态。这很有用,因为这样就可以获取到谁可以在哪里登录的信息。第一种选择是排除在给定地址簿中列出其uid或电子邮件地址的任何用户,从而允许您创建一个(隐藏的)地址簿,以过滤那些不应使用插件的用户

$config["nextcloud_attachment_exclude_users_in_addr_books"] = ["nocloud"];

您可以通过设置全局配置中的隐藏值来创建一个隐藏的地址簿。

$config['ldap_public']['nocloud'] = array(
        'name'              => 'Nextcloud Denylist Book',
        'hosts'             => array('ldap.example.com'),
        'port'              => 389,
        'user_specific'     => false,
        'base_dn'           => 'ou=users,dc=example,dc=com',
        'hidden'            => true,
        'filter'            => '(&(objectClass=posixAccount)(mail=*)(cloudLogin=no))',
        'search_fields' => array(
                'mail',
                'cn',
                ),
        'name_field' => 'displayName',
        'email_field' => 'mail',
        'vlv' => true,
        'sort' => 'displayName',
        'fieldmap' => [
                 'email' => 'mail:*',
                 'uid' => 'uid'
        ]
);

第二种选择是排除地址簿中具有特定映射值的用户。如果您已经有了公共地址簿,则可以使用映射值而不是创建新的地址簿。这尤其适用于支持memberOf覆盖的目录服务器,它可以直接在用户条目中指示组成员资格,然而目前这可能与多值属性一起或不一起工作。

$config["nextcloud_attachment_exclude_users_with_addr_book_value"] = [["public", "memberOf", "cn=no_cloud,ou=groups,dc=example,dc=com"]];

如上图所示,使用fieldset添加映射值。

第三种选择是在为地址簿设置组映射时排除特定组中的用户。

$config["nextcloud_attachment_exclude_users_in_addr_book_group"] = [["public", "nocloud"]];

您可以在全局LDAP配置中设置组映射。

$config['ldap_public']['public'] = array(
        'name'              => 'Public LDAP Addressbook',
        'hosts'             => array('ldap.example.com'),
        'port'              => 389,
        'user_specific'     => false,
        'base_dn'           => 'ou=users,dc=example,dc=com',
        'bind_dn'           => '',
        'bind_pass'         => '',
        'filter'            => '(&(objectClass=posixAccount)(mail=*))',
        'groups'            => array(
                'base_dn'         => 'ou=groups,dc=example,dc=com',     // in this Howto, the same base_dn as for the contacts is used
                'filter'          => '(objectClass=posixGroup)',
                'object_classes'  => array("top", "posixGroup"),
                'member_attr'     => 'memberUid',
                'name_attr'       => 'cn',
                'scope'           => 'sub',
                ),
        'search_fields' => array(
                'mail',
                'cn',
                ),
        'name_field' => 'displayName',
        'email_field' => 'mail',
        'vlv' => true,
        'sort' => 'displayName',
        'fieldmap' => [
                    'name'        => 'displayName',
                    'surname'     => 'sn',
                    'firstname'   => 'givenName',
                    'jobtitle'    => 'loginShell',
                    'email'       => 'mail:*',
                    'phone:home'  => 'homePhone',
                    'phone:work'  => 'telephoneNumber',
                    'phone:mobile' => 'mobile',
                    'phone:pager' => 'pager',
                    'phone:workfax' => 'facsimileTelephoneNumber',
                    'street'      => 'street',
                    'zipcode'     => 'postalCode',
                    'region'      => 'st',
                    'locality'    => 'l',
                    // if you country is a complex object, you need to configure 'sub_fields' below
                    'country'      => 'c',
                    'organization' => 'o',
                    'department'   => 'ou',
                    'notes'        => 'description',
                    'photo'        => 'jpegPhoto',
                    // these currently don't work:
                    // 'manager'       => 'manager',
                    // 'assistant'     => 'secretary',
                    'uid' => 'uid'
        ]
);

计划功能

  • 为(附加)用户特定的Nextcloud服务器提供选项
  • 包装WebDAV请求以更容易适应其他服务器
  • 允许定义全局用户
  • 可翻译的附件模板
  • 翻译到更多语言
  • 将文件夹添加到sync-exclude.lst中,以防止桌面客户端(自动)下载文件夹

鸣谢