File size: 14,148 Bytes
a8dbe18
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>EMZ License Manager</title>
    <!-- Tailwind CSS -->
    <script src="https://cdn.tailwindcss.com"></script>
    <!-- Supabase JS Library -->
    <script src="https://cdn.jsdelivr.net/npm/@supabase/supabase-js@2"></script>
    <style>

        body {

            background-color: #080c14;

            color: #ffffff;

            font-family: 'Inter', system-ui, -apple-system, sans-serif;

        }

        .glow-border {

            border: 1px solid rgba(0, 243, 255, 0.4);

            box-shadow: 0 0 20px rgba(0, 243, 255, 0.15);

        }

        .glow-button {

            background: linear-gradient(90deg, #00c6ff, #0072ff);

            transition: all 0.3s ease;

        }

        .glow-button:hover {

            box-shadow: 0 0 15px rgba(0, 198, 255, 0.5);

            opacity: 0.95;

        }

    </style>
</head>
<body class="flex items-center justify-center min-h-screen p-3 sm:p-4 bg-[#080c14]">

    <!-- MAIN CARD CONTAINER (LOGIN & USER REGISTER) -->
    <div id="authContainer" class="w-full max-w-md p-5 sm:p-8 rounded-3xl glow-border bg-[#0f172a] shadow-2xl">
        <div class="text-center mb-6">
            <div class="inline-flex items-center justify-center w-14 h-14 sm:w-16 sm:h-16 rounded-2xl bg-[#1e293b] text-[#00f3ff] text-2xl sm:text-3xl mb-3 shadow-inner">
                πŸ’»
            </div>
            <h1 class="text-2xl sm:text-3xl font-extrabold tracking-wide bg-gradient-to-r from-[#00f3ff] to-[#b5179e] bg-clip-text text-transparent">
                EMZ License Manager
            </h1>
            <p class="text-xs text-gray-400 mt-1">Select role to login or register serial</p>
        </div>

        <!-- ROLE SWITCH TABS -->
        <div class="flex gap-2 mb-6 p-1 bg-[#1e293b] rounded-xl">
            <button id="adminTabBtn" onclick="switchRole('admin')" class="w-1/2 py-2 text-xs sm:text-sm font-semibold rounded-lg bg-gradient-to-r from-[#00f3ff] to-[#b5179e] text-white shadow">
                πŸ‘‘ Admin
            </button>
            <button id="userTabBtn" onclick="switchRole('user')" class="w-1/2 py-2 text-xs sm:text-sm font-semibold rounded-lg text-gray-400 hover:text-white transition">
                πŸ‘€ User
            </button>
        </div>

        <!-- ADMIN LOGIN FORM -->
        <div id="adminLoginForm" class="space-y-4">
            <div>
                <label class="block text-xs font-medium text-gray-400 mb-1">Username</label>
                <input type="text" id="username" placeholder="Enter admin username" class="w-full px-4 py-3 bg-[#1e293b] border border-gray-700/80 rounded-xl focus:outline-none focus:border-[#00f3ff] text-sm">
            </div>
            <div>
                <label class="block text-xs font-medium text-gray-400 mb-1">Password</label>
                <input type="password" id="password" placeholder="Enter password" class="w-full px-4 py-3 bg-[#1e293b] border border-gray-700/80 rounded-xl focus:outline-none focus:border-[#00f3ff] text-sm">
            </div>
            <button onclick="handleLogin()" class="w-full py-3 mt-4 rounded-xl font-bold text-white glow-button">
                βž” Login
            </button>
            <p id="loginError" class="text-red-400 text-xs text-center mt-2 font-medium"></p>
        </div>

        <!-- USER SERIAL REGISTER FORM -->
        <div id="userRegisterForm" class="space-y-4 hidden">
            <div class="text-center py-2">
                <h3 class="text-base sm:text-lg font-bold text-[#00f3ff]">Register New Serial / HWID</h3>
                <p class="text-xs text-gray-400">Enter your hardware serial number below</p>
            </div>
            <div>
                <label class="block text-xs font-medium text-gray-400 mb-1">Serial Number / HWID</label>
                <input type="text" id="userSerialInput" placeholder="Enter your HWID or Serial" class="w-full px-4 py-3 bg-[#1e293b] border border-gray-700/80 rounded-xl focus:outline-none focus:border-[#00f3ff] text-xs sm:text-sm font-mono">
            </div>
            <button onclick="registerUserSerial()" class="w-full py-3 mt-2 rounded-xl font-bold text-white glow-button">
                Register Serial
            </button>
            <p id="userMsg" class="text-xs text-center mt-2 font-medium"></p>
        </div>
    </div>

    <!-- ADMIN PANEL DASHBOARD -->
    <div id="adminPanel" class="hidden w-full max-w-5xl p-3 sm:p-6 rounded-3xl glow-border bg-[#0f172a]">
        <!-- Header -->
        <div class="flex flex-col sm:flex-row justify-between items-start sm:items-center gap-4 mb-6 border-b border-gray-800 pb-4">
            <div>
                <h2 class="text-xl sm:text-2xl font-bold bg-gradient-to-r from-[#00f3ff] to-[#0072ff] bg-clip-text text-transparent">
                    EMZ License Manager
                </h2>
                <p class="text-xs text-gray-400">Admin Panel β€” License & Key Authorization System</p>
            </div>
            <button onclick="handleLogout()" class="w-full sm:w-auto px-4 py-2 bg-red-500/10 text-red-400 border border-red-500/20 rounded-xl text-xs font-semibold hover:bg-red-500 hover:text-white transition">
                Logout
            </button>
        </div>

        <!-- Table Section -->
        <div>
            <div class="flex justify-between items-center mb-4">
                <h3 class="text-sm sm:text-md font-semibold text-gray-200">Registered Licenses</h3>
                <button onclick="loadLicenses()" class="px-3 py-1.5 bg-cyan-500/10 text-cyan-400 border border-cyan-500/20 rounded-lg text-xs hover:bg-cyan-500 hover:text-black transition">
                    πŸ”„ Refresh List
                </button>
            </div>

            <div class="overflow-x-auto rounded-xl border border-gray-800">
                <table class="w-full text-left border-collapse min-w-[500px]">
                    <thead>
                        <tr class="bg-[#1e293b] text-gray-400 text-xs uppercase tracking-wider">
                            <th class="p-3 sm:p-4">HWID</th>
                            <th class="p-3 sm:p-4">Status</th>
                            <th class="p-3 sm:p-4 text-center">Actions</th>
                        </tr>
                    </thead>
                    <tbody id="licenseTableBody" class="divide-y divide-gray-800 text-xs sm:text-sm">
                        <!-- Dynamic Rows Load Here -->
                    </tbody>
                </table>
            </div>
        </div>
    </div>

    <script>

        const SUPABASE_URL = "https://iprvqmakahkzajjoeywf.supabase.co";

        const SUPABASE_ANON_KEY = "sb_publishable_d7m-MP4ghiBeUoldeOsfIA_AQUrxy1x";

        const _supabase = supabase.createClient(SUPABASE_URL, SUPABASE_ANON_KEY);



        const ADMIN_USER = "EMZ";

        const ADMIN_PASS = "Pak@19988";



        function switchRole(role) {

            const adminBtn = document.getElementById("adminTabBtn");

            const userBtn = document.getElementById("userTabBtn");

            const adminForm = document.getElementById("adminLoginForm");

            const userForm = document.getElementById("userRegisterForm");



            if (role === 'admin') {

                adminBtn.className = "w-1/2 py-2 text-xs sm:text-sm font-semibold rounded-lg bg-gradient-to-r from-[#00f3ff] to-[#b5179e] text-white shadow";

                userBtn.className = "w-1/2 py-2 text-xs sm:text-sm font-semibold rounded-lg text-gray-400 hover:text-white transition";

                adminForm.classList.remove("hidden");

                userForm.classList.add("hidden");

            } else {

                userBtn.className = "w-1/2 py-2 text-xs sm:text-sm font-semibold rounded-lg bg-gradient-to-r from-[#00f3ff] to-[#b5179e] text-white shadow";

                adminBtn.className = "w-1/2 py-2 text-xs sm:text-sm font-semibold rounded-lg text-gray-400 hover:text-white transition";

                userForm.classList.remove("hidden");

                adminForm.classList.add("hidden");

            }

        }



        function handleLogin() {

            const user = document.getElementById("username").value;

            const pass = document.getElementById("password").value;

            const err = document.getElementById("loginError");



            if (user === ADMIN_USER && pass === ADMIN_PASS) {

                document.getElementById("authContainer").classList.add("hidden");

                document.getElementById("adminPanel").classList.remove("hidden");

                loadLicenses();

            } else {

                err.innerText = "Invalid Username or Password!";

            }

        }



        function handleLogout() {

            document.getElementById("adminPanel").classList.add("hidden");

            document.getElementById("authContainer").classList.remove("hidden");

        }



        async function registerUserSerial() {

            const serialInput = document.getElementById("userSerialInput").value.trim();

            const msg = document.getElementById("userMsg");



            if (!serialInput) {

                msg.className = "text-red-400 text-xs text-center mt-2 font-medium";

                msg.innerText = "Please enter a valid Serial Number / HWID!";

                return;

            }



            msg.className = "text-yellow-400 text-xs text-center mt-2 font-medium";

            msg.innerText = "Registering...";



            const { data: existing } = await _supabase.from('licenses').select('*').eq('hwid', serialInput);



            if (existing && existing.length > 0) {

                msg.className = "text-amber-400 text-xs text-center mt-2 font-medium";

                msg.innerText = "This Serial/HWID is already registered!";

                return;

            }



            const { error } = await _supabase.from('licenses').insert([{ hwid: serialInput, status: 'DISABLED' }]);



            if (!error) {

                msg.className = "text-green-400 text-xs text-center mt-2 font-medium";

                msg.innerText = "Serial registered successfully! Waiting for Admin activation.";

                document.getElementById("userSerialInput").value = "";

            } else {

                msg.className = "text-red-400 text-xs text-center mt-2 font-medium";

                msg.innerText = "Registration failed! Please check your table structure.";

            }

        }



        async function loadLicenses() {

            const tbody = document.getElementById("licenseTableBody");

            tbody.innerHTML = `<tr><td colspan="3" class="p-6 text-center text-gray-400">Loading licenses...</td></tr>`;



            const { data, error } = await _supabase.from('licenses').select('*');



            if (error) {

                tbody.innerHTML = `<tr><td colspan="3" class="p-6 text-center text-red-400">Error loading data. Make sure 'licenses' table exists with columns: id, hwid, status.</td></tr>`;

                return;

            }



            if (!data || data.length === 0) {

                tbody.innerHTML = `<tr><td colspan="3" class="p-6 text-center text-gray-400">No registered licenses found.</td></tr>`;

                return;

            }



            tbody.innerHTML = "";

            data.forEach(item => {

                const isActive = item.status === "ACTIVE";

                const statusBadge = isActive 

                    ? `<span class="px-2.5 py-1 text-[10px] sm:text-xs font-bold rounded-full bg-green-500/10 text-green-400 border border-green-500/25">ACTIVE</span>`

                    : `<span class="px-2.5 py-1 text-[10px] sm:text-xs font-bold rounded-full bg-red-500/10 text-red-400 border border-red-500/25">DISABLED</span>`;

                

                const btnText = isActive ? "Disable" : "Enable";

                const btnStyle = isActive 

                    ? "bg-amber-500/20 text-amber-400 border-amber-500/30 hover:bg-amber-500 hover:text-black" 

                    : "bg-green-500/20 text-green-400 border-green-500/30 hover:bg-green-500 hover:text-black";



                tbody.innerHTML += `

                    <tr class="hover:bg-[#1e293b]/50 transition">

                        <td class="p-3 sm:p-4 font-mono text-cyan-300 font-medium">${item.hwid}</td>

                        <td class="p-3 sm:p-4">${statusBadge}</td>

                        <td class="p-3 sm:p-4 text-center space-x-1 sm:space-x-2">

                            <button onclick="toggleStatus('${item.id}', '${item.status}')" class="px-2.5 py-1 rounded-lg border text-[11px] sm:text-xs font-semibold transition ${btnStyle}">

                                ${btnText}

                            </button>

                            <button onclick="deleteLicense('${item.id}')" class="px-2.5 py-1 rounded-lg border bg-red-500/20 text-red-400 border-red-500/30 hover:bg-red-500 hover:text-white text-[11px] sm:text-xs font-semibold transition">

                                Delete

                            </button>

                        </td>

                    </tr>

                `;

            });

        }



        async function toggleStatus(id, currentStatus) {

            const newStatus = currentStatus === "ACTIVE" ? "DISABLED" : "ACTIVE";

            const { error } = await _supabase.from('licenses').update({ status: newStatus }).eq('id', id);

            if (!error) loadLicenses();

            else alert("Failed to update status!");

        }



        async function deleteLicense(id) {

            if (!confirm("Are you sure you want to delete this HWID?")) return;

            const { error } = await _supabase.from('licenses').delete().eq('id', id);

            if (!error) loadLicenses();

            else alert("Failed to delete HWID!");

        }

    </script>
</body>
</html>