diff --git a/tools/.gitignore b/tools/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..7e98e66ad27241930c673e95c6ddf7c910ae15df --- /dev/null +++ b/tools/.gitignore @@ -0,0 +1,2 @@ +./tmp +!./tmp/.gitkeep diff --git a/tools/Dockerfile b/tools/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..074421984b057d67f70a856ec5453d94a2aef892 --- /dev/null +++ b/tools/Dockerfile @@ -0,0 +1,9 @@ +FROM alpine:latest + +WORKDIR /app +VOLUME ["/app/cfg"] +ADD ./tmp/hclient-cli /app/hclient-cli + +CMD ["/app/hclient_cli"] + + diff --git a/tools/README.md b/tools/README.md new file mode 100644 index 0000000000000000000000000000000000000000..0b17ea157d6aa9801ad5fe24022ff58da39835f3 --- /dev/null +++ b/tools/README.md @@ -0,0 +1,46 @@ +# Tools + +该目录提供了一些快速使用 cli 的方法 + +## cmd.sh + +该文件主要是用来管理盒子的,基本与盒子管理的 API 一一对应。 + +使用方法为 + +``` +./cmd.sh sub_command +``` + +> sub_command 即对应的管理接口名称 + +## Docker + +为了方便容器应用访问,可以把 hclient-cli 包装在一个单独的容器中,使其与你的应用容器在同一个 docker 网络下,这样应用容器可以通过代理访问到懒猫的 ingress 端口资源。 + +在 `cmd.sh` 中提供了简单的一个封装,你可以根据自己的需求调整 `Dockerfile`. + +下面是一个启动容器的 Demo + +``` +docker run -itd \ + --privileged \ + --name lazycat \ + --hostname lazycat_in_docker \ + --restart always \ + --network lnmp \ + --ip 172.20.0.66 \ + -p 127.0.0.1:7777:7777 \ + -p 127.0.0.1:61090:61090 \ + -v /data/cfg:/app/cfg \ + ety001/lazycat-cli:latest \ + /app/hclient-cli \ + -api-addr "172.20.0.66:7777" \ + -http-addr "172.20.0.66:61090" +``` + +> 请注意不要暴露你的 7777 管理端口和 61090 代理端口给全局网络 + +Demo 容器启动后,所有 lnmp 网络中的容器可以通过 `172.20.0.66:61090` 代理访问懒猫资源。 + +宿主机可以通过 `127.0.0.1:7777` 管理,通过 `127.0.0.1:61090` 代理访问。 diff --git a/tools/cmd.sh b/tools/cmd.sh new file mode 100755 index 0000000000000000000000000000000000000000..deca6e78b3d57d7016c8f5a8937e7f8bd03c062c --- /dev/null +++ b/tools/cmd.sh @@ -0,0 +1,55 @@ +#!/bin/bash + +cookie_file=/tmp/lzc_cookie + +case $1 in + "list_box") + curl "http://127.0.0.1:7777/box_list" + ;; + "del_box") + read -s -p "Input your Box Name: " box + curl -X DELETE "http://127.0.0.1:7777/del_box?bname=$box" + ;; + "add_tfa") + read -p "Input your Box Name: " box + read -p "Input your 2fa code: " auth + curl -X POST "http://127.0.0.1:7777/add_tfa?bname=$box&tfa=$auth" + ;; + "add_box") + read -p "Input your Box Name: " box + read -p "Input your username: " uid + read -s -p "Input your password: " pw + curl -X POST "http://127.0.0.1:7777/add_box?bname=$box&uid=$uid&password=$pw" + ;; + "client_info") + curl "http://127.0.0.1:7777/client_info" + ;; + "login") + read -p "Input your Box Name: " box + read -p "Input your username: " username + read -s -p "Input your password: " password + curl -x http://127.0.0.1:61090 \ + -X POST \ + -d "username=${username}" \ + -d "password=${password}" \ + -c ${cookie_file} \ + "https://${box}.heiyu.space/sys/login" + ;; + "visit") + read -p "Input your test visit url: " uri + curl -x http://127.0.0.1:61090 \ + -b ${cookie_file} \ + "${uri}" + ;; + "build_docker_image") + read -p "Input your docker image name which you want to build: " img_name + read -p "Input the Bin download url: " dl_uri + wget ${dl_uri} -O ./tmp/hclient-cli + chmod +x ./tmp/hclient-cli + docker build -t ${img_name} -f Dockerfile . + ;; + *) + echo "Usage: $0 {list_box|del_box|add_tfa|add_box|client_info|build_docker_image}" + exit 1 + ;; +esac diff --git a/tools/tmp/.gitkeep b/tools/tmp/.gitkeep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/tools/tmp/hclient-cli b/tools/tmp/hclient-cli new file mode 100755 index 0000000000000000000000000000000000000000..e074335dc5f4bbcdc3c855adfd9d729e2cb903b5 Binary files /dev/null and b/tools/tmp/hclient-cli differ