Skip to content
This repository has been archived by the owner on Sep 12, 2024. It is now read-only.

Commit

Permalink
Update: 0.2.0发布
Browse files Browse the repository at this point in the history
前端静态文件打包进二进制 数据库增加对sqlite的支持
  • Loading branch information
jweny committed May 17, 2021
1 parent 5f01777 commit fa7d653
Show file tree
Hide file tree
Showing 107 changed files with 1,838 additions and 16,574 deletions.
117 changes: 74 additions & 43 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ pocassist借鉴了xray优秀的规则体系。但这不是一个xray的轮子,

### web

前端UI使用 react + antd开发。已单独拆分成一个项目,有兴趣的可以单独看这里:

https://github.com/jweny/pocassistweb

![登录页](pic.assets/登录页.jpg)


Expand Down Expand Up @@ -87,50 +91,19 @@ poc测试(漏洞检测):

### 部署

部署过程非常简单,从release中下载相应系统版本的zip文件,其中包括:
1. 从release中下载相应系统版本的zip文件,其中包括:

- pocassist二进制文件
- 打包好的前端 `build`文件夹
- config.yaml

#### api
- 二进制文件:pocassist
- 配置文件:config.yaml
- 数据库文件:sqlite(pocassist.db) + mysql(pocassist.sql)

1. 创建pocassist数据库,并将pocassist.sql导入。
2. 编辑config.yaml,配置数据库以及其他个性化配置
3. 运行服务端
- 如果使用默认端口(默认端口:1231):`./pocassist server`
- 如果使用其他端口,如8888:`./pocassist server --port 8888`

#### 前端

1. 准备release中的`build`
2. 安装nginx。修改nginx.conf反向代理后端。
3. 运行

```
upstream pocassistAPI {
# 配置后端端口
server 127.0.0.1:1231;
}
server {
listen 80;
location / {
# 配置build文件夹路径
root /opt/pocassistWEB/build/;
}
location /api/ {
proxy_pass http://pocassistAPI/api/;
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
```
- 如果使用默认端口(默认端口:1231):`./pocassist server`
- 如果使用其他端口,如8888:`./pocassist server --port`
- 默认使用sqlite数据库,如果使用mysql请自行建库导数据。

### 开发

Expand All @@ -143,7 +116,7 @@ cd pocassist
go build -o pocassist
# 创建数据库,导入数据,修改config.yaml
# 创建数据库修改config.yaml
./pocassist
```
Expand All @@ -155,7 +128,6 @@ develope模式下前端默认运行在3333端口
后端在craco.config.js中配置,默认为`127.0.0.1:1231`

```
# 启动前端
cd pocassist/web
yarn start
Expand All @@ -165,9 +137,15 @@ yarn start

## 使用

![0.2.0help-1](pic.assets/0.2.0help-1.jpg)

### web

==========详细的web端使用手册正在疯狂编写中==============
```
./pocassist server -p 端口
```

==========详细的web界面使用手册正在疯狂编写中==============

### cli

Expand Down Expand Up @@ -239,7 +217,60 @@ yarn start
go env -w GO111MODULE=on
```

4. 如果使用前后端分离部署的师傅依旧可以使用0.1.0版本,部署方式

从release中下载相应系统版本的zip文件,其中包括:

- pocassist二进制文件

- 打包好的前端 `build`文件夹

- config.yaml

api

1. 创建pocassist数据库,并将pocassist.sql导入。

2. 编辑config.yaml,配置数据库以及其他个性化配置

3. 运行服务端

- 如果使用默认端口(默认端口:1231):`./pocassist server`
- 如果使用其他端口,如8888:`./pocassist server --port 8888`

web

4. 准备release中的`build`

5. 安装nginx。修改nginx.conf反向代理后端。

```
upstream pocassistAPI {
# 配置后端端口
server 127.0.0.1:1231;
}
server {
listen 80;
location / {
# 配置build文件夹路径
root /opt/pocassistWEB/build/;
}
location /api/ {
proxy_pass http://pocassistAPI/api/;
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
```

###

## todo

Expand All @@ -253,7 +284,7 @@ yarn start

- 收集更多的poc

- 实现一个二进制走天下:数据库支持sqlite,并将前端打包进二进制
- ~~实现一个二进制走天下:数据库支持sqlite,并将前端打包进二进制~~ 已经搞定



Expand Down
62 changes: 57 additions & 5 deletions api/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ package api

import (
"github.com/astaxie/beego/validation"
assetfs "github.com/elazarl/go-bindata-assetfs"
"github.com/gin-gonic/gin"
"net/http"
"pocassist/ui"
"strings"
)

const (
Expand All @@ -13,7 +16,7 @@ const (

func init() {
// release 如果需要debug 此处改为 gin.DebugMode
gin.SetMode(gin.ReleaseMode)
gin.SetMode(gin.DebugMode)
}

// API Response 基础序列化器
Expand Down Expand Up @@ -43,20 +46,69 @@ func SuccessResp(data interface{}) (int,Response) {
return http.StatusOK, res
}

func DealValidError(valid validation.Validation) (string) {
func DealValidError(valid validation.Validation) string {
errStr := "参数校验不通过:"
for _, err := range valid.Errors {
errStr += err.Message + ";"
}
return errStr
}


type binaryFileSystem struct {
fs http.FileSystem
}

func (b *binaryFileSystem) Open(name string) (http.File, error) {
return b.fs.Open(name)
}

func (b *binaryFileSystem) Exists(prefix, filepath string) bool {
if p := strings.TrimPrefix(filepath, prefix); len(p) > len(filepath) {
if _, err := b.fs.Open(p); err != nil {
return false
}
return true
}
return false
}

// BinaryFileSystem ...
func BinaryFileSystem(root string) *binaryFileSystem {
return &binaryFileSystem{
fs: &assetfs.AssetFS{
Asset: ui.Asset,
AssetDir: ui.AssetDir,
AssetInfo: ui.AssetInfo,
Prefix: root,
},
}
}


func Route(port string) {
router := gin.Default()
// 无需身份校验的接口
// web
//router.Use(static.Serve("/static", BinaryFileSystem("ui/build")))
//router.StaticFS("/css", BinaryFileSystem("ui/build/static"))
//router.StaticFS("/js", BinaryFileSystem("ui/build/static"))
//router.StaticFS("/media", BinaryFileSystem("ui/build/static"))
//
//router.GET("/", func(c *gin.Context) {
// c.Writer.WriteHeader(200)
// indexHtml, _ := ui.Asset("ui/build/index.html")
// _, _ = c.Writer.Write(indexHtml)
// c.Writer.Header().Add("Accept", "text/html")
// c.Writer.Flush()
//})
router.StaticFS("/ui", BinaryFileSystem("ui/build"))

router.GET("/", func(c *gin.Context) {
c.Redirect(http.StatusPermanentRedirect, "/ui")
})

// api
router.POST("/api/v1/user/login", GetAuth)


pluginRoutes := router.Group("/api/v1/poc")
pluginRoutes.Use(JWT())
{
Expand Down
9 changes: 7 additions & 2 deletions basic/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ type Headers struct {
UserAgent string `mapstructure:"user_agent"`
}

// DbConfig
type DbConfig struct {
type Mysql struct {
Host string `mapstructure:"host"`
Password string `mapstructure:"password"`
Port string `mapstructure:"port"`
Expand All @@ -20,6 +19,12 @@ type DbConfig struct {
Timeout string `mapstructure:"timeout"`
}

// DbConfig
type DbConfig struct {
Sqlite string `mapstructure:"sqlite"`
Mysql Mysql `mapstructure:"mysql"`
}

// PluginsConfig
type PluginsConfig struct {
Parallel int `mapstructure:"parallel"`
Expand Down
24 changes: 17 additions & 7 deletions cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ var (
loadPoc string
condition string
debug bool
dbname string
)

func InitAll() error {
Expand All @@ -44,7 +45,7 @@ func InitAll() error {
}
basic.GlobalLogger.Debug("[config.yaml init success]")
// 建立数据库连接
err = database.InitDB()
err = database.InitDB(dbname)
if err != nil {
return err
}
Expand All @@ -68,14 +69,23 @@ func RunApp() {
app.Usage = "New POC Framework Without Writing Code"
app.Version = "1.0.0"
// 全局flag
app.Flags = []cli.Flag{ &cli.BoolFlag{
Name: "debug",
Aliases: []string{"d"},
Destination: &debug,
Value: false,
Usage: "enable debug log"},
app.Flags = []cli.Flag{
&cli.BoolFlag{
Name: "debug",
Aliases: []string{"d"},
Destination: &debug,
Value: false,
Usage: "enable debug log"},
&cli.StringFlag{
Name: "database",
Aliases: []string{"db"},
Destination: &dbname,
Value: "sqlite",
Usage: "kind of database, default: sqlite"},
}



// 子命令
app.Commands = []*cli.Command{
&subCommandCli,
Expand Down
2 changes: 2 additions & 0 deletions cmd/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ var subCommandServer = cli.Command{
Category: "server",
Flags: []cli.Flag{
&cli.StringFlag{
// 后端端口
Name: "port",
Aliases: []string{"p"},
Value: "1231",
Usage: "api server port",
},
Expand Down
15 changes: 8 additions & 7 deletions config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# HTTP配置
httpConfig:
# 127.0.0.1:8080
proxy: ""
# 读取http响应超时时间
http_timeout: 10
Expand All @@ -18,12 +17,14 @@ httpConfig:

# 数据库配置
dbConfig:
host: "127.0.0.1"
password: ""
port: ""
user: ""
database: "pocassist"
timeout: "3s"
sqlite : "pocassist.db"
mysql:
host: "127.0.0.1"
password: ""
port: "3306"
user: "root"
database: "pocassist"
timeout: "3s"

# 插件配置
pluginsConfig:
Expand Down
Loading

0 comments on commit fa7d653

Please sign in to comment.