Skip to content

Commit a6c992c

Browse files
committed
password reset function
1 parent 5b7e5ec commit a6c992c

File tree

7 files changed

+567
-3
lines changed

7 files changed

+567
-3
lines changed

web/inc/main.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,4 +97,21 @@ function get_percentage($used,$total) {
9797
return $percent;
9898
}
9999

100+
function send_email($to,$subject,$mailtext,$from) {
101+
$charset = "utf-8";
102+
$to = '<'.$to.'>';
103+
$boundary='--' . md5( uniqid("myboundary") );
104+
$priorities = array( '1 (Highest)', '2 (High)', '3 (Normal)', '4 (Low)', '5 (Lowest)' );
105+
$priority = $priorities[2];
106+
$ctencoding = "8bit";
107+
$sep = chr(13) . chr(10);
108+
$disposition = "inline";
109+
$subject = "=?$charset?B?".base64_encode($subject)."?=";
110+
$header.="From: $from \nX-Priority: $priority\nCC: $cc\n";
111+
$header.="Mime-Version: 1.0\nContent-Type: text/plain; charset=$charset \n";
112+
$header.="Content-Transfer-Encoding: $ctencoding\nX-Mailer: Php/libMailv1.3\n";
113+
$message .= $mailtext;
114+
mail($to, $subject, $message, $header);
115+
}
116+
100117
?>

web/login/index.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@
1919
} else {
2020
if (isset($_POST['user']) && isset($_POST['password'])) {
2121
$cmd="/usr/bin/sudo /usr/local/vesta/bin/";
22-
$command="$cmd"."v_check_user_password '".$_POST['user']."' '".$_POST['password']."' '".$_SERVER["REMOTE_ADDR"]."'";
22+
$v_user = escapeshellarg($_POST['user']);
23+
$v_password = escapeshellarg($_POST['password']);
24+
$command="$cmd"."v_check_user_password ".$v_user." ".$v_password." '".$_SERVER["REMOTE_ADDR"]."'";
2325
exec ($command, $output, $return_var);
2426
if ( $return_var > 0 ) {
2527
$ERROR = "<a class=\"error\">ERROR: Invalid username or password</a>";

web/reset/index.php

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
<?php
2+
session_start();
3+
4+
//
5+
function send_email($to,$subject,$mailtext,$from) {
6+
$charset = "utf-8";
7+
$to = '<'.$to.'>';
8+
$boundary='--' . md5( uniqid("myboundary") );
9+
$priorities = array( '1 (Highest)', '2 (High)', '3 (Normal)', '4 (Low)', '5 (Lowest)' );
10+
$priority = $priorities[2];
11+
$ctencoding = "8bit";
12+
$sep = chr(13) . chr(10);
13+
$disposition = "inline";
14+
$subject = "=?$charset?B?".base64_encode($subject)."?=";
15+
$header.="From: $from \nX-Priority: $priority\nCC: $cc\n";
16+
$header.="Mime-Version: 1.0\nContent-Type: text/plain; charset=$charset \n";
17+
$header.="Content-Transfer-Encoding: $ctencoding\nX-Mailer: Php/libMailv1.3\n";
18+
$message .= $mailtext;
19+
mail($to, $subject, $message, $header);
20+
}
21+
22+
if ((!empty($_POST['user'])) && (empty($_POST['code']))) {
23+
$v_user = escapeshellarg($_POST['user']);
24+
$user = $_POST['user'];
25+
$cmd="/usr/bin/sudo /usr/local/vesta/bin/v_list_user";
26+
exec ($cmd." ".$v_user." json", $output, $return_var);
27+
if ( $return_var == 0 ) {
28+
$data = json_decode(implode('', $output), true);
29+
$rkey = $data[$user]['RKEY'];
30+
$fname = $data[$user]['FNAME'];
31+
$lname = $data[$user]['LNAME'];
32+
$contact = $data[$user]['CONTACT'];
33+
$to = $data[$user]['CONTACT'];
34+
$subject = 'Password Reset '.date("Y-m-d H:i:s");
35+
$hostname = exec('hostname');
36+
$from = "Vesta Control Panel <noreply@".$hostname.">";
37+
if (!empty($fname)) {
38+
$mailtext = "Hello ".$fname." ".$lname.",\n";
39+
} else {
40+
$mailtext = "Hello,\n";
41+
}
42+
$mailtext .= "You recently asked to reset your control panel password. ";
43+
$mailtext .= "To complete your request, please follow this link:\n";
44+
$mailtext .= "https://".$_SERVER['HTTP_HOST']."/reset/?action=confirm&user=".$user."&code=".$rkey."\n\n";
45+
$mailtext .= "Alternately, you may go to https://".$_SERVER['HTTP_HOST']."/reset/?action=code&user=".$user." and enter the following password reset code:\n";
46+
$mailtext .= $rkey."\n\n";
47+
$mailtext .= "If you did not request a new password please ignore this letter and accept our apologies — we didn't intend to disturb you.\n";
48+
$mailtext .= "Thanks,\nThe VestaCP Team\n";
49+
if (!empty($rkey)) send_email($to, $subject, $mailtext, $from);
50+
unset($output);
51+
}
52+
53+
header("Location: /reset/?action=code&user=".$_POST['user']);
54+
exit;
55+
}
56+
57+
if ((!empty($_POST['user'])) && (!empty($_POST['code'])) && (!empty($_POST['password'])) ) {
58+
if ( $_POST['password'] == $_POST['password_confirm'] ) {
59+
$v_user = escapeshellarg($_POST['user']);
60+
$user = $_POST['user'];
61+
$v_password = escapeshellarg($_POST['password']);
62+
$cmd="/usr/bin/sudo /usr/local/vesta/bin/v_list_user";
63+
exec ($cmd." ".$v_user." json", $output, $return_var);
64+
if ( $return_var == 0 ) {
65+
$data = json_decode(implode('', $output), true);
66+
$rkey = $data[$user]['RKEY'];
67+
if ($rkey == $_POST['code']) {
68+
$cmd="/usr/bin/sudo /usr/local/vesta/bin/v_change_user_password";
69+
exec ($cmd." ".$v_user." ".$v_password, $output, $return_var);
70+
if ( $return_var > 0 ) {
71+
$ERROR = "<a class=\"error\">ERROR: Internal error</a>";
72+
} else {
73+
$_SESSION['user'] = $_POST['user'];
74+
header("Location: /");
75+
exit;
76+
}
77+
} else {
78+
$ERROR = "<a class=\"error\">ERROR: Invalid username or code</a>";
79+
}
80+
} else {
81+
$ERROR = "<a class=\"error\">ERROR: Invalid username or code</a>";
82+
}
83+
} else {
84+
$ERROR = "<a class=\"error\">ERROR: Passwords not match</a>";
85+
}
86+
}
87+
88+
if (empty($_GET['action'])) {
89+
require_once '../templates/reset_1.html';
90+
} else {
91+
if ($_GET['action'] == 'code' ) {
92+
require_once '../templates/reset_2.html';
93+
}
94+
if (($_GET['action'] == 'confirm' ) && (!empty($_GET['code']))) {
95+
require_once '../templates/reset_3.html';
96+
}
97+
}
98+
99+
?>

web/templates/login.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@
114114
<table>
115115
<tr>
116116
<td style="padding: 0 10 0 42;">
117-
<img src="/images/logo.png" width="124px" height="46px" alt="Vesta Control Panel" />
117+
<a href="/"><img border=0 src="/images/logo.png" width="124px" height="46px" alt="Vesta Control Panel" /></a>
118118
</td>
119119
<td style="padding: 20px 0 0 0;"><form method="post" action="/login/" >
120120
<table class="login-box">
@@ -123,7 +123,7 @@
123123
</tr><tr>
124124
<td><input tabindex="1" type="text" size="20px" style="width:200px;" name="user" class="loggin-input"></td>
125125
</tr><tr>
126-
<td><p class="login-text1">Password <a tabindex="5" class="forgot" href="#" >(forgot password)</a></p></td>
126+
<td><p class="login-text1">Password <a tabindex="5" class="forgot" href="/reset/" >(forgot password)</a></p></td>
127127
</tr><tr>
128128
<td><input tabindex="2" type="password" size="20px" style="width:200px;" name="password" class="loggin-input"></td>
129129
</tr><tr>

web/templates/reset_1.html

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
<link rel="icon" href="/images/favicon.ico" type="image/x-icon">
2+
<title> VestaCP - Reset Password </title>
3+
<style type="text/css">
4+
body {
5+
padding: 0;
6+
margin: 0;
7+
margin-left: auto;
8+
margin-right: auto;
9+
background-image: url(/images/b.png);
10+
font-family: Arial, sans-serif;
11+
}
12+
13+
.forgot {
14+
color: #484243;
15+
font-family: Arial, sans-serif;
16+
font-size: 8pt;
17+
padding: 0 10px 0 0;
18+
}
19+
20+
.login {
21+
margin: 80px 0 80px 0;
22+
padding: 0;
23+
border-top: 1px solid #cccccc;
24+
border-left: 1px solid #cccccc;
25+
border-right: 1px solid #cccccc;
26+
background: #ebe9dc;
27+
text-align: left;
28+
vertical-align:top;
29+
width: 500px;
30+
box-shadow: 0 0 8px 8px #d7d7d7;
31+
}
32+
33+
.login-box {
34+
width: 260px;
35+
text-align: left;
36+
vertical-align:top;
37+
padding: 0 0 10px 40px;
38+
}
39+
40+
.login-text1 {
41+
padding: 10px 0 0 2px;
42+
color: #433832;
43+
font-family: Arial, sans-serif;
44+
font-size: 12pt;
45+
}
46+
.login-text1 a {
47+
padding: 0 6px;
48+
font-family: Arial, sans-serif;
49+
font-size: 10pt;
50+
text-shadow: none;
51+
}
52+
.login-text2 {
53+
padding: 12px 0 10px 0;
54+
color: #484243;
55+
}
56+
57+
.login-bottom {
58+
color: #574F51;
59+
text-align: right;
60+
width: 500px;
61+
height: 50px;
62+
background: #484243;
63+
padding: 0 8px 0 0;
64+
margin: 0;
65+
}
66+
.vestacp{
67+
font-size: 8pt;
68+
color: #CCCCB4;
69+
text-align: right;
70+
padding: 20px 0 0 0;
71+
}
72+
.error {
73+
font-size: 10pt;
74+
color: #DE6C5D;
75+
}
76+
.loggin-input {
77+
color: #555;
78+
background-color: #FFFFFF;
79+
border: 1px solid #999999;
80+
border-radius: 3px 3px 3px 3px;
81+
color: #555555;
82+
font-family: Arial,sans-serif;
83+
font-size: 14pt;
84+
padding: 4px;
85+
width: 360px;
86+
}
87+
88+
.loggin-button {
89+
padding: 4px;
90+
margin: 0 6px 0 0;
91+
cursor: pointer;
92+
color: #333333;
93+
background-color: #f6f6f6;
94+
border: 1px solid #ACACAC;
95+
border-radius: 3px 3px 3px 3px;
96+
font-size: 12px;
97+
padding: 3px 16px;
98+
width: 105px;
99+
}
100+
101+
.loggin-button:hover {
102+
background-color: #f0f0f0;
103+
}
104+
105+
.loggin-button:active {
106+
background-color: #EBE9DC;
107+
}
108+
</style>
109+
</head>
110+
<body>
111+
<center>
112+
<table class="login">
113+
<tr>
114+
<td>
115+
<table>
116+
<tr>
117+
<td style="padding: 0 10px 0 42px;">
118+
<a href="/"><img border=0 src="/images/logo.png" width="124px" height="46px" alt="Vesta Control Panel" /></a>
119+
</td>
120+
<td style="padding: 20px 0 0 0;"><form method="post" action="/reset/" >
121+
<table class="login-box">
122+
<tr>
123+
<td style="padding: 6px 0 10px 0;">To reset your password, enter your username and we'll send you instructions on how to create a new password.</td>
124+
</tr><tr>
125+
<td><p class="login-text1">Username</p></td>
126+
</tr><tr>
127+
<td><input tabindex="1" type="text" size="20px" style="width:200px" name="user" class="loggin-input"></td>
128+
</tr><tr>
129+
<td style="padding: 20px 0 0 0;"><input tabindex="2" type="submit" value="Submit" class="loggin-button"></td>
130+
</tr>
131+
</table>
132+
</form>
133+
</td>
134+
</tr><tr>
135+
<td colspan=2>
136+
<table class="login-bottom">
137+
<tr><td>.<?php if (isset($ERROR)) echo $ERROR ?></td></tr>
138+
<tr><td><a tabindex="6" class="vestacp" href="http://vestacp.com" >vestacp.com</a></td></tr>
139+
</table>
140+
</tr>
141+
</table>
142+
</tr></table>
143+
</center>
144+
</body>
145+
</html>

0 commit comments

Comments
 (0)