Debian Codegraph @

modules/operserv/readonly.c

raw
1 /*
2 * Copyright (c) 2005-2010 Atheme Development Group
3 * Rights to this code are as documented in doc/LICENSE.
4 *
5 * Controls READONLY setting.
6 */
7
8 #include "atheme.h"
9
10 DECLARE_MODULE_V1
11 (
12 "operserv/readonly", false, _modinit, _moddeinit,
13 PACKAGE_STRING,
14 VENDOR_STRING
15 );
16
17 static void os_cmd_readonly(sourceinfo_t *si, int parc, char *parv[]);
18
19 command_t os_readonly = { "READONLY", N_("Changes the state of read-only mode for services."),
20 PRIV_ADMIN, 1, os_cmd_readonly, { .path = "oservice/readonly" } };
21
22 void _modinit(module_t *m)
23 {
24 service_named_bind_command("operserv", &os_readonly);
25 }
26
27 void _moddeinit(module_unload_intent_t intent)
28 {
29 service_named_unbind_command("operserv", &os_readonly);
30 }
31
32 static void os_cmd_readonly(sourceinfo_t *si, int parc, char *parv[])
33 {
34 service_t *svs;
35 char *action = parv[0];
36
37 if (!action)
38 {
39 command_fail(si, fault_needmoreparams, STR_INSUFFICIENT_PARAMS, "READONLY");
40 command_fail(si, fault_needmoreparams, _("Usage: READONLY <ON|OFF>"));
41 return;
42 }
43
44 svs = service_find("operserv");
45
46 if (!strcasecmp(action, "ON"))
47 {
48 if (readonly)
49 {
50 command_fail(si, fault_badparams, _("Read-only mode is already enabled."));
51 return;
52 }
53
54 readonly = true;
55
56 notice_global_sts(svs->me, "*", "Services are now running in readonly mode. Any changes you make will not be saved.");
57
58 wallops("%s set the READONLY option.", get_oper_name(si));
59 logcommand(si, CMDLOG_ADMIN, "READONLY:ON");
60 command_success_nodata(si, _("Read-only mode is now enabled."));
61 }
62 else if (!strcasecmp(action, "OFF"))
63 {
64 if (!readonly)
65 {
66 command_fail(si, fault_badparams, _("Read-only mode is already disabled."));
67 return;
68 }
69
70 readonly = false;
71
72 notice_global_sts(svs->me, "*", "Services are no longer running in readonly mode. Any changes you make will now be saved.");
73
74 wallops("%s unset the READONLY option.", get_oper_name(si));
75 logcommand(si, CMDLOG_ADMIN, "READONLY:OFF");
76 command_success_nodata(si, _("Read-only mode is now disabled."));
77 }
78 else
79 {
80 command_fail(si, fault_needmoreparams, STR_INVALID_PARAMS, "READONLY");
81 command_fail(si, fault_needmoreparams, _("Usage: READONLY <ON|OFF>"));
82 }
83 }
84
85 /* vim:cinoptions=>s,e0,n0,f0,{0,}0,^0,=s,ps,t0,c3,+s,(2s,us,)20,*30,gs,hs
86 * vim:ts=8
87 * vim:sw=8
88 * vim:noexpandtab
89 */