Showing preview only (707K chars total). Download the full file or copy to clipboard to get everything.
Repository: chaitin/SafeLine
Branch: main
Commit: 6d871e638bf8
Files: 236
Total size: 649.6 KB
Directory structure:
gitextract_r0ep21tc/
├── .github/
│ ├── ISSUE_TEMPLATE/
│ │ ├── bug-report.yaml
│ │ ├── config.yml
│ │ ├── feature-request.yaml
│ │ └── other.yaml
│ └── workflows/
│ └── slmcp-docker.yml
├── .gitignore
├── .gitmodules
├── LICENSE.md
├── README.md
├── README_CN.md
├── compose.yaml
├── management/
│ ├── .gitignore
│ ├── .golangci.yml
│ ├── Makefile
│ ├── README.md
│ ├── scripts/
│ │ └── genproto.sh
│ ├── tcontrollerd/
│ │ ├── README.md
│ │ ├── config.yml
│ │ ├── controller/
│ │ │ ├── controller.go
│ │ │ ├── template.go
│ │ │ └── website.go
│ │ ├── go.mod
│ │ ├── go.sum
│ │ ├── main.go
│ │ ├── model/
│ │ │ └── website.go
│ │ ├── pkg/
│ │ │ ├── config/
│ │ │ │ ├── config.go
│ │ │ │ ├── global.go
│ │ │ │ └── log.go
│ │ │ ├── constants/
│ │ │ │ ├── constants.go
│ │ │ │ └── forbidden_page.go
│ │ │ ├── cron/
│ │ │ │ ├── cron.go
│ │ │ │ └── forbidden_page.go
│ │ │ ├── log/
│ │ │ │ └── log.go
│ │ │ └── ngcmd/
│ │ │ └── ngcmd.go
│ │ ├── proto/
│ │ │ └── website/
│ │ │ └── website.proto
│ │ └── utils/
│ │ ├── file.go
│ │ └── random.go
│ └── webserver/
│ ├── .gitignore
│ ├── README.md
│ ├── api/
│ │ ├── auth.go
│ │ ├── behaviour.go
│ │ ├── cert.go
│ │ ├── common.go
│ │ ├── dashboard.go
│ │ ├── detectlog.go
│ │ ├── endpoints.go
│ │ ├── policygroup.go
│ │ ├── policyrule.go
│ │ ├── response/
│ │ │ ├── error.go
│ │ │ ├── jsonbody.go
│ │ │ └── png.go
│ │ └── website.go
│ ├── cmd/
│ │ ├── fake_logs.go
│ │ ├── gen_certs.go
│ │ ├── push_fsl.go
│ │ ├── reset_user.go
│ │ └── show_fsl.go
│ ├── config.yml
│ ├── go.mod
│ ├── go.sum
│ ├── main.go
│ ├── middleware/
│ │ └── auth.go
│ ├── model/
│ │ ├── base.go
│ │ ├── behaviour.go
│ │ ├── db_patch_1_4_0.go
│ │ ├── detectlog.go
│ │ ├── init.go
│ │ ├── option.go
│ │ ├── policygroup.go
│ │ ├── policyrule.go
│ │ ├── statistics.go
│ │ ├── user.go
│ │ └── website.go
│ ├── pkg/
│ │ ├── config/
│ │ │ ├── config.go
│ │ │ ├── db.go
│ │ │ ├── detector.go
│ │ │ ├── global.go
│ │ │ ├── grpc.go
│ │ │ ├── log.go
│ │ │ ├── server.go
│ │ │ └── telemetry.go
│ │ ├── constants/
│ │ │ ├── constants.go
│ │ │ ├── detectlog.go
│ │ │ ├── detector.go
│ │ │ ├── option.go
│ │ │ ├── session.go
│ │ │ └── telemetry.go
│ │ ├── cron/
│ │ │ ├── cron.go
│ │ │ └── update_policy.go
│ │ ├── database/
│ │ │ └── postgres.go
│ │ ├── fvm/
│ │ │ ├── fsl/
│ │ │ │ ├── action.go
│ │ │ │ ├── quote.go
│ │ │ │ ├── selector.go
│ │ │ │ ├── state.go
│ │ │ │ ├── table.go
│ │ │ │ └── target.go
│ │ │ ├── fvm.go
│ │ │ ├── generator.go
│ │ │ └── helper.go
│ │ ├── log/
│ │ │ └── log.go
│ │ └── telemetry.go
│ ├── proto/
│ │ └── website/
│ │ └── website.proto
│ ├── rpc/
│ │ ├── main.go
│ │ └── website.go
│ ├── tools/
│ │ └── init_db.sh
│ └── utils/
│ ├── cert.go
│ ├── file.go
│ ├── healthy.go
│ ├── httpclient.go
│ ├── random.go
│ └── url.go
├── mcp_server/
│ ├── Dockerfile
│ ├── README.md
│ ├── config.yaml
│ ├── docker-compose.yml
│ ├── go.mod
│ ├── go.sum
│ ├── internal/
│ │ ├── api/
│ │ │ ├── analyze/
│ │ │ │ └── get_event_list.go
│ │ │ ├── app/
│ │ │ │ └── create_application.go
│ │ │ ├── client.go
│ │ │ ├── response.go
│ │ │ ├── rule/
│ │ │ │ └── create_rule.go
│ │ │ ├── service.go
│ │ │ └── types.go
│ │ ├── config/
│ │ │ └── config.go
│ │ └── tools/
│ │ ├── analyze/
│ │ │ └── get_atttack_events.go
│ │ ├── app/
│ │ │ └── create_application.go
│ │ ├── example.go
│ │ ├── init.go
│ │ ├── rule/
│ │ │ ├── create_blacklist_rule.go
│ │ │ └── create_whitelist_rule.go
│ │ └── tool.go
│ ├── main.go
│ └── pkg/
│ ├── config/
│ │ └── config.go
│ ├── errors/
│ │ └── errors.go
│ ├── logger/
│ │ ├── field.go
│ │ └── logger.go
│ └── mcp/
│ ├── mcp.go
│ ├── schema.go
│ └── schema_test.go
├── scripts/
│ └── manage.py
├── sdk/
│ ├── ingress-nginx/
│ │ ├── README.md
│ │ ├── ingress-nginx-safeline-1.0.2-1.rockspec
│ │ ├── ingress-nginx-safeline-1.0.3-1.rockspec
│ │ ├── ingress-nginx-safeline-1.0.4-1.rockspec
│ │ └── lib/
│ │ └── safeline/
│ │ └── main.lua
│ ├── kong/
│ │ ├── Readme.md
│ │ ├── kong/
│ │ │ └── plugins/
│ │ │ └── safeline/
│ │ │ ├── handler.lua
│ │ │ └── schema.lua
│ │ ├── kong-safeline-1.0.0-1.rockspec
│ │ ├── kong-safeline-1.0.1-1.rockspec
│ │ ├── kong-safeline-1.0.2-1.rockspec
│ │ ├── kong-safeline-1.0.3-1.rockspec
│ │ ├── kong-safeline-1.0.4-1.rockspec
│ │ ├── kong-safeline-1.0.5-1.rockspec
│ │ ├── kong-safeline-1.0.6-1.rockspec
│ │ └── kong-safeline-1.0.7-1.rockspec
│ └── lua-resty-t1k/
│ ├── .github/
│ │ └── workflows/
│ │ ├── release.yml
│ │ └── test.yml
│ ├── .gitignore
│ ├── .luacheckrc
│ ├── LICENSE
│ ├── README.md
│ ├── ci/
│ │ ├── .dockerignore
│ │ ├── Dockerfile
│ │ └── bytecode
│ ├── lib/
│ │ └── resty/
│ │ ├── t1k/
│ │ │ ├── buffer.lua
│ │ │ ├── constants.lua
│ │ │ ├── file.lua
│ │ │ ├── filter.lua
│ │ │ ├── handler.lua
│ │ │ ├── log.lua
│ │ │ ├── request.lua
│ │ │ ├── utils.lua
│ │ │ └── uuid.lua
│ │ └── t1k.lua
│ ├── mainspec/
│ │ └── lua-resty-t1k-main-0-0.rockspec
│ ├── rockspec/
│ │ ├── lua-resty-t1k-1.0.0-0.rockspec
│ │ ├── lua-resty-t1k-1.0.1-0.rockspec
│ │ ├── lua-resty-t1k-1.0.2-0.rockspec
│ │ ├── lua-resty-t1k-1.0.3-0.rockspec
│ │ ├── lua-resty-t1k-1.1.0-0.rockspec
│ │ ├── lua-resty-t1k-1.1.1-0.rockspec
│ │ ├── lua-resty-t1k-1.1.2-0.rockspec
│ │ ├── lua-resty-t1k-1.1.3-0.rockspec
│ │ ├── lua-resty-t1k-1.1.4-0.rockspec
│ │ └── lua-resty-t1k-1.1.5-0.rockspec
│ └── t/
│ ├── buffer.t
│ ├── file.t
│ ├── filter.t
│ ├── handler.t
│ ├── integration.t
│ ├── log.t
│ ├── option.t
│ ├── request.t
│ ├── utils.t
│ └── uuid.t
├── version.json
└── yanshi/
├── .gitignore
├── Makefile
├── README.md
├── contrib/
│ ├── vim/
│ │ ├── compiler/
│ │ │ └── yanshi.vim
│ │ ├── ftdetect/
│ │ │ └── yanshi.vim
│ │ ├── ftplugin/
│ │ │ └── yanshi.vim
│ │ ├── syntax/
│ │ │ └── yanshi.vim
│ │ └── syntax_checkers/
│ │ └── yanshi/
│ │ └── yanshi.vim
│ └── zsh/
│ └── _yanshi
├── src/
│ ├── common.cc
│ ├── common.hh
│ ├── compiler.cc
│ ├── compiler.hh
│ ├── fsa.cc
│ ├── fsa.hh
│ ├── fsa_anno.cc
│ ├── fsa_anno.hh
│ ├── lexer.l
│ ├── lexer_helper.cc
│ ├── lexer_helper.hh
│ ├── loader.cc
│ ├── loader.hh
│ ├── location.cc
│ ├── location.hh
│ ├── main.cc
│ ├── option.cc
│ ├── option.hh
│ ├── parser.y
│ ├── repl.cc
│ ├── repl.hh
│ ├── syntax.cc
│ └── syntax.hh
└── unittest/
├── determinize_test.cc
├── difference_test.cc
├── intersection_test.cc
├── minimize_test.cc
├── union_test.cc
└── unittest_helper.hh
================================================
FILE CONTENTS
================================================
================================================
FILE: .github/ISSUE_TEMPLATE/bug-report.yaml
================================================
name: Bug
description: Report a bug
# Create a report to help us improve
title: "[Bug] "
body:
- type: markdown
attributes:
value: |
Please search the [open issues](https://github.com/chaitin/SafeLine/issues) and [discussion](https://github.com/chaitin/SafeLine/discussions) for duplicate issue first.
The more information you share, the faster we can identify and fix the bug.
# Please check for duplicate issue first.
- type: textarea
id: Description
attributes:
label: What happened?
# Describe the bug
validations:
required: false
- type: textarea
id: Reproduce
attributes:
label: How we reproduce?
description: |
Reports cannot be reproduced will Most likely be closed.
# To Reproduce
value: |
1. ...
2. ...
3. ...
- type: textarea
id: Expected
attributes:
label: Expected behavior
# placeholder: |
# Descript what you expected to happen.
# Expected behavior. Descript what you expected to happen.
- type: textarea
id: Errorlog
attributes:
label: Error log
placeholder: |
Paste the error logs if any.
# Expected behavior. Descript what you expected to happen.
================================================
FILE: .github/ISSUE_TEMPLATE/config.yml
================================================
blank_issues_enabled: false
contact_links:
- name: Discord
url: https://discord.gg/wyshSVuvxC
about: Ask questions and discuss with other SafeLine users in real time.
- name: Home page 官网
url: https://waf.chaitin.com/
about: Get feature descriptions, technical documentation and more information. 获取功能描述、技术文档和更多信息。
- name: 绕过反馈
url: https://stack.chaitin.com/security-challenge/safeline/index
about: Waf 绕过可在 CT Stack 安全挑战赛提交细节
================================================
FILE: .github/ISSUE_TEMPLATE/feature-request.yaml
================================================
name: Suggestion
# Feature request
description: New feature or improvements.
title: "[Suggestion] "
body:
- type: markdown
attributes:
value: |
Please search the [open issues](https://github.com/chaitin/SafeLine/issues) and [discussion](https://github.com/chaitin/SafeLine/discussions) for duplicate issue first.
Please rise only one suggestion in an issue.
- type: textarea
id: solution
attributes:
label: What would you like to be added or improved?
# Describe the solution you'd like
# placeholder: |
#
- type: textarea
id: problem
attributes:
label: Why is it needed?
# Background and the specific problem that frustrates you
placeholder: |
Background and the problem that frustrates you
validations:
required: true
================================================
FILE: .github/ISSUE_TEMPLATE/other.yaml
================================================
name: Other
description: Other issues such as Doc
body:
- type: markdown
attributes:
value: |
Please search the [open issues](https://github.com/chaitin/SafeLine/issues) and [discussion](https://github.com/chaitin/SafeLine/discussions) for duplicate issue first.
Please rise only one suggestion in an issue.
- type: textarea
id: content
attributes:
label: Content
================================================
FILE: .github/workflows/slmcp-docker.yml
================================================
name: MCP Docker
on:
push:
branches:
- main
tags:
- "v*"
paths:
- "mcp_server/**"
- ".github/workflows/slmcp-docker.yml"
jobs:
build-and-push:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
platforms: linux/amd64,linux/arm64
- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERIO_USERNAME }}
password: ${{ secrets.DOCKERIO_PASSWORD }}
- name: Build and push
uses: docker/build-push-action@v5
with:
context: ./mcp_server
push: true
platforms: linux/amd64,linux/arm64
tags: |
chaitin/safeline-mcp:latest
chaitin/safeline-mcp:${{ github.ref_name }}
cache-from: type=registry,ref=chaitin/safeline-mcp:buildcache
cache-to: type=registry,ref=chaitin/safeline-mcp:buildcache,mode=max
================================================
FILE: .gitignore
================================================
*.Zone.Identifier
.DS_Store
*.zip
*.tar
*.tar.gz
build.sh
compose.yml
__pycache__
.cursor
.vscode
================================================
FILE: .gitmodules
================================================
[submodule "blazehttp"]
path = blazehttp
url = https://github.com/chaitin/blazehttp
[submodule "sdk/traefik-safeline"]
path = sdk/traefik-safeline
url = https://github.com/chaitin/traefik-safeline
================================================
FILE: LICENSE.md
================================================
GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The GNU General Public License is a free, copyleft license for
software and other kinds of works.
The licenses for most software and other practical works are designed
to take away your freedom to share and change the works. By contrast,
the GNU General Public License is intended to guarantee your freedom to
share and change all versions of a program--to make sure it remains free
software for all its users. We, the Free Software Foundation, use the
GNU General Public License for most of our software; it applies also to
any other work released this way by its authors. You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
them if you wish), that you receive source code or can get it if you
want it, that you can change the software or use pieces of it in new
free programs, and that you know you can do these things.
To protect your rights, we need to prevent others from denying you
these rights or asking you to surrender the rights. Therefore, you have
certain responsibilities if you distribute copies of the software, or if
you modify it: responsibilities to respect the freedom of others.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must pass on to the recipients the same
freedoms that you received. You must make sure that they, too, receive
or can get the source code. And you must show them these terms so they
know their rights.
Developers that use the GNU GPL protect your rights with two steps:
(1) assert copyright on the software, and (2) offer you this License
giving you legal permission to copy, distribute and/or modify it.
For the developers' and authors' protection, the GPL clearly explains
that there is no warranty for this free software. For both users' and
authors' sake, the GPL requires that modified versions be marked as
changed, so that their problems will not be attributed erroneously to
authors of previous versions.
Some devices are designed to deny users access to install or run
modified versions of the software inside them, although the manufacturer
can do so. This is fundamentally incompatible with the aim of
protecting users' freedom to change the software. The systematic
pattern of such abuse occurs in the area of products for individuals to
use, which is precisely where it is most unacceptable. Therefore, we
have designed this version of the GPL to prohibit the practice for those
products. If such problems arise substantially in other domains, we
stand ready to extend this provision to those domains in future versions
of the GPL, as needed to protect the freedom of users.
Finally, every program is threatened constantly by software patents.
States should not allow patents to restrict development and use of
software on general-purpose computers, but in those that do, we wish to
avoid the special danger that patents applied to a free program could
make it effectively proprietary. To prevent this, the GPL assures that
patents cannot be used to render the program non-free.
The precise terms and conditions for copying, distribution and
modification follow.
TERMS AND CONDITIONS
0. Definitions.
"This License" refers to version 3 of the GNU General Public License.
"Copyright" also means copyright-like laws that apply to other kinds of
works, such as semiconductor masks.
"The Program" refers to any copyrightable work licensed under this
License. Each licensee is addressed as "you". "Licensees" and
"recipients" may be individuals or organizations.
To "modify" a work means to copy from or adapt all or part of the work
in a fashion requiring copyright permission, other than the making of an
exact copy. The resulting work is called a "modified version" of the
earlier work or a work "based on" the earlier work.
A "covered work" means either the unmodified Program or a work based
on the Program.
To "propagate" a work means to do anything with it that, without
permission, would make you directly or secondarily liable for
infringement under applicable copyright law, except executing it on a
computer or modifying a private copy. Propagation includes copying,
distribution (with or without modification), making available to the
public, and in some countries other activities as well.
To "convey" a work means any kind of propagation that enables other
parties to make or receive copies. Mere interaction with a user through
a computer network, with no transfer of a copy, is not conveying.
An interactive user interface displays "Appropriate Legal Notices"
to the extent that it includes a convenient and prominently visible
feature that (1) displays an appropriate copyright notice, and (2)
tells the user that there is no warranty for the work (except to the
extent that warranties are provided), that licensees may convey the
work under this License, and how to view a copy of this License. If
the interface presents a list of user commands or options, such as a
menu, a prominent item in the list meets this criterion.
1. Source Code.
The "source code" for a work means the preferred form of the work
for making modifications to it. "Object code" means any non-source
form of a work.
A "Standard Interface" means an interface that either is an official
standard defined by a recognized standards body, or, in the case of
interfaces specified for a particular programming language, one that
is widely used among developers working in that language.
The "System Libraries" of an executable work include anything, other
than the work as a whole, that (a) is included in the normal form of
packaging a Major Component, but which is not part of that Major
Component, and (b) serves only to enable use of the work with that
Major Component, or to implement a Standard Interface for which an
implementation is available to the public in source code form. A
"Major Component", in this context, means a major essential component
(kernel, window system, and so on) of the specific operating system
(if any) on which the executable work runs, or a compiler used to
produce the work, or an object code interpreter used to run it.
The "Corresponding Source" for a work in object code form means all
the source code needed to generate, install, and (for an executable
work) run the object code and to modify the work, including scripts to
control those activities. However, it does not include the work's
System Libraries, or general-purpose tools or generally available free
programs which are used unmodified in performing those activities but
which are not part of the work. For example, Corresponding Source
includes interface definition files associated with source files for
the work, and the source code for shared libraries and dynamically
linked subprograms that the work is specifically designed to require,
such as by intimate data communication or control flow between those
subprograms and other parts of the work.
The Corresponding Source need not include anything that users
can regenerate automatically from other parts of the Corresponding
Source.
The Corresponding Source for a work in source code form is that
same work.
2. Basic Permissions.
All rights granted under this License are granted for the term of
copyright on the Program, and are irrevocable provided the stated
conditions are met. This License explicitly affirms your unlimited
permission to run the unmodified Program. The output from running a
covered work is covered by this License only if the output, given its
content, constitutes a covered work. This License acknowledges your
rights of fair use or other equivalent, as provided by copyright law.
You may make, run and propagate covered works that you do not
convey, without conditions so long as your license otherwise remains
in force. You may convey covered works to others for the sole purpose
of having them make modifications exclusively for you, or provide you
with facilities for running those works, provided that you comply with
the terms of this License in conveying all material for which you do
not control copyright. Those thus making or running the covered works
for you must do so exclusively on your behalf, under your direction
and control, on terms that prohibit them from making any copies of
your copyrighted material outside their relationship with you.
Conveying under any other circumstances is permitted solely under
the conditions stated below. Sublicensing is not allowed; section 10
makes it unnecessary.
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
No covered work shall be deemed part of an effective technological
measure under any applicable law fulfilling obligations under article
11 of the WIPO copyright treaty adopted on 20 December 1996, or
similar laws prohibiting or restricting circumvention of such
measures.
When you convey a covered work, you waive any legal power to forbid
circumvention of technological measures to the extent such circumvention
is effected by exercising rights under this License with respect to
the covered work, and you disclaim any intention to limit operation or
modification of the work as a means of enforcing, against the work's
users, your or third parties' legal rights to forbid circumvention of
technological measures.
4. Conveying Verbatim Copies.
You may convey verbatim copies of the Program's source code as you
receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice;
keep intact all notices stating that this License and any
non-permissive terms added in accord with section 7 apply to the code;
keep intact all notices of the absence of any warranty; and give all
recipients a copy of this License along with the Program.
You may charge any price or no price for each copy that you convey,
and you may offer support or warranty protection for a fee.
5. Conveying Modified Source Versions.
You may convey a work based on the Program, or the modifications to
produce it from the Program, in the form of source code under the
terms of section 4, provided that you also meet all of these conditions:
a) The work must carry prominent notices stating that you modified
it, and giving a relevant date.
b) The work must carry prominent notices stating that it is
released under this License and any conditions added under section
7. This requirement modifies the requirement in section 4 to
"keep intact all notices".
c) You must license the entire work, as a whole, under this
License to anyone who comes into possession of a copy. This
License will therefore apply, along with any applicable section 7
additional terms, to the whole of the work, and all its parts,
regardless of how they are packaged. This License gives no
permission to license the work in any other way, but it does not
invalidate such permission if you have separately received it.
d) If the work has interactive user interfaces, each must display
Appropriate Legal Notices; however, if the Program has interactive
interfaces that do not display Appropriate Legal Notices, your
work need not make them do so.
A compilation of a covered work with other separate and independent
works, which are not by their nature extensions of the covered work,
and which are not combined with it such as to form a larger program,
in or on a volume of a storage or distribution medium, is called an
"aggregate" if the compilation and its resulting copyright are not
used to limit the access or legal rights of the compilation's users
beyond what the individual works permit. Inclusion of a covered work
in an aggregate does not cause this License to apply to the other
parts of the aggregate.
6. Conveying Non-Source Forms.
You may convey a covered work in object code form under the terms
of sections 4 and 5, provided that you also convey the
machine-readable Corresponding Source under the terms of this License,
in one of these ways:
a) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by the
Corresponding Source fixed on a durable physical medium
customarily used for software interchange.
b) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by a
written offer, valid for at least three years and valid for as
long as you offer spare parts or customer support for that product
model, to give anyone who possesses the object code either (1) a
copy of the Corresponding Source for all the software in the
product that is covered by this License, on a durable physical
medium customarily used for software interchange, for a price no
more than your reasonable cost of physically performing this
conveying of source, or (2) access to copy the
Corresponding Source from a network server at no charge.
c) Convey individual copies of the object code with a copy of the
written offer to provide the Corresponding Source. This
alternative is allowed only occasionally and noncommercially, and
only if you received the object code with such an offer, in accord
with subsection 6b.
d) Convey the object code by offering access from a designated
place (gratis or for a charge), and offer equivalent access to the
Corresponding Source in the same way through the same place at no
further charge. You need not require recipients to copy the
Corresponding Source along with the object code. If the place to
copy the object code is a network server, the Corresponding Source
may be on a different server (operated by you or a third party)
that supports equivalent copying facilities, provided you maintain
clear directions next to the object code saying where to find the
Corresponding Source. Regardless of what server hosts the
Corresponding Source, you remain obligated to ensure that it is
available for as long as needed to satisfy these requirements.
e) Convey the object code using peer-to-peer transmission, provided
you inform other peers where the object code and Corresponding
Source of the work are being offered to the general public at no
charge under subsection 6d.
A separable portion of the object code, whose source code is excluded
from the Corresponding Source as a System Library, need not be
included in conveying the object code work.
A "User Product" is either (1) a "consumer product", which means any
tangible personal property which is normally used for personal, family,
or household purposes, or (2) anything designed or sold for incorporation
into a dwelling. In determining whether a product is a consumer product,
doubtful cases shall be resolved in favor of coverage. For a particular
product received by a particular user, "normally used" refers to a
typical or common use of that class of product, regardless of the status
of the particular user or of the way in which the particular user
actually uses, or expects or is expected to use, the product. A product
is a consumer product regardless of whether the product has substantial
commercial, industrial or non-consumer uses, unless such uses represent
the only significant mode of use of the product.
"Installation Information" for a User Product means any methods,
procedures, authorization keys, or other information required to install
and execute modified versions of a covered work in that User Product from
a modified version of its Corresponding Source. The information must
suffice to ensure that the continued functioning of the modified object
code is in no case prevented or interfered with solely because
modification has been made.
If you convey an object code work under this section in, or with, or
specifically for use in, a User Product, and the conveying occurs as
part of a transaction in which the right of possession and use of the
User Product is transferred to the recipient in perpetuity or for a
fixed term (regardless of how the transaction is characterized), the
Corresponding Source conveyed under this section must be accompanied
by the Installation Information. But this requirement does not apply
if neither you nor any third party retains the ability to install
modified object code on the User Product (for example, the work has
been installed in ROM).
The requirement to provide Installation Information does not include a
requirement to continue to provide support service, warranty, or updates
for a work that has been modified or installed by the recipient, or for
the User Product in which it has been modified or installed. Access to a
network may be denied when the modification itself materially and
adversely affects the operation of the network or violates the rules and
protocols for communication across the network.
Corresponding Source conveyed, and Installation Information provided,
in accord with this section must be in a format that is publicly
documented (and with an implementation available to the public in
source code form), and must require no special password or key for
unpacking, reading or copying.
7. Additional Terms.
"Additional permissions" are terms that supplement the terms of this
License by making exceptions from one or more of its conditions.
Additional permissions that are applicable to the entire Program shall
be treated as though they were included in this License, to the extent
that they are valid under applicable law. If additional permissions
apply only to part of the Program, that part may be used separately
under those permissions, but the entire Program remains governed by
this License without regard to the additional permissions.
When you convey a copy of a covered work, you may at your option
remove any additional permissions from that copy, or from any part of
it. (Additional permissions may be written to require their own
removal in certain cases when you modify the work.) You may place
additional permissions on material, added by you to a covered work,
for which you have or can give appropriate copyright permission.
Notwithstanding any other provision of this License, for material you
add to a covered work, you may (if authorized by the copyright holders of
that material) supplement the terms of this License with terms:
a) Disclaiming warranty or limiting liability differently from the
terms of sections 15 and 16 of this License; or
b) Requiring preservation of specified reasonable legal notices or
author attributions in that material or in the Appropriate Legal
Notices displayed by works containing it; or
c) Prohibiting misrepresentation of the origin of that material, or
requiring that modified versions of such material be marked in
reasonable ways as different from the original version; or
d) Limiting the use for publicity purposes of names of licensors or
authors of the material; or
e) Declining to grant rights under trademark law for use of some
trade names, trademarks, or service marks; or
f) Requiring indemnification of licensors and authors of that
material by anyone who conveys the material (or modified versions of
it) with contractual assumptions of liability to the recipient, for
any liability that these contractual assumptions directly impose on
those licensors and authors.
All other non-permissive additional terms are considered "further
restrictions" within the meaning of section 10. If the Program as you
received it, or any part of it, contains a notice stating that it is
governed by this License along with a term that is a further
restriction, you may remove that term. If a license document contains
a further restriction but permits relicensing or conveying under this
License, you may add to a covered work material governed by the terms
of that license document, provided that the further restriction does
not survive such relicensing or conveying.
If you add terms to a covered work in accord with this section, you
must place, in the relevant source files, a statement of the
additional terms that apply to those files, or a notice indicating
where to find the applicable terms.
Additional terms, permissive or non-permissive, may be stated in the
form of a separately written license, or stated as exceptions;
the above requirements apply either way.
8. Termination.
You may not propagate or modify a covered work except as expressly
provided under this License. Any attempt otherwise to propagate or
modify it is void, and will automatically terminate your rights under
this License (including any patent licenses granted under the third
paragraph of section 11).
However, if you cease all violation of this License, then your
license from a particular copyright holder is reinstated (a)
provisionally, unless and until the copyright holder explicitly and
finally terminates your license, and (b) permanently, if the copyright
holder fails to notify you of the violation by some reasonable means
prior to 60 days after the cessation.
Moreover, your license from a particular copyright holder is
reinstated permanently if the copyright holder notifies you of the
violation by some reasonable means, this is the first time you have
received notice of violation of this License (for any work) from that
copyright holder, and you cure the violation prior to 30 days after
your receipt of the notice.
Termination of your rights under this section does not terminate the
licenses of parties who have received copies or rights from you under
this License. If your rights have been terminated and not permanently
reinstated, you do not qualify to receive new licenses for the same
material under section 10.
9. Acceptance Not Required for Having Copies.
You are not required to accept this License in order to receive or
run a copy of the Program. Ancillary propagation of a covered work
occurring solely as a consequence of using peer-to-peer transmission
to receive a copy likewise does not require acceptance. However,
nothing other than this License grants you permission to propagate or
modify any covered work. These actions infringe copyright if you do
not accept this License. Therefore, by modifying or propagating a
covered work, you indicate your acceptance of this License to do so.
10. Automatic Licensing of Downstream Recipients.
Each time you convey a covered work, the recipient automatically
receives a license from the original licensors, to run, modify and
propagate that work, subject to this License. You are not responsible
for enforcing compliance by third parties with this License.
An "entity transaction" is a transaction transferring control of an
organization, or substantially all assets of one, or subdividing an
organization, or merging organizations. If propagation of a covered
work results from an entity transaction, each party to that
transaction who receives a copy of the work also receives whatever
licenses to the work the party's predecessor in interest had or could
give under the previous paragraph, plus a right to possession of the
Corresponding Source of the work from the predecessor in interest, if
the predecessor has it or can get it with reasonable efforts.
You may not impose any further restrictions on the exercise of the
rights granted or affirmed under this License. For example, you may
not impose a license fee, royalty, or other charge for exercise of
rights granted under this License, and you may not initiate litigation
(including a cross-claim or counterclaim in a lawsuit) alleging that
any patent claim is infringed by making, using, selling, offering for
sale, or importing the Program or any portion of it.
11. Patents.
A "contributor" is a copyright holder who authorizes use under this
License of the Program or a work on which the Program is based. The
work thus licensed is called the contributor's "contributor version".
A contributor's "essential patent claims" are all patent claims
owned or controlled by the contributor, whether already acquired or
hereafter acquired, that would be infringed by some manner, permitted
by this License, of making, using, or selling its contributor version,
but do not include claims that would be infringed only as a
consequence of further modification of the contributor version. For
purposes of this definition, "control" includes the right to grant
patent sublicenses in a manner consistent with the requirements of
this License.
Each contributor grants you a non-exclusive, worldwide, royalty-free
patent license under the contributor's essential patent claims, to
make, use, sell, offer for sale, import and otherwise run, modify and
propagate the contents of its contributor version.
In the following three paragraphs, a "patent license" is any express
agreement or commitment, however denominated, not to enforce a patent
(such as an express permission to practice a patent or covenant not to
sue for patent infringement). To "grant" such a patent license to a
party means to make such an agreement or commitment not to enforce a
patent against the party.
If you convey a covered work, knowingly relying on a patent license,
and the Corresponding Source of the work is not available for anyone
to copy, free of charge and under the terms of this License, through a
publicly available network server or other readily accessible means,
then you must either (1) cause the Corresponding Source to be so
available, or (2) arrange to deprive yourself of the benefit of the
patent license for this particular work, or (3) arrange, in a manner
consistent with the requirements of this License, to extend the patent
license to downstream recipients. "Knowingly relying" means you have
actual knowledge that, but for the patent license, your conveying the
covered work in a country, or your recipient's use of the covered work
in a country, would infringe one or more identifiable patents in that
country that you have reason to believe are valid.
If, pursuant to or in connection with a single transaction or
arrangement, you convey, or propagate by procuring conveyance of, a
covered work, and grant a patent license to some of the parties
receiving the covered work authorizing them to use, propagate, modify
or convey a specific copy of the covered work, then the patent license
you grant is automatically extended to all recipients of the covered
work and works based on it.
A patent license is "discriminatory" if it does not include within
the scope of its coverage, prohibits the exercise of, or is
conditioned on the non-exercise of one or more of the rights that are
specifically granted under this License. You may not convey a covered
work if you are a party to an arrangement with a third party that is
in the business of distributing software, under which you make payment
to the third party based on the extent of your activity of conveying
the work, and under which the third party grants, to any of the
parties who would receive the covered work from you, a discriminatory
patent license (a) in connection with copies of the covered work
conveyed by you (or copies made from those copies), or (b) primarily
for and in connection with specific products or compilations that
contain the covered work, unless you entered into that arrangement,
or that patent license was granted, prior to 28 March 2007.
Nothing in this License shall be construed as excluding or limiting
any implied license or other defenses to infringement that may
otherwise be available to you under applicable patent law.
12. No Surrender of Others' Freedom.
If conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot convey a
covered work so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you may
not convey it at all. For example, if you agree to terms that obligate you
to collect a royalty for further conveying from those to whom you convey
the Program, the only way you could satisfy both those terms and this
License would be to refrain entirely from conveying the Program.
13. Use with the GNU Affero General Public License.
Notwithstanding any other provision of this License, you have
permission to link or combine any covered work with a work licensed
under version 3 of the GNU Affero General Public License into a single
combined work, and to convey the resulting work. The terms of this
License will continue to apply to the part which is the covered work,
but the special requirements of the GNU Affero General Public License,
section 13, concerning interaction through a network will apply to the
combination as such.
14. Revised Versions of this License.
The Free Software Foundation may publish revised and/or new versions of
the GNU General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the
Program specifies that a certain numbered version of the GNU General
Public License "or any later version" applies to it, you have the
option of following the terms and conditions either of that numbered
version or of any later version published by the Free Software
Foundation. If the Program does not specify a version number of the
GNU General Public License, you may choose any version ever published
by the Free Software Foundation.
If the Program specifies that a proxy can decide which future
versions of the GNU General Public License can be used, that proxy's
public statement of acceptance of a version permanently authorizes you
to choose that version for the Program.
Later license versions may give you additional or different
permissions. However, no additional obligations are imposed on any
author or copyright holder as a result of your choosing to follow a
later version.
15. Disclaimer of Warranty.
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. Limitation of Liability.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGES.
17. Interpretation of Sections 15 and 16.
If the disclaimer of warranty and limitation of liability provided
above cannot be given local legal effect according to their terms,
reviewing courts shall apply local law that most closely approximates
an absolute waiver of all civil liability in connection with the
Program, unless a warranty or assumption of liability accompanies a
copy of the Program in return for a fee.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
Also add information on how to contact you by electronic and paper mail.
If the program does terminal interaction, make it output a short
notice like this when it starts in an interactive mode:
<program> Copyright (C) <year> <name of author>
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, your program's commands
might be different; for a GUI interface, you would use an "about box".
You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU GPL, see
<https://www.gnu.org/licenses/>.
The GNU General Public License does not permit incorporating your program
into proprietary programs. If your program is a subroutine library, you
may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
<https://www.gnu.org/licenses/why-not-lgpl.html>.
================================================
FILE: README.md
================================================
<p align="center">
<img src="/images/banner.png" width="400" />
</p>
<h4 align="center">
SafeLine - Make your web apps secure
</h4>
<p align="center">
<a target="_blank" href="https://ly.safepoint.cloud/laA8asp">🏠 Website</a> |
<a target="_blank" href="https://ly.safepoint.cloud/w2AeHhb">📖 Docs</a> |
<a target="_blank" href="https://ly.safepoint.cloud/hSMd4SH">🔍 Live Demo</a> |
<a target="_blank" href="https://discord.gg/SVnZGzHFvn">🙋♂️ Discord</a> |
<a target="_blank" href="/README_CN.md">中文版</a>
</p>
## 👋 INTRODUCTION
SafeLine is a self-hosted **`WAF(Web Application Firewall)`** to protect your web apps from attacks and exploits.
A web application firewall helps protect web apps by filtering and monitoring HTTP traffic between a web application and the Internet. It typically protects web apps from attacks such as `SQL injection`, `XSS`, `code injection`, `os command injection`, `CRLF injection`, `ldap injection`, `xpath injection`, `RCE`, `XXE`, `SSRF`, `path traversal`, `backdoor`, `bruteforce`, `http-flood`, `bot abused`, among others.
#### 💡 How It Works
<img src="/images/how-it-works.png" width="800" />
By deploying a WAF in front of a web application, a shield is placed between the web application and the Internet. While a proxy server protects a client machine’s identity by using an intermediary, a WAF is a type of reverse-proxy, protecting the server from exposure by having clients pass through the WAF before reaching the server.
A WAF protects your web apps by filtering, monitoring, and blocking any malicious HTTP/S traffic traveling to the web application, and prevents any unauthorized data from leaving the app. It does this by adhering to a set of policies that help determine what traffic is malicious and what traffic is safe. Just as a proxy server acts as an intermediary to protect the identity of a client, a WAF operates in similar fashion but acting as a reverse proxy intermediary that protects the web app server from a potentially malicious client.
its core capabilities include:
- Defenses for web attacks
- Proactive bot abused defense
- HTML & JS code encryption
- IP-based rate limiting
- Web Access Control List
#### ⚡️ Screenshots
| <img src="./images/screenshot-1.png" width=370 /> | <img src="./images/screenshot-2.png" width=370 /> |
| ------------------------------------------------- | ------------------------------------------------- |
| <img src="./images/screenshot-3.png" width=370 /> | <img src="./images/screenshot-4.png" width=370 /> |
Get [Live Demo](https://demo.waf.chaitin.com:9443/)
## 🔥 FEATURES
List of the main features as follows:
- **`Block Web Attacks`**
- It defenses for all of web attacks, such as `SQL injection`, `XSS`, `code injection`, `os command injection`, `CRLF injection`, `XXE`, `SSRF`, `path traversal` and so on.
- **`Rate Limiting`**
- Defend your web apps against `DoS attacks`, `bruteforce attempts`, `traffic surges`, and other types of abuse by throttling traffic that exceeds defined limits.
- **`Anti-Bot Challenge`**
- Anti-Bot challenges to protect your website from `bot attacks`, humen users will be allowed, crawlers and bots will be blocked.
- **`Authentication Challenge`**
- When authentication challenge turned on, visitors need to enter the password, otherwise they will be blocked.
- **`Dynamic Protection`**
- When dynamic protection turned on, html and js codes in your web server will be dynamically encrypted by each time you visit.
#### 🧩 Showcases
| | Legitimate User | Malicious User |
| ----------------------------- | --------------------------------------------------- | ---------------------------------------------------------------- |
| **`Block Web Attacks`** | <img src="./images/skeleton.png" width=270 /> | <img src="./images/blocked-for-attack-detected.png" width=270 /> |
| **`Rate Limiting`** | <img src="./images/skeleton.png" width=270 /> | <img src="./images/blocked-for-access-too-fast.png" width=270 /> |
| **`Anti-Bot Challenge`** | <img src="./images/captcha-1.gif" width=270 /> | <img src="./images/captcha-2.gif" width=270 /> |
| **`Auth Challenge`** | <img src="./images/auth-1.gif" width=270 /> | <img src="./images/auth-2.gif" width=270 /> |
| **`HTML Dynamic Protection`** | <img src="./images/dynamic-html-1.png" width=270 /> | <img src="./images/dynamic-html-2.png" width=270 /> |
| **`JS Dynamic Protection`** | <img src="./images/dynamic-js-1.png" width=270 /> | <img src="./images/dynamic-js-2.png" width=270 /> |
## 🚀 Quickstart
> [!WARNING]
> 中国大陆用户安装国际版可能会导致无法连接云服务,请查看 [中文版安装文档](https://docs.waf-ce.chaitin.cn/zh/%E4%B8%8A%E6%89%8B%E6%8C%87%E5%8D%97/%E5%AE%89%E8%A3%85%E9%9B%B7%E6%B1%A0)
#### 📦 Installing
Information on how to install SafeLine can be found in the [Install Guide](https://docs.waf.chaitin.com/en/GetStarted/Deploy)
#### ⚙️ Protecting Web Apps
to see [Configuration](https://docs.waf.chaitin.com/en/GetStarted/AddApplication)
## 📋 More Informations
#### Effect Evaluation
| Metric | ModSecurity, Level 1 | CloudFlare, Free | SafeLine, Balance | SafeLine, Strict |
| ----------------- | -------------------- | -------------------- | ---------------------- | --------------------- |
| Total Samples | 33669 | 33669 | 33669 | 33669 |
| **Detection** | 69.74% | 10.70% | 71.65% | **76.17%** |
| **False Positive**| 17.58% | 0.07% | **0.07%** | 0.22% |
| **Accuracy** | 82.20% | 98.40% | **99.45%** | 99.38% |
#### Is SafeLine Production-Ready?
Yes, SafeLine is production-ready.
- Over 180,000 installations worldwide
- Protecting over 1,000,000 Websites
- Handling over 30,000,000,000 HTTP Requests Daily
#### 🙋♂️ Community
Join our [Discord](https://discord.gg/SVnZGzHFvn) to get community support, the core team members are identified by the STAFF role in Discord.
- channel [#feedback](https://discord.com/channels/1243085666485534830/1243120292822253598): for new features discussion.
- channel [#FAQ](https://discord.com/channels/1243085666485534830/1263761679619981413): for FAQ.
- channel [#general](https://discord.com/channels/1243085666485534830/1243115843919806486): for any other questions.
Several contact options exist for our community, the primary one being Discord. These are in addition to GitHub issues for creating a new issue.
<p align="left">
<a target="_blank" href="https://discord.gg/SVnZGzHFvn"><img src="https://img.shields.io/badge/Discord-5865F2?style=flat&logo=discord&logoColor=white"></a>
<a target="_blank" href="https://x.com/safeline_waf"><img src="https://img.shields.io/badge/X.com-000000?style=flat&logo=x&logoColor=white"></a>
<a target="_blank" href="/images/wechat.png"><img src="https://img.shields.io/badge/WeChat-07C160?style=flat&logo=wechat&logoColor=white"></a>
</p>
#### 💪 PRO Edition
Coming soon!
#### 📝 License
See [LICENSE](/LICENSE.md) for details.
================================================
FILE: README_CN.md
================================================
<p align="center">
<img src="/images/banner.png" width="400" />
</p>
<h4 align="center">
SafeLine - 雷池 - 不让黑客越过半步
</h4>
<p align="center">
<a target="_blank" href="https://waf-ce.chaitin.cn/">🏠 官网</a> |
<a target="_blank" href="https://docs.waf-ce.chaitin.cn/">📖 文档</a> |
<a target="_blank" href="https://demo.waf-ce.chaitin.cn:9443/">🔍 演示环境</a> |
<a target="_blank" href="/images/wechat.png">🙋♂️ 社区微信群</a> |
<a target="_blank" href="https://github.com/chaitin/SafeLine">国际版</a>
</p>
## 👋 项目介绍
SafeLine,中文名 "雷池",是一款简单好用, 效果突出的 **`Web 应用防火墙(WAF)`**,可以保护 Web 服务不受黑客攻击。
雷池通过过滤和监控 Web 应用与互联网之间的 HTTP 流量来保护 Web 服务。可以保护 Web 服务免受 `SQL 注入`、`XSS`、 `代码注入`、`命令注入`、`CRLF 注入`、`ldap 注入`、`xpath 注入`、`RCE`、`XXE`、`SSRF`、`路径遍历`、`后门`、`暴力破解`、`CC`、`爬虫` 等攻击。
#### 💡 工作原理
<img src="/images/how-it-works.png" width="800" />
雷池通过阻断流向 Web 服务的恶意 HTTP 流量来保护 Web 服务。雷池作为反向代理接入网络,通过在 Web 服务前部署雷池,可在 Web 服务和互联网之间设置一道屏障。
雷池的核心功能如下:
- 防护 Web 攻击
- 防爬虫, 防扫描
- 前端代码动态加密
- 基于源 IP 的访问速率限制
- HTTP 访问控制
#### ⚡️ 项目截图
| <img src="./images/screenshot-1.png" width=370 /> | <img src="./images/screenshot-2.png" width=370 /> |
| ------------------------------------------------- | ------------------------------------------------- |
| <img src="./images/screenshot-3.png" width=370 /> | <img src="./images/screenshot-4.png" width=370 /> |
查看 [演示环境](https://demo.waf-ce.chaitin.cn:9443/)
## 🔥 核心能力
对于你的网站而言, 雷池可以实现如下效果:
- **`阻断 Web 攻击`**
- 可以防御所有的 Web 攻击,例如 `SQL 注入`、`XSS`、`代码注入`、`操作系统命令注入`、`CRLF 注入`、`XXE`、`SSRF`、`路径遍历` 等等。
- **`限制访问频率`**
- 限制用户的访问速率,让 Web 服务免遭 `CC 攻击`、`暴力破解`、`流量激增` 和其他类型的滥用。
- **`人机验证`**
- 互联网上有来自真人用户的流量,但更多的是由爬虫, 漏洞扫描器, 蠕虫病毒, 漏洞利用程序等自动化程序发起的流量,开启雷池的人机验证功能后真人用户会被放行,恶意爬虫将会被阻断。
- **`身份认证`**
- 雷池的 "身份认证" 功能可以很好的解决 "未授权访问" 漏洞,当用户访问您的网站时,需要输入您配置的用户名和密码信息,不持有认证信息的用户将被拒之门外。
- **`动态防护`**
- 在用户浏览到的网页内容不变的情况下,将网页赋予动态特性,对 HTML 和 JavaScript 代码进行动态加密,确保每次访问时这些代码都以随机且独特的形态呈现。
#### 🧩 核心能力展示
| | Legitimate User | Malicious User |
| ----------------------------- | --------------------------------------------------- | ---------------------------------------------------------------- |
| **`阻断 Web 攻击`** | <img src="./images/skeleton.png" width=270 /> | <img src="./images/blocked-for-attack-detected.png" width=270 /> |
| **`限制访问频率`** | <img src="./images/skeleton.png" width=270 /> | <img src="./images/blocked-for-access-too-fast.png" width=270 /> |
| **`人机验证`** | <img src="./images/captcha-1.gif" width=270 /> | <img src="./images/captcha-2.gif" width=270 /> |
| **`身份认证`** | <img src="./images/auth-1.gif" width=270 /> | <img src="./images/auth-2.gif" width=270 /> |
| **`HTML 动态防护`** | <img src="./images/dynamic-html-1.png" width=270 /> | <img src="./images/dynamic-html-2.png" width=270 /> |
| **`JS 动态防护`** | <img src="./images/dynamic-js-1.png" width=270 /> | <img src="./images/dynamic-js-2.png" width=270 /> |
## 🚀 上手指南
#### 📦 安装
查看 [安装雷池](https://docs.waf-ce.chaitin.cn/zh/%E4%B8%8A%E6%89%8B%E6%8C%87%E5%8D%97/%E5%AE%89%E8%A3%85%E9%9B%B7%E6%B1%A0)
#### ⚙️ 配置防护站点
查看 [快速配置](https://docs.waf-ce.chaitin.cn/zh/%E4%B8%8A%E6%89%8B%E6%8C%87%E5%8D%97/%E5%BF%AB%E9%80%9F%E9%85%8D%E7%BD%AE)
## 📋 更多信息
#### 防护效果测试
| Metric | ModSecurity, Level 1 | CloudFlare | 雷池, 平衡 | 雷池, 严格 |
| ----------------- | -------------------- | -------------------- | ---------------------- | --------------------- |
| 样本数量 | 33669 | 33669 | 33669 | 33669 |
| **检出率** | 69.74% | 10.70% | 71.65% | **76.17%** |
| **误报率** | 17.58% | 0.07% | **0.07%** | 0.22% |
| **准确率** | 82.20% | 98.40% | **99.45%** | 99.38% |
#### 雷池可以投入生产使用吗
是的,已经有不少用户将雷池投入生产使用,截至目前
- 全球累计装机量已超过 18 万台
- 防护的网站数量超过 100 万个
- 每天清洗 HTTP 请求超过 300 亿次
#### 🙋♂️ 用户社区
欢迎加入雷池 [社区微信群](/images/wechat.png) 进行技术交流。
也可以加入雷池 [Discord](https://discord.gg/SVnZGzHFvn) 来获取更多社区支持。
<p align="left">
<a target="_blank" href="/images/wechat.png"><img src="https://img.shields.io/badge/WeChat-07C160?style=flat&logo=wechat&logoColor=white"></a>
<a target="_blank" href="https://discord.gg/SVnZGzHFvn"><img src="https://img.shields.io/badge/Discord-5865F2?style=flat&logo=discord&logoColor=white"></a>
<a target="_blank" href="https://x.com/safeline_waf"><img src="https://img.shields.io/badge/X.com-000000?style=flat&logo=x&logoColor=white"></a>
</p>
#### 💪 专业版
查看 [社区版 vs 专业版](https://waf-ce.chaitin.cn/version)
================================================
FILE: compose.yaml
================================================
networks:
safeline-ce:
name: safeline-ce
driver: bridge
ipam:
driver: default
config:
- gateway: ${SUBNET_PREFIX:?SUBNET_PREFIX required}.1
subnet: ${SUBNET_PREFIX}.0/24
driver_opts:
com.docker.network.bridge.name: safeline-ce
services:
postgres:
container_name: safeline-pg
restart: always
image: ${IMAGE_PREFIX}/safeline-postgres${ARCH_SUFFIX}:15.2
volumes:
- ${SAFELINE_DIR}/resources/postgres/data:/var/lib/postgresql/data
- /etc/localtime:/etc/localtime:ro
environment:
- POSTGRES_USER=safeline-ce
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD:?postgres password required}
networks:
safeline-ce:
ipv4_address: ${SUBNET_PREFIX}.2
command: [postgres, -c, max_connections=600]
healthcheck:
test: pg_isready -U safeline-ce -d safeline-ce
mgt:
container_name: safeline-mgt
restart: always
image: ${IMAGE_PREFIX}/safeline-mgt${REGION}${ARCH_SUFFIX}${RELEASE}:${IMAGE_TAG:?image tag required}
volumes:
- /etc/localtime:/etc/localtime:ro
- ${SAFELINE_DIR}/resources/mgt:/app/data
- ${SAFELINE_DIR}/logs/nginx:/app/log/nginx:z
- ${SAFELINE_DIR}/resources/sock:/app/sock
- /var/run:/app/run
ports:
- ${MGT_PORT:-9443}:1443
healthcheck:
test: curl -k -f https://localhost:1443/api/open/health
environment:
- MGT_PG=postgres://safeline-ce:${POSTGRES_PASSWORD}@safeline-pg/safeline-ce?sslmode=disable
depends_on:
- postgres
- fvm
logging:
driver: "json-file"
options:
max-size: "100m"
max-file: "5"
networks:
safeline-ce:
ipv4_address: ${SUBNET_PREFIX}.4
detect:
container_name: safeline-detector
restart: always
image: ${IMAGE_PREFIX}/safeline-detector${REGION}${ARCH_SUFFIX}${RELEASE}:${IMAGE_TAG}
volumes:
- ${SAFELINE_DIR}/resources/detector:/resources/detector
- ${SAFELINE_DIR}/logs/detector:/logs/detector
- /etc/localtime:/etc/localtime:ro
environment:
- LOG_DIR=/logs/detector
networks:
safeline-ce:
ipv4_address: ${SUBNET_PREFIX}.5
tengine:
container_name: safeline-tengine
restart: always
image: ${IMAGE_PREFIX}/safeline-tengine${REGION}${ARCH_SUFFIX}${RELEASE}:${IMAGE_TAG}
volumes:
- /etc/localtime:/etc/localtime:ro
- /etc/resolv.conf:/etc/resolv.conf:ro
- ${SAFELINE_DIR}/resources/nginx:/etc/nginx
- ${SAFELINE_DIR}/resources/detector:/resources/detector
- ${SAFELINE_DIR}/resources/chaos:/resources/chaos
- ${SAFELINE_DIR}/logs/nginx:/var/log/nginx:z
- ${SAFELINE_DIR}/resources/cache:/usr/local/nginx/cache
- ${SAFELINE_DIR}/resources/sock:/app/sock
environment:
- TCD_MGT_API=https://${SUBNET_PREFIX}.4:1443/api/open/publish/server
- TCD_SNSERVER=${SUBNET_PREFIX}.5:8000
# deprecated
- SNSERVER_ADDR=${SUBNET_PREFIX}.5:8000
- CHAOS_ADDR=${SUBNET_PREFIX}.10
ulimits:
nofile: 131072
network_mode: host
luigi:
container_name: safeline-luigi
restart: always
image: ${IMAGE_PREFIX}/safeline-luigi${REGION}${ARCH_SUFFIX}${RELEASE}:${IMAGE_TAG}
environment:
- MGT_IP=${SUBNET_PREFIX}.4
- LUIGI_PG=postgres://safeline-ce:${POSTGRES_PASSWORD}@safeline-pg/safeline-ce?sslmode=disable
volumes:
- /etc/localtime:/etc/localtime:ro
- ${SAFELINE_DIR}/resources/luigi:/app/data
logging:
driver: "json-file"
options:
max-size: "100m"
max-file: "5"
depends_on:
- detect
- mgt
networks:
safeline-ce:
ipv4_address: ${SUBNET_PREFIX}.7
fvm:
container_name: safeline-fvm
restart: always
image: ${IMAGE_PREFIX}/safeline-fvm${REGION}${ARCH_SUFFIX}${RELEASE}:${IMAGE_TAG}
volumes:
- /etc/localtime:/etc/localtime:ro
logging:
driver: "json-file"
options:
max-size: "100m"
max-file: "5"
networks:
safeline-ce:
ipv4_address: ${SUBNET_PREFIX}.8
chaos:
container_name: safeline-chaos
restart: always
image: ${IMAGE_PREFIX}/safeline-chaos${REGION}${ARCH_SUFFIX}${RELEASE}:${IMAGE_TAG}
logging:
driver: "json-file"
options:
max-size: "100m"
max-file: "10"
environment:
- DB_ADDR=postgres://safeline-ce:${POSTGRES_PASSWORD}@safeline-pg/safeline-ce?sslmode=disable
volumes:
- ${SAFELINE_DIR}/resources/sock:/app/sock
- ${SAFELINE_DIR}/resources/chaos:/app/chaos
networks:
safeline-ce:
ipv4_address: ${SUBNET_PREFIX}.10
================================================
FILE: management/.gitignore
================================================
# Test binary, build with `go test -c`
*.test
# Output of the go coverage tool, specifically when used with LiteIDE
*.out
**/.idea
*.iml
#OSX system files.
**/.DS_Store
/build
*.pb.go
submodule/
================================================
FILE: management/.golangci.yml
================================================
linters:
disable-all: true
enable:
- deadcode
- errcheck
- gofmt
- goimports
- gosimple
- govet
- ineffassign
- staticcheck
- structcheck
- typecheck
- unused
- varcheck
================================================
FILE: management/Makefile
================================================
GO = GO111MODULE=on go
#GO = GO111MODULE=on GOOS=linux GOARCH=amd64 go
GOBUILD = $(GO) build -mod=readonly
GOTEST = $(GO) test -v -p 1 -coverprofile=coverage-management.out
STAMP = $(shell date +%s)
GITHASH = $(shell git rev-parse --short=8 HEAD)
GITTAG = $(shell git describe --tags --abbrev=0)
BUILDFLAGS := -ldflags "-X main.buildstamp=$(STAMP) -X main.githash=$(GITHASH) -X main.version=$(GITTAG)"
pkgs = ./...
all: build-all
.PHONY: build-all
build-all: proto build-webserver build-tcd
.PHONY: build-webserver
build-webserver:
cd webserver && $(GOBUILD) $(BUILDFLAGS) -o ../build/webserver main.go
.PHONY: build-tcd
build-tcd:
cd tcontrollerd && CGO_ENABLED=0 $(GOBUILD) $(BUILDFLAGS) -o ../build/tcontrollerd main.go
.PHONY: test
test:
$(GOTEST) -failfast $(pkgs)
.PHONY: proto
proto:
@./scripts/genproto.sh
.PHONY: lint
lint:
# 'go list' needs to be executed before staticcheck to prepopulate the modules cache.
# Otherwise staticcheck might fail randomly for some reason not yet explained.
$(GO) list -e -compiled -test=true -export=false -deps=true -find=false -tags= -- ./... > /dev/null
goimports -local chaitin.cn -w $$(find . -type f -name '*.go' -not -path "./vendor/*")
golangci-lint version
cd webserver && golangci-lint run -v --skip-dirs vendor --deadline 10m
.PHONY: clean
clean:
rm -rf build
================================================
FILE: management/README.md
================================================
# Management Micro Service
## Requirements
Go 1.18+
================================================
FILE: management/scripts/genproto.sh
================================================
#!/usr/bin/env bash
#
# Generate all protobuf bindings.
# Run from repository root.
set -u
if ! [[ "$0" =~ scripts/genproto.sh ]]; then
echo "must be run from repository root"
exit 255
fi
DIRS="webserver/proto tcontrollerd/proto"
echo "generating code"
protoc --version
for dir in ${DIRS}; do
pushd "${dir}" || return
find . -type d -print0 | while IFS= read -r -d '' sdir ; do
pushd "${sdir}" || return
# shellcheck disable=SC2010
FS=$(ls | grep "\.proto\$")
if [ -n "${FS}" ] ; then
protoc --go_out=. --go_opt=paths=source_relative \
--go-grpc_out=. --go-grpc_opt=paths=source_relative \
"${FS}"
goimports -local chaitin.cn -w ./*.pb.go
fi
popd || return
done
popd || return
done
================================================
FILE: management/tcontrollerd/README.md
================================================
# TControllerD
Tengine Controller Daemon (abbr. TCD) will be running in the Tengine container,
designed to be in place with minion on the host machine.
## Requirements
Go 1.18+
## Development
### init protobuf
```shell
# Refer: https://grpc.io/docs/languages/go/quickstart/
# 1. Install protoc
# https://grpc.io/docs/protoc-installation/
# 2. Install Go plugins
go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.30.0
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@v1.3.0
# 3. Update your PATH so that the protoc compiler can find the plugins
# export PATH="$PATH:$(go env GOPATH)/bin"
# 4. Generate proto go code
# cd /path/to/management
./scripts/genproto.sh
```
================================================
FILE: management/tcontrollerd/config.yml
================================================
# develop use only. For production, refer to `package/build/tengine/tcontrollerd/config.yml`
log:
output: stdout # "stdout", "stderr" or file path
level: debug # "debug", "info", "warn" or "error"
mgt_addr: 169.254.0.4:9002 # gRPC addr of mgt-api webserver
================================================
FILE: management/tcontrollerd/controller/controller.go
================================================
package controller
import (
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
"chaitin.cn/patronus/safeline-2/management/tcontrollerd/pkg/config"
"chaitin.cn/patronus/safeline-2/management/tcontrollerd/pkg/log"
pb "chaitin.cn/patronus/safeline-2/management/tcontrollerd/proto/website"
)
var (
logger = log.GetLogger("controller")
)
func Handle() error {
logger.Infof("Connect mgt-webserver at %s", config.GlobalConfig.MgtWebserver)
gRPCConn, err := grpc.Dial(config.GlobalConfig.MgtWebserver, []grpc.DialOption{
grpc.WithTransportCredentials(insecure.NewCredentials()),
}...)
if err != nil {
logger.Errorf("Fail to dial: %v", err)
return err
}
wsClient := pb.NewWebsiteClient(gRPCConn)
defer func(conn *grpc.ClientConn) {
err := conn.Close()
if err != nil {
logger.Errorf("Fail to close: %v", err)
return
}
}(gRPCConn)
if err = websiteHandler(wsClient); err != nil {
return err
}
return nil
}
================================================
FILE: management/tcontrollerd/controller/template.go
================================================
package controller
var nginxConfigTpl = `
upstream %s {
%s
keepalive 128;
keepalive_timeout 75;
}
server {
%s
%s
%s
%s
location = /forbidden_page {
internal;
root /etc/nginx/forbidden_pages;
try_files /default_forbidden_page.html =403;
}
location ^~ / {
proxy_pass %s://%s;
include proxy_params;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Accept-Encoding "";
t1k_append_header SL-CE-SUID %d;
t1k_body_size 1024k;
tx_body_size 4k;
t1k_error_page 403 /forbidden_page;
tx_error_page 403 /forbidden_page;
}
}`
var upstreamAddrTpl = `server %s;`
var serverListenTpl = `listen 0.0.0.0:%s%s%s;`
var addrAnyPropertiesTpl = " default_server backlog=65536 reuseport"
var serverNameTpl = `server_name %s;`
var certTpl = `ssl_certificate /etc/nginx/certs/%s;`
var certKeyTpl = `ssl_certificate_key /etc/nginx/certs/%s;`
var backendTpl = `backend_%d`
================================================
FILE: management/tcontrollerd/controller/website.go
================================================
package controller
import (
"context"
"encoding/json"
"fmt"
"io"
"io/fs"
"io/ioutil"
"net/url"
"os"
"path/filepath"
"strings"
"chaitin.cn/patronus/safeline-2/management/tcontrollerd/model"
"chaitin.cn/patronus/safeline-2/management/tcontrollerd/pkg/ngcmd"
pb "chaitin.cn/patronus/safeline-2/management/tcontrollerd/proto/website"
"chaitin.cn/patronus/safeline-2/management/tcontrollerd/utils"
)
const (
Ping = "ping"
Pong = "pong"
EventTypeWebsite = "website"
EventTypeDeleteWebsite = "deleteWebsite"
EventTypeFullWebsite = "fullWebsite"
nginxConfigPath = "/etc/nginx/sites-enabled/" // 修改的为 host /resources/nginx/ 中的文件
nginxFilePrefix = "IF_backend_"
nginxBackupFilePrefix = "BAK_IF_backend_"
nginxFileMode = 0644
HttpsScheme = "https"
DefaultHttpsPort = "443"
)
var pong = pb.Response{Type: Pong, Msg: nil, Err: false}
func generateNginxConfig(website *model.WebsiteConfig) (string, error) {
// only ONE upstream supported in v1.0
var upstreamAddr string
scheme := "http"
for _, upstream := range website.Upstreams {
urlInfo, err := url.Parse(upstream)
if err != nil {
return "", err
}
if urlInfo.Scheme == HttpsScheme && urlInfo.Port() == "" {
urlInfo.Host = urlInfo.Host + ":" + DefaultHttpsPort
}
upstreamAddr = fmt.Sprintf(upstreamAddrTpl, urlInfo.Host)
if len(urlInfo.Scheme) > 0 {
scheme = urlInfo.Scheme
}
}
sslFlag := ""
sslCertFilename := ""
sslCertKeyFilename := ""
if website.KeyFilename != "" && website.CertFilename != "" {
sslFlag = " ssl" // with a blank ahead
sslCertFilename = fmt.Sprintf(certTpl, website.CertFilename)
sslCertKeyFilename = fmt.Sprintf(certKeyTpl, website.KeyFilename)
}
// only ONE server name supported in v1.0
var serverName string
var addrAnyProperties string
for _, sn := range website.ServerNames {
if sn == "*" || sn == "" {
sn = "_"
addrAnyProperties = addrAnyPropertiesTpl
}
serverName = fmt.Sprintf(serverNameTpl, sn)
}
// only ONE port supported in v1.0
var serverListen string
for _, port := range website.Ports {
serverListen = fmt.Sprintf(serverListenTpl, port, sslFlag, addrAnyProperties)
}
upstreamName := fmt.Sprintf(backendTpl, website.Id)
nginxConfig := strings.TrimSpace(fmt.Sprintf(nginxConfigTpl, upstreamName, upstreamAddr, serverListen, serverName, sslCertFilename, sslCertKeyFilename, scheme, upstreamName, website.Id))
return nginxConfig, nil
}
func nginxTestAndReload() error {
err := ngcmd.NginxConfTest()
if err != nil {
return err
}
err = ngcmd.NginxConfReload()
if err != nil {
return err
}
return nil
}
func generateFullConfigAndReload(msg []byte) error {
var websites []model.WebsiteConfig
if err := json.Unmarshal(msg, &websites); err != nil {
return err
}
configFilename := make(map[string]struct{})
for _, website := range websites {
configFilename[fmt.Sprintf("%s%d", nginxFilePrefix, website.Id)] = struct{}{}
}
filepath.Walk(nginxConfigPath, func(path string, info fs.FileInfo, err error) error {
_, ok := configFilename[info.Name()]
if !ok && strings.HasPrefix(info.Name(), nginxFilePrefix) {
if err := os.Remove(path); err != nil {
// not return error only logged error in order to delete not exist website nginx conf
logger.Warn(err)
}
}
return nil
})
for _, website := range websites {
if err := generateConfigAndReload(&website); err != nil {
// trigger a full site push when tcd starts, ignore some site errors, and push as much as possible
logger.Warn(err)
}
}
return nil
}
func generateConfigAndReload(website *model.WebsiteConfig) error {
nginxConfig, err := generateNginxConfig(website)
if err != nil {
return err
}
configPath := filepath.Join(nginxConfigPath, fmt.Sprintf("%s%d", nginxFilePrefix, website.Id))
backupPath := filepath.Join(nginxConfigPath, fmt.Sprintf("%s%d", nginxBackupFilePrefix, website.Id))
oldConfigExists, err := utils.FileExist(configPath)
if err != nil {
return err
}
if oldConfigExists {
oldConfig, err := ioutil.ReadFile(configPath)
if err != nil {
return err
}
if string(oldConfig) == nginxConfig {
logger.Info("No changes in the new website config, skip nginx -s reload")
return nil
}
// tmp save old config to the backup path
if err = utils.CopyFile(configPath, backupPath); err != nil {
return err
}
}
if err = utils.EnsureWriteFile(configPath, []byte(nginxConfig), nginxFileMode); err != nil {
return err
}
if err = nginxTestAndReload(); err != nil {
nginxError := err
if err = os.Remove(configPath); err != nil {
return err
}
if oldConfigExists {
// new config err, restore old config
if err = utils.CopyFile(backupPath, configPath); err != nil {
return err
}
if err = os.Remove(backupPath); err != nil {
return err
}
}
return nginxError
}
if oldConfigExists {
if err = os.Remove(backupPath); err != nil {
return err
}
}
return nil
}
func deleteConfigAndReload(config []byte) error {
var websiteIds []uint
if err := json.Unmarshal(config, &websiteIds); err != nil {
return err
}
for _, id := range websiteIds {
configPath := filepath.Join(nginxConfigPath, fmt.Sprintf("%s%d", nginxFilePrefix, id))
exists, err := utils.FileExist(configPath)
if err != nil {
return err
}
if exists {
if err := os.Remove(configPath); err != nil {
return err
}
}
}
if err := nginxTestAndReload(); err != nil {
return err
}
return nil
}
func sendResponse(stream pb.Website_SubscribeClient, eventType string, errMsg []byte) error {
return stream.Send(&pb.Response{
Type: eventType,
Msg: errMsg,
Err: len(errMsg) != 0,
})
}
func websiteHandler(wc pb.WebsiteClient) error {
stream, err := wc.Subscribe(context.Background())
if err != nil {
logger.Errorf("Subscribe failed: %v", err)
return err
}
for {
event, err := stream.Recv()
if err != nil {
if err == io.EOF {
// read done.
logger.Infof("Recv EOF from webserver")
return nil
} else {
logger.Errorf("Handle failed: %v", err)
return err
}
}
logger.Debugf("Got message Type %s, Msg: %s", event.GetType(), event.GetMsg())
if event.Type == Ping {
if err = stream.Send(&pong); err != nil {
return err
}
} else if event.Type == EventTypeWebsite {
logger.Infof("Update website with config: %s", event.GetMsg())
var website model.WebsiteConfig
if err := json.Unmarshal(event.GetMsg(), &website); err != nil {
return err
}
if err = generateConfigAndReload(&website); err != nil {
logger.Error(err)
if err := sendResponse(stream, EventTypeDeleteWebsite, []byte(err.Error())); err != nil {
return err
}
} else {
if err = sendResponse(stream, EventTypeDeleteWebsite, nil); err != nil {
return err
}
}
} else if event.Type == EventTypeFullWebsite {
if err = generateFullConfigAndReload(event.Msg); err != nil {
logger.Error(err)
sendErr := sendResponse(stream, EventTypeFullWebsite, []byte(err.Error()))
if sendErr != nil {
return sendErr
}
} else {
if err = sendResponse(stream, EventTypeFullWebsite, nil); err != nil {
return err
}
}
} else if event.Type == EventTypeDeleteWebsite {
if err = deleteConfigAndReload(event.Msg); err != nil {
logger.Error(err)
sendErr := sendResponse(stream, EventTypeDeleteWebsite, []byte(err.Error()))
if sendErr != nil {
return sendErr
}
} else {
if err = sendResponse(stream, EventTypeDeleteWebsite, nil); err != nil {
return err
}
}
}
}
}
================================================
FILE: management/tcontrollerd/go.mod
================================================
module chaitin.cn/patronus/safeline-2/management/tcontrollerd
go 1.21
toolchain go1.21.3
require (
chaitin.cn/dev/go/errors v0.0.0-20210324055134-dc5247602af6
chaitin.cn/dev/go/log v0.0.0-20221220104336-05125760b10c
chaitin.cn/dev/go/settings v0.0.0-20221220104336-05125760b10c
github.com/robfig/cron/v3 v3.0.1
github.com/sirupsen/logrus v1.9.3
google.golang.org/grpc v1.65.0
)
require (
golang.org/x/net v0.33.0 // indirect
golang.org/x/sys v0.20.0 // indirect
golang.org/x/text v0.15.0 // indirect
)
================================================
FILE: management/tcontrollerd/go.sum
================================================
chaitin.cn/dev/go/errors v0.0.0-20200717101723-df6132d53dc8/go.mod h1:u+ZD0shdyUt0UG9XfCgD1R5mSqXpTVoO5rwQXQeo3Eo=
chaitin.cn/dev/go/errors v0.0.0-20210324055134-dc5247602af6 h1:1Qa9ABk907/9ZrOLbbRcS8Fqq9VhjAF/mLjbSP1qAJY=
chaitin.cn/dev/go/errors v0.0.0-20210324055134-dc5247602af6/go.mod h1:u+ZD0shdyUt0UG9XfCgD1R5mSqXpTVoO5rwQXQeo3Eo=
chaitin.cn/dev/go/log v0.0.0-20221220104336-05125760b10c h1:Xn9IYkxmnpDcEpV+7JIR5ufEIexd1dhqKwpOLG1mYOE=
chaitin.cn/dev/go/log v0.0.0-20221220104336-05125760b10c/go.mod h1:xJIYwUoA2TX5mNg/RBrEPyE251BPwj+70/mM7UIhoxg=
chaitin.cn/dev/go/settings v0.0.0-20221220104336-05125760b10c h1:tXsraF7o9iUsQY6IwpDJusc6OFhB7iv/bBTfgR3MPUU=
chaitin.cn/dev/go/settings v0.0.0-20221220104336-05125760b10c/go.mod h1:fUvtmpG8Z8Zf5aciadL9a/vn5SB3knG7pdNJixDplPg=
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
github.com/envoyproxy/go-control-plane v0.9.9-0.20210217033140-668b12f5399d/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk=
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8=
github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA=
github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs=
github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w=
github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0=
github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8=
github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw=
github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps=
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/konsorten/go-windows-terminal-sequences v1.0.1 h1:mweAR1A6xJ3oS2pRaGiHgQ4OO8tzTaLawm8vnODuwDk=
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
github.com/robfig/cron/v3 v3.0.1 h1:WdRxkvbJztn8LMz/QEvLN5sBU+xKpSqwwUO1Pjr4qDs=
github.com/robfig/cron/v3 v3.0.1/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzGIFLtro=
github.com/sirupsen/logrus v1.4.2 h1:SPIRibHv4MatM3XXNO2BJeFLZwZ2LvZgfQ5+UNI2im4=
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H4=
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.8.0 h1:Zrh2ngAOFYneWTAIAPethzeaQLuHwhuBkuV6ZiRnUaQ=
golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc=
golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.8.0 h1:57P1ETyNKtuIjB4SRd15iJxuhj8Gc416Y78H3qgMh68=
golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY=
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc=
google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013 h1:+kGHl1aib/qcwaRi1CbqBZ1rk19r85MNUf8HaBghugY=
google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo=
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg=
google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY=
google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk=
google.golang.org/grpc v1.39.0-dev h1:K4VkkiYp4LCvQiW6OiGglzm5nO4Zyryf7pHhzP15cmI=
google.golang.org/grpc v1.39.0-dev/go.mod h1:NREThFqKR1f3iQ6oBuvc5LadQuXVGo9rkm5ZGrQdJfM=
google.golang.org/grpc v1.65.0/go.mod h1:WgYC2ypjlB0EiQi6wdKixMqukr6lBc0Vo+oOgjrM5ZQ=
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=
google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE=
google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo=
google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.28.1 h1:d0NfwRgPtno5B1Wa6L2DAG+KivqkdutMf1UhdNx175w=
google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
google.golang.org/protobuf v1.34.1/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.7 h1:VUgggvou5XRW9mHwD/yXxIYSMtY0zoKQf/v226p2nyo=
gopkg.in/yaml.v2 v2.2.7/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
================================================
FILE: management/tcontrollerd/main.go
================================================
package main
import (
"context"
"flag"
"fmt"
"os"
"os/signal"
"strconv"
"syscall"
"time"
"chaitin.cn/patronus/safeline-2/management/tcontrollerd/controller"
"chaitin.cn/patronus/safeline-2/management/tcontrollerd/pkg/cron"
"chaitin.cn/patronus/safeline-2/management/tcontrollerd/pkg/ngcmd"
"chaitin.cn/patronus/safeline-2/management/tcontrollerd/pkg/config"
"chaitin.cn/patronus/safeline-2/management/tcontrollerd/pkg/constants"
"chaitin.cn/patronus/safeline-2/management/tcontrollerd/pkg/log"
)
var (
logger = log.GetLogger("main")
version = "undefined"
githash = "undefined"
buildstamp = "undefined"
goVersion = "undefined"
)
func init() {
// do something that do not raise error
}
func handleLoop(ctx context.Context) {
for {
select {
case <-ctx.Done():
os.Exit(0)
default:
if err := controller.Handle(); err != nil {
logger.Error("Error occurred when handling controller: ", err)
}
time.Sleep(time.Second * 5)
}
}
}
func main() {
log.SetLogFormatter()
fs := flag.NewFlagSet("tcontrollerd", flag.ExitOnError)
showVersion := fs.Bool("v", false, "show version")
nginxTest := fs.Bool("t", false, "nginx -t")
nginxReload := fs.Bool("r", false, "nginx -s reload")
cfgFile := fs.String("c", constants.ConfigFilePath, "config file path")
if err := fs.Parse(os.Args[1:]); err != nil {
logger.Fatalln("Failed to parse args: ", err)
}
if *showVersion {
i, _ := strconv.Atoi(buildstamp)
t := time.Unix(int64(i), 0).Format("2006-01-02 15:04:05")
fmt.Println("Version: ", version)
fmt.Println("Githash: ", githash)
fmt.Println("Build: ", t)
fmt.Println("Go version: ", goVersion)
return
}
// init configs
if err := config.InitConfigs(*cfgFile); err != nil {
logger.Fatalln("Failed to init configs: ", err)
}
if err := log.InitLogger(); err != nil {
logger.Fatalln("Failed to init db: ", err)
}
if *nginxTest {
if err := ngcmd.NginxConfTest(); err != nil {
logger.Fatalln("Failed to test nginx conf: ", err)
}
return
}
if *nginxReload {
if err := ngcmd.NginxConfReload(); err != nil {
logger.Fatalln("Failed to reload nginx conf: ", err)
}
return
}
if err := cron.StartCron(); err != nil {
logger.Fatalln("Failed to start cron: ", err)
}
ctx, cancel := context.WithCancel(context.Background())
sig := make(chan os.Signal, 1)
signal.Notify(sig, syscall.SIGINT, syscall.SIGTERM)
go func() {
<-sig
cancel()
}()
handleLoop(ctx)
}
================================================
FILE: management/tcontrollerd/model/website.go
================================================
package model
// WebsiteConfig is supposed to be same with webserver/model/website.go
type WebsiteConfig struct {
Id int `json:"id"`
ServerNames []string `json:"server_names"`
Ports []string `json:"ports"`
Upstreams []string `json:"upstreams"`
CertFilename string `json:"cert_filename"`
KeyFilename string `json:"key_filename"`
}
================================================
FILE: management/tcontrollerd/pkg/config/config.go
================================================
package config
import (
"os"
"chaitin.cn/dev/go/settings"
)
var (
GlobalConfig = DefaultGlobalConfig()
)
func InitConfigs(configFilePath string) error {
s, err := settings.New(configFilePath)
if err != nil {
return err
}
if err = GlobalConfig.Log.Load(s); err != nil {
return err
}
if err := s.Unmarshal("mgt_addr", &GlobalConfig.MgtWebserver); err != nil {
return err
}
if v, ok := os.LookupEnv("MGT_ADDR"); ok {
GlobalConfig.MgtWebserver = v
}
return nil
}
================================================
FILE: management/tcontrollerd/pkg/config/global.go
================================================
package config
type Config struct {
Log LogConfig
MgtWebserver string
}
func DefaultGlobalConfig() Config {
return Config{
Log: DefaultLogConfig(),
MgtWebserver: "169.254.0.4:9002",
}
}
================================================
FILE: management/tcontrollerd/pkg/config/log.go
================================================
package config
import (
"chaitin.cn/dev/go/settings"
)
type LogConfig struct {
Output string `yaml:"output"`
Level string `yaml:"level"`
}
func DefaultLogConfig() LogConfig {
return LogConfig{
Output: "stdout",
Level: "info",
}
}
func (lc *LogConfig) Load(setting *settings.Setting) error {
if err := setting.Unmarshal("log", lc); err != nil {
return err
}
return nil
}
================================================
FILE: management/tcontrollerd/pkg/constants/constants.go
================================================
package constants
const (
ConfigFilePath = "config.yml"
)
================================================
FILE: management/tcontrollerd/pkg/constants/forbidden_page.go
================================================
package constants
const (
DefaultForbiddenPageMd5 = "d9921f84f36a6cc92a6fc13946a18e98"
DefaultForbiddenPage = ``
)
================================================
FILE: management/tcontrollerd/pkg/cron/cron.go
================================================
package cron
import (
"github.com/robfig/cron/v3"
"chaitin.cn/patronus/safeline-2/management/tcontrollerd/pkg/log"
)
var logger = log.GetLogger("cron")
func newCronWithSeconds() *cron.Cron {
secondParser := cron.NewParser(cron.Second | cron.Minute | cron.Hour |
cron.Dom | cron.Month | cron.DowOptional | cron.Descriptor)
return cron.New(cron.WithParser(secondParser), cron.WithChain())
}
func StartCron() error {
cronInstance := newCronWithSeconds()
_, err := cronInstance.AddFunc(specCheckForbiddenPage, checkAndUpdateForbiddenPage)
if err != nil {
return err
}
cronInstance.Start()
return nil
}
================================================
FILE: management/tcontrollerd/pkg/cron/forbidden_page.go
================================================
package cron
import (
"crypto/md5"
"encoding/hex"
"io/ioutil"
"chaitin.cn/patronus/safeline-2/management/tcontrollerd/pkg/constants"
"chaitin.cn/patronus/safeline-2/management/tcontrollerd/utils"
)
const (
// SpecUpdatePolicy http://www.quartz-scheduler.org/documentation/quartz-2.3.0/tutorials/tutorial-lesson-06.html
// Seconds Minutes Hours Day-of-Month Month Day-of-Week Year (optional field)
// every 30 second (starting from 0s)
specCheckForbiddenPage = "0/30 * * * * ?"
forbiddenPagePath = "/etc/nginx/forbidden_pages/default_forbidden_page.html"
)
func checkAndUpdateForbiddenPage() {
existed, err := utils.FileExist(forbiddenPagePath)
if err != nil {
logger.Error(err)
return
}
if !existed {
err = utils.EnsureWriteFile(forbiddenPagePath, []byte(constants.DefaultForbiddenPage), 0644)
if err != nil {
logger.Error(err)
}
return
}
content, err := ioutil.ReadFile(forbiddenPagePath)
if err != nil {
logger.Error(err)
return
}
hash := md5.New()
hash.Write([]byte(content))
forbiddenMd5 := hex.EncodeToString(hash.Sum(nil))
if forbiddenMd5 == constants.DefaultForbiddenPageMd5 {
return
}
err = ioutil.WriteFile(forbiddenPagePath, []byte(constants.DefaultForbiddenPage), 0644)
if err != nil {
logger.Error(err)
return
}
}
================================================
FILE: management/tcontrollerd/pkg/log/log.go
================================================
package log
import (
"fmt"
"os"
"runtime"
"strings"
"github.com/sirupsen/logrus"
"chaitin.cn/dev/go/log"
"chaitin.cn/patronus/safeline-2/management/tcontrollerd/pkg/config"
"chaitin.cn/patronus/safeline-2/management/tcontrollerd/utils"
)
func GetLogger(name string) *log.Logger {
return log.GetLogger(name)
}
func LoadLogLevel() {
lv, _ := log.ParseLevel(config.GlobalConfig.Log.Level)
log.SetLevel(log.AllLoggers, lv)
}
func SetLogFormatter() {
// format
formatter := new(log.TextFormatter)
formatter.FullTimestamp = true
formatter.TimestampFormat = "2006/01/02 15:04:05"
log.SetFormatter(log.AllLoggers, formatter)
}
func InitLogger() error {
// output
switch config.GlobalConfig.Log.Output {
case "stdout":
log.SetOutput(log.AllLoggers, os.Stdout)
case "stderr":
log.SetOutput(log.AllLoggers, os.Stderr)
default:
exist, err := utils.FileExist(config.GlobalConfig.Log.Output)
if err != nil {
return err
}
fileFlag := os.O_WRONLY | os.O_APPEND | os.O_SYNC
if !exist {
if err := utils.EnsureFileDir(config.GlobalConfig.Log.Output); err != nil {
return err
}
fileFlag = fileFlag | os.O_CREATE
}
if fp, err := os.OpenFile(config.GlobalConfig.Log.Output, fileFlag, os.ModePerm); err != nil {
return fmt.Errorf("failed to open log file: %s", err.Error())
} else {
log.SetOutput(log.AllLoggers, log.NewLockOutput(fp))
}
}
// hook
log.AddHook(log.AllLoggers, NewRuntimeHook())
log.AddHook(log.AllLoggers, log.NewErrorStackHook(true))
// level
LoadLogLevel()
return nil
}
type RuntimeHook struct{}
func (h *RuntimeHook) Levels() []logrus.Level {
return logrus.AllLevels
}
func (h *RuntimeHook) Fire(entry *logrus.Entry) error {
file := "???"
funcName := "???"
line := 0
pc := make([]uintptr, 64)
// Skip runtime.Callers, self, and another call from logrus
n := runtime.Callers(3, pc)
if n != 0 {
pc = pc[:n] // pass only valid pcs to runtime.CallersFrames
frames := runtime.CallersFrames(pc)
// Loop to get frames.
// A fixed number of pcs can expand to an indefinite number of Frames.
for {
frame, more := frames.Next()
if !strings.Contains(frame.File, "github.com/sirupsen/logrus") && !strings.Contains(frame.Function, "chaitin.cn/dev/go") {
file = frame.File
funcName = frame.Function
line = frame.Line
break
}
if !more {
break
}
}
}
slices := strings.Split(file, "/")
file = slices[len(slices)-1]
funcName = strings.ReplaceAll(funcName, "chaitin.cn", "")
entry.Data["file"] = file
entry.Data["func"] = funcName
entry.Data["line"] = line
return nil
}
func NewRuntimeHook() *RuntimeHook {
return &RuntimeHook{}
}
================================================
FILE: management/tcontrollerd/pkg/ngcmd/ngcmd.go
================================================
package ngcmd
import (
"fmt"
"os/exec"
"strings"
"chaitin.cn/dev/go/errors"
"chaitin.cn/patronus/safeline-2/management/tcontrollerd/pkg/log"
)
var logger = log.GetLogger("ngcmd")
// NginxConfTest exec nginx -t and return stderr
func NginxConfTest() error {
out, err := exec.Command("nginx", "-t").CombinedOutput()
logger.Debugf("nginx -t output: %v", string(out))
if err != nil {
return errors.Wrap(err, string(out))
}
//logger.Debugf("nginx -t output: %v", out)
if strings.Contains(string(out), "syntax is ok") && strings.Contains(string(out), "test is successful") {
return nil
} else {
return errors.New(fmt.Sprintf("nginx conf test error: %s", string(out)))
}
}
// NginxConfReload exec nginx -t and return stderr
func NginxConfReload() error {
out, err := exec.Command("nginx", "-s", "reload").CombinedOutput()
logger.Debugf("nginx -s reload output: %v", string(out))
if err != nil {
return errors.Wrap(err, string(out))
}
if len(out) == 0 {
return nil
} else {
return errors.New(fmt.Sprintf("nginx conf reload error: %s", string(out)))
}
}
================================================
FILE: management/tcontrollerd/proto/website/website.proto
================================================
syntax = "proto3";
package website;
option go_package = "proto/website";
service Website {
rpc Subscribe(stream Response) returns (stream Event) {}
}
// From client-side, may be "pong"
message Response {
string type = 1;
bytes msg = 2;
bool err = 3;
}
// From server-side, may be "ping"
message Event {
string type = 1; // ping/website
bytes msg = 2;
}
================================================
FILE: management/tcontrollerd/utils/file.go
================================================
package utils
import (
"fmt"
"io"
"io/ioutil"
"os"
"path/filepath"
)
func EnsureDir(dir string) error {
if _, err := os.Stat(dir); os.IsNotExist(err) {
return os.MkdirAll(dir, os.FileMode(0755))
}
return nil
}
func EnsureFileDir(path string) error {
return EnsureDir(filepath.Dir(path))
}
func FileExist(path string) (bool, error) {
stat, err := os.Stat(path)
if err != nil {
if os.IsNotExist(err) {
return false, nil
} else {
return false, err
}
} else {
if stat.IsDir() {
return false, fmt.Errorf("%s is dir", path)
} else {
return true, nil
}
}
}
func FilesExist(paths ...string) (bool, error) {
for _, path := range paths {
exist, err := FileExist(path)
if err != nil {
return false, err
}
if !exist {
return false, nil
}
}
return true, nil
}
func RenameWriteFile(filename string, data []byte, perm os.FileMode) error {
randFileName := filename + ".tmp." + RandStr(8)
if err := ioutil.WriteFile(randFileName, data, perm); err != nil {
return err
}
return os.Rename(randFileName, filename)
}
func EnsureRenameWriteFile(path string, data []byte, mode os.FileMode) error {
err := EnsureFileDir(path)
if err != nil {
return err
}
return RenameWriteFile(path, data, mode)
}
func EnsureWriteFile(path string, data []byte, mode os.FileMode) error {
err := EnsureFileDir(path)
if err != nil {
return err
}
return ioutil.WriteFile(path, data, mode)
}
func CopyFile(srcPath, dstPath string) error {
srcFile, err := os.Open(srcPath)
if err != nil {
return err
}
defer func(srcFile *os.File) {
err := srcFile.Close()
if err != nil {
}
}(srcFile)
fileInfo, err := srcFile.Stat()
if err != nil {
return err
}
return CopyFileFromIO(srcFile, dstPath, fileInfo.Mode())
}
func CopyFileFromIO(src io.Reader, dstPath string, perm os.FileMode) error {
if err := EnsureFileDir(dstPath); err != nil {
return err
}
dstFile, err := os.OpenFile(dstPath, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, perm)
if err != nil {
return err
}
defer func(dstFile *os.File) {
err := dstFile.Close()
if err != nil {
}
}(dstFile)
_, err = io.Copy(dstFile, src)
return err
}
func CopyFileIfNotExist(srcPath, dstPath string) error {
if exist, err := FileExist(dstPath); err != nil {
return err
} else if !exist {
return CopyFile(srcPath, dstPath)
} else {
return nil
}
}
================================================
FILE: management/tcontrollerd/utils/random.go
================================================
package utils
import (
"math/rand"
"time"
)
var letters = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
func RandStr(n int) string {
rand.Seed(time.Now().UnixNano())
b := make([]rune, n)
for i := range b {
b[i] = letters[rand.Intn(len(letters))]
}
return string(b)
}
================================================
FILE: management/webserver/.gitignore
================================================
tmp
Taskfile.yml
.air.toml
================================================
FILE: management/webserver/README.md
================================================
# Web Server
web server for mgt-api
## Requirements
Go 1.18+
## Development
### Init protobuf
```shell
# Refer: https://grpc.io/docs/languages/go/quickstart/
# 1. Install protoc
# https://grpc.io/docs/protoc-installation/
# 2. Install Go plugins
go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.30.0
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@v1.3.0
# 3. Update your PATH so that the protoc compiler can find the plugins
# export PATH="$PATH:$(go env GOPATH)/bin"
# 4. Generate proto go code
# cd /path/to/management
./scripts/genproto.sh
```
### Init fvm libs
```shell
# Due to the fvm c header files
mkdir -p management/webserver/submodule/fvm/
mkdir -p management/webserver/submodule/libct/
cd management/webserver/submodule/fvm/
# Download https://chaitin.cn/patronus/fvm/-/tags 1.8.21 release:release, https://chaitin.cn/patronus/fvm/-/jobs/6716645
unzip artifacts.zip
rm artifacts.zip
cd management/webserver/submodule/libct/
# Download https://chaitin.cn/patronus/libct/-/tags 1.1.1.0 release, https://chaitin.cn/patronus/libct/-/jobs/7229201
# rename
rm artifacts.zip
cd management/webserver/submodule/
# Download https://chaitin.cn/patronus/fusion-2/-/tags 5.3.9-r1 build:release, https://chaitin.cn/patronus/fusion-2/-/jobs/7326007
# rename
unzip artifacts.zip
mv artifacts/lib/libfusion.so libfvm.so
rm artifacts.zip
rm -r artifacts/
```
### Build
```shell
cd management/
docker run -it --rm -w="/mnt" --mount type=bind,source="$(pwd)",target=/mnt chaitin.cn/ci/golang:1.18 bash
cp webserver/submodule/libfvm.so /usr/lib/
make build-webserver
```
================================================
FILE: management/webserver/api/auth.go
================================================
package api
import (
"math"
"net/http"
"time"
"github.com/gin-contrib/sessions"
"github.com/gin-gonic/gin"
"github.com/pquerna/otp"
"github.com/pquerna/otp/totp"
"chaitin.cn/patronus/safeline-2/management/webserver/api/response"
"chaitin.cn/patronus/safeline-2/management/webserver/model"
"chaitin.cn/patronus/safeline-2/management/webserver/pkg/constants"
"chaitin.cn/patronus/safeline-2/management/webserver/pkg/database"
"chaitin.cn/patronus/safeline-2/management/webserver/pkg/log"
)
var logger = log.GetLogger("api")
var OtpOpts = totp.GenerateOpts{
Issuer: constants.ProductName,
AccountName: constants.SuperUser,
Period: 30, // seconds
Digits: otp.DigitsSix,
Algorithm: otp.AlgorithmSHA1,
}
type PostLoginRequest struct {
Passcode string `json:"passcode"`
Timestamp int64 `json:"timestamp"`
}
func PostLogin(c *gin.Context) {
var params PostLoginRequest
if err := c.BindJSON(¶ms); err != nil {
logger.Error(err)
response.Error(c, response.ErrorParamNotOK, http.StatusInternalServerError)
return
}
db := database.GetDB()
// only SuperUser in v0.9
var user model.User
db.Where(&model.User{Username: constants.SuperUser}).First(&user)
valid := totp.Validate(params.Passcode, user.TFASecret)
if !valid {
millisecondTimestamp := params.Timestamp
localTimeStamp := time.Now()
if millisecondTimestamp > 0 {
logger.Debugf("will valid otp frontend timestamp:%v, local timestamp:%v", millisecondTimestamp, localTimeStamp)
otpTime := time.Unix(millisecondTimestamp/1000, (millisecondTimestamp%1000)*int64(time.Millisecond))
timeSub := localTimeStamp.Sub(otpTime)
seconds := math.Abs(timeSub.Seconds())
if seconds >= 60 {
logger.Errorf("otp timestamp gap is more than a minute")
response.Error(c, response.JSONBody{Err: response.ErrWrongTimeGap, Msg: "otp timestamp gap is more than a minute"}, http.StatusUnauthorized)
return
}
}
response.Error(c, response.JSONBody{Err: response.ErrWrongPasscode, Msg: "Failed to verify your passcode"}, http.StatusUnauthorized)
return
}
user.LastLoginTime = time.Now().Unix()
user.IsEnabled = true
db.Save(&user)
session := sessions.Default(c)
session.Options(sessions.Options{
Path: "/",
MaxAge: 3600 * 24 * 7,
//Domain: options.Domain,
//HttpOnly: true,
//SameSite: http.SameSiteLaxMode,
//Secure: false,
})
session.Set(constants.DefaultSessionUserKey, user.ID)
if err := session.Save(); err != nil {
logger.Error(err)
response.Error(c, response.JSONBody{Err: response.ErrInternalError, Msg: "Error occurred when creating sessions"}, http.StatusInternalServerError)
return
}
response.Success(c, nil)
}
func PostLogout(c *gin.Context) {
session := sessions.Default(c)
session.Clear()
if err := session.Save(); err != nil {
response.Error(c, response.JSONBody{Err: response.ErrInternalError, Msg: "Error occurred when creating sessions"}, http.StatusInternalServerError)
return
}
response.Success(c, nil)
}
func GetOTPUrl(c *gin.Context) {
otpKey, err := totp.Generate(OtpOpts)
if err != nil {
logger.Error(err)
response.Error(c, response.JSONBody{Err: response.ErrInternalError, Msg: "Error occurred when generating otp qrcode"}, http.StatusInternalServerError)
return
}
db := database.GetDB()
// only SuperUser in v0.9
user := model.User{Username: constants.SuperUser}
db.First(&user)
if user.LastLoginTime > 0 {
// already bind tfa, because tfa binding is mandatory when login.
response.Success(c, gin.H{"url": ""})
return
}
user.TFASecret = otpKey.Secret()
db.Save(&user)
response.Success(c, gin.H{"url": otpKey.URL()})
}
func GetUser(c *gin.Context) {
db := database.GetDB()
user := model.User{Username: constants.SuperUser}
db.First(&user)
response.Success(c, gin.H{"id": user.ID, "username": user.Username})
}
================================================
FILE: management/webserver/api/behaviour.go
================================================
package api
import (
"net/http"
"github.com/gin-gonic/gin"
"chaitin.cn/patronus/safeline-2/management/webserver/api/response"
"chaitin.cn/patronus/safeline-2/management/webserver/model"
"chaitin.cn/patronus/safeline-2/management/webserver/pkg/database"
)
type PostBehaviourRequest struct {
model.Behaviour
}
func PostBehaviour(c *gin.Context) {
var params PostBehaviourRequest
if err := c.BindJSON(¶ms); err != nil {
logger.Error(err)
response.Error(c, response.ErrorParamNotOK, http.StatusInternalServerError)
return
}
db := database.GetDB()
db.Create(&model.Behaviour{SrcRouter: params.SrcRouter, DstRouter: params.DstRouter})
response.Success(c, nil)
}
================================================
FILE: management/webserver/api/cert.go
================================================
package api
import (
"crypto/x509/pkix"
"fmt"
"net/http"
"path/filepath"
"github.com/gin-gonic/gin"
"chaitin.cn/patronus/safeline-2/management/webserver/api/response"
"chaitin.cn/patronus/safeline-2/management/webserver/pkg/config"
"chaitin.cn/patronus/safeline-2/management/webserver/utils"
)
type postSSLCertRequest struct {
Hostname string `json:"hostname"`
}
// SSLCertDir is the dir of tengine conf, not mgt-api nginx certs dir defined by constants.CertsPath
const (
CRT = ".crt"
PEM = ".pem"
KEY = ".key"
SSLCertDir = "certs"
)
func PostUploadSSLCert(c *gin.Context) {
file, err := c.FormFile("file")
if err != nil {
logger.Error(err)
response.Error(c, response.ErrorParamNotOK, http.StatusInternalServerError)
return
}
switch filepath.Ext(file.Filename) {
case CRT, PEM, KEY:
logger.Debugf("File: %v is valid", file.Filename)
default:
logger.Errorf("Filename: %s, ext: %s", file.Filename, filepath.Ext(file.Filename))
response.Error(c, response.JSONBody{Err: response.ErrWrongFileType, Msg: "Wrong file type, please upload a file of .crt or .key"}, http.StatusUnsupportedMediaType)
return
}
var dstPath string
filename := fmt.Sprintf("%s_%s", utils.RandStr(16), file.Filename)
if config.GlobalConfig.Server.DevMode {
dstPath = filepath.Join("./nginx", SSLCertDir, filename)
} else {
dstPath = filepath.Join(config.GlobalConfig.NgxResDir, SSLCertDir, filename)
}
if err = c.SaveUploadedFile(file, dstPath); err != nil {
logger.Error(err)
response.Error(c, response.JSONBody{Err: response.ErrInternalError, Msg: "Error occurred when saving file"}, http.StatusInternalServerError)
return
}
response.Success(c, gin.H{"filename": filename})
}
func PostSSLCert(c *gin.Context) {
var params postSSLCertRequest
if err := c.BindJSON(¶ms); err != nil {
logger.Error(err)
response.Error(c, response.ErrorParamNotOK, http.StatusInternalServerError)
return
}
filePrefix := utils.RandStr(16)
certFilename := fmt.Sprintf("%s_backend.crt", filePrefix)
keyFilename := fmt.Sprintf("%s_backend.key", filePrefix)
var certPath, keyPath string
if config.GlobalConfig.Server.DevMode {
certPath = filepath.Join("./management", SSLCertDir, certFilename)
keyPath = filepath.Join("./management", SSLCertDir, keyFilename)
} else {
certPath = filepath.Join(config.GlobalConfig.NgxResDir, SSLCertDir, certFilename)
keyPath = filepath.Join(config.GlobalConfig.NgxResDir, SSLCertDir, keyFilename)
}
if err := utils.WriteCertIfNotExist(
certPath,
keyPath,
func() ([]byte, []byte, error) {
return utils.GenerateCert(
[]string{params.Hostname},
3650,
4096,
&pkix.Name{
Country: []string{},
Province: []string{},
Locality: []string{},
Organization: []string{},
OrganizationalUnit: []string{},
CommonName: "",
},
false,
)
}); err != nil {
logger.Error(err)
response.Error(c, response.JSONBody{Err: response.ErrInternalError, Msg: "Error occurred when generating certs"}, http.StatusInternalServerError)
return
}
response.Success(c, gin.H{"crt": certFilename, "key": keyFilename})
}
================================================
FILE: management/webserver/api/common.go
================================================
package api
import (
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"strings"
"github.com/gin-gonic/gin"
"github.com/rogpeppe/go-internal/semver"
"chaitin.cn/patronus/safeline-2/management/webserver/api/response"
"chaitin.cn/patronus/safeline-2/management/webserver/pkg/config"
"chaitin.cn/patronus/safeline-2/management/webserver/pkg/constants"
"chaitin.cn/patronus/safeline-2/management/webserver/utils"
)
const VersionInfoEntrypoint = "/release/latest/version.json"
type idsRequest struct {
IDs []uint `json:"ids" form:"ids"`
}
type pageRequest struct {
Page int `json:"page" form:"page,default=1" binding:"min=1"`
PageSize int `json:"page_size" form:"page_size,default=10" binding:"min=1"`
}
type versionInfoResponse struct {
LatestVersion string `json:"latest_version"`
RecVersion string `json:"rec_version"`
}
func GetVersion(c *gin.Context) {
response.Success(c, gin.H{"version": strings.TrimPrefix(constants.Version, "ce-")})
}
func GetUpgradeTips(ctx *gin.Context) {
client := utils.GetHTTPClient()
logger.Debugf("GetUpgradeTips: %s", config.GlobalConfig.PlatformAddr+VersionInfoEntrypoint)
versionInfoReq, err := http.NewRequest(http.MethodGet, config.GlobalConfig.PlatformAddr+VersionInfoEntrypoint, nil)
if err != nil {
logger.Warn(err)
response.Success(ctx, gin.H{"upgrade_tips": constants.NotUpgrade})
return
}
versionInfoRsp, err := client.Do(versionInfoReq)
if err != nil {
logger.Warn(err)
response.Success(ctx, gin.H{"upgrade_tips": constants.NotUpgrade})
return
}
body, err := ioutil.ReadAll(versionInfoRsp.Body)
if err != nil {
logger.Warn(err)
response.Success(ctx, gin.H{"upgrade_tips": constants.NotUpgrade})
return
}
versionInfo := &versionInfoResponse{}
err = json.Unmarshal(body, versionInfo)
if err != nil {
logger.Warnf("err: %v, body: %s", err, body)
response.Success(ctx, gin.H{"upgrade_tips": constants.NotUpgrade})
return
}
currentVersion := fmt.Sprintf("v%s", constants.Version)
latestVersionCmp := semver.Compare(currentVersion, versionInfo.LatestVersion)
recVersionCmp := semver.Compare(currentVersion, versionInfo.RecVersion)
if semver.Compare(versionInfo.LatestVersion, versionInfo.RecVersion) == -1 || latestVersionCmp == 1 {
logger.Warnf("The version number is invalid, current version: %s, latest version: %s, rec version: %s",
currentVersion, versionInfo.LatestVersion, versionInfo.RecVersion)
response.Success(ctx, gin.H{"upgrade_tips": constants.NotUpgrade})
return
}
var upgradeTips int
if recVersionCmp == -1 {
upgradeTips = constants.MustUpgrade
} else if recVersionCmp == 0 {
if latestVersionCmp == 0 {
upgradeTips = constants.NotUpgrade
} else {
upgradeTips = constants.RecommendedUpgrade
}
} else {
if latestVersionCmp < 0 {
upgradeTips = constants.RecommendedUpgrade
} else {
upgradeTips = constants.NotUpgrade
}
}
response.Success(ctx, gin.H{"upgrade_tips": upgradeTips})
}
================================================
FILE: management/webserver/api/dashboard.go
================================================
package api
import (
"math"
"time"
"github.com/gin-gonic/gin"
"chaitin.cn/patronus/safeline-2/management/webserver/api/response"
"chaitin.cn/patronus/safeline-2/management/webserver/model"
"chaitin.cn/patronus/safeline-2/management/webserver/pkg/database"
)
func GetDashboardCounts(c *gin.Context) {
var requested int64 = 0
var intercepted int64 = 0
db := database.GetDB()
var statisticTotalReq model.SystemStatistics
r := db.Where("type = 'total-req'").Where("created_at >= date_trunc('day',now())").First(&statisticTotalReq)
if r.RowsAffected > 0 {
requested = statisticTotalReq.Value
}
var statisticTotalDenied model.SystemStatistics
r = db.Where("type = 'total-denied'").Where("created_at >= date_trunc('day',now())").First(&statisticTotalDenied)
if r.RowsAffected > 0 {
intercepted = statisticTotalDenied.Value
}
response.Success(c, gin.H{"requested": requested, "intercepted": intercepted})
}
func GetDashboardSites(c *gin.Context) {
response.Success(c, gin.H{"normal": 0, "abnormal": 0})
}
func GetDashboardQps(c *gin.Context) {
var statistics []model.SystemStatistics
db := database.GetDB()
db.Where("type = 'req'").Order("created_at desc").Limit(75).Find(&statistics)
type Node struct {
Label string `json:"label"`
Value int64 `json:"value"`
}
var nodes = make([]Node, 0)
for i := len(statistics) - 1; i >= 0; i-- {
nodes = append(nodes, Node{
Label: statistics[i].CreatedAt.Format("2006-01-02 15:04:05"),
Value: int64(math.Ceil(float64(statistics[i].Value) / 5)),
})
}
response.Success(c, gin.H{"nodes": nodes, "total": len(nodes)})
}
func GetDashboardRequests(c *gin.Context) {
var statistics []model.SystemStatistics
db := database.GetDB()
db.Where("type = 'total-req'").Order("created_at desc").Limit(30).Find(&statistics)
type Node struct {
Label string `json:"label"`
Value int64 `json:"value"`
}
var nodes = make([]Node, 0)
for i := 30; i > len(statistics); i-- {
nodes = append(nodes, Node{
Label: time.Now().Add(-time.Duration(i-1) * time.Hour * 24).Format("2006-01-02"),
Value: 0,
})
}
for i := len(statistics) - 1; i >= 0; i-- {
nodes = append(nodes, Node{
Label: statistics[i].CreatedAt.Format("2006-01-02"),
Value: statistics[i].Value,
})
}
response.Success(c, gin.H{"nodes": nodes, "total": len(nodes)})
}
func GetDashboardIntercepts(c *gin.Context) {
var statistics []model.SystemStatistics
db := database.GetDB()
db.Where("type = 'total-denied'").Order("created_at desc").Limit(30).Find(&statistics)
type Node struct {
Label string `json:"label"`
Value int64 `json:"value"`
}
var nodes = make([]Node, 0)
for i := 30; i > len(statistics); i-- {
nodes = append(nodes, Node{
Label: time.Now().Add(-time.Duration(i-1) * time.Hour * 24).Format("2006-01-02"),
Value: 0,
})
}
for i := len(statistics) - 1; i >= 0; i-- {
nodes = append(nodes, Node{
Label: statistics[i].CreatedAt.Format("2006-01-02"),
Value: statistics[i].Value,
})
}
response.Success(c, gin.H{"nodes": nodes, "total": len(nodes)})
}
================================================
FILE: management/webserver/api/detectlog.go
================================================
package api
import (
"bytes"
"encoding/json"
"fmt"
"net/http"
"strconv"
"strings"
"chaitin.cn/dev/go/errors"
"chaitin.cn/patronus/safeline-2/management/webserver/pkg"
"github.com/gin-gonic/gin"
"chaitin.cn/dev/go/log"
"chaitin.cn/patronus/safeline-2/management/webserver/api/response"
"chaitin.cn/patronus/safeline-2/management/webserver/model"
"chaitin.cn/patronus/safeline-2/management/webserver/pkg/config"
"chaitin.cn/patronus/safeline-2/management/webserver/pkg/constants"
"chaitin.cn/patronus/safeline-2/management/webserver/pkg/database"
"chaitin.cn/patronus/safeline-2/management/webserver/utils"
)
type (
GetDetectLogDetailRequest struct {
EventId string `json:"event_id" form:"event_id"`
}
PostFalsePositivesRequest struct {
EventId string `json:"event_id"`
}
telemetryFalsePositives struct {
Telemetry struct {
Id string `json:"id"`
} `json:"telemetry"`
Safeline struct {
Id string `json:"id"`
Type string `json:"type"`
DetectLog model.DetectLog `json:"detect_log"`
} `json:"safeline"`
}
)
func getDetectLog(eventId string) (*model.DetectLog, error) {
db := database.GetDB()
var detectLogBasic model.DetectLogBasic
res := db.Where(&model.DetectLogBasic{EventId: eventId}).First(&detectLogBasic)
if res.RowsAffected == 0 {
return nil, errors.New("Data queried does not exist")
}
var detectLogDetail model.DetectLogDetail
db.Where(&model.DetectLogDetail{EventId: eventId}).First(&detectLogDetail)
detectLog, err := model.TransformDetectLog(&detectLogBasic, &detectLogDetail)
if err != nil {
return nil, err
}
return detectLog, nil
}
func GetDetectLogList(c *gin.Context) {
var params pageRequest
if err := c.BindQuery(¶ms); err != nil {
logger.Error(err)
response.Error(c, response.ErrorParamNotOK, http.StatusInternalServerError)
return
}
db := database.GetDB()
tx := db.Where("")
// 按 ip 搜索条件
if ip := c.Query("ip"); ip != "" {
tx = tx.Where("src_ip = ?", ip)
}
// 按 url 搜索条件
if url := c.Query("url"); url != "" {
tx = tx.Where("url_path like ?", "%"+url+"%")
}
// 按 type 搜索条件
if at := c.Query("attack_type"); at != "" {
ns := make([]int, 0)
for _, s := range strings.Split(at, ",") {
n, err := strconv.Atoi(s)
if err == nil {
ns = append(ns, n)
}
}
tx = tx.Where("attack_type in (?)", ns)
}
var total int64
tx.Model(&model.DetectLogBasic{}).Count(&total)
var basicList []model.DetectLogBasic
tx.Limit(params.PageSize).Offset(params.PageSize * (params.Page - 1)).Order("id desc").Find(&basicList)
var dLogList []*model.DetectLog
for _, basic := range basicList {
dLog, err := model.TransformDetectLog(&basic, nil)
if err != nil {
logger.Warn(err)
continue
}
dLogList = append(dLogList, dLog)
}
response.Success(c, gin.H{"data": dLogList, "total": total})
}
func GetDetectLogDetail(c *gin.Context) {
var params GetDetectLogDetailRequest
if err := c.BindQuery(¶ms); err != nil {
logger.Error(err)
response.Error(c, response.ErrorParamNotOK, http.StatusInternalServerError)
return
}
detectLog, err := getDetectLog(params.EventId)
if err != nil {
logger.Error(err)
response.Error(c, response.ErrorDataNotExist, http.StatusNotFound)
return
}
response.Success(c, detectLog)
}
func PostFalsePositives(c *gin.Context) {
var params PostFalsePositivesRequest
if err := c.BindJSON(¶ms); err != nil {
logger.Error(err)
response.Error(c, response.ErrorParamNotOK, http.StatusInternalServerError)
return
}
detectLog, err := getDetectLog(params.EventId)
if err != nil {
logger.Error(err)
response.Error(c, response.ErrorDataNotExist, http.StatusNotFound)
return
}
db := database.GetDB()
var option model.Options
db.Where(&model.Options{Key: constants.MachineID}).First(&option)
var jsonData telemetryFalsePositives
jsonData.Telemetry.Id = constants.TelemetryId
jsonData.Safeline.Id = option.Value
jsonData.Safeline.Type = constants.FalsePositives
jsonData.Safeline.DetectLog = *detectLog
data, err := json.Marshal(jsonData)
if err != nil {
log.Warn(err)
response.Success(c, nil)
return
}
reader := bytes.NewReader(data)
client := utils.GetHTTPClient()
addr := config.GlobalConfig.Telemetry.Addr
rsp, err := pkg.DoPostTelemetry(client, addr, reader)
if err != nil {
log.Warn(err)
response.Success(c, nil)
return
}
if rsp.StatusCode != http.StatusOK && rsp.StatusCode != http.StatusCreated {
log.Warn(fmt.Sprintf("Transfer telemetry failed, status code = %d", rsp.StatusCode), err)
response.Success(c, nil)
return
}
response.Success(c, nil)
}
================================================
FILE: management/webserver/api/endpoints.go
================================================
package api
const (
Version = "/Version"
UpgradeTips = "/UpgradeTips"
Login = "/Login"
Logout = "/Logout"
OTPUrl = "/OTPUrl"
User = "/User"
DetectLogList = "/DetectLogList"
DetectLogDetail = "/DetectLogDetail"
Behaviour = "/Behaviour"
FalsePositives = "/FalsePositives"
Website = "/Website"
UploadSSLCert = "/UploadSSLCert"
SSLCert = "/SSLCert"
PolicyRule = "/PolicyRule"
SwitchPolicyRule = "/SwitchPolicyRule"
DashboardCounts = "/dashboard/counts"
DashboardSites = "/dashboard/sites"
DashboardQps = "/dashboard/qps"
DashboardRequests = "/dashboard/requests"
DashboardIntercepts = "/dashboard/intercepts"
PolicyGroupGlobal = "/PolicyGroupGlobal"
SrcIPConfig = "/SrcIPConfig"
)
================================================
FILE: management/webserver/api/policygroup.go
================================================
package api
import (
"encoding/json"
"net/http"
"github.com/gin-gonic/gin"
"gorm.io/gorm"
"chaitin.cn/dev/go/errors"
"chaitin.cn/patronus/safeline-2/management/webserver/api/response"
"chaitin.cn/patronus/safeline-2/management/webserver/model"
"chaitin.cn/patronus/safeline-2/management/webserver/pkg/constants"
"chaitin.cn/patronus/safeline-2/management/webserver/pkg/database"
"chaitin.cn/patronus/safeline-2/management/webserver/pkg/fvm"
)
func PutPolicyGroupGlobal(ctx *gin.Context) {
var params model.PolicyGroup
if err := ctx.BindJSON(¶ms); err != nil {
logger.Error(err)
response.Error(ctx, response.ErrorParamNotOK, http.StatusInternalServerError)
return
}
db := database.GetDB()
err := db.Transaction(func(tx *gorm.DB) error {
var pggOption model.Options
res := tx.Where(&model.Options{Key: constants.PolicyGroupGlobal}).First(&pggOption)
if res.Error != nil {
return res.Error
}
if res.RowsAffected == 0 {
return errors.New("Data queried does not exist")
}
pggStr, err := json.Marshal(params)
if err != nil {
logger.Error(err)
response.Error(ctx, response.JSONBody{Err: response.ErrInternalError, Msg: err.Error()}, http.StatusInternalServerError)
return err
}
pggOption.Value = string(pggStr)
tx.Save(&pggOption)
if err := fvm.PushFSL(tx); err != nil {
return errors.New("Rules compile error, please check your params.")
}
return nil
})
if err != nil {
logger.Error(err)
response.Error(ctx, response.JSONBody{Err: response.ErrInternalError, Msg: err.Error()}, http.StatusInternalServerError)
return
}
response.Success(ctx, nil)
}
func GetPolicyGroupGlobal(ctx *gin.Context) {
var pggOption model.Options
database.GetDB().Where(&model.Options{Key: constants.PolicyGroupGlobal}).First(&pggOption)
var pgg model.PolicyGroup
err := json.Unmarshal([]byte(pggOption.Value), &pgg)
if err != nil {
logger.Error(err)
response.Error(ctx, response.JSONBody{Err: response.ErrInternalError, Msg: err.Error()}, http.StatusInternalServerError)
return
}
response.Success(ctx, gin.H{"data": pgg})
}
func PutSrcIPConfig(ctx *gin.Context) {
var params model.SrcIPConfig
if err := ctx.BindJSON(¶ms); err != nil {
logger.Error(err)
response.Error(ctx, response.ErrorParamNotOK, http.StatusInternalServerError)
return
}
db := database.GetDB()
err := db.Transaction(func(tx *gorm.DB) error {
var scOption model.Options
res := tx.Where(&model.Options{Key: constants.SrcIPConfig}).First(&scOption)
if res.Error != nil {
return res.Error
}
if res.RowsAffected == 0 {
return errors.New("Data queried does not exist")
}
scStr, err := json.Marshal(params)
if err != nil {
logger.Error(err)
response.Error(ctx, response.JSONBody{Err: response.ErrInternalError, Msg: err.Error()}, http.StatusInternalServerError)
return err
}
scOption.Value = string(scStr)
tx.Save(&scOption)
if err := fvm.PushFSL(tx); err != nil {
return errors.New("Rules compile error, please check your params.")
}
return nil
})
if err != nil {
logger.Error(err)
response.Error(ctx, response.JSONBody{Err: response.ErrInternalError, Msg: err.Error()}, http.StatusInternalServerError)
return
}
response.Success(ctx, nil)
}
func GetSrcIPConfig(ctx *gin.Context) {
srcIPConfig, err := model.GetSrcIPConfig(database.GetDB().DB)
if err != nil {
return
}
response.Success(ctx, gin.H{"data": srcIPConfig})
}
================================================
FILE: management/webserver/api/policyrule.go
================================================
package api
import (
"net/http"
"chaitin.cn/patronus/safeline-2/management/webserver/pkg/fvm"
"github.com/gin-gonic/gin"
"gorm.io/gorm"
"chaitin.cn/dev/go/errors"
"chaitin.cn/patronus/safeline-2/management/webserver/api/response"
"chaitin.cn/patronus/safeline-2/management/webserver/model"
"chaitin.cn/patronus/safeline-2/management/webserver/pkg/database"
)
type putSwitchRequest struct {
IDs []uint `json:"ids"`
IsEnabled bool `json:"is_enabled"`
}
func PostPolicyRule(ctx *gin.Context) {
var params model.PolicyRule
if err := ctx.BindJSON(¶ms); err != nil {
logger.Error(err)
response.Error(ctx, response.ErrorParamNotOK, http.StatusInternalServerError)
return
}
db := database.GetDB()
err := db.Transaction(func(tx *gorm.DB) error {
policyRule := &model.PolicyRule{Action: params.Action, Comment: params.Comment, IsEnabled: params.IsEnabled, Pattern: params.Pattern}
res := tx.Create(policyRule)
if res.Error != nil {
return res.Error
}
if err := fvm.PushFSL(tx); err != nil {
return errors.New("Rules compile error, please check your params.")
}
return nil
})
if err != nil {
logger.Error(err)
response.Error(ctx, response.JSONBody{Err: response.ErrInternalError, Msg: err.Error()}, http.StatusInternalServerError)
return
}
response.Success(ctx, nil)
}
func PutSwitchPolicyRule(ctx *gin.Context) {
var params putSwitchRequest
if err := ctx.BindJSON(¶ms); err != nil {
logger.Error(err)
response.Error(ctx, response.ErrorParamNotOK, http.StatusInternalServerError)
return
}
db := database.GetDB()
err := db.Transaction(func(tx *gorm.DB) error {
res := tx.Model(&model.PolicyRule{}).Where(params.IDs).Updates(model.PolicyRule{IsEnabled: params.IsEnabled})
if res.Error != nil {
return res.Error
}
if res.RowsAffected == 0 {
return errors.New("Data queried does not exist")
}
if err := fvm.PushFSL(tx); err != nil {
return errors.New("Rules compile error, please check your params.")
}
return nil
})
if err != nil {
logger.Error(err)
response.Error(ctx, response.JSONBody{Err: response.ErrInternalError, Msg: err.Error()}, http.StatusInternalServerError)
return
}
}
func PutPolicyRule(ctx *gin.Context) {
var params model.PolicyRule
if err := ctx.BindJSON(¶ms); err != nil {
logger.Error(err)
response.Error(ctx, response.ErrorParamNotOK, http.StatusInternalServerError)
return
}
db := database.GetDB()
err := db.Transaction(func(tx *gorm.DB) error {
var policyRule model.PolicyRule
res := tx.Where(params.ID).First(&policyRule)
if res.Error != nil {
return res.Error
}
if res.RowsAffected == 0 {
return errors.New("Data queried does not exist")
}
policyRule.Action = params.Action
policyRule.Comment = params.Comment
policyRule.IsEnabled = params.IsEnabled
policyRule.Pattern = params.Pattern
tx.Save(&policyRule)
if err := fvm.PushFSL(tx); err != nil {
return errors.New("Rules compile error, please check your params.")
}
return nil
})
if err != nil {
logger.Error(err)
response.Error(ctx, response.JSONBody{Err: response.ErrInternalError, Msg: err.Error()}, http.StatusInternalServerError)
return
}
response.Success(ctx, nil)
}
func DeletePolicyRule(ctx *gin.Context) {
var params idsRequest
if err := ctx.BindJSON(¶ms); err != nil {
logger.Error(err)
response.Error(ctx, response.ErrorParamNotOK, http.StatusInternalServerError)
return
}
db := database.GetDB()
err := db.Transaction(func(tx *gorm.DB) error {
res := tx.Where(params.IDs).Delete(&model.PolicyRule{})
if res.Error != nil {
return res.Error
}
if res.RowsAffected == 0 {
return errors.New("Data queried does not exist")
}
if err := fvm.PushFSL(tx); err != nil {
return errors.New("Rules compile error, please check your params.")
}
return nil
})
if err != nil {
logger.Error(err)
response.Error(ctx, response.JSONBody{Err: response.ErrInternalError, Msg: err.Error()}, http.StatusInternalServerError)
return
}
response.Success(ctx, nil)
}
func GetPolicyRule(ctx *gin.Context) {
var params pageRequest
if err := ctx.BindQuery(¶ms); err != nil {
logger.Error(err)
response.Error(ctx, response.ErrorParamNotOK, http.StatusInternalServerError)
return
}
db := database.GetDB()
var policyRuleList []model.PolicyRule
db.Limit(params.PageSize).Offset(params.PageSize * (params.Page - 1)).Order("id desc").Find(&policyRuleList)
var total int64
db.Model(&model.PolicyRule{}).Count(&total)
response.Success(ctx, gin.H{"data": policyRuleList, "total": total})
}
================================================
FILE: management/webserver/api/response/error.go
================================================
package response
const (
ErrLoginRequired = "login-required"
ErrWrongPasscode = "wrong-passcode"
ErrWrongTimeGap = "wrong-time-gap"
ErrInternalError = "internal-error"
ErrDataNotExist = "data-not-exist"
ErrWrongFileType = "wrong-filetype"
ErrReadOnly = "read-only"
)
================================================
FILE: management/webserver/api/response/jsonbody.go
================================================
package response
import (
"net/http"
"github.com/gin-gonic/gin"
)
type JSONBody struct {
Err string
Msg string
Data interface{}
}
var (
ErrorLoginRequired = JSONBody{ErrLoginRequired, "Login required", nil}
ErrorParamNotOK = JSONBody{ErrInternalError, "Error occurred when extracting params", nil}
ErrorDataNotExist = JSONBody{ErrDataNotExist, "Data queried does not exist", nil}
ErrorReadOnly = JSONBody{ErrReadOnly, "This environment is read only", nil}
)
func Success(c *gin.Context, data interface{}) {
c.JSON(http.StatusOK, gin.H{
"data": data,
"msg": "",
"err": nil,
})
//c.Abort()
}
func SuccessWithList(c *gin.Context, data interface{}) {
c.JSON(http.StatusOK, gin.H{
"data": data,
"msg": "",
"err": nil,
})
//c.Abort()
}
func SuccessWithMsg(c *gin.Context, data interface{}, msg string) {
c.JSON(http.StatusOK, gin.H{
"data": data,
"msg": msg,
"err": nil,
})
//c.Abort()
}
func Error(c *gin.Context, rsp JSONBody, status int) {
c.JSON(status, gin.H{
"data": rsp.Data,
"msg": rsp.Msg,
"err": rsp.Err,
})
//c.Abort()
}
================================================
FILE: management/webserver/api/response/png.go
================================================
package response
import (
"net/http"
"github.com/gin-gonic/gin"
)
const StreamContentType = "application/octet-stream"
func PNG(c *gin.Context, bytes []byte) {
c.Data(http.StatusOK, StreamContentType, bytes)
}
================================================
FILE: management/webserver/api/website.go
================================================
package api
import (
"encoding/json"
"net/http"
"strconv"
"chaitin.cn/dev/go/errors"
"github.com/gin-gonic/gin"
"gorm.io/gorm"
"chaitin.cn/patronus/safeline-2/management/webserver/api/response"
"chaitin.cn/patronus/safeline-2/management/webserver/model"
"chaitin.cn/patronus/safeline-2/management/webserver/pkg/config"
"chaitin.cn/patronus/safeline-2/management/webserver/pkg/database"
"chaitin.cn/patronus/safeline-2/management/webserver/rpc"
)
func publishWebsiteConfig(website *model.Website) error {
byteWebsite, err := json.Marshal(website)
if err != nil {
return err
}
err = rpc.Publish(byteWebsite, rpc.EventTypeWebsite)
if err != nil {
return err
}
return nil
}
func publishDeleteWebsiteConfig(id []uint) error {
byteId, err := json.Marshal(id)
if err != nil {
return err
}
err = rpc.Publish(byteId, rpc.EventTypeDeleteWebsite)
if err != nil {
return err
}
return nil
}
func PostWebsite(ctx *gin.Context) {
var params model.Website
if err := ctx.BindJSON(¶ms); err != nil {
logger.Error(err)
response.Error(ctx, response.ErrorParamNotOK, http.StatusInternalServerError)
return
}
db := database.GetDB()
err := db.Transaction(func(tx *gorm.DB) error {
website := &model.Website{Comment: params.Comment, ServerNames: params.ServerNames, Upstreams: params.Upstreams, Ports: params.Ports,
CertFilename: params.CertFilename, KeyFilename: params.KeyFilename, IsEnabled: true}
res := tx.Create(website)
if res.Error != nil {
return res.Error
}
if config.GlobalConfig.Server.DevMode {
return nil
}
err := publishWebsiteConfig(website)
if err != nil {
return err
}
return nil
})
if err != nil {
logger.Error(err)
response.Error(ctx, response.JSONBody{Err: response.ErrInternalError, Msg: err.Error()}, http.StatusInternalServerError)
return
}
response.Success(ctx, nil)
}
func PutWebsite(ctx *gin.Context) {
var params model.Website
if err := ctx.BindJSON(¶ms); err != nil {
logger.Error(err)
response.Error(ctx, response.ErrorParamNotOK, http.StatusInternalServerError)
return
}
db := database.GetDB()
err := db.Transaction(func(tx *gorm.DB) error {
var website model.Website
res := tx.Where(params.ID).First(&website)
if res.Error != nil {
return res.Error
}
if res.RowsAffected == 0 {
return errors.New("Data queried does not exist")
}
website.Comment = params.Comment
website.ServerNames = params.ServerNames
website.Upstreams = params.Upstreams
website.Ports = params.Ports
website.CertFilename = params.CertFilename
website.KeyFilename = params.KeyFilename
website.IsEnabled = true
tx.Save(&website)
if config.GlobalConfig.Server.DevMode {
return nil
}
err := publishWebsiteConfig(¶ms)
if err != nil {
return err
}
return nil
})
if err != nil {
logger.Error(err)
response.Error(ctx, response.JSONBody{Err: response.ErrInternalError, Msg: err.Error()}, http.StatusInternalServerError)
return
}
response.Success(ctx, nil)
}
func DeleteWebsite(ctx *gin.Context) {
var params idsRequest
if err := ctx.BindJSON(¶ms); err != nil {
logger.Error(err)
response.Error(ctx, response.ErrorParamNotOK, http.StatusInternalServerError)
return
}
db := database.GetDB()
err := db.Transaction(func(tx *gorm.DB) error {
res := tx.Where(params.IDs).Delete(&model.Website{})
if res.Error != nil {
return res.Error
}
if res.RowsAffected == 0 {
return errors.New("Data queried does not exist")
}
if config.GlobalConfig.Server.DevMode {
return nil
}
err := publishDeleteWebsiteConfig(params.IDs)
if err != nil {
return err
}
return nil
})
if err != nil {
logger.Error(err)
response.Error(ctx, response.JSONBody{Err: response.ErrInternalError, Msg: err.Error()}, http.StatusInternalServerError)
return
}
response.Success(ctx, nil)
}
func GetWebsite(ctx *gin.Context) {
var params pageRequest
if err := ctx.BindQuery(¶ms); err != nil {
logger.Error(err)
response.Error(ctx, response.ErrorParamNotOK, http.StatusInternalServerError)
return
}
db := database.GetDB()
type Website struct {
model.Website
ReqValue int64 `json:"req_value"`
DeniedValue int64 `json:"denied_value"`
}
var websiteList []Website
db.Limit(params.PageSize).Offset(params.PageSize * (params.Page - 1)).Order("id desc").Find(&websiteList)
var statistics []model.SystemStatistics
var websiteIds []string
for _, i := range websiteList {
websiteIds = append(websiteIds, strconv.Itoa(int(i.ID)))
}
db.Where("created_at >= date_trunc('day',now())").Where("website in (?)", websiteIds).Find(&statistics)
for i, website := range websiteList {
for _, j := range statistics {
if strconv.Itoa(int(website.ID)) == j.Website {
if j.Type == "website-req" {
websiteList[i].ReqValue = j.Value
} else if j.Type == "website-denied" {
websiteList[i].DeniedValue = j.Value
}
}
}
}
var total int64
db.Model(&model.Website{}).Count(&total)
response.Success(ctx, gin.H{"data": websiteList, "total": total})
}
================================================
FILE: management/webserver/cmd/fake_logs.go
================================================
package cmd
import "chaitin.cn/patronus/safeline-2/management/webserver/model"
func FakeLogs() {
model.InitDetectLogSamples()
}
================================================
FILE: management/webserver/cmd/gen_certs.go
================================================
package cmd
import (
"crypto/x509/pkix"
"path/filepath"
"chaitin.cn/patronus/safeline-2/management/webserver/pkg/config"
"chaitin.cn/patronus/safeline-2/management/webserver/pkg/constants"
"chaitin.cn/patronus/safeline-2/management/webserver/utils"
)
func GenCerts() error {
if err := genServerCert(); err != nil {
return err
}
if err := genClientCACert(); err != nil {
return err
}
return nil
}
func genServerCert() error {
certPath := filepath.Join(config.GlobalConfig.MgtResDir, constants.CertsPath, "server.crt")
keyPath := filepath.Join(config.GlobalConfig.MgtResDir, constants.CertsPath, "server.key")
if err := utils.WriteCertIfNotExist(
certPath,
keyPath,
func() ([]byte, []byte, error) {
return utils.GenerateCert(
[]string{},
3650,
4096,
&pkix.Name{
Country: []string{"CN"},
Province: []string{"Beijing"},
Locality: []string{"Beijing"},
Organization: []string{"Beijing WAF Technology Co., Ltd."},
OrganizationalUnit: []string{"Service Infrastructure Department"},
CommonName: "WAF Management Server",
},
false,
)
}); err != nil {
return err
}
return nil
}
func genClientCACert() error {
certPath := filepath.Join(config.GlobalConfig.MgtResDir, constants.CertsPath, "client_ca.crt")
keyPath := filepath.Join(config.GlobalConfig.MgtResDir, constants.CertsPath, "client_ca.key")
if err := utils.WriteCertIfNotExist(
certPath,
keyPath,
func() ([]byte, []byte, error) {
return utils.GenerateCert(
[]string{},
3650,
4096,
&pkix.Name{
Country: []string{"CN"},
Province: []string{"Beijing"},
Locality: []string{"Beijing"},
Organization: []string{"Beijing WAF Technology Co., Ltd."},
OrganizationalUnit: []string{"Service Infrastructure Department"},
CommonName: "WAF Client Certificate Authority",
},
true,
)
}); err != nil {
return err
}
return nil
}
================================================
FILE: management/webserver/cmd/push_fsl.go
================================================
package cmd
import (
"chaitin.cn/patronus/safeline-2/management/webserver/pkg/database"
"chaitin.cn/patronus/safeline-2/management/webserver/pkg/fvm"
)
func PushFSL() error {
return fvm.PushFSL(database.GetDB().DB)
}
================================================
FILE: management/webserver/cmd/reset_user.go
================================================
package cmd
import (
"chaitin.cn/patronus/safeline-2/management/webserver/model"
"chaitin.cn/patronus/safeline-2/management/webserver/pkg/database"
)
func ResetUser(username string) {
db := database.GetDB()
var user model.User
db.Where(&model.User{Username: username}).First(&user)
user.LastLoginTime = 0
db.Save(&user)
}
================================================
FILE: management/webserver/cmd/show_fsl.go
================================================
package cmd
import (
"chaitin.cn/patronus/safeline-2/management/webserver/pkg/database"
"chaitin.cn/patronus/safeline-2/management/webserver/pkg/fvm"
)
func ShowFSL() (string, error) {
return fvm.GenerateFullFSL(database.GetDB().DB)
}
================================================
FILE: management/webserver/config.yml
================================================
# develop use only. For production, refer to `package/build/mgt-api/webserver/config.yml`
log:
output: stdout # "stdout", "stderr" or file path
level: debug # "debug", "info", "warn" or "error"
server:
listen_addr: :9001
dev_mode: true
db:
url: postgres://safeline-ce:safeline-ce@127.0.0.1/safeline-ce
log_sql: false
detector:
addr: ""
fsl_bytecode: fvm/bytecode
grpc_server:
listen_addr: :9002
================================================
FILE: management/webserver/go.mod
================================================
module chaitin.cn/patronus/safeline-2/management/webserver
go 1.21
toolchain go1.21.3
require (
chaitin.cn/dev/go/errors v0.0.0-20210324055134-dc5247602af6
chaitin.cn/dev/go/log v0.0.0-20221220104336-05125760b10c
chaitin.cn/dev/go/settings v0.0.0-20221220104336-05125760b10c
github.com/gin-contrib/sessions v0.0.5
github.com/gin-gonic/gin v1.10.0
github.com/pquerna/otp v1.4.0
github.com/robfig/cron/v3 v3.0.1
github.com/rogpeppe/go-internal v1.10.0
github.com/sirupsen/logrus v1.4.2
google.golang.org/grpc v1.65.0
gorm.io/datatypes v1.1.1
gorm.io/driver/postgres v1.5.9
gorm.io/gorm v1.25.10
)
require (
github.com/boombuler/barcode v1.0.1-0.20190219062509-6c824513bacc // indirect
github.com/bytedance/sonic v1.11.6 // indirect
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.20.0 // indirect
github.com/go-sql-driver/mysql v1.7.0 // indirect
github.com/goccy/go-json v0.10.2 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/gorilla/context v1.1.1 // indirect
github.com/gorilla/securecookie v1.1.1 // indirect
github.com/gorilla/sessions v1.2.1 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect
github.com/jackc/pgx/v5 v5.5.5 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/now v1.1.5 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/cpuid/v2 v2.2.7 // indirect
github.com/konsorten/go-windows-terminal-sequences v1.0.2 // indirect
github.com/leodido/go-urn v1.4.0 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.2.12 // indirect
golang.org/x/arch v0.8.0 // indirect
golang.org/x/sys v0.20.0 // indirect
golang.org/x/text v0.15.0 // indirect
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
google.golang.org/genproto v0.0.0-20230110181048-76db0878b65f // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
gorm.io/driver/mysql v1.4.7 // indirect
)
================================================
FILE: management/webserver/go.sum
================================================
chaitin.cn/dev/go/errors v0.0.0-20200717101723-df6132d53dc8/go.mod h1:u+ZD0shdyUt0UG9XfCgD1R5mSqXpTVoO5rwQXQeo3Eo=
chaitin.cn/dev/go/errors v0.0.0-20210324055134-dc5247602af6 h1:1Qa9ABk907/9ZrOLbbRcS8Fqq9VhjAF/mLjbSP1qAJY=
chaitin.cn/dev/go/errors v0.0.0-20210324055134-dc5247602af6/go.mod h1:u+ZD0shdyUt0UG9XfCgD1R5mSqXpTVoO5rwQXQeo3Eo=
chaitin.cn/dev/go/log v0.0.0-20221220104336-05125760b10c h1:Xn9IYkxmnpDcEpV+7JIR5ufEIexd1dhqKwpOLG1mYOE=
chaitin.cn/dev/go/log v0.0.0-20221220104336-05125760b10c/go.mod h1:xJIYwUoA2TX5mNg/RBrEPyE251BPwj+70/mM7UIhoxg=
chaitin.cn/dev/go/settings v0.0.0-20221220104336-05125760b10c h1:tXsraF7o9iUsQY6IwpDJusc6OFhB7iv/bBTfgR3MPUU=
chaitin.cn/dev/go/settings v0.0.0-20221220104336-05125760b10c/go.mod h1:fUvtmpG8Z8Zf5aciadL9a/vn5SB3knG7pdNJixDplPg=
github.com/boombuler/barcode v1.0.1-0.20190219062509-6c824513bacc h1:biVzkmvwrH8WK8raXaxBx6fRVTlJILwEwQGL1I/ByEI=
github.com/boombuler/barcode v1.0.1-0.20190219062509-6c824513bacc/go.mod h1:paBWMcWSl3LHKBqUq+rly7CNSldXjb2rDl3JlRe0mD8=
github.com/bytedance/sonic v1.5.0/go.mod h1:ED5hyg4y6t3/9Ku1R6dU/4KyJ48DZ4jPhfY1O2AihPM=
github.com/bytedance/sonic v1.8.0 h1:ea0Xadu+sHlu7x5O3gKhRpQ1IKiMrSiHttPF0ybECuA=
github.com/bytedance/sonic v1.8.0/go.mod h1:i736AoUSYt75HyZLoJW9ERYxcy6eaN6h4BZXU064P/U=
github.com/bytedance/sonic v1.11.6/go.mod h1:LysEHSvpvDySVdC2f87zGWf6CIKJcAvqab1ZaiQtds4=
github.com/bytedance/sonic/loader v0.1.1/go.mod h1:ncP89zfokxS5LZrJxl5z0UJcsk4M4yY2JpfqGeCtNLU=
github.com/chenzhuoyu/base64x v0.0.0-20211019084208-fb5309c8db06/go.mod h1:DH46F32mSOjUmXrMHnKwZdA8wcEefY7UVqBKYGjpdQY=
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 h1:qSGYFH7+jGhDF8vLC+iwCD4WpbV1EBDSzWkJODFLams=
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311/go.mod h1:b583jCggY9gE99b6G5LEC39OIiVsWj+R97kbl5odCEk=
github.com/cloudwego/base64x v0.1.4/go.mod h1:0zlkT4Wn5C6NdauXdJRhSKRlJvmclQ1hhJgA0rcu/8w=
github.com/cloudwego/iasm v0.2.0/go.mod h1:8rXZaNYT2n95jn+zTI1sDr+IgcD2GVs0nlbbQPiEFhY=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/gin-contrib/sessions v0.0.5 h1:CATtfHmLMQrMNpJRgzjWXD7worTh7g7ritsQfmF+0jE=
github.com/gin-contrib/sessions v0.0.5/go.mod h1:vYAuaUPqie3WUSsft6HUlCjlwwoJQs97miaG2+7neKY=
github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE=
github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
github.com/gin-gonic/gin v1.9.0 h1:OjyFBKICoexlu99ctXNR2gg+c5pKrKMuyjgARg9qeY8=
github.com/gin-gonic/gin v1.9.0/go.mod h1:W1Me9+hsUSyj3CePGrd1/QrKJMSJ1Tu/0hFEH89961k=
github.com/gin-gonic/gin v1.10.0/go.mod h1:4PMNQiOhvDRa013RKVbsiNwoyezlm2rm0uX/T7kzp5Y=
github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s=
github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA=
github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY=
github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY=
github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=
github.com/go-playground/validator/v10 v10.11.2 h1:q3SHpufmypg+erIExEKUmsgmhDTyhcJ38oeKGACXohU=
github.com/go-playground/validator/v10 v10.11.2/go.mod h1:NieE624vt4SCTJtD87arVLvdmjPAeV8BQlHtMnw9D7s=
github.com/go-playground/validator/v10 v10.20.0/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM=
github.com/go-sql-driver/mysql v1.7.0 h1:ueSltNNllEqE3qcWBTD0iQd3IpL/6U+mJxLkazJ7YPc=
github.com/go-sql-driver/mysql v1.7.0/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI=
github.com/goccy/go-json v0.10.0 h1:mXKd9Qw4NuzShiRlOXKews24ufknHO7gx30lsDyokKA=
github.com/goccy/go-json v0.10.0/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
github.com/golang-sql/civil v0.0.0-20220223132316-b832511892a9 h1:au07oEsX2xN0ktxqI+Sida1w446QrXBRJ0nee3SNZlA=
github.com/golang-sql/sqlexp v0.1.0 h1:ZCD6MBpcuOVfGVqsEmY5/4FtYiKz6tSyUv9LPEDei6A=
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw=
github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/gorilla/context v1.1.1 h1:AWwleXJkX/nhcU9bZSnZoi3h/qGYqQAGhq6zZe/aQW8=
github.com/gorilla/context v1.1.1/go.mod h1:kBGZzfjB9CEq2AlWe17Uuf7NDRt0dE0s8S51q0aT7Yg=
github.com/gorilla/securecookie v1.1.1 h1:miw7JPhV+b/lAHSXz4qd/nN9jRiAFV5FwjeKyCS8BvQ=
github.com/gorilla/securecookie v1.1.1/go.mod h1:ra0sb63/xPlUeL+yeDciTfxMRAA+MP+HVt/4epWDjd4=
github.com/gorilla/sessions v1.2.1 h1:DHd3rPN5lE3Ts3D8rKkQ8x/0kqfeNmBAaiSi+o7FsgI=
github.com/gorilla/sessions v1.2.1/go.mod h1:dk2InVEVJ0sfLlnXv9EAgkf6ecYs/i80K/zI+bUmuGM=
github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM=
github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg=
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a h1:bbPeKD0xmW/Y25WS6cokEszi5g+S0QxI/d45PkRi7Nk=
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM=
github.com/jackc/pgx/v5 v5.3.0 h1:/NQi8KHMpKWHInxXesC8yD4DhkXPrVhmnwYkjp9AmBA=
github.com/jackc/pgx/v5 v5.3.0/go.mod h1:t3JDKnCBlYIc0ewLF0Q7B8MXmoIaBOZj/ic7iHozM/8=
github.com/jackc/pgx/v5 v5.5.5/go.mod h1:ez9gk+OAat140fv9ErkZDYFWmXLfV+++K0uAOiwgm1A=
github.com/jackc/puddle/v2 v2.2.0/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4=
github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E=
github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
github.com/jinzhu/now v1.1.4/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ=
github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
github.com/klauspost/cpuid/v2 v2.0.9 h1:lgaqFMSdTdQYdZ04uHyN2d/eKdOMyi2YLSvlQIBFYa4=
github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
github.com/klauspost/cpuid/v2 v2.2.7/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws=
github.com/knz/go-libedit v1.10.1/go.mod h1:MZTVkCWyz0oBc7JOWP3wNAzd002ZbM/5hgShxwh4x8M=
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/konsorten/go-windows-terminal-sequences v1.0.2 h1:DB17ag19krx9CFsz4o3enTrPXyIXCl+2iCXH/aMAp9s=
github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0=
github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/leodido/go-urn v1.2.1 h1:BqpAaACuzVSgi/VLzGZIobT2z4v53pjosyNd9Yv6n/w=
github.com/leodido/go-urn v1.2.1/go.mod h1:zt4jvISO2HfUBqxjfIshjdMTYS56ZS/qv49ictyFfxY=
github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI=
github.com/mattn/go-isatty v0.0.17 h1:BTarxUcIeDqL27Mc+vyvdWYSL28zpIhv3RoTdsLMPng=
github.com/mattn/go-isatty v0.0.17/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-sqlite3 v2.0.3+incompatible h1:gXHsfypPkaMZrKbD5209QV9jbUTJKjyR5WD3HYQSd+U=
github.com/microsoft/go-mssqldb v0.17.0 h1:Fto83dMZPnYv1Zwx5vHHxpNraeEaUlQ/hhHLgZiaenE=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 h1:ZqeYNhU3OHLH3mGKHDcjJRFFRrJa6eAM5H+CtDdOsPc=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
github.com/pelletier/go-toml/v2 v2.0.6 h1:nrzqCb7j9cDFj2coyLNLaZuJTLjWjlaz6nvTvIwycIU=
github.com/pelletier/go-toml/v2 v2.0.6/go.mod h1:eumQOmlWiOPt5WriQQqoM5y18pDHwha2N+QD+EUNTek=
github.com/pelletier/go-toml/v2 v2.2.2/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h4qDAS4n929Rs=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/pquerna/otp v1.4.0 h1:wZvl1TIVxKRThZIBiwOOHOGP/1+nZyWBil9Y2XNEDzg=
github.com/pquerna/otp v1.4.0/go.mod h1:dkJfzwRKNiegxyNb54X/3fLwhCynbMspSyWKnvi1AEg=
github.com/robfig/cron/v3 v3.0.1 h1:WdRxkvbJztn8LMz/QEvLN5sBU+xKpSqwwUO1Pjr4qDs=
github.com/robfig/cron/v3 v3.0.1/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzGIFLtro=
github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc=
github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ=
github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog=
github.com/sirupsen/logrus v1.4.2 h1:SPIRibHv4MatM3XXNO2BJeFLZwZ2LvZgfQ5+UNI2im4=
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI=
github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08=
github.com/ugorji/go/codec v1.2.9 h1:rmenucSohSTiyL09Y+l2OCk+FrMxGMzho2+tjr5ticU=
github.com/ugorji/go/codec v1.2.9/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg=
github.com/ugorji/go/codec v1.2.12/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
golang.org/x/arch v0.0.0-20210923205945-b76863e36670 h1:18EFjUmQOcUvxNYSkA6jO9VAiXCnxFY6NyDX0bHDmkU=
golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8=
golang.org/x/arch v0.8.0/go.mod h1:FEVrYAQjsQXMVJ1nsMoVVXPZg6p2JE2mx8psSWTDQys=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.6.0/go.mod h1:OFC/31mSvZgRz0V1QTNCzfAI1aIRzbiufJtkMIlEp58=
golang.org/x/crypto v0.7.0 h1:AvwMYaRytfdeVt3u6mLaxYtErKYjxA2OXjJ1HHq6t3A=
golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU=
golang.org/x/crypto v0.17.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
golang.org/x/net v0.8.0 h1:Zrh2ngAOFYneWTAIAPethzeaQLuHwhuBkuV6ZiRnUaQ=
golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc=
golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.8.0 h1:57P1ETyNKtuIjB4SRd15iJxuhj8Gc416Y78H3qgMh68=
golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/genproto v0.0.0-20230110181048-76db0878b65f h1:BWUVssLB0HVOSY78gIdvk1dTVYtT1y8SBWtPYuTJ/6w=
google.golang.org/genproto v0.0.0-20230110181048-76db0878b65f/go.mod h1:RGgjbofJ8xD9Sq1VVhDM1Vok1vRONV+rg+CjzG4SZKM=
google.golang.org/grpc v1.54.0 h1:EhTqbhiYeixwWQtAEZAxmV9MGqcjEU2mFx52xCzNyag=
google.golang.org/grpc v1.54.0/go.mod h1:PUSEXI6iWghWaB6lXM4knEgpJNu2qUcKfDtNci3EC2g=
google.golang.org/grpc v1.65.0/go.mod h1:WgYC2ypjlB0EiQi6wdKixMqukr6lBc0Vo+oOgjrM5ZQ=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.28.1 h1:d0NfwRgPtno5B1Wa6L2DAG+KivqkdutMf1UhdNx175w=
google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.7/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10=
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gorm.io/datatypes v1.1.1 h1:XAjO7NNfUKVUvnS3+BkqMrPXxCAcxDlpOYbjnizxNCw=
gorm.io/datatypes v1.1.1/go.mod h1:u8GEgFjJ+GpsGfgHmBUcQqHm/937t3sj/SO9dvbndTg=
gorm.io/driver/mysql v1.4.7 h1:rY46lkCspzGHn7+IYsNpSfEv9tA+SU4SkkB+GFX125Y=
gorm.io/driver/mysql v1.4.7/go.mod h1:SxzItlnT1cb6e1e4ZRpgJN2VYtcqJgqnHxWr4wsP8oc=
gorm.io/driver/postgres v1.5.0 h1:u2FXTy14l45qc3UeCJ7QaAXZmZfDDv0YrthvmRq1l0U=
gorm.io/driver/postgres v1.5.0/go.mod h1:FUZXzO+5Uqg5zzwzv4KK49R8lvGIyscBOqYrtI1Ce9A=
gorm.io/driver/postgres v1.5.9/go.mod h1:DX3GReXH+3FPWGrrgffdvCk3DQ1dwDPdmbenSkweRGI=
gorm.io/driver/sqlite v1.4.3 h1:HBBcZSDnWi5BW3B3rwvVTc510KGkBkexlOg0QrmLUuU=
gorm.io/driver/sqlserver v1.4.1 h1:t4r4r6Jam5E6ejqP7N82qAJIJAht27EGT41HyPfXRw0=
gorm.io/gorm v1.23.8/go.mod h1:l2lP/RyAtc1ynaTjFksBde/O8v9oOGIApu2/xRitmZk=
gorm.io/gorm v1.24.7-0.20230306060331-85eaf9eeda11 h1:9qNbmu21nNThCNnF5i2R3kw2aL27U8ZwbzccNjOmW0g=
gorm.io/gorm v1.24.7-0.20230306060331-85eaf9eeda11/go.mod h1:L4uxeKpfBml98NYqVqwAdmV1a2nBtAec/cf3fpucW/k=
gorm.io/gorm v1.25.10/go.mod h1:hbnx/Oo0ChWMn1BIhpy1oYozzpM15i4YPuHDmfYtwg8=
nullprogram.com/x/optparse v1.0.0/go.mod h1:KdyPE+Igbe0jQUrVfMqDMeJQIJZEuyV7pjYmp6pbG50=
rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4=
================================================
FILE: management/webserver/main.go
================================================
package main
import (
"flag"
"fmt"
"net/http"
"os"
"strconv"
"strings"
"time"
"github.com/gin-contrib/sessions"
"github.com/gin-contrib/sessions/cookie"
"github.com/gin-gonic/gin"
"chaitin.cn/patronus/safeline-2/management/webserver/api"
"chaitin.cn/patronus/safeline-2/management/webserver/cmd"
"chaitin.cn/patronus/safeline-2/management/webserver/middleware"
"chaitin.cn/patronus/safeline-2/management/webserver/model"
"chaitin.cn/patronus/safeline-2/management/webserver/pkg/config"
"chaitin.cn/patronus/safeline-2/management/webserver/pkg/constants"
"chaitin.cn/patronus/safeline-2/management/webserver/pkg/cron"
"chaitin.cn/patronus/safeline-2/management/webserver/pkg/database"
"chaitin.cn/patronus/safeline-2/management/webserver/pkg/fvm"
"chaitin.cn/patronus/safeline-2/management/webserver/pkg/log"
"chaitin.cn/patronus/safeline-2/management/webserver/rpc"
)
var (
logger = log.GetLogger("main")
version = "undefined"
githash = "undefined"
buildstamp = "undefined"
goVersion = "undefined"
)
func init() {
// do something that do not raise error
}
func main() {
log.SetLogFormatter()
fs := flag.NewFlagSet("webserver", flag.ExitOnError)
showVersion := fs.Bool("v", false, "show version")
cfgFile := fs.String("c", constants.ConfigFilePath, "config file path")
genCerts := fs.Bool("gen_certs", false, "generate certs")
showFSL := fs.Bool("show_fsl", false, "show full selectors")
push_fsl := fs.Bool("push_fsl", false, "compile and push fsl")
fakeLogs := fs.Bool("fake_logs", false, "fake logs")
resetUsername := fs.String("reset_user", "", "reset user")
if err := fs.Parse(os.Args[1:]); err != nil {
logger.Fatalln("Failed to parse args: ", err)
}
if *showVersion {
i, _ := strconv.Atoi(buildstamp)
t := time.Unix(int64(i), 0).Format("2006-01-02 15:04:05")
fmt.Println("Version: ", version)
fmt.Println("Githash: ", githash)
fmt.Println("Build: ", t)
fmt.Println("Go version: ", goVersion)
return
}
constants.Version = strings.TrimPrefix(version, "ce-")
// init configs
if err := config.InitConfigs(*cfgFile); err != nil {
logger.Fatalln("Failed to init configs: ", err)
}
if err := log.InitLogger(); err != nil {
logger.Fatalln("Failed to init db: ", err)
}
if *genCerts {
if err := cmd.GenCerts(); err != nil {
logger.Fatalln("Failed to generate certs: ", err)
}
return
}
logger.Info("Init database")
if err := database.InitDB(); err != nil {
logger.Fatalln("Failed to init db: ", err)
}
if *showFSL {
if fullFSL, err := cmd.ShowFSL(); err != nil {
logger.Fatalln("Failed to generate fsl: ", err)
} else {
logger.Info(strings.ReplaceAll(strings.ReplaceAll(fullFSL, ";", ";\n"), "CREATE", "\nCREATE"))
}
return
}
logger.Info("Init models")
if err := model.InitModels(); err != nil {
logger.Fatalln("Failed to init models: ", err)
}
if len(*resetUsername) > 0 {
logger.Infoln("reset user:", *resetUsername)
cmd.ResetUser(*resetUsername)
logger.Infoln("success!")
return
}
if *fakeLogs {
logger.Infoln("faking logs...")
cmd.FakeLogs()
logger.Infoln("success!")
return
}
if *push_fsl {
logger.Infoln("push fsl...")
if err := cmd.PushFSL(); err != nil {
logger.Fatalln("Failed to generate fsl: ", err)
}
logger.Infoln("success!")
return
}
logger.Info("Init FVM bytecode")
fvm.InitFVMBytecode()
if err := cron.StartCron(); err != nil {
logger.Fatalln("Failed to start cron: ", err)
}
if err := rpc.StartGRPCSever(); err != nil {
logger.Fatalln("Failed to start gRPC server: ", err)
}
gin.SetMode(gin.ReleaseMode)
r := gin.Default()
var option model.Options
database.GetDB().Where(&model.Options{Key: constants.SecretKey}).First(&option)
logger.Debugf("Secret: %s", option.Value)
store := cookie.NewStore([]byte(option.Value))
r.Use(sessions.Sessions("session", store))
publicRouters := r.Group("/api")
publicRouters.POST(api.Login, api.PostLogin)
publicRouters.POST(api.Logout, api.PostLogout)
publicRouters.POST(api.Behaviour, api.PostBehaviour)
publicRouters.POST(api.FalsePositives, api.PostFalsePositives)
publicRouters.GET(api.OTPUrl, api.GetOTPUrl)
publicRouters.GET(api.Version, api.GetVersion)
publicRouters.GET(api.UpgradeTips, api.GetUpgradeTips)
// test use
publicRouters.GET("/Ping", func(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{
"message": "pong",
})
})
limitedRouters := r.Group("/api")
noAuth, existed := os.LookupEnv("NO_AUTH")
if existed && len(noAuth) >= 0 {
logger.Warn("No auth")
} else {
limitedRouters.Use(middleware.AuthRequired)
}
readOnly, existed := os.LookupEnv("READ_ONLY")
if existed && len(readOnly) >= 0 {
logger.Warn("Read only")
limitedRouters.Use(middleware.ReadOnly)
}
limitedRouters.GET(api.User, api.GetUser)
limitedRouters.GET(api.DetectLogList, api.GetDetectLogList)
limitedRouters.GET(api.DetectLogDetail, api.GetDetectLogDetail)
limitedRouters.POST(api.Website, api.PostWebsite)
limitedRouters.PUT(api.Website, api.PutWebsite)
limitedRouters.DELETE(api.Website, api.DeleteWebsite)
limitedRouters.GET(api.Website, api.GetWebsite)
limitedRouters.POST(api.UploadSSLCert, api.PostUploadSSLCert)
limitedRouters.POST(api.SSLCert, api.PostSSLCert)
limitedRouters.POST(api.PolicyRule, api.PostPolicyRule)
limitedRouters.PUT(api.PolicyRule, api.PutPolicyRule)
limitedRouters.DELETE(api.PolicyRule, api.DeletePolicyRule)
limitedRouters.GET(api.PolicyRule, api.GetPolicyRule)
limitedRouters.PUT(api.SwitchPolicyRule, api.PutSwitchPolicyRule)
// 仪表盘接口
limitedRouters.GET(api.DashboardCounts, api.GetDashboardCounts)
limitedRouters.GET(api.DashboardSites, api.GetDashboardSites)
limitedRouters.GET(api.DashboardQps, api.GetDashboardQps)
limitedRouters.GET(api.DashboardRequests, api.GetDashboardRequests)
limitedRouters.GET(api.DashboardIntercepts, api.GetDashboardIntercepts)
limitedRouters.GET(api.PolicyGroupGlobal, api.GetPolicyGroupGlobal)
limitedRouters.PUT(api.PolicyGroupGlobal, api.PutPolicyGroupGlobal)
limitedRouters.GET(api.SrcIPConfig, api.GetSrcIPConfig)
limitedRouters.PUT(api.SrcIPConfig, api.PutSrcIPConfig)
logger.Info("Staring...")
if err := r.Run(config.GlobalConfig.Server.ListenAddr); err != nil {
logger.Fatalln("Error occurred when running web server: ", err)
}
}
================================================
FILE: management/webserver/middleware/auth.go
================================================
package middleware
import (
"net/http"
"github.com/gin-contrib/sessions"
"github.com/gin-gonic/gin"
"chaitin.cn/patronus/safeline-2/management/webserver/api/response"
"chaitin.cn/patronus/safeline-2/management/webserver/pkg/constants"
)
func AuthRequired(c *gin.Context) {
session := sessions.Default(c)
user := session.Get(constants.DefaultSessionUserKey)
if user == nil {
response.Error(c, response.ErrorLoginRequired, http.StatusUnauthorized)
c.Abort()
return
}
// extend session expired time
session.Options(sessions.Options{
Path: "/",
MaxAge: 3600 * 24 * 7,
//Domain: options.Domain,
//HttpOnly: true,
//SameSite: http.SameSiteLaxMode,
//Secure: false,
})
if err := session.Save(); err != nil {
response.Error(c, response.JSONBody{Err: response.ErrInternalError, Msg: "Error occurred when creating sessions"}, http.StatusInternalServerError)
return
}
c.Next()
}
func ReadOnly(c *gin.Context) {
if c.Request.Method != "GET" && c.Request.Method != "HEAD" && c.Request.Method != "OPTIONS" {
response.Error(c, response.ErrorReadOnly, http.StatusBadRequest)
c.Abort()
}
}
================================================
FILE: management/webserver/model/base.go
================================================
package model
import (
"time"
"chaitin.cn/patronus/safeline-2/management/webserver/pkg/log"
)
// Base is a replacement for gorm.Model without DeletedAt, which is considered to be not good.
type Base struct {
ID uint `gorm:"primarykey" json:"id"`
CreatedAt time.Time ` json:"created_at"`
UpdatedAt time.Time ` json:"updated_at"`
}
var logger = log.GetLogger("model")
================================================
FILE: management/webserver/model/behaviour.go
================================================
package model
type Behaviour struct {
Base
SrcRouter string `json:"src_router"`
DstRouter string `json:"dst_router"`
}
================================================
FILE: management/webserver/model/db_patch_1_4_0.go
================================================
package model
import (
"strings"
"chaitin.cn/dev/go/errors"
"gorm.io/gorm"
)
type sqlResult struct {
Ids string `json:"ids"`
}
func DBPatch140(tx *gorm.DB) error {
if !tx.Migrator().HasTable(&SystemStatistics{}) {
return nil
}
var result []sqlResult
//SELECT string_agg(id::text, ',') as ids FROM mgt_system_statistics GROUP BY (type, website, created_at) HAVING COUNT(*) > 1) as tmp
res := tx.Model(&SystemStatistics{}).Select("string_agg(id::text, ',') as ids").Group("type, website, created_at").Having("COUNT(*) > 1").Find(&result)
if res.Error != nil {
return errors.Wrap(res.Error, "Failed to select data")
}
if len(result) <= 0 {
return nil
}
var deleteIds []string
for _, s := range result {
tmpIds := strings.Split(s.Ids, ",")
deleteIds = append(deleteIds, tmpIds...)
}
deleteRes := tx.Delete(&SystemStatistics{}, deleteIds)
return errors.Wrap(deleteRes.Error, "Failed to delete")
}
================================================
FILE: management/webserver/model/detectlog.go
================================================
package model
import (
"fmt"
"math/rand"
"strings"
"time"
"chaitin.cn/dev/go/errors"
"chaitin.cn/patronus/safeline-2/management/webserver/pkg/constants"
"chaitin.cn/patronus/safeline-2/management/webserver/pkg/database"
"chaitin.cn/patronus/safeline-2/management/webserver/utils"
)
// DetectLog is designed to be used in response, not a good naming.
type DetectLog struct {
DetectLogBasic
DetectLogDetail
EventId string `json:"event_id"` // to eliminate ambiguous
Website string `json:"website"`
AttackType string `json:"attack_type"`
Module string `json:"module"`
Reason string `json:"reason"`
}
func getRuleModule(ruleId string, attackType int) string {
var module string
if strings.HasPrefix(ruleId, "m_rule") { // `m_rule/65543`
module = "m_rule"
} else if strings.HasPrefix(ruleId, "/") {
if attackType == -2 {
module = "whitelist"
} else { // if attackType == -3
module = "blacklist"
}
} else {
module = ruleId
}
return constants.RuleModule[module]
}
func getRuleReason(ruleId string, attackType int) string {
var reason string
if strings.HasPrefix(ruleId, "m_rule") { // `m_rule/65543`
reason = constants.RuleReason[strings.ReplaceAll(ruleId, "m_rule/", "")]
} else if strings.HasPrefix(ruleId, "/") {
reason = ruleId[1:]
} else {
reason = fmt.Sprintf("检测到 %s 攻击", getAttackType(attackType))
}
return reason
}
func getAttackType(at int) string {
atStr, ok := constants.AttackType[at]
if !ok {
atStr = constants.AttackType[62] // unknown
}
return atStr
}
func getCountry(country string) string {
countryStr, ok := constants.CountryCode[country]
if !ok {
countryStr = ""
}
return countryStr
}
func TransformDetectLog(basic *DetectLogBasic, detail *DetectLogDetail) (*DetectLog, error) {
if basic == nil {
return nil, errors.New("basic *DetectLogBasic cannot be nil")
}
if detail != nil && basic.EventId != detail.EventId {
return nil, errors.New("EventId field should be the same for basic and detail")
}
basic.Country = getCountry(basic.Country)
dLog := DetectLog{
DetectLogBasic: *basic,
EventId: basic.EventId,
Website: utils.BuildUrl(basic.Protocol, basic.Host, basic.DstPort, basic.UrlPath),
AttackType: getAttackType(basic.AttackType),
Module: getRuleModule(basic.RuleId, basic.AttackType),
Reason: getRuleReason(basic.RuleId, basic.AttackType),
}
if detail != nil {
dLog.DetectLogDetail = *detail
}
return &dLog, nil
}
type DetectLogBasic struct {
ID uint `json:"id" gorm:"primarykey"`
EventId string `json:"event_id" gorm:"uniqueIndex;not null"`
SiteUUID string `json:"site_uuid" gorm:"column:site_uuid"`
SrcIp string `json:"src_ip" gorm:"index"`
SocketIp string `json:"socket_ip" gorm:"index"`
Protocol int `json:"protocol"`
Host string `json:"host"`
UrlPath string `json:"url_path"`
DstPort uint `json:"dst_port"`
Country string `json:"country"`
Province string `json:"province"`
City string `json:"city"`
AttackType int `json:"attack_type" gorm:"index"`
RiskLevel int `json:"risk_level" gorm:"index"`
Action int `json:"action" gorm:"index"`
RuleId string `json:"rule_id"`
Timestamp int64 `json:"timestamp" gorm:"index"`
}
type DetectLogDetail struct {
ID uint ` gorm:"primarykey"`
EventId string ` gorm:"uniqueIndex;not null"`
SrcPort uint `json:"src_port"`
DstIp string `json:"dst_ip"`
Method string `json:"method"`
QueryString string `json:"query_string"`
StatusCode uint `json:"status_code"`
ReqHeader string `json:"req_header"`
ReqBody string `json:"req_body"`
RspHeader string `json:"rsp_header"`
RspBody string `json:"rsp_body"`
Payload string `json:"payload"`
Location string `json:"location"`
DecodePath string `json:"decode_path"`
}
func InitDetectLogSamples() {
db := database.GetDB()
var detectLogBasicList []DetectLogBasic
var detectLogDetailList []DetectLogDetail
timestamp := time.Now().Unix()
detail := DetectLogDetail{
SrcPort: 58694,
DstIp: "10.2.35.143",
Method: "GET",
QueryString: "",
ReqHeader: "GET /webshell.php HTTP/1.1\nUser-Agent: curl/7.77.0\nAccept: */*\n\n\"",
ReqBody: "",
RspHeader: "",
RspBody: "",
Payload: "",
Location: "urlpath",
DecodePath: "",
}
protocolList := []int{constants.ProtocolHTTP, constants.ProtocolHTTPS}
portList := []uint{80, 443}
provinceList := []string{}
cityList := []string{}
ipList := []string{}
ruleIdList := []string{}
for i := 0; i < 100; i++ {
randInt := rand.Intn(1000)
eventId := utils.RandStr(32)
basic := DetectLogBasic{}
basic.EventId = eventId
basic.SrcIp = ipList[randInt%len(ipList)]
basic.SocketIp = ipList[randInt%len(ipList)]
basic.Protocol = protocolList[randInt%len(protocolList)]
basic.DstPort = portList[randInt%len(portList)]
basic.Host = fmt.Sprintf("%s.com", utils.RandStr(5))
basic.UrlPath = fmt.Sprintf("/%s", utils.RandStr(10))
basic.Country = "CN"
basic.Province = provinceList[randInt%len(provinceList)]
basic.City = cityList[randInt%len(cityList)]
basic.AttackType = randInt % 32
basic.RiskLevel = randInt % 4
basic.Action = randInt % 2
basic.RuleId = ruleIdList[randInt%len(ruleIdList)]
basic.Timestamp = timestamp - int64(randInt*100)
detailCopy := detail
detailCopy.EventId = eventId
detectLogBasicList = append(detectLogBasicList, basic)
detectLogDetailList = append(detectLogDetailList, detailCopy)
}
db.CreateInBatches(detectLogBasicList, 100)
db.CreateInBatches(detectLogDetailList, 100)
}
================================================
FILE: management/webserver/model/init.go
================================================
package model
import (
"gorm.io/gorm"
"chaitin.cn/patronus/safeline-2/management/webserver/pkg/database"
)
func InitModels() error {
db := database.GetDB()
err := db.Transaction(func(tx *gorm.DB) error {
//
if err := DBPatch140(tx); err != nil {
return err
}
return nil
})
if err != nil {
return err
}
if err := db.AutoMigrate(&User{}, &DetectLogBasic{}, &DetectLogDetail{}, &Behaviour{}, &Options{}, &Website{}, &PolicyRule{}, &SystemStatistics{}); err != nil {
return err
}
if err := initAdminUser(); err != nil {
return err
}
if err := initOptions(); err != nil {
return err
}
if err := initPolicyGroupGlobal(); err != nil {
return err
}
if err := initSrcIPConfig(); err != nil {
return err
}
//InitDetectLogSamples()
return nil
}
================================================
FILE: management/webserver/model/option.go
================================================
package model
import (
"bytes"
"encoding/json"
"net/http"
"gorm.io/gorm/clause"
"chaitin.cn/patronus/safeline-2/management/webserver/pkg/config"
"chaitin.cn/patronus/safeline-2/management/webserver/pkg"
"chaitin.cn/patronus/safeline-2/management/webserver/pkg/constants"
"chaitin.cn/patronus/safeline-2/management/webserver/pkg/database"
"chaitin.cn/patronus/safeline-2/management/webserver/utils"
)
type Options struct {
Base
Key string `gorm:"column:key;uniqueIndex"`
Value string `gorm:"column:value;"`
}
func initOptions() error {
db := database.GetDB()
secretKey := Options{Key: constants.SecretKey, Value: utils.RandStr(32)}
db.Clauses(clause.OnConflict{DoNothing: true}).Create(&secretKey)
machineId := Options{Key: constants.MachineID, Value: utils.RandStr(32)}
_ = db.Clauses(clause.OnConflict{DoNothing: true}).Create(&machineId)
go NotifyInstallation(machineId.Value)
return nil
}
func NotifyInstallation(machineId string) {
logger.Info("Notify installation")
tr := pkg.TelemetryRequest{
Telemetry: pkg.TelemetryInfo{
Id: constants.TelemetryId,
},
Safeline: pkg.SafelineInfo{
Id: machineId,
Type: constants.Installation,
Version: constants.Version,
},
}
data, err := json.Marshal(tr)
if err != nil {
logger.Error(err)
return
}
reader := bytes.NewReader(data)
rsp, err := pkg.DoPostTelemetry(utils.GetHTTPClient(), config.GlobalConfig.Telemetry.Addr, reader)
if err != nil {
logger.Error(err)
return
}
if rsp.StatusCode != http.StatusOK && rsp.StatusCode != http.StatusCreated {
logger.Errorf("transfer telemetry %s failed, status code = %d", constants.Installation, rsp.StatusCode)
return
}
}
================================================
FILE: management/webserver/model/policygroup.go
================================================
package model
import (
"encoding/json"
"gorm.io/gorm"
"gorm.io/gorm/clause"
"chaitin.cn/dev/go/errors"
"chaitin.cn/patronus/safeline-2/management/webserver/pkg/constants"
"chaitin.cn/patronus/safeline-2/management/webserver/pkg/database"
)
type PolicyGroup map[string]string
const (
StrictMode = "strict"
DefaultMode = "default"
DisableMode = "disable"
SocketIP = "socket_ip"
HTTPHeader = "http_header"
)
type SrcIPConfig struct {
Source string `json:"source"` // socket_ip, http_header
Value string `json:"value"`
}
type SkynetConfigModule struct {
DetectConfig interface{} `json:"detect_config,omitempty"`
HighRiskAction string `json:"high_risk_action"`
MediumRiskAction string `json:"medium_risk_action"`
LowRiskAction string `json:"low_risk_action"`
HighRiskEnableLog int `json:"high_risk_enable_log"`
MediumRiskEnableLog int `json:"medium_risk_enable_log"`
LowRiskEnableLog int `json:"low_risk_enable_log"`
State string `json:"state"`
}
type SkynetConfig struct {
DetectConfig string `json:"detect_config"`
DeepDetect bool `json:"deep_detect"`
Timeout interface{} `json:"timeout"`
Modules map[string]*SkynetConfigModule `json:"modules"`
}
func GetSrcIPConfig(db *gorm.DB) (*SrcIPConfig, error) {
var scOption Options
db.Where(&Options{Key: constants.SrcIPConfig}).First(&scOption)
var sc SrcIPConfig
err := json.Unmarshal([]byte(scOption.Value), &sc)
if err != nil {
return nil, err
}
return &sc, nil
}
func initSrcIPConfig() error {
db := database.GetDB()
// policyGroupGlobal config, three mode: strict/default/disable
var srcIPConfig = SrcIPConfig{
Source: SocketIP,
Value: "",
}
scStr, err := json.Marshal(srcIPConfig)
if err != nil {
return err
}
pgg := Options{Key: constants.SrcIPConfig, Value: string(scStr)}
db.Clauses(clause.OnConflict{DoNothing: true}).Create(&pgg)
return nil
}
func GetSkynetConfig(db *gorm.DB) (string, error) {
// skynetConfigStr skynet config in 5.3.9
const skynetConfigStr = "{\"decode_config\":{\"decode_methods\":[\"url decode\",\"JSON\",\"base64\",\"hex\",\"eval\",\"XML\",\"PHP deserialize\",\"utf7\"]},\"deep_detect\":false,\"modules\":{\"m_asp_code_injection\":{\"high_risk_action\":\"deny\",\"high_risk_enable_log\":1,\"low_risk_action\":\"continue\",\"low_risk_enable_log\":1,\"medium_risk_action\":\"continue\",\"medium_risk_enable_log\":1,\"state\":\"enabled\"},\"m_cmd_injection\":{\"high_risk_action\":\"deny\",\"high_risk_enable_log\":1,\"low_risk_action\":\"continue\",\"low_risk_enable_log\":1,\"medium_risk_action\":\"continue\",\"medium_risk_enable_log\":1,\"state\":\"enabled\"},\"m_csrf\":{\"high_risk_action\":\"deny\",\"high_risk_enable_log\":1,\"low_risk_action\":\"continue\",\"low_risk_enable_log\":1,\"medium_risk_action\":\"continue\",\"medium_risk_enable_log\":1,\"state\":\"enabled\"},\"m_file_include\":{\"detect_config\":{\"detect_suspicious_schema\":true},\"high_risk_action\":\"deny\",\"high_risk_enable_log\":1,\"low_risk_action\":\"continue\",\"low_risk_enable_log\":1,\"medium_risk_action\":\"continue\",\"medium_risk_enable_log\":1,\"state\":\"enabled\"},\"m_file_upload\":{\"detect_config\":{\"action_of_handling_custome_file\":[\"deny transmission\"],\"detect_file_content\":true,\"detect_real_file_content\":false,\"enable_module_in_detecting_file_content\":[\"java\",\"asp_code_injection\",\"php_code_injection\"],\"file_type_of_custome_action\":[],\"forbidden_extra_token\":false,\"forbidden_multiple_filename\":true,\"forbidden_suspicious_filename\":true},\"high_risk_action\":\"deny\",\"high_risk_enable_log\":1,\"low_risk_action\":\"continue\",\"low_risk_enable_log\":1,\"medium_risk_action\":\"continue\",\"medium_risk_enable_log\":1,\"state\":\"enabled\"},\"m_http\":{\"detect_config\":{\"warning_http_parse_failed\":false,\"warning_suspicious_http_version\":false},\"high_risk_action\":\"deny\",\"high_risk_enable_log\":1,\"low_risk_action\":\"continue\",\"low_risk_enable_log\":1,\"medium_risk_action\":\"continue\",\"medium_risk_enable_log\":1,\"state\":\"disabled\"},\"m_java\":{\"detect_config\":{\"detect_lookup\":false},\"high_risk_action\":\"deny\",\"high_risk_enable_log\":1,\"low_risk_action\":\"continue\",\"low_risk_enable_log\":1,\"medium_risk_action\":\"continue\",\"medium_risk_enable_log\":1,\"state\":\"enabled\"},\"m_java_unserialize\":{\"high_risk_action\":\"deny\",\"high_risk_enable_log\":1,\"low_risk_action\":\"continue\",\"low_risk_enable_log\":1,\"medium_risk_action\":\"continue\",\"medium_risk_enable_log\":1,\"state\":\"enabled\"},\"m_php_code_injection\":{\"high_risk_action\":\"deny\",\"high_risk_enable_log\":1,\"low_risk_action\":\"continue\",\"low_risk_enable_log\":1,\"medium_risk_action\":\"continue\",\"medium_risk_enable_log\":1,\"state\":\"enabled\"},\"m_php_unserialize\":{\"high_risk_action\":\"deny\",\"high_risk_enable_log\":1,\"low_risk_action\":\"continue\",\"low_risk_enable_log\":1,\"medium_risk_action\":\"continue\",\"medium_risk_enable_log\":1,\"state\":\"enabled\"},\"m_response\":{\"detect_config\":{\"detection_configure\":[\"detect_jsp_code_leak\",\"detect_php_code_leak\",\"detect_webshell\"],\"error_types\":[\"directory indexing\",\"SQL execution error\",\"server exception\"]},\"high_risk_action\":\"deny\",\"high_risk_enable_log\":1,\"low_risk_action\":\"continue\",\"low_risk_enable_log\":1,\"medium_risk_action\":\"continue\",\"medium_risk_enable_log\":1,\"state\":\"disabled\"},\"m_rule\":{\"detect_config\":{\"check_info_leak_by_rsp\":false,\"compatibility_mode\":false,\"detection_configure\":[\"detect_phpinfo\",\"detect_admin_page\",\"detect_backdoor\",\"detect_php_vuln\",\"detect_nginx\",\"detect_dedecms\",\"detect_apache\",\"detect_xml\",\"detect_struts2\",\"detect_java_vuln\",\"detect_php168\",\"detect_wordpress\",\"detect_directory_traversal\",\"detect_iis\",\"detect_gogs_gitea\",\"detect_thinkphp\",\"detect_jenkins\",\"detect_ecshop\",\"detect_nexus\",\"detect_drupal\",\"detect_ghostscript\",\"detect_atlassian\",\"detect_weblogic\",\"detect_coremail\",\"detect_phpcms\",\"detect_spring\",\"detect_southidc\",\"detect_fastjson\",\"detect_tbk_dvr\",\"detect_joomla\",\"detect_ecology_oa\",\"detect_jackson\",\"detect_xstream\",\"detect_activemq\",\"detect_solr\",\"detect_csii\",\"detect_big_ip\",\"detect_apisix\",\"detect_druid\",\"detect_log4j\"],\"info_leak_types\":[\"test file\",\"backup file\",\"code repository\",\"server sensitive file\"],\"rules_config\":{\"disable_ruleid\":[],\"enable_ruleid\":[],\"rules_status\":[]}},\"high_risk_action\":\"deny\",\"high_risk_enable_log\":1,\"low_risk_action\":\"continue\",\"low_risk_enable_log\":1,\"medium_risk_action\":\"continue\",\"medium_risk_enable_log\":1,\"state\":\"enabled\"},\"m_scanner\":{\"detect_config\":{\"language_types\":[\"python_scanner\",\"go_scanner\"],\"other_types\":[\"normal_scanner\"],\"spider_types\":[]},\"high_risk_action\":\"deny\",\"high_risk_enable_log\":1,\"low_risk_action\":\"continue\",\"low_risk_enable_log\":1,\"medium_risk_action\":\"continue\",\"medium_risk_enable_log\":1,\"state\":\"disabled\"},\"m_sqli\":{\"detect_config\":{\"detect_non_injection_sql\":true},\"high_risk_action\":\"deny\",\"high_risk_enable_log\":1,\"low_risk_action\":\"continue\",\"low_risk_enable_log\":1,\"medium_risk_action\":\"continue\",\"medium_risk_enable_log\":1,\"state\":\"enabled\"},\"m_ssrf\":{\"high_risk_action\":\"deny\",\"high_risk_enable_log\":1,\"low_risk_action\":\"continue\",\"low_risk_enable_log\":1,\"medium_risk_action\":\"continue\",\"medium_risk_enable_log\":1,\"state\":\"enabled\"},\"m_ssti\":{\"high_risk_action\":\"deny\",\"high_risk_enable_log\":1,\"low_risk_action\":\"continue\",\"low_risk_enable_log\":1,\"medium_risk_action\":\"continue\",\"medium_risk_enable_log\":1,\"state\":\"enabled\"},\"m_xss\":{\"detect_config\":{\"detect_complete_html\":true},\"high_risk_action\":\"deny\",\"high_risk_enable_log\":1,\"low_risk_action\":\"continue\",\"low_risk_enable_log\":1,\"medium_risk_action\":\"continue\",\"medium_risk_enable_log\":1,\"state\":\"enabled\"}},\"timeout\":{\"threshold\":1000,\"log\":\"enabled\"}}"
var sc SkynetConfig
err := json.Unmarshal([]byte(skynetConfigStr), &sc)
if err != nil {
return "", err
}
var pggOption Options
db.Where(&Options{Key: constants.PolicyGroupGlobal}).First(&pggOption)
var pgg PolicyGroup
err = json.Unmarshal([]byte(pggOption.Value), &pgg)
if err != nil {
return "", err
}
for module, mode := range pgg {
switch mode {
case StrictMode:
scm := sc.Modules[module]
scm.HighRiskAction = "deny"
scm.MediumRiskAction = "deny"
scm.LowRiskAction = "deny"
scm.State = "enabled"
sc.Modules[module] = scm
case DefaultMode:
scm := sc.Modules[module]
scm.HighRiskAction = "deny"
scm.MediumRiskAction = "continue"
scm.LowRiskAction = "continue"
scm.State = "enabled"
sc.Modules[module] = scm
case DisableMode:
scm := sc.Modules[module]
scm.HighRiskAction = "continue"
scm.MediumRiskAction = "continue"
scm.LowRiskAction = "continue"
scm.State = "disabled"
sc.Modules[module] = scm
default:
return "", errors.New("no such mode")
}
}
scStr, err := json.Marshal(sc)
if err != nil {
return "", err
}
return string(scStr), nil
}
func initPolicyGroupGlobal() error {
db := database.GetDB()
// policyGroupGlobal config, three mode: strict/default/disable
var policyGroupGlobal = PolicyGroup{
"m_asp_code_injection": DefaultMode,
"m_cmd_injection": DefaultMode,
"m_csrf": DefaultMode,
"m_file_include": DefaultMode,
"m_file_upload": DefaultMode,
"m_http": DefaultMode,
"m_java": DefaultMode,
"m_java_unserialize": DefaultMode,
"m_php_code_injection": DefaultMode,
"m_php_unserialize": DefaultMode,
"m_response": DefaultMode,
"m_rule": DefaultMode,
"m_scanner": DefaultMode,
"m_sqli": DefaultMode,
"m_ssrf": DefaultMode,
"m_ssti": DefaultMode,
"m_xss": DefaultMode,
}
pggStr, err := json.Marshal(policyGroupGlobal)
if err != nil {
return err
}
pgg := Options{Key: constants.PolicyGroupGlobal, Value: string(pggStr)}
db.Clauses(clause.OnConflict{DoNothing: true}).Create(&pgg)
return nil
}
================================================
FILE: management/webserver/model/policyrule.go
================================================
package model
import "gorm.io/datatypes"
type PolicyRule struct {
Base
Action int `gorm:"action" json:"action"`
Comment string `gorm:"comment" json:"comment"`
Pattern datatypes.JSON `gorm:"pattern" json:"pattern"`
IsEnabled bool `gorm:"is_enabled;default=true" json:"is_enabled"`
}
type PolicyRulePattern struct {
K string `json:"k"`
Op string `json:"op"`
V string `json:"v"`
}
const (
KeySrcIP = "src_ip"
KeyURI = "uri"
KeyHost = "host"
OpEq = "eq" // 完全相等
OpMatch = "match" // 模糊匹配
OpCIDR = "cidr" // CIDR
OpHas = "has" // 关键字
OpPrefix = "prefix" // 前缀关键字
OpRe = "re" // 正则
)
================================================
FILE: management/webserver/model/statistics.go
================================================
package model
import "time"
type SystemStatistics struct {
ID uint `json:"id" gorm:"primarykey"`
Type string `json:"type" gorm:"index;uniqueIndex:type_website_createdat"`
Value int64 `json:"value"`
CreatedAt time.Time `json:"created_at" gorm:"index;uniqueIndex:type_website_createdat"`
Website string `json:"website" gorm:"index;uniqueIndex:type_website_createdat"`
}
================================================
FILE: management/webserver/model/user.go
================================================
package model
import (
"gorm.io/gorm/clause"
"chaitin.cn/patronus/safeline-2/management/webserver/pkg/constants"
"chaitin.cn/patronus/safeline-2/management/webserver/pkg/database"
)
type User struct {
Base
Username string `gorm:"uniqueIndex;not null"`
Password string
Comment string
TFAEnabled bool `gorm:"column:tfa_enabled;default:true"`
TFASecret string `gorm:"column:tfa_secret"`
LastLoginTime int64 `gorm:"default:0"`
IsEnabled bool `gorm:"default:true"`
}
func initAdminUser() error {
db := database.GetDB()
user := User{
Username: constants.SuperUser,
}
db.Clauses(clause.OnConflict{DoNothing: true}).Create(&user)
return nil
}
================================================
FILE: management/webserver/model/website.go
================================================
package model
import "gorm.io/datatypes"
type Website struct {
Base
Comment string `gorm:"comment" json:"comment"`
ServerNames datatypes.JSON `gorm:"server_names" json:"server_names"`
Ports datatypes.JSON `gorm:"ports" json:"ports"`
Upstreams datatypes.JSON `gorm:"upstreams" json:"upstreams"`
CertFilename string `gorm:"cert_filename" json:"cert_filename"`
KeyFilename string `gorm:"key_filename" json:"key_filename"`
IsEnabled bool `gorm:"is_enabled;default=true" json:"is_enabled"`
}
================================================
FILE: management/webserver/pkg/config/config.go
================================================
package config
import (
"os"
"chaitin.cn/dev/go/settings"
)
var (
GlobalConfig = DefaultGlobalConfig()
)
func InitConfigs(configFilePath string) error {
s, err := settings.New(configFilePath)
if err != nil {
return err
}
if err = GlobalConfig.DB.Load(s); err != nil {
return err
}
if err = GlobalConfig.Log.Load(s); err != nil {
return err
}
if err = GlobalConfig.Server.Load(s); err != nil {
return err
}
if err = GlobalConfig.Detector.Load(s); err != nil {
return err
}
if err = GlobalConfig.Telemetry.Load(s); err != nil {
return err
}
if err = GlobalConfig.GPRC.Load(s); err != nil {
return err
}
if err := settings.Unmarshal("platform_addr", &GlobalConfig.PlatformAddr); err != nil {
return err
}
if v, ok := os.LookupEnv("MANAGEMENT_RESOURCES_DIR"); ok {
GlobalConfig.MgtResDir = v
}
if v, ok := os.LookupEnv("NGINX_RESOURCES_DIR"); ok {
GlobalConfig.NgxResDir = v
}
return nil
}
================================================
FILE: management/webserver/pkg/config/db.go
================================================
package config
import (
"net/url"
"os"
"chaitin.cn/dev/go/settings"
)
type DBConfig struct {
URL string `yaml:"url"`
LogSQL bool `yaml:"log_sql"`
SSLMode bool `yaml:"ssl_mode"`
}
func DefaultDBConfig() DBConfig {
return DBConfig{
URL: "postgres://safeline-ce:safeline-ce@127.0.0.1/safeline-ce",
LogSQL: false,
SSLMode: false,
}
}
func (dbc *DBConfig) Load(setting *settings.Setting) error {
if err := setting.Unmarshal("db", dbc); err != nil {
return err
}
if v, ok := os.LookupEnv("DATABASE_URL"); ok {
dbc.URL = v
}
dbURL, err := url.Parse(dbc.URL)
if err != nil {
return err
}
q := dbURL.Query()
if !dbc.SSLMode {
q.Set("sslmode", "disable")
}
dbURL.RawQuery = q.Encode()
dbc.URL = dbURL.String()
return nil
}
================================================
FILE: management/webserver/pkg/config/detector.go
================================================
package config
import (
"chaitin.cn/dev/go/settings"
)
type DetectorConfig struct {
Addr string `yaml:"addr"`
FslBytecode string `yaml:"fsl_bytecode"`
}
func DefaultDetectorConfig() DetectorConfig {
return DetectorConfig{
Addr: "http://127.0.0.1:8001",
FslBytecode: "bytecode",
}
}
func (d *DetectorConfig) Load(setting *settings.Setting) error {
if err := setting.Unmarshal("detector", d); err != nil {
return err
}
return nil
}
======================
gitextract_r0ep21tc/
├── .github/
│ ├── ISSUE_TEMPLATE/
│ │ ├── bug-report.yaml
│ │ ├── config.yml
│ │ ├── feature-request.yaml
│ │ └── other.yaml
│ └── workflows/
│ └── slmcp-docker.yml
├── .gitignore
├── .gitmodules
├── LICENSE.md
├── README.md
├── README_CN.md
├── compose.yaml
├── management/
│ ├── .gitignore
│ ├── .golangci.yml
│ ├── Makefile
│ ├── README.md
│ ├── scripts/
│ │ └── genproto.sh
│ ├── tcontrollerd/
│ │ ├── README.md
│ │ ├── config.yml
│ │ ├── controller/
│ │ │ ├── controller.go
│ │ │ ├── template.go
│ │ │ └── website.go
│ │ ├── go.mod
│ │ ├── go.sum
│ │ ├── main.go
│ │ ├── model/
│ │ │ └── website.go
│ │ ├── pkg/
│ │ │ ├── config/
│ │ │ │ ├── config.go
│ │ │ │ ├── global.go
│ │ │ │ └── log.go
│ │ │ ├── constants/
│ │ │ │ ├── constants.go
│ │ │ │ └── forbidden_page.go
│ │ │ ├── cron/
│ │ │ │ ├── cron.go
│ │ │ │ └── forbidden_page.go
│ │ │ ├── log/
│ │ │ │ └── log.go
│ │ │ └── ngcmd/
│ │ │ └── ngcmd.go
│ │ ├── proto/
│ │ │ └── website/
│ │ │ └── website.proto
│ │ └── utils/
│ │ ├── file.go
│ │ └── random.go
│ └── webserver/
│ ├── .gitignore
│ ├── README.md
│ ├── api/
│ │ ├── auth.go
│ │ ├── behaviour.go
│ │ ├── cert.go
│ │ ├── common.go
│ │ ├── dashboard.go
│ │ ├── detectlog.go
│ │ ├── endpoints.go
│ │ ├── policygroup.go
│ │ ├── policyrule.go
│ │ ├── response/
│ │ │ ├── error.go
│ │ │ ├── jsonbody.go
│ │ │ └── png.go
│ │ └── website.go
│ ├── cmd/
│ │ ├── fake_logs.go
│ │ ├── gen_certs.go
│ │ ├── push_fsl.go
│ │ ├── reset_user.go
│ │ └── show_fsl.go
│ ├── config.yml
│ ├── go.mod
│ ├── go.sum
│ ├── main.go
│ ├── middleware/
│ │ └── auth.go
│ ├── model/
│ │ ├── base.go
│ │ ├── behaviour.go
│ │ ├── db_patch_1_4_0.go
│ │ ├── detectlog.go
│ │ ├── init.go
│ │ ├── option.go
│ │ ├── policygroup.go
│ │ ├── policyrule.go
│ │ ├── statistics.go
│ │ ├── user.go
│ │ └── website.go
│ ├── pkg/
│ │ ├── config/
│ │ │ ├── config.go
│ │ │ ├── db.go
│ │ │ ├── detector.go
│ │ │ ├── global.go
│ │ │ ├── grpc.go
│ │ │ ├── log.go
│ │ │ ├── server.go
│ │ │ └── telemetry.go
│ │ ├── constants/
│ │ │ ├── constants.go
│ │ │ ├── detectlog.go
│ │ │ ├── detector.go
│ │ │ ├── option.go
│ │ │ ├── session.go
│ │ │ └── telemetry.go
│ │ ├── cron/
│ │ │ ├── cron.go
│ │ │ └── update_policy.go
│ │ ├── database/
│ │ │ └── postgres.go
│ │ ├── fvm/
│ │ │ ├── fsl/
│ │ │ │ ├── action.go
│ │ │ │ ├── quote.go
│ │ │ │ ├── selector.go
│ │ │ │ ├── state.go
│ │ │ │ ├── table.go
│ │ │ │ └── target.go
│ │ │ ├── fvm.go
│ │ │ ├── generator.go
│ │ │ └── helper.go
│ │ ├── log/
│ │ │ └── log.go
│ │ └── telemetry.go
│ ├── proto/
│ │ └── website/
│ │ └── website.proto
│ ├── rpc/
│ │ ├── main.go
│ │ └── website.go
│ ├── tools/
│ │ └── init_db.sh
│ └── utils/
│ ├── cert.go
│ ├── file.go
│ ├── healthy.go
│ ├── httpclient.go
│ ├── random.go
│ └── url.go
├── mcp_server/
│ ├── Dockerfile
│ ├── README.md
│ ├── config.yaml
│ ├── docker-compose.yml
│ ├── go.mod
│ ├── go.sum
│ ├── internal/
│ │ ├── api/
│ │ │ ├── analyze/
│ │ │ │ └── get_event_list.go
│ │ │ ├── app/
│ │ │ │ └── create_application.go
│ │ │ ├── client.go
│ │ │ ├── response.go
│ │ │ ├── rule/
│ │ │ │ └── create_rule.go
│ │ │ ├── service.go
│ │ │ └── types.go
│ │ ├── config/
│ │ │ └── config.go
│ │ └── tools/
│ │ ├── analyze/
│ │ │ └── get_atttack_events.go
│ │ ├── app/
│ │ │ └── create_application.go
│ │ ├── example.go
│ │ ├── init.go
│ │ ├── rule/
│ │ │ ├── create_blacklist_rule.go
│ │ │ └── create_whitelist_rule.go
│ │ └── tool.go
│ ├── main.go
│ └── pkg/
│ ├── config/
│ │ └── config.go
│ ├── errors/
│ │ └── errors.go
│ ├── logger/
│ │ ├── field.go
│ │ └── logger.go
│ └── mcp/
│ ├── mcp.go
│ ├── schema.go
│ └── schema_test.go
├── scripts/
│ └── manage.py
├── sdk/
│ ├── ingress-nginx/
│ │ ├── README.md
│ │ ├── ingress-nginx-safeline-1.0.2-1.rockspec
│ │ ├── ingress-nginx-safeline-1.0.3-1.rockspec
│ │ ├── ingress-nginx-safeline-1.0.4-1.rockspec
│ │ └── lib/
│ │ └── safeline/
│ │ └── main.lua
│ ├── kong/
│ │ ├── Readme.md
│ │ ├── kong/
│ │ │ └── plugins/
│ │ │ └── safeline/
│ │ │ ├── handler.lua
│ │ │ └── schema.lua
│ │ ├── kong-safeline-1.0.0-1.rockspec
│ │ ├── kong-safeline-1.0.1-1.rockspec
│ │ ├── kong-safeline-1.0.2-1.rockspec
│ │ ├── kong-safeline-1.0.3-1.rockspec
│ │ ├── kong-safeline-1.0.4-1.rockspec
│ │ ├── kong-safeline-1.0.5-1.rockspec
│ │ ├── kong-safeline-1.0.6-1.rockspec
│ │ └── kong-safeline-1.0.7-1.rockspec
│ └── lua-resty-t1k/
│ ├── .github/
│ │ └── workflows/
│ │ ├── release.yml
│ │ └── test.yml
│ ├── .gitignore
│ ├── .luacheckrc
│ ├── LICENSE
│ ├── README.md
│ ├── ci/
│ │ ├── .dockerignore
│ │ ├── Dockerfile
│ │ └── bytecode
│ ├── lib/
│ │ └── resty/
│ │ ├── t1k/
│ │ │ ├── buffer.lua
│ │ │ ├── constants.lua
│ │ │ ├── file.lua
│ │ │ ├── filter.lua
│ │ │ ├── handler.lua
│ │ │ ├── log.lua
│ │ │ ├── request.lua
│ │ │ ├── utils.lua
│ │ │ └── uuid.lua
│ │ └── t1k.lua
│ ├── mainspec/
│ │ └── lua-resty-t1k-main-0-0.rockspec
│ ├── rockspec/
│ │ ├── lua-resty-t1k-1.0.0-0.rockspec
│ │ ├── lua-resty-t1k-1.0.1-0.rockspec
│ │ ├── lua-resty-t1k-1.0.2-0.rockspec
│ │ ├── lua-resty-t1k-1.0.3-0.rockspec
│ │ ├── lua-resty-t1k-1.1.0-0.rockspec
│ │ ├── lua-resty-t1k-1.1.1-0.rockspec
│ │ ├── lua-resty-t1k-1.1.2-0.rockspec
│ │ ├── lua-resty-t1k-1.1.3-0.rockspec
│ │ ├── lua-resty-t1k-1.1.4-0.rockspec
│ │ └── lua-resty-t1k-1.1.5-0.rockspec
│ └── t/
│ ├── buffer.t
│ ├── file.t
│ ├── filter.t
│ ├── handler.t
│ ├── integration.t
│ ├── log.t
│ ├── option.t
│ ├── request.t
│ ├── utils.t
│ └── uuid.t
├── version.json
└── yanshi/
├── .gitignore
├── Makefile
├── README.md
├── contrib/
│ ├── vim/
│ │ ├── compiler/
│ │ │ └── yanshi.vim
│ │ ├── ftdetect/
│ │ │ └── yanshi.vim
│ │ ├── ftplugin/
│ │ │ └── yanshi.vim
│ │ ├── syntax/
│ │ │ └── yanshi.vim
│ │ └── syntax_checkers/
│ │ └── yanshi/
│ │ └── yanshi.vim
│ └── zsh/
│ └── _yanshi
├── src/
│ ├── common.cc
│ ├── common.hh
│ ├── compiler.cc
│ ├── compiler.hh
│ ├── fsa.cc
│ ├── fsa.hh
│ ├── fsa_anno.cc
│ ├── fsa_anno.hh
│ ├── lexer.l
│ ├── lexer_helper.cc
│ ├── lexer_helper.hh
│ ├── loader.cc
│ ├── loader.hh
│ ├── location.cc
│ ├── location.hh
│ ├── main.cc
│ ├── option.cc
│ ├── option.hh
│ ├── parser.y
│ ├── repl.cc
│ ├── repl.hh
│ ├── syntax.cc
│ └── syntax.hh
└── unittest/
├── determinize_test.cc
├── difference_test.cc
├── intersection_test.cc
├── minimize_test.cc
├── union_test.cc
└── unittest_helper.hh
SYMBOL INDEX (899 symbols across 128 files)
FILE: management/tcontrollerd/controller/controller.go
function Handle (line 16) | func Handle() error {
FILE: management/tcontrollerd/controller/website.go
constant Ping (line 22) | Ping = "ping"
constant Pong (line 23) | Pong = "pong"
constant EventTypeWebsite (line 24) | EventTypeWebsite = "website"
constant EventTypeDeleteWebsite (line 25) | EventTypeDeleteWebsite = "deleteWebsite"
constant EventTypeFullWebsite (line 26) | EventTypeFullWebsite = "fullWebsite"
constant nginxConfigPath (line 28) | nginxConfigPath = "/etc/nginx/sites-enabled/"
constant nginxFilePrefix (line 29) | nginxFilePrefix = "IF_backend_"
constant nginxBackupFilePrefix (line 30) | nginxBackupFilePrefix = "BAK_IF_backend_"
constant nginxFileMode (line 31) | nginxFileMode = 0644
constant HttpsScheme (line 33) | HttpsScheme = "https"
constant DefaultHttpsPort (line 34) | DefaultHttpsPort = "443"
function generateNginxConfig (line 39) | func generateNginxConfig(website *model.WebsiteConfig) (string, error) {
function nginxTestAndReload (line 88) | func nginxTestAndReload() error {
function generateFullConfigAndReload (line 102) | func generateFullConfigAndReload(msg []byte) error {
function generateConfigAndReload (line 134) | func generateConfigAndReload(website *model.WebsiteConfig) error {
function deleteConfigAndReload (line 195) | func deleteConfigAndReload(config []byte) error {
function sendResponse (line 221) | func sendResponse(stream pb.Website_SubscribeClient, eventType string, e...
function websiteHandler (line 229) | func websiteHandler(wc pb.WebsiteClient) error {
FILE: management/tcontrollerd/main.go
function init (line 31) | func init() {
function handleLoop (line 35) | func handleLoop(ctx context.Context) {
function main (line 49) | func main() {
FILE: management/tcontrollerd/model/website.go
type WebsiteConfig (line 4) | type WebsiteConfig struct
FILE: management/tcontrollerd/pkg/config/config.go
function InitConfigs (line 13) | func InitConfigs(configFilePath string) error {
FILE: management/tcontrollerd/pkg/config/global.go
type Config (line 3) | type Config struct
function DefaultGlobalConfig (line 8) | func DefaultGlobalConfig() Config {
FILE: management/tcontrollerd/pkg/config/log.go
type LogConfig (line 7) | type LogConfig struct
method Load (line 19) | func (lc *LogConfig) Load(setting *settings.Setting) error {
function DefaultLogConfig (line 12) | func DefaultLogConfig() LogConfig {
FILE: management/tcontrollerd/pkg/constants/constants.go
constant ConfigFilePath (line 4) | ConfigFilePath = "config.yml"
FILE: management/tcontrollerd/pkg/constants/forbidden_page.go
constant DefaultForbiddenPageMd5 (line 4) | DefaultForbiddenPageMd5 = "d9921f84f36a6cc92a6fc13946a18e98"
constant DefaultForbiddenPage (line 5) | DefaultForbiddenPage = ``
FILE: management/tcontrollerd/pkg/cron/cron.go
function newCronWithSeconds (line 11) | func newCronWithSeconds() *cron.Cron {
function StartCron (line 17) | func StartCron() error {
FILE: management/tcontrollerd/pkg/cron/forbidden_page.go
constant specCheckForbiddenPage (line 16) | specCheckForbiddenPage = "0/30 * * * * ?"
constant forbiddenPagePath (line 18) | forbiddenPagePath = "/etc/nginx/forbidden_pages/default_forbidden_page.h...
function checkAndUpdateForbiddenPage (line 21) | func checkAndUpdateForbiddenPage() {
FILE: management/tcontrollerd/pkg/log/log.go
function GetLogger (line 16) | func GetLogger(name string) *log.Logger {
function LoadLogLevel (line 20) | func LoadLogLevel() {
function SetLogFormatter (line 25) | func SetLogFormatter() {
function InitLogger (line 33) | func InitLogger() error {
type RuntimeHook (line 70) | type RuntimeHook struct
method Levels (line 72) | func (h *RuntimeHook) Levels() []logrus.Level {
method Fire (line 76) | func (h *RuntimeHook) Fire(entry *logrus.Entry) error {
function NewRuntimeHook (line 115) | func NewRuntimeHook() *RuntimeHook {
FILE: management/tcontrollerd/pkg/ngcmd/ngcmd.go
function NginxConfTest (line 15) | func NginxConfTest() error {
function NginxConfReload (line 31) | func NginxConfReload() error {
FILE: management/tcontrollerd/utils/file.go
function EnsureDir (line 11) | func EnsureDir(dir string) error {
function EnsureFileDir (line 18) | func EnsureFileDir(path string) error {
function FileExist (line 22) | func FileExist(path string) (bool, error) {
function FilesExist (line 39) | func FilesExist(paths ...string) (bool, error) {
function RenameWriteFile (line 52) | func RenameWriteFile(filename string, data []byte, perm os.FileMode) err...
function EnsureRenameWriteFile (line 60) | func EnsureRenameWriteFile(path string, data []byte, mode os.FileMode) e...
function EnsureWriteFile (line 69) | func EnsureWriteFile(path string, data []byte, mode os.FileMode) error {
function CopyFile (line 78) | func CopyFile(srcPath, dstPath string) error {
function CopyFileFromIO (line 98) | func CopyFileFromIO(src io.Reader, dstPath string, perm os.FileMode) err...
function CopyFileIfNotExist (line 118) | func CopyFileIfNotExist(srcPath, dstPath string) error {
FILE: management/tcontrollerd/utils/random.go
function RandStr (line 10) | func RandStr(n int) string {
FILE: management/webserver/api/auth.go
type PostLoginRequest (line 30) | type PostLoginRequest struct
function PostLogin (line 35) | func PostLogin(c *gin.Context) {
function PostLogout (line 91) | func PostLogout(c *gin.Context) {
function GetOTPUrl (line 102) | func GetOTPUrl(c *gin.Context) {
function GetUser (line 126) | func GetUser(c *gin.Context) {
FILE: management/webserver/api/behaviour.go
type PostBehaviourRequest (line 13) | type PostBehaviourRequest struct
function PostBehaviour (line 17) | func PostBehaviour(c *gin.Context) {
FILE: management/webserver/api/cert.go
type postSSLCertRequest (line 16) | type postSSLCertRequest struct
constant CRT (line 22) | CRT = ".crt"
constant PEM (line 23) | PEM = ".pem"
constant KEY (line 24) | KEY = ".key"
constant SSLCertDir (line 26) | SSLCertDir = "certs"
function PostUploadSSLCert (line 29) | func PostUploadSSLCert(c *gin.Context) {
function PostSSLCert (line 61) | func PostSSLCert(c *gin.Context) {
FILE: management/webserver/api/common.go
constant VersionInfoEntrypoint (line 19) | VersionInfoEntrypoint = "/release/latest/version.json"
type idsRequest (line 21) | type idsRequest struct
type pageRequest (line 25) | type pageRequest struct
type versionInfoResponse (line 30) | type versionInfoResponse struct
function GetVersion (line 35) | func GetVersion(c *gin.Context) {
function GetUpgradeTips (line 39) | func GetUpgradeTips(ctx *gin.Context) {
FILE: management/webserver/api/dashboard.go
function GetDashboardCounts (line 14) | func GetDashboardCounts(c *gin.Context) {
function GetDashboardSites (line 33) | func GetDashboardSites(c *gin.Context) {
function GetDashboardQps (line 37) | func GetDashboardQps(c *gin.Context) {
function GetDashboardRequests (line 60) | func GetDashboardRequests(c *gin.Context) {
function GetDashboardIntercepts (line 90) | func GetDashboardIntercepts(c *gin.Context) {
FILE: management/webserver/api/detectlog.go
type GetDetectLogDetailRequest (line 28) | type GetDetectLogDetailRequest struct
type PostFalsePositivesRequest (line 32) | type PostFalsePositivesRequest struct
type telemetryFalsePositives (line 36) | type telemetryFalsePositives struct
function getDetectLog (line 49) | func getDetectLog(eventId string) (*model.DetectLog, error) {
function GetDetectLogList (line 68) | func GetDetectLogList(c *gin.Context) {
function GetDetectLogDetail (line 115) | func GetDetectLogDetail(c *gin.Context) {
function PostFalsePositives (line 133) | func PostFalsePositives(c *gin.Context) {
FILE: management/webserver/api/endpoints.go
constant Version (line 4) | Version = "/Version"
constant UpgradeTips (line 5) | UpgradeTips = "/UpgradeTips"
constant Login (line 6) | Login = "/Login"
constant Logout (line 7) | Logout = "/Logout"
constant OTPUrl (line 8) | OTPUrl = "/OTPUrl"
constant User (line 9) | User = "/User"
constant DetectLogList (line 10) | DetectLogList = "/DetectLogList"
constant DetectLogDetail (line 11) | DetectLogDetail = "/DetectLogDetail"
constant Behaviour (line 12) | Behaviour = "/Behaviour"
constant FalsePositives (line 13) | FalsePositives = "/FalsePositives"
constant Website (line 14) | Website = "/Website"
constant UploadSSLCert (line 15) | UploadSSLCert = "/UploadSSLCert"
constant SSLCert (line 16) | SSLCert = "/SSLCert"
constant PolicyRule (line 17) | PolicyRule = "/PolicyRule"
constant SwitchPolicyRule (line 18) | SwitchPolicyRule = "/SwitchPolicyRule"
constant DashboardCounts (line 19) | DashboardCounts = "/dashboard/counts"
constant DashboardSites (line 20) | DashboardSites = "/dashboard/sites"
constant DashboardQps (line 21) | DashboardQps = "/dashboard/qps"
constant DashboardRequests (line 22) | DashboardRequests = "/dashboard/requests"
constant DashboardIntercepts (line 23) | DashboardIntercepts = "/dashboard/intercepts"
constant PolicyGroupGlobal (line 24) | PolicyGroupGlobal = "/PolicyGroupGlobal"
constant SrcIPConfig (line 25) | SrcIPConfig = "/SrcIPConfig"
FILE: management/webserver/api/policygroup.go
function PutPolicyGroupGlobal (line 19) | func PutPolicyGroupGlobal(ctx *gin.Context) {
function GetPolicyGroupGlobal (line 63) | func GetPolicyGroupGlobal(ctx *gin.Context) {
function PutSrcIPConfig (line 78) | func PutSrcIPConfig(ctx *gin.Context) {
function GetSrcIPConfig (line 122) | func GetSrcIPConfig(ctx *gin.Context) {
FILE: management/webserver/api/policyrule.go
type putSwitchRequest (line 18) | type putSwitchRequest struct
function PostPolicyRule (line 23) | func PostPolicyRule(ctx *gin.Context) {
function PutSwitchPolicyRule (line 54) | func PutSwitchPolicyRule(ctx *gin.Context) {
function PutPolicyRule (line 85) | func PutPolicyRule(ctx *gin.Context) {
function DeletePolicyRule (line 125) | func DeletePolicyRule(ctx *gin.Context) {
function GetPolicyRule (line 158) | func GetPolicyRule(ctx *gin.Context) {
FILE: management/webserver/api/response/error.go
constant ErrLoginRequired (line 4) | ErrLoginRequired = "login-required"
constant ErrWrongPasscode (line 5) | ErrWrongPasscode = "wrong-passcode"
constant ErrWrongTimeGap (line 6) | ErrWrongTimeGap = "wrong-time-gap"
constant ErrInternalError (line 7) | ErrInternalError = "internal-error"
constant ErrDataNotExist (line 8) | ErrDataNotExist = "data-not-exist"
constant ErrWrongFileType (line 9) | ErrWrongFileType = "wrong-filetype"
constant ErrReadOnly (line 10) | ErrReadOnly = "read-only"
FILE: management/webserver/api/response/jsonbody.go
type JSONBody (line 9) | type JSONBody struct
function Success (line 22) | func Success(c *gin.Context, data interface{}) {
function SuccessWithList (line 31) | func SuccessWithList(c *gin.Context, data interface{}) {
function SuccessWithMsg (line 40) | func SuccessWithMsg(c *gin.Context, data interface{}, msg string) {
function Error (line 49) | func Error(c *gin.Context, rsp JSONBody, status int) {
FILE: management/webserver/api/response/png.go
constant StreamContentType (line 9) | StreamContentType = "application/octet-stream"
function PNG (line 11) | func PNG(c *gin.Context, bytes []byte) {
FILE: management/webserver/api/website.go
function publishWebsiteConfig (line 20) | func publishWebsiteConfig(website *model.Website) error {
function publishDeleteWebsiteConfig (line 34) | func publishDeleteWebsiteConfig(id []uint) error {
function PostWebsite (line 48) | func PostWebsite(ctx *gin.Context) {
function PutWebsite (line 85) | func PutWebsite(ctx *gin.Context) {
function DeleteWebsite (line 133) | func DeleteWebsite(ctx *gin.Context) {
function GetWebsite (line 171) | func GetWebsite(ctx *gin.Context) {
FILE: management/webserver/cmd/fake_logs.go
function FakeLogs (line 5) | func FakeLogs() {
FILE: management/webserver/cmd/gen_certs.go
function GenCerts (line 12) | func GenCerts() error {
function genServerCert (line 22) | func genServerCert() error {
function genClientCACert (line 49) | func genClientCACert() error {
FILE: management/webserver/cmd/push_fsl.go
function PushFSL (line 8) | func PushFSL() error {
FILE: management/webserver/cmd/reset_user.go
function ResetUser (line 8) | func ResetUser(username string) {
FILE: management/webserver/cmd/show_fsl.go
function ShowFSL (line 8) | func ShowFSL() (string, error) {
FILE: management/webserver/main.go
function init (line 38) | func init() {
function main (line 42) | func main() {
FILE: management/webserver/middleware/auth.go
function AuthRequired (line 13) | func AuthRequired(c *gin.Context) {
function ReadOnly (line 41) | func ReadOnly(c *gin.Context) {
FILE: management/webserver/model/base.go
type Base (line 10) | type Base struct
FILE: management/webserver/model/behaviour.go
type Behaviour (line 3) | type Behaviour struct
FILE: management/webserver/model/db_patch_1_4_0.go
type sqlResult (line 10) | type sqlResult struct
function DBPatch140 (line 14) | func DBPatch140(tx *gorm.DB) error {
FILE: management/webserver/model/detectlog.go
type DetectLog (line 17) | type DetectLog struct
function getRuleModule (line 27) | func getRuleModule(ruleId string, attackType int) string {
function getRuleReason (line 43) | func getRuleReason(ruleId string, attackType int) string {
function getAttackType (line 55) | func getAttackType(at int) string {
function getCountry (line 63) | func getCountry(country string) string {
function TransformDetectLog (line 71) | func TransformDetectLog(basic *DetectLogBasic, detail *DetectLogDetail) ...
type DetectLogBasic (line 95) | type DetectLogBasic struct
type DetectLogDetail (line 120) | type DetectLogDetail struct
function InitDetectLogSamples (line 141) | func InitDetectLogSamples() {
FILE: management/webserver/model/init.go
function InitModels (line 9) | func InitModels() error {
FILE: management/webserver/model/option.go
type Options (line 18) | type Options struct
function initOptions (line 24) | func initOptions() error {
function NotifyInstallation (line 37) | func NotifyInstallation(machineId string) {
FILE: management/webserver/model/policygroup.go
type PolicyGroup (line 14) | type PolicyGroup
constant StrictMode (line 17) | StrictMode = "strict"
constant DefaultMode (line 18) | DefaultMode = "default"
constant DisableMode (line 19) | DisableMode = "disable"
constant SocketIP (line 21) | SocketIP = "socket_ip"
constant HTTPHeader (line 22) | HTTPHeader = "http_header"
type SrcIPConfig (line 25) | type SrcIPConfig struct
type SkynetConfigModule (line 30) | type SkynetConfigModule struct
type SkynetConfig (line 41) | type SkynetConfig struct
function GetSrcIPConfig (line 49) | func GetSrcIPConfig(db *gorm.DB) (*SrcIPConfig, error) {
function initSrcIPConfig (line 62) | func initSrcIPConfig() error {
function GetSkynetConfig (line 82) | func GetSkynetConfig(db *gorm.DB) (string, error) {
function initPolicyGroupGlobal (line 136) | func initPolicyGroupGlobal() error {
FILE: management/webserver/model/policyrule.go
type PolicyRule (line 5) | type PolicyRule struct
type PolicyRulePattern (line 13) | type PolicyRulePattern struct
constant KeySrcIP (line 20) | KeySrcIP = "src_ip"
constant KeyURI (line 21) | KeyURI = "uri"
constant KeyHost (line 22) | KeyHost = "host"
constant OpEq (line 24) | OpEq = "eq"
constant OpMatch (line 25) | OpMatch = "match"
constant OpCIDR (line 26) | OpCIDR = "cidr"
constant OpHas (line 27) | OpHas = "has"
constant OpPrefix (line 28) | OpPrefix = "prefix"
constant OpRe (line 29) | OpRe = "re"
FILE: management/webserver/model/statistics.go
type SystemStatistics (line 5) | type SystemStatistics struct
FILE: management/webserver/model/user.go
type User (line 10) | type User struct
function initAdminUser (line 22) | func initAdminUser() error {
FILE: management/webserver/model/website.go
type Website (line 5) | type Website struct
FILE: management/webserver/pkg/config/config.go
function InitConfigs (line 13) | func InitConfigs(configFilePath string) error {
FILE: management/webserver/pkg/config/db.go
type DBConfig (line 10) | type DBConfig struct
method Load (line 24) | func (dbc *DBConfig) Load(setting *settings.Setting) error {
function DefaultDBConfig (line 16) | func DefaultDBConfig() DBConfig {
FILE: management/webserver/pkg/config/detector.go
type DetectorConfig (line 7) | type DetectorConfig struct
method Load (line 19) | func (d *DetectorConfig) Load(setting *settings.Setting) error {
function DefaultDetectorConfig (line 12) | func DefaultDetectorConfig() DetectorConfig {
FILE: management/webserver/pkg/config/global.go
type Config (line 3) | type Config struct
function DefaultGlobalConfig (line 15) | func DefaultGlobalConfig() Config {
FILE: management/webserver/pkg/config/grpc.go
type GRPCConfig (line 7) | type GRPCConfig struct
method Load (line 17) | func (sc *GRPCConfig) Load(setting *settings.Setting) error {
function DefaultGRPCConfig (line 11) | func DefaultGRPCConfig() GRPCConfig {
FILE: management/webserver/pkg/config/log.go
type LogConfig (line 7) | type LogConfig struct
method Load (line 19) | func (lc *LogConfig) Load(setting *settings.Setting) error {
function DefaultLogConfig (line 12) | func DefaultLogConfig() LogConfig {
FILE: management/webserver/pkg/config/server.go
type ServerConfig (line 7) | type ServerConfig struct
method Load (line 20) | func (sc *ServerConfig) Load(setting *settings.Setting) error {
function DefaultServerConfig (line 13) | func DefaultServerConfig() ServerConfig {
FILE: management/webserver/pkg/config/telemetry.go
type TelemetryConfig (line 7) | type TelemetryConfig struct
method Load (line 17) | func (t *TelemetryConfig) Load(setting *settings.Setting) error {
function DefaultTelemetryConfig (line 11) | func DefaultTelemetryConfig() TelemetryConfig {
FILE: management/webserver/pkg/constants/constants.go
constant SuperUser (line 4) | SuperUser = "admin"
constant ProductName (line 5) | ProductName = "长亭雷池 WAF 社区版"
constant ProductVersion (line 6) | ProductVersion = ""
constant ConfigFilePath (line 7) | ConfigFilePath = "config.yml"
constant CertsPath (line 8) | CertsPath = "certs"
constant NotUpgrade (line 12) | NotUpgrade int = iota
constant RecommendedUpgrade (line 13) | RecommendedUpgrade
constant MustUpgrade (line 14) | MustUpgrade
FILE: management/webserver/pkg/constants/detectlog.go
constant ProtocolHTTP (line 4) | ProtocolHTTP = 0
constant ProtocolHTTPS (line 5) | ProtocolHTTPS = 1
constant ProtocolHTTP2 (line 6) | ProtocolHTTP2 = 2
FILE: management/webserver/pkg/constants/detector.go
constant ContentType (line 4) | ContentType = "application/octet-stream"
constant UpdateEntrypoint (line 5) | UpdateEntrypoint = "/update/policy"
constant StatEntrypoint (line 6) | StatEntrypoint = "/stat"
constant DefaultPolicyVersion (line 7) | DefaultPolicyVersion = "1"
FILE: management/webserver/pkg/constants/option.go
constant SecretKey (line 4) | SecretKey = "secret_key"
constant MachineID (line 5) | MachineID = "machine_id"
constant PolicyGroupGlobal (line 6) | PolicyGroupGlobal = "policy_group_global"
constant SrcIPConfig (line 7) | SrcIPConfig = "src_ip_config"
FILE: management/webserver/pkg/constants/session.go
constant DefaultSessionUserKey (line 4) | DefaultSessionUserKey = "user"
FILE: management/webserver/pkg/constants/telemetry.go
constant ApplicationJson (line 4) | ApplicationJson = "application/json"
constant TelemetryEntryPoint (line 5) | TelemetryEntryPoint = "/telemetry"
constant TelemetryId (line 6) | TelemetryId = "9e88109c-ebbf-4d82-8a25-f97f2ac5f3c4"
constant Behaviour (line 7) | Behaviour = "behaviour"
constant FalsePositives (line 8) | FalsePositives = "false_positives"
constant Installation (line 9) | Installation = "Installation"
FILE: management/webserver/pkg/cron/cron.go
function newCronWithSeconds (line 11) | func newCronWithSeconds() *cron.Cron {
function StartCron (line 17) | func StartCron() error {
FILE: management/webserver/pkg/cron/update_policy.go
constant SpecUpdatePolicy (line 19) | SpecUpdatePolicy = "0/5 * * * * ?"
type statResponseBody (line 21) | type statResponseBody struct
function getBytecode (line 25) | func getBytecode() ([]byte, error) {
function CheckAndUpdatePolicy (line 33) | func CheckAndUpdatePolicy() {
FILE: management/webserver/pkg/database/postgres.go
type PostgresDB (line 13) | type PostgresDB struct
method SetDB (line 61) | func (db *PostgresDB) SetDB(gormDB *gorm.DB) {
function GetDB (line 22) | func GetDB() *PostgresDB {
function InitDB (line 26) | func InitDB() error {
FILE: management/webserver/pkg/fvm/fsl/action.go
function Goto (line 8) | func Goto(m string) string {
function Wheres (line 12) | func Wheres(items ...string) string {
function Actions (line 16) | func Actions(items ...string) string {
function Set (line 20) | func Set(k, t, v string) string {
FILE: management/webserver/pkg/fvm/fsl/quote.go
function appendEscapedByte (line 9) | func appendEscapedByte(buf []byte, b byte) []byte {
function appendQuotedWith (line 35) | func appendQuotedWith(buf []byte, s string, quote byte) []byte {
function quoteWith (line 44) | func quoteWith(s string, quote byte) string {
function Quote (line 48) | func Quote(s string) string {
FILE: management/webserver/pkg/fvm/fsl/selector.go
type Selector (line 7) | type Selector struct
method String (line 23) | func (s *Selector) String() string {
method AppendInto (line 32) | func (s *Selector) AppendInto() string {
function NewSelector (line 14) | func NewSelector(tableName, id, where, action string) *Selector {
function AppendInto (line 36) | func AppendInto(tableName, id, where, action string) string {
FILE: management/webserver/pkg/fvm/fsl/state.go
type State (line 7) | type State
method String (line 15) | func (s State) String() string {
constant S_NOP (line 10) | S_NOP State = iota
constant S_ABORT (line 11) | S_ABORT
constant S_RETURN (line 12) | S_RETURN
FILE: management/webserver/pkg/fvm/fsl/table.go
type Table (line 8) | type Table struct
method String (line 20) | func (t *Table) String() string {
method Create (line 32) | func (t *Table) Create() string {
function NewTable (line 13) | func NewTable(name string, mappings map[State]State) *Table {
function CreateTable (line 36) | func CreateTable(name string, mappings map[State]State) string {
FILE: management/webserver/pkg/fvm/fsl/target.go
type Target (line 7) | type Target struct
method String (line 25) | func (t *Target) String() string {
method Create (line 29) | func (t *Target) Create() string {
function NewTarget (line 13) | func NewTarget(id string, typ string, args string) *Target {
function NewSkynetTarget (line 21) | func NewSkynetTarget(id, configJSONStr string) *Target {
function CreateTarget (line 33) | func CreateTarget(id, configJSONStr string) string {
FILE: management/webserver/pkg/fvm/fvm.go
constant OutputItemTable (line 35) | OutputItemTable int = 0
constant OutputItemSelector (line 36) | OutputItemSelector int = 1
constant OutputItemTarget (line 37) | OutputItemTarget int = 2
type FVM (line 41) | type FVM struct
method Update (line 113) | func (f *FVM) Update(upd *FVMUpdate) error {
method Compile (line 124) | func (f *FVM) Compile(text string, re []byte) (*FVMOutput, *FVMRe, err...
method Plot (line 154) | func (f *FVM) Plot() string {
method Dump (line 161) | func (f *FVM) Dump() *FVMUpdate {
method Release (line 165) | func (f *FVM) Release() {
method PushFsl (line 185) | func (f *FVM) PushFsl(server string, update *FVMUpdate) error {
type FVMUpdate (line 47) | type FVMUpdate struct
method ToBytes (line 62) | func (u *FVMUpdate) ToBytes() []byte {
method FromBytes (line 66) | func (u *FVMUpdate) FromBytes(out []byte) error {
method MergeUpdate (line 75) | func (u *FVMUpdate) MergeUpdate(patch *FVMUpdate) error {
method Release (line 85) | func (u *FVMUpdate) Release() {
type FVMRe (line 51) | type FVMRe struct
method ToBytes (line 89) | func (r *FVMRe) ToBytes() []byte {
method FromBytes (line 93) | func (r *FVMRe) FromBytes(o []byte) {
function maybePointer (line 55) | func maybePointer(array []byte) unsafe.Pointer {
type FVMOutput (line 97) | type FVMOutput struct
function New (line 102) | func New() (*FVM, error) {
function Serialize (line 169) | func Serialize(out *FVMOutput, diff bool, base int64, target int64) *FVM...
function ReleaseOutput (line 181) | func ReleaseOutput(out *FVMOutput) {
type upload (line 244) | type upload struct
method Read (line 250) | func (u *upload) Read(p []byte) (n int, err error) {
FILE: management/webserver/pkg/fvm/generator.go
constant Main (line 21) | Main = "main"
constant Preprocess (line 22) | Preprocess = "preprocess"
constant MassPackage (line 23) | MassPackage = "mass_package"
constant PolicyRule (line 24) | PolicyRule = "policy_rule"
constant PolicyRuleGlobal (line 25) | PolicyRuleGlobal = "policy_rule_global"
constant PolicyGroup (line 26) | PolicyGroup = "policy_group"
constant PolicyGroupDetect (line 27) | PolicyGroupDetect = "policy_group_detect"
constant WeblogGenerate (line 28) | WeblogGenerate = "weblog_generate"
constant ReqWeblogGenerate (line 29) | ReqWeblogGenerate = "req_weblog_generate"
constant RspWeblogGenerate (line 30) | RspWeblogGenerate = "rsp_weblog_generate"
constant CommonLog (line 31) | CommonLog = "common_log"
constant STR (line 33) | STR = "STRING"
constant INT (line 34) | INT = "INTEGER"
constant INET (line 35) | INET = "INET"
constant BOOL (line 36) | BOOL = "BOOLEAN"
function InitFVMBytecode (line 41) | func InitFVMBytecode() {
function PushFSL (line 53) | func PushFSL(tx *gorm.DB) error {
function GenerateFullFSL (line 67) | func GenerateFullFSL(tx *gorm.DB) (fullFSL string, err error) {
function PreprocessTable (line 97) | func PreprocessTable(db *gorm.DB) (pFSL string, err error) {
function MassPackageTable (line 134) | func MassPackageTable() (mpFSL string) {
function PolicyRuleTable (line 147) | func PolicyRuleTable(db *gorm.DB) (prFSL string, err error) {
function PolicyGroupTable (line 239) | func PolicyGroupTable(db *gorm.DB) (pgFSL string, err error) {
function CommonLogTable (line 268) | func CommonLogTable() (clFSL string) {
function ReqWeblogGenerateTable (line 277) | func ReqWeblogGenerateTable() (reqWGFSL string) {
function RspWeblogGenerateTable (line 288) | func RspWeblogGenerateTable() (rspWGFSL string) {
function WeblogGenerateTable (line 299) | func WeblogGenerateTable() (wgFSL string) {
function MainTable (line 309) | func MainTable() (mainFSL string) {
FILE: management/webserver/pkg/fvm/helper.go
function init (line 11) | func init() {
function CompileAndSave (line 19) | func CompileAndSave(text string) error {
function CompileAndPush (line 37) | func CompileAndPush(text, serverAddr string) error {
FILE: management/webserver/pkg/log/log.go
function GetLogger (line 16) | func GetLogger(name string) *log.Logger {
function LoadLogLevel (line 20) | func LoadLogLevel() {
function SetLogFormatter (line 25) | func SetLogFormatter() {
function InitLogger (line 33) | func InitLogger() error {
type RuntimeHook (line 70) | type RuntimeHook struct
method Levels (line 72) | func (h *RuntimeHook) Levels() []logrus.Level {
method Fire (line 76) | func (h *RuntimeHook) Fire(entry *logrus.Entry) error {
function NewRuntimeHook (line 115) | func NewRuntimeHook() *RuntimeHook {
FILE: management/webserver/pkg/telemetry.go
type WebsiteResult (line 14) | type WebsiteResult struct
type TelemetryInfo (line 19) | type TelemetryInfo struct
type SafelineInfo (line 23) | type SafelineInfo struct
type TelemetryRequest (line 41) | type TelemetryRequest struct
function GetUploadTimestamp (line 46) | func GetUploadTimestamp() string {
function GetUploadNonce (line 52) | func GetUploadNonce() string {
function DoPostTelemetry (line 58) | func DoPostTelemetry(client *http.Client, addr string, reader io.Reader)...
FILE: management/webserver/rpc/main.go
constant WaitRspTimeout (line 16) | WaitRspTimeout = 30 * time.Second
constant KeepaliveTime (line 17) | KeepaliveTime = 5 * time.Second
constant KeepaliveTimeout (line 18) | KeepaliveTimeout = 30 * time.Second
constant Ping (line 20) | Ping = "ping"
constant Pong (line 21) | Pong = "pong"
constant EventTypeWebsite (line 22) | EventTypeWebsite = "website"
constant EventTypeDeleteWebsite (line 23) | EventTypeDeleteWebsite = "deleteWebsite"
constant EventTypeFullWebsite (line 24) | EventTypeFullWebsite = "fullWebsite"
function StartGRPCSever (line 29) | func StartGRPCSever() error {
FILE: management/webserver/rpc/website.go
function Publish (line 19) | func Publish(msg []byte, eventType string) error {
type StreamClient (line 57) | type StreamClient struct
method pingLoop (line 75) | func (sc *StreamClient) pingLoop() {
method recvLoop (line 102) | func (sc *StreamClient) recvLoop() {
function newStreamClient (line 65) | func newStreamClient(stream pb.Website_SubscribeServer) *StreamClient {
type WebsiteServer (line 134) | type WebsiteServer struct
method Subscribe (line 155) | func (ws *WebsiteServer) Subscribe(stream pb.Website_SubscribeServer) ...
function GetWebsiteServer (line 138) | func GetWebsiteServer() *WebsiteServer {
function publishFullWebsite (line 142) | func publishFullWebsite() error {
FILE: management/webserver/utils/cert.go
function GenerateCert (line 15) | func GenerateCert(hostnames []string, days int64, keyBits int, subject *...
function WriteCertIfNotExist (line 72) | func WriteCertIfNotExist(certFilePath, keyFilePath string, generator fun...
function genCertIfNotExist (line 89) | func genCertIfNotExist(certFilePath, keyFilePath string, generator func(...
FILE: management/webserver/utils/file.go
function EnsureDir (line 10) | func EnsureDir(dir string) error {
function EnsureFileDir (line 17) | func EnsureFileDir(path string) error {
function FileExist (line 21) | func FileExist(path string) (bool, error) {
function FilesExist (line 38) | func FilesExist(paths ...string) (bool, error) {
function RenameWriteFile (line 51) | func RenameWriteFile(filename string, data []byte, perm os.FileMode) err...
function EnsureRenameWriteFile (line 59) | func EnsureRenameWriteFile(path string, data []byte, mode os.FileMode) e...
function EnsureWriteFile (line 68) | func EnsureWriteFile(path string, data []byte, mode os.FileMode) error {
FILE: management/webserver/utils/healthy.go
function CheckHealthy (line 8) | func CheckHealthy(url string) bool {
function CheckWafHealthy (line 28) | func CheckWafHealthy() bool {
FILE: management/webserver/utils/httpclient.go
constant proxyName (line 11) | proxyName = "HTTPS_PROXY"
function GetHTTPClient (line 15) | func GetHTTPClient() *http.Client {
FILE: management/webserver/utils/random.go
function RandStr (line 10) | func RandStr(n int) string {
FILE: management/webserver/utils/url.go
function IsIPv6 (line 11) | func IsIPv6(str string) bool {
function BuildUrl (line 16) | func BuildUrl(protocol int, host string, port uint, path string) string {
FILE: mcp_server/internal/api/analyze/get_event_list.go
type GetEventListRequest (line 10) | type GetEventListRequest struct
type GetEventListResponse (line 18) | type GetEventListResponse struct
type Event (line 23) | type Event struct
function GetEventList (line 40) | func GetEventList(ctx context.Context, req *GetEventListRequest) (*GetEv...
FILE: mcp_server/internal/api/app/create_application.go
type CreateAppRequest (line 10) | type CreateAppRequest struct
function CreateApp (line 18) | func CreateApp(ctx context.Context, req *CreateAppRequest) (int64, error) {
FILE: mcp_server/internal/api/client.go
type Client (line 18) | type Client struct
method Request (line 82) | func (c *Client) Request(ctx context.Context, method, path string, bod...
method Get (line 140) | func (c *Client) Get(ctx context.Context, path string, result interfac...
method Post (line 145) | func (c *Client) Post(ctx context.Context, path string, body interface...
method Put (line 150) | func (c *Client) Put(ctx context.Context, path string, body interface{...
method Delete (line 155) | func (c *Client) Delete(ctx context.Context, path string, result inter...
type ClientOption (line 25) | type ClientOption
function WithTimeout (line 28) | func WithTimeout(timeout time.Duration) ClientOption {
function WithHeader (line 35) | func WithHeader(key, value string) ClientOption {
function WithBaseURL (line 42) | func WithBaseURL(baseURL string) ClientOption {
function WithInsecureSkipVerify (line 49) | func WithInsecureSkipVerify(skip bool) ClientOption {
function NewClient (line 61) | func NewClient(opts ...ClientOption) *Client {
FILE: mcp_server/internal/api/response.go
type Response (line 4) | type Response struct
FILE: mcp_server/internal/api/rule/create_rule.go
type CreateRuleRequest (line 10) | type CreateRuleRequest struct
function CreateRule (line 19) | func CreateRule(ctx context.Context, req *CreateRuleRequest) (int64, err...
FILE: mcp_server/internal/api/service.go
type APIClient (line 14) | type APIClient struct
method Post (line 83) | func (c *APIClient) Post(ctx context.Context, path string, body interf...
method Get (line 88) | func (c *APIClient) Get(ctx context.Context, path string, result inter...
method Put (line 93) | func (c *APIClient) Put(ctx context.Context, path string, body interfa...
method Delete (line 98) | func (c *APIClient) Delete(ctx context.Context, path string, result in...
function Init (line 25) | func Init(cfg *config.APIConfig) error {
function Service (line 39) | func Service() *APIClient {
function newAPIClient (line 48) | func newAPIClient(config *config.APIConfig) (*APIClient, error) {
FILE: mcp_server/internal/api/types.go
type PolicyRuleAction (line 3) | type PolicyRuleAction
constant PolicyRuleActionAllow (line 6) | PolicyRuleActionAllow PolicyRuleAction = iota
constant PolicyRuleActionDeny (line 7) | PolicyRuleActionDeny
constant PolicyRuleActionMax (line 8) | PolicyRuleActionMax
constant KeySrcIP (line 14) | KeySrcIP Key = "src_ip"
constant KeyURI (line 15) | KeyURI Key = "uri"
constant KeyURINoQuery (line 16) | KeyURINoQuery Key = "uri_no_query"
constant KeyHost (line 17) | KeyHost Key = "host"
constant KeyMethod (line 18) | KeyMethod Key = "method"
constant KeyReqHeader (line 19) | KeyReqHeader Key = "req_header"
constant KeyReqBody (line 20) | KeyReqBody Key = "req_body"
constant KeyGetParam (line 21) | KeyGetParam Key = "get_param"
constant KeyPostParam (line 22) | KeyPostParam Key = "post_param"
constant OpEq (line 28) | OpEq Op = "eq"
constant OpNotEq (line 29) | OpNotEq Op = "not_eq"
constant OpMatch (line 30) | OpMatch Op = "match"
constant OpCIDR (line 31) | OpCIDR Op = "cidr"
constant OpHas (line 32) | OpHas Op = "has"
constant OpNotHas (line 33) | OpNotHas Op = "not_has"
constant OpPrefix (line 34) | OpPrefix Op = "prefix"
constant OpRe (line 35) | OpRe Op = "re"
constant OpIn (line 36) | OpIn Op = "in"
constant OpNotIn (line 37) | OpNotIn Op = "not_in"
constant OpNotCIDR (line 38) | OpNotCIDR Op = "not_cidr"
constant OpExist (line 39) | OpExist Op = "exist"
constant OpNotExist (line 40) | OpNotExist Op = "not_exist"
constant OpGeoEq (line 41) | OpGeoEq Op = "geo_eq"
constant OpGeoNotEq (line 42) | OpGeoNotEq Op = "geo_not_eq"
type Pattern (line 45) | type Pattern struct
FILE: mcp_server/internal/config/config.go
type Config (line 12) | type Config struct
type APIConfig (line 19) | type APIConfig struct
type ServerConfig (line 33) | type ServerConfig struct
type LoggerConfig (line 42) | type LoggerConfig struct
function getEnvString (line 53) | func getEnvString(key, defaultValue string) string {
function getEnvInt (line 61) | func getEnvInt(key string, defaultValue int) int {
function Load (line 71) | func Load(path string) error {
function GetServer (line 97) | func GetServer() *ServerConfig {
function GetLogger (line 105) | func GetLogger() *LoggerConfig {
function GetAPI (line 113) | func GetAPI() *APIConfig {
FILE: mcp_server/internal/tools/analyze/get_atttack_events.go
type GetAttackEventsParams (line 10) | type GetAttackEventsParams struct
type GetAttackEvents (line 18) | type GetAttackEvents struct
method Name (line 20) | func (t *GetAttackEvents) Name() string {
method Description (line 24) | func (t *GetAttackEvents) Description() string {
method Validate (line 28) | func (t *GetAttackEvents) Validate(params GetAttackEventsParams) error {
method Execute (line 32) | func (t *GetAttackEvents) Execute(ctx context.Context, params GetAttac...
FILE: mcp_server/internal/tools/app/create_application.go
type CreateApp (line 10) | type CreateApp struct
method Name (line 18) | func (t *CreateApp) Name() string {
method Description (line 22) | func (t *CreateApp) Description() string {
method Validate (line 26) | func (t *CreateApp) Validate(params CreateAppParams) error {
method Execute (line 30) | func (t *CreateApp) Execute(ctx context.Context, params CreateAppParam...
type CreateAppParams (line 12) | type CreateAppParams struct
FILE: mcp_server/internal/tools/example.go
type CalculateSum (line 10) | type CalculateSum struct
method Name (line 12) | func (t *CalculateSum) Name() string {
method Description (line 16) | func (t *CalculateSum) Description() string {
method Validate (line 29) | func (t *CalculateSum) Validate(params MyToolInput) error {
method Execute (line 33) | func (t *CalculateSum) Execute(ctx context.Context, params MyToolInput...
type MyToolInput (line 20) | type MyToolInput struct
type MyToolOutput (line 25) | type MyToolOutput struct
FILE: mcp_server/internal/tools/init.go
function init (line 9) | func init() {
FILE: mcp_server/internal/tools/rule/create_blacklist_rule.go
type CreateBlacklistRule (line 11) | type CreateBlacklistRule struct
method Name (line 19) | func (t *CreateBlacklistRule) Name() string {
method Description (line 23) | func (t *CreateBlacklistRule) Description() string {
method Validate (line 27) | func (t *CreateBlacklistRule) Validate(params CreateBlacklistRuleParam...
method Execute (line 31) | func (t *CreateBlacklistRule) Execute(ctx context.Context, params Crea...
type CreateBlacklistRuleParams (line 13) | type CreateBlacklistRuleParams struct
FILE: mcp_server/internal/tools/rule/create_whitelist_rule.go
type CreateWhitelistRule (line 11) | type CreateWhitelistRule struct
method Name (line 19) | func (t *CreateWhitelistRule) Name() string {
method Description (line 23) | func (t *CreateWhitelistRule) Description() string {
method Validate (line 27) | func (t *CreateWhitelistRule) Validate(params CreateWhitelistRuleParam...
method Execute (line 31) | func (t *CreateWhitelistRule) Execute(ctx context.Context, params Crea...
type CreateWhitelistRuleParams (line 13) | type CreateWhitelistRuleParams struct
FILE: mcp_server/internal/tools/tool.go
type ToolWrapper (line 13) | type ToolWrapper interface
function AppendTool (line 21) | func AppendTool[T any, R any](tool ...mcp.Tool[T, R]) {
function Tools (line 27) | func Tools() []ToolWrapper {
type toolWrapper (line 31) | type toolWrapper struct
method Register (line 35) | func (w *toolWrapper[T, R]) Register(s *mcp.MCPServer) error {
FILE: mcp_server/main.go
function main (line 14) | func main() {
FILE: mcp_server/pkg/config/config.go
type Config (line 10) | type Config struct
type ServerConfig (line 16) | type ServerConfig struct
type LoggerConfig (line 25) | type LoggerConfig struct
function Load (line 38) | func Load(filename string) error {
function Get (line 54) | func Get() *Config {
function GetServer (line 59) | func GetServer() ServerConfig {
function GetLogger (line 67) | func GetLogger() LoggerConfig {
FILE: mcp_server/pkg/errors/errors.go
type Error (line 23) | type Error struct
method Error (line 31) | func (e *Error) Error() string {
method Unwrap (line 39) | func (e *Error) Unwrap() error {
method Stack (line 50) | func (e *Error) Stack() []string {
method Location (line 55) | func (e *Error) Location() string {
function getCallerLocation (line 60) | func getCallerLocation(skip int) string {
function WrapL (line 69) | func WrapL(err error, msg string) error {
function Is (line 109) | func Is(err, target error) bool {
function As (line 114) | func As(err error, target interface{}) bool {
function Wrap (line 119) | func Wrap(err error, msg string) error {
function New (line 131) | func New(text string) error {
FILE: mcp_server/pkg/logger/field.go
function String (line 12) | func String(key string, val string) Field {
function Int (line 17) | func Int(key string, val int) Field {
function Int64 (line 22) | func Int64(key string, val int64) Field {
function Float64 (line 27) | func Float64(key string, val float64) Field {
function Bool (line 32) | func Bool(key string, val bool) Field {
function Err (line 37) | func Err(err error) Field {
function Any (line 42) | func Any(key string, val interface{}) Field {
function Duration (line 47) | func Duration(key string, val float64) Field {
FILE: mcp_server/pkg/logger/logger.go
type Logger (line 14) | type Logger struct
method With (line 139) | func (l *Logger) With(key string, value interface{}) *Logger {
method Debug (line 144) | func (l *Logger) Debug(msg string, fields ...Field) {
method Info (line 149) | func (l *Logger) Info(msg string, fields ...Field) {
method Warn (line 154) | func (l *Logger) Warn(msg string, fields ...Field) {
method Error (line 159) | func (l *Logger) Error(msg string, fields ...Field) {
method Fatal (line 164) | func (l *Logger) Fatal(msg string, fields ...Field) {
type Config (line 24) | type Config struct
function Init (line 47) | func Init(cfg *Config) error {
function GetLogger (line 131) | func GetLogger() *Logger {
function With (line 171) | func With(key string, value interface{}) *Logger {
function Debug (line 178) | func Debug(msg string, fields ...Field) {
function Info (line 184) | func Info(msg string, fields ...Field) {
function Warn (line 190) | func Warn(msg string, fields ...Field) {
function Error (line 196) | func Error(msg string, fields ...Field) {
function Fatal (line 202) | func Fatal(msg string, fields ...Field) {
FILE: mcp_server/pkg/mcp/mcp.go
type Tool (line 17) | type Tool interface
type SSEServer (line 27) | type SSEServer struct
method Start (line 32) | func (s *SSEServer) Start(addr string) error {
method ServeHTTP (line 40) | func (s *SSEServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
type MCPServer (line 56) | type MCPServer struct
method Start (line 73) | func (s *MCPServer) Start(addr string) error {
function NewMCPServer (line 61) | func NewMCPServer(name, version string, secret string) *MCPServer {
function handleToolCall (line 77) | func handleToolCall[T any, R any](ctx context.Context, request mcp.CallT...
function RegisterTool (line 124) | func RegisterTool[T any, R any](s *MCPServer, tool Tool[T, R]) error {
FILE: mcp_server/pkg/mcp/schema.go
function SchemaToOptions (line 13) | func SchemaToOptions(schema any) ([]mcp.ToolOption, error) {
FILE: mcp_server/pkg/mcp/schema_test.go
function TestSchemaToOptions (line 10) | func TestSchemaToOptions(t *testing.T) {
FILE: scripts/manage.py
function parse_assets (line 461) | def parse_assets(args):
function init_global_config (line 496) | def init_global_config():
class log (line 531) | class log():
method _log (line 533) | def _log(c, l, s):
method debug (line 538) | def debug(s):
method info (line 543) | def info(s):
method warning (line 547) | def warning(s):
method error (line 551) | def error(s):
method fatal (line 555) | def fatal(s):
function text (line 559) | def text(label, var=()):
function color (line 566) | def color(t, attrs=[], end=True):
function banner (line 574) | def banner():
function get_url (line 586) | def get_url(url):
function ui_read (line 594) | def ui_read(question, default):
function ui_choice (line 612) | def ui_choice(question, options):
function humen_size (line 621) | def humen_size(x):
function rand_subnet (line 633) | def rand_subnet():
function free_space (line 660) | def free_space(path):
function free_memory (line 671) | def free_memory():
function exec_command (line 675) | def exec_command(*args,shell=False):
function exec_command_with_loading (line 683) | def exec_command_with_loading(*args, cwd=None, env=None):
function subprocess_output (line 706) | def subprocess_output(stdout):
function start_docker (line 712) | def start_docker():
function check_port (line 715) | def check_port(port):
function install_docker (line 727) | def install_docker():
function precheck_docker_compose (line 757) | def precheck_docker_compose():
function precheck_dns_scope (line 803) | def precheck_dns_scope():
function precheck (line 836) | def precheck():
function docker_pull (line 878) | def docker_pull(cwd):
function docker_restart (line 887) | def docker_restart(container):
function docker_exec (line 896) | def docker_exec(container, command):
function image_clean (line 905) | def image_clean():
function docker_up (line 911) | def docker_up(cwd):
function docker_down (line 933) | def docker_down(cwd):
function get_url_time (line 941) | def get_url_time(url):
function get_avg_delay (line 954) | def get_avg_delay(url):
function image_source (line 966) | def image_source():
function docker_source (line 986) | def docker_source():
function read_config (line 1002) | def read_config(path,config):
function write_config (line 1016) | def write_config(path,config):
function generate_config (line 1021) | def generate_config(path):
function show_address (line 1085) | def show_address(mgt_port):
function init_mgt (line 1092) | def init_mgt():
function check_install_path (line 1109) | def check_install_path(safeline_path):
function install (line 1124) | def install():
function get_installed_dir (line 1181) | def get_installed_dir():
function save_file_from_url (line 1195) | def save_file_from_url(url, path):
function rename_file (line 1204) | def rename_file(src, dst):
function remove_file (line 1208) | def remove_file(src):
function generate_config_and_run (line 1212) | def generate_config_and_run(safeline_path):
function upgrade (line 1243) | def upgrade():
function finish (line 1266) | def finish(mgt_port):
function reset_tengine (line 1270) | def reset_tengine():
function docker_restart_all (line 1297) | def docker_restart_all(cwd):
function reset_postgres (line 1308) | def reset_postgres():
function repair (line 1340) | def repair():
function restart (line 1351) | def restart():
function backup (line 1363) | def backup():
function uninstall (line 1366) | def uninstall():
function get_version_from_input (line 1397) | def get_version_from_input(old_version):
function check_version_format (line 1408) | def check_version_format(version):
function compare_version (line 1424) | def compare_version(old_version, new_version):
function get_version_from_mgt (line 1456) | def get_version_from_mgt():
function get_version (line 1470) | def get_version(old_version):
function main (line 1501) | def main():
FILE: yanshi/src/common.cc
function output_error (line 53) | void output_error(bool use_err, const char *format, va_list ap)
function err_msg (line 67) | void err_msg(const char *format, ...)
function err_exit (line 78) | void err_exit(int exitno, const char *format, ...)
function get_long (line 100) | long get_long(const char *arg)
function log_generic (line 115) | void log_generic(const char *prefix, const char *format, va_list ap)
function log_event (line 131) | void log_event(const char *format, ...)
function log_action (line 139) | void log_action(const char *format, ...)
function log_status (line 147) | void log_status(const char *format, ...)
function bold (line 155) | void bold(long fd) { if (isatty(fd)) fputs("\x1b[1m", fd == STDOUT_FILEN...
function blue (line 156) | void blue(long fd) { if (isatty(fd)) fputs(BLUE, fd == STDOUT_FILENO ? s...
function cyan (line 157) | void cyan(long fd) { if (isatty(fd)) fputs(CYAN, fd == STDOUT_FILENO ? s...
function green (line 158) | void green(long fd) { if (isatty(fd)) fputs(GREEN, fd == STDOUT_FILENO ?...
function magenta (line 159) | void magenta(long fd) { if (isatty(fd)) fputs(MAGENTA, fd == STDOUT_FILE...
function red (line 160) | void red(long fd) { if (isatty(fd)) fputs(RED, fd == STDOUT_FILENO ? std...
function sgr0 (line 161) | void sgr0(long fd) { if (isatty(fd)) fputs(SGR0, fd == STDOUT_FILENO ? s...
function yellow (line 162) | void yellow(long fd) { if (isatty(fd)) fputs(YELLOW, fd == STDOUT_FILENO...
function normal_yellow (line 163) | void normal_yellow(long fd) { if (isatty(fd)) fputs(NORMAL_YELLOW, fd ==...
function indent (line 165) | void indent(FILE* f, int d)
FILE: yanshi/src/common.hh
function emplace_front (line 85) | void emplace_front(vector<T>& a, Args&&... args)
function sorted_insert (line 91) | void sorted_insert(vector<T>& a, const T& x)
function sorted_emplace (line 101) | void sorted_emplace(vector<T>& a, Args&&... args)
type DisjointIntervals (line 111) | struct DisjointIntervals
method emplace (line 116) | void emplace(Args&&... args) {
FILE: yanshi/src/compiler.cc
function print_assoc (line 19) | void print_assoc(const FsaAnno& anno)
function print_automaton (line 46) | void print_automaton(const Fsa& fsa)
function Expr (line 71) | Expr* find_lca(Expr* u, Expr* v)
type Compiler (line 88) | struct Compiler : Visitor<Expr> {
method pre_expr (line 93) | void pre_expr(Expr& expr) {
method post_expr (line 105) | void post_expr(Expr& expr) {
method visit (line 113) | void visit(Expr& expr) override {
method visit (line 118) | void visit(BracketExpr& expr) override {
method visit (line 121) | void visit(CallExpr& expr) override {
method visit (line 124) | void visit(CollapseExpr& expr) override {
method visit (line 127) | void visit(ComplementExpr& expr) override {
method visit (line 131) | void visit(ConcatExpr& expr) override {
method visit (line 137) | void visit(DifferenceExpr& expr) override {
method visit (line 143) | void visit(DotExpr& expr) override {
method visit (line 146) | void visit(EmbedExpr& expr) override {
method visit (line 149) | void visit(EpsilonExpr& expr) override {
method visit (line 152) | void visit(IntersectExpr& expr) override {
method visit (line 158) | void visit(LiteralExpr& expr) override {
method visit (line 161) | void visit(PlusExpr& expr) override {
method visit (line 165) | void visit(QuestionExpr& expr) override {
method visit (line 169) | void visit(RepeatExpr& expr) override {
method visit (line 173) | void visit(StarExpr& expr) override {
method visit (line 177) | void visit(UnionExpr& expr) override {
function compile (line 185) | void compile(DefineStmt* stmt)
function generate_transitions (line 198) | void generate_transitions(DefineStmt* stmt)
function compile_export (line 411) | bool compile_export(DefineStmt* stmt)
function generate_graphviz (line 618) | void generate_graphviz(Module* mo)
function generate_final (line 677) | static void generate_final(const char* name, const vector<bool>& final)
function generate_cxx_export (line 704) | static void generate_cxx_export(DefineStmt* stmt)
function generate_cxx (line 749) | void generate_cxx(Module* mo)
FILE: yanshi/src/fsa.cc
type std (line 18) | namespace std
type hash<vector<T>> (line 21) | struct hash<vector<T>> {
function Fsa (line 92) | Fsa Fsa::operator~() const
function Fsa (line 229) | Fsa Fsa::difference(const Fsa& rhs, function<void(long)> relate) const
function Fsa (line 274) | Fsa Fsa::intersect(const Fsa& rhs, function<void(long, long)> relate) const
function Fsa (line 315) | Fsa Fsa::determinize(const vector<long>* starts, function<void(long, con...
function Fsa (line 386) | Fsa Fsa::distinguish(function<void(vector<long>&)> relate) const
FILE: yanshi/src/fsa.hh
type Fsa (line 14) | struct Fsa {
method n (line 20) | long n() const { return adj.size(); }
FILE: yanshi/src/fsa_anno.cc
function assoc_has_expr (line 19) | bool assoc_has_expr(vector<pair<Expr*, ExprTag>>& as, Expr* x)
function sort_assoc (line 25) | void sort_assoc(vector<pair<Expr*, ExprTag>>& as)
function FsaAnno (line 185) | FsaAnno FsaAnno::epsilon_fsa(EpsilonExpr* expr) {
function FsaAnno (line 339) | FsaAnno FsaAnno::bracket(BracketExpr& expr) {
function FsaAnno (line 352) | FsaAnno FsaAnno::call(CallExpr& expr) {
function FsaAnno (line 366) | FsaAnno FsaAnno::collapse(CollapseExpr& expr) {
function FsaAnno (line 380) | FsaAnno FsaAnno::dot(DotExpr* expr) {
function FsaAnno (line 393) | FsaAnno FsaAnno::embed(EmbedExpr& expr) {
function FsaAnno (line 425) | FsaAnno FsaAnno::literal(LiteralExpr& expr) {
function REP (line 456) | REP(i, src) {
FILE: yanshi/src/fsa_anno.hh
type ExprTag (line 5) | enum class ExprTag {
function has_start (line 11) | extern inline bool has_start(ExprTag x) { return long(x) & long(ExprTag:...
function has_inner (line 12) | extern inline bool has_inner(ExprTag x) { return long(x) & long(ExprTag:...
function has_final (line 13) | extern inline bool has_final(ExprTag x) { return long(x) & long(ExprTag:...
type FsaAnno (line 18) | struct FsaAnno {
FILE: yanshi/src/loader.cc
function print_module_info (line 28) | void print_module_info(Module& mo)
function Stmt (line 45) | Stmt* resolve(Module& mo, const string qualified, const string& ident)
function ActionStmt (line 76) | ActionStmt* resolve_action(Module& mo, const string qualified, const str...
type ModuleImportDef (line 98) | struct ModuleImportDef : PreorderStmtVisitor {
method ModuleImportDef (line 101) | ModuleImportDef(Module& mo, long& n_errors) : mo(mo), n_errors(n_error...
method visit (line 103) | void visit(ActionStmt& stmt) override {
method visit (line 111) | void visit(DefineStmt& stmt) override {
method visit (line 121) | void visit(ImportStmt& stmt) override {
method visit (line 133) | void visit(PreprocessDefineStmt& stmt) override {
type ModuleUse (line 142) | struct ModuleUse : PrePostActionExprStmtVisitor {
method ModuleUse (line 146) | ModuleUse(Module& mo, long& n_errors) : mo(mo), n_errors(n_errors) {}
method pre_expr (line 148) | void pre_expr(Expr& expr) override {
method post_expr (line 152) | void post_expr(Expr& expr) override {
method visit (line 163) | void visit(RefAction& action) override {
method visit (line 178) | void visit(BracketExpr& expr) override {
method visit (line 182) | void visit(CallExpr& expr) override {
method visit (line 196) | void visit(CollapseExpr& expr) override {
method visit (line 210) | void visit(DefineStmt& stmt) override {
method visit (line 215) | void visit(EmbedExpr& expr) override {
method error_undefined (line 235) | void error_undefined(const Location& loc, const string& qualified, con...
method error_ambiguous (line 242) | void error_ambiguous(const Location& loc, const string& ident) {
method error_misuse_macro (line 246) | void error_misuse_macro(const char* name, const Location& loc, const s...
function Module (line 255) | Module* load_module(long& n_errors, const string& filename)
function topo_define_stmts (line 314) | static vector<DefineStmt*> topo_define_stmts(long& n_errors)
function load (line 366) | long load(const string& filename)
function unload_all (line 550) | void unload_all()
FILE: yanshi/src/loader.hh
type ModuleStatus (line 15) | enum ModuleStatus { UNPROCESSED = 0, BAD, GOOD }
type Module (line 17) | struct Module {
FILE: yanshi/src/location.cc
function FOR (line 35) | FOR(i, linemap[line1], linemap[line1+1]) {
function FOR (line 41) | FOR(i, linemap[line1+1], linemap[line2]) {
function FOR (line 47) | FOR(i, linemap[line1+1], linemap[line1+4]) {
function FOR (line 53) | FOR(i, linemap[line2-3], linemap[line2]) {
FILE: yanshi/src/location.hh
type Location (line 8) | struct Location { long start, end; }
type LocationFile (line 10) | struct LocationFile {
method LocationFile (line 14) | LocationFile() = default;
method LocationFile (line 16) | LocationFile& operator=(const LocationFile&) = default;
method error_context (line 23) | void error_context(const Location& loc, const char* fmt, Args&&... arg...
method warning_context (line 28) | void warning_context(const Location& loc, const char* fmt, Args&&... a...
FILE: yanshi/src/main.cc
function print_help (line 17) | void print_help(FILE *fh)
function main (line 50) | int main(int argc, char *argv[])
FILE: yanshi/src/option.hh
type Mode (line 11) | enum class Mode {cxx, graphviz, interactive}
FILE: yanshi/src/repl.cc
type ReplMode (line 24) | enum class ReplMode {string, integer}
type Command (line 29) | struct Command
function run_command (line 159) | static void run_command(char* line)
function repl (line 184) | void repl(DefineStmt* stmt)
FILE: yanshi/src/syntax.cc
function stmt_free (line 3) | void stmt_free(Stmt* stmt)
FILE: yanshi/src/syntax.hh
type Visitor (line 19) | struct Visitor
type VisitableBase (line 22) | struct VisitableBase {
type Visitable (line 27) | struct Visitable : Base {
method accept (line 28) | void accept(Visitor<Base>& visitor) override {
type Action (line 33) | struct Action
type InlineAction (line 34) | struct InlineAction
method InlineAction (line 108) | InlineAction(string& code) : code(move(code)) {}
type RefAction (line 35) | struct RefAction
method RefAction (line 115) | RefAction(string& qualified, string& ident) : qualified(move(qualified...
type Visitor<Action> (line 37) | struct Visitor<Action> {
type Expr (line 43) | struct Expr
method string (line 136) | string name() const {
method no_action (line 146) | bool no_action() const {
type BracketExpr (line 44) | struct BracketExpr
method BracketExpr (line 153) | BracketExpr(DisjointIntervals* intervals) : intervals(std::move(*inter...
type CallExpr (line 45) | struct CallExpr
method CallExpr (line 159) | CallExpr(string& qualified, string& ident) : qualified(move(qualified)...
type CollapseExpr (line 46) | struct CollapseExpr
method CollapseExpr (line 165) | CollapseExpr(string& qualified, string& ident) : qualified(move(qualif...
type ComplementExpr (line 47) | struct ComplementExpr
method ComplementExpr (line 170) | ComplementExpr(Expr* inner) : inner(inner) {}
type ConcatExpr (line 48) | struct ConcatExpr
method ConcatExpr (line 178) | ConcatExpr(Expr* lhs, Expr* rhs) : lhs(lhs), rhs(rhs) {}
type DifferenceExpr (line 49) | struct DifferenceExpr
method DifferenceExpr (line 187) | DifferenceExpr(Expr* lhs, Expr* rhs) : lhs(lhs), rhs(rhs) {}
type DotExpr (line 50) | struct DotExpr
type EmbedExpr (line 51) | struct EmbedExpr
method EmbedExpr (line 200) | EmbedExpr(string& qualified, string& ident) : qualified(move(qualified...
type EpsilonExpr (line 52) | struct EpsilonExpr
type IntersectExpr (line 53) | struct IntersectExpr
method IntersectExpr (line 207) | IntersectExpr(Expr* lhs, Expr* rhs) : lhs(lhs), rhs(rhs) {}
type LiteralExpr (line 54) | struct LiteralExpr
method LiteralExpr (line 216) | LiteralExpr(string& literal) : literal(move(literal)) {}
type PlusExpr (line 55) | struct PlusExpr
method PlusExpr (line 221) | PlusExpr(Expr* inner) : inner(inner) {}
type RepeatExpr (line 56) | struct RepeatExpr
method RepeatExpr (line 230) | RepeatExpr(Expr* inner, long low, long high) : inner(inner), low(low),...
type QuestionExpr (line 57) | struct QuestionExpr
method QuestionExpr (line 238) | QuestionExpr(Expr* inner) : inner(inner) {}
type StarExpr (line 58) | struct StarExpr
method StarExpr (line 246) | StarExpr(Expr* inner) : inner(inner) {}
type UnionExpr (line 59) | struct UnionExpr
method UnionExpr (line 254) | UnionExpr(Expr* lhs, Expr* rhs) : lhs(lhs), rhs(rhs) {}
type Visitor<Expr> (line 61) | struct Visitor<Expr> {
type Stmt (line 81) | struct Stmt
type ActionStmt (line 82) | struct ActionStmt
method ActionStmt (line 274) | ActionStmt(string& ident, string& code) : ident(move(ident)), code(mov...
type CppStmt (line 83) | struct CppStmt
method CppStmt (line 279) | CppStmt(string& code) : code(move(code)) {}
type DefineStmt (line 84) | struct DefineStmt
method DefineStmt (line 287) | DefineStmt(string& lhs, Expr* rhs) : lhs(move(lhs)), rhs(rhs) {}
type EmptyStmt (line 85) | struct EmptyStmt
type ImportStmt (line 86) | struct ImportStmt
method ImportStmt (line 295) | ImportStmt(string& filename, string& qualified) : filename(move(filena...
type PreprocessDefineStmt (line 87) | struct PreprocessDefineStmt
method PreprocessDefineStmt (line 301) | PreprocessDefineStmt(string& ident, long value) : ident(move(ident)), ...
type Visitor<Stmt> (line 89) | struct Visitor<Stmt> {
type Action (line 101) | struct Action : VisitableBase<Action> {
type InlineAction (line 106) | struct InlineAction : Visitable<Action, InlineAction> {
method InlineAction (line 108) | InlineAction(string& code) : code(move(code)) {}
type Module (line 111) | struct Module
type RefAction (line 112) | struct RefAction : Visitable<Action, RefAction> {
method RefAction (line 115) | RefAction(string& qualified, string& ident) : qualified(move(qualified...
type Expr (line 120) | struct Expr : VisitableBase<Expr> {
method string (line 136) | string name() const {
method no_action (line 146) | bool no_action() const {
type BracketExpr (line 151) | struct BracketExpr : Visitable<Expr, BracketExpr> {
method BracketExpr (line 153) | BracketExpr(DisjointIntervals* intervals) : intervals(std::move(*inter...
type CallExpr (line 156) | struct CallExpr : Visitable<Expr, CallExpr> {
method CallExpr (line 159) | CallExpr(string& qualified, string& ident) : qualified(move(qualified)...
type CollapseExpr (line 162) | struct CollapseExpr : Visitable<Expr, CollapseExpr> {
method CollapseExpr (line 165) | CollapseExpr(string& qualified, string& ident) : qualified(move(qualif...
type ComplementExpr (line 168) | struct ComplementExpr : Visitable<Expr, ComplementExpr> {
method ComplementExpr (line 170) | ComplementExpr(Expr* inner) : inner(inner) {}
type ConcatExpr (line 176) | struct ConcatExpr : Visitable<Expr, ConcatExpr> {
method ConcatExpr (line 178) | ConcatExpr(Expr* lhs, Expr* rhs) : lhs(lhs), rhs(rhs) {}
type DifferenceExpr (line 185) | struct DifferenceExpr : Visitable<Expr, DifferenceExpr> {
method DifferenceExpr (line 187) | DifferenceExpr(Expr* lhs, Expr* rhs) : lhs(lhs), rhs(rhs) {}
type DotExpr (line 194) | struct DotExpr : Visitable<Expr, DotExpr> {}
type EmbedExpr (line 196) | struct EmbedExpr : Visitable<Expr, EmbedExpr> {
method EmbedExpr (line 200) | EmbedExpr(string& qualified, string& ident) : qualified(move(qualified...
type EpsilonExpr (line 203) | struct EpsilonExpr : Visitable<Expr, EpsilonExpr> {}
type IntersectExpr (line 205) | struct IntersectExpr : Visitable<Expr, IntersectExpr> {
method IntersectExpr (line 207) | IntersectExpr(Expr* lhs, Expr* rhs) : lhs(lhs), rhs(rhs) {}
type LiteralExpr (line 214) | struct LiteralExpr : Visitable<Expr, LiteralExpr> {
method LiteralExpr (line 216) | LiteralExpr(string& literal) : literal(move(literal)) {}
type PlusExpr (line 219) | struct PlusExpr : Visitable<Expr, PlusExpr> {
method PlusExpr (line 221) | PlusExpr(Expr* inner) : inner(inner) {}
type RepeatExpr (line 227) | struct RepeatExpr : Visitable<Expr, RepeatExpr> {
method RepeatExpr (line 230) | RepeatExpr(Expr* inner, long low, long high) : inner(inner), low(low),...
type QuestionExpr (line 236) | struct QuestionExpr : Visitable<Expr, QuestionExpr> {
method QuestionExpr (line 238) | QuestionExpr(Expr* inner) : inner(inner) {}
type StarExpr (line 244) | struct StarExpr : Visitable<Expr, StarExpr> {
method StarExpr (line 246) | StarExpr(Expr* inner) : inner(inner) {}
type UnionExpr (line 252) | struct UnionExpr : Visitable<Expr, UnionExpr> {
method UnionExpr (line 254) | UnionExpr(Expr* lhs, Expr* rhs) : lhs(lhs), rhs(rhs) {}
type Stmt (line 263) | struct Stmt {
type EmptyStmt (line 270) | struct EmptyStmt : Visitable<Stmt, EmptyStmt> {}
type ActionStmt (line 272) | struct ActionStmt : Visitable<Stmt, ActionStmt> {
method ActionStmt (line 274) | ActionStmt(string& ident, string& code) : ident(move(ident)), code(mov...
type CppStmt (line 277) | struct CppStmt : Visitable<Stmt, CppStmt> {
method CppStmt (line 279) | CppStmt(string& code) : code(move(code)) {}
type DefineStmt (line 282) | struct DefineStmt : Visitable<Stmt, DefineStmt> {
method DefineStmt (line 287) | DefineStmt(string& lhs, Expr* rhs) : lhs(move(lhs)), rhs(rhs) {}
type ImportStmt (line 293) | struct ImportStmt : Visitable<Stmt, ImportStmt> {
method ImportStmt (line 295) | ImportStmt(string& filename, string& qualified) : filename(move(filena...
type PreprocessDefineStmt (line 298) | struct PreprocessDefineStmt : Visitable<Stmt, PreprocessDefineStmt> {
method PreprocessDefineStmt (line 301) | PreprocessDefineStmt(string& ident, long value) : ident(move(ident)), ...
type StmtPrinter (line 308) | struct StmtPrinter : Visitor<Action>, Visitor<Expr>, Visitor<Stmt> {
method visit (line 311) | void visit(Action& action) override {
method visit (line 314) | void visit(InlineAction& action) override {
method visit (line 318) | void visit(RefAction& action) override {
method visit (line 323) | void visit(Expr& expr) override {
method visit (line 366) | void visit(BracketExpr& expr) override {
method visit (line 373) | void visit(CallExpr& expr) override {
method visit (line 381) | void visit(CollapseExpr& expr) override {
method visit (line 389) | void visit(ComplementExpr& expr) override {
method visit (line 395) | void visit(ConcatExpr& expr) override {
method visit (line 402) | void visit(DifferenceExpr& expr) override {
method visit (line 409) | void visit(DotExpr& expr) override {
method visit (line 412) | void visit(EmbedExpr& expr) override {
method visit (line 420) | void visit(EpsilonExpr& expr) override {
method visit (line 423) | void visit(IntersectExpr& expr) override {
method visit (line 430) | void visit(LiteralExpr& expr) override {
method visit (line 434) | void visit(PlusExpr& expr) override {
method visit (line 440) | void visit(RepeatExpr& expr) override {
method visit (line 447) | void visit(QuestionExpr& expr) override {
method visit (line 453) | void visit(StarExpr& expr) override {
method visit (line 459) | void visit(UnionExpr& expr) override {
method visit (line 467) | void visit(Stmt& stmt) override {
method visit (line 470) | void visit(ActionStmt& stmt) override {
method visit (line 475) | void visit(CppStmt& stmt) override {
method visit (line 479) | void visit(DefineStmt& stmt) override {
method visit (line 489) | void visit(EmptyStmt& stmt) override {
method visit (line 492) | void visit(ImportStmt& stmt) override {
method visit (line 498) | void visit(PreprocessDefineStmt& stmt) override {
type PreorderStmtVisitor (line 506) | struct PreorderStmtVisitor : Visitor<Stmt> {
method visit (line 507) | void visit(Stmt& stmt) override { stmt.accept(*this); }
method visit (line 508) | void visit(ActionStmt& stmt) override {}
method visit (line 509) | void visit(CppStmt& stmt) override {}
method visit (line 510) | void visit(DefineStmt& stmt) override {}
method visit (line 511) | void visit(EmptyStmt& stmt) override {}
method visit (line 512) | void visit(ImportStmt& stmt) override {}
method visit (line 513) | void visit(PreprocessDefineStmt&) override {}
type PrePostActionExprStmtVisitor (line 516) | struct PrePostActionExprStmtVisitor : Visitor<Action>, Visitor<Expr>, Vi...
method pre_action (line 517) | virtual void pre_action(Action&) {}
method post_action (line 518) | virtual void post_action(Action&) {}
method pre_expr (line 519) | virtual void pre_expr(Expr&) {}
method post_expr (line 520) | virtual void post_expr(Expr&) {}
method pre_stmt (line 521) | virtual void pre_stmt(Stmt&) {}
method post_stmt (line 522) | virtual void post_stmt(Stmt&) {}
method visit (line 524) | void visit(Action& action) override {
method visit (line 529) | void visit(InlineAction&) override {}
method visit (line 530) | void visit(RefAction&) override {}
method visit (line 532) | void visit(Expr& expr) override {
method visit (line 537) | void visit(BracketExpr& expr) override {}
method visit (line 538) | void visit(CallExpr& expr) override {}
method visit (line 539) | void visit(CollapseExpr& expr) override {}
method visit (line 540) | void visit(ComplementExpr& expr) override { visit(*expr.inner); }
method visit (line 541) | void visit(ConcatExpr& expr) override {
method visit (line 545) | void visit(DifferenceExpr& expr) override {
method visit (line 549) | void visit(DotExpr& expr) override {}
method visit (line 550) | void visit(EmbedExpr& expr) override {}
method visit (line 551) | void visit(EpsilonExpr& expr) override {}
method visit (line 552) | void visit(IntersectExpr& expr) override {
method visit (line 556) | void visit(LiteralExpr& expr) override {}
method visit (line 557) | void visit(PlusExpr& expr) override { visit(*expr.inner); }
method visit (line 558) | void visit(RepeatExpr& expr) override { visit(*expr.inner); }
method visit (line 559) | void visit(QuestionExpr& expr) override { visit(*expr.inner); }
method visit (line 560) | void visit(StarExpr& expr) override { visit(*expr.inner); }
method visit (line 561) | void visit(UnionExpr& expr) override {
method visit (line 566) | void visit(Stmt& stmt) override {
method visit (line 571) | void visit(ActionStmt& stmt) override {}
method visit (line 572) | void visit(CppStmt& stmt) override {}
method visit (line 573) | void visit(DefineStmt& stmt) override { stmt.rhs->accept(*this); }
method visit (line 574) | void visit(EmptyStmt& stmt) override {}
method visit (line 575) | void visit(ImportStmt& stmt) override {}
method visit (line 576) | void visit(PreprocessDefineStmt&) override {}
FILE: yanshi/unittest/determinize_test.cc
function main (line 24) | int main(int argc, char *argv[])
FILE: yanshi/unittest/difference_test.cc
function main (line 27) | int main(int argc, char *argv[])
FILE: yanshi/unittest/intersection_test.cc
function main (line 27) | int main(int argc, char *argv[])
FILE: yanshi/unittest/minimize_test.cc
function main (line 22) | int main(int argc, char *argv[])
FILE: yanshi/unittest/union_test.cc
function main (line 29) | int main(int argc, char *argv[])
FILE: yanshi/unittest/unittest_helper.hh
function Fsa (line 12) | static Fsa read_nfa()
function Fsa (line 40) | static Fsa read_dfa()
function print_fsa (line 55) | static void print_fsa(const Fsa& fsa)
Condensed preview — 236 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (724K chars).
[
{
"path": ".github/ISSUE_TEMPLATE/bug-report.yaml",
"chars": 1270,
"preview": "name: Bug\ndescription: Report a bug\n# Create a report to help us improve\ntitle: \"[Bug] \"\n\nbody:\n - type: markdown\n a"
},
{
"path": ".github/ISSUE_TEMPLATE/config.yml",
"chars": 457,
"preview": "blank_issues_enabled: false\ncontact_links:\n - name: Discord\n url: https://discord.gg/wyshSVuvxC\n about: Ask quest"
},
{
"path": ".github/ISSUE_TEMPLATE/feature-request.yaml",
"chars": 830,
"preview": "name: Suggestion\n# Feature request\ndescription: New feature or improvements.\ntitle: \"[Suggestion] \"\n\nbody:\n - type: mar"
},
{
"path": ".github/ISSUE_TEMPLATE/other.yaml",
"chars": 408,
"preview": "name: Other\ndescription: Other issues such as Doc\nbody:\n - type: markdown\n attributes:\n value: |\n Please"
},
{
"path": ".github/workflows/slmcp-docker.yml",
"chars": 1064,
"preview": "name: MCP Docker\n\non:\n push:\n branches:\n - main\n tags:\n - \"v*\"\n paths:\n - \"mcp_server/**\"\n "
},
{
"path": ".gitignore",
"chars": 97,
"preview": "*.Zone.Identifier\n.DS_Store\n*.zip\n*.tar\n*.tar.gz\nbuild.sh\ncompose.yml\n__pycache__\n.cursor\n.vscode"
},
{
"path": ".gitmodules",
"chars": 203,
"preview": "[submodule \"blazehttp\"]\n\tpath = blazehttp\n\turl = https://github.com/chaitin/blazehttp\n\n\n[submodule \"sdk/traefik-safeline"
},
{
"path": "LICENSE.md",
"chars": 35149,
"preview": " GNU GENERAL PUBLIC LICENSE\n Version 3, 29 June 2007\n\n Copyright (C) 2007 Free "
},
{
"path": "README.md",
"chars": 7434,
"preview": "<p align=\"center\">\n <img src=\"/images/banner.png\" width=\"400\" />\n</p>\n\n<h4 align=\"center\">\n SafeLine - Make your web a"
},
{
"path": "README_CN.md",
"chars": 4947,
"preview": "<p align=\"center\">\n <img src=\"/images/banner.png\" width=\"400\" />\n</p>\n\n<h4 align=\"center\">\n SafeLine - 雷池 - 不让黑客越过半步\n<"
},
{
"path": "compose.yaml",
"chars": 4619,
"preview": "networks:\n safeline-ce:\n name: safeline-ce\n driver: bridge\n ipam:\n driver: default\n config:\n "
},
{
"path": "management/.gitignore",
"chars": 200,
"preview": "# Test binary, build with `go test -c`\n*.test\n\n# Output of the go coverage tool, specifically when used with LiteIDE\n*.o"
},
{
"path": "management/.golangci.yml",
"chars": 222,
"preview": "linters:\n disable-all: true\n enable:\n - deadcode\n - errcheck\n - gofmt\n - goimports\n - gosimple\n - go"
},
{
"path": "management/Makefile",
"chars": 1368,
"preview": "GO = GO111MODULE=on go\n#GO = GO111MODULE=on GOOS=linux GOARCH=amd64 go\nGOBUILD = $(GO) build -mod=rea"
},
{
"path": "management/README.md",
"chars": 54,
"preview": "# Management Micro Service\n\n## Requirements\n\nGo 1.18+\n"
},
{
"path": "management/scripts/genproto.sh",
"chars": 785,
"preview": "#!/usr/bin/env bash\n#\n# Generate all protobuf bindings.\n# Run from repository root.\n\nset -u\n\nif ! [[ \"$0\" =~ scripts/gen"
},
{
"path": "management/tcontrollerd/README.md",
"chars": 692,
"preview": "# TControllerD\n\nTengine Controller Daemon (abbr. TCD) will be running in the Tengine container, \ndesigned to be in place"
},
{
"path": "management/tcontrollerd/config.yml",
"chars": 295,
"preview": "# develop use only. For production, refer to `package/build/tengine/tcontrollerd/config.yml`\nlog:\n output: stdout "
},
{
"path": "management/tcontrollerd/controller/controller.go",
"chars": 959,
"preview": "package controller\n\nimport (\n\t\"google.golang.org/grpc\"\n\t\"google.golang.org/grpc/credentials/insecure\"\n\n\t\"chaitin.cn/patr"
},
{
"path": "management/tcontrollerd/controller/template.go",
"chars": 1015,
"preview": "package controller\n\nvar nginxConfigTpl = `\nupstream %s {\n %s\n keepalive 128;\n keepalive_timeout 75;\n}\nserver {\n"
},
{
"path": "management/tcontrollerd/controller/website.go",
"chars": 7617,
"preview": "package controller\n\nimport (\n\t\"context\"\n\t\"encoding/json\"\n\t\"fmt\"\n\t\"io\"\n\t\"io/fs\"\n\t\"io/ioutil\"\n\t\"net/url\"\n\t\"os\"\n\t\"path/file"
},
{
"path": "management/tcontrollerd/go.mod",
"chars": 515,
"preview": "module chaitin.cn/patronus/safeline-2/management/tcontrollerd\n\ngo 1.21\n\ntoolchain go1.21.3\n\nrequire (\n\tchaitin.cn/dev/go"
},
{
"path": "management/tcontrollerd/go.sum",
"chars": 12345,
"preview": "chaitin.cn/dev/go/errors v0.0.0-20200717101723-df6132d53dc8/go.mod h1:u+ZD0shdyUt0UG9XfCgD1R5mSqXpTVoO5rwQXQeo3Eo=\nchait"
},
{
"path": "management/tcontrollerd/main.go",
"chars": 2467,
"preview": "package main\n\nimport (\n\t\"context\"\n\t\"flag\"\n\t\"fmt\"\n\t\"os\"\n\t\"os/signal\"\n\t\"strconv\"\n\t\"syscall\"\n\t\"time\"\n\n\t\"chaitin.cn/patronus"
},
{
"path": "management/tcontrollerd/model/website.go",
"chars": 368,
"preview": "package model\n\n// WebsiteConfig is supposed to be same with webserver/model/website.go\ntype WebsiteConfig struct {\n\tId "
},
{
"path": "management/tcontrollerd/pkg/config/config.go",
"chars": 488,
"preview": "package config\n\nimport (\n\t\"os\"\n\n\t\"chaitin.cn/dev/go/settings\"\n)\n\nvar (\n\tGlobalConfig = DefaultGlobalConfig()\n)\n\nfunc Ini"
},
{
"path": "management/tcontrollerd/pkg/config/global.go",
"chars": 214,
"preview": "package config\n\ntype Config struct {\n\tLog LogConfig\n\tMgtWebserver string\n}\n\nfunc DefaultGlobalConfig() Config {"
},
{
"path": "management/tcontrollerd/pkg/config/log.go",
"chars": 391,
"preview": "package config\n\nimport (\n\t\"chaitin.cn/dev/go/settings\"\n)\n\ntype LogConfig struct {\n\tOutput string `yaml:\"output\"`\n\tLevel "
},
{
"path": "management/tcontrollerd/pkg/constants/constants.go",
"chars": 60,
"preview": "package constants\n\nconst (\n\tConfigFilePath = \"config.yml\"\n)\n"
},
{
"path": "management/tcontrollerd/pkg/constants/forbidden_page.go",
"chars": 121,
"preview": "package constants\n\nconst (\n\tDefaultForbiddenPageMd5 = \"d9921f84f36a6cc92a6fc13946a18e98\"\n\tDefaultForbiddenPage = ``\n)"
},
{
"path": "management/tcontrollerd/pkg/cron/cron.go",
"chars": 619,
"preview": "package cron\n\nimport (\n\t\"github.com/robfig/cron/v3\"\n\n\t\"chaitin.cn/patronus/safeline-2/management/tcontrollerd/pkg/log\"\n)"
},
{
"path": "management/tcontrollerd/pkg/cron/forbidden_page.go",
"chars": 1285,
"preview": "package cron\n\nimport (\n\t\"crypto/md5\"\n\t\"encoding/hex\"\n\t\"io/ioutil\"\n\n\t\"chaitin.cn/patronus/safeline-2/management/tcontroll"
},
{
"path": "management/tcontrollerd/pkg/log/log.go",
"chars": 2664,
"preview": "package log\n\nimport (\n\t\"fmt\"\n\t\"os\"\n\t\"runtime\"\n\t\"strings\"\n\n\t\"github.com/sirupsen/logrus\"\n\n\t\"chaitin.cn/dev/go/log\"\n\t\"chai"
},
{
"path": "management/tcontrollerd/pkg/ngcmd/ngcmd.go",
"chars": 1084,
"preview": "package ngcmd\n\nimport (\n\t\"fmt\"\n\t\"os/exec\"\n\t\"strings\"\n\n\t\"chaitin.cn/dev/go/errors\"\n\t\"chaitin.cn/patronus/safeline-2/manag"
},
{
"path": "management/tcontrollerd/proto/website/website.proto",
"chars": 371,
"preview": "syntax = \"proto3\";\npackage website;\noption go_package = \"proto/website\";\n\nservice Website {\n rpc Subscribe(stream Respo"
},
{
"path": "management/tcontrollerd/utils/file.go",
"chars": 2368,
"preview": "package utils\n\nimport (\n\t\"fmt\"\n\t\"io\"\n\t\"io/ioutil\"\n\t\"os\"\n\t\"path/filepath\"\n)\n\nfunc EnsureDir(dir string) error {\n\tif _, er"
},
{
"path": "management/tcontrollerd/utils/random.go",
"chars": 297,
"preview": "package utils\n\nimport (\n\t\"math/rand\"\n\t\"time\"\n)\n\nvar letters = []rune(\"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWX"
},
{
"path": "management/webserver/.gitignore",
"chars": 27,
"preview": "tmp\nTaskfile.yml\n.air.toml\n"
},
{
"path": "management/webserver/README.md",
"chars": 1597,
"preview": "# Web Server\n\nweb server for mgt-api\n\n## Requirements\n\nGo 1.18+\n\n## Development\n\n### Init protobuf\n\n```shell\n# Refer: ht"
},
{
"path": "management/webserver/api/auth.go",
"chars": 3837,
"preview": "package api\n\nimport (\n\t\"math\"\n\t\"net/http\"\n\t\"time\"\n\n\t\"github.com/gin-contrib/sessions\"\n\t\"github.com/gin-gonic/gin\"\n\t\"gith"
},
{
"path": "management/webserver/api/behaviour.go",
"chars": 683,
"preview": "package api\n\nimport (\n\t\"net/http\"\n\n\t\"github.com/gin-gonic/gin\"\n\n\t\"chaitin.cn/patronus/safeline-2/management/webserver/ap"
},
{
"path": "management/webserver/api/cert.go",
"chars": 3167,
"preview": "package api\n\nimport (\n\t\"crypto/x509/pkix\"\n\t\"fmt\"\n\t\"net/http\"\n\t\"path/filepath\"\n\n\t\"github.com/gin-gonic/gin\"\n\n\t\"chaitin.cn"
},
{
"path": "management/webserver/api/common.go",
"chars": 2967,
"preview": "package api\n\nimport (\n\t\"encoding/json\"\n\t\"fmt\"\n\t\"io/ioutil\"\n\t\"net/http\"\n\t\"strings\"\n\n\t\"github.com/gin-gonic/gin\"\n\t\"github."
},
{
"path": "management/webserver/api/dashboard.go",
"chars": 3063,
"preview": "package api\n\nimport (\n\t\"math\"\n\t\"time\"\n\n\t\"github.com/gin-gonic/gin\"\n\n\t\"chaitin.cn/patronus/safeline-2/management/webserve"
},
{
"path": "management/webserver/api/detectlog.go",
"chars": 4614,
"preview": "package api\n\nimport (\n\t\"bytes\"\n\t\"encoding/json\"\n\t\"fmt\"\n\t\"net/http\"\n\t\"strconv\"\n\t\"strings\"\n\n\t\"chaitin.cn/dev/go/errors\"\n\n\t"
},
{
"path": "management/webserver/api/endpoints.go",
"chars": 870,
"preview": "package api\n\nconst (\n\tVersion = \"/Version\"\n\tUpgradeTips = \"/UpgradeTips\"\n\tLogin = \"/Lo"
},
{
"path": "management/webserver/api/policygroup.go",
"chars": 3445,
"preview": "package api\n\nimport (\n\t\"encoding/json\"\n\t\"net/http\"\n\n\t\"github.com/gin-gonic/gin\"\n\t\"gorm.io/gorm\"\n\n\t\"chaitin.cn/dev/go/err"
},
{
"path": "management/webserver/api/policyrule.go",
"chars": 4592,
"preview": "package api\n\nimport (\n\t\"net/http\"\n\n\t\"chaitin.cn/patronus/safeline-2/management/webserver/pkg/fvm\"\n\n\t\"github.com/gin-goni"
},
{
"path": "management/webserver/api/response/error.go",
"chars": 282,
"preview": "package response\n\nconst (\n\tErrLoginRequired = \"login-required\"\n\tErrWrongPasscode = \"wrong-passcode\"\n\tErrWrongTimeGap = "
},
{
"path": "management/webserver/api/response/jsonbody.go",
"chars": 1098,
"preview": "package response\n\nimport (\n\t\"net/http\"\n\n\t\"github.com/gin-gonic/gin\"\n)\n\ntype JSONBody struct {\n\tErr string\n\tMsg string\n"
},
{
"path": "management/webserver/api/response/png.go",
"chars": 217,
"preview": "package response\n\nimport (\n\t\"net/http\"\n\n\t\"github.com/gin-gonic/gin\"\n)\n\nconst StreamContentType = \"application/octet-stre"
},
{
"path": "management/webserver/api/website.go",
"chars": 5070,
"preview": "package api\n\nimport (\n\t\"encoding/json\"\n\t\"net/http\"\n\t\"strconv\"\n\n\t\"chaitin.cn/dev/go/errors\"\n\n\t\"github.com/gin-gonic/gin\"\n"
},
{
"path": "management/webserver/cmd/fake_logs.go",
"chars": 131,
"preview": "package cmd\n\nimport \"chaitin.cn/patronus/safeline-2/management/webserver/model\"\n\nfunc FakeLogs() {\n\tmodel.InitDetectLogS"
},
{
"path": "management/webserver/cmd/gen_certs.go",
"chars": 2013,
"preview": "package cmd\n\nimport (\n\t\"crypto/x509/pkix\"\n\t\"path/filepath\"\n\n\t\"chaitin.cn/patronus/safeline-2/management/webserver/pkg/co"
},
{
"path": "management/webserver/cmd/push_fsl.go",
"chars": 222,
"preview": "package cmd\n\nimport (\n\t\"chaitin.cn/patronus/safeline-2/management/webserver/pkg/database\"\n\t\"chaitin.cn/patronus/safeline"
},
{
"path": "management/webserver/cmd/reset_user.go",
"chars": 331,
"preview": "package cmd\n\nimport (\n\t\"chaitin.cn/patronus/safeline-2/management/webserver/model\"\n\t\"chaitin.cn/patronus/safeline-2/mana"
},
{
"path": "management/webserver/cmd/show_fsl.go",
"chars": 240,
"preview": "package cmd\n\nimport (\n\t\"chaitin.cn/patronus/safeline-2/management/webserver/pkg/database\"\n\t\"chaitin.cn/patronus/safeline"
},
{
"path": "management/webserver/config.yml",
"chars": 443,
"preview": "# develop use only. For production, refer to `package/build/mgt-api/webserver/config.yml`\nlog:\n output: stdout "
},
{
"path": "management/webserver/go.mod",
"chars": 2501,
"preview": "module chaitin.cn/patronus/safeline-2/management/webserver\n\ngo 1.21\n\ntoolchain go1.21.3\n\nrequire (\n\tchaitin.cn/dev/go/er"
},
{
"path": "management/webserver/go.sum",
"chars": 20427,
"preview": "chaitin.cn/dev/go/errors v0.0.0-20200717101723-df6132d53dc8/go.mod h1:u+ZD0shdyUt0UG9XfCgD1R5mSqXpTVoO5rwQXQeo3Eo=\nchait"
},
{
"path": "management/webserver/main.go",
"chars": 6296,
"preview": "package main\n\nimport (\n\t\"flag\"\n\t\"fmt\"\n\t\"net/http\"\n\t\"os\"\n\t\"strconv\"\n\t\"strings\"\n\t\"time\"\n\n\t\"github.com/gin-contrib/sessions"
},
{
"path": "management/webserver/middleware/auth.go",
"chars": 1129,
"preview": "package middleware\n\nimport (\n\t\"net/http\"\n\n\t\"github.com/gin-contrib/sessions\"\n\t\"github.com/gin-gonic/gin\"\n\n\t\"chaitin.cn/p"
},
{
"path": "management/webserver/model/base.go",
"chars": 424,
"preview": "package model\n\nimport (\n\t\"time\"\n\n\t\"chaitin.cn/patronus/safeline-2/management/webserver/pkg/log\"\n)\n\n// Base is a replacem"
},
{
"path": "management/webserver/model/behaviour.go",
"chars": 123,
"preview": "package model\n\ntype Behaviour struct {\n\tBase\n\tSrcRouter string `json:\"src_router\"`\n\tDstRouter string `json:\"dst_router\"`"
},
{
"path": "management/webserver/model/db_patch_1_4_0.go",
"chars": 928,
"preview": "package model\n\nimport (\n\t\"strings\"\n\n\t\"chaitin.cn/dev/go/errors\"\n\t\"gorm.io/gorm\"\n)\n\ntype sqlResult struct {\n\tIds string `"
},
{
"path": "management/webserver/model/detectlog.go",
"chars": 5691,
"preview": "package model\n\nimport (\n\t\"fmt\"\n\t\"math/rand\"\n\t\"strings\"\n\t\"time\"\n\n\t\"chaitin.cn/dev/go/errors\"\n\n\t\"chaitin.cn/patronus/safel"
},
{
"path": "management/webserver/model/init.go",
"chars": 786,
"preview": "package model\n\nimport (\n\t\"gorm.io/gorm\"\n\n\t\"chaitin.cn/patronus/safeline-2/management/webserver/pkg/database\"\n)\n\nfunc Ini"
},
{
"path": "management/webserver/model/option.go",
"chars": 1689,
"preview": "package model\n\nimport (\n\t\"bytes\"\n\t\"encoding/json\"\n\t\"net/http\"\n\n\t\"gorm.io/gorm/clause\"\n\n\t\"chaitin.cn/patronus/safeline-2/"
},
{
"path": "management/webserver/model/policygroup.go",
"chars": 10349,
"preview": "package model\n\nimport (\n\t\"encoding/json\"\n\n\t\"gorm.io/gorm\"\n\t\"gorm.io/gorm/clause\"\n\n\t\"chaitin.cn/dev/go/errors\"\n\t\"chaitin."
},
{
"path": "management/webserver/model/policyrule.go",
"chars": 730,
"preview": "package model\n\nimport \"gorm.io/datatypes\"\n\ntype PolicyRule struct {\n\tBase\n\tAction int `gorm:\"action\" "
},
{
"path": "management/webserver/model/statistics.go",
"chars": 453,
"preview": "package model\n\nimport \"time\"\n\ntype SystemStatistics struct {\n\tID uint `json:\"id\" gorm:\"primar"
},
{
"path": "management/webserver/model/user.go",
"chars": 675,
"preview": "package model\n\nimport (\n\t\"gorm.io/gorm/clause\"\n\n\t\"chaitin.cn/patronus/safeline-2/management/webserver/pkg/constants\"\n\t\"c"
},
{
"path": "management/webserver/model/website.go",
"chars": 568,
"preview": "package model\n\nimport \"gorm.io/datatypes\"\n\ntype Website struct {\n\tBase\n\tComment string `gorm:\"comment\" "
},
{
"path": "management/webserver/pkg/config/config.go",
"chars": 945,
"preview": "package config\n\nimport (\n\t\"os\"\n\n\t\"chaitin.cn/dev/go/settings\"\n)\n\nvar (\n\tGlobalConfig = DefaultGlobalConfig()\n)\n\nfunc Ini"
},
{
"path": "management/webserver/pkg/config/db.go",
"chars": 770,
"preview": "package config\n\nimport (\n\t\"net/url\"\n\t\"os\"\n\n\t\"chaitin.cn/dev/go/settings\"\n)\n\ntype DBConfig struct {\n\tURL string `yaml"
},
{
"path": "management/webserver/pkg/config/detector.go",
"chars": 463,
"preview": "package config\n\nimport (\n\t\"chaitin.cn/dev/go/settings\"\n)\n\ntype DetectorConfig struct {\n\tAddr string `yaml:\"addr\"`"
},
{
"path": "management/webserver/pkg/config/global.go",
"chars": 670,
"preview": "package config\n\ntype Config struct {\n\tLog LogConfig\n\tDB DBConfig\n\tServer ServerConfig\n\tDetector"
},
{
"path": "management/webserver/pkg/config/grpc.go",
"chars": 368,
"preview": "package config\n\nimport (\n\t\"chaitin.cn/dev/go/settings\"\n)\n\ntype GRPCConfig struct {\n\tListenAddr string `yaml:\"listen_addr"
},
{
"path": "management/webserver/pkg/config/log.go",
"chars": 391,
"preview": "package config\n\nimport (\n\t\"chaitin.cn/dev/go/settings\"\n)\n\ntype LogConfig struct {\n\tOutput string `yaml:\"output\"`\n\tLevel "
},
{
"path": "management/webserver/pkg/config/server.go",
"chars": 475,
"preview": "package config\n\nimport (\n\t\"chaitin.cn/dev/go/settings\"\n)\n\ntype ServerConfig struct {\n\tListenAddr string `yaml:\"listen_a"
},
{
"path": "management/webserver/pkg/config/telemetry.go",
"chars": 387,
"preview": "package config\n\nimport (\n\t\"chaitin.cn/dev/go/settings\"\n)\n\ntype TelemetryConfig struct {\n\tAddr string `yaml:\"addr\"`\n}\n\nfu"
},
{
"path": "management/webserver/pkg/constants/constants.go",
"chars": 233,
"preview": "package constants\n\nconst (\n\tSuperUser = \"admin\"\n\tProductName = \"长亭雷池 WAF 社区版\"\n\tProductVersion = \"\"\n\tConfigFilePa"
},
{
"path": "management/webserver/pkg/constants/detectlog.go",
"chars": 18925,
"preview": "package constants\n\nconst (\n\tProtocolHTTP = 0\n\tProtocolHTTPS = 1\n\tProtocolHTTP2 = 2\n)\n\nvar (\n\tHTTPProtocol = map[int]str"
},
{
"path": "management/webserver/pkg/constants/detector.go",
"chars": 181,
"preview": "package constants\n\nconst (\n\tContentType = \"application/octet-stream\"\n\tUpdateEntrypoint = \"/update/policy\"\n\t"
},
{
"path": "management/webserver/pkg/constants/option.go",
"chars": 177,
"preview": "package constants\n\nconst (\n\tSecretKey = \"secret_key\"\n\tMachineID = \"machine_id\"\n\tPolicyGroupGlobal = \"pol"
},
{
"path": "management/webserver/pkg/constants/session.go",
"chars": 61,
"preview": "package constants\n\nconst (\n\tDefaultSessionUserKey = \"user\"\n)\n"
},
{
"path": "management/webserver/pkg/constants/telemetry.go",
"chars": 303,
"preview": "package constants\n\nconst (\n\tApplicationJson = \"application/json\"\n\tTelemetryEntryPoint = \"/telemetry\"\n\tTelemetryId "
},
{
"path": "management/webserver/pkg/cron/cron.go",
"chars": 602,
"preview": "package cron\n\nimport (\n\t\"github.com/robfig/cron/v3\"\n\n\t\"chaitin.cn/patronus/safeline-2/management/webserver/pkg/log\"\n)\n\nv"
},
{
"path": "management/webserver/pkg/cron/update_policy.go",
"chars": 2431,
"preview": "package cron\n\nimport (\n\t\"bytes\"\n\t\"encoding/json\"\n\t\"io/ioutil\"\n\t\"net/http\"\n\t\"time\"\n\n\t\"chaitin.cn/patronus/safeline-2/mana"
},
{
"path": "management/webserver/pkg/database/postgres.go",
"chars": 1267,
"preview": "package database\n\nimport (\n\t\"gorm.io/driver/postgres\"\n\t\"gorm.io/gorm\"\n\t\"gorm.io/gorm/logger\"\n\t\"gorm.io/gorm/schema\"\n\n\t\"c"
},
{
"path": "management/webserver/pkg/fvm/fsl/action.go",
"chars": 347,
"preview": "package fsl\n\nimport (\n\t\"fmt\"\n\t\"strings\"\n)\n\nfunc Goto(m string) string {\n\treturn fmt.Sprintf(\"GOTO %s\", m)\n}\n\nfunc Wheres"
},
{
"path": "management/webserver/pkg/fvm/fsl/quote.go",
"chars": 1054,
"preview": "package fsl\n\nimport (\n\t\"fmt\"\n)\n\n// see : https://chaitin.cn/patronus/fvm/-/blob/master/src/util/StrUtil.cpp#L18\n\nfunc ap"
},
{
"path": "management/webserver/pkg/fvm/fsl/selector.go",
"chars": 731,
"preview": "package fsl\n\nimport (\n\t\"fmt\"\n)\n\ntype Selector struct {\n\tTableName string\n\tID string\n\tWhere string\n\tAction "
},
{
"path": "management/webserver/pkg/fvm/fsl/state.go",
"chars": 308,
"preview": "package fsl\n\nimport (\n\t\"chaitin.cn/dev/go/errors\"\n)\n\ntype State int\n\nconst (\n\tS_NOP State = iota\n\tS_ABORT\n\tS_RETURN\n)\n\nf"
},
{
"path": "management/webserver/pkg/fvm/fsl/table.go",
"chars": 758,
"preview": "package fsl\n\nimport (\n\t\"fmt\"\n\t\"strings\"\n)\n\ntype Table struct {\n\tName string\n\tMappings map[State]State\n}\n\nfunc NewTab"
},
{
"path": "management/webserver/pkg/fvm/fsl/target.go",
"chars": 627,
"preview": "package fsl\n\nimport (\n\t\"fmt\"\n)\n\ntype Target struct {\n\tID string\n\tType string\n\tArgs string\n}\n\nfunc NewTarget(id string,"
},
{
"path": "management/webserver/pkg/fvm/fvm.go",
"chars": 5658,
"preview": "package fvm\n\n/*\n#cgo CFLAGS: -I../../submodule/fvm/include -I../../submodule/libct/include\n#cgo LDFLAGS: -L../../submodu"
},
{
"path": "management/webserver/pkg/fvm/generator.go",
"chars": 14198,
"preview": "package fvm\n\nimport (\n\t\"encoding/json\"\n\t\"fmt\"\n\t\"strings\"\n\n\t\"gorm.io/gorm\"\n\n\t\"chaitin.cn/patronus/safeline-2/management/w"
},
{
"path": "management/webserver/pkg/fvm/helper.go",
"chars": 1376,
"preview": "package fvm\n\nimport (\n\t\"chaitin.cn/dev/go/errors\"\n\t\"chaitin.cn/patronus/safeline-2/management/webserver/pkg/config\"\n\t\"ch"
},
{
"path": "management/webserver/pkg/log/log.go",
"chars": 2658,
"preview": "package log\n\nimport (\n\t\"fmt\"\n\t\"os\"\n\t\"runtime\"\n\t\"strings\"\n\n\t\"github.com/sirupsen/logrus\"\n\n\t\"chaitin.cn/dev/go/log\"\n\t\"chai"
},
{
"path": "management/webserver/pkg/telemetry.go",
"chars": 1798,
"preview": "package pkg\n\nimport (\n\t\"fmt\"\n\t\"io\"\n\t\"net/http\"\n\t\"strconv\"\n\t\"time\"\n\n\t\"chaitin.cn/patronus/safeline-2/management/webserver"
},
{
"path": "management/webserver/proto/website/website.proto",
"chars": 371,
"preview": "syntax = \"proto3\";\npackage website;\noption go_package = \"proto/website\";\n\nservice Website {\n rpc Subscribe(stream Respo"
},
{
"path": "management/webserver/rpc/main.go",
"chars": 1015,
"preview": "package rpc\n\nimport (\n\t\"net\"\n\t\"time\"\n\n\t\"google.golang.org/grpc\"\n\n\t\"chaitin.cn/dev/go/errors\"\n\t\"chaitin.cn/dev/go/log\"\n\t\""
},
{
"path": "management/webserver/rpc/website.go",
"chars": 4334,
"preview": "package rpc\n\nimport (\n\t\"encoding/json\"\n\t\"io\"\n\t\"time\"\n\n\t\"chaitin.cn/dev/go/errors\"\n\t\"chaitin.cn/patronus/safeline-2/manag"
},
{
"path": "management/webserver/tools/init_db.sh",
"chars": 386,
"preview": "docker rm -f mgt-postgres-dev\n\n#docker run -it -d -e POSTGRES_DB=safeline-ce -e POSTGRES_USER=safeline-ce -e POSTGRES_PA"
},
{
"path": "management/webserver/utils/cert.go",
"chars": 2719,
"preview": "package utils\n\nimport (\n\t\"bytes\"\n\t\"crypto/rand\"\n\t\"crypto/rsa\"\n\t\"crypto/x509\"\n\t\"crypto/x509/pkix\"\n\t\"encoding/pem\"\n\t\"io/io"
},
{
"path": "management/webserver/utils/file.go",
"chars": 1426,
"preview": "package utils\n\nimport (\n\t\"fmt\"\n\t\"io/ioutil\"\n\t\"os\"\n\t\"path/filepath\"\n)\n\nfunc EnsureDir(dir string) error {\n\tif _, err := o"
},
{
"path": "management/webserver/utils/healthy.go",
"chars": 545,
"preview": "package utils\n\nimport (\n\t\"fmt\"\n\t\"net/http\"\n)\n\nfunc CheckHealthy(url string) bool {\n\tmethod := \"GET\"\n\n\tclient := &http.Cl"
},
{
"path": "management/webserver/utils/httpclient.go",
"chars": 562,
"preview": "package utils\n\nimport (\n\t\"crypto/tls\"\n\t\"net/http\"\n\t\"net/url\"\n\t\"os\"\n\t\"time\"\n)\n\nconst proxyName = \"HTTPS_PROXY\"\n\nvar httpC"
},
{
"path": "management/webserver/utils/random.go",
"chars": 297,
"preview": "package utils\n\nimport (\n\t\"math/rand\"\n\t\"time\"\n)\n\nvar letters = []rune(\"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWX"
},
{
"path": "management/webserver/utils/url.go",
"chars": 835,
"preview": "package utils\n\nimport (\n\t\"fmt\"\n\t\"net\"\n\t\"strings\"\n\n\t\"chaitin.cn/patronus/safeline-2/management/webserver/pkg/constants\"\n)"
},
{
"path": "mcp_server/Dockerfile",
"chars": 391,
"preview": "FROM golang:1.24-alpine AS builder\n\nWORKDIR /app\n\nRUN apk add --no-cache git\n\nCOPY go.mod go.sum ./\n\nRUN go mod download"
},
{
"path": "mcp_server/README.md",
"chars": 7054,
"preview": "# SafeLine MCP Server\n\nSafeLine MCP Server is an implementation of the [Model Context Protocol (MCP)](https://modelconte"
},
{
"path": "mcp_server/config.yaml",
"chars": 981,
"preview": "# Server Configuration\nserver:\n name: \"SafeLine MCP Server\"\n version: \"1.0.0\"\n # Can be overridden by environment var"
},
{
"path": "mcp_server/docker-compose.yml",
"chars": 577,
"preview": "version: '3.8'\n\nservices:\n mcp_server:\n image: chaitin/safeline-mcp:latest\n container_name: mcp_server\n restar"
},
{
"path": "mcp_server/go.mod",
"chars": 350,
"preview": "module github.com/chaitin/SafeLine/mcp_server\n\ngo 1.24.1\n\nrequire (\n\tgithub.com/mark3labs/mcp-go v0.18.0\n\tgo.uber.org/za"
},
{
"path": "mcp_server/go.sum",
"chars": 2440,
"preview": "github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=\ngithub.com/davecgh/go-spew v1.1.1/go.m"
},
{
"path": "mcp_server/internal/api/analyze/get_event_list.go",
"chars": 1279,
"preview": "package analyze\n\nimport (\n\t\"context\"\n\t\"fmt\"\n\n\t\"github.com/chaitin/SafeLine/mcp_server/internal/api\"\n)\n\ntype GetEventList"
},
{
"path": "mcp_server/internal/api/app/create_application.go",
"chars": 772,
"preview": "package app\n\nimport (\n\t\"context\"\n\n\t\"github.com/chaitin/SafeLine/mcp_server/internal/api\"\n\t\"github.com/chaitin/SafeLine/m"
},
{
"path": "mcp_server/internal/api/client.go",
"chars": 3868,
"preview": "package api\n\nimport (\n\t\"bytes\"\n\t\"context\"\n\t\"crypto/tls\"\n\t\"encoding/json\"\n\t\"fmt\"\n\t\"io\"\n\t\"net/http\"\n\t\"time\"\n\n\t\"github.com/"
},
{
"path": "mcp_server/internal/api/response.go",
"chars": 211,
"preview": "package api\n\n// Response Common API response structure\ntype Response[T any] struct {\n\t// Response data\n\tData T `json:\"da"
},
{
"path": "mcp_server/internal/api/rule/create_rule.go",
"chars": 830,
"preview": "package rule\n\nimport (\n\t\"context\"\n\n\t\"github.com/chaitin/SafeLine/mcp_server/internal/api\"\n\t\"github.com/chaitin/SafeLine/"
},
{
"path": "mcp_server/internal/api/service.go",
"chars": 2404,
"preview": "package api\n\nimport (\n\t\"context\"\n\t\"sync\"\n\t\"time\"\n\n\t\"github.com/chaitin/SafeLine/mcp_server/internal/config\"\n\t\"github.com"
},
{
"path": "mcp_server/internal/api/types.go",
"chars": 1223,
"preview": "package api\n\ntype PolicyRuleAction int\n\nconst (\n\tPolicyRuleActionAllow PolicyRuleAction = iota\n\tPolicyRuleActionDeny\n\tPo"
},
{
"path": "mcp_server/internal/config/config.go",
"chars": 2778,
"preview": "package config\n\nimport (\n\t\"os\"\n\t\"strconv\"\n\n\t\"github.com/chaitin/SafeLine/mcp_server/pkg/errors\"\n\t\"gopkg.in/yaml.v3\"\n)\n\n/"
},
{
"path": "mcp_server/internal/tools/analyze/get_atttack_events.go",
"chars": 1333,
"preview": "package analyze\n\nimport (\n\t\"context\"\n\n\t\"github.com/chaitin/SafeLine/mcp_server/internal/api/analyze\"\n\t\"github.com/chaiti"
},
{
"path": "mcp_server/internal/tools/app/create_application.go",
"chars": 1025,
"preview": "package app\n\nimport (\n\t\"context\"\n\n\t\"github.com/chaitin/SafeLine/mcp_server/internal/api/app\"\n\t\"github.com/chaitin/SafeLi"
},
{
"path": "mcp_server/internal/tools/example.go",
"chars": 923,
"preview": "package tools\n\nimport (\n\t\"context\"\n\n\t\"github.com/chaitin/SafeLine/mcp_server/pkg/errors\"\n\t\"github.com/chaitin/SafeLine/m"
},
{
"path": "mcp_server/internal/tools/init.go",
"chars": 414,
"preview": "package tools\n\nimport (\n\t\"github.com/chaitin/SafeLine/mcp_server/internal/tools/analyze\"\n\t\"github.com/chaitin/SafeLine/m"
},
{
"path": "mcp_server/internal/tools/rule/create_blacklist_rule.go",
"chars": 1563,
"preview": "package rule\n\nimport (\n\t\"context\"\n\n\t\"github.com/chaitin/SafeLine/mcp_server/internal/api\"\n\t\"github.com/chaitin/SafeLine/"
},
{
"path": "mcp_server/internal/tools/rule/create_whitelist_rule.go",
"chars": 1564,
"preview": "package rule\n\nimport (\n\t\"context\"\n\n\t\"github.com/chaitin/SafeLine/mcp_server/internal/api\"\n\t\"github.com/chaitin/SafeLine/"
},
{
"path": "mcp_server/internal/tools/tool.go",
"chars": 966,
"preview": "package tools\n\nimport (\n\t\"github.com/chaitin/SafeLine/mcp_server/pkg/logger\"\n\t\"github.com/chaitin/SafeLine/mcp_server/pk"
},
{
"path": "mcp_server/main.go",
"chars": 1665,
"preview": "package main\n\nimport (\n\t\"flag\"\n\t\"fmt\"\n\n\t\"github.com/chaitin/SafeLine/mcp_server/internal/api\"\n\t\"github.com/chaitin/SafeL"
},
{
"path": "mcp_server/pkg/config/config.go",
"chars": 1358,
"preview": "package config\n\nimport (\n\t\"os\"\n\n\t\"gopkg.in/yaml.v3\"\n)\n\n// Config Global configuration structure\ntype Config struct {\n\tSe"
},
{
"path": "mcp_server/pkg/errors/errors.go",
"chars": 2584,
"preview": "package errors\n\nimport (\n\t\"errors\"\n\t\"fmt\"\n\t\"runtime\"\n\t\"strings\"\n\n\t\"github.com/chaitin/SafeLine/mcp_server/pkg/logger\"\n)\n"
},
{
"path": "mcp_server/pkg/logger/field.go",
"chars": 826,
"preview": "package logger\n\nimport (\n\t\"go.uber.org/zap\"\n\t\"go.uber.org/zap/zapcore\"\n)\n\n// Field 日志字段\ntype Field = zapcore.Field\n\n// S"
},
{
"path": "mcp_server/pkg/logger/logger.go",
"chars": 4159,
"preview": "package logger\n\nimport (\n\t\"os\"\n\t\"path/filepath\"\n\t\"sync\"\n\t\"time\"\n\n\t\"go.uber.org/zap\"\n\t\"go.uber.org/zap/zapcore\"\n)\n\n// Log"
},
{
"path": "mcp_server/pkg/mcp/mcp.go",
"chars": 3375,
"preview": "package mcp\n\nimport (\n\t\"context\"\n\t\"encoding/json\"\n\t\"fmt\"\n\t\"net/http\"\n\t\"strconv\"\n\n\t\"github.com/chaitin/SafeLine/mcp_serve"
},
{
"path": "mcp_server/pkg/mcp/schema.go",
"chars": 4964,
"preview": "package mcp\n\nimport (\n\t\"encoding/json\"\n\t\"reflect\"\n\t\"strconv\"\n\t\"strings\"\n\n\t\"github.com/mark3labs/mcp-go/mcp\"\n)\n\n// Schema"
},
{
"path": "mcp_server/pkg/mcp/schema_test.go",
"chars": 5782,
"preview": "package mcp\n\nimport (\n\t\"reflect\"\n\t\"testing\"\n\n\t\"github.com/mark3labs/mcp-go/mcp\"\n)\n\nfunc TestSchemaToOptions(t *testing.T"
},
{
"path": "scripts/manage.py",
"chars": 49286,
"preview": "#!/usr/bin/env python3\nimport argparse\nimport base64\nimport json\nimport shutil\nimport ssl\nimport sys\nimport datetime\nimp"
},
{
"path": "sdk/ingress-nginx/README.md",
"chars": 3774,
"preview": "# ingress-nginx-safeline\n\n[Ingress-nginx](https://kubernetes.github.io/ingress-nginx/) plugin for Chaitin SafeLine Web A"
},
{
"path": "sdk/ingress-nginx/ingress-nginx-safeline-1.0.2-1.rockspec",
"chars": 534,
"preview": "package = \"ingress-nginx-safeline\"\nversion = \"1.0.2-1\"\nsource = {\n url = \"git://github.com/xbingW/ingress-nginx-safeli"
},
{
"path": "sdk/ingress-nginx/ingress-nginx-safeline-1.0.3-1.rockspec",
"chars": 543,
"preview": "package = \"ingress-nginx-safeline\"\nversion = \"1.0.3-1\"\nsource = {\n url = \"git://github.com/xbingW/ingress-nginx-safeli"
},
{
"path": "sdk/ingress-nginx/ingress-nginx-safeline-1.0.4-1.rockspec",
"chars": 545,
"preview": "package = \"ingress-nginx-safeline\"\nversion = \"1.0.4-1\"\nsource = {\n url = \"git://github.com/chaitin/ingress-nginx-safel"
},
{
"path": "sdk/ingress-nginx/lib/safeline/main.lua",
"chars": 1973,
"preview": "local t1k = require \"resty.t1k\"\nlocal t1k_constants = require \"resty.t1k.constants\"\n\nlocal ngx = ngx\nlocal fmt = string."
},
{
"path": "sdk/kong/Readme.md",
"chars": 2467,
"preview": "# Kong Safeline Plugin\nKong plugin for Chaitin SafeLine Web Application Firewall (WAF). This plugin is used to protect y"
},
{
"path": "sdk/kong/kong/plugins/safeline/handler.lua",
"chars": 1403,
"preview": "local t1k = require \"resty.t1k\"\nlocal t1k_constants = require \"resty.t1k.constants\"\n\nlocal fmt = string.format\n\nlocal Sa"
},
{
"path": "sdk/kong/kong/plugins/safeline/schema.lua",
"chars": 2014,
"preview": "local typedefs = require \"kong.db.schema.typedefs\"\n\nreturn {\n name = \"kong-safeline\",\n fields = {{\n consume"
},
{
"path": "sdk/kong/kong-safeline-1.0.0-1.rockspec",
"chars": 602,
"preview": "package = \"kong-safeline\"\nversion = \"1.0.0-1\"\nsource = {\n url = \"git://github.com/xbingW/kong-safeline.git\"\n}\ndescript"
},
{
"path": "sdk/kong/kong-safeline-1.0.1-1.rockspec",
"chars": 602,
"preview": "package = \"kong-safeline\"\nversion = \"1.0.1-1\"\nsource = {\n url = \"git://github.com/xbingW/kong-safeline.git\"\n}\ndescript"
},
{
"path": "sdk/kong/kong-safeline-1.0.2-1.rockspec",
"chars": 611,
"preview": "package = \"kong-safeline\"\nversion = \"1.0.2-1\"\nsource = {\n url = \"git://github.com/xbingW/kong-safeline.git\"\n}\ndescript"
},
{
"path": "sdk/kong/kong-safeline-1.0.3-1.rockspec",
"chars": 779,
"preview": "package = \"kong-safeline\"\nversion = \"1.0.3-1\"\nsource = {\n url = \"file://kong-safeline-1.0.3.tar.gz\",\n}\nbuild = {\n typ"
},
{
"path": "sdk/kong/kong-safeline-1.0.4-1.rockspec",
"chars": 783,
"preview": "package = \"kong-safeline\"\nversion = \"1.0.4-1\"\nsource = {\n url = \"git://github.com/chaitin/SafeLine.git\",\n}\nbuild = {\n "
},
{
"path": "sdk/kong/kong-safeline-1.0.5-1.rockspec",
"chars": 783,
"preview": "package = \"kong-safeline\"\nversion = \"1.0.5-1\"\nsource = {\n url = \"git://github.com/chaitin/SafeLine.git\",\n}\nbuild = {\n "
},
{
"path": "sdk/kong/kong-safeline-1.0.6-1.rockspec",
"chars": 608,
"preview": "package = \"kong-safeline\"\nversion = \"1.0.6-1\"\nsource = {\n url = \"git://github.com/xbingW/kong-safeline.git\",\n}\ndescrip"
},
{
"path": "sdk/kong/kong-safeline-1.0.7-1.rockspec",
"chars": 609,
"preview": "package = \"kong-safeline\"\nversion = \"1.0.7-1\"\nsource = {\n url = \"git://github.com/chaitin/kong-safeline.git\",\n}\ndescri"
},
{
"path": "sdk/lua-resty-t1k/.github/workflows/release.yml",
"chars": 1210,
"preview": "name: Release\n\non:\n push:\n tags:\n - \"v*\"\n\njobs:\n release:\n name: Release\n runs-on: ubuntu-latest\n ste"
},
{
"path": "sdk/lua-resty-t1k/.github/workflows/test.yml",
"chars": 1704,
"preview": "name: Test\n\non: [ push, pull_request ]\n\njobs:\n luacheck:\n runs-on: ubuntu-latest\n steps:\n - uses: actions/ch"
},
{
"path": "sdk/lua-resty-t1k/.gitignore",
"chars": 354,
"preview": "# IntelliJ project files\n.idea\n*.iml\nout\ngen\n\n# Visual Studio Code\n.vscode/*\n!.vscode/settings.json\n!.vscode/tasks.json\n"
},
{
"path": "sdk/lua-resty-t1k/.luacheckrc",
"chars": 142,
"preview": "std = \"ngx_lua\"\nredefined = false\nmax_line_length = 130\nmax_code_line_length = 130\nmax_string_line_length = 130\nmax_comm"
},
{
"path": "sdk/lua-resty-t1k/LICENSE",
"chars": 11366,
"preview": " Apache License\n Version 2.0, January 2004\n "
},
{
"path": "sdk/lua-resty-t1k/README.md",
"chars": 3549,
"preview": "# lua-resty-t1k\n\n[](https://lua"
},
{
"path": "sdk/lua-resty-t1k/ci/.dockerignore",
"chars": 10,
"preview": "/bytecode\n"
},
{
"path": "sdk/lua-resty-t1k/ci/Dockerfile",
"chars": 296,
"preview": "# Usage:\n# docker build -t chaitin/safeline-detector:t1k-ci-1.6.0 .\n# docker push chaitin/safeline-detector:t1k-ci-1"
},
{
"path": "sdk/lua-resty-t1k/lib/resty/t1k/buffer.lua",
"chars": 320,
"preview": "local _M = {\n _VERSION = '1.0.0',\n}\n\nfunction _M:new(o)\n o = o or {}\n setmetatable(o, self)\n self.__index = "
},
{
"path": "sdk/lua-resty-t1k/lib/resty/t1k/constants.lua",
"chars": 583,
"preview": "local t = {}\n\nt.ACTION_PASSED = \".\"\nt.ACTION_BLOCKED = \"?\"\n\nt.MODE_OFF = \"off\"\nt.MODE_BLOCK = \"block\"\nt.MODE_MONITOR = \""
},
{
"path": "sdk/lua-resty-t1k/lib/resty/t1k/file.lua",
"chars": 644,
"preview": "local buffer = require \"resty.t1k.buffer\"\n\nlocal _M = {\n _VERSION = '1.0.0'\n}\n\nlocal buffer_size = 2 ^ 13\n\nfunction _"
},
{
"path": "sdk/lua-resty-t1k/lib/resty/t1k/filter.lua",
"chars": 1014,
"preview": "local _M = {\n _VERSION = '1.0.0'\n}\n\nlocal find = string.find\nlocal sub = string.sub\n\nlocal ngx = ngx\n\nlocal function "
},
{
"path": "sdk/lua-resty-t1k/lib/resty/t1k/handler.lua",
"chars": 871,
"preview": "local consts = require \"resty.t1k.constants\"\nlocal log = require \"resty.t1k.log\"\n\nlocal fmt = string.format\n\nlocal ngx ="
},
{
"path": "sdk/lua-resty-t1k/lib/resty/t1k/log.lua",
"chars": 502,
"preview": "local _M = {\n _VERSION = '1.0.0'\n}\n\nlocal fmt = string.format\n\nlocal ERR = ngx.ERR\nlocal WARN = ngx.WARN\nlocal DEBUG "
},
{
"path": "sdk/lua-resty-t1k/lib/resty/t1k/request.lua",
"chars": 10286,
"preview": "local bit = require \"bit\"\n\nlocal buffer = require \"resty.t1k.buffer\"\nlocal consts = require \"resty.t1k.constants\"\nlocal "
},
{
"path": "sdk/lua-resty-t1k/lib/resty/t1k/utils.lua",
"chars": 2593,
"preview": "local consts = require \"resty.t1k.constants\"\n\nlocal _M = {\n _VERSION = '1.0.0'\n}\n\nlocal band = bit.band\nlocal bnot = "
},
{
"path": "sdk/lua-resty-t1k/lib/resty/t1k/uuid.lua",
"chars": 2728,
"preview": "local bit = require \"bit\"\nlocal ffi = require \"ffi\"\n\nlocal log = require \"resty.t1k.log\"\n\nlocal _M = {\n _VERSION = '1"
},
{
"path": "sdk/lua-resty-t1k/lib/resty/t1k.lua",
"chars": 2637,
"preview": "local consts = require \"resty.t1k.constants\"\nlocal filter = require \"resty.t1k.filter\"\nlocal handler = require \"resty.t1"
},
{
"path": "sdk/lua-resty-t1k/mainspec/lua-resty-t1k-main-0-0.rockspec",
"chars": 1126,
"preview": "package = \"lua-resty-t1k-main\"\nversion = \"0-0\"\nsource = {\n url = \"git://github.com/chaitin/lua-resty-t1k\",\n branch"
},
{
"path": "sdk/lua-resty-t1k/rockspec/lua-resty-t1k-1.0.0-0.rockspec",
"chars": 1123,
"preview": "package = \"lua-resty-t1k\"\nversion = \"1.0.0-0\"\nsource = {\n url = \"git://github.com/chaitin/lua-resty-t1k\",\n tag = \""
},
{
"path": "sdk/lua-resty-t1k/rockspec/lua-resty-t1k-1.0.1-0.rockspec",
"chars": 1123,
"preview": "package = \"lua-resty-t1k\"\nversion = \"1.0.1-0\"\nsource = {\n url = \"git://github.com/chaitin/lua-resty-t1k\",\n tag = \""
},
{
"path": "sdk/lua-resty-t1k/rockspec/lua-resty-t1k-1.0.2-0.rockspec",
"chars": 1123,
"preview": "package = \"lua-resty-t1k\"\nversion = \"1.0.2-0\"\nsource = {\n url = \"git://github.com/chaitin/lua-resty-t1k\",\n tag = \""
},
{
"path": "sdk/lua-resty-t1k/rockspec/lua-resty-t1k-1.0.3-0.rockspec",
"chars": 1123,
"preview": "package = \"lua-resty-t1k\"\nversion = \"1.0.3-0\"\nsource = {\n url = \"git://github.com/chaitin/lua-resty-t1k\",\n tag = \""
},
{
"path": "sdk/lua-resty-t1k/rockspec/lua-resty-t1k-1.1.0-0.rockspec",
"chars": 1123,
"preview": "package = \"lua-resty-t1k\"\nversion = \"1.1.0-0\"\nsource = {\n url = \"git://github.com/chaitin/lua-resty-t1k\",\n tag = \""
},
{
"path": "sdk/lua-resty-t1k/rockspec/lua-resty-t1k-1.1.1-0.rockspec",
"chars": 1123,
"preview": "package = \"lua-resty-t1k\"\nversion = \"1.1.1-0\"\nsource = {\n url = \"git://github.com/chaitin/lua-resty-t1k\",\n tag = \""
},
{
"path": "sdk/lua-resty-t1k/rockspec/lua-resty-t1k-1.1.2-0.rockspec",
"chars": 1123,
"preview": "package = \"lua-resty-t1k\"\nversion = \"1.1.2-0\"\nsource = {\n url = \"git://github.com/chaitin/lua-resty-t1k\",\n tag = \""
},
{
"path": "sdk/lua-resty-t1k/rockspec/lua-resty-t1k-1.1.3-0.rockspec",
"chars": 1123,
"preview": "package = \"lua-resty-t1k\"\nversion = \"1.1.3-0\"\nsource = {\n url = \"git://github.com/chaitin/lua-resty-t1k\",\n tag = \""
},
{
"path": "sdk/lua-resty-t1k/rockspec/lua-resty-t1k-1.1.4-0.rockspec",
"chars": 1123,
"preview": "package = \"lua-resty-t1k\"\nversion = \"1.1.4-0\"\nsource = {\n url = \"git://github.com/chaitin/lua-resty-t1k\",\n tag = \""
},
{
"path": "sdk/lua-resty-t1k/rockspec/lua-resty-t1k-1.1.5-0.rockspec",
"chars": 1123,
"preview": "package = \"lua-resty-t1k\"\nversion = \"1.1.5-0\"\nsource = {\n url = \"git://github.com/chaitin/lua-resty-t1k\",\n tag = \""
},
{
"path": "sdk/lua-resty-t1k/t/buffer.t",
"chars": 692,
"preview": "use Test::Nginx::Socket;\n\nour $HttpConfig = <<'_EOC_';\n lua_package_path \"lib/?.lua;/usr/local/share/lua/5.1/?.lua;;\""
},
{
"path": "sdk/lua-resty-t1k/t/file.t",
"chars": 2879,
"preview": "use Test::Nginx::Socket;\n\nour $HttpConfig = <<'_EOC_';\n lua_package_path \"lib/?.lua;/usr/local/share/lua/5.1/?.lua;;\""
},
{
"path": "sdk/lua-resty-t1k/t/filter.t",
"chars": 714,
"preview": "use Test::Nginx::Socket;\n\nour $HttpConfig = <<'_EOC_';\n lua_package_path \"lib/?.lua;/usr/local/share/lua/5.1/?.lua;;\""
},
{
"path": "sdk/lua-resty-t1k/t/handler.t",
"chars": 2799,
"preview": "use Test::Nginx::Socket;\n\nour $HttpConfig = <<'_EOC_';\n lua_package_path \"lib/?.lua;/usr/local/share/lua/5.1/?.lua;;\""
},
{
"path": "sdk/lua-resty-t1k/t/integration.t",
"chars": 29002,
"preview": "use Test::Nginx::Socket 'no_plan';\n\nour $MainConfig = <<'_EOC_';\nenv DETECTOR_IP;\n_EOC_\n\nour $HttpConfig = <<'_EOC_';\n "
},
{
"path": "sdk/lua-resty-t1k/t/log.t",
"chars": 1301,
"preview": "use Test::Nginx::Socket;\n\nour $HttpConfig = <<'_EOC_';\n lua_package_path \"lib/?.lua;/usr/local/share/lua/5.1/?.lua;;\""
},
{
"path": "sdk/lua-resty-t1k/t/option.t",
"chars": 3211,
"preview": "use Test::Nginx::Socket;\n\nour $HttpConfig = <<'_EOC_';\n lua_package_path \"lib/?.lua;/usr/local/share/lua/5.1/?.lua;;\""
},
{
"path": "sdk/lua-resty-t1k/t/request.t",
"chars": 16964,
"preview": "use Test::Nginx::Socket;\n\nour $HttpConfig = <<'_EOC_';\n lua_package_path \"lib/?.lua;/usr/local/share/lua/5.1/?.lua;;\""
},
{
"path": "sdk/lua-resty-t1k/t/utils.t",
"chars": 8230,
"preview": "use Test::Nginx::Socket;\n\nour $HttpConfig = <<'_EOC_';\n lua_package_path \"lib/?.lua;/usr/local/share/lua/5.1/?.lua;;\""
},
{
"path": "sdk/lua-resty-t1k/t/uuid.t",
"chars": 576,
"preview": "use Test::Nginx::Socket;\n\nour $HttpConfig = <<'_EOC_';\n lua_package_path \"lib/?.lua;/usr/local/share/lua/5.1/?.lua;;\""
},
{
"path": "version.json",
"chars": 91,
"preview": "{\n \"latest_version\": \"v9.2.7\",\n \"rec_version\": \"v9.2.7\",\n \"lts_version\": \"v9.1.0-lts\"\n}\n"
},
{
"path": "yanshi/.gitignore",
"chars": 84,
"preview": "*.o\n*.dot\n*.output\n/build\n/src/parser.cc\n/src/parser.hh\n/src/lexer.cc\n/src/lexer.hh\n"
},
{
"path": "yanshi/Makefile",
"chars": 1618,
"preview": "CPPFLAGS := -g3 -std=c++1y -Isrc -I. -DHAVE_READLINE\n\nifeq ($(build),release)\n BUILD := release\n CPPFLAGS += -Os\nelse\n"
},
{
"path": "yanshi/README.md",
"chars": 8216,
"preview": "# 偃师 (yanshi)\n\nyanshi is a finite state automaton generator like Ragel. Use inline operators to embed C++ code in the re"
}
]
// ... and 36 more files (download for full content)
About this extraction
This page contains the full source code of the chaitin/SafeLine GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 236 files (649.6 KB), approximately 209.4k tokens, and a symbol index with 899 extracted functions, classes, methods, constants, and types. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.
Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.