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 22:10:59 +0000 (17:10 -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 bd2c9b9..38b234e 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 1f9f00f..4da8f1c 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 8c36fb6..d0fb155 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 42dcb40..caf4b51 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 3dd4b9d..1b16be3 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);
+}
+
+
+
+