<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />

    <title>Identity Monitoring - Intelligence X</title>

    <link href="css/font-awesome.min.css" rel="stylesheet" type="text/css" />
    <link href="fonts/OpenSans.css" rel="stylesheet" type="text/css" />
    <link href="css/bootstrap.min.css" rel="stylesheet" />
    <link href="css/uniform.default.min.css" rel="stylesheet" type="text/css" />
    <link href="css/ark.css" rel="stylesheet" type="text/css" />

    <script src="js/jquery.min.js"></script>
    <script src="js/config.js"></script>
    <script>
        apiGet = function apiGet(api, path, parameters, success, error) {
            $.ajax({
                type: 'GET',
                url: api + path + "?k=" + API_KEY + parameters,
                success: success,
                error: error
            });
        }

        apiPost = function apiPost(url, data, success, error) {
            $.ajax({
                type: 'POST',
                url: API_URL + url + "?k=" + API_KEY,
                data: data,
                success: success,
                error: error
            });
        }

        document.addEventListener('DOMContentLoaded', function() {
            fetchStatusData();
        });

        function fetchStatusData() {
            // 3.intelx.io
            apiGet('https://3.intelx.io/', 'authenticate/info', '',
                function(data) {
                    $('#status3').text('Valid').css('background-color', 'green').css('color', 'white');;
                    updateTable(data.paths, 'credits3');
                },
                function(jqXHR, exception) {
                    var msg = '';
                    if (jqXHR.status === 0) {
                        msg = 'No connection to the API. The API is possibly down.';
                    } else if (jqXHR.status == 401) {
                        msg = 'Your API key was not authorized. [401]';
                    } else if (jqXHR.status == 404) {
                        msg = 'Your API key was not authorized. [404]';
                    } else if (jqXHR.status == 500) {
                        msg = 'Internal Server Error [500].';
                    } else if (exception === 'parsererror') {
                        msg = 'Requested JSON parse failed.';
                    } else if (exception === 'timeout') {
                        msg = 'Time out error.';
                    } else if (exception === 'abort') {
                        msg = 'Ajax request aborted.';
                    } else {
                        msg = 'Unknown error.\n' + jqXHR.responseText;
                    }
                    $('#status3').text(msg).css('background-color', 'red').css('color', 'white');
                }
            );

            // 4.intelx.io
            apiGet('https://4.intelx.io/', 'authenticate/info', '',
                function(data) {
                    $('#status4').text('Valid').css('background-color', 'green').css('color', 'white');;
                    updateTable(data.paths, 'credits4');
                },
                function(jqXHR, exception) {
                    var msg = '';
                    if (jqXHR.status === 0) {
                        msg = 'No connection to the API. The API is possibly down.';
                    } else if (jqXHR.status == 401) {
                        msg = 'Your API key was not authorized. [401]';
                    } else if (jqXHR.status == 404) {
                        msg = 'Your API key was not authorized. [404]';
                    } else if (jqXHR.status == 500) {
                        msg = 'Internal Server Error [500].';
                    } else if (exception === 'parsererror') {
                        msg = 'Requested JSON parse failed.';
                    } else if (exception === 'timeout') {
                        msg = 'Time out error.';
                    } else if (exception === 'abort') {
                        msg = 'Ajax request aborted.';
                    } else {
                        msg = 'Unknown error.\n' + jqXHR.responseText;
                    }
                    $('#status4').text(msg).css('background-color', 'red').css('color', 'white');
                }
            );
        }

        function updateTable(paths, tableID) {
            const table = document.getElementById(tableID);
            for (const path in paths) {
                const row = table.insertRow();
                const cellPath = row.insertCell();
                const cellCredit = row.insertCell();
                const cellCreditMax = row.insertCell();

                cellPath.style.padding = "0 5px 0 5px";
                cellCredit.style.padding = "0 5px 0 5px";
                cellCreditMax.style.padding = "0 5px 0 5px";

                if (paths[path].CreditReset == 0) { // use of credits disabled
                    cellPath.textContent = paths[path].Path;
                    cellCredit.textContent = '';
                    cellCreditMax.textContent = '(no limit)';

                } else if (paths[path].CreditReset == 1) { // no reset
                    cellPath.textContent = paths[path].Path;
                    cellCredit.textContent = paths[path].Credit;
                    cellCreditMax.textContent = paths[path].CreditMax;

                } else if (paths[path].CreditReset == 2) { // 24 hours
                    cellPath.textContent = paths[path].Path;
                    cellCredit.textContent = paths[path].Credit;
                    cellCreditMax.textContent = paths[path].CreditMax;
                } 
            }
        }

    </script>
</head>

<body class="cover fixed_header">

    <div class="wrapper">
        <!-- HEAD NAV -->
        <div class="navbar navbar-default navbar-static-top navbar-main" role="navigation">
            <div class="navbar-header">
                <a class="navbar-brand" href="index.html"><img src="img/IntelligenceX.svg" alt="Intelligence X" width="180"></a>
            </div>
            <div class=" navbar-right">
                <a href="/logout" style="font-size: 16px;padding: 20px;"><i class="fa fa-sign-out"></i>Logout</a>
            </div>

        </div>
        <!-- END: HEAD NAV -->

        <div class="navbar navbar-default navbar-static-top navbar-top" role="navigation">
            <ul class="nav navbar-nav">
                <li><a href="index.html"><i class="fa fa-search fa-fw"></i>Search Data Leaks</a></li>
                <li><a href="export.html"><i class="fa fa-download fa-fw"></i>Export Leaked Accounts</a></li>
                <li><a href="changelog.html"><i class="fa fa-book fa-fw"></i>Changelog</a></li>
                <li><a href="Leaks API.pdf"><i class="fa fa-download fa-fw"></i>API documentation</a></li>
                <li class="active"><a href="status.html"><i class="fa fa-code fa-fw"></i>API status</a></li>
                <li><a href="faq.html"><i class="fa fa-question-circle fa-fw"></i>FAQ</a></li>
            </ul>
        </div>

        <!-- BODY -->
        <div class="body">

            <section class="content">

                <div class="header">
                    <div class="col-md-12">
                        <h3 class="header-title">API Instance Status</h3>

                        <p class="header-info">
                        </p>
                    </div>
                </div>

                <!-- CONTENT -->
                <div class="main-content" style="padding-bottom: 5px;">

                        <div>
                            <h4 class="header-title">Leaks API 3.intelx.io instance. For API users:</h4>

                            <div style="padding-bottom: 5px;">
                                Status of API key: <span id="status3">Verifying...</span>
                            </div>

                            <table id="credits3" border="1">
                                <thead>
                                    <tr>
                                        <th style="padding:5px">Path</th>
                                        <th style="padding:5px">Credit Available</th>
                                        <th style="padding:5px">Daily Credit</th>
                                    </tr>
                                </thead>
                            </table>

                            <br>
                            <h4 class="header-title">Leaks API 4.intelx.io instance. This API is used by this user interface:</h4>

                            <div style="padding-bottom: 5px;">   
                                Status of API key: <span id="status4">Verifying...</span>
                            </div>

                            <table id="credits4" border="1">
                                <thead>
                                    <tr>
                                        <th style="padding:5px">Path</th>
                                        <th style="padding:5px">Credit Available</th>
                                        <th style="padding:5px">Daily Credit</th>
                                    </tr>
                                </thead>
                            </table>

                            <div style="padding-top: 10px;">
                                Note: Users must not use the 4.intelx.io API instance in an automated way. It is only supposed to be used by the identity.intelx.io frontend.
                            </div>

                        </div>

                        <hr>&copy; 2020 - 2024 Intelligence X



                </div>
                <!-- END: CONTENT -->
            </section>
        </div>
        <!-- END: BODY -->
    </div>

    <script src="js/jquery.uniform.min.js"></script>
    <script src="js/bootstrap.min.js"></script>
    <script src="js/jquery.dataTables.min.js"></script>
    <script src="js/ark.min.js"></script>
    <script src="js/jquery.autosize.min.js"></script>

</body>

</html>