diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..0e61cd7 --- /dev/null +++ b/LICENSE @@ -0,0 +1,19 @@ +Copyright (c) 2022-2023 + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/README.MD b/README.MD index 94346f9..d9c19be 100644 --- a/README.MD +++ b/README.MD @@ -13,70 +13,15 @@ All you need it's to run web-server and connect to them via client -# Server run +# Run -## Linux - -For linux its required to have python3.10 +### Create and activate virtual environment python ``` -chmod +x run_server.sh +python main.py ``` -``` -./run_server.sh -``` - -## Windows - -``` -python -m venv venv -``` - -``` -venv/scripts/Activate -``` - -``` -pip install -r requirements.txt -``` - -``` -sanic server.server.app -H 0.0.0.0 -p -``` - -# Client run - -## Linux - -For linux its required to have python3.10 - -``` -chmod +x run_client.sh -``` -``` -./run_client.sh -``` - -## Windows - -``` -python -m venv venv -``` - -``` -venv/scripts/Activate -``` - -``` -pip install -r requirements.txt -``` - -``` -python client/client.py -``` - -## How crypting works? +# How crypting works? * Client making priv key * Server making symmetric key diff --git a/cmd_chat/__init__.py b/cmd_chat/__init__.py new file mode 100644 index 0000000..262ff97 --- /dev/null +++ b/cmd_chat/__init__.py @@ -0,0 +1,48 @@ +import asyncio + +from cmd_chat.server.server import app +from cmd_chat.client.client import Client + + +async def run_server( + ip: str, + port: int +) -> None: + app.run( + host=ip, + port=port, + dev=False + ) + + +async def run_client( + username: str, + server: str, + port: int +) -> None: + Client( + server = server, + port = port, + username = username + ).run() + + +async def run() -> None: + action: int = int(input("Choose action:\n1. Run server\n2. Run client\nAction: ")) + if action == 1: + await run_server( + input("IP: "), + int(input("PORT: ")) + ) + if action == 2: + await run_client( + input("USERNAME: "), + input("IP: "), + int(input("PORT: ")) + ) + + +if __name__ == '__main__': + asyncio.run( + run() + ) \ No newline at end of file diff --git a/client/client.py b/cmd_chat/client/client.py similarity index 98% rename from client/client.py rename to cmd_chat/client/client.py index 456b67f..8261b58 100644 --- a/client/client.py +++ b/cmd_chat/client/client.py @@ -2,11 +2,12 @@ import os import time import platform import threading + from colorama import init -from colorama import Fore from websocket import create_connection -from core.crypto import RSAService -from config import ( + +from cmd_chat.client.core.crypto import RSAService +from cmd_chat.client.config import ( COLORS ) diff --git a/client/config.py b/cmd_chat/client/config.py similarity index 100% rename from client/config.py rename to cmd_chat/client/config.py diff --git a/client/core/abs/abs_crypto.py b/cmd_chat/client/core/abs/abs_crypto.py similarity index 100% rename from client/core/abs/abs_crypto.py rename to cmd_chat/client/core/abs/abs_crypto.py diff --git a/client/core/crypto.py b/cmd_chat/client/core/crypto.py similarity index 97% rename from client/core/crypto.py rename to cmd_chat/client/core/crypto.py index 6e605e1..0b5e317 100644 --- a/client/core/crypto.py +++ b/cmd_chat/client/core/crypto.py @@ -2,7 +2,8 @@ import os import rsa import requests from cryptography.fernet import Fernet -from core.abs.abs_crypto import CryptoService + +from cmd_chat.client.core.abs.abs_crypto import CryptoService class RSAService(CryptoService): diff --git a/server/models.py b/cmd_chat/server/models.py similarity index 100% rename from server/models.py rename to cmd_chat/server/models.py diff --git a/server/server.py b/cmd_chat/server/server.py similarity index 95% rename from server/server.py rename to cmd_chat/server/server.py index 6921be8..1be4fcd 100644 --- a/server/server.py +++ b/cmd_chat/server/server.py @@ -6,8 +6,8 @@ from cryptography.fernet import Fernet from sanic.response import HTTPResponse from sanic import Sanic, Request, response, Websocket -from server.models import Message -from server.services import ( +from cmd_chat.server.models import Message +from cmd_chat.server.services import ( _get_bytes_and_serialize, _check_ws_for_close_status, _generate_new_message, diff --git a/server/services.py b/cmd_chat/server/services.py similarity index 87% rename from server/services.py rename to cmd_chat/server/services.py index bab8931..e4206d5 100644 --- a/server/services.py +++ b/cmd_chat/server/services.py @@ -1,5 +1,5 @@ -from sanic import Sanic, Request, response, Websocket -from server.models import Message +from sanic import Websocket +from cmd_chat.server.models import Message async def _get_bytes_and_serialize( diff --git a/main.py b/main.py new file mode 100644 index 0000000..f3b16a0 --- /dev/null +++ b/main.py @@ -0,0 +1,7 @@ +from cmd_chat import run +import asyncio + +if __name__ == '__main__': + asyncio.run( + run() + ) \ No newline at end of file