Skip to content
Snippets Groups Projects
js_system.c 59.9 KiB
Newer Older
	JS_SET_RVAL(cx, arglist, JSVAL_VOID);

	if((cfg=(scfg_t*)JS_GetPrivate(cx,obj))==NULL)
		return(JS_FALSE);

	if(argc<1)
	else {
		JS_ValueToInt32(cx,argv[0],&val);
		zone=(short)val;
	}
deuce's avatar
deuce committed
	cstr=smb_zonestr(zone,NULL);
deuce's avatar
deuce committed
	if((js_str = JS_NewStringCopyZ(cx, cstr))==NULL)
		return(JS_FALSE);
	JS_SET_RVAL(cx, arglist, STRING_TO_JSVAL(js_str));
/* Returns a ctime()-like string in the system-preferred time format */
js_timestr(JSContext *cx, uintN argc, jsval *arglist)
	JSObject *obj=JS_THIS_OBJECT(cx, arglist);
	jsval *argv=JS_ARGV(cx, arglist);
deuce's avatar
deuce committed
	jsrefcount	rc;
	JS_SET_RVAL(cx, arglist, JSVAL_VOID);

	if((cfg=(scfg_t*)JS_GetPrivate(cx,obj))==NULL)
		return(JS_FALSE);

	if(argc<1)
		ti=(jsdouble)time(NULL);	/* use current time */
		JS_ValueToNumber(cx,argv[0],&ti);
	timestr(cfg,(time32_t)ti,str);
	if((js_str = JS_NewStringCopyZ(cx, str))==NULL)
		return(JS_FALSE);
	JS_SET_RVAL(cx, arglist, STRING_TO_JSVAL(js_str));
/* Returns a mm/dd/yy or dd/mm/yy formated string */
js_datestr(JSContext *cx, uintN argc, jsval *arglist)
	JSObject *obj=JS_THIS_OBJECT(cx, arglist);
	jsval *argv=JS_ARGV(cx, arglist);
deuce's avatar
deuce committed
	char		*p;
	JS_SET_RVAL(cx, arglist, JSVAL_VOID);

	if((cfg=(scfg_t*)JS_GetPrivate(cx,obj))==NULL)
		return(JS_FALSE);

	if(argc<1)
		t=time32(NULL);	/* use current time */
	else {
		if(JSVAL_IS_STRING(argv[0])) {	/* convert from string to time_t? */
deuce's avatar
deuce committed
			JSVALUE_TO_ASTRING(cx, argv[0], p, 10, NULL);
deuce's avatar
deuce committed
			JS_SET_RVAL(cx, arglist, DOUBLE_TO_JSVAL((double)dstrtounix(cfg, p)));
	if((js_str = JS_NewStringCopyZ(cx, str))==NULL)
		return(JS_FALSE);
	JS_SET_RVAL(cx, arglist, STRING_TO_JSVAL(js_str));
js_secondstr(JSContext *cx, uintN argc, jsval *arglist)
	jsval *argv=JS_ARGV(cx, arglist);
	JS_SET_RVAL(cx, arglist, JSVAL_NULL);
	JS_ValueToInt32(cx,argv[0],&t);
	if((js_str = JS_NewStringCopyZ(cx, str))==NULL)
		return(JS_FALSE);
	JS_SET_RVAL(cx, arglist, STRING_TO_JSVAL(js_str));
js_spamlog(JSContext *cx, uintN argc, jsval *arglist)
	JSObject *obj=JS_THIS_OBJECT(cx, arglist);
	jsval *argv=JS_ARGV(cx, arglist);
	uintN		i;
	char*		p;
	char*		prot=NULL;
	char*		reason=NULL;
	char*		host=NULL;
	char*		ip_addr=NULL;
	char*		to=NULL;
deuce's avatar
deuce committed
	jsrefcount	rc;
deuce's avatar
deuce committed
	BOOL		ret;
	JS_SET_RVAL(cx, arglist, JSVAL_VOID);

	if((cfg=(scfg_t*)JS_GetPrivate(cx,obj))==NULL)
		return(JS_FALSE);

	for(i=0;i<argc;i++) {
		if(!JSVAL_IS_STRING(argv[i]))
			continue;
deuce's avatar
deuce committed
		if(from==NULL) {
			JSVALUE_TO_MSTRING(cx, argv[i], p, NULL);
			if(JS_IsExceptionPending(cx)) {
				if(prot)
					free(prot);
				if(action)
					free(action);
				if(reason)
					free(reason);
				if(host)
					free(host);
				if(ip_addr)
					free(ip_addr);
				if(to)
					free(to);
				if(from)
					free(from);
				return JS_FALSE;
			}
		}
		if(p==NULL)
			continue;
		if(prot==NULL)
			prot=p;
		else if(action==NULL)
			action=p;
		else if(reason==NULL)
			reason=p;
		else if(host==NULL)
			host=p;
		else if(ip_addr==NULL)
			ip_addr=p;
		else if(to==NULL)
			to=p;
deuce's avatar
deuce committed
		else
			free(p);
deuce's avatar
deuce committed
	ret=spamlog(cfg,prot,action,reason,host,ip_addr,to,from);
	if(prot)
		free(prot);
	if(action)
		free(action);
	if(reason)
		free(reason);
	if(host)
		free(host);
	if(ip_addr)
		free(ip_addr);
	if(to)
		free(to);
	if(from)
		free(from);
deuce's avatar
deuce committed
	JS_SET_RVAL(cx, arglist, BOOLEAN_TO_JSVAL(ret));
	return(JS_TRUE);
}

static JSBool
js_hacklog(JSContext *cx, uintN argc, jsval *arglist)
	JSObject *obj=JS_THIS_OBJECT(cx, arglist);
	jsval *argv=JS_ARGV(cx, arglist);
	char*		p;
	char*		prot=NULL;
	char*		user=NULL;
	char*		text=NULL;
	char*		host=NULL;
	SOCKADDR_IN	addr;
	scfg_t*		cfg;
deuce's avatar
deuce committed
	jsrefcount	rc;
deuce's avatar
deuce committed
	BOOL		ret;
	JS_SET_RVAL(cx, arglist, JSVAL_VOID);

	if((cfg=(scfg_t*)JS_GetPrivate(cx,obj))==NULL)
		return(JS_FALSE);

	memset(&addr,0,sizeof(addr));
	for(i=0;i<argc;i++) {
		if(JSVAL_IS_NUMBER(argv[i])) {
			JS_ValueToInt32(cx,argv[i],&i32);
			if(addr.sin_addr.s_addr==0)
			continue;
		}
		if(!JSVAL_IS_STRING(argv[i]))
			continue;
deuce's avatar
deuce committed
		if(host==NULL) {
			JSVALUE_TO_MSTRING(cx, argv[i], p, NULL);
			if(JS_IsExceptionPending(cx)) {
				if(prot)
					free(prot);
				if(user)
					free(user);
				if(text)
					free(text);
				if(host)
					free(host);
				return JS_FALSE;
			}
		}
		if(p==NULL)
			continue;
		if(prot==NULL)
			prot=p;
		else if(user==NULL)
			user=p;
		else if(text==NULL)
			text=p;
		else if(host==NULL)
			host=p;
	}
deuce's avatar
deuce committed
	ret=hacklog(cfg,prot,user,text,host,&addr);
	if(prot)
		free(prot);
	if(user)
		free(user);
	if(text)
		free(text);
	if(host)
		free(host);
deuce's avatar
deuce committed
	JS_SET_RVAL(cx, arglist, BOOLEAN_TO_JSVAL(ret));
static JSBool
js_filter_ip(JSContext *cx, uintN argc, jsval *arglist)
	JSObject *obj=JS_THIS_OBJECT(cx, arglist);
	jsval *argv=JS_ARGV(cx, arglist);
	uintN		i;
	char*		p;
	char*		prot=NULL;
	char*		reason=NULL;
	char*		host=NULL;
	char*		ip_addr=NULL;
	char*		from=NULL;
	scfg_t*		cfg;
deuce's avatar
deuce committed
	jsrefcount	rc;
deuce's avatar
deuce committed
	BOOL		ret;
	JS_SET_RVAL(cx, arglist, JSVAL_VOID);

	if((cfg=(scfg_t*)JS_GetPrivate(cx,obj))==NULL)
		return(JS_FALSE);

	for(i=0;i<argc;i++) {
		if(!JSVAL_IS_STRING(argv[i]))
			continue;
deuce's avatar
deuce committed
		if(fname==NULL) {
			JSVALUE_TO_MSTRING(cx, argv[i], p, NULL);
			if(JS_IsExceptionPending(cx)) {
				if(prot)
					free(prot);
				if(reason)
					free(reason);
				if(host)
					free(host);
				if(ip_addr)
					free(ip_addr);
				if(from)
					free(from);
				if(fname)
					free(fname);
				return JS_FALSE;
			}
		}
		if(p==NULL)
			continue;
		if(prot==NULL)
			prot=p;
		else if(reason==NULL)
			reason=p;
		else if(host==NULL)
			host=p;
		else if(ip_addr==NULL)
			ip_addr=p;
		else if(from==NULL)
			from=p;
deuce's avatar
deuce committed
	ret=filter_ip(cfg,prot,reason,host,ip_addr,from,fname);
	if(prot)
		free(prot);
	if(reason)
		free(reason);
	if(host)
		free(host);
	if(ip_addr)
		free(ip_addr);
	if(from)
		free(from);
	if(fname)
		free(fname);
deuce's avatar
deuce committed
	JS_SET_RVAL(cx, arglist, BOOLEAN_TO_JSVAL(ret));
	return(JS_TRUE);
}

js_get_node_message(JSContext *cx, uintN argc, jsval *arglist)
	JSObject *obj=JS_THIS_OBJECT(cx, arglist);
	jsval *argv=JS_ARGV(cx, arglist);
	char*		buf;
	int32		node_num;
	JSString*	js_str;
	scfg_t*		cfg;
deuce's avatar
deuce committed
	jsrefcount	rc;
	JS_SET_RVAL(cx, arglist, JSVAL_NULL);

	if((cfg=(scfg_t*)JS_GetPrivate(cx,obj))==NULL)
		return(JS_FALSE);

	node_num=cfg->node_num;
	if(argc) 
		JS_ValueToInt32(cx,argv[0],&node_num);
	if(node_num<1)
		node_num=1;


	js_str=JS_NewStringCopyZ(cx, buf);
	free(buf);

	if(js_str==NULL)
		return(JS_FALSE);
	JS_SET_RVAL(cx, arglist, STRING_TO_JSVAL(js_str));
js_put_node_message(JSContext *cx, uintN argc, jsval *arglist)
	JSObject *obj=JS_THIS_OBJECT(cx, arglist);
	jsval *argv=JS_ARGV(cx, arglist);
	JSString*	js_msg;
	char*		msg;
	scfg_t*		cfg;
deuce's avatar
deuce committed
	jsrefcount	rc;
deuce's avatar
deuce committed
	BOOL		ret;
	JS_SET_RVAL(cx, arglist, JSVAL_VOID);

	if((cfg=(scfg_t*)JS_GetPrivate(cx,obj))==NULL)
		return(JS_FALSE);

	JS_ValueToInt32(cx,argv[0],&node);
	if(node<1)
		node=1;

	if((js_msg=JS_ValueToString(cx, argv[1]))==NULL) 
		return(JS_FALSE);

deuce's avatar
deuce committed
	JSSTRING_TO_MSTRING(cx, js_msg, msg, NULL);
	HANDLE_PENDING(cx)
deuce's avatar
deuce committed
	if(msg==NULL) 
deuce's avatar
deuce committed
		return(JS_TRUE);
deuce's avatar
deuce committed
	ret=putnmsg(cfg,node,msg)==0;
	free(msg);
deuce's avatar
deuce committed
	JS_SET_RVAL(cx, arglist, BOOLEAN_TO_JSVAL(ret));
js_get_telegram(JSContext *cx, uintN argc, jsval *arglist)
	JSObject *obj=JS_THIS_OBJECT(cx, arglist);
	jsval *argv=JS_ARGV(cx, arglist);
	char*		buf;
	int32		usernumber=1;
	JSString*	js_str;
	scfg_t*		cfg;
deuce's avatar
deuce committed
	jsrefcount	rc;
	JS_SET_RVAL(cx, arglist, JSVAL_NULL);

	if((cfg=(scfg_t*)JS_GetPrivate(cx,obj))==NULL)
		return(JS_FALSE);

	JS_ValueToInt32(cx,argv[0],&usernumber);
	if(usernumber<1)
		usernumber=1;


	js_str=JS_NewStringCopyZ(cx, buf);
	free(buf);

	if(js_str==NULL)
		return(JS_FALSE);
	JS_SET_RVAL(cx, arglist, STRING_TO_JSVAL(js_str));
js_put_telegram(JSContext *cx, uintN argc, jsval *arglist)
	JSObject *obj=JS_THIS_OBJECT(cx, arglist);
	jsval *argv=JS_ARGV(cx, arglist);
	JSString*	js_msg;
	char*		msg;
	scfg_t*		cfg;
deuce's avatar
deuce committed
	jsrefcount	rc;
deuce's avatar
deuce committed
	BOOL		ret;
	JS_SET_RVAL(cx, arglist, JSVAL_VOID);

	if((cfg=(scfg_t*)JS_GetPrivate(cx,obj))==NULL)
		return(JS_FALSE);

	JS_ValueToInt32(cx,argv[0],&usernumber);
	if(usernumber<1)
		usernumber=1;

	if((js_msg=JS_ValueToString(cx, argv[1]))==NULL) 
		return(JS_FALSE);

deuce's avatar
deuce committed
	JSSTRING_TO_MSTRING(cx, js_msg, msg, NULL);
	HANDLE_PENDING(cx);
	if(msg==NULL)
		return(JS_TRUE);
deuce's avatar
deuce committed
	ret=putsmsg(cfg,usernumber,msg)==0;
	free(msg);
deuce's avatar
deuce committed
	JS_SET_RVAL(cx, arglist, BOOLEAN_TO_JSVAL(ret));
js_new_user(JSContext *cx, uintN argc, jsval *arglist)
	JSObject *obj=JS_THIS_OBJECT(cx, arglist);
	jsval *argv=JS_ARGV(cx, arglist);
deuce's avatar
deuce committed
	jsrefcount	rc;
	JS_SET_RVAL(cx, arglist, JSVAL_VOID);

	if((cfg=(scfg_t*)JS_GetPrivate(cx,obj))==NULL)
		return(JS_FALSE);

	if(argc<1 || JSVAL_NULL_OR_VOID(argv[0])) {
		JS_ReportError(cx,"Missing or invalid argument");
		return JS_FALSE;
	}

deuce's avatar
deuce committed
	JSVALUE_TO_ASTRING(cx, argv[0], alias, LEN_ALIAS+2, NULL);
		JS_ReportError(cx,"Invalid or duplicate user alias: %s", alias);
		return JS_FALSE;
	}

	for(n=0;n<argc;n++) {
		if(JSVAL_IS_OBJECT(argv[n])) {
			JSClass*	cl;
			JSObject*	objarg = JSVAL_TO_OBJECT(argv[n]);
			if((cl=JS_GetClass(cx,objarg))!=NULL && strcmp(cl->name,"Client")==0) {
				client=JS_GetPrivate(cx,objarg);
				continue;
			}
		}
	}
	if(client!=NULL) {
		SAFECOPY(user.modem,client->protocol);
		SAFECOPY(user.comp,client->host);
		SAFECOPY(user.note,client->addr);
	}
	user.firston=user.laston=user.pwmod=time32(NULL);

	/* security */
	user.level=cfg->new_level;
	user.flags1=cfg->new_flags1;
	user.flags2=cfg->new_flags2;
	user.flags3=cfg->new_flags3;
	user.flags4=cfg->new_flags4;
	user.rest=cfg->new_rest;
	user.exempt=cfg->new_exempt;

	user.cdt=cfg->new_cdt;
	user.min=cfg->new_min;
	user.freecdt=cfg->level_freecdtperday[user.level];
	if(cfg->new_expire)
		user.expire=user.firston+((long)cfg->new_expire*24L*60L*60L);
	else
		user.expire=0;

	/* settings */
	if(cfg->total_fcomps)
		strcpy(user.tmpext,cfg->fcomp[0]->ext);
	else
		strcpy(user.tmpext,"ZIP");

	user.shell=cfg->new_shell;
	user.misc=cfg->new_misc|(AUTOTERM|COLOR);
	user.prot=cfg->new_prot;
rswindell's avatar
rswindell committed
		if(!stricmp(cfg->xedit[i]->code,cfg->new_xedit) && chk_ar(cfg,cfg->xedit[i]->ar,&user,/* client: */NULL))
		userobj=js_CreateUserObject(cx, obj, cfg, NULL, &user, /* client: */NULL, /* global_user: */FALSE);
		JS_SET_RVAL(cx, arglist, OBJECT_TO_JSVAL(userobj));
		JS_SET_RVAL(cx, arglist, INT_TO_JSVAL(i));
static JSBool
js_del_user(JSContext *cx, uintN argc, jsval *arglist)
{
	JSObject *obj=JS_THIS_OBJECT(cx, arglist);
	jsval *argv=JS_ARGV(cx, arglist);
	jsrefcount	rc;
	int32		n;
	scfg_t*		cfg;
	user_t		user;
	char		str[128];

	if((cfg=(scfg_t*)JS_GetPrivate(cx,obj))==NULL)
		return(JS_FALSE);

	if(!JS_ValueToInt32(cx,argv[0],&n))
		return(JS_FALSE);
	user.number=n;
	JS_SET_RVAL(cx, arglist, JSVAL_FALSE);	/* fail, by default */
	if(getuserdat(cfg, &user)==0
		&& putuserrec(cfg,n,U_MISC,8,ultoa(user.misc|DELETED,str,16))==0
		&& putusername(cfg,n,nulstr)==0)
		JS_SET_RVAL(cx, arglist, JSVAL_TRUE);	/* success */
js_exec(JSContext *cx, uintN argc, jsval *arglist)
	jsval *argv=JS_ARGV(cx, arglist);
deuce's avatar
deuce committed
	jsrefcount	rc;
deuce's avatar
deuce committed
	char	*cmd;
deuce's avatar
deuce committed
	int		ret;
deuce's avatar
deuce committed
	JSVALUE_TO_MSTRING(cx, argv[0], cmd, NULL);
	HANDLE_PENDING(cx);
	if(cmd==NULL) {
		JS_ReportError(cx, "Illegal NULL command");
		return JS_FALSE;
	}
deuce's avatar
deuce committed
	ret=system(cmd);
	free(cmd);
deuce's avatar
deuce committed
	JS_SET_RVAL(cx, arglist, INT_TO_JSVAL(ret));
js_popen(JSContext *cx, uintN argc, jsval *arglist)
	jsval *argv=JS_ARGV(cx, arglist);
	char		str[1024];
	char*		cmd;
	FILE*		fp;
	jsint		line=0;
	jsval		val;
	JSObject*	array;
	JSString*	js_str;
deuce's avatar
deuce committed
	jsrefcount	rc;
	JS_SET_RVAL(cx, arglist, JSVAL_VOID);

	if(argc<1)
		return(JS_TRUE);

	if((array=JS_NewArrayObject(cx,0,NULL))==NULL)
		return(JS_FALSE);

deuce's avatar
deuce committed
	JSVALUE_TO_MSTRING(cx, argv[0], cmd, NULL);
	HANDLE_PENDING(cx);
	if(cmd==NULL) {
		JS_ReportError(cx, "Illegal NULL command");
		return JS_FALSE;
	}
deuce's avatar
deuce committed
	if((fp=popen(cmd,"r"))==NULL) {
deuce's avatar
deuce committed
		free(cmd);
deuce's avatar
deuce committed
	free(cmd);
	while(!feof(fp)) {
		if(fgets(str,sizeof(str),fp)==NULL)
			break;
deuce's avatar
deuce committed
		if((js_str=JS_NewStringCopyZ(cx,str))==NULL) {
		val=STRING_TO_JSVAL(js_str);
deuce's avatar
deuce committed
        if(!JS_SetElement(cx, array, line++, &val)) {
    JS_SET_RVAL(cx, arglist, OBJECT_TO_JSVAL(array));
js_chksyspass(JSContext *cx, uintN argc, jsval *arglist)
	JSObject *obj=JS_THIS_OBJECT(cx, arglist);
	jsval *argv=JS_ARGV(cx, arglist);
deuce's avatar
deuce committed
	char		*pass;
	JS_SET_RVAL(cx, arglist, JSVAL_VOID);

	if((cfg=(scfg_t*)JS_GetPrivate(cx,obj))==NULL)
		return(JS_FALSE);

deuce's avatar
deuce committed
	JSVALUE_TO_ASTRING(cx, argv[0], pass, LEN_PASS+2, NULL); // +2 is so overly long passwords fail.
deuce's avatar
deuce committed
	JS_SET_RVAL(cx, arglist, BOOLEAN_TO_JSVAL(stricmp(pass,cfg->sys_pass)==0));

js_chkname(JSContext *cx, uintN argc, jsval *arglist)
	JSObject *obj=JS_THIS_OBJECT(cx, arglist);
	jsval *argv=JS_ARGV(cx, arglist);
deuce's avatar
deuce committed
	jsrefcount	rc;
	JS_SET_RVAL(cx, arglist, JSVAL_VOID);

deuce's avatar
deuce committed
	JSVALUE_TO_ASTRING(cx, argv[0], str, (LEN_ALIAS > LEN_NAME)?LEN_ALIAS+2:LEN_NAME+2, NULL);
	if((cfg=(scfg_t*)JS_GetPrivate(cx,obj))==NULL)
		return(JS_FALSE);
	JS_SET_RVAL(cx, arglist, BOOLEAN_TO_JSVAL(check_name(cfg,str)));
js_chkpid(JSContext *cx, uintN argc, jsval *arglist)
	jsval *argv=JS_ARGV(cx, arglist);
	JS_SET_RVAL(cx, arglist, JSVAL_FALSE);

	if(argc<1)
		return(JS_TRUE);

	JS_ValueToInt32(cx,argv[0],&pid);

	rc=JS_SUSPENDREQUEST(cx);
	JS_SET_RVAL(cx, arglist, BOOLEAN_TO_JSVAL(check_pid(pid)));
js_killpid(JSContext *cx, uintN argc, jsval *arglist)
	jsval *argv=JS_ARGV(cx, arglist);
	JS_SET_RVAL(cx, arglist, JSVAL_FALSE);

	if(argc<1)
		return(JS_TRUE);

	JS_ValueToInt32(cx,argv[0],&pid);

	rc=JS_SUSPENDREQUEST(cx);
	JS_SET_RVAL(cx, arglist, BOOLEAN_TO_JSVAL(terminate_pid(pid)));
static jsSyncMethodSpec js_system_functions[] = {
	{"username",		js_username,		1,	JSTYPE_STRING,	JSDOCSTR("number")
	,JSDOCSTR("returns name of user in specified user record <i>number</i>, or empty string if not found")
rswindell's avatar
rswindell committed
	{"alias",			js_alias,			1,	JSTYPE_STRING,	JSDOCSTR("alias")
	,JSDOCSTR("returns name of user that matches alias (if found in <tt>ctrl/alias.cfg</tt>)")
rswindell's avatar
rswindell committed
	{"matchuser",		js_matchuser,		1,	JSTYPE_NUMBER,	JSDOCSTR("username [,sysop_alias=<tt>true</tt>]")
	,JSDOCSTR("exact user name matching, returns number of user whose name/alias matches <i>username</i> "
		" or 0 if not found, matches well-known sysop aliases by default")
	{"matchuserdata",	js_matchuserdata,	2,	JSTYPE_NUMBER,	JSDOCSTR("field, data [,usernumber, match_next=<tt>false</tt>]")
	,JSDOCSTR("search user database for data in a specific field (see <tt>U_*</tt> in <tt>sbbsdefs.js</tt>), "
		"returns first matching user record number, optional <i>usernumber</i> specifies user record to skip, "
		"or record at which to begin searching if optional <i>match_next</i> is <tt>true</tt>")
	{"trashcan",		js_trashcan,		2,	JSTYPE_BOOLEAN,	JSDOCSTR("basename, find_string")
	,JSDOCSTR("search <tt>text/<i>basename</i>.can</tt> for pseudo-regexp")
rswindell's avatar
rswindell committed
	{"findstr",			js_findstr,			2,	JSTYPE_BOOLEAN,	JSDOCSTR("path/filename, find_string")
	,JSDOCSTR("search any file for pseudo-regexp")
rswindell's avatar
rswindell committed
	{"zonestr",			js_zonestr,			0,	JSTYPE_STRING,	JSDOCSTR("[timezone=<i>local</i>]")
	,JSDOCSTR("convert time zone integer to string, defaults to system timezone if <i>timezone</i> not specified")
rswindell's avatar
rswindell committed
	{"timestr",			js_timestr,			0,	JSTYPE_STRING,	JSDOCSTR("[time=<i>current</i>]")
	,JSDOCSTR("convert time_t integer into a time string, "
		"defaults to current time if <i>time</i> not specified")
rswindell's avatar
rswindell committed
	{"datestr",			js_datestr,			0,	JSTYPE_STRING,	JSDOCSTR("[time=<i>current</i>]")
	,JSDOCSTR("convert time_t integer into a date string (in either <tt>MM/DD/YY</tt> or <tt>DD/MM/YY</tt> format), "
		"defaults to current date if <i>time</i> not specified. "
		"If <i>time</i> is a string in the appropriate format, returns the time_t.")
	{"secondstr",		js_secondstr,		0,	JSTYPE_STRING,	JSDOCSTR("seconds")
	,JSDOCSTR("convert elapsed time in seconds into a string in <tt>hh:mm:ss</tt> format")
	{"spamlog",			js_spamlog,			6,	JSTYPE_BOOLEAN,	JSDOCSTR("[protocol, action, reason, host, ip, to, from]")
	,JSDOCSTR("log a suspected SPAM attempt")
	{"hacklog",			js_hacklog,			5,	JSTYPE_BOOLEAN,	JSDOCSTR("[protocol, user, text, host, ip, port]")
	,JSDOCSTR("log a suspected hack attempt")
	{"filter_ip",		js_filter_ip,		4,	JSTYPE_BOOLEAN,	JSDOCSTR("[protocol, reason, host, ip, username, filename]")
	,JSDOCSTR("add an IP address (with comment) to an IP filter file. If filename is not specified, the ip.can file is used")
rswindell's avatar
rswindell committed
	{"get_node_message",js_get_node_message,0,	JSTYPE_STRING,	JSDOCSTR("node_number")
	,JSDOCSTR("read any messages waiting for the specified node and return in a single string")
rswindell's avatar
rswindell committed
	{"put_node_message",js_put_node_message,2,	JSTYPE_BOOLEAN,	JSDOCSTR("node_number, message_text")
	,JSDOCSTR("send a node a short text message, delivered immediately")
rswindell's avatar
rswindell committed
	{"get_telegram",	js_get_telegram,	1,	JSTYPE_STRING,	JSDOCSTR("user_number")
	,JSDOCSTR("returns any short text messages waiting for the specified user")
rswindell's avatar
rswindell committed
	{"put_telegram",	js_put_telegram,	2,	JSTYPE_BOOLEAN,	JSDOCSTR("user_number, message_text")
	,JSDOCSTR("sends a user a short text message, delivered immediately or during next logon")
	{"newuser",			js_new_user,		1,	JSTYPE_ALIAS },
	{"new_user",		js_new_user,		1,	JSTYPE_OBJECT,	JSDOCSTR("name/alias [,client object]")
	,JSDOCSTR("creates a new user record, returns a new <a href=#User>User</a> object representing the new user account, on success.<br>"
	"returns an numeric error code on failure (optional <i>client</i> object argument added in v3.15a)")
	{"del_user",		js_del_user,		1,	JSTYPE_BOOLEAN,	JSDOCSTR("number")
	,JSDOCSTR("delete the specified user account")
	,316
	},
	{"exec",			js_exec,			1,	JSTYPE_NUMBER,	JSDOCSTR("command-line")
	,JSDOCSTR("executes a native system/shell command-line, returns <i>0</i> on success")
	},
	{"popen",			js_popen,			0,	JSTYPE_ARRAY,	JSDOCSTR("command-line")
	,JSDOCSTR("executes a native system/shell command-line, returns array of captured output lines on success "
		"(<b>only functional on UNIX systems</b>)")
rswindell's avatar
rswindell committed
	{"check_syspass",	js_chksyspass,		1,	JSTYPE_BOOLEAN,	JSDOCSTR("password")
	,JSDOCSTR("compares the supplied <i>password</i> against the system password and returns <i>true</i> if it matches")
	{"check_name",		js_chkname,			1,	JSTYPE_BOOLEAN,	JSDOCSTR("name/alias")
	,JSDOCSTR("checks that the provided name/alias string is suitable for a new user account, "
		"returns <i>true</i> if it is valid")
	{"check_pid",		js_chkpid,			1,	JSTYPE_BOOLEAN,	JSDOCSTR("process-ID")
	,JSDOCSTR("checks that the provided process ID is a valid executing process on the system, "
		"returns <i>true</i> if it is valid")
	,315
	},
	{"terminate_pid",	js_killpid,			1,	JSTYPE_BOOLEAN,	JSDOCSTR("process-ID")
	,JSDOCSTR("terminates executing process on the system with the specified process ID, "
		"returns <i>true</i> on success")
	,315
	},
/* node properties */
enum {
	/* raw node_t fields */
	 NODE_PROP_STATUS
	,NODE_PROP_ERRORS
	,NODE_PROP_ACTION
	,NODE_PROP_USERON
	,NODE_PROP_CONNECTION
	,NODE_PROP_MISC
	,NODE_PROP_AUX
	,NODE_PROP_EXTAUX
static char* node_prop_desc[] = {
	 "status (see <tt>nodedefs.js</tt> for valid values)"
	,"error counter"
	,"current user action (see <tt>nodedefs.js</tt>)"
	,"current user number"
	,"connection speed (<tt>0xffff</tt> = Telnet or RLogin)"
	,"miscellaneous bitfield (see <tt>nodedefs.js</tt>)"
	,"auxillary value"
	,"extended auxillary value"
static JSBool js_node_get(JSContext *cx, JSObject *obj, jsid id, jsval *vp)
	uint		node_num;
    jsint       tiny;
	node_t		node;
	scfg_t*		cfg;
	JSObject*	sysobj;
	JSObject*	node_list;
deuce's avatar
deuce committed
	jsrefcount	rc;
	JS_IdToValue(cx, id, &idval);
	tiny = JSVAL_TO_INT(idval);

	if((node_list=JS_GetParent(cx, obj))==NULL)
		return(JS_FALSE);

	if((sysobj=JS_GetParent(cx, node_list))==NULL)
		return(JS_FALSE);

	if((cfg=(scfg_t*)JS_GetPrivate(cx,sysobj))==NULL)
		return(JS_FALSE);

	node_num=(uint)JS_GetPrivate(cx,obj)>>1;

	memset(&node,0,sizeof(node));
deuce's avatar
deuce committed
	if(getnodedat(cfg, node_num, &node, NULL)) {
		return(JS_TRUE);
	
    switch(tiny) {
		case NODE_PROP_STATUS:
			*vp = INT_TO_JSVAL((int)node.status);
			break;
		case NODE_PROP_ERRORS:	
			*vp = INT_TO_JSVAL((int)node.errors);
			break;
		case NODE_PROP_ACTION:	
			*vp = INT_TO_JSVAL((int)node.action);
			break;
		case NODE_PROP_USERON:	
			*vp = INT_TO_JSVAL((int)node.useron);
			break;
		case NODE_PROP_CONNECTION:
			*vp = INT_TO_JSVAL((int)node.connection);
			break;
		case NODE_PROP_MISC:		
			*vp = INT_TO_JSVAL((int)node.misc);
			break;
		case NODE_PROP_AUX:		
			*vp = INT_TO_JSVAL((int)node.aux);
			break;
		case NODE_PROP_EXTAUX:	
			*vp=UINT_TO_JSVAL(node.extaux);
		case NODE_PROP_DIR:
			if((js_str=JS_NewStringCopyZ(cx, cfg->node_path[node_num-1]))==NULL)
				return(JS_FALSE);
			*vp = STRING_TO_JSVAL(js_str);
			break;