Browse code

jQuery-based Certlogin, so entfällt ein Mausklick

Bernd Wurst authored on23/01/2013 10:36:54
Showing4 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,79 @@
1
+<?php
2
+/*
3
+This file belongs to the Webinterface of schokokeks.org Hosting
4
+
5
+Written 2008-2013 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
+// Setze das Arbeitsverzeichnis auf das Stammverzeichnis, damit die Voraussetzungen gleich sind wie bei allen anderen Requests
18
+chdir('..');
19
+
20
+require_once('config.php');
21
+global $prefix;
22
+$prefix = '../';
23
+
24
+// Das Parent-Verzeichnis in den Include-Pfad, da wir uns jetzt in einem anderen Verzeichnis befinden.
25
+ini_set('include_path', ini_get('include_path').':../');
26
+
27
+require_once('session/start.php');
28
+require_once('inc/base.php');
29
+require_once('inc/debug.php');
30
+require_once('inc/error.php');
31
+require_once('inc/theme.php');
32
+
33
+
34
+function prepare_cert($cert)
35
+{
36
+	return str_replace(array('-----BEGIN CERTIFICATE-----', '-----END CERTIFICATE-----', ' ', "\n"), array(), $cert);
37
+}
38
+
39
+
40
+function get_logins_by_cert($cert) 
41
+{
42
+	$cert = mysql_real_escape_string(prepare_cert($cert));
43
+	$query = "SELECT type,username,startpage FROM system.clientcert WHERE cert='{$cert}'";
44
+	$result = db_query($query);
45
+	if (mysql_num_rows($result) < 1)
46
+		return NULL;
47
+	else {
48
+		$ret = array();
49
+		while ($row = mysql_fetch_assoc($result)) {
50
+			$ret[] = $row;
51
+		}
52
+		return $ret;
53
+	}
54
+}
55
+
56
+DEBUG('$_SERVER:');
57
+DEBUG($_SERVER);
58
+
59
+header('Content-type: text/plain');
60
+
61
+if (isset($_SERVER['REDIRECT_SSL_CLIENT_CERT']) && 
62
+    isset($_SERVER['REDIRECT_SSL_CLIENT_S_DN']) && $_SERVER['REDIRECT_SSL_CLIENT_S_DN'] != '' && 
63
+    isset($_SERVER['REDIRECT_SSL_CLIENT_I_DN']) && $_SERVER['REDIRECT_SSL_CLIENT_I_DN'] != '') {
64
+  $ret = get_logins_by_cert($_SERVER['REDIRECT_SSL_CLIENT_CERT']);
65
+  if ($ret === NULL) {
66
+    echo 'error';
67
+    die();
68
+  }
69
+  if (count($ret) == 1) {
70
+    $uid = $ret[0]['username'];
71
+    $role = find_role($uid, '', True);
72
+    setup_session($role, $uid);
73
+    echo 'ok';
74
+    die();
75
+  }
76
+}
77
+echo 'error';
78
+die();
79
+?>
... ...
@@ -14,6 +14,7 @@ http://creativecommons.org/publicdomain/zero/1.0/
14 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 15
 */
16 16
 
17
+// Setze das Arbeitsverzeichnis auf das Stammverzeichnis, damit die Voraussetzungen gleich sind wie bei allen anderen Requests
17 18
 chdir('..');
18 19
 
19 20
 require_once('config.php');
20 21
new file mode 100644
... ...
@@ -0,0 +1,43 @@
1
+<?php
2
+/*
3
+This file belongs to the Webinterface of schokokeks.org Hosting
4
+
5
+Written 2008-2013 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
+title('Login über SSL-Client-Zertifikat');
18
+
19
+$path = config('jquery_ui_path');
20
+html_header('
21
+<link rel="stylesheet" href="'.$path.'/themes/base/jquery-ui.css">
22
+<script type="text/javascript" src="'.$path.'/jquery-1.9.0.js" ></script>
23
+<script type="text/javascript" src="'.$path.'/ui/jquery-ui.js" ></script>
24
+<script>
25
+  function redirect(status) {
26
+    if (status == "ok") {
27
+      window.location.href="../../go/index/index";
28
+    } else {
29
+      window.location.href="../../certlogin/";
30
+    }
31
+  }
32
+  $.get("../../certlogin/ajax.php", redirect);
33
+</script>
34
+');
35
+
36
+output('<p>Sie werden nun über Ihr SSL-Client-Zertifikat eingeloggt. Möglicherweise werden Sie von Ihrem Browser zunächst gebeten, ein Zertifkkat auszuwählen.</p>');
37
+
38
+output('<p>Sollte der Login nicht funktionieren, klicken Sie bitte diesen Link:</p>
39
+<p><strong>'.internal_link('../../certlogin/', 'Login über SSL-Client-Zertifikat').'</strong></p>
40
+');
41
+
42
+
43
+
... ...
@@ -18,7 +18,7 @@ $role = $_SESSION['role'];
18 18
 
19 19
 if ($role == ROLE_ANONYMOUS) {
20 20
   $menu["index_login"] = array("label" => "Login", "file" => "index", "weight" => 0);
21
-  $menu["certlogin"] = array("label" => "Client-Zertifikat", "file" => "certinfo", "weight" => 10);
21
+  $menu["certlogin"] = array("label" => "Zertifikat-Login", "file" => "certlogin", "weight" => 10);
22 22
 } else {
23 23
   if ($role & (ROLE_SYSTEMUSER | ROLE_SUBUSER | ROLE_VMAIL_ACCOUNT))
24 24
     $menu["index_cert"] = array("label" => "Client-Zertifikat", "file" => "cert", "weight" => 10, "submenu" => "index_index");