Решение для доступа должников на сайты платежных систем
Два решения. Для сервера linux и второе с заливкой на mikrotik
https://wiki.mikbill.ru/billing/howto/ipset_paysystems
Для NAS на сервере linux:
#!/bin/bash #͑Client DNS DNS1=8.8.8.8 DNS2=8.8.4.4 DIG=`which dig` IPSET=`which ipset` IPSETNAME="paysystems" HOME_DIR=$(cd $(dirname $0)&& pwd) SRCDATA=`cat $HOME_DIR/domains.list` IPLIST="$HOME_DIR/ip.list" RESULT="$HOME_DIR/paysys.txt" $DIG +short $SRCDATA @$DNS1 |grep '\([[:digit:]]\{1,3\}\.\)\{3\}[[:digit:]]\{1,3\}' > $RESULT $DIG +short $SRCDATA @$DNS2 |grep '\([[:digit:]]\{1,3\}\.\)\{3\}[[:digit:]]\{1,3\}' >> $RESULT cat $IPLIST >> $RESULT $IPSET -N $IPSETNAME iphash -exist for i in `cat $RESULT`; do $IPSET add $IPSETNAME $i -exist 2>/dev/null; done
DNS1 и DNS2 - указываем клиентские DNS-сервера (это важно!)
domains.list - файл с доменами (внести все домены используемые на сайте)
ip.list - файл с IP (тут можно добавлять IP к общему списку)
Правила для сервера
iptables -t nat -A PREROUTING -m set --match-set paysystems dst -m set --match-set nomoney src -j ACCEPT
iptables -I nat 1 POSTROUTING -s 0.0.0.0/0 -m set --match-set paysystems dst -j MASQUERADE
iptables -A FORWARD -s --match-set nomoney -m set --match-set paysystems dst -j ACCEPT
Крон
00 06 * * * root /home/ipset_paysystems/ipset_paysystems.sh
Скрипт загрузки IP доменов на mikrotik в address-list и Hotspot Walled Garden IP List
#!/bin/bash #Client DNS DNS1=192.168.10.1 DNS2=8.8.8.8 # Mikrotik MT_SSH_PORT="22" IP_TO_ADDRESS_LIST=1 IP_TO_WALLED_GARDEN_IP_LIST=1 Path_Config=/var/www/mikbill/admin/app/etc/config.xml SSH_INTERVAL=10 SSH_SUM=10 DIG=`which dig` IPSETNAME="nomoney_dst_accept" HOME_DIR=$(cd $(dirname $0)&& pwd) SRCDATA=`cat $HOME_DIR/domains.list` IPLIST="$HOME_DIR/ip.list" UPLOAD=$HOME_DIR/upload_paysys.rsc ADDRESS_LIST="nomoney_dst_accept" TMP=$HOME_DIR/tmp if !([ -e "$IPLIST" ])then touch $IPLIST fi RESULT1=$($DIG +short $SRCDATA @$DNS1 |grep '\([[:digit:]]\{1,3\}\.\)\{3\}[[:digit:]]\{1,3\}') RESULT2=$($DIG +short $SRCDATA @$DNS2 |grep '\([[:digit:]]\{1,3\}\.\)\{3\}[[:digit:]]\{1,3\}') RESULT="$RESULT1 $RESULT2 $(cat $IPLIST)" echo >$UPLOAD if [ "$IP_TO_ADDRESS_LIST" -ne 0 ] then echo "/ip firewall address-list remove [/ip firewall address-list find list=$ADDRESS_LIST]" >>$UPLOAD fi if [ "$IP_TO_WALLED_GARDEN_IP_LIST" -ne 0 ] then echo "/ip hotspot walled-garden ip remove numbers=[/ip hotspot walled-garden ip find comment=$ADDRESS_LIST]" >>$UPLOAD fi echo >$TMP for i in $RESULT; do if ! grep -q $i $TMP then if [ "$IP_TO_ADDRESS_LIST" -ne 0 ] then echo "/ip firewall address-list add list="$ADDRESS_LIST" address=$i" >>$UPLOAD fi if [ "$IP_TO_WALLED_GARDEN_IP_LIST" -ne 0 ] then echo "/ip hotspot walled-garden ip add comment=$ADDRESS_LIST dst-address=$i" >>$UPLOAD fi echo $i >>$TMP fi done SSH_UPLOAD (){ for (( i=0;i!=$SSH_SUM;i++ )); do scp -P $MT_SSH_PORT $UPLOAD $Mikrotik_Login@$Mikrotik_IP:/ STATUS=$? if [ $STATUS -ne 0 ]; then sleep $SSH_INTERVAL else CMD="/import file=$(basename $UPLOAD)" for (( i=0;i!=$SSH_SUM;i++ )); do ssh -p $MT_SSH_PORT $Mikrotik_Login@$Mikrotik_IP "${CMD}" > /dev/null STATUS=$? if [ $STATUS -ne 0 ]; then sleep $SSH_INTERVAL fi done break fi done } # Находим все микротики DB_User=$(cat $Path_Config| grep username | awk '{ gsub("<username>"," "); print }' | awk '{ gsub("</username>"," "); print }' | awk '{print $1}') DB_Password=$(cat $Path_Config| grep password | awk '{ gsub("<password>"," "); print }' | awk '{ gsub("</password>"," "); print }' | awk '{print $1}') SQL=`mysql -D mikbill -u $DB_User -p$DB_Password -e "SELECT nasname, naslogin FROM radnas WHERE usessh=1 and (nastype='mikrotik' or nastype='HotSpot')" 2>/dev/null` #SQL=${SQL:$17:${#SQL}} NUM=0 for i in $SQL; do SQL_Array[$NUM]=$i let "NUM=NUM+1" done for((i=2;i!=NUM;i+=2)) do Mikrotik_IP=${SQL_Array[$i]} Mikrotik_Login=${SQL_Array[$i+1]} SSH_UPLOAD done
Данные для входа на микротики берутся из настроек NAS админки
Вкл/выкл выгрузку в Firewall Address list (0/1):
IP_TO_ADDRESS_LIST=1Вкл/выкл выгрузку в Hotspot Walled Garden IP List (0/1):
IP_TO_WALLED_GARDEN_IP_LIST=1
Сделать авторизацию по ключу
Добавить исполнение скрипта в крон
Пример правил NAT на mikrotik
/ip firewall nat add action=accept chain=srcnat comment=\ "To LK" dst-address=\ 192.168.10.2 src-address=172.22.0.0/20 add action=masquerade chain=srcnat comment="Nomoney dst accept" \ dst-address-list=nomoney_dst_accept src-address=172.22.0.0/20 add action=dst-nat chain=dstnat comment="Nomoney 80 redirect" dst-address-list=\ !nomoney_dst_accept dst-port=80 protocol=tcp src-address=172.22.0.0/20 \ to-addresses=192.168.10.2 to-ports=80 add action=dst-nat chain=dstnat comment="Nomoney 443 redirect" \ dst-address-list=!nomoney_dst_accept dst-port=443 protocol=tcp src-address=\ 172.22.0.0/20 to-addresses=192.168.10.2 to-ports=443
___Другое______________________________________________________________________
wget http://www.cubbyusercontent.com/pli/privat24.sh/_66180ac9c7db4b80b57c8fd846ab12f6 -O privat24
ipset --create privat24 iphash --hashsize 4096
#!/bin/bash
IPS=`which ipset`
DIG=`which dig`
CTL=`which sysctl`
DNS_lookup="4.2.2.2"
pay_ipset="privat24"
pay_sites=(
# LIQPAY
www.liqpay.com
liqpay.com
static.liqpay.com
ecommerce.liqpay.com
# PRIVAT
www.privat24.ua
privat24.ua
privat24.privatbank.ua
privatbank.ua
qrapi.privatbank.ua
api.privatbank.ua
login.privatbank.ua
socauth.privatbank.ua
st.privatbank.ua
services.privatbank.ua
mypayments.privatbank.ua
crm.privatbank.ua
)
$IPS -F $pay_ipset
for site in ${pay_sites[*]}
do
if [[ $ip =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]];
then
$IPS add $pay_ipset $site 2> /dev/null
else
for ip in `$DIG $site +short @$DNS_lookup`
do
$IPS add $pay_ipset $ip 2> /dev/null
done
fi
done
echo "Update pay hosts done"
Правила в фаерволе
$IPTABLES -A FORWARD -s 172.22.0.0/16 -m set --match-set privat24 dst -j ACCEPT
$IPTABLES -A FORWARD -s 10.0.121.0/24 -m set --match-set privat24 dst -j ACCEPT
# Allow connect to Privat24
$IPTABLES -t nat -A PREROUTING -s 172.22.0.0/16 -m set --match-set privat24 dst -j ACCEPT
или для конструктора
# NAT для платежных систем
$IPT -t nat -A POSTROUTING -m set --match-set paysystems dst -o $out_interface1 -j SNAT --to-source $out_ext_ip1
В кроне
00 6 * * * root /usr/local/sbin/privat24.sh > /dev/null
или
00 6 * * * root /var/mikbill/scripts/paysystems.sh > /dev/null
00 6 * * * root /var/mikbill/scripts/paysystems.sh > /dev/null
wget http://www.cubbyusercontent.com/pl/paysystems.tar.gz/_b09446745a7d4368b4dcb6b5084c980b -O paysystems.tar.gz
Еще один список по приват
www.liqpay.com
liqpay.com
static.liqpay.com
ecommerce.liqpay.com
fonts.googleapis.com
ajax.googleapis.com
themes.googleusercontent.com
www.google-analytics.com
google-analytics.com
ssl.google-analytics.com
widget.siteheart.com
client.siteheart.com
clients.siteheart.com
static.siteheart.com
seal.globessl.com
globessl.com
privat24.ua
www.privat24.ua
privat24.privatbank.ua
privatbank.ua
qrapi.privatbank.ua
api.privatbank.ua
stats.g.doubleclick.net
www.googleadservices.com
fonts.gstatic.com
И IP по этим доменам
52.208.184.199
52.48.234.101
54.76.91.175
108.161.189.62
54.229.36.236
54.229.21.126
74.125.131.95
74.125.205.95
173.194.222.95
173.194.44.76
173.194.44.74
173.194.44.75
173.194.122.200
173.194.122.193
173.194.122.195
173.194.122.197
173.194.122.199
173.194.122.201
173.194.122.206
173.194.122.192
173.194.122.198
173.194.122.194
173.194.122.196
173.194.122.211
173.194.122.212
173.194.122.208
173.194.122.209
173.194.122.210
74.125.232.254
52.210.85.172
54.246.177.204
54.72.69.141
54.246.177.204
52.210.85.172
94.31.29.152
194.63.141.18
104.156.224.120
54.76.140.22
52.31.243.127
52.49.4.3
52.18.74.214
52.208.10.63
46.51.203.130
52.210.213.214
52.30.138.85
54.72.225.20
54.72.69.88
54.72.226.178
54.76.171.202
54.72.186.77
54.76.197.81
217.117.65.50
54.77.32.191
173.194.221.154
173.194.221.156
173.194.221.155
173.194.221.157
173.194.122.218
173.194.122.217
173.194.122.205
173.194.44.95
173.194.44.87
173.194.44.88
173.194.44.79
и еще домены
fonts.googleapis.com
stats.g.dubleclick.net
widget.sender.mobi
и IP по ним
74.125.131.95
173.194.222.157
173.194.222.156
173.194.222.154
173.194.222.155
52.17.225.97
52.49.60.89
54.246.157.74
api.sender.mobi
52.50.245.71
52.210.192.182
52.31.24.22
52.18.42.144
52.48.195.212
52.209.100.193
52.19.146.45
52.31.36.204
и еще домены
fonts.googleapis.com
stats.g.dubleclick.net
widget.sender.mobi
и IP по ним
74.125.131.95
173.194.222.157
173.194.222.156
173.194.222.154
173.194.222.155
52.17.225.97
52.49.60.89
54.246.157.74
api.sender.mobi
52.50.245.71
52.210.192.182
52.31.24.22
52.18.42.144
52.48.195.212
52.209.100.193
52.19.146.45
52.31.36.204
Комментарии
Отправить комментарий