-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathinstall.php
executable file
·145 lines (128 loc) · 4.13 KB
/
install.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
<?php
require_once('util4p/util.php');
require_once('util4p/CRObject.class.php');
require_once('Code.class.php');
require_once('util4p/MysqlPDO.class.php');
require_once('util4p/SQLBuilder.class.php');
require_once('util4p/Random.class.php');
require_once('UserManager.class.php');
require_once('config.inc.php');
require_once('init.inc.php');
/* show error for debug purpose */
$config = new CRObject();
$config->set('show_error', true);
MysqlPDO::configure($config);
create_tables_user();
create_tables_oauth();
create_tables_log();
add_root_user();
function execute_sqls($sqls)
{
foreach ($sqls as $description => $sql) {
echo "Executing $description: ";
$success = (new MysqlPDO)->execute($sql, array());
echo $success ? '<em>Success</em>' : '<em>Failed</em>';
echo "<hr/>";
}
}
function add_root_user()
{
$password = Random::randomString(12);
echo "Adding root user with (root,$password) \n";
/* pseudo encryption in client side */
$password = md5($password . 'QuickAuth');
$password = md5($password . 'newnius');
$password = md5($password . 'com');
$password = password_hash($password, PASSWORD_DEFAULT);
$user = new CRObject();
$user->set('username', 'root');
$user->set('email', '[email protected]');
$user->set('password', $password);
$user->set('role', 'root');
$success = UserManager::add($user);
echo $success ? '<em>Success</em>' : '<em>Failed</em>';
echo "<hr/>";
}
function create_tables_user()
{
$sqls = array(
// 'DROP `qa_user`' => 'DROP TABLE IF EXISTS `qa_user`',
'CREATE `qa_user`' =>
'CREATE TABLE `qa_user`(
`username` VARCHAR(12) PRIMARY KEY,
`password` CHAR(255) NOT NULL,
`email` VARCHAR(45) NOT NULL UNIQUE,
INDEX(`email`),
`email_verified` TINYINT NOT NULL DEFAULT 0,
`role` VARCHAR(12) NOT NULL,
`reg_time` BIGINT,
`reg_ip` BIGINT
)ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE utf8mb4_general_ci'
);
execute_sqls($sqls);
}
function create_tables_oauth()
{
$sqls = array(
// 'DROP `qa_oauth_client`' => 'DROP TABLE IF EXISTS `qa_oauth_client`',
'CREATE `qa_oauth_client`' =>
'CREATE TABLE `qa_oauth_client`(
`client_id` VARCHAR(16) PRIMARY KEY,
`client_secret` CHAR(64) NOT NULL,
`domain` VARCHAR(64) NOT NULL,
`owner` VARCHAR(12) NOT NULL,
INDEX(`owner`)
)ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE utf8mb4_general_ci',
// 'DROP `qa_oauth_openid`' => 'DROP TABLE IF EXISTS `qa_oauth_openid`',
'CREATE `qa_oauth_openid`' =>
'CREATE TABLE `qa_oauth_openid`(
`open_id` VARCHAR(64) PRIMARY KEY,
`uid` VARCHAR(12) NOT NULL,
`client_id` CHAR(16) NOT NULL,
UNIQUE(`uid`, `client_id`)
)ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE utf8mb4_general_ci',
// 'DROP `qa_oauth_code`' => 'DROP TABLE IF EXISTS `qa_oauth_code`',
'CREATE `qa_oauth_code`' =>
'CREATE TABLE `qa_oauth_code`(
`code` VARCHAR(64) PRIMARY KEY,
`client_id` CHAR(16) NOT NULL,
`open_id` VARCHAR(64) NOT NULL,
`expires` BIGINT NOT NULL DEFAULT 0,
`redirect_uri` VARCHAR(256) NOT NULL,
`scope` VARCHAR(256) NOT NULL DEFAULT ""
)ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE utf8mb4_general_ci',
// 'DROP `qa_oauth_token`' => 'DROP TABLE IF EXISTS `qa_oauth_token`',
'CREATE `qa_oauth_token`' =>
'CREATE TABLE `qa_oauth_token`(
`token` VARCHAR(64) PRIMARY KEY,
`client_id` CHAR(16) NOT NULL,
`open_id` VARCHAR(64) NOT NULL,
INDEX(`client_id`, `open_id`),
`expires` BIGINT NOT NULL DEFAULT 0,
`scope` VARCHAR(256) NOT NULL DEFAULT ""
)ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE utf8mb4_general_ci',
);
execute_sqls($sqls);
}
function create_tables_log()
{
$sqls = array(
// 'DROP `qa_log`' => 'DROP TABLE IF EXISTS `qa_log`',
'CREATE `qa_log`' =>
'CREATE TABLE `qa_log`(
`id` BIGINT AUTO_INCREMENT,
PRIMARY KEY(`id`),
`scope` VARCHAR(128) NOT NULL,
INDEX(`scope`),
`tag` VARCHAR(128) NOT NULL,
INDEX(`tag`),
`level` INT NOT NULL, /* too small value sets, no need to index */
`time` BIGINT NOT NULL,
INDEX(`time`),
`ip` BIGINT NOT NULL,
INDEX(`ip`),
`content` json
)ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE utf8mb4_general_ci'
);
execute_sqls($sqls);
}