|
|
@@ -1,38 +1,87 @@
|
|
|
#!/bin/sh
|
|
|
|
|
|
-title=$1
|
|
|
-content=$2
|
|
|
-reward=$3
|
|
|
-level=$4
|
|
|
-money=$5
|
|
|
-
|
|
|
-echo 传入的邮件标题:$title
|
|
|
-echo 传入的邮件内容:$content
|
|
|
-echo 传入的邮件奖励:$reward
|
|
|
-echo 传入的等级筛选:$level
|
|
|
-echo 传入的充值筛选:$money
|
|
|
-
|
|
|
-for server in `cat /data/shell/jenkins/serverlist`;do
|
|
|
-
|
|
|
- url=`echo $server | cut -d',' -f2`
|
|
|
- ro=`echo $server | cut -d',' -f3`
|
|
|
-
|
|
|
- if [[ $reward == "0" ]];then
|
|
|
- url="$url/gm/mail?type=add&id=1&title=$title&content=$content"
|
|
|
+usage() {
|
|
|
+ echo "Usage: $0 \"title\" \"content\" [reward] [level] [money]"
|
|
|
+ exit 1
|
|
|
+}
|
|
|
+
|
|
|
+# Positional parameters only
|
|
|
+title="$1"
|
|
|
+content="$2"
|
|
|
+reward="${3:-0}"
|
|
|
+level="${4:-0}"
|
|
|
+money="${5:-0}"
|
|
|
+
|
|
|
+if [ -z "$title" ] || [ -z "$content" ]; then
|
|
|
+ echo "title and content are required"
|
|
|
+ usage
|
|
|
+fi
|
|
|
+
|
|
|
+echo "传入的邮件标题:$title"
|
|
|
+echo "传入的邮件内容:$content"
|
|
|
+echo "传入的邮件奖励:$reward"
|
|
|
+echo "传入的等级筛选:$level"
|
|
|
+echo "传入的充值筛选:$money"
|
|
|
+
|
|
|
+# urlencode: prefer python3, then python, fallback to simple sed
|
|
|
+urlencode() {
|
|
|
+ if command -v python3 >/dev/null 2>&1; then
|
|
|
+ python3 -c "import sys,urllib.parse as u; print(u.quote(sys.argv[1]))" "$1"
|
|
|
+ elif command -v python >/dev/null 2>&1; then
|
|
|
+ python -c "import sys,urllib; print(urllib.quote(sys.argv[1]))" "$1"
|
|
|
else
|
|
|
- url="$url/gm/mail?type=add&id=1&title=$title&content=$content&reward=$reward"
|
|
|
+ # best-effort simple replacement for common problematic chars
|
|
|
+ printf '%s' "$1" | sed -e 's/ /%20/g' -e 's/&/%26/g' -e 's/?/%3F/g' -e 's/+/ %2B/g' -e 's/=/ %3D/g' | sed 's/ */ /g'
|
|
|
fi
|
|
|
+}
|
|
|
|
|
|
- uids=$(mysql -uroot -p123456 $ro -N -e "select uid from role where base_level>=$level and total_recharge>=$money;")
|
|
|
- for id in ${uids}; do
|
|
|
- curl "$url&uid=$id"
|
|
|
- done
|
|
|
+enc_title=$(urlencode "${title}")
|
|
|
+enc_content=$(urlencode "${content}")
|
|
|
+
|
|
|
+# Read server list line-by-line to handle spaces safely
|
|
|
+serverlist_file="/data/shell/jenkins/serverlist"
|
|
|
+if [ ! -f "$serverlist_file" ]; then
|
|
|
+ echo "server list not found: $serverlist_file"
|
|
|
+ exit 1
|
|
|
+fi
|
|
|
+
|
|
|
+while IFS= read -r server || [ -n "$server" ]; do
|
|
|
+ # skip empty lines
|
|
|
+ if [ -z "${server}" ]; then
|
|
|
+ continue
|
|
|
+ fi
|
|
|
|
|
|
-done
|
|
|
+ url="$(printf '%s' "$server" | cut -d',' -f2)"
|
|
|
+ ro="$(printf '%s' "$server" | cut -d',' -f3)"
|
|
|
|
|
|
+ if [ -z "$url" ] || [ -z "$ro" ]; then
|
|
|
+ echo "skip invalid server line: $server"
|
|
|
+ continue
|
|
|
+ fi
|
|
|
|
|
|
+ if [ "$reward" = "0" ]; then
|
|
|
+ full_url="${url}/gm/mail?type=add&id=1&title=${enc_title}&content=${enc_content}"
|
|
|
+ else
|
|
|
+ full_url="${url}/gm/mail?type=add&id=1&title=${enc_title}&content=${enc_content}&reward=${reward}"
|
|
|
+ fi
|
|
|
|
|
|
+ # Query uids and send mails line-by-line
|
|
|
+ uids=$(mysql -uroot -p123456 "$ro" -N -e "select uid from role where base_level>=${level} and total_recharge>=${money};")
|
|
|
+ if [ -z "$uids" ]; then
|
|
|
+ echo "no uids found for server $ro"
|
|
|
+ continue
|
|
|
+ fi
|
|
|
+
|
|
|
+ # iterate uids safely (line-by-line)
|
|
|
+ printf '%s
|
|
|
+' "$uids" | while IFS= read -r id; do
|
|
|
+ if [ -z "$id" ]; then
|
|
|
+ continue
|
|
|
+ fi
|
|
|
+ curl "${full_url}&uid=${id}"
|
|
|
+ done
|
|
|
|
|
|
+done < "$serverlist_file"
|
|
|
|
|
|
|
|
|
echo "-----执行完毕-----"
|