Use group (minimal GUI) defaults similarly to the user template
[pyi2ncommon] / src / cnfline / configure_webfilter.py
1 # The software in this package is distributed under the GNU General
2 # Public License version 2 (with a special exception described below).
3 #
4 # A copy of GNU General Public License (GPL) is included in this distribution,
5 # in the file COPYING.GPL.
6 #
7 # As a special exception, if other files instantiate templates or use macros
8 # or inline functions from this file, or you compile this file and link it
9 # with other works to produce a work based on this file, this file
10 # does not by itself cause the resulting work to be covered
11 # by the GNU General Public License.
12 #
13 # However the source code for this file must still be made available
14 # in accordance with section (3) of the GNU General Public License.
15 #
16 # This exception does not invalidate any other reasons why a work based
17 # on this file might be covered by the GNU General Public License.
18 #
19 # Copyright (c) 2016-2018 Intra2net AG <info@intra2net.com>
20
21 """
22 .. note:: DEPRECATED! Please do not extend this or add new uses of this module,
23           use :py:mod:`pyi2ncommon.arnied_api` or :py:mod:`pyi2ncommon.cnfvar`
24           instead!
25 """
26
27 from .build_cnfvar import BuildCnfVar
28 """Class to configure the webfilter cnfvars on the fly"""
29
30
31 class ConfigureWebfilter(BuildCnfVar):
32     def __init__(self, enabled='1', line_no=1):
33         BuildCnfVar.__init__(self, 'PROXY_WEBFILTER_ENABLE',
34                              0, enabled, line_no)
35
36     def block_drugs(self, enabled='1'):
37         line_no = self.update_cnf('PROXY_WEBFILTER_BLOCK_DRUGS', 0, enabled)
38         self.mark_as_own_parent(line_no)
39         return self
40
41     def block_gambling(self, enabled='1'):
42         line_no = self.update_cnf('PROXY_WEBFILTER_BLOCK_GAMBLING', 0, enabled)
43         self.mark_as_own_parent(line_no)
44         return self
45
46     def block_pornography(self, enabled='1'):
47         line_no = self.update_cnf('PROXY_WEBFILTER_BLOCK_PORNOGRAPHY',
48                                   0, enabled)
49         self.mark_as_own_parent(line_no)
50         return self
51
52     def block_violence(self, enabled='1'):
53         line_no = self.update_cnf('PROXY_WEBFILTER_BLOCK_VIOLENCE', 0, enabled)
54         self.mark_as_own_parent(line_no)
55         return self
56
57     def block_warez(self, enabled='1'):
58         line_no = self.update_cnf('PROXY_WEBFILTER_BLOCK_WAREZ', 0, enabled)
59         self.mark_as_own_parent(line_no)
60         return self
61
62     def add_pass_site(self, url):
63         sites_parent = self.update_cnf('PROXY_WEBFILTER_PASS_SITES', 0, '')
64         self.mark_as_own_parent(sites_parent)
65
66         self.add_cnf('PROXY_WEBFILTER_PASS_SITES_URL', -1, url, sites_parent)
67         return self
68
69     def clear_pass_sites(self):
70         self.del_cnf('PROXY_WEBFILTER_PASS_SITES_URL')
71         self.del_cnf('PROXY_WEBFILTER_PASS_SITES')
72         return self