Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: API支持 #206

Merged
merged 10 commits into from
May 18, 2022
Merged

feat: API支持 #206

merged 10 commits into from
May 18, 2022

Conversation

AkkiaS7
Copy link
Member

@AkkiaS7 AkkiaS7 commented May 17, 2022

工作完成

  • 服务器状态API
  • 服务器信息API
  • Token生成
  • Token验证
  • 前端修改
  • 前向兼容性检查

安全性相关

额外为Auth中间件增加AllowAPI选项(默认false)
目前仅/api/v1/目录下的路径支持API认证(获取服务器列表与详情)
防止API Token泄漏后调用计划任务相关接口进行恶意攻击

后续可以尝试通过增加scope字段对Token权限进行约束

接口参考

API接口(允许使用API Token认证与Cookies认证)

Token认证方式:

Request Headers:
Authorization: 10d6f0375b708ebb9d01694c1fbefb30

获取服务器列表:GET /api/v1/server/list?tag=
query: tag (ServerTag 提供此参数则仅查询该分组下的服务器)

{
    "code": 0,
    "message": "success",
    "result": [
        {
            "id": 1,
            "name": "ServerName",
            "tag": "ServerTag",
            "ipv4": "1.1.1.1",
            "ipv6": "",
            "valid_ip": "1.1.1.1"
        }
    ]
}

获取服务器详情: GET /api/v1/server/details?id=&tag=
query: id (ServerID 以逗号分隔 提供此参数则查询该列表对应的服务器 同时无视tag参数)
query: tag (ServerTag 提供此参数则仅查询该分组下的服务器)

{
    "code": 0,
    "message": "success",
    "result": [
        {
            "id": 1,
            "name": "ServerName",
            "tag": "ServerTag",
            "ipv4": "1.1.1.1",
            "ipv6": "",
            "valid_ip": "1.1.1.1",
            "host": {
                "Platform": "darwin",
                "PlatformVersion": "12.3.1",
                "CPU": [
                    "Apple M1 Pro 1 Physical Core"
                ],
                "MemTotal": 17179869184,
                "DiskTotal": 2473496842240,
                "SwapTotal": 0,
                "Arch": "arm64",
                "Virtualization": "",
                "BootTime": 1652683962,
                "CountryCode": "hk",
                "Version": ""
            },
            "status": {
                "CPU": 10.94117647050606,
                "MemUsed": 14150975488,
                "SwapUsed": 0,
                "DiskUsed": 2138323378176,
                "NetInTransfer": 652628744,
                "NetOutTransfer": 465447325,
                "NetInSpeed": 2156,
                "NetOutSpeed": 4254,
                "Uptime": 157738,
                "Load1": 3.82373046875,
                "Load5": 3.74169921875,
                "Load15": 4.5966796875,
                "TcpConnCount": 214,
                "UdpConnCount": 48,
                "ProcessCount": 451
            }
        }
    ]
}

@AkkiaS7 AkkiaS7 changed the title WIP: API支持 feat: API支持 May 18, 2022
@AkkiaS7 AkkiaS7 marked this pull request as ready for review May 18, 2022 12:58
service/singleton/api.go Outdated Show resolved Hide resolved
@@ -469,6 +469,21 @@ other = "Services"
[ScheduledTasks]
other = "Scheduled Tasks"

[ApiManagement]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

en 和 es 需要恢复,在仓库直接改会让 crowdin 混乱

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

最新的commit是在en和es里直接删掉了这几个设置
不太确定是不是要这样做
现在conf设置成en-US会panic

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

没事,crowdin 会自己补缺失的 key,先不发版,提交了翻译完再发

@naiba
Copy link
Member

naiba commented May 18, 2022

其他没了 👍🏿

@naiba naiba merged commit dd79c7f into nezhahq:master May 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants