Ejemplo n.º 1
0
 def post(self):
     data = request.get_json()
     domaintoadd = Domain(data['customer'], data['environment'],
                          data['domain'])
     try:
         Domain.save_to_db(domaintoadd)
         return {"message": "Domain entry added"}, 201
     except:
         return {'message': 'Domain entry already exists'}, 400
Ejemplo n.º 2
0
 def load_domain_dns_server(self, db_session: Session, domain: Domain) -> None:
     try:
         name_servers = domain.isp_instance.get_domain_info(domain.domain).name_servers
     except Exception as e:
         self.log_exception(e)
     else:
         domain.name_server = ','.join(name_servers)
         db_session.commit()
Ejemplo n.º 3
0
def get_files_by_type(user, domain_id, file_type):
    domain = Domain.objects(id=domain_id, user=user.id).first()
    if domain:
        res = FileInDomain.objects(domain=domain.id,
                                   type_of_file=file_type).all().to_json()
        return res
    else:
        return "", 404
Ejemplo n.º 4
0
def user_quit_from_domain(user, domain_id):
    domain = Domain.objects(id=domain_id).first()
    if domain and domain.user.id != user.id:
        uid = UserInDomain(domain=domain.id, user=user.id).first()
        if uid:
            uid.delete()
        return "", 202
    else:
        return "", 404
Ejemplo n.º 5
0
 def get(self, customer):
     try:
         return {
             'Domains':
             list(map(lambda x: x.json(),
                      Domain.find_by_customer(customer)))
         }, 200
     except Exception:
         return {'message': 'No Domain entries found'}, 404
Ejemplo n.º 6
0
def get_domain_users(user, domain_id):
    domain = Domain.objects(id=domain_id).first()
    users = []
    if domain:
        uid_ls = UserInDomain.objects(domain=domain.id).all()
        for uid in uid_ls:
            user = User.objects(id=uid.user.id).first()
            users.append({'username': user.username, 'id': str(user.id)})
    return json.dumps(users)
Ejemplo n.º 7
0
def domain_today():
    data = Domain.get_all()
    result = []
    total = 0
    for item in data:
        article_new = Article.count(item['domain'], today=True)
        result.append({'domain': item['domain'], 'article_num': article_new})
        total += article_new
    result = sorted(result, key=lambda k: k['article_num'], reverse=True)
    return jsonify(article_total=total, data=result)
Ejemplo n.º 8
0
 def get(self, environment):
     try:
         return {
             'Domains':
             list(
                 map(lambda x: x.json(),
                     Domain.find_by_environment(environment)))
         }, 200
     except Exception:
         return {'message': 'No Domain entries found'}, 404
Ejemplo n.º 9
0
def user_connect_to_domain(user, domain_id):
    domain = Domain.objects(id=domain_id).first()
    if domain and domain.user.id != user.id:
        uid = UserInDomain.objects(domain=domain.id, user=user.id).first()
        if not uid:
            uid = UserInDomain()
            uid.user = user.to_dbref()
            uid.domain = domain.to_dbref()
            uid.save()
        return "", 202
    else:
        return "", 404
Ejemplo n.º 10
0
def domain_today():
    data = Domain.get_all()
    result = []
    total = 0
    for item in data:
        article_new = Article.count(item['domain'], today=True)
        result.append({
            'domain': item['domain'],
            'article_num': article_new
        })
        total += article_new
    result = sorted(result, key=lambda k: k['article_num'], reverse=True)
    return jsonify(article_total=total, data=result)
Ejemplo n.º 11
0
 def __init__(self):
     self.engine = Database().connect()
     self.start_urls = ['http://blog.scrapinghub.com']
     # Insert multiple data in this session, similarly you can delete
     Session = sessionmaker(bind=self.engine)
     self.session = Session()
     if self.session.query(Domain).count() == 0:
         domain = Domain(name="https://en.wikipedia.org/wiki/Main_Page")
         self.session.add(domain)
         try:
             self.session.commit()
         # You can catch exceptions with  SQLAlchemyError base class
         except SQLAlchemyError as e:
             self.session.rollback()
             print(str(e))
Ejemplo n.º 12
0
def put_domain_field(user, domain_id):
    domain = Domain.objects(id=domain_id).first()
    if domain:
        if request.method == "PUT":
            name = request.json.get('name')
            domain.name = name
            res = domain.save_me()
            if 'errors' in res.keys():
                return jsonify(res), 403
            else:
                return jsonify(res)
        if request.method == "GET":
            return domain.to_json()
    else:
        return "", 404
Ejemplo n.º 13
0
def post_file_domain(user, domain_id):
    file = request.files['file']
    name = request.form.get('name')
    type_of_file = request.form.get('type_of_file')
    if not name:
        return "Add name", 403
    if not type_of_file:
        return "Add type of file", 403
    domain = Domain.objects(id=domain_id, user=user.id).first()
    if domain:
        dm = for_domain.add_file_to_domain(domain, file, name, 'files',
                                           type_of_file)

        if not dm:
            return "", 202
        else:
            return dm, 403
    else:
        return "", 404
Ejemplo n.º 14
0
def put_file_domain(user, domain_id, file_id):
    domain = Domain.objects(id=domain_id).first()
    if domain:
        fid = FileInDomain.objects(domain=domain.id, id=file_id).first()
        if fid:
            if request.method == 'PUT':
                name = request.json.get('name')
                fid.name = name
                res = fid.save_me()
                if 'errors' in res.keys():
                    return jsonify(res), 403
                else:
                    return jsonify(res)
            else:
                print(fid.filename)
                return send_file('files/' + fid.filename)
        else:
            return "", 404
    else:
        return "", 404
Ejemplo n.º 15
0
def domainexport():
    # Exports all of the Domain entries for the users customer into a csv file that the user can download
    user = User.get_by_email(session['email'])
    customer = user.customer
    q = Domain.find_by_customer(customer)
    csv_list = [['Customer', 'Environment', 'Domain']]
    for each in q:
        csv_list.append(
            [
                each.customer,
                each.environment,
                each.domain
            ]
        )
    si = io.StringIO()
    cw = csv.writer(si)
    cw.writerows(csv_list)
    output = make_response(si.getvalue())
    output.headers["Content-Disposition"] = "attachment; filename=export.csv"
    output.headers["Content-type"] = "text/csv"
    return output
Ejemplo n.º 16
0
def add_domain():
    domain = request.form['Domain']
    Domain(name=domain).create_domain()
    return redirect("/god")
Ejemplo n.º 17
0
def edit_domain():
    old_domain = request.form['OldDomain']
    new_domain = request.form['NewDomain']
    Domain(name=old_domain).update_domain(new_domain=new_domain)
    return redirect(url_for('editor_mode'))
Ejemplo n.º 18
0
def domain_all():
    data = Domain.get_all()
    total = sum(item['article_num'] for item in data)
    data = sorted(data, key=lambda k: k['article_num'], reverse=True)
    return jsonify(article_total=total, data=data)
Ejemplo n.º 19
0
def domain_all():
    data = Domain.get_all()
    total = sum(item['article_num'] for item in data)
    data = sorted(data, key=lambda k: k['article_num'], reverse=True)
    return jsonify(article_total=total, data=data)
Ejemplo n.º 20
0
def add_domain(user, name):
    dom = Domain()
    dom.user = user.to_dbref()
    dom.name = name
    return dom.save_me()
Ejemplo n.º 21
0
def delete_domain(domain):
    Domain(name=domain).remove_domain()
    return redirect("/god")
Ejemplo n.º 22
0
def handle_domain(domain):
    global SessionMaker
    session = SessionMaker()

    domain_model = Domain()

    domain_model.domain_name = domain

    spf_record = spflib.SpfRecord.from_domain(domain)
    try:
        if spf_record is not None and spf_record.record is not None:
            domain_model.spf_record = spf_record.record
            domain_model.spf_strong = spf_record.is_record_strong()
        else:
            domain_model.spf_record = None
            domain_model.spf_strong = False

        dmarc_record = dmarclib.DmarcRecord.from_domain(domain)
        org_domain = dmarc_record.get_org_domain()
        domain_model.is_subdomain = False

        if dmarc_record is not None and dmarc_record.record is not None:
            domain_model.dmarc_record = dmarc_record.record
            domain_model.dmarc_policy = dmarc_record.policy
            domain_model.dmarc_strong = dmarc_record.is_record_strong()
        elif org_domain is not None:
            domain_model.is_subdomain = True
            domain_model.org_domain = org_domain
            domain_model.org_record = dmarc_record.get_org_record().record
            domain_model.dmarc_record = None
            domain_model.dmarc_policy = None
            domain_model.dmarc_strong = dmarc_record.is_record_strong()
        else:
            domain_model.dmarc_record = None
            domain_model.dmarc_policy = None
            domain_model.dmarc_strong = False

        if dmarc_record is not None and spf_record is not None:
            domain_model.domain_vulnerable = not (domain_model.dmarc_strong and domain_model.spf_strong)
        else:
            domain_model.domain_vulnerable = True
    except Exception as e:
        logging.exception("Encountered an error processing domain %(domain)s: %(exception)s" % {
            'domain': domain,
            'exception': e,
        })

    session.add(domain_model)
    session.commit()
Ejemplo n.º 23
0
 def delete(self, domain):
     domain = Domain.find_by_domain(domain)
     if domain:
         Domain.delete_from_db(domain)
     return {'message': 'Domain entry {} deleted'.format(domain.domain)}
Ejemplo n.º 24
0
def domainlist():
    # Gets the customer the user is assigned to and shows all of the Domain server entries for that customer
    user = User.get_by_email(session['email'])
    customer = user.customer
    entries = Domain.find_by_customer(customer)
    return render_template('listdomain.html', entries=entries)