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

Annotation of /lbbs/src/menu_proc.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.51 - (hide annotations)
Tue Nov 11 10:54:22 2025 UTC (4 months ago) by sysadm
Branch: MAIN
Changes since 1.50: +10 -0 lines
Content type: text/x-csrc
User edit self-defined signatures

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

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