Commit 26d4bdf7 authored by Ad Schellevis's avatar Ad Schellevis Committed by Franco Fichtner

(Captiveportal, new) move zoneid from redirect url to generated zone javascript file

(cherry picked from commit 67415c33)
parent 2ddab71d
......@@ -16,6 +16,8 @@
<link href="css/bootstrap.min.css" rel="stylesheet">
<link href="css/signin.css" rel="stylesheet">
<script type="text/javascript" src="js/zone.js"></script>
<script type="text/javascript" src="js/jquery-1.11.2.min.js"></script>
<script>
function getURLparams()
......@@ -42,7 +44,7 @@
// try to login
$.ajax({
type: "POST",
url: "/api/captiveportal/access/logon",
url: "/api/captiveportal/access/logon/" + zoneid + "/",
dataType:"json",
data:{ user: $("#inputUsername").val(), password: $("#inputPassword").val() }
}).done(function(data) {
......
......@@ -39,10 +39,11 @@ from lib import Config
if len(sys.argv) > 1:
cnf = Config()
target_directory = '/var/captiveportal/zone%s/htdocs/' % sys.argv[1]
zoneid = sys.argv[1]
target_directory = '/var/captiveportal/zone%s/htdocs/' % zoneid
template_data = cnf.fetch_template_data(sys.argv[1])
if template_data is not None and len(template_data) > 20:
print ('overlay user template package for zone %s' % sys.argv[1] )
print ('overlay user template package for zone %s' % zoneid )
zip_content = template_data.decode('base64')
input_data = StringIO.StringIO(zip_content)
with zipfile.ZipFile(input_data, mode='r', compression=zipfile.ZIP_DEFLATED) as zf_in:
......@@ -54,5 +55,10 @@ if len(sys.argv) > 1:
os.makedirs(file_target_directory)
with open(target_filename, 'wb') as f_out:
f_out.write(zf_in.read(zf_info.filename))
# write zone settings
filename ='%sjs/zone.js' % target_directory
with open(filename, 'wb') as f_out:
f_out.write('var zoneid = %s' % zoneid)
os.chmod(filename, 0444)
sys.exit(0)
......@@ -23,10 +23,10 @@
{# generate zone redirect address #}
{% if cp_zone_item.certificate|default("") != "" %}
# ssl enabled, redirect to https
{% do cp_zone_item.update({'redirect_host':'https://'+cp_zone_item.interface_hostaddr + ':' ~ (cp_zone_item.zoneid|int + 8000) ~ '/index.html?zone=' ~ cp_zone_item.zoneid }) %}
{% do cp_zone_item.update({'redirect_host':'https://'+cp_zone_item.interface_hostaddr + ':' ~ (cp_zone_item.zoneid|int + 8000) ~ '/index.html'}) %}
{% else %}
# ssl disabled, redirect to http
{% do cp_zone_item.update({'redirect_host':'http://'+cp_zone_item.interface_hostaddr + ':' ~ (cp_zone_item.zoneid|int + 8000) ~ '/index.html?zone=' ~ cp_zone_item.zoneid }) %}
{% do cp_zone_item.update({'redirect_host':'http://'+cp_zone_item.interface_hostaddr + ':' ~ (cp_zone_item.zoneid|int + 8000) ~ '/index.html'}) %}
{% endif %}
{% do cp_zone_item.update({'redirect_host_match':cp_zone_item.interface_hostaddr.replace('.','\.') ~ ':' ~ (cp_zone_item.zoneid|int + 8000) }) %}
......@@ -81,19 +81,19 @@ server.port = {{ cp_zone_item.zoneid|int + 8000 }}
##
$HTTP["host"] !~ "(.*{{cp_zone_item.redirect_host_match}}.*)" {
$HTTP["host"] =~ "([^:/]+)" {
url.redirect = ( "^(.*)$" => "{{cp_zone_item.redirect_host}}&redirurl=%1$1")
url.redirect = ( "^(.*)$" => "{{cp_zone_item.redirect_host}}?redirurl=%1$1")
}
}
## redirect http traffic to http(s) main target
$SERVER["socket"] == ":{{ cp_zone_item.zoneid|int + 9000 }}" {
$HTTP["host"] =~ "([^:/]+)" {
url.redirect = ( "^(.*)$" => "{{cp_zone_item.redirect_host}}&redirurl=%1$1")
url.redirect = ( "^(.*)$" => "{{cp_zone_item.redirect_host}}?redirurl=%1$1")
}
}
$SERVER["socket"] == "[::]:{{ cp_zone_item.zoneid|int + 9000 }}" {
$HTTP["host"] =~ "([^:/]+)" {
url.redirect = ( "(.*)" => "{{cp_zone_item.redirect_host}}&redirurl=%1$1")
url.redirect = ( "(.*)" => "{{cp_zone_item.redirect_host}}?redirurl=%1$1")
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment