Debian Codegraph @

modules/hostserv/onoff.c

raw
1 /*
2 * Copyright (c) 2005 William Pitcock <nenolod -at- nenolod.net>
3 * Rights to this code are as documented in doc/LICENSE.
4 *
5 * Allows setting a vhost on/off
6 *
7 */
8
9 #include "atheme.h"
10 #include "hostserv.h"
11
12 DECLARE_MODULE_V1
13 (
14 "hostserv/onoff", false, _modinit, _moddeinit,
15 PACKAGE_STRING,
16 VENDOR_STRING
17 );
18
19 static void hs_cmd_on(sourceinfo_t *si, int parc, char *parv[]);
20 static void hs_cmd_off(sourceinfo_t *si, int parc, char *parv[]);
21
22 command_t hs_on = { "ON", N_("Activates your assigned vhost."), AC_AUTHENTICATED, 1, hs_cmd_on, { .path = "hostserv/on" } };
23 command_t hs_off = { "OFF", N_("Deactivates your assigned vhost."), AC_AUTHENTICATED, 1, hs_cmd_off, { .path = "hostserv/off" } };
24
25 void _modinit(module_t *m)
26 {
27 service_named_bind_command("hostserv", &hs_on);
28 service_named_bind_command("hostserv", &hs_off);
29 }
30
31 void _moddeinit(module_unload_intent_t intent)
32 {
33 service_named_unbind_command("hostserv", &hs_on);
34 service_named_unbind_command("hostserv", &hs_off);
35 }
36
37
38 static void hs_cmd_on(sourceinfo_t *si, int parc, char *parv[])
39 {
40 mynick_t *mn = NULL;
41 metadata_t *md;
42 char buf[BUFSIZE];
43
44 if (si->su == NULL)
45 {
46 command_fail(si, fault_noprivs, _("\2%s\2 can only be executed via IRC."), "ON");
47 return;
48 }
49
50 mn = mynick_find(si->su->nick);
51 if (mn == NULL)
52 {
53 command_fail(si, fault_nosuch_target, _("Nick \2%s\2 is not registered."), si->su->nick);
54 return;
55 }
56 if (mn->owner != si->smu && !myuser_access_verify(si->su, mn->owner))
57 {
58 command_fail(si, fault_noprivs, _("You are not recognized as \2%s\2."), entity(mn->owner)->name);
59 return;
60 }
61 snprintf(buf, BUFSIZE, "%s:%s", "private:usercloak", mn->nick);
62 md = metadata_find(si->smu, buf);
63 if (md == NULL)
64 md = metadata_find(si->smu, "private:usercloak");
65 if (md == NULL)
66 {
67 command_success_nodata(si, _("Please contact an Operator to get a vhost assigned to this nick."));
68 return;
69 }
70 do_sethost(si->su, md->value);
71 command_success_nodata(si, _("Your vhost of \2%s\2 is now activated."), md->value);
72 }
73
74 static void hs_cmd_off(sourceinfo_t *si, int parc, char *parv[])
75 {
76 mynick_t *mn = NULL;
77 metadata_t *md;
78 char buf[BUFSIZE];
79
80 if (si->su == NULL)
81 {
82 command_fail(si, fault_noprivs, _("\2%s\2 can only be executed via IRC."), "OFF");
83 return;
84 }
85
86 mn = mynick_find(si->su->nick);
87 if (mn == NULL)
88 {
89 command_fail(si, fault_nosuch_target, _("Nick \2%s\2 is not registered."), si->su->nick);
90 return;
91 }
92 if (mn->owner != si->smu && !myuser_access_verify(si->su, mn->owner))
93 {
94 command_fail(si, fault_noprivs, _("You are not recognized as \2%s\2."), entity(mn->owner)->name);
95 return;
96 }
97 snprintf(buf, BUFSIZE, "%s:%s", "private:usercloak", mn->nick);
98 md = metadata_find(si->smu, buf);
99 if (md == NULL)
100 md = metadata_find(si->smu, "private:usercloak");
101 if (md == NULL)
102 {
103 command_success_nodata(si, _("Please contact an Operator to get a vhost assigned to this nick."));
104 return;
105 }
106 do_sethost(si->su, NULL);
107 command_success_nodata(si, _("Your vhost of \2%s\2 is now deactivated."), md->value);
108 }
109
110 /* vim:cinoptions=>s,e0,n0,f0,{0,}0,^0,=s,ps,t0,c3,+s,(2s,us,)20,*30,gs,hs
111 * vim:ts=8
112 * vim:sw=8
113 * vim:noexpandtab
114 */