升级特性
v0.1.0:配置文件存入中心,调用脚本conf.sh运行;
v0.1.1:新增wget测试功能,采用hosts绑定方式;
v0.2.0:新增curl测试、配置文件校对功能,采用指定代理参数,避免修改hosts权限问题;
v0.3.0:更新配置分发功能,直接逐句插入;
v0.3.1:加强wget和curl测试定制功能,支持HTTPS、防盗链、过期时间检查;
v0.3.2:支持url批量测试;
v0.3.3:加强输入IP自动识别;
更多精彩,敬请期待~~
```
[root@BeiJingBGP-Dns-02 cgi-bin]# cat rt.cgi
```bash
#!/bin/bash
function filter(){
sed '{
s/%23/#/g;
s/%0D%0A/n/g;
s/%5E/^/g;
s/%3A/:/g;
s/%2F///g;
s/%28/\(/g;
s/%7C/\|/g;
s/%29/\)/g;
s/%24/$/g;
s/%25/%/g;
s/%3F/?/g;
s/%3D/=/g;
s/%5C/\/g;
}' $1
}
function regulate(){
sed "{
1i#$custom
$a#$custom+end
$!N; /^(.*)n1$/!P;D
}" $1
}
function uniform(){
awk -F"[+| ]" '{
for(i=1;i<=NF;i++){
if($i~/[0-9]+.[0-9]+.[0-9]+.[0-9]+/){
print $i
}
}
}'
}
echo "Content-type:text/html"
echo ""
echo ""
if [ "$REQUEST_METHOD" = "POST" ] ; then
QUERY_STRING=`cat -`
fi
#echo "
$QUERY_STRING"
action=`echo $QUERY_STRING|awk -F"[=|&]" '{print $8}'`
custom=`echo $QUERY_STRING|awk -F"[=|&]" '{print $6}'`
iplist=`echo $QUERY_STRING|awk -F"[=|&]" '{print $4}'|filter|uniform`
case $action in
add)
ref_conf=`echo $QUERY_STRING|awk -F"[=|&]" '{print $2}'|filter|regulate|sed '1!G;h;$!d'`
#echo "$ref_conf"
for ip in $iplist;do
ping -c 3 $ip|awk -F, '/loss/{print $3}'
for ref in $ref_conf;do
echo "$ref
"
/usr/local/bin/sshpass -p 123456 ssh -oUserKnownHostsFile=/dev/null -oStrictHostKeyChecking=no
root@$ip sed -i "/config/a\`echo $ref|sed 's/+/\ /g'`" /home/squid/etc/squid.conf && /home/squid/sbin/squid -k reconfigure
done
done
;;
wget)
test_url=`echo $QUERY_STRING|awk -F"[=|&]" '{print $2}'|filter`
for ip in $iplist;do
for url in $test_url;do
domain=`echo $url|awk -F/ '{print $3}'`
echo "$ip $domain" > /etc/hosts
wget -S -O /dev/null "$url" -o wget.log --no-check-certificate -t 1
cat wget.log|awk 'BEGIN{ORS="
"}1'
done
done
;;
curl)
test_url=`echo $QUERY_STRING|awk -F"[=|&]" '{print $2}'|filter`
for url in $test_url;do
echo "##################################
"
echo "###$url
"
for ip in $iplist;do
domain=`echo $url|awk -F/ '{print $3}'`
echo "##############
"
echo "$ip
"
curl -I -x $ip:80 -A "support/RT (21V-CDN)" -e "
http://$domain" "$url"|awk 'BEGIN{ORS="
"}/HTTP/1|Cache|Age/'
sleep 1;
done
done
;;
*)
echo '
'
;;
esac
echo ""
```