Ejemplo n.º 1
0
    def check_voters_file(self):

        # HES & HTS

        if not checkfile(self.voter_f):
            return False
        if not checkfile(self.voter_public_key_f):
            return False

        print "Kontrollin valijate faili avalikku võtit"
        if not sigverify.check_sig_file(self.voter_public_key_f):
            return False

        print "Kontrollin valijate faili terviklikkust"
        checkResult = sigverify.check_initial(self.voter_f,
                                              self.voter_public_key_f)
        if not checkResult[0]:
            print 'Kontrollimisel tekkis viga: %s\n' % checkResult[1]
            return False

        self._vl = inputlists.VotersList(self.root, self.reg, self._ed)
        self._vl.attach_elid(self.elid)
        self._vl.attach_logger(AppLog())
        if not self._vl.check_format(self.voter_f,
                                     'Kontrollin valijate nimekirja: '):
            print "Valijate nimekiri ei vasta nõuetele"
            return False

        if not self._vl.algne:
            print "Valijate nimekirja tüüp ei ole 'algne'"
            return False

        print "Valijate nimekiri OK"
        return True
Ejemplo n.º 2
0
    def check_voters_file(self):

        # HES & HTS

        if not checkfile(self.voter_f):
            return False

        print "Kontrollin valijate faili kontrollsummat"
        if not ksum.check(self.voter_f):
            print "Valijate faili kontrollsumma ei klapi"
            return False

        self._vl = inputlists.VotersList(self.root, self.reg, self._ed)
        self._vl.attach_elid(self.elid)
        self._vl.attach_logger(AppLog())
        if not self._vl.check_format(self.voter_f, \
            'Kontrollin valijate nimekirja: '):
            print "Valijate nimekiri ei vasta nõuetele"
            return False

        if not self._vl.algne:
            print "Valijate nimekirja tüüp ei ole 'algne'"
            return False

        print "Valijate nimekiri OK"
        return True
Ejemplo n.º 3
0
 def get_voter(self, ik):
     vl = None
     try:
         vl = inputlists.VotersList(self._root, self._reg)
         if not vl.has_voter(ik):
             return None
         return vl.get_voter(ik)
     finally:
         if vl != None:
             vl.close()
Ejemplo n.º 4
0
 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
Ejemplo n.º 5
0
def apply_changes(elid, voter_f):
    """Muudatuste rakendamine"""

    vl = None
    tokend = {}

    def check_state():
        if not ElectionState().can_apply_changes():
            sys.stderr.write('Selles hääletuse faasis (%s) pole võimalik '
                'nimekirju uuendada\n'
                % ElectionState().str())
            sys.exit(1)

    try:

        buflog = None

        if Election().is_hes():
            root = 'hes'
        elif Election().is_hts():
            root = 'hts'
        else:
            raise Exception('Vigane serveritüüp')

        buflog = BufferedLog(Election().
                get_path(evcommon.VOTER_LIST_LOG_FILE),
                'APPLY-CHANGES', elid)

        check_state()
        reg = Election().get_sub_reg(elid)
        ed = inputlists.Districts()
        ed.load(root, reg)
        vl = inputlists.VotersList(root, reg, ed)
        vl.attach_elid(elid)
        vl.ignore_errors()
        evlog.AppLog().set_app('APPLY-CHANGES')
        vl.attach_logger(evlog.AppLog())

        print "Kontrollin valijate faili terviklikkust"
        checkResult = sigverify.check_existent(voter_f, elid)
        if not checkResult[0]:
            raise Exception('Kontrollimisel tekkis viga: %s\n' % checkResult[1])
        else:
            print "Valijate faili terviklikkus OK"

        voters_file_sha256 = ksum.compute(voter_f)
        if Election().get_root_reg().check(
            ['common', 'voters_file_hashes', voters_file_sha256]):
            raise Exception('Kontrollsummaga %s fail on juba laaditud\n'
                % voters_file_sha256)

        if not vl.check_format(voter_f, 'Kontrollin valijate nimekirja: '):
            print "Valijate nimekiri ei vasta vormingunõuetele"
            sys.exit(1)
        else:
            print 'Valijate nimekiri OK'

        vl.attach_logger(buflog)
        if not vl.check_muudatus(
            'Kontrollin muudatuste kooskõlalisust: ',
            ElectionState().election_on(), tokend):
            print "Sisend ei ole kooskõlas olemasoleva konfiguratsiooniga"
        else:
            print "Muudatuste kooskõlalisus OK"

        _apply = 1
        if not buflog.empty():
            print 'Muudatuste sisselaadimisel esines vigu'
            buflog.output_errors()
            _apply = uiutil.ask_yes_no(
            'Kas rakendan kooskõlalised muudatused?')

        if not _apply:
            buflog.log_error('Muudatusi ei rakendatud')
            print 'Muudatusi ei rakendatud'
        else:
            if ElectionState().election_on() and root == 'hts':
                create_tokend_file(tokend, reg, elid)
            a_count, d_count = vl.create('Paigaldan valijaid: ')
            print 'Teostasin %d lisamist ja %d eemaldamist' \
                % (a_count, d_count)
            Election().copy_config_file(
                elid, root, voter_f, evcommon.VOTERS_FILES)
            Election().add_voters_file_hash(voter_f)
            print 'Muudatuste rakendamine lõppes edukalt'

    except SystemExit:
        sys.stderr.write('Viga muudatuste laadimisel\n')
        if buflog:
            buflog.output_errors()
        raise

    except Exception as ex:
        sys.stderr.write('Viga muudatuste laadimisel: ' + str(ex) + '\n')
        if buflog:
            buflog.output_errors()
        sys.exit(1)

    finally:
        if vl is not None:
            vl.close()
Ejemplo n.º 6
0
    if dist_f:
        ed = inputlists.Districts()
        ed.attach_logger(blog)
        if not ed.check_format(dist_f, 'Kontrollin jaoskondade nimekirja: '):
            print "Jaoskondade nimekiri ei vasta nõuetele"
        else:
            print "Jaoskondade nimekiri OK"

    if choices_f:
        ch = inputlists.ChoicesList(ed)
        ch.attach_logger(blog)
        if not ch.check_format(choices_f, 'Kontrollin valikute nimekirja: '):
            print "Valikute nimekiri ei vasta nõuetele"
        else:
            print "Valikute nimekiri OK"

    if voters_f:
        vl = inputlists.VotersList(None, None, ed)
        vl.attach_logger(blog)
        vl.ignore_errors()
        if not vl.check_format(voters_f, 'Kontrollin valijate nimekirja: '):
            print "Valijate nimekiri ei vasta nõuetele"
        else:
            print "Valijate nimekiri OK"


if __name__ == '__main__':
    check_inputlists(sys.argv)

# vim:set ts=4 sw=4 et fileencoding=utf8:
Ejemplo n.º 7
0
def check_inputlists(args):

    ed = None
    ch = None
    vl = None

    dist_f = None
    choices_f = None
    voters_f = None

    try:
        opts, args = getopt.getopt(args[1:], "d:c:v:h")
    except getopt.GetoptError as err:
        print str(err)
        usage()
        sys.exit(2)

    for option, value in opts:
        if option == "-v":
            voters_f = value
            evcommon.checkfile(voters_f)
        elif option == "-c":
            choices_f = value
            evcommon.checkfile(choices_f)
        elif option == "-d":
            dist_f = value
            evcommon.checkfile(dist_f)
        elif option == "-h":
            usage()
            sys.exit()
        else:
            assert False, "unhandled option"

    if (not dist_f) and (not choices_f) and (not voters_f):
        usage()
        sys.exit()

    blog = BufferedLog()

    if dist_f:
        ed = inputlists.Districts()
        ed.attach_logger(blog)
        if not ed.check_format(dist_f, 'Kontrollin jaoskondade nimekirja: '):
            print "Jaoskondade nimekiri ei vasta nõuetele"
        else:
            print "Jaoskondade nimekiri OK"

    if choices_f:
        ch = inputlists.ChoicesList(ed)
        ch.attach_logger(blog)
        if not ch.check_format(choices_f, 'Kontrollin valikute nimekirja: '):
            print "Valikute nimekiri ei vasta nõuetele"
        else:
            print "Valikute nimekiri OK"

    if voters_f:
        vl = inputlists.VotersList(None, None, ed)
        vl.attach_logger(blog)
        vl.ignore_errors()
        if not vl.check_format(voters_f, 'Kontrollin valijate nimekirja: '):
            print "Valijate nimekiri ei vasta nõuetele"
        else:
            print "Valijate nimekiri OK"