Advertisement
KingP1n

Untitled

Jul 25th, 2018
764
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 41.18 KB | None | 0 0
  1. #!/bin/sh
  2. ##FreshJR_QOS (Compatible Method - ALTERNATIVE WAN INTERFACE VARIENT) v5 (BETA) released 06/14/2018
  3. ##Script Tested on ASUS AC-68U, FW384.4, using Adaptive QOS with Manual Bandwidth Settings
  4. ##Script Changes Unidentified Packet QOS destination from "Default" Traffic Container (Category7) into user definable (in WebUI) "Others" Traffic Container
  5. ##Script Changes Minimum Guaranteed Bandwidth per QOS category from 128Kbit into user defined percentages upload and download.
  6. ##Script bumps "Defaults" Traffic Container priority into position 6 (orginally position 7)
  7. ##Script decreases "User Defined Bottom WebUI Traffic" traffic container priority into position 7 (originally position 6)
  8. ##Script supports custom QOS rules. To create rules, copy applicable rules from templates below, change filter parameters as desired, and then paste into applicable custom rule start area.
  9. ## Included custom rule moves any UDP traffic on ports 500 & 4500 into VOIP traffic Container. (Wifi Calling)
  10. ## Included custom rule moves any UDP traffic on ports 16384 - 16415 into VOIP traffic Container. (Facetime)
  11. ## Included custom rule moves any Snapchat traffic into Others traffic Container. (Snapchat)
  12. ## Included custom rule moves any Speedtest.net traffic into Downloads traffic Container. (Speedtest.net)
  13. ## Included custom rule moves any Google Play Store traffic into Downloads traffic Container. (Google Play)
  14. ## Included custom rule moves any Apple AppStore traffic into Downloads traffic Container. (Apple AppStore)
  15. ## Included custom rule moves any Gaming traffic from ports 80 & 443 into Defaults traffic Container. (Gaming)
  16. ## port 80 & 443 is primarily game downloads & patches BUT login protocols are also caught within
  17. ## Included, but disabled by default (commented out) is an additional gaming device oriented rule (Gaming)
  18. ## The use of this gaming rule REQUIRES gaming devices to have a static dhcp ip assignment (in webUI) <<AND>>
  19. ## this user chosen dhcp range needs to AGAIN be specified within this scripts up/down rules, using CIDR notation
  20. ## The rule takes unidentified traffic for specified devices and routes it into the Gaming traffic Container.
  21. #
  22. #---------------------------------------------------------------------------------------------------------------
  23. # VALID FLOW ID'S FOR TC APP REDIRECTION
  24. # ${VOIP}, ${Gaming}, ${Others}, ${Web}, ${Streaming}, ${Downloads}, ${Net}, ${Defaults}
  25. #
  26. # VALID MARKS FOR **DOWNLOAD** IPTABLES RULES
  27. # ${VOIP_mark_down}, ${Gaming_mark_down}, ${Others_mark_down}, ${Web_mark_down}, ${Streaming_mark_down}, ${Downloads_mark_down}, ${Net_mark_down}, ${Default_mark_down}
  28. #
  29. # VALID MARKS FOR **UPLOAD** IPTABLES RULES
  30. # ${VOIP_mark_up}, ${Gaming_mark_up}, ${Others_mark_up}, ${Web_mark_up}, ${Streaming_mark_up}, ${Downloads_mark_up}, ${Net_mark_up}, ${Default_mark_up}
  31. #
  32. # DOWNLOAD/INCOMMING TRAFFIC rule templates. See comments next to rule for details. Make sure to correctly define TCP or UDP designation.
  33. # See comments next to rule for details.
  34. # Make sure to correctly define TCP or UDP designation for port rules.
  35. #
  36. # iptables -D POSTROUTING -t mangle -o br0 -p tcp --dport 1234:1236 -j MARK --set-mark ${Downloads_mark_down} &> /dev/null #Template Rule 1 (Download traffic towards LAN (local) device ports 1234-1236 via TCP goes to "Downloads" Traffic Container)
  37. # iptables -A POSTROUTING -t mangle -o br0 -p tcp --dport 1234:1236 -j MARK --set-mark ${Downloads_mark_down} (XXXX:YYYY defines port range, XXXX defines for single port)
  38. #
  39. # iptables -D POSTROUTING -t mangle -o br0 -d 192.168.2.123/32 -j MARK --set-mark ${Downloads_mark_down} &> /dev/null #Template Rule 2 (Download traffic towards LAN (local) device 192.168.2.123 goes to "Downloads" Traffic Container)
  40. # iptables -A POSTROUTING -t mangle -o br0 -d 192.168.2.123/32 -j MARK --set-mark ${Downloads_mark_down} ( /32 CIDR mask defines only one ip, see SNB forum post for guide)
  41. #
  42. # iptables -D POSTROUTING -t mangle -o br0 -p udp --sport 5555 -j MARK --set-mark ${VOIP_mark_down} &> /dev/null #Template Rule 3 (Download traffic from WAN (remote) server port 5555 via UDP) goes to "VOIP" Traffic Container)
  43. # iptables -A POSTROUTING -t mangle -o br0 -p udp --sport 5555 -j MARK --set-mark ${VOIP_mark_down} (XXXX:YYYY defines port range, XXXX defines for single port)
  44. #
  45. # iptables -D POSTROUTING -t mangle -o br0 -s 75.75.75.75/32 -j MARK --set-mark ${VOIP_mark_down} &> /dev/null #Template Rule 4 (Download traffic from WAN (remote) server 75.75.75.75 goes to "VOIP" Traffic Container)
  46. # iptables -A POSTROUTING -t mangle -o br0 -s 75.75.75.75/32 -j MARK --set-mark ${VOIP_mark_down} ( /32 CIDR mask defines only one ip, see SNB forum post for guide)
  47. #
  48. #
  49. # UPLOAD/OUTOING TRAFFIC rule templates.
  50. # See comments next to rule for details.
  51. # Make sure to correctly define TCP or UDP designation for port rules.
  52. #
  53. # iptables -D POSTROUTING -t mangle -o $wan -p tcp --sport 1234:1236 -j MARK --set-mark ${Downloads_mark_up} &> /dev/null #Template Rule 1 (Upload traffic from LAN (local) device ports 1234-1236 via TCP) goes to "Downloads" Traffic Container)
  54. # iptables -A POSTROUTING -t mangle -o $wan -p tcp --sport 1234:1236 -j MARK --set-mark ${Downloads_mark_up} (XXXX:YYYY defines port range, XXXX defines for single port)
  55. #
  56. # iptables -D POSTROUTING -t mangle -o $wan -s 192.168.2.123/32 -j MARK --set-mark ${Downloads_mark_up} &> /dev/null #Template Rule 2 (Upload traffic from LAN (local) device ip 192.168.2.123 goes to "Downloads" Traffic Container)
  57. # iptables -A POSTROUTING -t mangle -o $wan -s 192.168.2.123/32 -j MARK --set-mark ${Downloads_mark_up} ( /32 CIDR mask defines only one ip, see SNB forum post for guide)
  58. #
  59. # iptables -D POSTROUTING -t mangle -o $wan -p udp --dport 5555 -j MARK --set-mark ${VOIP_mark_up} &> /dev/null #Template Rule 3 (Upload traffic towards WAN (remote) server port 1234 via UDP goes to "VOIP" Traffic Container)
  60. # iptables -A POSTROUTING -t mangle -o $wan -p udp --dport 5555 -j MARK --set-mark ${VOIP_mark_up} (XXXX:YYYY defines port range, XXXX defines for single port)
  61. #
  62. # iptables -D POSTROUTING -t mangle -o $wan -d 75.75.75.75/32 -j MARK --set-mark ${VOIP_mark_up} &> /dev/null #Template Rule 4 (Upload traffic towards WAN (remote) server 75.75.75.75 goes to "VOIP" Traffic Container)
  63. # iptables -A POSTROUTING -t mangle -o $wan -d 75.75.75.75/32 -j MARK --set-mark ${VOIP_mark_up} ( /32 CIDR mask defines only one ip, see SNB forum post for guide)
  64. #
  65. #---------------------------------------------------------------------------------------------------------------
  66.  
  67.  
  68. #################### Bandwidth Setup #####################
  69.  
  70. user_variables() {
  71. #Percent of download speed guaranteed per QOS category, change below as desired (minimum value per section 5, sum should not be greater than 100)
  72. NetControl_DownBandPercent=5 #This value can be adjust as desired ** no spaces before or after the "=" sign **
  73. VoIP_DownBandPercent=10 #This value can be adjust as desired ** no decimals **
  74. Gaming_DownBandPercent=15 #This value can be adjust as desired
  75. Others_DownBandPercent=15 #This value can be adjust as desired #Note: New destination for unidentified traffic
  76. WebSurfing_DownBandPercent=10 #This value can be adjust as desired
  77. Video_DownBandPercent=30 #This value can be adjust as desired
  78. FileTransfer_DownBandPercent=5 #This value can be adjust as desired
  79. Default_DownBandPercent=10 #This value can be adjust as desired #Note: Original destination for unidentified traffic, repurposed for "Gaming Downloads on ports 80/443"
  80.  
  81. #Percent of upload speed guaranteed per QOS category, change below as desired (minimum value per section 5, sum should not be greater than 100)
  82. NetControl_UpBandPercent=5 #This value can be adjust as desired
  83. VoIP_UpBandPercent=10 #This value can be adjust as desired
  84. Gaming_UpBandPercent=15 #This value can be adjust as desired
  85. Others_UpBandPercent=15 #This value can be adjust as desired #Note: New destination for unidentified traffic
  86. WebSurfing_UpBandPercent=10 #This value can be adjust as desired
  87. Video_UpBandPercent=30 #This value can be adjust as desired
  88. FileTransfer_UpBandPercent=5 #This value can be adjust as desired
  89. Default_UpBandPercent=10 #This value can be adjust as desired #Note: Original destination for unidentified traffic, repurposed for "Gaming Downloads on ports 80/443"
  90. }
  91.  
  92.  
  93. #################### Custom Rules Setup #####################
  94.  
  95. iptable_down_rules() {
  96. echo "Applying - Iptable Down Rules"
  97. ##DOWNLOAD (INCOMMING TRAFFIC) CUSTOM RULES START HERE
  98.  
  99. iptables -D POSTROUTING -t mangle -o br0 -p udp --sport 500 -j MARK --set-mark ${VOIP_mark_down} &> /dev/null #Wifi Calling (1/2) - (All incoming traffic w/ WAN source port 500 goes to "VOIP" Traffic Container)
  100. iptables -A POSTROUTING -t mangle -o br0 -p udp --sport 500 -j MARK --set-mark ${VOIP_mark_down}
  101.  
  102. iptables -D POSTROUTING -t mangle -o br0 -p udp --sport 4500 -j MARK --set-mark ${VOIP_mark_down} &> /dev/null #Wifi Calling (2/2) - (All incoming traffic w/ WAN source port 4500 goes to "VOIP" Traffic Container)
  103. iptables -A POSTROUTING -t mangle -o br0 -p udp --sport 4500 -j MARK --set-mark ${VOIP_mark_down}
  104.  
  105. iptables -D POSTROUTING -t mangle -o br0 -p udp --dport 16384:16415 -j MARK --set-mark ${VOIP_mark_down} &> /dev/null #Facetime
  106. iptables -A POSTROUTING -t mangle -o br0 -p udp --dport 16384:16415 -j MARK --set-mark ${VOIP_mark_down}
  107.  
  108. iptables -D POSTROUTING -t mangle -o br0 -m mark --mark 0x80080000/0xc03f0000 -p tcp --sport 80 -j MARK --set-mark ${Default_mark_down} &> /dev/null #Gaming (1/3) - Routes "Gaming" traffic coming from port 443 into "Defaults"
  109. iptables -A POSTROUTING -t mangle -o br0 -m mark --mark 0x80080000/0xc03f0000 -p tcp --sport 80 -j MARK --set-mark ${Default_mark_down}
  110.  
  111. iptables -D POSTROUTING -t mangle -o br0 -m mark --mark 0x80080000/0xc03f0000 -p tcp --sport 443 -j MARK --set-mark ${Default_mark_down} &> /dev/null #Gaming (2/3) - Routes "Gaming" traffic coming from port 80 into "Defaults"
  112. iptables -A POSTROUTING -t mangle -o br0 -m mark --mark 0x80080000/0xc03f0000 -p tcp --sport 443 -j MARK --set-mark ${Default_mark_down}
  113.  
  114. iptables -D POSTROUTING -t mangle -o br0 -d 192.168.1.100/28 -m mark --mark 0x80000000/0x8000ffff -j MARK --set-mark ${Gaming_mark_down} &> /dev/null #Gaming (3/3) - Routes Unidentified Traffic into "Gaming", instead of "Others", for LAN clients specified
  115. iptables -A POSTROUTING -t mangle -o br0 -d 192.168.1.100/28 -m mark --mark 0x80000000/0x8000ffff -j MARK --set-mark ${Gaming_mark_down}
  116.  
  117. iptables -D POSTROUTING -t mangle -o br0 -d 192.168.1.112/30 -j MARK --set-xmark 0x80000000/0xC0000000 &> /dev/null #VPN Client
  118. iptables -A POSTROUTING -t mangle -o br0 -d 192.168.1.112/30 -j MARK --set-xmark 0x80000000/0xC0000000
  119.  
  120. ##DOWNLOAD (INCOMMING TRAFFIC) CUSTOM RULES END HERE
  121. }
  122.  
  123. iptable_up_rules(){
  124.  
  125. #wan="ppp0" ## WAN interface over-ride for upload traffic -- Variable ONLY needs to be defined for users on STOCK firmware
  126. # RMerlin Firmware AUTOMATICALLY detects correct interface --> so variable should be left COMMENTED/DISABLED
  127. # Stock Firmware configured to assume ppp0 --> variable should be manually set if connection type differs ( eth0, ppp0, vlanXXX, etc)
  128.  
  129. echo "Applying - Iptable Up Rules (ppp0)"
  130.  
  131. ##UPLOAD (OUTGOING TRAFFIC) CUSTOM RULES START HERE
  132.  
  133. iptables -D POSTROUTING -t mangle -o eth0 -p udp --dport 500 -j MARK --set-mark ${VOIP_mark_up} &> /dev/null #Wifi Calling (1/2) - (All outgoing traffic w/ WAN destination port 500 goes to "VOIP" Traffic Container)
  134. iptables -A POSTROUTING -t mangle -o eth0 -p udp --dport 500 -j MARK --set-mark ${VOIP_mark_up}
  135.  
  136. iptables -D POSTROUTING -t mangle -o eth0 -p udp --dport 4500 -j MARK --set-mark ${VOIP_mark_up} &> /dev/null #Wifi Calling (2/2) - (All outgoing traffic w/ WAN destination port 4500 goes to "VOIP" Traffic Container)
  137. iptables -A POSTROUTING -t mangle -o eth0 -p udp --dport 4500 -j MARK --set-mark ${VOIP_mark_up}
  138.  
  139. iptables -D POSTROUTING -t mangle -o eth0 -p udp --sport 16384:16415 -j MARK --set-mark ${VOIP_mark_up} &> /dev/null #Facetime
  140. iptables -A POSTROUTING -t mangle -o eth0 -p udp --sport 16384:16415 -j MARK --set-mark ${VOIP_mark_up}
  141.  
  142. iptables -D POSTROUTING -t mangle -o eth0 -m mark --mark 0x40080000/0xc03f0000 -p tcp --sport 80 -j MARK --set-mark ${Default_mark_up} &> /dev/null #Gaming (1/3) - Routes "Gaming" traffic going to port 443 into "Defaults"
  143. iptables -A POSTROUTING -t mangle -o eth0 -m mark --mark 0x40080000/0xc03f0000 -p tcp --sport 80 -j MARK --set-mark ${Default_mark_up}
  144.  
  145. iptables -D POSTROUTING -t mangle -o eth0 -m mark --mark 0x40080000/0xc03f0000 -p tcp --sport 443 -j MARK --set-mark ${Default_mark_up} &> /dev/null #Gaming (2/3) - Routes "Gaming" traffic going to port 80 into "Defaults"
  146. iptables -A POSTROUTING -t mangle -o eth0 -m mark --mark 0x40080000/0xc03f0000 -p tcp --sport 443 -j MARK --set-mark ${Default_mark_up}
  147.  
  148. iptables -D POSTROUTING -t mangle -o eth0 -s 192.168.1.100/28 -m mark --mark 0x40000000/0x4000ffff -j MARK --set-mark ${Gaming_mark_up} &> /dev/null #Gaming (3/3) - Routes Unidentified Traffic into "Gaming", instead of "Others", from specified LAN devices in rule (line 1/2)
  149. iptables -A POSTROUTING -t mangle -o eth0 -s 192.168.1.100/28 -m mark --mark 0x40000000/0x4000ffff -j MARK --set-mark ${Gaming_mark_up}
  150.  
  151. ##UPLOAD (OUTGOING TRAFFIC) CUSTOM RULES END HERE
  152. }
  153.  
  154. tc_down_rules() {
  155. echo "Applying TC Down Rules"
  156. ${tc} filter del dev br0 parent 1: prio $1 #remove original unidentified traffic rule
  157. ${tc} filter del dev br0 parent 1: prio 22 &> /dev/null #remove original HTTPS rule
  158. ${tc} filter del dev br0 parent 1: prio 23 &> /dev/null #remove original HTTPS rule
  159. ${tc} filter add dev br0 protocol all prio 22 u32 match mark 0x80130000 0xc03f0000 flowid ${Web} #recreate HTTPS rule with different destination
  160. ${tc} filter add dev br0 protocol all prio 23 u32 match mark 0x80140000 0xc03f0000 flowid ${Web} #recreate HTTPS rule with different destination
  161. ##DOWNLOAD APP_DB REDIRECTION RULES START HERE
  162.  
  163. ${tc} filter add dev br0 protocol all prio $1 u32 match mark 0x8000006B 0xc03fffff flowid ${Web} #Snapchat
  164. ${tc} filter add dev br0 protocol all prio 15 u32 match mark 0x800D0007 0xc03fffff flowid ${Downloads} #Speedtest.net
  165. ${tc} filter add dev br0 protocol all prio 15 u32 match mark 0x800D0086 0xc03fffff flowid ${Downloads} #Google Play
  166. ${tc} filter add dev br0 protocol all prio 15 u32 match mark 0x800D00A0 0xc03fffff flowid ${Downloads} #Apple AppStore
  167.  
  168. ##DOWNLOAD APP_DB REDIRECTION RULES END HERE
  169. ${tc} filter add dev br0 protocol all prio $1 u32 match mark 0x80000000 0x8000ffff flowid ${Others} #recreate unidentified traffic rule with diferent destination - Routes Unidentified Traffic into webUI adjustable "Others" traffic container instead of "Defaults"
  170. ${tc} filter add dev br0 protocol all prio 10 u32 match mark 0x803f0001 0xc03fffff flowid ${Defaults} #Used to achieve iptables Default_mark_down functionality
  171. }
  172.  
  173. tc_up_rules() {
  174. echo "Applying TC Up Rules"
  175. ${tc} filter del dev eth0 parent 1: prio $1 #remove original unidentified traffic rule
  176. ${tc} filter del dev eth0 parent 1: prio 22 &> /dev/null #remove original HTTPS rule
  177. ${tc} filter del dev eth0 parent 1: prio 23 &> /dev/null #remove original HTTPS rule
  178. ${tc} filter add dev eth0 protocol all prio 22 u32 match mark 0x40130000 0xc03f0000 flowid ${Web} #recreate HTTPS rule with different destination
  179. ${tc} filter add dev eth0 protocol all prio 23 u32 match mark 0x40140000 0xc03f0000 flowid ${Web} #recreate HTTPS rule with different destination
  180. ##UPLOAD APP_DB REDIRECTION RULES START HERE
  181.  
  182. ${tc} filter add dev eth0 protocol all prio $1 u32 match mark 0x4000006B 0xc03fffff flowid ${Web} #Snapchat
  183. ${tc} filter add dev eth0 protocol all prio 15 u32 match mark 0x400D0007 0xc03fffff flowid ${Downloads} #Speedtest.net
  184. ${tc} filter add dev eth0 protocol all prio 15 u32 match mark 0x400D0086 0xc03fffff flowid ${Downloads} #Google Play
  185. ${tc} filter add dev eth0 protocol all prio 15 u32 match mark 0x400D00A0 0xc03fffff flowid ${Downloads} #Apple AppStore
  186.  
  187. ##UPLOAD APP_DB REDIRECTION RULES END HERE
  188. ${tc} filter add dev eth0 protocol all prio $1 u32 match mark 0x40000000 0x4000ffff flowid ${Others} #recreate unidentified traffic rule with diferent destination - Routes Unidentified Traffic into webUI adjustable "Others" traffic container, instead of "Default" traffic container
  189. ${tc} filter add dev eth0 protocol all prio 10 u32 match mark 0x403f0001 0xc03fffff flowid ${Defaults} #Used to achieve iptables Default_mark_up functionality
  190. }
  191.  
  192. custom_rates() {
  193. echo "Modifying TC Class Rates"
  194. ${tc} class change dev br0 parent 1:1 classid 1:10 htb ${PARMS}prio 0 rate ${DownRate0}Kbit ceil ${DownCeil}Kbit burst ${DownBurst0} cburst ${DownCburst0}
  195. ${tc} class change dev br0 parent 1:1 classid 1:11 htb ${PARMS}prio 1 rate ${DownRate1}Kbit ceil ${DownCeil}Kbit burst ${DownBurst1} cburst ${DownCburst1}
  196. ${tc} class change dev br0 parent 1:1 classid 1:12 htb ${PARMS}prio 2 rate ${DownRate2}Kbit ceil ${DownCeil}Kbit burst ${DownBurst2} cburst ${DownCburst2}
  197. ${tc} class change dev br0 parent 1:1 classid 1:13 htb ${PARMS}prio 3 rate ${DownRate3}Kbit ceil ${DownCeil}Kbit burst ${DownBurst3} cburst ${DownCburst3}
  198. ${tc} class change dev br0 parent 1:1 classid 1:14 htb ${PARMS}prio 4 rate ${DownRate4}Kbit ceil ${DownCeil}Kbit burst ${DownBurst4} cburst ${DownCburst4}
  199. ${tc} class change dev br0 parent 1:1 classid 1:15 htb ${PARMS}prio 5 rate ${DownRate5}Kbit ceil ${DownCeil}Kbit burst ${DownBurst5} cburst ${DownCburst5}
  200. ${tc} class change dev br0 parent 1:1 classid 1:16 htb ${PARMS}prio 7 rate ${DownRate6}Kbit ceil ${DownCeil}Kbit burst ${DownBurst6} cburst ${DownCburst6}
  201. ${tc} class change dev br0 parent 1:1 classid 1:17 htb ${PARMS}prio 6 rate ${DownRate7}Kbit ceil ${DownCeil}Kbit burst ${DownBurst7} cburst ${DownCburst7}
  202.  
  203. ${tc} class change dev eth0 parent 1:1 classid 1:10 htb ${PARMS}prio 0 rate ${UpRate0}Kbit ceil ${UpCeil}Kbit burst ${UpBurst0} cburst ${UpCburst0}
  204. ${tc} class change dev eth0 parent 1:1 classid 1:11 htb ${PARMS}prio 1 rate ${UpRate1}Kbit ceil ${UpCeil}Kbit burst ${UpBurst1} cburst ${UpCburst1}
  205. ${tc} class change dev eth0 parent 1:1 classid 1:12 htb ${PARMS}prio 2 rate ${UpRate2}Kbit ceil ${UpCeil}Kbit burst ${UpBurst2} cburst ${UpCburst2}
  206. ${tc} class change dev eth0 parent 1:1 classid 1:13 htb ${PARMS}prio 3 rate ${UpRate3}Kbit ceil ${UpCeil}Kbit burst ${UpBurst3} cburst ${UpCburst3}
  207. ${tc} class change dev eth0 parent 1:1 classid 1:14 htb ${PARMS}prio 4 rate ${UpRate4}Kbit ceil ${UpCeil}Kbit burst ${UpBurst4} cburst ${UpCburst4}
  208. ${tc} class change dev eth0 parent 1:1 classid 1:15 htb ${PARMS}prio 5 rate ${UpRate5}Kbit ceil ${UpCeil}Kbit burst ${UpBurst5} cburst ${UpCburst5}
  209. ${tc} class change dev eth0 parent 1:1 classid 1:16 htb ${PARMS}prio 7 rate ${UpRate6}Kbit ceil ${UpCeil}Kbit burst ${UpBurst6} cburst ${UpCburst6}
  210. ${tc} class change dev eth0 parent 1:1 classid 1:17 htb ${PARMS}prio 6 rate ${UpRate7}Kbit ceil ${UpCeil}Kbit burst ${UpBurst7} cburst ${UpCburst7}
  211. }
  212.  
  213. #################### DO NOT MODIFY BELOW #####################
  214. #################### DO NOT MODIFY BELOW #####################
  215. #################### DO NOT MODIFY BELOW #####################
  216. #################### DO NOT MODIFY BELOW #####################
  217. #################### DO NOT MODIFY BELOW #####################
  218. #################### DO NOT MODIFY BELOW #####################
  219. #################### DO NOT MODIFY BELOW #####################
  220. #################### DO NOT MODIFY BELOW #####################
  221. #################### DO NOT MODIFY BELOW #####################
  222. #################### DO NOT MODIFY BELOW #####################
  223. #################### DO NOT MODIFY BELOW #####################
  224.  
  225. #marks for iptable rules
  226.  
  227. Net_mark_down="0x80090001"
  228. VOIP_mark_down="0x80060001" # Marks for iptables varient of download rules
  229. Gaming_mark_down="0x80080001" # Note these marks are same as filter match/mask combo but have a 1 at the end. That trailing 1 prevents them from being caught by unidentified mask
  230. Others_mark_down="0x800a0001"
  231. Web_mark_down="0x800d0001"
  232. Streaming_mark_down="0x80040001"
  233. Downloads_mark_down="0x80030001"
  234. #Default_mark_down="0x80000000"
  235. Default_mark_down="0x803f0001"
  236.  
  237. Net_mark_up="0x40090001"
  238. VOIP_mark_up="0x40060001" # Marks for iptables varient of upload rules
  239. Gaming_mark_up="0x40080001" # Note these marks are same as filter match/mask combo but have a 1 at the end. That trailing 1 prevents them from being caught by unidentified mask
  240. Others_mark_up="0x400a0001"
  241. Web_mark_up="0x400d0001"
  242. Streaming_mark_up="0x40040001"
  243. Downloads_mark_up="0x40030001"
  244. #Default_mark_up="0x40000000" #this technically is working correctly but will behave different from what you expect
  245. Default_mark_up="0x403f0001"
  246.  
  247.  
  248. #if something is marked with the commented "default_mark" it will ultimately reach "others"
  249. #this is because a rule in the script routes all traffic marked as "unidentified/default" into "others"
  250. #to achieve what is intended (sending traffic to defaults) a different custom mark and corresponding rule has to be created
  251. #---> a "Custom_mark" for which marks 402C0001 - 403F0001 are available.
  252. #---> a corresponding "tc match rule" that will send traffic with this "custom mark" to "flowid ${Default}"
  253.  
  254. #example:
  255. #Default_mark_up="0x403f0001" #place in set_all_variables
  256. #${tc} filter add dev eth0 protocol all prio $1 u32 match mark 0x403f0000 0xc03f0000 flowid ${Default} #place at beggining of custom_up_rules
  257. #iptables -D POSTROUTING -t mangle -o eth0 -s 192.168.1.100/32 -j MARK --set-mark ${Default_mark_up} &> /dev/null #example rule
  258. #iptables -A POSTROUTING -t mangle -o eth0 -s 192.168.1.100/32 -j MARK --set-mark ${Default_mark_up} #example rule
  259.  
  260. #The "Custom_mark" implementation has already been applied in this version of the script
  261.  
  262. set_all_variables(){
  263.  
  264. if [ -e "/usr/sbin/realtc" ] ; then
  265. tc="realtc"
  266. else
  267. tc="tc"
  268. fi
  269.  
  270. #read variables at beginning of script
  271. user_variables
  272.  
  273.  
  274. #read order of QOS categories
  275. Defaults="1:17"
  276. Net="1:10"
  277. flowid=0
  278. while read -r line; # reads users order of QOS categories
  279. do
  280. #logger -s "${line}"
  281. case ${line} in
  282. '0')
  283. VOIP="1:1${flowid}"
  284. eval "Cat${flowid}DownBandPercent=${VoIP_DownBandPercent}"
  285. eval "Cat${flowid}UpBandPercent=${VoIP_UpBandPercent}"
  286. ;;
  287. '1')
  288. Downloads="1:1${flowid}"
  289. eval "Cat${flowid}DownBandPercent=${FileTransfer_DownBandPercent}"
  290. eval "Cat${flowid}UpBandPercent=${FileTransfer_UpBandPercent}"
  291. ;;
  292. '4')
  293. Streaming="1:1${flowid}"
  294. eval "Cat${flowid}DownBandPercent=${Video_DownBandPercent}"
  295. eval "Cat${flowid}UpBandPercent=${Video_UpBandPercent}"
  296. ;;
  297. '7')
  298. Others="1:1${flowid}"
  299. eval "Cat${flowid}DownBandPercent=${Others_DownBandPercent}"
  300. eval "Cat${flowid}UpBandPercent=${Others_UpBandPercent}"
  301. ;;
  302. '8')
  303. Gaming="1:1${flowid}"
  304. eval "Cat${flowid}DownBandPercent=${Gaming_DownBandPercent}"
  305. eval "Cat${flowid}UpBandPercent=${Gaming_UpBandPercent}"
  306. ;;
  307. '9')
  308. flowid=0
  309. ;;
  310. '13')
  311. Web="1:1${flowid}"
  312. eval "Cat${flowid}DownBandPercent=${WebSurfing_DownBandPercent}"
  313. eval "Cat${flowid}UpBandPercent=${WebSurfing_UpBandPercent}"
  314. ;;
  315. esac
  316.  
  317. firstchar="${line%%[0-9]*}"
  318. if [ "${firstchar}" == "[" ] ; then
  319. flowid=$((flowid + 1))
  320. #logger -s "flowid = ${flowid} ==========="
  321. fi
  322.  
  323. done <<EOF
  324. $(cat /tmp/bwdpi/qosd.conf | sed 's/rule=//g' | sed '/na/q')
  325. EOF
  326.  
  327. #calculate up/down rates
  328. DownCeil="$(printf "%.0f" $(nvram get qos_ibw))"
  329. UpCeil="$(printf "%.0f" $(nvram get qos_obw))"
  330.  
  331.  
  332. DownRate0="$(expr ${DownCeil} \* ${NetControl_DownBandPercent} / 100)" #Minimum guaranteed Up/Down rates per QOS category corresponding to user defined percentages
  333. DownRate1="$(expr ${DownCeil} \* ${Cat1DownBandPercent} / 100)"
  334. DownRate2="$(expr ${DownCeil} \* ${Cat2DownBandPercent} / 100)"
  335. DownRate3="$(expr ${DownCeil} \* ${Cat3DownBandPercent} / 100)"
  336. DownRate4="$(expr ${DownCeil} \* ${Cat4DownBandPercent} / 100)"
  337. DownRate5="$(expr ${DownCeil} \* ${Cat5DownBandPercent} / 100)"
  338. DownRate6="$(expr ${DownCeil} \* ${Cat6DownBandPercent} / 100)"
  339. DownRate7="$(expr ${DownCeil} \* ${Default_DownBandPercent} / 100)"
  340.  
  341.  
  342. UpRate0="$(expr ${UpCeil} \* ${NetControl_UpBandPercent} / 100)"
  343. UpRate1="$(expr ${UpCeil} \* ${Cat1UpBandPercent} / 100)"
  344. UpRate2="$(expr ${UpCeil} \* ${Cat2UpBandPercent} / 100)"
  345. UpRate3="$(expr ${UpCeil} \* ${Cat3UpBandPercent} / 100)"
  346. UpRate4="$(expr ${UpCeil} \* ${Cat4UpBandPercent} / 100)"
  347. UpRate5="$(expr ${UpCeil} \* ${Cat5UpBandPercent} / 100)"
  348. UpRate6="$(expr ${UpCeil} \* ${Cat6UpBandPercent} / 100)"
  349. UpRate7="$(expr ${UpCeil} \* ${Default_UpBandPercent} / 100)"
  350.  
  351. ClassesPresent=0
  352. #read existing burst/cburst per download class
  353. while read -r line;
  354. do
  355. ClassesPresent=$(($ClassesPresent+1))
  356. if [ "$( echo ${line} | sed -n -e 's/.*1:10 //p' )" != "" ] ; then
  357. DownBurst0=$( echo ${line} | sed -n -e 's/.* burst \([a-zA-z0-9]*\).*/\1/p' )
  358. DownCburst0=$( echo ${line} | sed -n -e 's/.*cburst \([a-zA-z0-9]*\).*/\1/p' )
  359. fi
  360.  
  361. if [ "$( echo ${line} | sed -n -e 's/.*1:11 //p' )" != "" ] ; then
  362. DownBurst1=$( echo ${line} | sed -n -e 's/.* burst \([a-zA-z0-9]*\).*/\1/p' )
  363. DownCburst1=$( echo ${line} | sed -n -e 's/.*cburst \([a-zA-z0-9]*\).*/\1/p' )
  364. fi
  365.  
  366. if [ "$( echo ${line} | sed -n -e 's/.*1:12 //p' )" != "" ] ; then
  367. DownBurst2=$( echo ${line} | sed -n -e 's/.* burst \([a-zA-z0-9]*\).*/\1/p' )
  368. DownCburst2=$( echo ${line} | sed -n -e 's/.*cburst \([a-zA-z0-9]*\).*/\1/p' )
  369. fi
  370.  
  371. if [ "$( echo ${line} | sed -n -e 's/.*1:13 //p' )" != "" ] ; then
  372. DownBurst3=$( echo ${line} | sed -n -e 's/.* burst \([a-zA-z0-9]*\).*/\1/p' )
  373. DownCburst3=$( echo ${line} | sed -n -e 's/.*cburst \([a-zA-z0-9]*\).*/\1/p' )
  374. fi
  375.  
  376. if [ "$( echo ${line} | sed -n -e 's/.*1:14 //p' )" != "" ] ; then
  377. DownBurst4=$( echo ${line} | sed -n -e 's/.* burst \([a-zA-z0-9]*\).*/\1/p' )
  378. DownCburst4=$( echo ${line} | sed -n -e 's/.*cburst \([a-zA-z0-9]*\).*/\1/p' )
  379. fi
  380.  
  381. if [ "$( echo ${line} | sed -n -e 's/.*1:15 //p' )" != "" ] ; then
  382. DownBurst5=$( echo ${line} | sed -n -e 's/.* burst \([a-zA-z0-9]*\).*/\1/p' )
  383. DownCburst5=$( echo ${line} | sed -n -e 's/.*cburst \([a-zA-z0-9]*\).*/\1/p' )
  384. fi
  385.  
  386. if [ "$( echo ${line} | sed -n -e 's/.*1:16 //p' )" != "" ] ; then
  387. DownBurst6=$( echo ${line} | sed -n -e 's/.* burst \([a-zA-z0-9]*\).*/\1/p' )
  388. DownCburst6=$( echo ${line} | sed -n -e 's/.*cburst \([a-zA-z0-9]*\).*/\1/p' )
  389. fi
  390.  
  391. if [ "$( echo ${line} | sed -n -e 's/.*1:17 //p' )" != "" ] ; then
  392. DownBurst7=$( echo ${line} | sed -n -e 's/.* burst \([a-zA-z0-9]*\).*/\1/p' )
  393. DownCburst7=$( echo ${line} | sed -n -e 's/.*cburst \([a-zA-z0-9]*\).*/\1/p' )
  394. fi
  395. done <<EOF
  396. $( tc class show dev br0 | grep "parent 1:1 " )
  397. EOF
  398.  
  399. #read existing burst/cburst per upload class
  400. while read -r line;
  401. do
  402. if [ "$( echo ${line} | sed -n -e 's/.*1:10 //p' )" != "" ] ; then
  403. UpBurst0=$( echo ${line} | sed -n -e 's/.* burst \([a-zA-z0-9]*\).*/\1/p' )
  404. UpCburst0=$( echo ${line} | sed -n -e 's/.*cburst \([a-zA-z0-9]*\).*/\1/p' )
  405. fi
  406.  
  407. if [ "$( echo ${line} | sed -n -e 's/.*1:11 //p' )" != "" ] ; then
  408. UpBurst1=$( echo ${line} | sed -n -e 's/.* burst \([a-zA-z0-9]*\).*/\1/p' )
  409. UpCburst1=$( echo ${line} | sed -n -e 's/.*cburst \([a-zA-z0-9]*\).*/\1/p' )
  410. fi
  411.  
  412. if [ "$( echo ${line} | sed -n -e 's/.*1:12 //p' )" != "" ] ; then
  413. UpBurst2=$( echo ${line} | sed -n -e 's/.* burst \([a-zA-z0-9]*\).*/\1/p' )
  414. UpCburst2=$( echo ${line} | sed -n -e 's/.*cburst \([a-zA-z0-9]*\).*/\1/p' )
  415. fi
  416.  
  417. if [ "$( echo ${line} | sed -n -e 's/.*1:13 //p' )" != "" ] ; then
  418. UpBurst3=$( echo ${line} | sed -n -e 's/.* burst \([a-zA-z0-9]*\).*/\1/p' )
  419. UpCburst3=$( echo ${line} | sed -n -e 's/.*cburst \([a-zA-z0-9]*\).*/\1/p' )
  420. fi
  421.  
  422. if [ "$( echo ${line} | sed -n -e 's/.*1:14 //p' )" != "" ] ; then
  423. UpBurst4=$( echo ${line} | sed -n -e 's/.* burst \([a-zA-z0-9]*\).*/\1/p' )
  424. UpCburst4=$( echo ${line} | sed -n -e 's/.*cburst \([a-zA-z0-9]*\).*/\1/p' )
  425. fi
  426.  
  427. if [ "$( echo ${line} | sed -n -e 's/.*1:15 //p' )" != "" ] ; then
  428. UpBurst5=$( echo ${line} | sed -n -e 's/.* burst \([a-zA-z0-9]*\).*/\1/p' )
  429. UpCburst5=$( echo ${line} | sed -n -e 's/.*cburst \([a-zA-z0-9]*\).*/\1/p' )
  430. fi
  431.  
  432. if [ "$( echo ${line} | sed -n -e 's/.*1:16 //p' )" != "" ] ; then
  433. UpBurst6=$( echo ${line} | sed -n -e 's/.* burst \([a-zA-z0-9]*\).*/\1/p' )
  434. UpCburst6=$( echo ${line} | sed -n -e 's/.*cburst \([a-zA-z0-9]*\).*/\1/p' )
  435. fi
  436.  
  437. if [ "$( echo ${line} | sed -n -e 's/.*1:17 //p' )" != "" ] ; then
  438. UpBurst7=$( echo ${line} | sed -n -e 's/.* burst \([a-zA-z0-9]*\).*/\1/p' )
  439. UpCburst7=$( echo ${line} | sed -n -e 's/.*cburst \([a-zA-z0-9]*\).*/\1/p' )
  440. fi
  441. done <<EOF
  442. $( tc class show dev eth0 | grep "parent 1:1 " )
  443. EOF
  444.  
  445.  
  446. #read parameters for fakeTC
  447. PARMS=""
  448. OVERHEAD=$(nvram get qos_overhead)
  449. if [ ! -z "$OVERHEAD" ] && [ "$OVERHEAD" -gt "0" ] ; then
  450. ATM=$(nvram get qos_atm)
  451. if [ "$ATM" == "1" ] ; then
  452. PARMS="overhead $OVERHEAD linklayer atm "
  453. else
  454. PARMS="overhead $OVERHEAD linklayer ethernet "
  455. fi
  456. fi
  457.  
  458.  
  459. }
  460.  
  461. appdb(){
  462.  
  463. if [ "$( grep -i "${1}" /tmp/bwdpi/bwdpi.app.db | wc -l )" -lt "5" ] ; then
  464. grep -i "${1}" /tmp/bwdpi/bwdpi.app.db | while read -r line ; do
  465. echo $line | cut -f 4 -d ","
  466.  
  467. cat_decimal=$(echo $line | cut -f 1 -d "," )
  468. cat_hex=$( printf "80%02x" $cat_decimal )
  469. case "$cat_decimal" in
  470. '9'|'20')
  471. echo " Cat: Net Control"
  472. ;;
  473. '0'|'5'|'6'|'15'|'17')
  474. echo " Cat: VoIP"
  475. ;;
  476. '8')
  477. echo " Cat: Gaming"
  478. ;;
  479. '7'|'10'|'11'|'21'|'23')
  480. echo " Cat: Others"
  481. ;;
  482. '13'|'24'|'18'|'19')
  483. echo " Cat: Web"
  484. ;;
  485. '4'|'12')
  486. echo " Cat: Streaming"
  487. ;;
  488. '1'|'3'|'14')
  489. echo " Cat: Downloads"
  490. ;;
  491. esac
  492.  
  493.  
  494. printf " Mark: 0x${cat_hex}"
  495. echo $line | cut -f 2 -d "," | awk '{printf("%04x 0xc03fffff\n",$1)}'
  496. echo -e " Prio: $(expr $(tc filter show dev br0 | grep "${cat_hex}0000" -B1 | tail -2 | cut -d " " -f7 | head -1) - 1) \n"
  497. done
  498. else
  499. echo "AppDB search parameter has to be more specfic"
  500. fi
  501. }
  502.  
  503. debug(){
  504. current_undf_rule="$(tc filter show dev br0 | grep -v "/" | grep "000ffff" -B1)"
  505. undf_flowid=$(echo $current_undf_rule | grep -o "flowid.*" | cut -d" " -f2 | head -1)
  506. undf_prio=$(echo $current_undf_rule | grep -o "pref.*" | cut -d" " -f2 | head -1)
  507. set_all_varabiles
  508.  
  509. logger -t "adaptive QOS" -s "Undf Prio: $undf_prio"
  510. logger -t "adaptive QOS" -s "Undf FlowID: $undf_flowid"
  511. logger -t "adaptive QOS" -s "Classes Present: $ClassesPresent"
  512. logger -t "adaptive QOS" -s "Down Band: $DownCeil"
  513. logger -t "adaptive QOS" -s "Up Band : $UpCeil"
  514. logger -t "adaptive QOS" -s "***********"
  515. logger -t "adaptive QOS" -s "Net = ${Net}"
  516. logger -t "adaptive QOS" -s "VOIP = ${VOIP}"
  517. logger -t "adaptive QOS" -s "Gaming = ${Gaming}"
  518. logger -t "adaptive QOS" -s "Others = ${Others}"
  519. logger -t "adaptive QOS" -s "Web = ${Web}"
  520. logger -t "adaptive QOS" -s "Streaming = ${Streaming}"
  521. logger -t "adaptive QOS" -s "Downloads = ${Downloads}"
  522. logger -t "adaptive QOS" -s "Defaults = ${Defaults}"
  523. logger -t "adaptive QOS" -s "***********"
  524. logger -t "adaptive QOS" -s "Downrates -- $DownRate0, $DownRate1, $DownRate2, $DownRate3, $DownRate4, $DownRate5, $DownRate6, $DownRate7"
  525. logger -t "adaptive QOS" -s "Downbursts -- $DownBurst0, $DownBurst1, $DownBurst2, $DownBurst3, $DownBurst4, $DownBurst5, $DownBurst6, $DownBurst7"
  526. logger -t "adaptive QOS" -s "DownCbursts -- $DownCburst0, $DownCburst1, $DownCburst2, $DownCburst3, $DownCburst4, $DownCburst5, $DownCburst6, $DownCburst7"
  527. logger -t "adaptive QOS" -s "***********"
  528. logger -t "adaptive QOS" -s "Uprates -- $UpRate0, $UpRate1, $UpRate2, $UpRate3, $UpRate4, $UpRate5, $UpRate6, $UpRate7"
  529. logger -t "adaptive QOS" -s "Upbursts -- $UpBurst0, $UpBurst1, $UpBurst2, $UpBurst3, $UpBurst4, $UpBurst5, $UpBurst6, $UpBurst7"
  530. logger -t "adaptive QOS" -s "UpCbursts -- $UpCburst0, $UpCburst1, $UpCburst2, $UpCburst3, $UpCburst4, $UpCburst5, $UpCburst6, $UpCburst7"
  531. }
  532.  
  533.  
  534. #Main program here, will execute different things depending on arguments
  535. arg1="$(echo "$1" | tr -d "-")"
  536. case "$arg1" in
  537. 'start'|'check'|'mount') ##RAN ON FIREWALL-START OR CRON TASK, (RAN ONLY POST USB MOUNT IF USING STOCK ASUS FIRMWARE)
  538. cru d FreshJR_QOS_run_once
  539. cru a FreshJR_QOS "30 3 * * * /jffs/scripts/FreshJR_QOS -check"
  540. if [ "$(nvram get qos_enable)" == "1" ] ; then
  541. for pid in $(pidof FreshJR_QOS); do
  542. if [ $pid != $$ ]; then
  543. kill $pid
  544. logger -t "adaptive QOS" -s "Delayed Start Cancelled"
  545. fi
  546. done
  547.  
  548. if [ "$arg1" == "start" ] ; then
  549. wan="${2}"
  550. if [ -z "$wan" ] ; then
  551. wan="ppp0"
  552. fi
  553. iptable_down_rules 2>&1 | logger -t "adaptive QOS"
  554. iptable_up_rules 2>&1 | logger -t "adaptive QOS"
  555.  
  556. logger -t "adaptive QOS" -s -- "TC Modification Delayed Start (5min)"
  557. sleep 300s
  558. fi
  559.  
  560. if [ "$arg1" == "mount" ] ; then
  561. logger -t "adaptive QOS" -s -- "--Post USB Mount-- Delayed Start (10min)"
  562. sleep 600s
  563. fi
  564.  
  565. current_undf_rule="$(tc filter show dev br0 | grep -v "/" | grep "000ffff" -B1)"
  566. undf_flowid=$(echo $current_undf_rule | grep -o "flowid.*" | cut -d" " -f2 | head -1)
  567. undf_prio=$(echo $current_undf_rule | grep -o "pref.*" | cut -d" " -f2 | head -1)
  568. if [ -e /jffs/scripts/FreshJR_QOS.debug ] ; then
  569. debug
  570. elif [ "${undf_flowid}" == "1:17" ] ; then #if rule setting unidentified traffic to 1:17 exists then run modification script
  571. if [ "$arg1" == "check" ] ; then
  572. logger -t "adaptive QOS" -s "Scheduled Persistence Check -> Reapplying Changes"
  573. fi
  574.  
  575. if [ "$(nvram get script_usbmount)" == "/jffs/scripts/script_usbmount" ] && [ "$arg1" != "start" ] ; then #used only on stock ASUS firmware -mount && -check script calls
  576. wan="ppp0"
  577. iptable_down_rules 2>&1 | logger -t "adaptive QOS"
  578. iptable_up_rules 2>&1 | logger -t "adaptive QOS"
  579. fi
  580.  
  581. set_all_varabiles
  582. tc_down_rules "$undf_prio" 2>&1 | logger -t "adaptive QOS" #forwards terminal output & errors to logger
  583. tc_up_rules "$undf_prio" 2>&1 | logger -t "adaptive QOS" #forwards terminal output & errors to logger
  584.  
  585. if [ "$ClassesPresent" -lt "8" ] ; then
  586. logger -t "adaptive QOS" -s "Adaptive QOS not fully done setting up prior to modification script"
  587. logger -t "adaptive QOS" -s "(Skipping class modification, delay trigger time period needs increase)"
  588. else
  589. if [ "$DownCeil" -gt "500" ] && [ "$UpCeil" -gt "500" ] ; then
  590. custom_rates 2>&1 | logger -t "adaptive QOS" #forwards terminal output & errors to logger
  591. fi
  592. fi
  593.  
  594. else
  595. if [ "$arg1" == "check" ] ; then
  596. logger -t "adaptive QOS" -s "Scheduled Persistence Check -> No modifications necessary"
  597. else
  598. logger -t "adaptive QOS" -s "No modifications necessary"
  599. fi
  600. fi
  601. fi
  602. ;;
  603. 'install'|'enable') ## INSTALLS AND TURNS ON SCRIPT
  604. if [ -f /jffs/scripts/firewall-start ] ; then #check if firewall-start exists
  605. if grep -q "#!/bin/sh" /jffs/scripts/firewall-start ; then #check if firewall-start header is correct
  606. : #if header is correct, do nothing
  607. else #if header is incorrect, fix header
  608. echo "Detected improper header in firewall-start, fixing header"
  609. sed -i "1i #!/bin/sh" /jffs/scripts/firewall-start
  610. chmod 0755 /jffs/scripts/firewall-start
  611. fi
  612.  
  613. if grep -q -x '/jffs/scripts/FreshJR_QOS -start $1 & ' /jffs/scripts/firewall-start ; then #check if FreshJR_QOS is present as item in firewall start
  614. : #if FreshJR_QOS is present do nothing
  615. else #if not, appened it to the last line (also delete any previously formated entry)
  616. echo "Placing FreshJR_QOS entry into firewall-start"
  617. sed -i '/FreshJR_QOS/d' /jffs/scripts/firewall-start
  618. echo '/jffs/scripts/FreshJR_QOS -start $1 & ' >> /jffs/scripts/firewall-start
  619. fi
  620. else #if firewall-start did not exist then set it up entirely
  621. echo "Firewall-start not detected, creating firewall-start"
  622. echo "Placing FreshJR_QOS entry into firewall-start"
  623. echo "#!/bin/sh" > /jffs/scripts/firewall-start
  624. echo '/jffs/scripts/FreshJR_QOS -start $1 & ' >> /jffs/scripts/firewall-start
  625. chmod 0755 /jffs/scripts/firewall-start
  626. fi
  627. cru a FreshJR_QOS "30 3 * * * /jffs/scripts/FreshJR_QOS -check"
  628. chmod 0755 /jffs/scripts/FreshJR_QOS
  629. echo -e "\033[1;32m FreshJR QOS has been enabled \033[0m"
  630. ;;
  631. 'uninstall') ## UNINSTALLS SCRIPT AND DELETES FILES
  632. sed -i '/FreshJR_QOS/d' /jffs/scripts/firewall-start #remove FreshJR_QOS from firewall start
  633. sed -i '/FreshJR_QOS/d' /jffs/scripts/script_usbmount #remove FreshJR_QOS from script_usbmount - only used on stock ASUS firmware installs
  634. cru d FreshJR_QOS
  635. rm -f /jffs/scripts/FreshJR_QOS
  636. if [ "$(nvram get script_usbmount)" == "/jffs/scripts/script_usbmount" ] ; then #only used on stock ASUS firmware installs
  637. nvram unset script_usbmount
  638. nvram commit
  639. fi
  640. echo -e "\033[1;32m FreshJR QOS has been uninstalled \033[0m"
  641. ;;
  642. 'disable') ## TURNS OFF SCRIPT BUT KEEP FILES
  643. sed -i '/FreshJR_QOS/d' /jffs/scripts/firewall-start
  644. cru d FreshJR_QOS
  645. echo -e "\033[1;32m FreshJR QOS has been disabled \033[0m"
  646. ;;
  647. 'debug')
  648. debug
  649. ;;
  650. 'appdb')
  651. appdb "$2"
  652. ;;
  653. 'stock_install')
  654. chmod 0755 /jffs/scripts/FreshJR_QOS
  655.  
  656. if [ "$(nvram get script_usbmount)" != "/jffs/scripts/script_usbmount" ] ; then
  657. echo -e "\033[1;32m Creating environemnt to trigger scripts post USB Mount \033[0m"
  658. nvram set script_usbmount="/jffs/scripts/script_usbmount"
  659. nvram commit
  660. fi
  661.  
  662. if [ -f /jffs/scripts/script_usbmount ] ; then #check if script_usbmount exists
  663. if grep -q "#!/bin/sh" /jffs/scripts/script_usbmount ; then #check if script_usbmount header is correct
  664. : #if header is correct, do nothing
  665. else #if header is incorrect, fix header
  666. echo " Detected improper header in script_usbmount, fixing header"
  667. sed -i "1i #!/bin/sh" /jffs/scripts/script_usbmount
  668. chmod 0755 /jffs/scripts/script_usbmount
  669. fi
  670.  
  671. sed -i '/FreshJR_QOS/d' /jffs/scripts/script_usbmount
  672. echo '/jffs/scripts/FreshJR_QOS mount &' >> /jffs/scripts/script_usbmount
  673.  
  674. else #if script_usbmount did not exist then set it up entirely
  675. echo " Creating script_usbmount in /jffs/scripts/"
  676. echo " Placing FreshJR_QOS into script_usbmount"
  677. echo "#!/bin/sh" > /jffs/scripts/script_usbmount
  678. echo '/jffs/scripts/FreshJR_QOS mount &' >> /jffs/scripts/script_usbmount
  679. chmod 0755 /jffs/scripts/script_usbmount
  680. fi
  681. echo -e "\033[1;32m FreshJR QOS has been enabled \033[0m"
  682. echo -e "\033[1;32m (observe system log in ~ 5 min for results) \033[0m"
  683.  
  684. cru a FreshJR_QOS_run_once "* * * * * /jffs/scripts/FreshJR_QOS -start &"
  685. ;;
  686. *)
  687. echo "These are available commands:"
  688. echo ""
  689. echo "FreshJR_QOS -install installs script"
  690. echo "FreshJR_QOS -uninstall uninstalls script, deletes from disk "
  691. echo "FreshJR_QOS -enable enables script trigger on firewall-start activity"
  692. echo "FreshJR_QOS -disable disables script trigger on firewall-start activity"
  693. echo "FreshJR_QOS -check instantaneously performs QOS modification if required"
  694. echo ""
  695. echo "FreshJR_QOS -stock_install ** Use this INSTEAD of -install or -enable on stock firmware **"
  696. echo " (this install method requires a USB drive connected to router 24/7) "
  697. echo ""
  698. echo 'FreshJR_QOS -appdb "App Name" Use this to lookup mark/prio paramters required to create an App Analysis redirection rule'
  699. echo ""
  700. ;;
  701. esac
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement