Ssh: reformat
This commit is contained in:
parent
24760ff46d
commit
984425021e
1 changed files with 12 additions and 11 deletions
|
@ -3,7 +3,6 @@ import socket
|
||||||
import threading
|
import threading
|
||||||
import select
|
import select
|
||||||
import sys
|
import sys
|
||||||
import os
|
|
||||||
|
|
||||||
|
|
||||||
class CustomServer(paramiko.ServerInterface):
|
class CustomServer(paramiko.ServerInterface):
|
||||||
|
@ -27,7 +26,9 @@ class CustomServer(paramiko.ServerInterface):
|
||||||
return paramiko.OPEN_SUCCEEDED
|
return paramiko.OPEN_SUCCEEDED
|
||||||
return paramiko.OPEN_FAILED_ADMINISTRATIVELY_PROHIBITED
|
return paramiko.OPEN_FAILED_ADMINISTRATIVELY_PROHIBITED
|
||||||
|
|
||||||
def check_channel_pty_request(self, channel, term, width, height, pixelwidth, pixelheight, modes):
|
def check_channel_pty_request(
|
||||||
|
self, channel, term, width, height, pixelwidth, pixelheight, modes
|
||||||
|
):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def check_channel_shell_request(self, channel):
|
def check_channel_shell_request(self, channel):
|
||||||
|
@ -40,11 +41,7 @@ class CustomServer(paramiko.ServerInterface):
|
||||||
|
|
||||||
|
|
||||||
def get_vm_port(username):
|
def get_vm_port(username):
|
||||||
user_map = {
|
user_map = {"user0": 9000, "user1": 9001, "emiliko": 9002}
|
||||||
'user0': 9000,
|
|
||||||
'user1': 9001,
|
|
||||||
'emiliko': 9002
|
|
||||||
}
|
|
||||||
return user_map.get(username)
|
return user_map.get(username)
|
||||||
|
|
||||||
|
|
||||||
|
@ -73,7 +70,9 @@ def handle_tcp_forwarding(channel, origin, destination):
|
||||||
def handle_client(client_sock):
|
def handle_client(client_sock):
|
||||||
try:
|
try:
|
||||||
transport = paramiko.Transport(client_sock)
|
transport = paramiko.Transport(client_sock)
|
||||||
transport.add_server_key(paramiko.Ed25519Key.from_private_key_file('daemon.key'))
|
transport.add_server_key(
|
||||||
|
paramiko.Ed25519Key.from_private_key_file("daemon.key")
|
||||||
|
)
|
||||||
|
|
||||||
server = CustomServer(None)
|
server = CustomServer(None)
|
||||||
transport.start_server(server=server)
|
transport.start_server(server=server)
|
||||||
|
@ -98,7 +97,7 @@ def handle_client(client_sock):
|
||||||
|
|
||||||
vm_transport = paramiko.Transport(("localhost", vm_port))
|
vm_transport = paramiko.Transport(("localhost", vm_port))
|
||||||
vm_transport.start_client()
|
vm_transport.start_client()
|
||||||
vm_transport.auth_password('root', '')
|
vm_transport.auth_password("root", "")
|
||||||
|
|
||||||
vm_channel = vm_transport.open_session()
|
vm_channel = vm_transport.open_session()
|
||||||
vm_channel.get_pty()
|
vm_channel.get_pty()
|
||||||
|
@ -129,7 +128,8 @@ def handle_client(client_sock):
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def start_server(port=22, bind_address=''):
|
|
||||||
|
def start_server(port=22, bind_address=""):
|
||||||
try:
|
try:
|
||||||
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||||
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
||||||
|
@ -148,5 +148,6 @@ def start_server(port=22, bind_address=''):
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Error: {str(e)}")
|
print(f"Error: {str(e)}")
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
|
if __name__ == "__main__":
|
||||||
start_server(port=2222)
|
start_server(port=2222)
|
||||||
|
|
Loading…
Reference in a new issue