Esempio n. 1
0
    def issue_vote_id(self):
        vote_id = self.__create_vote_key()
        rreg = Election().get_root_reg()
        key = htscommon.get_verification_key(vote_id)

        rreg.create_string_value(key, "voter", self.signercode)
        rreg.create_integer_value(key, "timestamp", int(time.time()))
        rreg.create_integer_value(key, "count", \
                Election().get_verification_count())

        # Store the election IDs and include a backreference in the
        # corresponding questions' subregistries.
        elids = ""
        for elid in [quest[0] for quest in self.questions]:
            elids += elid + "\t"

            sreg = Election().get_sub_reg(elid)
            skey = htscommon.get_user_key(self.signercode)
            sreg.ensure_key(skey)
            sreg.create_string_value(skey, \
                    htscommon.VOTE_VERIFICATION_ID_FILENAME, vote_id)

        rreg.create_string_value(key, "elids", elids)
        return vote_id
Esempio n. 2
0
class HTSBase:
    def __init__(self, elid):
        self._elid = elid
        self._errmsg = None
        self._reg = Election().get_sub_reg(self._elid)

        self._revlog = evlog.Logger()
        self._revlog.set_format(evlog.RevLogFormat())
        self._revlog.set_logs(self._reg.path(['common', evcommon.REVLOG_FILE]))

    def haaletanud(self, isikukood):
        latest = self.get_latest_vote(isikukood)
        return latest <> None

    def get_revoked_path(self, pc):
        user_key = htscommon.get_user_key(pc)
        return self._reg.path(user_key + ['reason'])

    def get_latest_vote(self, pc):
        user_key = htscommon.get_user_key(pc)
        if self._reg.check(user_key):
            files = self._reg.list_keys(user_key)
            votes = []
            for el in files:
                if htscommon.VALID_VOTE_PATTERN.match(el):
                    votes.append(el)
            votes.sort()
            latest = votes.pop()
            if latest:
                return htscommon.get_votefile_time(latest)

        return None

    def restore_vote(self, revline, operator):
        timest = self.get_latest_vote(revline[0])
        os.unlink(self.get_revoked_path(revline[0]))
        self._revlog.log_info(tegevus='ennistamine',
                              isikukood=revline[0],
                              nimi=revline[1],
                              timestamp=timest,
                              operaator=operator,
                              pohjus=revline[2])

    def revoke_vote(self, revline, operator):
        timest = self.get_latest_vote(revline[0])
        nowstr = time.strftime("%Y%m%d%H%M%S", time.localtime())
        self._reg.create_string_value(\
            htscommon.get_user_key(revline[0]), 'reason', \
            "%s\t%s" % (nowstr, revline[2]))

        self._revlog.log_info(tegevus='tühistamine',
                              testtime=nowstr,
                              isikukood=revline[0],
                              nimi=revline[1],
                              timestamp=timest,
                              operaator=operator,
                              pohjus=revline[2])

    def is_user_revoked(self, pc):
        user_key = htscommon.get_user_key(pc)
        if self._reg.check(user_key + ['reason']):
            line = self._reg.read_string_value(user_key, 'reason').value
            data = line.split('\t')
            return True, data[1], data[0]
        return False, '', ''

    def save_log(self, lines, log):
        fn = self._reg.path(['common', 'log%s' % log])
        lf = htscommon.LoggedFile(fn)
        lf.open('w')
        lf.write(evcommon.VERSION + "\n")
        lf.write(self._elid + "\n")
        lf.write("%s\n" % log)
        for el in lines:
            lf.write(el + '\n')
        lf.close()

    def save_revocation_report(self, report):
        fn = self._reg.path(['hts', 'output', evcommon.REVREPORT_FILE])
        outfile = htscommon.LoggedFile(fn)
        outfile.open('a')
        for el in report:
            outfile.write("\t".join(el) + "\n")

        outfile.close()

    def talletaja(self, ik):
        vl = None
        try:
            vl = inputlists.VotersList('hts', self._reg)
            if not vl.has_voter(ik):
                return None
            ret = vl.get_voter(ik)
            return ret
        finally:
            if vl != None:
                vl.close()
                vl = None
Esempio n. 3
0
def do_change_election_description(elid):
    description = uiutil.ask_string("Sisesta valimiste kirjeldus")
    el_reg = Election().get_sub_reg(elid)
    el_reg.create_string_value(['common'], 'description', description)
Esempio n. 4
0
def do_change_election_description(elid):
    description = uiutil.ask_string("Sisesta valimiste kirjeldus")
    el_reg = Election().get_sub_reg(elid)
    el_reg.create_string_value(['common'], 'description', description)
Esempio n. 5
0
class HTSBase:

    def __init__(self, elid):
        self._elid = elid
        self._errmsg = None
        self._reg = Election().get_sub_reg(self._elid)

        self._revlog = evlog.Logger()
        self._revlog.set_format(evlog.RevLogFormat())
        self._revlog.set_logs(self._reg.path(['common', evcommon.REVLOG_FILE]))

    def haaletanud(self, isikukood):
        latest = self.get_latest_vote(isikukood)
        return latest is not None

    def get_revoked_path(self, pc):
        user_key = htscommon.get_user_key(pc)
        return self._reg.path(user_key + ['reason'])

    def get_latest_vote(self, pc):
        user_key = htscommon.get_user_key(pc)
        if self._reg.check(user_key):
            files = self._reg.list_keys(user_key)
            votes = []
            for el in files:
                if htscommon.VALID_VOTE_PATTERN.match(el):
                    votes.append(el)
            votes.sort()
            latest = votes.pop()
            if latest:
                return htscommon.get_votefile_time(latest)

        return None

    def restore_vote(self, revline, operator):
        timest = self.get_latest_vote(revline[0])
        os.unlink(self.get_revoked_path(revline[0]))
        self._revlog.log_info(
            tegevus='ennistamine',
            isikukood=revline[0],
            nimi=revline[1],
            timestamp=timest,
            operaator=operator,
            pohjus=revline[2])

    def revoke_vote(self, revline, operator):
        timest = self.get_latest_vote(revline[0])
        nowstr = time.strftime("%Y%m%d%H%M%S", time.localtime())
        self._reg.create_string_value(
            htscommon.get_user_key(revline[0]), 'reason',
            "%s\t%s" % (nowstr, revline[2]))

        self._revlog.log_info(
            tegevus='tühistamine',
            testtime=nowstr,
            isikukood=revline[0],
            nimi=revline[1],
            timestamp=timest,
            operaator=operator,
            pohjus=revline[2])

    def is_user_revoked(self, pc):
        user_key = htscommon.get_user_key(pc)
        if self._reg.check(user_key + ['reason']):
            line = self._reg.read_string_value(user_key, 'reason').value
            data = line.split('\t')
            return True, data[1], data[0]
        return False, '', ''

    def save_log(self, lines, log):
        fn = self._reg.path(['common', 'log%s' % log])
        lf = htscommon.LoggedFile(fn)
        lf.open('w')
        lf.write(evcommon.VERSION + "\n")
        lf.write(self._elid + "\n")
        lf.write("%s\n" % log)
        for el in lines:
            lf.write(el + '\n')
        lf.close()

    def save_revocation_report(self, report):
        fn = self._reg.path(['hts', 'output', evcommon.REVREPORT_FILE])
        outfile = htscommon.LoggedFile(fn)
        outfile.open('a')
        for el in report:
            outfile.write("\t".join(el) + "\n")

        outfile.close()

    def talletaja(self, ik):
        vl = None
        try:
            vl = inputlists.VotersList('hts', self._reg)
            if not vl.has_voter(ik):
                return None
            ret = vl.get_voter(ik)
            return ret
        finally:
            if vl is not None:
                vl.close()
                vl = None