Customizable Templates

Customizable Templates

Templates are used throughout Safesquid as a replacement for pages which can't be displayed due to filtering, error, or other conditions. SafeSquid comes with the following default templates:

Default Templates

Template Condition
badauth Authorization failed (when forwarding through SOCKS4)
badprotocol Protocol not implemented
badrequest Malformed HTTP header from client
badresponse Malformed HTTP header from server
blacklisted Page is blacklisted
blocked Page blocked
downloading Download in progress
downloadlimit Download transfer limit exceeded
expired Software license has expired
imgfilter Possible pornographic image
interface.css Web interface stylesheet
maxrequests Request limit exceeded
noaccess Access denied
nocache Cache file not found when browsing in offline mode
noconnect Connection failed
nodns DNS lookup failed
nofile File not found
proxy.pac Returns script to configure the browser to use the proxy
unknown Unknown Error
uploadlimit Upload transfer limit exceeded
userexceeded Max User limit exceeded
virus Virus detected

These templates can be viewed from http://safesquid.cfg/template/blocked (template name)

You can replace the default templates with your own customized templates (SafeSquid Advanced Edition, all Composite and Business Editions, including the free Editions). Customized templates can be really useful, when you would want the error messages to be displayed in a language other than English. It can also be used to display your company logo, warning or message like 'If you feel this site was unnecessarily blocked, please notify the administrator on moc.ynapmocym|ksidpleh#moc.ynapmocym|ksidpleh'.

A template may not necessarily be an html, but can be almost about anything like an audio file, flash file or an executable. It can be used to invoke a file for a specific condition. For example, SafeSquid has 3 built-in templates - tinygif (a 1x1 transparent gif image), checkeredgif (a 4x4 gray and transparent checkered pattern), and tinyswf (an empty flash animation). The checkeredgif template is used by default, to replace images that it blocked by the Pornographic Image Filter add-on module that is used to block pornographic images in real time. So, when the page is displayed to a user, a block of checkered boxes is displayed instead of the blocked image.

There are several variables that can be used in templates if the parsable option is selected which will be replaced with information about the request currently being handled. These variable can be used to generate content in real time.

Template Variables

Variable Description
@AVSCANNER@ The name of Antivirus Scanner used
@CATEGORY@ The Category of Blacklist used
@HTTP_METHOD@ Method used to request file
@HTTP_HOST@ The Host to which HTTP request was made to
@HTTP_FILE@ File HTTP request was made for
@HTTP_PORT@ Port HTTP request was made to
@DOWNLOADLIMIT@ The Limit given to Downloading
@UPLOADLIMIT@ The Limit given to Upload a file
@IP@ IP address of client making request
@INTERFACE@ IP address of the interface the client connected to
@IMAGESCORE@ Score for Individual Images
@IMAGETHRESHOLD@ The cut-off value from which Image is decided as good or bad (porn)
@PORT@ PORT the client connected to
@SIZE@ Amount of value going to transferred
@TRANSFERRED@ Amount of value transferred already
@USERNAME@ The username by which the user logs on after authentication
@URL@ The full URL (the same as @HTTP_METHOD@://@HTTP_HOST@:@HTTP_PORT@@HTTP_FILE@)
@VERSION@ The proxy server version
@VIRUSNAME@ The name of the Virus detected


Web Filter Proxy Interface Screen-shot - Customizable Template
Web Filter Proxy Interface Screen-shot - Customizable Template

Main Section

The directory path on the server where the template files are located
Add a custom template

Sub Section

This option allows you to enable, or completely disable the URL Blacklist Section irrespective of the rules defined in the section

Yes - Enable URL Blacklist Section
No - Disable URL Blacklist Section
A comment for future reference explaining what this rule does
A comma separated list of Profiles on which this rule should apply. The rule applies to every one if this field is left blank
The name by which this template should be referred to in other sections.
The name of the file in template directory, to be used with this template
Mime type
The MIME-type of the template file. When using an executable, this is send in the HTTP response header.
Response code
The response code to use when sending the template. Leave blank to use internal default.
Specify the type of template.

File: The content of the file will be sent as template.
Executable: The file is executed, and whatever it writes on STDOUT, is sent as the template.
If this option is selected, all variables in the template will be substituted.


This example shows how you can replace the default template displayed when a site is blocked by URL Filter section.
Let us presume that this file is called filter.html, and it's simple content is as below -


<title>site is blocked</title>

<h3 align="center"><font color="#FF0000">The site @HTTP_HOST@ is blocked</font></h3>


Copy this file to the directory /opt/safesquid/safesquid/template/ (Linux) or C:\Program Files\SafeSquid\templates (Windows) on the SafeSquid Server. Next, from the SafeSquid Interface (http://safesquid.cfg) go to Config => Template.
Click on 'Add' under the template subsection and add the following rule -

Web Filter Proxy Interface Screen-shot - Customizable Template

Next, go to Config => URL filter, and change the value of 'Default template' to 'filter'

Web Filter Proxy Interface Screen-shot - Customizable Template

Now, when you visit a website that is blocked by URL filter, you will see the new template, instead of the default.

Web Filter Proxy Interface Screen-shot - Customizable Template

Remember to save the changed setting by clicking on Save setting from the Top Menu in the SafeSquid Interface.

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License