Skip to content

Commit

Permalink
Move login form to a new page
Browse files Browse the repository at this point in the history
Signed-off-by: RD WebDesign <[email protected]>
  • Loading branch information
rdwebdesign committed Aug 12, 2022
1 parent 3daca13 commit 5091132
Show file tree
Hide file tree
Showing 34 changed files with 553 additions and 442 deletions.
2 changes: 1 addition & 1 deletion api.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
*/

$api = true;
require_once 'scripts/pi-hole/php/FTL.php';
require_once 'scripts/pi-hole/php/password.php';
require_once 'scripts/pi-hole/php/FTL.php';
require_once 'scripts/pi-hole/php/database.php';
require_once 'scripts/pi-hole/php/auth.php';
check_cors();
Expand Down
3 changes: 2 additions & 1 deletion api_db.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
*/

$api = true;
require 'scripts/pi-hole/php/password.php';

header('Content-type: application/json');
require 'scripts/pi-hole/php/database.php';
require 'scripts/pi-hole/php/password.php';
require 'scripts/pi-hole/php/auth.php';
require_once 'scripts/pi-hole/php/func.php';
check_cors();
Expand Down
2 changes: 1 addition & 1 deletion auditlog.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* Please see LICENSE file for your rights under this license.
*/

require 'scripts/pi-hole/php/header.php';
require 'scripts/pi-hole/php/header_authenticated.php';
?>

<!-- Title -->
Expand Down
2 changes: 1 addition & 1 deletion cname_records.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* Please see LICENSE file for your rights under this license.
*/

require 'scripts/pi-hole/php/header.php';
require 'scripts/pi-hole/php/header_authenticated.php';
?>

<!-- Title -->
Expand Down
2 changes: 1 addition & 1 deletion db_graph.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* Please see LICENSE file for your rights under this license.
*/

require 'scripts/pi-hole/php/header.php';
require 'scripts/pi-hole/php/header_authenticated.php';
?>
<!-- Sourceing CSS colors from stylesheet to be used in JS code -->
<span class="queries-permitted"></span>
Expand Down
2 changes: 1 addition & 1 deletion db_lists.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* Please see LICENSE file for your rights under this license.
*/

require 'scripts/pi-hole/php/header.php';
require 'scripts/pi-hole/php/header_authenticated.php';
?>

<!-- Sourceing CSS colors from stylesheet to be used in JS code -->
Expand Down
2 changes: 1 addition & 1 deletion db_queries.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* Please see LICENSE file for your rights under this license.
*/

require 'scripts/pi-hole/php/header.php';
require 'scripts/pi-hole/php/header_authenticated.php';
?>

<!-- Title -->
Expand Down
2 changes: 1 addition & 1 deletion debug.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* Please see LICENSE file for your rights under this license.
*/

require 'scripts/pi-hole/php/header.php';
require 'scripts/pi-hole/php/header_authenticated.php';
?>
<!-- Title -->
<div class="page-header">
Expand Down
2 changes: 1 addition & 1 deletion dns_records.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* Please see LICENSE file for your rights under this license.
*/

require 'scripts/pi-hole/php/header.php';
require 'scripts/pi-hole/php/header_authenticated.php';
?>

<!-- Title -->
Expand Down
2 changes: 1 addition & 1 deletion gravity.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* Please see LICENSE file for your rights under this license.
*/

require 'scripts/pi-hole/php/header.php';
require 'scripts/pi-hole/php/header_authenticated.php';
?>
<!-- Title -->
<div class="page-header">
Expand Down
5 changes: 3 additions & 2 deletions groups-adlists.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php /*
<?php
/*
* Pi-hole: A black hole for Internet advertisements
* (c) 2019 Pi-hole, LLC (https://pi-hole.net)
* Network-wide ad blocking via your own hardware.
Expand All @@ -7,7 +8,7 @@
* Please see LICENSE file for your rights under this license.
*/

require 'scripts/pi-hole/php/header.php';
require 'scripts/pi-hole/php/header_authenticated.php';
?>

<!-- Title -->
Expand Down
2 changes: 1 addition & 1 deletion groups-clients.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* Please see LICENSE file for your rights under this license.
*/

require 'scripts/pi-hole/php/header.php';
require 'scripts/pi-hole/php/header_authenticated.php';
?>

<!-- Title -->
Expand Down
2 changes: 1 addition & 1 deletion groups-domains.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* Please see LICENSE file for your rights under this license.
*/

require 'scripts/pi-hole/php/header.php';
require 'scripts/pi-hole/php/header_authenticated.php';
?>

<!-- Title -->
Expand Down
2 changes: 1 addition & 1 deletion groups.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* Please see LICENSE file for your rights under this license.
*/

require 'scripts/pi-hole/php/header.php';
require 'scripts/pi-hole/php/header_authenticated.php';
?>

<!-- Title -->
Expand Down
2 changes: 1 addition & 1 deletion index.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*/

$indexpage = true;
require 'scripts/pi-hole/php/header.php';
require 'scripts/pi-hole/php/header_authenticated.php';
require_once 'scripts/pi-hole/php/gravity.php';
?>
<!-- Sourceing CSS colors from stylesheet to be used in JS code -->
Expand Down
98 changes: 98 additions & 0 deletions login.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
<?php
/*
* Pi-hole: A black hole for Internet advertisements
* (c) 2017 Pi-hole, LLC (https://pi-hole.net)
* Network-wide ad blocking via your own hardware.
*
* This file is copyright under the latest version of the EUPL.
* Please see LICENSE file for your rights under this license.
*/

require 'scripts/pi-hole/php/password.php';

// Go directly to index, if authenticated.
if ($_SESSION['auth']) {
header('Location: index.php');
exit;
}

require 'scripts/pi-hole/php/theme.php';
require 'scripts/pi-hole/php/header.php';
?>
<body class="hold-transition layout-boxed login-page">
<div class="box login-box">
<section style="padding: 15px;">
<div class="login-logo">
<div class="text-center">
<img src="img/logo.svg" alt="Pi-hole logo" class="loginpage-logo">
</div>
<div class="panel-title text-center"><span class="logo-lg" style="font-size: 25px;">Pi-<b>hole</b></span></div>
</div>
<!-- /.login-logo -->

<div class="card">
<div class="card-body login-card-body">
<div id="cookieInfo" class="panel-title text-center text-red" style="font-size: 150%" hidden>Verify that cookies are allowed for <code><?php echo $_SERVER['HTTP_HOST']; ?></code></div>
<?php if ($wrongpassword) { ?>
<div class="form-group has-error login-box-msg">
<label class="control-label"><i class="fa fa-times-circle"></i> Wrong password!</label>
</div>
<?php } ?>

<form action="" id="loginform" method="post">
<div class="form-group login-options has-feedback<?php if ($wrongpassword) { ?> has-error<?php } ?>">
<div class="pwd-field">
<input type="password" id="loginpw" name="pw" class="form-control" placeholder="Password" autocomplete="current-password" autofocus>
<span class="fa fa-key form-control-feedback"></span>
</div>
<div>
<input type="checkbox" id="logincookie" name="persistentlogin">
<label for="logincookie">Remember me for 7 days</label>
</div>
</div>
<div class="form-group">
<button type="submit" class="btn btn-primary form-control"><i class="fas fa-sign-in-alt"></i>&nbsp;&nbsp;&nbsp;Log in</button>
</div>
</form>
<br>
<div class="row">
<div class="col-xs-12">
<div class="box box-<?php if (!$wrongpassword) { ?>info collapsed-box<?php } else { ?>danger<?php }?>">
<div class="box-header with-border pointer no-user-select" data-widget="collapse">
<h3 class="box-title">Forgot password?</h3>
<div class="box-tools pull-right">
<button type="button" class="btn btn-box-tool">
<i class="fa <?php if ($wrongpassword) { ?>fa-minus<?php } else { ?>fa-plus<?php } ?>"></i>
</button>
</div>
</div>
<div class="box-body">
<p>After installing Pi-hole for the first time, a password is generated and displayed
to the user. The password cannot be retrieved later on, but it is possible to set
a new password (or explicitly disable the password by setting an empty password)
using the command
</p>
<pre>sudo pihole -a -p</pre>
</div>
</div>
</div>
</div>
</div>
<!-- /.login-card-body -->
<div class="login-footer" style="margin-top: 15px; display: flex; justify-content: space-between;">
<a class="btn btn-default btn-sm" role="button" href="https://docs.pi-hole.net/" target="_blank"><i class="fas fa-question-circle"></i> Documentation</a>
<a class="btn btn-default btn-sm" role="button" href="https://github.com/pi-hole/" target="_blank"><i class="fab fa-github"></i> Github</a>
<a class="btn btn-default btn-sm" role="button" href="https://discourse.pi-hole.net/" target="_blank"><i class="fab fa-discourse"></i> Pi-hole Discourse</a>
</div>
</div>
</section>
</div>

<div class="login-donate">
<div class="text-center" style="font-size:125%">
<strong><a href="https://pi-hole.net/donate/" rel="noopener" target="_blank"><i class="fa fa-heart text-red"></i> Donate</a></strong> if you found this useful.
</div>
</div>
<script src="scripts/pi-hole/js/footer.js?v=<?php echo $cacheVer; ?>"></script>
</body>
</html>
9 changes: 9 additions & 0 deletions logout.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

// If the user wants to log out, we free all session variables currently registered
// and delete any persistent cookie.
session_start();
session_unset();
setcookie('persistentlogin', '', 1);
header('Location: login.php');
exit;
2 changes: 1 addition & 1 deletion messages.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* Please see LICENSE file for your rights under this license.
*/

require 'scripts/pi-hole/php/header.php';
require 'scripts/pi-hole/php/header_authenticated.php';
?>

<!-- Title -->
Expand Down
2 changes: 1 addition & 1 deletion network.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* Please see LICENSE file for your rights under this license.
*/

require 'scripts/pi-hole/php/header.php';
require 'scripts/pi-hole/php/header_authenticated.php';
?>

<div class="row">
Expand Down
2 changes: 1 addition & 1 deletion queries.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* Please see LICENSE file for your rights under this license.
*/

require 'scripts/pi-hole/php/header.php';
require 'scripts/pi-hole/php/header_authenticated.php';

$showing = '';

Expand Down
2 changes: 1 addition & 1 deletion queryads.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* Please see LICENSE file for your rights under this license.
*/

require 'scripts/pi-hole/php/header.php';
require 'scripts/pi-hole/php/header_authenticated.php';
?>
<!-- Title -->
<div class="page-header">
Expand Down
49 changes: 27 additions & 22 deletions scripts/pi-hole/js/footer.js
Original file line number Diff line number Diff line change
Expand Up @@ -256,36 +256,41 @@ $("#pihole-disable-custom").on("click", function (e) {
});

// Session timer
var sessionTimerCounter = document.getElementById("sessiontimercounter");
var sessionvalidity = parseInt(sessionTimerCounter.textContent, 10);
var start = new Date();

function updateSessionTimer() {
start = new Date();
start.setSeconds(start.getSeconds() + sessionvalidity);
}

if (sessionvalidity > 0) {
// setSeconds will correctly handle wrap-around cases
updateSessionTimer();
var sessionTimerCounter, sessionvalidity, start;

setInterval(function () {
var current = new Date();
var totalseconds = (start - current) / 1000;
var minutes = Math.floor(totalseconds / 60);
if (minutes < 10) {
minutes = "0" + minutes;
}
var sessiontimer = document.getElementById("sessiontimer");
if (sessiontimer) {
sessionTimerCounter = document.getElementById("sessiontimercounter");
sessionvalidity = parseInt(sessionTimerCounter.textContent, 10);
start = new Date();

var seconds = Math.floor(totalseconds % 60);
if (seconds < 10) {
seconds = "0" + seconds;
}
if (sessionvalidity > 0) {
// setSeconds will correctly handle wrap-around cases
updateSessionTimer();

setInterval(function () {
var current = new Date();
var totalseconds = (start - current) / 1000;
var minutes = Math.floor(totalseconds / 60);
if (minutes < 10) {
minutes = "0" + minutes;
}

var seconds = Math.floor(totalseconds % 60);
if (seconds < 10) {
seconds = "0" + seconds;
}

sessionTimerCounter.textContent = totalseconds > 0 ? minutes + ":" + seconds : "-- : --";
}, 1000);
} else {
document.getElementById("sessiontimer").style.display = "none";
sessionTimerCounter.textContent = totalseconds > 0 ? minutes + ":" + seconds : "-- : --";
}, 1000);
} else {
sessiontimer.style.display = "none";
}
}

// Handle Ctrl + Enter button on Login page
Expand Down
Loading

0 comments on commit 5091132

Please sign in to comment.