Netgate Discussion Forum
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Search
    • Register
    • Login
    Introducing Netgate Nexus: Multi-Instance Management at Your Fingertips.

    Custom SquidGuard Error Pages?

    Scheduled Pinned Locked Moved Cache/Proxy
    28 Posts 8 Posters 13.0k 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.
    • K Offline
      killmasta93
      last edited by

      Hi,
      So im running pfSense 2.2.2 with squid3, squidGuard, and pfBlockerNG.  I use pfBlockerNG to block https (IP) and use squidGuard to block http. Everything is working well. But I would like to have a custom block page. Currently it shows the default blocked page (see picture below). I tried ext url redirect and put in the redirect info www.google.com just to see if redirection is working. Which is not working.

      Thank you

      Capture.1PNG.PNG
      Capture.1PNG.PNG_thumb
      Capture.PNG
      Capture.PNG_thumb

      Tutorials:

      https://www.mediafire.com/folder/v329emaz1e9ih/Tutorials

      1 Reply Last reply Reply Quote 0
      • F Offline
        foresthus
        last edited by

        Hi,

        surely you can change the default look and feel. I changed the behavior directly in the file sgerror.php. I uploaded a logo called "pfsenselogo.png" to the pfsense directory /usr/local/www/. Than I changed the file replacing to original text to this:

        # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        # IE displayed self-page, if them size > 1024
        # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        function get_error_page($er_code_id, $err_msg='') {
                global $err_code;
                global $cl;
                $str = Array();
        
                header("HTTP/1.1 " . $err_code[$er_code_id]);
        				$str[] = '';
        				$str[] = '';
        				$str[] = '';
                $str[] = '';
        				$str[] = '';
        				$str[] = '';
        				$str[] = '
        
        				 [![](http://'. $_SERVER['HTTP_HOST'] .'/pfsenselogo.png "A PROVEN OPEN SOURCE FIREWALL")](http://www.pfsense.org/) |				 Web Filtering by
        **PfSense**, **Squid** and **SquidGuard** |												
        
        ';
        				$str[] = '';
        				$str[] = '';
        				$str[] = ''. $err_msg . ' = '. $err_code[$er_code_id] .' ';
        				$str[] = '';
        				if ($cl['u'])
        								if ($cl['u'])        $str[] = "**Requested URL:**            {$cl['u']} 
        ";
        								if ($cl['a'])        $str[] = "**Client address:**	{$cl['a']} 
        ";
        								if ($cl['n'])        $str[] = "**Client name:**    {$cl['n']} 
        ";
        								if ($cl['i'])        $str[] = "**Client user:**    {$cl['i']} 
        ";
        								if ($cl['s'])        $str[] = "**Group ACL:**   {$cl['s']} 
        ";
        								if ($cl['t'])        $str[] = "**Target Rule:**   {$cl['t']} ";
        				$str[] = '
        
        * * *
        
        ';
        				$str[] = '
        
        **Internet Usage Policy:**
        The requested URL has been blocked by the URL Filter database. The requested site is in a category that is not allowed by your administrator.
        You need to contact your system administrator if the URL is to be enabled.
        
        ';
        				$str[] = '**Steps to get help:**
        Please send the full URL and a screenshot to your [administrator](mailto:webmaster@localhost). The request will be processed as quickly as we can. Thank you for your help and for your patience.';
        				$str[] = 'Generated on,  ';
        				$str[] = "";
        				$str[] = "";
        				return implode("\n", $str);
        }
        
        If you reload your blocked testpage you will see the result.
        
        Surely ther might be a better way for someone else, but it works for me.
        
        ![pfsenselogo.png](/public/_imported_attachments_/1/pfsenselogo.png)
        ![pfsense_block_forum.jpg](/public/_imported_attachments_/1/pfsense_block_forum.jpg)
        ![pfsense_block_forum.jpg_thumb](/public/_imported_attachments_/1/pfsense_block_forum.jpg_thumb)
        
        1 Reply Last reply Reply Quote 0
        • K Offline
          killmasta93
          last edited by

          WOW Thank you so much  ;)

          Tutorials:

          https://www.mediafire.com/folder/v329emaz1e9ih/Tutorials

          1 Reply Last reply Reply Quote 0
          • F Offline
            foresthus
            last edited by

            pleasure.

            smile

            1 Reply Last reply Reply Quote 0
            • A Offline
              awsiemieniec
              last edited by

              Does this work on transparent mode?

              Because when I run it I get an error that makes note of line 126.  I didn't try it before I cut-n-pasted the replacement function/code so I'm not sure if the cut-n-paste broke something or if the error was already there.  I believe it errors out on get_about().

              ?

              thanks

              1 Reply Last reply Reply Quote 0
              • K Offline
                killmasta93
                last edited by

                yeah it worked on transparent mode just make sure you copy and paste correctly dont cut the whole thing just the part which it starts.

                Tutorials:

                https://www.mediafire.com/folder/v329emaz1e9ih/Tutorials

                1 Reply Last reply Reply Quote 0
                • A Offline
                  awsiemieniec
                  last edited by

                  When I get a blocked page I get the following error message instead of the "this has been blocked" page:
                  (see  pic)

                  Maybe my sgerror.php is messed up… ?  Can someone post an original or a modified (to include the modification mention above)?

                  Thx.

                  Capture.PNG
                  Capture.PNG_thumb

                  1 Reply Last reply Reply Quote 0
                  • K Offline
                    killmasta93
                    last edited by

                    it happens if the subnet is not added in the squid proxy see pic

                    Clipboarder.2015.05.30.png
                    Clipboarder.2015.05.30.png_thumb

                    Tutorials:

                    https://www.mediafire.com/folder/v329emaz1e9ih/Tutorials

                    1 Reply Last reply Reply Quote 0
                    • A Offline
                      awsiemieniec
                      last edited by

                      I must have another config setting set incorrectly.  Still not working but I don't want to hijack this thread; I'll open my own.  thx.

                      1 Reply Last reply Reply Quote 0
                      • K Offline
                        killmasta93
                        last edited by

                        it always best sometime to start from scratch reformat everything and install squid3 first configure it then install squidguard configure it then change the php

                        Tutorials:

                        https://www.mediafire.com/folder/v329emaz1e9ih/Tutorials

                        1 Reply Last reply Reply Quote 0
                        • F Offline
                          foresthus
                          last edited by

                          Hi there,

                          I guess that everything works fine with all here.

                          cu  ;)

                          1 Reply Last reply Reply Quote 0
                          • D Offline
                            Dogfish
                            last edited by

                            Hi,
                            Please check my attached page and let me know if you know why it is not showing correct info….thanks.
                            I copied the script into Note ++ and uploaded it. I have tried a few different sgerror.php on the forum, all give a similar result.

                            :-[

                            ![Screenshot 2015-08-31 12.33.44.png](/public/imported_attachments/1/Screenshot 2015-08-31 12.33.44.png)
                            ![Screenshot 2015-08-31 12.33.44.png_thumb](/public/imported_attachments/1/Screenshot 2015-08-31 12.33.44.png_thumb)

                            1 Reply Last reply Reply Quote 0
                            • F Offline
                              foresthus
                              last edited by

                              Hi there,

                              there must be a problem when ypu pasted in the CODE. The Code I posted first is NOT the hole file, is is just a part of it. Recheck this and leave your comment here.

                              1 Reply Last reply Reply Quote 0
                              • D Offline
                                Dogfish
                                last edited by

                                Hi foresthus,
                                I did not back up the original sgerror.php file (my bad).
                                All I have in the file now is the code you posted.
                                Would you be able to share your whole sgerror.php file for me to try?
                                Thanks

                                1 Reply Last reply Reply Quote 0
                                • D Offline
                                  Dogfish
                                  last edited by

                                  I don't think it is incomplete code. I have tried other sgerror.php files on the forum and they all give me similar results. It seems like the commands in the file are not being executed and instead just printed on screen eg: function get_error_page($er_code_id, $err_msg='')
                                  This just comes up as is on the screen when accessing a restricted page.

                                  This is the file I am using at the moment:

                                  # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                                  # IE displayed self-page, if them size > 1024
                                  # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                                  function get_error_page($er_code_id, $err_msg='') {
                                          global $err_code;
                                          global $cl;
                                          global $g;
                                          global $config;
                                          $str = Array();
                                  
                                          header("HTTP/1.1 " . $err_code[$er_code_id]);
                                  		$str[] = '';
                                          $str[] = '';
                                  			$str[] = '<title>Access Denied by EoN Gateway</title>';
                                          $str[] = '';
                                  /*	if ($config['installedpackages']['squidguarddefault']['config'][0]['deniedmessage']) {
                                  		$str[] = "
                                  
                                  ### {$config['installedpackages']['squidguarddefault']['config'][0]['deniedmessage']}: {$err_code[$er_code_id]}
                                  
                                  ";
                                  	} else {
                                  		$str[] = "
                                  
                                  ### Request denied by {$g['product_name']} proxy: {$err_code[$er_code_id]}
                                  
                                  ";
                                  	}
                                  */
                                          $str[] = '';
                                  		$str[] = '';
                                                  if ($cl['n'])        $str[] = "Client Name: {$cl['n']} | ";
                                                  if ($cl['a'])        $str[] = "IP: {$cl['a']} | ";
                                                  if ($cl['i'])        $str[] = "User: {$cl['i']} | ";
                                                  if ($cl['s'])        $str[] = "Group: {$cl['s']} | ";
                                                  if ($cl['t'])        $str[] = "Blocked Category: {$cl['t']} ";
                                  		$str[] = '';
                                  		$str[] = 'Request Denied by Gateway!';
                                  		$str[] = '';
                                  				if ($cl['u'])        $str[] = "
                                  
                                  **URL:** {$cl['u']}
                                  
                                  ";
                                  		$str[] = '
                                  
                                  Access to above site is restricted during office hours (Sunday to Thursday, 9.30am - 6.30pm / Saturday, 10.30am - 3.00pm).
                                   Please try again outside of these hours, or if you need urgent access, discuss with the [System Administrator](mailto:user@domain.com).
                                  
                                  ';
                                  		$str[] = '
                                  
                                  ![geblockt](http://gateway2.domain.local/logo.png)
                                  
                                  ';
                                          $str[] = 'Web Filtering by [**PfSense**](https://pfsense.org) and [**SquidGuard**](http://squidguard.org) | Copyrights © 2014\. Company Name';
                                          $str[] = "";
                                          $str[] = "";
                                  
                                          return implode("\n", $str);
                                  }
                                  

                                  And it looks like this;

                                  ![Screenshot 2015-08-31 17.18.23.png](/public/imported_attachments/1/Screenshot 2015-08-31 17.18.23.png)
                                  ![Screenshot 2015-08-31 17.18.23.png_thumb](/public/imported_attachments/1/Screenshot 2015-08-31 17.18.23.png_thumb)

                                  1 Reply Last reply Reply Quote 0
                                  • KOMK Offline
                                    KOM
                                    last edited by

                                    I don't think it is incomplete code.

                                    Of course it's incomplete code.  You don't even have the PHP declaration at the top.  That's why it doesn't work.  Attached you find a proper sgerror.php.

                                    sgerror.zip

                                    1 Reply Last reply Reply Quote 0
                                    • D Offline
                                      Dogfish
                                      last edited by

                                      Thanks. I understand now. I have it working.

                                      1 Reply Last reply Reply Quote 0
                                      • F Offline
                                        foresthus
                                        last edited by

                                        Hi.

                                        You could also uninstall the addon SquidGuard and then reinstall it again. You should get the original file.

                                        It is always better to make a backup copy. ;)

                                        1 Reply Last reply Reply Quote 0
                                        • KOMK Offline
                                          KOM
                                          last edited by

                                          It is always better to make a backup copy.

                                          In this case it's mandatory.  Every upgrade will overwrite that file with the default copy.

                                          1 Reply Last reply Reply Quote 0
                                          • M Offline
                                            maverik1
                                            last edited by

                                            @killmasta93:

                                            Hi,
                                            So im running pfSense 2.2.2 with squid3, squidGuard, and pfBlockerNG.  I use pfBlockerNG to block https (IP) and use squidGuard to block http. Everything is working well. But I would like to have a custom block page. Currently it shows the default blocked page (see picture below). I tried ext url redirect and put in the redirect info www.google.com just to see if redirection is working. Which is not working.

                                            Thank you

                                            My error pages are showing the client IP and hostname as part of the url like yours is. I've gone through the code as much as I can and can't find anything that would help me to understand why this is happening.

                                            1 Reply Last reply Reply Quote 0
                                            • First post
                                              Last post
                                            Copyright 2026 Rubicon Communications LLC (Netgate). All rights reserved.
                                            Privacy Policy · Cookie Policy