rs232

p2partisan 6.08

Jul 12th, 2017
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 89.51 KB | None | 0 0
  1. #!/bin/sh
  2. #
  3. # p2partisan v6.08 (13/06/2017)
  4. #
  5. # Official page - http://www.linksysinfo.org/index.php?posts/235301/
  6. #
  7. # <CONFIGURATION> ###########################################
  8. # Adjust location where the files are kept
  9. P2Partisandir=/cifs1/p2partisan
  10. #
  11. # Enable logging? Use only for troubleshooting. 0=off 1=on
  12. syslogs=1
  13. # Maximum number of logs to be recorded in a given 60 min
  14. # Consider set this very low (like 3 or 6) once your are
  15. # happy with the installation. To troubleshoot blocked
  16. # connection close all the secondary traffic e.g. p2p
  17. # and try a connection to the blocked site/port you should
  18. # find a reference in the logs.
  19. maxloghour=1
  20. #
  21. # Ports to be whitelisted. Whitelisted ports will never be
  22. # blocked no matter what the source/destination IP is.
  23. # This is very important if you're running a service like
  24. # e.g. SMTP/HTTP/IMAP/else. Separate value in the list below
  25. # with commas - NOTE: It is suggested to leave the following ports
  26. # always on as a minimum:
  27. # tcp:43,80,443
  28. # udp:53,123,1194:1196
  29. # you might want to append remote admin and VPN ports, and
  30. # anything else you think it's relevant.
  31. # Standard iptables syntax, individual ports divided by "," and ":" to
  32. # define a range e.g. 80,443,2100:2130. Do not whitelist you P2P client!
  33. whiteports_tcp=80,443,3658,8080
  34. whiteports_udp=53,123,1194:1197,1723,3658
  35. #
  36. # Greyports are port/s you absolutely want to filter against lists.
  37. # Think of an Internet host that has its P2P client set on port 53 UDP.
  38. # If you have the DNS port is in the whiteports_udp then P2Partisan would
  39. # be completely bypassed. Internet-client:53 -> your-client:"P2Pport""
  40. # greyport is in a nutshell a list of port/s used by your LAN P2Pclient/s.
  41. # It's suggested you disable random port on your P2Pclient and add the
  42. # client port/s here. NOTE:
  43. # Accepted syntax: single port, multiple ports and ranges e.g.
  44. # greyports=22008,6789
  45. # the above would grey list 22008 and 6789. Don't know your client port?
  46. # try ./p2partisan.sh detective
  47. greyports_tcp=
  48. greyports_udp=
  49. #
  50. # Greyline is the limit of connections per given "IP:port" above which
  51. # Detective becomes suspicious. NOTE: This counts 1/2 of the sessions the
  52. # router actually reports on because of the NAT implication. So this number
  53. # represents the session as seen on the LAN client. Affects detective only.
  54. greyline=100
  55. #
  56. # Schedule defines the allowed hours when P2Partisan tutor can update lists
  57. # Use the syntax from 0 to 23. e.g. 1,6 allows updates from 1 to 6 am
  58. scheduleupdates="1,6"
  59. #
  60. # Defines how many lists can be loaded concurrently at any given time. Default 2
  61. maxconcurrentlistload=2
  62. #
  63. # Enable check on script availability to help autorun.
  64. # If the ./partisan.sh is remote wait for the file to be available
  65. # instead of quit with a file missing error
  66. autorun_availability_check=1
  67. #
  68. # IP for testing Internet connectivity
  69. testip=google.com
  70. # </CONFIGURATION> ###########################################
  71.  
  72.     ipsetversion=`ipset -V | grep ipset | awk '{print $2}' | cut -c2` #4=old 6=new
  73.     if [ $ipsetversion != 6 ]; then
  74.         echo -e "\033[1;31mipset not compatible with this P2Partisan release.
  75. ipset available: $ipsetversion
  76. ipset supported: 6.x\033[0;40m"
  77.     exit
  78.     fi
  79.  
  80.     # Wait until Internet is available
  81.     while :
  82.     do
  83.             ping -c 3 $testip >/dev/null 2>&1
  84.             if [ $? = 0 ]; then
  85.                     break
  86.             fi
  87.             sleep 5
  88.     done
  89.  
  90. pidfile="/var/run/p2partisan.pid"
  91. logfile=`nvram get log_file_path` || logfile=`/var/log/messages`
  92. cd $P2Partisandir
  93. version=`head -3 ./p2partisan.sh | tail -1 | cut -f 3- -d " "`
  94. alias ipset='/bin/nice -n10 /usr/sbin/ipset'
  95. alias sed='/bin/sed'
  96. alias iptables='/usr/sbin/iptables'
  97. alias service='/sbin/service'
  98. alias killall='/usr/bin/killall'
  99. alias plog='logger -t "| P2PARTISAN" -s'
  100. alias deaggregate='/bin/nice -n10 /tmp/deaggregate.sh'
  101. service ntpc restart >/dev/null
  102. now=`date +%s`
  103. rm=1
  104. wanif=`nvram get wan_ifname` && rm=0 || wanif=`nvram get wan_ifnames`  #RMerlin work around
  105. lanif=`nvram get lan_ifname`
  106. vpnif=`route | grep -E '^default.*.tun..$|^default.*.ppp.$' | awk '{print $8}'`
  107.  
  108. # DHCP hardcoded patch
  109. p1=`echo $whiteports_udp | grep -Eo '^67[,|:]|[,|:]67[,|:]|,67$' | wc -l`
  110. p2=`echo $whiteports_udp | grep -Eo '^68[,|:]|[,|:]68[,|:]|,68$' | wc -l`
  111. if [ $p1 -eq "0" ]; then
  112.         whiteports_udp=${whiteports_udp},67
  113. fi            
  114. if [ $p2 -eq "0" ]; then
  115.         whiteports_udp=${whiteports_udp},68
  116. fi
  117.  
  118.  
  119.  
  120. [ -f /tmp/deaggregate.sh ] ||
  121. {
  122.  
  123. b64="openssl enc -base64 -d"
  124. [[ "$(echo WQ==|$b64)" != "Y" ]] && b64="b64"
  125.  
  126. {
  127. cat <<'ENDF'| $b64 | gunzip > /tmp/deaggregate.sh
  128. H4sIAKYyLVYCA+1UwU7bQBC971cMxi02sZPYlIJIF4mKtqpUtZV6DKli7E2yqlkv
  129. XodEBf69M+slJKEqp0o9NDnEnnnz5u2bye7u9C6l6pkZY4XIptNaTLNGBCHcMptQ
  130. MhcQq6QP2eIH7LHJXOWNrBRInUrVBFITFGBS1RDUouH9SHGjS0mpKIu8i64XRkue
  131. DJZvuBosO50QCFbVQWlmctJQUXQcRtlwOQqRCF/ntaIfds/W2qkmlZo4Cb9smxJR
  132. pgqKpoeHVC01r1tajB2HrbAAex8MtsBe1yOmrYKIBA6eyHj77sPHz9jyUjaG95cT
  133. 92Hvv3FvGI88wpCgy8wI7pzxE2ovVLEKpBRYzGQpICAkvOGUb89iGqGBQ/8RAqic
  134. YBE4p5LIosIQdrht1VbKyTrWnSYgqREEB0nc1mDVKXWDtuiyFtkPOui9693puBdd
  135. o9gHv20Xr+cFB2nL4w4JrQDobGuzJPdsD2CXmlUTuzcmr6W2TqrsSnA/YaU0aHDJ
  136. /ZRV80bPG+4fMF1j7hUzi0xz/5CVVVZw/zX7mn7N6kYanJ6suX/EhhD/BL+tgxG8
  137. fAmOo+9SVLmRSBgzpUCHE9a6O4RxaSBOoNdc6d5+99OXs3NIT6FXiJuempcl3MEi
  138. h7gcQzwVD4ysqBzPIT4qwRiaP1xJicU1pDAaQDMTCp0go0U+qzB4Cp7tpFPtztL1
  139. yQvb2LObawQy7ODKmaaq8U83IZ3+xuF7bU0ui5p29Oo50vuNIzFRPpGbrMm1UpPn
  140. pS6mpPQLxOD5bo4eNlq3bjpXP6XGhwvE46WiIb4B8L4PhydGZ7k4GY32dy/uNt59
  141. z+Fz0lacoAOpi6xdTRi5Xf1HcIkLsG7gYJyDZxBfk49WM/gui7NaeXwOcfaISLr2
  142. +5jeJNhO03I+cNtnXLKLx2x28xD//fwoZecHd3dP6izr83PPZ1dVAUdHR399O/rb
  143. 29H/vx1/3o5/YI4T6a6lWOEI8E71VlPUlWn4uCCjOi/MmNVz1Ui8kMd2uH4QgE8Q
  144. nB3VQRiOWZtxQJz+llSXoKa/APAZbrlLCAAA
  145. ENDF
  146. }
  147. chmod 777 /tmp/deaggregate.sh
  148. }
  149.  
  150.  
  151. psoftstop() {
  152.                 [ -f /tmp/p2partisan.loading ] && echo "P2Partisan is still loading. Can't stop right now Exiting..." && exit
  153.         echo -e "\033[0;40m
  154. +------------------------- P2Partisan --------------------------+
  155. |                   _______ __              
  156. |                  |     __|  |_.-----.-----.
  157. |                  |__     |   _|  _  |  _  |
  158. |            Soft  |_______|____|_____|   __|
  159. |                                     |__|  
  160. |                                            
  161. +---------------------------------------------------------------+"
  162.         echo -e "| Stopping P2Partisan..."
  163.         ./iptables-del 2> /dev/null
  164.         plog "Stopping P2Partisan..."
  165.         [ -f $pidfile ] && rm -f "$pidfile" 2> /dev/null
  166.         [ -f iptables-add ] && rm -f "iptables-add" 2> /dev/null
  167.         [ -f iptables-del ] && rm -f "iptables-del" 2> /dev/null
  168.         ptutorunset
  169.         echo -e "+---------------------------------------------------------------+ \033[0;39m"
  170. }
  171.  
  172. pforcestop() {
  173. if [ -n "$1" ]; then
  174.     if [ $1 != fix ]; then
  175.     name=$1
  176.         echo -e "\033[0;40m
  177. +------------------------- P2Partisan --------------------------+
  178. |  _____   __         __                         __         __        
  179. | |     |_|__|.-----.|  |_ ______.--.--.-----.--|  |.---.-.|  |_.-----.
  180. | |       |  ||__ --||   _|______|  |  |  _  |  _  ||  _  ||   _|  -__|
  181. | |_______|__||_____||____|      |_____|   __|_____||___._||____|_____|
  182. |                                     |__|                
  183. |                                            
  184. +---------------------------------------------------------------+
  185. |            background updating list: \033[1;35m$1\033[0;40m
  186. +---------------------------------------------------------------+\033[0;39m"
  187.         cat blacklists | grep -Ev "^$" | tr -d "\r" | grep -E "^#( .*|)$name http*." > /dev/null 2>&1 && {
  188.         echo -e "\033[0;40m| Warning: \033[1;33mthe list reference exists but is currently disabled in the blacklists\033[0;40m
  189. +---------------------------------------------------------------+\033[0;39m"
  190.         exit
  191.         }  2> /dev/null
  192.         {
  193.         cat blacklists | grep -Ev "^#|^$" | tr -d "\r" | grep $name > /dev/null 2>&1 || {
  194.         echo -e "\033[0;40m| Error: \033[1;31mit appears like the list $name is not a valid reference.\033[0;40m Typo?
  195. +---------------------------------------------------------------+\033[0;39m"
  196.         exit
  197.         } 2> /dev/null
  198.         }
  199.  
  200. url=`cat blacklists | grep -Ev "^#|^$" | tr -d "\r" | grep $name | awk '{print $2}'`
  201.  
  202.     if [ -n "$url" ]; then
  203.          ps | grep -E ".*deaggregate.sh $name"| grep -v grep | cut -c1-6 | while read line; do kill $line 2> /dev/null; done
  204.          rm "/tmp/p2partisan.$name.LOAD" 2> /dev/null
  205.         if [ "$(ipset --swap "$name.bro" "$name.bro" 2>&1 | grep 'does not exist')" != "" ]
  206.             then
  207.                 ipset -N "$name.bro" hash:net hashsize 1024 --resize 5 maxelem 4096000
  208.             fi
  209.            
  210.                 statusaaa=`ipset -T $name.bro 1.1.1.1 2> /dev/null && echo "1" || echo "0"`
  211.                 statusaa=`ipset -L $name 2> /dev/null | head -8 | tail -1 | grep -Eo "^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]).*" > /dev/null && echo "1" || echo "0"`
  212.                     if [ $statusaa -eq 0 ]; then
  213.                         if [ $statusaaa -eq 1 ]; then
  214.                             {
  215.                             ipset swap $name $name.bro
  216.                             ipset -F $name.bro
  217.                             ipset -X $name.bro
  218.                             ipset -N $name.bro hash:net hashsize 1024 --resize 5 maxelem 4096000
  219.                             deaggregate $name.bro $url 1 "" $name $maxconcurrentlistload $P2Partisandir &
  220.                             } 2> /dev/null
  221.                         elif [ $statusaaa -eq 0 ]; then
  222.                             {
  223.                             ipset -F $name
  224.                             ipset -N $name hash:net hashsize 1024 --resize 5 maxelem 4096000
  225.                             deaggregate $name $url 1 "" "" $maxconcurrentlistload $P2Partisandir &
  226.                             } 2> /dev/null
  227.                         fi
  228.                     elif [ $statusaa -eq 1 ]; then
  229.                         {
  230.                         ipset -F $name.bro
  231.                         ipset -X $name.bro
  232.                         ipset -N $name.bro hash:net hashsize 1024 --resize 5 maxelem 4096000
  233.                         deaggregate $name.bro $url 1 "" $name $maxconcurrentlistload $P2Partisandir &
  234.                         } 2> /dev/null
  235.                     fi
  236.         else
  237.             echo -e "|                    \033[1;31mError: list not found\033[0;40m
  238. +---------------------------------------------------------------+\033[0;39m"
  239.         fi
  240.     exit
  241.     elif [ $1 == "fix" ]; then
  242.         rm ./*.cidr 2> /dev/null
  243.        
  244.     fi
  245. fi
  246.         echo -e "\033[0;40m
  247. +------------------------- P2Partisan --------------------------+
  248. |                   _______ __              
  249. |                  |     __|  |_.-----.-----.
  250. |                  |__     |   _|  _  |  _  |
  251. |            Hard  |_______|____|_____|   __|
  252. |                                     |__|  
  253. |                                            
  254. +---------------------------------------------------------------+"
  255. {
  256.     counter=0
  257.         killall "deaggregate.sh"
  258.         while iptables -L wanin | grep P2PARTISAN-IN
  259.         do
  260.                 iptables -D wanin -i $wanif -m state --state NEW -j P2PARTISAN-IN
  261.         done
  262.         while iptables -L wanout | grep P2PARTISAN-OUT
  263.         do
  264.                 iptables -D wanout -o $wanif -m state --state NEW -j P2PARTISAN-OUT
  265.         done
  266.         while iptables -L INPUT | grep P2PARTISAN-IN
  267.         do
  268.                 iptables -D INPUT -i $wanif -m state --state NEW -j P2PARTISAN-IN
  269.         done
  270.         while iptables -L OUTPUT | grep P2PARTISAN-OUT
  271.         do
  272.                 iptables -D OUTPUT -o $wanif -m state --state NEW -j P2PARTISAN-OUT
  273.         done
  274.         iptables -D INPUT -o $vpnif -m state --state NEW -j P2PARTISAN-IN
  275.         iptables -D OUTPUT -i $vpnif -m state --state NEW -j P2PARTISAN-IN
  276.         iptables -D FORWARD -o $vpnif -m state --state NEW -j P2PARTISAN-IN
  277.         iptables -F P2PARTISAN-DROP-IN
  278.         iptables -F P2PARTISAN-DROP-OUT
  279.         iptables -F P2PARTISAN-LISTS-IN
  280.         iptables -F P2PARTISAN-LISTS-OUT            
  281.         iptables -F P2PARTISAN-IN
  282.         iptables -F P2PARTISAN-OUT
  283.         iptables -X P2PARTISAN-DROP-IN  
  284.         iptables -X P2PARTISAN-DROP-OUT
  285.         iptables -X P2PARTISAN-LISTS-IN    
  286.         iptables -X P2PARTISAN-LISTS-OUT
  287.         iptables -X P2PARTISAN-IN
  288.         iptables -X P2PARTISAN-OUT
  289.         ipset -F
  290.         for i in `ipset --list | grep Name | cut -f2 -d ":" `; do
  291.                 ipset -X $i
  292.         done
  293.         chmod 777 ./*.gz
  294.         [ -f iptables-add ] && rm iptables-add
  295.         [ -f iptables-del ] && rm iptables-del
  296.         [ -f ipset-del ] && rm ipset-del
  297.         [ -f $pidfile ] && rm -f "$pidfile"
  298.         [ -f runtime ] && rm -f "runtime"
  299.         [ -f /tmp/p2partisan.loading ] && rm -r /tmp/p2partisan.loading
  300. plog " Unloading ipset modules"
  301.         lsmod | grep "xt_set" && sleep 2 ; rmmod -f xt_set
  302.         lsmod | grep "ip_set_hash_net" && sleep 2 ; rmmod -f ip_set_hash_net
  303.         lsmod | grep "ip_set" && sleep 2 ; rmmod -f ip_set
  304. plog " Removing the list files"
  305.         cat blacklists |  grep -Ev "^#|^$" | tr -d "\r" |
  306.    (
  307.     while read line
  308.     do
  309.             counter=`expr $counter + 1`
  310.             counter=$(printf "%02d" $counter)
  311.             name=`echo $line | awk '{print $1}'`
  312.             echo -e "| Removing Blacklist_$counter --> \033[1;37m***$name***\033[0;40m"
  313.                   [ -f ./$name.gz ] && rm -f ./$name.gz
  314.                         done
  315.     )
  316.         rm /tmp/*.LOAD
  317. } > /dev/null 2>&1
  318.         ptutorunset
  319. plog " P2Partisan stopped."
  320. echo -e "+---------------------------------------------------------------+\033[0;39m"
  321. }
  322.  
  323. pstatus() {
  324. if [ -n "$1" ]; then
  325. name=$1
  326.         echo -e "\033[0;40m
  327.        
  328. +------------------------- P2Partisan --------------------------+
  329. |  _____   __         __          _______ __          __              
  330. | |     |_|__|.-----.|  |_ ______|     __|  |_.---.-.|  |_.--.--.-----.
  331. | |       |  ||__ --||   _|______|__     |   _|  _  ||   _|  |  |__ --|
  332. | |_______|__||_____||____|      |_______|____|___._||____|_____|_____|                                                
  333. |                                            
  334. +---------------------------------------------------------------+
  335. |                    list name: \033[1;33m$1\033[0;40m
  336. +---------------------------------------------------------------+"
  337.  
  338. cat blacklists | grep -Ev "^$" | tr -d "\r" | grep -E "^#( .*|)$name http*." > /dev/null 2>&1 && {
  339. echo -e "| Warning: \033[1;33mthe list reference exists but is currently disabled in the blacklists\033[0;40m
  340. +---------------------------------------------------------------+"
  341. exit
  342. }  2> /dev/null
  343. {
  344. cat blacklists | grep -Ev "^#|^$" | tr -d "\r" | grep -o "$name " > /dev/null 2>&1 || {
  345. echo -e "| Error: \033[1;31mit appears like the list $name is not a valid reference.\033[0;40m Typo?
  346. +---------------------------------------------------------------+"
  347. exit
  348. } 2> /dev/null
  349. }
  350.             statusa=`cat /tmp/p2partisan.$name.LOAD 2> /dev/null || echo 5`
  351.             statusb=`cat /tmp/p2partisan.$name.bro.LOAD 2> /dev/null || echo 5`
  352.             statusap=`ps w | grep $name | grep -v grep | wc -l`
  353.             statusbp=`ps w | grep $name.bro | grep -v grep | wc -l`
  354.             statusaa=`ipset -L $name 2> /dev/null | head -8 | tail -1 | grep -Eo "^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]).*" > /dev/null && echo "1" || echo "0"`
  355.             statusbb=`ipset -L $name.bro 2> /dev/null | head -8 | tail -1 | grep -Eo "^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]).*" > /dev/null && echo "1" || echo "0"`
  356.             statusaaa=`ipset -T $name 1.1.1.1 2> /dev/null && echo "1" || echo "0"`
  357.             statusbbb=`ipset -T $name.bro 1.1.1.1 2> /dev/null && echo "1" || echo "0"`
  358.             sizeb=`ipset -L $name 2> /dev/null | head -5 | tail -1 | awk '{print $4}' || echo=0`
  359.             sizebb=`ipset -L $name.bro 2> /dev/null | head -5 | tail -1 | awk '{print $4}' || echo=0`
  360.             sizem=`echo $((sizeb/1024))`
  361.             sizemm=`echo $((sizebb/1024))`
  362.             age=`[ -e $name.cidr ] && echo $((\`date +%s\` - \`date -r $name.cidr +%s\`)) || echo 0`
  363.                         if [ $statusaaa -eq 0 ]; then
  364.                             if [ $statusaa -eq 1 ]; then
  365.                                 if [ $statusa -gt 2 ]; then
  366.                                     a="\033[1;33mPartially loaded\033[0;40m"
  367.                                 elif [ $statusa -le 2 ]; then
  368.                                     a="\033[1;35mLoading\033[0;40m"
  369.                                 fi
  370.                             else
  371.                                 if [ $statusap -eq 1 ]; then
  372.                                     a="\033[1;36mQueued\033[0;40m"
  373.                                 else
  374.                                     a="\033[1;31mEmpty\033[0;40m"
  375.                                 fi
  376.                             fi
  377.                         elif [ $statusaaa -eq 1 ]; then
  378.                             a="\033[1;32mFully loaded\033[0;40m"
  379.                         fi
  380.                        
  381.                         if [ $statusbbb -eq 0 ]; then
  382.                             if [ $statusbb -eq 1 ]; then
  383.                                 if [ $statusb -gt 2 ]; then
  384.                                     b="\033[1;37mPartially loaded\033[0;40m"
  385.                                 elif [ $statusb -le 2 ]; then
  386.                                     b="\033[1;35mLoading\033[0;40m"
  387.                                 fi
  388.                             else
  389.                                 if [ $statusbp -eq 1 ]; then
  390.                                     b="\033[1;36mQueued\033[0;40m"
  391.                                 else
  392.                                     b="\033[1;37mEmpty\033[0;40m"
  393.                                 fi
  394.                             fi
  395.                         elif [ $statusbbb -eq 1 ]; then
  396.                             b="\033[1;37mFully loaded\033[0;40m"
  397.                         fi
  398.                        
  399.                         if [ -f ./$name.cidr ]; then
  400.                             cat ./$name.cidr 2>/dev/null | cut -d" " -f3 | grep -E "^1.1.1.1$" > /dev/null && c="\033[1;37mFully loaded\033[0;40m" || c="\033[1;37mPartially loaded\033[0;40m"
  401.                         else
  402.                             c="\033[1;37mEmpty\033[0;40m"
  403.                         fi
  404.  
  405.                           d=`echo $(( $age / 86400 ))`
  406.                           h=`echo $((( $age / 3600 ) %24 ))`
  407.                           m=`echo $((( $age / 60 ) %60 ))`
  408.                           s=`echo $(( $age %60 ))`
  409.                         age=`printf "$d - %02d:%02d:%02d\n" $h $m $s`
  410.                        ipta=`cat ./iptables-add | grep $name | wc -l`
  411.                        iptb=`iptables -L | grep $name | wc -l`
  412.                         if [ `echo $(( ipta + iptb ))` -eq 4 ]; then d="\033[1;32mFully loaded\033[0;40m";
  413.                         elif [ `echo $(( ipta + iptb ))` -eq 0 ]; then d="\033[1;37mEmpty\033[0;40m";
  414.                         else "\033[1;33mPartially loaded\033[0;40m";
  415.                         fi
  416. echo -e "| Primary lists and iptables are used for filtering, they are both
  417. | expected to be Fully Loaded while P2Partisan operates.
  418. | Secondary lists are used for updates only, so empty when unused
  419. | cidr file are created after a list update and allow quick startup
  420. +---------------------------------------------------------------+
  421. |           Name: $name
  422. |            URL: `cat blacklists | grep -Ev "^#|^$" | tr -d "\r" | grep $name | awk '{print $2}'`
  423. +---------------------------------------------------------------+
  424. |  ipset primary: $a
  425. |          items: `ipset -L $name 2> /dev/null | tail -n +8 | wc -l || echo 0`
  426. |    size in RAM: $sizem KB
  427. +---------------------------------------------------------------+
  428. | ipset seconday: $b
  429. |          items: `ipset -L $name.bro 2> /dev/null | tail -n +8 | wc -l || echo 0`
  430. |    size in RAM: $sizemm KB
  431. +---------------------------------------------------------------+
  432. |      cidr file: $c
  433. |          items: `cat $name.cidr 2> /dev/null | tail -n +2 | wc -l || echo 0`
  434. |   size on disk: `ls -lh $name.cidr 2> /dev/null | awk '{print $5}' || echo 0`
  435. |   Last updated: `date -r $name.cidr '+%H:%M:%S %d/%b/%y' 2> /dev/null` | \033[1;37m$age\033[0;40m ago
  436. +---------------------------------------------------------------+
  437. |       iptables: $d
  438. `cat ./iptables-add | grep $name`
  439. `iptables -L | grep $name`
  440. +---------------------------------------------------------------+\033[0;39m
  441. "
  442.  
  443. exit
  444. fi
  445.  
  446.         counter=0
  447.         running3=`iptables -L | grep -v Chain| grep 'P2PARTISAN-IN\|P2PARTISAN-OUT'  2> /dev/null | wc -l`
  448.         running4=`[ -f $pidfile ] && echo 1 || echo 0`
  449.         running5=`nvram get script_fire | grep "p2partisan.sh restart" >/dev/null && echo "\033[1;32mYes\033[0;40m" || echo "\033[1;31mNo\033[0;40m"`
  450.         running7=`tail -200 $logfile | grep Dropped | tail -1 | awk '{printf "| %s %s %s ",$1,$2,$3;for (i=4;i<=NF;i++) if ($i~/(IN|OUT|SRC|DST|PROTO|SPT|DPT)=/) printf "%s ",$i;print ""}'| sed -e 's/PROTO=//g' -e 's/IN=/I=/g' -e 's/OUT=/O=/g' -e 's/SPT=/S=/g' -e 's/DPT=/D=/g' -e 's/SRC=/S=/g' -e 's/DST=/D=/g'`
  451.        running7a=`tail -200 $logfile | grep Rejected | tail -1 | awk '{printf "| %s %s %s ",$1,$2,$3;for (i=4;i<=NF;i++) if ($i~/(IN|OUT|SRC|DST|PROTO|SPT|DPT)=/) printf "%s ",$i;print ""}'| sed -e 's/PROTO=//g' -e 's/IN=/I=/g' -e 's/OUT=/O=/g' -e 's/SPT=/S=/g' -e 's/DPT=/D=/g' -e 's/SRC=/S=/g' -e 's/DST=/D=/g'`
  452.         running9=`nvram get script_fire | grep "P2Partisan-tutor" >/dev/null && echo "\033[1;32mYes\033[0;40m" || echo "\033[1;31mNo\033[0;40m"`
  453.         logwin=`echo $(( $now - 86400 ))`
  454.         tail -1500 $logfile | grep -i "P2Partisan tutor had" > /tmp/tutor.tmp
  455.          [ -f /tmp/tutor.temp ] && {
  456.          cat /tmp/tutor.tmp |
  457.          (  
  458.          while read line
  459.          do
  460.                 logtime=`echo $line | awk '{print $3}'`
  461.                 if [[ `date -d"$logtime" +%s` -gt $logwin ]]; then
  462.                     echo $line >> /tmp/tutor.temp  
  463.                 fi
  464.         done
  465.         )
  466.             }
  467.         runningB=`wc -l /tmp/tutor.temp 2> /dev/null | awk '{print $1}'`
  468.         [ -f /tmp/tutor.tmp ] && rm /tmp/tutor.tmp; [ -f /tmp/tutor.temp ] && rm /tmp/tutor.temp || runningB=0
  469.         runningD=`[ -f ./runtime ] && cat ./runtime`
  470.         runningF=`iptables -L P2PARTISAN-DROP-IN 2> /dev/null | grep DEBUG | wc -l`
  471.             from=`[ -f ./iptables-add ] && head -1 ./iptables-add 2> /dev/null | awk '{print $2}' || echo $now`
  472.          runtime=`echo $(( $now - $from ))`
  473.                d=`echo $(( $runtime / 86400 ))`
  474.                h=`echo $((( $runtime / 3600 ) %24 ))`
  475.                m=`echo $((( $runtime / 60 ) %60 ))`
  476.                s=`echo $(( $runtime %60 ))`
  477.         runtime=`printf "$d\0d - %02d:%02d:%02d\n" $h $m $s`
  478.         drop_packet_count_in=`iptables -vL P2PARTISAN-DROP-IN 2> /dev/null | grep " DROP " | awk '{print $1}'`
  479.        drop_packet_count_out=`iptables -vL P2PARTISAN-DROP-OUT 2> /dev/null | grep " REJECT " | awk '{print $1}'`
  480.                         if [ -e ./iptables-debug-del ]; then
  481.           dfrom=`[ -f ./iptables-debug ] && head -1 ./iptables-debug 2> /dev/null | awk '{print $2}'`
  482.            druntime=`echo $(( $now - $dfrom ))`
  483.                           h=`echo $((( $druntime / 3600 ) %24 ))`
  484.                           m=`echo $((( $druntime / 60 ) %60 ))`
  485.                           s=`echo $(( $druntime %60 ))`
  486.            druntime=`printf "%02d:%02d:%02d\n" $h $m $s`
  487.            dendtime=`[ -f ./iptables-debug-del ] && head -2 ./iptables-debug-del | tail -n 1 | awk '{print $2}'`
  488.                   ttime=`echo $(( $dendtime / 60 ))`
  489.                   ttime=`echo $(( $dfrom + $dendtime ))`
  490.                 leftime=`echo $(( $ttime - $now ))`
  491.                           m=`echo $((( $leftime / 60 ) %60 ))`
  492.                           s=`echo $(( $leftime %60 ))`
  493.                 leftime=`printf "%02d:%02d:%02d\n" $h $m $s`
  494.                 zzztime=`echo $(( $dendtime / 60 ))`
  495.                         fi
  496.            
  497.         if [[ $running3 -eq "0" ]] && [[ $running4 -eq "0" ]]; then
  498.                 running8="\033[1;31mNo\033[0;40m"
  499.         elif [[ $running3 -eq "0" ]] && [[ $running4 -eq "1" ]]; then
  500.                 running8="\033[1;35mLoading...\033[0;40m"
  501.         elif [[ $running3 -lt "4" ]] && [[ $running4 -eq "0" ]]; then
  502.                 running8="\033[1;31mNot quite... try to run \"p2partisan.sh update\"\033[0;40m"
  503.         elif [[ $running3 -eq "4" ]] && [[ $running4 -eq "1" ]]; then
  504.                 running8="\033[1;32mYes\033[0;40m"
  505.         fi
  506.                
  507.                 if [[ $runningF -eq 1 ]]; then
  508.                                 runningF="\033[1;35mOn\033[0;40m IP \033[1;33m`iptables -L P2PARTISAN-DROP-IN  2> /dev/null | grep DEBUG |  awk '{print $5}'` \033[1;33m$f\033[0;40mrunning for \033[1;33m$druntime\033[0;40m /\033[1;33m$zzztime\033[0;40m min (\033[1;33m$leftime\033[0;40m left)"
  509.                 elif [[ $runningF -gt 1 ]]; then
  510.                                 runningF="\033[1;35mOn - reverse \033[0;40m(entire LAN except port \033[1;33m`iptables -L P2PARTISAN-DROP-IN  2> /dev/null | grep DEBUG | head -1 |  awk '{print $7}' | cut -f2 -d!`) \033[1;33m$f\033[0;40mrunning for \033[1;33m$druntime\033[0;40m /\033[1;33m$zzztime\033[0;40m min (\033[1;33m$leftime\033[0;40m left)"
  511.                 else
  512.                                 runningF="Off"        
  513.                 fi
  514.  
  515. whiteip=`ipset -L whitelist 2> /dev/null | grep -E "(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])" | wc -l`
  516. whiteextra=`ipset -L whitelist 2> /dev/null | grep -E '(^10\.|(^172\.1[6-9]\.|^172\.2[0-9]\.|^172\.3[0-1]\.)|^192\.168\.)' | wc -l`
  517.  
  518. if [[ $whiteextra == "0" ]]; then
  519.     whiteextra=" "
  520. else
  521.     whiteextra=`echo "/ $whiteextra" LAN IP ref defined`
  522. fi
  523.     blackip=`ipset -L blacklist-custom 2> /dev/null | grep -E "(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])" | wc -l`
  524.     greyip=`ipset -L greylist 2> /dev/null | grep -E "(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])" | wc -l`
  525.  
  526. echo -e "\e[40m
  527. +------------------------- P2Partisan --------------------------+
  528. |            _______ __          __              
  529. |           |     __|  |_.---.-.|  |_.--.--.-----.
  530. |           |__     |   _|  _  ||   _|  |  |__ --|
  531. |           |_______|____|___._||____|_____|_____|
  532. |  
  533. | Release version:  \033[1;40m$version\033[0;40m
  534. +---------------------------------------------------------------+
  535. |         Running:  $running8
  536. |         Autorun:  $running5
  537. |           Tutor:  $running9 / \033[1;37m$runningB\033[0;40m problems in the last 24h
  538. |        Debugger:  $runningF
  539. | Partisan uptime:  \033[1;37m$runtime\033[0;40m
  540. |    Startup time:  \033[1;37m$runningD\033[0;40m seconds
  541. |      Dropped in:  \033[1;37m$drop_packet_count_in\033[0;40m
  542. |    Rejected out:  \033[1;37m$drop_packet_count_out\033[0;40m
  543. +---------------------------------------------------------------+"
  544. echo -e "|       Black IPs:  \033[1;37m$blackip\033[0;40m"
  545. echo -e "|        Grey IPs:  \033[1;37m$greyip\033[0;40m"
  546. echo -e "|       White IPs:  \033[1;37m$whiteip $whiteextra\033[0;40m"
  547. transmissionenable=`nvram get bt_enable`
  548. if [ -z $transmissionenable ]; then
  549.     echo "|  TransmissionBT:  Not available"
  550.     elif [ $transmissionenable -eq 0 ]; then
  551.     echo "|  TransmissionBT:  Off"
  552.     else
  553.     echo -e "|  TransmissionBT:  \033[1;32mOn\033[0;40m"
  554.         transmissionport=`nvram get bt_port 2> /dev/null`
  555.         greyports_tcp=$greyports_tcp,$transmissionport
  556.         greyports_udp=$greyports_udp,$transmissionport
  557. fi
  558. echo $greyports_tcp | awk -v RS=',' -F : '{ gsub(/\n$/, "") } NF > 1 { r=(r ? r "," : "") $0; if (r ~ /([^,]*,){6}/) { print r; r=""; } next } { s=(s ? s "," : "") $0; if (s ~ /([^,]*,){14}/) { print s; s=""; } }  END { if (r && s) { p = r "," s; if (p !~ /([^,:]*[:,]){15}/) { print p; r=s="" } } if (r) print r ; if (s) print s }' | while read w; do
  559.             echo -e "|  Grey ports TCP:  \033[1;37m$w\033[0;40m"
  560.                 done
  561. echo $greyports_udp | awk -v RS=',' -F : '{ gsub(/\n$/, "") } NF > 1 { r=(r ? r "," : "") $0; if (r ~ /([^,]*,){6}/) { print r; r=""; } next } { s=(s ? s "," : "") $0; if (s ~ /([^,]*,){14}/) { print s; s=""; } }  END { if (r && s) { p = r "," s; if (p !~ /([^,:]*[:,]){15}/) { print p; r=s="" } } if (r) print r ; if (s) print s }' | while read w; do
  562.             echo -e "|  Grey ports UDP:  \033[1;37m$w\033[0;40m"
  563.                 done
  564. echo $whiteports_tcp | awk -v RS=',' -F : '{ gsub(/\n$/, "") } NF > 1 { r=(r ? r "," : "") $0; if (r ~ /([^,]*,){6}/) { print r; r=""; } next } { s=(s ? s "," : "") $0; if (s ~ /([^,]*,){14}/) { print s; s=""; } }  END { if (r && s) { p = r "," s; if (p !~ /([^,:]*[:,]){15}/) { print p; r=s="" } } if (r) print r ; if (s) print s }' | while read w; do
  565.             echo -e "| White ports TCP:  \033[1;37m$w\033[0;40m"
  566.                 done
  567. echo $whiteports_udp | awk -v RS=',' -F : '{ gsub(/\n$/, "") } NF > 1 { r=(r ? r "," : "") $0; if (r ~ /([^,]*,){6}/) { print r; r=""; } next } { s=(s ? s "," : "") $0; if (s ~ /([^,]*,){14}/) { print s; s=""; } }  END { if (r && s) { p = r "," s; if (p !~ /([^,:]*[:,]){15}/) { print p; r=s="" } } if (r) print r ; if (s) print s }' | while read w; do
  568.             ColorOff='\\\e[0;40m'
  569.             ColorOn='\\\e[1;37m'
  570.             BWhite='\\\e[100m'
  571.             p1=`head -70 ./p2partisan.sh | grep -E ^whiteports_udp= | grep -Eo '[,|:|=]67[,|:]|,67$' | wc -l`
  572.             p2=`head -70 ./p2partisan.sh | grep -E ^whiteports_udp= | grep -Eo '[,|:|=]68[,|:]|,68$' | wc -l`
  573.             if [ $p1 -eq "0" ]; then
  574.                     w=`echo -e $w | sed -e "s/^67,/${BWhite}67${ColorOn},/g" | sed -e "s/,67,/,${BWhite}67${ColorOff}${ColorOn},/g" | sed -e "s/,67$/,${BWhite}67/g"`
  575.             fi
  576.             if [ $p2 -eq "0" ]; then
  577.                     w=`echo -e $w | sed -e "s/^68,/${BWhite}68${ColorOn},/g" | sed -e "s/,68,/,${BWhite}68${ColorOff}${ColorOn},/g" | sed -e "s/,68$/,${BWhite}68/g"`
  578.             fi
  579.             echo -e "| White ports UDP:  \033[1;37m$w\033[0;40m"
  580.                 done
  581. cat blacklists | grep -Ev "^#|^$" | tr -d "\r" |
  582.    (
  583.     while read line
  584.     do
  585.             counter=`expr $counter + 1`
  586.             counter=$(printf "%02d" $counter)
  587.             name=`echo $line | awk '{print $1}'`
  588.             statusa=`cat /tmp/p2partisan.$name.LOAD 2> /dev/null || echo 5`
  589.             statusb=`cat /tmp/p2partisan.$name.bro.LOAD 2> /dev/null || echo 5`
  590.             statusap=`ps w | grep $name | grep -v grep | wc -l`
  591.             statusbp=`ps w | grep $name.bro | grep -v grep | wc -l`
  592.             statusaa=`ipset -L $name 2> /dev/null | head -8 | tail -1 | grep -Eo "^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]).*" > /dev/null && echo "1" || echo "0"`
  593.             statusbb=`ipset -L $name.bro 2> /dev/null | head -8 | tail -1 | grep -Eo "^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]).*" > /dev/null && echo "1" || echo "0"`
  594.             statusaaa=`ipset -T $name 1.1.1.1 2> /dev/null && echo "1" || echo "0"`
  595.             statusbbb=`ipset -T $name.bro 1.1.1.1 2> /dev/null && echo "1" || echo "0"`
  596.             sizeb=`ipset -L $name 2> /dev/null | head -5 | tail -1 | awk '{print $4}' || echo=0`
  597.             sizebb=`ipset -L $name.bro 2> /dev/null | head -5 | tail -1 | awk '{print $4}' || echo=0`
  598.             sizem=`echo $((sizeb/1024))`
  599.             sizem=$(printf "%04s" $sizem)
  600.             sizemm=`echo $((sizebb/1024))`
  601.             lin=`iptables -L P2PARTISAN-LISTS-IN 2> /dev/null | grep $name | wc -l`
  602.             lout=`iptables -L P2PARTISAN-LISTS-OUT 2> /dev/null | grep $name | wc -l`
  603.             ipt=`echo $((lin + lout))`
  604.             if [ $ipt -eq 2 ]; then
  605.                 i="\033[1;32mo\033[0;40m"
  606.             elif [ $ipt -eq 1 ]; then
  607.                 i="\033[1;33mp\033[0;40m"          
  608.             else
  609.                 i="\033[1;31me\033[0;40m"          
  610.             fi
  611.  
  612.             if [ $statusaaa -eq 0 ]; then
  613.                             if [ $statusaa -eq 1 ]; then
  614.                                 if [ $statusa -gt 2 ]; then
  615.                                     a="\033[1;33mp\033[0;40m"
  616.                                 elif [ $statusa -le 2 ]; then
  617.                                     a="\033[1;35ml\033[0;40m"
  618.                                 fi
  619.                             else
  620.                                 if [ $statusap -eq 1 ]; then
  621.                                     a="\033[1;36mq\033[0;40m"
  622.                                 else
  623.                                     a="\033[1;31me\033[0;40m"
  624.                                 fi
  625.                             fi
  626.                         elif [ $statusaaa -eq 1 ]; then
  627.                             a="\033[1;32mo\033[0;40m"
  628.                         fi
  629.                        
  630.                         if [ $statusbbb -eq 0 ]; then
  631.                             if [ $statusbb -eq 1 ]; then
  632.                                 if [ $statusb -gt 2 ]; then
  633.                                     b="\033[1;37mp\033[0;40m"
  634.                                 elif [ $statusb -le 2 ]; then
  635.                                     b="\033[1;35ml\033[0;40m"
  636.                                 fi
  637.                             else
  638.                                 if [ $statusbp -eq 1 ]; then
  639.                                     b="\033[1;36mq\033[0;40m"
  640.                                 else
  641.                                     b="\033[1;37me\033[0;40m"
  642.                                 fi
  643.                             fi
  644.                         elif [ $statusbbb -eq 1 ]; then
  645.                             b="\033[1;37mo\033[0;40m"
  646.                         fi
  647.                        
  648.                         if [ -f ./$name.cidr ];then
  649.                             cat ./$name.cidr | cut -d" " -f3 | grep -E "^1.1.1.1$" > /dev/null &&
  650.                             {
  651.                             age=`[ -e $name.cidr ] && echo $((\`date +%s\` - \`date -r $name.cidr +%s\`)) || echo 0`
  652.                             d=`echo $(( $age / 86400 ))`
  653.                                 if [[ $d -eq 7 ]]; then
  654.                                     c="\033[1;33mo\033[0;40m"
  655.                                 elif [[ $d -ge 8 ]]; then
  656.                                     c="\033[1;31mo\033[0;40m"
  657.                                 else
  658.                                     c="\033[1;37mo\033[0;40m"
  659.                           fi
  660.                             } || c="\033[1;37mp\033[0;40m"
  661.                         else
  662.                             c="\033[1;37me\033[0;40m"
  663.                         fi
  664.                        
  665.                 echo -e "|    Blacklist_$counter:  [$a] [$b] [$c] [$i] - $sizem KB - \033[1;37m$name\033[0;40m"
  666.  
  667.                         sizeram=`echo $((sizeram+sizeb+sizebb))`                      
  668.         done
  669.                         sizeram=`echo $((sizeram/1024))`
  670.                 echo  "|                    ^   ^   ^   ^"      
  671.              echo  -e "|      maxload: \033[1;37m$maxconcurrentlistload\033[0;40m - \e[1;37;100mpri sec cid ipt\033[0;40m - [\033[1;37me\033[0;40m]mpty [\033[1;37ml\033[0;40m]oading l[\033[1;37mo\033[0;40m]aded [\033[1;37mp\033[0;40m]artial [\033[1;37mq\033[0;40m]ueued"  
  672.              echo  -e "|    Consumed RAM:  \033[1;37m$sizeram\033[0;40m KB"
  673.         )
  674.  
  675. echo -e "+----------------------- Logs max($maxloghour/hour) ----------------------+      
  676. $running7
  677. $running7a
  678. +---------------------------------------------------------------+\033[0;39m"
  679. }
  680.  
  681. if [ $autorun_availability_check = 1 ]; then
  682. av="while true; do [ -f $P2Partisandir/p2partisan.sh ] && break || sleep 5; done ;"
  683. fi
  684.  
  685. pautorunset() {
  686. echo -e "\033[0;40m
  687. +------------------------- P2Partisan --------------------------+
  688. |            ______               __               __
  689. |           |      |.-----.-----.|  |_.----.-----.|  |
  690. |           |   ---||  _  |     ||   _|   _|  _  ||  |
  691. |           |______||_____|__|__||____|__| |_____||__|
  692. |                                                  
  693. +--------------------------- Autorun ---------------------------+"
  694.         p=`nvram get script_fire | grep "p2partisan.sh restart" | grep -v cru | wc -l`
  695.         if [ $p -eq "0" ] ; then
  696.                 t=`nvram get script_fire`; t=`printf "$t\n$av$P2Partisandir/p2partisan.sh restart\n"` ; nvram set "script_fire=$t"
  697.         fi
  698.         plog "P2Partisan AUTO RUN is ON"
  699.                 echo -e "+---------------------------------------------------------------+\033[0;39m"
  700.         nvram commit
  701. }
  702.  
  703. pautorununset() {
  704. echo -e "\033[0;40m
  705. +------------------------- P2Partisan --------------------------+
  706. |            ______               __               __
  707. |           |      |.-----.-----.|  |_.----.-----.|  |
  708. |           |   ---||  _  |     ||   _|   _|  _  ||  |
  709. |           |______||_____|__|__||____|__| |_____||__|
  710. |                                                  
  711. +--------------------------- Autorun ---------------------------+"
  712.         p=`nvram get script_fire | grep "p2partisan.sh restart" | grep -v cru | wc -l`
  713.         if [ $p -eq "1" ]; then
  714.         t=`nvram get script_fire`; t=`printf "$t" | grep -v "p2partisan.sh restart"` ; nvram set "script_fire=$t"
  715.         fi
  716.         plog "P2Partisan AUTO RUN is OFF"
  717.                 echo -e "+---------------------------------------------------------------+\033[0;39m"
  718.         nvram commit
  719. }
  720.  
  721. pdetective() {
  722. echo -e "\033[0;40m
  723. +------------------------- P2Partisan --------------------------+
  724. |         __         __               __   __              
  725. |     .--|  |.-----.|  |_.-----.----.|  |_|__|.--.--.-----.
  726. |     |  _  ||  -__||   _|  -__|  __||   _|  ||  |  |  -__|
  727. |     |_____||_____||____|_____|____||____|__| \___/|_____| BETA
  728. |
  729. +---------------------------------------------------------------+
  730. | After an investigation it appears that the following socket/s
  731. | should be considered a greyports candidates. Consider re-run the
  732. | command multiple times to reduce the number of false positive. Once
  733. | identified the port/s can be added under greyports_tcp & greyports_udp.
  734. +---------------------------------------------------------------+"
  735. cat /proc/net/ip_conntrack | awk '{for (i=1;i<=NF;i++) if ($i~/(src|dst|sport|dport)=/) printf "%s ",$i;print "\n"}' | grep -vE '^$' | sed s/\ src=/'\n'/ | awk '{print $1" "$3" "$2" "$4}' | sed s/\ dst=/'\n'/ | sed s/sport=//  | sed s/dport=// | grep -E '(^10\.|(^172\.1[6-9]\.|^172\.2[0-9]\.|^172\.3[0-1]\.)|^192\.168\.)' | grep -v "`nvram get lan_ipaddr`$" | grep -v "`nvram get lan1_ipaddr`$" | awk '/[0-9]/ {cnt[$1" "$2]++}END{for(k in cnt) print cnt[k],k}' | sort -nr | while read socket; do echo $socket | if [ `cut -f1 -d" "` -gt $greyline ];then echo $socket | awk '{print "| "$2" "$3" - "$1" Sessions"}'; fi ; done
  736. echo -e "+---------------------------------------------------------------+\033[0;39m"
  737. }
  738.  
  739. pupgrade() {
  740.         [ -f p2partisan_new.sh ] && rm -f "p2partisan_new.sh" 2> /dev/null
  741.         wget -q -O - http://pastebin.com/raw.php?i=mUeS6jP2 | grep "p2partisan v" | grep -v grep> ./latest
  742.         latest=`cat ./latest | cut -c3-31`
  743.         current=`cat ./p2partisan.sh | grep "p2partisan v" | head -1 | cut -c3-32 `
  744.         if [[ "$latest" == "$current" ]]; then
  745.         echo -e "\033[0;40m
  746. +------------------------- P2Partisan --------------------------+
  747. |          _______                            __        
  748. |         |   |   |.-----.-----.----.---.-.--|  |.-----.
  749. |         |   |   ||  _  |  _  |   _|  _  |  _  ||  -__|
  750. |         |_______||   __|___  |__| |___._|_____||_____|
  751. |                  |__|  |_____|                        
  752. |
  753. +---------------------------------------------------------------+
  754. You're already running the latest version of P2Partisan
  755. \033[0;39m"
  756.         else
  757.         echo -e "\033[0;40m
  758. +------------------------- P2Partisan --------------------------+
  759. |          _______                            __        
  760. |         |   |   |.-----.-----.----.---.-.--|  |.-----.
  761. |         |   |   ||  _  |  _  |   _|  _  |  _  ||  -__|
  762. |         |_______||   __|___  |__| |___._|_____||_____|
  763. |                  |__|  |_____|                        
  764. |
  765. +---------------------------------------------------------------+
  766. | There's a new P2Partisan update available. Do you want to upgrade?
  767. |  
  768. |                  current = $current
  769. |  
  770. |                          to
  771. |                      
  772. |                   latest = $latest
  773. |
  774. | y/n"
  775.         read answer
  776.                 if [[ $answer == "y" ]]; then
  777. wget -q -O ./p2partisan_new.sh http://pastebin.com/raw.php?i=mUeS6jP2
  778. pupgraderoutine
  779.                 else
  780.                 echo -e "| Upgrade skipped. Quitting...
  781. +---------------------------------------------------------------+\033[0;39m"
  782.                 exit
  783.                 fi
  784.        
  785.         fi
  786.  }
  787.  
  788. pupgradebeta() {
  789.         [ -f p2partisan_new.sh ] && rm -f "p2partisan_new.sh" 2> /dev/null
  790.         wget -q -O - http://pastebin.com/raw.php?i=Lt1axJ9a | grep "p2partisan v" | grep -v grep > ./latest
  791.         echo "| Do you want to install the latest testing beta (not suggested)?
  792. |
  793. | y/n"
  794.         read answer
  795.                 if [[ $answer == "y" ]]; then
  796. wget -q -O ./p2partisan_new.sh http://pastebin.com/raw.php?i=Lt1axJ9a
  797. pupgraderoutine
  798.                 else
  799.                 echo -e "| Beta upgrade skipped. Quitting...
  800. +---------------------------------------------------------------+\033[0;39m"
  801.                                
  802.                 exit
  803.                 fi
  804.  }
  805.  
  806. pupgraderoutine() {
  807.                 echo -e "\033[0;40m| Upgrading, please wait:"
  808.                 echo -e "\033[0;40m| 1/6) Stopping the script"
  809.                                 pforcestop
  810.                 [ -f p2partisan_new.sh ] || plog "There's a problem with the p2partisan upgrade. Please try again"
  811.                 echo -e "\033[0;40m| 2/6) Migrating the configuration"
  812.                 sed '1,/P2Partisandir/{s@P2Partisandir=.*@'"P2Partisandir=$P2Partisandir"'@'} -i ./p2partisan_new.sh
  813.                 sed '1,/syslogs/{s@syslogs=.*@'"syslogs=$syslogs"'@'} -i ./p2partisan_new.sh
  814.                 sed '1,/maxloghour/{s@maxloghour=.*@'"maxloghour=$maxloghour"'@'} -i ./p2partisan_new.sh
  815.                 sed '1,/whiteports_tcp/{s@whiteports_tcp=.*@'"whiteports_tcp=$whiteports_tcp"'@'} -i ./p2partisan_new.sh
  816.                 sed '1,/whiteports_udp/{s@whiteports_udp=.*@'"whiteports_udp=$whiteports_udp"'@'} -i ./p2partisan_new.sh
  817.                 sed '1,/greyports_tcp/{s@greyports_tcp=.*@'"greyports_tcp=$greyports_tcp"'@'} -i ./p2partisan_new.sh
  818.                 sed '1,/greyports_udp/{s@greyports_udp=.*@'"greyports_udp=$greyports_udp"'@'} -i ./p2partisan_new.sh
  819.                 sed '1,/greyline/{s@greyline=.*@'"greyline=$greyline"'@'} -i ./p2partisan_new.sh
  820.                 sed '1,/scheduleupdates/{s@scheduleupdates=.*@'"scheduleupdates=\"$scheduleupdates\""'@'} -i ./p2partisan_new.sh
  821.                 sed '1,/maxconcurrentlistload/{s@maxconcurrentlistload=.*@'"maxconcurrentlistload=$maxconcurrentlistload"'@'} -i ./p2partisan_new.sh
  822.                 sed '1,/autorun_availability_check/{s@autorun_availability_check=.*@'"autorun_availability_check=$autorun_availability_check"'@'} -i ./p2partisan_new.sh
  823.                 sed '1,/testip/{s@testip=.*@'"testip=$testip"'@'} -i ./p2partisan_new.sh              
  824.                 tr -d "\r"< ./p2partisan_new.sh > ./.temp ; mv ./.temp ./p2partisan_new.sh
  825.                 echo -e "\033[0;40m| 3/6) Copying p2partisan.sh into p2partisan.sh.old"
  826.                 cp ./p2partisan.sh ./p2partisan_old
  827.                 echo -e "\033[0;40m| 4/6) Installing new script into p2partisan.sh"
  828.                 mv ./p2partisan_new.sh ./p2partisan.sh
  829.                 echo -e "\033[0;40m| 5/6) Setting up permissions"
  830.                 chmod -R 777 ./p2partisan.sh
  831.                 echo -e "\033[0;40m| 6/6) all done, \033[1;32mPlease run the script manually!\033[0;40m
  832. | NOTE: autorun setting is left as it was found
  833. +---------------------------------------------------------------+
  834. \033[0;39m"
  835. exit
  836. }
  837.  
  838. ptutor() {
  839.         h=`date +%H`
  840.         pwhitelist
  841.         pgreylist
  842.         pblacklistcustom
  843.         running3=`iptables -L | grep -v Chain| grep 'P2PARTISAN-IN\|P2PARTISAN-OUT'  2> /dev/null | wc -l`
  844.         running4=`[ -f $pidfile ] && echo 1 || echo 0`
  845.         runningE=`iptables -L wanin | grep P2PARTISAN-IN  2> /dev/null | wc -l`
  846.          schfrom=`echo $scheduleupdates | cut -d, -f1`
  847.            schto=`echo $scheduleupdates | cut -d, -f2`
  848.  
  849.         cat blacklists |  grep -Ev "^#|^$" | tr -d "\r" |
  850.            (
  851.             while read line
  852.             do
  853.                     name=`echo $line | awk '{print $1}'`
  854.                     statusbbb=`ipset -T $name.bro 1.1.1.1 2> /dev/null && echo 1 || echo 0`
  855.                     iptables -L P2PARTISAN-LISTS-IN | grep $name > /dev/null || {
  856.                         plog "P2Partisan tutor had to reinstall the iptables due to: P2PARTISAN-LIST-IN $name instruction missing"
  857.                         ./iptables-del ; ./iptables-add
  858.                         exit
  859.                         }
  860.                     iptables -L P2PARTISAN-LISTS-OUT | grep $name  > /dev/null || {
  861.                         plog "P2Partisan tutor had to reinstall the iptables due to: P2PARTISAN-LIST-OUT $name instruction missing"
  862.                         ./iptables-del ; ./iptables-add
  863.                         exit
  864.                         }
  865.                 age=`echo $((\`date +%s\` - \`date -r $name.cidr +%s\`))`
  866.                 if [[ $age -gt "604800" ]] && [[ $h -ge $schfrom ]] && [[ $h -le $schto ]]; then
  867.                     plog "P2Partisan is updating list $name"
  868.                     pforcestop $name
  869.                     exit
  870.                 fi
  871.                 if [[ $age -gt "300" ]] && [[ $statusbbb -eq 1 ]]; then
  872.                     plog "P2Partisan is clearing the $name secondary list"
  873.                     ipset -F $name.bro
  874.                 fi
  875.             done
  876.             )
  877.                 if [[ $runningE -gt "1" ]]; then
  878.                         pforcestop
  879.                         plog "P2Partisan tutor had to restart due to: iptables redundant rules found"
  880.                         pstart
  881.                 elif [[ $running3 -eq "4" ]] && [[ $running4 -eq "0" ]]; then
  882.                         plog "P2Partisan tutor had to restart due to: pid file missing"
  883.                         pforcestop
  884.                         pstart
  885.                 # elif [[ $running3 -eq "0" ]] && [[ $running4 -eq "1" ]]; then
  886.                         # plog "P2Partisan tutor had to restart due to: iptables instructions missing"
  887.                         # pforcestop
  888.                         # pstart        
  889.                 elif [[ $running3 -ne "4" ]] && [[ $running4 -eq "1" ]]; then
  890.                         plog "P2Partisan might be loading, I'll wait 10 seconds..."    
  891.                         sleep 10
  892.                     if [[ $running3 -ne "4" ]] && [[ $running4 -eq "1" ]]; then
  893.                             plog "P2Partisan tutor had to restart due to iptables instruction missing"
  894.                             pforcestop
  895.                             pstart
  896.                     fi
  897.                 else
  898.                     echo -e "\033[0;40m
  899. +------------------------- P2Partisan --------------------------+
  900. |                _______         __              
  901. |               |_     _|.--.--.|  |_.-----.----.
  902. |                 |   |  |  |  ||   _|  _  |   _|
  903. |                 |___|  |_____||____|_____|__|                                                  
  904. |
  905. +---------------------------------------------------------------+              
  906. | P2Partisan up and running. The tutor is happy
  907. +---------------------------------------------------------------+\033[0;39m"
  908.         fi
  909. }
  910.  
  911. ptutorset() {
  912.         echo -e "\033[0;40m
  913. +------------------------- P2Partisan --------------------------+
  914. |                _______         __              
  915. |               |_     _|.--.--.|  |_.-----.----.
  916. |                 |   |  |  |  ||   _|  _  |   _|
  917. |                 |___|  |_____||____|_____|__|                                                  
  918. |
  919. +-------------------------- Scheduler --------------------------+"
  920.         cru d P2Partisan-tutor
  921.         ab=`tr -cd 0-5 </dev/urandom | head -c 1`
  922.         a=`tr -cd 0-9 </dev/urandom | head -c 1`
  923.         a=`echo $ab$a`
  924.         scheduleme=`echo "$a * * * *"`
  925.         cru a P2Partisan-tutor "$scheduleme $P2Partisandir/p2partisan.sh tutor"
  926.         p=`nvram get script_fire | grep "cru a P2Partisan-tutor" | wc -l`
  927.         if [ $p -eq "0" ] ; then
  928.                 t=`nvram get script_fire`; t=`printf "$t\ncru a P2Partisan-tutor \"$scheduleme $P2Partisandir/p2partisan.sh tutor\"\n"` ; nvram set "script_fire=$t"
  929.         fi
  930.         plog "P2Partisan tutor is ON"
  931.                 echo -e "+---------------------------------------------------------------+\033[0;39m"
  932.         nvram commit
  933. }
  934.  
  935. ptutorunset() {
  936.         echo -e "\033[0;40m
  937. +------------------------- P2Partisan --------------------------+
  938. |                _______         __              
  939. |               |_     _|.--.--.|  |_.-----.----.
  940. |                 |   |  |  |  ||   _|  _  |   _|
  941. |                 |___|  |_____||____|_____|__|                                                  
  942. |
  943. +-------------------------- Scheduler --------------------------+"
  944.         cru d P2Partisan-tutor
  945.         p=`nvram get script_fire | grep "cru a P2Partisan-tutor" | wc -l`
  946.         if [ $p -eq "1" ] ; then
  947.         t=`nvram get script_fire`; t=`printf "$t\ncru a P2Partisan-tutor \"$schedule $P2Partisandir/p2partisan.sh tutor\"\n" | grep -v "cru a P2Partisan-tutor"` ; nvram set "script_fire=$t"
  948.         fi
  949.         plog "P2Partisan tutor is OFF"
  950.                 echo -e "+---------------------------------------------------------------+\033[0;39m"
  951.         nvram commit
  952.  }
  953.  
  954.  ptest() {
  955. checklist="blacklist-custom greylist whitelist `cat blacklists | grep -Ev "^#|^$" | tr -d "\r" | awk '{print $1}'`"
  956. echo -e "\033[0;40m
  957. +------------------------- P2Partisan --------------------------+
  958. |                  _______               __  
  959. |                 |_     _|.-----.-----.|  |_
  960. |                   |   |  |  -__|__ --||   _|
  961. |                   |___|  |_____|_____||____|
  962. |                                              
  963. +----------- Lists are sorted in order of precedence -----------+"
  964.         if [[ -z $1 ]]; then
  965. echo "+---------------------------------------------------------------+
  966. | Invalid input. Please specify a valid IP address.
  967. +---------------------------------------------------------------+"    
  968.         else
  969.         test=$1
  970.         echo $test | grep -E "(^[2][5][0-5].|^[2][0-4][0-9].|^[1][0-9][0-9].|^[0-9][0-9].|^[0-9].)([2][0-5][0-5].|[2][0-4][0-9].|[1][0-9][0-9].|[0-9][0-9].|[0-9].)([2][0-5][0-5].|[2][0-4][0-9].|[1][0-9][0-9].|[0-9][0-9].|[0-9].)([2][0-5][0-5]|[2][0-4][0-9]|[1][0-9][0-9]|[0-9][0-9]|[0-9])$" >/dev/null 2>&1 && test=1 || test=0
  971.         if [[ $test -eq 1 ]]; then
  972.         echo $checklist | tr " " "\n" |
  973.     (
  974.                 while read LIST
  975.                 do
  976.                 ipset -T $LIST $1 > /dev/null 2>&1 && if [ $LIST = "whitelist" ]; then echo -e "| \033[1;32m$1 found in        $LIST\033[0;40m"; else echo -e "| \033[1;31m$1 found in        $LIST\033[0;40m"; fi || echo -e "| $1 not found in    $LIST"
  977.         done                                                                                                                                    
  978.     )
  979.         echo -e "+---------------------------------------------------------------+
  980. |        in case of multiple match the first prevails
  981. +---------------------------------------------------------------+\033[0;39m"
  982.         elif [[ $test -eq 0 ]]; then
  983.         echo -e "| Invalid input. Please specify a valid IP address.
  984. +---------------------------------------------------------------+\033[0;39m"    
  985.         fi
  986. fi
  987. }
  988.  
  989.  
  990. pdebug() {
  991. echo -e "\033[0;40m
  992. +------------------------- P2Partisan --------------------------+
  993. |                _____         __                
  994. |               |     \.-----.|  |--.--.--.-----.
  995. |               |  --  |  -__||  _  |  |  |  _  |
  996. |               |_____/|_____||_____|_____|___  |
  997. |                                         |_____|
  998. |                                              
  999. +--------------------------- Guide -----------------------------+
  1000. | Debug allows to fully log the P2Partisan interventions given a LAN IP
  1001. | Maximum 1 debug at the time / Debug automatically times out or can be forced off manually
  1002. +---------------------------------------------------------------+
  1003. | p2partisan.sh debug <LAN IP> <minutes>    Syntax
  1004. | p2partisan.sh debug                       Displays debug status and this help text
  1005. | p2partisan.sh debug 192.168.0.3 <1-120>   Enables debug for the given LAN IP for N min (15 default)
  1006. | p2partisan.sh debug 192.168.0.3 9         Enables debug for the given LAN IP for 9 min
  1007. | p2partisan.sh debug reverse <1-120>       Enables debug for all the LAN IPs excluding greyports_tcp/udp
  1008. | p2partisan.sh debug off                   Disable debug without waiting for the timer to timeout
  1009. | p2partisan.sh debug-display <in|out>      Display logs Syntax
  1010. | p2partisan.sh debug-display               Displays in&out debug logs + guide
  1011. | p2partisan.sh debug-display out           Same as above but displays outbound records only
  1012. +-------------------------- Activity ---------------------------+"
  1013. echo "$1" | grep -Eo "([2][5][0-5].|[2][0-4][0-9].|[1][0-9][0-9].|[0-9][0-9].|[0-9].)([2][0-5][0-5].|[2][0-4][0-9].|[1][0-9][0-9].|[0-9][0-9].|[0-9].)([2][0-5][0-5].|[2][0-4][0-9].|[1][0-9][0-9].|[0-9][0-9].|[0-9].)([2][0-5][0-5]|[2][0-4][0-9]|[1][0-9][0-9]|[0-9][0-9]|[0-9])" >/dev/null 2>&1 && q=0 || q=1
  1014. echo "$1" | grep "reverse" >/dev/null 2>&1 && q=2
  1015. echo "$1" | grep "off" >/dev/null 2>&1 && off=1 || off=0
  1016.  
  1017.                         if [ -e ./iptables-debug-del ]; then
  1018.               dfrom=`head -1 ./iptables-debug 2> /dev/null | awk '{print $2}'`
  1019.            druntime=`echo $(( $now - $dfrom ))`
  1020.                   h=`echo $((( $druntime / 3600 ) %24 ))`
  1021.                   m=`echo $((( $druntime / 60 ) %60 ))`
  1022.                   s=`echo $(( $druntime %60 ))`
  1023.            druntime=`printf "%02d:%02d:%02d\n" $h $m $s`
  1024.            dendtime=`head -2 ./iptables-debug-del | tail -n 1 | awk '{print $2}'`
  1025.               ttime=`echo $(( $dendtime / 60 ))`
  1026.               ttime=`echo $(( $dfrom + $dendtime ))`
  1027.             leftime=`echo $(( $ttime - $now ))`
  1028.                   m=`echo $((( $leftime / 60 ) %60 ))`
  1029.                   s=`echo $(( $leftime %60 ))`
  1030.             leftime=`printf "%02d:%02d:%02d\n" $h $m $s`
  1031.             zzztime=`echo $(( $dendtime / 60 ))`
  1032.                         fi          
  1033.  
  1034.         if [[ $off -eq 1 ]]; then
  1035.         f=`iptables -L P2PARTISAN-DROP-IN | grep DEBUG `
  1036.         fc=`iptables -L P2PARTISAN-DROP-IN | grep DEBUG | wc -l`
  1037.                 if [[ $fc -ge 1 ]]; then
  1038.                 kill `ps | grep -E "sleep $dendtime$" | awk '{print $1}'` > /dev/null 2>&1
  1039.                 plog "| All DEBUG activities have stopped"
  1040.                 {
  1041.         while iptables -L P2PARTISAN-DROP-IN | grep DEBUG
  1042.         do
  1043.                 iptables -D P2PARTISAN-DROP-IN 1
  1044.                 done
  1045.         while iptables -L P2PARTISAN-DROP-OUT | grep DEBUG
  1046.         do
  1047.                 iptables -D P2PARTISAN-DROP-OUT 1
  1048.                 done
  1049.                 } > /dev/null 2>&1
  1050.                 echo -e "| Use \033[1;33m./p2partisan.sh debug-display\033[0;40m to show debug information, if any.
  1051. +---------------------------------------------------------------+\033[0;39m" ; exit
  1052.                 else
  1053.                         echo -e "| Debug is currently off and not collecting any information.
  1054. | Use \033[1;33m./p2partisan.sh debug-display\033[0;40m to show existing debug information, if any.
  1055. +---------------------------------------------------------------+\033[0;39m" ; exit      
  1056.                 fi
  1057.         fi
  1058.  
  1059.         if [[ -z $1 ]]; then  
  1060.                 f=`iptables -L P2PARTISAN-DROP-IN | grep DEBUG | awk '{print $5}' | head -1`
  1061.                 fc=`iptables -L P2PARTISAN-DROP-IN | grep DEBUG | wc -l`
  1062.                 if [[ $fc -gt 1 ]]; then
  1063. echo -e "| P2partisan is currently debugging IP \033[1;33m$f\033[0;40m for \033[1;33m$druntime\033[0;40m /\033[1;33m$zzztime\033[0;40m min (\033[1;33m$leftime\033[0;40m left)
  1064. | Use \033[1;33m./p2partisan.sh debug-display\033[0;40m to show debug information
  1065. +---------------------------------------------------------------+\033[0;39m" ; exit
  1066.                 elif [[ $fc -eq 0 ]]; then
  1067.                         echo -e "| Debug is currently off and not collecting any information.
  1068. | Use \033[1;33m./p2partisan.sh debug-display\033[0;40m to show existing debug information, if any.
  1069. +---------------------------------------------------------------+\033[0;39m" ; exit
  1070.                 fi
  1071.         elif [[ $q -eq 1 ]]; then
  1072.                         echo -e "| The input \033[1;31m$1\033[0;40m doesn't appear to be a valid IP
  1073. +---------------------------------------------------------------+\033[0;39m" ; exit
  1074.         fi
  1075.  
  1076.         f=`iptables -L P2PARTISAN-DROP-IN | grep DEBUG | awk '{print $5}' | head -1`
  1077.         fc=`iptables -L P2PARTISAN-DROP-IN | grep DEBUG | wc -l`
  1078.         if [[ $fc -gt 1 ]]; then
  1079. echo -e "| P2partisan is currently debugging IP \033[1;33m$f\033[0;40m for \033[1;33m$druntime\033[0;40m /\033[1;33m$zzztime\033[0;40m min (\033[1;33m$leftime\033[0;40m left)
  1080. | NOTE: Only one debug at the time is possible! Command ignored.
  1081. | Use \033[1;33m./p2partisan.sh debug-display\033[0;40m to show the debug information
  1082. +---------------------------------------------------------------+\033[0;39m" ; exit
  1083.         fi
  1084.  
  1085. if [ -z $2 ]; then
  1086.                 minutes=15
  1087.                 time=900
  1088. elif [[ $2 -gt 120 ]] || [[ $2 -eq 0 ]]; then
  1089.                 echo -e "| Please specify an acceptable time: 1 to 60 (min). If omitted 15 will be used
  1090. | Debug NOT enabled. Exiting...
  1091. +---------------------------------------------------------------+\033[0;39m" ; exit
  1092. else
  1093.                 minutes=$2
  1094.                 time=` echo $(( $2 * 60 ))`
  1095. fi
  1096. if [[ $q -eq 2 ]]; then
  1097. if [ -z $greyports_tcp ] || [ -z $greyports_udp ]; then
  1098. echo -e "| It appears like you have no greyport set. This function due to the potential amount
  1099. | of logging involved requires the both greyports_tcp and greyports_udp to be set
  1100. | if unsure on what ports to use, try to run \033[1;33m./p2partisan.sh detective\033[0;40m
  1101. +---------------------------------------------------------------+"
  1102. exit
  1103. fi
  1104. echo "# $now
  1105. iptables -I P2PARTISAN-DROP-IN 1 -p tcp --sport $greyports_tcp -j DROP
  1106. iptables -I P2PARTISAN-DROP-IN 1 -p udp --sport $greyports_udp -j DROP
  1107. iptables -I P2PARTISAN-DROP-IN 1 -p tcp --dport $greyports_tcp -j DROP
  1108. iptables -I P2PARTISAN-DROP-IN 1 -p udp --dport $greyports_udp -j DROP
  1109. iptables -I P2PARTISAN-DROP-OUT 1 -p tcp --sport $greyports_tcp -j DROP
  1110. iptables -I P2PARTISAN-DROP-OUT 1 -p udp --sport $greyports_udp -j DROP
  1111. iptables -I P2PARTISAN-DROP-OUT 1 -p tcp --dport $greyports_tcp -j DROP
  1112. iptables -I P2PARTISAN-DROP-OUT 1 -p udp --dport $greyports_udp -j DROP
  1113. iptables -I P2PARTISAN-DROP-IN 5 -j LOG --log-prefix 'P2Partisan-DEBUG-IN->> ' --log-level 1
  1114. iptables -I P2PARTISAN-DROP-OUT 5 -j LOG --log-prefix 'P2Partisan-DEBUG-OUT->> ' --log-level 1" > ./iptables-debug
  1115. chmod 777 ./iptables-debug  > /dev/null 2>&1
  1116. plog "Reverse Debug started for for $minutes minute"
  1117. ./iptables-debug 1>/dev/null &
  1118.                 echo -e "| Enabled full debug logging for all the LAN IPs for \033[1;32m$minutes\033[0;40m minutes
  1119. | This excludes the greyports_tcp $greyports_tcp and greyports_udp $greyports_udp              
  1120. | Use \033[1;33m./p2partisan.sh debug-display\033[0;40m to show the debug information
  1121. +---------------------------------------------------------------+"
  1122.  
  1123. echo "# $now
  1124. sleep $time
  1125. iptables -D P2PARTISAN-DROP-IN -p tcp -m tcp --sport $greyports_tcp -j DROP
  1126. iptables -D P2PARTISAN-DROP-IN -p udp -m udp --sport $greyports_udp -j DROP
  1127. iptables -D P2PARTISAN-DROP-IN -p tcp -m tcp --dport $greyports_tcp -j DROP
  1128. iptables -D P2PARTISAN-DROP-IN -p udp -m udp --dport $greyports_udp -j DROP
  1129. iptables -D P2PARTISAN-DROP-OUT -p tcp -m tcp --sport $greyports_tcp -j DROP
  1130. iptables -D P2PARTISAN-DROP-OUT -p udp -m udp --sport $greyports_udp -j DROP
  1131. iptables -D P2PARTISAN-DROP-OUT -p tcp -m tcp --dport $greyports_tcp -j DROP
  1132. iptables -D P2PARTISAN-DROP-OUT -p udp -m udp --dport $greyports_udp -j DROP
  1133. iptables -D P2PARTISAN-DROP-IN -j LOG --log-prefix 'P2Partisan-DEBUG-IN->> ' --log-level 1
  1134. iptables -D P2PARTISAN-DROP-OUT -j LOG --log-prefix 'P2Partisan-DEBUG-OUT->> ' --log-level 1" > ./iptables-debug-del
  1135. chmod 777 ./iptables-debug-del 2> /dev/null
  1136. ./iptables-debug-del 1>/dev/null &
  1137. else
  1138. echo "# $now
  1139. iptables -I P2PARTISAN-DROP-IN 1 -d $1 -j LOG --log-prefix \"P2Partisan-DEBUG-IN->> \" --log-level 1 > /dev/null 2>&1
  1140. iptables -I P2PARTISAN-DROP-OUT 1 -s $1 -j LOG --log-prefix \"P2Partisan-DEBUG-OUT->> \" --log-level 1 > /dev/null 2>&1" > ./iptables-debug
  1141. chmod 777 ./iptables-debug  > /dev/null 2>&1
  1142. plog "Debug started for IP $1 for $minutes minute"
  1143. ./iptables-debug 1>/dev/null &
  1144.                 echo -e "| Enabled full debug logging for LAN IP \033[1;32m$1\033[0;40m for \033[1;32m$minutes\033[0;40m minutes
  1145. | Use \033[1;33m./p2partisan.sh debug-display\033[0;40m to show the debug information
  1146. +---------------------------------------------------------------+"
  1147.  
  1148. echo "# $now
  1149. sleep $time
  1150. iptables -D P2PARTISAN-DROP-IN -d $1 -j LOG --log-prefix \"P2Partisan-DEBUG-IN->> \" --log-level 1  > /dev/null 2>&1
  1151. iptables -D P2PARTISAN-DROP-OUT -s $1 -j LOG --log-prefix \"P2Partisan-DEBUG-OUT->> \" --log-level 1 > /dev/null 2>&1" > ./iptables-debug-del
  1152. chmod 777 ./iptables-debug-del 2> /dev/null
  1153. ./iptables-debug-del 1>/dev/null &
  1154. fi
  1155. }
  1156.  
  1157. pdebugdisplay() {
  1158. echo -e "\033[0;40m
  1159. +------------------------- P2Partisan --------------------------+
  1160. _____         __                          __ __               __              
  1161. |     \.-----.|  |--.--.--.-----.______.--|  |__|.-----.-----.|  |.---.-.--.--.
  1162. |  --  |  -__||  _  |  |  |  _  |______|  _  |  ||__ --|  _  ||  ||  _  |  |  |
  1163. |_____/|_____||_____|_____|___  |      |_____|__||_____|   __||__||___._|___  |
  1164.                         |_____|                      |__|             |_____|
  1165.  
  1166. +---------------------------------------------------------------+
  1167. | p2partisan.sh debug-display               Displays in & outbound debug logs
  1168. | p2partisan.sh debug-display in            Displays inbound debug logs only
  1169. | p2partisan.sh debug-display out           Displays outbound debug logs only
  1170. +-------------------------- Drop Logs --------------------------+"
  1171.  
  1172.    dfrom=`head -1 ./iptables-debug 2> /dev/null | awk '{print $2}'`
  1173. druntime=`echo $(( $now - $dfrom ))`
  1174.       h=`echo $((( $druntime / 3600 ) %24 ))`
  1175.       m=`echo $((( $druntime / 60 ) %60 ))`
  1176.       s=`echo $(( $druntime %60 ))`
  1177. druntime=`printf "%02d:%02d:%02d\n" $h $m $s`
  1178. dendtime=`head -2 ./iptables-debug-del | tail -n 1 | awk '{print $2}'`
  1179.   ttime=`echo $(( $dendtime / 60 ))`
  1180.   ttime=`echo $(( $dfrom + $dendtime ))`
  1181. leftime=`echo $(( $ttime - $now ))`
  1182.       m=`echo $((( $leftime / 60 ) %60 ))`
  1183.       s=`echo $(( $leftime %60 ))`
  1184. leftime=`printf "%02d:%02d:%02d\n" $h $m $s`
  1185. zzztime=`echo $(( $dendtime / 60 ))`
  1186.  
  1187. c=0
  1188. rm ./debug.rev  > /dev/null 2>&1
  1189. tail -800 $logfile | grep -i "P2Partisan" > ./debug.log
  1190. cat ./debug.log | sed '1!G;h;$!d' |
  1191.  (  
  1192.  while read line
  1193.  do
  1194. testo=`echo $line | grep "Debug started for IP" | wc -l`
  1195. if [[ $testo -ge 1 ]]; then
  1196.         echo $line >> ./debug.rev
  1197.         cat ./debug.rev | sed '1!G;h;$!d' > ./debug.log
  1198.         rm ./debug.rev  > /dev/null 2>&1
  1199.         exit
  1200. else
  1201.         echo $line >> ./debug.rev
  1202. fi
  1203. done
  1204. )
  1205.  
  1206. if [ -z $1 ]; then
  1207.         echo -e "\033[48;5;89m+----------------------- INPUT & OUTPUT ------------------------+\033[40m"
  1208.         head -1 ./debug.log
  1209.         cat ./debug.log | grep "DEBUG-" | awk '{printf "%s %s %s ",$1,$2,$3;for (i=4;i<=NF;i++) if ($i~/(IN|OUT|SRC|DST|PROTO|SPT|DPT)=/) printf "%s ",$i;print ""}' | sed -e 's/PROTO=//g' -e 's/IN=/I=/g' -e 's/OUT=/O=/g' -e 's/SPT=/S=/g' -e 's/DPT=/D=/g' -e 's/SRC=/S=/g' -e 's/DST=/D=/g' | while read line; do
  1210.           [ $(($c%2)) -eq 1 ] && printf "\e[100m"
  1211.           printf "%s\033[0m\n" "$line"
  1212.           c=$(($c+1))
  1213.                 done
  1214.         fc=`iptables -L P2PARTISAN-DROP-IN | grep DEBUG | wc -l`
  1215.                 if [[ $fc -ge 1 ]]; then
  1216.                 echo -e "\e[93mNOTE: debugging is active for $druntime /$zzztime min ($leftime left). Run this command again to update the report\033[0m"
  1217.                 fi
  1218.         echo -e "\033[48;5;89m+----------------------- INPUT & OUTPUT ------------------------+\033[40m"
  1219. elif [[ $1 = "in" ]]; then
  1220.         echo -e "\033[48;5;89m+--------------------------- INPUT -----------------------------+\033[40m"
  1221.         head -1 ./debug.log
  1222.         cat ./debug.log | grep "DEBUG-IN" | awk '{printf "%s %s %s ",$1,$2,$3;for (i=4;i<=NF;i++) if ($i~/(IN|OUT|SRC|DST|PROTO|SPT|DPT)=/) printf "%s ",$i;print ""}' | sed -e 's/PROTO=//g' -e 's/IN=/I=/g' -e 's/OUT=/O=/g' -e 's/SPT=/S=/g' -e 's/DPT=/D=/g' -e 's/SRC=/S=/g' -e 's/DST=/D=/g' | while read line; do
  1223.           [ $(($c%2)) -eq 1 ] && printf "\e[100m"
  1224.           printf "%s\033[0m\n" "$line"
  1225.           c=$(($c+1))
  1226.                 done
  1227.         fc=`iptables -L P2PARTISAN-DROP-IN | grep DEBUG | wc -l`
  1228.                 if [[ $fc -ge 1 ]]; then
  1229.                 echo -e "\e[93mNOTE: debugging is active for $druntime /$zzztime min ($leftime left). Run this command again to update the report\033[0m"
  1230.                 fi
  1231.         echo -e "\033[48;5;89m+--------------------------- INPUT -----------------------------+\033[40m"
  1232. elif [[ $1 = "out" ]]; then
  1233.                 echo -e "\033[48;5;89m+--------------------------- OUTPUT ----------------------------+\033[40m"
  1234.                 head -1 ./debug.log
  1235.         cat ./debug.log | grep "DEBUG-OUT" | awk '{printf "%s %s %s ",$1,$2,$3;for (i=4;i<=NF;i++) if ($i~/(IN|OUT|SRC|DST|PROTO|SPT|DPT)=/) printf "%s ",$i;print ""}' | sed -e 's/PROTO=//g' -e 's/IN=/I=/g' -e 's/OUT=/O=/g' -e 's/SPT=/S=/g' -e 's/DPT=/D=/g' -e 's/SRC=/S=/g' -e 's/DST=/D=/g' | while read line; do
  1236.           [ $(($c%2)) -eq 1 ] && printf "\e[100m"
  1237.           printf "%s\033[0m\n" "$line"
  1238.           c=$(($c+1))
  1239.                 done
  1240.         fc=`iptables -L P2PARTISAN-DROP-IN | grep DEBUG | wc -l`
  1241.                 if [[ $fc -ge 1 ]]; then
  1242.                 echo -e "\e[93mNOTE: debugging is active for $druntime /$zzztime min ($leftime left). Run this command again to update the report\033[0m"
  1243.                 fi
  1244.                 echo -e "\033[48;5;89m+--------------------------- OUTPUT ----------------------------+\033[40m"
  1245. fi
  1246.     echo -e "+---------------------------------------------------------------+\033[0;39m"
  1247. }
  1248.  
  1249. pwhitelist() {
  1250.         ipset -F whitelist
  1251.  
  1252.         # VPN - Tinc hosts are IP whitelisted
  1253.         if [ `nvram get tinc_wanup` -eq 1 ]; then
  1254.         for IP in `nvram get tinc_hosts | grep -Eo '\w*[a-z]\w*(\.\w*[a-z]\w*)+'`; do
  1255.         echo "$IP" | grep -E "(([a-zA-Z]|[a-zA-Z][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z]|[A-Za-z][A-Za-z0-9\-]*[A-Za-z0-9])" >/dev/null 2>&1 && nslookup $IP | grep "Address [0-9]*:" | grep -v 127.0.0.1 | grep -v "\:\:" | grep -Eo "([0-9\.]{7,15})" | {
  1256.                                 while read IPO
  1257.                                 do
  1258.                                 ipset -A whitelist ${IPO%*/32} 2> /dev/null
  1259.                                 done
  1260.                                 }
  1261.         echo "$IP" | grep -Eo "^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])(\/([0-9]|[1-2][0-9]|3[0-2]))$" >/dev/null 2>&1 && ipset -A whitelist $IP 2> /dev/null
  1262.         done
  1263.         fi
  1264.         #/ VPN - Tinc hosts are IP whitelisted
  1265.        
  1266.         [ -f ./whitelist ] && cat ./whitelist | grep -Ev "^#|^$" | tr -d "\r" |
  1267.     (
  1268.     while read IP
  1269.     do             
  1270.                 q=100
  1271.                 echo "$IP" | grep -E "(([a-zA-Z]|[a-zA-Z][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z]|[A-Za-z][A-Za-z0-9\-]*[A-Za-z0-9])" >/dev/null 2>&1 && q=1
  1272.                 echo "$IP" | grep -Eo "^([2][5][0-5].|[2][0-4][0-9].|[1][0-9][0-9].|[0-9][0-9].|[0-9].)([2][0-5][0-5].|[2][0-4][0-9].|[1][0-9][0-9].|[0-9][0-9].|[0-9].)([2][0-5][0-5].|[2][0-4][0-9].|[1][0-9][0-9].|[0-9][0-9].|[0-9].)([2][0-5][0-5]|[2][0-4][0-9]|[1][0-9][0-9]|[0-9][0-9]|[0-9]-.*)" >/dev/null 2>&1 && q=0
  1273.                 echo "$IP" | grep -Eo "^([2][5][0-5].|[2][0-4][0-9].|[1][0-9][0-9].|[0-9][0-9].|[0-9].)([2][0-5][0-5].|[2][0-4][0-9].|[1][0-9][0-9].|[0-9][0-9].|[0-9].)([2][0-5][0-5].|[2][0-4][0-9].|[1][0-9][0-9].|[0-9][0-9].|[0-9].)([2][0-5][0-5]|[2][0-4][0-9]|[1][0-9][0-9]|[0-9][0-9]|[0-9])$" >/dev/null 2>&1 && q=2
  1274.                 echo "$IP" | grep -Eo "^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])(\/([0-9]|[1-2][0-9]|3[0-2]))$" >/dev/null 2>&1 && q=3
  1275.                 echo "$IP" | awk '{print $2}' | grep -E '^(http)' >/dev/null 2>&1 && q=4
  1276.         if [[ $q -eq 0 ]]; then
  1277.                                 echo $IP | pdeaggregate | {
  1278.                                 while read cidr
  1279.                                 do
  1280.                                         ipset -A whitelist $cidr 2> /dev/null
  1281.                                 done
  1282.                                 }
  1283.         elif [[ $q -eq 1 ]]; then
  1284.                 nslookup $IP | grep "Address [0-9]*:" | grep -v 127.0.0.1 | grep -v "\:\:" | grep -Eo "([0-9\.]{7,15})" |
  1285.                                 while read IPO
  1286.                                 do
  1287.                                 ipset -A whitelist ${IPO%*/32} 2> /dev/null
  1288.                                 done
  1289.         elif [[ $q -eq 2 ]]; then
  1290.                                 ipset -A whitelist ${IP%*/32} 2> /dev/null
  1291.         elif [[ $q -eq 3 ]]; then
  1292.                                 ipset -A whitelist $IP 2> /dev/null
  1293.         elif [[ $q -eq 4 ]]; then
  1294.         # SORT OUT
  1295.                                 url=`echo $IP | awk '{print $2}'`
  1296.                                 # deaggregate whitelist $url 3 &
  1297.         fi
  1298.         done
  1299.     )  
  1300. }
  1301.  
  1302. pgreylist() {
  1303.         ipset -F greylist
  1304.     [ -f ./greylist ] && cat ./greylist | grep -Ev "^#|^$" | tr -d "\r" |
  1305.     (
  1306.     while read IP
  1307.     do             
  1308.                 q=100
  1309.                 echo "$IP" | grep -E "(([a-zA-Z]|[a-zA-Z][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z]|[A-Za-z][A-Za-z0-9\-]*[A-Za-z0-9])" >/dev/null 2>&1 && q=1
  1310.                 echo "$IP" | grep -Eo "^([2][5][0-5].|[2][0-4][0-9].|[1][0-9][0-9].|[0-9][0-9].|[0-9].)([2][0-5][0-5].|[2][0-4][0-9].|[1][0-9][0-9].|[0-9][0-9].|[0-9].)([2][0-5][0-5].|[2][0-4][0-9].|[1][0-9][0-9].|[0-9][0-9].|[0-9].)([2][0-5][0-5]|[2][0-4][0-9]|[1][0-9][0-9]|[0-9][0-9]|[0-9]-.*)" >/dev/null 2>&1 && q=0
  1311.                 echo "$IP" | grep -Eo "^([2][5][0-5].|[2][0-4][0-9].|[1][0-9][0-9].|[0-9][0-9].|[0-9].)([2][0-5][0-5].|[2][0-4][0-9].|[1][0-9][0-9].|[0-9][0-9].|[0-9].)([2][0-5][0-5].|[2][0-4][0-9].|[1][0-9][0-9].|[0-9][0-9].|[0-9].)([2][0-5][0-5]|[2][0-4][0-9]|[1][0-9][0-9]|[0-9][0-9]|[0-9])$" >/dev/null 2>&1 && q=2
  1312.                 echo "$IP" | grep -Eo "^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])(\/([0-9]|[1-2][0-9]|3[0-2]))$" >/dev/null 2>&1 && q=3
  1313.                 echo "$IP" | awk '{print $2}' | grep -E '^(http)' >/dev/null 2>&1 && q=4
  1314.         if [[ $q -eq 0 ]]; then
  1315.                                 echo $IP | pdeaggregate | {
  1316.                                 while read cidr
  1317.                                 do
  1318.                                         ipset -A greylist $cidr 2> /dev/null
  1319.                                 done
  1320.                                 }
  1321.         elif [[ $q -eq 1 ]]; then
  1322.                 nslookup $IP | grep "Address [0-9]*:" | grep -v 127.0.0.1 | grep -v "\:\:" | grep -Eo "([0-9\.]{7,15})" |
  1323.                                 while read IPO
  1324.                                 do
  1325.                                 ipset -A greylist ${IPO%*/32} 2> /dev/null
  1326.                                 done
  1327.         elif [[ $q -eq 2 ]]; then
  1328.                                 ipset -A greylist ${IP%*/32} 2> /dev/null
  1329.         elif [[ $q -eq 3 ]]; then
  1330.                                 ipset -A greylist $IP 2> /dev/null
  1331.         elif [[ $q -eq 4 ]]; then
  1332.         # SORT OUT
  1333.                                 url=`echo $IP | awk '{print $2}'`
  1334.                                 # deaggregate whitelist $url 3 &
  1335.         fi
  1336.         done
  1337.     )  
  1338. }
  1339.  
  1340. pblacklistcustom() {
  1341.         ipset -F blacklist-custom
  1342.     [ -f ./blacklist-custom ] && cat ./blacklist-custom | grep -Ev "^#|^$" | tr -d "\r" |
  1343.     (
  1344.     while read IP
  1345.     do
  1346.                 q=100
  1347.                 echo "$IP" | grep -E "(([a-zA-Z]|[a-zA-Z][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z]|[A-Za-z][A-Za-z0-9\-]*[A-Za-z0-9])" >/dev/null 2>&1 && q=1
  1348.                 echo "$IP" | grep -Eo "^([2][5][0-5].|[2][0-4][0-9].|[1][0-9][0-9].|[0-9][0-9].|[0-9].)([2][0-5][0-5].|[2][0-4][0-9].|[1][0-9][0-9].|[0-9][0-9].|[0-9].)([2][0-5][0-5].|[2][0-4][0-9].|[1][0-9][0-9].|[0-9][0-9].|[0-9].)([2][0-5][0-5]|[2][0-4][0-9]|[1][0-9][0-9]|[0-9][0-9]|[0-9]-.*)" >/dev/null 2>&1 && q=0
  1349.                 echo "$IP" | grep -Eo "^([2][5][0-5].|[2][0-4][0-9].|[1][0-9][0-9].|[0-9][0-9].|[0-9].)([2][0-5][0-5].|[2][0-4][0-9].|[1][0-9][0-9].|[0-9][0-9].|[0-9].)([2][0-5][0-5].|[2][0-4][0-9].|[1][0-9][0-9].|[0-9][0-9].|[0-9].)([2][0-5][0-5]|[2][0-4][0-9]|[1][0-9][0-9]|[0-9][0-9]|[0-9])$" >/dev/null 2>&1 && q=2
  1350.                 echo "$IP" | grep -Eo "^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])(\/([0-9]|[1-2][0-9]|3[0-2]))$" >/dev/null 2>&1 && q=3
  1351.         if [[ $q -eq 0 ]]; then
  1352.                                 echo $IP | pdeaggregate | {
  1353.                                 while read cidr
  1354.                                 do
  1355.                                     ipset -A whitelist $cidr 2> /dev/null
  1356.                                 done
  1357.                                 }
  1358.         elif [[ $q -eq 1 ]]; then
  1359.                 nslookup $IP | grep "Address [0-9]*:" | grep -v 127.0.0.1 | grep -v "\:\:" | grep -Eo "([0-9\.]{7,15})" |
  1360.                                 while read IPO
  1361.                                 do
  1362.                                 ipset -A blacklist-custom ${IPO%*/32} 2> /dev/null
  1363.                                 done
  1364.         elif [[ $q -eq 2 ]]; then
  1365.                                 ipset -A blacklist-custom ${IP%*/32} 2> /dev/null
  1366.         elif [[ $q -eq 3 ]]; then
  1367.                                 ipset -A blacklist-custom $IP 2> /dev/null
  1368.         fi
  1369.         done
  1370.     )  
  1371. }
  1372.        
  1373. pstart() {
  1374.                
  1375.         running4=`[ -f $pidfile ] && echo 1 || echo 0`
  1376.         if [ $running4 -eq "0" ] ; then
  1377.             [ -f /tmp/p2partisan.loading ] && echo "P2Partisan is still loading. Exiting..." && exit
  1378.             touch /tmp/p2partisan.loading
  1379.             pre=`date +%s`
  1380.             echo $$ > $pidfile
  1381.        
  1382.     [ -e iptables-add ] && rm iptables-add
  1383.     [ -e iptables-del ] && rm iptables-del
  1384.     [ -e ipset-del ] && rm ipset-del
  1385.  
  1386.         echo -e "\033[0;40m
  1387. +------------------------- P2Partisan --------------------------+
  1388. |                 _______ __               __  
  1389. |                |     __|  |_.---.-.----.|  |_
  1390. |                |__     |   _|  _  |   _||   _|
  1391. |                |_______|____|___._|__|  |____|
  1392. |                                            
  1393. +---------------------------------------------------------------+
  1394. +--------- PREPARATION --------"
  1395.         echo "| Loading the ipset modules"
  1396.         {
  1397.         lsmod | awk '{print $1}' | grep -we "^ip_set" || insmod ip_set
  1398.         lsmod | awk '{print $1}' | grep -we "^xt_set" || insmod xt_set
  1399.         lsmod | awk '{print $1}' | grep -we "^ip_set_hash_net" || insmod ip_set_hash_net
  1400.         } > /dev/null 2>&1
  1401. counter=0
  1402. pos=1
  1403.                 counter=$(printf "%02d" $counter)
  1404.                 echo "+---- CUSTOM IP BLACKLIST -----
  1405. | preparing blacklist-custom ..."
  1406.                 echo -e "| Loading Blacklist_$counter data ---> \033[1;37m***Custom IP blacklist***\033[0;40m"
  1407.                 if [ "$(ipset --swap blacklist-custom blacklist-custom 2>&1 | grep 'does not exist')" != "" ]
  1408.                         then
  1409.                         ipset --create blacklist-custom hash:net hashsize 1024 --resize 5 maxelem 1024000  2> /dev/null
  1410.                         fi                            
  1411.  
  1412.         pblacklistcustom
  1413.  
  1414. [ -e /tmp/iptables-add.tmp ] && rm /tmp/iptables-add.tmp > /dev/null 2>&1
  1415.  
  1416. echo "+--------- GREYPORTs ----------"
  1417. echo $greyports_tcp | awk -v RS=',' -F : '{ gsub(/\n$/, "") } NF > 1 { r=(r ? r "," : "") $0; if (r ~ /([^,]*,){6}/) { print r; r=""; } next } { s=(s ? s "," : "") $0; if (s ~ /([^,]*,){14}/) { print s; s=""; } }  END { if (r && s) { p = r "," s; if (p !~ /([^,:]*[:,]){15}/) { print p; r=s="" } } if (r) print r ; if (s) print s }' | while read w; do
  1418.                         echo -e "| Loading grey TCP ports:  \033[1;37m$w\033[0;40m"
  1419.                         echo "iptables -A P2PARTISAN-IN -i $wanif -p tcp --match multiport --dports $w -g P2PARTISAN-LISTS-IN
  1420. iptables -A P2PARTISAN-OUT -o $wanif -p tcp --match multiport --sports $w -g P2PARTISAN-LISTS-OUT" >> /tmp/iptables-add.tmp
  1421. done
  1422. echo $greyports_udp | awk -v RS=',' -F : '{ gsub(/\n$/, "") } NF > 1 { r=(r ? r "," : "") $0; if (r ~ /([^,]*,){6}/) { print r; r=""; } next } { s=(s ? s "," : "") $0; if (s ~ /([^,]*,){14}/) { print s; s=""; } }  END { if (r && s) { p = r "," s; if (p !~ /([^,:]*[:,]){15}/) { print p; r=s="" } } if (r) print r ; if (s) print s }' | while read w; do
  1423.                         echo -e "| Loading grey UDP ports:  \033[1;37m$w\033[0;40m"
  1424.                         echo "iptables -A P2PARTISAN-IN -i $wanif -p udp --match multiport --dports $w -g P2PARTISAN-LISTS-IN
  1425. iptables -A P2PARTISAN-OUT -o $wanif -p udp --match multiport --sports $w -g P2PARTISAN-LISTS-OUT" >> /tmp/iptables-add.tmp
  1426. done
  1427. # Get transmission port for greylisting if enabled
  1428. transmissionenable=`nvram get bt_enable`
  1429. if [ -z $transmissionenable ]; then
  1430.     echo "|  TransmissionBT:  Not available"
  1431.     elif [ $transmissionenable -eq 0 ]; then
  1432.     echo "|  TransmissionBT:  Off"
  1433.     else
  1434.     echo -e "|  TransmissionBT:  \033[1;32mOn\033[0;40m"
  1435.         transmissionport=`nvram get bt_port 2> /dev/null`
  1436.         wanip=`nvram get wan_ipaddr`
  1437.         p3=`echo $greyports_tcp | grep -Eo '$transmissionport' | wc -l`
  1438.         p4=`echo $greyports_udp | grep -Eo '$transmissionport' | wc -l`
  1439.         if [ $p3 -eq "0" ]; then
  1440.                         echo "iptables -A P2PARTISAN-IN -i $wanif -p tcp -d $wanip --dport $transmissionport -g P2PARTISAN-LISTS-IN
  1441. iptables -A P2PARTISAN-OUT -o $wanif -p tcp -s $wanip --sport $transmissionport -g P2PARTISAN-LISTS-OUT
  1442. iptables -A P2PARTISAN-OUT -o $wanif -p tcp -s $wanip --sport 49152:65535 -g P2PARTISAN-LISTS-OUT" >> /tmp/iptables-add.tmp
  1443.         fi            
  1444.         if [ $p4 -eq "0" ]; then
  1445.                         echo "iptables -A P2PARTISAN-IN -i $wanif -p udp -d $wanip --dport $transmissionport -g P2PARTISAN-LISTS-IN
  1446. iptables -A P2PARTISAN-OUT -o $wanif -p udp -s $wanip --sport $transmissionport -g P2PARTISAN-LISTS-OUT
  1447. iptables -A P2PARTISAN-OUT -o $wanif -p udp -s $wanip --sport 49152:65535 -g P2PARTISAN-LISTS-OUT" >> /tmp/iptables-add.tmp
  1448.         fi
  1449. fi
  1450.            
  1451. echo "+--------- WHITEPORTs ---------"
  1452. echo $whiteports_tcp | awk -v RS=',' -F : '{ gsub(/\n$/, "") } NF > 1 { r=(r ? r "," : "") $0; if (r ~ /([^,]*,){6}/) { print r; r=""; } next } { s=(s ? s "," : "") $0; if (s ~ /([^,]*,){14}/) { print s; s=""; } }  END { if (r && s) { p = r "," s; if (p !~ /([^,:]*[:,]){15}/) { print p; r=s="" } } if (r) print r ; if (s) print s }' | while read w; do
  1453.                 echo -e "| Loading white TCP ports \033[1;37m$w\033[0;40m"
  1454.                 echo "iptables -A P2PARTISAN-IN -i $wanif -p tcp --match multiport --sports $w -j RETURN
  1455. iptables -A P2PARTISAN-IN -i $wanif -p tcp --match multiport --dports $w -j RETURN
  1456. iptables -A P2PARTISAN-OUT -o $wanif -p tcp --match multiport --sports $w -j RETURN
  1457. iptables -A P2PARTISAN-OUT -o $wanif -p tcp --match multiport --dports $w -j RETURN" >> /tmp/iptables-add.tmp
  1458.                 done
  1459. echo $whiteports_udp | awk -v RS=',' -F : '{ gsub(/\n$/, "") } NF > 1 { r=(r ? r "," : "") $0; if (r ~ /([^,]*,){6}/) { print r; r=""; } next } { s=(s ? s "," : "") $0; if (s ~ /([^,]*,){14}/) { print s; s=""; } }  END { if (r && s) { p = r "," s; if (p !~ /([^,:]*[:,]){15}/) { print p; r=s="" } } if (r) print r ; if (s) print s }' | while read w; do
  1460.                 echo -e "| Loading white UDP ports \033[1;37m$w\033[0;40m"
  1461.                 echo "iptables -A P2PARTISAN-IN -i $wanif -p udp --match multiport --sports $w -j RETURN
  1462. iptables -A P2PARTISAN-IN -i $wanif -p udp --match multiport --dports $w -j RETURN
  1463. iptables -A P2PARTISAN-OUT -o $wanif -p udp --match multiport --sports $w -j RETURN
  1464. iptables -A P2PARTISAN-OUT -o $wanif -p udp --match multiport --dports $w -j RETURN" >> /tmp/iptables-add.tmp
  1465.                 done
  1466. echo "iptables -A P2PARTISAN-IN -j P2PARTISAN-LISTS-IN
  1467. iptables -A P2PARTISAN-OUT -j P2PARTISAN-LISTS-OUT" >> /tmp/iptables-add.tmp
  1468.  
  1469.                 echo "# $now
  1470. iptables -N P2PARTISAN-IN
  1471. iptables -N P2PARTISAN-OUT
  1472. iptables -N P2PARTISAN-LISTS-IN
  1473. iptables -N P2PARTISAN-LISTS-OUT
  1474. iptables -N P2PARTISAN-DROP-IN
  1475. iptables -N P2PARTISAN-DROP-OUT
  1476. iptables -F P2PARTISAN-IN
  1477. iptables -F P2PARTISAN-OUT
  1478. iptables -F P2PARTISAN-LISTS-IN
  1479. iptables -F P2PARTISAN-LISTS-OUT
  1480. iptables -F P2PARTISAN-DROP-IN
  1481. iptables -F P2PARTISAN-DROP-OUT
  1482. iptables -A P2PARTISAN-IN -m set  --match-set blacklist-custom src -j P2PARTISAN-DROP-IN
  1483. iptables -A P2PARTISAN-OUT -m set  --match-set blacklist-custom dst -j P2PARTISAN-DROP-OUT" > iptables-add
  1484.  
  1485. #Add winin/wanout for RMerlin compatibility only
  1486. if [ $rm -eq 1 ]; then
  1487.         echo "iptables -N wanin
  1488. iptables -I FORWARD 1 -i $wanif -j wanin
  1489. iptables -N wanout
  1490. iptables -I FORWARD 2 -o $wanif -j wanout" >> ./iptables-add
  1491. fi
  1492. #
  1493.                 echo "# $now" >> iptables-del
  1494. [ -f ./custom-script-del ] && cat ./custom-script-add >> iptables-del
  1495. [ ! -z $vpnif ] && echo "iptables -D INPUT -o $vpnif -m state --state NEW -j P2PARTISAN-IN"  >> iptables-del
  1496. [ ! -z $vpnif ] && echo "iptables -D OUTPUT -i $vpnif -m state --state NEW -j P2PARTISAN-IN"  >> iptables-add
  1497. [ ! -z $vpnif ] && echo "iptables -D FORWARD -o $vpnif -m state --state NEW -j P2PARTISAN-IN"  >> iptables-del
  1498. echo "iptables -D wanin -i $wanif -m state --state NEW -j P2PARTISAN-IN
  1499. iptables -D wanout -o $wanif -m state --state NEW -j P2PARTISAN-OUT
  1500. iptables -D INPUT -i $wanif -m state --state NEW -j P2PARTISAN-IN
  1501. iptables -D OUTPUT -o $wanif -m state --state NEW -j P2PARTISAN-OUT
  1502. iptables -F P2PARTISAN-DROP-IN
  1503. iptables -F P2PARTISAN-DROP-OUT
  1504. iptables -F P2PARTISAN-LISTS-IN
  1505. iptables -F P2PARTISAN-LISTS-OUT
  1506. iptables -F P2PARTISAN-IN
  1507. iptables -F P2PARTISAN-OUT
  1508. iptables -X P2PARTISAN-IN
  1509. iptables -X P2PARTISAN-OUT
  1510. iptables -X P2PARTISAN-LISTS-IN
  1511. iptables -X P2PARTISAN-LISTS-OUT
  1512. iptables -X P2PARTISAN-DROP-IN
  1513. iptables -X P2PARTISAN-DROP-OUT" >> iptables-del
  1514.  
  1515. echo "+--------- GREY IPs ---------"
  1516. echo "| preparing IP greylist ..."
  1517. #Load the whitelist
  1518.         if [ "$(ipset --swap greylist greylist 2>&1 | grep 'does not exist')" != "" ]
  1519.                 then
  1520.                         ipset --create greylist hash:net hashsize 16 --resize 5 maxelem 255  > /dev/null 2>&1          
  1521.         fi
  1522.         pgreylist
  1523.                         echo -e "| Loading IP greylist data ---> \033[1;37m***IP greylist***\033[0;40m"
  1524.                         echo "iptables -A P2PARTISAN-IN -m set  --match-set greylist src -g P2PARTISAN-LISTS-IN
  1525. iptables -A P2PARTISAN-IN -m set  --match-set greylist dst -g P2PARTISAN-LISTS-IN
  1526. iptables -A P2PARTISAN-OUT -m set  --match-set greylist src -g P2PARTISAN-LISTS-OUT
  1527. iptables -A P2PARTISAN-OUT -m set  --match-set greylist dst -g P2PARTISAN-LISTS-OUT" >> iptables-add
  1528.  
  1529.  
  1530. echo "+--------- WHITE IPs ---------"
  1531. echo "| preparing IP whitelist ..."
  1532. #Load the whitelist
  1533.         if [ "$(ipset --swap whitelist whitelist 2>&1 | grep 'does not exist')" != "" ]
  1534.                 then
  1535.                         ipset --create whitelist hash:net hashsize 1024 --resize 5 maxelem 1024000  > /dev/null 2>&1          
  1536.         fi
  1537.         pwhitelist
  1538.  
  1539.         echo "# $now
  1540. ipset -F
  1541. ipset -X blacklist-custom
  1542. ipset -X greylist
  1543. ipset -X whitelist" > ipset-del
  1544.  
  1545.                         echo -e "| Loading IP whitelist data ---> \033[1;37m***IP Whitelist***\033[0;40m"
  1546.                         echo "iptables -A P2PARTISAN-IN -m set  --match-set whitelist src -j RETURN
  1547. iptables -A P2PARTISAN-IN -m set  --match-set whitelist dst -j RETURN
  1548. iptables -A P2PARTISAN-OUT -m set  --match-set whitelist src -j RETURN
  1549. iptables -A P2PARTISAN-OUT -m set  --match-set whitelist dst -j RETURN" >> iptables-add
  1550.  
  1551. cat /tmp/iptables-add.tmp >> ./iptables-add
  1552. rm /tmp/iptables-add.tmp > /dev/null 2>&1
  1553.  
  1554.                 if [ $syslogs -eq "1" ]; then        
  1555. echo "iptables -A P2PARTISAN-DROP-IN -m limit --limit $maxloghour/hour --limit-burst 1 -j LOG --log-prefix 'P2Partisan Dropped IN - ' --log-level 1
  1556. iptables -A P2PARTISAN-DROP-OUT -m limit --limit $maxloghour/hour  --limit-burst 1 -j LOG --log-prefix 'P2Partisan Rejected OUT - ' --log-level 1" >> iptables-add
  1557.                 fi
  1558.                 echo "iptables -A P2PARTISAN-DROP-IN -j DROP
  1559. iptables -A P2PARTISAN-DROP-OUT -j REJECT --reject-with icmp-admin-prohibited"  >> iptables-add
  1560.  
  1561.  
  1562. echo "+------- IP BLACKLISTs -------"
  1563.        
  1564.         cat blacklists | grep -Ev "^#|^$" | tr -d "\r" |
  1565.    (
  1566.     while read line
  1567.     do
  1568.             counter=`expr $counter + 1`
  1569.             counter=$(printf "%02d" $counter)          
  1570.             name=`echo $line | awk '{print $1}'`
  1571.             url=`echo $line | awk '{print $2}'`
  1572.      
  1573.         if [ "$(ipset swap "$name.bro" "$name.bro" 2>&1 | grep 'does not exist')" != "" ]
  1574.             then
  1575.             ipset --create "$name.bro" hash:net hashsize 1024 --resize 5 maxelem 4096000 > /dev/null
  1576.         fi
  1577.         if [ "$(ipset swap $name $name 2>&1 | grep 'does not exist')" != "" ]
  1578.             then
  1579.                 [ -f ./$name.cidr ] && cat ./$name.cidr | cut -d" " -f3 | grep -E "^1.1.1.1$" > /dev/null && complete=1 || complete=0
  1580.                 if [ $complete -eq 1 ]; then                #.cidr exists and populated, using it
  1581.                         echo -e "| Async loading [cached] Blacklist_$counter --> \033[1;37m***$name***\033[0;40m"
  1582.                         {
  1583.                         ipset -F $name
  1584.                         ipset -X $name
  1585.                         ipset --create $name hash:net hashsize 1024 --resize 5 maxelem 4096000
  1586.                         deaggregate $name "" 2 $pre "" $maxconcurrentlistload $P2Partisandir &
  1587.                         } 2> /dev/null
  1588.                 else                                        #fresh load/first run
  1589.                         echo -e "| Async loading [convert] Blacklist_$counter --> \033[1;37m***$name***\033[0;40m"
  1590.                         {
  1591.                         ipset -F $name
  1592.                         ipset -X $name
  1593.                         ipset --create $name hash:net hashsize 1024 --resize 5 maxelem 4096000
  1594.                         deaggregate $name $url 0 $pre "" $maxconcurrentlistload $P2Partisandir &
  1595.                                              # 4 = On the fly record by record STOUT output
  1596.                                              # 3 = add from public whitelist sIP-dIP to ipset only
  1597.                                              # 2 = add from .cidr to ipset only
  1598.                                              # 1 = convert + add live + create .cidr file (very slow)
  1599.                                              # 0 = convert + add live + create ipset dump
  1600.                                              # different = convert + add to ipset + create .cidr file
  1601.                         } 2> /dev/null                   
  1602.                 fi
  1603.         fi
  1604.  
  1605.         echo "ipset -X $name " >> ipset-del
  1606.         echo "iptables -A P2PARTISAN-LISTS-IN -m set  --match-set $name src -j P2PARTISAN-DROP-IN
  1607. iptables -A P2PARTISAN-LISTS-OUT -m set  --match-set $name dst -j P2PARTISAN-DROP-OUT" >> iptables-add
  1608.     done
  1609.     )
  1610.  
  1611. echo "iptables -I INPUT $pos -i $wanif -m state --state NEW -j P2PARTISAN-IN
  1612. iptables -I OUTPUT $pos -o $wanif -m state --state NEW -j P2PARTISAN-OUT
  1613. iptables -I wanin $pos -i $wanif -m state --state NEW -j P2PARTISAN-IN
  1614. iptables -I wanout $pos -o $wanif -m state --state NEW -j P2PARTISAN-OUT" >> iptables-add
  1615.  
  1616. [ ! -z $vpnif ] && echo "iptables -I INPUT $pos -o $vpnif -m state --state NEW -j P2PARTISAN-IN"  >> iptables-add
  1617. [ ! -z $vpnif ] && echo "iptables -I OUTPUT $pos -i $vpnif -m state --state NEW -j P2PARTISAN-IN"  >> iptables-add
  1618. [ ! -z $vpnif ] && echo "iptables -I FORWARD $pos -o $vpnif -m state --state NEW -j P2PARTISAN-IN"  >> iptables-add
  1619.  
  1620. #Add winin/wanout for RMerlin compatibility only
  1621. if [ $rm -eq 1 ]; then
  1622. echo "iptables -F wanin
  1623. iptables -X wanin
  1624. iptables -D FORWARD -i $wanif -j wanin
  1625. iptables -F wanout
  1626. iptables -X wanout
  1627. iptables -D FORWARD -o $wanif -j wanout" >> iptables-del
  1628. fi
  1629. #
  1630.  
  1631. [ -f ./custom-script-add ] && cat ./custom-script-add >> iptables-add
  1632.  
  1633. chmod 777 ./iptables-*
  1634. chmod 777 ./ipset-*
  1635. ./iptables-del 2> /dev/null #cleaning
  1636. ./iptables-add 2> /dev/null  #protecting
  1637.  
  1638. plog "... P2Partisan started"
  1639. echo "+------------------------- Controls ----------------------------+"
  1640.  
  1641. p=`nvram get dnsmasq_custom | grep log-async | wc -l`
  1642. if [ $p -eq "1" ]; then
  1643.         plog "log-async found under dnsmasq -> OK"
  1644. echo "+---------------------------------------------------------------+"
  1645. else
  1646.         plog "
  1647. | It appears like you don't have a log-async parameter in your dnsmasq
  1648. | config. This is strongly suggested due to the amount of logs involved,
  1649. | especially while debugging to consider adding the following command
  1650. | under Advanced/DHCP/DNS/Dnsmasq Custom configuration:
  1651. |  
  1652. | log-async=20
  1653. |  
  1654. +---------------------------------------------------------------+\033[0;39m"
  1655.     fi
  1656. p=`nvram get script_fire | grep "cru a P2Partisan-tutor" | wc -l`
  1657.         if [ $p -eq "0" ] ; then
  1658.         ptutorset
  1659.         fi
  1660.  
  1661.         post=`date +%s`
  1662.         [ -f /tmp/p2partisan.loading ] && rm -r "/tmp/p2partisan.loading" >/dev/null 2>&1
  1663.         else
  1664.         echo -e "\033[0;40m
  1665. +------------------------- P2Partisan --------------------------+
  1666. |                 _______ __               __  
  1667. |                |     __|  |_.---.-.----.|  |_
  1668. |                |__     |   _|  _  |   _||   _|
  1669. |        already |_______|____|___._|__|  |____| ed
  1670. |                                            
  1671. +---------------------------------------------------------------+
  1672. | It appears like P2Partisan is already running. Skipping...
  1673. |                      
  1674. | Is this is not what you expected? Try:
  1675. | \033[1;33m./p2partisan.sh update\033[0;40m
  1676. +---------------------------------------------------------------+
  1677.                \033[0;39m"
  1678.         fi
  1679. }
  1680.  
  1681. b64(){
  1682. awk 'BEGIN{b64="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"}
  1683. {for(i=1;i<=length($0);i++){c=index(b64,substr($0,i,1));if(c--)
  1684. for(b=0;b<6;b++){o=o*2+int(c/32);c=(c*2)%64;if(++obc==8){if(o)
  1685. {printf"%c",o}else{system("echo -en \"\\0\"")}obc=o=0}}}}';}
  1686.  
  1687. pdeaggregate() {
  1688. awk '
  1689. function ip2int(ip) {
  1690. for (ret=0,n=split(ip,a,"\."),x=1;x<=n;x++) ret=or(lshift(ret,8),a[x])
  1691. return ret
  1692. }
  1693.  
  1694. function int2ip(ip,ret,x) {
  1695. ret=and(ip,255)
  1696. ip=rshift(ip,8)
  1697. for(;x<3;ret=and(ip,255)"."ret,ip=rshift(ip,8),x++);
  1698. return ret
  1699. }
  1700.  
  1701. BEGIN {
  1702. bits=0xffffffff
  1703. FS="[-]"
  1704. }
  1705.  
  1706. {
  1707. base=ip2int($1)
  1708. end=ip2int($2)
  1709. while (base <= end) {
  1710. step = 0
  1711. while ( or(base, lshift(1, step)) != base) {
  1712. if ( or(base, rshift((bits, (31-step)))) > end ) {
  1713. break;
  1714. }
  1715. step++
  1716. }
  1717. print int2ip(base)"/"(32-step)
  1718. base = base + lshift(1, step)
  1719. }
  1720. }
  1721.  
  1722. '  #end of awk script
  1723. }
  1724.  
  1725. for p in $1
  1726. do
  1727. case "$p" in
  1728.         "start")
  1729.                 pstart
  1730.                         exit
  1731.                 ;;            
  1732.         "stop")
  1733.                 pforcestop
  1734.                         exit
  1735.                 ;;
  1736.         "restart")
  1737.                 psoftstop
  1738.                 ;;
  1739.         "status")
  1740.                 pstatus $2
  1741.                         exit                          
  1742.                 ;;
  1743.         "pause")
  1744.                 psoftstop
  1745.                         exit
  1746.                 ;;
  1747.         "detective")          
  1748.                 pdetective
  1749.                         exit
  1750.                 ;;
  1751.         "test")
  1752.                 ptest $2
  1753.                         exit
  1754.                 ;;    
  1755.         "debug")
  1756.                 pdebug $2 $3
  1757.                         exit
  1758.                 ;;  
  1759.         "debug-display")
  1760.                 pdebugdisplay $2
  1761.                         exit
  1762.                 ;;                            
  1763.         "update")
  1764.                 pforcestop $2
  1765.                         echo "| Now updating..."
  1766.                         ;;
  1767.         "autorun-on")
  1768.                         pautorunset
  1769.                         exit
  1770.         ;;
  1771.         "autorun-off")
  1772.                         pautorununset
  1773.                         exit
  1774.         ;;
  1775.         "tutor")
  1776.                         ptutor
  1777.                         exit
  1778.                         ;;
  1779.         "upgrade")
  1780.                         pupgrade
  1781.                         ;;
  1782.         "upgrade-beta")
  1783.                         pupgradebeta
  1784.                         ;;                            
  1785.         "help")
  1786.                
  1787.                 echo -e "\033[48;5;89m
  1788.      ______ ______ ______              __   __                                        
  1789.     |   __ \__    |   __ \.---.-.----.|  |_|__|.-----.---.-.-----.                    
  1790.     |    __/    __|    __/|  _  |   _||   _|  ||__ --|  _  |     |                    
  1791.     |___|  |______|___|   |___._|__|  |____|__||_____|___._|__|__| $version
  1792. \e[39m\e[49m\033[0;40m
  1793.            
  1794.       help                    Display this text              
  1795.       \e[97mstart                   Starts the process (this runs also if no option is provided)
  1796.       stop                    Stops P2Partisan
  1797.       restart                 Soft restart, updates whiteports & whitelist only
  1798.       pause                   Soft stop P2Partisan allowing for quick start
  1799.       update                  Hard restart, slow removes p2partisan, updates
  1800.                               the lists and does a fresh start
  1801.       update <list|fix>       Updated the selected list only | remove cidr a start from scratch\e[39m
  1802.       status                  Display P2Partisan running status + extra information
  1803.       status <list>           Display P2Partisan detailed list information
  1804.       \e[93mtest <IP>               Verify existence of the given IP against lists
  1805.       debug                   Shows a guide on how to operate debug
  1806.       debug-display <in|out>  Shows all the logs relevant to the last debug only
  1807.       detective               Determines highest impact IPs:ports (number of sessions)
  1808.       \e[36mautorun-on              Sets P2Partisan to boot with the router
  1809.       autorun-off             Sets P2Partisan not to boot with the router
  1810.       upgrade                 Download and install the latest P2Partisan
  1811. \033[0;39m"
  1812.                                 exit
  1813.                 ;;
  1814.         *)
  1815.                                 echo -e "\033[0;40mparameter not valid. please run:
  1816.                            
  1817.       p2partisan.sh help
  1818.       \033[0;39m"
  1819.                                 exit
  1820.                                 ;;
  1821.  
  1822. esac
  1823. done
  1824.  
  1825. pstart
  1826.  
  1827.  
  1828. exit
Add Comment
Please, Sign In to add comment