From dafd798faca202aa52ce678281a1ce2f19f458aa Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Thu, 15 Dec 2011 12:53:21 -0500 Subject: [PATCH] Added a shutdown command to ctdlsh --- ctdlsh/README | 8 +++++--- ctdlsh/src/Makefile.am | 2 +- ctdlsh/src/Makefile.in | 5 +++-- ctdlsh/src/ctdlsh.h | 1 + ctdlsh/src/main.c | 1 + ctdlsh/src/shutdown.c | 30 ++++++++++++++++++++++++++++++ 6 files changed, 41 insertions(+), 6 deletions(-) create mode 100644 ctdlsh/src/shutdown.c diff --git a/ctdlsh/README b/ctdlsh/README index bd2c9b98c..38b234e6c 100644 --- a/ctdlsh/README +++ b/ctdlsh/README @@ -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. diff --git a/ctdlsh/src/Makefile.am b/ctdlsh/src/Makefile.am index 1f9f00ff3..4da8f1c95 100644 --- a/ctdlsh/src/Makefile.am +++ b/ctdlsh/src/Makefile.am @@ -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 diff --git a/ctdlsh/src/Makefile.in b/ctdlsh/src/Makefile.in index 8c36fb6fe..d0fb155bd 100644 --- a/ctdlsh/src/Makefile.in +++ b/ctdlsh/src/Makefile.in @@ -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: diff --git a/ctdlsh/src/ctdlsh.h b/ctdlsh/src/ctdlsh.h index 42dcb4085..caf4b516e 100644 --- a/ctdlsh/src/ctdlsh.h +++ b/ctdlsh/src/ctdlsh.h @@ -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 *); diff --git a/ctdlsh/src/main.c b/ctdlsh/src/main.c index 3dd4b9dd7..1b16be3f0 100644 --- a/ctdlsh/src/main.c +++ b/ctdlsh/src/main.c @@ -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 index 000000000..cab803604 --- /dev/null +++ b/ctdlsh/src/shutdown.c @@ -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); +} + + + + -- 2.30.2