Repository navigation
Expand file tree
/
Copy pathaccounts.php
More file actions
85 lines (81 loc) · 4.69 KB
/
Copy pathaccounts.php
File metadata and controls
85 lines (81 loc) · 4.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<?php
function page_accounts($rights)
{
global $dbconn;
// Read once: an own password change ends the session (users.cookie), and
// the page still lists the own account afterwards.
$ownId = checklogin('id');
if (isset($_POST['submit'])) {
$parts = explode(" ", $_POST['submit']);
if (count($parts) == 3) {
$id = intval($parts[1]);
$rights = write_rights($rights);
if ($rights === false || $id != $ownId && !has_right($rights, 'root')) {
echo '<div class="slot_error" id="slot_error">FEHLER: Keine Zugriffsrechte.</div><br /><br /><br />';
return;
}
// New passwords need 12 characters (UTF-8); "******" keeps the
// stored password. Login does not check the length. A refused
// password saves nothing; the form is shown again.
$rawPass = isset($_POST["password$id"]) && is_string($_POST["password$id"]) ? $_POST["password$id"] : '';
$tooShort = $rawPass !== "******" && mb_strlen($rawPass, 'UTF-8') < 12;
if ($tooShort) {
echo '<div class="slot_error" id="slot_error">FEHLER: Das Passwort muss mindestens 12 Zeichen lang sein.</div><br />';
}
$pass = pg_escape_string($dbconn, $rawPass);
$name = isset($_POST["name$id"]) ? pg_escape_string($dbconn, $_POST["name$id"]) : '';
$nrights = isset($_POST["rights$id"]) ? pg_escape_string($dbconn, $_POST["rights$id"]) : '';
if ($tooShort) {
$query = "SELECT 1";
} elseif (has_right($rights, 'root') && $id == -1) {
if ($pass != "******") {
$query = "INSERT INTO users (name,hash,rights) VALUES ('$name', crypt('$pass', gen_salt('bf', 10)), '$nrights');";
} else {
$query = "SELECT 1";
}
} elseif (!has_right($rights, 'root') && $pass != "******") {
$query = "UPDATE users SET hash = crypt('$pass', gen_salt('bf', 10)), cookie = NULL WHERE id = $id";
} elseif (has_right($rights, 'root')) {
$query = "UPDATE users SET rights = '$nrights'" . ($pass != "******" ? ", hash = crypt('$pass', gen_salt('bf', 10)), cookie = NULL" : "") . " WHERE id = $id";
} else {
echo '<div class="slot_error" id="slot_error">FEHLER: Keine Zugriffsrechte.</div><br /><br /><br />';
return;
}
$result = pg_query($dbconn, $query) or die('Abfrage fehlgeschlagen: ' . html_escape(pg_last_error($dbconn)));
while ($line = pg_fetch_array($result, null, PGSQL_ASSOC)) {
}
pg_free_result($result);
}
}
echo '<h1>Benutzerverwaltung:</h1><br>';
if (has_right($rights, 'root')) {
echo '<p>1: Burgenland, 2: Kärnten, 3: Niederösterreich, 4: Oberösterreich, 5: Salzburg, 6: Steiermark, 8: Vorarlberg, 9: Wien, 10: Bund (only), bgf: Alles</p>';
echo '<p>Ein vorgestelltes R erzeugt einen read only Zugang. Beispiel: Rbgf. root hat Möglichkeit Buchungen zu mergen, sowie gelöschte Buchungszeilen wiederherzustellen</p>';
// For migrate-receipt-key.php --key-fingerprint (UPGRADING.md): a
// fingerprint of the configured key, never the key itself.
echo receipt_key_notice(receipt_configured_key());
}
block_start();
echo '<form action="index.php?action=accounts" method="POST">' . csrf_field() . '<table>
<tr><td><b>Name</b></td><td><b>Passwort</b> (mindestens 12 Zeichen)</td>' . (has_right($rights, 'root') ? '<td><b>Rechte</b></td>' : '') . '</tr>
';
$id = $ownId;
$restrict = "";
if (!has_right($rights, 'root')) {
$restrict = " WHERE id = $id ";
}
$query = "SELECT * FROM users $restrict ORDER BY rights DESC,id ASC";
$result = db_query($dbconn, $query);
while ($line = pg_fetch_array($result, null, PGSQL_ASSOC)) {
$i = $line['id'];
echo '<tr><td>' . html_escape($line['name']) . '</td><td><input type="password" name="password' . $i . '" value="******"></td>' . (has_right($rights, 'root') ? '<td><input type="text" name="rights' . $i . '" value="' . html_escape($line['rights']) . '" /></td>' : '') . '<td><input type="submit" name="submit" value="Benutzer ' . $i . ' aktualisieren" /></td></tr>' . "\n";
}
pg_free_result($result);
if (has_right($rights, 'root')) {
echo '<tr><td><input type="text" name="name-1" value="" /></td><td><input type="password" name="password-1" value="******"></td><td><input type="text" name="rights-1" value="" /></td><td><input type="submit" name="submit" value="Benutzer -1 erstellen" /></td></tr>' . "\n";
}
echo '
</table></form>
';
block_end();
}