Beispiel #1
0
import os
from flask import Flask
from werkzeug import secure_filename


UPLOAD_FOLDER = './uploads/'
ALLOWED_EXTENSIONS = set(['txt', 'pdf', 'png', 'jpg', 'jpeg', 'gif'])

app = Flask(__name__)
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
app.secret_key = 'development key'

app.config["MAIL_SERVER"] = "smtp.gmail.com"
app.config["MAIL_PORT"] = 465
app.config["MAIL_USE_SSL"] = True
app.config["MAIL_USERNAME"] = 'joeterskine@gmail.com'
app.config["MAIL_PASSWORD"] = 'Pavilion12'

from routes import mail
mail.init_app(app)

app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql://root:password@localhost/development'

from models import db
db.init_app(app)

import creighton.routes
Beispiel #2
0
# coding:utf-8

import os

# import ipdb
from flask.ext.mail import Mail
from flask.ext.mail import Message
from flask import Flask, render_template

app = Flask(__name__)

app.config["MAIL_SERVER"] = "smtp.qq.com"
app.config["MAIL_PORT"] = 587
app.config["MAIL_USE_TLS"] = True
app.config["MAIL_USERNAME"] = os.environ.get("MAIL_USERNAME")
app.config["MAIL_PASSWORD"] = os.environ.get("MAIL_PASSWORD")
app.config["FLASK_MAIL_SUBJECT_PREFIX"] = "Lilium Accounts"
app.config["FLASKY_MAIL_SENDER"] = "1372488211@qq.com"

mail = Mail(app)


# todo, 发送邮件找回密码
# def send_email(to, subject, template, **kwargs):
def send_email(to_email, body):
    msg = Message(
        app.config["FLASK_MAIL_SUBJECT_PREFIX"], sender=app.config["FLASKY_MAIL_SENDER"], recipients=[to_email]
    )
    # msg.body=render_template(template+'.txt',**kwargs)
    # msg.html=render_template(template+'.html',**kwargs)
    msg.body = "text body"
Beispiel #3
0
def create_app(configfile=None):
    app = Flask(__name__)
    handler = RotatingFileHandler("urlabuse.log", maxBytes=10000, backupCount=5)
    handler.setFormatter(Formatter("%(asctime)s %(message)s"))
    app.wsgi_app = ReverseProxied(app.wsgi_app)
    app.logger.addHandler(handler)
    app.logger.setLevel(logging.INFO)
    Bootstrap(app)
    q = Queue(connection=conn)

    # Mail Config
    app.config["MAIL_SERVER"] = "localhost"
    app.config["MAIL_PORT"] = 25
    mail = Mail(app)

    app.config["SECRET_KEY"] = "devkey"
    app.config["BOOTSTRAP_SERVE_LOCAL"] = True
    app.config["configfile"] = config_path

    parser = configparser.SafeConfigParser()
    parser.read(app.config["configfile"])

    replacelist = make_dict(parser, "replacelist")
    auth_users = prepare_auth()
    ignorelist = [i.strip() for i in parser.get("abuse", "ignore").split("\n") if len(i.strip()) > 0]
    autosend_threshold = 5

    def _get_user_ip(request):
        ip = request.headers.get("X-Forwarded-For")
        if ip is None:
            ip = request.remote_addr
        return ip

    @app.route("/", methods=["GET", "POST"])
    def index():
        form = URLForm()
        return render_template("index.html", form=form)

    @app.route("/urlreport", methods=["GET"])
    def url_report():
        return render_template("url-report.html")

    @app.errorhandler(404)
    def page_not_found(e):
        ip = request.headers.get("X-Forwarded-For")
        if ip is None:
            ip = request.remote_addr
        if request.path != "/_result/":
            app.logger.info("404 of {} on {}".format(ip, request.path))
        return render_template("404.html"), 404

    def authenticate():
        """Sends a 401 response that enables basic auth"""
        return Response(
            "Could not verify your access level for that URL.\n" "You have to login with proper credentials",
            401,
            {"WWW-Authenticate": 'Basic realm="Login Required"'},
        )

    def check_auth(username, password):
        """This function is called to check if a username /
        password combination is valid.
        """
        if auth_users is None:
            return False
        else:
            db_pass = auth_users.get(username)
            return db_pass == password

    @app.route("/login", methods=["GET", "POST"])
    def login():
        auth = request.authorization
        if not auth or not check_auth(auth.username, auth.password):
            return authenticate()
        return redirect(url_for("index"))

    @app.route("/_result/<job_key>", methods=["GET"])
    def check_valid(job_key):
        if job_key is None:
            return json.dumps(None), 200
        job = Job.fetch(job_key, connection=conn)
        if job.is_finished:
            return json.dumps(job.result), 200
        else:
            return json.dumps("Nay!"), 202

    @app.route("/start", methods=["POST"])
    def run_query():
        data = json.loads(request.data)
        url = data["url"]
        ip = _get_user_ip(request)
        app.logger.info("{} {}".format(ip, url))
        if get_submissions(url) >= autosend_threshold:
            send(url, "", True)
        is_valid = q.enqueue_call(func=is_valid_url, args=(url,), result_ttl=500)
        return is_valid.get_id()

    @app.route("/urls", methods=["POST"])
    def urls():
        data = json.loads(request.data)
        url = data["url"]
        u = q.enqueue_call(func=url_list, args=(url,), result_ttl=500)
        return u.get_id()

    @app.route("/resolve", methods=["POST"])
    def resolve():
        data = json.loads(request.data)
        url = data["url"]
        u = q.enqueue_call(func=dns_resolve, args=(url,), result_ttl=500)
        return u.get_id()

    @app.route("/phishtank", methods=["POST"])
    def phishtank():
        data = json.loads(request.data)
        if not os.path.exists("phishtank.key"):
            return None
        url = parser.get("PHISHTANK", "url")
        key = open("phishtank.key", "r").readline().strip()
        query = data["query"]
        u = q.enqueue_call(func=phish_query, args=(url, key, query), result_ttl=500)
        return u.get_id()

    @app.route("/virustotal_report", methods=["POST"])
    def vt():
        data = json.loads(request.data)
        if not os.path.exists("virustotal.key"):
            return None
        url = parser.get("VIRUSTOTAL", "url_report")
        url_up = parser.get("VIRUSTOTAL", "url_upload")
        key = open("virustotal.key", "r").readline().strip()
        query = data["query"]
        u = q.enqueue_call(func=vt_query_url, args=(url, url_up, key, query), result_ttl=500)
        return u.get_id()

    @app.route("/googlesafebrowsing", methods=["POST"])
    def gsb():
        data = json.loads(request.data)
        if not os.path.exists("googlesafebrowsing.key"):
            return None
        url = parser.get("GOOGLESAFEBROWSING", "url")
        key = open("googlesafebrowsing.key", "r").readline().strip()
        url = url.format(key)
        query = data["query"]
        u = q.enqueue_call(func=gsb_query, args=(url, query), result_ttl=500)
        return u.get_id()

    @app.route("/urlquery", methods=["POST"])
    def urlquery():
        data = json.loads(request.data)
        if not os.path.exists("urlquery.key"):
            return None
        url = parser.get("URLQUERY", "url")
        key = open("urlquery.key", "r").readline().strip()
        query = data["query"]
        u = q.enqueue_call(func=urlquery_query, args=(url, key, query), result_ttl=500)
        return u.get_id()

    @app.route("/ticket", methods=["POST"])
    def ticket():
        if not request.authorization:
            return ""
        data = json.loads(request.data)
        server = parser.get("SPHINX", "server")
        port = int(parser.get("SPHINX", "port"))
        url = parser.get("ITS", "url")
        query = data["query"]
        u = q.enqueue_call(func=sphinxsearch, args=(server, port, url, query), result_ttl=500)
        return u.get_id()

    @app.route("/whois", methods=["POST"])
    def whoismail():
        if not request.authorization:
            return ""
        server = parser.get("WHOIS", "server")
        port = parser.getint("WHOIS", "port")
        data = json.loads(request.data)
        query = data["query"]
        u = q.enqueue_call(func=whois, args=(server, port, query, ignorelist, replacelist), result_ttl=500)
        return u.get_id()

    @app.route("/eupi", methods=["POST"])
    def eu():
        data = json.loads(request.data)
        if not os.path.exists("eupi.key"):
            return None
        url = parser.get("EUPI", "url")
        key = open("eupi.key", "r").readline().strip()
        query = data["query"]
        u = q.enqueue_call(func=eupi, args=(url, key, query), result_ttl=500)
        return u.get_id()

    @app.route("/pdnscircl", methods=["POST"])
    def dnscircl():
        url = parser.get("PDNS_CIRCL", "url")
        user, password = open("pdnscircl.key", "r").readlines()
        data = json.loads(request.data)
        query = data["query"]
        u = q.enqueue_call(func=pdnscircl, args=(url, user.strip(), password.strip(), query), result_ttl=500)
        return u.get_id()

    @app.route("/bgpranking", methods=["POST"])
    def bgpr():
        data = json.loads(request.data)
        query = data["query"]
        u = q.enqueue_call(func=bgpranking, args=(query,), result_ttl=500)
        return u.get_id()

    @app.route("/psslcircl", methods=["POST"])
    def sslcircl():
        url = parser.get("PSSL_CIRCL", "url")
        user, password = open("psslcircl.key", "r").readlines()
        data = json.loads(request.data)
        query = data["query"]
        u = q.enqueue_call(func=psslcircl, args=(url, user.strip(), password.strip(), query), result_ttl=500)
        return u.get_id()

    @app.route("/get_cache", methods=["POST"])
    def get_cache():
        data = json.loads(request.data)
        url = data["query"]
        data = cached(url)
        dumped = json.dumps(data, sort_keys=True, indent=4, separators=(",", ": "))
        return dumped

    def digest(data):
        to_return = ""
        all_mails = set()
        for entry in data:
            for url, info in list(entry.items()):
                to_return += "\n{}\n".format(url)
                if info.get("whois"):
                    all_mails.update(info.get("whois"))
                    to_return += "\tContacts: {}\n".format(", ".join(info.get("whois")))
                if info.get("vt") and len(info.get("vt")) == 4:
                    vtstuff = info.get("vt")
                    to_return += "\t{} out of {} positive detections in VT - {}\n".format(
                        vtstuff[2], vtstuff[3], vtstuff[1]
                    )
                if info.get("gsb"):
                    to_return += "\tKnown as malicious on Google Safe Browsing: {}\n".format(info.get("gsb"))
                if info.get("phishtank"):
                    to_return += "\tKnown as malicious on PhishTank\n"
                if info.get("dns"):
                    ipv4, ipv6 = info.get("dns")
                    if ipv4 is not None:
                        for ip in ipv4:
                            to_return += "\t" + ip + "\n"
                            data = info[ip]
                            if data.get("bgp"):
                                to_return += "\t\t(PTR: {}) is announced by {} ({}).\n".format(*(data.get("bgp")[:3]))
                            if data.get("whois"):
                                all_mails.update(data.get("whois"))
                                to_return += "\t\tContacts: {}\n".format(", ".join(data.get("whois")))
                    if ipv6 is not None:
                        for ip in ipv6:
                            to_return += "\t" + ip + "\n"
                            data = info[ip]
                            if data.get("whois"):
                                all_mails.update(data.get("whois"))
                                to_return += "\t\tContacts: {}\n".format(", ".join(data.get("whois")))
            to_return += "\tAll contacts: {}\n".format(", ".join(all_mails))
        return to_return

    def send(url, ip="", autosend=False):
        if not get_mail_sent(url):
            set_mail_sent(url)
            data = cached(url)
            if not autosend:
                subject = "URL Abuse report from " + ip
            else:
                subject = "URL Abuse report sent automatically"
            msg = Message(subject, sender="urlabuse@circl.lu", recipients=["info@circl.lu"])
            msg.body = digest(data)
            msg.body += "\n\n"
            msg.body += json.dumps(data, sort_keys=True, indent=4, separators=(",", ": "))
            mail.send(msg)

    @app.route("/submit", methods=["POST"])
    def send_mail():
        data = json.loads(request.data)
        url = data["url"]
        if not get_mail_sent(url):
            ip = _get_user_ip(request)
            send(url, ip)
        return redirect(url_for("index"))

    return app
else:
    sentry = None

app.before_request(redis_connect)

app.before_request(check_csrf_token)

app.after_request(set_cookie)
app.after_request(db_commit)

app.teardown_request(db_disconnect)
app.teardown_request(redis_disconnect)


app.config["MAIL_SERVER"] = os.environ.get("MAIL_SERVER", "localhost")
app.config["MAIL_PORT"] = int(os.environ.get("MAIL_PORT", 25))
app.config["MAIL_USE_TLS"] = "MAIL_USE_TLS" in os.environ
app.config["MAIL_USERNAME"] = os.environ.get("MAIL_USERNAME")
app.config["MAIL_PASSWORD"] = os.environ.get("MAIL_PASSWORD")
app.config["MAIL_SUPPRESS_SEND"] = app.testing or bool(os.environ.get("NOMAIL"))
mail = Mail(app)


# Views/routes

from newparp import views
from newparp.views import (
    account, admin, characters, chat, chat_api, chat_list, errors, guides,
    search, search_characters, settings,
)
from newparp.views.admin import spamless, spamless2
Beispiel #5
0
try:
    from settings_local import MAIL_SERVER
    from settings_local import MAIL_PORT
    from settings_local import MAIL_USE_TLS
    from settings_local import MAIL_USERNAME
    from settings_local import MAIL_PASSWORD
    from settings_local import DEFAULT_MAIL_SENDER
except ImportError:
    MAIL_SERVER = "localhost"
    MAIL_PORT = 25
    MAIL_USE_TLS = False
    MAIL_USERNAME = MAIL_PASSWORD = DEFAULT_MAIL_SENDER = None

rsvp_app.config["MAIL_SERVER"] = MAIL_SERVER
rsvp_app.config["MAIL_PORT"] = MAIL_PORT
rsvp_app.config["MAIL_USE_TLS"] = MAIL_USE_TLS
rsvp_app.config["MAIL_USERNAME"] = MAIL_USERNAME
rsvp_app.config["MAIL_PASSWORD"] = MAIL_PASSWORD
rsvp_app.config["DEFAULT_MAIL_SENDER"] = DEFAULT_MAIL_SENDER

mail = Mail(rsvp_app)

basedir = os.path.abspath(os.path.dirname(__file__))
rsvp_app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///" + os.path.join(basedir, "rsvp.db")  # 'sqlite:////tmp/test.db'
rsvp_app.config["SQLALCHEMY_MIGRATE_REPO"] = os.path.join(basedir, "db_repository")

db = SQLAlchemy(rsvp_app)
# CORS(rsvp_app)  # allow all origins

# LOGGING
Beispiel #6
0
from werkzeug.security import generate_password_hash, check_password_hash

mail = Mail()

app = Flask(__name__)
app.config.from_object(__name__)

app.config['SQLALCHEMY_DATABASE_URI'] = settings.database_uri
db = SQLAlchemy(app)

app.secret_key = settings.app_secret_key

# Mail config

app.config["MAIL_SERVER"] = settings.mail['server']
app.config["MAIL_PORT"] = settings.mail['port']
app.config["MAIL_USE_SSL"] = settings.mail['use_ssl']
app.config["MAIL_USERNAME"] = settings.mail['username']
app.config["MAIL_PASSWORD"] = settings.mail['password']

mail.init_app(app)


# Database Setup


class User(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    email = db.Column(db.String(120), unique=True)
    password = db.Column(db.String(100))
    is_active = db.Column(db.Boolean())
Beispiel #7
0
from flask import Flask
from flask.ext.sqlalchemy import SQLAlchemy
from flask_mail import Mail
from forms import LoginForm
from config import *


app = Flask(__name__)
app.config.from_object("config")

app.config["MAIL_SERVER"] = "192.168.1.223"
app.config["MAIL_PORT"] = "25"
app.config["MAIL_USERNAME"] = "s_int7"
app.config["MAIL_PASSWORD"] = "1234"
app.config["MAIL_USE_TLS"] = False
app.config["MAIL_USE_SSL"] = False
app.config["MAIL_DEBUG"] = True
app.config["DEFAULT_MAIL_SENDER"] = True

mail = Mail(app)
db = SQLAlchemy(app)

from app import views, models
Beispiel #8
0
from sqlalchemy.event import listens_for
from jinja2 import Markup
from flask.ext.security import current_user, login_required, RoleMixin, Security, SQLAlchemyUserDatastore, UserMixin
from flask_mail import Mail
from flask_admin import Admin, form, AdminIndexView, BaseView, helpers as admin_helpers
from flask_admin.form import rules
from flask_admin.contrib import sqla
from werkzeug import secure_filename

# Create application
app = Flask(__name__)
app.config["SECRET_KEY"] = "COfwEzLtXbxwuIxkTNBcG0"

# Mail
app.config["MAIL_SERVER"] = "smtp.gmail.com"
app.config["MAIL_PORT"] = "465"
app.config["MAIL_USE_SSL"] = True
app.config["MAIL_USERNAME"] = "botflasktest@gmail.com"
app.config["MAIL_PASSWORD"] = "medabots"
app.config["MAIL_DEFAULT_SENDER"] = "naoresponder"
mail = Mail(app)


# Create dummy secrety key so we can use sessions
app.config["SECURITY_PASSWORD_SALT"] = "COfwEzLtXbxwuIxkTNBcG0"
app.config["SECURITY_PASSWORD_HASH"] = "bcrypt"
app.config["SECURITY_RECOVERABLE"] = True

# Create in-memory database
app.config["DATABASE_FILE"] = "sample_db.sqlite"
app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///" + app.config["DATABASE_FILE"]
Beispiel #9
0
from flask import Flask, render_template, request, flash
from forms import ContactForm
from flask_mail import Message, Mail
import os

mail = Mail()

app = Flask(__name__)
app.secret_key = 'development key'

app.config["MAIL_SERVER"] = "smtp.mail.com"
app.config["MAIL_PORT"] = 993
app.config["MAIL_USE_SSL"] = True
app.config["MAIL_USERNAME"] = 'jafarocean@mail.com'
app.config["MAIL_PASSWORD"] = 'Osalami20_'

mail.init_app(app)

@app.route("/")
def index():
    return render_template("index.html")

@app.route("/portfolio")
def portfolio():
    return render_template("portfolio.html")
    
@app.route("/portfolio/cusu")
def cusu():
    return render_template("cusu.html")
    
@app.route("/portfolio/fdm")
#!/usr/bin/env python
from flask import Flask, render_template,request, flash
from forms import ContactForm
from flask.ext.mail import Message, Mail
# Create the application
mail = Mail()
APP = Flask(__name__)

APP.secret_key = 'codeLearningKey'

APP.config["MAIL_SERVER"] = "smtp.gmail.com"
APP.config["MAIL_PORT"] = 465
APP.config["MAIL_USE_SSL"] = True
APP.config["MAIL_USERNAME"] = 'jhona.22.baz'
APP.config["MAIL_PASSWORD"] = 'password'
 
 # administrator list
ADMINS = ['jhona.22.baz@gmail.com']

mail.init_app(APP)

@APP.route('/')
@APP.route('/index')
def index():
    """ Displays the index page accesible at '/'  """
    return  render_template('index.html', title = 'Home')

@APP.route('/hello/<name>/')
def hello(name):
    """ Displays the page greats who ever comes to visit it.
    """