2023-09-29 03:24:14 +03:00
|
|
|
#!/usr/local/bin/perl
|
|
|
|
# switch_theme.cgi
|
|
|
|
# Change the theme for the current user if allowed
|
|
|
|
|
|
|
|
BEGIN { push(@INC, "."); };
|
|
|
|
use WebminCore;
|
|
|
|
|
|
|
|
&init_config();
|
|
|
|
&ReadParse();
|
2025-02-21 14:58:37 +02:00
|
|
|
&PrintHeader();
|
2023-09-29 03:24:14 +03:00
|
|
|
my $err = sub {
|
|
|
|
print("<tt>Cannot change theme : $_[0]</tt>\n");
|
|
|
|
exit(1);
|
|
|
|
};
|
2024-07-19 12:36:52 +03:00
|
|
|
|
2023-09-29 03:24:14 +03:00
|
|
|
# Check if allowed to change theme,
|
|
|
|
# otherwise throw an error
|
|
|
|
if (!&foreign_available('theme') &&
|
|
|
|
!&foreign_available('change-user') &&
|
|
|
|
!&foreign_available('webmin') &&
|
|
|
|
!&foreign_available('acl')) {
|
|
|
|
&$err("You are not allowed to change themes!");
|
|
|
|
}
|
|
|
|
# Check if the theme is known
|
|
|
|
&$err("Theme identification is not known!")
|
|
|
|
if (!$in{'theme'} || $in{'theme'} !~ /^[123]$/);
|
|
|
|
# Check if the remote user is known
|
|
|
|
&$err("Remote user is not known!") if (!$remote_user);
|
|
|
|
# Define the theme
|
|
|
|
my $themes = {
|
|
|
|
'1' => 'authentic-theme',
|
|
|
|
'2' => 'gray-theme',
|
|
|
|
'3' => '' };
|
|
|
|
my $theme = $themes->{$in{'theme'}};
|
|
|
|
# Change the theme
|
2023-10-01 14:36:56 +03:00
|
|
|
&foreign_require('acl');
|
|
|
|
my @users = &acl::list_users();
|
|
|
|
my ($user) = grep { $_->{'name'} eq $remote_user } @users;
|
|
|
|
$user->{'theme'} = $theme;
|
|
|
|
&acl::modify_user($user->{'name'}, $user);
|
2024-11-19 13:21:34 +02:00
|
|
|
&load_theme_library();
|
|
|
|
&theme_post_change_theme() if (defined(&theme_post_change_theme));
|
2025-02-21 14:58:37 +02:00
|
|
|
&reload_miniserv();
|
|
|
|
print &js_redirect("/", "top");
|