Add simple authentication
parent
926d7ba13b
commit
4e77adce33
@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
function Status($message, $level='success', $dismissable=true) {
|
||||
$status = '<div class="alert alert-'.$level;
|
||||
if ($dismissable) $status .= ' alert-dismissable';
|
||||
$status .= '">'.$message;
|
||||
if ($dismissable) $status .= '<button type="button" class="close" data-dismiss="alert" aria-hidden="true">x</button>';
|
||||
$status .= '</div>';
|
||||
|
||||
return $status;
|
||||
}
|
||||
|
||||
function DisplayRaspAPConfig($username, $password){
|
||||
$status = '';
|
||||
if (isset($_POST['UpdateAdminPassword'])) {
|
||||
if (password_verify($_POST['oldpass'], $password)) {
|
||||
$new_username=trim($_POST['username']);
|
||||
if ($_POST['newpass'] != $_POST['newpassagain']) {
|
||||
$status = Status('New passwords do not match', 'danger');
|
||||
} else if ($new_username == '') {
|
||||
$status = Status('Username must not be empty', 'danger');
|
||||
} else {
|
||||
if ($auth_file = fopen(RASPI_ADMIN_DETAILS, 'w')) {
|
||||
fwrite($auth_file, $new_username.PHP_EOL);
|
||||
fwrite($auth_file, password_hash($_POST['newpass'], PASSWORD_BCRYPT).PHP_EOL);
|
||||
fclose($auth_file);
|
||||
$username = $new_username;
|
||||
$status = Status('Admin password updated');
|
||||
} else {
|
||||
$status = Status('Failed to update admin password', 'danger');
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$status = Status('Old password does not match', 'danger');
|
||||
}
|
||||
}
|
||||
?>
|
||||
<div class="row">
|
||||
<div class="col-lg-12">
|
||||
<div class="panel panel-primary">
|
||||
<div class="panel-heading"><i class="fa fa-dashboard fa-fw"></i>RaspAP Configuration</div>
|
||||
<div class="panel-body">
|
||||
<p><?php echo $status; ?></p>
|
||||
<form role="form" action="/?page=admin_conf" method="POST">
|
||||
<div class="row">
|
||||
<div class="form-group col-md-4">
|
||||
<label for="username">Username</label>
|
||||
<input type="text" class="form-control" name="username" value="<?php echo $username; ?>"/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="form-group col-md-4">
|
||||
<label for="password">Old password</label>
|
||||
<input type="password" class="form-control" name="oldpass"/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="form-group col-md-4">
|
||||
<label for="password">New password</label>
|
||||
<input type="password" class="form-control" name="newpass"/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="form-group col-md-4">
|
||||
<label for="password">Repeat new password</label>
|
||||
<input type="password" class="form-control" name="newpassagain"/>
|
||||
</div>
|
||||
</div>
|
||||
<input type="submit" class="btn btn-outline btn-primary" name="UpdateAdminPassword" value="Save settings" />
|
||||
</form>
|
||||
</div><!-- /.panel-body -->
|
||||
</div><!-- /.panel-default -->
|
||||
</div><!-- /.col-lg-12 -->
|
||||
</div><!-- /.row -->
|
||||
<?php
|
||||
}
|
||||
|
||||
?>
|
@ -0,0 +1,17 @@
|
||||
<?php
|
||||
$valid_passwords = array ("admin" => "admin");
|
||||
$valid_users = array_keys($valid_passwords);
|
||||
|
||||
$user = $_SERVER['PHP_AUTH_USER'];
|
||||
$pass = $_SERVER['PHP_AUTH_PW'];
|
||||
|
||||
//$validated = (in_array($user, $valid_users)) && ($pass == $valid_passwords[$user]);
|
||||
$validated = ($user == $config['admin_user']) && password_verify($pass, $config['admin_pass']);
|
||||
|
||||
if (!$validated) {
|
||||
header('WWW-Authenticate: Basic realm="RaspAP"');
|
||||
header('HTTP/1.0 401 Unauthorized');
|
||||
die ("Not authorized");
|
||||
}
|
||||
|
||||
?>
|
@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
$config = array(
|
||||
'admin_user' => 'admin',
|
||||
'admin_pass' => '$2y$10$YKIyWAmnQLtiJAy6QgHQ.eCpY4m.HCEbiHaTgN6.acNC6bDElzt.i'
|
||||
);
|
||||
|
||||
if ( $auth_details = fopen(RASPI_CONFIG.'/raspap.auth', 'r') ) {
|
||||
$config['admin_user'] = trim(fgets($auth_details));
|
||||
$config['admin_pass'] = trim(fgets($auth_details));
|
||||
fclose($auth_details);
|
||||
}
|
||||
|
||||
?>
|
Loading…
Reference in New Issue