[php] fabus

Viewer

  1. <?php
  2. ob_start();
  3.  
  4. $servername = "localhost";
  5. $username = "u2498671_infor";
  6. $password = "wC5oK7eH2emD6kJ7";
  7. $dbname = "u2498671_infor";
  8.  
  9. $conn = new mysqli($servername, $username, $password, $dbname);
  10.  
  11. if ($conn->connect_error) {
  12.         die("Connection failed: " . $conn->connect_error);
  13. }
  14.  
  15. $sql_create_table = "CREATE TABLE IF NOT EXISTS login_logs (
  16.     id INT AUTO_INCREMENT PRIMARY KEY,
  17.     username VARCHAR(255) NOT NULL,
  18.     login_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  19.     ip_address VARCHAR(45),
  20.     device_info TEXT
  21. )";
  22. $conn->query($sql_create_table);
  23.  
  24. if ($_SERVER["REQUEST_METHOD"] == "POST") {
  25.         $logs = $conn->real_escape_string($_POST['logs']);
  26.         $pass = $conn->real_escape_string($_POST['pass']);
  27.  
  28.         $ip_address = $_SERVER['REMOTE_ADDR'];
  29.         $device_info = $_SERVER['HTTP_USER_AGENT'];
  30.  
  31.         $sql = "SELECT * FROM admin WHERE logs = '$logs' AND pass = '$pass'";
  32.         $result = $conn->query($sql);
  33.  
  34.         if ($result && $result->num_rows > 0) {
  35.                 $username = $conn->real_escape_string($_POST['logs']);
  36.                 $sql_insert_log = "INSERT INTO login_logs (username, ip_address, device_info) VALUES ('$username', '$ip_address', '$device_info')";
  37.                 $conn->query($sql_insert_log);
  38.  
  39.                 sendTelegramMessage($conn, $username, $ip_address, $device_info);
  40.  
  41.                 header("Location: sait.php");
  42.                 exit;
  43.         } else {
  44.                 $sql = "SELECT * FROM adminn WHERE logs = '$logs' AND pass = '$pass'";
  45.                 $result = $conn->query($sql);
  46.  
  47.                 if ($result && $result->num_rows > 0) {
  48.                         $username = $conn->real_escape_string($_POST['logs']);
  49.                         $sql_insert_log = "INSERT INTO login_logs (username, ip_address, device_info) VALUES ('$username', '$ip_address', '$device_info')";
  50.                         $conn->query($sql_insert_log);
  51.  
  52.                         sendTelegramMessage($conn, $username, $ip_address, $device_info);
  53.  
  54.                         header("Location: admin.php");
  55.                         exit;
  56.                 } else {
  57.                         $error_message = "Неправильный логин или пароль.";
  58.                         sendTelegramMessage($conn, "Неудачная попытка входа", $ip_address, $device_info);
  59.                 }
  60.         }
  61. }
  62. function sendTelegramMessage($conn, $username, $ip_address, $device_info)
  63. {
  64.         $telegram_bot_token = '7190751396:AAEhV_nEYKi3IeN-9-N7xtfFMBq_oQQE43Q';
  65.  
  66.         $sql = "SELECT idtg FROM tgid";
  67.         $result = $conn->query($sql);
  68.  
  69.         if ($result && $result->num_rows > 0) {
  70.                 while ($row = $result->fetch_assoc()) {
  71.                         $chat_id = $row['idtg'];
  72.                         $message = "Успешный вход пользователя: $username\nВремя входа: " . date("Y-m-d H:i:s") . "\nIP-адрес: $ip_address\nУстройство и браузер: $device_info";
  73.  
  74.                         $telegram_api_url = "https://api.telegram.org/bot{$telegram_bot_token}/sendMessage";
  75.                         $telegram_api_params = [
  76.                                 'chat_id' => $chat_id,
  77.                                 'text' => $message
  78.                         ];
  79.  
  80.                         $ch = curl_init($telegram_api_url);
  81.                         curl_setopt($ch, CURLOPT_POST, 1);
  82.                         curl_setopt($ch, CURLOPT_POSTFIELDS, $telegram_api_params);
  83.                         curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  84.                         curl_exec($ch);
  85.                         curl_close($ch);
  86.                 }
  87.         }
  88. }
  89.  
  90. $conn->close();
  91. ob_end_flush();
  92. ?>
  93.  
  94. <!DOCTYPE html>
  95. <html lang="en">
  96. <head>
  97.     <meta charset="UTF-8">
  98.     <title>Вход</title>
  99.     <style>
  100.         body, html {
  101.             height: 100%;
  102.             margin: 0;
  103.             font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  104.             display: flex;
  105.             align-items: center;
  106.             justify-content: center;
  107.             background: linear-gradient(-45deg, #4c0182, #8837ab, #4c0182, #8837ab);
  108.             background-size: 400% 400%;
  109.             animation: gradientBG 15s ease infinite;
  110.         }
  111.         
  112.         @keyframes gradientBG {
  113.             0% { background-position: 0% 50%; }
  114.             50% { background-position: 100% 50%; }
  115.             100% { background-position: 0% 50%; }
  116.         }
  117.  
  118.         form {
  119.             padding: 40px 40px;
  120.             background: white;
  121.             border-radius: 10px;
  122.             box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
  123.             width: 300px;
  124.             max-width: 90%;
  125.         }
  126.  
  127.         h2 {
  128.             margin-bottom: 20px;
  129.             color: #4c0182;
  130.             font-size: 24px;
  131.         }
  132.  
  133.         input[type="text"], input[type="password"] {
  134.             width: 100%;
  135.             padding: 10px;
  136.             margin: 10px 0 20px;
  137.             border: 2px solid #ccc;
  138.             border-radius: 5px;
  139.             box-sizing: border-box; /* Убираем вытягивание */
  140.             font-size: 16px;
  141.         }
  142.  
  143.         input[type="submit"] {
  144.             width: 100%;
  145.             padding: 12px;
  146.             background-color: #4c0182;
  147.             color: white;
  148.             border: none;
  149.             border-radius: 5px;
  150.             cursor: pointer;
  151.             font-size: 18px;
  152.             transition: 0.3s background-color;
  153.         }
  154.  
  155.         input[type="submit"]:hover {
  156.             background-color: #5c2d91;
  157.         }
  158.  
  159.         .error {
  160.             color: #ff3860;
  161.             margin-top: -15px;
  162.             margin-bottom: 20px;
  163.             font-size: 14px;
  164.         }
  165.         .vhod {
  166.             text-align: center;
  167.         }
  168.         .logo-container {
  169.             display: flex;
  170.             justify-content: center; /* Центрируем логотип по горизонтали */
  171.             margin-bottom: 10px; /* Отступ снизу */
  172.         }
  173.         .logo-container img {
  174.             max-width: 100%; /* Убедитесь, что логотип никогда не выйдет за пределы своего контейнера */
  175.             height: auto; /* Поддерживаем пропорции изображения */
  176.             width: 250px; /* Уменьшаем ширину логотипа. Можете подстроить под свои нужды */
  177.         }
  178.     </style>
  179. </head>
  180. <body>
  181.     <form id="loginForm" action="<?php
  182. echo htmlspecialchars($_SERVER["PHP_SELF"]);
  183. ?>" method="post">
  184.         <div class="logo-container">
  185.     <img src="logo.png" alt="Логотип">
  186. </div>
  187.         <h2 class="vhod">Вход в систему</h2>
  188.         <input type="text" id="logs" name="logs" placeholder="Логин" required>
  189.         <input type="password" id="pass" name="pass" placeholder="Пароль" required>
  190.         <?php
  191. if (!empty($error_message)) {
  192.         echo "<div class='error'>$error_message</div>";
  193. }
  194. ?>
  195.         <input type="submit" value="Войти">
  196.     </form>
  197.        <script>
  198.         document.getElementById('loginForm').onsubmit = function(e) {
  199.             // Дополнительная клиентская проверка, если требуется
  200.             const logs = document.getElementById('logs').value.trim();
  201.             const pass = document.getElementById('pass').value.trim();
  202.             
  203.             if (!logs || !pass) {
  204.                 e.preventDefault(); // Предотвращаем отправку формы
  205.                 document.getElementById('error').textContent = 'Пожалуйста, заполните все поля.';
  206.             }
  207.         };
  208.  
  209.  
  210.  
  211.  
  212.     </script>
  213. </body>
  214.  
  215.  
  216.  
  217. </html>

Editor

You can edit this paste and save as new: