# Path: hashview/models.py
# class Wordlists(db.Model):
#     id = db.Column(db.Integer, primary_key=True)
#     name = db.Column(db.String(256), nullable=False)
#     last_updated = db.Column(db.DateTime, nullable=False, default=datetime.utcnow)
#     owner_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False)
#     type = db.Column(db.String(7))                          # Dynamic or Static
#     path = db.Column(db.String(245), nullable=False)
#     size = db.Column(db.BigInteger, nullable=False)
#     checksum = db.Column(db.String(64), nullable=False)
# 
# class Rules(db.Model):
#     id = db.Column(db.Integer, primary_key=True)
#     name = db.Column(db.String(50), nullable=False)
#     last_updated = db.Column(db.DateTime, nullable=False, default=datetime.utcnow)
#     owner_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False)
#     path = db.Column(db.String(256), nullable=False)
#     size = db.Column(db.Integer, nullable=False, default=0)
#     checksum = db.Column(db.String(64), nullable=False)
# 
# class Tasks(db.Model):
#     id = db.Column(db.Integer, primary_key=True)
#     name = db.Column(db.String(100), nullable=False)
#     hc_attackmode = db.Column(db.String(25), nullable=False) # dictionary, mask, bruteforce, combinator
#     owner_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False)
#     wl_id = db.Column(db.Integer)
#     rule_id = db.Column(db.Integer)
#     hc_mask = db.Column(db.String(50))


from flask_wtf import FlaskForm
from wtforms import StringField, SubmitField, SelectField
from wtforms.validators import DataRequired, ValidationError
from hashview.models import Wordlists, Rules, Tasks
from wtforms_sqlalchemy.fields import QuerySelectField

def get_wordlists():
    return Wordlists.query

def get_rules():
    return Rules.query

class TasksForm(FlaskForm):
    name = StringField('Name', validators=([DataRequired()]))
    hc_attackmode = SelectField('Attack Mode', choices=[('', '--SELECT--'), ('dictionary', 'dictionary'), ('maskmode', 'maskmode'), ('bruteforce', 'bruteforce'), ('combinator', 'combinator')], validators=[DataRequired()])  # dictionary, maskmode, bruteforce, combinator
    wl_id = QuerySelectField('Wordlist',query_factory=get_wordlists, get_label='name')
    rule_id = QuerySelectField('Rules', query_factory=get_rules, get_label='name', allow_blank=True)
    mask = StringField('Hashcat Mask')
    submit = SubmitField('Create')  

    def validate_task(self, name):

# Path: hashview/models.py
# class Wordlists(db.Model):
#     id = db.Column(db.Integer, primary_key=True)
#     name = db.Column(db.String(256), nullable=False)
#     last_updated = db.Column(db.DateTime, nullable=False, default=datetime.utcnow)
#     owner_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False)
#     type = db.Column(db.String(7))                          # Dynamic or Static
#     path = db.Column(db.String(245), nullable=False)
#     size = db.Column(db.BigInteger, nullable=False)
#     checksum = db.Column(db.String(64), nullable=False)
# 
# class Rules(db.Model):
#     id = db.Column(db.Integer, primary_key=True)
#     name = db.Column(db.String(50), nullable=False)
#     last_updated = db.Column(db.DateTime, nullable=False, default=datetime.utcnow)
#     owner_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False)
#     path = db.Column(db.String(256), nullable=False)
#     size = db.Column(db.Integer, nullable=False, default=0)
#     checksum = db.Column(db.String(64), nullable=False)
# 
# class Tasks(db.Model):
#     id = db.Column(db.Integer, primary_key=True)
#     name = db.Column(db.String(100), nullable=False)
#     hc_attackmode = db.Column(db.String(25), nullable=False) # dictionary, mask, bruteforce, combinator
#     owner_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False)
#     wl_id = db.Column(db.Integer)
#     rule_id = db.Column(db.Integer)
#     hc_mask = db.Column(db.String(50))


# Path: hashview/tasks/forms.py
from flask_wtf import FlaskForm
from wtforms import StringField, SubmitField, SelectField
from wtforms.validators import DataRequired, ValidationError
from hashview.models import Wordlists, Rules, Tasks
from wtforms_sqlalchemy.fields import QuerySelectField


def get_wordlists():
    return Wordlists.query

def get_rules():
    return Rules.query

class TasksForm(FlaskForm):
    name = StringField('Name', validators=([DataRequired()]))
    hc_attackmode = SelectField('Attack Mode', choices=[('', '--SELECT--'), ('dictionary', 'dictionary'), ('maskmode', 'maskmode'), ('bruteforce', 'bruteforce'), ('combinator', 'combinator')], validators=[DataRequired()])  # dictionary, maskmode, bruteforce, combinator
    wl_id = QuerySelectField('Wordlist',query_factory=get_wordlists, get_label='name')
    rule_id = QuerySelectField('Rules', query_factory=get_rules, get_label='name', allow_blank=True)
    mask = StringField('Hashcat Mask')
    submit = SubmitField('Create')  

    def validate_task(self, name):

        task = Tasks.query.filter_by(name = name.data).first()