Ejemplo n.º 1
0
def add_mailserver(request):
    from datetime import datetime
    from datetime import timedelta
    from mxhelpers import fake_fill
    engineer = Engineer.objects.get(user__username=request.user.username)
    mailserver_list = get_mx_list(engineer.company)
    message = None
    company = engineer.company
    engineer_list = Engineer.objects.filter(company=company)
    if request.method == 'POST':
        site_form = MailserverForm(request.POST)
        if site_form.is_valid():
            if request.user.is_authenticated():
                mx_url=site_form.cleaned_data['mx_url']
                ipaddr=site_form.cleaned_data['ipaddr']
                new_mailserver = Mailserver(name=site_form.cleaned_data['name'],
                                      slug=slugify(site_form.cleaned_data['name']),
                                      company=engineer.company,
                                      mx_url=mx_url,
                                      ipaddr=ipaddr,
                                      )
                new_mailserver.save()
                new_mailserver.alert_contact.add(engineer)

                
                MailserverPrefs.objects.create(mailserver=new_mailserver)
                rbl_all = Blacklist.objects.all()
                for rbl_obj in rbl_all:
                    new_mailserver.rbl.add(rbl_obj)
                    mx_status = MailserverRblStatus(mailserver=new_mailserver, rbl=rbl_obj, status='clear')
                    mx_status.save()
                end_results, rbl_result = run_diag(mx_url, ipaddr)

                if end_results['revdns_result'] is not "no":
                    revdns_status = "yes"
                else:
                    revdns_status = "no"
                    
                MailserverStatus.objects.create(mailserver=new_mailserver, port="up",
                    blacklist="clear", webmail="up", relay=end_results['relay_result'],
                    backupmx=end_results['redund_result'], backupmxport=end_results['backupmxport_result'], revdns=revdns_status)

                add_feed_mailserver(new_mailserver)
                fake_fill(new_mailserver) # DO NOT remove.
                mark_checked(new_mailserver, 'port', 'us') # DO NOT remove
                
                message = "Mailserver has been created successfully."
                site_form = MailserverForm() # this clears the form to add more
    else:
        site_form = MailserverForm()
    return render_to_response("hosts/add_mailserver.html", {
                                'mailserver_form': site_form,
                                'mailserver_list': mailserver_list,
                                'message': message,
                                'company': company,
                                'engineer_list': engineer_list,
                                },
                                context_instance=RequestContext(request))
Ejemplo n.º 2
0
def run_tests(mx_obj):
    try:
        end_results, rbl_result = run_diag(mx_obj.mx_url, mx_obj.ipaddr)
        p_status, created = MailserverStatus.objects.get_or_create(mailserver=mx)
        if created == False:
            p_status.relay = end_results['relay_result']
            p_status.backupmx = end_results['redund_result']
            p_status.backupmxport = end_results['backupmxport_result']
            p_status.score = get_diag_score(end_results['diag_count'])
            if end_results['revdns_result'] is not "no":
                p_status.revdns = "yes"
            else:
                p_status.revdns = "no"
            p_status.save()
    except:
        end_results = None
Ejemplo n.º 3
0
def diag_html(request):
    import timeit
    import smtplib
    import dns.resolver
    from datetime import datetime
    from monitor.models import FreeCheckHistory
    from mxhelpers import check_relay, check_rbl, check_rtt, get_diag_score
    
    rbl_result=None
    ipaddr = None
    diag_score=None

    if request.method == 'GET':
        mx_domain = request.GET.get('mx')
        mx_tld = request.GET.get('tld')
        if mx_domain:

            raw_ip = dns.resolver.query(mx_domain)

            ipaddr = raw_ip[0].to_text()

            end_results, rbl_result = run_diag(mx_tld, ipaddr)

            # Lastly, calculate the score
            diag_score = get_diag_score(end_results['diag_count'])

            try:
                checker_ip = request.META.get("REMOTE_ADDR", "")
                # this is for the counter on the front page
                b = FreeCheckHistory(ipaddr=ipaddr, checker=checker_ip)
                b.save()
            except:
                pass

    return render_to_response("hosts/diag_result.html", {
                        'rbl_result': rbl_result,
                        'ipaddr': ipaddr,
                        'redund_result': end_results['redund_result'],
                        'relay_result': end_results['relay_result'],
                        'avail_result': end_results['avail_result'],
                        'revdns_result': end_results['revdns_result'],
                        'diag_score': diag_score,

                        },
                        context_instance=RequestContext(request))
Ejemplo n.º 4
0
def diag_html(request):
    import timeit
    import smtplib
    import dns.resolver
    from datetime import datetime
    from monitor.models import FreeCheckHistory
    from mxhelpers import check_relay, check_rbl, check_rtt, get_diag_score

    rbl_result = None
    ipaddr = None
    diag_score = None

    if request.method == 'GET':
        mx_domain = request.GET.get('mx')
        mx_tld = request.GET.get('tld')
        if mx_domain:

            raw_ip = dns.resolver.query(mx_domain)

            ipaddr = raw_ip[0].to_text()

            end_results, rbl_result = run_diag(mx_tld, ipaddr)

            # Lastly, calculate the score
            diag_score = get_diag_score(end_results['diag_count'])

            try:
                checker_ip = request.META.get("REMOTE_ADDR", "")
                # this is for the counter on the front page
                b = FreeCheckHistory(ipaddr=ipaddr, checker=checker_ip)
                b.save()
            except:
                pass

    return render_to_response("hosts/diag_result.html", {
        'rbl_result': rbl_result,
        'ipaddr': ipaddr,
        'redund_result': end_results['redund_result'],
        'relay_result': end_results['relay_result'],
        'avail_result': end_results['avail_result'],
        'revdns_result': end_results['revdns_result'],
        'diag_score': diag_score,
    },
                              context_instance=RequestContext(request))
Ejemplo n.º 5
0
def add_mailserver(request):
    from datetime import datetime
    from datetime import timedelta
    from mxhelpers import fake_fill
    engineer = Engineer.objects.get(user__username=request.user.username)
    mailserver_list = get_mx_list(engineer.company)
    message = None
    company = engineer.company
    engineer_list = Engineer.objects.filter(company=company)
    if request.method == 'POST':
        site_form = MailserverForm(request.POST)
        if site_form.is_valid():
            if request.user.is_authenticated():
                mx_url = site_form.cleaned_data['mx_url']
                ipaddr = site_form.cleaned_data['ipaddr']
                new_mailserver = Mailserver(
                    name=site_form.cleaned_data['name'],
                    slug=slugify(site_form.cleaned_data['name']),
                    company=engineer.company,
                    mx_url=mx_url,
                    ipaddr=ipaddr,
                )
                new_mailserver.save()
                new_mailserver.alert_contact.add(engineer)

                MailserverPrefs.objects.create(mailserver=new_mailserver)
                rbl_all = Blacklist.objects.all()
                for rbl_obj in rbl_all:
                    new_mailserver.rbl.add(rbl_obj)
                    mx_status = MailserverRblStatus(mailserver=new_mailserver,
                                                    rbl=rbl_obj,
                                                    status='clear')
                    mx_status.save()
                end_results, rbl_result = run_diag(mx_url, ipaddr)

                if end_results['revdns_result'] is not "no":
                    revdns_status = "yes"
                else:
                    revdns_status = "no"

                MailserverStatus.objects.create(
                    mailserver=new_mailserver,
                    port="up",
                    blacklist="clear",
                    webmail="up",
                    relay=end_results['relay_result'],
                    backupmx=end_results['redund_result'],
                    backupmxport=end_results['backupmxport_result'],
                    revdns=revdns_status)

                add_feed_mailserver(new_mailserver)
                fake_fill(new_mailserver)  # DO NOT remove.
                mark_checked(new_mailserver, 'port', 'us')  # DO NOT remove

                message = "Mailserver has been created successfully."
                site_form = MailserverForm(
                )  # this clears the form to add more
    else:
        site_form = MailserverForm()
    return render_to_response("hosts/add_mailserver.html", {
        'mailserver_form': site_form,
        'mailserver_list': mailserver_list,
        'message': message,
        'company': company,
        'engineer_list': engineer_list,
    },
                              context_instance=RequestContext(request))