diff options
Diffstat (limited to 'cli')
-rw-r--r-- | cli/onionshare_cli/__init__.py | 2 | ||||
-rw-r--r-- | cli/onionshare_cli/censorship.py | 2 | ||||
-rw-r--r-- | cli/onionshare_cli/common.py | 2 | ||||
-rw-r--r-- | cli/onionshare_cli/meek.py | 2 | ||||
-rw-r--r-- | cli/onionshare_cli/mode_settings.py | 10 | ||||
-rw-r--r-- | cli/onionshare_cli/onion.py | 2 | ||||
-rw-r--r-- | cli/onionshare_cli/onionshare.py | 2 | ||||
-rw-r--r-- | cli/onionshare_cli/resources/static/js/chat.js | 32 | ||||
-rw-r--r-- | cli/onionshare_cli/resources/version.txt | 2 | ||||
-rw-r--r-- | cli/onionshare_cli/settings.py | 2 | ||||
-rw-r--r-- | cli/onionshare_cli/web/__init__.py | 2 | ||||
-rw-r--r-- | cli/onionshare_cli/web/chat_mode.py | 107 | ||||
-rw-r--r-- | cli/onionshare_cli/web/receive_mode.py | 4 | ||||
-rw-r--r-- | cli/onionshare_cli/web/send_base_mode.py | 2 | ||||
-rw-r--r-- | cli/onionshare_cli/web/share_mode.py | 2 | ||||
-rw-r--r-- | cli/onionshare_cli/web/web.py | 2 | ||||
-rw-r--r-- | cli/onionshare_cli/web/website_mode.py | 2 | ||||
-rw-r--r-- | cli/pyproject.toml | 2 | ||||
-rw-r--r-- | cli/setup.py | 6 |
19 files changed, 102 insertions, 85 deletions
diff --git a/cli/onionshare_cli/__init__.py b/cli/onionshare_cli/__init__.py index ded67ed6..f77bceab 100644 --- a/cli/onionshare_cli/__init__.py +++ b/cli/onionshare_cli/__init__.py @@ -2,7 +2,7 @@ """ OnionShare | https://onionshare.org/ -Copyright (C) 2014-2021 Micah Lee, et al. <micah@micahflee.com> +Copyright (C) 2014-2022 Micah Lee, et al. <micah@micahflee.com> 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 diff --git a/cli/onionshare_cli/censorship.py b/cli/onionshare_cli/censorship.py index 9f41d61c..c1845f6a 100644 --- a/cli/onionshare_cli/censorship.py +++ b/cli/onionshare_cli/censorship.py @@ -2,7 +2,7 @@ """ OnionShare | https://onionshare.org/ -Copyright (C) 2014-2021 Micah Lee, et al. <micah@micahflee.com> +Copyright (C) 2014-2022 Micah Lee, et al. <micah@micahflee.com> 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 diff --git a/cli/onionshare_cli/common.py b/cli/onionshare_cli/common.py index 272d2860..82ac9883 100644 --- a/cli/onionshare_cli/common.py +++ b/cli/onionshare_cli/common.py @@ -2,7 +2,7 @@ """ OnionShare | https://onionshare.org/ -Copyright (C) 2014-2021 Micah Lee, et al. <micah@micahflee.com> +Copyright (C) 2014-2022 Micah Lee, et al. <micah@micahflee.com> 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 diff --git a/cli/onionshare_cli/meek.py b/cli/onionshare_cli/meek.py index 3ada19c7..777c0ab6 100644 --- a/cli/onionshare_cli/meek.py +++ b/cli/onionshare_cli/meek.py @@ -2,7 +2,7 @@ """ OnionShare | https://onionshare.org/ -Copyright (C) 2014-2021 Micah Lee, et al. <micah@micahflee.com> +Copyright (C) 2014-2022 Micah Lee, et al. <micah@micahflee.com> 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 diff --git a/cli/onionshare_cli/mode_settings.py b/cli/onionshare_cli/mode_settings.py index b94b1d25..90bcaf07 100644 --- a/cli/onionshare_cli/mode_settings.py +++ b/cli/onionshare_cli/mode_settings.py @@ -2,7 +2,7 @@ """ OnionShare | https://onionshare.org/ -Copyright (C) 2014-2021 Micah Lee, et al. <micah@micahflee.com> +Copyright (C) 2014-2022 Micah Lee, et al. <micah@micahflee.com> 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 @@ -55,12 +55,8 @@ class ModeSettings: "disable_text": False, "disable_files": False, }, - "website": { - "disable_csp": False, - "custom_csp": None, - "filenames": [] - }, - "chat": {"room": "default"}, + "website": {"disable_csp": False, "custom_csp": None, "filenames": []}, + "chat": {}, } self._settings = {} diff --git a/cli/onionshare_cli/onion.py b/cli/onionshare_cli/onion.py index 76deea80..6ef4af2c 100644 --- a/cli/onionshare_cli/onion.py +++ b/cli/onionshare_cli/onion.py @@ -2,7 +2,7 @@ """ OnionShare | https://onionshare.org/ -Copyright (C) 2014-2021 Micah Lee, et al. <micah@micahflee.com> +Copyright (C) 2014-2022 Micah Lee, et al. <micah@micahflee.com> 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 diff --git a/cli/onionshare_cli/onionshare.py b/cli/onionshare_cli/onionshare.py index 2bb22296..2d43cc6f 100644 --- a/cli/onionshare_cli/onionshare.py +++ b/cli/onionshare_cli/onionshare.py @@ -2,7 +2,7 @@ """ OnionShare | https://onionshare.org/ -Copyright (C) 2014-2021 Micah Lee, et al. <micah@micahflee.com> +Copyright (C) 2014-2022 Micah Lee, et al. <micah@micahflee.com> 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 diff --git a/cli/onionshare_cli/resources/static/js/chat.js b/cli/onionshare_cli/resources/static/js/chat.js index b4ef30df..88abf4f4 100644 --- a/cli/onionshare_cli/resources/static/js/chat.js +++ b/cli/onionshare_cli/resources/static/js/chat.js @@ -9,31 +9,25 @@ $(function () { ); // Store current username received from app context - var current_username = $('#username').val(); - - // On browser connect, emit a socket event to be added to - // room and assigned random username - socket.on('connect', function () { - socket.emit('joined', {}); - }); + var current_username = $('#username').val().trim(); // Triggered on any status change by any user, such as some // user joined, or changed username, or left, etc. socket.on('status', function (data) { - addMessageToRoom(data, current_username, 'status'); + addMessageToPanel(data, current_username, 'status'); console.log(data, current_username); }); // Triggered when message is received from a user. Even when sent // by self, it get triggered after the server sends back the emit. - socket.on('message', function (data) { - addMessageToRoom(data, current_username, 'chat'); + socket.on('chat_message', function (data) { + addMessageToPanel(data, current_username, 'chat'); console.log(data, current_username); }); // Triggered when disconnected either by server stop or timeout socket.on('disconnect', function (data) { - addMessageToRoom({ 'msg': 'The chat server is disconnected.' }, current_username, 'status'); + addMessageToPanel({ 'msg': 'The chat server is disconnected.' }, current_username, 'status'); }) socket.on('connect_error', function (error) { console.log("error"); @@ -66,7 +60,7 @@ $(function () { }); }); -var addMessageToRoom = function (data, current_username, messageType) { +var addMessageToPanel = function (data, current_username, messageType) { var scrollDiff = getScrollDiffBefore(); if (messageType === 'status') { addStatusMessage(data.msg); @@ -88,7 +82,7 @@ var emitMessage = function (socket) { var updateUsername = function (socket) { var username = $('#username').val(); - if (!checkUsernameExists(username) && !checkUsernameTooLong(username)) { + if (!checkUsernameExists(username) && !checkUsernameTooLong(username) && !checkUsernameAscii(username)) { $.ajax({ method: 'POST', url: `http://${document.domain}:${location.port}/update-session-username`, @@ -99,6 +93,8 @@ var updateUsername = function (socket) { console.log(response); if (response.success && response.username == username) { socket.emit('update_username', { username: username }); + } else { + addStatusMessage("Failed to update username.") } }); return username; @@ -121,6 +117,16 @@ var createUserListHTML = function (connected_users, current_user) { return userListHTML; } +var checkUsernameAscii = function (username) { + // ASCII characters have code points in the range U+0000-U+007F. + $('#username-error').text(''); + if (!/^[\u0000-\u007f]*$/.test(username)) { + $('#username-error').text('Non-ASCII usernames are not supported.'); + return true; + } + return false; +} + var checkUsernameExists = function (username) { $('#username-error').text(''); var userMatches = $('#user-list li').filter(function () { diff --git a/cli/onionshare_cli/resources/version.txt b/cli/onionshare_cli/resources/version.txt index 7208c218..68151b2e 100644 --- a/cli/onionshare_cli/resources/version.txt +++ b/cli/onionshare_cli/resources/version.txt @@ -1 +1 @@ -2.4
\ No newline at end of file +2.5
\ No newline at end of file diff --git a/cli/onionshare_cli/settings.py b/cli/onionshare_cli/settings.py index 8a4a9939..7fd50a10 100644 --- a/cli/onionshare_cli/settings.py +++ b/cli/onionshare_cli/settings.py @@ -2,7 +2,7 @@ """ OnionShare | https://onionshare.org/ -Copyright (C) 2014-2021 Micah Lee, et al. <micah@micahflee.com> +Copyright (C) 2014-2022 Micah Lee, et al. <micah@micahflee.com> 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 diff --git a/cli/onionshare_cli/web/__init__.py b/cli/onionshare_cli/web/__init__.py index 3c7f4a51..24a08a19 100644 --- a/cli/onionshare_cli/web/__init__.py +++ b/cli/onionshare_cli/web/__init__.py @@ -2,7 +2,7 @@ """ OnionShare | https://onionshare.org/ -Copyright (C) 2014-2021 Micah Lee, et al. <micah@micahflee.com> +Copyright (C) 2014-2022 Micah Lee, et al. <micah@micahflee.com> 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 diff --git a/cli/onionshare_cli/web/chat_mode.py b/cli/onionshare_cli/web/chat_mode.py index e92ce385..5a11eedd 100644 --- a/cli/onionshare_cli/web/chat_mode.py +++ b/cli/onionshare_cli/web/chat_mode.py @@ -2,7 +2,7 @@ """ OnionShare | https://onionshare.org/ -Copyright (C) 2014-2021 Micah Lee, et al. <micah@micahflee.com> +Copyright (C) 2014-2022 Micah Lee, et al. <micah@micahflee.com> 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 @@ -19,7 +19,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. """ from flask import request, render_template, make_response, jsonify, session -from flask_socketio import emit, join_room, leave_room +from flask_socketio import emit, ConnectionRefusedError class ChatModeWeb: @@ -33,7 +33,7 @@ class ChatModeWeb: self.web = web - # This tracks users in the room + # This tracks users in the server self.connected_users = [] # This tracks the history id @@ -47,6 +47,15 @@ class ChatModeWeb: self.define_routes() + def validate_username(self, username): + username = username.strip() + return ( + username + and username.isascii() + and username not in self.connected_users + and len(username) < 128 + ) + def define_routes(self): """ The web app routes for chatting @@ -61,7 +70,6 @@ class ChatModeWeb: if session.get("name") else self.common.build_username() ) - session["room"] = self.web.settings.default_settings["chat"]["room"] self.web.add_request( request.path, {"id": history_id, "status_code": 200}, @@ -79,12 +87,9 @@ class ChatModeWeb: def update_session_username(): history_id = self.cur_history_id data = request.get_json() - if ( - data.get("username", "") - and data.get("username", "") not in self.connected_users - and len(data.get("username", "")) < 128 - ): - session["name"] = data.get("username", session.get("name")) + username = data.get("username", session.get("name")).strip() + if self.validate_username(username): + session["name"] = username self.web.add_request( request.path, {"id": history_id, "status_code": 200}, @@ -111,67 +116,75 @@ class ChatModeWeb: ) return r - @self.web.socketio.on("joined", namespace="/chat") - def joined(message): + @self.web.socketio.on("connect", namespace="/chat") + def server_connect(): """Sent by clients when they enter a room. A status message is broadcast to all people in the room.""" - self.connected_users.append(session.get("name")) - join_room(session.get("room")) - emit( - "status", - { - "username": session.get("name"), - "msg": "{} has joined.".format(session.get("name")), - "connected_users": self.connected_users, - "user": session.get("name"), - }, - room=session.get("room"), - ) + if self.validate_username(session.get("name")): + self.connected_users.append(session.get("name")) + emit( + "status", + { + "username": session.get("name"), + "msg": "{} has joined.".format(session.get("name")), + "connected_users": self.connected_users, + "user": session.get("name"), + }, + broadcast=True, + ) + else: + raise ConnectionRefusedError('You are active from another session!') @self.web.socketio.on("text", namespace="/chat") def text(message): """Sent by a client when the user entered a new message. - The message is sent to all people in the room.""" + The message is sent to all people in the server.""" emit( - "message", + "chat_message", {"username": session.get("name"), "msg": message["msg"]}, - room=session.get("room"), + broadcast=True, ) @self.web.socketio.on("update_username", namespace="/chat") def update_username(message): """Sent by a client when the user updates their username. - The message is sent to all people in the room.""" + The message is sent to all people in the server.""" current_name = session.get("name") - if message.get("username", ""): - session["name"] = message["username"] + new_name = message.get("username", "").strip() + if self.validate_username(new_name): + session["name"] = new_name self.connected_users[ self.connected_users.index(current_name) ] = session.get("name") - emit( - "status", - { - "msg": "{} has updated their username to: {}".format( - current_name, session.get("name") - ), - "connected_users": self.connected_users, - "old_name": current_name, - "new_name": session.get("name"), - }, - room=session.get("room"), - ) + emit( + "status", + { + "msg": "{} has updated their username to: {}".format( + current_name, session.get("name") + ), + "connected_users": self.connected_users, + "old_name": current_name, + "new_name": session.get("name"), + }, + broadcast=True, + ) + else: + emit( + "status", + {"msg": "Failed to update username."}, + ) @self.web.socketio.on("disconnect", namespace="/chat") def disconnect(): - """Sent by clients when they disconnect from a room. - A status message is broadcast to all people in the room.""" - self.connected_users.remove(session.get("name")) - leave_room(session.get("room")) + """Sent by clients when they disconnect. + A status message is broadcast to all people in the server.""" + if session.get("name") in self.connected_users: + self.connected_users.remove(session.get("name")) emit( "status", { "msg": "{} has left the room.".format(session.get("name")), "connected_users": self.connected_users, }, - room=session.get("room"), + broadcast=True, ) diff --git a/cli/onionshare_cli/web/receive_mode.py b/cli/onionshare_cli/web/receive_mode.py index 6b106d37..9ddf22ff 100644 --- a/cli/onionshare_cli/web/receive_mode.py +++ b/cli/onionshare_cli/web/receive_mode.py @@ -2,7 +2,7 @@ """ OnionShare | https://onionshare.org/ -Copyright (C) 2014-2021 Micah Lee, et al. <micah@micahflee.com> +Copyright (C) 2014-2022 Micah Lee, et al. <micah@micahflee.com> 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 @@ -378,7 +378,7 @@ class ReceiveModeRequest(Request): # Figure out what files should be saved now = datetime.now() date_dir = now.strftime("%Y-%m-%d") - time_dir = now.strftime("%H%M%S") + time_dir = now.strftime("%H%M%S%f") self.receive_mode_dir = os.path.join( self.web.settings.get("receive", "data_dir"), date_dir, time_dir ) diff --git a/cli/onionshare_cli/web/send_base_mode.py b/cli/onionshare_cli/web/send_base_mode.py index d0fccf06..e608298b 100644 --- a/cli/onionshare_cli/web/send_base_mode.py +++ b/cli/onionshare_cli/web/send_base_mode.py @@ -2,7 +2,7 @@ """ OnionShare | https://onionshare.org/ -Copyright (C) 2014-2021 Micah Lee, et al. <micah@micahflee.com> +Copyright (C) 2014-2022 Micah Lee, et al. <micah@micahflee.com> 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 diff --git a/cli/onionshare_cli/web/share_mode.py b/cli/onionshare_cli/web/share_mode.py index 9be3a89b..f714081d 100644 --- a/cli/onionshare_cli/web/share_mode.py +++ b/cli/onionshare_cli/web/share_mode.py @@ -2,7 +2,7 @@ """ OnionShare | https://onionshare.org/ -Copyright (C) 2014-2021 Micah Lee, et al. <micah@micahflee.com> +Copyright (C) 2014-2022 Micah Lee, et al. <micah@micahflee.com> 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 diff --git a/cli/onionshare_cli/web/web.py b/cli/onionshare_cli/web/web.py index 0fc55eb4..64844b5c 100644 --- a/cli/onionshare_cli/web/web.py +++ b/cli/onionshare_cli/web/web.py @@ -2,7 +2,7 @@ """ OnionShare | https://onionshare.org/ -Copyright (C) 2014-2021 Micah Lee, et al. <micah@micahflee.com> +Copyright (C) 2014-2022 Micah Lee, et al. <micah@micahflee.com> 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 diff --git a/cli/onionshare_cli/web/website_mode.py b/cli/onionshare_cli/web/website_mode.py index 5ab1b184..1f61532b 100644 --- a/cli/onionshare_cli/web/website_mode.py +++ b/cli/onionshare_cli/web/website_mode.py @@ -2,7 +2,7 @@ """ OnionShare | https://onionshare.org/ -Copyright (C) 2014-2021 Micah Lee, et al. <micah@micahflee.com> +Copyright (C) 2014-2022 Micah Lee, et al. <micah@micahflee.com> 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 diff --git a/cli/pyproject.toml b/cli/pyproject.toml index 9b664d72..49418205 100644 --- a/cli/pyproject.toml +++ b/cli/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "onionshare_cli" -version = "2.4" +version = "2.5" description = "OnionShare lets you securely and anonymously send and receive files. It works by starting a web server, making it accessible as a Tor onion service, and generating an unguessable web address so others can download files from you, or upload files to you. It does _not_ require setting up a separate server or using a third party file-sharing service." authors = ["Micah Lee <micah@micahflee.com>"] license = "GPLv3+" diff --git a/cli/setup.py b/cli/setup.py index 407991d0..2db047e5 100644 --- a/cli/setup.py +++ b/cli/setup.py @@ -3,7 +3,7 @@ """ OnionShare | https://onionshare.org/ -Copyright (C) 2014-2021 Micah Lee, et al. <micah@micahflee.com> +Copyright (C) 2014-2022 Micah Lee, et al. <micah@micahflee.com> 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 @@ -18,9 +18,11 @@ 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/>. """ +import os import setuptools -version = "2.4" +with open(os.path.join("onionshare_cli", "resources", "version.txt")) as f: + version = f.read().strip() setuptools.setup( name="onionshare-cli", |