Working development server (no encryption now)

This commit is contained in:
BarsTiger
2023-07-02 11:54:49 +03:00
parent 68f1990b7e
commit 2a4e40b41b
23 changed files with 486 additions and 9 deletions

View File

@@ -0,0 +1 @@
pass

View File

@@ -0,0 +1,37 @@
import os
import click
from dragonion_server.utils.config import db
from dragonion_server.common import console
class ServiceRemoveCommand(click.Command):
def __init__(self):
super().__init__(
name='remove',
callback=self.callback,
params=[
click.Option(
('--name', '-n'),
required=True,
prompt=True,
type=str,
help='Name of service to write to'
)
]
)
@staticmethod
def callback(name: str):
try:
del db.services[name]
if os.path.isfile(f'{name}.auth'):
os.remove(f'{name}.auth')
print(f'Removed service {name}')
except KeyError:
print(f'Service "{name}" does not exist in this storage')
except Exception as e:
assert e
console.print_exception(show_locals=True)

View File

@@ -0,0 +1,37 @@
import click
from dragonion_server.modules.server import run
from dragonion_server.common import console
class ServiceRunCommand(click.Command):
def __init__(self):
super().__init__(
name='run',
callback=self.callback,
params=[
click.Option(
('--name', '-n'),
required=True,
prompt=True,
type=str,
help='Name of service to write to'
),
click.Option(
('--port', '-p'),
required=False,
prompt=True,
prompt_required=False,
type=int,
help='Port to start service on'
)
]
)
@staticmethod
def callback(name: str, port: int | None):
try:
run(name, port)
except Exception as e:
assert e
console.print_exception(show_locals=True)

View File

@@ -0,0 +1,14 @@
from ...utils import ModuleGroup
from .write import ServiceWriteCommand
from .run import ServiceRunCommand
from .remove import ServiceRemoveCommand
service_group = ModuleGroup(
name='service',
commands={
'write': ServiceWriteCommand(),
'run': ServiceRunCommand(),
'remove': ServiceRemoveCommand()
}
)

View File

@@ -0,0 +1,37 @@
import click
from dragonion_server.utils.onion import Onion
from dragonion_server.common import console
class ServiceWriteCommand(click.Command):
def __init__(self):
super().__init__(
name='write',
callback=self.callback,
params=[
click.Option(
('--name', '-n'),
required=True,
prompt=True,
type=str,
help='Name of service to write to'
),
click.Option(
('--port', '-p'),
required=True,
prompt=True,
type=int,
help='Port to start service on'
)
]
)
@staticmethod
def callback(name: str, port: int):
try:
Onion.write_onion_service(name, port)
print(f'Written service "{name}" info')
except Exception as e:
assert e
console.print_exception(show_locals=True)