46 |
|
static void cmd_check(char *, const struct ChannelConf *); |
47 |
|
static void cmd_stat(char *, const struct ChannelConf *); |
48 |
|
static void cmd_fdstat(char *, const struct ChannelConf *); |
49 |
+ |
static void cmd_protocols(char *, const struct ChannelConf *); |
50 |
|
|
51 |
|
static const struct OperCommandHash COMMAND_TABLE[] = |
52 |
|
{ |
53 |
< |
{ "CHECK", cmd_check }, |
54 |
< |
{ "SCAN", cmd_check }, |
55 |
< |
{ "STAT", cmd_stat }, |
56 |
< |
{ "STATS", cmd_stat }, |
57 |
< |
{ "STATUS", cmd_stat }, |
58 |
< |
{ "FDSTAT", cmd_fdstat }, |
59 |
< |
{ NULL, NULL } |
53 |
> |
{ "CHECK", cmd_check }, |
54 |
> |
{ "SCAN", cmd_check }, |
55 |
> |
{ "STAT", cmd_stat }, |
56 |
> |
{ "STATS", cmd_stat }, |
57 |
> |
{ "STATUS", cmd_stat }, |
58 |
> |
{ "FDSTAT", cmd_fdstat }, |
59 |
> |
{ "PROTOCOLS", cmd_protocols }, |
60 |
> |
{ NULL, NULL } |
61 |
|
}; |
62 |
|
|
63 |
|
|
64 |
|
/* command_init |
65 |
< |
* |
65 |
> |
* |
66 |
|
* Do command initialization |
67 |
|
* |
68 |
|
* Parameters: NONE |
81 |
|
* Perform ~1 second actions. |
82 |
|
* |
83 |
|
* Parameters: NONE |
84 |
< |
* |
84 |
> |
* |
85 |
|
* Return: NONE |
86 |
|
* |
87 |
|
*/ |
89 |
|
command_timer(void) |
90 |
|
{ |
91 |
|
static unsigned int interval; |
92 |
< |
node_t *node, *next; |
92 |
> |
node_t *node, *node_next; |
93 |
|
time_t present; |
94 |
|
|
95 |
|
/* Only perform command removal every COMMANDINTERVAL seconds */ |
100 |
|
|
101 |
|
time(&present); |
102 |
|
|
103 |
< |
LIST_FOREACH_SAFE(node, next, COMMANDS->head) |
103 |
> |
LIST_FOREACH_SAFE(node, node_next, COMMANDS->head) |
104 |
|
{ |
105 |
|
struct Command *cs = node->data; |
106 |
|
|
110 |
|
list_remove(COMMANDS, node); |
111 |
|
node_free(node); |
112 |
|
} |
113 |
< |
else /* Since the queue is in order, it's also ordered by time, no nodes after this will be timed out */ |
113 |
> |
else /* Since the queue is in order, it's also ordered by time, no nodes after this will be timed out */ |
114 |
|
return; |
115 |
|
} |
116 |
|
} |
169 |
|
*param = '\0'; |
170 |
|
param++; |
171 |
|
} |
170 |
– |
else |
171 |
– |
param = ""; |
172 |
|
|
173 |
< |
log_printf("COMMAND -> parsed [%s] [%s]", command, param); |
173 |
> |
log_printf("COMMAND -> parsed [%s] [%s]", command, param ? param : ""); |
174 |
|
|
175 |
|
/* Lookup the command in the table */ |
176 |
|
for (const struct OperCommandHash *tab = COMMAND_TABLE; tab->command; ++tab) |
189 |
|
} |
190 |
|
|
191 |
|
/* command_create |
192 |
< |
* |
192 |
> |
* |
193 |
|
* Create a Command struct. |
194 |
< |
* |
194 |
> |
* |
195 |
|
* Parameters: |
196 |
|
* type: Index in COMMAND_TABLE |
197 |
|
* param: Parameters to the command (NULL if there are not any) |
212 |
|
|
213 |
|
ret->tab = tab; |
214 |
|
ret->irc_nick = xstrdup(irc_nick); |
215 |
< |
ret->target = target; /* FIXME: This needs fixed if rehash is implemented */ |
215 |
> |
ret->target = target; |
216 |
|
|
217 |
< |
time(&(ret->added)); |
217 |
> |
time(&ret->added); |
218 |
|
|
219 |
|
return ret; |
220 |
|
} |
221 |
|
|
222 |
|
/* command_free |
223 |
< |
* |
223 |
> |
* |
224 |
|
* Free a command struct |
225 |
|
* |
226 |
|
* Parameters: |
227 |
|
* command: Command struct to free |
228 |
< |
* |
228 |
> |
* |
229 |
|
* Return: NONE |
230 |
|
*/ |
231 |
|
static void |
232 |
|
command_free(struct Command *command) |
233 |
|
{ |
234 |
|
if (command->param) |
235 |
< |
MyFree(command->param); |
235 |
> |
xfree(command->param); |
236 |
|
|
237 |
< |
MyFree(command->irc_nick); |
238 |
< |
MyFree(command); |
237 |
> |
xfree(command->irc_nick); |
238 |
> |
xfree(command); |
239 |
|
} |
240 |
|
|
241 |
|
/* command_userhost |
243 |
|
* A 302 reply was received. The reply is parsed to check if the |
244 |
|
* user was an operator. If so any commands they had queued are |
245 |
|
* executed. |
246 |
< |
* |
246 |
> |
* |
247 |
|
* Parameters: |
248 |
|
* reply: Reply to USERHOST (ex: :grifferz*=+goats@pc-62-30-219-54-pb.blueyonder.co.uk) |
249 |
|
* |
250 |
|
* Return: NONE |
251 |
< |
* |
251 |
> |
* |
252 |
|
*/ |
253 |
|
void |
254 |
|
command_userhost(const char *reply) |
255 |
|
{ |
256 |
< |
node_t *node, *next; |
256 |
> |
node_t *node, *node_next; |
257 |
|
char *tmp; |
258 |
|
int oper = 0; |
259 |
|
|
274 |
|
*(tmp) = '\0'; |
275 |
|
|
276 |
|
/* Find any queued commands that match this user */ |
277 |
< |
LIST_FOREACH_SAFE(node, next, COMMANDS->head) |
277 |
> |
LIST_FOREACH_SAFE(node, node_next, COMMANDS->head) |
278 |
|
{ |
279 |
|
struct Command *cs = node->data; |
280 |
|
|
293 |
|
|
294 |
|
/* cmd_check |
295 |
|
* |
296 |
< |
* Start a manual scan on given IP. Parameter MUST be an IP. HOPM should not |
297 |
< |
* have to waste any time resolving a hostname. |
296 |
> |
* Start a manual scan on given IP address/hostname. |
297 |
|
* |
298 |
|
* Parameters: |
299 |
|
* param: Parameters of the command |
333 |
|
{ |
334 |
|
fdstats_output(target->name); |
335 |
|
} |
336 |
+ |
|
337 |
+ |
static void |
338 |
+ |
cmd_protocols(char *param, const struct ChannelConf *target) |
339 |
+ |
{ |
340 |
+ |
node_t *node, *node2; |
341 |
+ |
|
342 |
+ |
LIST_FOREACH(node, ScannerItemList->head) |
343 |
+ |
{ |
344 |
+ |
const struct ScannerConf *sc = node->data; |
345 |
+ |
irc_send("PRIVMSG %s :Scanner: '%s'", target->name, sc->name); |
346 |
+ |
|
347 |
+ |
LIST_FOREACH(node2, sc->protocols->head) |
348 |
+ |
{ |
349 |
+ |
const struct ProtocolConf *proto = node2->data; |
350 |
+ |
irc_send("PRIVMSG %s : %s:%d", target->name, scan_gettype(proto->type), proto->port); |
351 |
+ |
} |
352 |
+ |
} |
353 |
+ |
} |