-
Notifications
You must be signed in to change notification settings - Fork 177
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Dev
- Loading branch information
Showing
7 changed files
with
188 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
## api_key | ||
api_key可以在config.lua中增加配置 | ||
```lua | ||
config['api_key'] = "your api key string" | ||
``` | ||
|
||
## 域名 | ||
### 添加域名 | ||
#### 接口地址 | ||
- POST /api/v1/domain/add?api_key={api_key} | ||
#### 表单参数 | ||
| 参数 | 是否必须 | 说明 | | ||
| ---------------- | ------ | --------------------------------------- | | ||
| name | 是 | 域名名称 | | ||
|
||
#### 返回示例 | ||
```json | ||
{ | ||
"info": { | ||
"insert_id": 17, | ||
"affected_rows": 1, | ||
"server_status": 2, | ||
"warning_count": 0 | ||
}, | ||
"errno": 0, | ||
"status": 200, | ||
"msg": "success" | ||
} | ||
``` | ||
|
||
### 删除域名 | ||
#### 接口地址 | ||
- POST /api/v1/domain/delete?api_key={api_key} | ||
#### 表单参数 | ||
| 参数 | 是否必须 | 说明 | | ||
| ---------------- | ------ | --------------------------------------- | | ||
| domain_id | 是 | 域名ID | | ||
|
||
#### 返回示例 | ||
```json | ||
{ | ||
"errno": 0, | ||
"status": 200, | ||
"msg": "success" | ||
} | ||
``` | ||
> 域名删除时会删除所有域名相关的数据,慎用 | ||
### 修改域名 | ||
#### 接口地址 | ||
- POST /api/v1/domain/update?api_key={api_key} | ||
#### 表单参数 | ||
| 参数 | 是否必须 | 说明 | | ||
| ---------------- | ------ | --------------------------------------- | | ||
| domain_id | 是 | 域名ID | | ||
| name | 是 | 域名名称 | | ||
|
||
#### 返回示例 | ||
```json | ||
{ | ||
"errno": 0, | ||
"status": 200, | ||
"msg": "success" | ||
} | ||
``` | ||
> 域名删除时会删除所有域名相关的数据,慎用 | ||
### 查询已添加域名列表 | ||
#### 接口地址 | ||
- GET /api/v1/domain/all?api_key={api_key} | ||
|
||
#### 返回示例 | ||
```json | ||
{ | ||
"info": [ | ||
{ | ||
"name": "www.xxx.com", | ||
"id": 2 | ||
} | ||
], | ||
"errno": 0, | ||
"status": 200, | ||
"msg": "success" | ||
} | ||
``` | ||
|
||
## 模块 | ||
> 每个域名下可以有多个模块 | ||
- /api/v1/service/add | ||
- /api/v1/service/edit | ||
- /api/v1/service/delete | ||
- /api/v1/service/get | ||
- /api/v1/service/list | ||
|
||
## 服务器 | ||
> 每个模块可以有多个后端服务器 | ||
- /api/v1/server/add | ||
- /api/v1/server/edit | ||
- /api/v1/server/delete | ||
- /api/v1/server/get | ||
- /api/v1/server/list | ||
|
||
## URI映射 | ||
> 每个模块可以有多个URI接口映射 | ||
- /api/v1/api/add | ||
- /api/v1/api/edit | ||
- /api/v1/api/delete | ||
- /api/v1/api/get | ||
- /api/v1/api/list |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,38 @@ | ||
local _M = {} | ||
local cjson = require "cjson" | ||
local config = require "config" | ||
|
||
function _M.checkLogin() | ||
local params = ngx.req.get_uri_args() | ||
if params["api_key"] ~= nil and params["api_key"] == config["api_key"] then | ||
return 1 | ||
end | ||
local uri = ngx.var.uri | ||
if uri ~= "/api/v1/login" and uri ~= "/login.html" then | ||
local cache = ngx.shared.cache | ||
local token = cache:get("login-token") | ||
local session = ngx.shared.session | ||
local ck = require "resty.cookie" | ||
local cookie, err = ck:new() | ||
local isApi = string.find(uri,"/api/v1/"); | ||
if isApi and (token == nil or token ~= cookie:get("token")) then | ||
local cookie, _ = ck:new() | ||
local token = cookie:get("token") | ||
local user; | ||
if token ~= nil then | ||
user = session:get(token) | ||
end | ||
local isApi = string.find(uri, "/api/v1/"); | ||
if isApi and user == nil then | ||
local response = {} | ||
response["status"] = 401 | ||
response["errno"] = 40100 | ||
response["msg"] = "Authentication required" | ||
ngx.header.content_type = 'application/json;charset=UTF-8'; | ||
ngx.say(cjson.encode(response)) | ||
ngx.exit(401) | ||
return; | ||
end | ||
if token == nil or token ~= cookie:get("token") then | ||
if user == nil then | ||
return ngx.redirect("/login.html") | ||
end | ||
end | ||
return 1 | ||
end | ||
|
||
return _M |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.