进阶使用

储存标签分页

关闭您托管的 OnionShare 标签页会破坏它们,防止重复使用。即使共享网站的计算机重启,永久托管的网站仍可在同一地址上使用。

在启动服务器之前,通过选中“启动 OnionShare 时始终打开此标签页”框,使任何标签页持久化。

_images/advanced-save-tabs.png

打开 OnionShare 时,您之前会话中保存的标签页将开始打开。然后可以手动启动每个服务,这些服务将在同一个 OnionShare 地址上可用,并受同一个私钥保护。

如果您保存了一个标签页,其洋葱服务密钥的副本将存储在您的计算机上。

关闭私钥

所有 OnionShare 服务默认都使用私钥保护,Tor 称之为“客户端验证”。

加载 OnionShare 服务时,Tor 浏览器将要求您输入私钥。如果您想允许公众使用您的服务,最好完全禁用私钥。

要关闭任何标签页的私钥,请在启动服务器之前选中“这是一项公共 OnionShare 服务(禁用私钥)”框。然后服务器将公开,并且不需要私钥即可在 Tor 浏览器中加载它。

自定义标题

当人们在 Tor 浏览器中加载 OnionShare 服务时,他们会看到每种服务的默认标题。例如,聊天服务的默认标题是“OnionShare Chat”。

如果在启动服务器之前编辑“自定义标题”设置,则可以更改它。

排程的时间

OnionShare 具排程功能可设定服务开始与停止时间。在启动服务器前,点击标签分页中”显示进阶设定”再分别勾选”在排定时间启动 OnionShare”、”在排定时间关闭 OnionShare” 旁边的小方块,来安排日期和时刻。

当点击“开始分享”按钮时,计划在未来启动的服务会显示倒计时器。计划在未来停止的服务在启动时显示倒计时器。

将 OnionShare 服务安排为自动启动可以作为一个死开关。这意味着,如果您不在那里阻止,您的服务将在未来的某个特定时间公开。如果您没有发生任何事情,您可以在计划启动之前取消该服务。

_images/advanced-schedule-start-timer.png

安排 OnionShare 服务自动停止会限制其暴露。如果您想分享秘密信息或一些将过期的信息,您可以在选定的有限时间内进行分享。

_images/advanced-schedule-stop-timer.png

命令行界面

除了图形界面外,OnionShare 还有命令行界面。

安装 CLI 版本

如果安装了 Snap、macOS 或 Windows 软件包,则已经安装了 CLI 版本。

另外,您可以使用 pip3 只安装 OnionShare 的命令行版本:

pip3 install --user onionshare-cli

记住这需要已安装``tor``软件包,macOS 可透过 ``brew install tor``来安装

然后像这样执行:

onionshare-cli --help

有关在不同操作系统上安装它的信息可以在 Git 存储库中的 CLI README 文件 中找到。

从 Snap 运行 CLI

如果使用 Snap 软件包安装了 OnionShare,可以运行 onionshare.cli 来访问命令行界面版本。

从 macOS 运行 CLI

从终端可以运行 /Applications/OnionShare.app/Contents/MacOS/onionshare-cli --help

从 Windows 运行 CLI

在 Windows 安装中,可执行文件 onionshare-cli.exe 可以使用。

使用

通过运行 onionshare --help 浏览命令行文档:

$ onionshare-cli --help
╭───────────────────────────────────────────╮
│    *            ▄▄█████▄▄            *    │
│               ▄████▀▀▀████▄     *         │
│              ▀▀█▀       ▀██▄              │
│      *      ▄█▄          ▀██▄             │
│           ▄█████▄         ███        -+-  │
│             ███         ▀█████▀           │
│             ▀██▄          ▀█▀             │
│         *    ▀██▄       ▄█▄▄     *        │
│ *             ▀████▄▄▄████▀               │
│                 ▀▀█████▀▀                 │
│             -+-                     *     │
│   ▄▀▄               ▄▀▀ █                 │
│   █ █     ▀         ▀▄  █                 │
│   █ █ █▀▄ █ ▄▀▄ █▀▄  ▀▄ █▀▄ ▄▀▄ █▄▀ ▄█▄   │
│   ▀▄▀ █ █ █ ▀▄▀ █ █ ▄▄▀ █ █ ▀▄█ █   ▀▄▄   │
│                                           │
│                  v2.4.1                   │
│                                           │
│          https://onionshare.org/          │
╰───────────────────────────────────────────╯

usage: onionshare-cli [-h] [--receive] [--website] [--chat] [--local-only] [--connect-timeout SECONDS] [--config FILENAME] [--persistent FILENAME] [--title TITLE] [--public]
                      [--auto-start-timer SECONDS] [--auto-stop-timer SECONDS] [--no-autostop-sharing] [--log-filenames] [--qr] [--data-dir data_dir] [--webhook-url webhook_url] [--disable-text]
                      [--disable-files] [--disable_csp] [--custom_csp custom_csp] [-v]
                      [filename ...]

positional arguments:
  filename                  List of files or folders to share

optional arguments:
  -h, --help                Show this help message and exit
  --receive                 Receive files
  --website                 Publish website
  --chat                    Start chat server
  --local-only              Don't use Tor (only for development)
  --connect-timeout SECONDS
                            Give up connecting to Tor after a given amount of seconds (default: 120)
  --config FILENAME         Filename of custom global settings
  --persistent FILENAME     Filename of persistent session
  --title TITLE             Set a title
  --public                  Don't use a private key
  --auto-start-timer SECONDS
                            Start onion service at scheduled time (N seconds from now)
  --auto-stop-timer SECONDS
                            Stop onion service at scheduled time (N seconds from now)
  --no-autostop-sharing     Share files: Continue sharing after files have been sent (the default is to stop sharing)
  --log-filenames           Log file download activity to stdout
  --qr                      Display a QR code in the terminal for share links
  --data-dir data_dir       Receive files: Save files received to this directory
  --webhook-url webhook_url
                            Receive files: URL to receive webhook notifications
  --disable-text            Receive files: Disable receiving text messages
  --disable-files           Receive files: Disable receiving files
  --disable_csp             Publish website: Disable the default Content Security Policy header (allows your website to use third-party resources)
  --custom_csp custom_csp   Publish website: Set a custom Content Security Policy header
  -v, --verbose             Log OnionShare errors to stdout, and web errors to disk

将 CLI 作为 systemd 单元文件运行

可以使用 systemd 单元文件从 CLI 自动启动 OnionShare。

如果您以“持久”模式运行,并且想要每次启动设备时都启动相同的洋葱服务,您可能会发现这特别有用。

为此,您需要先准备一些 OnionShare JSON 配置。

此处是主要的 OnionShare 配置。在此示例中,它存储在 /home/user/.config/onionshare/onionshare.json。您可能需要调整其中的一些设置,但如果您已经安装了 OnionShare,它看起来可能已经和这个类似:

{
  "version": "2.6.2",
  "connection_type": "bundled",
  "control_port_address": "127.0.0.1",
  "control_port_port": 9051,
  "socks_address": "127.0.0.1",
  "socks_port": 9050,
  "socket_file_path": "/var/run/tor/control",
  "auth_type": "no_auth",
  "auth_password": "",
  "auto_connect": true,
  "use_autoupdate": true,
  "autoupdate_timestamp": null,
  "bridges_enabled": false,
  "bridges_type": "built-in",
  "bridges_builtin_pt": "obfs4",
  "bridges_moat": "",
  "bridges_custom": "",
  "bridges_builtin": {},
  "persistent_tabs": [
      "my-persistent-onion"
  ],
  "locale": "en",
  "theme": 0
}

注意“persistent_tabs”部分。现在,我们将在 /home/user/.config/onionshare/persistent/my-persistent-onion.json 创建文件,类似这样:

{
  "onion": {
      "private_key": "UDIaZD8QgoXRP8JnAJ+pnlogQazfZ0wrfWJk5zPBGUBqg6+lozzjUJKTYWxwrxR33pDgJdTFtCUN1CX1FE22UQ==",
      "client_auth_priv_key": "RHJSN4VI3NKGDSIWK45CCWTLYOJHA6DQQRQXUID3FXMAILYXWVUQ",
      "client_auth_pub_key": "J4YLYAHS25UU3TZTE27H32RN3MCRGLR345U52XS2JNQ76CCHCRSQ"
  },
  "persistent": {
      "mode": "share",
      "enabled": true
  },
  "general": {
      "title": null,
      "public": false,
      "autostart_timer": 0,
      "autostop_timer": 0,
      "service_id": "niktadkcp6z7rym3r5o3j2hnmis53mno5ughvur357xo7jkjvmqrchid",
      "qr": false
  },
  "share": {
     "autostop_sharing": true,
     "filenames": [
       "/home/user/my-shared-file.txt"
     ]
  },
  "receive": {
     "data_dir": "/home/user/OnionShare",
     "webhook_url": null,
     "disable_text": false,
     "disable_files": false
  },
  "website": {
     "disable_csp": false,
     "custom_csp": null,
     "filenames": []
  },
  "chat": {}
}

请勿实际使用此私钥、service_id 或 client_auth 密钥!它们仅作为示例显示。切勿与任何人分享私钥。

生成洋葱地址和私钥的最简单方法是,先在桌面应用中创建“固定”的 OnionShare 标签页,并首次启动分享。这会将持久设置以随机名称保存到 .config/onionshare/persistent/ 文件夹。您可以在首次生成后取消固定该标签页。或者,也可以将其留在原处,并在下方 systemd 单元文件中使用该持久文件。

现在,您可以在 /etc/systemd/system/onionshare-cli.service 创建 systemd 单元文件。请确保将用户和组调整为您自己的用户/组,并更改 onionshare-cli 二进制文件的任何路径或 JSON 配置和共享的路径。

systemd 单元文件应该类似这样:

[Unit]
Description=OnionShare CLI
After=network.target

[Service]
ExecStart=/home/user/.local/bin/onionshare-cli --persistent /home/user/.config/onionshare/persistent/my-persistent-onion.json /home/user/my-shared-file.txt
Restart=on-failure
User=user
Group=user

[Install]
WantedBy=multi-user.target

请注意,尽管在 my-persistent-onion.json 文件的 filenames 部分定义了 /home/user/my-shared-file.txt,但仍有必要将其指定为 onionshare-cli 命令的参数。

请确保在创建单元文件后运行 sudo systemctl daemon-reload

现在您可以运行 sudo systemctl start onionshare-cli.service。如果安装了 journalctl,可以运行 sudo journalctl -f -t onionshare-cli,您应该看到服务启动的一些输出:

[...]
Feb 09 10:14:09 onionshare onionshare-cli[18852]: [6.5K blob data]
Feb 09 10:14:18 onionshare onionshare-cli[18852]: Compressing files.
Feb 09 10:14:18 onionshare onionshare-cli[18852]: Give this address and private key to the recipient:
Feb 09 10:14:18 onionshare onionshare-cli[18852]: http://niktadkcp6z7rym3r5o3j2hnmis53mno5ughvur357xo7jkjvmqrchid.onion
Feb 09 10:14:18 onionshare onionshare-cli[18852]: Private key: RHJSN4VI3NKGDSIWK45CCWTLYOJHA6DQQRQXUID3FXMAILYXWVUQ
Feb 09 10:14:18 onionshare onionshare-cli[18852]: Press Ctrl+C to stop the server

如果不想让用户使用私钥,可在 my-persistent-onion.json 文件的``常规``设置中将 public 设为 true

键盘快捷键

OnionShare 桌面应用程序包含一些键盘快捷键,以方便使用和访问:

Ctrl T - New Tab
Ctrl X - Closes current tab

从主模式选择器屏幕:

Ctrl S - Share mode
Ctrl R - Receive mode
Ctrl W - Website mode
Ctrl C - Chat mode
Ctrl H - Settings tab

将 OnionShare 数据迁移到另一台计算机上

当切换到另一台计算机时,您可能想迁移您的 OnionShare 数据。如果您有“持久”的洋葱地址并想要保留它,则尤其如此。

OnionShare 会将所有这些数据存储在特定文件夹中。将下方操作系统相关的文件夹复制到新计算机:

  • Linux: ~/.config/onionshare

  • macOS: ~/Library/Application Support/OnionShare

  • Windows: %APPDATA%\OnionShare

配置文件参数

OnionShare 将其设置存储在 JSON 文件中。CLI 和桌面版本都使用此配置文件。CLI 还可让您使用 --config 指定自定义配置文件的路径。

以下是配置文件参数及其含义。如果您的配置文件中有其他未在此处列出的参数,它们可能已从旧版本的 OnionShare 中过时。

参数

类型

说明

版本

string

OnionShare 的版本。您永远不需要更改此值。

connection_type

string

OnionShare 连接到 Tor 的方式。有效选项包括 ‘bundled’、’automatic’(使用 Tor 浏览器的 Tor 连接)、’control_port’ 或 ‘socket_file’。默认:’bundled’

control_port_address

string

如果 connection_type 设置为 ‘control_port’,即 Tor 控制端口的 IP 地址。默认:’127.0.0.1’

control_port_port

integer

如果 connection_type 设置为 ‘control_port’,即 Tor 控制端口的的端口号。默认:’9051’

socks_address

string

如果 connection_type 设置为 ‘control_port’ 或 ‘socket_file’,即 Tor 的 SOCKS 代理的 IP 地址。默认:’127.0.0.1’

socks_port

integer

如果 connection_type 设置为 ‘control_port’ 或 ‘socket_file’,即 Tor 的 SOCKS 代理的端口号。默认:’’9050’

socket_file_path

string

如果 connection_type 设置为 ‘socket_file’,即 Tor 的 Socket 文件路径。默认:’/var/run/tor/control’

auth_type

string

如果访问 Tor 的控制端口需要密码,则可以将其设置为 ‘password’,否则设置为 ‘no_auth’。默认:’no_auth’

auth_password

string

如果访问 Tor 的控制端口需要密码,并且 auth_type 设置为 ‘password’,请在此处指定密码。默认:’’

auto_connect

boolean

OnionShare 启动时是否应自动连接到 Tor。默认:False

use_autoupdate

boolean

OnionShare 是否应自动检查更新(通过 Tor)。此设置仅适用于 MacOS 或 Windows 安装。默认:True。

autoupdate_timestamp

integer

OnionShare 上次检查更新的时间。默认:None

bridges_enabled

boolean

是否使用网桥连接到 Tor。默认:False

bridges_type

string

bridges_enabled 为 True 时,网桥加载来源。选项包括 “built-in”(OnionShare 附带的网桥,可能会从 Tor 更新)、”moat”(从 Tor 的 Moat API 请求网桥)或 “custom”(用户提供的网桥)。默认:”built-in”

bridges_builtin_pt

string

bridges_type 设置为 “built-in” 时,这指定了要使用哪种类型的网桥协议。选项有 “obfs4”、”meek-azure” 或 “snowflake”。默认:”obfs4”

bridges_moat

string

bridges_type 设置为 “moat” 时,从 Tor 的 Moat API 返回的网桥将存储在此处。默认:””

bridges_custom

string

bridges_type 设置为 “custom” 时,用户指定的网桥将存储在此处。用 ‘n’ 分隔字符串中的每个网桥行。默认:””

bridges_builtin

dict

bridges_type 设置为 “built-in” 时,OnionShare 会获取 Tor 推荐的最新内置网桥并将其存储在此处。默认:{}

persistent_tabs

list

如果用户将任何标签页定义为 ‘saved’(这意味着在每次 OnionShare 启动时它们都是持久的,并且它们的洋葱地址不会改变),这些标签页将被赋予一个随机标识符,并在此处列出。持久洋葱以与此标识符同名的 JSON 文件存储在 OnionShare 配置文件夹中名为 ‘persistent’ 的子文件夹中。默认:[]

语言区域

string

OnionShare 中使用的语言区域设置。默认:None(与 ‘en’ 相同)。有关有效的语言区域设置代码,请参阅 https://github.com/onionshare/onionshare/blob/main/cli/onionshare_cli/settings.py 中的 ‘available_locales’

主题

boolean

OnionShare 桌面应用的主题。有效选项有 0(自动检测用户计算机的深色或浅色主题)、1(深色)或 2(浅色)。

持久洋葱的配置文件参数

如上所述,每个“持久”洋葱都有自己的参数,这些参数存储在自己的 JSON 文件中。可以使用 --persistent 为 CLI 工具指定此文件的路径。

以下是一个持久 JSON 配置示例:

{
  "onion": {
      "private_key": "0HGxILDDwYhxAB2Zq8mM3Wu3MirBgK7Fw2/tVrTw1XraElH7MWbVn3lzKbcJEapVWz2TFjaoCAVN48hGqraiRg==",
      "client_auth_priv_key": "UT55HDBA5VSRWOUERMGOHEIBKZCMOOGZAFFNI54GDQFZ6CMCUGIQ",
      "client_auth_pub_key": "TPQCMCV26UEDMCWGZCWAWM4FOJSQKZZTVPC5TC3CAGMDWKV255OA"
  },
  "persistent": {
      "mode": "share",
      "enabled": true,
      "autostart_on_launch": false
  },
  "general": {
      "title": null,
      "public": false,
      "autostart_timer": false,
      "autostop_timer": false,
      "service_id": "hvsufvk2anyadehahfqiacy4wbrjt2atpnagk4itlkh4mdfsg6vhd5ad"
  },
  "share": {
      "autostop_sharing": true,
      "filenames": [
          "/home/user/git/onionshare/desktop/org.onionshare.OnionShare.svg"
      ],
      "log_filenames": false
  },
  "receive": {
      "data_dir": "/home/user/OnionShare",
      "webhook_url": null,
      "disable_text": false,
      "disable_files": false
  },
  "website": {
      "disable_csp": false,
      "custom_csp": null,
      "log_filenames": false,
      "filenames": []
  },
  "chat": {}
}

下方是持久洋葱的配置文件参数及其含义,适用于 JSON 中的每个部分

洋葱

参数

类型

说明

private_key

string

Base64 编码的洋葱服务的私钥

client_auth_priv_key

string

使用客户端身份验证时的私钥。将此发送给用户。

client_auth_pub_key

string

使用客户端身份验证时的公钥。在 OnionShare 端使用。

持久

参数

类型

说明

模式

string

此持久洋葱所使用的模式。选项包括“共享”、“接收”、“网站”或“聊天”。

已启用

boolean

是否为此洋葱启用了持久性。当在桌面中不选中持久选项时,会删除整个 JSON 文件。默认:true

autostart_on_launch

boolean

是否在 OnionShare 启动时以及连接 Tor 后自动启动此持久洋葱。默认:false

常规

参数

类型

说明

标题

string

用于在洋葱服务上显示的可选自定义标题。默认:null(将显示“OnionShare”)

公开

boolean

是否可在有无私钥的情况下访问洋葱服务(客户端身份验证)。如果为 true,则不需要私钥。

autostart_timer

boolean

洋葱服务是否配置为在特定时间启动。可在桌面应用中设置时间,也可用 CLI 工具的 --auto-start-timer 以秒为单位指定。默认:false

autostop_timer

boolean

洋葱服务是否配置为在特定时间停止。可在桌面应用中设置时间,也可用 CLI 工具的 --auto-stop-timer 以秒为单位指定。默认:false

service_id

string

32 个字符的洋葱服务 URL,没有方案,也没有 ‘.onion’ 后缀。

以下是特定于上述 persistent 部分中指定的“模式”的设置。

共享

参数

类型

说明

autostop_sharing

boolean

是否在首次下载文件后自动停止共享。默认:true

文件名

list

要共享的文件列表。默认:[]

log_filenames

boolean

使用 CLI 工具时是否将 URL 请求记录到 stdout。默认:false

接收

参数

类型

说明

data_dir

string

接收到的文件或文本消息的存储路径。默认:用户主目录的“OnionShare”文件夹。

webhook_url

string

OnionShare 在接收文件或文本消息时将 POST 到的 webhook URL。默认:null

disable_text

boolean

是否禁用接收文本消息。默认:false

disable_files

boolean

是否禁用接收文件。默认:false

网站

参数

类型

说明

disable_csp

boolean

如果设置为 true,OnionShare 将不会为网站设置默认的内容安全策略标头。默认:false

custom_csp

string

要发送的自定义内容安全策略标头,而不是默认标头。

log_filenames

boolean

使用 CLI 工具时是否将 URL 请求记录到 stdout。默认:false

文件名

list

要共享的文件列表。默认:[]

聊天

当前没有聊天模式的可配置设置。