Advertisement
rs232

p2partisan latest 5.x+

Mar 16th, 2015
1,303
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 73.42 KB | None | 0 0
  1. #!/bin/sh
  2. #
  3. # p2partisan v5.16 (23/02/2020)
  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,67,68,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. # Fastrouting will process the IP classes very quickly but use
  57. # Lot of resources. If you disable the effect is transparent
  58. # but the full process will take minutes rather than seconds
  59. # 0=disabled 1=enabled
  60. fastroutine=1
  61. #
  62. # Enable check on script availability to help autorun.
  63. # If the ./partisan.sh is remote wait for the file to be available
  64. # instead of quit with a file missing error
  65. autorun_availability_check=1
  66. #
  67. # Schedule updates? (once a week is plenty). Custom syntax:
  68. # m = random minute picked up in the range[0-59]
  69. # h = random hour picked up in the range [1-5]am
  70. # d = random day of the week picked up in the range Sun to Sat [0-6]
  71. # if unwanted set your own specific time e.g.
  72. # "30 4 * * 1" 4:30 on a Monday
  73. # or use a combination e.g. random minute at 1am on a Tuesday:
  74. # "m 1 * * 3"
  75. # Specify this always in between "" please
  76. schedule="m h * * d"
  77. #
  78. # IP for testing Internet connectivity
  79. testip=8.8.8.8
  80. # </CONFIGURATION> ###########################################
  81.  
  82. ipsetversion=`ipset -V | grep ipset | awk '{print $2}' | cut -c2` #4=old 6=new
  83.     if [ $ipsetversion != 4 ]; then
  84.         echo "ipset not compatible with this P2Partisan version"
  85.     exit
  86.     fi
  87.  
  88.         paranoiastuck=`iptables -L | grep PARANOIA | wc -l`
  89.         if [[ $paranoiastuck -lt 1 ]]; then
  90.  
  91.         # Wait until Internet is available
  92.         while :
  93.         do
  94.                 ping -c 3 $testip >/dev/null 2>&1
  95.                 if [ $? = 0 ]; then
  96.                         break
  97.                 fi
  98.                 sleep 5
  99.         done
  100.         fi
  101.  
  102. pidfile="/var/run/p2partisan.pid"
  103. logfile=`nvram get log_file_path` || logfile=`/var/log/messages`
  104. cd $P2Partisandir
  105. version=`head -3 ./p2partisan.sh | tail -1 | cut -f 3- -d " "`
  106.  
  107. alias ipset='/bin/nice -n19 /usr/sbin/ipset'
  108. alias sed='/bin/nice -n19 /bin/sed'
  109. alias iptables='/usr/sbin/iptables'
  110. alias service='/sbin/service'
  111. alias plog='logger -t "| P2PARTISAN" -s'
  112. now=`date +%s`
  113. rm=1
  114. wanif=`nvram get wan_ifname` && rm=0 || wanif=`nvram get wan_ifnames`  #RMerlin work around
  115. lanif=`nvram get lan_ifname`
  116.  
  117. # DHCP hardcoded patch
  118. p1=`echo $whiteports_udp | grep -Eo '[,|:]67[,|:| ]' | wc -l`
  119. p2=`echo $whiteports_udp | grep -Eo '[,|:]68[,|:| ]' | wc -l`
  120. if [ $p1 -eq "0" ]; then
  121.     whiteports_udp=${whiteports_udp},67
  122. fi     
  123. if [ $p2 -eq "0" ]; then
  124.     whiteports_udp=${whiteports_udp},68
  125. fi
  126.  
  127. psoftstop() {
  128.         [ -f /tmp/p2partisan.loading ] && echo "P2Partisan is still loading. Can't stop right now Exiting..." && exit
  129.     echo -e "
  130. +------------------------- P2Partisan --------------------------+
  131. |                   _______ __              
  132. |                  |     __|  |_.-----.-----.
  133. |                  |__     |   _|  _  |  _  |
  134. |            Soft  |_______|____|_____|   __|
  135. |                                     |__|  
  136. |                                            
  137. +---------------------------------------------------------------+"
  138.         echo -e "| Stopping P2Partisan..."
  139.         ./iptables-del 2> /dev/null
  140.         plog "Stopping P2Partisan..."
  141.         [ -f $pidfile ] && rm -f "$pidfile" 2> /dev/null
  142.         [ -f iptables-add ] && rm -f "iptables-add" 2> /dev/null
  143.         [ -f iptables-del ] && rm -f "iptables-del" 2> /dev/null
  144. echo "+---------------------------------------------------------------+"
  145. }
  146.  
  147.        
  148. pblock() {
  149.         plog "P2PArtisan: Applying paranoia block"
  150.         iptables -N PARANOIA-DROP 2> /dev/null
  151.     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
  152.         echo "| loading whitelisted ports $w exemption for paranoia-update"    
  153.         iptables -A PARANOIA-DROP -p tcp --match multiport --sports $w -j ACCEPT 2> /dev/null
  154.         iptables -A PARANOIA-DROP -p tcp --match multiport --dports $w -j ACCEPT 2> /dev/null
  155.         done               
  156.     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
  157.         echo "| loading whitelisted UDP ports $w exemption"
  158.         iptables -A PARANOIA-DROP -p udp --match multiport --sports $w -j ACCEPT 2> /dev/null
  159.         iptables -A PARANOIA-DROP -p udp --match multiport --dports $w -j ACCEPT 2> /dev/null
  160.         done
  161.        
  162.         iptables -A PARANOIA-DROP -m set --set whitelist dst -j ACCEPT 2> /dev/null
  163.         iptables -A PARANOIA-DROP -m limit --limit $maxloghour/hour --limit-burst 5 -j LOG --log-prefix "P2Partisan DROP (PARANOIA) >> " --log-level 1 2> /dev/null
  164.         iptables -A PARANOIA-DROP -j DROP
  165.         iptables -I wanin 1 -i $wanif -m state --state NEW -j PARANOIA-DROP 2> /dev/null
  166.         iptables -I wanout 1 -o $wanif -m state --state NEW -j PARANOIA-DROP 2> /dev/null
  167.         iptables -I INPUT 1 -i $wanif -m state --state NEW -j PARANOIA-DROP 2> /dev/null
  168.         iptables -I OUTPUT 1 -o $wanif -m state --state NEW -j PARANOIA-DROP 2> /dev/null
  169. }
  170.  
  171. punblock() {
  172.         while iptables -L wanin 2> /dev/null | grep "PARANOIA-DROP"  > /dev/null 2>&1
  173.         do
  174.                 iptables -D wanin -i $wanif -m state --state NEW -j PARANOIA-DROP > /dev/null 2>&1
  175.         done
  176.         while iptables -L wanout 2> /dev/null | grep "PARANOIA-DROP" > /dev/null 2>&1
  177.         do
  178.                 iptables -D wanout -o $wanif -m state --state NEW -j PARANOIA-DROP > /dev/null 2>&1
  179.         done
  180.         while iptables -L OUTPUT 2> /dev/null | grep "PARANOIA-DROP" > /dev/null 2>&1
  181.         do
  182.                 iptables -D OUTPUT -o $wanif -m state --state NEW -j PARANOIA-DROP > /dev/null 2>&1
  183.         done
  184.         while iptables -L INPUT 2> /dev/null | grep "PARANOIA-DROP" > /dev/null 2>&1
  185.         do
  186.                 iptables -D INPUT -i $wanif -m state --state NEW -j PARANOIA-DROP > /dev/null 2>&1
  187.         done
  188.         iptables -F PARANOIA-DROP 2> /dev/null && plog "P2PArtisan: Removing paranoia block"
  189.         iptables -X PARANOIA-DROP 2> /dev/null
  190. }
  191.  
  192. pforcestop() {
  193.     echo -e "
  194. +------------------------- P2Partisan --------------------------+
  195. |                   _______ __              
  196. |                  |     __|  |_.-----.-----.
  197. |                  |__     |   _|  _  |  _  |
  198. |            Hard  |_______|____|_____|   __|
  199. |                                     |__|  
  200. |                                            
  201. +---------------------------------------------------------------+"
  202. counter=0
  203.         while iptables -L wanin 2> /dev/null | grep P2PARTISAN-IN > /dev/null 2>&1
  204.         do
  205.                 iptables -D wanin -i $wanif -m state --state NEW -j P2PARTISAN-IN > /dev/null 2>&1
  206.         done
  207.         while iptables -L wanout 2> /dev/null | grep P2PARTISAN-OUT > /dev/null 2>&1
  208.         do
  209.                 iptables -D wanout -o $wanif -m state --state NEW -j P2PARTISAN-OUT > /dev/null 2>&1
  210.         done
  211.         while iptables -L INPUT | grep P2PARTISAN-IN > /dev/null 2>&1
  212.         do
  213.                 iptables -D INPUT -i $wanif -m state --state NEW -j P2PARTISAN-IN > /dev/null 2>&1
  214.         done
  215.         while iptables -L OUTPUT | grep P2PARTISAN-OUT > /dev/null 2>&1
  216.         do
  217.                 iptables -D OUTPUT -o $wanif -m state --state NEW -j P2PARTISAN-OUT > /dev/null 2>&1
  218.         done
  219.  
  220. #Remove wanin/wanout. For P2Partisan-RMerlin compatibility only
  221.     if [ $rm -eq 1 ]; then
  222.         iptables -F wanin 2> /dev/null
  223.         iptables -X wanin 2> /dev/null
  224.         iptables -D FORWARD -i $wanif -j wanin 2> /dev/null
  225.         iptables -F wanout 2> /dev/null
  226.         iptables -X wanout 2> /dev/null
  227.         iptables -D FORWARD -o $wanif -j wanout 2> /dev/null
  228.     fi
  229. #
  230.         iptables -F P2PARTISAN-DROP-IN > /dev/null 2>&1
  231.         iptables -F P2PARTISAN-DROP-OUT > /dev/null 2>&1
  232.         iptables -F P2PARTISAN-LISTS-IN > /dev/null 2>&1
  233.         iptables -F P2PARTISAN-LISTS-OUT > /dev/null 2>&1      
  234.         iptables -F P2PARTISAN-IN > /dev/null 2>&1
  235.         iptables -F P2PARTISAN-OUT > /dev/null 2>&1
  236.         iptables -X P2PARTISAN-DROP-IN > /dev/null 2>&1    
  237.         iptables -X P2PARTISAN-DROP-OUT > /dev/null 2>&1
  238.         iptables -X P2PARTISAN-LISTS-IN > /dev/null 2>&1    
  239.         iptables -X P2PARTISAN-LISTS-OUT > /dev/null 2>&1
  240.         iptables -X P2PARTISAN-IN > /dev/null 2>&1
  241.         iptables -X P2PARTISAN-OUT > /dev/null 2>&1
  242.         ipset -F  > /dev/null 2>&1
  243.         for i in `ipset --list | grep Name | cut -f2 -d ":" `; do
  244.                 ipset -X $i > /dev/null 2>&1
  245.         done
  246.         chmod 777 ./*.gz > /dev/null 2>&1
  247.     [ -f iptables-add ] && rm iptables-add
  248.     [ -f iptables-del ] && rm iptables-del
  249.     [ -f ipset-del ] && rm ipset-del
  250.     [ -f $pidfile ] && rm -f "$pidfile" > /dev/null 2>&1
  251.     [ -f runtime ] && rm -f "runtime" > /dev/null 2>&1     
  252.     [ -f /tmp/p2partisan.loading ] && rm -r "status.loading" >/dev/null 2>&1
  253. plog " Unloading ipset modules"
  254.         lsmod | grep "ipt_set" > /dev/null 2>&1 && sleep 2 ; rmmod -f ipt_set > /dev/null 2>&1
  255.         lsmod | grep "ip_set_iptreemap" > /dev/null 2>&1 && sleep 2 ; rmmod -f ip_set_iptreemap > /dev/null 2>&1
  256.         lsmod | grep "ip_set" > /dev/null 2>&1 && sleep 2 ; rmmod -f ip_set > /dev/null 2>&1
  257. plog " Removing the list files"
  258.         cat blacklists |  grep -Ev "^#|^$" | tr -d "\r" |
  259.    (
  260.     while read line
  261.     do
  262.             counter=`expr $counter + 1`
  263.             name=`echo $line | awk '{print $1}'`
  264.             echo "| Removing blacklist #$counter --> ***$name***"
  265.                   [ -f ./$name.gz ] && rm -f ./$name.gz > /dev/null 2>&1
  266.                         done
  267.     )
  268. plog " P2Partisan stopped."
  269. echo -e "+---------------------------------------------------------------+"
  270. }
  271.  
  272. pstatus() {
  273. counter=0
  274.         running3=`iptables -L INPUT  2> /dev/null | grep P2PARTISAN-IN | wc -l`
  275.         running4=`[ -f $pidfile ] && echo 1 || echo 0`
  276.         running5=`nvram get script_fire | grep "p2partisan.sh ]" >/dev/null && echo "\033[1;32mYes\033[0;39m" || echo "\033[1;31mNo\033[0;39m"`
  277.         running6=`cru l | grep P2Partisan-update >/dev/null && echo "\033[1;32mYes\033[0;39m" || echo "\033[1;31mNo\033[0;39m"`
  278.         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'`
  279.        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'`        runningA=`cat $logfile | grep "Applying paranoia" | wc -l`
  280.         running9=`nvram get script_fire | grep "P2Partisan-tutor" >/dev/null && echo "\033[1;32mYes\033[0;39m" || echo "\033[1;31mNo\033[0;39m"`
  281.         logwin=`echo $(( $now - 86400 ))`
  282.         tail -1500 $logfile | grep -i "P2Partisan tutor" > /tmp/tutor.tmp  
  283.          cat /tmp/tutor.tmp |
  284.          (  
  285.          while read line
  286.          do
  287.                     logtime=`echo $line | awk '{print $3}'`
  288.                 if [[ `date -d"$logtime" +%s` -gt $logwin ]]; then
  289.                 echo $line >> /tmp/tutor.temp  
  290.                 fi
  291.         done
  292.         )
  293.         [ -f /tmp/tutor.temp ] && runningB=`wc -l /tmp/tutor.temp | awk '{print $1}'`
  294.         [ -f /tmp/tutor.tmp ] && rm /tmp/tutor.tmp; [ -f /tmp/tutor.temp ] && rm /tmp/tutor.temp || runningB=0
  295.         runningC=`cat blacklists | grep -Ev "^#|^$" | tr -d "\r" | wc -l`
  296.         runningD=`[ -f ./runtime ] && cat ./runtime`
  297.         runningF=`iptables -L P2PARTISAN-DROP-IN 2> /dev/null | grep DEBUG | wc -l`
  298.                 if [ -e ./iptables-add ]; then
  299.             from=`head -1 ./iptables-add 2> /dev/null | awk '{print $2}'`
  300.          runtime=`echo $(( $now - $from ))`
  301.                d=`echo $(( $runtime / 86400 ))`
  302.                h=`echo $((( $runtime / 3600 ) %24 ))`
  303.                m=`echo $((( $runtime / 60 ) %60 ))`
  304.                s=`echo $(( $runtime %60 ))`
  305.         runtime=`printf "$d - %02d:%02d:%02d\n" $h $m $s`
  306.                 fi
  307.         drop_packet_count_in=`iptables -vL P2PARTISAN-DROP-IN 2> /dev/null | grep " DROP " | awk '{print $1}'`
  308.        drop_packet_count_out=`iptables -vL P2PARTISAN-DROP-OUT 2> /dev/null | grep " REJECT " | awk '{print $1}'`
  309.             if [ -e ./iptables-debug-del ]; then
  310.           dfrom=`[ -f ./iptables-debug ] && head -1 ./iptables-debug 2> /dev/null | awk '{print $2}'`
  311.        druntime=`echo $(( $now - $dfrom ))`
  312.               h=`echo $((( $druntime / 3600 ) %24 ))`
  313.               m=`echo $((( $druntime / 60 ) %60 ))`
  314.               s=`echo $(( $druntime %60 ))`
  315.        druntime=`printf "%02d:%02d:%02d\n" $h $m $s`
  316.        dendtime=`[ -f ./iptables-debug-del ] && head -2 ./iptables-debug-del | tail -n 1 | awk '{print $2}'`
  317.           ttime=`echo $(( $dendtime / 60 ))`
  318.           ttime=`echo $(( $dfrom + $dendtime ))`
  319.         leftime=`echo $(( $ttime - $now ))`
  320.               m=`echo $((( $leftime / 60 ) %60 ))`
  321.               s=`echo $(( $leftime %60 ))`
  322.         leftime=`printf "%02d:%02d:%02d\n" $h $m $s`
  323.         zzztime=`echo $(( $dendtime / 60 ))`
  324.             fi
  325.        
  326.         if [[ $running3 -eq "0" ]] && [[ $running4 -eq "0" ]]; then
  327.                 running8="\033[1;31mNo\033[0;39m"
  328.         elif [[ $running3 -eq "0" ]] && [[ $running4 -eq "1" ]]; then
  329.                 running8="\033[1;35mLoading...\033[0;39m"
  330.         elif [[ $running3 -gt "0" ]] && [[ $running4 -eq "0" ]]; then
  331.                 running8="\033[1;31mNot quite... try to run \"p2partisan.sh update\"\033[0;39m"
  332.         else
  333.                 running8="\033[1;32mYes\033[0;39m"
  334.         fi
  335.        
  336.         if [[ $runningF -eq 1 ]]; then
  337.                 runningF="\033[1;35mOn\033[0;39m IP \033[1;33m`iptables -L P2PARTISAN-DROP-IN  2> /dev/null | grep DEBUG |  awk '{print $5}'` \033[1;33m$f\033[0;39mrunning for \033[1;33m$druntime\033[0;39m /\033[1;33m$zzztime\033[0;39m min (\033[1;33m$leftime\033[0;39m left)"
  338.         else
  339.                 runningF="Off"     
  340.         fi
  341.  
  342. 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`
  343. 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`
  344. if [[ $whiteextra == "0" ]]; then
  345. whiteextra=" "
  346. else
  347. whiteextra=`echo "/ $whiteextra" LAN IP ref defined`
  348. fi
  349. 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`
  350.      
  351. echo -e "
  352. +------------------------- P2Partisan --------------------------+
  353. |            _______ __          __              
  354. |           |     __|  |_.---.-.|  |_.--.--.-----.
  355. |           |__     |   _|  _  ||   _|  |  |__ --|
  356. |           |_______|____|___._||____|_____|_____|
  357. |  
  358. | Release version:  \033[1;37m$version\033[0;39m
  359. +---------------------------------------------------------------+
  360. |         Running:  $running8
  361. |         Autorun:  $running5
  362. |       Scheduled:  $running6 / \033[1;37m$runningA\033[0;39m since device boot
  363. |           Tutor:  $running9 / \033[1;37m$runningB\033[0;39m in the last 24h
  364. |        Debugger:  $runningF
  365. +---------------------------------------------------------------+
  366. | Partisan uptime:  \033[1;37m$runtime\033[0;39m
  367. |    Startup time:  \033[1;37m$runningD\033[0;39m seconds
  368. |      Dropped in:  \033[1;37m$drop_packet_count_in\033[0;39m
  369. |    Rejected out:  \033[1;37m$drop_packet_count_out\033[0;39m
  370. +---------------------------------------------------------------+
  371. |       Black IPs:  \033[1;37m$blackip\033[0;39m
  372. |       White IPs:  \033[1;37m$whiteip $whiteextra\033[0;39m"
  373. transmissionenable=`nvram get bt_enable`
  374. if [ -z $transmissionenable ]; then
  375.     echo "|  TransmissionBT:  Not available"
  376.  elif [ "$transmissionenable" = "0" ]; then
  377.     echo "|  TransmissionBT:  Off"
  378.  elif [ "$transmissionenable" = "1" ]; then
  379.     echo -e "|  TransmissionBT:  \033[1;37mOn\033[0;39m"
  380.     transmissionport=`nvram get bt_port 2> /dev/null`
  381.     greyports_tcp=$greyports_tcp,$transmissionport
  382.     greyports_udp=$greyports_udp,$transmissionport
  383. fi
  384. 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
  385.             echo -e "|  Grey ports TCP:  \033[1;37m$w\033[0;39m"
  386.                 done
  387. 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
  388.             echo -e "|  Grey ports UDP:  \033[1;37m$w\033[0;39m"
  389.                 done
  390. 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
  391.             echo -e "| White ports TCP:  \033[1;37m$w\033[0;39m"
  392.                 done
  393. 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
  394.             echo -e "| White ports UDP:  \033[1;37m$w\033[0;39m"
  395.                 done
  396.             echo -e "|     Black lists:  \033[1;37m$runningC\033[0;39m"    
  397.        
  398. echo "+----------------------- Logs max($maxloghour/hour) ----------------------+      
  399. $running7
  400. $running7a
  401. +---------------------------------------------------------------+"
  402. }
  403.  
  404.  
  405. if [ $autorun_availability_check = 1 ]; then
  406. av="while true; do [ -f $P2Partisandir/p2partisan.sh ] && break || sleep 5; done ;"
  407. fi
  408.  
  409. pautorunset() {
  410. echo -e "
  411. +------------------------- P2Partisan --------------------------+
  412. |            ______               __               __
  413. |           |      |.-----.-----.|  |_.----.-----.|  |
  414. |           |   ---||  _  |     ||   _|   _|  _  ||  |
  415. |           |______||_____|__|__||____|__| |_____||__|
  416. |                                                  
  417. +--------------------------- Autorun ---------------------------+"
  418.         p=`nvram get script_fire | grep "p2partisan.sh restart" | grep -v cru | wc -l`
  419.         if [ $p -eq "0" ] ; then
  420.                 t=`nvram get script_fire`; t=`printf "$t\n$av$P2Partisandir/p2partisan.sh restart\n"` ; nvram set "script_fire=$t"
  421.         fi
  422.         plog "P2Partisan AUTO RUN is ON"
  423.         echo "+---------------------------------------------------------------+"
  424.         nvram commit
  425. }
  426.  
  427. pautorununset() {
  428. echo -e "
  429. +------------------------- P2Partisan --------------------------+
  430. |            ______               __               __
  431. |           |      |.-----.-----.|  |_.----.-----.|  |
  432. |           |   ---||  _  |     ||   _|   _|  _  ||  |
  433. |           |______||_____|__|__||____|__| |_____||__|
  434. |                                                  
  435. +--------------------------- Autorun ---------------------------+"
  436.         p=`nvram get script_fire | grep "p2partisan.sh restart" | grep -v cru | wc -l`
  437.         if [ $p -eq "1" ]; then
  438.         t=`nvram get script_fire`; t=`printf "$t" | grep -v "p2partisan.sh restart"` ; nvram set "script_fire=$t"
  439.         fi
  440.         plog "P2Partisan AUTO RUN is OFF"
  441.         echo "+---------------------------------------------------------------+"
  442.         nvram commit
  443. }
  444.  
  445. pscheduleset() {
  446. echo -e "
  447. +------------------------- P2Partisan --------------------------+
  448. |            ______               __               __
  449. |           |      |.-----.-----.|  |_.----.-----.|  |
  450. |           |   ---||  _  |     ||   _|   _|  _  ||  |
  451. |           |______||_____|__|__||____|__| |_____||__|
  452. |                                                  
  453. +-------------------------- Scheduler --------------------------+"
  454.         cru d P2Partisan-update
  455.         e=`tr -cd 0-5 </dev/urandom | head -c 1`
  456.         f=`tr -cd 0-9 </dev/urandom | head -c 1`
  457.         a=`echo $e$f`
  458.  
  459.         b=`tr -cd 1-5 </dev/urandom | head -c 1`
  460.         c=`tr -cd 0-6 </dev/urandom | head -c 1`
  461.         d=`echo $c | sed -e 's/0/Sundays/' -e 's/1/Mondays/' -e 's/3/Tuesdays/' -e 's/4/Wednesys/' -e 's/5/Thursdays/' -e 's/6/Fridays/' -e 's/7/Saturdays/'`
  462.         scheduleme=`echo "$schedule" | sed s/m/$a/`
  463.         scheduleme=`echo "$scheduleme" | sed s/h/$b/`
  464.         scheduleme=`echo "$scheduleme" | sed s/d/$c/`
  465.         cru a P2Partisan-update "$scheduleme $P2Partisandir/p2partisan.sh paranoia-update"
  466.         pp=`nvram get script_fire | grep "p2partisan.sh paranoia-update" | grep -v cru | wc -l`
  467.         p=`nvram get script_fire | grep "cru a P2Partisan-update" | wc -l`
  468.         if [ $p -eq "0" ] ; then
  469.                 if [ $pp -eq "0" ]; then
  470.                 t=`nvram get script_fire`; t=`printf "$t\ncru a P2Partisan-update \"$scheduleme $P2Partisandir/p2partisan.sh paranoia-update\"\n"` ; nvram set "script_fire=$t"
  471.                 else
  472.                 pautorununset
  473.                 t=`nvram get script_fire`; t=`printf "$t\ncru a P2Partisan-update \"$scheduleme $P2Partisandir/p2partisan.sh paranoia-update\"\n"` ; nvram set "script_fire=$t"
  474.                 pautorunset
  475.                 fi
  476.         fi
  477.         plog "P2Partisan AUTO UPDATE is ON"
  478.         echo "| at $b:$a on $d
  479. +---------------------------------------------------------------+"
  480.         nvram commit
  481. }
  482.  
  483. pscheduleunset() {
  484. echo -e "
  485. +------------------------- P2Partisan --------------------------+
  486. |            ______               __               __
  487. |           |      |.-----.-----.|  |_.----.-----.|  |
  488. |           |   ---||  _  |     ||   _|   _|  _  ||  |
  489. |           |______||_____|__|__||____|__| |_____||__|
  490. |                                                  
  491. +-------------------------- Schedule ---------------------------+"
  492.         cru d P2Partisan-update
  493.         p=`nvram get script_fire | grep "cru a P2Partisan-update" | wc -l`
  494.         if [ $p -eq "1" ] ; then
  495.         t=`nvram get script_fire`; t=`printf "$t\ncru a P2Partisan-update \"$schedule $P2Partisandir/p2partisan.sh paranoia-update\"\n" | grep -v "cru a P2Partisan-update"` ; nvram set "script_fire=$t"
  496.         fi
  497.         plog "P2Partisan AUTO UPDATE is OFF"
  498.         echo "+---------------------------------------------------------------+"
  499.         nvram commit
  500. }
  501.  
  502. pdetective() {
  503. echo -e "
  504. +------------------------- P2Partisan --------------------------+
  505. |         __         __               __   __              
  506. |     .--|  |.-----.|  |_.-----.----.|  |_|__|.--.--.-----.
  507. |     |  _  ||  -__||   _|  -__|  __||   _|  ||  |  |  -__|
  508. |     |_____||_____||____|_____|____||____|__| \___/|_____|
  509. |
  510. +---------------------------------------------------------------+"
  511.  
  512. echo "| After an investigation it appears that the following socket/s
  513. | should be considered a greyports candidates. Consider adding the
  514. | ports under greyports_tcp & greyports_udp.
  515. +---------------------------------------------------------------+"
  516. 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
  517. echo "+---------------------------------------------------------------+"
  518. }
  519.  
  520. pupgrade() {
  521.         [ -f p2partisan_new.sh ] && rm -f "p2partisan_new.sh" 2> /dev/null
  522.         wget -q -O - http://pastebin.com/raw.php?i=eDgM0S5i | grep "p2partisan v" | grep -v grep> ./latest
  523.         latest=`cat ./latest | cut -c3-31`
  524.         current=`cat ./p2partisan.sh | grep "p2partisan v" | head -1 | cut -c3-32 `
  525.         if [[ "$latest" == "$current" ]]; then
  526.         echo "
  527. +------------------------- P2Partisan --------------------------+
  528. |          _______                            __        
  529. |         |   |   |.-----.-----.----.---.-.--|  |.-----.
  530. |         |   |   ||  _  |  _  |   _|  _  |  _  ||  -__|
  531. |         |_______||   __|___  |__| |___._|_____||_____|
  532. |                  |__|  |_____|                        
  533. |
  534. +---------------------------------------------------------------+
  535. You're already running the latest version of P2Partisan
  536. "
  537.         else
  538.         echo "
  539. +------------------------- P2Partisan --------------------------+
  540. |          _______                            __        
  541. |         |   |   |.-----.-----.----.---.-.--|  |.-----.
  542. |         |   |   ||  _  |  _  |   _|  _  |  _  ||  -__|
  543. |         |_______||   __|___  |__| |___._|_____||_____|
  544. |                  |__|  |_____|                        
  545. |
  546. +---------------------------------------------------------------+
  547. | There's a new P2Partisan update available. Do you want to upgrade?
  548. |  
  549. |                  current = $current
  550. |  
  551. |                          to
  552. |                      
  553. |                   latest = $latest
  554. |
  555. | y/n"
  556.         read answer
  557.                 if [[ $answer == "y" ]]; then
  558. wget -q -O ./p2partisan_new.sh http://pastebin.com/raw.php?i=eDgM0S5i
  559. pupgraderoutine
  560.                 else
  561.                 echo "| Upgrade skipped. Quitting...
  562. +---------------------------------------------------------------+"
  563.                 exit
  564.                 fi
  565.        
  566.         fi
  567.  }
  568.  
  569. pupgradebeta() {
  570.         [ -f p2partisan_new.sh ] && rm -f "p2partisan_new.sh" 2> /dev/null
  571.         wget -q -O - http://pastebin.com/raw.php?i=qe79uDJi | grep "p2partisan v" | grep -v grep > ./latest
  572.         echo "| Do you want to install the latest testing beta (not suggested)?
  573. |
  574. | y/n"
  575.         read answer
  576.                 if [[ $answer == "y" ]]; then
  577. wget -q -O ./p2partisan_new.sh http://pastebin.com/raw.php?i=qe79uDJi
  578. pupgraderoutine
  579.                 else
  580.                 echo "| Beta upgrade skipped. Quitting...
  581. +---------------------------------------------------------------+"
  582.                
  583.                 exit
  584.                 fi
  585.  }
  586.  
  587. pupgraderoutine() {
  588.                 echo "| Upgrading, please wait:"
  589.                 echo "| 1/6) Stopping the script"
  590.                 pforcestop
  591.                 [ -f p2partisan_new.sh ] || plog "There's a problem with the p2partisan upgrade. Please try again"
  592.                 echo "| 2/6) Migrating the configuration"
  593.                 sed '1,/P2Partisandir/{s@P2Partisandir=.*@'"P2Partisandir=$P2Partisandir"'@'} -i ./p2partisan_new.sh
  594.                 sed '1,/syslogs/{s@syslogs=.*@'"syslogs=$syslogs"'@'} -i ./p2partisan_new.sh
  595.                 sed '1,/maxloghour/{s@maxloghour=.*@'"maxloghour=$maxloghour"'@'} -i ./p2partisan_new.sh
  596.                 sed '1,/whiteports_tcp/{s@whiteports_tcp=.*@'"whiteports_tcp=$whiteports_tcp"'@'} -i ./p2partisan_new.sh
  597.                 sed '1,/whiteports_udp/{s@whiteports_udp=.*@'"whiteports_udp=$whiteports_udp"'@'} -i ./p2partisan_new.sh
  598.                 sed '1,/greyports_tcp/{s@greyports_tcp=.*@'"greyports_tcp=$greyports_tcp"'@'} -i ./p2partisan_new.sh
  599.                 sed '1,/greyports_udp/{s@greyports_udp=.*@'"greyports_udp=$greyports_udp"'@'} -i ./p2partisan_new.sh
  600.                 sed '1,/greyline/{s@greyline=.*@'"greyline=$greyline"'@'} -i ./p2partisan_new.sh
  601.                 sed '1,/fastroutine/{s@fastroutine=.*@'"fastroutine=$fastroutine"'@'} -i ./p2partisan_new.sh
  602.                 sed '1,/autorun_availability_check/{s@autorun_availability_check=.*@'"autorun_availability_check=$autorun_availability_check"'@'} -i ./p2partisan_new.sh
  603.                 sed '1,/schedule/{s@schedule=.*@'"schedule=\"$schedule\""'@'} -i ./p2partisan_new.sh
  604.                 sed '1,/testip/{s@testip=.*@'"testip=$testip"'@'} -i ./p2partisan_new.sh              
  605.                 tr -d "\r"< ./p2partisan_new.sh > ./.temp ; mv ./.temp ./p2partisan_new.sh
  606.                 echo "| 3/6) Copying p2partisan.sh into p2partisan.sh.old"
  607.                 cp ./p2partisan.sh ./p2partisan_old
  608.                 echo "| 4/6) Installing new script into p2partisan.sh"
  609.                 mv ./p2partisan_new.sh ./p2partisan.sh
  610.                 echo "| 5/6) Setting up permissions"
  611.                 chmod -R 777 ./p2partisan.sh
  612.                 echo -e "| 6/6) all done, \033[1;32mPlease run the script manually!\033[0;39m
  613. | NOTE: autorun, autoupdate and tutor settings are left as they were found
  614. +---------------------------------------------------------------+
  615. "
  616. exit
  617. }
  618.  
  619. ptutor() {
  620.         h=`date +%H`
  621.         pwhitelist
  622.         pblacklistcustom
  623.         running3=`iptables -L INPUT | grep P2PARTISAN-IN  2> /dev/null | wc -l`
  624.         running4=`[ -f $pidfile ] && echo 1 || echo 0`
  625.         runningE=`iptables -L wanin | grep P2PARTISAN-IN  2> /dev/null | wc -l`
  626.         cat blacklists |  grep -Ev "^#|^$" | tr -d "\r" |
  627.            (
  628.             while read line
  629.             do
  630.                     name=`echo $line | awk '{print $1}'`       
  631.                     iptables -L P2PARTISAN-LISTS-IN | grep $name > /dev/null || {
  632.                         plog "P2Partisan tutor had to reinstall the iptables due to: P2PARTISAN-LIST-IN $name instruction missing"
  633.                         ./iptables-del ; ./iptables-add
  634.                         exit
  635.                         }
  636.                     iptables -L P2PARTISAN-LISTS-OUT | grep $name  > /dev/null || {
  637.                         plog "P2Partisan tutor had to reinstall the iptables due to: P2PARTISAN-LIST-OUT $name instruction missing"
  638.                         ./iptables-del ; ./iptables-add
  639.                         exit
  640.                         }
  641.                 # age=`echo $((\`date +%s\` - \`date -r $name.cidr +%s\`))`
  642.                 # if [[ $age -gt "604800" ]] && [[ $h -le 6 ]] && [[ $h -ge 2 ]]; then
  643.                     # plog "P2Partisan is updating list $name"
  644.                     # pforcestop $name
  645.                 # exit 
  646.                 # fi
  647.             done
  648.             )
  649.                 if [[ $runningE -gt "1" ]]; then
  650.                         pforcestop
  651.                         plog "P2Partisan tutor had to restart due to: iptables redundant rules found"
  652.                         pstart
  653.                 elif [[ $running3 -eq "1" ]] && [[ $running4 -eq "0" ]]; then
  654.                         plog "P2Partisan tutor had to restart due to: pid file missing"
  655.                         pforcestop
  656.                         pstart
  657.                 elif [[ $running3 -eq "0" ]] && [[ $running4 -eq "1" ]]; then
  658.                         plog "P2Partisan tutor had to restart due to: iptables instructions missing"
  659.                         pforcestop
  660.                         pstart        
  661.                 elif [[ $running3 -ne "1" ]] && [[ $running4 -eq "1" ]]; then
  662.                         plog "P2Partisan appears to be loading, I'll wait 30 seconds..."    
  663.                         sleep 30
  664.                     if [[ $running3 -ne "1" ]] && [[ $running4 -eq "1" ]]; then
  665.                             plog "P2Partisan tutor had to restart due to Stuck on Loading"
  666.                             pforcestop
  667.                             pstart
  668.                     fi
  669.                 else
  670.                     echo -e "
  671. +------------------------- P2Partisan --------------------------+
  672. |                _______         __              
  673. |               |_     _|.--.--.|  |_.-----.----.
  674. |                 |   |  |  |  ||   _|  _  |   _|
  675. |                 |___|  |_____||____|_____|__|                                                  
  676. |
  677. +---------------------------------------------------------------+              
  678. | P2Partisan up and running. The tutor is happy
  679. +---------------------------------------------------------------+"
  680.         fi
  681. }
  682.  
  683. ptutorset() {
  684.         echo -e "
  685. +------------------------- P2Partisan --------------------------+
  686. |                _______         __              
  687. |               |_     _|.--.--.|  |_.-----.----.
  688. |                 |   |  |  |  ||   _|  _  |   _|
  689. |                 |___|  |_____||____|_____|__|                                                  
  690. |
  691. +-------------------------- Scheduler --------------------------+"
  692.         cru d P2Partisan-tutor
  693.         ab=`tr -cd 0-5 </dev/urandom | head -c 1`
  694.         a=`tr -cd 0-9 </dev/urandom | head -c 1`
  695.         a=`echo $ab$a`
  696.         scheduleme=`echo "$a * * * *"`
  697.         cru a P2Partisan-tutor "$scheduleme $P2Partisandir/p2partisan.sh tutor"
  698.         p=`nvram get script_fire | grep "cru a P2Partisan-tutor" | wc -l`
  699.         if [ $p -eq "0" ] ; then
  700.                 t=`nvram get script_fire`; t=`printf "$t\ncru a P2Partisan-tutor \"$scheduleme $P2Partisandir/p2partisan.sh tutor\"\n"` ; nvram set "script_fire=$t"
  701.         fi
  702.         plog "P2Partisan tutor is ON"
  703.         echo "+---------------------------------------------------------------+"
  704.         nvram commit
  705. }
  706.  
  707. ptutorunset() {
  708.         echo -e "
  709. +------------------------- P2Partisan --------------------------+
  710. |                _______         __              
  711. |               |_     _|.--.--.|  |_.-----.----.
  712. |                 |   |  |  |  ||   _|  _  |   _|
  713. |                 |___|  |_____||____|_____|__|                                                  
  714. |
  715. +-------------------------- Scheduler --------------------------+"
  716.         cru d P2Partisan-tutor
  717.         p=`nvram get script_fire | grep "cru a P2Partisan-tutor" | wc -l`
  718.         if [ $p -eq "1" ] ; then
  719.         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"
  720.         fi
  721.         plog "P2Partisan tutor is OFF"
  722.         echo "+---------------------------------------------------------------+"
  723.         nvram commit
  724.  }
  725.  
  726.  ptest() {
  727. checklist="blacklist-custom greylist whitelist `cat blacklists | grep -Ev "^#|^$" | tr -d "\r" | awk '{print $1}'`"
  728. echo -e "
  729. +------------------------- P2Partisan --------------------------+
  730. |                  _______               __  
  731. |                 |_     _|.-----.-----.|  |_
  732. |                   |   |  |  -__|__ --||   _|
  733. |                   |___|  |_____|_____||____|
  734. |                                              
  735. +----------- Lists are sorted in order of precedence -----------+"
  736.     if [[ -z $1 ]]; then
  737. echo "+---------------------------------------------------------------+
  738. | Invalid input. Please specify a valid IP address.
  739. +---------------------------------------------------------------+" 
  740.     else
  741.     test=$1
  742.     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
  743.     if [[ $test -eq 1 ]]; then
  744.     echo $checklist | tr " " "\n" |
  745.     (
  746.                 while read LIST
  747.                 do
  748.                 ipset -T $LIST $1 > /dev/null 2>&1 && if [ $LIST = "whitelist" ]; then echo -e "| \033[1;32m$1 found in        $LIST\033[0;39m"; else echo -e "| \033[1;31m$1 found in        $LIST\033[0;39m"; fi || echo -e "| $1 not found in    $LIST"
  749.         done                                                                                                                                    
  750.     )
  751.     echo "+---------------------------------------------------------------+
  752. |        in case of multiple match the first prevails
  753. +---------------------------------------------------------------+"
  754.     elif [[ $test -eq 0 ]]; then
  755.     echo "| Invalid input. Please specify a valid IP address.
  756. +---------------------------------------------------------------+" 
  757.     fi
  758. fi
  759. }
  760.  
  761. pdebug() {
  762. echo -e "
  763. +------------------------- P2Partisan --------------------------+
  764. |                _____         __                
  765. |               |     \.-----.|  |--.--.--.-----.
  766. |               |  --  |  -__||  _  |  |  |  _  |
  767. |               |_____/|_____||_____|_____|___  |
  768. |                                         |_____|
  769. |                                              
  770. +--------------------------- Guide -----------------------------+
  771. | Debug allows to fully log the P2Partisan interventions given a LAN IP
  772. | Maximum 1 debug at the time / Debug automatically times out or can be forced off manually
  773. +---------------------------------------------------------------+
  774. | p2partisan.sh debug <LAN IP> <minutes>    Syntax
  775. | p2partisan.sh debug                       Displays debug status and this help text
  776. | p2partisan.sh debug 192.168.0.3 <1-120>   Enables debug for the given LAN IP for N min (15 default)
  777. | p2partisan.sh debug 192.168.0.3 9         Enables debug for the given LAN IP for 9 min
  778. | p2partisan.sh debug reverse <1-120>       Enables debug for all the LAN IPs excluding greyports_tcp/udp
  779. | p2partisan.sh debug off                   Disable debug without waiting for the timer to timeout
  780. | p2partisan.sh debug-display <in|out>      Display logs Syntax
  781. | p2partisan.sh debug-display               Displays in&out debug logs + guide
  782. | p2partisan.sh debug-display out           Same as above but displays outbound records only
  783. +-------------------------- Activity ---------------------------+"
  784. 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
  785. echo "$1" | grep "reverse" >/dev/null 2>&1 && q=2
  786. echo "$1" | grep "off" >/dev/null 2>&1 && off=1 || off=0
  787.  
  788.                         if [ -e ./iptables-debug-del ]; then
  789.               dfrom=`head -1 ./iptables-debug 2> /dev/null | awk '{print $2}'`
  790.            druntime=`echo $(( $now - $dfrom ))`
  791.                   h=`echo $((( $druntime / 3600 ) %24 ))`
  792.                   m=`echo $((( $druntime / 60 ) %60 ))`
  793.                   s=`echo $(( $druntime %60 ))`
  794.            druntime=`printf "%02d:%02d:%02d\n" $h $m $s`
  795.            dendtime=`head -2 ./iptables-debug-del | tail -n 1 | awk '{print $2}'`
  796.               ttime=`echo $(( $dendtime / 60 ))`
  797.               ttime=`echo $(( $dfrom + $dendtime ))`
  798.             leftime=`echo $(( $ttime - $now ))`
  799.                   m=`echo $((( $leftime / 60 ) %60 ))`
  800.                   s=`echo $(( $leftime %60 ))`
  801.             leftime=`printf "%02d:%02d:%02d\n" $h $m $s`
  802.             zzztime=`echo $(( $dendtime / 60 ))`
  803.                         fi          
  804.  
  805.         if [[ $off -eq 1 ]]; then
  806.         f=`iptables -L P2PARTISAN-DROP-IN | grep DEBUG `
  807.         fc=`iptables -L P2PARTISAN-DROP-IN | grep DEBUG | wc -l`
  808.                 if [[ $fc -ge 1 ]]; then
  809.                 kill `ps | grep -E "sleep $dendtime$" | awk '{print $1}'` > /dev/null 2>&1
  810.                 plog "| All DEBUG activities have stopped"
  811.                 {
  812.         while iptables -L P2PARTISAN-DROP-IN | grep DEBUG
  813.         do
  814.                 iptables -D P2PARTISAN-DROP-IN 1
  815.                 done
  816.         while iptables -L P2PARTISAN-DROP-OUT | grep DEBUG
  817.         do
  818.                 iptables -D P2PARTISAN-DROP-OUT 1
  819.                 done
  820.                 } > /dev/null 2>&1
  821.                 echo -e "| Use \033[1;33m./p2partisan.sh debug-display\033[0;39m to show debug information, if any.
  822. +---------------------------------------------------------------+" ; exit
  823.                 else
  824.                         echo -e "| Debug is currently off and not collecting any information.
  825. | Use \033[1;33m./p2partisan.sh debug-display\033[0;39m to show existing debug information, if any.
  826. +---------------------------------------------------------------+" ; exit      
  827.                 fi
  828.         fi
  829.  
  830.         if [[ -z $1 ]]; then  
  831.                 f=`iptables -L P2PARTISAN-DROP-IN | grep DEBUG | awk '{print $5}' | head -1`
  832.                 fc=`iptables -L P2PARTISAN-DROP-IN | grep DEBUG | wc -l`
  833.                 if [[ $fc -gt 1 ]]; then
  834. echo -e "| P2partisan is currently debugging IP \033[1;33m$f\033[0;39m for \033[1;33m$druntime\033[0;39m /\033[1;33m$zzztime\033[0;39m min (\033[1;33m$leftime\033[0;39m left)
  835. | Use \033[1;33m./p2partisan.sh debug-display\033[0;39m to show debug information
  836. +---------------------------------------------------------------+" ; exit
  837.                 elif [[ $fc -eq 0 ]]; then
  838.                         echo -e "| Debug is currently off and not collecting any information.
  839. | Use \033[1;33m./p2partisan.sh debug-display\033[0;39m to show existing debug information, if any.
  840. +---------------------------------------------------------------+" ; exit
  841.                 fi
  842.         elif [[ $q -eq 1 ]]; then
  843.                         echo -e "| The input \033[1;31m$1\033[0;39m doesn't appear to be a valid IP
  844. +---------------------------------------------------------------+" ; exit
  845.         fi
  846.  
  847.         f=`iptables -L P2PARTISAN-DROP-IN | grep DEBUG | awk '{print $5}' | head -1`
  848.         fc=`iptables -L P2PARTISAN-DROP-IN | grep DEBUG | wc -l`
  849.         if [[ $fc -gt 1 ]]; then
  850. echo -e "| P2partisan is currently debugging IP \033[1;33m$f\033[0;39m for \033[1;33m$druntime\033[0;39m /\033[1;33m$zzztime\033[0;39m min (\033[1;33m$leftime\033[0;39m left)
  851. | NOTE: Only one debug at the time is possible! Command ignored.
  852. | Use \033[1;33m./p2partisan.sh debug-display\033[0;39m to show the debug information
  853. +---------------------------------------------------------------+" ; exit
  854.         fi
  855.  
  856. if [ -z $2 ]; then
  857.                 minutes=15
  858.                 time=900
  859. elif [[ $2 -gt 120 ]] || [[ $2 -eq 0 ]]; then
  860.                 echo "| Please specify an acceptable time: 1 to 60 (min). If omitted 15 will be used
  861. | Debug NOT enabled. Exiting...
  862. +---------------------------------------------------------------+" ; exit
  863. else
  864.                 minutes=$2
  865.                 time=` echo $(( $2 * 60 ))`
  866. fi
  867. if [[ $q -eq 2 ]]; then
  868. if [ -z $greyports_tcp ] || [ -z $greyports_udp ]; then
  869. echo -e "| It appears like you have no greyport set. This function due to the potential amount
  870. | of logging involved requires the both greyports_tcp and greyports_udp to be set
  871. | if unsure on what ports to use, try to run \033[1;33m./p2partisan.sh detective\033[0;39m
  872. +---------------------------------------------------------------+"
  873. exit
  874. fi
  875. echo "# $now
  876. iptables -I P2PARTISAN-DROP-IN 1 -p tcp --sport $greyports_tcp -j DROP
  877. iptables -I P2PARTISAN-DROP-IN 1 -p udp --sport $greyports_udp -j DROP
  878. iptables -I P2PARTISAN-DROP-IN 1 -p tcp --dport $greyports_tcp -j DROP
  879. iptables -I P2PARTISAN-DROP-IN 1 -p udp --dport $greyports_udp -j DROP
  880. iptables -I P2PARTISAN-DROP-OUT 1 -p tcp --sport $greyports_tcp -j DROP
  881. iptables -I P2PARTISAN-DROP-OUT 1 -p udp --sport $greyports_udp -j DROP
  882. iptables -I P2PARTISAN-DROP-OUT 1 -p tcp --dport $greyports_tcp -j DROP
  883. iptables -I P2PARTISAN-DROP-OUT 1 -p udp --dport $greyports_udp -j DROP
  884. iptables -I P2PARTISAN-DROP-IN 5 -j LOG --log-prefix 'P2Partisan-DEBUG-IN->> ' --log-level 1
  885. iptables -I P2PARTISAN-DROP-OUT 5 -j LOG --log-prefix 'P2Partisan-DEBUG-OUT->> ' --log-level 1" > ./iptables-debug
  886. chmod 777 ./iptables-debug  > /dev/null 2>&1
  887. plog "Reverse Debug started for for $minutes minute"
  888. ./iptables-debug 1>/dev/null &
  889.                 echo -e "| Enabled full debug logging for all the LAN IPs for \033[1;32m$minutes\033[0;39m minutes
  890. | This excludes the greyports_tcp $greyports_tcp and greyports_udp $greyports_udp              
  891. | Use \033[1;33m./p2partisan.sh debug-display\033[0;39m to show the debug information
  892. +---------------------------------------------------------------+"
  893.  
  894. echo "# $now
  895. sleep $time
  896. iptables -D P2PARTISAN-DROP-IN -p tcp -m tcp --sport $greyports_tcp -j DROP
  897. iptables -D P2PARTISAN-DROP-IN -p udp -m udp --sport $greyports_udp -j DROP
  898. iptables -D P2PARTISAN-DROP-IN -p tcp -m tcp --dport $greyports_tcp -j DROP
  899. iptables -D P2PARTISAN-DROP-IN -p udp -m udp --dport $greyports_udp -j DROP
  900. iptables -D P2PARTISAN-DROP-OUT -p tcp -m tcp --sport $greyports_tcp -j DROP
  901. iptables -D P2PARTISAN-DROP-OUT -p udp -m udp --sport $greyports_udp -j DROP
  902. iptables -D P2PARTISAN-DROP-OUT -p tcp -m tcp --dport $greyports_tcp -j DROP
  903. iptables -D P2PARTISAN-DROP-OUT -p udp -m udp --dport $greyports_udp -j DROP
  904. iptables -D P2PARTISAN-DROP-IN -j LOG --log-prefix 'P2Partisan-DEBUG-IN->> ' --log-level 1
  905. iptables -D P2PARTISAN-DROP-OUT -j LOG --log-prefix 'P2Partisan-DEBUG-OUT->> ' --log-level 1" > ./iptables-debug-del
  906. chmod 777 ./iptables-debug-del 2> /dev/null
  907. ./iptables-debug-del 1>/dev/null &
  908. else
  909. echo "# $now
  910. iptables -I P2PARTISAN-DROP-IN 1 -d $1 -j LOG --log-prefix \"P2Partisan-DEBUG-IN->> \" --log-level 1 > /dev/null 2>&1
  911. iptables -I P2PARTISAN-DROP-OUT 1 -s $1 -j LOG --log-prefix \"P2Partisan-DEBUG-OUT->> \" --log-level 1 > /dev/null 2>&1" > ./iptables-debug
  912. chmod 777 ./iptables-debug  > /dev/null 2>&1
  913. plog "Debug started for IP $1 for $minutes minute"
  914. ./iptables-debug 1>/dev/null &
  915.                 echo -e "| Enabled full debug logging for LAN IP \033[1;32m$1\033[0;39m for \033[1;32m$minutes\033[0;39m minutes
  916. | Use \033[1;33m./p2partisan.sh debug-display\033[0;39m to show the debug information
  917. +---------------------------------------------------------------+"
  918.  
  919. echo "# $now
  920. sleep $time
  921. iptables -D P2PARTISAN-DROP-IN -d $1 -j LOG --log-prefix \"P2Partisan-DEBUG-IN->> \" --log-level 1  > /dev/null 2>&1
  922. iptables -D P2PARTISAN-DROP-OUT -s $1 -j LOG --log-prefix \"P2Partisan-DEBUG-OUT->> \" --log-level 1 > /dev/null 2>&1" > ./iptables-debug-del
  923. chmod 777 ./iptables-debug-del 2> /dev/null
  924. ./iptables-debug-del 1>/dev/null &
  925. fi
  926. }
  927.  
  928. pdebugdisplay() {
  929. echo -e "
  930. +------------------------- P2Partisan --------------------------+
  931. _____         __                          __ __               __              
  932. |     \.-----.|  |--.--.--.-----.______.--|  |__|.-----.-----.|  |.---.-.--.--.
  933. |  --  |  -__||  _  |  |  |  _  |______|  _  |  ||__ --|  _  ||  ||  _  |  |  |
  934. |_____/|_____||_____|_____|___  |      |_____|__||_____|   __||__||___._|___  |
  935.                         |_____|                      |__|             |_____|
  936.  
  937. +---------------------------------------------------------------+
  938. | p2partisan.sh debug-display               Displays in & outbound debug logs
  939. | p2partisan.sh debug-display in            Displays inbound debug logs only
  940. | p2partisan.sh debug-display out           Displays outbound debug logs only
  941. +-------------------------- Drop Logs --------------------------+"
  942.  
  943.    dfrom=`head -1 ./iptables-debug 2> /dev/null | awk '{print $2}'`
  944. druntime=`echo $(( $now - $dfrom ))`
  945.       h=`echo $((( $druntime / 3600 ) %24 ))`
  946.       m=`echo $((( $druntime / 60 ) %60 ))`
  947.       s=`echo $(( $druntime %60 ))`
  948. druntime=`printf "%02d:%02d:%02d\n" $h $m $s`
  949. dendtime=`head -2 ./iptables-debug-del | tail -n 1 | awk '{print $2}'`
  950.   ttime=`echo $(( $dendtime / 60 ))`
  951.   ttime=`echo $(( $dfrom + $dendtime ))`
  952. leftime=`echo $(( $ttime - $now ))`
  953.       m=`echo $((( $leftime / 60 ) %60 ))`
  954.       s=`echo $(( $leftime %60 ))`
  955. leftime=`printf "%02d:%02d:%02d\n" $h $m $s`
  956. zzztime=`echo $(( $dendtime / 60 ))`
  957.  
  958. c=0
  959. rm ./debug.rev  > /dev/null 2>&1
  960. tail -800 $logfile | grep -i "P2Partisan" > ./debug.log
  961. cat ./debug.log | sed '1!G;h;$!d' |
  962.  (  
  963.  while read line
  964.  do
  965. testo=`echo $line | grep "Debug started for IP" | wc -l`
  966. if [[ $testo -ge 1 ]]; then
  967.         echo $line >> ./debug.rev
  968.         cat ./debug.rev | sed '1!G;h;$!d' > ./debug.log
  969.         rm ./debug.rev  > /dev/null 2>&1
  970.         exit
  971. else
  972.         echo $line >> ./debug.rev
  973. fi
  974. done
  975. )
  976.  
  977. if [ -z $1 ]; then
  978.         echo -e "\033[48;5;89m+----------------------- INPUT & OUTPUT ------------------------+\033[0m"
  979.         head -1 ./debug.log
  980.         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
  981.           [ $(($c%2)) -eq 1 ] && printf "\e[100m"
  982.           printf "%s\033[0m\n" "$line"
  983.           c=$(($c+1))
  984.                 done
  985.         fc=`iptables -L P2PARTISAN-DROP-IN | grep DEBUG | wc -l`
  986.                 if [[ $fc -ge 1 ]]; then
  987.                 echo -e "\e[93mNOTE: debugging is active for $druntime /$zzztime min ($leftime left). Run this command again to update the report\033[0m"
  988.                 fi
  989.         echo -e "\033[48;5;89m+----------------------- INPUT & OUTPUT ------------------------+\033[0m"
  990. elif [[ $1 = "in" ]]; then
  991.         echo -e "\033[48;5;89m+--------------------------- INPUT -----------------------------+\033[0m"
  992.         head -1 ./debug.log
  993.         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
  994.           [ $(($c%2)) -eq 1 ] && printf "\e[100m"
  995.           printf "%s\033[0m\n" "$line"
  996.           c=$(($c+1))
  997.                 done
  998.         fc=`iptables -L P2PARTISAN-DROP-IN | grep DEBUG | wc -l`
  999.                 if [[ $fc -ge 1 ]]; then
  1000.                 echo -e "\e[93mNOTE: debugging is active for $druntime /$zzztime min ($leftime left). Run this command again to update the report\033[0m"
  1001.                 fi
  1002.         echo -e "\033[48;5;89m+--------------------------- INPUT -----------------------------+\033[0m"
  1003. elif [[ $1 = "out" ]]; then
  1004.                 echo -e "\033[48;5;89m+--------------------------- OUTPUT ----------------------------+\033[0m"
  1005.                 head -1 ./debug.log
  1006.         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
  1007.           [ $(($c%2)) -eq 1 ] && printf "\e[100m"
  1008.           printf "%s\033[0m\n" "$line"
  1009.           c=$(($c+1))
  1010.                 done
  1011.         fc=`iptables -L P2PARTISAN-DROP-IN | grep DEBUG | wc -l`
  1012.                 if [[ $fc -ge 1 ]]; then
  1013.                 echo -e "\e[93mNOTE: debugging is active for $druntime /$zzztime min ($leftime left). Run this command again to update the report\033[0m"
  1014.                 fi
  1015.                 echo -e "\033[48;5;89m+--------------------------- OUTPUT ----------------------------+\033[0m"
  1016. fi
  1017.     echo -e "+---------------------------------------------------------------+"
  1018. }
  1019.  
  1020. pwhitelist() {
  1021.     ipset -F whitelist
  1022.     [ -f ./whitelist ] && cat ./whitelist | grep -Ev "^#|^$" | tr -d "\r" |
  1023.     (
  1024.     while read IP
  1025.     do
  1026.         q=100
  1027.         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
  1028.         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
  1029.         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
  1030.         echo "$IP" | awk '{print $2}' | grep -E '^(http)' >/dev/null 2>&1 && q=4
  1031.  
  1032.     if [[ $q -eq 0 ]]; then
  1033.                 ipset -A whitelist $IP  2> /dev/null
  1034.     elif [[ $q -eq 1 ]]; then
  1035.         nslookup $IP | grep "Address [0-9]*:" | grep -v 127.0.0.1 | grep -v "\:\:" | grep -Eo "([0-9\.]{7,15})" |
  1036.                 while read IPO
  1037.                 do
  1038.                 ipset -A whitelist $IPO 2> /dev/null
  1039.                 done
  1040.     elif [[ $q -eq 3 ]]; then
  1041.                 ipset -A whitelist $IP 2> /dev/null
  1042.     elif [[ $q -eq 4 ]]; then
  1043.                 name=`echo $IP | awk '{print $1}'`
  1044.                 url=`echo $IP | awk '{print $2}'`
  1045.                 [ -e $name.lst ] || wget -q -O - "$url" | \
  1046.                 gunzip | cut -d: -f2 > $name.lst
  1047.                     for IPO in $(cat $name.lst)
  1048.                     do
  1049.                         ipset -A whitelist $IPO 2> /dev/null
  1050.                     done
  1051.     fi
  1052.     done
  1053.     )
  1054. }
  1055.  
  1056. pblacklistcustom() {
  1057.     ipset -F blacklist-custom
  1058.     [ -f ./blacklist-custom ] && cat ./blacklist-custom | grep -Ev "^#|^$" | tr -d "\r" |
  1059.     (
  1060.     while read IP
  1061.     do             
  1062.         q=100
  1063.         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
  1064.         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
  1065.         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
  1066.  
  1067.     if [[ $q -eq 0 ]]; then
  1068.                 ipset -A blacklist-custom $IP 2> /dev/null
  1069.     elif [[ $q -eq 1 ]]; then
  1070.         nslookup $IP | grep "Address [0-9]*:" | grep -v 127.0.0.1 | grep -v "\:\:" | grep -Eo "([0-9\.]{7,15})" |
  1071.                 while read IPO
  1072.                 do
  1073.                 ipset -A blacklist-custom $IPO 2> /dev/null
  1074.                 done
  1075.     elif [[ $q -eq 3 ]]; then
  1076.                 ipset -A blacklist-custom $IP 2> /dev/null
  1077.     fi
  1078.     done
  1079.     )  
  1080. }
  1081.    
  1082. pstart() {
  1083.         if [[ $paranoiastuck -gt 1 ]]; then
  1084.         punblock
  1085.         fi
  1086.        
  1087.         running4=`[ -f $pidfile ] && echo 1 || echo 0`
  1088.         if [ $running4 -eq "0" ] ; then
  1089.  
  1090.         [ -f /tmp/p2partisan.loading ] && echo "P2Partisan is still loading. Exiting..." && exit
  1091.         touch /tmp/p2partisan.loading
  1092.  
  1093.         /bin/ntpsync > /dev/null 2>&1
  1094.         pre=`date +%s`
  1095.         sleep 1
  1096.  
  1097.         echo $$ > $pidfile
  1098.        
  1099.     [ -e iptables-add ] && rm iptables-add
  1100.     [ -e iptables-del ] && rm iptables-del
  1101.     [ -e ipset-del ] && rm ipset-del
  1102.  
  1103.     echo -e "
  1104. +------------------------- P2Partisan --------------------------+
  1105. |                 _______ __               __  
  1106. |                |     __|  |_.---.-.----.|  |_
  1107. |                |__     |   _|  _  |   _||   _|
  1108. |                |_______|____|___._|__|  |____|
  1109. |                                            
  1110. +---------------------------------------------------------------+
  1111. +--------- PREPARATION --------"
  1112.         echo "| Loading the ipset modules"
  1113.         lsmod | awk '{print $1}' | grep "ip_set" > /dev/null 2>&1 || insmod ip_set
  1114.         lsmod | awk '{print $1}' | grep "ip_set_iptreemap" > /dev/null 2>&1 || insmod ip_set_iptreemap
  1115.         lsmod | awk '{print $1}' | grep "ipt_set" > /dev/null 2>&1 || insmod ipt_set
  1116.  
  1117. counter=0
  1118. pos=1
  1119.  
  1120.                 echo "+---- CUSTOM IP BLACKLIST -----
  1121. | preparing blacklist-custom ..."
  1122.                 echo "| Loading blacklist #$counter --> ***Custom IP blacklist***"
  1123.         if [ "$(ipset --swap blacklist-custom blacklist-custom 2>&1 | grep 'Unknown set')" != "" ]
  1124.             then
  1125.             ipset --create blacklist-custom iptreemap > /dev/null 2>&1
  1126.             fi             
  1127.     pblacklistcustom               
  1128.  
  1129. [ -e /tmp/iptables-add.tmp ] && rm /tmp/iptables-add.tmp > /dev/null 2>&1
  1130. echo "+--------- GREYPORTs ----------"
  1131. 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
  1132.             echo "| Loading grey TCP ports  $w"
  1133.             echo "iptables -A P2PARTISAN-IN -i $wanif -p tcp --match multiport --dports $w -g P2PARTISAN-LISTS-IN 2> /dev/null
  1134. iptables -A P2PARTISAN-OUT -o $wanif -p tcp --match multiport --sports $w -g P2PARTISAN-LISTS-OUT 2> /dev/null" >> /tmp/iptables-add.tmp
  1135. done
  1136. 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
  1137.             echo "| Loading grey UDP ports  $w"
  1138.             echo "iptables -A P2PARTISAN-IN -i $wanif -p udp --match multiport --dports $w -g P2PARTISAN-LISTS-IN 2> /dev/null
  1139. iptables -A P2PARTISAN-OUT -o $wanif -p udp --match multiport --sports $w -g P2PARTISAN-LISTS-OUT 2> /dev/null" >> /tmp/iptables-add.tmp
  1140. done
  1141. # Get transmission port for greylisting if enabled
  1142. transmissionenable=`nvram get bt_enable`
  1143. if [ -z $transmissionenable ]; then
  1144.     echo "|  TransmissionBT:  Not available"
  1145.   elif [ "$transmissionenable" = "0" ]; then
  1146.     echo "|  TransmissionBT:  Off"
  1147.   elif [ "$transmissionenable" = "1" ]; then
  1148.     echo "|  TransmissionBT:  On"
  1149.     transmissionport=`nvram get bt_port 2> /dev/null`
  1150.     wanip=`nvram get wan_ipaddr`
  1151.     p3=`echo $greyports_tcp | grep -Eo '$transmissionport' | wc -l`
  1152.     p4=`echo $greyports_udp | grep -Eo '$transmissionport' | wc -l`
  1153.         if [ $p3 -eq "0" ]; then
  1154.                         echo "iptables -A P2PARTISAN-IN -i $wanif -p tcp -d $wanip --dport $transmissionport -g P2PARTISAN-LISTS-IN
  1155. iptables -A P2PARTISAN-OUT -o $wanif -p tcp -s $wanip --sport $transmissionport -g P2PARTISAN-LISTS-OUT
  1156. iptables -A P2PARTISAN-OUT -o $wanif -p tcp -s $wanip --sport 49152:65535 -g P2PARTISAN-LISTS-OUT" >> /tmp/iptables-add.tmp
  1157.         fi            
  1158.         if [ $p4 -eq "0" ]; then
  1159.                         echo "iptables -A P2PARTISAN-IN -i $wanif -p udp -d $wanip --dport $transmissionport -g P2PARTISAN-LISTS-IN
  1160. iptables -A P2PARTISAN-OUT -o $wanif -p udp -s $wanip --sport $transmissionport -g P2PARTISAN-LISTS-OUT
  1161. iptables -A P2PARTISAN-OUT -o $wanif -p udp -s $wanip --sport 49152:65535 -g P2PARTISAN-LISTS-OUT" >> /tmp/iptables-add.tmp
  1162.         fi
  1163. fi
  1164.        
  1165. echo "+--------- WHITEPORTs ---------"
  1166. 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
  1167.         echo "| Loading white TCP ports $w"
  1168.         echo "iptables -A P2PARTISAN-IN -i $wanif -p tcp --match multiport --sports $w -j RETURN 2> /dev/null
  1169. iptables -A P2PARTISAN-IN -i $wanif -p tcp --match multiport --dports $w -j RETURN 2> /dev/null
  1170. iptables -A P2PARTISAN-OUT -o $wanif -p tcp --match multiport --sports $w -j RETURN 2> /dev/null
  1171. iptables -A P2PARTISAN-OUT -o $wanif -p tcp --match multiport --dports $w -j RETURN 2> /dev/null" >> /tmp/iptables-add.tmp
  1172.         done
  1173. 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
  1174.         echo "| Loading white UDP ports $w"
  1175.         echo "iptables -A P2PARTISAN-IN -i $wanif -p udp --match multiport --sports $w -j RETURN 2> /dev/null
  1176. iptables -A P2PARTISAN-IN -i $wanif -p udp --match multiport --dports $w -j RETURN 2> /dev/null
  1177. iptables -A P2PARTISAN-OUT -o $wanif -p udp --match multiport --sports $w -j RETURN 2> /dev/null
  1178. iptables -A P2PARTISAN-OUT -o $wanif -p udp --match multiport --dports $w -j RETURN 2> /dev/null" >> /tmp/iptables-add.tmp
  1179.         done
  1180. echo "iptables -A P2PARTISAN-IN -j P2PARTISAN-LISTS-IN 2> /dev/null
  1181. iptables -A P2PARTISAN-OUT -j P2PARTISAN-LISTS-OUT 2> /dev/null" >> /tmp/iptables-add.tmp
  1182.        
  1183.                 echo "# $now
  1184. iptables -N P2PARTISAN-IN 2> /dev/null
  1185. iptables -N P2PARTISAN-OUT 2> /dev/null
  1186. iptables -N P2PARTISAN-LISTS-IN 2> /dev/null
  1187. iptables -N P2PARTISAN-LISTS-OUT 2> /dev/null
  1188. iptables -N P2PARTISAN-DROP-IN 2> /dev/null
  1189. iptables -N P2PARTISAN-DROP-OUT 2> /dev/null
  1190. iptables -F P2PARTISAN-IN 2> /dev/null
  1191. iptables -F P2PARTISAN-OUT 2> /dev/null
  1192. iptables -F P2PARTISAN-LISTS-IN 2> /dev/null
  1193. iptables -F P2PARTISAN-LISTS-OUT 2> /dev/null
  1194. iptables -F P2PARTISAN-DROP-IN 2> /dev/null
  1195. iptables -F P2PARTISAN-DROP-OUT 2> /dev/null
  1196. iptables -A P2PARTISAN-IN -m set --set blacklist-custom src -j P2PARTISAN-DROP-IN 2> /dev/null
  1197. iptables -A P2PARTISAN-OUT -m set --set blacklist-custom dst -j P2PARTISAN-DROP-OUT 2> /dev/null" > iptables-add
  1198.  
  1199. #Add winin/wanout. For P2Partisan-RMerlin compatibility only
  1200. if [ $rm -eq 1 ]; then
  1201.     echo "iptables -N wanin" >> ./iptabled-add
  1202.     echo "iptables -I FORWARD 1 -i $wanif -j wanin 2> /dev/null" >> ./iptabled-add
  1203.     echo "iptables -N wanout" >> ./iptabled-add
  1204.     echo "iptables -I FORWARD 2 -o $wanif -j wanout 2> /dev/null" >> iptables-add
  1205. fi
  1206. #
  1207.                
  1208.                 echo "# $now" >> iptables-del
  1209. [ -f ./custom-script-del ] && cat ./custom-script-del >> iptables-del
  1210. echo "iptables -D wanin -i $wanif -m state --state NEW -j P2PARTISAN-IN
  1211. iptables -D wanout -o $wanif -m state --state NEW -j P2PARTISAN-OUT
  1212. iptables -D INPUT -i $wanif -m state --state NEW -j P2PARTISAN-IN
  1213. iptables -D OUTPUT -o $wanif -m state --state NEW -j P2PARTISAN-OUT
  1214. iptables -F P2PARTISAN-DROP-IN
  1215. iptables -F P2PARTISAN-DROP-OUT
  1216. iptables -F P2PARTISAN-LISTS-IN
  1217. iptables -F P2PARTISAN-LISTS-OUT
  1218. iptables -F P2PARTISAN-IN
  1219. iptables -F P2PARTISAN-OUT
  1220. iptables -X P2PARTISAN-IN
  1221. iptables -X P2PARTISAN-OUT
  1222. iptables -X P2PARTISAN-LISTS-IN
  1223. iptables -X P2PARTISAN-LISTS-OUT
  1224. iptables -X P2PARTISAN-DROP-IN
  1225. iptables -X P2PARTISAN-DROP-OUT" >> iptables-del
  1226.                
  1227. echo "+--------- WHITE IPs ---------"
  1228. echo "| preparing IP whitelist ..."
  1229. #Load the whitelist
  1230.     if [ "$(ipset --swap whitelist whitelist 2>&1 | grep 'Unknown set')" != "" ]
  1231.         then
  1232.         ipset --create whitelist iptreemap > /dev/null 2>&1
  1233.     fi
  1234.     pwhitelist
  1235.  
  1236.     echo "# $now
  1237. ipset -F
  1238. ipset -X blacklist-custom
  1239. ipset -X whitelist" > ipset-del
  1240.  
  1241.                         echo "| Loading IP whitelist"
  1242.                         echo "iptables -A P2PARTISAN-IN -m set --set whitelist src -j RETURN > /dev/null 2>&1
  1243. iptables -A P2PARTISAN-IN -m set --set whitelist dst -j RETURN > /dev/null 2>&1
  1244. iptables -A P2PARTISAN-OUT -m set --set whitelist src -j RETURN > /dev/null 2>&1
  1245. iptables -A P2PARTISAN-OUT -m set --set whitelist dst -j RETURN > /dev/null 2>&1" >> iptables-add
  1246.  
  1247. cat /tmp/iptables-add.tmp >> iptables-add
  1248. rm /tmp/iptables-add.tmp > /dev/null 2>&1
  1249.  
  1250.                 if [ $syslogs -eq "1" ]; then        
  1251. echo "iptables -A P2PARTISAN-DROP-IN -m limit --limit $maxloghour/hour --limit-burst 1 -j LOG --log-prefix \"P2Partisan Dropped IN >> \" --log-level 1 2> /dev/null
  1252. iptables -A P2PARTISAN-DROP-OUT -m limit --limit $maxloghour/hour --limit-burst 1 -j LOG --log-prefix \"P2Partisan Rejected OUT >> \" --log-level 1 2> /dev/null" >> iptables-add
  1253.  
  1254.                 fi
  1255.                 echo "iptables -A P2PARTISAN-DROP-IN -j DROP
  1256. iptables -A P2PARTISAN-DROP-OUT -j REJECT --reject-with icmp-admin-prohibited"  >> iptables-add
  1257.  
  1258.  
  1259. echo "+------- IP BLACKLISTs -------"
  1260.        
  1261.         cat blacklists | grep -Ev "^#|^$" | tr -d "\r" |
  1262.    (
  1263.     while read line
  1264.     do
  1265.             counter=`expr $counter + 1`
  1266.             name=`echo $line | awk '{print $1}'`
  1267.             url=`echo $line | awk '{print $2}'`
  1268.             echo "| loading blacklist #$counter --> ***$name***"
  1269.      
  1270.     if [ $fastroutine -eq "1" ]; then
  1271.      
  1272.      if [ "$(ipset --swap $name $name 2>&1 | grep 'Unknown set')" != "" ]
  1273.       then
  1274.                   [ -e ./runtime ] && rm -f ./runtime 2> /dev/null
  1275.                   [ -e $name.gz ] || wget -q -O $name.gz "$url"
  1276.                   { echo "-N $name iptreemap"
  1277.                         gunzip -c  $name.gz | \
  1278.                         sed -e "/^[\t ]*#.*\|^[\t ]*$/d;s/^.*:/-A $name /" | \
  1279.                         grep -Ev '(^10\.|(^172\.1[6-9]\.|^172\.2[0-9]\.|^172\.3[0-1]\.)|^192\.168\.)'
  1280.                         echo COMMIT
  1281.                   } | ipset -R
  1282.      fi
  1283.     else
  1284.      
  1285.                 if [ "$(ipset --swap $name $name 2>&1 | grep 'Unknown set')" != "" ]
  1286.             then
  1287.                         [ -e ./runtime ] && rm -f ./runtime 2> /dev/null
  1288.             ipset --create $name iptreemap
  1289.             [ -e $name.lst ] || wget -q -O - "$url" | gunzip | cut -d: -f2 | grep -E "^[-0-9.]+$" | grep -Ev '(^10\.|(^172\.1[6-9]\.|^172\.2[0-9]\.|^172\.3[0-1]\.)|^192\.168\.)' > $name.lst
  1290.             for IP in $(cat $name.lst)
  1291.                     do
  1292.                     ipset -A $name $IP  2> /dev/null
  1293.                     done
  1294.                         fi
  1295.                          
  1296.         fi
  1297.  
  1298.                                 echo "ipset -X $name " >> ipset-del
  1299.                                 echo "iptables -A P2PARTISAN-LISTS-IN -m set --set $name src -j P2PARTISAN-DROP-IN 2> /dev/null
  1300. iptables -A P2PARTISAN-LISTS-OUT -m set --set $name dst -j P2PARTISAN-DROP-OUT 2> /dev/null" >> iptables-add
  1301.                         done
  1302. echo "iptables -A P2PARTISAN-LISTS-IN -i $wanif -j RETURN 2> /dev/null
  1303. iptables -A P2PARTISAN-LISTS-OUT -o $wanif -j RETURN 2> /dev/null" >> iptables-add
  1304.     )
  1305.  
  1306.  
  1307. echo "iptables -I INPUT $pos -i $wanif -m state --state NEW -j P2PARTISAN-IN 2> /dev/null
  1308. iptables -I OUTPUT $pos -o $wanif -m state --state NEW -j P2PARTISAN-OUT 2> /dev/null
  1309. iptables -I wanin $pos -i $wanif -m state --state NEW -j P2PARTISAN-IN 2> /dev/null
  1310. iptables -I wanout $pos -o $wanif -m state --state NEW -j P2PARTISAN-OUT 2> /dev/null" >> iptables-add
  1311.  
  1312. #Remove wanin/wanout. For P2Partisan-RMerlin compatibility only
  1313. if [ $rm -eq 1 ]; then
  1314.     echo "iptables -F wanin 2> /dev/null" >> ./iptabled-del
  1315.     echo "iptables -X wanin 2> /dev/null" >> ./iptabled-del
  1316.     echo "iptables -D FORWARD -i $wanif -j wanin 2> /dev/null" >> ./iptable-del
  1317.     echo "iptables -F wanout 2> /dev/null" >> ./iptabled-del
  1318.     echo "iptables -X wanout 2> /dev/null" >> ./iptabled-del
  1319.     echo "iptables -D FORWARD -o $wanif -j wanout 2> /dev/null" >> iptables-del
  1320. fi
  1321. #
  1322.  
  1323. [ -f ./custom-script-add ] && cat ./custom-script-add >> iptables-add
  1324.  
  1325. chmod 777 ./iptables-*
  1326. chmod 777 ./ipset-*
  1327. ./iptables-add  #protecting
  1328.  
  1329. plog "... P2Partisan started"
  1330. echo "+------------------------- Controls ----------------------------+"
  1331.  
  1332. p=`nvram get dnsmasq_custom | grep log-async | wc -l`
  1333. if [ $p -eq "1" ]; then
  1334.         plog "log-async found under dnsmasq -> OK"
  1335. echo "+---------------------------------------------------------------+"
  1336. else
  1337.         plog "
  1338. | It appears like you don't have a log-async parameter in your dnsmasq
  1339. | config. This is strongly suggested due to the amount of logs involved,
  1340. | especially while debugging to consider adding the following command
  1341. | under Advanced/DHCP/DNS/Dnsmasq Custom configuration:
  1342. |  
  1343. | log-async=20
  1344. |  
  1345. +---------------------------------------------------------------+"
  1346. fi
  1347. p=`nvram get script_fire | grep "cru a P2Partisan-tutor" | wc -l`
  1348.         if [ $p -eq "0" ] ; then
  1349.         ptutorset
  1350.         fi
  1351. punblock  #remove paranoia DROPs if any
  1352.  
  1353.         post=`date +%s`
  1354.         runtime=`echo $(( $post - $pre ))`
  1355.         [ -f ./runtime ] || echo $runtime > ./runtime
  1356.         [ -f /tmp/p2partisan.loading ] && rm -r "/tmp/p2partisan.loading" >/dev/null 2>&1
  1357.         else
  1358.     echo -e "
  1359. +------------------------- P2Partisan --------------------------+
  1360. |                 _______ __               __  
  1361. |                |     __|  |_.---.-.----.|  |_
  1362. |                |__     |   _|  _  |   _||   _|
  1363. |        already |_______|____|___._|__|  |____| ed
  1364. |                                            
  1365. +---------------------------------------------------------------+
  1366. | It appears like P2Partisan is already running. Skipping...
  1367. |                      
  1368. | Is this is not what you expected? Try:
  1369. | \033[1;33m./p2partisan.sh update\033[0;39m
  1370. +---------------------------------------------------------------+
  1371.         "
  1372.         fi
  1373. }
  1374.  
  1375.  
  1376. for p in $1
  1377. do
  1378. case "$p" in
  1379.         "start")
  1380.                 pstart
  1381.                 exit
  1382.                 ;;            
  1383.         "stop")
  1384.                 pforcestop
  1385.                 exit
  1386.                 ;;
  1387.         "restart")
  1388.                 psoftstop
  1389.                 ;;
  1390.         "status")
  1391.                 pstatus
  1392.                 exit                          
  1393.                 ;;
  1394.         "pause")
  1395.                 psoftstop
  1396.                 exit
  1397.                 ;;
  1398.         "detective")       
  1399.                 pdetective
  1400.                 exit
  1401.                 ;;
  1402.         "test")
  1403.                 ptest $2
  1404.                 exit
  1405.                 ;;    
  1406.         "debug")
  1407.                 pdebug $2 $3
  1408.                 exit
  1409.                 ;;  
  1410.         "debug-display")
  1411.                 pdebugdisplay $2
  1412.                 exit
  1413.                 ;;                 
  1414.         "update")
  1415.                 pforcestop
  1416.                 echo "| Now updating..."
  1417.                 ;;
  1418.         "paranoia-update")
  1419.         echo -e "
  1420. +------------------------- P2Partisan --------------------------+
  1421. |     ______                                __        
  1422. |    |   __ \.---.-.----.---.-.-----.-----.|__|.---.-.
  1423. |    |    __/|  _  |   _|  _  |     |  _  ||  ||  _  |
  1424. |    |___|   |___._|__| |___._|__|__|_____||__||___._| update
  1425. |
  1426. +---------------------------------------------------------------+"
  1427.                 pblock
  1428.                 pforcestop
  1429.                 ;;
  1430.         "autorun-on")
  1431.                 pautorunset
  1432.                 exit
  1433.                 ;;
  1434.         "autorun-off")
  1435.                 pautorununset
  1436.                 exit
  1437.                 ;;
  1438.         "autoupdate-on")
  1439.                 pscheduleset
  1440.                 exit
  1441.                 ;;
  1442.         "autoupdate-off")
  1443.                 pscheduleunset
  1444.                 exit
  1445.                 ;;
  1446.         "tutor-on")
  1447.                 ptutorset
  1448.                 exit
  1449.                 ;;
  1450.         "tutor-off")
  1451.                 ptutorunset
  1452.                 exit
  1453.                 ;;
  1454.         "tutor")
  1455.                 ptutor
  1456.                 exit
  1457.                 ;;
  1458.         "upgrade")
  1459.                 pupgrade
  1460.                 ;;
  1461.         "upgrade-beta")
  1462.                 pupgradebeta
  1463.                 ;;                            
  1464.         "help")
  1465.        
  1466. version=`head -3 ./p2partisan.sh | tail -1 | cut -f 3- -d " "`
  1467.        
  1468.                 echo -e "\033[48;5;60m
  1469.       ______ ______ ______              __   __                                        
  1470.      |   __ \__    |   __ \.---.-.----.|  |_|__|.-----.---.-.-----.                    
  1471.      |    __/    __|    __/|  _  |   _||   _|  ||__ --|  _  |     |                    
  1472.      |___|  |______|___|   |___._|__|  |____|__||_____|___._|__|__| $version
  1473.                         \e[39m\e[49m
  1474.              
  1475.        help                    Display this text              
  1476.        \e[97mstart                   Starts the process (this runs also if no option is provided)
  1477.        stop                    Stops P2Partisan
  1478.        restart                 Soft restart, updates whiteports & whitelist only
  1479.        pause                   Soft stop P2Partisan allowing for quick start
  1480.        update                  Hard restart, slow removes p2partisan, updates
  1481.                                the lists and does a fresh start
  1482.        paranoia-update         Like update but blocks any new connection until
  1483.                                P2Partisan is running again\e[39m
  1484.        status                  Display P2Partisan running status + extra info
  1485.        \e[93mtest <IP>               Verify existence of the given IP against lists
  1486.        debug                   Shows a guide on how to operate debug
  1487.        debug-display <in|out>  Shows all the logs relevant to the last debug only
  1488.        detective               Determines highest impact IPs:ports (number of sessions)
  1489.        \e[36mautorun-on              Sets P2Partisan to boot with the router
  1490.        autorun-off             Sets P2Partisan not to boot with the router
  1491.        autoupdate-on           Sets automatic weekly updates to on
  1492.        autoupdate-off          Sets automatic weekly updates to off
  1493.        tutor-on                Sets hourly running-status checks to on
  1494.        tutor-off               Sets hourly running-status checks to off
  1495.        upgrade                 Download and install the latest P2Partisan\e[39m
  1496. "
  1497.                                 exit
  1498.                 ;;
  1499.         *)
  1500.                 echo "parameter not valid. please run:
  1501.                              
  1502.        p2partisan.sh help
  1503.        "
  1504.                                 exit
  1505.                 ;;
  1506.  
  1507. esac
  1508. done
  1509.  
  1510. pstart
  1511.  
  1512. exit
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement