Netgate Discussion Forum
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Search
    • Register
    • Login

    Configurar squid numa interface autenticado e na outra transparent

    Scheduled Pinned Locked Moved Portuguese
    34 Posts 6 Posters 6.1k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • R Offline
      rlrobs
      last edited by

      Você nao pode fazer isso aqui na instância:

      http_port 192.168.10.1:3128
      http_port 172.0.0.1:3128 intercept

      Ou é transparente (intercept) ou proxy ativo.

      Crie um squid.conf agrupado por tipo de instância. Ex:

      squid-lab.conf
      http_port 192.168.10.1:3128

      squid.conf
      http_port 172.0.0.1:3128 intercept

      1 Reply Last reply Reply Quote 0
      • G Offline
        gerardocoelho
        last edited by

        Vendo tentando fazer essa configuração, mas sem sucesso.
        Quem conseguiu fazer funcionar poderia fazer um tutorial!?
        Desde já agradeço.
        Att.
        Gerardo Coelho

        1 Reply Last reply Reply Quote 0
        • I Offline
          isaiasbertin
          last edited by

          Quando ativo o proxy transparente na interface funciona e copio o arquivo ele sempre gera assim
          http_port 192.168.10.1:3128
          http_port 127.0.0.1:3128 intercept

          O endereço de rede mais a  loopback
          Pessoal desculpem coloquei errado é a loopback

          Se configurar no navegador funciona quer dizer que o arquivo do squid está OK mais no meu ponto de vista está faltando a entrada PF o encaminhamento para porta 80 para o squid trabalhar transparente

          Quem sabe solicitar ajuda para o Marcello ou Jack

          Mas vamos lá vamos descobrir como colocar esta entrada no PF o firewall

          1 Reply Last reply Reply Quote 0
          • R Offline
            rlrobs
            last edited by

            Seguinte… acabei de refazer os testes e só funcionou quando eu deixei a instância padrão (configurada via webgui) como transparente e a segunda instância como autenticada. Segue os arquivos de configuração de cada.

            Instancia padrão squid.conf e transparente. (Deve ser configurada no webgi)

            
            # This file is automatically generated by pfSense
            # Do not edit manually !
            
            http_port 10.40.0.1:3128
            http_port 127.0.0.1:3128 intercept
            icp_port 0
            dns_v4_first on
            pid_filename /var/run/squid/squid.pid
            cache_effective_user squid
            cache_effective_group proxy
            error_default_language en
            icon_directory /usr/local/etc/squid/icons
            visible_hostname proxy
            cache_mgr admin@localhost
            access_log /var/squid/logs/access.log
            cache_log /var/squid/logs/cache.log
            cache_store_log none
            netdb_filename /var/squid/logs/netdb.state
            pinger_enable on
            pinger_program /usr/local/libexec/squid/pinger
            
            logfile_rotate 0
            debug_options rotate=0
            shutdown_lifetime 3 seconds
            # Allow local network(s) on interface(s)
            acl localnet src  10.40.0.0/16
            forwarded_for on
            uri_whitespace strip
            
            acl dynamic urlpath_regex cgi-bin \?
            cache deny dynamic
            
            cache_mem 64 MB
            maximum_object_size_in_memory 256 KB
            memory_replacement_policy heap GDSF
            cache_replacement_policy heap LFUDA
            minimum_object_size 0 KB
            maximum_object_size 4 MB
            
            offline_mode off
            cache_swap_low 90
            cache_swap_high 95
            cache allow all
            # Add any of your own refresh_pattern entries above these.
            refresh_pattern ^ftp:    1440  20%  10080
            refresh_pattern ^gopher:  1440  0%  1440
            refresh_pattern -i (/cgi-bin/|\?) 0  0%  0
            refresh_pattern .    0  20%  4320
            
            #Remote proxies
            
            # Setup some default acls
            # From 3.2 further configuration cleanups have been done to make things easier and safer. The manager, localhost, and to_localhost ACL definitions are now built-in.
            # acl localhost src 127.0.0.1/32
            acl allsrc src all
            acl safeports port 21 70 80 210 280 443 488 563 591 631 777 901  3128 3129 1025-65535 
            acl sslports port 443 563  
            
            # From 3.2 further configuration cleanups have been done to make things easier and safer. The manager, localhost, and to_localhost ACL definitions are now built-in.
            #acl manager proto cache_object
            
            acl purge method PURGE
            acl connect method CONNECT
            
            # Define protocols used for redirects
            acl HTTP proto HTTP
            acl HTTPS proto HTTPS
            acl allowed_subnets src 10.40.0.0/16
            http_access allow manager localhost
            
            http_access deny manager
            http_access allow purge localhost
            http_access deny purge
            http_access deny !safeports
            http_access deny CONNECT !sslports
            
            # Always allow localhost connections
            # From 3.2 further configuration cleanups have been done to make things easier and safer.
            # The manager, localhost, and to_localhost ACL definitions are now built-in.
            # http_access allow localhost
            
            request_body_max_size 0 KB
            delay_pools 1
            delay_class 1 2
            delay_parameters 1 -1/-1 -1/-1
            delay_initial_bucket_level 100
            delay_access 1 allow allsrc
            
            # Reverse Proxy settings
            
            # Package Integration
            url_rewrite_program /usr/local/bin/squidGuard -c /usr/local/etc/squidGuard/squidGuard.conf
            url_rewrite_bypass off
            url_rewrite_children 16 startup=8 idle=4 concurrency=0
            
            # Custom options before auth
            
            acl sglog url_regex -i sgr=ACCESSDENIED
            http_access deny sglog
            # Setup allowed ACLs
            # Allow local network(s) on interface(s)
            http_access allow allowed_subnets
            http_access allow localnet
            # Default block all to be sure
            http_access deny allsrc
            
            

            Segunda instância. proxy ativo (configurada apenas via cli)
            Obs: estou usando autenticação com o AD. lembre-se de trocar as redes.

            
            # This file is automatically generated by pfSense
            # Do not edit manually !
            #squid autenticado
            
            http_port 10.20.0.1:3128
            #http_port 127.0.0.1:3128
            icp_port 0
            dns_v4_first on
            pid_filename /var/run/squid/squid-auth.pid
            cache_effective_user squid
            cache_effective_group proxy
            error_default_language en
            icon_directory /usr/local/etc/squid/icons
            visible_hostname localhost
            cache_mgr admin@localhost
            access_log /var/squid/logs/access.log
            cache_log /var/squid/logs/cache.log
            cache_store_log none
            netdb_filename /var/squid/logs/netdb.state
            pinger_enable on
            pinger_program /usr/local/libexec/squid/pinger
            
            logfile_rotate 0
            debug_options rotate=0
            shutdown_lifetime 3 seconds
            # Allow local network(s) on interface(s)
            acl localnet src  10.20.0.0/16 127.0.0.0/8
            forwarded_for on
            uri_whitespace strip
            
            acl dynamic urlpath_regex cgi-bin \?
            cache deny dynamic
            
            cache_mem 64 MB
            maximum_object_size_in_memory 256 KB
            memory_replacement_policy heap GDSF
            cache_replacement_policy heap LFUDA
            minimum_object_size 0 KB
            maximum_object_size 4 MB
            
            offline_mode off
            cache_swap_low 90
            cache_swap_high 95
            cache allow all
            # Add any of your own refresh_pattern entries above these.
            refresh_pattern ^ftp:    1440  20%  10080
            refresh_pattern ^gopher:  1440  0%  1440
            refresh_pattern -i (/cgi-bin/|\?) 0  0%  0
            refresh_pattern .    0  20%  4320
            
            #Remote proxies
            
            # Setup some default acls
            # From 3.2 further configuration cleanups have been done to make things easier and safer. The manager, localhost, and to_localhost ACL definitions are now built-in.
            # acl localhost src 127.0.0.1/32
            acl allsrc src all
            acl safeports port 21 70 80 210 280 443 488 563 591 631 777 901 8443 3128 3129 1025-65535 
            acl sslports port 443 563 8443 
            
            # From 3.2 further configuration cleanups have been done to make things easier and safer. The manager, localhost, and to_localhost ACL definitions are now built-in.
            #acl manager proto cache_object
            
            acl purge method PURGE
            acl connect method CONNECT
            
            # Define protocols used for redirects
            acl HTTP proto HTTP
            acl HTTPS proto HTTPS
            acl allowed_subnets src 10.20.0.0/16
            http_access allow manager localhost
            
            http_access deny manager
            http_access allow purge localhost
            http_access deny purge
            http_access deny !safeports
            http_access deny CONNECT !sslports
            
            # Always allow localhost connections
            # From 3.2 further configuration cleanups have been done to make things easier and safer.
            # The manager, localhost, and to_localhost ACL definitions are now built-in.
            # http_access allow localhost
            
            request_body_max_size 0 KB
            delay_pools 1
            delay_class 1 2
            delay_parameters 1 -1/-1 -1/-1
            delay_initial_bucket_level 100
            delay_access 1 allow allsrc
            
            # Reverse Proxy settings
            
            # Package Integration
            url_rewrite_program /usr/local/bin/squidGuard -c /usr/local/etc/squidGuard/squidGuard.conf
            url_rewrite_bypass off
            url_rewrite_children 16 startup=8 idle=4 concurrency=0
            
            # Custom options before auth
            
            acl sglog url_regex -i sgr=ACCESSDENIED
            auth_param basic program /usr/local/libexec/squid/basic_ldap_auth -v 3 -b dc=ifg,dc=teste -D cn=Administrator,cn=Users,dc=ifg,dc=teste -w 123456 -f "sAMAccountName=%s" -u uid -P 10.30.0.10:389
            auth_param basic children 5
            auth_param basic realm Please enter your credentials to access the proxy
            auth_param basic credentialsttl 5 minutes
            acl password proxy_auth REQUIRED
            # Custom options after auth
            
            http_access deny password sglog
            http_access allow password localnet
            http_access allow password allowed_subnets
            # Default block all to be sure
            http_access deny allsrc
            
            

            Script de inicialização da segunda instância. (iniciará no boot)
            Pf 2.3: /usr/local/etc/rc.d/check_squid-auth.sh

            
            #!/bin/sh
            
            /bin/ps ax | /usr/bin/grep /usr/local/etc/squid/squid-auth.conf | /usr/bin/grep -v grep
            if [ $? -eq 0 ];then
                /bin/echo ok
            else
                /usr/local/sbin/squid -f /usr/local/etc/squid/squid-auth.conf
            fi
            
            

            Dessa forma ai eu consegui fazer funcionar.

            1 Reply Last reply Reply Quote 0
            • G Offline
              gerardocoelho
              last edited by

              No meu caso preciso usar uma instancia como transparente para rede wifi com captive portal ( autenticacao e vouchers)
              E a outra instancia proxy ativo para rede dos funcionários.
              Preciso pegar os logs de acesso das duas redes.
              Você testou se esta pegando os logs de acesso das duas redes?

              1 Reply Last reply Reply Quote 0
              • R Offline
                rlrobs
                last edited by

                Pra integrar o captive ao squid vc tem q trocar o script check_ip.sh pq o original tem bug. Depois posto o script q funciona aqui ,mas se quiser adiantar da uma pesquisada aqui no fórum em português… tem um colega q postou um  script q funciona.

                1 Reply Last reply Reply Quote 0
                • G Offline
                  gerardocoelho
                  last edited by

                  Vou ver…
                  testou se esta pegando os logs de acesso das duas redes?
                  Eu uso aqui o LogSquid, muito bom por sinal.

                  1 Reply Last reply Reply Quote 0
                  • I Offline
                    isaiasbertin
                    last edited by

                    Nós meus teste aparece na interface web os logs do squid das duas redes.

                    Vou fazer os teste que nosso colega passou
                    Ai passo para vcs

                    1 Reply Last reply Reply Quote 0
                    • R Offline
                      rlrobs
                      last edited by

                      Sim.. os logs do webgui são das duas instâncias pq elas compartilham o cache.log e o access.log.

                      1 Reply Last reply Reply Quote 0
                      • I Offline
                        isaiasbertin
                        last edited by

                        Este post está merecendo um belo de toturial né rlrobs

                        1 Reply Last reply Reply Quote 0
                        • G Offline
                          gerardocoelho
                          last edited by

                          Poderia enviar o script do captive portal funcionando? Eu até testei o captive portal no 2.3.1 e parece que está ok nos meus testes, mas não coloquei em um ambiente de produção.
                          Você ativou o wpad na rede do proxy autenticado?
                          Já testei vários tutoriais sem sucesso, se puder enviar, agradeço.
                          Att.
                          Gerardo Coelho

                          1 Reply Last reply Reply Quote 0
                          • R Offline
                            rlrobs
                            last edited by

                            O captive portal funciona ta normal sim. O problema é quando você muda a autenticação do squid para "captive portal". Além de nao  navegar, não loga os acessos dos usuários. Pra corrigir isso troque o conteúdo do script /usr/local/bin/check_ip.php por esse abaixo:

                            Obs: após a troca do conteúdo edite as configurações do squid e do captive portal e mande salvar (não precisa modificar)

                            
                            #!/usr/local/bin/php-cgi -q
                            /*
                            	check_ip.php
                            	part of pfSense (https://www.pfSense.org/)
                            	Copyright (C) 2013-2016 Marcello Coutinho
                            	Copyright (C) 2016 ESF, LLC
                            	All rights reserved.
                            
                            	Redistribution and use in source and binary forms, with or without
                            	modification, are permitted provided that the following conditions are met:
                            
                            	1\. Redistributions of source code must retain the above copyright notice,
                            	   this list of conditions and the following disclaimer.
                            
                            	2\. Redistributions in binary form must reproduce the above copyright
                            	   notice, this list of conditions and the following disclaimer in the
                            	   documentation and/or other materials provided with the distribution.
                            
                            	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
                            	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
                            	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
                            	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
                            	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
                            	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
                            	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
                            	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
                            	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
                            	POSSIBILITY OF SUCH DAMAGE.
                            */
                            require_once("config.inc");
                            require_once("globals.inc");
                            if (!extension_loaded('sqlite3')) {
                            dl("sqlite3.so");
                            }
                            error_reporting(0);
                            global $g;
                            // stdin loop
                            if (!defined(STDIN)) {
                            	define("STDIN", fopen("php://stdin", "r"));
                            }
                            if (!defined(STDOUT)) {
                            	define("STDOUT", fopen('php://stdout', 'w'));
                            }
                            while (!feof(STDIN)) {
                            	$line = trim(fgets(STDIN));
                            	$files = glob("{$g['vardb_path']}/captive*.db");
                            	$answer="ERR";
                            	foreach ($files as $file) {
                            		$result = squid_cp_read_db($file);
                            	foreach ($result as $row) {
                            //Database contains 5 fields: 1461302438 - 2006 - 192.168.4.100 - fc:aa:14:7d:e6:de - admin - 80b7d55a1bacb9c6
                            			if ($row[2] != "" && $row[2] == $line) {
                            				$answer = "OK user={$row[4]}";
                            				break 2;
                            			}
                            		}
                            	}
                            	fwrite(STDOUT, "{$answer}\n");
                            }
                            /* read captive portal DB into array */
                            function squid_cp_read_db($file) {
                            	$cpdb = array();
                            	$DB = new SQLite3($file);
                            	if ($DB) {
                            		$response = $DB->query("SELECT * FROM captiveportal");
                            		if ($response != FALSE) {
                            			while ($row = $response->fetchArray()) {
                            				$cpdb[] = $row;
                            			}
                            		}
                            		$DB->close();
                            	}
                            	return $cpdb;
                            }
                            
                            ?>
                            
                            
                            1 Reply Last reply Reply Quote 0
                            • marcellocM Offline
                              marcelloc
                              last edited by

                              Já tentaram no lugar de dois squid rodando, apenas um com custom acls?

                              Treinamentos de Elite: http://sys-squad.com

                              Help a community developer! ;D

                              1 Reply Last reply Reply Quote 0
                              • R Offline
                                rlrobs
                                last edited by

                                @marcelloc:

                                Já tentaram no lugar de dois squid rodando, apenas um com custom acls?

                                Não tentei. Confesso que nao manjo muito dessas ACLs do squid, mas cheguei a pensar nisso. Na verdade seria uma opção mais elegante. :D

                                1 Reply Last reply Reply Quote 0
                                • marcellocM Offline
                                  marcelloc
                                  last edited by

                                  @rlrobs:

                                  Na verdade seria uma opção mais elegante.

                                  Além de elegante, fica tudo no backup e não precisaria de patches ou arquivos criados na mão.

                                  Treinamentos de Elite: http://sys-squad.com

                                  Help a community developer! ;D

                                  1 Reply Last reply Reply Quote 0
                                  • I Offline
                                    isaiasbertin
                                    last edited by

                                    Marcello já tentei fazer isso, mas do jeito que fiz não consegui criar as entradas no firewall pf que seria responsável por redirecionar a porta 80 para 3128 pois quando seleciona as interfaces e digo que são transparentes ele cria automaticamente duas entradas no firewall pf uma pass e uma rdr essas eu não consegui reproduzir na interface web que dica vc nos dá

                                    1 Reply Last reply Reply Quote 0
                                    • marcellocM Offline
                                      marcelloc
                                      last edited by

                                      O rdr é um nat.

                                      Treinamentos de Elite: http://sys-squad.com

                                      Help a community developer! ;D

                                      1 Reply Last reply Reply Quote 0
                                      • I Offline
                                        isaiasbertin
                                        last edited by

                                        Podes dar um exemplo na interface web como fazer isso pois confesso tentei fazer mas não consegui

                                        1 Reply Last reply Reply Quote 0
                                        • G Offline
                                          gerardocoelho
                                          last edited by

                                          Não consegui rodar o squid em duas instancias…
                                          Configurei para cada interface o que eu queria, copiei o squid.conf das duas...
                                          mas acho que tem algo errado no script que peguei aqui...
                                          Meu cenário sao duas WANS, uma LAN (rede com proxy ativo) e LANWIFI(rede com proxy transparente).

                                          Esse script abaixo é pra rodar a outra configuração de proxy do squid

                                          
                                          Script de inicialização da segunda instância. (iniciará no boot) 
                                          Pf 2.3: /usr/local/etc/rc.d/check_squid-auth.sh
                                          
                                          #!/bin/sh
                                          
                                          /bin/ps ax | /usr/bin/grep /usr/local/etc/squid/squid-auth.conf | /usr/bin/grep -v grep
                                          if [ $? -eq 0 ];then
                                              /bin/echo ok
                                          else
                                              /usr/local/sbin/squid -f /usr/local/etc/squid/squid-auth.conf
                                          fi
                                          
                                          
                                          1 Reply Last reply Reply Quote 0
                                          • First post
                                            Last post
                                          Copyright 2025 Rubicon Communications LLC (Netgate). All rights reserved.