-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathinstall.php
More file actions
77 lines (75 loc) · 2.48 KB
/
install.php
File metadata and controls
77 lines (75 loc) · 2.48 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
<?php
if (!defined('SP_ENDUSER')) die('File not included');
$title = 'Install';
require_once('inc/header.php');
require_once('inc/core.php');
$ok = true;
?>
</div>
<div style="padding: 10px;">
<?php
if (empty($settings['node'])) {
$ok = false;
?>
<p><strong>ERROR:</strong> No system node(s)</p>
<?php } ?>
<?php
if (!isset($settings['api-key'])) {
?>
<p><em>WARNING:</em> No api-key, dynamic user creation and black/whitelist lookups will not work until you specify one.</p>
<?php } else { ?>
<p><em>INFO:</em> The trigger URL for this setup is <tt><?php p(self_url()); ?>api.php?api-key=<i>secret-api-key</i></tt>.</p>
<?php } ?>
<?php
if (empty($settings['authentication'])) {
$ok = false;
?>
<p><strong>ERROR:</strong> No authentication sources</p>
<?php } ?>
<?php
if (isset($settings['database']['dsn'])) {
?>
<p>
<?php
$notes = array();
try {
$dbh = new PDO($settings['database']['dsn'], $settings['database']['user'], $settings['database']['password']);
$statement = $dbh->prepare('SELECT * FROM users LIMIT 1;');
if (!$statement || $statement->execute() === false) {
$notes[] = 'Adding table users';
$dbh->exec('CREATE TABLE users (username VARCHAR(128), password TEXT, reset_password_token TEXT, reset_password_timestamp INTEGER, PRIMARY KEY(username));');
}
$statement = $dbh->prepare('SELECT * FROM users_relations LIMIT 1;');
if (!$statement || $statement->execute() === false) {
$notes[] = 'Adding table users_relations';
$dbh->exec('CREATE TABLE users_relations (username VARCHAR(128) REFERENCES users(username) ON DELETE CASCADE, type VARCHAR(32), access VARCHAR(128), PRIMARY KEY(username, type, access));');
}
$statement = $dbh->prepare('SELECT * FROM bwlist LIMIT 1;');
if (!$statement || $statement->execute() === false) {
$notes[] = 'Adding table bwlist';
$dbh->exec('CREATE TABLE bwlist (access VARCHAR(128), type VARCHAR(32), value VARCHAR(128), PRIMARY KEY(access, type, value));');
}
if (!empty($notes))
echo 'Database<ul><li>'.implode($notes, '<li>').'</ul>';
} catch (PDOException $e) {
$ok = false;
echo "<p><b>Database error: ".$e->getMessage()."</b></p>";
}
} else {
echo "<em>WARNING:</em> No database. Database users and black/whitelist will not be available until created.";
}
?>
</p>
<?php if ($ok) { ?>
<p>
<strong>You should now remove install.php to proceed.</strong>
</p>
<?php } else { ?>
<p>
<strong>System configuration is incomplete. Edit settings.php</strong>
</p>
<?php } ?>
</div>
<?php
require_once('inc/footer.php');
?>