def hts_vote(self, valid_person, vote): ik = valid_person[0] en = valid_person[1] pn = valid_person[2] evlog.AppLog().set_person(ik) import base64 decoded_vote = base64.decodestring(vote) evlog.log("Hääle talletamine: %s %s" % (en, pn)) if not Election().can_vote(ik): error = HESResult() error.pole_valija(ik) return self.__return_error(error) inspector = VoteChecker(decoded_vote, ik) mobid = "MOBILE_ID_CONTEXT" in os.environ if not inspector.check_vote(mobid): return self.__return_error(inspector.error) params = {} params[evcommon.POST_EVOTE] = vote params[evcommon.POST_PERSONAL_CODE] = ik params[evcommon.POST_VOTERS_FILES_SHA256] = Election().get_voters_files_sha256() params[evcommon.POST_SESS_ID] = sessionid.voting() hts_connector = HTSConnector(params) if not hts_connector.work_strict(): return self.__return_error(hts_connector.error) return hts_connector.answer[1], hts_connector.answer[2]
def hts_vote(self, valid_person, vote): ik = valid_person[0] en = valid_person[1] pn = valid_person[2] evlog.AppLog().set_person(ik) import base64 decoded_vote = base64.decodestring(vote) evlog.log('Hääle talletamine: %s %s' % (en, pn)) if not Election().can_vote(ik): error = HESResult() error.pole_valija(ik) return self.__return_error(error) inspector = VoteChecker(decoded_vote, ik) mobid = 'MOBILE_ID_CONTEXT' in os.environ if not inspector.check_vote(mobid): return self.__return_error(inspector.error) params = {} params[evcommon.POST_EVOTE] = vote params[evcommon.POST_PERSONAL_CODE] = ik params[evcommon.POST_VOTERS_FILES_SHA256] = \ Election().get_voters_files_sha256() params[evcommon.POST_SESS_ID] = sessionid.voting() hts_connector = HTSConnector(params) if not hts_connector.work_strict(): return self.__return_error(hts_connector.error) return hts_connector.answer[1], hts_connector.answer[2]
def message(self, args): logstring = "%s (%s:%d:%d:%s:%s:%s:%s): %s" % ( time.strftime("%Y-%m-%d %H:%M:%S"), self.__app, self.__sess, self.__psess, sessionid.voting(), sessionid.apache(), self.__elid, self.__pers_id, args['message']) return logstring
def get_candidate_list(self, valid_person): ik = valid_person[0] en = valid_person[1] pn = valid_person[2] evlog.AppLog().set_person(ik) evlog.log("Kandidaatide nimekiri: %s %s" % (en, pn)) cld = CandidateListExtractor(ik, sessionid.voting()) cld.compose_list() if cld.has_list(): return evcommon.EVOTE_OK, cld.get_list() error = HESResult() error.pole_valija(ik) return self.__return_error(error)
def get_candidate_list(self, valid_person): ik = valid_person[0] en = valid_person[1] pn = valid_person[2] evlog.AppLog().set_person(ik) evlog.log('Kandidaatide nimekiri: %s %s' % (en, pn)) cld = CandidateListExtractor(ik, sessionid.voting()) cld.compose_list() if cld.has_list(): return evcommon.EVOTE_OK, cld.get_list() error = HESResult() error.pole_valija(ik) return self.__return_error(error)
def message(self, args): logstring = '' lines = args['message'].split('\n') for line in lines: logstring += "%s (%s:%d:%d:%s:%s:%s:%s): %s\n" % ( time.strftime("%Y-%m-%d %H:%M:%S"), self.__app, self.__sess, self.__psess, sessionid.voting(), sessionid.apache(), self.__elid, self.__pers_id, line) return logstring
def do_cgi(): try: elec = election.Election() evlog.AppLog().set_app(APP) # Create a list of pairs from the form parameters. Don't use a dictionary # because that will overwrite recurring keys. form = cgi.FieldStorage() params = [] for key in form: for value in form.getlist(key): params.append((key, value)) # Only accept up to a single parameter if len(params) > 1: def keys(pairs): """Return a comma-separated list of the keys.""" return ", ".join([pair[0] for pair in pairs]) evlog.log_error("Too many query parameters: " + keys(params)) bad_parameters() return # Only accept the POST_VERIFY_VOTE parameter. if len(params) and params[0][0] != evcommon.POST_VERIFY_VOTE: evlog.log_error('Unknown query parameter "%s"' % params[0][0]) bad_parameters() return # Make sure the parameter is correctly formatted. if not formatutil.is_vote_verification_id(params[0][1]): # Don't write to disk; we don't know how large the value is evlog.log_error("Malformed vote ID") bad_parameters() return evlog.log("verif/auth REMOTE_ADDR: " + evlogdata.get_remote_ip()) evlog.log("verif/auth VOTE-ID: " + params[0][1]) params.append((evcommon.POST_SESS_ID, sessionid.voting())) url = "http://" + elec.get_hts_ip() + "/" + elec.get_hts_verify_path() conn = urllib.urlopen(url, urllib.urlencode(params)) protocol.http_response(conn.read()) except: evlog.log_exception() technical_error()
def do_cgi(): try: elec = election.Election() evlog.AppLog().set_app(APP) # Create a list of pairs from the form parameters. Don't use a dictionary # because that will overwrite recurring keys. form = cgi.FieldStorage() params = [] for key in form: for value in form.getlist(key): params.append((key, value)) # Only accept up to a single parameter if len(params) > 1: def keys(pairs): """Return a comma-separated list of the keys.""" return ", ".join([pair[0] for pair in pairs]) evlog.log_error("Too many query parameters: " + keys(params)) bad_parameters() return # Only accept the POST_VERIFY_VOTE parameter. if len(params) and params[0][0] != evcommon.POST_VERIFY_VOTE: evlog.log_error("Unknown query parameter \"%s\"" % params[0][0]) bad_parameters() return # Make sure the parameter is correctly formatted. if not formatutil.is_vote_verification_id(params[0][1]): # Don't write to disk; we don't know how large the value is evlog.log_error("Malformed vote ID") bad_parameters() return evlog.log("verif/auth REMOTE_ADDR: " + evlogdata.get_remote_ip()) evlog.log("verif/auth VOTE-ID: " + params[0][1]) params.append((evcommon.POST_SESS_ID, sessionid.voting())) url = "http://" + elec.get_hts_ip() + "/" + elec.get_hts_verify_path() conn = urllib.urlopen(url, urllib.urlencode(params)) protocol.http_response(conn.read()) except: evlog.log_exception() technical_error()
def hts_repeat_check(self, valid_person): ik = valid_person[0] evlog.AppLog().set_person(ik) evlog.log("Korduvhääletuse kontroll") params = {} params[evcommon.POST_PERSONAL_CODE] = ik params[evcommon.POST_VOTERS_FILES_SHA256] = Election().get_voters_files_sha256() params[evcommon.POST_SESS_ID] = sessionid.voting() hts_connector = HTSConnector(params) if not hts_connector.work(): hts_connector.error.user_code = evcommon.EVOTE_REPEAT_ERROR return self.__return_error(hts_connector.error) retcode = hts_connector.answer[1] ans = "<br>".join(hts_connector.answer[2:]) return retcode, ans
def hts_repeat_check(self, valid_person): ik = valid_person[0] evlog.AppLog().set_person(ik) evlog.log('Korduvhääletuse kontroll') params = {} params[evcommon.POST_PERSONAL_CODE] = ik params[evcommon.POST_VOTERS_FILES_SHA256] = \ Election().get_voters_files_sha256() params[evcommon.POST_SESS_ID] = sessionid.voting() hts_connector = HTSConnector(params) if not hts_connector.work(): hts_connector.error.user_code = evcommon.EVOTE_REPEAT_ERROR return self.__return_error(hts_connector.error) retcode = hts_connector.answer[1] ans = '<br>'.join(hts_connector.answer[2:]) return retcode, ans
import urllib import os if not evcommon.testrun(): os.umask(007) form = cgi.FieldStorage() result = protocol.msg_error_technical() evlog.AppLog().set_app("VERIFY") try: req_params = [evcommon.POST_VERIFY_VOTE] res, logline = cgivalidator.validate_form(form, req_params) if res: cgilog.do_log("verif/auth") elec = election.Election() params = ((evcommon.POST_SESS_ID, sessionid.voting()), (evcommon.POST_VERIFY_VOTE, form.getvalue(evcommon.POST_VERIFY_VOTE))) evlog.log("verif/auth VOTE-ID: " + urllib.quote_plus(params[1][1])[:200]) url = ("http://" + elec.get_hts_ip() + "/" + elec.get_hts_verify_path()) conn = urllib.urlopen(url, urllib.urlencode(params)) result = conn.read() else: cgilog.do_log_error("verif/err") evlog.log_error(logline) except: evlog.log_exception()
def keys(pairs): """Return a comma-separated list of the keys.""" return ", ".join([pair[0] for pair in pairs]) evlog.log_error("Too many query parameters: " + keys(params)) bad_parameters() # Only accept the POST_VERIFY_VOTE parameter. if len(params) and params[0][0] != evcommon.POST_VERIFY_VOTE: evlog.log_error('Unknown query parameter "%s"' % params[0][0]) bad_parameters() # Make sure the parameter is correctly formatted. if not formatutil.is_vote_verification_id(params[0][1]): # Don't write to disk; we don't know how large the value is evlog.log_error("Malformed vote ID") bad_parameters() evlog.log("verif/auth REMOTE_ADDR: " + evlogdata.get_remote_ip()) evlog.log("verif/auth VOTE-ID: " + params[0][1]) params.append((evcommon.POST_SESS_ID, sessionid.voting())) url = "http://" + elec.get_hts_ip() + "/" + elec.get_hts_verify_path() conn = urllib.urlopen(url, urllib.urlencode(params)) protocol.http_response(conn.read()) cgi.sys.exit(0) # vim:set ts=4 sw=4 et fileencoding=utf8:
def ctx(self): # Can't be initialized in __init__, because sessionid.voting() is # subject to change before the first time ctx is used. if self.__use_ctx and not self.__ctx: self.__ctx = SessionContext(sessionid.voting()) return self.__ctx
def ctx(self): if not self.__ctx: self.__ctx = MobileIDContext(sessionid.voting()) return self.__ctx