forked from riccardonobile/Bootstrap3-Webmin-Theme
-
Notifications
You must be signed in to change notification settings - Fork 0
/
session_login.cgi
178 lines (167 loc) · 7.21 KB
/
session_login.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
#############################################################################################################################
# BWTheme 0.7.0 (https://github.com/winfuture/Bootstrap3-Webmin-Theme) - (http://theme.winfuture.it) #
# Copyright (c) 2015 Riccardo Nobile <[email protected]> and Simone Cragnolini <[email protected]> #
# Licensed under GPLv3 License (https://github.com/winfuture/Bootstrap3-Webmin-Theme/blob/testing/LICENSE) #
#############################################################################################################################
BEGIN {push(@INC, ".." );};
use WebminCore;
$name = (&get_product_name() eq 'usermin') ? 'Usermin' : 'Webmin';
$pragma_no_cache = 1;
&ReadParse();
&init_config();
%text = &load_language($current_theme);
%gaccess = &get_module_acl(undef, "");
&get_miniserv_config(\%miniserv);
# Get some config parameters
$charset = &get_charset();
$realname = $gconfig{'realname'};
$showhost = $gconfig{'showhost'};
$loginbanner = $gconfig{'loginbanner'};
$webprefix = $gconfig{'webprefix'};
$noremember = $gconfig{'noremember'};
$tag = noremember ? 'autocomplete="off"' : '';
# Define the page title
$title = &get_html_framed_title();
if ($showhost) {
$title = &get_display_hostname() . " : " . $title;
}
# Define host name
if ($realname) {
$host = &get_display_hostname();
} else {
$host = $ENV{'HTTP_HOST'};
$host =~ s/:\d+//g;
$host = &html_escape($host);
}
# Show pre login banner if exist
if ($loginbanner && $ENV{'HTTP_COOKIE'} !~ /banner=1/ && !$in{'logout'} && !$in{'failed'} && !$in{'timed_out'} ) {
print "Set-Cookie: banner=1; path=/\r\n";
&PrintHeader($charset);
&LoginHeader($title, $webprefix);
print '<div class="box-container box-banner">' . "\n";
&BoxHeader($name, $host);
print '<div class="box-body clearfix">' . "\n";
print '<div>' . "\n";
$url = $in{'page'};
open(BANNER, $loginbanner);
while (<BANNER>) {
s/LOGINURL/$url/g;
print;
}
close(BANNER);
print '</div>' . "\n";
print '<div class="input-group pull-right">' . "\n";
print '<a href="' . $webprefix . '" type="submit" class="btn btn-danger"><i class="fa fa-unlock"></i> ' . &text('banner_login') . '</a>' . "\n";
print '</div>' . "\n";
print '</div>' . "\n";
print '</div>' . "\n";
print '</div>' . "\n";
&LoginFooter();
return;
}
# Show login form
$sec = uc($ENV{'HTTPS'}) eq 'ON' ? "; secure" : "";
$sidname = $miniserv{'sidname'} || "sid";
print "Set-Cookie: banner=0; path=/$sec\r\n" if ($loginbanner);
print "Set-Cookie: $sidname=x; path=/$sec\r\n" if ($in{'logout'});
print "Set-Cookie: testing=1; path=/$sec\r\n";
&PrintHeader($charset);
&LoginHeader($title, $webprefix);
if (defined($in{'failed'})) {
if ($in{'twofactor_msg'}) {
LoginMessage('alert-danger', 'fa-bolt', $text{'login_danger'} . '!', &text('session_twofailed', &html_escape($in{'twofactor_msg'})));
} else {
LoginMessage('alert-danger', 'fa-bolt', $text{'login_danger'} . '!', $text{'session_failed'});
}
} elsif ($in{'logout'}) {
LoginMessage('alert-success', 'fa-check', $text{'login_success'} . '!', $text{'session_logout'});
} elsif ($in{'timed_out'}) {
LoginMessage('alert-warning', 'fa-exclamation-triangle', $text{'login_warning'} . '!', &text('session_timedout', int($in{'timed_out'} / 60)));
}
print '<div class="box-container box-login">' . "\n";
&BoxHeader($name, $host);
print '<div class="box-body clearfix">' . "\n";
print '<div>' . "\n";
print '<p>Please, sign in with your account to manage this server</p>' . "\n";
print '<form method="post" action="' . $webprefix . '/session_login.cgi" role="form">' . "\n";
print '<div class="form-group">' . "\n";
print '<div class="input-group">' . "\n";
print '<span class="input-group-addon"><i class="fa fa-fw fa-user"></i></span>' ."\n";
print '<input type="text" class="form-control" placeholder="' . $text{'login_username'} . '" name="user" ' . $tag . '>' . "\n";
print '</div>' . "\n";
print '</div>' . "\n";
print '<div class="form-group">' . "\n";
print '<div class="input-group">' . "\n";
print '<span class="input-group-addon"><i class="fa fa-fw fa-lock"></i></span>' . "\n";
print '<input type="password" class="form-control" placeholder="' . $text{'login_password'} . '" name="pass" ' . $tag . '>' . "\n";
print '</div>' . "\n";
print '</div>' . "\n";
if ($miniserv{'twofactor_provider'}) {
print '<div class="form-group">' . "\n";
print '<div class="input-group">' . "\n";
print '<span class="input-group-addon"><i class="fa fa-fw fa-qrcode"></i></span>' . "\n";
print '<input type="text" class="form-control" placeholder="' . $text{'login_token'} . '" name="twofactor" autocomplete=off>' . "\n";
print '</div>' . "\n";
print '</div>' . "\n";
}
if (!$noremember) {
print '<div class="input-group pull-left">' . "\n";
print '<div class="checkbox">' . "\n";
print '<input type="checkbox" name="remember-me" id="remember-me" class="remember-me">' . "\n";
print '<label class="remember-me" for="remember-me">' . $text{'login_remember'} . '</label>' . "\n";
print '</div>' . "\n";
print '</div>' . "\n";
}
print '<div class="input-group pull-right">' . "\n";
print '<button type="submit" class="btn btn-primary"><i class="fa fa-sign-in"></i> ' . $text{'login_signin'} . '</button>' . "\n";
print '</div>' . "\n";
print '</form>' . "\n";
print '</div>' . "\n";
print '</div>' . "\n";
print '</div>' . "\n";
print '</div>' . "\n";
&LoginFooter();
# Login functions
sub LoginHeader {
my ($title, $webprefix) = @_;
print '<!DOCTYPE HTML>' , "\n";
print '<html>' , "\n";
print '<head>' , "\n";
print '<title>' , $title , '</title>' , "\n";
print '<meta charset="utf-8">' , "\n";
print '<meta name="viewport" content="width=device-width, initial-scale=1.0">' . "\n";
print '<link href="' . $webprefix . '/unauthenticated/assets/css/bootstrap.min.css" rel="stylesheet" type="text/css">' , "\n";
print '<link href="' . $webprefix. '/unauthenticated/assets/css/font-awesome.min.css" rel="stylesheet" type="text/css">' , "\n";
print '<link href="' . $webprefix. '/unauthenticated/assets/css/bootstrap-checkbox.css" rel="stylesheet" type="text/css">' , "\n";
print '<link href="' . $webprefix. '/unauthenticated/assets/css/login.css" rel="stylesheet" type="text/css">' , "\n";
print '<script src="' . $webprefix. '/unauthenticated/assets/js/jquery.min.js" type="text/javascript"></script>' , "\n";
print '<script src="' . $webprefix. '/unauthenticated/assets/js/bootstrap.min.js" type="text/javascript"></script>' , "\n";
print '</head>' , "\n";
print '<body>' . "\n";
print '<div class="container">' . "\n";
print '<div class="row">' . "\n";
print '<div class="col-xs-12 col-sm-fix">' . "\n";
}
sub LoginFooter {
print '</div>' . "\n";
print '</div>' . "\n";
print '</div>' . "\n";
print '</body>' , "\n";
print '</html>' , "\n";
}
sub LoginMessage {
my ($class, $icon, $title, $message) = @_;
print '<div class="message-container">' . "\n";
print '<div class="alert ' . $class . '">' . "\n";
print '<strong><i class ="fa ' . $icon . '"></i> ' . $title . '</strong><br />' . "\n";
print $message . "\n";
print '</div>' . "\n";
print '</div>' . "\n";
}
sub BoxHeader {
my ($name, $host) = @_;
print '<div class="box-header">' . "\n";
print '<h1><i class="fa fa-cloud"></i> ' . $name . ' ' . &get_webmin_version() . '</h1>' . "\n";
print '<h2>' . $host . '</h2>' . "\n";
print '</div>' . "\n";
}