Added a shutdown command to ctdlsh
authorArt Cancro <ajc@uncensored.citadel.org>
Thu, 15 Dec 2011 17:53:21 +0000 (12:53 -0500)
committerArt Cancro <ajc@uncensored.citadel.org>
Thu, 15 Dec 2011 17:53:21 +0000 (12:53 -0500)
ctdlsh/README
ctdlsh/src/Makefile.am
ctdlsh/src/Makefile.in
ctdlsh/src/ctdlsh.h
ctdlsh/src/main.c
ctdlsh/src/shutdown.c [new file with mode: 0644]

index bd2c9b98c1a46ca93e0f70ead5be3c6e922f8935..38b234e6c181f1fc44fcaa6fd47bf39c4ceea63e 100644 (file)
@@ -1,5 +1,7 @@
 
-This is unfinished.  Don't use it.  Don't touch it.  Go away.
-
-Die in a car fire.
+Someday this will be a Citadel server administration/maintenance shell.
+Right now it is unfinished.  You are welcome to tinker with it and
+submit patches, but if you attempt to use it in a production system or
+if you request support for the program, you will be told to die in a
+car fire.
 
index 1f9f00ff3718045a5a49126f3f291d464a8ba552..4da8f1c955ac6908e3e32d3eac3ee91f44df5095 100644 (file)
@@ -4,4 +4,4 @@
 ##/
 
 bin_PROGRAMS = ctdlsh
-ctdlsh_SOURCES = main.c sockets.c ctdlsh.h datetime.c passwd.c
+ctdlsh_SOURCES = main.c sockets.c ctdlsh.h datetime.c passwd.c shutdown.c
index 8c36fb6fe5ec26b06ef367a9aec244b944f5052e..d0fb155bdffa7ed30803225d7eb66a60f9669aa8 100644 (file)
@@ -46,7 +46,7 @@ CONFIG_CLEAN_VPATH_FILES =
 am__installdirs = "$(DESTDIR)$(bindir)"
 PROGRAMS = $(bin_PROGRAMS)
 am_ctdlsh_OBJECTS = main.$(OBJEXT) sockets.$(OBJEXT) \
-       datetime.$(OBJEXT) passwd.$(OBJEXT)
+       datetime.$(OBJEXT) passwd.$(OBJEXT) shutdown.$(OBJEXT)
 ctdlsh_OBJECTS = $(am_ctdlsh_OBJECTS)
 ctdlsh_LDADD = $(LDADD)
 DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)
@@ -145,7 +145,7 @@ target_alias = @target_alias@
 top_build_prefix = @top_build_prefix@
 top_builddir = @top_builddir@
 top_srcdir = @top_srcdir@
-ctdlsh_SOURCES = main.c sockets.c ctdlsh.h datetime.c passwd.c
+ctdlsh_SOURCES = main.c sockets.c ctdlsh.h datetime.c passwd.c shutdown.c
 all: all-am
 
 .SUFFIXES:
@@ -230,6 +230,7 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/datetime.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/main.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/passwd.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/shutdown.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sockets.Po@am__quote@
 
 .c.o:
index 42dcb408548db584654c5951452e88df9f76de8c..caf4b516ec52d6e6900eaafdc40e11ef84944619 100644 (file)
@@ -63,3 +63,4 @@ int cmd_help(int, char *);
 int cmd_quit(int, char *);
 int cmd_datetime(int, char *);
 int cmd_passwd(int, char *);
+int cmd_shutdown(int, char *);
index 3dd4b9dd7136d16eec6cbacd3f08cdc16f35244b..1b16be3f0248b0e2f9e8e0d6da206f5aa5129c54 100644 (file)
@@ -30,6 +30,7 @@ COMMAND commands[] = {
        {       "date",         cmd_datetime,   "Print the server's date and time"      },
        {       "time",         cmd_datetime,   "Print the server's date and time"      },
        {       "passwd",       cmd_passwd,     "Set or change an account password"     },
+       {       "shutdown",     cmd_shutdown,   "Shut down the Citadel server"          },
        {       NULL,           NULL,           NULL                                    }
 };
 
diff --git a/ctdlsh/src/shutdown.c b/ctdlsh/src/shutdown.c
new file mode 100644 (file)
index 0000000..cab8036
--- /dev/null
@@ -0,0 +1,30 @@
+/*
+ * (c) 2011 by Art Cancro and citadel.org
+ * This program is released under the terms of the GNU General Public License v3.
+ */
+
+#include "ctdlsh.h"
+
+int cmd_shutdown(int server_socket, char *cmdbuf) {
+       char buf[1024];
+
+       char *p1 = readline("Do you really want to shut down the Citadel server? ");
+
+       if (strncasecmp(p1, "y", 1)) {
+               return(cmdret_ok);
+       }
+
+       sock_puts("DOWN");
+       sock_getln(server_socket, buf, sizeof buf);
+       if (buf[0] != '2') {
+               fprintf(stderr, "%s\n", &buf[4]);
+               return(cmdret_error);
+       }
+
+       fprintf(stderr, "%s\n", &buf[4]);
+       return(cmdret_ok);
+}
+
+
+
+