lighttpd-zone.conf 9.45 KB
Newer Older
1 2
{# select Captiveportal zone item #}
{% set cp_zone_item = [] %}
3
{% for item in helpers.toList('OPNsense.captiveportal.zones.zone') %}
4
    {% if TARGET_FILTERS['OPNsense.captiveportal.zones.zone.' ~ loop.index0] or TARGET_FILTERS['OPNsense.captiveportal.zones.zone'] %}
5 6 7 8
        {# found zone, search for interface ip #}
        {% for intf_tag in item.interfaces.split(',') %}
            {% for conf_key, conf_inf in interfaces.iteritems() %}
                {% if conf_key == intf_tag and conf_inf.ipaddr != 'dhcp' %}
9
                    {% do item.update({'interface_hostaddr':conf_inf.ipaddr}) %}
10 11 12
                {% endif %}
            {% endfor %}
        {% endfor %}
13 14 15 16 17
        {% do cp_zone_item.append(item) %}
    {% endif %}
{% endfor %}
{% set cp_zone_item = cp_zone_item[0]|default(None) %}

18
{% if cp_zone_item != None %}
19 20 21 22
    {% if cp_zone_item.servername|default("") != "" %}
      {% do cp_zone_item.update({'interface_hostaddr':cp_zone_item.servername}) %}
    {% endif %}

23
    {# generate zone redirect address #}
24 25
    {% if cp_zone_item.certificate|default("") != "" %}
      # ssl enabled, redirect to https
26
      {% do cp_zone_item.update({'redirect_host':'https://'+cp_zone_item.interface_hostaddr + ':'  ~ (cp_zone_item.zoneid|int + 8000) ~ '/index.html'}) %}
27 28
    {% else %}
      # ssl disabled, redirect to http
29
      {% do cp_zone_item.update({'redirect_host':'http://'+cp_zone_item.interface_hostaddr + ':'  ~ (cp_zone_item.zoneid|int + 8000) ~ '/index.html'}) %}
30 31
    {% endif %}
    {% do cp_zone_item.update({'redirect_host_match':cp_zone_item.interface_hostaddr.replace('.','\.') ~ ':' ~ (cp_zone_item.zoneid|int + 8000) }) %}
32

33

34
#############################################################################################
35 36 37
###  Captive portal zone {{ cp_zone_item.zoneid  }} lighttpd.conf  BEGIN
###  -- listen on port {{ cp_zone_item.zoneid|int + 8000  }} for primary (ssl) connections
###  -- forward on port {{ cp_zone_item.zoneid|int + 9000  }} for plain http redirection
38
#############################################################################################
39 40 41 42 43 44 45 46 47 48
#
#### modules to load
server.modules           = ( "mod_expire",
                             "mod_auth",
                             "mod_redirect",
                             "mod_access",
                             "mod_evasive",
                             "mod_compress",
                             "mod_status",
                             "mod_rewrite",
49 50 51
                             "mod_proxy",
                             "mod_setenv",
                             "mod_extforward"
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
                            )

#### performance options (aggressive timeouts)
server.max-keep-alive-requests = 6
server.max-keep-alive-idle = 15
server.max-read-idle     = 15
server.max-write-idle    = 15

## number of child worker processes to spawn (0 for lightly loaded sites)
# server.max-worker      = 0

## number of file descriptors (leave off for lighty loaded sites)
# server.max-fds         = 512

## maximum concurrent connections the server will accept (1/2 of server.max-fds)
# server.max-connections = 256

## single client connection bandwidth limit in kilobytes (0=unlimited)
connection.kbytes-per-second = 0

## global server bandwidth limit in kilobytes (0=unlimited)
server.kbytes-per-second = 0

#### bind to interface (default: all interfaces)
server.bind              = "0.0.0.0"

#### bind to port
79
server.port              = {{ cp_zone_item.zoneid|int + 8000  }}
80 81

##
82
$HTTP["host"] !~ "(.*{{cp_zone_item.redirect_host_match}}.*)" {
83
	$HTTP["host"] =~ "([^:/]+)" {
84
		url.redirect = ( "^(.*)$" => "{{cp_zone_item.redirect_host}}?redirurl=%1$1")
85 86 87
	}
}

88 89
## redirect http traffic to http(s) main target
$SERVER["socket"] == ":{{ cp_zone_item.zoneid|int + 9000 }}" {
90
	$HTTP["host"] =~ "([^:/]+)" {
91
		url.redirect = ( "^(.*)$" => "{{cp_zone_item.redirect_host}}?redirurl=%1$1")
92 93
	}
}
94
$SERVER["socket"] == "[::]:{{ cp_zone_item.zoneid|int + 9000 }}" {
95
	$HTTP["host"] =~ "([^:/]+)" {
96
		url.redirect = ( "(.*)" => "{{cp_zone_item.redirect_host}}?redirurl=%1$1")
97 98 99 100
	}
}

proxy.server = ( "/api/captiveportal/access/" => (
101
		( "host" => "127.0.0.1",
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
		  "port" => 8999 )
	)
)
extforward.headers = ("X-Real-Ip")
server.upload-dirs = ( "/tmp/" )
setenv.add-response-header = ( "Cache-Control" => "no-store, no-cache, must-revalidate, post-check=0, pre-check=0" )
etag.use-inode = "disable"
etag.use-mtime = "disable"
etag.use-size = "disable"


#### run daemon as uid (default: don't care)
server.username          = "www"

#### run daemon as gid (default: don't care)
server.groupname         = "www"

#### set the pid file (newsyslog)
120
server.pid-file          = "/var/run/lighttpd-cp-zone-{{cp_zone_item.zoneid}}.pid"
121

122 123 124
#### errors to syslog
server.errorlog-use-syslog="enable"

125 126 127 128 129 130 131
#### name the server daemon publicly displays
server.tag               = "lighttpd"

#### static document-root
server.document-root     = "/htdocs/"

#### chroot() to captive portal zone directory
132
server.chroot            = "/var/captiveportal/zone{{cp_zone_item.zoneid}}"
133 134 135 136 137 138 139

#### files to check for if .../ is requested
index-file.names         = ( "index.html" )

#### disable auto index directory listings
dir-listing.activate     = "disable"

140
##
141
## ssl configuration
142 143
##
{% if cp_zone_item.certificate|default("") != "" %}
144
ssl.engine = "enable"
145 146 147 148 149 150 151
ssl.pemfile = "/var/etc/cert-cp-zone{{cp_zone_item.zoneid}}.pem"
{# set ca-file if ca is provided #}
{% for certItem in helpers.toList('cert') %}
{%    if certItem.refid == cp_zone_item.certificate and certItem.caref %}
ssl.ca-file = "/var/etc/ca-cp-zone{{cp_zone_item.zoneid}}.pem"
{%    endif %}
{% endfor %}
152 153

ssl.use-sslv2 = "disable"
154
ssl.use-sslv3 = "disable"
155
ssl.cipher-list = "ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA256:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA:DHE-RSA-AES256-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:AES:CAMELLIA:DES-CBC3-SHA:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!PSK:!aECDH:!EDH-DSS-DES-CBC3-SHA:!EDH-RSA-DES-CBC3-SHA:!KRB5-DES-CBC3-SHA"
156 157 158
{% else %}
ssl.engine               = "disable"
{% endif %}
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242

#### compress module
compress.cache-dir       = "/tmp/"
compress.filetype        = ("text/plain", "text/html", "text/css", "image/png")

#### expire module
expire.url               = ( "" => "access plus 6 hours")

#### error pages
server.errorfile-prefix  = "/htdocs/errors/errorcode-"

#### mod_evasive
evasive.max-conns-per-ip = 250

#### limit request method "POST" size in kilobytes (KB)
server.max-request-size    = 2

#### disable multi range requests
server.range-requests    = "disable"

#### disable symlinks
server.follow-symlink    = "disable"

#### ONLY serve files with all lowercase file names
server.force-lowercase-filenames = "disable"

#### mimetype mapping
mimetype.assign             = (
  ".pdf"          =>      "application/pdf",
  ".sig"          =>      "application/pgp-signature",
  ".spl"          =>      "application/futuresplash",
  ".class"        =>      "application/octet-stream",
  ".ps"           =>      "application/postscript",
  ".torrent"      =>      "application/x-bittorrent",
  ".dvi"          =>      "application/x-dvi",
  ".gz"           =>      "application/x-gzip",
  ".pac"          =>      "application/x-ns-proxy-autoconfig",
  ".swf"          =>      "application/x-shockwave-flash",
  ".tar.gz"       =>      "application/x-tgz",
  ".tgz"          =>      "application/x-tgz",
  ".tar"          =>      "application/x-tar",
  ".zip"          =>      "application/zip",
  ".mp3"          =>      "audio/mpeg",
  ".m3u"          =>      "audio/x-mpegurl",
  ".wma"          =>      "audio/x-ms-wma",
  ".wax"          =>      "audio/x-ms-wax",
  ".ogg"          =>      "application/ogg",
  ".wav"          =>      "audio/x-wav",
  ".gif"          =>      "image/gif",
  ".jpg"          =>      "image/jpeg",
  ".jpeg"         =>      "image/jpeg",
  ".png"          =>      "image/png",
  ".xbm"          =>      "image/x-xbitmap",
  ".xpm"          =>      "image/x-xpixmap",
  ".xwd"          =>      "image/x-xwindowdump",
  ".css"          =>      "text/css",
  ".html"         =>      "text/html",
  ".htm"          =>      "text/html",
  ".js"           =>      "text/javascript",
  ".asc"          =>      "text/plain",
  ".c"            =>      "text/plain",
  ".cpp"          =>      "text/plain",
  ".log"          =>      "text/plain",
  ".conf"         =>      "text/plain",
  ".text"         =>      "text/plain",
  ".txt"          =>      "text/plain",
  ".dtd"          =>      "text/xml",
  ".xml"          =>      "text/xml",
  ".mpeg"         =>      "video/mpeg",
  ".mpg"          =>      "video/mpeg",
  ".mov"          =>      "video/quicktime",
  ".qt"           =>      "video/quicktime",
  ".avi"          =>      "video/x-msvideo",
  ".asf"          =>      "video/x-ms-asf",
  ".asx"          =>      "video/x-ms-asf",
  ".wmv"          =>      "video/x-ms-wmv",
  ".bz2"          =>      "application/x-bzip",
  ".tbz"          =>      "application/x-bzip-compressed-tar",
  ".tar.bz2"      =>      "application/x-bzip-compressed-tar"
 )
#
#######################################################
###  Captive Portal lighttpd.conf  END
#######################################################
243
{% endif %}