-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver_here.py
More file actions
56 lines (46 loc) · 1.59 KB
/
server_here.py
File metadata and controls
56 lines (46 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
"""SSH server."""
import asyncio
from pathlib import Path
from kivy.app import App
from kivy.logger import Logger
from herethere.here.server import SSHServerHere, ServerConfig, start_server
from exception_manager_here import show_exception_popup
class PythonHereServer(SSHServerHere):
"""SSH server protocol handler."""
def auth_completed(self):
"""Authentication was completed successfully."""
super().auth_completed()
App.get_running_app().on_ssh_connection_made()
async def run_ssh_server(app):
"""Start and run SSH server."""
Logger.debug("PythonHere: wait for %here settings")
try:
await app.ssh_server_config_ready.wait()
except asyncio.CancelledError:
return
config = ServerConfig(
host="",
chroot=app.upload_dir,
key_path=Path("./key.rsa").resolve(),
**app.get_pythonhere_config(),
)
try:
server = await start_server(
config, namespace=app.ssh_server_namespace, server_factory=PythonHereServer
)
app.ssh_server_started.set()
except Exception as exc:
Logger.error("PythonHere: SSH server start error")
Logger.exception(exc)
show_exception_popup(exc)
return
try:
await server.wait_closed()
except asyncio.CancelledError:
Logger.info("PythonHere: SSH server task canceled")
await server.stop()
except Exception as exc:
Logger.errror("PythonHere: SSH server stop by exception")
Logger.exception(exc)
show_exception_popup(exc)
Logger.info("PythonHere: SSH server closed")