-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmysql.sql
More file actions
207 lines (166 loc) · 6.73 KB
/
mysql.sql
File metadata and controls
207 lines (166 loc) · 6.73 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
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";
--
-- Base de données: `ressi`
--
CREATE USER 'ctf'@'localhost' IDENTIFIED BY 'ctf';
CREATE DATABASE `ctf` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
GRANT ALL PRIVILEGES ON ctf. * TO 'ctf'@'localhost';
USE `ctf`;
-- --------------------------------------------------------
--
-- Structure de la table `ctf_log`
--
CREATE TABLE IF NOT EXISTS `ctf_log` (
`timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`ip_src` varchar(50) NOT NULL DEFAULT '-1',
`user_id` int(11) NOT NULL DEFAULT '-1',
`is_auth` int(11) NOT NULL DEFAULT '-1',
`is_admin` int(11) NOT NULL DEFAULT '-1',
`php_session` varchar(50) NOT NULL DEFAULT '-1',
`get` text NOT NULL,
`post` text NOT NULL,
`URI` text NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
-- --------------------------------------------------------
--
-- Structure de la table `ctf_people`
--
CREATE TABLE IF NOT EXISTS `ctf_people` (
`people_id` int(11) NOT NULL AUTO_INCREMENT,
`user_id` int(11) NOT NULL,
`university` varchar(50) NOT NULL,
`cursus` varchar(50) NOT NULL,
`firstname` varchar(50) NOT NULL,
`lastname` varchar(50) NOT NULL,
`email` varchar(50) NOT NULL,
PRIMARY KEY (`people_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=37 ;
--
-- Structure de la table `ctf_reports`
--
CREATE TABLE IF NOT EXISTS `ctf_reports` (
`report_id` int(11) NOT NULL AUTO_INCREMENT,
`user_id` int(11) NOT NULL,
`service_id` int(11) NOT NULL,
`time_submitted` datetime NOT NULL,
`time_graded` datetime NOT NULL,
`details` text NOT NULL,
`quick_grade` int(11) NOT NULL DEFAULT '-1',
`final_grade` int(11) NOT NULL DEFAULT '-1',
`previous_id` int(11) NOT NULL DEFAULT '-1',
`graded_by` varchar(50) NOT NULL,
`name` text NOT NULL,
`solution` text NOT NULL,
PRIMARY KEY (`report_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=109 ;
-- --------------------------------------------------------
--
-- Structure de la table `ctf_services`
--
CREATE TABLE IF NOT EXISTS `ctf_services` (
`service_id` int(11) NOT NULL AUTO_INCREMENT,
`service_name` varchar(50) NOT NULL,
`service_patch` text,
PRIMARY KEY (`service_id`),
UNIQUE KEY `uid` (`service_id`,`service_name`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=16 ;
--
-- Contenu de la table `ctf_services`
--
INSERT INTO `ctf_services` (`service_id`, `service_name`, `service_patch`) VALUES
(-1, 'undef', ''),
(1, 'Le point 1', ''),
(2, 'Le point 2', '');
-- --------------------------------------------------------
--
-- Structure de la table `ctf_users`
--
CREATE TABLE IF NOT EXISTS `ctf_users` (
`user_id` int(11) NOT NULL AUTO_INCREMENT,
`user_name` varchar(50) NOT NULL,
`email` varchar(100) NOT NULL,
`password` varchar(50) NOT NULL,
`is_admin` tinyint(1) NOT NULL DEFAULT '0',
`is_local` tinyint(1) NOT NULL,
PRIMARY KEY (`user_id`),
UNIQUE KEY `user_name` (`user_name`,`email`),
UNIQUE KEY `user_name_2` (`user_name`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=66 ;
--
-- Contenu de la table `ctf_users`
--
INSERT INTO `ctf_users` (`user_id`, `user_name`, `email`, `password`, `is_admin`, `is_local`) VALUES
(40, 'Profs', 'profs@profs.fr', '*81F5E21E35407D884A6CD4A731AEBFB6AF209E1B', 1, 1);
-- --------------------------------------------------------
--
-- Doublure de structure pour la vue `ctf_v_achievements`
--
CREATE TABLE IF NOT EXISTS `ctf_v_achievements` (
`user_id` int(11)
,`service_id` int(11)
,`Max` int(11)
);
-- --------------------------------------------------------
--
-- Doublure de structure pour la vue `ctf_v_completedservices`
--
CREATE TABLE IF NOT EXISTS `ctf_v_completedservices` (
`service_id` int(11)
,`nbcomplete` bigint(21)
);
-- --------------------------------------------------------
--
-- Doublure de structure pour la vue `ctf_v_partialservices`
--
CREATE TABLE IF NOT EXISTS `ctf_v_partialservices` (
`service_id` int(11)
,`nbpartial` bigint(21)
);
-- --------------------------------------------------------
--
-- Doublure de structure pour la vue `ctf_v_scores`
--
CREATE TABLE IF NOT EXISTS `ctf_v_scores` (
`user_id` int(11)
,`score` decimal(32,0)
);
-- --------------------------------------------------------
--
-- Doublure de structure pour la vue `ctf_v_servicesstats`
--
CREATE TABLE IF NOT EXISTS `ctf_v_servicesstats` (
`service_id` int(11)
,`nbcomplete` bigint(20)
,`nbpartial` bigint(20)
);
-- --------------------------------------------------------
--
-- Structure de la vue `ctf_v_achievements`
--
DROP TABLE IF EXISTS `ctf_v_achievements`;
CREATE VIEW `ctf_v_achievements` AS select `ctf_users`.`user_id` AS `user_id`,`ctf_reports`.`service_id` AS `service_id`,max(`ctf_reports`.`quick_grade`) AS `Max` from (`ctf_users` join `ctf_reports` on((`ctf_reports`.`user_id` = `ctf_users`.`user_id`))) where (`ctf_reports`.`quick_grade` <> -(1)) group by `ctf_users`.`user_id`,`ctf_reports`.`service_id`;
-- --------------------------------------------------------
--
-- Structure de la vue `ctf_v_completedservices`
--
DROP TABLE IF EXISTS `ctf_v_completedservices`;
CREATE VIEW `ctf_v_completedservices` AS select `ctf_v_achievements`.`service_id` AS `service_id`,count(0) AS `nbcomplete` from `ctf_v_achievements` where (`ctf_v_achievements`.`Max` = 2) group by `ctf_v_achievements`.`service_id`;
-- --------------------------------------------------------
--
-- Structure de la vue `ctf_v_partialservices`
--
DROP TABLE IF EXISTS `ctf_v_partialservices`;
CREATE VIEW `ctf_v_partialservices` AS select `ctf_v_achievements`.`service_id` AS `service_id`,count(0) AS `nbpartial` from `ctf_v_achievements` where (`ctf_v_achievements`.`Max` = 1) group by `ctf_v_achievements`.`service_id`;
-- --------------------------------------------------------
--
-- Structure de la vue `ctf_v_scores`
--
DROP TABLE IF EXISTS `ctf_v_scores`;
CREATE VIEW `ctf_v_scores` AS select `ctf_users`.`user_id` AS `user_id`,coalesce(sum(`ctf_v_achievements`.`Max`),0) AS `score` from (`ctf_users` left join `ctf_v_achievements` on((`ctf_users`.`user_id` = `ctf_v_achievements`.`user_id`))) where (`ctf_users`.`is_admin` <> 1) group by `ctf_users`.`user_id` order by coalesce(sum(`ctf_v_achievements`.`Max`),0) desc;
-- --------------------------------------------------------
--
-- Structure de la vue `ctf_v_servicesstats`
--
DROP TABLE IF EXISTS `ctf_v_servicesstats`;
CREATE VIEW `ctf_v_servicesstats` AS select `ctf_services`.`service_id` AS `service_id`,coalesce(`ctf_v_completedservices`.`nbcomplete`,0) AS `nbcomplete`,coalesce(`ctf_v_partialservices`.`nbpartial`,0) AS `nbpartial` from ((`ctf_services` left join `ctf_v_partialservices` on((`ctf_v_partialservices`.`service_id` = `ctf_services`.`service_id`))) left join `ctf_v_completedservices` on((`ctf_v_completedservices`.`service_id` = `ctf_services`.`service_id`)));