【FireFox Send】自建文件加密分享传输网站

本文最后更新于:2022年11月30日 下午

Firefox Send 服务于2019年3月上线,提供了安全、私密的文件托管和文件共享服务。无需注册。但因为这种安全特性,被黑客滥用传播黑客工具。2020 年 7 月,Mozilla 宣布暂时中止 Firefox Send 服务。虽然官方网站很可惜不能用了,但 Firefox 慷慨地开源了网站,我们可以自建来使用。

文件分享服务

可能大家听得比较多的是奶牛快传、sendAnywhere 这些。但其实文件分享服务还有很多,不过基本上我都没用过,所以只是分享一下:

其他可自建:

项目地址

下面会分别介绍原版维护版的安装,建议用维护版,兼容 ffsend

Requirements

  • Node.js 12.x (原版)
  • Node.js 16.x (维护版)
  • Redis server (可选)
  • AWS S3 or compatible service (可选)
  • git

本文教程假设

  • 你有一个服务器
  • 你懂基本的 Linux 命令行操作

本文基于 Ubuntu 20.04 系统,其他 Linux 系统类似,但不保证可行性。

安装依赖

1
2
apt update && apt upgrade -y
apt install git nginx nodejs npm

安装 redis【可选】

docker-compose 安装

1
2
mkdir -p /opt/redis && cd /opt/redis
vim /opt/redis/docker-compose.yml

输入:

1
2
3
4
5
6
7
8
9
10
version: '3'
services:
cache:
image: redis:6.2-alpine
restart: always
ports:
- '127.0.0.1:6379:6379'
command: redis-server --save 20 1 --loglevel warning
volumes:
- ./data:/data

启动

1
cd /opt/redis && docker-compose up -d

开始安装

注意,不能使用 root 用户来编译!所以我们需要新建用户并切换至新用户。

下载

原版

1
2
mkdir /opt/send/ && cd /opt/send
git clone https://github.com/tech-fever/send.git htdocs

维护版

1
2
mkdir /opt/send/ && cd /opt/send
git clone https://github.com/timvisee/send.git htdocs

新建用户

1
2
adduser --disabled-login send
chown -R send:send /opt/send/htdocs

原版依赖问题【可跳过不看】

由于原版 FireFox Send 已经不再维护,它的依赖 webcrypto-core 是旧版本的。

参考:(谈firefox-send安装与new Error(“Cannot find module ‘webcrypto-core’”);错误)[https://fudaoyuan.icu/2022/02/25/%E8%B0%88firefox-send%E5%AE%89%E8%A3%85%E4%B8%8Enew-errorcannot-find-module-webcrypto-core%E9%94%99%E8%AF%AF/]

所以这个仓库是在原来代码上进行了修改,在 package.json 中增加一行

1
"webcrypto-core": "github:mozilla-fxa/webcrypto-core"

编译安装

输入下面命令:

1
2
3
4
5
6
su - send
cd /opt/send/htdocs
# 安装依赖
npm install
# 构建生产环境
npm run build

运行

根据官方文档,是使用 su www-data -c ,但会出现提示 This account is currently not available. 因为 www-datano-login 的。所以换别的。

维护版的运行

维护版还需要额外添加环境变量,可选的变量有:

NameDescription
BASE_URLThe HTTPS URL where traffic will be served (e.g. https://send.firefox.com)
DETECT_BASE_URLAutodetect the base URL using browser if BASE_URL is unset (defaults to false)
PORTPort the server will listen on (defaults to 1443)
NODE_ENVRun in development mode (unsafe) or production mode (the default)
SEND_FOOTER_DMCA_URLA URL to a contact page for DMCA requests (empty / not shown by default)
SENTRY_CLIENT, SENTRY_DSNSentry Client ID and DNS for error tracking (optional, disabled by default)

Note: more options can be found here: https://github.com/timvisee/send/blob/master/server/config.js

NameDescription
MAX_FILE_SIZEMaximum upload file size in bytes (defaults to 2147483648 aka 2GB)
MAX_FILES_PER_ARCHIVEMaximum number of files per archive (defaults to 64)
MAX_EXPIRE_SECONDSMaximum upload expiry time in seconds (defaults to 604800 aka 7 days)
MAX_DOWNLOADSMaximum number of downloads (defaults to 100)
DOWNLOAD_COUNTSDownload limit options to show in UI dropdown, e.g. 10,1,2,5,10,15,25,50,100,1000
EXPIRE_TIMES_SECONDSExpire time options to show in UI dropdown, e.g. 3600,86400,604800,2592000,31536000
DEFAULT_DOWNLOADSDefault download limit in UI (defaults to 1)
DEFAULT_EXPIRE_SECONDSDefault expire time in UI (defaults to 86400)

新建 .env 文件:

1
2
DETECT_BASE_URL=true
REDIS_HOST=localhost

如果使用了 redis 就加入第二行,没有的话就删除

用 root 用户创建脚本,先退出回到root用户

1
exit

再使用root用户:

1
2
cd /opt/send
vim run.sh

输入脚本内容:

1
2
#!/bin/bash
cd /opt/send/htdocs && export $(xargs < .env) && nohup su send -c "npm run prod" 2>/dev/null &

运行:

1
chmod +x run.sh && ./run.sh

原版的运行

nohup 运行就行,运行脚本

1
2
cd /opt/send
vim run.sh

输入:

1
2
#!/bin/bash
cd /opt/send/htdocs && nohup su send -c "npm run prod" 2>/dev/null &

之后

1
chmod +x run.sh && ./run.sh

Nginx 反代

记得修改 send.example.com 成你的:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
server {
listen 80;
listen [::]:80;
server_name send.example.com;

return 301 https://$host$request_uri;
}

server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
# Replace bark.app.dev with your real domain name.
server_name send.example.com;

ssl_certificate /etc/letsencrypt/live/send.example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/send.example.com/privkey.pem;
ssl_session_timeout 1d;
ssl_session_cache shared:MozSSL:10m; # about 40000 sessions
ssl_session_tickets off;

# modern configuration
ssl_protocols TLSv1.3;
ssl_prefer_server_ciphers off;

# HSTS (ngx_http_headers_module is required) (63072000 seconds)
add_header Strict-Transport-Security "max-age=63072000" always;

# OCSP stapling
ssl_stapling on;
ssl_stapling_verify on;

# verify chain of trust of OCSP response using Root CA and Intermediate certs
# ssl_trusted_certificate /path/to/root_CA_cert_plus_intermediates;

# replace with the IP address of your resolver
#resolver 127.0.0.1;

location / {
proxy_pass http://localhost:1443;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_buffering off;
proxy_cache off;
proxy_set_header X-Forwarded-Proto $scheme;
}
location /api/ws {
proxy_redirect off;
proxy_pass ws://localhost:1443;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $http_host;
}
}

【FireFox Send】自建文件加密分享传输网站
https://pawswrite.xyz/posts/4ae3f173.html
作者
Rainbow
发布于
2022年10月15日
许可协议