rs232

p2partisan v6.09

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