diff --git a/scripts/Makefile b/scripts/Makefile new file mode 100644 index 0000000..e047201 --- /dev/null +++ b/scripts/Makefile @@ -0,0 +1,16 @@ +# cnd Makefile +# (C)2005, Dan Ponte +# $Amigan: phoned/scripts/Makefile,v 1.1 2005/06/19 05:50:23 dcp1990 Exp $ +include ../global.mk +# basic stuff. we append for a reason. +CPPFLAGS+=-I/usr/local/include/tcl8.4 +CFLAGS+=-g ${CPPFLAGS} +LDFLAGS+=-shared +# keep these up to date. +MAINBIN=terminal.so +SRCS=terminal.c +OBJS=terminal.o + +include ../main.mk +ourclean: + diff --git a/scripts/terminal.c b/scripts/terminal.c new file mode 100644 index 0000000..5db466e --- /dev/null +++ b/scripts/terminal.c @@ -0,0 +1,88 @@ +#include +#include +#include +#include +#include /*For MAX_CANON -- Linux: use instead */ +#include + +#define CMD_ARGS (ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]) + +int TerminalEchoOff CMD_ARGS { + struct termios terminal; + int fid = fileno (stdout); + + if (objc != 1) { + Tcl_WrongNumArgs (interp, 0, NULL, "terminal:echoOff"); + return TCL_ERROR; + } + + tcgetattr (fid, &terminal); + terminal.c_lflag &= (~ECHO); + tcsetattr (fid, TCSANOW, &terminal); + + return TCL_OK; +} + +int TerminalEchoOn CMD_ARGS { + struct termios terminal; + int fid = fileno (stdout); + + if (objc != 1) { + Tcl_WrongNumArgs (interp, 0, NULL, "terminal:echoOn"); + return TCL_ERROR; + } + + tcgetattr (fid, &terminal); + terminal.c_lflag |= (ECHO); + tcsetattr (fid, TCSANOW, &terminal); + + return TCL_OK; +} + +int TerminalCanonicalOff CMD_ARGS { + struct termios terminal; + int fid = fileno (stdin); + + if (objc != 1) { + Tcl_WrongNumArgs (interp, 0, NULL, "terminal:canonicalOff"); + return TCL_ERROR; + } + + tcgetattr (fid, &terminal); + terminal.c_lflag &= (~ICANON); + terminal.c_cc[VTIME] = 0; + terminal.c_cc[VMIN] = 1; + tcsetattr (fid, TCSANOW, &terminal); + + return TCL_OK; +} + +int TerminalCanonicalOn CMD_ARGS { + struct termios terminal; + int fid = fileno (stdin); + + if (objc != 1) { + Tcl_WrongNumArgs (interp, 0, NULL, "terminal:canonicalOn"); + return TCL_ERROR; + } + + tcgetattr (fid, &terminal); + terminal.c_lflag |= (ICANON); + terminal.c_cc[VTIME] = 0; + terminal.c_cc[VMIN] = MAX_CANON; + tcsetattr (fid, TCSANOW, &terminal); + + return TCL_OK; +} + +int Terminal_Init (Tcl_Interp *interp) { + #define OBJ_CMD(name,func) Tcl_CreateObjCommand(interp, name, func, (ClientData) NULL, (Tcl_CmdDeleteProc *) NULL) + + OBJ_CMD ("terminal:echoOff", TerminalEchoOff); + OBJ_CMD ("terminal:echoOn", TerminalEchoOn); + OBJ_CMD ("terminal:canonicalOff", TerminalCanonicalOff); + OBJ_CMD ("terminal:canonicalOn", TerminalCanonicalOn); + + #undef OBJ_CMD + return TCL_OK; +} diff --git a/scripts/usermaint.tcl b/scripts/usermaint.tcl new file mode 100755 index 0000000..8af9543 --- /dev/null +++ b/scripts/usermaint.tcl @@ -0,0 +1,24 @@ +#!/usr/local/bin/tclsh8.4 +if {$argc < 3} { + puts stderr "usage: %s dbname command arg1 arg2 ...\ncommands:\nadduser uname - asks for pass, no echo" + exit -1 +} +package require md5 +load ./terminal.so +load /usr/local/lib/sqlite/libtclsqlite3.so Sqlite3 +sqlite db [lindex $argv 0] +set cmd [lindex $argv 1] +if {[string equal $cmd "adduser"]} { + set uname [lindex $argv 2] + puts -nonewline "Password: " + flush stdout + terminal:echoOff + set pass [gets stdin] + terminal:echoOn + puts "" + # pkey, login, pass, priv + set md5pass [string tolower [md5::md5 -hex $pass]] + db eval {INSERT INTO users VALUES(null, $uname, $md5pass, 32)} + puts "User added successfully." +} +db close