Add CSRF to hostapd config

And tidy things up a bit
This commit is contained in:
Joe Haig
2016-08-05 15:50:05 +01:00
parent 15a4ece433
commit 671016e685
2 changed files with 180 additions and 170 deletions

View File

@@ -20,6 +20,35 @@ function CSRFValidate() {
return hash_equals($_POST['csrf_token'], $_SESSION['csrf_token']);
}
/**
* Test whether array is associative
*/
function isAssoc($arr) {
return array_keys($arr) !== range(0, count($arr) - 1);
}
/**
*
* Display a selector field for a form. Arguments are:
* $name: Field name
* $options: Array of options
* $selected: Selected option (optional)
* If $options is an associative array this should be the key
*
*/
function SelectorOptions($name, $options, $selected = null) {
echo "<select class=\"form-control\" name=\"$name\">";
foreach ( $options as $opt => $label) {
$select = '';
$key = isAssoc($options) ? $opt : $label;
if( $key == $selected ) {
$select = " selected";
}
echo "<option value=\"$key\"$select>$label</options>";
}
echo "</select>";
}
/**
*
* @param string $input