onionshare_cli 2.3__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. onionshare_cli/__init__.py +522 -0
  2. onionshare_cli/common.py +296 -0
  3. onionshare_cli/mode_settings.py +146 -0
  4. onionshare_cli/onion.py +845 -0
  5. onionshare_cli/onionshare.py +110 -0
  6. onionshare_cli/resources/static/css/style.css +393 -0
  7. onionshare_cli/resources/static/img/ajax.gif +0 -0
  8. onionshare_cli/resources/static/img/favicon.ico +0 -0
  9. onionshare_cli/resources/static/img/logo.png +0 -0
  10. onionshare_cli/resources/static/img/logo_large.png +0 -0
  11. onionshare_cli/resources/static/img/web_file.png +0 -0
  12. onionshare_cli/resources/static/img/web_folder.png +0 -0
  13. onionshare_cli/resources/static/js/chat.js +173 -0
  14. onionshare_cli/resources/static/js/jquery-3.5.1.min.js +2 -0
  15. onionshare_cli/resources/static/js/receive.js +130 -0
  16. onionshare_cli/resources/static/js/send.js +75 -0
  17. onionshare_cli/resources/static/js/socket.io.min.js +3 -0
  18. onionshare_cli/resources/templates/401.html +21 -0
  19. onionshare_cli/resources/templates/403.html +21 -0
  20. onionshare_cli/resources/templates/404.html +21 -0
  21. onionshare_cli/resources/templates/405.html +21 -0
  22. onionshare_cli/resources/templates/chat.html +46 -0
  23. onionshare_cli/resources/templates/denied.html +14 -0
  24. onionshare_cli/resources/templates/listing.html +59 -0
  25. onionshare_cli/resources/templates/receive.html +46 -0
  26. onionshare_cli/resources/templates/send.html +69 -0
  27. onionshare_cli/resources/templates/thankyou.html +27 -0
  28. onionshare_cli/resources/torrc_template +8 -0
  29. onionshare_cli/resources/torrc_template-meek_lite_amazon +2 -0
  30. onionshare_cli/resources/torrc_template-meek_lite_azure +2 -0
  31. onionshare_cli/resources/torrc_template-obfs4 +27 -0
  32. onionshare_cli/resources/version.txt +1 -0
  33. onionshare_cli/resources/wordlist.txt +7776 -0
  34. onionshare_cli/settings.py +201 -0
  35. onionshare_cli/web/__init__.py +21 -0
  36. onionshare_cli/web/chat_mode.py +169 -0
  37. onionshare_cli/web/receive_mode.py +488 -0
  38. onionshare_cli/web/send_base_mode.py +338 -0
  39. onionshare_cli/web/share_mode.py +406 -0
  40. onionshare_cli/web/web.py +424 -0
  41. onionshare_cli/web/website_mode.py +123 -0
  42. onionshare_cli-2.3.dist-info/METADATA +34 -0
  43. onionshare_cli-2.3.dist-info/RECORD +45 -0
  44. onionshare_cli-2.3.dist-info/WHEEL +4 -0
  45. onionshare_cli-2.3.dist-info/entry_points.txt +3 -0
@@ -0,0 +1,201 @@
1
+ # -*- coding: utf-8 -*-
2
+ """
3
+ OnionShare | https://onionshare.org/
4
+
5
+ Copyright (C) 2014-2020 Micah Lee, et al. <micah@micahflee.com>
6
+
7
+ This program is free software: you can redistribute it and/or modify
8
+ it under the terms of the GNU General Public License as published by
9
+ the Free Software Foundation, either version 3 of the License, or
10
+ (at your option) any later version.
11
+
12
+ This program is distributed in the hope that it will be useful,
13
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ GNU General Public License for more details.
16
+
17
+ You should have received a copy of the GNU General Public License
18
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
19
+ """
20
+
21
+ import json
22
+ import os
23
+ import platform
24
+ import locale
25
+
26
+ try:
27
+ # We only need pwd module in macOS, and it's not available in Windows
28
+ import pwd
29
+ except:
30
+ pass
31
+
32
+
33
+ class Settings(object):
34
+ """
35
+ This class stores all of the settings for OnionShare, specifically for how
36
+ to connect to Tor. If it can't find the settings file, it uses the default,
37
+ which is to attempt to connect automatically using default Tor Browser
38
+ settings.
39
+ """
40
+
41
+ def __init__(self, common, config=False):
42
+ self.common = common
43
+
44
+ self.common.log("Settings", "__init__")
45
+
46
+ # If a readable config file was provided, use that instead
47
+ if config:
48
+ if os.path.isfile(config):
49
+ self.filename = config
50
+ else:
51
+ self.common.log(
52
+ "Settings",
53
+ "__init__",
54
+ "Supplied config does not exist or is unreadable. Falling back to default location",
55
+ )
56
+ self.filename = self.build_filename()
57
+
58
+ else:
59
+ # Default config
60
+ self.filename = self.build_filename()
61
+
62
+ # Dictionary of available languages in this version of OnionShare,
63
+ # mapped to the language name, in that language
64
+ self.available_locales = {
65
+ "ar": "العربية", # Arabic
66
+ "bn": "বাংলা", # Bengali
67
+ "ca": "Català", # Catalan
68
+ "zh_Hant": "正體中文 (繁體)", # Traditional Chinese
69
+ "zh_Hans": "中文 (简体)", # Simplified Chinese
70
+ "hr": "Hrvatski", # Croatian
71
+ "da": "Dansk", # Danish
72
+ "nl": "Nederlands", # Dutch
73
+ "en": "English", # English
74
+ "fi": "Suomi", # Finnish
75
+ "fr": "Français", # French
76
+ "gl": "Galego", # Galician
77
+ "de": "Deutsch", # German
78
+ "el": "Ελληνικά", # Greek
79
+ "is": "Íslenska", # Icelandic
80
+ # "ga": "Gaeilge", # Irish
81
+ "it": "Italiano", # Italian
82
+ "ja": "日本語", # Japanese
83
+ "ckb": "Soranî", # Kurdish (Central)
84
+ "nb_NO": "Norsk Bokmål", # Norwegian Bokmål
85
+ # "fa": "فارسی", # Persian
86
+ "pl": "Polski", # Polish
87
+ "pt_BR": "Português (Brasil)", # Portuguese Brazil
88
+ "pt_PT": "Português (Portugal)", # Portuguese Portugal
89
+ "sk": "Slovenčina", # Slovak
90
+ # "ro": "Română", # Romanian
91
+ "ru": "Русский", # Russian
92
+ # "sr_Latn": "Srpska (latinica)", # Serbian (latin)
93
+ "es": "Español", # Spanish
94
+ "sv": "Svenska", # Swedish
95
+ # "te": "తెలుగు", # Telugu
96
+ "tr": "Türkçe", # Turkish
97
+ "uk": "Українська", # Ukrainian
98
+ }
99
+
100
+ # These are the default settings. They will get overwritten when loading from disk
101
+ self.default_settings = {
102
+ "version": self.common.version,
103
+ "connection_type": "bundled",
104
+ "control_port_address": "127.0.0.1",
105
+ "control_port_port": 9051,
106
+ "socks_address": "127.0.0.1",
107
+ "socks_port": 9050,
108
+ "socket_file_path": "/var/run/tor/control",
109
+ "auth_type": "no_auth",
110
+ "auth_password": "",
111
+ "use_autoupdate": True,
112
+ "autoupdate_timestamp": None,
113
+ "no_bridges": True,
114
+ "tor_bridges_use_obfs4": False,
115
+ "tor_bridges_use_meek_lite_azure": False,
116
+ "tor_bridges_use_custom_bridges": "",
117
+ "persistent_tabs": [],
118
+ "locale": None, # this gets defined in fill_in_defaults()
119
+ }
120
+ self._settings = {}
121
+ self.fill_in_defaults()
122
+
123
+ def fill_in_defaults(self):
124
+ """
125
+ If there are any missing settings from self._settings, replace them with
126
+ their default values.
127
+ """
128
+ for key in self.default_settings:
129
+ if key not in self._settings:
130
+ self._settings[key] = self.default_settings[key]
131
+
132
+ # Choose the default locale based on the OS preference, and fall-back to English
133
+ if self._settings["locale"] is None:
134
+ language_code, encoding = locale.getdefaultlocale()
135
+
136
+ # Default to English
137
+ if not language_code:
138
+ language_code = "en_US"
139
+
140
+ if language_code == "pt_PT" and language_code == "pt_BR":
141
+ # Portuguese locales include country code
142
+ default_locale = language_code
143
+ else:
144
+ # All other locales cut off the country code
145
+ default_locale = language_code[:2]
146
+
147
+ if default_locale not in self.available_locales:
148
+ default_locale = "en"
149
+ self._settings["locale"] = default_locale
150
+
151
+ def build_filename(self):
152
+ """
153
+ Returns the path of the settings file.
154
+ """
155
+ return os.path.join(self.common.build_data_dir(), "onionshare.json")
156
+
157
+ def load(self):
158
+ """
159
+ Load the settings from file.
160
+ """
161
+ self.common.log("Settings", "load")
162
+
163
+ # If the settings file exists, load it
164
+ if os.path.exists(self.filename):
165
+ try:
166
+ self.common.log("Settings", "load", f"Trying to load {self.filename}")
167
+ with open(self.filename, "r") as f:
168
+ self._settings = json.load(f)
169
+ self.fill_in_defaults()
170
+ except:
171
+ pass
172
+
173
+ # Make sure data_dir exists
174
+ try:
175
+ os.makedirs(self.get("data_dir"), exist_ok=True)
176
+ except:
177
+ pass
178
+
179
+ def save(self):
180
+ """
181
+ Save settings to file.
182
+ """
183
+ self.common.log("Settings", "save")
184
+ open(self.filename, "w").write(json.dumps(self._settings, indent=2))
185
+ self.common.log("Settings", "save", f"Settings saved in {self.filename}")
186
+
187
+ def get(self, key):
188
+ return self._settings[key]
189
+
190
+ def set(self, key, val):
191
+ # If typecasting int values fails, fallback to default values
192
+ if key == "control_port_port" or key == "socks_port":
193
+ try:
194
+ val = int(val)
195
+ except:
196
+ if key == "control_port_port":
197
+ val = self.default_settings["control_port_port"]
198
+ elif key == "socks_port":
199
+ val = self.default_settings["socks_port"]
200
+
201
+ self._settings[key] = val
@@ -0,0 +1,21 @@
1
+ # -*- coding: utf-8 -*-
2
+ """
3
+ OnionShare | https://onionshare.org/
4
+
5
+ Copyright (C) 2014-2020 Micah Lee, et al. <micah@micahflee.com>
6
+
7
+ This program is free software: you can redistribute it and/or modify
8
+ it under the terms of the GNU General Public License as published by
9
+ the Free Software Foundation, either version 3 of the License, or
10
+ (at your option) any later version.
11
+
12
+ This program is distributed in the hope that it will be useful,
13
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ GNU General Public License for more details.
16
+
17
+ You should have received a copy of the GNU General Public License
18
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
19
+ """
20
+
21
+ from .web import Web
@@ -0,0 +1,169 @@
1
+ # -*- coding: utf-8 -*-
2
+ """
3
+ OnionShare | https://onionshare.org/
4
+
5
+ Copyright (C) 2014-2020 Micah Lee, et al. <micah@micahflee.com>
6
+
7
+ This program is free software: you can redistribute it and/or modify
8
+ it under the terms of the GNU General Public License as published by
9
+ the Free Software Foundation, either version 3 of the License, or
10
+ (at your option) any later version.
11
+
12
+ This program is distributed in the hope that it will be useful,
13
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ GNU General Public License for more details.
16
+
17
+ You should have received a copy of the GNU General Public License
18
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
19
+ """
20
+
21
+ from flask import (
22
+ Request,
23
+ request,
24
+ render_template,
25
+ make_response,
26
+ jsonify,
27
+ redirect,
28
+ session,
29
+ )
30
+ from werkzeug.utils import secure_filename
31
+ from flask_socketio import emit, join_room, leave_room
32
+
33
+
34
+ class ChatModeWeb:
35
+ """
36
+ All of the web logic for chat mode
37
+ """
38
+
39
+ def __init__(self, common, web):
40
+ self.common = common
41
+ self.common.log("ChatModeWeb", "__init__")
42
+
43
+ self.web = web
44
+
45
+ # This tracks users in the room
46
+ self.connected_users = []
47
+
48
+ # This tracks the history id
49
+ self.cur_history_id = 0
50
+
51
+ self.define_routes()
52
+
53
+ def define_routes(self):
54
+ """
55
+ The web app routes for chatting
56
+ """
57
+
58
+ @self.web.app.route("/")
59
+ def index():
60
+ history_id = self.cur_history_id
61
+ self.cur_history_id += 1
62
+ session["name"] = (
63
+ session.get("name")
64
+ if session.get("name")
65
+ else self.common.build_username()
66
+ )
67
+ session["room"] = self.web.settings.default_settings["chat"]["room"]
68
+ self.web.add_request(
69
+ request.path,
70
+ {"id": history_id, "status_code": 200},
71
+ )
72
+
73
+ self.web.add_request(self.web.REQUEST_LOAD, request.path)
74
+ r = make_response(
75
+ render_template(
76
+ "chat.html",
77
+ static_url_path=self.web.static_url_path,
78
+ username=session.get("name"),
79
+ )
80
+ )
81
+ return self.web.add_security_headers(r)
82
+
83
+ @self.web.app.route("/update-session-username", methods=["POST"])
84
+ def update_session_username():
85
+ history_id = self.cur_history_id
86
+ data = request.get_json()
87
+ if (
88
+ data.get("username", "")
89
+ and data.get("username", "") not in self.connected_users
90
+ ):
91
+ session["name"] = data.get("username", session.get("name"))
92
+ self.web.add_request(
93
+ request.path,
94
+ {"id": history_id, "status_code": 200},
95
+ )
96
+
97
+ self.web.add_request(self.web.REQUEST_LOAD, request.path)
98
+ r = make_response(
99
+ jsonify(
100
+ username=session.get("name"),
101
+ success=True,
102
+ )
103
+ )
104
+ return self.web.add_security_headers(r)
105
+
106
+ @self.web.socketio.on("joined", namespace="/chat")
107
+ def joined(message):
108
+ """Sent by clients when they enter a room.
109
+ A status message is broadcast to all people in the room."""
110
+ self.connected_users.append(session.get("name"))
111
+ join_room(session.get("room"))
112
+ emit(
113
+ "status",
114
+ {
115
+ "username": session.get("name"),
116
+ "msg": "{} has joined.".format(session.get("name")),
117
+ "connected_users": self.connected_users,
118
+ "user": session.get("name"),
119
+ },
120
+ room=session.get("room"),
121
+ )
122
+
123
+ @self.web.socketio.on("text", namespace="/chat")
124
+ def text(message):
125
+ """Sent by a client when the user entered a new message.
126
+ The message is sent to all people in the room."""
127
+ emit(
128
+ "message",
129
+ {"username": session.get("name"), "msg": message["msg"]},
130
+ room=session.get("room"),
131
+ )
132
+
133
+ @self.web.socketio.on("update_username", namespace="/chat")
134
+ def update_username(message):
135
+ """Sent by a client when the user updates their username.
136
+ The message is sent to all people in the room."""
137
+ current_name = session.get("name")
138
+ if message.get("username", ""):
139
+ session["name"] = message["username"]
140
+ self.connected_users[
141
+ self.connected_users.index(current_name)
142
+ ] = session.get("name")
143
+ emit(
144
+ "status",
145
+ {
146
+ "msg": "{} has updated their username to: {}".format(
147
+ current_name, session.get("name")
148
+ ),
149
+ "connected_users": self.connected_users,
150
+ "old_name": current_name,
151
+ "new_name": session.get("name"),
152
+ },
153
+ room=session.get("room"),
154
+ )
155
+
156
+ @self.web.socketio.on("disconnect", namespace="/chat")
157
+ def disconnect():
158
+ """Sent by clients when they disconnect from a room.
159
+ A status message is broadcast to all people in the room."""
160
+ self.connected_users.remove(session.get("name"))
161
+ leave_room(session.get("room"))
162
+ emit(
163
+ "status",
164
+ {
165
+ "msg": "{} has left the room.".format(session.get("name")),
166
+ "connected_users": self.connected_users,
167
+ },
168
+ room=session.get("room"),
169
+ )