Skip to content

Commit d3c1500

Browse files
committed
More implementing 2fa
1 parent 0ecb820 commit d3c1500

File tree

2 files changed

+52
-9
lines changed

2 files changed

+52
-9
lines changed

interface/web/login/otp.php

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,13 @@
5555
$app->auth->csrf_token_check();
5656
}
5757

58+
59+
// FIXME What's the deal with otp_enabled=v ??
60+
61+
62+
5863
//* Handle recovery code
59-
if(isset($_POST['code']) && strlen($_POST['code']) == 32 && $_SESSION['otp']['recovery'])) {
64+
if(isset($_POST['code']) && strlen($_POST['code']) == 32 && $_SESSION['otp']['recovery']) {
6065
//* TODO Recovery code handling
6166

6267
$user = $app->db->queryOneRecord('SELECT otp_attempts FROM sys_user WHERE userid = ?',$_SESSION['s_pending']['user']['userid']);
@@ -66,6 +71,7 @@
6671

6772
}
6873

74+
// show reset form to create a new 2fa secret?
6975
7076
die('Handle recovery code');
7177
}
@@ -104,8 +110,8 @@
104110
die();
105111
} else {
106112
//* 2fa wrong code
107-
$_SESSION['otp']['session_attempts']++;
108-
$app->db->query()
113+
$_SESSION['otp']['session_attempts']++; // FIXME can't we skip this and rely on the DB only?
114+
$app->db->query('UPDATE `sys_user` SET otp_attempts=otp_attempts + 1 WHERE userid = ?', $_SESSION['s_pending']['user']['userid']);
109115
}
110116
}
111117

@@ -125,12 +131,16 @@
125131
}
126132

127133
$app->uses('functions');
128-
134+
$app->uses('getconf');
135+
$system_config = $app->getconf->get_global_config();
136+
$from = $system_config['mail']['admin_mail'];
137+
138+
129139
//* send email
130140
$email_to = $_SESSION['otp']['data'];
131141
$subject = 'ISPConfig Login authentication';
132-
$text = '';
133-
$from = 'root@localhost';
142+
$text = 'Your One time login code is ' . $_SESSION['otp']['code'] . PHP_EOL
143+
. 'This code is valid for 10 minutes' . PHP_EOL;
134144

135145
$app->functions->mail($email_to, $subject, $text, $from);
136146

@@ -144,7 +154,7 @@
144154
}
145155

146156
//* Show form to enter email code
147-
157+
// ... below
148158

149159

150160
} else {
@@ -153,7 +163,15 @@
153163
}
154164

155165

166+
$logo = $app->db->queryOneRecord("SELECT * FROM sys_ini WHERE sysini_id = 1");
167+
if($logo['custom_logo'] != ''){
168+
$base64_logo_txt = $logo['custom_logo'];
169+
} else {
170+
$base64_logo_txt = $logo['default_logo'];
171+
}
172+
$app->tpl->setVar('base64_logo_txt', $base64_logo_txt);
156173

174+
$app->tpl->setVar('current_theme', isset($_SESSION['s']['theme']) ? $_SESSION['s']['theme'] : 'default', true);
157175

158176

159177
//* Load templating system and lang file
@@ -168,7 +186,8 @@
168186
$app->tpl->setVar('_csrf_key',$csrf_token['csrf_key']);
169187

170188

171-
$app->load_language_file('web/login/lib/lang/'.$conf["language"].'.lng');
189+
require ISPC_ROOT_PATH.'/web/login/lib/lang/'.$app->functions->check_language($conf['language']).'.lng';
190+
$app->tpl->setVar($wb);
172191

173192

174193

@@ -178,4 +197,4 @@
178197
$app->tpl->pparse();
179198

180199

181-
?>
200+
?>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<tmpl_if name="msg">
2+
<div class="alert alert-success" role="alert"><tmpl_var name="msg"></div>
3+
</tmpl_if>
4+
<tmpl_if name="error">
5+
<div class="alert alert-danger" role="alert"><tmpl_var name="error"></div>
6+
</tmpl_if>
7+
<h2><tmpl_var name="otp_code_txt"></h2>
8+
<p><tmpl_var name="otp_code_desc_txt"></p>
9+
<form accept-charset="UTF-8" role="form" method="post" action="otp.php">
10+
<fieldset>
11+
<div class="form-group">
12+
<input class="form-control" placeholder="{tmpl_var name='otp_code_placeholder_txt'}" name="code" id="code" type="text" autofocus>
13+
</div>
14+
<div class="right">
15+
<input class="btn btn-default formbutton-default" type="submit" value="{tmpl_var name='login_button_txt'}">
16+
</div>
17+
<a href="otp.php?action=resent">{tmpl_var name='otp_code_reset_txt'}</a>
18+
19+
20+
<input type="hidden" name="_csrf_id" value="{tmpl_var name='_csrf_id'}" />
21+
<input type="hidden" name="_csrf_key" value="{tmpl_var name='_csrf_key'}" />
22+
23+
</fieldset>
24+
</form>

0 commit comments

Comments
 (0)