Esempio n. 1
0
def run():
    sess = db_utils.get_session()
    smtp_config = dict()
    smtp_config["smtp_host"] = sess.query(
        db_utils.Config.config_value).filter_by(
            config_key="smtp_host").first()[0]
    smtp_config["smtp_port"] = sess.query(
        db_utils.Config.config_value).filter_by(
            config_key="smtp_port").first()[0]
    smtp_config["smtp_user"] = sess.query(
        db_utils.Config.config_value).filter_by(
            config_key="smtp_user").first()[0]
    smtp_config["smtp_password"] = sess.query(
        db_utils.Config.config_value).filter_by(
            config_key="smtp_password").first()[0]
    tasks = sess.query(db_utils.Task).filter_by(task_status="Queued")
    mailer = mail_utils.Mailer(smtp_config)
    for task in tasks:
        task.task_status = "Sending"
        sess.commit()
        try:
            mailer.send_mail(task)
            task.task_status = "Done"
            task.task_msg = ""
        except Exception as e:
            task.task_status = "Failed"
            task.task_msg = str(e)
        sess.commit()
Esempio n. 2
0
def verify_pw(username, password):
    sess = db_utils.get_session()
    r_user = sess.query(db_utils.Config.config_value).filter_by(config_key="admin_user").first()[0]
    r_pass = sess.query(db_utils.Config.config_value).filter_by(config_key="admin_password").first()[0]
    if (username == r_user) and (password == r_pass):
        return True
    else:
        return False
Esempio n. 3
0
def submit():
    sess = db_utils.get_session()
    for to_addr in request.form.get("task_to_address").split("|"):
        sess.add(db_utils.Task(task_show_name=request.form.get("task_show_name"),
                               task_from_address=request.form.get("task_from_address"),
                               task_to_address=to_addr,
                               task_subject=request.form.get("task_subject"),
                               task_body=request.form.get("task_body"),
                               task_atts=request.form.get("task_atts"),
                               task_status="Queued",
                               task_msg=""))
    sess.commit()
    sess.close()
    return "1"
Esempio n. 4
0
def clear_done():
    sess = db_utils.get_session()
    sess.query(db_utils.Task).filter_by(task_status="Done").delete()
    sess.commit()
    sess.close()
    return "1"
Esempio n. 5
0
def get_tasks():
    sess = db_utils.get_session()
    tasks = sess.query(db_utils.Task).with_entities(db_utils.Task.id, db_utils.Task.task_show_name, db_utils.Task.task_from_address, db_utils.Task.task_to_address, db_utils.Task.task_status, db_utils.Task.task_msg)
    ret = [dict(zip(["id", "task_show_name", "task_from_address", "task_to_address", "task_status", "task_msg"], task)) for task in tasks]
    sess.close()
    return jsonify(ret)
Esempio n. 6
0
def clear_all():
    sess = db_utils.get_session()
    sess.query(db_utils.Task).delete()
    sess.commit()
    sess.close()
    return "1"
Esempio n. 7
0
def requeue():
    sess = db_utils.get_session()
    sess.query(db_utils.Task).filter_by(task_status="Failed").update({"task_status": "Queued", "task_msg": ""})
    sess.commit()
    sess.close()
    return "1"
Esempio n. 8
0
import db_utils
import getpass
import os

smtp_host = input("SMTP server host:")
smtp_port = input("SMTP server port:")
smtp_user = input("SMTP user:"******"SMTP password:"******"Administrator username:"******"Administrator password:"******"smtp_host", config_value=smtp_host))
sess.add(db_utils.Config(config_key="smtp_port", config_value=smtp_port))
sess.add(db_utils.Config(config_key="smtp_user", config_value=smtp_user))
sess.add(
    db_utils.Config(config_key="smtp_password", config_value=smtp_password))
sess.add(db_utils.Config(config_key="admin_user", config_value=admin_user))
sess.add(
    db_utils.Config(config_key="admin_password", config_value=admin_password))
sess.commit()
sess.close()

os.mkdir("attachments")