Issues (27)

Labels
Severity
1
<?php
2
3
// Copyright (C) 2014-2023 Universitätsbibliothek Mannheim
4
// See file LICENSE for license details.
5
6
// This file implements user authorization.
7
8
// PalMA installation can authorize users by a PIN, by a
9
// user name and by a password.
10
11
// The PIN is a four digit random number which is changed for
12
// every new session.
13
14
// Authorization with a user name and a password requires code
15
// which implements the authorization mechanism (for example
16
// proxy based authorization, LDAP, Shibboleth, fixed password).
17
// Password authorization can optionally be disabled.
18
19
require_once 'globals.php';
20
debug('login.php: begin');
21
22
require_once 'i12n.php';
23
require_once 'DBConnector.class.php';
24
25
$dbcon = palma\DBConnector::getInstance();
26
27
$errtext = false;
28
29
$username = '';
30
$pin = '';
31
$posted_pin = '';
32
if (isset($_REQUEST['pin'])) {
33
  $posted_pin = escapeshellcmd($_REQUEST['pin']);
34
}
35
36
monitor("login.php: page loaded");
37
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
38
  session_start();
39
  $username = escapeshellcmd($_POST['username']);
40
  $password = '';
41
  if (CONFIG_PASSWORD) {
42
    // The password must not be escaped.
43
    $password = $_POST['userpassword'];
44
  }
45
  if (CONFIG_PIN) {
46
    $posted_pin = escapeshellcmd($_POST['pin']);
47
    $pin = $dbcon->querySingle("SELECT value FROM setting WHERE key = 'pin'");
48
  }
49
50
  if (CONFIG_PASSWORD && !checkCredentials($username, $password)) {
51
    monitor("login.php: access denied for user '$username'");
52
    // Invalid username or password.
53
  } elseif (CONFIG_PIN && ($pin != $posted_pin)) {
54
    monitor("login.php: access denied for user '$username': invalid pin");
55
    debug("login.php: access denied for user '$username', wrong pin $posted_pin");
56
    $errtext = addslashes(__('Invalid PIN.'));
0 ignored issues
show
The function __ was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

56
    $errtext = addslashes(/** @scrutinizer ignore-call */ __('Invalid PIN.'));
Loading history...
57
  } else {
58
    // Successfully checked username, password and PIN.
59
    monitor("login.php: access granted for user '$username'");
60
    debug("login.php: access granted for user '$username'");
61
    $_SESSION['username'] = $username;
62
    $_SESSION['address'] = $dbcon->ipAddress();
63
    $_SESSION['pin'] = $pin;
64
    $_SESSION['starturl'] = CONFIG_START_URL;
65
    $_SESSION['monitor'] = CONFIG_STATIONNAME;
66
    $dbcon->addUser($username, $dbcon->ipAddress(), getDevice());
67
68
    // Weiterleitung zur geschützten Startseite
69
    if ($_SERVER['SERVER_PROTOCOL'] == 'HTTP/1.1') {
70
      if (php_sapi_name() == 'cgi') {
71
        header('Status: 303 See Other');
72
      } else {
73
        header('HTTP/1.1 303 See Other');
74
      }
75
    }
76
    debug('login.php: ' . CONFIG_START_URL);
77
    header('Location: ' . CONFIG_START_URL);
78
    exit;
79
  }
80
}
81
?>
82
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
83
          "http://www.w3.org/TR/html4/strict.dtd">
84
85
<html lang="de">
86
87
  <head>
88
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
89
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
90
    <meta name="viewport" content="width=device-width, initial-scale=1">
91
    <title><?=addslashes(__("PalMA &ndash; Login"))?></title>
92
93
    <link rel="icon" href="theme/<?=CONFIG_THEME?>/favicon.ico" type="image/x-icon">
94
    <link rel="stylesheet" href="font-awesome/css/font-awesome.min.css">
95
    <link rel="stylesheet" href="pure-min.css">
96
    <link rel="stylesheet" href="palma.css">
97
98
  </head>
99
100
  <!--
101
102
       Copyright (C) 2014 Stefan Weil, Universitätsbibliothek Mannheim
103
104
       TODO:
105
       * Use 'placeholder' attribute for input fields.
106
107
  -->
108
109
  <body onLoad="document.forms.auth.username.focus()">
110
    <div id="login_mask">
111
112
      <form name="auth" class="pure-form pure-form-aligned" action="login.php" method="post">
113
114
        <fieldset class="login">
115
          <legend>
116
            <img src="theme/<?=CONFIG_THEME?>/palma-logo-67x25.png" alt="PalMA" height="25"/>
117
            &ndash; <?=addslashes(__("Login"))?>
118
          </legend>
119
          <div id="login_fields">
120
            <div class="pure-control-group">
121
              <label for="username"><?=addslashes(__("User name"))?></label>
122
              <input id="username" name="username" type="text" value="<?=htmlspecialchars($username)?>">
123
            </div>
124
            <?php
125
            if (CONFIG_PASSWORD) {
126
              ?>
127
              <div class="pure-control-group">
128
                <label for="userpassword"><?=addslashes(__("Password"))?></label>
129
                <input id="userpassword" name="userpassword" type="password">
130
              </div>
131
              <?php
132
            }
133
            if (CONFIG_PIN) {
134
              ?>
135
              <div class="pure-control-group">
136
                <label for="pin"><?=addslashes(__("PIN"))?></label>
137
                <input id="pin" name="pin" type="text" value="<?=htmlspecialchars($posted_pin)?>">
138
              </div>
139
              <?php
140
            }
141
            ?>
142
          </div>
143
          <div class="pure-controls">
144
            <button type="submit" class="pure-button pure-button-primary">
145
              <?=addslashes(__("Log in"))?><i class="fa fa-sign-in"></i>
146
            </button>
147
          </div>
148
        </fieldset>
149
150
      </form>
151
152
      <?php
153
      if ($errtext) {
154
        echo("<p>$errtext</p>");
155
      }
156
      if (defined('CONFIG_POLICY')) {
157
        echo('<div class="policy">' . CONFIG_POLICY . '</div>');
158
      }
159
      ?>
160
161
    </div>
162
163
  </body>
164
</html>
165