<?php
/*========================================================================================
* +-+-+-+-+-+ Project    : ZeroFault
* |V|1|P|3|R| Author     : ZeroFaultツ
* +-+-+-+-+-+ Version    : V1.0
========================================================================================*/

  /* Require Files */
  require_once '../../includes/Functions.php';

  if($_SERVER['REQUEST_METHOD'] == 'POST'):

    $data = json_decode(file_get_contents('php://input'), true);

    exit(

      json_encode(

        V1P3R_Bounce($data)

      )

    );

  endif;

?>

<!DOCTYPE html>

<html>

<head>

  <meta charset="utf-8">

  <meta http-equiv="x-ua-compatible" content="ie=edge">

  <title>ZeroBOUNCE</title>

  <meta name="robots" content="noindex, nofollow, noimageindex">

  <meta name="description" content="">

  <meta name="viewport" content="width=device-width, initial-scale=1">

  <link rel="shortcut icon nofollow" href="https://iili.io/5rMNta.png">

  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.4.1/semantic.min.css">

  <style>

    .ui.container{ padding: 20px } 

    h2{ margin-bottom: 0!important }

    table{ width: 100%!important; max-width: 100%!important }

    td.top:nth-child(2) div.two.fields{ margin-bottom: 0 }

    form{ margin-top: 14px }

    textarea:not([name="list"]){ height: 148px!important }

    div.button{ padding-top: 15px !important; padding-bottom: 15px !important }

  </style>

</head>

<body>

  <section class="ui container">

    <div align="center">
      
      <h2 class="ui icon header">
      
        <i class="viacoin icon"></i>
      
        <div class="content">
      
          ZeroBOUNCEツ
      
          <div class="sub header">Email Checker application.</div>
      
        </div>
      
      </h2>
    
    </div>

    <form class="ui form">

      <table class="ui teal single line fixed three column table small">

        <thead>
        
          <tr>

            <th>

              Please Add Your EmailList In Your Input Window:
            
            </th>

            <th class="right aligned">
              
              <small>
            
                &copy; 2018-<?php echo date('Y'); ?> By <a href="https://t.me/zfault" target="_blank">ZEROFAULTツ</a> - All rights reserved.
              
              </small>

            </th>

          </tr>

        </thead>

        <tbody>
          
          <tr>

            <td class="top aligned">

              <div class="field">

                <label>

                  Enter The EmailList

                  <span id="round"></span>

                </label>

                <textarea name="list" rows="22" autocomplete="off"></textarea>

              </div>

            </td>

            <td class="top aligned">

              <div class="field">

                <label>

                  Valid Email Address

                </label>

                <textarea name="valid" autocomplete="off"></textarea>

              </div>

              <div class="field">

                <label>

                 Invalid Email Address

                </label>

                <textarea name="invalid" autocomplete="off"></textarea>

              </div>

              <div class="two fields">

                <div class="field">

                  <div class="ui teal fluid animated fade button" tabindex="0" id="start">

                    <div class="visible content">Start</div>

                    <div class="hidden content">

                      <i class="paper plane icon"></i>

                    </div>

                  </div>

                </div>

                <div class="field">

                  <div class="ui disabled fluid animated fade button" tabindex="0" id="stop">

                    <div class="visible content">stop</div>

                    <div class="hidden content">

                      <i class="ban icon"></i>

                    </div>

                  </div>

                </div>

              </div>

            </td>

          </tr>

        </tbody>

      </table>

    </form>

  </section>

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

  <script src="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.4.1/semantic.min.js"></script>

  <script src="https://cdnjs.cloudflare.com/ajax/libs/d3-collection/1.0.5/d3-collection.min.js"></script>

  <script src="https://cdnjs.cloudflare.com/ajax/libs/d3-dispatch/1.0.3/d3-dispatch.min.js"></script>

  <script src="https://cdnjs.cloudflare.com/ajax/libs/d3-request/1.0.6/d3-request.min.js"></script>

  <script src="https://cdnjs.cloudflare.com/ajax/libs/d3-queue/3.0.7/d3-queue.min.js"></script>

  <script>

    $(document).ready(function() {

      'use strict'

      let 
        list    = $('textarea[name="list"]'),
        valid   = $('textarea[name="valid"]'),
        invalid = $('textarea[name="invalid"]'),
        round   = $('span#round'),
        start   = $('div#start'),
        stop    = $('div#stop'),
        queue

      start.click(function(){

        if(!start.hasClass('disabled')){

          queue = d3.queue(6)

          let 
            regex     = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/,
            emailList = [...new Set(
                list.val().split('\n').filter(function(e) {
                  return e
                })
              )],
            $length = list.length

          start.addClass('disabled')

          stop.removeClass('disabled')

          round.html('')

          valid.val('')

          invalid.val('')

          $.each(emailList, function(index, email) {

            if(regex.test(email)){

              queue.defer(function(data, callback) {

                d3.request(window.location)
                  .header('Content-Type', 'application/json')
                  .post(JSON.stringify(data), function(error, output) {

                    let 
                      value    = $.parseJSON(output.response),
                      response = value.response,
                      email    = value.email

                    round.html('(' + email + ')')

                    /* Show Result */
                    if (response == 'Valid') {

                      valid.val(

                        valid.val() + email + '\n'

                      )

                    }else{

                      invalid.val(

                        invalid.val() + email + '\n'

                      )

                    }

                    callback(error, output)

                  })

              }, {

                /* Post Values */
                url: 'https://gsuite.tools/verify-email',
                email: email

              })

            }

          })

          queue.awaitAll(function(error) {

            if (error) throw error

            round.html('')

            start.removeClass('disabled')

            stop.removeClass('disabled')

          })

        }

      })

      stop.click(function() {

        /* Abort any pending request */
        queue.abort()

        start.removeClass('disabled')

        stop.addClass('disabled')

      })

    })

	</script>

</body>

</html>
