2014-09-02 20:30:01 -04:00
|
|
|
# -*- coding: utf-8 -*-
|
2014-09-02 15:10:42 -04:00
|
|
|
"""
|
|
|
|
OnionShare | https://onionshare.org/
|
|
|
|
|
2021-02-22 16:35:14 -05:00
|
|
|
Copyright (C) 2014-2021 Micah Lee, et al. <micah@micahflee.com>
|
2014-09-02 15:10:42 -04:00
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
"""
|
2017-01-06 22:00:08 -05:00
|
|
|
|
2021-04-29 20:13:05 -04:00
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
import time
|
|
|
|
import argparse
|
|
|
|
import threading
|
2019-03-11 00:55:17 -04:00
|
|
|
from datetime import datetime
|
|
|
|
from datetime import timedelta
|
2017-01-06 22:00:08 -05:00
|
|
|
|
2020-11-29 14:08:46 -05:00
|
|
|
from .common import Common, CannotFindTor
|
2021-10-18 02:17:47 -04:00
|
|
|
from .censorship import CensorshipCircumvention
|
2021-10-18 20:36:03 -04:00
|
|
|
from .meek import Meek, MeekNotRunning
|
2018-03-05 14:06:59 -05:00
|
|
|
from .web import Web
|
2021-10-18 02:17:47 -04:00
|
|
|
from .onion import TorErrorProtocolError, TorTooOldEphemeral, TorTooOldStealth, Onion
|
2017-04-17 22:28:51 -04:00
|
|
|
from .onionshare import OnionShare
|
2019-11-02 17:56:40 -04:00
|
|
|
from .mode_settings import ModeSettings
|
2017-01-06 22:00:08 -05:00
|
|
|
|
2019-05-21 13:08:54 -04:00
|
|
|
|
2017-01-06 22:00:08 -05:00
|
|
|
def main(cwd=None):
|
|
|
|
"""
|
|
|
|
The main() function implements all of the logic that the command-line version of
|
|
|
|
onionshare uses.
|
|
|
|
"""
|
2018-03-08 13:18:31 -05:00
|
|
|
common = Common()
|
2021-04-26 22:29:18 -04:00
|
|
|
common.display_banner()
|
2017-01-06 22:00:08 -05:00
|
|
|
|
2017-04-17 22:12:02 -04:00
|
|
|
# OnionShare CLI in OSX needs to change current working directory (#132)
|
2019-10-13 00:01:25 -04:00
|
|
|
if common.platform == "Darwin":
|
2017-01-06 22:00:08 -05:00
|
|
|
if cwd:
|
|
|
|
os.chdir(cwd)
|
|
|
|
|
2017-04-17 22:12:02 -04:00
|
|
|
# Parse arguments
|
2019-10-13 00:01:25 -04:00
|
|
|
parser = argparse.ArgumentParser(
|
|
|
|
formatter_class=lambda prog: argparse.HelpFormatter(prog, max_help_position=28)
|
|
|
|
)
|
2019-11-02 18:37:21 -04:00
|
|
|
# Select modes
|
|
|
|
parser.add_argument(
|
|
|
|
"--receive", action="store_true", dest="receive", help="Receive files"
|
|
|
|
)
|
|
|
|
parser.add_argument(
|
|
|
|
"--website", action="store_true", dest="website", help="Publish website"
|
|
|
|
)
|
2020-03-08 05:21:43 -04:00
|
|
|
parser.add_argument(
|
|
|
|
"--chat", action="store_true", dest="chat", help="Start chat server"
|
|
|
|
)
|
2019-11-02 18:37:21 -04:00
|
|
|
# Tor connection-related args
|
2019-10-13 00:01:25 -04:00
|
|
|
parser.add_argument(
|
|
|
|
"--local-only",
|
|
|
|
action="store_true",
|
|
|
|
dest="local_only",
|
2019-11-02 18:37:21 -04:00
|
|
|
default=False,
|
2019-10-13 00:01:25 -04:00
|
|
|
help="Don't use Tor (only for development)",
|
|
|
|
)
|
|
|
|
parser.add_argument(
|
2019-11-02 18:37:21 -04:00
|
|
|
"--connect-timeout",
|
2019-11-03 00:00:23 -04:00
|
|
|
metavar="SECONDS",
|
2019-11-02 18:37:21 -04:00
|
|
|
dest="connect_timeout",
|
|
|
|
default=120,
|
|
|
|
help="Give up connecting to Tor after a given amount of seconds (default: 120)",
|
|
|
|
)
|
|
|
|
parser.add_argument(
|
|
|
|
"--config",
|
2019-11-03 00:00:23 -04:00
|
|
|
metavar="FILENAME",
|
2019-11-02 18:37:21 -04:00
|
|
|
default=None,
|
|
|
|
help="Filename of custom global settings",
|
|
|
|
)
|
|
|
|
# Persistent file
|
|
|
|
parser.add_argument(
|
|
|
|
"--persistent",
|
2019-11-03 00:00:23 -04:00
|
|
|
metavar="FILENAME",
|
2019-11-02 18:37:21 -04:00
|
|
|
default=None,
|
|
|
|
help="Filename of persistent session",
|
|
|
|
)
|
|
|
|
# General args
|
2021-10-18 02:17:47 -04:00
|
|
|
parser.add_argument("--title", metavar="TITLE", default=None, help="Set a title")
|
2019-11-02 18:37:21 -04:00
|
|
|
parser.add_argument(
|
|
|
|
"--public",
|
2019-10-13 00:01:25 -04:00
|
|
|
action="store_true",
|
2019-11-02 18:37:21 -04:00
|
|
|
dest="public",
|
|
|
|
default=False,
|
2021-08-27 01:52:29 -04:00
|
|
|
help="Don't use a private key",
|
2019-10-13 00:01:25 -04:00
|
|
|
)
|
|
|
|
parser.add_argument(
|
|
|
|
"--auto-start-timer",
|
2019-11-03 00:00:23 -04:00
|
|
|
metavar="SECONDS",
|
2019-10-13 00:01:25 -04:00
|
|
|
dest="autostart_timer",
|
|
|
|
default=0,
|
2019-11-02 18:37:21 -04:00
|
|
|
help="Start onion service at scheduled time (N seconds from now)",
|
2019-10-13 00:01:25 -04:00
|
|
|
)
|
|
|
|
parser.add_argument(
|
|
|
|
"--auto-stop-timer",
|
2019-11-03 00:00:23 -04:00
|
|
|
metavar="SECONDS",
|
2019-10-13 00:01:25 -04:00
|
|
|
dest="autostop_timer",
|
|
|
|
default=0,
|
2019-11-02 18:37:21 -04:00
|
|
|
help="Stop onion service at schedule time (N seconds from now)",
|
2019-10-13 00:01:25 -04:00
|
|
|
)
|
2019-11-02 18:37:21 -04:00
|
|
|
# Share args
|
2019-10-13 00:01:25 -04:00
|
|
|
parser.add_argument(
|
2020-11-25 00:52:15 -05:00
|
|
|
"--no-autostop-sharing",
|
2019-10-13 00:01:25 -04:00
|
|
|
action="store_true",
|
2020-11-25 00:52:15 -05:00
|
|
|
dest="no_autostop_sharing",
|
|
|
|
default=False,
|
|
|
|
help="Share files: Continue sharing after files have been sent (default is to stop sharing)",
|
2019-10-13 00:01:25 -04:00
|
|
|
)
|
2019-11-02 18:37:21 -04:00
|
|
|
# Receive args
|
2019-10-13 00:01:25 -04:00
|
|
|
parser.add_argument(
|
2019-11-02 18:37:21 -04:00
|
|
|
"--data-dir",
|
|
|
|
metavar="data_dir",
|
|
|
|
default=None,
|
|
|
|
help="Receive files: Save files received to this directory",
|
2019-10-13 00:01:25 -04:00
|
|
|
)
|
2021-04-11 16:33:58 -04:00
|
|
|
parser.add_argument(
|
|
|
|
"--webhook-url",
|
|
|
|
metavar="webhook_url",
|
|
|
|
default=None,
|
|
|
|
help="Receive files: URL to receive webhook notifications",
|
|
|
|
)
|
2021-04-25 20:46:03 -04:00
|
|
|
parser.add_argument(
|
|
|
|
"--disable-text",
|
|
|
|
action="store_true",
|
|
|
|
dest="disable_text",
|
|
|
|
help="Receive files: Disable receiving text messages",
|
|
|
|
)
|
|
|
|
parser.add_argument(
|
|
|
|
"--disable-files",
|
|
|
|
action="store_true",
|
|
|
|
dest="disable_files",
|
|
|
|
help="Receive files: Disable receiving files",
|
|
|
|
)
|
2019-11-02 18:37:21 -04:00
|
|
|
# Website args
|
2019-10-13 00:01:25 -04:00
|
|
|
parser.add_argument(
|
2019-11-02 18:37:21 -04:00
|
|
|
"--disable_csp",
|
|
|
|
action="store_true",
|
|
|
|
dest="disable_csp",
|
2019-10-13 00:01:25 -04:00
|
|
|
default=False,
|
2019-11-02 18:37:21 -04:00
|
|
|
help="Publish website: Disable Content Security Policy header (allows your website to use third-party resources)",
|
2019-10-13 00:01:25 -04:00
|
|
|
)
|
2019-11-02 18:37:21 -04:00
|
|
|
# Other
|
2019-10-13 00:01:25 -04:00
|
|
|
parser.add_argument(
|
|
|
|
"-v",
|
|
|
|
"--verbose",
|
|
|
|
action="store_true",
|
|
|
|
dest="verbose",
|
|
|
|
help="Log OnionShare errors to stdout, and web errors to disk",
|
|
|
|
)
|
|
|
|
parser.add_argument(
|
|
|
|
"filename",
|
|
|
|
metavar="filename",
|
|
|
|
nargs="*",
|
|
|
|
help="List of files or folders to share",
|
|
|
|
)
|
2017-01-06 22:00:08 -05:00
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
|
|
filenames = args.filename
|
|
|
|
for i in range(len(filenames)):
|
|
|
|
filenames[i] = os.path.abspath(filenames[i])
|
|
|
|
|
2018-03-05 10:45:10 -05:00
|
|
|
receive = bool(args.receive)
|
2019-04-19 08:25:42 -04:00
|
|
|
website = bool(args.website)
|
2020-03-08 05:21:43 -04:00
|
|
|
chat = bool(args.chat)
|
2019-11-02 18:37:21 -04:00
|
|
|
local_only = bool(args.local_only)
|
|
|
|
connect_timeout = int(args.connect_timeout)
|
2019-11-03 00:00:23 -04:00
|
|
|
config_filename = args.config
|
|
|
|
persistent_filename = args.persistent
|
2021-04-12 17:55:16 -04:00
|
|
|
title = args.title
|
2019-11-02 18:37:21 -04:00
|
|
|
public = bool(args.public)
|
|
|
|
autostart_timer = int(args.autostart_timer)
|
|
|
|
autostop_timer = int(args.autostop_timer)
|
2020-11-25 00:52:15 -05:00
|
|
|
autostop_sharing = not bool(args.no_autostop_sharing)
|
2019-11-02 18:37:21 -04:00
|
|
|
data_dir = args.data_dir
|
2021-04-11 16:33:58 -04:00
|
|
|
webhook_url = args.webhook_url
|
2021-04-25 20:46:03 -04:00
|
|
|
disable_text = args.disable_text
|
|
|
|
disable_files = args.disable_files
|
2019-11-02 18:37:21 -04:00
|
|
|
disable_csp = bool(args.disable_csp)
|
|
|
|
verbose = bool(args.verbose)
|
2017-01-06 22:00:08 -05:00
|
|
|
|
2019-11-03 01:32:44 -05:00
|
|
|
# Verbose mode?
|
|
|
|
common.verbose = verbose
|
2017-01-06 22:00:08 -05:00
|
|
|
|
2018-09-30 20:06:29 -04:00
|
|
|
# Re-load settings, if a custom config was passed in
|
2019-11-03 00:00:23 -04:00
|
|
|
if config_filename:
|
|
|
|
common.load_settings(config_filename)
|
2019-09-01 23:45:19 -04:00
|
|
|
else:
|
|
|
|
common.load_settings()
|
2018-03-13 06:28:47 -04:00
|
|
|
|
2019-11-02 17:56:40 -04:00
|
|
|
# Mode settings
|
2019-11-03 00:00:23 -04:00
|
|
|
if persistent_filename:
|
|
|
|
mode_settings = ModeSettings(common, persistent_filename)
|
|
|
|
mode_settings.set("persistent", "enabled", True)
|
|
|
|
else:
|
|
|
|
mode_settings = ModeSettings(common)
|
2019-11-03 01:32:44 -05:00
|
|
|
|
2021-08-31 03:53:50 -04:00
|
|
|
if receive:
|
|
|
|
mode = "receive"
|
|
|
|
elif website:
|
|
|
|
mode = "website"
|
|
|
|
elif chat:
|
|
|
|
mode = "chat"
|
|
|
|
else:
|
|
|
|
mode = "share"
|
|
|
|
|
2019-11-03 00:00:23 -04:00
|
|
|
if mode_settings.just_created:
|
2019-11-03 01:32:44 -05:00
|
|
|
# This means the mode settings were just created, not loaded from disk
|
2021-04-12 17:55:16 -04:00
|
|
|
mode_settings.set("general", "title", title)
|
2019-11-03 00:00:23 -04:00
|
|
|
mode_settings.set("general", "public", public)
|
|
|
|
mode_settings.set("general", "autostart_timer", autostart_timer)
|
|
|
|
mode_settings.set("general", "autostop_timer", autostop_timer)
|
2021-08-31 03:53:50 -04:00
|
|
|
if persistent_filename:
|
|
|
|
mode_settings.set("persistent", "mode", mode)
|
2019-11-03 00:00:23 -04:00
|
|
|
if mode == "share":
|
|
|
|
mode_settings.set("share", "autostop_sharing", autostop_sharing)
|
|
|
|
if mode == "receive":
|
|
|
|
if data_dir:
|
|
|
|
mode_settings.set("receive", "data_dir", data_dir)
|
2021-04-11 16:33:58 -04:00
|
|
|
if webhook_url:
|
|
|
|
mode_settings.set("receive", "webhook_url", webhook_url)
|
2021-04-25 20:46:03 -04:00
|
|
|
mode_settings.set("receive", "disable_text", disable_text)
|
|
|
|
mode_settings.set("receive", "disable_files", disable_files)
|
2019-11-03 00:00:23 -04:00
|
|
|
if mode == "website":
|
|
|
|
mode_settings.set("website", "disable_csp", disable_csp)
|
2019-11-03 01:32:44 -05:00
|
|
|
else:
|
|
|
|
# See what the persistent mode was
|
|
|
|
mode = mode_settings.get("persistent", "mode")
|
|
|
|
|
2019-11-28 22:30:48 -05:00
|
|
|
# In share and website mode, you must supply a list of filenames
|
2019-11-03 01:32:44 -05:00
|
|
|
if mode == "share" or mode == "website":
|
|
|
|
# Unless you passed in a persistent filename, in which case get the filenames from
|
|
|
|
# the mode settings
|
2021-02-22 16:35:14 -05:00
|
|
|
if (
|
|
|
|
persistent_filename
|
|
|
|
and not mode_settings.just_created
|
|
|
|
and len(filenames) != 0
|
|
|
|
):
|
2019-11-03 01:32:44 -05:00
|
|
|
filenames = mode_settings.get(mode, "filenames")
|
|
|
|
|
|
|
|
else:
|
|
|
|
# Make sure filenames given if not using receiver mode
|
|
|
|
if len(filenames) == 0:
|
|
|
|
if persistent_filename:
|
|
|
|
mode_settings.delete()
|
|
|
|
|
|
|
|
parser.print_help()
|
|
|
|
sys.exit()
|
|
|
|
|
|
|
|
# Validate filenames
|
|
|
|
valid = True
|
|
|
|
for filename in filenames:
|
|
|
|
if not os.path.isfile(filename) and not os.path.isdir(filename):
|
|
|
|
print(f"{filename} is not a valid file.")
|
|
|
|
valid = False
|
|
|
|
if not os.access(filename, os.R_OK):
|
|
|
|
print(f"{filename} is not a readable file.")
|
|
|
|
valid = False
|
|
|
|
if not valid:
|
|
|
|
sys.exit()
|
2019-11-02 17:56:40 -04:00
|
|
|
|
2021-02-22 15:53:31 -05:00
|
|
|
# Save the filenames in persistent file
|
|
|
|
if persistent_filename:
|
|
|
|
mode_settings.set(mode, "filenames", filenames)
|
|
|
|
|
2021-04-25 20:46:03 -04:00
|
|
|
# In receive mode, you must allows either text, files, or both
|
|
|
|
if mode == "receive" and disable_text and disable_files:
|
2021-04-29 20:13:05 -04:00
|
|
|
print("You cannot disable both text and files")
|
2021-04-25 20:46:03 -04:00
|
|
|
sys.exit()
|
|
|
|
|
2018-03-05 14:06:59 -05:00
|
|
|
# Create the Web object
|
2019-11-02 17:56:40 -04:00
|
|
|
web = Web(common, False, mode_settings, mode)
|
2018-03-05 14:06:59 -05:00
|
|
|
|
2021-10-18 20:36:03 -04:00
|
|
|
# Create the Meek object and start the meek client
|
2021-10-24 19:44:38 -04:00
|
|
|
# meek = Meek(common)
|
|
|
|
# meek.start()
|
2021-10-18 20:36:03 -04:00
|
|
|
|
|
|
|
# Create the CensorshipCircumvention object to make
|
|
|
|
# API calls to Tor over Meek
|
|
|
|
censorship = CensorshipCircumvention(common, meek)
|
|
|
|
# Example: request recommended bridges, pretending to be from China, using
|
|
|
|
# domain fronting.
|
|
|
|
# censorship_recommended_settings = censorship.request_settings(country="cn")
|
|
|
|
# print(censorship_recommended_settings)
|
2021-10-24 19:44:38 -04:00
|
|
|
# Clean up the meek subprocess once we're done working with the censorship circumvention API
|
|
|
|
# meek.cleanup()
|
2021-10-18 20:36:03 -04:00
|
|
|
|
2017-04-17 22:12:02 -04:00
|
|
|
# Start the Onion object
|
2020-11-29 14:08:46 -05:00
|
|
|
try:
|
|
|
|
onion = Onion(common, use_tmp_dir=True)
|
|
|
|
except CannotFindTor:
|
|
|
|
print("You must install tor to use OnionShare from the command line")
|
|
|
|
if common.platform == "Darwin":
|
|
|
|
print("In macOS, you can do this with Homebrew (https://brew.sh):")
|
|
|
|
print(" brew install tor")
|
|
|
|
sys.exit()
|
|
|
|
|
2017-01-06 22:00:08 -05:00
|
|
|
try:
|
2019-10-13 00:01:25 -04:00
|
|
|
onion.connect(
|
2019-11-02 17:56:40 -04:00
|
|
|
custom_settings=False,
|
2019-11-03 00:00:23 -04:00
|
|
|
config=config_filename,
|
2019-11-02 17:56:40 -04:00
|
|
|
connect_timeout=connect_timeout,
|
|
|
|
local_only=local_only,
|
2019-10-13 00:01:25 -04:00
|
|
|
)
|
2017-01-06 22:00:08 -05:00
|
|
|
except KeyboardInterrupt:
|
|
|
|
print("")
|
|
|
|
sys.exit()
|
2021-04-29 20:13:05 -04:00
|
|
|
except Exception:
|
2020-11-29 15:30:19 -05:00
|
|
|
sys.exit()
|
2017-01-06 22:00:08 -05:00
|
|
|
|
2017-04-17 22:12:02 -04:00
|
|
|
# Start the onionshare app
|
|
|
|
try:
|
2019-03-04 18:28:27 -05:00
|
|
|
common.settings.load()
|
2021-04-11 16:33:58 -04:00
|
|
|
|
|
|
|
# Receive mode needs to know the tor proxy details for webhooks
|
|
|
|
if mode == "receive":
|
|
|
|
if local_only:
|
|
|
|
web.proxies = None
|
|
|
|
else:
|
|
|
|
(socks_address, socks_port) = onion.get_tor_socks_port()
|
|
|
|
web.proxies = {
|
2021-04-24 05:59:53 -04:00
|
|
|
"http": f"socks5h://{socks_address}:{socks_port}",
|
|
|
|
"https": f"socks5h://{socks_address}:{socks_port}",
|
2021-04-11 16:33:58 -04:00
|
|
|
}
|
|
|
|
|
2019-03-24 03:19:50 -04:00
|
|
|
app = OnionShare(common, onion, local_only, autostop_timer)
|
2018-04-28 18:00:23 -04:00
|
|
|
app.choose_port()
|
2019-05-20 22:22:03 -04:00
|
|
|
|
2019-03-04 18:28:27 -05:00
|
|
|
# Delay the startup if a startup timer was set
|
2019-03-24 03:19:50 -04:00
|
|
|
if autostart_timer > 0:
|
2019-03-25 00:05:54 -04:00
|
|
|
# Can't set a schedule that is later than the auto-stop timer
|
2019-11-02 18:37:21 -04:00
|
|
|
if autostop_timer > 0 and autostop_timer < autostart_timer:
|
2019-10-13 00:01:25 -04:00
|
|
|
print(
|
|
|
|
"The auto-stop time can't be the same or earlier than the auto-start time. Please update it to start sharing."
|
|
|
|
)
|
2019-03-24 01:35:53 -04:00
|
|
|
sys.exit()
|
|
|
|
|
2021-03-09 23:04:22 -05:00
|
|
|
app.start_onion_service(mode, mode_settings, False)
|
2021-08-27 01:52:29 -04:00
|
|
|
url = f"http://{app.onion_host}"
|
2019-03-24 03:19:50 -04:00
|
|
|
schedule = datetime.now() + timedelta(seconds=autostart_timer)
|
2019-10-13 00:01:25 -04:00
|
|
|
if mode == "receive":
|
|
|
|
print(
|
2019-11-02 18:37:21 -04:00
|
|
|
f"Files sent to you appear in this folder: {mode_settings.get('receive', 'data_dir')}"
|
2019-10-13 00:01:25 -04:00
|
|
|
)
|
|
|
|
print("")
|
|
|
|
print(
|
2021-04-29 20:13:05 -04:00
|
|
|
"Warning: Receive mode lets people upload files to your computer. Some files can potentially take "
|
|
|
|
"control of your computer if you open them. Only open things from people you trust, or if you know "
|
|
|
|
"what you are doing."
|
2019-10-13 00:01:25 -04:00
|
|
|
)
|
|
|
|
print("")
|
2021-08-27 01:52:29 -04:00
|
|
|
if not mode_settings.get("general", "public"):
|
2021-05-03 20:02:02 -04:00
|
|
|
print(
|
2021-08-27 01:52:29 -04:00
|
|
|
f"Give this address and private key to your sender, and tell them it won't be accessible until: {schedule.strftime('%I:%M:%S%p, %b %d, %y')}"
|
2021-05-03 20:02:02 -04:00
|
|
|
)
|
2021-08-27 01:52:29 -04:00
|
|
|
print(f"Private key: {app.auth_string}")
|
2019-03-11 00:55:17 -04:00
|
|
|
else:
|
2019-10-13 00:01:25 -04:00
|
|
|
print(
|
2019-10-20 13:15:16 -04:00
|
|
|
f"Give this address to your sender, and tell them it won't be accessible until: {schedule.strftime('%I:%M:%S%p, %b %d, %y')}"
|
2019-10-13 00:01:25 -04:00
|
|
|
)
|
2019-03-11 00:55:17 -04:00
|
|
|
else:
|
2021-08-27 01:52:29 -04:00
|
|
|
if not mode_settings.get("general", "public"):
|
2021-05-03 20:02:02 -04:00
|
|
|
print(
|
2021-08-27 01:52:29 -04:00
|
|
|
f"Give this address and private key to your recipient, and tell them it won't be accessible until: {schedule.strftime('%I:%M:%S%p, %b %d, %y')}"
|
2021-05-03 20:02:02 -04:00
|
|
|
)
|
2021-08-27 01:52:29 -04:00
|
|
|
print(f"Private key: {app.auth_string}")
|
2019-03-11 00:55:17 -04:00
|
|
|
else:
|
2019-10-13 00:01:25 -04:00
|
|
|
print(
|
2019-10-20 13:15:16 -04:00
|
|
|
f"Give this address to your recipient, and tell them it won't be accessible until: {schedule.strftime('%I:%M:%S%p, %b %d, %y')}"
|
2019-10-13 00:01:25 -04:00
|
|
|
)
|
2019-03-11 00:55:17 -04:00
|
|
|
print(url)
|
2019-10-13 00:01:25 -04:00
|
|
|
print("")
|
2019-04-19 20:31:34 -04:00
|
|
|
print("Waiting for the scheduled time before starting...")
|
2019-03-11 00:55:17 -04:00
|
|
|
app.onion.cleanup(False)
|
2019-03-24 03:19:50 -04:00
|
|
|
time.sleep(autostart_timer)
|
2020-11-27 14:22:29 -05:00
|
|
|
app.start_onion_service(mode, mode_settings)
|
2019-03-04 18:28:27 -05:00
|
|
|
else:
|
2020-11-27 14:22:29 -05:00
|
|
|
app.start_onion_service(mode, mode_settings)
|
2017-04-17 22:12:02 -04:00
|
|
|
except KeyboardInterrupt:
|
|
|
|
print("")
|
|
|
|
sys.exit()
|
2021-03-09 23:04:22 -05:00
|
|
|
except (TorTooOldEphemeral, TorTooOldStealth, TorErrorProtocolError) as e:
|
2018-09-18 20:17:25 -04:00
|
|
|
print("")
|
|
|
|
sys.exit()
|
2017-04-17 22:12:02 -04:00
|
|
|
|
2019-10-13 00:01:25 -04:00
|
|
|
if mode == "website":
|
2019-04-19 08:25:42 -04:00
|
|
|
# Prepare files to share
|
|
|
|
try:
|
|
|
|
web.website_mode.set_file_info(filenames)
|
|
|
|
except OSError as e:
|
|
|
|
print(e.strerror)
|
|
|
|
sys.exit(1)
|
|
|
|
|
2019-10-13 00:01:25 -04:00
|
|
|
if mode == "share":
|
2018-09-21 14:19:36 -04:00
|
|
|
# Prepare files to share
|
2019-04-19 20:31:34 -04:00
|
|
|
print("Compressing files.")
|
2018-09-21 14:19:36 -04:00
|
|
|
try:
|
|
|
|
web.share_mode.set_file_info(filenames)
|
|
|
|
except OSError as e:
|
|
|
|
print(e.strerror)
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
# Warn about sending large files over Tor
|
2021-10-18 02:17:47 -04:00
|
|
|
if web.share_mode.download_filesize >= 157_286_400: # 150mb
|
2019-10-13 00:01:25 -04:00
|
|
|
print("")
|
2019-04-19 20:31:34 -04:00
|
|
|
print("Warning: Sending a large share could take hours")
|
2019-10-13 00:01:25 -04:00
|
|
|
print("")
|
2017-01-06 22:00:08 -05:00
|
|
|
|
2017-04-17 22:12:02 -04:00
|
|
|
# Start OnionShare http service in new thread
|
2019-11-02 18:37:21 -04:00
|
|
|
t = threading.Thread(target=web.start, args=(app.port,))
|
2017-01-06 22:00:08 -05:00
|
|
|
t.daemon = True
|
|
|
|
t.start()
|
|
|
|
|
|
|
|
try: # Trap Ctrl-C
|
2017-02-22 17:10:06 -05:00
|
|
|
time.sleep(0.2)
|
2017-01-06 22:00:08 -05:00
|
|
|
|
2019-03-25 00:05:54 -04:00
|
|
|
# start auto-stop timer thread
|
|
|
|
if app.autostop_timer > 0:
|
|
|
|
app.autostop_timer_thread.start()
|
2017-11-08 04:25:59 -05:00
|
|
|
|
2019-05-21 13:08:54 -04:00
|
|
|
# Build the URL
|
2021-08-27 01:52:29 -04:00
|
|
|
url = f"http://{app.onion_host}"
|
2019-05-21 13:08:54 -04:00
|
|
|
|
2019-10-13 00:01:25 -04:00
|
|
|
print("")
|
2019-03-24 03:19:50 -04:00
|
|
|
if autostart_timer > 0:
|
2019-04-19 20:31:34 -04:00
|
|
|
print("Server started")
|
2017-01-06 22:00:08 -05:00
|
|
|
else:
|
2019-10-13 00:01:25 -04:00
|
|
|
if mode == "receive":
|
|
|
|
print(
|
2019-11-02 18:37:21 -04:00
|
|
|
f"Files sent to you appear in this folder: {mode_settings.get('receive', 'data_dir')}"
|
2019-10-13 00:01:25 -04:00
|
|
|
)
|
|
|
|
print("")
|
|
|
|
print(
|
2021-04-29 20:13:05 -04:00
|
|
|
"Warning: Receive mode lets people upload files to your computer. Some files can potentially take "
|
|
|
|
"control of your computer if you open them. Only open things from people you trust, or if you know "
|
|
|
|
"what you are doing."
|
2019-10-13 00:01:25 -04:00
|
|
|
)
|
|
|
|
print("")
|
2019-03-11 00:55:17 -04:00
|
|
|
|
2021-08-27 01:52:29 -04:00
|
|
|
if mode_settings.get("general", "public"):
|
|
|
|
print("Give this address to the sender:")
|
2021-05-03 20:02:02 -04:00
|
|
|
print(url)
|
2019-03-11 00:55:17 -04:00
|
|
|
else:
|
2021-08-27 01:52:29 -04:00
|
|
|
print("Give this address and private key to the sender:")
|
2019-03-11 00:55:17 -04:00
|
|
|
print(url)
|
2021-08-27 01:52:29 -04:00
|
|
|
print(f"Private key: {app.auth_string}")
|
2018-03-06 06:24:17 -05:00
|
|
|
else:
|
2021-08-27 01:52:29 -04:00
|
|
|
if mode_settings.get("general", "public"):
|
|
|
|
print("Give this address to the recipient:")
|
2021-05-03 20:02:02 -04:00
|
|
|
print(url)
|
2019-03-11 00:55:17 -04:00
|
|
|
else:
|
2021-08-27 01:52:29 -04:00
|
|
|
print("Give this address and private key to the recipient:")
|
2019-03-11 00:55:17 -04:00
|
|
|
print(url)
|
2021-08-27 01:52:29 -04:00
|
|
|
print(f"Private key: {app.auth_string}")
|
2019-10-13 00:01:25 -04:00
|
|
|
print("")
|
2019-04-19 20:31:34 -04:00
|
|
|
print("Press Ctrl+C to stop the server")
|
2017-01-06 22:00:08 -05:00
|
|
|
|
2017-04-17 22:12:02 -04:00
|
|
|
# Wait for app to close
|
2017-01-06 22:00:08 -05:00
|
|
|
while t.is_alive():
|
2019-03-25 00:05:54 -04:00
|
|
|
if app.autostop_timer > 0:
|
|
|
|
# if the auto-stop timer was set and has run out, stop the server
|
|
|
|
if not app.autostop_timer_thread.is_alive():
|
2019-10-13 00:01:25 -04:00
|
|
|
if mode == "share" or (mode == "website"):
|
2018-09-21 14:36:19 -04:00
|
|
|
# If there were no attempts to download the share, or all downloads are done, we can stop
|
2019-09-04 01:20:52 -04:00
|
|
|
if web.share_mode.cur_history_id == 0 or web.done:
|
2019-04-19 20:31:34 -04:00
|
|
|
print("Stopped because auto-stop timer ran out")
|
2018-09-21 14:36:19 -04:00
|
|
|
web.stop(app.port)
|
|
|
|
break
|
2019-10-13 00:01:25 -04:00
|
|
|
if mode == "receive":
|
|
|
|
if (
|
|
|
|
web.receive_mode.cur_history_id == 0
|
|
|
|
or not web.receive_mode.uploads_in_progress
|
|
|
|
):
|
2019-04-19 20:31:34 -04:00
|
|
|
print("Stopped because auto-stop timer ran out")
|
2018-10-02 01:41:29 -04:00
|
|
|
web.stop(app.port)
|
|
|
|
break
|
2021-03-10 03:40:06 -05:00
|
|
|
web.receive_mode.can_upload = False
|
2017-04-17 22:12:02 -04:00
|
|
|
# Allow KeyboardInterrupt exception to be handled with threads
|
2017-02-22 16:35:34 -05:00
|
|
|
# https://stackoverflow.com/questions/3788208/python-threading-ignores-keyboardinterrupt-exception
|
2017-11-08 04:25:59 -05:00
|
|
|
time.sleep(0.2)
|
2017-01-06 22:00:08 -05:00
|
|
|
except KeyboardInterrupt:
|
|
|
|
web.stop(app.port)
|
|
|
|
finally:
|
2017-04-17 22:12:02 -04:00
|
|
|
# Shutdown
|
2021-05-04 02:21:42 -04:00
|
|
|
web.cleanup()
|
2017-05-14 20:21:13 -04:00
|
|
|
onion.cleanup()
|
2017-01-06 22:00:08 -05:00
|
|
|
|
2019-10-13 00:01:25 -04:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2017-01-06 22:00:08 -05:00
|
|
|
main()
|