<commit_before>from django import forms
from django.utils.translation import ugettext as _

# current structure:
# - FirefoxTracking: builtin features, which send data to Mozilla,
#   google and other thirdparties
# - WebsiteTracking: Features, which are made for tracking (i.e. ping, beacons)
#   or may used for it (i.e. battery api)
# - Privacy: General privacy related settings like referer, cookies, etc.
#   which may be harmless or needed (i.e. cookies)
# - Security: No direct privacy problems, but maybe security issues
#   (i.e. webgl may hang Firefox)
# - Bloatware: Settings, which disable unwanted features like hello or pocket
# - Annoyances: Settings, which disable first-run
#   "did you know, here is our new tab page" popups.
#
# TODO: WebsiteTracking could be split into Tracking (ping, beacon, ...) and
#       Fingerprinting (battery, canvas, ...), when there are more settings.



class ConfigForm(forms.Form):
    def __init__(self, *args, **kwargs):
        super(ConfigForm, self).__init__(*args, **kwargs)
        self.fields['form_name'] = forms.CharField(initial=self.id, widget=forms.widgets.HiddenInput)
        for option in self.options:
            if option['type'] == "boolean":
                self.fields[option['name']] = forms.BooleanField(
                    label=option['label'],
                    help_text=option['help_text'],
                    initial=option['initial'], required=False)
            if option['type'] == "choice":
                choices = option['choices']
                self.fields[option['name']] = forms.ChoiceField(
                    label=option['label'],
                    help_text=option['help_text'],
                    choices = zip(range(len(choices)), choices),
                    initial=option['initial'], required=False)
            elif option['type'] == "text":
                self.fields[option['name']] = forms.CharField(
                    label=option['label'],
                    help_text=option['help_text'],
                    initial=option['initial'], required=False)

    def get_config_and_addons(self):
        config = {}
        addons = []
        if self.is_valid():
            for option in self.options:
                if option['type'] == "boolean":
                    if self.cleaned_data[option['name']]:
                        for key in option['config']:
                            config[key] = option['config'][key]
                        addons += option['addons']
                elif option['type'] == "choice":
                    choice = int(self.cleaned_data[option['name']])
                    for key in option['config'][choice]:
                        config[key] = option['config'][choice][key]
                    addons += option['addons'][choice]
                elif option['type'] == "text":
                    if option.get('blank_means_default', False) and self.cleaned_data[option['name']] == "":
                        continue
                    else:
                        config[option['setting']] = self.cleaned_data[option['name']]

        return config, addons

def create_configform(id, name, options):
    class DynamicConfigForm(ConfigForm):
        pass
    DynamicConfigForm.id=id
    DynamicConfigForm.name=name
    DynamicConfigForm.options=options
    return DynamicConfigForm

ITEMS = {
    'Firefox Tracking': [
        {
            'name': 'telemetry',
            'type': 'boolean',
            'label': _(u'Disable Telemetry'),
            'help_text': _(u'The <a href="https://support.mozilla.org/en-US/kb/share-telemetry-data-mozilla-help-improve-firefox">telemetry feature</a> '
                'sends data about the performance and responsiveness of Firefox to Mozilla.'),
            'initial': True,
            'config':
            {
                'toolkit.telemetry.enabled': False,
            },
            'addons': []
        },
        {
            'name': 'health_report',
            'type': 'boolean',
            'label': _(u'Disable health report'),
            'help_text': _(u'Disable sending <a href="https://www.mozilla.org/en-US/privacy/firefox/#health-report">Firefox health reports</a> to Mozilla'),
            'initial': True,
            'config':
            {
                'datareporting.healthreport.service.enabled': False,
                'datareporting.healthreport.uploadEnabled': False,
                # see https://bugzilla.mozilla.org/show_bug.cgi?id=1195552#c4
                'datareporting.policy.dataSubmissionEnabled': False,
            },
            'addons': []
        },
        {
            'name': 'addon_data',
            'type': 'boolean',
            'label': _(u'Opt out metadata updates'),
            'help_text': _(u'Firefox sends data about installed addons as <a href="https://blog.mozilla.org/addons/how-to-opt-out-of-add-on-metadata-updates/">metadata updates</a>, so Mozilla is able to recommend you other addons.'),
            'initial': True,
            'config':
            {
                'extensions.getAddons.cache.enabled': False,
            },
            'addons': []
        },
        {
            'name': 'phishing_protection',
            'type': 'boolean',
            'label': _(u'Disable phishing protection'),
            'help_text': _(u'The phishing protection contacts google with an unique key:'
            ' <a href="http://electroholiker.de/?p=1594">wrkey</a>.'),
            'initial': True,
            'config':
            {
                'browser.safebrowsing.enabled': False,
            },
            'addons': []
        },
        {
            'name': 'malware_scan',
            'type': 'boolean',
            'label': _(u'Disable malware scan'),
            'help_text': _(u'The malware scan sends an unique identifier for each downloaded file to Google.'),
            'initial': True,
            'config':
            {
                'browser.safebrowsing.malware.enabled': False,
                'browser.safebrowsing.appRepURL': '',
            },
            'addons': []
        },
        {
            'name': 'newtab_preload',
            'type': 'boolean',
            'label': _(u'Disable preloading of the new tab page.'),
            'help_text': _(u'By default Firefox preloads the new tab page (with website thumbnails) in the background before it is even opened.'),
            'initial': True,
            'config':
            {
                'browser.newtab.preload': False
            },
            'addons': []
        },
    ],
    'Website Tracking': [
        {
            'name': 'dnt',
            'type': 'boolean',
            'label': _(u'Enable Do-not-Track'),
            'help_text': _(u'With the do not track feature, you tell websites, that you do not want to be tracked. '
                'Most websites ignore this, so you need other privacy options as well.'),
            'initial': True,
            'config':
            {
                'privacy.donottrackheader.enabled': True,
                'privacy.donottrackheader.value': 1,
            },
            'addons': []
        },
        {
            'name': 'trackingprotection',
            'type': 'boolean',
            'label': _(u'Enable Mozilla Trackingprotection'),
            'help_text': _(u'Firefox has a builtin <a href="https://wiki.mozilla.org/Security/Tracking_protection">tracking protection</a>, which blocks a list of known tracking sites.'),
            'initial': True,
            'config':
            {
                'privacy.trackingprotection.enabled': True,
                'privacy.trackingprotection.pbmode.enabled': True,
            },
            'addons': []
        },
        {
            'name': 'ping',
            'type': 'boolean',
            'label': _(u'Disable Browser Pings'),
            'help_text': _(u'Firefox sends <a href="http://kb.mozillazine.org/Browser.send_pings">"ping" requests</a>, '
                'when a website requests to be informed when a user clicks on a link.'),
            'initial': True,
            'config':
            {
                'browser.send_pings': False,
            },<commit_msg>Added privacy.resistFingerprinting setting, closes #56<commit_after>from django import forms
from django.utils.translation import ugettext as _

# current structure:
# - FirefoxTracking: builtin features, which send data to Mozilla,
#   google and other thirdparties
# - WebsiteTracking: Features, which are made for tracking (i.e. ping, beacons)
#   or may used for it (i.e. battery api)
# - Privacy: General privacy related settings like referer, cookies, etc.
#   which may be harmless or needed (i.e. cookies)
# - Security: No direct privacy problems, but maybe security issues
#   (i.e. webgl may hang Firefox)
# - Bloatware: Settings, which disable unwanted features like hello or pocket
# - Annoyances: Settings, which disable first-run
#   "did you know, here is our new tab page" popups.
#
# TODO: WebsiteTracking could be split into Tracking (ping, beacon, ...) and
#       Fingerprinting (battery, canvas, ...), when there are more settings.



class ConfigForm(forms.Form):
    def __init__(self, *args, **kwargs):
        super(ConfigForm, self).__init__(*args, **kwargs)
        self.fields['form_name'] = forms.CharField(initial=self.id, widget=forms.widgets.HiddenInput)
        for option in self.options:
            if option['type'] == "boolean":
                self.fields[option['name']] = forms.BooleanField(
                    label=option['label'],
                    help_text=option['help_text'],
                    initial=option['initial'], required=False)
            if option['type'] == "choice":
                choices = option['choices']
                self.fields[option['name']] = forms.ChoiceField(
                    label=option['label'],
                    help_text=option['help_text'],
                    choices = zip(range(len(choices)), choices),
                    initial=option['initial'], required=False)
            elif option['type'] == "text":
                self.fields[option['name']] = forms.CharField(
                    label=option['label'],
                    help_text=option['help_text'],
                    initial=option['initial'], required=False)

    def get_config_and_addons(self):
        config = {}
        addons = []
        if self.is_valid():
            for option in self.options:
                if option['type'] == "boolean":
                    if self.cleaned_data[option['name']]:
                        for key in option['config']:
                            config[key] = option['config'][key]
                        addons += option['addons']
                elif option['type'] == "choice":
                    choice = int(self.cleaned_data[option['name']])
                    for key in option['config'][choice]:
                        config[key] = option['config'][choice][key]
                    addons += option['addons'][choice]
                elif option['type'] == "text":
                    if option.get('blank_means_default', False) and self.cleaned_data[option['name']] == "":
                        continue
                    else:
                        config[option['setting']] = self.cleaned_data[option['name']]

        return config, addons

def create_configform(id, name, options):
    class DynamicConfigForm(ConfigForm):
        pass
    DynamicConfigForm.id=id
    DynamicConfigForm.name=name
    DynamicConfigForm.options=options
    return DynamicConfigForm

ITEMS = {
    'Firefox Tracking': [
        {
            'name': 'telemetry',
            'type': 'boolean',
            'label': _(u'Disable Telemetry'),
            'help_text': _(u'The <a href="https://support.mozilla.org/en-US/kb/share-telemetry-data-mozilla-help-improve-firefox">telemetry feature</a> '
                'sends data about the performance and responsiveness of Firefox to Mozilla.'),
            'initial': True,
            'config':
            {
                'toolkit.telemetry.enabled': False,
            },
            'addons': []
        },
        {
            'name': 'health_report',
            'type': 'boolean',
            'label': _(u'Disable health report'),
            'help_text': _(u'Disable sending <a href="https://www.mozilla.org/en-US/privacy/firefox/#health-report">Firefox health reports</a> to Mozilla'),
            'initial': True,
            'config':
            {
                'datareporting.healthreport.service.enabled': False,
                'datareporting.healthreport.uploadEnabled': False,
                # see https://bugzilla.mozilla.org/show_bug.cgi?id=1195552#c4
                'datareporting.policy.dataSubmissionEnabled': False,
            },
            'addons': []
        },
        {
            'name': 'addon_data',
            'type': 'boolean',
            'label': _(u'Opt out metadata updates'),
            'help_text': _(u'Firefox sends data about installed addons as <a href="https://blog.mozilla.org/addons/how-to-opt-out-of-add-on-metadata-updates/">metadata updates</a>, so Mozilla is able to recommend you other addons.'),
            'initial': True,
            'config':
            {
                'extensions.getAddons.cache.enabled': False,
            },
            'addons': []
        },
        {
            'name': 'phishing_protection',
            'type': 'boolean',
            'label': _(u'Disable phishing protection'),
            'help_text': _(u'The phishing protection contacts google with an unique key:'
            ' <a href="http://electroholiker.de/?p=1594">wrkey</a>.'),
            'initial': True,
            'config':
            {
                'browser.safebrowsing.enabled': False,
            },
            'addons': []
        },
        {
            'name': 'malware_scan',
            'type': 'boolean',
            'label': _(u'Disable malware scan'),
            'help_text': _(u'The malware scan sends an unique identifier for each downloaded file to Google.'),
            'initial': True,
            'config':
            {
                'browser.safebrowsing.malware.enabled': False,
                'browser.safebrowsing.appRepURL': '',
            },
            'addons': []
        },
        {
            'name': 'newtab_preload',
            'type': 'boolean',
            'label': _(u'Disable preloading of the new tab page.'),
            'help_text': _(u'By default Firefox preloads the new tab page (with website thumbnails) in the background before it is even opened.'),
            'initial': True,
            'config':
            {
                'browser.newtab.preload': False
            },
            'addons': []
        },
    ],
    'Website Tracking': [
        {
            'name': 'dnt',
            'type': 'boolean',
            'label': _(u'Enable Do-not-Track'),
            'help_text': _(u'With the do not track feature, you tell websites, that you do not want to be tracked. '
                'Most websites ignore this, so you need other privacy options as well.'),
            'initial': True,
            'config':
            {
                'privacy.donottrackheader.enabled': True,
                'privacy.donottrackheader.value': 1,
            },
            'addons': []
        },
        {
            'name': 'resist-fingerprinting',
            'type': 'boolean',
            'label': _(u'Enable resistFingerprinting'),
            'help_text': _(u'The <tt>privacy.resistFingerprinting</tt> setting coming from the tor-browser hides some system properties.'
                'See <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1308340">Bug #1308340</a> for more information.'),
            'initial': True,
            'config':
            {
                'privacy.resistFingerprinting': True,
            },
            'addons': []
        },
        {
            'name': 'trackingprotection',
            'type': 'boolean',
            'label': _(u'Enable Mozilla Trackingprotection'),
            'help_text': _(u'Firefox has a builtin <a href="https://wiki.mozilla.org/Security/Tracking_protection">tracking protection</a>, which blocks a list of known tracking sites.'),
            'initial': True,
            'config':
            {
                'privacy.trackingprotection.enabled': True,
                'privacy.trackingprotection.pbmode.enabled': True,
            },
            'addons': []
        },
        {
            'name': 'ping',
            'type': 'boolean',
            'label': _(u'Disable Browser Pings'),
            'help_text': _(u'Firefox sends <a href="http://kb.mozillazine.org/Browser.send_pings">"ping" requests</a>, '
                'when a website requests to be informed when a user clicks on a link.'),
            'initial': True,
            'config':
            {
                'browser.send_pings': False,
            },
{'fraction_non_alphanumeric': 0.13069890887643762, 'fraction_numerical': 0.0024771453848422293, 'mean_word_length': 1.7828655834564253, 'pattern_counts': {'":': 14, '<': 31, '<?xml version=': 0, '>': 31, 'https://': 11, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '689196', 'n_tokens_mistral': 4648, 'n_tokens_neox': 4409, 'n_words': 1090}