예제 #1
0
    def onCommandDec(self):
        """"""
        done  = True
        if self.o.outputfile is None :
            self.o.outputfile = self.a[1][:-4] if self.a[1][-4:] == Kirmah.EXT else self.a[1]

        if not Sys.g.QUIET : self.parser.print_header()

        if Io.file_exists(self.o.outputfile) and not self.o.force:
            Sys.pwarn((('the file ',(self.o.outputfile, Sys.Clz.fgb3), ' already exists !'),))
            done  = Sys.pask('Are you sure to rewrite this file')
            self.stime = Sys.datetime.now()

        if done :

            try :

                if (self.o.multiprocess is not None and not represents_int(self.o.multiprocess)) or (not self.o.multiprocess is None and not(int(self.o.multiprocess)>=2 and int(self.o.multiprocess) <=8)) :
                    self.parser.error_cmd((('invalid option ',('-j, --multiprocess', Sys.Clz.fgb3), ' value (', ('2',Sys.Clz.fgb3),' to ', ('8',Sys.Clz.fgb3),')'),))

                nproc = int(self.o.multiprocess) if not self.o.multiprocess is None and int(self.o.multiprocess)>=2 and int(self.o.multiprocess) <=8 else 1

                Sys.ptask()

                key    = Io.get_data(self.o.keyfile)
                km     = Kirmah(key)

                km.decrypt(self.a[1], self.o.outputfile, nproc)

            except BadKeyException:
                done = False
                Sys.pwarn((('BadKeyException : ',('wrong key ',Sys.CLZ_WARN_PARAM), ' !'),), False)

        if not Sys.g.QUIET :
            self.onend_cmd('Kirmah Decrypt', self.stime, done, self.o.outputfile)
예제 #2
0
 def getMatchKey(self):
     key = None
     if not len(self.a) > 1:
         self.parser.error_cmd((a[0] + " command need an id",), True)
     else:
         if not represents_int(self.a[1]):
             self.parser.error_cmd((("not a valid id : ", (self.a[1], Sys.CLZ_ERROR_PARAM)),), False)
         else:
             vid = self.a[1]
             key = self.impst.idxu.index.getById(vid)
             if key is None:
                 self.parser.error_cmd(((" not a valid id : ", (self.a[1], Sys.CLZ_ERROR_PARAM)),), False)
     return key
예제 #3
0
    def onCommandDec(self):
        """"""
        done = True
        if self.o.outputfile is None:
            self.o.outputfile = self.a[1][:-4] if self.a[1][
                -4:] == Kirmah.EXT else self.a[1]

        if not Sys.g.QUIET: self.parser.print_header()

        if Io.file_exists(self.o.outputfile) and not self.o.force:
            Sys.pwarn((('the file ', (self.o.outputfile, Sys.Clz.fgb3),
                        ' already exists !'), ))
            done = Sys.pask('Are you sure to rewrite this file')
            self.stime = Sys.datetime.now()

        if done:

            try:

                if (self.o.multiprocess is not None
                        and not represents_int(self.o.multiprocess)) or (
                            not self.o.multiprocess is None
                            and not (int(self.o.multiprocess) >= 2
                                     and int(self.o.multiprocess) <= 8)):
                    self.parser.error_cmd(
                        (('invalid option ', ('-j, --multiprocess',
                                              Sys.Clz.fgb3), ' value (',
                          ('2', Sys.Clz.fgb3), ' to ', ('8',
                                                        Sys.Clz.fgb3), ')'), ))

                nproc = int(self.o.multiprocess
                            ) if not self.o.multiprocess is None and int(
                                self.o.multiprocess) >= 2 and int(
                                    self.o.multiprocess) <= 8 else 1

                Sys.ptask()

                key = Io.get_data(self.o.keyfile)
                km = Kirmah(key)

                km.decrypt(self.a[1], self.o.outputfile, nproc)

            except BadKeyException:
                done = False
                Sys.pwarn((('BadKeyException : ',
                            ('wrong key ', Sys.CLZ_WARN_PARAM), ' !'), ),
                          False)

        if not Sys.g.QUIET:
            self.onend_cmd('Kirmah Decrypt', self.stime, done,
                           self.o.outputfile)
예제 #4
0
파일: cliapp.py 프로젝트: necrose99/Kirmah
    def onCommandEnc(self):
        """"""
        done   = True
        if self.o.outputfile is None :
            self.o.outputfile = Sys.basename(self.a[1])
        if self.o.outputfile[-len(Kirmah.EXT):] != Kirmah.EXT :
            print(self.o.outputfile[-len(Kirmah.EXT):])
            self.o.outputfile += Kirmah.EXT
        print(self.o.outputfile)

        d        = self.getDefaultOption((self.o.compress,self.o.fullcompress,self.o.nocompress))
        compress = (KirmahHeader.COMP_END if d == 0 or (d is None and Io.is_binary(self.a[1])) else (KirmahHeader.COMP_ALL if d==1 or d is None else KirmahHeader.COMP_NONE))
        random   = True if (self.o.random is None and self.o.norandom is None) or self.o.random else False
        mix      = True if (self.o.mix is None and self.o.nomix is None) or self.o.mix else False

        if (self.o.multiprocess is not None and not represents_int(self.o.multiprocess)) or (not self.o.multiprocess is None and not(int(self.o.multiprocess)>=2 and int(self.o.multiprocess) <=8)) :
            self.parser.error_cmd((('invalid option ',('-j, --multiprocess', Sys.Clz.fgb3), ' value (', ('2',Sys.Clz.fgb3),' to ', ('8',Sys.Clz.fgb3),')'),))

        nproc = int(self.o.multiprocess) if not self.o.multiprocess is None and int(self.o.multiprocess)>=2 and int(self.o.multiprocess) <=8 else 1

        if not Sys.g.QUIET : self.parser.print_header()

        if Io.file_exists(self.o.outputfile) and not self.o.force:
            Sys.pwarn((('the file ',(self.o.outputfile, Sys.Clz.fgb3), ' already exists !'),))
            done  = Sys.pask('Are you sure to rewrite this file')
            self.stime = Sys.datetime.now()

        if done :

            try :
                Sys.ptask()

                key    = Io.get_data(self.o.keyfile)
                km     = Kirmah(key, None, compress, random, mix)

                km.encrypt(self.a[1], self.o.outputfile, nproc)

            except Exception as e :
                done = False
                print(e)
                raise e
                pass

        if not Sys.g.QUIET :
            self.onend_cmd('Kirmah Encrypt', self.stime, done, self.o.outputfile)
예제 #5
0
    def onCommandConf(self):
        """"""
        if self.o.load is not None or self.o.view is not None or self.o.save is not None:

            if self.o.view is not None:
                self.o.active_profile = self.o.view
            if self.o.load is not None:
                self.o.active_profile = self.o.load
            if self.o.save is not None:
                self.o.active_profile = self.o.save

            if self.o.active_profile == None:
                if self.ini.has("profile"):
                    self.o.active_profile = self.ini.get("profile")
                else:
                    self.o.active_profile = "default"

            if self.o.load:
                self.pheader()
                self.load_profile()

            elif self.o.view:
                self.pheader()
                if self.o.view == "all":
                    sections = self.ini.getSections()
                    if len(sections) > 0:
                        ap = self.ini.get("profile")
                        sep = ""
                        for p in sections:
                            if p == ap:
                                colr = Sys.Clz.fgB1
                                p = "*" + p
                            else:
                                colr = Sys.Clz.fgB3
                            Sys.echo(sep + p, colr, False)
                            if sep == "":
                                sep = ","
                        Sys.dprint()
                    else:
                        Sys.echo(" no profiles", Sys.Clz.fgB1)
                else:
                    print(self.ini.get("profile"))
                    self.ini.print(self.o.view)

            elif self.o.save:
                self.pheader()
                if (
                    not self.o.set_host
                    and not self.o.set_user
                    and not self.o.set_pass
                    and not self.o.set_port
                    and not self.o.set_boxname
                    and not self.o.set_name
                    and not self.o.gen_key
                    and not self.o.set_multi
                    and not self.o.remove_multi
                ):
                    self.parser.error(" no options specified")
                else:
                    if self.o.set_port and not represents_int(self.o.set_port):
                        self.parser.error(" port must be a number")
                        self.exit(1)
                    else:
                        if self.o.set_boxname:
                            self.ini.set("box", self.o.set_boxname, self.o.active_profile + ".imap")
                        if self.o.set_host:
                            self.ini.set("host", self.o.set_host, self.o.active_profile + ".imap")
                        if self.o.set_user:
                            self.ini.set("user", self.o.set_user, self.o.active_profile + ".imap")
                        if self.o.set_pass:
                            self.ini.set("pass", self.o.set_pass, self.o.active_profile + ".imap")
                        if self.o.set_port:
                            self.ini.set("port", self.o.set_port, self.o.active_profile + ".imap")
                        if self.o.set_name:
                            self.ini.set("name", self.o.set_name, self.o.active_profile + ".infos")

                        if self.ini.has("multi", self.o.active_profile + ".imap"):
                            m = self.ini.get("multi", self.o.active_profile + ".imap")
                        else:
                            m = None
                        if m is None:
                            m = []
                        else:
                            m = m.split(",")
                        m = [x for x in m if x]
                        if self.o.set_multi:
                            if self.check_imap(self.o.set_multi):
                                if not self.o.set_multi in m:
                                    m.append(self.o.set_multi)
                            else:
                                Sys.dprint()
                                Sys.echo("imap profile " + self.o.set_multi + " not found", Sys.Clz.fgB1)
                                Sys.dprint()
                        elif self.o.remove_multi and self.o.remove_multi in m:
                            m.remove(self.o.remove_multi)
                        self.ini.set("multi", ",".join(m), self.o.active_profile + ".imap")

                        if self.o.gen_key:
                            kg = KeyGen()
                            self.ini.set("key", kg.key, self.o.active_profile + ".keys")
                            self.ini.set("mark", kg.mark, self.o.active_profile + ".keys")
                            self.ini.set("salt", "-¤-ImpraStorage-¤-", self.o.active_profile + ".keys")
                        if self.check_profile(self.o.active_profile):
                            self.ini.set("profile", self.o.active_profile)
                        if not self.o.set_boxname and not self.ini.has("box", self.o.active_profile + ".imap"):
                            self.ini.set("box", self.rootBox, self.o.active_profile + ".imap")
                        self.ini.save()
                        self.ini.print(self.o.active_profile)

        elif self.o.check:
            self.pheader()
            self.check_profile(self.o.check, True)

        else:
            self.parser.print_usage("")
예제 #6
0
    def onCommandEnc(self):
        """"""
        done = True
        if self.o.outputfile is None:
            self.o.outputfile = Sys.basename(self.a[1])
        if self.o.outputfile[-len(Kirmah.EXT):] != Kirmah.EXT:
            print(self.o.outputfile[-len(Kirmah.EXT):])
            self.o.outputfile += Kirmah.EXT
        print(self.o.outputfile)

        d = self.getDefaultOption(
            (self.o.compress, self.o.fullcompress, self.o.nocompress))
        compress = (KirmahHeader.COMP_END if d == 0 or
                    (d is None and Io.is_binary(self.a[1])) else
                    (KirmahHeader.COMP_ALL
                     if d == 1 or d is None else KirmahHeader.COMP_NONE))
        random = True if (self.o.random is None and
                          self.o.norandom is None) or self.o.random else False
        mix = True if (self.o.mix is None
                       and self.o.nomix is None) or self.o.mix else False

        if (self.o.multiprocess is not None
                and not represents_int(self.o.multiprocess)) or (
                    not self.o.multiprocess is None
                    and not (int(self.o.multiprocess) >= 2
                             and int(self.o.multiprocess) <= 8)):
            self.parser.error_cmd(
                (('invalid option ', ('-j, --multiprocess',
                                      Sys.Clz.fgb3), ' value (',
                  ('2', Sys.Clz.fgb3), ' to ', ('8', Sys.Clz.fgb3), ')'), ))

        nproc = int(
            self.o.multiprocess) if not self.o.multiprocess is None and int(
                self.o.multiprocess) >= 2 and int(
                    self.o.multiprocess) <= 8 else 1

        if not Sys.g.QUIET: self.parser.print_header()

        if Io.file_exists(self.o.outputfile) and not self.o.force:
            Sys.pwarn((('the file ', (self.o.outputfile, Sys.Clz.fgb3),
                        ' already exists !'), ))
            done = Sys.pask('Are you sure to rewrite this file')
            self.stime = Sys.datetime.now()

        if done:

            try:
                Sys.ptask()

                key = Io.get_data(self.o.keyfile)
                km = Kirmah(key, None, compress, random, mix)

                km.encrypt(self.a[1], self.o.outputfile, nproc)

            except Exception as e:
                done = False
                print(e)
                raise e
                pass

        if not Sys.g.QUIET:
            self.onend_cmd('Kirmah Encrypt', self.stime, done,
                           self.o.outputfile)