Commit 591b3660 authored by Yury's avatar Yury

new version format, new __main__, todo list in readme

parent dd2dac97
Pipeline #115 failed with stages
in 4 minutes and 55 seconds
......@@ -33,4 +33,9 @@ You can implement your own authentication method (Login/Password)
All you need to do is to implement `Authenticator` class with `async def authenticate(self, data)` method which will return `bool`
authentication result. Then just import your module and use it in config
`saturn.config.AUTHENTICATION_METHODS = ["your_auth_method"]`
You can see examples in `saturn.auth`
\ No newline at end of file
You can see examples in `saturn.auth`
### TODO list
- [ ] Logging
- [ ] Max socket limit
- [ ] More tests
\ No newline at end of file
import datetime
from saturn.version import __version__
import os
version = datetime.datetime.now(tz=datetime.timezone.utc).strftime('%Y.%m.%d.%H%M')
with open("./saturn/version", "w") as ver_file:
if "MAJOR" in os.environ.get("CI_COMMIT_DESCRIPTION", ""):
major_version = int(__version__.split()[0]) + 1
minor_version = 0
else:
major_version = int(__version__.split()[0])
minor_version = int(__version__.split()[1]) + 1
full_version = f"{major_version}.{minor_version}"
ver_file.write(f"__version__ = \"{full_version}\"")
try:
with open('README.md', 'r', encoding='utf-8') as f:
with open("README.md", "r", encoding="utf-8") as f:
long_description = f.read()
except FileNotFoundError:
long_description = ''
long_description = ""
with open('setup.txt', 'r') as text:
with open('setup.py', 'w') as setup:
with open("setup.txt", "r") as text:
with open("setup.py", "w") as setup:
txt = text.read()
setup.write(txt.format(version=version, long_description=long_description))
\ No newline at end of file
setup.write(txt.format(version=full_version, long_description=long_description))
\ No newline at end of file
......@@ -8,6 +8,7 @@ from . import dispatcher
from . import engine
from . import socks
from . import state
from .version import __version__
logging.basicConfig(level=logging.INFO)
......
from saturn import start_server
import sys
def get_argv(index, default=None):
try:
return sys.argv[index]
except IndexError:
return default
host = get_argv(1, "0.0.0.0")
port = get_argv(2, 8080)
start_server(host, port)
\ No newline at end of file
......@@ -4,7 +4,7 @@ from saturn.socks.request import SocksRequest
class Dispatcher:
def __init__(self, server, loop, protocol, transport):
def __init__(self, server, loop, transport):
self.server_transport = transport
self.server = server
self.loop = loop
......
import asyncio
import typing
from ipaddress import IPv4Address, IPv6Address
from saturn import protocol, config
class Server:
def __init__(self, host, port, tcp=True, udp=False, custom_auth=None):
def __init__(self, host: typing.Union[IPv6Address, IPv4Address, str],
port: int,
tcp:bool=True, udp=False, custom_auth=None):
self.host = host
self.port = port
self.tcp = tcp
......@@ -36,8 +40,3 @@ class Server:
if self.tcp:
loop.create_task(protocol.Socks5TcpServer(self, loop).start_server(self.host, self.port))
loop.run_forever()
if __name__ == "__main__":
server = Server("0.0.0.0", 8081)
server.start()
......@@ -12,7 +12,7 @@ class Socks5TcpServer(asyncio.Protocol):
def connection_made(self, transport):
self.transport = transport
self.dispatcher = Dispatcher(self.server, self.loop, self, transport)
self.dispatcher = Dispatcher(self.server, self.loop, self.transport)
def data_received(self, data):
asyncio.Task(self.async_data_handler(data))
......
......@@ -11,7 +11,7 @@ class SocksRequestBind(SocksRequest):
action_id = 2
async def go(self):
# Check if CONNECTED
port = random.randrange(30000, 65535)
new_server = TcpServer(self.dispatcher, self.dispatcher.loop).start_server(port)
return reply.Success(IPv4Address(socket.gethostbyname(socket.gethostname())), port)
__version__ = "0.1"
\ No newline at end of file
......@@ -6,3 +6,9 @@ class ImportTest(unittest.TestCase):
def test(self):
saturn = __import__('saturn', globals=globals(), fromlist=[''])
self.assertTrue(hasattr(saturn, 'engine'))
self.assertTrue(hasattr(saturn, 'config'))
self.assertTrue(hasattr(saturn, 'protocol'))
self.assertTrue(hasattr(saturn, 'socks'))
self.assertTrue(hasattr(saturn, 'auth'))
self.assertTrue(hasattr(saturn, 'dispatcher'))
self.assertTrue(hasattr(saturn, 'state'))
\ No newline at end of file
......@@ -2,6 +2,12 @@ import unittest
import saturn
import asyncio
class ServerTests(unittest.TestCase):
def test_auth_methods(self):
self.assertRaises(TypeError, saturn.engine.Server)
server = saturn.engine.Server()
class SocksTests(unittest.TestCase):
def test_hello_none_auth(self):
......@@ -42,4 +48,5 @@ class SocksTests(unittest.TestCase):
login = 'USER_TEST'
password = 'Test_password'
req = b"\x05" + len(login).to_bytes(1, "big") + login.encode() + len(password).to_bytes(1, "big") + password.encode()
self.assertEqual(b"\x01\x00", asyncio.run(saturn.socks.SocksAuthenticate(dispatcher, req).authenticate()))
\ No newline at end of file
self.assertEqual(b"\x01\x00", asyncio.run(saturn.socks.SocksAuthenticate(dispatcher, req).authenticate()))
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment