Anope IRC Services  Version 1.8
ns_info.c
Go to the documentation of this file.
1 /* NickServ core functions
2  *
3  * (C) 2003-2014 Anope Team
4  * Contact us at team@anope.org
5  *
6  * Please read COPYING and README for further details.
7  *
8  * Based on the original code of Epona by Lara.
9  * Based on the original code of Services by Andy Church.
10  *
11  *
12  */
13 /*************************************************************************/
14 
15 #include "module.h"
16 
17 static int do_info(User * u);
18 static void myNickServHelp(User * u);
19 
26 int AnopeInit(int argc, char **argv)
27 {
28  Command *c;
29 
30  moduleAddAuthor("Anope");
32  (VERSION_STRING);
34 
35  c = createCommand("INFO", do_info, NULL, NICK_HELP_INFO, -1,
36  NICK_HELP_INFO, NICK_SERVADMIN_HELP_INFO,
37  NICK_SERVADMIN_HELP_INFO);
39 
41 
42  return MOD_CONT;
43 }
44 
48 void AnopeFini(void)
49 {
50 
51 }
52 
53 
54 
59 static void myNickServHelp(User * u)
60 {
61  notice_lang(s_NickServ, u, NICK_HELP_CMD_INFO);
62 }
63 
69 static int do_info(User * u)
70 {
71 
72 /* Show hidden info to nick owners and sadmins when the "ALL" parameter is
73  * supplied. If a nick is online, the "Last seen address" changes to "Is
74  * online from".
75  * Syntax: INFO <nick> {ALL}
76  * -TheShadow (13 Mar 1999)
77  */
78 
79  char *nick = strtok(NULL, " ");
80  char *param = strtok(NULL, " ");
81 
82  NickAlias *na;
83  NickRequest *nr = NULL;
84  /* Being an oper is enough from now on -GD */
85  int is_servadmin = is_services_oper(u);
86 
87  if (!nick) {
88  syntax_error(s_NickServ, u, "INFO", NICK_INFO_SYNTAX);
89  } else if (!(na = findnick(nick))) {
90  if ((nr = findrequestnick(nick))) {
91  notice_lang(s_NickServ, u, NICK_IS_PREREG);
92  if (param && stricmp(param, "ALL") == 0 && is_servadmin) {
93  notice_lang(s_NickServ, u, NICK_INFO_EMAIL, nr->email);
94  } else {
95  if (is_servadmin) {
96  notice_lang(s_NickServ, u, NICK_INFO_FOR_MORE,
97  s_NickServ, nr->nick);
98  }
99  }
100  } else if (nickIsServices(nick, 1)) {
101  notice_lang(s_NickServ, u, NICK_X_IS_SERVICES, nick);
102  } else {
103  notice_lang(s_NickServ, u, NICK_X_NOT_REGISTERED, nick);
104  }
105  } else if (na->status & NS_VERBOTEN) {
106  if (is_oper(u) && na->last_usermask)
107  notice_lang(s_NickServ, u, NICK_X_FORBIDDEN_OPER, nick,
108  na->last_usermask,
109  (na->last_realname ? na->
110  last_realname : getstring(u->na, NO_REASON)));
111  else
112  notice_lang(s_NickServ, u, NICK_X_FORBIDDEN, nick);
113  } else {
114  struct tm *tm;
115  char buf[BUFSIZE], *end;
116  const char *commastr = getstring(u->na, COMMA_SPACE);
117  int need_comma = 0;
118  int nick_online = 0;
119  int show_hidden = 0;
120  time_t expt;
121 
122  /* Is the real owner of the nick we're looking up online? -TheShadow */
123  if (na->status & (NS_RECOGNIZED | NS_IDENTIFIED))
124  nick_online = 1;
125 
126  /* Only show hidden fields to owner and sadmins and only when the ALL
127  * parameter is used. -TheShadow */
128  if (param && stricmp(param, "ALL") == 0 && u->na
129  && ((nick_identified(u) && (na->nc == u->na->nc))
130  || is_servadmin))
131  show_hidden = 1;
132 
133  notice_lang(s_NickServ, u, NICK_INFO_REALNAME, na->nick,
134  na->last_realname);
135 
136  if ((nick_identified(u) && (na->nc == u->na->nc)) || is_servadmin) {
137 
138  if (nick_is_services_root(na->nc))
139  notice_lang(s_NickServ, u, NICK_INFO_SERVICES_ROOT,
140  na->nick);
141  else if (nick_is_services_admin(na->nc))
142  notice_lang(s_NickServ, u, NICK_INFO_SERVICES_ADMIN,
143  na->nick);
144  else if (nick_is_services_oper(na->nc))
145  notice_lang(s_NickServ, u, NICK_INFO_SERVICES_OPER,
146  na->nick);
147 
148  } else {
149 
150  if (nick_is_services_root(na->nc)
151  && !(na->nc->flags & NI_HIDE_STATUS))
152  notice_lang(s_NickServ, u, NICK_INFO_SERVICES_ROOT,
153  na->nick);
154  else if (nick_is_services_admin(na->nc)
155  && !(na->nc->flags & NI_HIDE_STATUS))
156  notice_lang(s_NickServ, u, NICK_INFO_SERVICES_ADMIN,
157  na->nick);
158  else if (nick_is_services_oper(na->nc)
159  && !(na->nc->flags & NI_HIDE_STATUS))
160  notice_lang(s_NickServ, u, NICK_INFO_SERVICES_OPER,
161  na->nick);
162 
163  }
164 
165  if (nick_online) {
166  if (show_hidden || !(na->nc->flags & NI_HIDE_MASK))
167  notice_lang(s_NickServ, u, NICK_INFO_ADDRESS_ONLINE,
168  na->last_usermask);
169  else
170  notice_lang(s_NickServ, u, NICK_INFO_ADDRESS_ONLINE_NOHOST,
171  na->nick);
172  } else {
173  if (show_hidden || !(na->nc->flags & NI_HIDE_MASK))
174  notice_lang(s_NickServ, u, NICK_INFO_ADDRESS,
175  na->last_usermask);
176  }
177 
178  tm = localtime(&na->time_registered);
179  strftime_lang(buf, sizeof(buf), u, STRFTIME_DATE_TIME_FORMAT, tm);
180  notice_lang(s_NickServ, u, NICK_INFO_TIME_REGGED, buf);
181 
182  if (!nick_online) {
183  tm = localtime(&na->last_seen);
184  strftime_lang(buf, sizeof(buf), u, STRFTIME_DATE_TIME_FORMAT,
185  tm);
186  notice_lang(s_NickServ, u, NICK_INFO_LAST_SEEN, buf);
187  }
188 
189  if (na->last_quit
190  && (show_hidden || !(na->nc->flags & NI_HIDE_QUIT)))
191  notice_lang(s_NickServ, u, NICK_INFO_LAST_QUIT, na->last_quit);
192 
193  if (na->nc->url)
194  notice_lang(s_NickServ, u, NICK_INFO_URL, na->nc->url);
195  if (na->nc->email
196  && (show_hidden || !(na->nc->flags & NI_HIDE_EMAIL)))
197  notice_lang(s_NickServ, u, NICK_INFO_EMAIL, na->nc->email);
198  if (na->nc->icq)
199  notice_lang(s_NickServ, u, NICK_INFO_ICQ, na->nc->icq);
200 
201  if (show_hidden) {
202  if (s_HostServ && ircd->vhost) {
203  if (getvHost(na->nick) != NULL) {
204  if (ircd->vident && getvIdent(na->nick) != NULL) {
205  notice_lang(s_NickServ, u, NICK_INFO_VHOST2,
206  getvIdent(na->nick),
207  getvHost(na->nick));
208  } else {
209  notice_lang(s_NickServ, u, NICK_INFO_VHOST,
210  getvHost(na->nick));
211  }
212  }
213  }
214  if (na->nc->greet)
215  notice_lang(s_NickServ, u, NICK_INFO_GREET, na->nc->greet);
216 
217  *buf = 0;
218  end = buf;
219 
220  if (na->nc->flags & NI_KILLPROTECT) {
221  end += snprintf(end, sizeof(buf) - (end - buf), "%s",
222  getstring(u->na, NICK_INFO_OPT_KILL));
223  need_comma = 1;
224  }
225  if (na->nc->flags & NI_SECURE) {
226  end += snprintf(end, sizeof(buf) - (end - buf), "%s%s",
227  need_comma ? commastr : "",
228  getstring(u->na, NICK_INFO_OPT_SECURE));
229  need_comma = 1;
230  }
231  if (na->nc->flags & NI_PRIVATE) {
232  end += snprintf(end, sizeof(buf) - (end - buf), "%s%s",
233  need_comma ? commastr : "",
234  getstring(u->na, NICK_INFO_OPT_PRIVATE));
235  need_comma = 1;
236  }
237  if (na->nc->flags & NI_MSG) {
238  end += snprintf(end, sizeof(buf) - (end - buf), "%s%s",
239  need_comma ? commastr : "",
240  getstring(u->na, NICK_INFO_OPT_MSG));
241  need_comma = 1;
242  }
243  if (!(na->nc->flags & NI_AUTOOP)) {
244  end += snprintf(end, sizeof(buf) - (end - buf), "%s%s",
245  need_comma ? commastr : "",
246  getstring(u->na, NICK_INFO_OPT_AUTOOP));
247  need_comma = 1;
248  }
249 
250  notice_lang(s_NickServ, u, NICK_INFO_OPTIONS,
251  *buf ? buf : getstring(u->na, NICK_INFO_OPT_NONE));
252 
253  if (na->nc->flags & NI_SUSPENDED) {
254  if (na->last_quit) {
255  notice_lang(s_NickServ, u, NICK_INFO_SUSPENDED,
256  na->last_quit);
257  } else {
259  NICK_INFO_SUSPENDED_NO_REASON);
260  }
261  }
262 
263  if (na->status & NS_NO_EXPIRE) {
264  notice_lang(s_NickServ, u, NICK_INFO_NO_EXPIRE);
265  } else {
266  if (is_servadmin) {
267  expt = na->last_seen + NSExpire;
268  tm = localtime(&expt);
269  strftime_lang(buf, sizeof(buf), na->u,
270  STRFTIME_DATE_TIME_FORMAT, tm);
271  notice_lang(s_NickServ, u, NICK_INFO_EXPIRE, buf);
272  }
273  }
274  }
275 
276  if (!show_hidden
277  && ((u->na && (na->nc == u->na->nc) && nick_identified(u))
278  || is_servadmin))
279  notice_lang(s_NickServ, u, NICK_INFO_FOR_MORE, s_NickServ,
280  na->nick);
281  }
282  return MOD_CONT;
283 }
E int is_oper(User *user)
Definition: users.c:937
E char * getvIdent(char *nick)
Definition: hostserv.c:330
char * email
Definition: services.h:519
E int nick_is_services_admin(NickCore *nc)
Definition: operserv.c:636
E int nick_is_services_root(NickCore *nc)
Definition: operserv.c:623
static int do_info(User *u)
Definition: ns_info.c:69
E int snprintf(char *buf, size_t size, const char *fmt,...)
Definition: compat.c:37
E NickAlias * findnick(const char *nick)
Definition: db-merger.c:1857
char * url
Definition: services.h:547
void AnopeFini(void)
Definition: ns_info.c:48
#define NI_SUSPENDED
Definition: services.h:1308
E IRCDVar * ircd
Definition: extern.h:39
static void myNickServHelp(User *u)
Definition: ns_info.c:59
E int nick_identified(User *u)
Definition: nickserv.c:1111
char * last_quit
Definition: services.h:527
int vhost
Definition: services.h:301
E int stricmp(const char *s1, const char *s2)
Definition: compat.c:58
E int NSExpire
Definition: extern.h:381
E int nick_is_services_oper(NickCore *nc)
Definition: operserv.c:649
#define NS_RECOGNIZED
Definition: services.h:1276
#define NS_VERBOTEN
Definition: services.h:1273
#define getstring(na, index)
Definition: extern.h:731
int vident
Definition: services.h:337
#define NI_HIDE_QUIT
Definition: services.h:1299
#define NI_KILLPROTECT
Definition: services.h:1290
MDE void moduleAddAuthor(const char *author)
Definition: modules.c:1772
E void syntax_error(char *service, User *u, const char *command, int msgnum)
Definition: language.c:295
E void notice_lang(char *source, User *dest, int message,...)
Definition: send.c:169
MDE void moduleSetType(MODType type)
Definition: modules.c:818
#define NI_PRIVATE
Definition: services.h:1296
NickCore * nc
Definition: services.h:533
#define NI_HIDE_EMAIL
Definition: services.h:1297
E NickRequest * findrequestnick(const char *nick)
Definition: nickserv.c:1218
#define NI_HIDE_STATUS
Definition: services.h:1307
E int nickIsServices(char *nick, int bot)
Definition: misc.c:857
uint16 status
Definition: services.h:532
#define NI_HIDE_MASK
Definition: services.h:1298
MDE void moduleAddVersion(const char *version)
Definition: modules.c:1760
Command * c
Definition: ns_recover.c:17
#define MOD_CONT
Definition: modules.h:54
time_t time_registered
Definition: services.h:530
#define NI_MSG
Definition: services.h:1292
E char * s_HostServ
Definition: extern.h:303
#define NI_AUTOOP
Definition: services.h:1309
char * nick
Definition: services.h:526
int AnopeInit(int argc, char **argv)
Definition: ns_info.c:26
char * last_realname
Definition: services.h:528
#define NI_SECURE
Definition: services.h:1291
MDE void moduleSetNickHelp(void(*func)(User *u))
Definition: modules.c:2078
Definition: modules.h:99
MDE Command * createCommand(const char *name, int(*func)(User *u), int(*has_priv)(User *u), int help_all, int help_reg, int help_oper, int help_admin, int help_root)
Definition: modules.c:987
E char * getvHost(char *nick)
Definition: hostserv.c:315
#define NS_IDENTIFIED
Definition: services.h:1275
E int is_services_oper(User *u)
Definition: operserv.c:606
uint32 flags
Definition: services.h:548
time_t last_seen
Definition: services.h:531
char * greet
Definition: services.h:545
#define NS_NO_EXPIRE
Definition: services.h:1274
E int strftime_lang(char *buf, int size, User *u, int format, struct tm *tm)
Definition: language.c:240
User * u
Definition: services.h:536
char * nick
Definition: services.h:516
E char * s_NickServ
Definition: extern.h:284
MDE int moduleAddCommand(CommandHash *cmdTable[], Command *c, int pos)
Definition: modules.c:1082
char * last_usermask
Definition: services.h:529
uint32 icq
Definition: services.h:546
#define BUFSIZE
Definition: config.h:47
#define NICKSERV
Definition: modules.h:59
NickAlias * na
Definition: services.h:892
#define MOD_UNIQUE
Definition: module.h:11
char * email
Definition: services.h:544