Commit fdfd5a95 authored by Martin van Es's avatar Martin van Es
Browse files

WIP

parent 73c88cd8
This diff is collapsed.
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<title>customauth login page</title>
</head>
<body>
<h1>CustomAuth login page</h1>
<form method="post" action="?">
<p><b>Choose User profile</b><p>
<?php
foreach ($this->data['users'] as $user => $values) {
echo "<input type=radio name=username value='$user'> " . $values['displayName'] . "<br>\n";
}
?>
<p><b>Choose attributes</b></p>
<div style="float: left" id="attributes"></div>
<div id="explanation"></div><br style="clear: both" />
<p><b>Released attributes</b></p>
<div id="output"></div>
<input type="hidden" name="ReturnTo" value="<?= htmlspecialchars($this->data['returnTo']) ?>">
<p><input type="submit" value="Log in"></p>
</form>
</body>
<script>
var users = [];
var keys = [];
var user = '';
<?php
foreach ($this->data['users'] as $user => $values) {
echo "users['$user'] = [];\n";
foreach ($values as $key => $value) {
echo "users['$user']['$key'] = '$value';\n";
echo "keys['$key'] = true;";
}
}
?>
function update() {
var html = "";
for (let key in users[user]) {
if (keys[key]) {
html += key + ": " + users[user][key] + "<br />\n";
}
}
$('#output').html(html);
};
$('input[type=radio][name=username]').change(function() {
var attributes = "";
user = this.value;
for (let key in users[user]) {
attribute = users[user][key];
attributes += "<input id=chkbx_" + key + " type=checkbox name=keys[" + key + "] " + (keys[key]?'checked':'') + ">" + key + "<br>\n";
};
$('#attributes').html(attributes);
$('#explanation').html('');
$('input[id^=chkbx_]').change(function() {
var key = this.name.slice(5,-1);
keys[key] = this.checked;
if (this.checked) $('#explanation').html('Ah! You enabled ' + key + '!<br />\nIt\'s allways good to enable ' + key + ', because it\'s good you know!');
else $('#explanation').html('Never disable ' + key + '! You should leave it there.<br />No good will come from disabling ' + key + '!');
});
update();
});
//$('#attributes').change(update);
$('#attributes').change(function() {
update();
});
</script>
</html>
...@@ -23,25 +23,32 @@ ...@@ -23,25 +23,32 @@
<form method="post" action="?"> <form method="post" action="?">
<p><hr/><b>Choose User profile</b></p> <p><hr/><b>Choose User profile</b></p>
<div style="float:left; margin-right: 10px"> <div style="float:left; margin-right: 10px">
<select name=username size=5> <select name=username size=5 style='width: 250px;'>
<?php <?php
foreach ($this->data['users'] as $user => $values) { $first = true;
$uarr = explode(':', $user); $users = $this->data['users'];
$uid = $uarr[0]; $displays = $this->data['displays'];
$display = $this->data['displays'][$user]; $categories = $this->data['categories'];
echo "<option name=\"$uid\" value=\"$uid\">$display</option>\n"; foreach ($categories as $category => $cat) {
if (!$first) echo "<option></option>\n"; $first = false;
echo "<option value=\"$category\">--- $category ---</option>\n";
foreach ($cat['users'] as $user) {
$display = $displays[$user];
echo "<option name=\"$user\" value=\"$user\">$display</option>\n";
}
} }
?> ?>
<option></option>
<option value="Error Scenarios">--- Error Scenarios ---</option>
<option value="error">SAML Error</option>
</select> </select>
</div> </div>
<div id="explanation">Woohaa!</div><br style="clear: both" /> <div id="explanation" style='display: grid'>Woohaa!</div><br style="clear: both" />
<p><hr/><b>Choose attributes</b></p> <p><hr/><b>Choose attributes</b></p>
<div style="float: left" id="attributes"></div> <div style="float: left" id="attributes"></div>
<div id="about"></div><br style="clear: both" /> <div id="about"></div><br style="clear: both" />
<p><hr/><b>Released attributes</b></p> <p><hr/><b>Released attributes</b></p>
<div id="output"></div> <div id="output"></div>
<p><hr/><b>Special</b></p>
<div><input type="checkbox" name="error" value="true"> Create SAML Error Response</div>
<input type="hidden" name="ReturnTo" value="<?= htmlspecialchars($this->data['returnTo']) ?>"> <input type="hidden" name="ReturnTo" value="<?= htmlspecialchars($this->data['returnTo']) ?>">
<p><input id="submit_button" class="btn" type="submit" value="Log in"></p> <p><input id="submit_button" class="btn" type="submit" value="Log in"></p>
</form> </form>
...@@ -69,11 +76,14 @@ ...@@ -69,11 +76,14 @@
} }
?> ?>
explanations['Error Scenarios'] = "These are the Error Scenarios";
explanations['error'] = "This generates a SAML Error";
function update() { function update() {
var html = ""; var html = "";
for (let key in users[user]) { for (let key in users[user]) {
if (keys[key]) { if (keys[key]) {
html += key + ": " + users[user][key] + "<br />\n"; html += "<b>" + key + "</b>: " + users[user][key] + "<br />\n";
} }
} }
$('#output').html(html); $('#output').html(html);
...@@ -84,7 +94,7 @@ ...@@ -84,7 +94,7 @@
user = this.value; user = this.value;
for (let key in users[user]) { for (let key in users[user]) {
attribute = users[user][key]; attribute = users[user][key];
attributes += "<input id=chkbx_" + key + " type=checkbox name=keys[" + key + "] " + (keys[key]?'checked':'') + ">" + key + "<br>\n"; attributes += "<input id=chkbx_" + key + " type=checkbox name=keys[" + key + "] " + (keys[key]?'checked':'') + " value='" + users[user][key] + "'><span title='" + message[key] + "'>" + key + "</span><br>\n";
}; };
$('#explanation').html(explanations[user]); $('#explanation').html(explanations[user]);
$('#attributes').html(attributes); $('#attributes').html(attributes);
......
...@@ -42,34 +42,35 @@ $attributes = json_decode(file_get_contents('/opt/simplesamlphp/config/attribute ...@@ -42,34 +42,35 @@ $attributes = json_decode(file_get_contents('/opt/simplesamlphp/config/attribute
$users = []; $users = [];
$explanations = []; $explanations = [];
$displays = []; $displays = [];
foreach ($raw_users as $user => $values) { $categories = [];
foreach ($raw_users as $category => $cat) {
$categories[$category]['name'] = $category;
$explanations[$category] = $cat['message'];
foreach ($cat['profiles'] as $user => $values) {
$categories[$category]['users'][] = $user;
$explanations[$user] = $values['explanation']; $explanations[$user] = $values['explanation'];
$displays[$user] = $values['display']; $displays[$user] = $values['display'];
$type[$user] = $values['type'];
unset($values['explanation']); unset($values['explanation']);
unset($values['display']); unset($values['display']);
unset($values['type']);
$users[$user] = $values; $users[$user] = $values;
}
} }
// time to handle login responses; since this is a dummy example, we accept any data // time to handle login responses; since this is a dummy example, we accept any data
$badUserPass = false; $badUserPass = false;
if ($_SERVER['REQUEST_METHOD'] === 'POST') { if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$username = (string) $_REQUEST['username'];
$user_aa = $users[$username];
if (!session_id()) { if (!session_id()) {
// session_start not called before. Do it here. // session_start not called before. Do it here.
session_start(); session_start();
} }
foreach ($user_aa as $key => $value) { $attributes = @$_POST['keys'] or [];
if (isset($_POST['keys'][$key])) {
$_SESSION['attributes'][$key] = $value; foreach ($attributes as $key => $value) {
} $_SESSION['attributes'][$key] = $value;
} }
if (isset($_POST['error'])) {
$username = (string) $_REQUEST['username'];
if ($username == 'error') {
$_SESSION['ErrorResponse'] = TRUE; $_SESSION['ErrorResponse'] = TRUE;
} }
...@@ -83,5 +84,6 @@ $t->data['users'] = $users; ...@@ -83,5 +84,6 @@ $t->data['users'] = $users;
$t->data['attributes'] = $attributes; $t->data['attributes'] = $attributes;
$t->data['explanations'] = $explanations; $t->data['explanations'] = $explanations;
$t->data['displays'] = $displays; $t->data['displays'] = $displays;
$t->data['categories'] = $categories;
$t->data['returnTo'] = $returnTo; $t->data['returnTo'] = $returnTo;
$t->show(); $t->show();
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