Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
from openatlas.models.date import Date
from openatlas.models.entity import Entity
from openatlas.models.link import Link
class DateForm(FlaskForm): # type: ignore
validator_day = [Optional(), NumberRange(min=1, max=31)]
validator_month = [Optional(), NumberRange(min=1, max=12)]
validator_year = [Optional(), NumberRange(min=-4713, max=9999), NoneOf([0])]
begin_year_from = IntegerField(render_kw={'placeholder': _('YYYY')}, validators=validator_year)
begin_month_from = IntegerField(render_kw={'placeholder': _('MM')}, validators=validator_month)
begin_day_from = IntegerField(render_kw={'placeholder': _('DD')}, validators=validator_day)
begin_year_to = IntegerField(render_kw={'placeholder': _('YYYY')}, validators=validator_year)
begin_month_to = IntegerField(render_kw={'placeholder': _('MM')}, validators=validator_month)
begin_day_to = IntegerField(render_kw={'placeholder': _('DD')}, validators=validator_day)
begin_comment = StringField(render_kw={'placeholder': _('comment')})
end_year_from = IntegerField(render_kw={'placeholder': _('YYYY')}, validators=validator_year)
end_month_from = IntegerField(render_kw={'placeholder': _('MM')}, validators=validator_month)
end_day_from = IntegerField(render_kw={'placeholder': _('DD')}, validators=validator_day)
end_year_to = IntegerField(render_kw={'placeholder': _('YYYY')}, validators=validator_year)
end_month_to = IntegerField(render_kw={'placeholder': _('MM')}, validators=validator_month)
end_day_to = IntegerField(render_kw={'placeholder': _('DD')}, validators=validator_day)
end_comment = StringField(render_kw={'placeholder': _('comment')})
@staticmethod
def format_date(date: numpy.datetime64, part: str) -> str:
string = str(date).split(' ')[0]
bc = False
if string.startswith('-') or string.startswith('0000'):
bc = True
def create_user(self):
user = User(name=self.name.data,
email=self.email.data,
password=self.password.data)
db.session.add(user)
db.session.commit()
return user
class UserProfileForm(FlaskForm):
real_name = StringField('姓名', [Required()])
email = StringField('邮箱', validators=[Required(), Email()])
password = PasswordField('密码(不填写保持不变)')
phone = StringField('手机号')
work_years = IntegerField('工作年限')
resume = FileField('上传简历', validators=[FileRequired()])
submit = SubmitField('提交')
def validate_phone(self, field):
phone = field.data
if phone[:2] not in ('13', '15', '18') and len(phone) != 11:
raise ValidationError('请输入有效的手机号')
def upload_resume(self):
f = self.resume.data
filename = self.real_name.data + '.pdf'
f.save(os.path.join(
os.path.abspath(os.path.dirname(__file__)),
'static',
'resumes',
filename
from wtforms.validators import NoneOf, NumberRange, Optional
from openatlas.models.date import Date
from openatlas.models.entity import Entity
from openatlas.models.link import Link
class DateForm(FlaskForm): # type: ignore
validator_day = [Optional(), NumberRange(min=1, max=31)]
validator_month = [Optional(), NumberRange(min=1, max=12)]
validator_year = [Optional(), NumberRange(min=-4713, max=9999), NoneOf([0])]
begin_year_from = IntegerField(render_kw={'placeholder': _('YYYY')}, validators=validator_year)
begin_month_from = IntegerField(render_kw={'placeholder': _('MM')}, validators=validator_month)
begin_day_from = IntegerField(render_kw={'placeholder': _('DD')}, validators=validator_day)
begin_year_to = IntegerField(render_kw={'placeholder': _('YYYY')}, validators=validator_year)
begin_month_to = IntegerField(render_kw={'placeholder': _('MM')}, validators=validator_month)
begin_day_to = IntegerField(render_kw={'placeholder': _('DD')}, validators=validator_day)
begin_comment = StringField(render_kw={'placeholder': _('comment')})
end_year_from = IntegerField(render_kw={'placeholder': _('YYYY')}, validators=validator_year)
end_month_from = IntegerField(render_kw={'placeholder': _('MM')}, validators=validator_month)
end_day_from = IntegerField(render_kw={'placeholder': _('DD')}, validators=validator_day)
end_year_to = IntegerField(render_kw={'placeholder': _('YYYY')}, validators=validator_year)
end_month_to = IntegerField(render_kw={'placeholder': _('MM')}, validators=validator_month)
end_day_to = IntegerField(render_kw={'placeholder': _('DD')}, validators=validator_day)
end_comment = StringField(render_kw={'placeholder': _('comment')})
@staticmethod
def format_date(date: numpy.datetime64, part: str) -> str:
string = str(date).split(' ')[0]
bc = False
selections = get_selections(f['choosefrom'])
field = wtf.SelectField(f['fieldlabel'], choices=selections)
elif f['fieldtype'] == 'MultiSelect':
selections = get_selections(f['choosefrom'])
field = wtf.SelectMultipleField(f['fieldlabel'], choices=selections)
elif f['fieldtype'] == "Date":
#Need to specify a widget to allow for selecting from calendar
field = wtf.DateField(f['fieldlabel'], widget=DatePickerWidget())
elif f['fieldtype'] == "DateTime":
#Need to specify a widget to allow for selecting from calendar
field = wtf.DateTimeField(f['fieldlabel'], widget=DateTimePickerWidget())
elif f['fieldtype'] == "Boolean":
field = wtf.BooleanField(f['fieldlabel'])
elif f['fieldtype'] == "Number":
field = wtf.IntegerField(f['fieldlabel'])
else:
continue # we don't know what you specified, so just skip it
if field is not None:
# Append the field to the object
CaseForm.append_field(f['fieldname'], field)
return form
label='Activity Time')
bait_timings__ftp__sleep_interval = IntegerField(default=120, label='Sleep Interval',
validators=sleep_interval_validators,
description=interval_description)
bait_timings__ftp__activation_probability = FloatField(default=1, label='Activation Probability',
description=probability_description,
validators=probability_validators)
class LoginForm(Form):
username = StringField()
password = PasswordField()
class SettingsForm(Form):
bait_session_retain = IntegerField('Bait session retention', default=2,
description='<small><em>days until legit bait_sessions are deleted.</em></small>',
validators=[validators.required(message=u'This field is required'),
validators.NumberRange(min=1)])
malicious_session_retain = IntegerField('Malicious session retention', default=100,
description='<small><em>days until malicious sessions are deleted</em></small>',
validators=[validators.required(message=u'This field is required'),
validators.NumberRange(min=1)])
ignore_failed_bait_session = BooleanField('Ignore failed bait_sessions', default=True,
description='<small><em>Ignore bait_sessions that did not connect</em></small>')
ftdi_location = StringField(TRANSLATIONS['ftdi_location']['title'])
uart_location = StringField(TRANSLATIONS['uart_location']['title'])
gpio_location = IntegerField(TRANSLATIONS['gpio_location']['title'])
i2c_location = StringField(TRANSLATIONS['i2c_location']['title'])
i2c_bus = IntegerField(TRANSLATIONS['i2c_bus']['title'], widget=NumberInput())
baud_rate = IntegerField(TRANSLATIONS['baud_rate']['title'], widget=NumberInput())
power_output_id = StringField(lazy_gettext('Power Output')) # For powering input
calibrate_sensor_measure = StringField(lazy_gettext('Calibration Measurement'))
resolution = IntegerField(TRANSLATIONS['resolution']['title'], widget=NumberInput())
resolution_2 = IntegerField(TRANSLATIONS['resolution']['title'], widget=NumberInput())
sensitivity = IntegerField( TRANSLATIONS['sensitivity']['title'], widget=NumberInput())
measurements_enabled = SelectMultipleField(TRANSLATIONS['measurements_enabled']['title'])
# Server options
host = StringField(TRANSLATIONS['host']['title'])
port = IntegerField(
TRANSLATIONS['port']['title'], widget=NumberInput())
times_check = IntegerField(
TRANSLATIONS['times_check']['title'], widget=NumberInput())
deadline = IntegerField(
TRANSLATIONS['deadline']['title'], widget=NumberInput())
# Linux Command
cmd_command = StringField(TRANSLATIONS['cmd_command']['title'])
# MAX chip options
thermocouple_type = StringField(TRANSLATIONS['thermocouple_type']['title'])
ref_ohm = IntegerField(
TRANSLATIONS['ref_ohm']['title'], widget=NumberInput())
# SPI Communication
pin_clock = IntegerField(
class SettingsForm(IndicoForm):
enabled = BooleanField(_("Track global visits"), widget=SwitchWidget())
enabled_for_events = BooleanField(_("Track events"), widget=SwitchWidget())
enabled_for_downloads = BooleanField(_("Track downloads"), widget=SwitchWidget())
cache_enabled = BooleanField(_("Cache results"), widget=SwitchWidget())
server_url = StringField(_("Piwik server URL"))
server_api_url = StringField(_("Piwik API server URL"),
description=_("Should be pointing to 'index.php'"))
server_token = StringField(_("Piwik API token"),
description=_("Token to access the API. Do not share it!"))
site_id_general = StringField(_("Global statistics ID"),
description=_("Piwik site ID for global statistics"))
site_id_events = StringField(_("Event statistics ID"),
description=_("Piwik site ID for event statistics"))
cache_ttl = IntegerField(_("Result cache TTL (seconds)"),
description=_("How long event reports are kept cached"))
use_only_server_url = BooleanField(_("Use Piwik server URL for all requests"))
def validate_site_id_events(self, field):
if self.site_id_general is not None and field is not None and self.site_id_general.data == field.data:
raise ValidationError(_("Event statistics can't use the same Piwik site as global statistics"))
self.included.choices = [(str(a.id), a.display_name) for a in assignments]
self.included.data = [str(a.id) for a in assignments if a.published_scores]
def validate(self):
return super().validate() and len(self.included.data) > 0
########
# Jobs #
########
class TestJobForm(BaseForm):
should_fail = BooleanField('Divide By Zero', default=False)
make_file = BooleanField('Create a file', default=True)
duration = IntegerField('Duration (seconds)', default=2)
class MossSubmissionForm(BaseForm):
moss_userid = StringField('Moss User ID', default='619379711',
validators=[validators.required()])
file_regex = StringField('Regex for submitted files', default='.*',
validators=[validators.required()])
language = SelectField('Programming Language', choices=[(pl, pl) for pl in COMMON_LANGUAGES])
review_threshold = DecimalField('Review Threshold', default=0.30,
description="Results with this similarity percentage or higher will be tagged for review.")
num_results = IntegerField('Number of Results', default=250,
description="Number of similarity results to request from Moss.")
class GithubSearchRecentForm(BaseForm):
access_token = StringField('Github Access Token',
description="Get a token at https://github.com/settings/tokens",
validators=[validators.required()])