-
Notifications
You must be signed in to change notification settings - Fork 1
/
init.php
executable file
·73 lines (57 loc) · 1.5 KB
/
init.php
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
#!/usr/bin/php
<?php
/**
* Initialise the System
*
* SPDX-License-Identifier: MIT
*/
$config_file = sprintf('%s/etc/config.php', __DIR__);
if (is_file($config_file)) {
echo "Already Configured\n";
exit(1);
}
touch($config_file);
require_once(__DIR__ . '/boot.php');
$raw = sodium_crypto_box_keypair();
$pk0 = sodium_crypto_box_publickey($raw);
$sk0 = sodium_crypto_box_secretkey($raw);
$pk0b64 = enb64($pk0);
$sk0b64 = enb64($sk0);
$config_text = <<<TXT
<?php
/**
* OpenTHC Pub Configuration
*/
\$ret = [];
\$ret['app'] = [
'base' => '$argv[1]'
];
\$ret['pub'] = [
'public' => '$pk0b64',
'secret' => '$sk0b64',
];
return \$ret;
TXT;
file_put_contents($config_file, $config_text);
$dbc = new \Edoceo\Radix\DB\SQL(sprintf('sqlite:%s/var/pub.sqlite', __DIR__));
$dbc->query('CREATE TABLE account (id PRIMARY KEY, created_at TEXT DEFAULT CURRENT_TIMESTAMP, link, body, meta)');
$dbc->insert('account', [
'id' => $pk0b64,
'link' => '/pk',
'body' => 'This is the account for the Site Operator',
]);
$dbc->query('CREATE TABLE message (id PRIMARY KEY, created_at TEXT DEFAULT CURRENT_TIMESTAMP, pk_source, pk_target, nonce, crypt)');
# sqlite3 $FILE <EOF
# CREATE TRIGGER update_at_now BEFORE INSERT UPDATE ON account
# BEGIN
# NEW.updated_at = now();
# END;
# EOF
# sqlite3 $FILE <EOF
# CREATE TRIGGER update_at_now BEFORE INSERT UPDATE ON message
# BEGIN
# NEW.updated_at = now();
# END;
# EOF
chown(sprintf('%s/var/pub.sqlite', __DIR__), 'www-data');
chgrp(sprintf('%s/var/pub.sqlite', __DIR__), 'www-data');