1 |
adx |
30 |
/* |
2 |
|
|
* ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd). |
3 |
|
|
* m_help.c: Provides help information to a user/operator. |
4 |
|
|
* |
5 |
|
|
* Copyright (C) 2002 by the past and present ircd coders, and others. |
6 |
|
|
* |
7 |
|
|
* This program is free software; you can redistribute it and/or modify |
8 |
|
|
* it under the terms of the GNU General Public License as published by |
9 |
|
|
* the Free Software Foundation; either version 2 of the License, or |
10 |
|
|
* (at your option) any later version. |
11 |
|
|
* |
12 |
|
|
* This program is distributed in the hope that it will be useful, |
13 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 |
|
|
* GNU General Public License for more details. |
16 |
|
|
* |
17 |
|
|
* You should have received a copy of the GNU General Public License |
18 |
|
|
* along with this program; if not, write to the Free Software |
19 |
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
20 |
|
|
* USA |
21 |
|
|
* |
22 |
knight |
31 |
* $Id$ |
23 |
adx |
30 |
*/ |
24 |
|
|
|
25 |
|
|
#include "stdinc.h" |
26 |
|
|
#include "handlers.h" |
27 |
|
|
#include "client.h" |
28 |
|
|
#include "ircd.h" |
29 |
|
|
#include "ircd_handler.h" |
30 |
|
|
#include "msg.h" |
31 |
|
|
#include "numeric.h" |
32 |
|
|
#include "send.h" |
33 |
|
|
#include "s_conf.h" |
34 |
|
|
#include "s_log.h" |
35 |
|
|
#include "parse.h" |
36 |
|
|
#include "modules.h" |
37 |
|
|
#include "irc_string.h" |
38 |
|
|
|
39 |
|
|
#define HELPLEN 400 |
40 |
|
|
|
41 |
|
|
static void m_help(struct Client *, struct Client *, int, char *[]); |
42 |
|
|
static void mo_help(struct Client *, struct Client *, int, char *[]); |
43 |
|
|
static void mo_uhelp(struct Client *, struct Client *, int, char *[]); |
44 |
|
|
static void dohelp(struct Client *, const char *, char *); |
45 |
|
|
static void sendhelpfile(struct Client *, const char *, const char *); |
46 |
|
|
|
47 |
|
|
struct Message help_msgtab = { |
48 |
|
|
"HELP", 0, 0, 0, 0, MFLG_SLOW, 0, |
49 |
|
|
{m_unregistered, m_help, m_ignore, m_ignore, mo_help, m_ignore} |
50 |
|
|
}; |
51 |
|
|
|
52 |
|
|
struct Message uhelp_msgtab = { |
53 |
|
|
"UHELP", 0, 0, 0, 0, MFLG_SLOW, 0, |
54 |
|
|
{m_unregistered, m_help, m_ignore, m_ignore, mo_uhelp, m_ignore} |
55 |
|
|
}; |
56 |
|
|
|
57 |
|
|
void |
58 |
|
|
_modinit(void) |
59 |
|
|
{ |
60 |
|
|
mod_add_cmd(&help_msgtab); |
61 |
|
|
mod_add_cmd(&uhelp_msgtab); |
62 |
|
|
} |
63 |
|
|
|
64 |
|
|
void |
65 |
|
|
_moddeinit(void) |
66 |
|
|
{ |
67 |
|
|
mod_del_cmd(&help_msgtab); |
68 |
|
|
mod_del_cmd(&uhelp_msgtab); |
69 |
|
|
} |
70 |
|
|
|
71 |
knight |
31 |
const char *_version = "$Revision$"; |
72 |
adx |
30 |
|
73 |
|
|
/* |
74 |
|
|
* m_help - HELP message handler |
75 |
|
|
* parv[0] = sender prefix |
76 |
|
|
*/ |
77 |
|
|
static void |
78 |
|
|
m_help(struct Client *client_p, struct Client *source_p, |
79 |
|
|
int parc, char *parv[]) |
80 |
|
|
{ |
81 |
|
|
static time_t last_used = 0; |
82 |
|
|
|
83 |
|
|
/* HELP is always local */ |
84 |
|
|
if ((last_used + ConfigFileEntry.pace_wait_simple) > CurrentTime) |
85 |
|
|
{ |
86 |
|
|
/* safe enough to give this on a local connect only */ |
87 |
|
|
sendto_one(source_p,form_str(RPL_LOAD2HI), |
88 |
|
|
me.name, source_p->name); |
89 |
|
|
return; |
90 |
|
|
} |
91 |
|
|
|
92 |
|
|
last_used = CurrentTime; |
93 |
|
|
|
94 |
|
|
dohelp(source_p, UHPATH, parv[1]); |
95 |
|
|
} |
96 |
|
|
|
97 |
|
|
/* |
98 |
|
|
* mo_help - HELP message handler |
99 |
|
|
* parv[0] = sender prefix |
100 |
|
|
*/ |
101 |
|
|
static void |
102 |
|
|
mo_help(struct Client *client_p, struct Client *source_p, |
103 |
|
|
int parc, char *parv[]) |
104 |
|
|
{ |
105 |
|
|
dohelp(source_p, HPATH, parv[1]); |
106 |
|
|
} |
107 |
|
|
|
108 |
|
|
/* |
109 |
|
|
* mo_uhelp - HELP message handler |
110 |
|
|
* This is used so that opers can view the user help file without deopering |
111 |
|
|
* parv[0] = sender prefix |
112 |
|
|
*/ |
113 |
|
|
static void |
114 |
|
|
mo_uhelp(struct Client *client_p, struct Client *source_p, |
115 |
|
|
int parc, char *parv[]) |
116 |
|
|
{ |
117 |
|
|
dohelp(source_p, UHPATH, parv[1]); |
118 |
|
|
} |
119 |
|
|
|
120 |
|
|
static void |
121 |
|
|
dohelp(struct Client *source_p, const char *hpath, char *topic) |
122 |
|
|
{ |
123 |
michael |
575 |
char h_index[] = "index"; |
124 |
adx |
30 |
char path[PATH_MAX + 1]; |
125 |
|
|
struct stat sb; |
126 |
|
|
int i; |
127 |
|
|
|
128 |
|
|
if (topic != NULL) |
129 |
|
|
{ |
130 |
|
|
if (*topic == '\0') |
131 |
michael |
575 |
topic = h_index; |
132 |
adx |
30 |
else |
133 |
|
|
{ |
134 |
|
|
/* convert to lower case */ |
135 |
michael |
575 |
for (i = 0; topic[i] != '\0'; ++i) |
136 |
adx |
30 |
topic[i] = ToLower(topic[i]); |
137 |
|
|
} |
138 |
|
|
} |
139 |
|
|
else |
140 |
michael |
575 |
topic = h_index; /* list available help topics */ |
141 |
adx |
30 |
|
142 |
|
|
if (strpbrk(topic, "/\\")) |
143 |
|
|
{ |
144 |
|
|
sendto_one(source_p, form_str(ERR_HELPNOTFOUND), |
145 |
|
|
me.name, source_p->name, topic); |
146 |
|
|
return; |
147 |
|
|
} |
148 |
|
|
|
149 |
|
|
if (strlen(hpath) + strlen(topic) + 1 > PATH_MAX) |
150 |
|
|
{ |
151 |
|
|
sendto_one(source_p, form_str(ERR_HELPNOTFOUND), |
152 |
|
|
me.name, source_p->name, topic); |
153 |
|
|
return; |
154 |
|
|
} |
155 |
|
|
|
156 |
|
|
snprintf(path, sizeof(path), "%s/%s", hpath, topic); |
157 |
|
|
|
158 |
|
|
if (stat(path, &sb) < 0) |
159 |
|
|
{ |
160 |
|
|
sendto_one(source_p, form_str(ERR_HELPNOTFOUND), |
161 |
|
|
me.name, source_p->name, topic); |
162 |
|
|
return; |
163 |
|
|
} |
164 |
|
|
|
165 |
|
|
if (!S_ISREG(sb.st_mode)) |
166 |
|
|
{ |
167 |
|
|
sendto_one(source_p, form_str(ERR_HELPNOTFOUND), |
168 |
|
|
me.name, source_p->name, topic); |
169 |
|
|
return; |
170 |
|
|
} |
171 |
|
|
|
172 |
|
|
sendhelpfile(source_p, path, topic); |
173 |
|
|
} |
174 |
|
|
|
175 |
|
|
static void |
176 |
|
|
sendhelpfile(struct Client *source_p, const char *path, const char *topic) |
177 |
|
|
{ |
178 |
|
|
FBFILE *file; |
179 |
|
|
char line[HELPLEN]; |
180 |
|
|
char started = 0; |
181 |
|
|
int type; |
182 |
|
|
|
183 |
|
|
if ((file = fbopen(path, "r")) == NULL) |
184 |
|
|
{ |
185 |
|
|
sendto_one(source_p, form_str(ERR_HELPNOTFOUND), |
186 |
|
|
me.name, source_p->name, topic); |
187 |
|
|
return; |
188 |
|
|
} |
189 |
|
|
|
190 |
|
|
if (fbgets(line, sizeof(line), file) == NULL) |
191 |
|
|
{ |
192 |
|
|
sendto_one(source_p, form_str(ERR_HELPNOTFOUND), |
193 |
|
|
me.name, source_p->name, topic); |
194 |
|
|
return; |
195 |
|
|
} |
196 |
|
|
|
197 |
|
|
else if (line[0] != '#') |
198 |
|
|
{ |
199 |
|
|
line[strlen(line) - 1] = '\0'; |
200 |
|
|
sendto_one(source_p, form_str(RPL_HELPSTART), |
201 |
|
|
me.name, source_p->name, topic, line); |
202 |
|
|
started = 1; |
203 |
|
|
} |
204 |
|
|
|
205 |
|
|
while (fbgets(line, sizeof(line), file)) |
206 |
|
|
{ |
207 |
|
|
line[strlen(line) - 1] = '\0'; |
208 |
michael |
1055 |
if (line[0] != '#') |
209 |
adx |
30 |
{ |
210 |
|
|
if (!started) |
211 |
|
|
{ |
212 |
|
|
type = RPL_HELPSTART; |
213 |
michael |
1055 |
started = 1; |
214 |
adx |
30 |
} |
215 |
|
|
else |
216 |
|
|
type = RPL_HELPTXT; |
217 |
|
|
|
218 |
|
|
sendto_one(source_p, form_str(RPL_HELPTXT), |
219 |
|
|
me.name, source_p->name, topic, line); |
220 |
|
|
} |
221 |
|
|
} |
222 |
|
|
|
223 |
|
|
fbclose(file); |
224 |
|
|
sendto_one(source_p, form_str(RPL_HELPTXT), |
225 |
|
|
me.name, source_p->name, topic, ""); |
226 |
|
|
sendto_one(source_p, form_str(RPL_ENDOFHELP), |
227 |
|
|
me.name, source_p->name, topic); |
228 |
|
|
} |