/[LeafOK_CVS]/lbbs/src/menu_proc.c
ViewVC logotype

Contents of /lbbs/src/menu_proc.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.57 - (show annotations)
Mon Dec 1 11:28:03 2025 UTC (3 months, 2 weeks ago) by sysadm
Branch: MAIN
Changes since 1.56: +7 -0 lines
Content type: text/x-csrc
Add "End-User License Agreement" (EULA)

1 /* SPDX-License-Identifier: GPL-3.0-or-later */
2 /*
3 * menu_proc
4 * - handler functions of menu commands
5 *
6 * Copyright (C) 2004-2025 Leaflet <leaflet@leafok.com>
7 */
8
9 #ifdef HAVE_CONFIG_H
10 #include "config.h"
11 #endif
12
13 #include "article_cache.h"
14 #include "article_favor_display.h"
15 #include "article_view_log.h"
16 #include "bbs.h"
17 #include "bbs_cmd.h"
18 #include "bbs_net.h"
19 #include "chicken.h"
20 #include "common.h"
21 #include "io.h"
22 #include "log.h"
23 #include "login.h"
24 #include "menu.h"
25 #include "section_list_display.h"
26 #include "screen.h"
27 #include "user_info_update.h"
28 #include "user_list_display.h"
29 #include "user_priv.h"
30 #include <ctype.h>
31 #include <dlfcn.h>
32 #include <errno.h>
33 #include <signal.h>
34 #include <stdlib.h>
35 #include <string.h>
36 #include <time.h>
37 #include <unistd.h>
38 #include <sys/types.h>
39
40 int list_section(void *param)
41 {
42 section_list_display(param, 0);
43
44 return REDRAW;
45 }
46
47 typedef union exec_handler_t
48 {
49 void *p;
50 int (*handler)();
51 } exec_handler;
52
53 int exec_mbem(void *param)
54 {
55 void *hdll;
56 exec_handler func;
57 char *c, *s;
58 char buf[FILE_PATH_LEN];
59
60 strncpy(buf, (const char *)param, sizeof(buf) - 1);
61 buf[sizeof(buf) - 1] = '\0';
62
63 s = strstr(buf, "@mod:");
64 if (s)
65 {
66 c = strstr(s + 5, "#");
67 if (c)
68 {
69 *c = 0;
70 c++;
71 }
72
73 #ifdef _ENABLE_SHARED
74 hdll = dlopen(s + 5, RTLD_LAZY);
75
76 if (hdll)
77 {
78 char *error;
79
80 if ((func.p = dlsym(hdll, c ? c : "mod_main")) != NULL)
81 {
82 func.handler();
83 }
84 else if ((error = dlerror()) != NULL)
85 {
86 clearscr();
87 prints("%s\r\n", error);
88 press_any_key();
89 }
90 dlclose(hdll);
91 }
92 else
93 {
94 clearscr();
95 prints("加载库文件 [%s] 失败!!\r\n", s + 5);
96 prints("失败原因:%s\r\n", dlerror());
97 press_any_key();
98 }
99 #else
100 (void)hdll;
101 (void)func;
102
103 if (strcasecmp(c, "bbs_net") == 0)
104 {
105 bbs_net();
106 }
107 else if (strcasecmp(c, "chicken_main") == 0)
108 {
109 chicken_main();
110 }
111 else
112 {
113 clearscr();
114 prints("未知入口 [%s] !!\r\n", c);
115 press_any_key();
116 }
117 #endif
118 }
119
120 return REDRAW;
121 }
122
123 int exit_bbs(void *param)
124 {
125 return EXITBBS;
126 }
127
128 int eula(void *param)
129 {
130 display_file(DATA_EULA, 0);
131
132 return REDRAW;
133 }
134
135 int license(void *param)
136 {
137 display_file(DATA_LICENSE, 0);
138
139 return REDRAW;
140 }
141
142 int copyright(void *param)
143 {
144 display_file(DATA_COPYRIGHT, 1);
145
146 return REDRAW;
147 }
148
149 int version(void *param)
150 {
151 display_file(DATA_VERSION, 1);
152
153 return REDRAW;
154 }
155
156 int reload_bbs_conf(void *param)
157 {
158 clearscr();
159
160 if (kill(getppid(), SIGHUP) < 0)
161 {
162 log_error("Send SIGHUP signal failed (%d)\n", errno);
163
164 prints("发送指令失败\r\n");
165 }
166 else
167 {
168 prints("已发送指令\r\n");
169 }
170
171 press_any_key();
172
173 return REDRAW;
174 }
175
176 int shutdown_bbs(void *param)
177 {
178 char buf[2] = "N";
179
180 clearscr();
181 get_data(1, 1, "真的要关闭系统吗[y/N]? ", buf, sizeof(buf), 1);
182
183 if (toupper(buf[0]) == 'Y')
184 {
185 log_common("Notify main process to exit by [%s]\n", BBS_username);
186
187 if (kill(getppid(), SIGTERM) < 0)
188 {
189 log_error("Send SIGTERM signal failed (%d)\n", errno);
190 }
191 }
192
193 return REDRAW;
194 }
195
196 int favor_section_filter(void *param)
197 {
198 MENU_ITEM *p_menu_item = param;
199
200 return (is_favor(&BBS_priv, p_menu_item->priv) && checklevel2(&BBS_priv, p_menu_item->level));
201 }
202
203 static int display_ex_article_key_handler(int *p_key, DISPLAY_CTX *p_ctx)
204 {
205 switch (*p_key)
206 {
207 case 0: // Set msg
208 snprintf(p_ctx->msg, sizeof(p_ctx->msg),
209 "| 返回[\033[32m←\033[33m,\033[32mESC\033[33m] | "
210 "移动[\033[32m↑\033[33m/\033[32m↓\033[33m/\033[32mPgUp\033[33m/\033[32mPgDn\033[33m] | "
211 "帮助[\033[32mh\033[33m] |");
212 break;
213 }
214
215 return 0;
216 }
217
218 int view_ex_article(void *param)
219 {
220 ARTICLE_CACHE cache;
221 ARTICLE *p_article;
222 int32_t aid = atoi(param);
223 int ret;
224
225 (void)ret;
226
227 p_article = article_block_find_by_aid(aid);
228 if (p_article == NULL)
229 {
230 log_error("article_block_find_by_aid(%d) error\n", aid);
231 return NOREDRAW;
232 }
233
234 if (article_cache_load(&cache, VAR_ARTICLE_CACHE_DIR, p_article) < 0)
235 {
236 log_error("article_cache_load(aid=%d, cid=%d) error\n", p_article->aid, p_article->cid);
237 return NOREDRAW;
238 }
239
240 if (user_online_update("VIEW_ARTICLE") < 0)
241 {
242 log_error("user_online_update(VIEW_ARTICLE) error\n");
243 }
244
245 ret = display_data(cache.p_data, cache.line_total, cache.line_offsets, 0,
246 display_ex_article_key_handler, DATA_READ_HELP);
247
248 if (article_cache_unload(&cache) < 0)
249 {
250 log_error("article_cache_unload(aid=%d, cid=%d) error\n", p_article->aid, p_article->cid);
251 }
252
253 // Update article_view_log
254 if (article_view_log_set_viewed(p_article->aid, &BBS_article_view_log) < 0)
255 {
256 log_error("article_view_log_set_viewed(aid=%d) error\n", p_article->aid);
257 }
258
259 return REDRAW;
260 }
261
262 int list_ex_section(void *param)
263 {
264 SECTION_LIST *p_section;
265
266 p_section = section_list_find_by_name(param);
267 if (p_section == NULL)
268 {
269 log_error("Section %s not found\n", (const char *)param);
270 return -1;
271 }
272
273 if (section_list_ex_dir_display(p_section) < 0)
274 {
275 log_error("section_list_ex_dir_display(sid=%d) error\n", p_section->sid);
276 }
277
278 return REDRAW;
279 }
280
281 int show_top10_menu(void *param)
282 {
283 static int show_top10 = 0;
284 int ch = 0;
285 int loop;
286
287 if (show_top10)
288 {
289 return NOREDRAW;
290 }
291 show_top10 = 1;
292
293 clearscr();
294 show_top("", BBS_name, "");
295 show_bottom("");
296
297 if (display_menu(&top10_menu) == 0)
298 {
299 for (loop = 1; !SYS_server_exit && loop;)
300 {
301 iflush();
302 ch = igetch(100);
303
304 if (ch != KEY_NULL && ch != KEY_TIMEOUT)
305 {
306 BBS_last_access_tm = time(NULL);
307 }
308
309 switch (ch)
310 {
311 case KEY_NULL: // broken pipe
312 log_error("KEY_NULL\n");
313 loop = 0;
314 break;
315 case KEY_TIMEOUT:
316 if (time(NULL) - BBS_last_access_tm >= BBS_max_user_idle_time)
317 {
318 log_error("User input timeout\n");
319 loop = 0;
320 break;
321 }
322 continue;
323 case CR:
324 default:
325 switch (menu_control(&top10_menu, ch))
326 {
327 case EXITMENU:
328 loop = 0;
329 break;
330 case REDRAW:
331 clearscr();
332 show_bottom("");
333 display_menu(&top10_menu);
334 break;
335 case NOREDRAW:
336 case UNKNOWN_CMD:
337 default:
338 break;
339 }
340 }
341 }
342 }
343
344 show_top10 = 0;
345 return REDRAW;
346 }
347
348 int locate_article(void *param)
349 {
350 char buf[MAX_MENUITEM_NAME_LENGTH];
351 char *sname, *aid, *saveptr;
352
353 strncpy(buf, param, sizeof(buf) - 1);
354 buf[sizeof(buf) - 1] = '\0';
355
356 sname = strtok_r(buf, "|", &saveptr);
357 aid = strtok_r(NULL, "|", &saveptr);
358
359 if (sname == NULL || aid == NULL)
360 {
361 log_error("top10_locate(%s) error: invalid parameter\n", param);
362 return NOREDRAW;
363 }
364
365 section_list_display(sname, atoi(aid));
366
367 return REDRAW;
368 }
369
370 int favor_topic(void *param)
371 {
372 if (article_favor_display(&BBS_article_favor) < 0)
373 {
374 log_error("article_favor_display() error\n");
375 }
376
377 return REDRAW;
378 }
379
380 int list_user(void *param)
381 {
382 if (user_list_display(0) < 0)
383 {
384 log_error("user_list_display(all_user) error\n");
385 }
386
387 return REDRAW;
388 }
389
390 int list_online_user(void *param)
391 {
392 if (user_list_display(1) < 0)
393 {
394 log_error("user_list_display(online_user) error\n");
395 }
396
397 return REDRAW;
398 }
399
400 int edit_intro(void *param)
401 {
402 if (user_intro_edit(BBS_priv.uid) < 0)
403 {
404 log_error("user_intro_edit(%d) error\n", BBS_priv.uid);
405 }
406
407 return REDRAW;
408 }
409
410 int edit_sign(void *param)
411 {
412 if (user_sign_edit(BBS_priv.uid) < 0)
413 {
414 log_error("user_sign_edit(%d) error\n", BBS_priv.uid);
415 }
416
417 return REDRAW;
418 }

webmaster@leafok.com
ViewVC Help
Powered by ViewVC 1.3.0-beta1