51工具盒子

依楼听风雨
笑看云卷云舒,淡观潮起潮落

EUserv自动续期Shell脚本配合crontab

概述

由于领取免费EUserv在手需要不定期进行续费,故自己弄了个shell自动续费脚本。

使用脚本

需apt安装jq及curl,需支持IPV4访问。

#!/bin/bash
# EUserv免费服务器自动续费
# Author: admin@lolicp.com
# Version: 0.0.2
# Date: 2021-06-16

用户邮箱

User_Email=""

用户密码

User_Pawd=""

Login_Cookies() { curl -s -A "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36" -H "origin: https://www.euserv.com" "$@" }

钉钉授权ID

Ding_Access_Token= DingDing_Content(){ if [[ "${Current_Currency_Num_Rate_D}" =~ 'e' ]];then Post_Code=curl -s -H "Content-Type:application/json" -d "{\"msgtype\":\"text\",\"text\":{\"content\":\"${Post_Content}\"},\"at\":{\"atMobiles\":[\"${Mobile}\"],\"isAtAll\":false}}" https://oapi.dingtalk.com/robot/send?access_token=${Ding_Access_Token} |jq -r .errmsg else Post_Code=curl -s -H "Content-Type:application/json" -d "{\"msgtype\":\"markdown\",\"markdown\":{\"title\":\"${Post_Title}\",\"text\":\"${Post_Content}\"}}" https://oapi.dingtalk.com/robot/send?access_token=${Ding_Access_Token} |jq -r .errmsg fi if [ ! "${Post_Code}" = 'ok' ];then echo "提交失败请检查!:${Post_Code}" fi }

Error_Info(){ Post_Title="EUserv自动续期失败" Post_Content="EUserv ${Get_Contract_Id}\n\n[主机名称] ${Get_Servername_Info}\n\n[IPv6地址] ${Get_Ipv6_Address_Info}\n\n[自动续费] 失败 \n\n${1}" }

Index_Url='https://support.euserv.com/index.iphp'

登录

Euserv_Login=Login_Cookies -d "email=${User_Email}&password=${User_Pawd}&form_selected_language=en&Submit=Login&subaction=login" "${Index_Url}"

Sess_Id

Euserv_Sess_Id=echo "${Euserv_Login}"| awk -F"'" '/params[[:space:]]=[[:space:]].sess_id/ {print $2}'

获取首页信息

Get_Index_Info=Login_Cookies "${Index_Url}?${Euserv_Sess_Id}"

获取IPv6地址

Get_Ipv6_Address_Info=echo "${Get_Index_Info}" |grep IPv6: |sed -ne 's/</\n/g' -e 's/>/\n/gp' |awk '/IPv6/ {print $2}'

获取主机名

Get_Servername_Info=echo "${Get_Index_Info}" |grep Servername: |sed -ne 's/</\n/g' -e 's/>/\n/gp' |awk '/Servername/ {print $2}'

获取最早续期时间

Get_extension_Time_Info=echo "${Get_Index_Info}" |sed -ne 's/>/\n/g' -e 's/</\n/gp' |awk '/Contract extension possible/ {print $5}' if [ ! -z "${Get_extension_Time_Info}" ];then

请求头部

Post_Title="EUserv暂无需续期"

请求内容

Post_Content="EUserv ${Get_Contract_Id}\n\n[主机名称] ${Get_Servername_Info}\n\n[IPv6地址] ${Get_Ipv6_Address_Info}\n\n[最早延长] ${Get_extension_Time_Info}\n\n[自动续费] 暂停" else

合同ID

Get_Contract_Id=echo "${Get_Index_Info}" |sed -n 's/.*>\([0-9]\{5,9\}\) vServer VS2-free.*/\1/p'

Login_Cookies -d "Submit=Extend+contract&${Euserv_Sess_Id}&ord_no=${Get_Contract_Id}&subaction=choose_order&show_contract_extension=1&choose_order_subaction=show_contract_details" "${Index_Url}" &> /dev/null

Login_Cookies -v -d "${Euserv_Sess_Id}&subaction=kc2_customer_contract_details_get_change_plan_dialog&ord_id=${Get_Contract_Id}&show_manual_extension_if_available=1" "${Index_Url}" &> /dev/null

Login_Cookies -d "${Euserv_Sess_Id}&subaction=show_kc2_security_password_dialog&prefix=kc2_customer_contract_details_extend_contract_" "${Index_Url}" &> /dev/null

获取密码验证信息

Get_Password_Token_Info=Login_Cookies -d "${Euserv_Sess_Id}&subaction=kc2_security_password_get_token&prefix=kc2_customer_contract_details_extend_contract_&password=${User_Pawd}" "${Index_Url}"

获取密码验证结果状态

Get_Password_Token_Info_Status=echo "${Get_Password_Token_Info}" |jq -r '.rs' if [ "${Get_Password_Token_Info_Status}" = 'success' ];then # 获取验证Token_Id Get_Password_Token_Id=echo "${Get_Password_Token_Info}" |jq -r '.token.value' # 获取续约时间 Get_Extended_Time=Login_Cookies -d "${Euserv_Sess_Id}&subaction=kc2_customer_contract_details_get_extend_contract_confirmation_dialog&token=${Get_Password_Token_Id}" "${Index_Url}" |jq -r '.html.value' |sed -ne 's/>/\n/g' -e 's/</\n/gp' |awk '/selected/ {print $9}'

Get_Extend_Contract_Info=`Login_Cookies -d "${Euserv_Sess_Id}&ord_id=${Get_Contract_Id}&subaction=kc2_customer_contract_details_extend_contract_term&token=${Get_Password_Token_Id}" "${Index_Url}"`
if [ ! -z "${Get_Extend_Contract_Info/\.}" ];then
    # 请求头部
    Post_Title="EUserv续期至${Get_Extended_Time/\.}"
    # 请求内容
    Post_Content="EUserv ${Get_Contract_Id}\n\n[主机名称] ${Get_Servername_Info}\n\n[IPv6地址] ${Get_Ipv6_Address_Info}\n\n[到期时间] ${Get_Extended_Time/\.}\n\n[自动续费] 成功"
else
    Error_Info "${Get_Extend_Contract_Info}"
fi

else Error_Info "${Get_Password_Token_Info}" fi

fi

DingDing_Content


Crontab配置

每三天自动检测是否领取

0 1 */3 * * bash /root/EUserv_Auto.sh
赞(5)
未经允许不得转载:工具盒子 » EUserv自动续期Shell脚本配合crontab