Esempio n. 1
0
    def upgrade_auth_schemes(self, version, folder):

        file = os.path.join(folder, "auth_labels.json")
        if not os.path.isfile(file):
            return

        data = read_json_object(file)

        # save labelling
        obj = AuthLabel.objects.first()
        obj.enable = data['enable']
        obj.resolve_ip_as_user_name = data['resolve_ip_as_user_name']
        obj.save()

        # save labels
        for label in data["labels"]:

            if not label["user_name"]:
                continue

            try:
                v, c = AuthLabelUsers.objects.get_or_create(
                    user_name=label["user_name"])
                v.user_ip = label["user_ip"]
                v.user_mac = label["user_eui"]
                v.comment = label["comment"]

                v.save()
            except Exception as e:
                #logging.warning("Ignoring import of user name label %s, error '%s' ..." % (label["user_name"], str(e)))
                pass
Esempio n. 2
0
    def upgrade(self, etc_dir):

        path = os.path.join(etc_dir, "safety", "adult.json")
        if not os.path.exists(path):
            path = os.path.join(etc_dir, "adult.json")

        self.upgrade_impl(read_json_object(path))
Esempio n. 3
0
    def upgrade(self, etc_dir):

        path = os.path.join(etc_dir, "safety", "categories.json")
        if not os.path.exists(path):
            return

        self.upgrade_impl(read_json_object(path))
Esempio n. 4
0
    def upgrade_impl(self, folder):

        # loop through all the exclusions
        for n, s in {
                "content_type.json": self.policy.exclusioncontenttype_set,
                "domain_ip.json": self.policy.exclusionip_set,
                "domain_ip_range.json": self.policy.exclusionrange_set,
                "domain_ip_subnet.json": self.policy.exclusionsubnet_set,
                "request_uri.json": self.policy.exclusionurl_set,
                "domain_name.json": self.policy.exclusiondomain_set,
        }.iteritems():

            # load json array
            for data in read_json_object(os.path.join(folder, n)):

                if isinstance(data, basestring):
                    obj, created = s.get_or_create(value=data)
                else:
                    # create or get existing one
                    obj, created = s.get_or_create(value=data['value'])

                    # set scan flags for it
                    obj.scan_adult = data['scan']['adult']
                    obj.scan_categories = data['scan']['categories']
                    obj.scan_file = data['scan']['file']
                    obj.scan_adblock = data['scan']['adblock']
                    obj.scan_privacy = data['scan']['privacy']
                    obj.scan_http = data['scan']['http']

                    # save comment
                    if 'comment' in data:
                        obj.comment = data["comment"]

                    # and save the object
                    obj.save()
Esempio n. 5
0
    def upgrade(self, etc_dir):

        path = os.path.join(etc_dir, "squid", "wsicap.json")
        if not os.path.exists(path):
            path = os.path.join(etc_dir, "network.json")

        if os.path.exists(path):
            self.upgrade_impl(read_json_object(path))
Esempio n. 6
0
    def upgrade(self, etc_dir):

        path = os.path.join(etc_dir, "antivirus", "safe_browsing.json")

        if not os.path.exists(path):
            return

        self.upgrade_impl(read_json_object(path))
Esempio n. 7
0
    def upgrade_new(self, etc_dir):

        file = os.path.join(etc_dir, "squid", "auth_domain.json")
        if not os.path.isfile(file):
            return

        data = read_json_object(file)
        obj = AuthAd.objects.first()

        obj.dc1addr = data['dc1addr']
        obj.dc2addr = data['dc2addr']
        obj.base_dn = data['base_dn']
        obj.bind_user = data['bind_user']
        obj.bind_pass = data['bind_pass']
        obj.realm = data['realm']

        if "use_ldaps" in data:
            if data["use_ldaps"]:
                obj.lookup_mode = AuthAd.LOOKUP_MODE_LDAPS
        else:
            port1 = data.get("dc1port", 389)
            port2 = data.get("dc2port", 389)

            if port1 == 389 or port2 == 389:
                obj.lookup_mode = AuthAd.LOOKUP_MODE_LDAP
            elif port1 == 636 or port2 == 636:
                obj.lookup_mode = AuthAd.LOOKUP_MODE_LDAPS
            elif port1 == 3268 or port2 == 3268:
                obj.lookup_mode = AuthAd.LOOKUP_MODE_GC
            elif port1 == 3269 or port2 == 3269:
                obj.lookup_mode = AuthAd.LOOKUP_MODE_GCS
            else:
                pass

        obj.save()

        data = read_json_object(
            os.path.join(etc_dir, "squid", "auth_group_membership.json"))

        obj.cachetime = data['cache_time']
        obj.timeout = data['timeout']
        obj.save()
Esempio n. 8
0
    def upgrade_globals(self, major, minor, folder):

        if major < 4:
            return

        data = read_json_object(os.path.join(folder, "policy.json"))
        advanced = self.policy.advanced

        advanced.comment = data.get('description', "")
        advanced.enable = data.get('enabled', True)
        advanced.hide_history = data.get('hide_history', False)
        advanced.hide_result_info = data.get('hide_result_info', True)
        advanced.ignore_case = data.get('ignore_case_exclusions', True)
        advanced.sslbump = data.get('sslbump', True)
        advanced.tunnel_block = data.get('tunnel_block', True)

        path1 = os.path.join(folder, "advanced.json")
        if os.path.exists(path1):
            advanced.exclude_by_referer = read_json_object(path1).get(
                'exclude_by_referer', False)

        advanced.save()
Esempio n. 9
0
    def get_priority(self, policy_dir):
        j = os.path.join(policy_dir, "policy.json")
        if os.path.exists(j):
            d = read_json_object(j)
            return d['priority']

        j = os.path.join(policy_dir, "policy.conf")
        if os.path.exists(j):
            store = Storage(ConfFileReader(j).read_lines(True))
            priority = store.get_int('priority')
            if priority != 0:
                return priority

        return 1
Esempio n. 10
0
    def upgrade(self, etc_dir):

        # import adblock
        path = os.path.join(etc_dir, "safety", "adblock.json")
        if not os.path.exists(path):
            path = os.path.join(etc_dir, "adblock.json")

        self.upgrade_adblock_impl(read_json_array(path))

        # import privacy
        path = os.path.join(etc_dir, "safety", "privacy.json")
        if not os.path.exists(path):
            path = os.path.join(etc_dir, "privacy.json")

        self.upgrade_privacy_impl(read_json_array(path))

        # now the new annoyances
        path = os.path.join(etc_dir, "safety", "subscriptions.json")
        if os.path.exists(path):
            self.upgrade_subscriptions(read_json_object(path))
Esempio n. 11
0
    def upgrade_bypass(self, major, minor, folder):

        data = read_json_object(os.path.join(folder, "policy.json"))

        self.policy.bypass_allowed = data.get("bypass_allowed", False)
        self.policy.bypass_strip_www = data.get("bypass_strip_www", True)
        self.policy.bypass_children = data.get("bypass_children", True)
        # self.policy.bypass_category     = data.get("bypass_category", False) # not implemented
        # self.policy.bypass_all          = data.get("bypass_all", False)      # not implemented
        self.policy.bypass_referers = data.get("bypass_referers", False)
        self.policy.bypass_duration = data.get("bypass_duration", 60)
        self.policy.bypass_token_required = data.get("bypass_token_required",
                                                     False)

        self.policy.bypass_adult = data.get("bypass_adult", True)
        self.policy.bypass_categories = data.get("bypass_categories", True)
        self.policy.bypass_file = data.get("bypass_file", True)
        self.policy.bypass_adblock = data.get("bypass_adblock", True)
        self.policy.bypass_privacy = data.get("bypass_privacy", True)
        self.policy.bypass_http = data.get("bypass_http", True)
Esempio n. 12
0
    def upgrade_old(self, etc_dir):

        data = read_json_object(os.path.join(etc_dir, "ldap.json"))
        obj = AuthAd.objects.first()

        if 'server' in data and 'schema' in data:

            obj.dc1addr = data['server']
            if data['schema'] == "ldaps":
                obj.use_ldaps = True

        if 'bind_user' in data and 'bind_pass' in data and 'basedn' in data:
            obj.bind_user = data['bind_user']
            obj.bind_pass = data['bind_pass']
            obj.base_dn = data['basedn']
            obj.save()

        if 'cache_time' in data and 'timeout' in data:

            obj.cachetime = data['cache_time']
            obj.timeout = data['timeout']
            obj.save()
Esempio n. 13
0
    def upgrade_schedule(self, major, minor, folder):

        if major < 4:
            if major == 4 and minor < 9:
                return

        data = read_json_object(os.path.join(folder, "schedule.json"))
        schedules = self.policy.schedule_set

        for item in data:

            schedules.create(on_mon=item['days']['mon'],
                             on_tue=item['days']['tue'],
                             on_wed=item['days']['wed'],
                             on_thu=item['days']['thu'],
                             on_fri=item['days']['fri'],
                             on_sat=item['days']['sat'],
                             on_sun=item['days']['sun'],
                             from_hours=item['from']['hours'],
                             from_mins=item['from']['minutes'],
                             to_hours=item['to']['hours'],
                             to_mins=item['to']['minutes'])
Esempio n. 14
0
    def do_action(self, form):

        # process reset right away
        action = form.cleaned_data['action']
        if action == "reset":
            return self.do_reset()

        # if we got here, it is definitely not reset, see if file is present
        if not form.cleaned_data['file']:
            raise Exception("File is required for restore and import action!")

        # process the uploaded file
        arch_name = self.collect_zip()
        unpack_dir = self.unzip(arch_name)

        # set version hint (default empty)
        version4 = ""
        version2 = ""

        try:
            data = read_json_object(
                os.path.join(unpack_dir, "etc", "version.json"))
            version4 = data['version']
            digits = version4.split(".")
            version2 = "%s.%s" % (digits[0], digits[1])

        except Exception as e:

            version2 = ""
            version4 = ""

        if action == "restore":
            self.do_restore(unpack_dir, version2, version4)
        elif action == "import":
            self.do_import(form, unpack_dir, version2, version4)
        else:
            raise Exception("Unknown action '%s'" % action)
Esempio n. 15
0
    def upgrade_reports(self, etc_dir):

        path = os.path.join(etc_dir, "traffic", "reports.json")
        if not os.path.exists(path):
            return

        if self.major < 5:
            return
        if self.major == 5 and self.minor < 2:
            return

        # get json and upgrade
        data = read_json_object(path)

        # upgrade smtp settings
        if True:

            obj  = Reporter.objects.first()
            obj.smtp_use_auth = data['smtp_user']['authentication_required']
            obj.smtp_username = data['smtp_user']['username']
            obj.smtp_password = data['smtp_user']['password']
            obj.smtp_server   = data['smtp_user']['smtp_server']
            obj.smtp_port     = data['smtp_user']['port']
            obj.save()

        # upgrade jobs
        if True:

            for job in data['jobs']:

                obj, created = Job.objects.get_or_create(name=job['name'])

                obj.email         = job['email']
                obj.comments      = job['comments']
                obj.template_type = job['template']
                obj.enabled       = True
                obj.include_current   = job['params']['include_current']
                obj.limit_n_drilldown = job['params']['limit_n_drilldown']
                obj.limit_n_entries   = job['params']['limit_n_entries']

                obj.timeframe_from  = job['params']['timeframe_from']
                obj.timeframe_to    = job['params']['timeframe_to']
                obj.timeframe_type  = job['params']['timeframe_type']
                obj.timeframe_value = job['params']['timeframe_value']

                obj.schedule_min   = job['schedule']['min']
                obj.schedule_hour  = job['schedule']['hour']
                obj.schedule_dom   = job['schedule']['dom']
                obj.schedule_month = job['schedule']['month']
                obj.schedule_dow   = job['schedule']['dow']

                # items separated by comma
                obj.include_domains    = ",".join(job['limits']['include_domains'])
                obj.include_users      = ",".join(job['limits']['include_users'])
                obj.include_policies   = ",".join(job['limits']['include_policies'])
                obj.include_categories = ",".join(job['limits']['include_categories'])
                obj.exclude_domains    = ",".join(job['limits']['exclude_domains'])
                obj.exclude_users      = ",".join(job['limits']['exclude_users'])
                obj.exclude_policies   = ",".join(job['limits']['exclude_policies'])
                obj.exclude_categories = ",".join(job['limits']['exclude_categories'])

                obj.save()
Esempio n. 16
0
    def upgrade_impl(self, folder):

        # adblock
        path = os.path.join(folder, "block_ads.json")
        if os.path.exists(path):

            data = read_json_object(path)
            obj = self.policy.ruleannoyances

            obj.block_ads = data.get('block_ads', False)
            obj.save()

        # privacy
        path = os.path.join(folder, "protect_privacy.json")
        if os.path.exists(path):

            data = read_json_object(path)
            obj = self.policy.ruleannoyances

            obj.protect_privacy = data.get('protect_privacy', False)
            obj.save()

        # new annoyances file
        path = os.path.join(folder, "block_annoyances.json")
        if os.path.exists(path):

            data = read_json_object(path)
            obj = self.policy.ruleannoyances

            obj.block_ads = data.get('block_ads', False)
            obj.protect_privacy = data.get('protect_privacy', False)
            obj.save()

            obj = self.policy.ruleapps
            obj.hide_yt_comments = data.get('hide_yt_comments', False)
            obj.hide_yt_suggestions = data.get('hide_yt_suggestions', False)
            obj.hide_yt_other = data.get('hide_yt_other', False)
            obj.save()

        # safe search may be in two places
        enable_safe_search = True

        # adult
        data = read_json_object(os.path.join(folder, "block_adult.json"))
        obj = self.policy.ruleadult

        if 'enable_safe_search' in data:
            enable_safe_search = data['enable_safe_search']

        obj.enable_phrases = data['fulltext_detection_enable']
        obj.phrases_maximum_weight = data['fulltext_detection_maximum_weight']
        obj.phrases_maximum_size = data['fulltext_detection_maximum_size']
        obj.fulltext_parse_links = data.get('fulltext_parse_links', False)
        obj.fulltext_scan_css = data.get('fulltext_scan_css', False)
        obj.fulltext_scan_javascript = data.get('fulltext_scan_javascript',
                                                False)
        obj.fulltext_scan_links = data.get('fulltext_scan_links', False)
        obj.enable_image_filtering = data.get('enable_image_filtering', False)
        obj.heuristics_maximum_weight = data.get('heuristics_maximum_weight',
                                                 40)
        obj.trust_allowed_categories = data.get('trust_allowed_categories',
                                                True)
        obj.enable_heuristics = data['enable_heuristics']
        obj.save()

        # upgrade apps apps
        obj = self.policy.ruleapps
        path = os.path.join(folder, "apps.json")
        if os.path.exists(path):
            data = read_json_object(path)

            if 'enable_safe_search' in data:
                enable_safe_search = data['enable_safe_search']

            obj.enable_google_apps = data.get('enable_google_apps', False)
            obj.hide_yt_comments = data.get('hide_yt_comments', False)
            obj.hide_yt_suggestions = data.get('hide_yt_suggestions', False)
            obj.hide_yt_other = data.get('hide_yt_other', False)
            obj.enable_safe_search = enable_safe_search

        obj.save()

        # normal items are simple
        for name, set in {
                'block_urls.json': self.policy.ruleurl_set,
                'block_file_name.json': self.policy.rulefilename_set,
                'block_file_content.json': self.policy.rulefilecontent_set,
                'block_domains.json': self.policy.ruledomain_set,
                'block_content_type.json': self.policy.rulecontenttype_set,
                'block_charset.json': self.policy.rulecharset_set,
                'block_useragents.json': self.policy.ruleuseragent_set,
        }.iteritems():

            # only import if file exists
            path = os.path.join(folder, name)
            if not os.path.exists(path):
                continue

            items = read_json_array(path)
            for item in items:
                if isinstance(item, basestring):
                    value = item  # in < 4.7
                    comment = ""
                else:
                    value = item.get("value", "")
                    comment = item.get("comment", "")

                if len(value) > 0:
                    try:
                        v, c = set.get_or_create(value=value)
                        v.comment = comment
                        v.save()
                    except Exception as e:
                        #logging.warning("Ignoring import of %s, error '%s' ..." % (value, str(e)))
                        pass

        # categories are a bit different
        if True:

            data = read_json_object(
                os.path.join(folder, 'block_categories.json'))
            rule = self.policy.rulecategory

            if 'block_noncategorized_domains' in data:
                rule.block_noncategorized_domains = data[
                    'block_noncategorized_domains']

            items = None
            if 'blocked_categories' in data:
                items = data['blocked_categories']
            else:
                items = data

            for item in items:
                setattr(rule, "block_%s" % name, True)

            rule.save()

        # dynamic categories are different too
        if True:

            data = read_json_object(
                os.path.join(folder, 'dynamic_categorization.json'))

            rule = self.policy.ruledynamiccategory
            rule.enabled = data.get('enabled', True)
            rule.analyze_request = data.get('analyze_request', True)
            rule.analyze_response = data.get('analyze_response', True)
            rule.classify_type = data.get(
                'classify_type',
                RuleDynamicCategory.CLASSIFY_UNKNOWN_AND_UNTRUSTED)

            if 'classifiers' in data:
                items = data['classifiers']
                for item in items:
                    setattr(rule, "classify_%s" % name, True)

            rule.save()

        # custom categories are even more different
        for name, obj in {
                'block_categories_custom.json':
                self.policy.rulecategorycustom_set
        }.iteritems():
            for item in read_json_array(os.path.join(folder, name)):
                (category,
                 created) = CustomCategory.objects.get_or_create(name=item)
                obj.get_or_create(category=category.name, enable=True)

        # block file size
        obj = self.policy.rulefilesize
        path = os.path.join(folder, "block_file_size.json")
        if os.path.exists(path):
            data = read_json_object(path)
            obj.enable = data.get('enable', False)
            obj.max_size = data.get('max_size', 1048576)

        obj.save()
Esempio n. 17
0
    def upgrade_monitor(self, etc_dir):

        # first try newer path
        path = os.path.join(etc_dir, "traffic", "monitor.json")
        if not os.path.exists(path):
            path = os.path.join(etc_dir, "monitor.json")

        # get json and upgrade
        data = read_json_object(path)
        obj  = Monitoring.objects.first()

        if 'database' in data:

            src                                            = data['database']
            obj.persistent_enable                          = src['enable']
            obj.persistent_purge                           = src['purge']
            obj.persistent_store_clean                     = src['store_clean']
            obj.persistent_store_adblock                   = src['store_adblock']
            obj.persistent_store_privacy                   = src['store_privacy']
            obj.persistent_store_adult_heuristics          = src['store_adult_heuristics']
            obj.persistent_store_adult_safesearch          = src['store_adult_safesearch']
            obj.persistent_store_adult_youtube             = src['store_adult_youtube']
            obj.persistent_store_adult_phrases             = src['store_adult_phrases']
            obj.persistent_store_adult_image               = src['store_adult_image']

            # some custom logic for categories
            if True:

                # set default value to true
                obj.persistent_store_categories = True

                # see if we need to reset it to false
                cat1 = src.get('store_categories', False)
                cat2 = src.get('store_categories_dynamic', False)
                cat3 = src.get('store_custom', False)

                if not (cat1 or cat2 or cat3):
                    obj.persistent_store_categories = False

            obj.persistent_store_http_sanitation           = src['store_http_sanitation']
            obj.persistent_store_content_content_type      = src['store_content_content_type']
            obj.persistent_store_content_charset           = src['store_content_charset']
            obj.persistent_store_content_transfer_encoding = src['store_content_transfer_encoding']
            obj.persistent_store_content_file_name         = src['store_content_file_name']
            obj.persistent_store_content_file_type         = src['store_content_file_type']
            obj.persistent_store_content_file_size         = src['store_content_file_size']
            obj.persistent_store_apps                      = src['store_apps']
            obj.persistent_store_sslbump                   = src['store_sslbump']
            
        if 'logfile' in data:

            src                                            = data['logfile']
            obj.accesslog_enable                           = src['enable']
            obj.accesslog_store_clean                      = src['store_clean']
            obj.accesslog_store_adblock                    = src['store_adblock']
            obj.accesslog_store_privacy                    = src['store_privacy']
            obj.accesslog_store_adult_heuristics           = src['store_adult_heuristics']
            obj.accesslog_store_adult_safesearch           = src['store_adult_safesearch']
            obj.accesslog_store_adult_youtube              = src['store_adult_youtube']
            obj.accesslog_store_adult_phrases              = src['store_adult_phrases']
            obj.accesslog_store_adult_image                = src['store_adult_image']

            # some custom logic for categories
            if True:

                # set default value to true
                obj.accesslog_store_categories = True

                # see if we need to reset it to false
                cat1 = src.get('store_categories', False)
                cat2 = src.get('store_categories_dynamic', False)
                cat3 = src.get('store_custom', False)

                if not (cat1 or cat2 or cat3):
                    obj.accesslog_store_categories = False

            obj.accesslog_store_http_sanitation            = src['store_http_sanitation']
            obj.accesslog_store_content_content_type       = src['store_content_content_type']
            obj.accesslog_store_content_charset            = src['store_content_charset']
            obj.accesslog_store_content_transfer_encoding  = src['store_content_transfer_encoding']
            obj.accesslog_store_content_file_name          = src['store_content_file_name']
            obj.accesslog_store_content_file_type          = src['store_content_file_type']
            obj.accesslog_store_content_file_size          = src['store_content_file_size']
            obj.accesslog_store_apps                       = src['store_apps']
            obj.accesslog_store_sslbump                    = src['store_sslbump']

        if 'memory' in data:

            src                                            = data['memory']
            obj.realtime_enable                            = src['enable']
            obj.realtime_store_clean                       = src['store_clean']
            obj.realtime_store_adblock                     = src['store_adblock']
            obj.realtime_store_privacy                     = src['store_privacy']
            obj.realtime_store_adult_heuristics            = src['store_adult_heuristics']
            obj.realtime_store_adult_safesearch            = src['store_adult_safesearch']
            obj.realtime_store_adult_youtube               = src['store_adult_youtube']
            obj.realtime_store_adult_phrases               = src['store_adult_phrases']
            obj.realtime_store_adult_image                 = src['store_adult_image']

            # some custom logic for categories
            if True:

                # set default value to true
                obj.realtime_store_categories = True

                # see if we need to reset it to false
                cat1 = src.get('store_categories', False)
                cat2 = src.get('store_categories_dynamic', False)
                cat3 = src.get('store_custom', False)

                if not (cat1 or cat2 or cat3):
                    obj.realtime_store_categories = False

            obj.realtime_store_http_sanitation             = src['store_http_sanitation']
            obj.realtime_store_content_content_type        = src['store_content_content_type']
            obj.realtime_store_content_charset             = src['store_content_charset']
            obj.realtime_store_content_transfer_encoding   = src['store_content_transfer_encoding']
            obj.realtime_store_content_file_name           = src['store_content_file_name']
            obj.realtime_store_content_file_type           = src['store_content_file_type']
            obj.realtime_store_content_file_size           = src['store_content_file_size']
            obj.realtime_store_apps                        = src['store_apps']
            obj.realtime_store_sslbump                     = src['store_sslbump']

        if 'syslog' in data:

            src                                            = data['syslog']
            obj.syslog_enable                              = src['enable']
            obj.syslog_store_clean                         = src['store_clean']
            obj.syslog_store_adblock                       = src['store_adblock']
            obj.syslog_store_privacy                       = src['store_privacy']
            obj.syslog_store_adult_heuristics              = src['store_adult_heuristics']
            obj.syslog_store_adult_safesearch              = src['store_adult_safesearch']
            obj.syslog_store_adult_youtube                 = src['store_adult_youtube']
            obj.syslog_store_adult_phrases                 = src['store_adult_phrases']
            obj.syslog_store_adult_image                   = src['store_adult_image']

            # some custom logic for categories
            if True:

                # set default value to true
                obj.syslog_store_categories = True

                # see if we need to reset it to false
                cat1 = src.get('store_categories', False)
                cat2 = src.get('store_categories_dynamic', False)
                cat3 = src.get('store_custom', False)

                if not (cat1 or cat2 or cat3):
                    obj.syslog_store_categories = False

            obj.syslog_store_http_sanitation               = src['store_http_sanitation']
            obj.syslog_store_content_content_type          = src['store_content_content_type']
            obj.syslog_store_content_charset               = src['store_content_charset']
            obj.syslog_store_content_transfer_encoding     = src['store_content_transfer_encoding']
            obj.syslog_store_content_file_name             = src['store_content_file_name']
            obj.syslog_store_content_file_type             = src['store_content_file_type']
            obj.syslog_store_content_file_size             = src['store_content_file_size']
            obj.syslog_store_apps                          = src['store_apps']
            obj.syslog_store_sslbump                       = src['store_sslbump']
            obj.syslog_store_path                          = src.get('store_path', False)
            obj.syslog_store_query                         = src.get('store_query', False)

        obj.update_interval         = data.get('update_interval', 5)
        obj.history_normalize_names = data.get('history_normalize_names', True)
        obj.history_anonymize_names = data.get('history_anonymize_names', False)

        if 'persistent' in data:

            src                                            = data['persistent']
            obj.persistent_enable                          = src['enable']
            obj.persistent_purge                           = src['purge']
            obj.persistent_store_clean                     = src['store_clean']
            obj.persistent_store_adblock                   = src['store_adblock']
            obj.persistent_store_privacy                   = src['store_privacy']
            obj.persistent_store_adult_heuristics          = src['store_adult_heuristics']
            obj.persistent_store_adult_safesearch          = src['store_adult_safesearch']
            obj.persistent_store_adult_youtube             = src['store_adult_youtube']
            obj.persistent_store_adult_phrases             = src['store_adult_phrases']
            obj.persistent_store_adult_image               = src['store_adult_image']

            # some custom logic for categories
            if True:

                # set default value to true
                obj.persistent_store_categories = True

                # see if we need to reset it to false
                cat1 = src.get('store_categories', False)
                cat2 = src.get('store_categories_dynamic', False)
                cat3 = src.get('store_custom', False)

                if not (cat1 or cat2 or cat3):
                    obj.persistent_store_categories = False

            obj.persistent_store_http_sanitation           = src['store_http_sanitation']
            obj.persistent_store_content_content_type      = src['store_content_content_type']
            obj.persistent_store_content_charset           = src['store_content_charset']
            obj.persistent_store_content_transfer_encoding = src['store_content_transfer_encoding']
            obj.persistent_store_content_file_name         = src['store_content_file_name']
            obj.persistent_store_content_file_type         = src['store_content_file_type']
            obj.persistent_store_content_file_size         = src['store_content_file_size']
            obj.persistent_store_apps                      = src['store_apps']
            obj.persistent_store_sslbump                   = src['store_sslbump']
            obj.persistent_store_path                      = src.get('store_path', False)
            obj.persistent_store_query                     = src.get('store_query', False)

        if 'accesslog' in data:

            src                                            = data['accesslog']
            obj.accesslog_enable                           = src['enable']
            obj.accesslog_store_clean                      = src['store_clean']
            obj.accesslog_store_adblock                    = src['store_adblock']
            obj.accesslog_store_privacy                    = src['store_privacy']
            obj.accesslog_store_adult_heuristics           = src['store_adult_heuristics']
            obj.accesslog_store_adult_safesearch           = src['store_adult_safesearch']
            obj.accesslog_store_adult_youtube              = src['store_adult_youtube']
            obj.accesslog_store_adult_phrases              = src['store_adult_phrases']
            obj.accesslog_store_adult_image                = src['store_adult_image']

            # some custom logic for categories
            if True:

                # set default value to true
                obj.accesslog_store_categories = True

                # see if we need to reset it to false
                cat1 = src.get('store_categories', False)
                cat2 = src.get('store_categories_dynamic', False)
                cat3 = src.get('store_custom', False)

                if not (cat1 or cat2 or cat3):
                    obj.accesslog_store_categories = False

            obj.accesslog_store_http_sanitation            = src['store_http_sanitation']
            obj.accesslog_store_content_content_type       = src['store_content_content_type']
            obj.accesslog_store_content_charset            = src['store_content_charset']
            obj.accesslog_store_content_transfer_encoding  = src['store_content_transfer_encoding']
            obj.accesslog_store_content_file_name          = src['store_content_file_name']
            obj.accesslog_store_content_file_type          = src['store_content_file_type']
            obj.accesslog_store_content_file_size          = src['store_content_file_size']
            obj.accesslog_store_apps                       = src['store_apps']
            obj.accesslog_store_sslbump                    = src['store_sslbump']
            obj.accesslog_store_path                       = src.get('store_path', False)
            obj.accesslog_store_query                      = src.get('store_query', False)

        if 'realtime' in data:

            src                                            = data['realtime']
            obj.realtime_enable                            = src['enable']
            obj.realtime_store_clean                       = src['store_clean']
            obj.realtime_store_adblock                     = src['store_adblock']
            obj.realtime_store_privacy                     = src['store_privacy']
            obj.realtime_store_adult_heuristics            = src['store_adult_heuristics']
            obj.realtime_store_adult_safesearch            = src['store_adult_safesearch']
            obj.realtime_store_adult_youtube               = src['store_adult_youtube']
            obj.realtime_store_adult_phrases               = src['store_adult_phrases']
            obj.realtime_store_adult_image                 = src['store_adult_image']

            # some custom logic for categories
            if True:

                # set default value to true
                obj.realtime_store_categories = True

                # see if we need to reset it to false
                cat1 = src.get('store_categories', False)
                cat2 = src.get('store_categories_dynamic', False)
                cat3 = src.get('store_custom', False)

                if not (cat1 or cat2 or cat3):
                    obj.realtime_store_categories = False
                    
            obj.realtime_store_http_sanitation             = src['store_http_sanitation']
            obj.realtime_store_content_content_type        = src['store_content_content_type']
            obj.realtime_store_content_charset             = src['store_content_charset']
            obj.realtime_store_content_transfer_encoding   = src['store_content_transfer_encoding']
            obj.realtime_store_content_file_name           = src['store_content_file_name']
            obj.realtime_store_content_file_type           = src['store_content_file_type']
            obj.realtime_store_content_file_size           = src['store_content_file_size']
            obj.realtime_store_apps                        = src['store_apps']
            obj.realtime_store_sslbump                     = src['store_sslbump']
            obj.realtime_store_path                        = src.get('store_path', True)
            obj.realtime_store_query                       = src.get('store_query', True)
            obj.realtime_limit_record_count                = src.get('limit_record_count', 10000)

        obj.save()