allow setup of 2FA when logged in via mailaccount directly
Bernd Wurst

Bernd Wurst commited on 2020-07-30 11:08:47
Zeige 7 geänderte Dateien mit 62 Einfügungen und 8 Löschungen.

... ...
@@ -0,0 +1,43 @@
1
+<?php
2
+/*
3
+This file belongs to the Webinterface of schokokeks.org Hosting
4
+
5
+Written 2008-2018 by schokokeks.org Hosting, namely
6
+  Bernd Wurst <bernd@schokokeks.org>
7
+  Hanno Böck <hanno@schokokeks.org>
8
+
9
+To the extent possible under law, the author(s) have dedicated all copyright and related and neighboring rights to this software to the public domain worldwide. This software is distributed without any warranty.
10
+
11
+You should have received a copy of the CC0 Public Domain Dedication along with this software. If not, see
12
+http://creativecommons.org/publicdomain/zero/1.0/
13
+
14
+Nevertheless, in case you use a significant part of this code, we ask (but not require, see the license) that you keep the authors' names in place and return your changes to the public. We would be especially happy if you tell us what you're going to do with this code.
15
+*/
16
+
17
+require_once('totp.php');
18
+require_role(array(ROLE_MAILACCOUNT, ROLE_VMAIL_ACCOUNT));
19
+
20
+title("Zwei-Faktor-Anmeldung am Webmailer");
21
+
22
+output('<p>Sie können bei '.config('company_name').' den Zugang zum Webmailer mit einem Zwei-Faktor-Prozess mit abweichendem Passwort schützen.</p>
23
+<p>Dieses System schützt Sie vor mitgelesenen Tastatureingaben in nicht vertrauenswürdiger Umgebung z.B. in einem Internet-Café.</p>
24
+<p>Beim Zwei-Faktor-Prozess müssen Sie zum Login ein festes Webmail-Passwort und zusätzlich ein variabler Code, den beispielsweise Ihr Smartphone erzeugen kann, eingeben. Da sich dieser Code alle 30 Sekunden ändert, kann ein Angreifer sich nicht später mit einem abgehörten Passwort noch einmal anmelden. Zum Erzeugen des Einmal-Codes benötigen Sie ein Gerät, das <strong>TOTP-Einmalcodes nach RFC 6238</strong> erzeugt. Beispiele dafür sind <a href="https://code.google.com/p/google-authenticator/">Google-Authenticator</a> oder <a href="http://f-droid.org/repository/browse/?fdfilter=motp&fdid=org.cry.otp&fdpage=1">mOTP</a>. Meist ist dies ein Smartphone mit einer entsprechenden App.</p>
25
+<p><strong>Beachten Sie:</strong> Die Zwei-Faktor-Anmeldung funktioniert nur für Webmail und bei diesem Webinterface, beim Login via IMAP wird weiterhin das Passwort Ihres Postfachs benötigt. Damit dieses Passwort von einem Angreifer nicht mitgelesen werden kann, müssen Sie zur Zwei-Faktor-Anmeldung unbedingt ein separates Webmail-Passwort festlegen.</p>
26
+');
27
+
28
+
29
+require_once('modules/email/include/hasaccount.php');
30
+require_once('modules/email/include/vmail.php');
31
+
32
+$username = $_SESSION['mailaccount'];
33
+$id = account_has_totp($username);
34
+
35
+
36
+output('<h3>Zwei-Faktor-Anmeldung für '.htmlspecialchars($username).'</h3>
37
+<div style="margin-left: 2em;">');
38
+if ($id) {
39
+    output(addnew('delete', 'Zwei-Faktor-Anmeldung für dieses Postfach abschalten', 'id='.$id, 'style="background-image: url('.$prefix.'images/delete.png); color: red;"'));
40
+} else {
41
+    output(addnew('setup', 'Zwei-Faktor-Anmeldung für dieses Postfach aktivieren', 'username='.urlencode($username)));
42
+}
43
+output('</div>');
... ...
@@ -15,25 +15,30 @@ Nevertheless, in case you use a significant part of this code, we ask (but not r
15 15
 */
16 16
 
17 17
 require_once('inc/base.php');
18
-require_role(ROLE_SYSTEMUSER);
18
+require_role(array(ROLE_SYSTEMUSER, ROLE_MAILACCOUNT, ROLE_VMAIL_ACCOUNT));
19 19
 
20 20
 require_once('totp.php');
21 21
 
22 22
 $id = (int) $_REQUEST['id'];
23 23
 
24
+$startpage = 'account';
25
+if (have_role(ROLE_SYSTEMUSER)) {
26
+    $startpage = 'overview';
27
+}
28
+
24 29
 $account = accountname($id);
25 30
 $sure = user_is_sure();
26 31
 if ($sure === null) {
27
-    $section='webmailtotp_overview';
32
+    $section='webmailtotp_'.$startpage;
28 33
     title("Zwei-Faktor-Anmeldung am Webmailer");
29 34
     are_you_sure("id={$id}", "Möchten Sie die Zwei-Faktor-Anmeldung für das Postfach »{$account}« wirklich entfernen?");
30 35
 } elseif ($sure === true) {
31 36
     delete_totp($id);
32 37
     if (! $debugmode) {
33
-        header("Location: overview");
38
+        header("Location: ".$startpage);
34 39
     }
35 40
 } elseif ($sure === false) {
36 41
     if (! $debugmode) {
37
-        header("Location: overview");
42
+        header("Location: ".$startpage);
38 43
     }
39 44
 }
... ...
@@ -15,7 +15,7 @@ Nevertheless, in case you use a significant part of this code, we ask (but not r
15 15
 */
16 16
 
17 17
 require_once('inc/base.php');
18
-require_role(ROLE_SYSTEMUSER);
18
+require_role(array(ROLE_SYSTEMUSER, ROLE_MAILACCOUNT, ROLE_VMAIL_ACCOUNT));
19 19
 
20 20
 require_once('totp.php');
21 21
 
... ...
@@ -45,6 +45,10 @@ function validate_password($username, $password)
45 45
 
46 46
 function store_webmail_password($username, $oldpw, $newpw)
47 47
 {
48
+    $qual = strong_password($newpw);
49
+    if ($qual !== true) {
50
+        system_failure('Fehler beim Webmail-Passwort: '.$qual);
51
+    }
48 52
     $secret = $newpw;
49 53
     if (strlen($oldpw) > strlen($newpw)) {
50 54
         $secret = str_pad($newpw, strlen($oldpw), $newpw);
... ...
@@ -16,6 +16,8 @@ Nevertheless, in case you use a significant part of this code, we ask (but not r
16 16
 
17 17
 $role = $_SESSION['role'];
18 18
 
19
-if ($role & (ROLE_SYSTEMUSER | ROLE_MAILACCOUNT | ROLE_VMAIL_ACCOUNT)) {
19
+if ($role & (ROLE_MAILACCOUNT | ROLE_VMAIL_ACCOUNT)) {
20
+    $menu["webmailtotp_account"] = array("label" => "Zwei-Faktor-Anmeldung", "file" => "account", "weight" => 5);
21
+} elseif ($role & ROLE_SYSTEMUSER) {
20 22
     $menu["webmailtotp_overview"] = array("label" => "Zwei-Faktor-Anmeldung", "file" => "overview", "weight" => 5, "submenu" => "email_vmail" );
21 23
 }
... ...
@@ -16,7 +16,7 @@ Nevertheless, in case you use a significant part of this code, we ask (but not r
16 16
 
17 17
 require_once('inc/base.php');
18 18
 require_once('inc/security.php');
19
-require_role(ROLE_SYSTEMUSER);
19
+require_role(array(ROLE_SYSTEMUSER, ROLE_MAILACCOUNT, ROLE_VMAIL_ACCOUNT));
20 20
 
21 21
 $username = urldecode($_REQUEST['username']);
22 22
 
... ...
@@ -16,7 +16,7 @@ Nevertheless, in case you use a significant part of this code, we ask (but not r
16 16
 
17 17
 require_once('inc/base.php');
18 18
 require_once('inc/icons.php');
19
-require_role(ROLE_SYSTEMUSER);
19
+require_role(array(ROLE_SYSTEMUSER, ROLE_MAILACCOUNT, ROLE_VMAIL_ACCOUNT));
20 20
 
21 21
 require_once('totp.php');
22 22
 
23 23