From f15a551e4a3d20d52da387ce589634536e408fd5 Mon Sep 17 00:00:00 2001 From: "xiongdian.me" Date: Sat, 21 Jan 2023 16:43:08 +0800 Subject: [PATCH] beacon: support meta with limited len 64 --- tools/common.sh | 4 ++-- tools/logger.sh | 9 +++++---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/tools/common.sh b/tools/common.sh index 5f3b80c..6ceb6a9 100755 --- a/tools/common.sh +++ b/tools/common.sh @@ -174,10 +174,10 @@ apost_log() post_beacon() { - if [[ $# != 1 || -z "$1" ]]; then + if [[ $# < 1 || -z "$1" ]]; then fmt_fatal "usage: post_beacon " fi - "${DOTFILES}/tools/logger.sh" "beacon" "$1" + "${DOTFILES}/tools/logger.sh" "beacon" "$1" "$2" } apost_beacon() diff --git a/tools/logger.sh b/tools/logger.sh index df2b527..2096bb6 100755 --- a/tools/logger.sh +++ b/tools/logger.sh @@ -40,10 +40,11 @@ init_uuid() post_beacon() { local beacon_type=$1 + local meta=$2 if [[ -z "$beacon_type" ]]; then fmt_fatal "beacon type is required" fi - resp=$(curl -sSL -X POST "https://api.beardic.cn/post-beacon?hostname=$hostname&beacon=$beacon_type") + resp=$(curl -sSL -X POST -H "Content-Type: text/plain" -d "$meta" "https://api.beardic.cn/post-beacon?hostname=$hostname&beacon=$beacon_type") if grep -q "200" <<< "$resp"; then echo $resp else @@ -59,7 +60,7 @@ post_log() fmt_fatal "log content is required" fi init_uuid - resp=$(curl -sSL -X POST -H "Content-Type: text/plain" -d "$1" "https://api.beardic.cn/post-log?hostname=$hostname&uuid=$uuid") + resp=$(curl -sSL -X POST -H "Content-Type: text/plain" -d "$log_content" "https://api.beardic.cn/post-log?hostname=$hostname&uuid=$uuid") if grep -q "200" <<< "$resp"; then echo $resp elif grep -q "403" <<< "$resp"; then @@ -81,7 +82,7 @@ print_help() router() { - if [[ $# != 2 ]]; then + if [[ $# < 2 ]]; then print_help >&2 exit 1 fi @@ -91,7 +92,7 @@ router() fmt_info "usage: $0 " ;; beacon) - post_beacon "$2" + post_beacon "$2" "$3" ;; log) post_log "$2"