forked from Netatalk/netatalk-webmin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.cgi
executable file
·191 lines (176 loc) · 7.74 KB
/
index.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
#!/usr/bin/perl
#
# Netatalk Webmin Module
# Copyright (C) 2013 Ralph Boehme <[email protected]>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
#
# Redistributions of source code must retain the above copyright notice, this list
# of conditions and the following disclaimer.
# Redistributions in binary form must reproduce the above copyright notice, this list
# of conditions and the following disclaimer in the documentation and/or other
# materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOTOC LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
# IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
require './netatalk3-lib.pl';
&header($text{'index_title'}, "", undef, 1, 1, undef, "<a href=\"help/configs.cgi\">$text{help_configs}</a>");
# check if netatalk daemon's path is configured correctly, if not: print error and footer then exit
if(!-x $config{'netatalk_d'}) {
print &text('index_ever',"<tt>$config{'netatalk_d'}</tt>", "/config.cgi?$module_name");
print "<p>\n<hr>\n";
&footer("/", $text{'index'});
exit;
}
print "<hr>\n";
# since we are using a different number of forms, depending on the status of the service,
# we are keeping a running index while outputting the forms
my $current_formindex = 0;
# Process control Buttons
if(&find_byname($config{'netatalk_d'})) {
print "<h3>$text{'index_running_services'}</h3>\n";
print &ui_buttons_start();
print &ui_buttons_row('restart.cgi', $text{'index_process_control_restart'}, &text('index_process_control_restart_txt', $config{restart_netatalk}));
print &ui_buttons_row('stop.cgi', $text{'index_process_control_stop'}, &text('index_process_control_stop_txt', $config{stop_netatalk}));
print &ui_buttons_end();
$current_formindex += 2;
} else {
print "<h3>$text{'index_not_running_services'}</h3>\n";
print &ui_buttons_start();
print &ui_buttons_row('start.cgi', $text{'index_process_control_start'}, &text('index_process_control_start_txt', $config{start_netatalk}));
print &ui_buttons_end();
$current_formindex += 1;
}
print &ui_hr();
# now try to read and interpret afp.conf - if this doesn't work, print error and footer then exit
my $afpconf;
eval {
$afpconf = &read_afpconf();
};
if($@) {
print $@;
exit;
}
# Volumes
print "<p>\n";
print "<h3>$text{index_volumes}</h3>\n";
print "<p>\n";
my @volume_links = ( "<a href=\"edit_vol_section.cgi?action=new_volume\">$text{'index_create_volume_link_name'}</a>" );
if(@{$$afpconf{volumeSections}}) {
unshift @volume_links, (
&select_all_link('section_index', $current_formindex),
&select_invert_link('section_index', $current_formindex)
) if(@{$$afpconf{volumeSections}} > 1);
print &ui_links_row(\@volume_links);
print &ui_form_start('delete_sections.cgi', 'post', undef, "id='volumes'");
print &ui_columns_start( [
'',
$text{'index_col_title_vol_name'},
$text{'index_col_title_path'},
$text{'index_col_title_uses_preset'}
], undef, 0, undef, undef
);
foreach $volumeSection (@{$$afpconf{volumeSections}}) {
print &ui_checked_columns_row( [
"<a href=\"edit_vol_section.cgi?action=edit_volume&index=$$volumeSection{'index'}\"><b>$$volumeSection{name}</b></a>",
$$volumeSection{parameters}{'path'}{value},
$$volumeSection{parameters}{'vol preset'}{value}
], [ "width='20'" ], 'section_index', $$volumeSection{'index'});
}
print &ui_columns_end();
print &ui_form_end([[undef, $text{'index_delete_volumes_button_title'}, 0, undef]]);
print &ui_links_row(\@volume_links);
$current_formindex += 1;
} else {
print "<b>$text{'index_no_volumes'}</b>\n";
print "<p>\n";
print &ui_links_row(\@volume_links);
}
print &ui_hr();
# Volume presets
print "<p>\n";
print "<h3>$text{index_volume_presets}</h3>\n";
print "<p>\n";
my @volume_preset_links = ( "<a href=\"edit_vol_section.cgi?action=new_volume_preset\">$text{'index_create_volume_preset_link_name'}</a>" );
if(@{$$afpconf{volumePresetSections}}) {
# for an explanation of the following links, see above
unshift @volume_preset_links, (
&select_all_link('section_index', $current_formindex),
&select_invert_link('section_index', $current_formindex)
) if(@{$$afpconf{volumePresetSections}} > 1);
print &ui_links_row(\@volume_preset_links);
print &ui_form_start('delete_sections.cgi', 'post', undef, "id='volume_presets'");
print &ui_columns_start( [
'',
$text{'index_col_title_preset_name'},
$text{'index_col_title_used_by'}
], undef, 0, undef, undef
);
foreach $volumeSection (@{$$afpconf{volumePresetSections}}) {
print &ui_checked_columns_row( [
"<a href=\"edit_vol_section.cgi?action=edit_volume_preset&index=$$volumeSection{'index'}\"><b>$$volumeSection{name}</b></a>",
defined $$volumeSection{presetUsedBySectionNames} ? join("<br>", @{$$volumeSection{presetUsedBySectionNames}}) : ""
], [ "width='20'" ], 'section_index', $$volumeSection{'index'});
}
print &ui_columns_end();
print &ui_form_end([[undef, $text{'index_delete_volume_presets_button_title'}, 0, undef]]);
print &ui_links_row(\@volume_preset_links);
$current_formindex += 1;
} else {
print "<b>$text{'index_no_volume_presets'}</b>\n";
print "<p>\n";
print &ui_links_row(\@volume_preset_links);
}
print &ui_hr();
# Homes
print "<p>\n";
print "<h3>$text{index_homes}</h3>\n";
print "<p>\n";
if($$afpconf{sectionsByName}{'Homes'}) {
print &ui_form_start('delete_sections.cgi', 'post', undef, "id='homes'");
print &ui_columns_start( [
$text{'index_col_title_basedir_regex'},
$text{'index_col_title_home_path'},
$text{'index_col_title_home_name'},
$text{'index_col_title_uses_preset'}
] );
my $volumeSection = $$afpconf{sectionsByName}{'Homes'};
my @basedir_regex = get_parameter_of_section($afpconf, $volumeSection, 'basedir regex');
my @path = get_parameter_of_section($afpconf, $volumeSection, 'path');
my @home_name = get_parameter_of_section($afpconf, $volumeSection, 'home name');
print &ui_columns_row( [
"<input type='hidden' name='section_index' value='$$volumeSection{'index'}'>".
"<a href=\"edit_vol_section.cgi?action=edit_homes&index=$$volumeSection{'index'}\"><b>".($basedir_regex[0] ne '' ? html_escape($basedir_regex[0]) : $text{'index_value_not_set'})."</b></a>",
$path[0] ne '' ? html_escape($path[0]) : $text{'index_value_not_set'},
$home_name[0] ne '' ? html_escape($home_name[0]) : $text{'index_value_not_set'},
html_escape((get_parameter_of_section($afpconf, $volumeSection, 'vol preset'))[0])
] );
print &ui_columns_end();
print &ui_form_end([[undef, $text{'index_delete_homes_button_title'}, 0, undef]]);
} else {
print "<b>$text{'index_no_homes'}</b>\n";
print "<p>\n";
print &ui_links_row( ["<a href=\"edit_vol_section.cgi?action=new_homes\">$text{'index_create_homes_link_name'}</a>"] );
}
print &ui_hr();
print"<p>\n";
print"<h3>$text{index_global}</h3>\n";
print"<p>\n";
my @links = ("edit_global_section.cgi", "show_users.cgi");
my @titles = ($text{'index_icon_text_server'}, $text{'index_icon_text_users'});
my @icons = ("images/server.png", "images/users.png");
icons_table(\@links, \@titles, \@icons, 5);
print"<br>\n";
print"<hr>\n";
&footer("/right.cgi?open=system&auto=status&open=updates", $text{'index_root'});