# Path: scrypture/webapi.py
# class WebAPI(flask_wtf.Form):
# class PassHTTPAuthorizationHeader(requests.auth.AuthBase):
# def text_input(*args, **kwargs):
# def list_input(*args, **kwargs):
# def line_input(*args, **kwargs):
# def password_input(*args, **kwargs):
# def radio_field(*args, **kwargs):
# def submit_button(*args, **kwargs):
# def multiple_input(*args, **kwargs):
# def checkbox_field(*args, **kwargs):
# def file_field(*args, **kwargs):
#     def __init__(self, header):
#     def __call__(self, r):


import argparse
import sys
import re
from scrypture import webapi
        csv_out = 'ip,hostname,info\n'
        for entry in entries[1:]:
            entry_lines = entry.splitlines()
            ip_in_parens = re.findall('\(.*\)', entry_lines[0])
            if len(ip_in_parens) > 0:
                csv_out += ip_in_parens[0][1:-1]
                csv_out += ','
                csv_out += entry_lines[0]
            else:
                csv_out += entry_lines[0]
                csv_out +=','
            csv_out += ',"'
            csv_out += '\n'.join(entry_lines[1:])
            csv_out += '"\n'
        return csv_out

### CLI ###

def main():
    parser = argparse.ArgumentParser(description='Read NMAP output and convert to CSV')
    parser.add_argument('nmap_input', nargs=1, type=argparse.FileType('r'), default=sys.stdin)
    parser.add_argument('-o', '--outfile', nargs=1, type=argparse.FileType('w'), default=sys.stdout)

    args = parser.parse_args()
    print(nmap_to_csv(args.nmap_input[0].read()), file=args.outfile)

if __name__ == '__main__':
    main()

### WebAPI ###

# Path: scrypture/webapi.py
# class WebAPI(flask_wtf.Form):
# class PassHTTPAuthorizationHeader(requests.auth.AuthBase):
# def text_input(*args, **kwargs):
# def list_input(*args, **kwargs):
# def line_input(*args, **kwargs):
# def password_input(*args, **kwargs):
# def radio_field(*args, **kwargs):
# def submit_button(*args, **kwargs):
# def multiple_input(*args, **kwargs):
# def checkbox_field(*args, **kwargs):
# def file_field(*args, **kwargs):
#     def __init__(self, header):
#     def __call__(self, r):


# Path: scrypture/demo_scripts/Network/nmap_to_csv.py
import argparse
import sys
import re
from scrypture import webapi

        csv_out = 'ip,hostname,info\n'
        for entry in entries[1:]:
            entry_lines = entry.splitlines()
            ip_in_parens = re.findall('\(.*\)', entry_lines[0])
            if len(ip_in_parens) > 0:
                csv_out += ip_in_parens[0][1:-1]
                csv_out += ','
                csv_out += entry_lines[0]
            else:
                csv_out += entry_lines[0]
                csv_out +=','
            csv_out += ',"'
            csv_out += '\n'.join(entry_lines[1:])
            csv_out += '"\n'
        return csv_out

### CLI ###

def main():
    parser = argparse.ArgumentParser(description='Read NMAP output and convert to CSV')
    parser.add_argument('nmap_input', nargs=1, type=argparse.FileType('r'), default=sys.stdin)
    parser.add_argument('-o', '--outfile', nargs=1, type=argparse.FileType('w'), default=sys.stdout)

    args = parser.parse_args()
    print(nmap_to_csv(args.nmap_input[0].read()), file=args.outfile)

if __name__ == '__main__':
    main()

### WebAPI ###

class WebAPI(webapi.WebAPI):