Path : /var/www/html/work123/
File Upload :
Current File : /var/www/html/work123/security_tool.php

<?php
// เชื่อมต่อไฟล์ตั้งค่าและฟังก์ชันความปลอดภัย
require_once 'config.php';
require_once 'security.php';
require_once 'functions.php';

$input_text = "";
$result_text = "";
$mode = "";

// ประมวลผลเมื่อมีการกดปุ่ม
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    $input_text = $_POST['input_text'];
    $mode = $_POST['mode'];

    if ($mode == 'encrypt') {
        $result_text = encrypt_password($input_text);
    } else if ($mode == 'decrypt') {
        $result_text = decrypt_password($input_text);
    }
}
?>
<!DOCTYPE html>
<html lang="th">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>เครื่องมือเข้ารหัส - Attendance System</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
    <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Sarabun:wght@300;400;600&display=swap" rel="stylesheet">
    <style>
        body { 
            font-family: 'Sarabun', sans-serif; 
            background: #f0f2f5; 
            min-height: 100vh;
            display: flex;
            align-items: center;
        }
        .card { 
            border: none; 
            border-radius: 20px; 
            box-shadow: 0 15px 35px rgba(0,0,0,0.1); 
        }
        .btn-primary { background-color: #4e73df; border: none; }
        .btn-success { background-color: #1cc88a; border: none; }
        .result-area {
            background-color: #f8f9fc;
            border: 2px dashed #dddfeb;
            border-radius: 15px;
        }
        .nav-link-custom {
            color: #858796;
            text-decoration: none;
            transition: 0.3s;
        }
        .nav-link-custom:hover { color: #4e73df; }
    </style>
</head>
<body>

<div class="container py-5">
    <div class="row justify-content-center">
        <div class="col-md-7 col-lg-6">
            
            <div class="text-center mb-4">
                <h3 class="fw-bold text-dark"><i class="fas fa-shield-alt text-primary me-2"></i>Security Generator</h3>
                <p class="text-muted">จัดการรหัสผ่านสำหรับระบบลงเวลาปฏิบัติงาน</p>
            </div>

            <div class="card">
                <div class="card-body p-4 p-lg-5">
                    <form method="post">
                        <div class="mb-4">
                            <label class="form-label fw-600">ข้อความหรือรหัสผ่านที่ต้องการ</label>
                            <textarea name="input_text" class="form-control form-control-lg border-0 shadow-sm bg-light" 
                                      rows="3" required placeholder="เช่น 123456 หรือรหัสที่เข้ารหัสแล้ว..."
                                      style="border-radius: 12px;"><?php echo htmlspecialchars($input_text); ?></textarea>
                        </div>

                        <div class="row g-3 mb-4">
                            <div class="col-6">
                                <button type="submit" name="mode" value="encrypt" class="btn btn-primary w-100 py-3 rounded-4 shadow-sm">
                                    <i class="fas fa-lock me-2"></i> เข้ารหัส
                                </button>
                            </div>
                            <div class="col-6">
                                <button type="submit" name="mode" value="decrypt" class="btn btn-success text-white w-100 py-3 rounded-4 shadow-sm">
                                    <i class="fas fa-unlock me-2"></i> ถอดรหัส
                                </button>
                            </div>
                        </div>
                    </form>

                    <?php if ($result_text !== ""): ?>
                    <div class="result-area p-4 mt-2">
                        <label class="form-label fw-bold text-secondary mb-2 small uppercase">ผลลัพธ์ที่ได้:</label>
                        <div class="input-group">
                            <input type="text" id="copyTarget" class="form-control border-0 bg-transparent fw-bold text-primary fs-5" 
                                   value="<?php echo htmlspecialchars($result_text); ?>" readonly>
                            <button class="btn btn-outline-primary border-0" type="button" onclick="copyValue()">
                                <i class="fas fa-copy"></i> คัดลอก
                            </button>
                        </div>
                        <?php if ($mode == 'decrypt' && $result_text === false): ?>
                            <div class="text-danger mt-2 small"><i class="fas fa-times-circle me-1"></i> ข้อมูลไม่ถูกต้อง ไม่สามารถถอดรหัสได้</div>
                        <?php endif; ?>
                    </div>
                    <?php endif; ?>
                </div>
            </div>

            <div class="text-center mt-4">
                <a href="index.php" class="nav-link-custom small">
                    <i class="fas fa-arrow-left me-1"></i> กลับไปหน้าเข้าสู่ระบบ
                </a>
            </div>

        </div>
    </div>
</div>

<script>
function copyValue() {
    var copyText = document.getElementById("copyTarget");
    if(copyText.value === "") return;
    
    copyText.select();
    copyText.setSelectionRange(0, 99999);
    navigator.clipboard.writeText(copyText.value);
    
    // แจ้งเตือนสั้นๆ
    alert("คัดลอกรหัสแล้ว!");
}
</script>

<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>