-
Notifications
You must be signed in to change notification settings - Fork 0
/
editconf.cgi
executable file
·234 lines (182 loc) · 9.08 KB
/
editconf.cgi
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
#!/usr/bin/perl
# editconf.cgi
# by declaring all the globals we'll reference (including some in our own
# libraries)_before_ pulling in libraries and adding the 'use ...' _after_
# pulling in libraries, we can 'use strict' for our own code without
# generating any messages about the less-than-clean code in the very old
# Webmin libraries themselves
our (%text, %access, %config, %in, $module_name, $modulever, $moduleinfo);
our ($debug, $dg_version, $current_lang, $module_config_directory);
use POSIX;
require './dansguardian-lib.pl';
use warnings;
use strict qw(subs vars);
&passthroughautoreturn();
our %access = &get_module_acl();
our $return = &getcleanreturn();
our $pagename = "$text{'index_viewedit'} $text{'index_editconf'}";
our $conffilepath = &group2conffilepath(0);
our $readonly = ! &accessfile($conffilepath);
&webminheader();
# Make sure user has access to this file
&checkmodauth('editconf');
# Check if the right version
if (!(&checkdgver())) {
print "<span style='color: brown'>$text{'error_version_notsupp'}<br>$text{'index_modulever'} $modulever $text{'index_moduleversupports'}<br>$text{'index_dgversion'} $dg_version<p>\n";
}
# Check if DansGuardian conf file is there
if (! &checkdgconf) {
print "<span style='color: brown'>$text{'error_confnotfound'}<br>($text{'index_location'}: " . &group2conffilepath(0) . ")</span><p>\n";
}
# Load dynamic settings scripts
&loadeditjslib();
# list of tabs
our @tabs = qw( network process logging reporting content phrase updownload plugins );
push @tabs, '', 'allgroups' if &sharedoptionsavailable();
# lists of which options go on which tabs
# every option is listed exactly once
our @networktaboptions = qw( filterip filterport proxyip proxyport forwardedfor usexforwardedfor maxips );
our @processtaboptions = qw( maxchildren minchildren minsparechildren preforkchildren maxsparechildren maxagechildren ipcfilename urlipcfilename ipipcfilename pidfilename nodaemon daemonuser daemongroup softrestart createlistcachefiles languagedir language );
our @loggingtaboptions = qw( nologger logsyslog loglocation statlocation anonymizelogs maxlogitemlength logexceptionhits showweightedfound logconnectionhandlingerrors loglevel logfileformat logchildprocesshandling logclienthostnames logadblocks loguseragent logtimestamp );
our @reportingtaboptions = qw( reportinglevel htmltemplate accessdeniedaddress nonstandarddelimiter );
our @contenttaboptions = qw( filtergroups usecustombannedimage custombannedimagefile reverseclientiplookups maxcontentramcachescansize maxcontentfilecachescansize filecachedir contentscannertimeout contentscanexceptions reverseaddresslookups recheckreplacedurls );
our @phrasetaboptions = qw( weightedphrasemode scancleancache urlcachenumber urlcacheage maxcontentfiltersize phrasefiltermode preservecase hexdecodecontent forcequicksearch );
our @updownloadtaboptions = qw( maxuploadsize deletedownloadedtempfiles initialtrickledelay trickledelay );
our @pluginstaboptions = qw( authplugin downloadmanager contentscanner );
# this list of options is "special" - it may or may NOT be a tab
our @allgroupstaboptions = qw( groupmode blockdownloads naughtynesslimit categorydisplaythreshold embeddedurlweight enablepics bypass bypasskey infectionbypass infectionbypasskey infectionbypasserrorsonly disablecontentscan deepurlanalysis );
# complete the definitions of each tab
# each tab is specified by an array [0->handle, 1->tablegend,
# 2->destination (must be present, but not actually used), 3->displaytitle, 4->ref-to-array-of-options ]
# the first three (0, 1, 2) are used by Webmin, (3) is used by our subroutine, and (4) is only for here
@tabs = map { [ $_, $text{"edit_tab_$_"}, "saveconf.cgi", "$text{\"edit_tab_$_\"} $text{'edit_heading_options'}", \@{"${_}taboptions"} ] } @tabs;
################### find-tab-with-option section ################
# Init the hash that we'll use for our find-the-tab function
our %option2tab = ();
# first set up "allgroups" options
# if they're on a tab, the same thing will be written again
# if they're not on a tab, they won't be overwritten and will point at 'fg'
foreach my $option (@allgroupstaboptions) {
$option2tab{$option} = 'fg';
}
# now spin through everything that will appear on any displayed tab
foreach my $tabref (@tabs) {
next if ! defined $tabref;
next if ! $$tabref[0];
next if ! $$tabref[4];
next if scalar @{$$tabref[4]} <= 0;
foreach my $option (@{$$tabref[4]}) {
$option2tab{$option} = $$tabref[0];
}
}
# all the data is now fully prepared, so do the display
# (also set up the bit of javascript we need,
# it's separate because putting it inline involves too many quoting problems)
print <<"EOF";
<script type=text/javascript>
function findoption(name, value)
{
if (value == '') {
// just return, effectively igore the selection
} else if (value == 'fg') {
// a per-filter-group option, either on 'allgroups' tab if shared variables available, or not here at all
alert(name + " $text{'edit_fgoption'}");
} else {
// the normal situation
select_tab('', value);
}
return false;
}
</script>
EOF
print "<div style='margin-left: 60px'><p>$text{'edit_whichtab'}<br>\n";
print "<img border=0 src=images/transparent1x1.gif height=1 width=40><select onChange=\"findoption(this.options[this.selectedIndex].text, this.options[this.selectedIndex].value);\">\n";
print "<option value=''> - select option -</option>\n";
foreach my $findoption (sort keys %option2tab) {
my $description = $text{"conf_$findoption"};
print "<option value='$option2tab{$findoption}'>$findoption ($description)</option>\n";
}
print "</select></div><p>\n";
## the tabs
# message at top
print "<p align=left>($text{'index_clickhelp'})</p>";
our $initialtab = $in{'initialtab'};
$initialtab = $tabs[0][0] if ! $initialtab;
## following line is the minimal that works, line below that is how it used to be
print &ui_tabs_start(\@tabs, undef, $initialtab);
## fill in content for each tab
foreach my $tabref (@tabs) {
next if ! defined $tabref;
next if ! $$tabref[0];
next if ! $$tabref[4];
next if scalar @{$$tabref[4]} <= 0;
print &ui_tabs_start_tab(undef, $$tabref[0]);
&edit_options_formtable_start($tabref);
&edit_options_headings_row(0, -1);
foreach my $option (@{$$tabref[4]}) {
&edit_options_data_row($option);
}
my $tabreturn = $return;
$tabreturn .= '%3F' if ($tabreturn !~ m/%3[fF]/);
$tabreturn .= '%26' if ($tabreturn !~ m/(?:%3[fF]|%26)$/);
$tabreturn .= "initialtab%3D$$tabref[0]";
print "<input type=hidden name='conffilepath' value='$conffilepath'>";
print "<input type=hidden name='configsection' value='$$tabref[0]'>";
print "<input type=hidden name='group' value='0'>";
print "<input type=hidden name='return' value='$tabreturn'>";
&edit_options_formtable_end($readonly);
print &ui_tabs_end_tab();
}
## End of tabs
print &ui_tabs_end(1);
################### reversion section #################
our (@availableversions, $availableversion, $listlength, $label, @buttons);
if (! $readonly) {
print "<hr><p><hr>\n";
print "<p>$text{'editfile_whatrevert'}\n";
@availableversions = <$conffilepath.20*>;
$listlength = ($#availableversions > 20) ? 20 : ($#availableversions + 1);
if ($listlength > 0) {
print &ui_form_start('revertfile.cgi', 'post');
print "<input type=hidden name='return' value='$return'>";
print "<p>$text{'editfile_selectreversion'}<br><select name=revertfilepath>\n";
print "<option value=''>--revert to ? (YYYYMMDDhhmmss)--</option>\n";
foreach $availableversion (@availableversions) {
($label) = ($availableversion =~ m{/([^/]*)$});
print "<option value='$availableversion'>$label</option>\n";
}
print "</select><br><br>\n";
@buttons = ( [ 'button', $text{'button_revert'} ], [ 'button', $text{'button_cancel'} ] );
print &ui_form_end(\@buttons);
} else {
print "<p align=center>* $text{'editfile_noversionsavailable'} *\n";
}
}
################### manual edit section #################
print "<hr><p><hr>\n";
print "<p>$text{'editfile_whatmanual'}\n";
print &ui_form_start('editfile.cgi', 'get');
print "<input type=hidden name=file value='$conffilepath'><input type=hidden name=return value='$return'>\n";
@buttons = ( [ 'button', $text{'button_edit'} ], [ 'button', $text{'button_cancel'} ] );
print &ui_form_end(\@buttons);
print "<hr>\n";
################### end #################
&webminfooterandexit();
###########################################################################
#
# UTILITY SUBROUTINES
#
###########################################################################
################
sub webminheader
################
{
&ui_print_header($pagename, $text{'index_title'}, undef, 'editconf', 1, 0, 0, &restart_button.'<br>'.&help_search_link("dansguardian", "man"), undef, undef, "$text{'index_version'} $dg_version <small>($text{'index_modulever'} $modulever)</small>");
}
#######################
sub webminfooterandexit
#######################
{
&ui_print_footer('index.cgi', $text{'index_return'});
exit;
}