-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathplugin.py
25 lines (20 loc) · 974 Bytes
/
plugin.py
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
from nachovpn.plugins import VPNPlugin
from flask import Flask, jsonify, request
import logging
class ExamplePlugin(VPNPlugin):
def _setup_routes(self):
# Call the parent class's route setup
super()._setup_routes()
# Add additional routes specific to this plugin
@self.flask_app.route('/api/v2/healthcheck', methods=['GET'])
def healthcheck_v2():
return jsonify({"message": "OK"})
def can_handle_http(self, handler):
return handler.path in ['/api/v2/healthcheck']
def can_handle_data(self, data, client_socket, client_ip):
logging.info(f"ExamplePlugin::can_handle_data: Received data from {client_ip}: {data.hex()}")
return len(data) >= 4 and b"PING" in data[:4]
def handle_data(self, data, client_socket, client_ip):
logging.info(f"ExamplePlugin::handle_data: Received data from {client_ip}: {data.hex()}")
client_socket.sendall(b"PONG\n")
return True