ขอความช่วยเหลือหน่อยครับ ด่วน .. ขอความช่วยเหลือเรื่องการแก้ไข textfile อะครับ
แก้ไข textfile ยังไงครับอธิบายหน่อย
Date :
2010-01-23 18:13:27
By :
Dragons_first
# -------------------------------------------------------------
# Author : Mr.Permpong Chaorungmethee (Mr.Alexa)
# WebSite : http://www.zealzonecafe.com
# MSN : [email protected]
# Email : [email protected]
#
# Script : Traffic Control for Internet cafe' Business
# Type : N - WANs
#
# -------------------------------------------------------------
# ----- ----- ----- ----- ----- ----- ----- ----- #
# ----- Multi-Wan n Line(s)
# ----- ----- ----- ----- ----- ----- ----- ----- #
# ----- change to you local IP
My_Local_Net=192.168.0.0/16
My_IP=192.168.0.254
# ----- Number of internet connection (All connections that can access to INTERNET)
LineNumber=3
# ----- Number of game's line.
GameLineNumber=1
# If = 1, then you will get GOTO_GAME1
# If = 2, then you will get GOTO_GAME1, and GOTO_GAME2,
# . . . and so on.
# ----- Variables preparation
fwmark=0x800
pName="ppp"
startUpLink=0
i=0;
n=0
nn=0
nnn=0
upLinkCount=0
set pppMark
set pppName
set pppAddr
set pppGW
set pppStatus
set otherUpLink
set allUpLink
while [ $n -lt $LineNumber ]
do
pppMark[$n]=$fwmark$n
pppName[$n]=$pName$n
status=`/sbin/ifconfig | grep "${pppName[$n]}"`
if [ -n "$status" ]; then
pppStatus[$n]=1
upLinkCount=$((upLinkCount+1))
allUpLink[$nnn]=$n
if [ $upLinkCount -eq 1 ]; then
startUpLink=$n
else
otherUpLink[$nn]=$n
nn=$((nn+1))
fi
nnn=$((nnn+1))
else
pppStatus[$n]=0
fi
pppAddr[$n]=`ifconfig | grep -A1 ${pppName[$n]} | tail -1 | cut -d : -f 2 | cut -f 1 -d " "`
pppGW[$n]=`ip route | grep ${pppName[$n]} | head -1 | cut -f 1 -d " "`
n=$((n+1))
done
# ----- Controls settings
echo "1" > /proc/sys/net/ipv4/ip_forward
echo "1" > /proc/sys/net/ipv4/conf/default/rp_filter
echo "1" > /proc/sys/kernel/core_uses_pid
# ----- Flush
iptables -t mangle -F
modprobe ip_nat_ftp
modprobe ip_tables
modprobe iptable_nat
modprobe ipt_conntrack
modprobe ip_conntrack
modprobe ip_conntrack_ftp
modprobe ip_conntrack_irc
modprobe ip_nat_irc
modprobe ip_nat_snmp_basic
# ----- set default policies
iptables -P INPUT ACCEPT
iptables -P FORWARD ACCEPT
iptables -P OUTPUT ACCEPT
# ----- set default policies
iptables -t nat -P PREROUTING ACCEPT
iptables -t nat -P POSTROUTING ACCEPT
iptables -t nat -P OUTPUT ACCEPT
# ----- set default policies
iptables -t mangle -P PREROUTING ACCEPT
iptables -t mangle -P POSTROUTING ACCEPT
iptables -t mangle -P INPUT ACCEPT
iptables -t mangle -P OUTPUT ACCEPT
iptables -t mangle -P FORWARD ACCEPT
# ----- IP sharing
i=0;
while [ $i -lt ${#pppName[*]} ]
do
iptables -t nat -D POSTROUTING -s $My_Local_Net -o ${pppName[$i]} -j MASQUERADE
iptables -t nat -A POSTROUTING -s $My_Local_Net -o ${pppName[$i]} -j MASQUERADE
i=$((i+1));
done
# ----- Squid
if [ -f /var/run/squid.pid ]; then
iptables -t nat -D PREROUTING -p tcp -m multiport --dports 80,5977 -j REDIRECT --to-port 3128 > /dev/null
iptables -t nat -I PREROUTING -p tcp -m multiport --dports 80,5977 -j REDIRECT --to-port 3128
# CSO
iptables -t nat -D PREROUTING -p tcp -d 202.43.33.0/24 --dport 9898 -j REDIRECT --to-port 3128 > /dev/null
iptables -t nat -I PREROUTING -p tcp -d 202.43.33.0/24 --dport 9898 -j REDIRECT --to-port 3128
# SealOnline's Game Guard
iptables -t nat -D PREROUTING -p tcp -d 61.47.39.89 --dport 80 -j ACCEPT
iptables -t nat -I PREROUTING -p tcp -d 61.47.39.89 --dport 80 -j ACCEPT
iptables -t nat -D PREROUTING -p tcp -d 61.47.39.88 --dport 80 -j ACCEPT
iptables -t nat -I PREROUTING -p tcp -d 61.47.39.88 --dport 80 -j ACCEPT
# SF's Game Guard
iptables -t nat -D PREROUTING -p tcp -d 61.90.203.4 --dport 80 -j ACCEPT
iptables -t nat -I PREROUTING -p tcp -d 61.90.203.4 --dport 80 -j ACCEPT
# Pangya
iptables -t nat -D PREROUTING -p tcp -d 58.64.24.163/24 --dport 80 -j ACCEPT
iptables -t nat -D PREROUTING -p tcp -d 164.115.2.134/24 --dport 80 -j ACCEPT
iptables -t nat -D PREROUTING -p tcp -d 203.195.98.6/24 --dport 80 -j ACCEPT
iptables -t nat -I PREROUTING -p tcp -d 58.64.24.163/24 --dport 80 -j ACCEPT
iptables -t nat -I PREROUTING -p tcp -d 164.115.2.134/24 --dport 80 -j ACCEPT
iptables -t nat -I PREROUTING -p tcp -d 203.195.98.6/24 --dport 80 -j ACCEPT
# DotA
iptables -t nat -D PREROUTING -p tcp -d 210.86.182.252/24 --dport 80 -j ACCEPT
iptables -t nat -I PREROUTING -p tcp -d 210.86.182.252/24 --dport 80 -j ACCEPT
# Laghaim
iptables -t nat -D PREROUTING -p tcp -d 61.90.198.122 --dport 80 -j ACCEPT
iptables -t nat -I PREROUTING -p tcp -d 61.90.198.122 --dport 80 -j ACCEPT
# LastChaos
iptables -t nat -D PREROUTING -p tcp -d 61.90.198.99/24 --dport 80 -j ACCEPT
iptables -t nat -I PREROUTING -p tcp -d 61.90.198.99/24 --dport 80 -j ACCEPT
# RAN
iptables -t nat -D PREROUTING -p tcp -d 202.142.207.240 --dport 80 -j ACCEPT
iptables -t nat -I PREROUTING -p tcp -d 202.142.207.240 --dport 80 -j ACCEPT
# Hotmail
iptables -t nat -D PREROUTING -p tcp -d 207.46.8.249/16 --dport 80 -j ACCEPT
iptables -t nat -I PREROUTING -p tcp -d 207.46.9.121/16 --dport 80 -j ACCEPT
iptables -t nat -D PREROUTING -p tcp -d 65.55.187.39/16 --dport 80 -j ACCEPT
iptables -t nat -I PREROUTING -p tcp -d 65.55.113.23/16 --dport 80 -j ACCEPT
iptables -t nat -D PREROUTING -p tcp -d 64.62.193.48/16 --dport 80 -j ACCEPT
iptables -t nat -I PREROUTING -p tcp -d 64.62.193.48/16 --dport 80 -j ACCEPT
iptables -t nat -D PREROUTING -p tcp -d 8.12.221.126/16 --dport 80 -j ACCEPT
iptables -t nat -I PREROUTING -p tcp -d 8.12.221.126/16 --dport 80 -j ACCEPT
iptables -t nat -D PREROUTING -p tcp -d 206.33.55.125/16 --dport 80 -j ACCEPT
iptables -t nat -I PREROUTING -p tcp -d 206.33.55.125/16 --dport 80 -j ACCEPT
iptables -t nat -D PREROUTING -p tcp -d 12.129.210.41/16 --dport 80 -j ACCEPT
iptables -t nat -I PREROUTING -p tcp -d 12.129.210.41/16 --dport 80 -j ACCEPT
fi
# ----- Frox
if [ -f /var/run/frox.pid ]; then
iptables -t nat -D PREROUTING -p tcp --dport 21 -j REDIRECT --to-port 2121
iptables -t nat -I PREROUTING -p tcp --dport 21 -j REDIRECT --to-port 2121
# HipStreet for Frox
iptables -t nat -D PREROUTING -p tcp -d 58.97.46.0/24 --dport 8021 -j REDIRECT --to-port 2121 > /dev/null
iptables -t nat -I PREROUTING -p tcp -d 58.97.46.0/24 --dport 8021 -j REDIRECT --to-port 2121
fi
# ----- ----- ----- ----- ----- ----- ----- ----- #
# - START - multi wan N Line
# ----- ----- ----- ----- ----- ----- ----- ----- #
# ----- ----- ----- ----- ----- ----- ----- ----- #
# ----- Create our own CHAINS
# ----- ----- ----- ----- ----- ----- ----- ----- #
# ----- Creat GOTO_GAME
n=0;
while [ $n -lt $GameLineNumber ]
do
iptables -t mangle -N GOTO_GAME$((n+1))
iptables -t mangle -F GOTO_GAME$((n+1))
iptables -t mangle -A GOTO_GAME$((n+1)) -j MARK --set-mark ${pppMark[$n]}
iptables -t mangle -A GOTO_GAME$((n+1)) -j ACCEPT
n=$((n+1))
done
# ----- Create CHECK_STREAMING_WEBS
iptables -t mangle -N CHECK_STREAMING_WEBS
iptables -t mangle -F CHECK_STREAMING_WEBS
# Zheza.com
iptables -t mangle -A CHECK_STREAMING_WEBS -d 202.142.207.140 -j ACCEPT
# ----- Create CHECK_SERVICE_PORTS
iptables -t mangle -N CHECK_SERVICE_PORTS
iptables -t mangle -F CHECK_SERVICE_PORTS
iptables -t mangle -A CHECK_SERVICE_PORTS -p tcp -m multiport --dports 20:25,80,443,554,1863,5050,5190,3128,3130,8080,9099,16667 -j ACCEPT
iptables -t mangle -A CHECK_SERVICE_PORTS -p tcp -m multiport --dports 1863,6667,2009,2121,5977,6969,6889,8000,8021,9898 -j ACCEPT
iptables -t mangle -A CHECK_SERVICE_PORTS -p udp -m multiport --dports 20:25,80,443,554,1863,5050,5190,3128,3130,8080,9099,16667 -j ACCEPT
iptables -t mangle -A CHECK_SERVICE_PORTS -p udp -m multiport --dports 1863,6667,2009,2121,5977,6969,6889,8000,8021,9898 -j ACCEPT
# Dns
iptables -t mangle -A CHECK_SERVICE_PORTS -p tcp --destination-port 53 -j ACCEPT
iptables -t mangle -A CHECK_SERVICE_PORTS -p udp --destination-port 53 -j ACCEPT
# ----- Create CHECK_IPP2P
iptables -t mangle -N CHECK_IPP2P
iptables -t mangle -F CHECK_IPP2P
iptables -t mangle -A CHECK_IPP2P -m ipp2p --kazaa --gnu --edk --dc --bit --apple --soul --winmx --ares -j ACCEPT
# ----- Create CHECK_GAMES
iptables -t mangle -N CHECK_GAMES
iptables -t mangle -F CHECK_GAMES
# Abnormal game ports. CSO/Lineage2, check port of game patching. If so, using LoadBalance.
# CSO
iptables -t mangle -A CHECK_GAMES -d 202.43.33.0/24 -p tcp --dport 9898 -j ACCEPT
# LN2
iptables -t mangle -A CHECK_GAMES -d 61.90.199.6/32 -p tcp --dport 2009 -j ACCEPT
# Cabal patching?
iptables -t mangle -A CHECK_GAMES -d 203.144.132.0/24 -p tcp --dport 6969 -j ACCEPT
# Audition Korean
iptables -t mangle -A CHECK_GAMES -d 210.118.53.0/24 -j GOTO_GAME1
# Asiasoft
iptables -t mangle -A CHECK_GAMES -d 203.144.0.0/16 -j GOTO_GAME1
# N-age, and <unknown games>
# iptables -t mangle -A CHECK_GAMES -d 203.146.0.0/16 -j GOTO_GAME1
# Asiasoft International, SF,LN2
iptables -t mangle -A CHECK_GAMES -d 61.90.0.0/16 -j GOTO_GAME1
# ProjectOne, DOMO
# iptables -t mangle -A CHECK_GAMES -d 61.19.0.0/16 -j GOTO_GAME1
# RacyCity
iptables -t mangle -A CHECK_GAMES -d 61.19.242.0/24 -j GOTO_GAME1
# Seal, HY, 3Kingdoms, 16, PVP
iptables -t mangle -A CHECK_GAMES -d 61.47.0.0/16 -j GOTO_GAME1
# PFW, Eco
iptables -t mangle -A CHECK_GAMES -d 61.91.0.0/16 -j GOTO_GAME1
# HipStreet
iptables -t mangle -A CHECK_GAMES -d 58.97.46.10/32 -j GOTO_GAME1
iptables -t mangle -A CHECK_GAMES -d 58.97.46.16/32 -j GOTO_GAME1
# Pangya, Rebirth, Pucca, Flyff
iptables -t mangle -A CHECK_GAMES -d 58.64.0.0/16 -j GOTO_GAME1
# DotA, Getamped
iptables -t mangle -A CHECK_GAMES -d 210.86.0.0/16 -j GOTO_GAME1
# LunaOnline, pko, water, SDO, Secret, RYL
iptables -t mangle -A CHECK_GAMES -d 202.43.0.0/16 -j GOTO_GAME1
# RAN
iptables -t mangle -A CHECK_GAMES -d 202.142.207.0/24 -j GOTO_GAME1
# TalesRunner
iptables -t mangle -A CHECK_GAMES -d 203.113.0.0/16 -j GOTO_GAME1
# GG
iptables -t mangle -A CHECK_GAMES -d 74.55.122.70/24 -j GOTO_GAME1
# iptables -t mangle -A CHECK_GAMES -d 74.55.122.70:8687 -j GOTO_GAME1
# iptables -t mangle -A CHECK_GAMES -d 74.53.215.8:7456 -j GOTO_GAME1
# NosTale
iptables -t mangle -A CHECK_GAMES -d 203.121.165.196/24 -j GOTO_GAME1
# ----- Create CHECK_BONUS
iptables -t mangle -N CHECK_BONUS
iptables -t mangle -F CHECK_BONUS
iptables -t mangle -A CHECK_BONUS -d secure1.asiasoft.co.th -p tcp -m multiport --dports 443 -j GOTO_GAME1
iptables -t mangle -A CHECK_BONUS -d secure2.asiasoft.co.th -p tcp -m multiport --dports 443 -j GOTO_GAME1
# ----- ----- ----- ----- ----- ----- ----- ----- #
# ----- Load Balance
# ----- ----- ----- ----- ----- ----- ----- ----- #
# ----- ----- ----- ----- ----- ----- ----- ----- #
# ----- Only 1 link is up
# ----- ----- ----- ----- ----- ----- ----- ----- #
if [ $upLinkCount -eq 1 ]; then
i=0
while [ $i -lt $GameLineNumber ]
do
iptables -t mangle -F GOTO_GAME$((i+1))
iptables -t mangle -A GOTO_GAME$((i+1)) -j MARK --set-mark ${pppMark[$startUpLink]}
iptables -t mangle -A GOTO_GAME$((i+1)) -j ACCEPT
i=$((i+1))
done
ip route replace default table 250 proto static nexthop via ${pppGW[$startUpLink]} dev ${pppName[$startUpLink]} weight 10
fi
# ----- ----- ----- ----- ----- ----- ----- ----- #
# ----- more then 1 link is up, and up-links <= GameLineNumber
# ----- ----- ----- ----- ----- ----- ----- ----- #
if [ $upLinkCount -gt 1 -a $upLinkCount -lt $GameLineNumber -o $upLinkCount -eq $GameLineNumber ]; then
i=0
while [ $i -lt $GameLineNumber ]
do
iptables -t mangle -F GOTO_GAME$((i+1))
iptables -t mangle -A GOTO_GAME$((i+1)) -j MARK --set-mark ${pppMark[$startUpLink]}
iptables -t mangle -A GOTO_GAME$((i+1)) -j ACCEPT
i=$((i+1))
done
balanceRule="replace default table 250 proto static "
i=0
while [ $i -lt ${#otherUpLink[*]} ]
do
balanceRule=$balanceRule" nexthop via ${pppGW[${otherUpLink[$i]}]} dev ${pppName[${otherUpLink[$i]}]} weight 10 "
i=$((i+1))
done
ip route $balanceRule
fi
# ----- ----- ----- ----- ----- ----- ----- ----- #
# ----- more then 1 link is up, and > GameLineNumber
# ----- ----- ----- ----- ----- ----- ----- ----- #
if [ $upLinkCount -gt 1 -a $upLinkCount -gt $GameLineNumber ]; then
i=0
while [ $i -lt $GameLineNumber ]
do
iptables -t mangle -F GOTO_GAME$((i+1))
iptables -t mangle -A GOTO_GAME$((i+1)) -j MARK --set-mark ${pppMark[${allUpLink[$i]}]}
iptables -t mangle -A GOTO_GAME$((i+1)) -j ACCEPT
i=$((i+1))
done
balanceRule="replace default table 250 proto static "
while [ $i -lt ${#allUpLink[*]} ]
do
balanceRule=$balanceRule" nexthop via ${pppGW[${allUpLink[$i]}]} dev ${pppName[${allUpLink[$i]}]} weight 10 "
i=$((i+1))
done
ip route $balanceRule
fi
# ----- ----- ----- ----- ----- ----- ----- ----- #
# ----- START rule adding
# ----- ----- ----- ----- ----- ----- ----- ----- #
# Firstly, Allow to add IP-Bonus via ppp0
iptables -t mangle -A PREROUTING -p tcp -s $My_Local_Net -j CHECK_BONUS
# ipp2p
iptables -t mangle -A PREROUTING -s $My_IP -j CHECK_IPP2P
iptables -t mangle -A OUTPUT -s $My_IP -j CHECK_IPP2P
iptables -t mangle -A FORWARD -s $My_IP -j CHECK_IPP2P
iptables -t mangle -A PREROUTING -d $My_IP -j CHECK_IPP2P
iptables -t mangle -A OUTPUT -d $My_IP -j CHECK_IPP2P
iptables -t mangle -A FORWARD -d $My_IP -j CHECK_IPP2P
# Service Ports
iptables -t mangle -A PREROUTING -j CHECK_SERVICE_PORTS
iptables -t mangle -A OUTPUT -j CHECK_SERVICE_PORTS
# iptables -t mangle -A FORWARD -j CHECK_SERVICE_PORTS
# Streaming Webs
iptables -t mangle -A PREROUTING -j CHECK_STREAMING_WEBS
# Games
# PREROUTING
iptables -t mangle -A PREROUTING -p all -j CHECK_GAMES
# DotA
# Create DotA
iptables -t mangle -A PREROUTING -p tcp -m multiport --sports 7051:7080,7101:7160 -j GOTO_GAME1
iptables -t mangle -A PREROUTING -p udp -m multiport --sports 7051:7080,7101:7160 -j GOTO_GAME1
# Join DotA
iptables -t mangle -A PREROUTING -p tcp -m multiport --dports 6101:6200,7101:7200 -j GOTO_GAME1
iptables -t mangle -A PREROUTING -p udp -m multiport --dports 6101:6200,7101:7200 -j GOTO_GAME1
# BF2
iptables -t mangle -A PREROUTING -p tcp --sport 4711 --dport 4711 -j GOTO_GAME1
iptables -t mangle -A PREROUTING -p tcp -m multiport --dports 29900,29901,29920,28910 -j GOTO_GAME1
iptables -t mangle -A PREROUTING -p udp -m multiport --dports 27900,29900,29910,27901,55123:55570,1500:4999,16567:16568 -j GOTO_GAME1
# Allow ipp2p only me
iptables -t filter -D FORWARD -s $My_IP -m ipp2p --kazaa --gnu --edk --dc --bit --apple --soul --winmx --ares -j ACCEPT
iptables -t filter -I FORWARD -s $My_IP -m ipp2p --kazaa --gnu --edk --dc --bit --apple --soul --winmx --ares -j ACCEPT
iptables -t filter -D FORWARD -d $My_IP -m ipp2p --kazaa --gnu --edk --dc --bit --apple --soul --winmx --ares -j ACCEPT
iptables -t filter -I FORWARD -d $My_IP -m ipp2p --kazaa --gnu --edk --dc --bit --apple --soul --winmx --ares -j ACCEPT
# Allow ipp2p for Special Games (FIFA Online 2)
iptables -t filter -D FORWARD -p all -s 61.91.68.0/24 -j ACCEPT
iptables -t filter -I FORWARD -p all -s 61.91.68.0/24 -j ACCEPT
iptables -t filter -D FORWARD -p all -d 61.91.68.0/24 -j ACCEPT
iptables -t filter -I FORWARD -p all -d 61.91.68.0/24 -j ACCEPT
# No match, use Load Balance
iptables -t mangle -A PREROUTING -i eth1 -j ACCEPT
# ----- END rule adding
# ----- ----- ----- ----- ----- ----- ----- ----- #
# - END - Multi-Wan n Line(s)
# ----- ----- ----- ----- ----- ----- ----- ----- #
รับค่าจากtextboxมาแก้ไขในไฟล์ประมาณนี้อะครับ เช่นผมต้องการรับค่าที่กรอกเป็นตัวเลขมาแก้ไขบรรทักที่19ที่Linnumber=3ให้เป็นLinenumber=4
Date :
2010-01-23 22:57:26
By :
NextStep
file_get_contents + str_replace
Date :
2010-01-24 00:15:46
By :
เซ็งตัวเอง
Load balance : Server 02