Esempio n. 1
0
                elif self.cur_file.mimetype != expected_mime:
                    # Unexpected mimetype => dissalowed
                    valid = False
                    compare_mime = 'Mime: {} - Expected: {}'.format(self.cur_file.mimetype, expected_mime)

                if valid:
                    to_copy.append(self.cur_file)
                    self.cur_file.log_string = 'Extension: {} - MimeType: {}'.format(self.cur_file.extension, self.cur_file.mimetype)
                else:
                    error.append(self.cur_file)
                    if compare_ext:
                        self.cur_file.log_string = compare_ext
                    else:
                        self.cur_file.log_string = compare_mime
            self.cur_file.add_log_details('valid', valid)

        if len(error) > 0:
            for f in error + to_copy:
                self.cur_file = f
                self._print_log()
        else:
            for f in to_copy:
                self.cur_file = f
                self._safe_copy()
                self._print_log()


if __name__ == '__main__':
    main(KittenGroomerSpec, ' Only copy some files, returns an error is anything else is found')
    exit(0)
Esempio n. 2
0
            self.log_name.warning('ARCHIVE BOMB.')
            self.log_name.warning(
                'The content of the archive contains recursively other archives.'
            )
            self.log_name.warning(
                'This is a bad sign so the archive is not extracted to the destination key.'
            )
            self._safe_rmtree(src_dir)
            if src_dir.endswith('_temp'):
                archbomb_path = src_dir[:-len('_temp')]
                self._safe_remove(archbomb_path)

        for srcpath in self._list_all_files(src_dir):
            self.cur_file = File(srcpath, srcpath.replace(src_dir, dst_dir))

            self.log_name.info('Processing {} ({}/{})',
                               srcpath.replace(src_dir + '/', ''),
                               self.cur_file.main_type, self.cur_file.sub_type)
            if not self.cur_file.is_dangerous():
                self.mime_processing_options.get(self.cur_file.main_type,
                                                 self.unknown)()
            else:
                self._safe_copy()
            if not self.cur_file.is_recursive:
                self._print_log()


if __name__ == '__main__':
    main(KittenGroomer,
         'Generic version of the KittenGroomer. Convert and rename files.')
Esempio n. 3
0
                elif self.cur_file.mimetype != expected_mime:
                    # Unexpected mimetype => dissalowed
                    valid = False
                    compare_mime = 'Mime: {} - Expected: {}'.format(self.cur_file.mimetype, expected_mime)

                if valid:
                    to_copy.append(self.cur_file)
                    self.cur_file.log_string = 'Extension: {} - MimeType: {}'.format(self.cur_file.extension, self.cur_file.mimetype)
                else:
                    error.append(self.cur_file)
                    if compare_ext:
                        self.cur_file.log_string = compare_ext
                    else:
                        self.cur_file.log_string = compare_mime
            self.cur_file.add_log_details('valid', valid)

        if len(error) > 0:
            for f in error + to_copy:
                self.cur_file = f
                self._print_log()
        else:
            for f in to_copy:
                self.cur_file = f
                self._safe_copy()
                self._print_log()


if __name__ == '__main__':
    main(KittenGroomerSpec, ' Only copy some files, returns an error is anything else is found')
    exit(0)
Esempio n. 4
0
            self._print_log()

        if self.recursive >= self.max_recursive:
            self.cur_log.warning("ARCHIVE BOMB.")
            self.cur_log.warning("The content of the archive contains recursively other archives.")
            self.cur_log.warning("This is a bad sign so the archive is not extracted to the destination key.")
            self._safe_rmtree(src_dir)
            if src_dir.endswith("_temp"):
                archbomb_path = src_dir[: -len("_temp")]
                self._safe_remove(archbomb_path)

        for srcpath in self._list_all_files(src_dir):
            self.cur_file = File(srcpath, srcpath.replace(src_dir, dst_dir))

            self.log_name.info(
                "Processing {} ({}/{})",
                srcpath.replace(src_dir + "/", ""),
                self.cur_file.main_type,
                self.cur_file.sub_type,
            )
            if not self.cur_file.is_dangerous():
                self.mime_processing_options.get(self.cur_file.main_type, self.unknown)()
            else:
                self._safe_copy()
            if not self.cur_file.is_recursive:
                self._print_log()


if __name__ == "__main__":
    main(KittenGroomerFileCheck, "Generic version of the KittenGroomer. Convert and rename files.")
Esempio n. 5
0
        else:
            self._safe_copy()
        if not self.cur_file.is_recursive:
            self._print_log()

    def processdir(self, src_dir=None, dst_dir=None):
        """Main function coordinating file processing."""
        if src_dir is None:
            src_dir = self.src_root_dir
        if dst_dir is None:
            dst_dir = self.dst_root_dir

        if self.recursive_archive_depth > 0:
            self._print_log()

        if self.recursive_archive_depth >= self.max_recursive_depth:
            self._handle_archivebomb(src_dir)

        for srcpath in self._list_all_files(src_dir):
            dstpath = srcpath.replace(src_dir, dst_dir)
            relative_path = srcpath.replace(src_dir + '/', '')
            # which path do we want in the log?
            self.process_file(srcpath, dstpath, relative_path)


if __name__ == '__main__':
    main(
        KittenGroomerFileCheck,
        'File sanitizer used in CIRCLean. Renames potentially dangerous files.'
    )
Esempio n. 6
0
            Print the logs related to the current file being processed
        '''
        tmp_log = self.log_name.fields(**self.cur_file.log_details)
        if not self.cur_file.log_details.get('valid'):
            tmp_log.warning(self.cur_file.log_string)
        else:
            tmp_log.debug(self.cur_file.log_string)

    def processdir(self):
        '''
            Main function doing the processing
        '''
        for srcpath in self._list_all_files(self.src_root_dir):
            self.log_name.info('Processing {}', srcpath.replace(self.src_root_dir + '/', ''))
            self.cur_file = FilePier9(srcpath, srcpath.replace(self.src_root_dir, self.dst_root_dir))
            if not self.cur_file.is_dangerous() and self.cur_file.extension in self.authorized_extensions:
                self.cur_file.add_log_details('valid', True)
                self.cur_file.log_string = 'Expected extension: ' + self.cur_file.extension
                self._safe_copy()
            else:
                self.cur_file.make_dangerous()
                if self.cur_file.extension:
                    self.cur_file.log_string = 'Bad extension: ' + self.cur_file.extension
                else:
                    self.cur_file.log_string = 'No Extension.'
            self._print_log()


if __name__ == '__main__':
    main(KittenGroomerPier9, 'Pier 9 version of the KittenGroomer. Only copy some files.')
Esempio n. 7
0
            src_dir = self.src_root_dir
        if dst_dir is None:
            dst_dir = self.dst_root_dir

        if self.recursive > 0:
            self._print_log()

        if self.recursive >= self.max_recursive:
            self.cur_log.warning('ARCHIVE BOMB.')
            self.cur_log.warning('The content of the archive contains recursively other archives.')
            self.cur_log.warning('This is a bad sign so the archive is not extracted to the destination key.')
            self._safe_rmtree(src_dir)
            if src_dir.endswith('_temp'):
                archbomb_path = src_dir[:-len('_temp')]
                self._safe_remove(archbomb_path)

        for srcpath in self._list_all_files(src_dir):
            self.cur_file = File(srcpath, srcpath.replace(src_dir, dst_dir))

            self.log_name.info('Processing {} ({}/{})', srcpath.replace(src_dir + '/', ''),
                               self.cur_file.main_type, self.cur_file.sub_type)
            if not self.cur_file.is_dangerous():
                self.mime_processing_options.get(self.cur_file.main_type, self.unknown)()
            else:
                self._safe_copy()
            if not self.cur_file.is_recursive:
                self._print_log()

if __name__ == '__main__':
    main(KittenGroomer, 'Generic version of the KittenGroomer. Convert and rename files.')
Esempio n. 8
0
        self.authorized_extensions = printers + cnc + shopbot + omax + epilog_laser + metabeam + up

    def _print_log(self):
        '''
            Print the logs related to the current file being processed
        '''
        tmp_log = self.log_name.fields(**self.cur_file.log_details)
        if not self.cur_file.log_details.get('valid'):
            tmp_log.warning(self.cur_file.log_string)
        else:
            tmp_log.debug(self.cur_file.log_string)

    def processdir(self):
        '''
            Main function doing the processing
        '''
        for srcpath in self._list_all_files(self.src_root_dir):
            self.log_name.info('Processing {}', srcpath.replace(self.src_root_dir + '/', ''))
            self.cur_file = FilePier9(srcpath, srcpath.replace(self.src_root_dir, self.dst_root_dir))
            if self.cur_file.extension in self.authorized_extensions:
                self.cur_file.add_log_details('valid', True)
                self.cur_file.log_string = 'Expected extension: ' + self.cur_file.extension
                self._safe_copy()
            else:
                self.cur_file.log_string = 'Bad extension: ' + self.cur_file.extension
            self._print_log()


if __name__ == '__main__':
    main(KittenGroomerPier9, 'Pier 9 version of the KittenGroomer. Only copy some files.')