2024-06-19 22:33:28 +07:00

131 lines
1.9 KiB
Markdown

# Server Event
To handle the event can use `on_user()` decorator
## connect
Called when user connected to server and authenticated
```py
@ssh.on_user("connect")
def connect(client):
# do something
```
## connectsftp
Called when user connected to server and authenticated with sftp
```py
@ssh.on_user("connectsftp")
def connectsftp(client):
# do something
```
## auth (only usexternalauth=True in Server())
Called when user press enter to server and authenticating
```py
ssh = Server(usexternalauth=True)
@ssh.on_user("auth")
def auth(data):
# do something
return
```
### data
```py
{
"username": ...,
"password": ...,
}
```
**return** True/False
## connectpty
Called when user connected to server and authenticated with pty request (terminal info)
```py
@ssh.on_user("connectpty")
def connectpty(client, data):
# do something
```
### data
```py
{
"term": ...,
"width": ...,
"height": ...,
"pixelwidth": ...,
"pixelheight": ...,
"modes": ...
}
```
## resized
Called when user resized terminal
```py
@ssh.on_user("resized")
def resized(client, data):
# do something
```
### data
```py
{
"width": ...,
"height": ...,
"pixelwidth": ...,
"pixelheight": ...
}
```
## command
Called when user entered command
```py
@ssh.on_user("command")
def command(client, command):
# do something
```
## type
Called press key (no ansi)
```py
@ssh.on_user("type")
def type(client, key):
# do something
```
## rawtype
Called press key
```py
@ssh.on_user("rawtype")
def rawtype(client, key):
# do something
```
## error
Called when inside command event error
```py
@ssh.on_user("error")
def error(client, error):
# do something
```
## disconnected
Called when user is exited (safe exit)
```py
@ssh.on_user("disconnected")
def disconnected(client):
# do something
```
## timeout
Called when user is timeout (on inputsystem only)
```py
@ssh.on_user("timeout")
def timeout(client):
# do something
```