2 * Copyright (c) 2017, De Rais <derais@cock.li>
4 * Permission to use, copy, modify, and/or distribute this software for
5 * any purpose with or without fee is hereby granted, provided that the
6 * above copyright notice and this permission notice appear in all
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
10 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
11 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
12 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
13 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
14 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
15 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
16 * PERFORMANCE OF THIS SOFTWARE.
32 const char *program_name
= "rb79-moderate-post";
34 /* Show usage message, do not exit */
37 size_t len
= strlen(program_name
);
39 printf("Usage: %s -b board-name\n", program_name
);
40 printf(" %*s -p post-id\n", (int) len
, "");
41 printf(" %*s [ -a message ]\n", (int) len
, "");
42 printf(" %*s [ -s | -S ] # Sticky or unsticky\n", (int) len
,
44 printf(" %*s [ -c | -C ] # Close or unclose\n", (int) len
, "");
48 int main(int argc
, char **argv
)
51 struct configuration conf
= { 0 };
53 const char *b_arg
= 0;
55 const char *p_arg
= 0;
56 uintmax_t post_id
= 0;
57 const char *a_arg
= 0;
58 uint_fast8_t must_sticky
= 0;
59 uint_fast8_t must_unsticky
= 0;
60 uint_fast8_t must_close
= 0;
61 uint_fast8_t must_unclose
= 0;
62 uint_fast8_t actually_is_op
= 0;
64 setlocale(LC_ALL
, "");
67 while ((opt
= getopt(argc
, argv
, "b:p:a:sScC")) != -1) {
72 ERROR_MESSAGE("-b already specified");
81 ERROR_MESSAGE("-p already specified");
90 ERROR_MESSAGE("-a already specified");
122 ERROR_MESSAGE("-s and -S are mutually exclusive");
128 ERROR_MESSAGE("-c and -C are mutually exclusive");
132 conf
= (struct configuration
) {
134 .static_www_folder
= static_www_folder
, /* */
135 .work_path
= work_path
, /* */
136 .trip_salt
= trip_salt
, /* */
137 .trip_salt_len
= strlen(trip_salt
), /* */
138 .boards
= boards
, /* */
139 .boards_num
= NUM_OF(boards
), /* */
140 .max_form_data_size
= max_form_data_size
, /* */
141 .max_file_size
= max_file_size
, /* */
142 .max_text_len
= max_text_len
, /* */
143 .filetypes
= filetypes
, /* */
144 .filetypes_num
= NUM_OF(filetypes
), /* */
145 .file_description_prog
= file_description_prog
, /* */
146 .headers
= headers
, /* */
147 .headers_num
= NUM_OF(headers
), /* */
148 .challenges
= challenges
, /* */
149 .challenges_num
= NUM_OF(challenges
), /* */
150 .wordfilter_inputs
= wordfilter_inputs
, /* */
151 .wordfilter_inputs_num
= NUM_OF(wordfilter_inputs
), /* */
154 /* Interpret board */
155 board_idx
= (size_t) -1;
157 for (size_t j
= 0; j
< conf
.boards_num
; ++j
) {
158 if (!strcmp(conf
.boards
[j
].name
, b_arg
)) {
163 if (board_idx
== (size_t) -1) {
164 ERROR_MESSAGE("No board \"%s\" known", b_arg
);
170 post_id
= strtoull(p_arg
, 0, 0);
174 PERROR_MESSAGE("strtoull");
178 /* Set up a minimal part of the system */
179 if (setup_locks(&conf
) < 0) {
183 if (setup_dbs(&conf
) < 0) {
187 if (setup_write_thread(&conf
) < 0) {
191 if (db_is_op(board_idx
, post_id
, &actually_is_op
) < 0) {
195 if (!actually_is_op
&&
200 ERROR_MESSAGE("Board /%s/, post %ju is not an OP, "
201 "cannot apply -s, -S, -C, -c",
202 conf
.boards
[board_idx
].name
,
207 if (db_moderate_post(board_idx
, post_id
, a_arg
, (must_sticky
||
209 must_sticky
, (must_close
||
220 clean_write_thread();