Code refactoring
This commit is contained in:
parent
0f066d367f
commit
a8f296c0f1
19
LICENSE
Normal file
19
LICENSE
Normal file
|
|
@ -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.
|
||||
63
README.MD
63
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 <port>
|
||||
```
|
||||
|
||||
## Windows
|
||||
|
||||
```
|
||||
python -m venv venv
|
||||
```
|
||||
|
||||
```
|
||||
venv/scripts/Activate
|
||||
```
|
||||
|
||||
```
|
||||
pip install -r requirements.txt
|
||||
```
|
||||
|
||||
```
|
||||
sanic server.server.app -H 0.0.0.0 -p <port>
|
||||
```
|
||||
|
||||
# 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
|
||||
|
|
|
|||
48
cmd_chat/__init__.py
Normal file
48
cmd_chat/__init__.py
Normal file
|
|
@ -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()
|
||||
)
|
||||
|
|
@ -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
|
||||
)
|
||||
|
||||
|
|
@ -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):
|
||||
|
|
@ -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,
|
||||
|
|
@ -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(
|
||||
Loading…
Reference in New Issue
Block a user