mirror of
https://github.com/mail-in-a-box/mailinabox.git
synced 2026-03-13 17:17:23 +01:00
Compare commits
69 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3314c4f7de | ||
|
|
1f60236985 | ||
|
|
32c68874c5 | ||
|
|
286a4bd9e7 | ||
|
|
ddf8e857fd | ||
|
|
4d5ff0210b | ||
|
|
89cd9fb611 | ||
|
|
22a6270657 | ||
|
|
0a970f4bb2 | ||
|
|
9b111e2493 | ||
|
|
b8feb77ef4 | ||
|
|
3c44604316 | ||
|
|
1e1a054686 | ||
|
|
d584a41e60 | ||
|
|
56074ae035 | ||
|
|
30631b0fc5 | ||
|
|
84da4e6000 | ||
|
|
58ded74181 | ||
|
|
3fd2e3efa9 | ||
|
|
7cda439c80 | ||
|
|
91fc74b408 | ||
|
|
d7244ed920 | ||
|
|
e0c0b5053c | ||
|
|
268b31685d | ||
|
|
ab71abbc7c | ||
|
|
87e6df9e28 | ||
|
|
558f2db31f | ||
|
|
c23dd701f0 | ||
|
|
0a7b9d5089 | ||
|
|
1eddf9a220 | ||
|
|
78d71498fa | ||
|
|
b41a0ad80e | ||
|
|
78569e9a88 | ||
|
|
8cb360fe36 | ||
|
|
f534a530d4 | ||
|
|
2abcafd670 | ||
|
|
3c3d62ac27 | ||
|
|
d829d74048 | ||
|
|
2aca421415 | ||
|
|
99474b348f | ||
|
|
8bebaf6a48 | ||
|
|
9004bb6e8e | ||
|
|
69d8fdef99 | ||
|
|
eeee712cf3 | ||
|
|
8f42d97b54 | ||
|
|
6e40c69cb5 | ||
|
|
c0e54f87d7 | ||
|
|
3a7de051ee | ||
|
|
f11cb04a72 | ||
|
|
cb564a130a | ||
|
|
d1d6318862 | ||
|
|
34b7a02f4f | ||
|
|
a312acc3bc | ||
|
|
aab1ec691c | ||
|
|
520caf6557 | ||
|
|
c92fd02262 | ||
|
|
a85c429a85 | ||
|
|
50a5cb90bc | ||
|
|
aac878dce5 | ||
|
|
58b0323b36 | ||
|
|
646f971d8b | ||
|
|
86067be142 | ||
|
|
c67ff241c4 | ||
|
|
7b4cd443bf | ||
|
|
34017548d5 | ||
|
|
65861c68b7 | ||
|
|
71a7a3e201 | ||
|
|
1c3bca53bb | ||
|
|
b643cb3478 |
91
CHANGELOG.md
91
CHANGELOG.md
@@ -1,17 +1,93 @@
|
|||||||
CHANGELOG
|
CHANGELOG
|
||||||
=========
|
=========
|
||||||
|
|
||||||
In Development
|
Version 60.1 (October 30, 2022)
|
||||||
--------------
|
-------------------------------
|
||||||
|
|
||||||
|
* A setup issue where the DNS server nsd isn't running at the end of setup is (hopefully) fixed.
|
||||||
|
* Nextcloud is updated to 23.0.10 (contacts to 4.2.2, calendar to 3.5.1).
|
||||||
|
|
||||||
|
Version 60 (October 11, 2022)
|
||||||
|
-----------------------------
|
||||||
|
|
||||||
|
This is the first release for Ubuntu 22.04.
|
||||||
|
|
||||||
|
**Before upgrading**, you must **first upgrade your existing Ubuntu 18.04 box to Mail-in-a-Box v0.51 or later**, if you haven't already done so. That may not be possible after Ubuntu 18.04 reaches its end of life in April 2023, so please complete the upgrade well before then. (If you are not using Nextcloud's contacts or calendar, you can migrate to the latest version of Mail-in-a-Box from any previous version.)
|
||||||
|
|
||||||
|
For complete upgrade instructions, see:
|
||||||
|
|
||||||
|
https://discourse.mailinabox.email/t/version-60-for-ubuntu-22-04-is-about-to-be-released/9558
|
||||||
|
|
||||||
|
No major features of Mail-in-a-Box have changed in this release, although some minor fixes were made.
|
||||||
|
|
||||||
|
With the newer version of Ubuntu the following software packages we use are updated:
|
||||||
|
|
||||||
|
* dovecot is upgraded to 2.3.16, postfix to 3.6.4, opendmark to 1.4 (which adds ARC-Authentication-Results headers), and spampd to 2.53 (alleviating a mail delivery rate limiting bug).
|
||||||
|
* Nextcloud is upgraded to 23.0.4 (contacts to 4.2.0, calendar to 3.5.0).
|
||||||
|
* Roundcube is upgraded to 1.6.0.
|
||||||
|
* certbot is upgraded to 1.21 (via the Ubuntu repository instead of a PPA).
|
||||||
|
* fail2ban is upgraded to 0.11.2.
|
||||||
|
* nginx is upgraded to 1.18.
|
||||||
|
* PHP is upgraded from 7.2 to 8.0.
|
||||||
|
|
||||||
|
Also:
|
||||||
|
|
||||||
|
* Roundcube's login session cookie was tightened. Existing sessions may require a manual logout.
|
||||||
|
* Moved Postgrey's database under $STORAGE_ROOT.
|
||||||
|
|
||||||
|
Version 57a (June 19, 2022)
|
||||||
|
---------------------------
|
||||||
|
|
||||||
|
* The Backblaze backups fix posted in Version 57 was incomplete. It's now fixed.
|
||||||
|
|
||||||
|
Version 57 (June 12, 2022)
|
||||||
|
--------------------------
|
||||||
|
|
||||||
|
Setup:
|
||||||
|
|
||||||
|
* Fixed issue upgrading from Mail-in-a-Box v0.40-v0.50 because of a changed URL that Nextcloud is downloaded from.
|
||||||
|
|
||||||
|
Backups:
|
||||||
|
|
||||||
|
* Fixed S3 backups which broke with duplicity 0.8.23.
|
||||||
|
* Fixed Backblaze backups which broke with latest b2sdk package by rolling back its version.
|
||||||
|
|
||||||
|
Control panel:
|
||||||
|
|
||||||
|
* Fixed spurious changes in system status checks messages by sorting DNSSEC DS records.
|
||||||
|
* Fixed fail2ban lockout over IPv6 from excessive loads of the system status checks.
|
||||||
|
* Fixed an incorrect IPv6 system status check message.
|
||||||
|
|
||||||
|
Version 56 (January 19, 2022)
|
||||||
|
-----------------------------
|
||||||
|
|
||||||
|
Software updates:
|
||||||
|
|
||||||
|
* Roundcube updated to 1.5.2 (from 1.5.0), and the persistent_login and CardDAV (to 4.3.0 from 3.0.3) plugins are updated.
|
||||||
|
* Nextcloud updated to 20.0.14 (from 20.0.8), contacts to 4.0.7 (from 3.5.1), and calendar to 3.0.4 (from 2.2.0).
|
||||||
|
|
||||||
|
Setup:
|
||||||
|
|
||||||
|
* Fixed failed setup if a previous attempt failed while updating Nextcloud.
|
||||||
|
|
||||||
|
Control panel:
|
||||||
|
|
||||||
|
* Fixed a crash if a custom DNS entry is not under a zone managed by the box.
|
||||||
|
* Fix DNSSEC instructions typo.
|
||||||
|
|
||||||
|
Other:
|
||||||
|
|
||||||
|
* Set systemd journald log retention to 10 days (from no limit) to reduce disk usage.
|
||||||
|
* Fixed log processing for submission lines that have a sasl_sender or other extra information.
|
||||||
|
* Fix DNS secondary nameserver refesh failure retry period.
|
||||||
|
|
||||||
|
Version 55 (October 18, 2021)
|
||||||
|
-----------------------------
|
||||||
|
|
||||||
Mail:
|
Mail:
|
||||||
|
|
||||||
* "SMTPUTF8" is now disabled in Postfix. Because Dovecot still does not support SMTPUTF8, incoming mail to internationalized addresses was bouncing. This fixes incoming mail to internationalized domains (which was probably working prior to v0.40), but it will prevent sending outbound mail to addresses with internationalized local-parts.
|
* "SMTPUTF8" is now disabled in Postfix. Because Dovecot still does not support SMTPUTF8, incoming mail to internationalized addresses was bouncing. This fixes incoming mail to internationalized domains (which was probably working prior to v0.40), but it will prevent sending outbound mail to addresses with internationalized local-parts.
|
||||||
* Upgraded to Roundcube 1.5 Release Candidate.
|
* Upgraded to Roundcube 1.5.
|
||||||
|
|
||||||
Firewall:
|
|
||||||
|
|
||||||
* Fail2ban's IPv6 support is enabled.
|
|
||||||
|
|
||||||
Control panel:
|
Control panel:
|
||||||
|
|
||||||
@@ -27,6 +103,7 @@ Control panel:
|
|||||||
|
|
||||||
Other:
|
Other:
|
||||||
|
|
||||||
|
* Fail2ban's IPv6 support is enabled.
|
||||||
* The mail log tool now doesn't crash if there are email addresess in log messages with invalid UTF-8 characters.
|
* The mail log tool now doesn't crash if there are email addresess in log messages with invalid UTF-8 characters.
|
||||||
* Additional nsd.conf files can be placed in /etc/nsd.conf.d.
|
* Additional nsd.conf files can be placed in /etc/nsd.conf.d.
|
||||||
|
|
||||||
|
|||||||
@@ -20,9 +20,9 @@ _If you're seeing an error message about your *IP address being listed in the Sp
|
|||||||
|
|
||||||
### Modifying your `hosts` file
|
### Modifying your `hosts` file
|
||||||
|
|
||||||
After a while, Mail-in-a-Box will be available at `192.168.50.4` (unless you changed that in your `Vagrantfile`). To be able to use the web-based bits, we recommend to add a hostname to your `hosts` file:
|
After a while, Mail-in-a-Box will be available at `192.168.56.4` (unless you changed that in your `Vagrantfile`). To be able to use the web-based bits, we recommend to add a hostname to your `hosts` file:
|
||||||
|
|
||||||
$ echo "192.168.50.4 mailinabox.lan" | sudo tee -a /etc/hosts
|
$ echo "192.168.56.4 mailinabox.lan" | sudo tee -a /etc/hosts
|
||||||
|
|
||||||
You should now be able to navigate to https://mailinabox.lan/admin using your browser. There should be an initial admin user with the name `me@mailinabox.lan` and the password `12345678`.
|
You should now be able to navigate to https://mailinabox.lan/admin using your browser. There should be an initial admin user with the name `me@mailinabox.lan` and the password `12345678`.
|
||||||
|
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ Additionally, this project has a [Code of Conduct](CODE_OF_CONDUCT.md), which su
|
|||||||
In The Box
|
In The Box
|
||||||
----------
|
----------
|
||||||
|
|
||||||
Mail-in-a-Box turns a fresh Ubuntu 18.04 LTS 64-bit machine into a working mail server by installing and configuring various components.
|
Mail-in-a-Box turns a fresh Ubuntu 22.04 LTS 64-bit machine into a working mail server by installing and configuring various components.
|
||||||
|
|
||||||
It is a one-click email appliance. There are no user-configurable setup options. It "just works."
|
It is a one-click email appliance. There are no user-configurable setup options. It "just works."
|
||||||
|
|
||||||
@@ -54,13 +54,13 @@ Installation
|
|||||||
|
|
||||||
See the [setup guide](https://mailinabox.email/guide.html) for detailed, user-friendly instructions.
|
See the [setup guide](https://mailinabox.email/guide.html) for detailed, user-friendly instructions.
|
||||||
|
|
||||||
For experts, start with a completely fresh (really, I mean it) Ubuntu 18.04 LTS 64-bit machine. On the machine...
|
For experts, start with a completely fresh (really, I mean it) Ubuntu 22.04 LTS 64-bit machine. On the machine...
|
||||||
|
|
||||||
Clone this repository and checkout the tag corresponding to the most recent release:
|
Clone this repository and checkout the tag corresponding to the most recent release:
|
||||||
|
|
||||||
$ git clone https://github.com/mail-in-a-box/mailinabox
|
$ git clone https://github.com/mail-in-a-box/mailinabox
|
||||||
$ cd mailinabox
|
$ cd mailinabox
|
||||||
$ git checkout v0.54
|
$ git checkout v60.1
|
||||||
|
|
||||||
Begin the installation.
|
Begin the installation.
|
||||||
|
|
||||||
|
|||||||
4
Vagrantfile
vendored
4
Vagrantfile
vendored
@@ -2,14 +2,14 @@
|
|||||||
# vi: set ft=ruby :
|
# vi: set ft=ruby :
|
||||||
|
|
||||||
Vagrant.configure("2") do |config|
|
Vagrant.configure("2") do |config|
|
||||||
config.vm.box = "ubuntu/bionic64"
|
config.vm.box = "ubuntu/jammy64"
|
||||||
|
|
||||||
# Network config: Since it's a mail server, the machine must be connected
|
# Network config: Since it's a mail server, the machine must be connected
|
||||||
# to the public web. However, we currently don't want to expose SSH since
|
# to the public web. However, we currently don't want to expose SSH since
|
||||||
# the machine's box will let anyone log into it. So instead we'll put the
|
# the machine's box will let anyone log into it. So instead we'll put the
|
||||||
# machine on a private network.
|
# machine on a private network.
|
||||||
config.vm.hostname = "mailinabox.lan"
|
config.vm.hostname = "mailinabox.lan"
|
||||||
config.vm.network "private_network", ip: "192.168.50.4"
|
config.vm.network "private_network", ip: "192.168.56.4"
|
||||||
|
|
||||||
config.vm.provision :shell, :inline => <<-SH
|
config.vm.provision :shell, :inline => <<-SH
|
||||||
# Set environment variables so that the setup script does
|
# Set environment variables so that the setup script does
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ paths:
|
|||||||
x-codeSamples:
|
x-codeSamples:
|
||||||
- lang: curl
|
- lang: curl
|
||||||
source: |
|
source: |
|
||||||
curl -X GET "https://{host}/admin/login" \
|
curl -X POST "https://{host}/admin/login" \
|
||||||
-u "<email>:<password>"
|
-u "<email>:<password>"
|
||||||
responses:
|
responses:
|
||||||
200:
|
200:
|
||||||
@@ -103,13 +103,15 @@ paths:
|
|||||||
x-codeSamples:
|
x-codeSamples:
|
||||||
- lang: curl
|
- lang: curl
|
||||||
source: |
|
source: |
|
||||||
curl -X GET "https://{host}/admin/logout" \
|
curl -X POST "https://{host}/admin/logout" \
|
||||||
-u "<email>:<session_key>"
|
-u "<email>:<session_key>"
|
||||||
responses:
|
responses:
|
||||||
200:
|
200:
|
||||||
description: Successful operation
|
description: Successful operation
|
||||||
content:
|
content:
|
||||||
application/json:
|
application/json:
|
||||||
|
schema:
|
||||||
|
$ref: '#/components/schemas/LogoutResponse'
|
||||||
/system/status:
|
/system/status:
|
||||||
post:
|
post:
|
||||||
tags:
|
tags:
|
||||||
@@ -1740,7 +1742,7 @@ paths:
|
|||||||
text/html:
|
text/html:
|
||||||
schema:
|
schema:
|
||||||
type: string
|
type: string
|
||||||
/mfa/enable/totp:
|
/mfa/totp/enable:
|
||||||
post:
|
post:
|
||||||
tags:
|
tags:
|
||||||
- MFA
|
- MFA
|
||||||
@@ -2723,3 +2725,8 @@ components:
|
|||||||
nullable: true
|
nullable: true
|
||||||
MfaDisableSuccessResponse:
|
MfaDisableSuccessResponse:
|
||||||
type: string
|
type: string
|
||||||
|
LogoutResponse:
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
status:
|
||||||
|
type: string
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
# Whitelist our own IP addresses. 127.0.0.1/8 is the default. But our status checks
|
# Whitelist our own IP addresses. 127.0.0.1/8 is the default. But our status checks
|
||||||
# ping services over the public interface so we should whitelist that address of
|
# ping services over the public interface so we should whitelist that address of
|
||||||
# ours too. The string is substituted during installation.
|
# ours too. The string is substituted during installation.
|
||||||
ignoreip = 127.0.0.1/8 PUBLIC_IP
|
ignoreip = 127.0.0.1/8 PUBLIC_IP ::1 PUBLIC_IPV6
|
||||||
|
|
||||||
[dovecot]
|
[dovecot]
|
||||||
enabled = true
|
enabled = true
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ After=multi-user.target
|
|||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
Type=idle
|
Type=idle
|
||||||
|
IgnoreSIGPIPE=False
|
||||||
ExecStart=/usr/local/lib/mailinabox/start
|
ExecStart=/usr/local/lib/mailinabox/start
|
||||||
|
|
||||||
[Install]
|
[Install]
|
||||||
|
|||||||
@@ -7,6 +7,6 @@
|
|||||||
## your own --- please do not ask for help from us.
|
## your own --- please do not ask for help from us.
|
||||||
|
|
||||||
upstream php-fpm {
|
upstream php-fpm {
|
||||||
server unix:/var/run/php/php7.2-fpm.sock;
|
server unix:/var/run/php/php8.0-fpm.sock;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -22,20 +22,8 @@ class AuthService:
|
|||||||
def init_system_api_key(self):
|
def init_system_api_key(self):
|
||||||
"""Write an API key to a local file so local processes can use the API"""
|
"""Write an API key to a local file so local processes can use the API"""
|
||||||
|
|
||||||
def create_file_with_mode(path, mode):
|
with open(self.key_path, 'r') as file:
|
||||||
# Based on answer by A-B-B: http://stackoverflow.com/a/15015748
|
self.key = file.read()
|
||||||
old_umask = os.umask(0)
|
|
||||||
try:
|
|
||||||
return os.fdopen(os.open(path, os.O_WRONLY | os.O_CREAT, mode), 'w')
|
|
||||||
finally:
|
|
||||||
os.umask(old_umask)
|
|
||||||
|
|
||||||
self.key = secrets.token_hex(32)
|
|
||||||
|
|
||||||
os.makedirs(os.path.dirname(self.key_path), exist_ok=True)
|
|
||||||
|
|
||||||
with create_file_with_mode(self.key_path, 0o640) as key_file:
|
|
||||||
key_file.write(self.key + '\n')
|
|
||||||
|
|
||||||
def authenticate(self, request, env, login_only=False, logout=False):
|
def authenticate(self, request, env, login_only=False, logout=False):
|
||||||
"""Test if the HTTP Authorization header's username matches the system key, a session key,
|
"""Test if the HTTP Authorization header's username matches the system key, a session key,
|
||||||
|
|||||||
@@ -12,12 +12,7 @@ import dateutil.parser, dateutil.relativedelta, dateutil.tz
|
|||||||
import rtyaml
|
import rtyaml
|
||||||
from exclusiveprocess import Lock
|
from exclusiveprocess import Lock
|
||||||
|
|
||||||
from utils import load_environment, shell, wait_for_service, fix_boto
|
from utils import load_environment, shell, wait_for_service
|
||||||
|
|
||||||
rsync_ssh_options = [
|
|
||||||
"--ssh-options= -i /root/.ssh/id_rsa_miab",
|
|
||||||
"--rsync-options= -e \"/usr/bin/ssh -oStrictHostKeyChecking=no -oBatchMode=yes -p 22 -i /root/.ssh/id_rsa_miab\"",
|
|
||||||
]
|
|
||||||
|
|
||||||
def backup_status(env):
|
def backup_status(env):
|
||||||
# If backups are dissbled, return no status.
|
# If backups are dissbled, return no status.
|
||||||
@@ -64,9 +59,9 @@ def backup_status(env):
|
|||||||
"--archive-dir", backup_cache_dir,
|
"--archive-dir", backup_cache_dir,
|
||||||
"--gpg-options", "--cipher-algo=AES256",
|
"--gpg-options", "--cipher-algo=AES256",
|
||||||
"--log-fd", "1",
|
"--log-fd", "1",
|
||||||
config["target"],
|
get_duplicity_target_url(config),
|
||||||
] + rsync_ssh_options,
|
] + get_duplicity_additional_args(env),
|
||||||
get_env(env),
|
get_duplicity_env_vars(env),
|
||||||
trap=True)
|
trap=True)
|
||||||
if code != 0:
|
if code != 0:
|
||||||
# Command failed. This is likely due to an improperly configured remote
|
# Command failed. This is likely due to an improperly configured remote
|
||||||
@@ -195,7 +190,43 @@ def get_passphrase(env):
|
|||||||
|
|
||||||
return passphrase
|
return passphrase
|
||||||
|
|
||||||
def get_env(env):
|
def get_duplicity_target_url(config):
|
||||||
|
target = config["target"]
|
||||||
|
|
||||||
|
if get_target_type(config) == "s3":
|
||||||
|
from urllib.parse import urlsplit, urlunsplit
|
||||||
|
target = list(urlsplit(target))
|
||||||
|
|
||||||
|
# Although we store the S3 hostname in the target URL,
|
||||||
|
# duplicity no longer accepts it in the target URL. The hostname in
|
||||||
|
# the target URL must be the bucket name. The hostname is passed
|
||||||
|
# via get_duplicity_additional_args. Move the first part of the
|
||||||
|
# path (the bucket name) into the hostname URL component, and leave
|
||||||
|
# the rest for the path.
|
||||||
|
target[1], target[2] = target[2].lstrip('/').split('/', 1)
|
||||||
|
|
||||||
|
target = urlunsplit(target)
|
||||||
|
|
||||||
|
return target
|
||||||
|
|
||||||
|
def get_duplicity_additional_args(env):
|
||||||
|
config = get_backup_config(env)
|
||||||
|
|
||||||
|
if get_target_type(config) == 'rsync':
|
||||||
|
return [
|
||||||
|
"--ssh-options= -i /root/.ssh/id_rsa_miab",
|
||||||
|
"--rsync-options= -e \"/usr/bin/ssh -oStrictHostKeyChecking=no -oBatchMode=yes -p 22 -i /root/.ssh/id_rsa_miab\"",
|
||||||
|
]
|
||||||
|
elif get_target_type(config) == 's3':
|
||||||
|
# See note about hostname in get_duplicity_target_url.
|
||||||
|
from urllib.parse import urlsplit, urlunsplit
|
||||||
|
target = urlsplit(config["target"])
|
||||||
|
endpoint_url = urlunsplit(("https", target.netloc, '', '', ''))
|
||||||
|
return ["--s3-endpoint-url", endpoint_url]
|
||||||
|
|
||||||
|
return []
|
||||||
|
|
||||||
|
def get_duplicity_env_vars(env):
|
||||||
config = get_backup_config(env)
|
config = get_backup_config(env)
|
||||||
|
|
||||||
env = { "PASSPHRASE" : get_passphrase(env) }
|
env = { "PASSPHRASE" : get_passphrase(env) }
|
||||||
@@ -247,9 +278,10 @@ def perform_backup(full_backup):
|
|||||||
if quit:
|
if quit:
|
||||||
sys.exit(code)
|
sys.exit(code)
|
||||||
|
|
||||||
service_command("php7.2-fpm", "stop", quit=True)
|
service_command("php8.0-fpm", "stop", quit=True)
|
||||||
service_command("postfix", "stop", quit=True)
|
service_command("postfix", "stop", quit=True)
|
||||||
service_command("dovecot", "stop", quit=True)
|
service_command("dovecot", "stop", quit=True)
|
||||||
|
service_command("postgrey", "stop", quit=True)
|
||||||
|
|
||||||
# Execute a pre-backup script that copies files outside the homedir.
|
# Execute a pre-backup script that copies files outside the homedir.
|
||||||
# Run as the STORAGE_USER user, not as root. Pass our settings in
|
# Run as the STORAGE_USER user, not as root. Pass our settings in
|
||||||
@@ -273,15 +305,16 @@ def perform_backup(full_backup):
|
|||||||
"--volsize", "250",
|
"--volsize", "250",
|
||||||
"--gpg-options", "--cipher-algo=AES256",
|
"--gpg-options", "--cipher-algo=AES256",
|
||||||
env["STORAGE_ROOT"],
|
env["STORAGE_ROOT"],
|
||||||
config["target"],
|
get_duplicity_target_url(config),
|
||||||
"--allow-source-mismatch"
|
"--allow-source-mismatch"
|
||||||
] + rsync_ssh_options,
|
] + get_duplicity_additional_args(env),
|
||||||
get_env(env))
|
get_duplicity_env_vars(env))
|
||||||
finally:
|
finally:
|
||||||
# Start services again.
|
# Start services again.
|
||||||
|
service_command("postgrey", "start", quit=False)
|
||||||
service_command("dovecot", "start", quit=False)
|
service_command("dovecot", "start", quit=False)
|
||||||
service_command("postfix", "start", quit=False)
|
service_command("postfix", "start", quit=False)
|
||||||
service_command("php7.2-fpm", "start", quit=False)
|
service_command("php8.0-fpm", "start", quit=False)
|
||||||
|
|
||||||
# Remove old backups. This deletes all backup data no longer needed
|
# Remove old backups. This deletes all backup data no longer needed
|
||||||
# from more than 3 days ago.
|
# from more than 3 days ago.
|
||||||
@@ -292,9 +325,9 @@ def perform_backup(full_backup):
|
|||||||
"--verbosity", "error",
|
"--verbosity", "error",
|
||||||
"--archive-dir", backup_cache_dir,
|
"--archive-dir", backup_cache_dir,
|
||||||
"--force",
|
"--force",
|
||||||
config["target"]
|
get_duplicity_target_url(config)
|
||||||
] + rsync_ssh_options,
|
] + get_duplicity_additional_args(env),
|
||||||
get_env(env))
|
get_duplicity_env_vars(env))
|
||||||
|
|
||||||
# From duplicity's manual:
|
# From duplicity's manual:
|
||||||
# "This should only be necessary after a duplicity session fails or is
|
# "This should only be necessary after a duplicity session fails or is
|
||||||
@@ -307,9 +340,9 @@ def perform_backup(full_backup):
|
|||||||
"--verbosity", "error",
|
"--verbosity", "error",
|
||||||
"--archive-dir", backup_cache_dir,
|
"--archive-dir", backup_cache_dir,
|
||||||
"--force",
|
"--force",
|
||||||
config["target"]
|
get_duplicity_target_url(config)
|
||||||
] + rsync_ssh_options,
|
] + get_duplicity_additional_args(env),
|
||||||
get_env(env))
|
get_duplicity_env_vars(env))
|
||||||
|
|
||||||
# Change ownership of backups to the user-data user, so that the after-bcakup
|
# Change ownership of backups to the user-data user, so that the after-bcakup
|
||||||
# script can access them.
|
# script can access them.
|
||||||
@@ -345,9 +378,9 @@ def run_duplicity_verification():
|
|||||||
"--compare-data",
|
"--compare-data",
|
||||||
"--archive-dir", backup_cache_dir,
|
"--archive-dir", backup_cache_dir,
|
||||||
"--exclude", backup_root,
|
"--exclude", backup_root,
|
||||||
config["target"],
|
get_duplicity_target_url(config),
|
||||||
env["STORAGE_ROOT"],
|
env["STORAGE_ROOT"],
|
||||||
] + rsync_ssh_options, get_env(env))
|
] + get_duplicity_additional_args(env), get_duplicity_env_vars(env))
|
||||||
|
|
||||||
def run_duplicity_restore(args):
|
def run_duplicity_restore(args):
|
||||||
env = load_environment()
|
env = load_environment()
|
||||||
@@ -357,9 +390,9 @@ def run_duplicity_restore(args):
|
|||||||
"/usr/bin/duplicity",
|
"/usr/bin/duplicity",
|
||||||
"restore",
|
"restore",
|
||||||
"--archive-dir", backup_cache_dir,
|
"--archive-dir", backup_cache_dir,
|
||||||
config["target"],
|
get_duplicity_target_url(config),
|
||||||
] + rsync_ssh_options + args,
|
] + get_duplicity_additional_args(env) + args,
|
||||||
get_env(env))
|
get_duplicity_env_vars(env))
|
||||||
|
|
||||||
def list_target_files(config):
|
def list_target_files(config):
|
||||||
import urllib.parse
|
import urllib.parse
|
||||||
@@ -415,26 +448,13 @@ def list_target_files(config):
|
|||||||
raise ValueError("Connection to rsync host failed: {}".format(reason))
|
raise ValueError("Connection to rsync host failed: {}".format(reason))
|
||||||
|
|
||||||
elif target.scheme == "s3":
|
elif target.scheme == "s3":
|
||||||
# match to a Region
|
import boto3.s3
|
||||||
fix_boto() # must call prior to importing boto
|
from botocore.exceptions import ClientError
|
||||||
import boto.s3
|
|
||||||
from boto.exception import BotoServerError
|
|
||||||
custom_region = False
|
|
||||||
for region in boto.s3.regions():
|
|
||||||
if region.endpoint == target.hostname:
|
|
||||||
break
|
|
||||||
else:
|
|
||||||
# If region is not found this is a custom region
|
|
||||||
custom_region = True
|
|
||||||
|
|
||||||
|
# separate bucket from path in target
|
||||||
bucket = target.path[1:].split('/')[0]
|
bucket = target.path[1:].split('/')[0]
|
||||||
path = '/'.join(target.path[1:].split('/')[1:]) + '/'
|
path = '/'.join(target.path[1:].split('/')[1:]) + '/'
|
||||||
|
|
||||||
# Create a custom region with custom endpoint
|
|
||||||
if custom_region:
|
|
||||||
from boto.s3.connection import S3Connection
|
|
||||||
region = boto.s3.S3RegionInfo(name=bucket, endpoint=target.hostname, connection_cls=S3Connection)
|
|
||||||
|
|
||||||
# If no prefix is specified, set the path to '', otherwise boto won't list the files
|
# If no prefix is specified, set the path to '', otherwise boto won't list the files
|
||||||
if path == '/':
|
if path == '/':
|
||||||
path = ''
|
path = ''
|
||||||
@@ -444,18 +464,15 @@ def list_target_files(config):
|
|||||||
|
|
||||||
# connect to the region & bucket
|
# connect to the region & bucket
|
||||||
try:
|
try:
|
||||||
conn = region.connect(aws_access_key_id=config["target_user"], aws_secret_access_key=config["target_pass"])
|
s3 = boto3.client('s3', \
|
||||||
bucket = conn.get_bucket(bucket)
|
endpoint_url=f'https://{target.hostname}', \
|
||||||
except BotoServerError as e:
|
aws_access_key_id=config['target_user'], \
|
||||||
if e.status == 403:
|
aws_secret_access_key=config['target_pass'])
|
||||||
raise ValueError("Invalid S3 access key or secret access key.")
|
bucket_objects = s3.list_objects_v2(Bucket=bucket, Prefix=path)['Contents']
|
||||||
elif e.status == 404:
|
backup_list = [(key['Key'][len(path):], key['Size']) for key in bucket_objects]
|
||||||
raise ValueError("Invalid S3 bucket name.")
|
except ClientError as e:
|
||||||
elif e.status == 301:
|
raise ValueError(e)
|
||||||
raise ValueError("Incorrect region for this bucket.")
|
return backup_list
|
||||||
raise ValueError(e.reason)
|
|
||||||
|
|
||||||
return [(key.name[len(path):], key.size) for key in bucket.list(prefix=path)]
|
|
||||||
elif target.scheme == 'b2':
|
elif target.scheme == 'b2':
|
||||||
from b2sdk.v1 import InMemoryAccountInfo, B2Api
|
from b2sdk.v1 import InMemoryAccountInfo, B2Api
|
||||||
from b2sdk.v1.exception import NonExistentBucket
|
from b2sdk.v1.exception import NonExistentBucket
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ import auth, utils
|
|||||||
from mailconfig import get_mail_users, get_mail_users_ex, get_admins, add_mail_user, set_mail_password, remove_mail_user
|
from mailconfig import get_mail_users, get_mail_users_ex, get_admins, add_mail_user, set_mail_password, remove_mail_user
|
||||||
from mailconfig import get_mail_user_privileges, add_remove_mail_user_privilege
|
from mailconfig import get_mail_user_privileges, add_remove_mail_user_privilege
|
||||||
from mailconfig import get_mail_aliases, get_mail_aliases_ex, get_mail_domains, add_mail_alias, remove_mail_alias
|
from mailconfig import get_mail_aliases, get_mail_aliases_ex, get_mail_domains, add_mail_alias, remove_mail_alias
|
||||||
from mfa import get_public_mfa_state, provision_totp, provision_webauthn, validate_totp_secret, enable_mfa, disable_mfa
|
from mfa import get_public_mfa_state, provision_totp, validate_totp_secret, enable_mfa, disable_mfa
|
||||||
|
|
||||||
env = utils.load_environment()
|
env = utils.load_environment()
|
||||||
|
|
||||||
@@ -121,9 +121,9 @@ def index():
|
|||||||
no_users_exist = (len(get_mail_users(env)) == 0)
|
no_users_exist = (len(get_mail_users(env)) == 0)
|
||||||
no_admins_exist = (len(get_admins(env)) == 0)
|
no_admins_exist = (len(get_admins(env)) == 0)
|
||||||
|
|
||||||
utils.fix_boto() # must call prior to importing boto
|
import boto3.s3
|
||||||
import boto.s3
|
backup_s3_hosts = [(r, f"s3.{r}.amazonaws.com") for r in boto3.session.Session().get_available_regions('s3')]
|
||||||
backup_s3_hosts = [(r.name, r.endpoint) for r in boto.s3.regions()]
|
|
||||||
|
|
||||||
return render_template('index.html',
|
return render_template('index.html',
|
||||||
hostname=env['PRIMARY_HOSTNAME'],
|
hostname=env['PRIMARY_HOSTNAME'],
|
||||||
@@ -330,7 +330,7 @@ def dns_get_records(qname=None, rtype=None):
|
|||||||
r["sort-order"]["created"] = i
|
r["sort-order"]["created"] = i
|
||||||
domain_sort_order = utils.sort_domains([r["qname"] for r in records], env)
|
domain_sort_order = utils.sort_domains([r["qname"] for r in records], env)
|
||||||
for i, r in enumerate(sorted(records, key = lambda r : (
|
for i, r in enumerate(sorted(records, key = lambda r : (
|
||||||
zones.index(r["zone"]),
|
zones.index(r["zone"]) if r.get("zone") else 0, # record is not within a zone managed by the box
|
||||||
domain_sort_order.index(r["qname"]),
|
domain_sort_order.index(r["qname"]),
|
||||||
r["rtype"]))):
|
r["rtype"]))):
|
||||||
r["sort-order"]["qname"] = i
|
r["sort-order"]["qname"] = i
|
||||||
@@ -468,7 +468,7 @@ def ssl_provision_certs():
|
|||||||
def mfa_get_status():
|
def mfa_get_status():
|
||||||
# Anyone accessing this route is an admin, and we permit them to
|
# Anyone accessing this route is an admin, and we permit them to
|
||||||
# see the MFA status for any user if they submit a 'user' form
|
# see the MFA status for any user if they submit a 'user' form
|
||||||
# field. But we don't always include provisioning info since a user can
|
# field. But we don't include provisioning info since a user can
|
||||||
# only provision for themselves.
|
# only provision for themselves.
|
||||||
email = request.form.get('user', request.user_email) # user field if given, otherwise the user making the request
|
email = request.form.get('user', request.user_email) # user field if given, otherwise the user making the request
|
||||||
try:
|
try:
|
||||||
@@ -478,15 +478,14 @@ def mfa_get_status():
|
|||||||
if email == request.user_email:
|
if email == request.user_email:
|
||||||
resp.update({
|
resp.update({
|
||||||
"new_mfa": {
|
"new_mfa": {
|
||||||
"totp": provision_totp(email, env),
|
"totp": provision_totp(email, env)
|
||||||
"webauthn": provision_webauthn(email, env)
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
except ValueError as e:
|
except ValueError as e:
|
||||||
return (str(e), 400)
|
return (str(e), 400)
|
||||||
return json_response(resp)
|
return json_response(resp)
|
||||||
|
|
||||||
@app.route('/mfa/enable/totp', methods=['POST'])
|
@app.route('/mfa/totp/enable', methods=['POST'])
|
||||||
@authorized_personnel_only
|
@authorized_personnel_only
|
||||||
def totp_post_enable():
|
def totp_post_enable():
|
||||||
secret = request.form.get('secret')
|
secret = request.form.get('secret')
|
||||||
@@ -496,20 +495,7 @@ def totp_post_enable():
|
|||||||
return ("Bad Input", 400)
|
return ("Bad Input", 400)
|
||||||
try:
|
try:
|
||||||
validate_totp_secret(secret)
|
validate_totp_secret(secret)
|
||||||
enable_mfa(request.user_email, "totp", env, secret, token, label)
|
enable_mfa(request.user_email, "totp", secret, token, label, env)
|
||||||
except ValueError as e:
|
|
||||||
return (str(e), 400)
|
|
||||||
return "OK"
|
|
||||||
|
|
||||||
@app.route('/mfa/enable/webauthn', methods=['POST'])
|
|
||||||
@authorized_personnel_only
|
|
||||||
def webauthn_post_enable():
|
|
||||||
attestationObject = request.form.get('attestationObject')
|
|
||||||
clientDataJSON = request.form.get('clientDataJSON')
|
|
||||||
if type(attestationObject) != str or type(clientDataJSON) != str:
|
|
||||||
return ("Bad Input", 400)
|
|
||||||
try:
|
|
||||||
enable_mfa(request.user_email, "webauthn", env, attestationObject, clientDataJSON)
|
|
||||||
except ValueError as e:
|
except ValueError as e:
|
||||||
return (str(e), 400)
|
return (str(e), 400)
|
||||||
return "OK"
|
return "OK"
|
||||||
@@ -585,6 +571,8 @@ def system_status():
|
|||||||
# Create a temporary pool of processes for the status checks
|
# Create a temporary pool of processes for the status checks
|
||||||
with multiprocessing.pool.Pool(processes=5) as pool:
|
with multiprocessing.pool.Pool(processes=5) as pool:
|
||||||
run_checks(False, env, output, pool)
|
run_checks(False, env, output, pool)
|
||||||
|
pool.close()
|
||||||
|
pool.join()
|
||||||
return json_response(output.items)
|
return json_response(output.items)
|
||||||
|
|
||||||
@app.route('/system/updates')
|
@app.route('/system/updates')
|
||||||
|
|||||||
@@ -96,8 +96,17 @@ def do_dns_update(env, force=False):
|
|||||||
if len(updated_domains) == 0:
|
if len(updated_domains) == 0:
|
||||||
updated_domains.append("DNS configuration")
|
updated_domains.append("DNS configuration")
|
||||||
|
|
||||||
# Kick nsd if anything changed.
|
# Tell nsd to reload changed zone files.
|
||||||
if len(updated_domains) > 0:
|
if len(updated_domains) > 0:
|
||||||
|
# 'reconfig' is needed if there are added or removed zones, but
|
||||||
|
# it may not reload existing zones, so we call 'reload' too. If
|
||||||
|
# nsd isn't running, nsd-control fails, so in that case revert
|
||||||
|
# to restarting nsd to make sure it is running. Restarting nsd
|
||||||
|
# should also refresh everything.
|
||||||
|
try:
|
||||||
|
shell('check_call', ["/usr/sbin/nsd-control", "reconfig"])
|
||||||
|
shell('check_call', ["/usr/sbin/nsd-control", "reload"])
|
||||||
|
except:
|
||||||
shell('check_call', ["/usr/sbin/service", "nsd", "restart"])
|
shell('check_call', ["/usr/sbin/service", "nsd", "restart"])
|
||||||
|
|
||||||
# Write the OpenDKIM configuration tables for all of the mail domains.
|
# Write the OpenDKIM configuration tables for all of the mail domains.
|
||||||
@@ -298,7 +307,7 @@ def build_zone(domain, domain_properties, additional_records, env, is_zone=True)
|
|||||||
# Append a DMARC record.
|
# Append a DMARC record.
|
||||||
# Skip if the user has set a DMARC record already.
|
# Skip if the user has set a DMARC record already.
|
||||||
if not has_rec("_dmarc", "TXT", prefix="v=DMARC1; "):
|
if not has_rec("_dmarc", "TXT", prefix="v=DMARC1; "):
|
||||||
records.append(("_dmarc", "TXT", 'v=DMARC1; p=quarantine', "Recommended. Specifies that mail that does not originate from the box but claims to be from @%s or which does not have a valid DKIM signature is suspect and should be quarantined by the recipient's mail system." % domain))
|
records.append(("_dmarc", "TXT", 'v=DMARC1; p=quarantine;', "Recommended. Specifies that mail that does not originate from the box but claims to be from @%s or which does not have a valid DKIM signature is suspect and should be quarantined by the recipient's mail system." % domain))
|
||||||
|
|
||||||
if domain_properties[domain]["user"]:
|
if domain_properties[domain]["user"]:
|
||||||
# Add CardDAV/CalDAV SRV records on the non-primary hostname that points to the primary hostname
|
# Add CardDAV/CalDAV SRV records on the non-primary hostname that points to the primary hostname
|
||||||
@@ -363,7 +372,7 @@ def build_zone(domain, domain_properties, additional_records, env, is_zone=True)
|
|||||||
if not has_rec(qname, "TXT", prefix="v=spf1 "):
|
if not has_rec(qname, "TXT", prefix="v=spf1 "):
|
||||||
records.append((qname, "TXT", 'v=spf1 -all', "Recommended. Prevents use of this domain name for outbound mail by specifying that no servers are valid sources for mail from @%s. If you do send email from this domain name you should either override this record such that the SPF rule does allow the originating server, or, take the recommended approach and have the box handle mail for this domain (simply add any receiving alias at this domain name to make this machine treat the domain name as one of its mail domains)." % d))
|
records.append((qname, "TXT", 'v=spf1 -all', "Recommended. Prevents use of this domain name for outbound mail by specifying that no servers are valid sources for mail from @%s. If you do send email from this domain name you should either override this record such that the SPF rule does allow the originating server, or, take the recommended approach and have the box handle mail for this domain (simply add any receiving alias at this domain name to make this machine treat the domain name as one of its mail domains)." % d))
|
||||||
if not has_rec("_dmarc" + ("."+qname if qname else ""), "TXT", prefix="v=DMARC1; "):
|
if not has_rec("_dmarc" + ("."+qname if qname else ""), "TXT", prefix="v=DMARC1; "):
|
||||||
records.append(("_dmarc" + ("."+qname if qname else ""), "TXT", 'v=DMARC1; p=reject', "Recommended. Prevents use of this domain name for outbound mail by specifying that the SPF rule should be honoured for mail from @%s." % d))
|
records.append(("_dmarc" + ("."+qname if qname else ""), "TXT", 'v=DMARC1; p=reject;', "Recommended. Prevents use of this domain name for outbound mail by specifying that the SPF rule should be honoured for mail from @%s." % d))
|
||||||
|
|
||||||
# And with a null MX record (https://explained-from-first-principles.com/email/#null-mx-record)
|
# And with a null MX record (https://explained-from-first-principles.com/email/#null-mx-record)
|
||||||
if not has_rec(qname, "MX"):
|
if not has_rec(qname, "MX"):
|
||||||
@@ -484,7 +493,7 @@ def write_nsd_zone(domain, zonefile, records, env, force):
|
|||||||
# @ the PRIMARY_HOSTNAME. Hopefully that's legit.
|
# @ the PRIMARY_HOSTNAME. Hopefully that's legit.
|
||||||
#
|
#
|
||||||
# For the refresh through TTL fields, a good reference is:
|
# For the refresh through TTL fields, a good reference is:
|
||||||
# http://www.peerwisdom.org/2013/05/15/dns-understanding-the-soa-record/
|
# https://www.ripe.net/publications/docs/ripe-203
|
||||||
#
|
#
|
||||||
# A hash of the available DNSSEC keys are added in a comment so that when
|
# A hash of the available DNSSEC keys are added in a comment so that when
|
||||||
# the keys change we force a re-generation of the zone which triggers
|
# the keys change we force a re-generation of the zone which triggers
|
||||||
@@ -497,7 +506,7 @@ $TTL 86400 ; default time to live
|
|||||||
@ IN SOA ns1.{primary_domain}. hostmaster.{primary_domain}. (
|
@ IN SOA ns1.{primary_domain}. hostmaster.{primary_domain}. (
|
||||||
__SERIAL__ ; serial number
|
__SERIAL__ ; serial number
|
||||||
7200 ; Refresh (secondary nameserver update interval)
|
7200 ; Refresh (secondary nameserver update interval)
|
||||||
86400 ; Retry (when refresh fails, how often to try again)
|
3600 ; Retry (when refresh fails, how often to try again, should be lower than the refresh)
|
||||||
1209600 ; Expire (when refresh fails, how long secondary nameserver will keep records around anyway)
|
1209600 ; Expire (when refresh fails, how long secondary nameserver will keep records around anyway)
|
||||||
86400 ; Negative TTL (how long negative responses are cached)
|
86400 ; Negative TTL (how long negative responses are cached)
|
||||||
)
|
)
|
||||||
@@ -1000,9 +1009,9 @@ def get_secondary_dns(custom_dns, mode=None):
|
|||||||
# doesn't.
|
# doesn't.
|
||||||
if not hostname.startswith("xfr:"):
|
if not hostname.startswith("xfr:"):
|
||||||
if mode == "xfr":
|
if mode == "xfr":
|
||||||
response = dns.resolver.query(hostname+'.', "A", raise_on_no_answer=False)
|
response = dns.resolver.resolve(hostname+'.', "A", raise_on_no_answer=False)
|
||||||
values.extend(map(str, response))
|
values.extend(map(str, response))
|
||||||
response = dns.resolver.query(hostname+'.', "AAAA", raise_on_no_answer=False)
|
response = dns.resolver.resolve(hostname+'.', "AAAA", raise_on_no_answer=False)
|
||||||
values.extend(map(str, response))
|
values.extend(map(str, response))
|
||||||
continue
|
continue
|
||||||
values.append(hostname)
|
values.append(hostname)
|
||||||
@@ -1025,10 +1034,10 @@ def set_secondary_dns(hostnames, env):
|
|||||||
if not item.startswith("xfr:"):
|
if not item.startswith("xfr:"):
|
||||||
# Resolve hostname.
|
# Resolve hostname.
|
||||||
try:
|
try:
|
||||||
response = resolver.query(item, "A")
|
response = resolver.resolve(item, "A")
|
||||||
except (dns.resolver.NoNameservers, dns.resolver.NXDOMAIN, dns.resolver.NoAnswer):
|
except (dns.resolver.NoNameservers, dns.resolver.NXDOMAIN, dns.resolver.NoAnswer):
|
||||||
try:
|
try:
|
||||||
response = resolver.query(item, "AAAA")
|
response = resolver.resolve(item, "AAAA")
|
||||||
except (dns.resolver.NoNameservers, dns.resolver.NXDOMAIN, dns.resolver.NoAnswer):
|
except (dns.resolver.NoNameservers, dns.resolver.NXDOMAIN, dns.resolver.NoAnswer):
|
||||||
raise ValueError("Could not resolve the IP address of %s." % item)
|
raise ValueError("Could not resolve the IP address of %s." % item)
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -549,8 +549,9 @@ def scan_postfix_submission_line(date, log, collector):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
# Match both the 'plain' and 'login' sasl methods, since both authentication methods are
|
# Match both the 'plain' and 'login' sasl methods, since both authentication methods are
|
||||||
# allowed by Dovecot
|
# allowed by Dovecot. Exclude trailing comma after the username when additional fields
|
||||||
m = re.match("([A-Z0-9]+): client=(\S+), sasl_method=(PLAIN|LOGIN), sasl_username=(\S+)", log)
|
# follow after.
|
||||||
|
m = re.match("([A-Z0-9]+): client=(\S+), sasl_method=(PLAIN|LOGIN), sasl_username=(\S+)(?<!,)", log)
|
||||||
|
|
||||||
if m:
|
if m:
|
||||||
_, client, method, user = m.groups()
|
_, client, method, user = m.groups()
|
||||||
|
|||||||
@@ -1,12 +1,9 @@
|
|||||||
import base64
|
import base64
|
||||||
import hmac
|
import hmac
|
||||||
import io
|
import io
|
||||||
import json
|
|
||||||
import os
|
import os
|
||||||
import pyotp
|
import pyotp
|
||||||
import qrcode
|
import qrcode
|
||||||
import pywarp
|
|
||||||
import pywarp.backends
|
|
||||||
|
|
||||||
from mailconfig import open_database
|
from mailconfig import open_database
|
||||||
|
|
||||||
@@ -32,44 +29,25 @@ def get_public_mfa_state(email, env):
|
|||||||
]
|
]
|
||||||
|
|
||||||
def get_hash_mfa_state(email, env):
|
def get_hash_mfa_state(email, env):
|
||||||
# Get the current MFA credential secrets from which we form a hash
|
mfa_state = get_mfa_state(email, env)
|
||||||
# so that we can reset user logins when any authentication information
|
return [
|
||||||
# changes.
|
{ "id": s["id"], "type": s["type"], "secret": s["secret"] }
|
||||||
mfa_state = []
|
for s in mfa_state
|
||||||
for s in get_mfa_state(email, env):
|
]
|
||||||
# Add TOTP id and secret to the state.
|
|
||||||
# Skip WebAuthn state if it's just a challenge.
|
|
||||||
if s["type"] == "webauthn":
|
|
||||||
try:
|
|
||||||
# Get the credential and only include it (not challenges) in the state.
|
|
||||||
s["secret"] = json.loads(s["secret"])["cred_pub_key"]
|
|
||||||
except:
|
|
||||||
# Skip this one --- there is no cred_pub_key.
|
|
||||||
continue
|
|
||||||
mfa_state.append({ "id": s["id"], "type": s["type"], "secret": s["secret"] })
|
|
||||||
return mfa_state
|
|
||||||
|
|
||||||
def enable_mfa(email, type, env, *args):
|
def enable_mfa(email, type, secret, token, label, env):
|
||||||
if type == "totp":
|
if type == "totp":
|
||||||
secret, token, label = args
|
|
||||||
validate_totp_secret(secret)
|
validate_totp_secret(secret)
|
||||||
# Sanity check with the provide current token.
|
# Sanity check with the provide current token.
|
||||||
totp = pyotp.TOTP(secret)
|
totp = pyotp.TOTP(secret)
|
||||||
if not totp.verify(token, valid_window=1):
|
if not totp.verify(token, valid_window=1):
|
||||||
raise ValueError("Invalid token.")
|
raise ValueError("Invalid token.")
|
||||||
conn, c = open_database(env, with_connection=True)
|
|
||||||
c.execute('INSERT INTO mfa (user_id, type, secret, label) VALUES (?, ?, ?, ?)', (get_user_id(email, c), type, secret, label))
|
|
||||||
conn.commit()
|
|
||||||
elif type == "webauthn":
|
|
||||||
attestationObject, clientDataJSON = args
|
|
||||||
rp = pywarp.RelyingPartyManager(
|
|
||||||
get_relying_party_name(env),
|
|
||||||
rp_id=env["PRIMARY_HOSTNAME"], # must match hostname the control panel is served from
|
|
||||||
credential_storage_backend=WebauthnStorageBackend(env))
|
|
||||||
rp.register(attestation_object=base64.b64decode(attestationObject), client_data_json=base64.b64decode(clientDataJSON), email=email.encode("utf8")) # encoding of email is a little funky here, pywarp calls .decode() with no args?
|
|
||||||
else:
|
else:
|
||||||
raise ValueError("Invalid MFA type.")
|
raise ValueError("Invalid MFA type.")
|
||||||
|
|
||||||
|
conn, c = open_database(env, with_connection=True)
|
||||||
|
c.execute('INSERT INTO mfa (user_id, type, secret, label) VALUES (?, ?, ?, ?)', (get_user_id(email, c), type, secret, label))
|
||||||
|
conn.commit()
|
||||||
|
|
||||||
def set_mru_token(email, mfa_id, token, env):
|
def set_mru_token(email, mfa_id, token, env):
|
||||||
conn, c = open_database(env, with_connection=True)
|
conn, c = open_database(env, with_connection=True)
|
||||||
@@ -93,9 +71,6 @@ def validate_totp_secret(secret):
|
|||||||
if len(secret) != 32:
|
if len(secret) != 32:
|
||||||
raise ValueError("Secret should be a 32 characters base32 string")
|
raise ValueError("Secret should be a 32 characters base32 string")
|
||||||
|
|
||||||
def get_relying_party_name(env):
|
|
||||||
return env["PRIMARY_HOSTNAME"] + " Mail-in-a-Box Control Panel"
|
|
||||||
|
|
||||||
def provision_totp(email, env):
|
def provision_totp(email, env):
|
||||||
# Make a new secret.
|
# Make a new secret.
|
||||||
secret = base64.b32encode(os.urandom(20)).decode('utf-8')
|
secret = base64.b32encode(os.urandom(20)).decode('utf-8')
|
||||||
@@ -104,7 +79,7 @@ def provision_totp(email, env):
|
|||||||
# Make a URI that we encode within a QR code.
|
# Make a URI that we encode within a QR code.
|
||||||
uri = pyotp.TOTP(secret).provisioning_uri(
|
uri = pyotp.TOTP(secret).provisioning_uri(
|
||||||
name=email,
|
name=email,
|
||||||
issuer_name=get_relying_party_name(env)
|
issuer_name=env["PRIMARY_HOSTNAME"] + " Mail-in-a-Box Control Panel"
|
||||||
)
|
)
|
||||||
|
|
||||||
# Generate a QR code as a base64-encode PNG image.
|
# Generate a QR code as a base64-encode PNG image.
|
||||||
@@ -119,55 +94,6 @@ def provision_totp(email, env):
|
|||||||
"qr_code_base64": png_b64
|
"qr_code_base64": png_b64
|
||||||
}
|
}
|
||||||
|
|
||||||
class WebauthnStorageBackend(pywarp.backends.CredentialStorageBackend):
|
|
||||||
def __init__(self, env):
|
|
||||||
self.env = env
|
|
||||||
def get_record(self, email, conn=None, c=None):
|
|
||||||
# Get an existing record and parse the 'secret' column as JSON.
|
|
||||||
if conn is None: conn, c = open_database(self.env, with_connection=True)
|
|
||||||
c.execute('SELECT secret FROM mfa WHERE user_id=? AND type="webauthn"', (get_user_id(email, c),))
|
|
||||||
config = c.fetchone()
|
|
||||||
if config:
|
|
||||||
try:
|
|
||||||
return json.loads(config[0])
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
return { }
|
|
||||||
def update_record(self, email, fields):
|
|
||||||
# Update the webauthn record in the database for this user by
|
|
||||||
# merging the fields with the existing fields in the database.
|
|
||||||
conn, c = open_database(self.env, with_connection=True)
|
|
||||||
config = self.get_record(email, conn=conn, c=c)
|
|
||||||
if config:
|
|
||||||
# Merge and update.
|
|
||||||
config.update(fields)
|
|
||||||
config = json.dumps(config)
|
|
||||||
c.execute('UPDATE mfa SET secret=? WHERE user_id=? AND type="webauthn"', (config, get_user_id(email, c),))
|
|
||||||
conn.commit()
|
|
||||||
return
|
|
||||||
|
|
||||||
# Either there's no existing webauthn record or it's corrupted. Delete any existing record.
|
|
||||||
# Then add a new record.
|
|
||||||
c.execute('DELETE FROM mfa WHERE user_id=? AND type="webauthn"', (get_user_id(email, c),))
|
|
||||||
c.execute('INSERT INTO mfa (user_id, type, secret, label) VALUES (?, ?, ?, ?)', (
|
|
||||||
get_user_id(email, c), "webauthn",
|
|
||||||
json.dumps(fields),
|
|
||||||
"WebAuthn"))
|
|
||||||
conn.commit()
|
|
||||||
def save_challenge_for_user(self, email, challenge, type):
|
|
||||||
self.update_record(email, { type + "challenge": base64.b64encode(challenge).decode("ascii") })
|
|
||||||
def get_challenge_for_user(self, email, type):
|
|
||||||
challenge = self.get_record(email).get(type + "challenge")
|
|
||||||
if challenge: challenge = base64.b64decode(challenge.encode("ascii"))
|
|
||||||
return challenge
|
|
||||||
|
|
||||||
def provision_webauthn(email, env):
|
|
||||||
rp = pywarp.RelyingPartyManager(
|
|
||||||
get_relying_party_name(env),
|
|
||||||
rp_id=env["PRIMARY_HOSTNAME"], # must match hostname the control panel is served from
|
|
||||||
credential_storage_backend=WebauthnStorageBackend(env))
|
|
||||||
return rp.get_registration_options(email=email)
|
|
||||||
|
|
||||||
def validate_auth_mfa(email, request, env):
|
def validate_auth_mfa(email, request, env):
|
||||||
# Validates that a login request satisfies any MFA modes
|
# Validates that a login request satisfies any MFA modes
|
||||||
# that have been enabled for the user's account. Returns
|
# that have been enabled for the user's account. Returns
|
||||||
|
|||||||
@@ -58,36 +58,33 @@ def get_ssl_certificates(env):
|
|||||||
# Not a valid PEM format for a PEM type we care about.
|
# Not a valid PEM format for a PEM type we care about.
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# Remember where we got this object.
|
|
||||||
pem._filename = fn
|
|
||||||
|
|
||||||
# Is it a private key?
|
# Is it a private key?
|
||||||
if isinstance(pem, RSAPrivateKey):
|
if isinstance(pem, RSAPrivateKey):
|
||||||
private_keys[pem.public_key().public_numbers()] = pem
|
private_keys[pem.public_key().public_numbers()] = { "filename": fn, "key": pem }
|
||||||
|
|
||||||
# Is it a certificate?
|
# Is it a certificate?
|
||||||
if isinstance(pem, Certificate):
|
if isinstance(pem, Certificate):
|
||||||
certificates.append(pem)
|
certificates.append({ "filename": fn, "cert": pem })
|
||||||
|
|
||||||
# Process the certificates.
|
# Process the certificates.
|
||||||
domains = { }
|
domains = { }
|
||||||
for cert in certificates:
|
for cert in certificates:
|
||||||
# What domains is this certificate good for?
|
# What domains is this certificate good for?
|
||||||
cert_domains, primary_domain = get_certificate_domains(cert)
|
cert_domains, primary_domain = get_certificate_domains(cert["cert"])
|
||||||
cert._primary_domain = primary_domain
|
cert["primary_domain"] = primary_domain
|
||||||
|
|
||||||
# Is there a private key file for this certificate?
|
# Is there a private key file for this certificate?
|
||||||
private_key = private_keys.get(cert.public_key().public_numbers())
|
private_key = private_keys.get(cert["cert"].public_key().public_numbers())
|
||||||
if not private_key:
|
if not private_key:
|
||||||
continue
|
continue
|
||||||
cert._private_key = private_key
|
cert["private_key"] = private_key
|
||||||
|
|
||||||
# Add this cert to the list of certs usable for the domains.
|
# Add this cert to the list of certs usable for the domains.
|
||||||
for domain in cert_domains:
|
for domain in cert_domains:
|
||||||
# The primary hostname can only use a certificate mapped
|
# The primary hostname can only use a certificate mapped
|
||||||
# to the system private key.
|
# to the system private key.
|
||||||
if domain == env['PRIMARY_HOSTNAME']:
|
if domain == env['PRIMARY_HOSTNAME']:
|
||||||
if cert._private_key._filename != os.path.join(env['STORAGE_ROOT'], 'ssl', 'ssl_private_key.pem'):
|
if cert["private_key"]["filename"] != os.path.join(env['STORAGE_ROOT'], 'ssl', 'ssl_private_key.pem'):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
domains.setdefault(domain, []).append(cert)
|
domains.setdefault(domain, []).append(cert)
|
||||||
@@ -100,10 +97,10 @@ def get_ssl_certificates(env):
|
|||||||
#for c in cert_list: print(domain, c.not_valid_before, c.not_valid_after, "("+str(now)+")", c.issuer, c.subject, c._filename)
|
#for c in cert_list: print(domain, c.not_valid_before, c.not_valid_after, "("+str(now)+")", c.issuer, c.subject, c._filename)
|
||||||
cert_list.sort(key = lambda cert : (
|
cert_list.sort(key = lambda cert : (
|
||||||
# must be valid NOW
|
# must be valid NOW
|
||||||
cert.not_valid_before <= now <= cert.not_valid_after,
|
cert["cert"].not_valid_before <= now <= cert["cert"].not_valid_after,
|
||||||
|
|
||||||
# prefer one that is not self-signed
|
# prefer one that is not self-signed
|
||||||
cert.issuer != cert.subject,
|
cert["cert"].issuer != cert["cert"].subject,
|
||||||
|
|
||||||
###########################################################
|
###########################################################
|
||||||
# The above lines ensure that valid certificates are chosen
|
# The above lines ensure that valid certificates are chosen
|
||||||
@@ -113,7 +110,7 @@ def get_ssl_certificates(env):
|
|||||||
|
|
||||||
# prefer one with the expiration furthest into the future so
|
# prefer one with the expiration furthest into the future so
|
||||||
# that we can easily rotate to new certs as we get them
|
# that we can easily rotate to new certs as we get them
|
||||||
cert.not_valid_after,
|
cert["cert"].not_valid_after,
|
||||||
|
|
||||||
###########################################################
|
###########################################################
|
||||||
# We always choose the certificate that is good for the
|
# We always choose the certificate that is good for the
|
||||||
@@ -128,15 +125,15 @@ def get_ssl_certificates(env):
|
|||||||
|
|
||||||
# in case a certificate is installed in multiple paths,
|
# in case a certificate is installed in multiple paths,
|
||||||
# prefer the... lexicographically last one?
|
# prefer the... lexicographically last one?
|
||||||
cert._filename,
|
cert["filename"],
|
||||||
|
|
||||||
), reverse=True)
|
), reverse=True)
|
||||||
cert = cert_list.pop(0)
|
cert = cert_list.pop(0)
|
||||||
ret[domain] = {
|
ret[domain] = {
|
||||||
"private-key": cert._private_key._filename,
|
"private-key": cert["private_key"]["filename"],
|
||||||
"certificate": cert._filename,
|
"certificate": cert["filename"],
|
||||||
"primary-domain": cert._primary_domain,
|
"primary-domain": cert["primary_domain"],
|
||||||
"certificate_object": cert,
|
"certificate_object": cert["cert"],
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret
|
return ret
|
||||||
|
|||||||
@@ -135,7 +135,7 @@ def check_service(i, service, env):
|
|||||||
|
|
||||||
# IPv4 ok but IPv6 failed. Try the PRIVATE_IPV6 address to see if the service is bound to the interface.
|
# IPv4 ok but IPv6 failed. Try the PRIVATE_IPV6 address to see if the service is bound to the interface.
|
||||||
elif service["port"] != 53 and try_connect(env["PRIVATE_IPV6"]):
|
elif service["port"] != 53 and try_connect(env["PRIVATE_IPV6"]):
|
||||||
output.print_error("%s is running (and available over IPv4 and the local IPv6 address), but it is not publicly accessible at %s:%d." % (service['name'], env['PUBLIC_IP'], service['port']))
|
output.print_error("%s is running (and available over IPv4 and the local IPv6 address), but it is not publicly accessible at %s:%d." % (service['name'], env['PUBLIC_IPV6'], service['port']))
|
||||||
else:
|
else:
|
||||||
output.print_error("%s is running and available over IPv4 but is not accessible over IPv6 at %s port %d." % (service['name'], env['PUBLIC_IPV6'], service['port']))
|
output.print_error("%s is running and available over IPv4 but is not accessible over IPv6 at %s port %d." % (service['name'], env['PUBLIC_IPV6'], service['port']))
|
||||||
|
|
||||||
@@ -253,6 +253,18 @@ def check_free_disk_space(rounded_values, env, output):
|
|||||||
if rounded_values: disk_msg = "The disk has less than 15% free space."
|
if rounded_values: disk_msg = "The disk has less than 15% free space."
|
||||||
output.print_error(disk_msg)
|
output.print_error(disk_msg)
|
||||||
|
|
||||||
|
# Check that there's only one duplicity cache. If there's more than one,
|
||||||
|
# it's probably no longer in use, and we can recommend clearing the cache
|
||||||
|
# to save space. The cache directory may not exist yet, which is OK.
|
||||||
|
backup_cache_path = os.path.join(env['STORAGE_ROOT'], 'backup/cache')
|
||||||
|
try:
|
||||||
|
backup_cache_count = len(os.listdir(backup_cache_path))
|
||||||
|
except:
|
||||||
|
backup_cache_count = 0
|
||||||
|
if backup_cache_count > 1:
|
||||||
|
output.print_warning("The backup cache directory {} has more than one backup target cache. Consider clearing this directory to save disk space."
|
||||||
|
.format(backup_cache_path))
|
||||||
|
|
||||||
def check_free_memory(rounded_values, env, output):
|
def check_free_memory(rounded_values, env, output):
|
||||||
# Check free memory.
|
# Check free memory.
|
||||||
percent_free = 100 - psutil.virtual_memory().percent
|
percent_free = 100 - psutil.virtual_memory().percent
|
||||||
@@ -646,7 +658,7 @@ def check_dnssec(domain, env, output, dns_zonefiles, is_checking_primary=False):
|
|||||||
output.print_line("Option " + str(i+1) + ":")
|
output.print_line("Option " + str(i+1) + ":")
|
||||||
output.print_line("----------")
|
output.print_line("----------")
|
||||||
output.print_line("Key Tag: " + ds_suggestion['keytag'])
|
output.print_line("Key Tag: " + ds_suggestion['keytag'])
|
||||||
output.print_line("Key Flags: KSK (256)")
|
output.print_line("Key Flags: KSK / 257")
|
||||||
output.print_line("Algorithm: %s / %s" % (ds_suggestion['alg'], ds_suggestion['alg_name']))
|
output.print_line("Algorithm: %s / %s" % (ds_suggestion['alg'], ds_suggestion['alg_name']))
|
||||||
output.print_line("Digest Type: %s / %s" % (ds_suggestion['digalg'], ds_suggestion['digalg_name']))
|
output.print_line("Digest Type: %s / %s" % (ds_suggestion['digalg'], ds_suggestion['digalg_name']))
|
||||||
output.print_line("Digest: " + ds_suggestion['digest'])
|
output.print_line("Digest: " + ds_suggestion['digest'])
|
||||||
@@ -658,7 +670,7 @@ def check_dnssec(domain, env, output, dns_zonefiles, is_checking_primary=False):
|
|||||||
if len(ds) > 0:
|
if len(ds) > 0:
|
||||||
output.print_line("")
|
output.print_line("")
|
||||||
output.print_line("The DS record is currently set to:")
|
output.print_line("The DS record is currently set to:")
|
||||||
for rr in ds:
|
for rr in sorted(ds):
|
||||||
output.print_line("Key Tag: {0}, Algorithm: {1}, Digest Type: {2}, Digest: {3}".format(*rr))
|
output.print_line("Key Tag: {0}, Algorithm: {1}, Digest Type: {2}, Digest: {3}".format(*rr))
|
||||||
|
|
||||||
def check_mail_domain(domain, env, output):
|
def check_mail_domain(domain, env, output):
|
||||||
@@ -703,7 +715,7 @@ def check_mail_domain(domain, env, output):
|
|||||||
output.print_ok(good_news)
|
output.print_ok(good_news)
|
||||||
|
|
||||||
# Check MTA-STS policy.
|
# Check MTA-STS policy.
|
||||||
loop = asyncio.get_event_loop()
|
loop = asyncio.new_event_loop()
|
||||||
sts_resolver = postfix_mta_sts_resolver.resolver.STSResolver(loop=loop)
|
sts_resolver = postfix_mta_sts_resolver.resolver.STSResolver(loop=loop)
|
||||||
valid, policy = loop.run_until_complete(sts_resolver.resolve(domain))
|
valid, policy = loop.run_until_complete(sts_resolver.resolve(domain))
|
||||||
if valid == postfix_mta_sts_resolver.resolver.STSFetchResult.VALID:
|
if valid == postfix_mta_sts_resolver.resolver.STSFetchResult.VALID:
|
||||||
@@ -785,7 +797,7 @@ def query_dns(qname, rtype, nxdomain='[Not Set]', at=None, as_list=False):
|
|||||||
|
|
||||||
# Do the query.
|
# Do the query.
|
||||||
try:
|
try:
|
||||||
response = resolver.query(qname, rtype)
|
response = resolver.resolve(qname, rtype)
|
||||||
except (dns.resolver.NoNameservers, dns.resolver.NXDOMAIN, dns.resolver.NoAnswer):
|
except (dns.resolver.NoNameservers, dns.resolver.NXDOMAIN, dns.resolver.NoAnswer):
|
||||||
# Host did not have an answer for this query; not sure what the
|
# Host did not have an answer for this query; not sure what the
|
||||||
# difference is between the two exceptions.
|
# difference is between the two exceptions.
|
||||||
|
|||||||
@@ -38,7 +38,7 @@
|
|||||||
<p class="alert" role="alert">
|
<p class="alert" role="alert">
|
||||||
<span class="glyphicon glyphicon-info-sign"></span>
|
<span class="glyphicon glyphicon-info-sign"></span>
|
||||||
You may encounter zone file errors when attempting to create a TXT record with a long string.
|
You may encounter zone file errors when attempting to create a TXT record with a long string.
|
||||||
<a href="http://tools.ietf.org/html/rfc4408#section-3.1.3">RFC 4408</a> states a TXT record is allowed to contain multiple strings, and this technique can be used to construct records that would exceed the 255-byte maximum length.
|
<a href="https://tools.ietf.org/html/rfc4408#section-3.1.3">RFC 4408</a> states a TXT record is allowed to contain multiple strings, and this technique can be used to construct records that would exceed the 255-byte maximum length.
|
||||||
You may need to adopt this technique when adding DomainKeys. Use a tool like <code>named-checkzone</code> to validate your zone file.
|
You may need to adopt this technique when adding DomainKeys. Use a tool like <code>named-checkzone</code> to validate your zone file.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,34 @@
|
|||||||
<style>
|
<style>
|
||||||
|
.twofactor #totp-setup,
|
||||||
|
.twofactor #disable-2fa,
|
||||||
|
.twofactor #output-2fa {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.twofactor.loaded .loading-indicator {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.twofactor.disabled #disable-2fa,
|
||||||
|
.twofactor.enabled #totp-setup {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.twofactor.disabled #totp-setup,
|
||||||
|
.twofactor.enabled #disable-2fa {
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
|
||||||
.twofactor #totp-setup-qr img {
|
.twofactor #totp-setup-qr img {
|
||||||
display: block;
|
display: block;
|
||||||
width: 256px;
|
width: 256px;
|
||||||
max-width: 100%;
|
max-width: 100%;
|
||||||
height: auto;
|
height: auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.twofactor #output-2fa.visible {
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<h2>Two-Factor Authentication</h2>
|
<h2>Two-Factor Authentication</h2>
|
||||||
@@ -27,11 +51,10 @@ and ensure every administrator account for this control panel does the same.</st
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="twofactor">
|
<div class="twofactor">
|
||||||
<div id="mfa-devices">
|
<div class="loading-indicator">Loading...</div>
|
||||||
</div>
|
|
||||||
|
|
||||||
<form id="totp-setup" style="display: none">
|
<form id="totp-setup">
|
||||||
<h3>Add a TOTP Device</h3>
|
<h3>Setup Instructions</h3>
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<p>1. Install <a href="https://freeotp.github.io/">FreeOTP</a> or <a href="https://www.pcworld.com/article/3225913/what-is-two-factor-authentication-and-which-2fa-apps-are-best.html">any
|
<p>1. Install <a href="https://freeotp.github.io/">FreeOTP</a> or <a href="https://www.pcworld.com/article/3225913/what-is-two-factor-authentication-and-which-2fa-apps-are-best.html">any
|
||||||
@@ -62,32 +85,24 @@ and ensure every administrator account for this control panel does the same.</st
|
|||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
<form id="webauthn-setup" style="display: none">
|
<form id="disable-2fa">
|
||||||
<h3>Add a WebAuthn Device</h3>
|
|
||||||
<p>If you have a WebAuthn device such as a YubiKey, plug it in and click Add WebAuthn Device.</p>
|
|
||||||
<button type="submit" class="btn" onclick="return do_enable_webauthn()">Add WebAuthn Device</button>
|
|
||||||
</form>
|
|
||||||
|
|
||||||
<div id="webauthn-setup" style="display: none">
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div id="output-2fa" class="panel panel-danger hidden">
|
|
||||||
<div class="panel-body"></div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div id="mfa-device-templates" style="display: none">
|
|
||||||
<form class="totp" style="margin: 1em 0; border: 1px solid #AAA; padding: 10px;">
|
|
||||||
<p>Two-factor authentication is active for your account<span class="mfa-device-label"></span>.</p>
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<button type="submit" class="btn btn-danger">Disable TOTP Device</button>
|
<p>Two-factor authentication is active for your account<span id="mfa-device-label"></span>.</p>
|
||||||
|
<p>You will have to log into the admin panel again after disabling two-factor authentication.</p>
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<button type="submit" class="btn btn-danger">Disable Two-Factor Authentication</button>
|
||||||
</div>
|
</div>
|
||||||
<p style="margin-bottom: 0">You will have to log into the admin panel again after disabling two-factor authentication.</p>
|
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
|
<div id="output-2fa" class="panel panel-danger">
|
||||||
|
<div class="panel-body"></div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
var el = {
|
var el = {
|
||||||
|
disableForm: document.getElementById('disable-2fa'),
|
||||||
output: document.getElementById('output-2fa'),
|
output: document.getElementById('output-2fa'),
|
||||||
totpSetupForm: document.getElementById('totp-setup'),
|
totpSetupForm: document.getElementById('totp-setup'),
|
||||||
totpSetupToken: document.getElementById('totp-setup-token'),
|
totpSetupToken: document.getElementById('totp-setup-token'),
|
||||||
@@ -95,7 +110,6 @@ and ensure every administrator account for this control panel does the same.</st
|
|||||||
totpSetupLabel: document.getElementById('totp-setup-label'),
|
totpSetupLabel: document.getElementById('totp-setup-label'),
|
||||||
totpQr: document.getElementById('totp-setup-qr'),
|
totpQr: document.getElementById('totp-setup-qr'),
|
||||||
totpSetupSubmit: document.querySelector('#totp-setup-submit'),
|
totpSetupSubmit: document.querySelector('#totp-setup-submit'),
|
||||||
webauthnSetupForm: document.getElementById('webauthn-setup'),
|
|
||||||
wrapper: document.querySelector('.twofactor')
|
wrapper: document.querySelector('.twofactor')
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -116,8 +130,6 @@ and ensure every administrator account for this control panel does the same.</st
|
|||||||
}
|
}
|
||||||
|
|
||||||
function render_totp_setup(provisioned_totp) {
|
function render_totp_setup(provisioned_totp) {
|
||||||
$(el.totpSetupForm).show();
|
|
||||||
|
|
||||||
var img = document.createElement('img');
|
var img = document.createElement('img');
|
||||||
img.src = "data:image/png;base64," + provisioned_totp.qr_code_base64;
|
img.src = "data:image/png;base64," + provisioned_totp.qr_code_base64;
|
||||||
|
|
||||||
@@ -135,50 +147,38 @@ and ensure every administrator account for this control panel does the same.</st
|
|||||||
el.wrapper.classList.add('disabled');
|
el.wrapper.classList.add('disabled');
|
||||||
}
|
}
|
||||||
|
|
||||||
function arrayBufferToBase64(a) { return btoa(String.fromCharCode(...new Uint8Array(a))); }
|
|
||||||
function base64ToArrayBuffer(b) { return Uint8Array.from(atob(b), c => c.charCodeAt(0)); }
|
|
||||||
|
|
||||||
function render_webauthn_setup(provisioning) {
|
|
||||||
$(el.webauthnSetupForm).show();
|
|
||||||
provisioning.challenge = base64ToArrayBuffer(provisioning.challenge);
|
|
||||||
provisioning.user.id = new TextEncoder().encode(provisioning.user.name);
|
|
||||||
window.mailinabix_mfa_webauthn_provision = provisioning;
|
|
||||||
}
|
|
||||||
|
|
||||||
function render_disable(mfa) {
|
function render_disable(mfa) {
|
||||||
var panel = $('#mfa-device-templates .' + mfa.type).clone();
|
el.disableForm.addEventListener('submit', do_disable);
|
||||||
$('#mfa-devices').append(panel);
|
el.wrapper.classList.add('enabled');
|
||||||
panel.attr('data-mfa-id', mfa.id);
|
|
||||||
panel.on('submit', do_disable);
|
|
||||||
if (mfa.label)
|
if (mfa.label)
|
||||||
panel.find(".mfa-device-label").text(" on device '" + mfa.label + "'");
|
$("#mfa-device-label").text(" on device '" + mfa.label + "'");
|
||||||
}
|
}
|
||||||
|
|
||||||
function hide_error() {
|
function hide_error() {
|
||||||
el.output.querySelector('.panel-body').innerHTML = '';
|
el.output.querySelector('.panel-body').innerHTML = '';
|
||||||
el.output.classList.add('hidden');
|
el.output.classList.remove('visible');
|
||||||
}
|
}
|
||||||
|
|
||||||
function render_error(msg) {
|
function render_error(msg) {
|
||||||
el.output.querySelector('.panel-body').innerHTML = msg;
|
el.output.querySelector('.panel-body').innerHTML = msg;
|
||||||
el.output.classList.remove('hidden');
|
el.output.classList.add('visible');
|
||||||
}
|
}
|
||||||
|
|
||||||
function reset_view() {
|
function reset_view() {
|
||||||
el.wrapper.classList.remove('loaded', 'disabled', 'enabled');
|
el.wrapper.classList.remove('loaded', 'disabled', 'enabled');
|
||||||
$('#mfa-devices > *').remove();
|
|
||||||
|
el.disableForm.removeEventListener('submit', do_disable);
|
||||||
|
|
||||||
hide_error();
|
hide_error();
|
||||||
|
|
||||||
$(el.totpSetupForm).hide();
|
|
||||||
el.totpSetupForm.reset();
|
el.totpSetupForm.reset();
|
||||||
el.totpSetupForm.removeEventListener('submit', do_enable_totp);
|
el.totpSetupForm.removeEventListener('submit', do_enable_totp);
|
||||||
|
|
||||||
el.totpSetupSecret.setAttribute('value', '');
|
el.totpSetupSecret.setAttribute('value', '');
|
||||||
el.totpSetupToken.removeEventListener('input', update_setup_disabled);
|
el.totpSetupToken.removeEventListener('input', update_setup_disabled);
|
||||||
|
|
||||||
el.totpSetupSubmit.setAttribute('disabled', '');
|
el.totpSetupSubmit.setAttribute('disabled', '');
|
||||||
el.totpQr.innerHTML = '';
|
el.totpQr.innerHTML = '';
|
||||||
|
|
||||||
$(el.webauthnSetupForm).hide();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function show_mfa() {
|
function show_mfa() {
|
||||||
@@ -191,16 +191,16 @@ and ensure every administrator account for this control panel does the same.</st
|
|||||||
function(res) {
|
function(res) {
|
||||||
el.wrapper.classList.add('loaded');
|
el.wrapper.classList.add('loaded');
|
||||||
|
|
||||||
|
var has_mfa = false;
|
||||||
res.enabled_mfa.forEach(function(mfa) {
|
res.enabled_mfa.forEach(function(mfa) {
|
||||||
if (mfa.type == "totp") {
|
if (mfa.type == "totp") {
|
||||||
render_disable(mfa);
|
render_disable(mfa);
|
||||||
|
has_mfa = true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (res.new_mfa.totp)
|
if (!has_mfa)
|
||||||
render_totp_setup(res.new_mfa.totp);
|
render_totp_setup(res.new_mfa.totp);
|
||||||
if (res.new_mfa.webauthn && 'credentials' in navigator)
|
|
||||||
render_webauthn_setup(res.new_mfa.webauthn);
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -212,7 +212,7 @@ and ensure every administrator account for this control panel does the same.</st
|
|||||||
api(
|
api(
|
||||||
'/mfa/disable',
|
'/mfa/disable',
|
||||||
'POST',
|
'POST',
|
||||||
{ id: $(this).attr('data-mfa-id') },
|
{ type: 'totp' },
|
||||||
function() {
|
function() {
|
||||||
do_logout();
|
do_logout();
|
||||||
}
|
}
|
||||||
@@ -226,7 +226,7 @@ and ensure every administrator account for this control panel does the same.</st
|
|||||||
hide_error();
|
hide_error();
|
||||||
|
|
||||||
api(
|
api(
|
||||||
'/mfa/enable/totp',
|
'/mfa/totp/enable',
|
||||||
'POST',
|
'POST',
|
||||||
{
|
{
|
||||||
token: $(el.totpSetupToken).val(),
|
token: $(el.totpSetupToken).val(),
|
||||||
@@ -239,22 +239,4 @@ and ensure every administrator account for this control panel does the same.</st
|
|||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
function do_enable_webauthn() {
|
|
||||||
navigator.credentials.create({ publicKey: window.mailinabix_mfa_webauthn_provision })
|
|
||||||
.then(function(creds) {
|
|
||||||
api(
|
|
||||||
'/mfa/enable/webauthn',
|
|
||||||
'POST',
|
|
||||||
{
|
|
||||||
attestationObject: arrayBufferToBase64(creds.response['attestationObject']),
|
|
||||||
clientDataJSON: arrayBufferToBase64(creds.response['clientDataJSON'])
|
|
||||||
},
|
|
||||||
function(res) { do_logout(); },
|
|
||||||
function(res) { render_error(res); }
|
|
||||||
);
|
|
||||||
});
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -30,9 +30,9 @@
|
|||||||
|
|
||||||
<table class="table">
|
<table class="table">
|
||||||
<thead><tr><th>For...</th> <th>Use...</th></tr></thead>
|
<thead><tr><th>For...</th> <th>Use...</th></tr></thead>
|
||||||
<tr><td>Contacts and Calendar</td> <td><a href="https://play.google.com/store/apps/details?id=at.bitfire.davdroid">DAVdroid</a> ($3.69; free <a href="https://f-droid.org/packages/at.bitfire.davdroid/">here</a>)</td></tr>
|
<tr><td>Contacts and Calendar</td> <td><a href="https://play.google.com/store/apps/details?id=at.bitfire.davdroid">DAVx⁵</a> ($5.99; free <a href="https://f-droid.org/packages/at.bitfire.davdroid/">here</a>)</td></tr>
|
||||||
<tr><td>Only Contacts</td> <td><a href="https://play.google.com/store/apps/details?id=org.dmfs.carddav.sync">CardDAV-Sync free beta</a> (free)</td></tr>
|
<tr><td>Only Contacts</td> <td><a href="https://play.google.com/store/apps/details?id=org.dmfs.carddav.sync">CardDAV-Sync free</a> (free)</td></tr>
|
||||||
<tr><td>Only Calendar</td> <td><a href="https://play.google.com/store/apps/details?id=org.dmfs.caldav.lib">CalDAV-Sync</a> ($2.89)</td></tr>
|
<tr><td>Only Calendar</td> <td><a href="https://play.google.com/store/apps/details?id=org.dmfs.caldav.lib">CalDAV-Sync</a> ($2.99)</td></tr>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
<p>Use the following settings:</p>
|
<p>Use the following settings:</p>
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
<h2>Backup Status</h2>
|
<h2>Backup Status</h2>
|
||||||
|
|
||||||
<p>The box makes an incremental backup each night. By default the backup is stored on the machine itself, but you can also store in on S3-compatible services like Amazon Web Services (AWS).</p>
|
<p>The box makes an incremental backup each night. By default the backup is stored on the machine itself, but you can also store it on S3-compatible services like Amazon Web Services (AWS).</p>
|
||||||
|
|
||||||
<h3>Configuration</h3>
|
<h3>Configuration</h3>
|
||||||
|
|
||||||
@@ -269,6 +269,7 @@ function show_custom_backup() {
|
|||||||
$("#backup-target-type").val("s3");
|
$("#backup-target-type").val("s3");
|
||||||
var hostpath = r.target.substring(5).split('/');
|
var hostpath = r.target.substring(5).split('/');
|
||||||
var host = hostpath.shift();
|
var host = hostpath.shift();
|
||||||
|
$("#backup-target-s3-host-select").val(host);
|
||||||
$("#backup-target-s3-host").val(host);
|
$("#backup-target-s3-host").val(host);
|
||||||
$("#backup-target-s3-path").val(hostpath.join('/'));
|
$("#backup-target-s3-path").val(hostpath.join('/'));
|
||||||
} else if (r.target.substring(0, 5) == "b2://") {
|
} else if (r.target.substring(0, 5) == "b2://") {
|
||||||
|
|||||||
@@ -175,14 +175,6 @@ def wait_for_service(port, public, env, timeout):
|
|||||||
return False
|
return False
|
||||||
time.sleep(min(timeout/4, 1))
|
time.sleep(min(timeout/4, 1))
|
||||||
|
|
||||||
def fix_boto():
|
|
||||||
# Google Compute Engine instances install some Python-2-only boto plugins that
|
|
||||||
# conflict with boto running under Python 3. Disable boto's default configuration
|
|
||||||
# file prior to importing boto so that GCE's plugin is not loaded:
|
|
||||||
import os
|
|
||||||
os.environ["BOTO_CONFIG"] = "/etc/boto3.cfg"
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
from web_update import get_web_domains
|
from web_update import get_web_domains
|
||||||
env = load_environment()
|
env = load_environment()
|
||||||
|
|||||||
7
management/wsgi.py
Normal file
7
management/wsgi.py
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
from daemon import app
|
||||||
|
import auth, utils
|
||||||
|
|
||||||
|
app.logger.addHandler(utils.create_syslog_handler())
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
app.run(port=10222)
|
||||||
13
security.md
13
security.md
@@ -3,7 +3,12 @@ Mail-in-a-Box Security Guide
|
|||||||
|
|
||||||
Mail-in-a-Box turns a fresh Ubuntu 18.04 LTS 64-bit machine into a mail server appliance by installing and configuring various components.
|
Mail-in-a-Box turns a fresh Ubuntu 18.04 LTS 64-bit machine into a mail server appliance by installing and configuring various components.
|
||||||
|
|
||||||
This page documents the security features of Mail-in-a-Box. The term “box” is used below to mean a configured Mail-in-a-Box.
|
This page documents the security posture of Mail-in-a-Box. The term “box” is used below to mean a configured Mail-in-a-Box.
|
||||||
|
|
||||||
|
Reporting Security Vulnerabilities
|
||||||
|
----------------------------------
|
||||||
|
|
||||||
|
Security vulnerabilities should be reported to the [project's maintainer](https://joshdata.me) via email.
|
||||||
|
|
||||||
Threat Model
|
Threat Model
|
||||||
------------
|
------------
|
||||||
@@ -49,9 +54,7 @@ Additionally:
|
|||||||
|
|
||||||
### Password Storage
|
### Password Storage
|
||||||
|
|
||||||
The passwords for mail users are stored on disk using the [SHA512-CRYPT](http://man7.org/linux/man-pages/man3/crypt.3.html) hashing scheme. ([source](management/mailconfig.py))
|
The passwords for mail users are stored on disk using the [SHA512-CRYPT](http://man7.org/linux/man-pages/man3/crypt.3.html) hashing scheme. ([source](management/mailconfig.py)) Password changes (as well as changes to control panel two-factor authentication settings) expire any control panel login sessions.
|
||||||
|
|
||||||
When using the web-based administrative control panel, after logging in an API key is placed in the browser's local storage (rather than, say, the user's actual password). The API key is an HMAC based on the user's email address and current password, and it is keyed by a secret known only to the control panel service. By resetting an administrator's password, any HMACs previously generated for that user will expire.
|
|
||||||
|
|
||||||
### Console access
|
### Console access
|
||||||
|
|
||||||
@@ -65,7 +68,7 @@ If DNSSEC is enabled at the box's domain name's registrar, the SSHFP record that
|
|||||||
|
|
||||||
`fail2ban` provides some protection from brute-force login attacks (repeated logins that guess account passwords) by blocking offending IP addresses at the network level.
|
`fail2ban` provides some protection from brute-force login attacks (repeated logins that guess account passwords) by blocking offending IP addresses at the network level.
|
||||||
|
|
||||||
The following services are protected: SSH, IMAP (dovecot), SMTP submission (postfix), webmail (roundcube), Nextcloud/CalDAV/CardDAV (over HTTP), and the Mail-in-a-Box control panel & munin (over HTTP).
|
The following services are protected: SSH, IMAP (dovecot), SMTP submission (postfix), webmail (roundcube), Nextcloud/CalDAV/CardDAV (over HTTP), and the Mail-in-a-Box control panel (over HTTP).
|
||||||
|
|
||||||
Some other services running on the box may be missing fail2ban filters.
|
Some other services running on the box may be missing fail2ban filters.
|
||||||
|
|
||||||
|
|||||||
@@ -9,32 +9,37 @@
|
|||||||
if [ -z "$TAG" ]; then
|
if [ -z "$TAG" ]; then
|
||||||
# If a version to install isn't explicitly given as an environment
|
# If a version to install isn't explicitly given as an environment
|
||||||
# variable, then install the latest version. But the latest version
|
# variable, then install the latest version. But the latest version
|
||||||
# depends on the operating system. Existing Ubuntu 14.04 users need
|
# depends on the machine's version of Ubuntu. Existing users need to
|
||||||
# to be able to upgrade to the latest version supporting Ubuntu 14.04,
|
# be able to upgrade to the latest version available for that version
|
||||||
# in part because an upgrade is required before jumping to Ubuntu 18.04.
|
# of Ubuntu to satisfy the migration requirements.
|
||||||
# New users on Ubuntu 18.04 need to get the latest version number too.
|
|
||||||
#
|
#
|
||||||
# Also, the system status checks read this script for TAG = (without the
|
# Also, the system status checks read this script for TAG = (without the
|
||||||
# space, but if we put it in a comment it would confuse the status checks!)
|
# space, but if we put it in a comment it would confuse the status checks!)
|
||||||
# to get the latest version, so the first such line must be the one that we
|
# to get the latest version, so the first such line must be the one that we
|
||||||
# want to display in status checks.
|
# want to display in status checks.
|
||||||
if [ "$(lsb_release -d | sed 's/.*:\s*//' | sed 's/18\.04\.[0-9]/18.04/' )" == "Ubuntu 18.04 LTS" ]; then
|
#
|
||||||
# This machine is running Ubuntu 18.04.
|
# Allow point-release versions of the major releases, e.g. 22.04.1 is OK.
|
||||||
TAG=v0.54
|
UBUNTU_VERSION=$( lsb_release -d | sed 's/.*:\s*//' | sed 's/\([0-9]*\.[0-9]*\)\.[0-9]/\1/' )
|
||||||
|
if [ "$UBUNTU_VERSION" == "Ubuntu 22.04 LTS" ]; then
|
||||||
elif [ "$(lsb_release -d | sed 's/.*:\s*//' | sed 's/14\.04\.[0-9]/14.04/' )" == "Ubuntu 14.04 LTS" ]; then
|
# This machine is running Ubuntu 22.04, which is supported by
|
||||||
# This machine is running Ubuntu 14.04.
|
# Mail-in-a-Box versions 60 and later.
|
||||||
echo "You are installing the last version of Mail-in-a-Box that will"
|
TAG=v60.1
|
||||||
echo "support Ubuntu 14.04. If this is a new installation of Mail-in-a-Box,"
|
elif [ "$UBUNTU_VERSION" == "Ubuntu 18.04 LTS" ]; then
|
||||||
echo "stop now and switch to a machine running Ubuntu 18.04. If you are"
|
# This machine is running Ubuntu 18.04, which is supported by
|
||||||
echo "upgrading an existing Mail-in-a-Box --- great. After upgrading this"
|
# Mail-in-a-Box versions 0.40 through 5x.
|
||||||
echo "box, please visit https://mailinabox.email for notes on how to upgrade"
|
echo "Support is ending for Ubuntu 18.04."
|
||||||
echo "to Ubuntu 18.04."
|
echo "Please immediately begin to migrate your data to"
|
||||||
echo ""
|
echo "a new machine running Ubuntu 22.04. See:"
|
||||||
|
echo "https://mailinabox.email/maintenance.html#upgrade"
|
||||||
|
TAG=v57a
|
||||||
|
elif [ "$UBUNTU_VERSION" == "Ubuntu 14.04 LTS" ]; then
|
||||||
|
# This machine is running Ubuntu 14.04, which is supported by
|
||||||
|
# Mail-in-a-Box versions 1 through v0.30.
|
||||||
|
echo "Ubuntu 14.04 is no longer supported."
|
||||||
|
echo "The last version of Mail-in-a-Box supporting Ubuntu 14.04 will be installed."
|
||||||
TAG=v0.30
|
TAG=v0.30
|
||||||
|
|
||||||
else
|
else
|
||||||
echo "This script must be run on a system running Ubuntu 18.04 or Ubuntu 14.04."
|
echo "This script may be used only on a machine running Ubuntu 14.04, 18.04, or 22.04."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|||||||
46
setup/dns.sh
46
setup/dns.sh
@@ -10,17 +10,13 @@
|
|||||||
source setup/functions.sh # load our functions
|
source setup/functions.sh # load our functions
|
||||||
source /etc/mailinabox.conf # load global vars
|
source /etc/mailinabox.conf # load global vars
|
||||||
|
|
||||||
# Install the packages.
|
|
||||||
#
|
|
||||||
# * nsd: The non-recursive nameserver that publishes our DNS records.
|
|
||||||
# * ldnsutils: Helper utilities for signing DNSSEC zones.
|
|
||||||
# * openssh-client: Provides ssh-keyscan which we use to create SSHFP records.
|
|
||||||
echo "Installing nsd (DNS server)..."
|
|
||||||
apt_install nsd ldnsutils openssh-client
|
|
||||||
|
|
||||||
# Prepare nsd's configuration.
|
# Prepare nsd's configuration.
|
||||||
|
# We configure nsd before installation as we only want it to bind to some addresses
|
||||||
|
# and it otherwise will have port / bind conflicts with bind9 used as the local resolver
|
||||||
mkdir -p /var/run/nsd
|
mkdir -p /var/run/nsd
|
||||||
|
mkdir -p /etc/nsd
|
||||||
|
mkdir -p /etc/nsd/zones
|
||||||
|
touch /etc/nsd/zones.conf
|
||||||
|
|
||||||
cat > /etc/nsd/nsd.conf << EOF;
|
cat > /etc/nsd/nsd.conf << EOF;
|
||||||
# Do not edit. Overwritten by Mail-in-a-Box setup.
|
# Do not edit. Overwritten by Mail-in-a-Box setup.
|
||||||
@@ -42,18 +38,6 @@ server:
|
|||||||
|
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
# Add log rotation
|
|
||||||
cat > /etc/logrotate.d/nsd <<EOF;
|
|
||||||
/var/log/nsd.log {
|
|
||||||
weekly
|
|
||||||
missingok
|
|
||||||
rotate 12
|
|
||||||
compress
|
|
||||||
delaycompress
|
|
||||||
notifempty
|
|
||||||
}
|
|
||||||
EOF
|
|
||||||
|
|
||||||
# Since we have bind9 listening on localhost for locally-generated
|
# Since we have bind9 listening on localhost for locally-generated
|
||||||
# DNS queries that require a recursive nameserver, and the system
|
# DNS queries that require a recursive nameserver, and the system
|
||||||
# might have other network interfaces for e.g. tunnelling, we have
|
# might have other network interfaces for e.g. tunnelling, we have
|
||||||
@@ -70,6 +54,26 @@ echo "include: /etc/nsd/nsd.conf.d/*.conf" >> /etc/nsd/nsd.conf;
|
|||||||
# now be stored in /etc/nsd/nsd.conf.d.
|
# now be stored in /etc/nsd/nsd.conf.d.
|
||||||
rm -f /etc/nsd/zones.conf
|
rm -f /etc/nsd/zones.conf
|
||||||
|
|
||||||
|
# Add log rotation
|
||||||
|
cat > /etc/logrotate.d/nsd <<EOF;
|
||||||
|
/var/log/nsd.log {
|
||||||
|
weekly
|
||||||
|
missingok
|
||||||
|
rotate 12
|
||||||
|
compress
|
||||||
|
delaycompress
|
||||||
|
notifempty
|
||||||
|
}
|
||||||
|
EOF
|
||||||
|
|
||||||
|
# Install the packages.
|
||||||
|
#
|
||||||
|
# * nsd: The non-recursive nameserver that publishes our DNS records.
|
||||||
|
# * ldnsutils: Helper utilities for signing DNSSEC zones.
|
||||||
|
# * openssh-client: Provides ssh-keyscan which we use to create SSHFP records.
|
||||||
|
echo "Installing nsd (DNS server)..."
|
||||||
|
apt_install nsd ldnsutils openssh-client
|
||||||
|
|
||||||
# Create DNSSEC signing keys.
|
# Create DNSSEC signing keys.
|
||||||
|
|
||||||
mkdir -p "$STORAGE_ROOT/dns/dnssec";
|
mkdir -p "$STORAGE_ROOT/dns/dnssec";
|
||||||
|
|||||||
@@ -4,6 +4,8 @@
|
|||||||
# -o pipefail: don't ignore errors in the non-last command in a pipeline
|
# -o pipefail: don't ignore errors in the non-last command in a pipeline
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
|
PHP_VER=8.0
|
||||||
|
|
||||||
function hide_output {
|
function hide_output {
|
||||||
# This function hides the output of a command unless the command fails
|
# This function hides the output of a command unless the command fails
|
||||||
# and returns a non-zero exit code.
|
# and returns a non-zero exit code.
|
||||||
|
|||||||
@@ -84,10 +84,11 @@ tools/editconf.py /etc/dovecot/conf.d/10-ssl.conf \
|
|||||||
ssl=required \
|
ssl=required \
|
||||||
"ssl_cert=<$STORAGE_ROOT/ssl/ssl_certificate.pem" \
|
"ssl_cert=<$STORAGE_ROOT/ssl/ssl_certificate.pem" \
|
||||||
"ssl_key=<$STORAGE_ROOT/ssl/ssl_private_key.pem" \
|
"ssl_key=<$STORAGE_ROOT/ssl/ssl_private_key.pem" \
|
||||||
"ssl_protocols=TLSv1.2" \
|
"ssl_min_protocol=TLSv1.2" \
|
||||||
"ssl_cipher_list=ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384" \
|
"ssl_cipher_list=ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384" \
|
||||||
"ssl_prefer_server_ciphers=no" \
|
"ssl_prefer_server_ciphers=no" \
|
||||||
"ssl_dh_parameters_length=2048"
|
"ssl_dh_parameters_length=2048" \
|
||||||
|
"ssl_dh=<$STORAGE_ROOT/ssl/dh2048.pem"
|
||||||
|
|
||||||
# Disable in-the-clear IMAP/POP because there is no reason for a user to transmit
|
# Disable in-the-clear IMAP/POP because there is no reason for a user to transmit
|
||||||
# login credentials outside of an encrypted connection. Only the over-TLS versions
|
# login credentials outside of an encrypted connection. Only the over-TLS versions
|
||||||
|
|||||||
@@ -13,8 +13,8 @@
|
|||||||
# destinations according to aliases, and passses email on to
|
# destinations according to aliases, and passses email on to
|
||||||
# another service for local mail delivery.
|
# another service for local mail delivery.
|
||||||
#
|
#
|
||||||
# The first hop in local mail delivery is to Spamassassin via
|
# The first hop in local mail delivery is to spampd via
|
||||||
# LMTP. Spamassassin then passes mail over to Dovecot for
|
# LMTP. spampd then passes mail over to Dovecot for
|
||||||
# storage in the user's mailbox.
|
# storage in the user's mailbox.
|
||||||
#
|
#
|
||||||
# Postfix also listens on ports 465/587 (SMTPS, SMTP+STARTLS) for
|
# Postfix also listens on ports 465/587 (SMTPS, SMTP+STARTLS) for
|
||||||
@@ -193,16 +193,17 @@ tools/editconf.py /etc/postfix/main.cf \
|
|||||||
|
|
||||||
# ### Incoming Mail
|
# ### Incoming Mail
|
||||||
|
|
||||||
# Pass any incoming mail over to a local delivery agent. Spamassassin
|
# Pass mail to spampd, which acts as the local delivery agent (LDA),
|
||||||
# will act as the LDA agent at first. It is listening on port 10025
|
# which then passes the mail over to the Dovecot LMTP server after.
|
||||||
# with LMTP. Spamassassin will pass the mail over to Dovecot after.
|
# spampd runs on port 10025 by default.
|
||||||
#
|
#
|
||||||
# In a basic setup we would pass mail directly to Dovecot by setting
|
# In a basic setup we would pass mail directly to Dovecot by setting
|
||||||
# virtual_transport to `lmtp:unix:private/dovecot-lmtp`.
|
# virtual_transport to `lmtp:unix:private/dovecot-lmtp`.
|
||||||
tools/editconf.py /etc/postfix/main.cf "virtual_transport=lmtp:[127.0.0.1]:10025"
|
tools/editconf.py /etc/postfix/main.cf "virtual_transport=lmtp:[127.0.0.1]:10025"
|
||||||
# Because of a spampd bug, limit the number of recipients in each connection.
|
# Clear the lmtp_destination_recipient_limit setting which in previous
|
||||||
|
# versions of Mail-in-a-Box was set to 1 because of a spampd bug.
|
||||||
# See https://github.com/mail-in-a-box/mailinabox/issues/1523.
|
# See https://github.com/mail-in-a-box/mailinabox/issues/1523.
|
||||||
tools/editconf.py /etc/postfix/main.cf lmtp_destination_recipient_limit=1
|
tools/editconf.py /etc/postfix/main.cf -e lmtp_destination_recipient_limit=
|
||||||
|
|
||||||
|
|
||||||
# Who can send mail to us? Some basic filters.
|
# Who can send mail to us? Some basic filters.
|
||||||
@@ -232,11 +233,32 @@ tools/editconf.py /etc/postfix/main.cf \
|
|||||||
# As a matter of fact RFC is not strict about retry timer so postfix and
|
# As a matter of fact RFC is not strict about retry timer so postfix and
|
||||||
# other MTA have their own intervals. To fix the problem of receiving
|
# other MTA have their own intervals. To fix the problem of receiving
|
||||||
# e-mails really latter, delay of greylisting has been set to
|
# e-mails really latter, delay of greylisting has been set to
|
||||||
# 180 seconds (default is 300 seconds).
|
# 180 seconds (default is 300 seconds). We will move the postgrey database
|
||||||
|
# under $STORAGE_ROOT. This prevents a "warming up" that would have occured
|
||||||
|
# previously with a migrated or reinstalled OS. We will specify this new path
|
||||||
|
# with the --dbdir=... option. Arguments within POSTGREY_OPTS can not have spaces,
|
||||||
|
# including dbdir. This is due to the way the init script sources the
|
||||||
|
# /etc/default/postgrey file. --dbdir=... either needs to be a path without spaces
|
||||||
|
# (luckily $STORAGE_ROOT does not currently work with spaces), or it needs to be a
|
||||||
|
# symlink without spaces that can point to a folder with spaces). We'll just assume
|
||||||
|
# $STORAGE_ROOT won't have spaces to simplify things.
|
||||||
tools/editconf.py /etc/default/postgrey \
|
tools/editconf.py /etc/default/postgrey \
|
||||||
POSTGREY_OPTS=\"'--inet=127.0.0.1:10023 --delay=180'\"
|
POSTGREY_OPTS=\""--inet=127.0.0.1:10023 --delay=180 --dbdir=$STORAGE_ROOT/mail/postgrey/db"\"
|
||||||
|
|
||||||
|
|
||||||
|
# If the $STORAGE_ROOT/mail/postgrey is empty, copy the postgrey database over from the old location
|
||||||
|
if [ ! -d $STORAGE_ROOT/mail/postgrey/db ]; then
|
||||||
|
# Stop the service
|
||||||
|
service postgrey stop
|
||||||
|
# Ensure the new paths for postgrey db exists
|
||||||
|
mkdir -p $STORAGE_ROOT/mail/postgrey/db
|
||||||
|
# Move over database files
|
||||||
|
mv /var/lib/postgrey/* $STORAGE_ROOT/mail/postgrey/db/ || true
|
||||||
|
fi
|
||||||
|
# Ensure permissions are set
|
||||||
|
chown -R postgrey:postgrey $STORAGE_ROOT/mail/postgrey/
|
||||||
|
chmod 700 $STORAGE_ROOT/mail/postgrey/{,db}
|
||||||
|
|
||||||
# We are going to setup a newer whitelist for postgrey, the version included in the distribution is old
|
# We are going to setup a newer whitelist for postgrey, the version included in the distribution is old
|
||||||
cat > /etc/cron.daily/mailinabox-postgrey-whitelist << EOF;
|
cat > /etc/cron.daily/mailinabox-postgrey-whitelist << EOF;
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|||||||
@@ -1,23 +1,12 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
source setup/functions.sh
|
source setup/functions.sh
|
||||||
|
source /etc/mailinabox.conf # load global vars
|
||||||
|
|
||||||
echo "Installing Mail-in-a-Box system management daemon..."
|
echo "Installing Mail-in-a-Box system management daemon..."
|
||||||
|
|
||||||
# DEPENDENCIES
|
# DEPENDENCIES
|
||||||
|
|
||||||
# We used to install management daemon-related Python packages
|
|
||||||
# directly to /usr/local/lib. We moved to a virtualenv because
|
|
||||||
# these packages might conflict with apt-installed packages.
|
|
||||||
# We may have a lingering version of acme that conflcits with
|
|
||||||
# certbot, which we're about to install below, so remove it
|
|
||||||
# first. Once acme is installed by an apt package, this might
|
|
||||||
# break the package version and `apt-get install --reinstall python3-acme`
|
|
||||||
# might be needed in that case.
|
|
||||||
while [ -d /usr/local/lib/python3.4/dist-packages/acme ]; do
|
|
||||||
pip3 uninstall -y acme;
|
|
||||||
done
|
|
||||||
|
|
||||||
# duplicity is used to make backups of user data.
|
# duplicity is used to make backups of user data.
|
||||||
#
|
#
|
||||||
# virtualenv is used to isolate the Python 3 packages we
|
# virtualenv is used to isolate the Python 3 packages we
|
||||||
@@ -25,12 +14,12 @@ done
|
|||||||
#
|
#
|
||||||
# certbot installs EFF's certbot which we use to
|
# certbot installs EFF's certbot which we use to
|
||||||
# provision free TLS certificates.
|
# provision free TLS certificates.
|
||||||
apt_install duplicity python-pip virtualenv certbot
|
apt_install duplicity python3-pip virtualenv certbot rsync
|
||||||
|
|
||||||
# b2sdk is used for backblaze backups.
|
# b2sdk is used for backblaze backups.
|
||||||
# boto is used for amazon aws backups.
|
# boto3 is used for amazon aws backups.
|
||||||
# Both are installed outside the pipenv, so they can be used by duplicity
|
# Both are installed outside the pipenv, so they can be used by duplicity
|
||||||
hide_output pip3 install --upgrade b2sdk boto
|
hide_output pip3 install --upgrade b2sdk boto3
|
||||||
|
|
||||||
# Create a virtualenv for the installation of Python 3 packages
|
# Create a virtualenv for the installation of Python 3 packages
|
||||||
# used by the management daemon.
|
# used by the management daemon.
|
||||||
@@ -49,9 +38,10 @@ hide_output $venv/bin/pip install --upgrade pip
|
|||||||
# NOTE: email_validator is repeated in setup/questions.sh, so please keep the versions synced.
|
# NOTE: email_validator is repeated in setup/questions.sh, so please keep the versions synced.
|
||||||
hide_output $venv/bin/pip install --upgrade \
|
hide_output $venv/bin/pip install --upgrade \
|
||||||
rtyaml "email_validator>=1.0.0" "exclusiveprocess" \
|
rtyaml "email_validator>=1.0.0" "exclusiveprocess" \
|
||||||
flask dnspython python-dateutil expiringdict \
|
flask dnspython python-dateutil expiringdict gunicorn \
|
||||||
qrcode[pil] pyotp pywarp \
|
qrcode[pil] pyotp \
|
||||||
"idna>=2.0.0" "cryptography==2.2.2" boto psutil postfix-mta-sts-resolver b2sdk
|
"idna>=2.0.0" "cryptography==37.0.2" psutil postfix-mta-sts-resolver \
|
||||||
|
b2sdk boto3
|
||||||
|
|
||||||
# CONFIGURATION
|
# CONFIGURATION
|
||||||
|
|
||||||
@@ -88,6 +78,9 @@ rm -f /tmp/bootstrap.zip
|
|||||||
|
|
||||||
# Create an init script to start the management daemon and keep it
|
# Create an init script to start the management daemon and keep it
|
||||||
# running after a reboot.
|
# running after a reboot.
|
||||||
|
# Set a long timeout since some commands take a while to run, matching
|
||||||
|
# the timeout we set for PHP (fastcgi_read_timeout in the nginx confs).
|
||||||
|
# Note: Authentication currently breaks with more than 1 gunicorn worker.
|
||||||
cat > $inst_dir/start <<EOF;
|
cat > $inst_dir/start <<EOF;
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# Set character encoding flags to ensure that any non-ASCII don't cause problems.
|
# Set character encoding flags to ensure that any non-ASCII don't cause problems.
|
||||||
@@ -96,8 +89,13 @@ export LC_ALL=en_US.UTF-8
|
|||||||
export LANG=en_US.UTF-8
|
export LANG=en_US.UTF-8
|
||||||
export LC_TYPE=en_US.UTF-8
|
export LC_TYPE=en_US.UTF-8
|
||||||
|
|
||||||
|
mkdir -p /var/lib/mailinabox
|
||||||
|
tr -cd '[:xdigit:]' < /dev/urandom | head -c 32 > /var/lib/mailinabox/api.key
|
||||||
|
chmod 640 /var/lib/mailinabox/api.key
|
||||||
|
|
||||||
source $venv/bin/activate
|
source $venv/bin/activate
|
||||||
exec python $(pwd)/management/daemon.py
|
export PYTHONPATH=$(pwd)/management
|
||||||
|
exec gunicorn -b localhost:10222 -w 1 --timeout 630 wsgi:app
|
||||||
EOF
|
EOF
|
||||||
chmod +x $inst_dir/start
|
chmod +x $inst_dir/start
|
||||||
cp --remove-destination conf/mailinabox.service /lib/systemd/system/mailinabox.service # target was previously a symlink so remove it first
|
cp --remove-destination conf/mailinabox.service /lib/systemd/system/mailinabox.service # target was previously a symlink so remove it first
|
||||||
|
|||||||
@@ -9,12 +9,50 @@ source /etc/mailinabox.conf # load global vars
|
|||||||
|
|
||||||
echo "Installing Nextcloud (contacts/calendar)..."
|
echo "Installing Nextcloud (contacts/calendar)..."
|
||||||
|
|
||||||
|
# Nextcloud core and app (plugin) versions to install.
|
||||||
|
# With each version we store a hash to ensure we install what we expect.
|
||||||
|
|
||||||
|
# Nextcloud core
|
||||||
|
# --------------
|
||||||
|
# * See https://nextcloud.com/changelog for the latest version.
|
||||||
|
# * Check https://docs.nextcloud.com/server/latest/admin_manual/installation/system_requirements.html
|
||||||
|
# for whether it supports the version of PHP available on this machine.
|
||||||
|
# * Since Nextcloud only supports upgrades from consecutive major versions,
|
||||||
|
# we automatically install intermediate versions as needed.
|
||||||
|
# * The hash is the SHA1 hash of the ZIP package, which you can find by just running this script and
|
||||||
|
# copying it from the error message when it doesn't match what is below.
|
||||||
|
nextcloud_ver=23.0.10
|
||||||
|
nextcloud_hash=8831c7862e39460fbb789bacac8729fab0ba02dd
|
||||||
|
|
||||||
|
# Nextcloud apps
|
||||||
|
# --------------
|
||||||
|
# * Find the most recent tag that is compatible with the Nextcloud version above by
|
||||||
|
# consulting the <dependencies>...<nextcloud> node at:
|
||||||
|
# https://github.com/nextcloud-releases/contacts/blob/main/appinfo/info.xml
|
||||||
|
# https://github.com/nextcloud-releases/calendar/blob/main/appinfo/info.xml
|
||||||
|
# https://github.com/nextcloud/user_external/blob/master/appinfo/info.xml
|
||||||
|
# * The hash is the SHA1 hash of the ZIP package, which you can find by just running this script and
|
||||||
|
# copying it from the error message when it doesn't match what is below.
|
||||||
|
contacts_ver=4.2.2
|
||||||
|
contacts_hash=ca13d608ed8955aa374cb4f31b6026b57ef88887
|
||||||
|
calendar_ver=3.5.1
|
||||||
|
calendar_hash=c8136a3deb872a3ef73ce1155b58f3ab27ec7110
|
||||||
|
user_external_ver=3.0.0
|
||||||
|
user_external_hash=0df781b261f55bbde73d8c92da3f99397000972f
|
||||||
|
|
||||||
|
# Clear prior packages and install dependencies from apt.
|
||||||
|
|
||||||
apt-get purge -qq -y owncloud* # we used to use the package manager
|
apt-get purge -qq -y owncloud* # we used to use the package manager
|
||||||
|
|
||||||
apt_install php php-fpm \
|
apt_install curl php${PHP_VER} php${PHP_VER}-fpm \
|
||||||
php-cli php-sqlite3 php-gd php-imap php-curl php-pear curl \
|
php${PHP_VER}-cli php${PHP_VER}-sqlite3 php${PHP_VER}-gd php${PHP_VER}-imap php${PHP_VER}-curl \
|
||||||
php-dev php-gd php-xml php-mbstring php-zip php-apcu php-json \
|
php${PHP_VER}-dev php${PHP_VER}-gd php${PHP_VER}-xml php${PHP_VER}-mbstring php${PHP_VER}-zip php${PHP_VER}-apcu \
|
||||||
php-intl php-imagick php-gmp php-bcmath
|
php${PHP_VER}-intl php${PHP_VER}-imagick php${PHP_VER}-gmp php${PHP_VER}-bcmath
|
||||||
|
|
||||||
|
# Enable APC before Nextcloud tools are run.
|
||||||
|
tools/editconf.py /etc/php/$PHP_VER/mods-available/apcu.ini -c ';' \
|
||||||
|
apc.enabled=1 \
|
||||||
|
apc.enable_cli=1
|
||||||
|
|
||||||
InstallNextcloud() {
|
InstallNextcloud() {
|
||||||
|
|
||||||
@@ -46,18 +84,18 @@ InstallNextcloud() {
|
|||||||
# their github repositories.
|
# their github repositories.
|
||||||
mkdir -p /usr/local/lib/owncloud/apps
|
mkdir -p /usr/local/lib/owncloud/apps
|
||||||
|
|
||||||
wget_verify https://github.com/nextcloud/contacts/releases/download/v$version_contacts/contacts.tar.gz $hash_contacts /tmp/contacts.tgz
|
wget_verify https://github.com/nextcloud-releases/contacts/archive/refs/tags/v$version_contacts.tar.gz $hash_contacts /tmp/contacts.tgz
|
||||||
tar xf /tmp/contacts.tgz -C /usr/local/lib/owncloud/apps/
|
tar xf /tmp/contacts.tgz -C /usr/local/lib/owncloud/apps/
|
||||||
rm /tmp/contacts.tgz
|
rm /tmp/contacts.tgz
|
||||||
|
|
||||||
wget_verify https://github.com/nextcloud/calendar/releases/download/v$version_calendar/calendar.tar.gz $hash_calendar /tmp/calendar.tgz
|
wget_verify https://github.com/nextcloud-releases/calendar/archive/refs/tags/v$version_calendar.tar.gz $hash_calendar /tmp/calendar.tgz
|
||||||
tar xf /tmp/calendar.tgz -C /usr/local/lib/owncloud/apps/
|
tar xf /tmp/calendar.tgz -C /usr/local/lib/owncloud/apps/
|
||||||
rm /tmp/calendar.tgz
|
rm /tmp/calendar.tgz
|
||||||
|
|
||||||
# Starting with Nextcloud 15, the app user_external is no longer included in Nextcloud core,
|
# Starting with Nextcloud 15, the app user_external is no longer included in Nextcloud core,
|
||||||
# we will install from their github repository.
|
# we will install from their github repository.
|
||||||
if [ -n "$version_user_external" ]; then
|
if [ -n "$version_user_external" ]; then
|
||||||
wget_verify https://github.com/nextcloud/user_external/releases/download/v$version_user_external/user_external-$version_user_external.tar.gz $hash_user_external /tmp/user_external.tgz
|
wget_verify https://github.com/nextcloud-releases/user_external/releases/download/v$version_user_external/user_external-v$version_user_external.tar.gz $hash_user_external /tmp/user_external.tgz
|
||||||
tar -xf /tmp/user_external.tgz -C /usr/local/lib/owncloud/apps/
|
tar -xf /tmp/user_external.tgz -C /usr/local/lib/owncloud/apps/
|
||||||
rm /tmp/user_external.tgz
|
rm /tmp/user_external.tgz
|
||||||
fi
|
fi
|
||||||
@@ -79,33 +117,23 @@ InstallNextcloud() {
|
|||||||
if [ -e $STORAGE_ROOT/owncloud/owncloud.db ]; then
|
if [ -e $STORAGE_ROOT/owncloud/owncloud.db ]; then
|
||||||
# ownCloud 8.1.1 broke upgrades. It may fail on the first attempt, but
|
# ownCloud 8.1.1 broke upgrades. It may fail on the first attempt, but
|
||||||
# that can be OK.
|
# that can be OK.
|
||||||
sudo -u www-data php /usr/local/lib/owncloud/occ upgrade
|
sudo -u www-data php$PHP_VER /usr/local/lib/owncloud/occ upgrade
|
||||||
if [ \( $? -ne 0 \) -a \( $? -ne 3 \) ]; then
|
if [ \( $? -ne 0 \) -a \( $? -ne 3 \) ]; then
|
||||||
echo "Trying ownCloud upgrade again to work around ownCloud upgrade bug..."
|
echo "Trying ownCloud upgrade again to work around ownCloud upgrade bug..."
|
||||||
sudo -u www-data php /usr/local/lib/owncloud/occ upgrade
|
sudo -u www-data php$PHP_VER /usr/local/lib/owncloud/occ upgrade
|
||||||
if [ \( $? -ne 0 \) -a \( $? -ne 3 \) ]; then exit 1; fi
|
if [ \( $? -ne 0 \) -a \( $? -ne 3 \) ]; then exit 1; fi
|
||||||
sudo -u www-data php /usr/local/lib/owncloud/occ maintenance:mode --off
|
sudo -u www-data php$PHP_VER /usr/local/lib/owncloud/occ maintenance:mode --off
|
||||||
echo "...which seemed to work."
|
echo "...which seemed to work."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Add missing indices. NextCloud didn't include this in the normal upgrade because it might take some time.
|
# Add missing indices. NextCloud didn't include this in the normal upgrade because it might take some time.
|
||||||
sudo -u www-data php /usr/local/lib/owncloud/occ db:add-missing-indices
|
sudo -u www-data php$PHP_VER /usr/local/lib/owncloud/occ db:add-missing-indices
|
||||||
|
|
||||||
# Run conversion to BigInt identifiers, this process may take some time on large tables.
|
# Run conversion to BigInt identifiers, this process may take some time on large tables.
|
||||||
sudo -u www-data php /usr/local/lib/owncloud/occ db:convert-filecache-bigint --no-interaction
|
sudo -u www-data php$PHP_VER /usr/local/lib/owncloud/occ db:convert-filecache-bigint --no-interaction
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# Nextcloud Version to install. Checks are done down below to step through intermediate versions.
|
|
||||||
nextcloud_ver=20.0.8
|
|
||||||
nextcloud_hash=372b0b4bb07c7984c04917aff86b280e68fbe761
|
|
||||||
contacts_ver=3.5.1
|
|
||||||
contacts_hash=d2ffbccd3ed89fa41da20a1dff149504c3b33b93
|
|
||||||
calendar_ver=2.2.0
|
|
||||||
calendar_hash=673ad72ca28adb8d0f209015ff2dca52ffad99af
|
|
||||||
user_external_ver=1.0.0
|
|
||||||
user_external_hash=3bf2609061d7214e7f0f69dd8883e55c4ec8f50a
|
|
||||||
|
|
||||||
# Current Nextcloud Version, #1623
|
# Current Nextcloud Version, #1623
|
||||||
# Checking /usr/local/lib/owncloud/version.php shows version of the Nextcloud application, not the DB
|
# Checking /usr/local/lib/owncloud/version.php shows version of the Nextcloud application, not the DB
|
||||||
# $STORAGE_ROOT/owncloud is kept together even during a backup. It is better to rely on config.php than
|
# $STORAGE_ROOT/owncloud is kept together even during a backup. It is better to rely on config.php than
|
||||||
@@ -114,7 +142,7 @@ user_external_hash=3bf2609061d7214e7f0f69dd8883e55c4ec8f50a
|
|||||||
|
|
||||||
# If config.php exists, get version number, otherwise CURRENT_NEXTCLOUD_VER is empty.
|
# If config.php exists, get version number, otherwise CURRENT_NEXTCLOUD_VER is empty.
|
||||||
if [ -f "$STORAGE_ROOT/owncloud/config.php" ]; then
|
if [ -f "$STORAGE_ROOT/owncloud/config.php" ]; then
|
||||||
CURRENT_NEXTCLOUD_VER=$(php -r "include(\"$STORAGE_ROOT/owncloud/config.php\"); echo(\$CONFIG['version']);")
|
CURRENT_NEXTCLOUD_VER=$(php$PHP_VER -r "include(\"$STORAGE_ROOT/owncloud/config.php\"); echo(\$CONFIG['version']);")
|
||||||
else
|
else
|
||||||
CURRENT_NEXTCLOUD_VER=""
|
CURRENT_NEXTCLOUD_VER=""
|
||||||
fi
|
fi
|
||||||
@@ -123,8 +151,8 @@ fi
|
|||||||
# from the version currently installed, do the install/upgrade
|
# from the version currently installed, do the install/upgrade
|
||||||
if [ ! -d /usr/local/lib/owncloud/ ] || [[ ! ${CURRENT_NEXTCLOUD_VER} =~ ^$nextcloud_ver ]]; then
|
if [ ! -d /usr/local/lib/owncloud/ ] || [[ ! ${CURRENT_NEXTCLOUD_VER} =~ ^$nextcloud_ver ]]; then
|
||||||
|
|
||||||
# Stop php-fpm if running. If theyre not running (which happens on a previously failed install), dont bail.
|
# Stop php-fpm if running. If they are not running (which happens on a previously failed install), dont bail.
|
||||||
service php7.2-fpm stop &> /dev/null || /bin/true
|
service php$PHP_VER-fpm stop &> /dev/null || /bin/true
|
||||||
|
|
||||||
# Backup the existing ownCloud/Nextcloud.
|
# Backup the existing ownCloud/Nextcloud.
|
||||||
# Create a backup directory to store the current installation and database to
|
# Create a backup directory to store the current installation and database to
|
||||||
@@ -151,41 +179,21 @@ if [ ! -d /usr/local/lib/owncloud/ ] || [[ ! ${CURRENT_NEXTCLOUD_VER} =~ ^$nextc
|
|||||||
elif [[ ${CURRENT_NEXTCLOUD_VER} =~ ^1[012] ]]; then
|
elif [[ ${CURRENT_NEXTCLOUD_VER} =~ ^1[012] ]]; then
|
||||||
echo "Upgrades from Mail-in-a-Box prior to v0.28 (dated July 30, 2018) with Nextcloud < 13.0.6 (you have ownCloud 10, 11 or 12) are not supported. Upgrade to Mail-in-a-Box version v0.30 first. Setup will continue, but skip the Nextcloud migration."
|
echo "Upgrades from Mail-in-a-Box prior to v0.28 (dated July 30, 2018) with Nextcloud < 13.0.6 (you have ownCloud 10, 11 or 12) are not supported. Upgrade to Mail-in-a-Box version v0.30 first. Setup will continue, but skip the Nextcloud migration."
|
||||||
return 0
|
return 0
|
||||||
elif [[ ${CURRENT_NEXTCLOUD_VER} =~ ^13 ]]; then
|
elif [[ ${CURRENT_NEXTCLOUD_VER} =~ ^1[3456789] ]]; then
|
||||||
# If we are running Nextcloud 13, upgrade to Nextcloud 14
|
echo "Upgrades from Mail-in-a-Box prior to v60 with Nextcloud 19 or earlier are not supported. Upgrade to the latest Mail-in-a-Box version supported on your machine first. Setup will continue, but skip the Nextcloud migration."
|
||||||
InstallNextcloud 14.0.6 4e43a57340f04c2da306c8eea98e30040399ae5a 3.3.0 e55d0357c6785d3b1f3b5f21780cb6d41d32443a 2.0.3 9d9717b29337613b72c74e9914c69b74b346c466
|
return 0
|
||||||
CURRENT_NEXTCLOUD_VER="14.0.6"
|
|
||||||
fi
|
fi
|
||||||
if [[ ${CURRENT_NEXTCLOUD_VER} =~ ^14 ]]; then
|
if [[ ${CURRENT_NEXTCLOUD_VER} =~ ^20 ]]; then
|
||||||
# During the upgrade from Nextcloud 14 to 15, user_external may cause the upgrade to fail.
|
InstallNextcloud 21.0.7 f5c7079c5b56ce1e301c6a27c0d975d608bb01c9 4.0.7 45e7cf4bfe99cd8d03625cf9e5a1bb2e90549136 3.0.4 d0284b68135777ec9ca713c307216165b294d0fe
|
||||||
# We will disable it here before the upgrade and install it again after the upgrade.
|
CURRENT_NEXTCLOUD_VER="21.0.7"
|
||||||
hide_output sudo -u www-data php /usr/local/lib/owncloud/console.php app:disable user_external
|
|
||||||
InstallNextcloud 15.0.8 4129d8d4021c435f2e86876225fb7f15adf764a3 3.3.0 e55d0357c6785d3b1f3b5f21780cb6d41d32443a 2.0.3 9d9717b29337613b72c74e9914c69b74b346c466 0.7.0 555a94811daaf5bdd336c5e48a78aa8567b86437
|
|
||||||
CURRENT_NEXTCLOUD_VER="15.0.8"
|
|
||||||
fi
|
fi
|
||||||
if [[ ${CURRENT_NEXTCLOUD_VER} =~ ^15 ]]; then
|
if [[ ${CURRENT_NEXTCLOUD_VER} =~ ^21 ]]; then
|
||||||
InstallNextcloud 16.0.6 0bb3098455ec89f5af77a652aad553ad40a88819 3.3.0 e55d0357c6785d3b1f3b5f21780cb6d41d32443a 2.0.3 9d9717b29337613b72c74e9914c69b74b346c466 0.7.0 555a94811daaf5bdd336c5e48a78aa8567b86437
|
InstallNextcloud 22.2.6 9d39741f051a8da42ff7df46ceef2653a1dc70d9 4.1.0 697f6b4a664e928d72414ea2731cb2c9d1dc3077 3.2.2 ce4030ab57f523f33d5396c6a81396d440756f5f 3.0.0 0df781b261f55bbde73d8c92da3f99397000972f
|
||||||
CURRENT_NEXTCLOUD_VER="16.0.6"
|
CURRENT_NEXTCLOUD_VER="22.2.6"
|
||||||
fi
|
|
||||||
if [[ ${CURRENT_NEXTCLOUD_VER} =~ ^16 ]]; then
|
|
||||||
InstallNextcloud 17.0.6 50b98d2c2f18510b9530e558ced9ab51eb4f11b0 3.3.0 e55d0357c6785d3b1f3b5f21780cb6d41d32443a 2.0.3 9d9717b29337613b72c74e9914c69b74b346c466 0.7.0 555a94811daaf5bdd336c5e48a78aa8567b86437
|
|
||||||
CURRENT_NEXTCLOUD_VER="17.0.6"
|
|
||||||
fi
|
|
||||||
if [[ ${CURRENT_NEXTCLOUD_VER} =~ ^17 ]]; then
|
|
||||||
echo "ALTER TABLE oc_flow_operations ADD COLUMN entity VARCHAR;" | sqlite3 $STORAGE_ROOT/owncloud/owncloud.db
|
|
||||||
InstallNextcloud 18.0.10 39c0021a8b8477c3f1733fddefacfa5ebf921c68 3.4.1 aee680a75e95f26d9285efd3c1e25cf7f3bfd27e 2.0.3 9d9717b29337613b72c74e9914c69b74b346c466 1.0.0 3bf2609061d7214e7f0f69dd8883e55c4ec8f50a
|
|
||||||
CURRENT_NEXTCLOUD_VER="18.0.10"
|
|
||||||
fi
|
|
||||||
if [[ ${CURRENT_NEXTCLOUD_VER} =~ ^18 ]]; then
|
|
||||||
InstallNextcloud 19.0.4 01e98791ba12f4860d3d4047b9803f97a1b55c60 3.4.1 aee680a75e95f26d9285efd3c1e25cf7f3bfd27e 2.0.3 9d9717b29337613b72c74e9914c69b74b346c466 1.0.0 3bf2609061d7214e7f0f69dd8883e55c4ec8f50a
|
|
||||||
CURRENT_NEXTCLOUD_VER="19.0.4"
|
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
InstallNextcloud $nextcloud_ver $nextcloud_hash $contacts_ver $contacts_hash $calendar_ver $calendar_hash $user_external_ver $user_external_hash
|
InstallNextcloud $nextcloud_ver $nextcloud_hash $contacts_ver $contacts_hash $calendar_ver $calendar_hash $user_external_ver $user_external_hash
|
||||||
|
|
||||||
# Nextcloud 20 needs to have some optional columns added
|
|
||||||
sudo -u www-data php /usr/local/lib/owncloud/occ db:add-missing-columns
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# ### Configuring Nextcloud
|
# ### Configuring Nextcloud
|
||||||
@@ -211,9 +219,9 @@ if [ ! -f $STORAGE_ROOT/owncloud/owncloud.db ]; then
|
|||||||
'overwrite.cli.url' => '/cloud',
|
'overwrite.cli.url' => '/cloud',
|
||||||
'user_backends' => array(
|
'user_backends' => array(
|
||||||
array(
|
array(
|
||||||
'class' => 'OC_User_IMAP',
|
'class' => '\OCA\UserExternal\IMAP',
|
||||||
'arguments' => array(
|
'arguments' => array(
|
||||||
'127.0.0.1', 143, null
|
'127.0.0.1', 143, null, null, false, false
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -256,7 +264,7 @@ EOF
|
|||||||
# Execute Nextcloud's setup step, which creates the Nextcloud sqlite database.
|
# Execute Nextcloud's setup step, which creates the Nextcloud sqlite database.
|
||||||
# It also wipes it if it exists. And it updates config.php with database
|
# It also wipes it if it exists. And it updates config.php with database
|
||||||
# settings and deletes the autoconfig.php file.
|
# settings and deletes the autoconfig.php file.
|
||||||
(cd /usr/local/lib/owncloud; sudo -u www-data php /usr/local/lib/owncloud/index.php;)
|
(cd /usr/local/lib/owncloud; sudo -u www-data php$PHP_VER /usr/local/lib/owncloud/index.php;)
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Update config.php.
|
# Update config.php.
|
||||||
@@ -272,10 +280,12 @@ fi
|
|||||||
# Use PHP to read the settings file, modify it, and write out the new settings array.
|
# Use PHP to read the settings file, modify it, and write out the new settings array.
|
||||||
TIMEZONE=$(cat /etc/timezone)
|
TIMEZONE=$(cat /etc/timezone)
|
||||||
CONFIG_TEMP=$(/bin/mktemp)
|
CONFIG_TEMP=$(/bin/mktemp)
|
||||||
php <<EOF > $CONFIG_TEMP && mv $CONFIG_TEMP $STORAGE_ROOT/owncloud/config.php;
|
php$PHP_VER <<EOF > $CONFIG_TEMP && mv $CONFIG_TEMP $STORAGE_ROOT/owncloud/config.php;
|
||||||
<?php
|
<?php
|
||||||
include("$STORAGE_ROOT/owncloud/config.php");
|
include("$STORAGE_ROOT/owncloud/config.php");
|
||||||
|
|
||||||
|
\$CONFIG['config_is_read_only'] = true;
|
||||||
|
|
||||||
\$CONFIG['trusted_domains'] = array('$PRIMARY_HOSTNAME');
|
\$CONFIG['trusted_domains'] = array('$PRIMARY_HOSTNAME');
|
||||||
|
|
||||||
\$CONFIG['memcache.local'] = '\OC\Memcache\APCu';
|
\$CONFIG['memcache.local'] = '\OC\Memcache\APCu';
|
||||||
@@ -287,7 +297,14 @@ include("$STORAGE_ROOT/owncloud/config.php");
|
|||||||
|
|
||||||
\$CONFIG['mail_domain'] = '$PRIMARY_HOSTNAME';
|
\$CONFIG['mail_domain'] = '$PRIMARY_HOSTNAME';
|
||||||
|
|
||||||
\$CONFIG['user_backends'] = array(array('class' => 'OC_User_IMAP','arguments' => array('127.0.0.1', 143, null),),);
|
\$CONFIG['user_backends'] = array(
|
||||||
|
array(
|
||||||
|
'class' => '\OCA\UserExternal\IMAP',
|
||||||
|
'arguments' => array(
|
||||||
|
'127.0.0.1', 143, null, null, false, false
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
echo "<?php\n\\\$CONFIG = ";
|
echo "<?php\n\\\$CONFIG = ";
|
||||||
var_export(\$CONFIG);
|
var_export(\$CONFIG);
|
||||||
@@ -300,25 +317,25 @@ chown www-data.www-data $STORAGE_ROOT/owncloud/config.php
|
|||||||
# The firstrunwizard gave Josh all sorts of problems, so disabling that.
|
# The firstrunwizard gave Josh all sorts of problems, so disabling that.
|
||||||
# user_external is what allows Nextcloud to use IMAP for login. The contacts
|
# user_external is what allows Nextcloud to use IMAP for login. The contacts
|
||||||
# and calendar apps are the extensions we really care about here.
|
# and calendar apps are the extensions we really care about here.
|
||||||
hide_output sudo -u www-data php /usr/local/lib/owncloud/console.php app:disable firstrunwizard
|
hide_output sudo -u www-data php$PHP_VER /usr/local/lib/owncloud/console.php app:disable firstrunwizard
|
||||||
hide_output sudo -u www-data php /usr/local/lib/owncloud/console.php app:enable user_external
|
hide_output sudo -u www-data php$PHP_VER /usr/local/lib/owncloud/console.php app:enable user_external
|
||||||
hide_output sudo -u www-data php /usr/local/lib/owncloud/console.php app:enable contacts
|
hide_output sudo -u www-data php$PHP_VER /usr/local/lib/owncloud/console.php app:enable contacts
|
||||||
hide_output sudo -u www-data php /usr/local/lib/owncloud/console.php app:enable calendar
|
hide_output sudo -u www-data php$PHP_VER /usr/local/lib/owncloud/console.php app:enable calendar
|
||||||
|
|
||||||
# When upgrading, run the upgrade script again now that apps are enabled. It seems like
|
# When upgrading, run the upgrade script again now that apps are enabled. It seems like
|
||||||
# the first upgrade at the top won't work because apps may be disabled during upgrade?
|
# the first upgrade at the top won't work because apps may be disabled during upgrade?
|
||||||
# Check for success (0=ok, 3=no upgrade needed).
|
# Check for success (0=ok, 3=no upgrade needed).
|
||||||
sudo -u www-data php /usr/local/lib/owncloud/occ upgrade
|
sudo -u www-data php$PHP_VER /usr/local/lib/owncloud/occ upgrade
|
||||||
if [ \( $? -ne 0 \) -a \( $? -ne 3 \) ]; then exit 1; fi
|
if [ \( $? -ne 0 \) -a \( $? -ne 3 \) ]; then exit 1; fi
|
||||||
|
|
||||||
# Disable default apps that we don't support
|
# Disable default apps that we don't support
|
||||||
sudo -u www-data \
|
sudo -u www-data \
|
||||||
php /usr/local/lib/owncloud/occ app:disable photos dashboard activity \
|
php$PHP_VER /usr/local/lib/owncloud/occ app:disable photos dashboard activity \
|
||||||
| (grep -v "No such app enabled" || /bin/true)
|
| (grep -v "No such app enabled" || /bin/true)
|
||||||
|
|
||||||
# Set PHP FPM values to support large file uploads
|
# Set PHP FPM values to support large file uploads
|
||||||
# (semicolon is the comment character in this file, hashes produce deprecation warnings)
|
# (semicolon is the comment character in this file, hashes produce deprecation warnings)
|
||||||
tools/editconf.py /etc/php/7.2/fpm/php.ini -c ';' \
|
tools/editconf.py /etc/php/$PHP_VER/fpm/php.ini -c ';' \
|
||||||
upload_max_filesize=16G \
|
upload_max_filesize=16G \
|
||||||
post_max_size=16G \
|
post_max_size=16G \
|
||||||
output_buffering=16384 \
|
output_buffering=16384 \
|
||||||
@@ -327,7 +344,7 @@ tools/editconf.py /etc/php/7.2/fpm/php.ini -c ';' \
|
|||||||
short_open_tag=On
|
short_open_tag=On
|
||||||
|
|
||||||
# Set Nextcloud recommended opcache settings
|
# Set Nextcloud recommended opcache settings
|
||||||
tools/editconf.py /etc/php/7.2/cli/conf.d/10-opcache.ini -c ';' \
|
tools/editconf.py /etc/php/$PHP_VER/cli/conf.d/10-opcache.ini -c ';' \
|
||||||
opcache.enable=1 \
|
opcache.enable=1 \
|
||||||
opcache.enable_cli=1 \
|
opcache.enable_cli=1 \
|
||||||
opcache.interned_strings_buffer=8 \
|
opcache.interned_strings_buffer=8 \
|
||||||
@@ -336,23 +353,20 @@ tools/editconf.py /etc/php/7.2/cli/conf.d/10-opcache.ini -c ';' \
|
|||||||
opcache.save_comments=1 \
|
opcache.save_comments=1 \
|
||||||
opcache.revalidate_freq=1
|
opcache.revalidate_freq=1
|
||||||
|
|
||||||
# If apc is explicitly disabled we need to enable it
|
# Migrate users_external data from <0.6.0 to version 3.0.0 (see https://github.com/nextcloud/user_external).
|
||||||
if grep -q apc.enabled=0 /etc/php/7.2/mods-available/apcu.ini; then
|
# This version was probably in use in Mail-in-a-Box v0.41 (February 26, 2019) and earlier.
|
||||||
tools/editconf.py /etc/php/7.2/mods-available/apcu.ini -c ';' \
|
# We moved to v0.6.3 in 193763f8. Ignore errors - maybe there are duplicated users with the
|
||||||
apc.enabled=1
|
# correct backend already.
|
||||||
fi
|
sqlite3 $STORAGE_ROOT/owncloud/owncloud.db "UPDATE oc_users_external SET backend='127.0.0.1';" || /bin/true
|
||||||
|
|
||||||
# Set up a cron job for Nextcloud.
|
# Set up a cron job for Nextcloud.
|
||||||
cat > /etc/cron.d/mailinabox-nextcloud << EOF;
|
cat > /etc/cron.d/mailinabox-nextcloud << EOF;
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# Mail-in-a-Box
|
# Mail-in-a-Box
|
||||||
*/5 * * * * root sudo -u www-data php -f /usr/local/lib/owncloud/cron.php
|
*/5 * * * * root sudo -u www-data php$PHP_VER -f /usr/local/lib/owncloud/cron.php
|
||||||
EOF
|
EOF
|
||||||
chmod +x /etc/cron.d/mailinabox-nextcloud
|
chmod +x /etc/cron.d/mailinabox-nextcloud
|
||||||
|
|
||||||
# Remove previous hourly cronjob
|
|
||||||
rm -f /etc/cron.hourly/mailinabox-owncloud
|
|
||||||
|
|
||||||
# There's nothing much of interest that a user could do as an admin for Nextcloud,
|
# There's nothing much of interest that a user could do as an admin for Nextcloud,
|
||||||
# and there's a lot they could mess up, so we don't make any users admins of Nextcloud.
|
# and there's a lot they could mess up, so we don't make any users admins of Nextcloud.
|
||||||
# But if we wanted to, we would do this:
|
# But if we wanted to, we would do this:
|
||||||
@@ -363,4 +377,4 @@ rm -f /etc/cron.hourly/mailinabox-owncloud
|
|||||||
# ```
|
# ```
|
||||||
|
|
||||||
# Enable PHP modules and restart PHP.
|
# Enable PHP modules and restart PHP.
|
||||||
restart_service php7.2-fpm
|
restart_service php$PHP_VER-fpm
|
||||||
|
|||||||
@@ -7,11 +7,11 @@ if [[ $EUID -ne 0 ]]; then
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Check that we are running on Ubuntu 18.04 LTS (or 18.04.xx).
|
# Check that we are running on Ubuntu 20.04 LTS (or 20.04.xx).
|
||||||
if [ "$(lsb_release -d | sed 's/.*:\s*//' | sed 's/18\.04\.[0-9]/18.04/' )" != "Ubuntu 18.04 LTS" ]; then
|
if [ "$( lsb_release --id --short )" != "Ubuntu" ] || [ "$( lsb_release --release --short )" != "22.04" ]; then
|
||||||
echo "Mail-in-a-Box only supports being installed on Ubuntu 18.04, sorry. You are running:"
|
echo "Mail-in-a-Box only supports being installed on Ubuntu 22.04, sorry. You are running:"
|
||||||
echo
|
echo
|
||||||
lsb_release -d | sed 's/.*:\s*//'
|
lsb_release --description --short
|
||||||
echo
|
echo
|
||||||
echo "We can't write scripts that run on every possible setup, sorry."
|
echo "We can't write scripts that run on every possible setup, sorry."
|
||||||
exit 1
|
exit 1
|
||||||
|
|||||||
@@ -67,6 +67,10 @@ fi
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# Create the STORAGE_USER and STORAGE_ROOT directory if they don't already exist.
|
# Create the STORAGE_USER and STORAGE_ROOT directory if they don't already exist.
|
||||||
|
#
|
||||||
|
# Set the directory and all of its parent directories' permissions to world
|
||||||
|
# readable since it holds files owned by different processes.
|
||||||
|
#
|
||||||
# If the STORAGE_ROOT is missing the mailinabox.version file that lists a
|
# If the STORAGE_ROOT is missing the mailinabox.version file that lists a
|
||||||
# migration (schema) number for the files stored there, assume this is a fresh
|
# migration (schema) number for the files stored there, assume this is a fresh
|
||||||
# installation to that directory and write the file to contain the current
|
# installation to that directory and write the file to contain the current
|
||||||
@@ -77,6 +81,8 @@ fi
|
|||||||
if [ ! -d $STORAGE_ROOT ]; then
|
if [ ! -d $STORAGE_ROOT ]; then
|
||||||
mkdir -p $STORAGE_ROOT
|
mkdir -p $STORAGE_ROOT
|
||||||
fi
|
fi
|
||||||
|
f=$STORAGE_ROOT
|
||||||
|
while [[ $f != / ]]; do chmod a+rx "$f"; f=$(dirname "$f"); done;
|
||||||
if [ ! -f $STORAGE_ROOT/mailinabox.version ]; then
|
if [ ! -f $STORAGE_ROOT/mailinabox.version ]; then
|
||||||
setup/migrate.py --current > $STORAGE_ROOT/mailinabox.version
|
setup/migrate.py --current > $STORAGE_ROOT/mailinabox.version
|
||||||
chown $STORAGE_USER.$STORAGE_USER $STORAGE_ROOT/mailinabox.version
|
chown $STORAGE_USER.$STORAGE_USER $STORAGE_ROOT/mailinabox.version
|
||||||
|
|||||||
@@ -75,6 +75,13 @@ then
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# ### Set log retention policy.
|
||||||
|
|
||||||
|
# Set the systemd journal log retention from infinite to 10 days,
|
||||||
|
# since over time the logs take up a large amount of space.
|
||||||
|
# (See https://discourse.mailinabox.email/t/journalctl-reclaim-space-on-small-mailinabox/6728/11.)
|
||||||
|
tools/editconf.py /etc/systemd/journald.conf MaxRetentionSec=10day
|
||||||
|
|
||||||
# ### Add PPAs.
|
# ### Add PPAs.
|
||||||
|
|
||||||
# We install some non-standard Ubuntu packages maintained by other
|
# We install some non-standard Ubuntu packages maintained by other
|
||||||
@@ -90,12 +97,13 @@ fi
|
|||||||
# come from there and minimal Ubuntu installs may have it turned off.
|
# come from there and minimal Ubuntu installs may have it turned off.
|
||||||
hide_output add-apt-repository -y universe
|
hide_output add-apt-repository -y universe
|
||||||
|
|
||||||
# Install the certbot PPA.
|
|
||||||
hide_output add-apt-repository -y ppa:certbot/certbot
|
|
||||||
|
|
||||||
# Install the duplicity PPA.
|
# Install the duplicity PPA.
|
||||||
hide_output add-apt-repository -y ppa:duplicity-team/duplicity-release-git
|
hide_output add-apt-repository -y ppa:duplicity-team/duplicity-release-git
|
||||||
|
|
||||||
|
# Stock PHP is now 8.1, but we're transitioning through 8.0 because
|
||||||
|
# of Nextcloud.
|
||||||
|
hide_output add-apt-repository --y ppa:ondrej/php
|
||||||
|
|
||||||
# ### Update Packages
|
# ### Update Packages
|
||||||
|
|
||||||
# Update system packages to make sure we have the latest upstream versions
|
# Update system packages to make sure we have the latest upstream versions
|
||||||
@@ -116,9 +124,6 @@ apt_get_quiet autoremove
|
|||||||
|
|
||||||
# Install basic utilities.
|
# Install basic utilities.
|
||||||
#
|
#
|
||||||
# * haveged: Provides extra entropy to /dev/random so it doesn't stall
|
|
||||||
# when generating random numbers for private keys (e.g. during
|
|
||||||
# ldns-keygen).
|
|
||||||
# * unattended-upgrades: Apt tool to install security updates automatically.
|
# * unattended-upgrades: Apt tool to install security updates automatically.
|
||||||
# * cron: Runs background processes periodically.
|
# * cron: Runs background processes periodically.
|
||||||
# * ntp: keeps the system time correct
|
# * ntp: keeps the system time correct
|
||||||
@@ -132,8 +137,8 @@ apt_get_quiet autoremove
|
|||||||
|
|
||||||
echo Installing system packages...
|
echo Installing system packages...
|
||||||
apt_install python3 python3-dev python3-pip python3-setuptools \
|
apt_install python3 python3-dev python3-pip python3-setuptools \
|
||||||
netcat-openbsd wget curl git sudo coreutils bc \
|
netcat-openbsd wget curl git sudo coreutils bc file \
|
||||||
haveged pollinate openssh-client unzip \
|
pollinate openssh-client unzip \
|
||||||
unattended-upgrades cron ntp fail2ban rsyslog
|
unattended-upgrades cron ntp fail2ban rsyslog
|
||||||
|
|
||||||
# ### Suppress Upgrade Prompts
|
# ### Suppress Upgrade Prompts
|
||||||
@@ -324,7 +329,7 @@ fi #NODOC
|
|||||||
# If more queries than specified are sent, bind9 returns SERVFAIL. After flushing the cache during system checks,
|
# If more queries than specified are sent, bind9 returns SERVFAIL. After flushing the cache during system checks,
|
||||||
# we ran into the limit thus we are increasing it from 75 (default value) to 100.
|
# we ran into the limit thus we are increasing it from 75 (default value) to 100.
|
||||||
apt_install bind9
|
apt_install bind9
|
||||||
tools/editconf.py /etc/default/bind9 \
|
tools/editconf.py /etc/default/named \
|
||||||
"OPTIONS=\"-u bind -4\""
|
"OPTIONS=\"-u bind -4\""
|
||||||
if ! grep -q "listen-on " /etc/bind/named.conf.options; then
|
if ! grep -q "listen-on " /etc/bind/named.conf.options; then
|
||||||
# Add a listen-on directive if it doesn't exist inside the options block.
|
# Add a listen-on directive if it doesn't exist inside the options block.
|
||||||
@@ -356,6 +361,7 @@ systemctl restart systemd-resolved
|
|||||||
rm -f /etc/fail2ban/jail.local # we used to use this file but don't anymore
|
rm -f /etc/fail2ban/jail.local # we used to use this file but don't anymore
|
||||||
rm -f /etc/fail2ban/jail.d/defaults-debian.conf # removes default config so we can manage all of fail2ban rules in one config
|
rm -f /etc/fail2ban/jail.d/defaults-debian.conf # removes default config so we can manage all of fail2ban rules in one config
|
||||||
cat conf/fail2ban/jails.conf \
|
cat conf/fail2ban/jails.conf \
|
||||||
|
| sed "s/PUBLIC_IPV6/$PUBLIC_IPV6/g" \
|
||||||
| sed "s/PUBLIC_IP/$PUBLIC_IP/g" \
|
| sed "s/PUBLIC_IP/$PUBLIC_IP/g" \
|
||||||
| sed "s#STORAGE_ROOT#$STORAGE_ROOT#" \
|
| sed "s#STORAGE_ROOT#$STORAGE_ROOT#" \
|
||||||
> /etc/fail2ban/jail.d/mailinabox.conf
|
> /etc/fail2ban/jail.d/mailinabox.conf
|
||||||
|
|||||||
18
setup/web.sh
18
setup/web.sh
@@ -19,7 +19,7 @@ fi
|
|||||||
|
|
||||||
echo "Installing Nginx (web server)..."
|
echo "Installing Nginx (web server)..."
|
||||||
|
|
||||||
apt_install nginx php-cli php-fpm idn2
|
apt_install nginx php${PHP_VER}-cli php${PHP_VER}-fpm idn2
|
||||||
|
|
||||||
rm -f /etc/nginx/sites-enabled/default
|
rm -f /etc/nginx/sites-enabled/default
|
||||||
|
|
||||||
@@ -46,15 +46,15 @@ tools/editconf.py /etc/nginx/nginx.conf -s \
|
|||||||
ssl_protocols="TLSv1.2 TLSv1.3;"
|
ssl_protocols="TLSv1.2 TLSv1.3;"
|
||||||
|
|
||||||
# Tell PHP not to expose its version number in the X-Powered-By header.
|
# Tell PHP not to expose its version number in the X-Powered-By header.
|
||||||
tools/editconf.py /etc/php/7.2/fpm/php.ini -c ';' \
|
tools/editconf.py /etc/php/$PHP_VER/fpm/php.ini -c ';' \
|
||||||
expose_php=Off
|
expose_php=Off
|
||||||
|
|
||||||
# Set PHPs default charset to UTF-8, since we use it. See #367.
|
# Set PHPs default charset to UTF-8, since we use it. See #367.
|
||||||
tools/editconf.py /etc/php/7.2/fpm/php.ini -c ';' \
|
tools/editconf.py /etc/php/$PHP_VER/fpm/php.ini -c ';' \
|
||||||
default_charset="UTF-8"
|
default_charset="UTF-8"
|
||||||
|
|
||||||
# Configure the path environment for php-fpm
|
# Configure the path environment for php-fpm
|
||||||
tools/editconf.py /etc/php/7.2/fpm/pool.d/www.conf -c ';' \
|
tools/editconf.py /etc/php/$PHP_VER/fpm/pool.d/www.conf -c ';' \
|
||||||
env[PATH]=/usr/local/bin:/usr/bin:/bin \
|
env[PATH]=/usr/local/bin:/usr/bin:/bin \
|
||||||
|
|
||||||
# Configure php-fpm based on the amount of memory the machine has
|
# Configure php-fpm based on the amount of memory the machine has
|
||||||
@@ -64,7 +64,7 @@ tools/editconf.py /etc/php/7.2/fpm/pool.d/www.conf -c ';' \
|
|||||||
TOTAL_PHYSICAL_MEM=$(head -n 1 /proc/meminfo | awk '{print $2}' || /bin/true)
|
TOTAL_PHYSICAL_MEM=$(head -n 1 /proc/meminfo | awk '{print $2}' || /bin/true)
|
||||||
if [ $TOTAL_PHYSICAL_MEM -lt 1000000 ]
|
if [ $TOTAL_PHYSICAL_MEM -lt 1000000 ]
|
||||||
then
|
then
|
||||||
tools/editconf.py /etc/php/7.2/fpm/pool.d/www.conf -c ';' \
|
tools/editconf.py /etc/php/$PHP_VER/fpm/pool.d/www.conf -c ';' \
|
||||||
pm=ondemand \
|
pm=ondemand \
|
||||||
pm.max_children=8 \
|
pm.max_children=8 \
|
||||||
pm.start_servers=2 \
|
pm.start_servers=2 \
|
||||||
@@ -72,7 +72,7 @@ then
|
|||||||
pm.max_spare_servers=3
|
pm.max_spare_servers=3
|
||||||
elif [ $TOTAL_PHYSICAL_MEM -lt 2000000 ]
|
elif [ $TOTAL_PHYSICAL_MEM -lt 2000000 ]
|
||||||
then
|
then
|
||||||
tools/editconf.py /etc/php/7.2/fpm/pool.d/www.conf -c ';' \
|
tools/editconf.py /etc/php/$PHP_VER/fpm/pool.d/www.conf -c ';' \
|
||||||
pm=ondemand \
|
pm=ondemand \
|
||||||
pm.max_children=16 \
|
pm.max_children=16 \
|
||||||
pm.start_servers=4 \
|
pm.start_servers=4 \
|
||||||
@@ -80,14 +80,14 @@ then
|
|||||||
pm.max_spare_servers=6
|
pm.max_spare_servers=6
|
||||||
elif [ $TOTAL_PHYSICAL_MEM -lt 3000000 ]
|
elif [ $TOTAL_PHYSICAL_MEM -lt 3000000 ]
|
||||||
then
|
then
|
||||||
tools/editconf.py /etc/php/7.2/fpm/pool.d/www.conf -c ';' \
|
tools/editconf.py /etc/php/$PHP_VER/fpm/pool.d/www.conf -c ';' \
|
||||||
pm=dynamic \
|
pm=dynamic \
|
||||||
pm.max_children=60 \
|
pm.max_children=60 \
|
||||||
pm.start_servers=6 \
|
pm.start_servers=6 \
|
||||||
pm.min_spare_servers=3 \
|
pm.min_spare_servers=3 \
|
||||||
pm.max_spare_servers=9
|
pm.max_spare_servers=9
|
||||||
else
|
else
|
||||||
tools/editconf.py /etc/php/7.2/fpm/pool.d/www.conf -c ';' \
|
tools/editconf.py /etc/php/$PHP_VER/fpm/pool.d/www.conf -c ';' \
|
||||||
pm=dynamic \
|
pm=dynamic \
|
||||||
pm.max_children=120 \
|
pm.max_children=120 \
|
||||||
pm.start_servers=12 \
|
pm.start_servers=12 \
|
||||||
@@ -147,7 +147,7 @@ chown -R $STORAGE_USER $STORAGE_ROOT/www
|
|||||||
|
|
||||||
# Start services.
|
# Start services.
|
||||||
restart_service nginx
|
restart_service nginx
|
||||||
restart_service php7.2-fpm
|
restart_service php$PHP_VER-fpm
|
||||||
|
|
||||||
# Open ports.
|
# Open ports.
|
||||||
ufw_allow http
|
ufw_allow http
|
||||||
|
|||||||
@@ -22,19 +22,25 @@ source /etc/mailinabox.conf # load global vars
|
|||||||
echo "Installing Roundcube (webmail)..."
|
echo "Installing Roundcube (webmail)..."
|
||||||
apt_install \
|
apt_install \
|
||||||
dbconfig-common \
|
dbconfig-common \
|
||||||
php-cli php-sqlite3 php-intl php-json php-common php-curl php-ldap \
|
php${PHP_VER}-cli php${PHP_VER}-sqlite3 php${PHP_VER}-intl php${PHP_VER}-common php${PHP_VER}-curl php${PHP_VER}-imap \
|
||||||
php-gd php-pspell tinymce libjs-jquery libjs-jquery-mousewheel libmagic1 php-mbstring
|
php${PHP_VER}-gd php${PHP_VER}-pspell php${PHP_VER}-mbstring libjs-jquery libjs-jquery-mousewheel libmagic1
|
||||||
|
|
||||||
# Install Roundcube from source if it is not already present or if it is out of date.
|
# Install Roundcube from source if it is not already present or if it is out of date.
|
||||||
# Combine the Roundcube version number with the commit hash of plugins to track
|
# Combine the Roundcube version number with the commit hash of plugins to track
|
||||||
# whether we have the latest version of everything.
|
# whether we have the latest version of everything.
|
||||||
|
# For the latest versions, see:
|
||||||
VERSION=1.5-rc
|
# https://github.com/roundcube/roundcubemail/releases
|
||||||
HASH=a7cb2a39702536d769c7ff93f716e27f0b93f9d9
|
# https://github.com/mfreiholz/persistent_login/commits/master
|
||||||
PERSISTENT_LOGIN_VERSION=6b3fc450cae23ccb2f393d0ef67aa319e877e435 # version 5.2.0
|
# https://github.com/stremlau/html5_notifier/commits/master
|
||||||
|
# https://github.com/mstilkerich/rcmcarddav/releases
|
||||||
|
# The easiest way to get the package hashes is to run this script and get the hash from
|
||||||
|
# the error message.
|
||||||
|
VERSION=1.6.0
|
||||||
|
HASH=fd84b4fac74419bb73e7a3bcae1978d5589c52de
|
||||||
|
PERSISTENT_LOGIN_VERSION=bde7b6840c7d91de627ea14e81cf4133cbb3c07a # version 5.2
|
||||||
HTML5_NOTIFIER_VERSION=68d9ca194212e15b3c7225eb6085dbcf02fd13d7 # version 0.6.4+
|
HTML5_NOTIFIER_VERSION=68d9ca194212e15b3c7225eb6085dbcf02fd13d7 # version 0.6.4+
|
||||||
CARDDAV_VERSION=3.0.3
|
CARDDAV_VERSION=4.4.3
|
||||||
CARDDAV_HASH=d1e3b0d851ffa2c6bd42bf0c04f70d0e1d0d78f8
|
CARDDAV_HASH=74f8ba7aee33e78beb9de07f7f44b81f6071b644
|
||||||
|
|
||||||
UPDATE_KEY=$VERSION:$PERSISTENT_LOGIN_VERSION:$HTML5_NOTIFIER_VERSION:$CARDDAV_VERSION
|
UPDATE_KEY=$VERSION:$PERSISTENT_LOGIN_VERSION:$HTML5_NOTIFIER_VERSION:$CARDDAV_VERSION
|
||||||
|
|
||||||
@@ -77,13 +83,13 @@ if [ $needs_update == 1 ]; then
|
|||||||
|
|
||||||
# download and verify the full release of the carddav plugin
|
# download and verify the full release of the carddav plugin
|
||||||
wget_verify \
|
wget_verify \
|
||||||
https://github.com/blind-coder/rcmcarddav/releases/download/v${CARDDAV_VERSION}/carddav-${CARDDAV_VERSION}.zip \
|
https://github.com/mstilkerich/rcmcarddav/releases/download/v${CARDDAV_VERSION}/carddav-v${CARDDAV_VERSION}.tar.gz \
|
||||||
$CARDDAV_HASH \
|
$CARDDAV_HASH \
|
||||||
/tmp/carddav.zip
|
/tmp/carddav.tar.gz
|
||||||
|
|
||||||
# unzip and cleanup
|
# unzip and cleanup
|
||||||
unzip -q /tmp/carddav.zip -d ${RCM_PLUGIN_DIR}
|
tar -C ${RCM_PLUGIN_DIR} -zxf /tmp/carddav.tar.gz
|
||||||
rm -f /tmp/carddav.zip
|
rm -f /tmp/carddav.tar.gz
|
||||||
|
|
||||||
# record the version we've installed
|
# record the version we've installed
|
||||||
echo $UPDATE_KEY > ${RCM_DIR}/version
|
echo $UPDATE_KEY > ${RCM_DIR}/version
|
||||||
@@ -109,8 +115,7 @@ cat > $RCM_CONFIG <<EOF;
|
|||||||
\$config['log_dir'] = '/var/log/roundcubemail/';
|
\$config['log_dir'] = '/var/log/roundcubemail/';
|
||||||
\$config['temp_dir'] = '/var/tmp/roundcubemail/';
|
\$config['temp_dir'] = '/var/tmp/roundcubemail/';
|
||||||
\$config['db_dsnw'] = 'sqlite:///$STORAGE_ROOT/mail/roundcube/roundcube.sqlite?mode=0640';
|
\$config['db_dsnw'] = 'sqlite:///$STORAGE_ROOT/mail/roundcube/roundcube.sqlite?mode=0640';
|
||||||
\$config['default_host'] = 'ssl://localhost';
|
\$config['imap_host'] = 'ssl://localhost:993';
|
||||||
\$config['default_port'] = 993;
|
|
||||||
\$config['imap_conn_options'] = array(
|
\$config['imap_conn_options'] = array(
|
||||||
'ssl' => array(
|
'ssl' => array(
|
||||||
'verify_peer' => false,
|
'verify_peer' => false,
|
||||||
@@ -118,7 +123,7 @@ cat > $RCM_CONFIG <<EOF;
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
\$config['imap_timeout'] = 15;
|
\$config['imap_timeout'] = 15;
|
||||||
\$config['smtp_server'] = 'tls://127.0.0.1';
|
\$config['smtp_host'] = 'tls://127.0.0.1';
|
||||||
\$config['smtp_conn_options'] = array(
|
\$config['smtp_conn_options'] = array(
|
||||||
'ssl' => array(
|
'ssl' => array(
|
||||||
'verify_peer' => false,
|
'verify_peer' => false,
|
||||||
@@ -135,6 +140,10 @@ cat > $RCM_CONFIG <<EOF;
|
|||||||
\$config['login_username_filter'] = 'email';
|
\$config['login_username_filter'] = 'email';
|
||||||
\$config['password_charset'] = 'UTF-8';
|
\$config['password_charset'] = 'UTF-8';
|
||||||
\$config['junk_mbox'] = 'Spam';
|
\$config['junk_mbox'] = 'Spam';
|
||||||
|
/* ensure roudcube session id's aren't leaked to other parts of the server */
|
||||||
|
\$config['session_path'] = '/mail/';
|
||||||
|
/* prevent CSRF, requires php 7.3+ */
|
||||||
|
\$config['session_samesite'] = 'Strict';
|
||||||
?>
|
?>
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
@@ -148,7 +157,7 @@ cat > ${RCM_PLUGIN_DIR}/carddav/config.inc.php <<EOF;
|
|||||||
'name' => 'ownCloud',
|
'name' => 'ownCloud',
|
||||||
'username' => '%u', // login username
|
'username' => '%u', // login username
|
||||||
'password' => '%p', // login password
|
'password' => '%p', // login password
|
||||||
'url' => 'https://${PRIMARY_HOSTNAME}/cloud/remote.php/carddav/addressbooks/%u/contacts',
|
'url' => 'https://${PRIMARY_HOSTNAME}/cloud/remote.php/dav/addressbooks/users/%u/contacts/',
|
||||||
'active' => true,
|
'active' => true,
|
||||||
'readonly' => false,
|
'readonly' => false,
|
||||||
'refresh_time' => '02:00:00',
|
'refresh_time' => '02:00:00',
|
||||||
@@ -196,10 +205,10 @@ chown -f -R root.www-data ${RCM_PLUGIN_DIR}/carddav
|
|||||||
chmod -R 774 ${RCM_PLUGIN_DIR}/carddav
|
chmod -R 774 ${RCM_PLUGIN_DIR}/carddav
|
||||||
|
|
||||||
# Run Roundcube database migration script (database is created if it does not exist)
|
# Run Roundcube database migration script (database is created if it does not exist)
|
||||||
${RCM_DIR}/bin/updatedb.sh --dir ${RCM_DIR}/SQL --package roundcube
|
php$PHP_VER ${RCM_DIR}/bin/updatedb.sh --dir ${RCM_DIR}/SQL --package roundcube
|
||||||
chown www-data:www-data $STORAGE_ROOT/mail/roundcube/roundcube.sqlite
|
chown www-data:www-data $STORAGE_ROOT/mail/roundcube/roundcube.sqlite
|
||||||
chmod 664 $STORAGE_ROOT/mail/roundcube/roundcube.sqlite
|
chmod 664 $STORAGE_ROOT/mail/roundcube/roundcube.sqlite
|
||||||
|
|
||||||
# Enable PHP modules.
|
# Enable PHP modules.
|
||||||
phpenmod -v php mcrypt imap
|
phpenmod -v $PHP_VER imap
|
||||||
restart_service php7.2-fpm
|
restart_service php$PHP_VER-fpm
|
||||||
|
|||||||
@@ -17,9 +17,9 @@ source /etc/mailinabox.conf # load global vars
|
|||||||
|
|
||||||
echo "Installing Z-Push (Exchange/ActiveSync server)..."
|
echo "Installing Z-Push (Exchange/ActiveSync server)..."
|
||||||
apt_install \
|
apt_install \
|
||||||
php-soap php-imap libawl-php php-xsl
|
php${PHP_VER}-soap php${PHP_VER}-imap libawl-php php$PHP_VER-xml
|
||||||
|
|
||||||
phpenmod -v php imap
|
phpenmod -v $PHP_VER imap
|
||||||
|
|
||||||
# Copy Z-Push into place.
|
# Copy Z-Push into place.
|
||||||
VERSION=2.6.2
|
VERSION=2.6.2
|
||||||
@@ -42,8 +42,6 @@ if [ $needs_update == 1 ]; then
|
|||||||
rm -rf /tmp/z-push.zip /tmp/z-push
|
rm -rf /tmp/z-push.zip /tmp/z-push
|
||||||
|
|
||||||
rm -f /usr/sbin/z-push-{admin,top}
|
rm -f /usr/sbin/z-push-{admin,top}
|
||||||
ln -s /usr/local/lib/z-push/z-push-admin.php /usr/sbin/z-push-admin
|
|
||||||
ln -s /usr/local/lib/z-push/z-push-top.php /usr/sbin/z-push-top
|
|
||||||
echo $VERSION > /usr/local/lib/z-push/version
|
echo $VERSION > /usr/local/lib/z-push/version
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -102,8 +100,8 @@ EOF
|
|||||||
|
|
||||||
# Restart service.
|
# Restart service.
|
||||||
|
|
||||||
restart_service php7.2-fpm
|
restart_service php$PHP_VER-fpm
|
||||||
|
|
||||||
# Fix states after upgrade
|
# Fix states after upgrade
|
||||||
|
|
||||||
hide_output z-push-admin -a fixstates
|
hide_output php$PHP_VER /usr/local/lib/z-push/z-push-admin.php -a fixstates
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ def test(server, description):
|
|||||||
(hostname, "TXT", "\"v=spf1 mx -all\""),
|
(hostname, "TXT", "\"v=spf1 mx -all\""),
|
||||||
("mail._domainkey." + hostname, "TXT", "\"v=DKIM1; k=rsa; s=email; \" \"p=__KEY__\""),
|
("mail._domainkey." + hostname, "TXT", "\"v=DKIM1; k=rsa; s=email; \" \"p=__KEY__\""),
|
||||||
#("_adsp._domainkey." + hostname, "TXT", "\"dkim=all\""),
|
#("_adsp._domainkey." + hostname, "TXT", "\"dkim=all\""),
|
||||||
("_dmarc." + hostname, "TXT", "\"v=DMARC1; p=quarantine\""),
|
("_dmarc." + hostname, "TXT", "\"v=DMARC1; p=quarantine;\""),
|
||||||
]
|
]
|
||||||
return test2(tests, server, description)
|
return test2(tests, server, description)
|
||||||
|
|
||||||
@@ -48,7 +48,7 @@ def test2(tests, server, description):
|
|||||||
for qname, rtype, expected_answer in tests:
|
for qname, rtype, expected_answer in tests:
|
||||||
# do the query and format the result as a string
|
# do the query and format the result as a string
|
||||||
try:
|
try:
|
||||||
response = dns.resolver.query(qname, rtype)
|
response = dns.resolver.resolve(qname, rtype)
|
||||||
except dns.resolver.NoNameservers:
|
except dns.resolver.NoNameservers:
|
||||||
# host did not have an answer for this query
|
# host did not have an answer for this query
|
||||||
print("Could not connect to %s for DNS query." % server)
|
print("Could not connect to %s for DNS query." % server)
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ server = smtplib.SMTP_SSL(host)
|
|||||||
ipaddr = socket.gethostbyname(host) # IPv4 only!
|
ipaddr = socket.gethostbyname(host) # IPv4 only!
|
||||||
reverse_ip = dns.reversename.from_address(ipaddr) # e.g. "1.0.0.127.in-addr.arpa."
|
reverse_ip = dns.reversename.from_address(ipaddr) # e.g. "1.0.0.127.in-addr.arpa."
|
||||||
try:
|
try:
|
||||||
reverse_dns = dns.resolver.query(reverse_ip, 'PTR')[0].target.to_text(omit_final_dot=True) # => hostname
|
reverse_dns = dns.resolver.resolve(reverse_ip, 'PTR')[0].target.to_text(omit_final_dot=True) # => hostname
|
||||||
except dns.resolver.NXDOMAIN:
|
except dns.resolver.NXDOMAIN:
|
||||||
print("Reverse DNS lookup failed for %s. SMTP EHLO name check skipped." % ipaddr)
|
print("Reverse DNS lookup failed for %s. SMTP EHLO name check skipped." % ipaddr)
|
||||||
reverse_dns = None
|
reverse_dns = None
|
||||||
|
|||||||
@@ -14,6 +14,10 @@
|
|||||||
#
|
#
|
||||||
# NAME VALUE
|
# NAME VALUE
|
||||||
#
|
#
|
||||||
|
# If the -e option is given and VALUE is empty, the setting is removed
|
||||||
|
# from the configuration file if it is set (i.e. existing occurrences
|
||||||
|
# are commented out and no new setting is added).
|
||||||
|
#
|
||||||
# If the -c option is given, then the supplied character becomes the comment character
|
# If the -c option is given, then the supplied character becomes the comment character
|
||||||
#
|
#
|
||||||
# If the -w option is given, then setting lines continue onto following
|
# If the -w option is given, then setting lines continue onto following
|
||||||
@@ -35,6 +39,7 @@ settings = sys.argv[2:]
|
|||||||
|
|
||||||
delimiter = "="
|
delimiter = "="
|
||||||
delimiter_re = r"\s*=\s*"
|
delimiter_re = r"\s*=\s*"
|
||||||
|
erase_setting = False
|
||||||
comment_char = "#"
|
comment_char = "#"
|
||||||
folded_lines = False
|
folded_lines = False
|
||||||
testing = False
|
testing = False
|
||||||
@@ -44,6 +49,9 @@ while settings[0][0] == "-" and settings[0] != "--":
|
|||||||
# Space is the delimiter
|
# Space is the delimiter
|
||||||
delimiter = " "
|
delimiter = " "
|
||||||
delimiter_re = r"\s+"
|
delimiter_re = r"\s+"
|
||||||
|
elif opt == "-e":
|
||||||
|
# Erase settings that have empty values.
|
||||||
|
erase_setting = True
|
||||||
elif opt == "-w":
|
elif opt == "-w":
|
||||||
# Line folding is possible in this file.
|
# Line folding is possible in this file.
|
||||||
folded_lines = True
|
folded_lines = True
|
||||||
@@ -81,7 +89,7 @@ while len(input_lines) > 0:
|
|||||||
|
|
||||||
# See if this line is for any settings passed on the command line.
|
# See if this line is for any settings passed on the command line.
|
||||||
for i in range(len(settings)):
|
for i in range(len(settings)):
|
||||||
# Check that this line contain this setting from the command-line arguments.
|
# Check if this line contain this setting from the command-line arguments.
|
||||||
name, val = settings[i].split("=", 1)
|
name, val = settings[i].split("=", 1)
|
||||||
m = re.match(
|
m = re.match(
|
||||||
"(\s*)"
|
"(\s*)"
|
||||||
@@ -91,8 +99,10 @@ while len(input_lines) > 0:
|
|||||||
if not m: continue
|
if not m: continue
|
||||||
indent, is_comment, existing_val = m.groups()
|
indent, is_comment, existing_val = m.groups()
|
||||||
|
|
||||||
# If this is already the setting, do nothing.
|
# If this is already the setting, keep it in the file, except:
|
||||||
if is_comment is None and existing_val == val:
|
# * If we've already seen it before, then remove this duplicate line.
|
||||||
|
# * If val is empty and erase_setting is on, then comment it out.
|
||||||
|
if is_comment is None and existing_val == val and not (not val and erase_setting):
|
||||||
# It may be that we've already inserted this setting higher
|
# It may be that we've already inserted this setting higher
|
||||||
# in the file so check for that first.
|
# in the file so check for that first.
|
||||||
if i in found: break
|
if i in found: break
|
||||||
@@ -107,8 +117,9 @@ while len(input_lines) > 0:
|
|||||||
# the line is already commented, pass it through
|
# the line is already commented, pass it through
|
||||||
buf += line
|
buf += line
|
||||||
|
|
||||||
# if this option oddly appears more than once, don't add the setting again
|
# if this option already is set don't add the setting again,
|
||||||
if i in found:
|
# or if we're clearing the setting with -e, don't add it
|
||||||
|
if (i in found) or (not val and erase_setting):
|
||||||
break
|
break
|
||||||
|
|
||||||
# add the new setting
|
# add the new setting
|
||||||
@@ -122,10 +133,12 @@ while len(input_lines) > 0:
|
|||||||
# If did not match any setting names, pass this line through.
|
# If did not match any setting names, pass this line through.
|
||||||
buf += line
|
buf += line
|
||||||
|
|
||||||
# Put any settings we didn't see at the end of the file.
|
# Put any settings we didn't see at the end of the file,
|
||||||
|
# except settings being cleared.
|
||||||
for i in range(len(settings)):
|
for i in range(len(settings)):
|
||||||
if i not in found:
|
if i not in found:
|
||||||
name, val = settings[i].split("=", 1)
|
name, val = settings[i].split("=", 1)
|
||||||
|
if not (not val and erase_setting):
|
||||||
buf += name + delimiter + val + "\n"
|
buf += name + delimiter + val + "\n"
|
||||||
|
|
||||||
if not testing:
|
if not testing:
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ if [ ! -f $1/config.php ]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
echo "Restoring backup from $1"
|
echo "Restoring backup from $1"
|
||||||
service php7.2-fpm stop
|
service php8.0-fpm stop
|
||||||
|
|
||||||
# remove the current ownCloud/Nextcloud installation
|
# remove the current ownCloud/Nextcloud installation
|
||||||
rm -rf /usr/local/lib/owncloud/
|
rm -rf /usr/local/lib/owncloud/
|
||||||
@@ -43,7 +43,7 @@ ln -sf $STORAGE_ROOT/owncloud/config.php /usr/local/lib/owncloud/config/config.p
|
|||||||
chown -f -R www-data.www-data $STORAGE_ROOT/owncloud /usr/local/lib/owncloud
|
chown -f -R www-data.www-data $STORAGE_ROOT/owncloud /usr/local/lib/owncloud
|
||||||
chown www-data.www-data $STORAGE_ROOT/owncloud/config.php
|
chown www-data.www-data $STORAGE_ROOT/owncloud/config.php
|
||||||
|
|
||||||
sudo -u www-data php /usr/local/lib/owncloud/occ maintenance:mode --off
|
sudo -u www-data php$PHP_VER /usr/local/lib/owncloud/occ maintenance:mode --off
|
||||||
|
|
||||||
service php7.2-fpm start
|
service php8.0-fpm start
|
||||||
echo "Done"
|
echo "Done"
|
||||||
|
|||||||
@@ -20,4 +20,4 @@ echo
|
|||||||
echo Press enter to continue.
|
echo Press enter to continue.
|
||||||
read
|
read
|
||||||
|
|
||||||
sudo -u www-data php /usr/local/lib/owncloud/occ group:adduser admin $ADMIN && echo Done.
|
sudo -u www-data php$PHP_VER /usr/local/lib/owncloud/occ group:adduser admin $ADMIN && echo Done.
|
||||||
|
|||||||
Reference in New Issue
Block a user