Advertisement
Jungblut

PFSENSE squid balance

Aug 16th, 2019
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.16 KB | None | 0 0
  1. squid_lb_check.sh
  2.  
  3. 1 Acionar modo PHP php -a
  4. No modo PHP
  5.  
  6. 2> require("interfaces.inc");
  7. 3> print_R(return_gateways_status(true));
  8.  
  9.  
  10. 4 criar arquivo /usr/local/etc/squid/squid_lb_check.sh
  11. 5 chmod +x squid_lb_check.sh
  12. 6 Rodar Script Para Criar Instancia
  13.  
  14. 7 NO Squid em Custom ACL
  15. Before Auth Adicionar
  16. > include /usr/local/etc/squid/squid_lb.conf
  17.  
  18. 8 Cria Cron a Cada Minuto para /usr/local/etc/squid/squid_lb_check.sh
  19.  
  20. ----------
  21. Checar Configuracao
  22. SSH
  23.  
  24. cat /usr/local/etc/squid/squid_lb.conf
  25. ----
  26. Conteudo Personalizado
  27.  
  28.  
  29.  
  30. #!/bin/sh
  31.  
  32. SQUID_LB="/usr/local/etc/squid/squid_lb.conf"
  33.  
  34. echo "acl rede_net src 192.168.x.x/x #rede " > $SQUID_LB
  35. echo "acl wifi_net src 192.168.x.x/x #wifi" >> $SQUID_LB
  36.  
  37. ## Checagem WAN1
  38. STATUS=$(/usr/local/bin/php <<'EOF'
  39. <?php
  40. require("interfaces.inc");
  41. print(return_gateways_status(true)['Algar']['status']);
  42. ?>
  43. EOF
  44. )
  45. SRCIP=$(/usr/local/bin/php <<'EOF'
  46. <?php
  47. require("interfaces.inc");
  48. print(return_gateways_status(true)['Algar']['srcip']);
  49. ?>
  50. EOF
  51. )
  52. if [ "$STATUS" = "none" ]; then
  53. echo "tcp_outgoing_address 192.ip da wan rede_net" >> $SQUID_LB
  54. fi
  55. if [ "$STATUS" = "down" ]; then
  56. echo "tcp_outgoing_address 192.ip da wan2 rede_net" >> $SQUID_LB
  57. fi
  58.  
  59. ## Checagem WAN2
  60. STATUS=$(/usr/local/bin/php <<'EOF'
  61. <?php
  62. require("interfaces.inc");
  63. print(return_gateways_status(true)['Internet2']['status']);
  64. ?>
  65. EOF
  66. )
  67. SRCIP=$(/usr/local/bin/php <<'EOF'
  68. <?php
  69. require("interfaces.inc");
  70. print(return_gateways_status(true)['Internet2']['srcip']);
  71. ?>
  72. EOF
  73. )
  74. if [ "$STATUS" = "none" ]; then
  75. echo "tcp_outgoing_address 192.ip da wan wifi_net" >> $SQUID_LB
  76. fi
  77. if [ "$STATUS" = "down" ]; then
  78. echo "tcp_outgoing_address 192.ip da wan 2 wifi_net" >> $SQUID_LB
  79. fi
  80.  
  81.  
  82. if [ -f "$SQUID_LB.md5" ]; then
  83. OLD_MD5=$(cat ${SQUID_LB}.md5)
  84. md5 -q $SQUID_LB > $SQUID_LB.md5
  85. NEW_MD5=$(cat ${SQUID_LB}.md5)
  86. if [ "$OLD_MD5" != "$NEW_MD5" ]; then
  87. squid -k reconfigure
  88. fi
  89. else
  90. md5 -q $SQUID_LB > $SQUID_LB.md5
  91. fi
  92.  
  93.  
  94.  
  95.  
  96.  
  97.  
  98.  
  99. Conteúdo do Script Original
  100.  
  101. #!/bin/sh
  102.  
  103. SQUID_LB="/usr/local/etc/squid/squid_lb.conf"
  104.  
  105. echo "acl rnd random 0.5 # 50 %" > $SQUID_LB
  106.  
  107. ## Checagem WAN1
  108. STATUS=$(/usr/local/bin/php <<'EOF'
  109. <?php
  110. require("interfaces.inc");
  111. print(return_gateways_status(true)['GW_WAN1']['status']);
  112. ?>
  113. EOF
  114. )
  115. SRCIP=$(/usr/local/bin/php <<'EOF'
  116. <?php
  117. require("interfaces.inc");
  118. print(return_gateways_status(true)['GW_WAN1']['srcip']);
  119. ?>
  120. EOF
  121. )
  122. if [ "$STATUS" != "down" ]; then
  123. echo "tcp_outgoing_address $SRCIP rnd" >> $SQUID_LB
  124. fi
  125.  
  126. ## Checagem WAN2
  127. STATUS=$(/usr/local/bin/php <<'EOF'
  128. <?php
  129. require("interfaces.inc");
  130. print(return_gateways_status(true)['GW_WAN2']['status']);
  131. ?>
  132. EOF
  133. )
  134. SRCIP=$(/usr/local/bin/php <<'EOF'
  135. <?php
  136. require("interfaces.inc");
  137. print(return_gateways_status(true)['GW_WAN2']['srcip']);
  138. ?>
  139. EOF
  140. )
  141. if [ "$STATUS" != "down" ]; then
  142. echo "tcp_outgoing_address $SRCIP rnd" >> $SQUID_LB
  143. fi
  144.  
  145. if [ -f "$SQUID_LB.md5" ]; then
  146. OLD_MD5=$(cat ${SQUID_LB}.md5)
  147. md5 -q $SQUID_LB > $SQUID_LB.md5
  148. NEW_MD5=$(cat ${SQUID_LB}.md5)
  149. if [ "$OLD_MD5" != "$NEW_MD5" ]; then
  150. squid -k reconfigure
  151. fi
  152. else
  153. md5 -q $SQUID_LB > $SQUID_LB.md5
  154. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement