-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
166 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# frp插件开发 | ||
本代码运行在特定端口用于监听frp的RPC消息 | ||
## 运行代码 | ||
首先在当前项目主目录下创建虚拟环境 | ||
`python3 -m venv venv` | ||
然后安装`requirements.txt`文件的依赖 | ||
`pip install -r requirements.txt` | ||
然后输入以下命令启动uwsgi: | ||
`source venv/bin/activate && uwsgi --ini uwsgi_frp-info.ini -d /dev/null && deactivate` | ||
再添加以下内容到文件`frps.ini` | ||
```conf | ||
[plugin.frp-info] | ||
addr = 127.0.0.1:6666 | ||
path = /handler | ||
ops = Login,NewProxy,NewWorkConn,NewUserConn | ||
``` | ||
最后重启frps服务`service frps restart`即可实现插件的安装配置 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
# author: 'zfb' | ||
# time: 20-07-08 19:25:56 | ||
from flask import Flask | ||
import app.config as config | ||
|
||
app = Flask(__name__) | ||
app.secret_key = config.FLASK_SECRET_KEY | ||
|
||
from app.controller.main import * | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
# author: 'zfb' | ||
# time: 20-07-08 19:24:15 | ||
|
||
# flask秘钥 | ||
FLASK_SECRET_KEY = "qrd762^$#&*hgwd$%UTD(*#RYD" |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
# author: 'zfb' | ||
# time: 20-07-08 19:40:23 | ||
from app import app | ||
from flask import request | ||
import app.config as config | ||
import logging | ||
import json | ||
|
||
from app.model.HandleFrpMsg import handlemsg | ||
|
||
# 初始化 | ||
logging = logging.getLogger('runserver.main') | ||
|
||
@app.route('/handler', methods=["POST", "GET"]) | ||
def handler(): | ||
if request.method == "GET": | ||
logging.debug('GET访问') | ||
data = [{'提示': "非法访问"}] | ||
return json.dumps(data, ensure_ascii=False), 403 | ||
try: | ||
logging.debug('POST访问') | ||
data = request.json | ||
# print(data) | ||
# 处理来自frp的请求数据 | ||
handlemsg(data) | ||
# 始终返回此信息:不拒绝连接,保持不变;即不对内容进行任何操作 | ||
response_data = {"reject": False, "unchange": True} | ||
return json.dumps(response_data, ensure_ascii=False), 200 | ||
except Exception as e: | ||
logging.error(repr(e)) | ||
return 404 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
# author: 'zfb' | ||
# time: 2020-07-08 19:55 | ||
|
||
import logging | ||
|
||
logging = logging.getLogger('runserver.handlefrpmsg') | ||
|
||
|
||
# 处理frps的各种信息,包括以下几种 | ||
# Login、NewProxy、Ping、NewWorkConn、NewUserConn | ||
def handlemsg(data): | ||
operation = data['op'] | ||
# Ping操作每隔30s发送一次 | ||
if operation == 'Ping': | ||
return | ||
content = data['content'] | ||
logging.debug(content) |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
# author: 'zfb' | ||
# time: 20-07-08 19:23:11 | ||
import os | ||
import logging | ||
from logging.handlers import RotatingFileHandler | ||
|
||
LOG_FORMAT = "%(asctime)s [%(funcName)s: %(filename)s,%(lineno)d] - %(levelname)s : %(message)s" | ||
DATE_FORMAT = "%m/%d/%Y %H:%M:%S" | ||
LOG_PATH = "./log/" | ||
|
||
# 初始化日志文件配置 | ||
def initLog(fileName,logger): | ||
# 创建日志文件夹 | ||
if not os.path.exists(LOG_PATH): | ||
os.mkdir(LOG_PATH) | ||
myapp = logging.getLogger(logger) | ||
myapp.setLevel(logging.DEBUG) | ||
# 切割日志文件 | ||
handler = RotatingFileHandler(LOG_PATH+fileName, maxBytes=128*1024, backupCount=60) | ||
handler.setFormatter(logging.Formatter(LOG_FORMAT,DATE_FORMAT)) | ||
myapp.addHandler(handler) | ||
return myapp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
flask | ||
uwsgi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#! /bin/bash | ||
PORT=6666 | ||
kill -9 $(lsof -t -i:$PORT) > /dev/null 2>&1 | ||
if [ $? -eq 0 ];then | ||
echo "Kill $PORT port successfully!" | ||
else | ||
echo "Fail to kill $PORT port" | ||
fi | ||
NAME=~/frp-info/log/server.log | ||
uwsgi uwsgi_frp-info.ini -d $NAME > /dev/null 2>&1 | ||
if [ $? -eq 0 ];then | ||
echo "Restart successfully!" | ||
else | ||
echo "Fail to restart" | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
# author: 'zfb' | ||
# time: 20-07-08 19:20:22 | ||
from app import app | ||
from log import initLog | ||
|
||
logging = initLog('frp-info.log','runserver') | ||
|
||
if __name__ == '__main__': | ||
app.run(host="0.0.0.0", debug=False, port=6665) | ||
|
||
application = app |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
[uwsgi] | ||
# http协议对客户端开发的端口号 | ||
# 端口保证与frps.ini的plugin的addr一致 | ||
http = 0.0.0.0:6666 | ||
# 应用目录,即python代码所在目录 | ||
pythonpath = ./ | ||
# web 应用python主程序 | ||
wsgi-file = ./runserver.py | ||
# 一般在主运行程序里指定 app = Flask(__name__) | ||
callable = app | ||
# 工作进程数 | ||
processes = 4 | ||
# 线程数 | ||
threads = 2 | ||
# 指定日志文件 | ||
demonize = ./log/server.log | ||
# 切割日志文件 | ||
log-maxsize = 1000000 | ||
# python 虚拟环境目录 | ||
home = ./venv | ||
# 修改python代码后自动重启 | ||
python-autoreload = 1 | ||
# 方便重启 | ||
safe-pidfile = ./uwsgi-master.pid |