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 @@ ...@@ -16,6 +16,8 @@
<link href="css/bootstrap.min.css" rel="stylesheet"> <link href="css/bootstrap.min.css" rel="stylesheet">
<link href="css/signin.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 type="text/javascript" src="js/jquery-1.11.2.min.js"></script>
<script> <script>
function getURLparams() function getURLparams()
...@@ -42,7 +44,7 @@ ...@@ -42,7 +44,7 @@
// try to login // try to login
$.ajax({ $.ajax({
type: "POST", type: "POST",
url: "/api/captiveportal/access/logon", url: "/api/captiveportal/access/logon/" + zoneid + "/",
dataType:"json", dataType:"json",
data:{ user: $("#inputUsername").val(), password: $("#inputPassword").val() } data:{ user: $("#inputUsername").val(), password: $("#inputPassword").val() }
}).done(function(data) { }).done(function(data) {
......
...@@ -39,10 +39,11 @@ from lib import Config ...@@ -39,10 +39,11 @@ from lib import Config
if len(sys.argv) > 1: if len(sys.argv) > 1:
cnf = Config() 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]) template_data = cnf.fetch_template_data(sys.argv[1])
if template_data is not None and len(template_data) > 20: 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') zip_content = template_data.decode('base64')
input_data = StringIO.StringIO(zip_content) input_data = StringIO.StringIO(zip_content)
with zipfile.ZipFile(input_data, mode='r', compression=zipfile.ZIP_DEFLATED) as zf_in: with zipfile.ZipFile(input_data, mode='r', compression=zipfile.ZIP_DEFLATED) as zf_in:
...@@ -54,5 +55,10 @@ if len(sys.argv) > 1: ...@@ -54,5 +55,10 @@ if len(sys.argv) > 1:
os.makedirs(file_target_directory) os.makedirs(file_target_directory)
with open(target_filename, 'wb') as f_out: with open(target_filename, 'wb') as f_out:
f_out.write(zf_in.read(zf_info.filename)) 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) sys.exit(0)
...@@ -23,10 +23,10 @@ ...@@ -23,10 +23,10 @@
{# generate zone redirect address #} {# generate zone redirect address #}
{% if cp_zone_item.certificate|default("") != "" %} {% if cp_zone_item.certificate|default("") != "" %}
# ssl enabled, redirect to https # 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 %} {% else %}
# ssl disabled, redirect to http # 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 %} {% endif %}
{% do cp_zone_item.update({'redirect_host_match':cp_zone_item.interface_hostaddr.replace('.','\.') ~ ':' ~ (cp_zone_item.zoneid|int + 8000) }) %} {% 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 }} ...@@ -81,19 +81,19 @@ server.port = {{ cp_zone_item.zoneid|int + 8000 }}
## ##
$HTTP["host"] !~ "(.*{{cp_zone_item.redirect_host_match}}.*)" { $HTTP["host"] !~ "(.*{{cp_zone_item.redirect_host_match}}.*)" {
$HTTP["host"] =~ "([^:/]+)" { $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 ## redirect http traffic to http(s) main target
$SERVER["socket"] == ":{{ cp_zone_item.zoneid|int + 9000 }}" { $SERVER["socket"] == ":{{ cp_zone_item.zoneid|int + 9000 }}" {
$HTTP["host"] =~ "([^:/]+)" { $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 }}" { $SERVER["socket"] == "[::]:{{ cp_zone_item.zoneid|int + 9000 }}" {
$HTTP["host"] =~ "([^:/]+)" { $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