forked from webmin/authentic-theme
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.cgi
executable file
·364 lines (331 loc) · 11 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
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
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
#!/usr/bin/perl
#
# Authentic Theme 14.02 (https://github.com/qooob/authentic-theme)
# Copyright 2015 Ilia Rostovtsev <programming@rostovtsev.ru>
# Licensed under MIT (https://github.com/qooob/authentic-theme/blob/master/LICENSE)
#
BEGIN { push( @INC, ".." ); }
use WebminCore;
&ReadParse();
&init_config();
# Detecting Virtualmin/Cloudmin request
our $is_virtualmin = index( $ENV{'REQUEST_URI'}, 'virtualmin' );
our $is_cloudmin = index( $ENV{'REQUEST_URI'}, 'cloudmin' );
our $is_webmail = index( $ENV{'REQUEST_URI'}, 'mail' );
%text = &load_language($current_theme);
%gaccess = &get_module_acl( undef, "" );
$title = &get_html_framed_title();
if ( !-d $root_directory . "/authentic-theme"
&& -d $root_directory . "/authentic-theme-master" )
{
die("ATTENTION:\nHave you downloaded Authentic Theme from GitHub, and unpacked it manually\nto Webmin directory? In this case you need to rename theme directory from\n`authentic-theme-master` to `authentic-theme` in order to make theme work.\nAfterward, you will need to reset the theme again in Webmin Configuration.\n"
);
}
# Load dependencies
do "authentic-theme/authentic-lib.cgi";
# Check user settings on default page for Virtualmin/Cloudmin
if ( $is_virtualmin != -1
&& length __settings('settings_right_virtualmin_default')
&& __settings('settings_right_virtualmin_default') ne ''
&& domain_available( __settings('settings_right_virtualmin_default') ) )
{
parse_virtual_server_access_level();
if ( $virtual_server_access_level eq '2' ) {
our $udefgoto = '/sysinfo.cgi';
}
else {
our $udefgoto = '/virtual-server/summary_domain.cgi?dom='
. __settings('settings_right_virtualmin_default');
}
}
elsif ($is_cloudmin != -1
&& length __settings('settings_right_cloudmin_default')
&& __settings('settings_right_cloudmin_default') ne ''
&& server_available( __settings('settings_right_cloudmin_default') ) )
{
our $udefgoto = '/server-manager/edit_serv.cgi?id='
. __settings('settings_right_cloudmin_default');
}
else {
our $udefgoto = '/sysinfo.cgi';
}
#Going to default right page
$minfo = &get_goto_module();
$__goto
= ( $is_virtualmin != -1 || $is_cloudmin != -1 ) ? $udefgoto
: $minfo ? "$minfo->{'dir'}/"
: $udefgoto;
# Redirect user away, in case requested mode can not be satisfied
if ($ENV{'REQUEST_URI'} ne '/' && $ENV{'REQUEST_URI'} ne '/?virtualmin' && $ENV{'REQUEST_URI'} ne '/?cloudmin' && $ENV{'REQUEST_URI'} ne '/?mail' && index( $ENV{'REQUEST_URI'}, 'xhr' ) lt 0) {
$webmin
= ( $ENV{'HTTPS'} ? 'https://' : 'http://' )
. $ENV{'HTTP_HOST'} . '/';
print "Location: $webmin\n\n";
}
elsif ( ( $is_virtualmin != -1 && !&foreign_available("virtual-server") )
|| ( $is_cloudmin != -1 && !&foreign_available("server-manager") )
|| ($is_webmail != -1
&& (&get_product_name() ne 'usermin'
|| ( &get_product_name() eq 'usermin'
&& !&foreign_available("mailbox") )
)
)
)
{
print "Set-Cookie: redirect=0; path=/\r\n";
$webmin
= ( $ENV{'HTTPS'} ? 'https://' : 'http://' )
. $ENV{'HTTP_HOST'} . '/';
print "Location: $webmin\n\n";
}
# In case Virtualmin/Cloudmin is installed, after logging in, redirect to Virtualmin/Cloudmin
if ($ENV{'HTTP_COOKIE'} =~ /redirect=1/
&& ( &foreign_available("virtual-server")
|| &foreign_available("server-manager") )
&& &get_product_name() eq "webmin"
&& ( $is_virtualmin == -1 && $is_cloudmin == -1 )
)
{
print "Set-Cookie: redirect=0; path=/\r\n";
$virtualmin
= ( $ENV{'HTTPS'} ? 'https://' : 'http://' )
. $ENV{'HTTP_HOST'}
. (
length __settings('settings_right_default_tab_webmin')
? __settings('settings_right_default_tab_webmin')
: '/'
);
print "Location: $virtualmin\n\n";
}
# In case Mailbox module is installed, after logging in, redirect to Webmail
if ( $ENV{'HTTP_COOKIE'} =~ /redirect=1/
&& &foreign_check("mailbox")
&& &foreign_available("mailbox")
&& &get_product_name() eq "usermin"
&& $is_webmail == -1 )
{
print "Set-Cookie: redirect=0; path=/\r\n";
$webmail
= ( $ENV{'HTTPS'} ? 'https://' : 'http://' )
. $ENV{'HTTP_HOST'}
. (
length __settings('settings_right_default_tab_usermin')
? __settings('settings_right_default_tab_usermin')
: '/'
);
print "Location: $webmail\n\n";
}
if ( $ENV{'HTTP_COOKIE'} =~ /redirect=1/ ) {
print "Set-Cookie: redirect=0; path=/\r\n";
# Notify on successful authentication
notify('settings_security_notify_on_login_success');
}
# Clearing possibly stuck update states
if ( index( $ENV{'REQUEST_URI'}, 'updating' ) != -1
|| index( $ENV{'REQUEST_URI'}, 'updating-processing' ) != -1
|| index( $ENV{'REQUEST_URI'}, 'recollect' ) != -1
|| index( $ENV{'REQUEST_URI'}, 'recollect-system-status' ) != -1
|| index( $ENV{'REQUEST_URI'}, 'recollecting' ) != -1
|| index( $ENV{'REQUEST_URI'}, 'recollecting-system-status' ) != -1
|| index( $ENV{'REQUEST_URI'}, 'recollecting-package-updates' ) != -1
|| index( $ENV{'REQUEST_URI'}, 'recollecting-package-updates-processing' )
!= -1 )
{
if ( $is_virtualmin != -1 ) {
$virtualmin
= ( $ENV{'HTTPS'} ? 'https://' : 'http://' )
. $ENV{'HTTP_HOST'}
. '/?virtualmin';
print "Location: $virtualmin\n\n";
}
elsif ( $is_cloudmin != -1 ) {
$cloudmin
= ( $ENV{'HTTPS'} ? 'https://' : 'http://' )
. $ENV{'HTTP_HOST'}
. '/?cloudmin';
print "Location: $cloudmin\n\n";
}
else {
$webmin
= ( $ENV{'HTTPS'} ? 'https://' : 'http://' )
. $ENV{'HTTP_HOST'} . '/';
print "Location: $webmin\n\n";
}
}
parse_virtual_server_access_level();
# Provide unobstructive access for AJAX calls
if ( $in{'xhr-navigation'} eq '1' ) {
print "Content-type: text/html\n\n";
do "authentic-theme/navigation.cgi";
}
elsif ( $in{'xhr-buttons'} eq '1' ) {
print "Content-type: text/html\n\n";
do "authentic-theme/buttons.cgi";
}
elsif ( $in{'xhr-switch'} eq '1' ) {
print "Content-type: text/html\n\n";
print $__goto;
}
elsif ( $in{'xhr-settings'} eq '1' ) {
print "Content-type: text/html\n\n";
if ( $in{'save'} eq '1' ) {
_settings( 'save', undef, undef );
}
elsif ( $in{'restore'} eq '1' ) {
_settings( 'restore', undef, undef );
}
else {
do "authentic-theme/settings.cgi";
}
}
else {
# Force regular user to be in Virtualmin
if ( $virtual_server_access_level eq '2'
&& $ENV{'REQUEST_URI'} ne '/?virtualmin' )
{
$virtualmin
= ( $ENV{'HTTPS'} ? 'https://' : 'http://' )
. $ENV{'HTTP_HOST'}
. '/?virtualmin';
print "Location: $virtualmin\n\n";
}
&header($title);
#### Wrapper. Start.
#
#
print '<div id="wrapper" data-product="'
. &get_product_name()
. '" data-virtual-server="'
. $is_virtualmin
. '" data-server-manager="'
. $is_cloudmin
. '" data-webmail="'
. $is_webmail
. '" data-access-level="'
. $virtual_server_access_level
. '" data-hostname="'
. &get_display_hostname()
. '" class="index">' . "\n";
#### Mobile. Start.
print
'<div class="visible-xs mobile-menu-toggler" style="position: fixed">';
print
'<button type="button" class="btn btn-primary btn-menu-toggler" style="padding-left: 6px; padding-right: 5px;">'
. "\n";
print '<i class="fa fa-fw fa-lg fa-bars"></i>' . "\n";
print '</button>' . "\n";
print '</div>' . "\n";
#### Mobile. End.
#### Left side desktop. Start.
print '<aside style="z-index:10;" id="sidebar" class="hidden-xs">' . "\n"
. "\n";
### Product switcher. Start.
#
#
if ( &get_product_name() eq 'webmin'
&& &foreign_available("asterisk") )
{
our $switch_mode = '2';
our $product_mode = '5';
}
elsif (&get_product_name() eq 'usermin'
&& &foreign_available("mailbox") )
{
our $switch_mode = '2';
our $product_mode = '4';
}
elsif (!&foreign_available("virtual-server")
&& !&foreign_available("server-manager")
|| &get_product_name() eq 'usermin'
|| $virtual_server_access_level eq '2' )
{
our $switch_mode = '3';
our $product_mode = '1';
}
elsif (&foreign_available("virtual-server")
&& &foreign_available("server-manager") )
{
our $switch_mode = '3';
our $product_mode = '3';
}
elsif (
&foreign_available("virtual-server")
|| &foreign_available("server-manager")
&& ( !&foreign_available("virtual-server")
|| !&foreign_available("server-manager") )
)
{
our $switch_mode = '2';
our $product_mode = '2';
}
print '<div class="switch-toggle switch-'
. $switch_mode
. ' switch-mins">';
if ( $product_mode eq '1' ) {
print_switch_empty(1);
$virtual_server_access_level eq '2'
? print_switch_virtualmin()
: print_switch_webmin();
print_switch_empty(2);
}
if ( $product_mode eq '2' ) {
print_switch_webmin(1);
&foreign_available("virtual-server")
? print_switch_virtualmin(1)
: print_switch_cloudmin(1);
}
if ( $product_mode eq '3' ) {
print_switch_webmin(1);
print_switch_virtualmin(1);
print_switch_cloudmin(1);
}
if ( $product_mode eq '4' ) {
print_switch_webmail(1);
print_switch_webmin(1);
}
if ( $product_mode eq '5' ) {
print_switch_webmin(1);
print_switch_thirdlane(1);
}
print '<a></a>
</div><br style="line-height:4.4">';
#
#
### Product switcher. Start.
## Navigation Main Container. Start.
print '<ul class="navigation">' . "\n";
do "authentic-theme/navigation.cgi";
print '</ul>' . "\n";
## Navigation Main Container. End.
### User Buttons. Start.
print '<br><br><ul class="user-links">';
do "authentic-theme/buttons.cgi";
print '</ul>';
### User Buttons. End.
print '</aside>' . "\n";
#### Left Side. End.
#Process logo
embed_logo();
### Right Side. Start.
print '<div id="content" class="__page">' . "\n";
print '<div class="loader-container">' . "\n";
print '<div class="loader"><span class="loading"></span></div>' . "\n";
print '</div>' . "\n";
print
'<script>__lrs()</script>';
print '<iframe name="page" id="iframe" src="'
. $gconfig{'webprefix'}
. (
( !-f $root_directory . '/authentic-theme/update' )
? $__goto
: '/sysinfo.cgi'
) . '">' . "\n";
print '</iframe>' . "\n";
print '</div>' . "\n";
### Right Side. End.
#print '</div>' . "\n"; // Possibly stray tag
#
#
#### Wrapper. End.
&footer();
}