From 5df79c53745fde5d6c3340a2979b1429cd5892c1 Mon Sep 17 00:00:00 2001 From: Henrik Rydberg Date: Sat, 8 Oct 2011 20:30:28 +0200 Subject: Initial import of htcd system 1.0 Signed-off-by: Henrik Rydberg --- src/sh/sys.cc | 152 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 152 insertions(+) create mode 100644 src/sh/sys.cc (limited to 'src/sh/sys.cc') diff --git a/src/sh/sys.cc b/src/sh/sys.cc new file mode 100644 index 0000000..b70991b --- /dev/null +++ b/src/sh/sys.cc @@ -0,0 +1,152 @@ +/************************************************************************* + * + * HTCd - Copyright (C) 1998-2006 Henrik Rydberg + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include +#include +#include +#include +#include +#include + +//////////////////////////////////////////// + +TOK_IMPL(sleep) { sleep(atoi(env[0])); } +TOK_IMPL(throw) { THROW(env[0]); } + +//////////////////////////////////////////// + +TOK_IMPL(sync) { dbmap::Sync(); } + +//////////////////////////////////////////// + +TOK_IMPL(gethost) { + IPnode node; if(Lookup(node,env[0])) out<\n"; + + //if(env[1].nempty()) ms<<"Reply-To: "<htc(); + if(htc->mailer.size()) { + issue_t cmd(htc->mailer+sref(" ")+env[2]); + mstream m; + cmd.run(m,ms.str()); + htc->syslog<<"["<syslog<<"["<syslog<<"-----------------------------------------\n"; + htc->syslog<syslog<<"=========================================\n"; + } + htc->syslog.flush(); +} + +//////////////////////////////////////////// + +TOK_IMPL(issue) { + HTC* htc=Req(env)->htc(); + htc->syslog<<"["<syslog.flush(); + issue_t cmd(DocPath(env,env[0])); + cmd.run(out,env[1]); + htc->syslog<<"["<syslog.flush(); +} + +////////////////////////////////////////////////////////// + +void envAddSys(tokmap& T) +{ + TOK_ADD(sleep,"x",tok_t::SYSONLY, + "%Sleep for seconds\n" + "%Syntax: \\sleep{t}\n" + "%\n" + "%This one works just like the UNIX command\n" + ); + TOK_ADD(throw,"x",tok_t::SYSONLY, + "%Throw an exception\n" + "%Syntax: \\throw{text}\n" + "%\n" + "%Throw a, for the HTC system, standard error\n" + "%expection, which also many of the built-in\n" + "%do. Enables well-behaved error handling.\n" + ); + + ///////////////////////////////////////////////////////////// + + TOK_ADD(sync,"",tok_t::SYSONLY, + "%Syncronize all open writable databases\n" + "%Syntax: \\sync\n" + "%\n" + "%Use in crontab only.\n" + ); + + ///////////////////////////////////////////////////////////// + + TOK_ADD(gethost,"x",tok_t::SYSONLY, + "%Lookup hostname on nameserver\n" + "%Syntax: \\gethost{IP address}\n" + "%\n" + "%Normally performed automatically by the server.\n" + ); + + ///////////////////////////////////////////////////////////// + + TOK_ADD(mail,"xxxxxxxx",tok_t::SYSONLY, + "%System mail\n" + "%Syntax: \\mail{from}{replyto}{to}{fromname}{date}{subject}{mime}{body}\n" + "%\n" + "%This mail command can do almost anything, so be careful!\n" + "%Usually there are several htc commands simplifying the use\n" + "%of this one.\n" + ); + + ///////////////////////////////////////////////////////////// + + TOK_ADD(issue,"xx",tok_t::SYSONLY, + "%Issue piped command\n" + "%Syntax: \\issue{uri}{stdin}\n" + "%\n" + "%Pipes stdin to cmd and output stdout.\n" + "%An extremely powerful command that may be used\n" + "%to run external programs via the web.\n" + "%\n" + "%Note that the normal uri handling is performed.\n" + ); + + ///////////////////////////////////////////////////////////// +} -- cgit v1.2.3