]> jfr.im git - irc/unrealircd/unrealircd-webpanel.git/blob - plugins/sql_auth/login.php
Rather large update, please see commit notes
[irc/unrealircd/unrealircd-webpanel.git] / plugins / sql_auth / login.php
1
2 <?php
3 require_once "../../common.php";
4 require_once "SQL/user.php";
5
6 $logout = false;
7 if (!empty($_GET['logout']))
8 {
9 if (!isset($_SESSION['id']))
10 $failmsg = "Nothing to logout from";
11 else {
12 session_destroy();
13 $logout = true;
14 }
15 }
16 if (!empty($_POST))
17 {
18 if ($_POST['username'] && $_POST['password'])
19 {
20
21 /* securitah */
22 security_check();
23 $user = new SQLA_User($_POST['username']);
24
25 /* not being too informative with the login error in case of attackers */
26 if (!$user->id)
27 {
28 $failmsg = "Incorrect login";
29 }
30 else if ($user->password_verify($_POST['password']))
31 {
32 $_SESSION['id'] = $user->id;
33 header('Location: ' . BASE_URL);
34 $user->add_meta("last_login", date("Y-m-d m:i:s"));
35 }
36 else
37 {
38 $failmsg = "Incorrect login";
39 }
40
41 }
42 else
43 $failmsg = "Couldn't log you in: Missing credentials";
44 }
45
46 ?><!DOCTYPE html>
47 <head>
48 <!-- Latest compiled and minified CSS -->
49 <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/css/bootstrap.min.css">
50
51 <!-- jQuery library -->
52 <script src="https://cdn.jsdelivr.net/npm/jquery@3.6.1/dist/jquery.slim.min.js"></script>
53
54 <!-- Popper JS -->
55 <script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.1/dist/umd/popper.min.js"></script>
56
57 <!-- Latest compiled JavaScript -->
58 <script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/js/bootstrap.bundle.min.js"></script>
59
60 <!-- Font Awesome icons -->
61 <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.2.1/css/all.min.css">
62
63 <script src="<?php echo BASE_URL; ?>js/unrealircd-admin.js"></script>
64 <title>UnrealIRCd Panel</title>
65 <link rel="icon" type="image/x-icon" href="<?php echo BASE_URL; ?>img/favicon.ico">
66 <link href="<?php echo BASE_URL; ?>css/unrealircd-admin.css" rel="stylesheet">
67 </head><div class="text-center">
68 <a href="<?php echo BASE_URL; ?>plugins/sql_auth/login.php"><button type="button" style="margin:0; top:50%; position: absolute;" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#loginModaltitle">
69 Login to continue
70 </button></a>
71 </div>
72 <script>
73 $(document).ready(function(){
74 $("#loginModal").modal('show');
75 });
76 </script>
77 <body role="document">
78 <div class="container-fluid">
79 <form method="post" action="login.php">
80 <div class="modal" id="loginModal" data-bs-backdrop="static" data-bs-keyboard="false" tabindex="-1" aria-labelledby="loginModal" aria-hidden="true">
81 <div class="modal-dialog modal-dialog-centered">
82 <div class="modal-content">
83 <div class="modal-header" style="margin: 0 auto;">
84 <h3 class="modal-title" id="loginModaltitle"><img src="<?php echo BASE_URL; ?>img/favicon.ico"> Log in to use Admin Panel</h3>
85 </div>
86 <div class="modal-body">
87 <div class="form-group">
88 <?php
89 if (isset($failmsg)) Message::Fail($failmsg);
90 if ($logout)
91 Message::Success("You have been logged out");
92 ?>
93 <label for="username">Username / Nick:</label>
94 <input style="width:90%;" type="text" class="form-control" name="username" id="username" >
95 </div>
96 <div class="form-group">
97 <label for="password">Password:</label>
98 <input style="width:90%;" type="password" class="form-control" name="password" id="password">
99 </div>
100 </div>
101 <div class="modal-footer">
102 <a class="btn btn-secondary" href="#">Cancel</a>
103 <button type="submit" class="btn btn-primary">Log-In</button>
104 </div>
105 </div>
106 </div>
107 </div>
108 </form>
109 <?php require_once "../../footer.php";