Flask 架构 --xunfeng实例研究

文件结构

│  Config.py  # 配置文件
│  README.md  # 说明文档
│  Run.bat  # Windows启动服务
│  Run.py  # webserver
│  Run.sh    # Linux启动服务,重新启动前需把进程先结束掉
│
├─aider
│      Aider.py  # 辅助验证脚本
│
├─db  # 初始数据库结构
│
├─masscan  # 内置编译好的Masscan程序(CentOS win64适用),需要chmod+x给执行权限(root),若无法使用请自行编译安装。
├─nascan
│  │  NAScan.py # 网络资产信息抓取引擎
│  │
│  ├─lib
│  │      common.py 其他方法
│  │      icmp.py  # ICMP发送类
│  │      log.py  # 日志输出
│  │      mongo.py  # 数据库连接
│  │      scan.py  # 扫描与识别
│  │      start.py  # 线程控制
│  │
│  └─plugin
│          masscan.py  # 调用Masscan脚本
│
├─views
│  │  View.py  # web请求处理
│  │
│  ├─lib
│  │      Conn.py  # 数据库公共类
│  │      CreateExcel.py  # 表格处理
│  │      Login.py  # 权限验证
│  │      QueryLogic.py  # 查询语句解析
│  │
│  ├─static #静态资源目录
│  │
│  └─templates #模板文件目录
│
└─vulscan
    │  VulScan.py  # 漏洞检测引擎
    │
    └─vuldb # 漏洞库目录


启动程序:

start mongod.exe --port 65521 --dbpath Data --auth     1--启动mongodb数据库服务,端口是65521
start python Run.py                      2--启动flask app程序 核心代码: app.run(threaded=True, port=80,host='127.0.0.1')
start python aider/Aider.py
start python nascan/NAScan.py
start python vulscan/VulScan.py
start python Run.py:代码 
app.debug = True
app.run(threaded=True, port=80,host='127.0.0.1')

设置了
app.debug = True后,flask将会执行以下的命令: 
options.setdefault('use_reloader', self.debug)
options.setdefault('use_debugger', self.debug)
options.setdefault('passthrough_errors', True)
try:
run_simple(host, port, self, **options)
finally:
# reset the first request information if the development server
# resetted normally. This makes it possible to restart the server
# without reloader and that stuff from an interactive shell.
self._got_first_request = False
其中
run_simple说明如下: 

Start a WSGI application. Optional features include a reloader,
multithreading and fork support.
方法定义说明:
def run_simple(hostname, port, application, use_reloader=False,
use_debugger=False, use_evalex=True,
extra_files=None, reloader_interval=1,
reloader_type='auto', threaded=False,
processes=1, request_handler=None, static_files=None,
passthrough_errors=False, ssl_context=None):


示例: 

if __name__ == '__main__':
from werkzeug.serving import run_simple
app = create_app()   --这个app,可以是自定义的WSGI程序  ,详情请看
run_simple('127.0.0.1', 5000, app, use_debugger=True, use_reloader=True)

 




flask app文件讲解:

入口函数:
def run(self, host=None, port=None, debug=None, **options):


其他函数:
create_jinja_environment(self): 
-----创建jinja2环境; based on :attr:`jinja_options` and :meth:`select_jinja_autoescape`.
-----其中:
jinja_options = ImmutableDict( extensions=['jinja2.ext.autoescape', 'jinja2.ext.with_'])








posted @ 2017-03-23 21:11  八月的男人  阅读(1059)  评论(0编辑  收藏  举报