Esempio n. 1
0
def pubdef(request):
    if request.method == 'POST':
        # check captcha first
        form = DefForm(request.POST)
        if not form.is_valid():
            return HttpResponse('The captcha is invalid!')
        name = request.POST['name']
        if name == "":
            name = "Anonymous"
        email = request.POST['email']
        if email == "":
            email = "*****@*****.**"
        q = request.POST['question']
        start = request.POST['elect_start']
        end = request.POST['elect_end']
        Paffiliation = request.POST['Paffiliation'].lower()
        title = request.POST['title'].lower()
        Porg = request.POST['Porg'].lower()
        total = request.POST['total']
        keyemails = request.POST['keyemails'].rstrip()
        pdf = request.POST.get('pdf', '')
        if pdf != '':
            intpdf = int(pdf)
        else:
            intpdf = 0
        opts = []

        # maximum 50 options cheat
        for pi in range(len(party_list) / 2):
            temp = party_list[2 * pi] + ";" + party_list[2 * pi + 1]
            opts.append(temp.decode('utf-8'))

        if Paffiliation == '':
            Paffiliation = '*'
        if title == '':
            title = '*'
        if Porg == '':
            Porg = '*'
        if total == '':
            total = "1"
        if start == '':
            start = timezone.now().strftime("%m/%d/%Y %H:%M")
        if end == '':
            end = timezone.now().strftime("%m/%d/%Y %H:%M")
        start_time = time.strptime(start, "%m/%d/%Y %H:%M")
        end_time = time.strptime(end, "%m/%d/%Y %H:%M")
        #EID should be hash of question start and end time short eid
        #eid = hashlib.sha1(q + start + end).hexdigest()
        counter = Election.objects.count()
        eid = base36encode(counter + 1)
        #first post to BB
        files = {
            'question': q,
            'start': start,
            'end': end,
            'eid': eid,
            'total': total
        }
        for i in range(len(opts)):
            files["opt" + str(i)] = opts[i]
        r = requests.post(BB_URL + 'def/', data=files, verify=False)
        #if r != "success":
        #    return HttpResponse(r)#('Error!')
        #create election
        new_e = Election(creator=name,
                         c_email=email,
                         Paffiliation=Paffiliation,
                         title=title,
                         Porg=Porg,
                         start=datetime.fromtimestamp(time.mktime(start_time)),
                         end=datetime.fromtimestamp(time.mktime(end_time)),
                         question=q,
                         EID=eid,
                         total=total)
        new_e.save()
        # store choices
        for x in opts:
            new_c = Choice(election=new_e, text=x)
            new_c.save()
        #go through the email files
        voter_emails = []
        emailfile = request.FILES.get('emailfile', '')
        if emailfile != '':
            reader = emailfile.read().splitlines()
            for line in reader:
                temp = line.rstrip().lower()
                if temp != '':
                    voter_emails.append(temp)
        #confirm EA
        data = []
        data.append("Question: " + q)
        for i in range(len(opts)):
            data.append("Option " + str(i + 1) + ": " + opts[i])
        data.append("Start time: " + start)
        data.append("End time: " + end)
        #data.append("End time: "+end)
        data.append("Key holders' emails: " + keyemails)
        data.append("Maximum number of voters: " + total)
        data.append("eduPersonPrimaryAffiliation: " + Paffiliation)
        data.append("Tile: " + title)
        data.append("eduPersonPrimaryOrgUnitDN: " + Porg)
        VBB_url = BB_URL + "vbb/" + eid + "/"
        ABB_url = BB_URL + "abb/" + eid + "/"
        #send email
        emailbody = "Hello " + name + ",\n\nThe following election is created.\n"
        emailbody += "\n".join(data)
        emailbody += "\nVBB_url: " + VBB_url + "\n"
        emailbody += "ABB_url: " + ABB_url + "\n"
        emailbody += "\nFINER  Election Authority\n"

        #send email
        p = subprocess.Popen([
            "sudo", "/var/www/finer/bingmail.sh",
            "Election Definition: " + q.encode('utf-8'),
            emailbody.encode('utf-8'), email
        ],
                             stdout=subprocess.PIPE,
                             stderr=subprocess.PIPE,
                             env=env)
        output, err = p.communicate()
        #celery prepare ballots
        prepare_ballot.delay(new_e, int(total), len(opts), voter_emails,
                             keyemails, intpdf)
        return render_to_response(
            'confirm.html', {
                'name': name,
                'data': data,
                'email': email,
                'VBB': VBB_url,
                'ABB': ABB_url
            })
    else:
        return render_to_response('pubdef.html', {'form': DefForm},
                                  context_instance=RequestContext(request))
Esempio n. 2
0
def pubdef(request):
    if request.method == 'POST':
        # check captcha first
        form = DefForm(request.POST)
        if not form.is_valid():
            return HttpResponse('The captcha is invalid!')
	name = request.POST['name']
	if name == "":
	    name = "Anonymous"
	email = request.POST['email']
	if email == "":
	    email = "*****@*****.**"
        q = request.POST['question']
        start = request.POST['elect_start']
        end = request.POST['elect_end']
        Paffiliation = request.POST['Paffiliation'].lower()
        title = request.POST['title'].lower()
        Porg = request.POST['Porg'].lower()
        total = request.POST['total']
	keyemails = request.POST['keyemails'].rstrip()	
	pdf = request.POST.get('pdf','')
	if pdf != '':
	    intpdf = int(pdf)
	else:
	    intpdf = 0
        opts = []

        # maximum 50 options cheat
        for pi in range(len(party_list)/2):
                temp = party_list[2*pi]+";"+ party_list[2*pi+1]
                opts.append(temp.decode('utf-8'))

        if Paffiliation == '':
            Paffiliation = '*'
        if title == '':
            title = '*'
        if Porg == '':
            Porg = '*'
        if total == '':
            total = "1"
        if start =='':
            start = timezone.now().strftime("%m/%d/%Y %H:%M")
        if end =='':
            end = timezone.now().strftime("%m/%d/%Y %H:%M")
        start_time = time.strptime(start, "%m/%d/%Y %H:%M")
        end_time = time.strptime(end, "%m/%d/%Y %H:%M")
        #EID should be hash of question start and end time short eid
        #eid = hashlib.sha1(q + start + end).hexdigest()
        counter = Election.objects.count()
        eid = base36encode(counter+1)
        #first post to BB
        files = { 'question': q, 'start':start,'end':end, 'eid':eid,'total':total}
        for i in range(len(opts)):
            files["opt"+str(i)] = opts[i]
        r = requests.post(BB_URL+'def/',data = files, verify=False)
        #if r != "success":
        #    return HttpResponse(r)#('Error!')
        #create election
        new_e = Election(creator = name, c_email = email, Paffiliation = Paffiliation, title = title, Porg = Porg, start = datetime.fromtimestamp(time.mktime(start_time)), end = datetime.fromtimestamp(time.mktime(end_time)), question = q, EID = eid, total = total)
        new_e.save()
        # store choices
        for x in opts:
            new_c = Choice(election = new_e, text = x)
            new_c.save()
        #go through the email files
        voter_emails = []
        emailfile = request.FILES.get('emailfile','')
        if emailfile != '':
            reader = emailfile.read().splitlines()
            for line in reader:
                temp = line.rstrip().lower()
                if temp != '':
                    voter_emails.append(temp)
        #confirm EA
        data = []
        data.append("Question: "+q)
        for i in range(len(opts)):
            data.append("Option "+str(i+1)+": "+opts[i])
        data.append("Start time: "+start)
        data.append("End time: "+end)
	#data.append("End time: "+end)
	data.append("Key holders' emails: "+keyemails)
        data.append("Maximum number of voters: "+total)
        data.append("eduPersonPrimaryAffiliation: "+Paffiliation)
        data.append("Tile: "+title)
        data.append("eduPersonPrimaryOrgUnitDN: "+Porg)
        VBB_url = BB_URL+"vbb/"+eid+"/"
        ABB_url = BB_URL+"abb/"+eid+"/"
        #send email
        emailbody = "Hello "+name+",\n\nThe following election is created.\n"
        emailbody+= "\n".join(data)
        emailbody+= "\nVBB_url: "+VBB_url+"\n"
        emailbody+= "ABB_url: "+ABB_url+"\n"
        emailbody+= "\nFINER  Election Authority\n"

        #send email         
    	p = subprocess.Popen(["sudo","/var/www/finer/bingmail.sh","Election Definition: "+q.encode('utf-8'), emailbody.encode('utf-8'),email],stdout=subprocess.PIPE,stderr=subprocess.PIPE, env=env)
    	output,err = p.communicate()
        #celery prepare ballots
        prepare_ballot.delay(new_e, int(total),len(opts), voter_emails, keyemails,intpdf)
        return render_to_response('confirm.html',{'name':name,'data':data, 'email':email,'VBB':VBB_url,'ABB':ABB_url})
    else:
        return render_to_response('pubdef.html', {'form':DefForm}, context_instance=RequestContext(request))
Esempio n. 3
0
def index(request):#CAS def no captcha
    name = request.META.get('HTTP_CAS_CN_LANG_EL','')
    if name == '':# for non-greek person
        name = request.META['HTTP_CAS_CN']
    email = request.META['HTTP_CAS_MAIL']
    if request.method == 'POST':
        q = request.POST['question'].strip()
        start = request.POST['elect_start'].strip()
        end = request.POST['elect_end'].strip()
        Paffiliation = request.POST['Paffiliation'].lower().strip()
        title = request.POST['title'].lower().strip()
        Porg = request.POST['Porg'].lower().strip()
	whitelist = request.POST['Whitelist'].lower().strip()
	blacklist = request.POST['Blacklist'].lower().strip()
        total = request.POST['total'].strip()
	keyemails = request.POST['keyemails'].strip()
	pdf = request.POST.get('pdf','') 
        if pdf != '':
            intpdf = int(pdf)
        else:
            intpdf = 0
        opts = []
        # maximum 100 options
        for i in range(1,101):
            temp = request.POST.get('opt'+str(i),'')
            if temp != '':
                opts.append(temp)
            else:
                break
        if Paffiliation == '':
	    Paffiliation = '*'
	if title == '':
	    title = '*'
	if Porg == '':
	    Porg = '*'
	if total == '':
	    total = "1"
	if start =='':
	    start = timezone.now().strftime("%m/%d/%Y %H:%M")
        if end =='':
            end = timezone.now().strftime("%m/%d/%Y %H:%M")
	start_time = time.strptime(start, "%m/%d/%Y %H:%M")
	end_time = time.strptime(end, "%m/%d/%Y %H:%M")
	#total = total + pdf (hack for new front page)
	total = str(int(total)+intpdf)
        #EID should be hash of question start and end time  short eid
        #eid = hashlib.sha1(q + start + end).hexdigest()
	counter = Election.objects.count()
	eid = base36encode(counter+1)
        #first post to BB
        files = { 'question': q, 'start':start,'end':end, 'eid':eid,'total':total, 'keysTotal':keyemails.count(',')+1}
        for i in range(len(opts)):
            files["opt"+str(i)] = opts[i]
        r = requests.post(BB_URL+'def/',data = files, verify=False)
        #if r != "success":
        #    return HttpResponse(r)#('Error!')

        #create election
        new_e = Election(creator = name, c_email = email, Paffiliation = Paffiliation, title = title, Porg = Porg,whitelist = whitelist, blacklist = blacklist, start = datetime.fromtimestamp(time.mktime(start_time)), end = datetime.fromtimestamp(time.mktime(end_time)), question = q, EID = eid, total = total)
        new_e.save()
        # store choices
        for x in opts:
            new_c = Choice(election = new_e, text = x)
            new_c.save()
        #go through the email files
	voter_emails = []
	emailfile = request.FILES.get('emailfile','')
	if emailfile != '':
	    reader = emailfile.read().splitlines()
	    for line in reader:
		temp = line.rstrip().lower()
		if temp != '':
		    voter_emails.append(temp)
        #confirm EA
        data = []
        data.append("Question: "+q)
        for i in range(len(opts)):
            data.append("Option "+str(i+1)+": "+opts[i])
        data.append("Start time: "+start)
        data.append("End time: "+end)
	data.append("Key holders' emails: "+keyemails)
        data.append("Maximum number of voters: "+total)
        data.append("eduPersonPrimaryAffiliation: "+Paffiliation)
        data.append("Tile: "+title)
        data.append("eduPersonPrimaryOrgUnitDN: "+Porg)
	data.append("Voter whitelist: "+whitelist)
	data.append("Voter blacklist: "+blacklist)
	VBB_url = BB_URL+"vbb/"+eid+"/"
        ABB_url = BB_URL+"abb/"+eid+"/"
	#send email
	en_name = request.META['HTTP_CAS_CN']
	emailbody = "Hello "+en_name+",\n\nThe following election is created.\n"
	emailbody+= "\n".join(data)
	emailbody+= "\nVBB_url: "+VBB_url+"\n"
	emailbody+= "ABB_url: "+ABB_url+"\n"
    	emailbody+= "\nFINER  Election Authority\n"

    	#send email         
    	p = subprocess.Popen(["sudo","/var/www/finer/bingmail.sh","Election Definition No. "+eid, emailbody.encode('utf-8'),email],stdout=subprocess.PIPE,stderr=subprocess.PIPE, env=env)
    	output,err = p.communicate()
	#celery prepare ballots
	prepare_ballot.delay(new_e, int(total),len(opts), voter_emails, keyemails, intpdf)
        return render_to_response('confirm.html',{'name':name,'data':data, 'email':email,'VBB':VBB_url,'ABB':ABB_url})
    else:
        return render_to_response('def.html', {'name':name, 'form':DefForm}, context_instance=RequestContext(request))
Esempio n. 4
0
def prepare_ballot(x, y):
    print "test...creating ballot.."
    #create election
    new_e = Election(start = timezone.now(), end = timezone.now(), question = "test", EID = 1234)
    new_e.save()
    return x + y