]> jfr.im git - irc/unrealircd/unrealircd-webpanel.git/blobdiff - login/index.php
Now that we have "RPC Servers" in settings, make installer redirect to that.
[irc/unrealircd/unrealircd-webpanel.git] / login / index.php
index 1fd14a37ea9ad958b964c76e9202a578364cbcf7..d2d1700196afcac76a32a54c6eafdf5229172b1b 100644 (file)
@@ -1,18 +1,17 @@
-
 <?php
-require_once "../common.php";
+require_once "../inc/common.php";
 
 $logout = false;
 
-$redirect = BASE_URL;
+$redirect = get_config("base_url");
 if (!empty($_GET['redirect']))
 {
        $str = urldecode($_GET['redirect']);
-       if (str_starts_with($str, BASE_URL)) // prevent redirects to like https://othersite/
+       if (str_starts_with($str, get_config("base_url"))) // prevent redirects to like https://othersite/
                $redirect = $_GET['redirect'];
 }
 
-$redirect = (isset($_GET['redirect'])) ? $_GET['redirect'] : BASE_URL;
+$redirect = (isset($_GET['redirect'])) ? $_GET['redirect'] : get_config("base_url");
 if (!empty($_GET['logout']))
 {
        if (!isset($_SESSION['id']))
@@ -33,21 +32,35 @@ if (!empty($_POST))
 {
        if ($_POST['username'] && $_POST['password'])
        {
-               
-               /* securitah */
-               security_check();
                $user = new PanelUser($_POST['username']);
                /* not being too informative with the login error in case of attackers */
-               if (isset($user->id) && $user->password_verify($_POST['password']))
+               $hash_needs_updating = false;
+               if (isset($user->id) && $user->password_verify($_POST['password'], $hash_needs_updating))
                {
+                       /* SUCCESSFUL LOGIN */
+                       if ($hash_needs_updating)
+                       {
+                               /* Set password again so it is freshly hashed */
+                               $hash = PanelUser::password_hash($_POST['password']);
+                               $ar = ["update_pass_conf"=>$hash];
+                               $user->update_core_info($ar);
+                               unset($ar);
+                               unset($hash);
+                       }
+                       panel_start_session($user);
                        $_SESSION['id'] = $user->id;
-                       header('Location: ' . $redirect);
                        $user->add_meta("last_login", date("Y-m-d H:i:s"));
                        Hook::run(HOOKTYPE_USER_LOGIN, $user);
+
+                       /* Middle of install? Override redirect: */
+                       if (!isset($config['unrealircd']))
+                               $redirect = get_config("base_url")."settings/rpc-servers.php";
+                       header('Location: ' . $redirect);
                        die();
                }
                else
                {
+                       /* LOGIN FAILED */
                        $fail = [
                                "login" => htmlspecialchars($_POST['username']),
                                "IP" => $_SERVER['REMOTE_ADDR']
@@ -63,8 +76,8 @@ if (!empty($_POST))
 
 ?><!DOCTYPE html>
 <head>
-<link href="<?php echo BASE_URL; ?>css/unrealircd-admin.css" rel="stylesheet">
-<script src="<?php echo BASE_URL; ?>js/unrealircd-admin.js"></script>
+<link href="<?php echo get_config("base_url"); ?>css/unrealircd-admin.css" rel="stylesheet">
+<script src="<?php echo get_config("base_url"); ?>js/unrealircd-admin.js"></script>
  <!-- Latest compiled and minified CSS -->
 <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/css/bootstrap.min.css">
 
@@ -80,7 +93,7 @@ if (!empty($_POST))
 <!-- Font Awesome icons -->
 <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.2.1/css/all.min.css">
 
-<link rel="icon" type="image/x-icon" href="<?php echo BASE_URL; ?>img/favicon.ico">
+<link rel="icon" type="image/x-icon" href="<?php echo get_config("base_url"); ?>img/favicon.ico">
 <title>UnrealIRCd Panel</title>
 </head>
 <section class="vh-100">
@@ -90,7 +103,7 @@ if (!empty($_POST))
                <div class="card shadow-2-strong" style="border-radius: 1rem;">
                  <div class="card-body p-5 text-center">
                        <form id="login" method="post" action="index.php?redirect=<?php echo $redirect; ?>">
-                               <h3><img src="<?php echo BASE_URL; ?>img/favicon.ico">  Log in to use Admin Panel</h3>
+                               <h3><img src="<?php echo get_config("base_url"); ?>img/favicon.ico">    Log in to use Admin Panel</h3>
                                
                                        <?php 
                                        if (isset($failmsg)) Message::Fail($failmsg);
@@ -152,4 +165,4 @@ if (!empty($_POST))
        });
 </script>
 
-<?php require_once "../footer.php";
\ No newline at end of file
+<?php require_once "../inc/footer.php";
\ No newline at end of file