-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.php
More file actions
63 lines (57 loc) · 1.64 KB
/
init.php
File metadata and controls
63 lines (57 loc) · 1.64 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
<?php
require_once(__DIR__ . "/config.php");
require_once(__DIR__ . "/vendor/autoload.php");
use Pdsinterop\PhpSolid\Server;
function initKeys() {
$keys = Server::generateKeySet();
file_put_contents(KEYDIR . "public.key", $keys['publicKey']);
file_put_contents(KEYDIR . "private.key", $keys['privateKey']);
file_put_contents(KEYDIR . "encryption.key", $keys['encryptionKey']);
}
function initDatabase() {
$statements = [
'CREATE TABLE IF NOT EXISTS clients (
clientId VARCHAR(255) NOT NULL PRIMARY KEY,
origin TEXT NOT NULL,
clientData TEXT NOT NULL
)',
'CREATE TABLE IF NOT EXISTS allowedClients (
userId VARCHAR(255) NOT NULL PRIMARY KEY,
clientId VARCHAR(255) NOT NULL
)',
'CREATE TABLE IF NOT EXISTS userStorage (
userId VARCHAR(255) NOT NULL PRIMARY KEY,
storageUrl VARCHAR(255) NOT NULL
)',
'CREATE TABLE IF NOT EXISTS verify (
code VARCHAR(255) NOT NULL PRIMARY KEY,
data TEXT NOT NULL
)',
'CREATE TABLE IF NOT EXISTS jti (
jti VARCHAR(255) NOT NULL PRIMARY KEY,
expires TEXT NOT NULL
)',
'CREATE TABLE IF NOT EXISTS users (
user_id VARCHAR(255) NOT NULL PRIMARY KEY,
email TEXT NOT NULL,
password TEXT NOT NULL,
data TEXT
)',
'CREATE TABLE IF NOT EXISTS ipAttempts (
ip VARCHAR(255) NOT NULL,
type VARCHAR(255) NOT NULL,
expires TEXT NOT NULL
)',
];
try {
$pdo = new \PDO("sqlite:" . DBPATH);
// create tables
foreach($statements as $statement){
$pdo->exec($statement);
}
} catch(\PDOException $e) {
echo $e->getMessage();
}
}
initKeys();
initDatabase();