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

    Modifying squid.conf when WAN is up / down ?

    Scheduled Pinned Locked Moved pfSense Packages
    7 Posts 3 Posters 3.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.
    • G
      Guldil
      last edited by

      Hi,

      I don't know if it's possible but to solve my problem and use a backup proxy available in OPT1, a solution could be to change squid.conf in real time.

      If WAN is up, squid is up in transparent mode with SquidGuard or HAVP for high security.
      If WAN is down, squid is not in transparent mode and just use a parent proxy and "never_direct allow all" is activated.

      I think i can create the two squid.conf but i dont know how to monitor WAN and execute a script ?

      With PHPService ?
      And to reload squid ?

      Thanks

      Guldil.

      1 Reply Last reply Reply Quote 0
      • D
        dvserg
        last edited by

        As variant:

        • make and start sh/php script for monitoring Wan state
        1. get string from grep ifconfig wan state & memory last state
        2. check state change with prevoius
        3. if state changed - reconfigure squid, else - nothing
        4. sleep 30-60c
        5. goto 1

        squid reconfiguring :

        • stop squid:  killall squid
        • start squid: squid …tram-pam-pam-keys.. /selected_config_path

        SquidGuardDoc EN  RU Tutorial
        Localization ru_PFSense

        1 Reply Last reply Reply Quote 0
        • G
          Guldil
          last edited by

          Ok thanks i'm on the good way then.

          Squid.conf is generated by pfsense on start / stop service right ?

          But where are stored the configuration ?

          I want to make something smart, stop squid, modifying squid.conf stored in Pfsense, start squid.
          So i just have to put my conf somewhere but if i control with WebGUI i'll see the real conf.

          EDIT :
          with this kind of php code i can change my config :)

          
          require_once("pfsense-utils.inc");
          require_once("functions.inc");
          require_once('config.inc');
          
          var_dump($config['installedpackages']['squid']);
          var_dump($config['installedpackages']['squidcache']);
          
          $config['installedpackages']['squid']['config'][0]['admin_email'] = "admin@localhost";
          
          write_config();
          
          1 Reply Last reply Reply Quote 0
          • D
            dvserg
            last edited by

            squid config generated by squid_resync() cmd or by Save button ib GUI or by pfSense restart.
            squid service start/stop use current config.
            if you want generate config with GUI mechanism - use php script

            …
            required_once ('squid.inc');
            ...

            setup new config

            ...
            write_config();
            squid_resync();
            ...

            But bad way generate new conf each up<>down state WAN Maybe need recheck state via timeout

            <monitor state="" cycle="">test state - if changed - wite (30-60s) - check state new => generate squid conf
            ..</monitor>

            SquidGuardDoc EN  RU Tutorial
            Localization ru_PFSense

            1 Reply Last reply Reply Quote 0
            • G
              Guldil
              last edited by

              Thanks a lot dvserg, it's working :)

              1 Reply Last reply Reply Quote 0
              • T
                tommyboy180
                last edited by

                Can you attach the code and make this a sticky. This would be really useful for many people.

                -Tom Schaefer
                SuperMicro 1U 2X Intel pro/1000 Dual Core Intel 2.2 Ghz - 2 Gig RAM

                Please support pfBlocker | File Browser | Strikeback

                1 Reply Last reply Reply Quote 0
                • G
                  Guldil
                  last edited by

                  Finally it dosen't work :(
                  With my multiwan config squid on the pfsense is lost with DNS resolution…Sometimes it's working, sometimes not...The OPT1 is really important for my client so i need a perfect access.

                  I put a debian lenny only with squid3 on my lan and it's working really better, the squid is configured to use the pfsense as DNS server and default gateway.
                  If i put down my WAN connection, it send an alert to the Squid3 wich restart with a special "conf" and use the parent proxy from my OPT1.

                  1 Reply Last reply Reply Quote 0
                  • First post
                    Last post
                  Copyright 2025 Rubicon Communications LLC (Netgate). All rights reserved.