Newer
Older
JS_SET_RVAL(cx, arglist, JSVAL_VOID);
if((cfg=(scfg_t*)JS_GetPrivate(cx,obj))==NULL)
return(JS_FALSE);
if(argc<1)
zone=sys_timezone(cfg);
else {
JS_ValueToInt32(cx,argv[0],&val);
zone=(short)val;
}
rc=JS_SUSPENDREQUEST(cx);
JS_RESUMEREQUEST(cx, rc);
if((js_str = JS_NewStringCopyZ(cx, cstr))==NULL)
JS_SET_RVAL(cx, arglist, STRING_TO_JSVAL(js_str));
/* Returns a ctime()-like string in the system-preferred time format */

rswindell
committed
static JSBool
js_timestr(JSContext *cx, uintN argc, jsval *arglist)

rswindell
committed
{
JSObject *obj=JS_THIS_OBJECT(cx, arglist);
jsval *argv=JS_ARGV(cx, arglist);

rswindell
committed
char str[128];
jsdouble ti;

rswindell
committed
JSString* js_str;
scfg_t* cfg;

rswindell
committed
JS_SET_RVAL(cx, arglist, JSVAL_VOID);

rswindell
committed
if((cfg=(scfg_t*)JS_GetPrivate(cx,obj))==NULL)
return(JS_FALSE);
if(argc<1)
ti=(jsdouble)time(NULL); /* use current time */

rswindell
committed
else
JS_ValueToNumber(cx,argv[0],&ti);
rc=JS_SUSPENDREQUEST(cx);
timestr(cfg,(time32_t)ti,str);
JS_RESUMEREQUEST(cx, rc);
if((js_str = JS_NewStringCopyZ(cx, str))==NULL)
return(JS_FALSE);

rswindell
committed
JS_SET_RVAL(cx, arglist, STRING_TO_JSVAL(js_str));

rswindell
committed
return(JS_TRUE);
}
/* Returns a mm/dd/yy or dd/mm/yy formated string */
static JSBool
js_datestr(JSContext *cx, uintN argc, jsval *arglist)
JSObject *obj=JS_THIS_OBJECT(cx, arglist);
jsval *argv=JS_ARGV(cx, arglist);
char str[128];
time32_t t;
JSString* js_str;
scfg_t* cfg;
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? */
JS_SET_RVAL(cx, arglist, DOUBLE_TO_JSVAL((double)dstrtounix(cfg, p)));
return(JS_TRUE);
}
JS_ValueToInt32(cx,argv[0],&t);
}
unixtodstr(cfg,t,str);
if((js_str = JS_NewStringCopyZ(cx, str))==NULL)
return(JS_FALSE);
JS_SET_RVAL(cx, arglist, STRING_TO_JSVAL(js_str));
return(JS_TRUE);
}
static JSBool
js_secondstr(JSContext *cx, uintN argc, jsval *arglist)
jsval *argv=JS_ARGV(cx, arglist);
char str[128];
int32 t=0;
JSString* js_str;
JS_SET_RVAL(cx, arglist, JSVAL_NULL);
if(argc<1)
return(JS_TRUE);
JS_ValueToInt32(cx,argv[0],&t);
sectostr(t,str);
if((js_str = JS_NewStringCopyZ(cx, str))==NULL)
return(JS_FALSE);
JS_SET_RVAL(cx, arglist, STRING_TO_JSVAL(js_str));
return(JS_TRUE);
}
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* action=NULL;
char* reason=NULL;
char* host=NULL;
char* ip_addr=NULL;
char* to=NULL;
char* from=NULL;
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;
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;
else if(from==NULL)
from=p;
rc=JS_SUSPENDREQUEST(cx);
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);
JS_RESUMEREQUEST(cx, rc);
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);
int32 i32=0;
char* p;
char* prot=NULL;
char* user=NULL;
char* text=NULL;
char* host=NULL;
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.in.sin_addr.s_addr==0)
addr.in.sin_addr.s_addr=i32;
continue;
}
if(!JSVAL_IS_STRING(argv[i]))
continue;
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;
}
rc=JS_SUSPENDREQUEST(cx);
ret=hacklog(cfg,prot,user,text,host,&addr);
if(prot)
free(prot);
if(user)
free(user);
if(text)
free(text);
if(host)
free(host);
JS_RESUMEREQUEST(cx, rc);
JS_SET_RVAL(cx, arglist, BOOLEAN_TO_JSVAL(ret));
return(JS_TRUE);
}
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* ip_addr=NULL;
char* from=NULL;
char* fname=NULL;
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;
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(ip_addr==NULL)
ip_addr=p;
else if(from==NULL)
from=p;
else if(fname==NULL)
fname=p;
rc=JS_SUSPENDREQUEST(cx);
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);
JS_RESUMEREQUEST(cx, rc);
JS_SET_RVAL(cx, arglist, BOOLEAN_TO_JSVAL(ret));
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;
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;
rc=JS_SUSPENDREQUEST(cx);
buf=getnmsg(cfg,node_num);
JS_RESUMEREQUEST(cx, rc);
if(buf==NULL)
return(JS_TRUE);
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));
return(JS_TRUE);
}
js_put_node_message(JSContext *cx, uintN argc, jsval *arglist)
JSObject *obj=JS_THIS_OBJECT(cx, arglist);
jsval *argv=JS_ARGV(cx, arglist);
int32 node=1;
JSString* js_msg;
char* msg;
scfg_t* cfg;
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);
JSSTRING_TO_MSTRING(cx, js_msg, msg, NULL);
HANDLE_PENDING(cx)
rc=JS_SUSPENDREQUEST(cx);
JS_RESUMEREQUEST(cx, rc);
JS_SET_RVAL(cx, arglist, BOOLEAN_TO_JSVAL(ret));
return(JS_TRUE);
}
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;
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;
rc=JS_SUSPENDREQUEST(cx);
buf=getsmsg(cfg,usernumber);
JS_RESUMEREQUEST(cx, rc);
if(buf==NULL)
return(JS_TRUE);
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));
return(JS_TRUE);
}
js_put_telegram(JSContext *cx, uintN argc, jsval *arglist)
JSObject *obj=JS_THIS_OBJECT(cx, arglist);
jsval *argv=JS_ARGV(cx, arglist);
int32 usernumber=1;
JSString* js_msg;
char* msg;
scfg_t* cfg;
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);
JSSTRING_TO_MSTRING(cx, js_msg, msg, NULL);
HANDLE_PENDING(cx);
if(msg==NULL)
return(JS_TRUE);
rc=JS_SUSPENDREQUEST(cx);
ret=putsmsg(cfg,usernumber,msg)==0;
free(msg);
JS_RESUMEREQUEST(cx, rc);
JS_SET_RVAL(cx, arglist, BOOLEAN_TO_JSVAL(ret));
return(JS_TRUE);
}
static JSBool
js_new_user(JSContext *cx, uintN argc, jsval *arglist)
{
JSObject *obj=JS_THIS_OBJECT(cx, arglist);
jsval *argv=JS_ARGV(cx, arglist);
char* alias;
int i;
uintN n;
scfg_t* cfg;
user_t user;
JSObject* userobj;
JSObject* objarg;
JSClass* cl;
client_t* client=NULL;
jsval val;
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;
}
JSVALUE_TO_ASTRING(cx, argv[0], alias, LEN_ALIAS+2, NULL);
rc=JS_SUSPENDREQUEST(cx);
if(!check_name(cfg,alias)) {
JS_RESUMEREQUEST(cx, rc);
JS_ReportError(cx,"Invalid or duplicate user alias: %s", alias);
return JS_FALSE;
}
memset(&user,0,sizeof(user));
for(n=0;n<argc;n++) {
if(JSVAL_IS_OBJECT(argv[n])) {
objarg = JSVAL_TO_OBJECT(argv[n]);
if((cl=JS_GetClass(cx,objarg))!=NULL && strcmp(cl->name,"Client")==0) {
client=JS_GetPrivate(cx,objarg);
continue;
}
}
}
// Find and use the global client object if possible...
if(client==NULL) {
if(JS_GetProperty(cx, JS_GetGlobalObject(cx), "client", &val) && !JSVAL_NULL_OR_VOID(val)) {
objarg = JSVAL_TO_OBJECT(val);
if((cl=JS_GetClass(cx,objarg))!=NULL && strcmp(cl->name,"Client")==0)
client=JS_GetPrivate(cx,objarg);
}
}
if(client!=NULL) {
SAFECOPY(user.modem,client->protocol);
SAFECOPY(user.comp,client->host);
}
SAFECOPY(user.alias,alias);
/* statistics */
user.firston=user.laston=user.pwmod=time32(NULL);
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
/* 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;
user.qwk=QWK_DEFAULT;
for(i=0;i<cfg->total_xedits;i++)
if(!stricmp(cfg->xedit[i]->code,cfg->new_xedit) && chk_ar(cfg,cfg->xedit[i]->ar,&user,/* client: */NULL))
break;
if(i<cfg->total_xedits)
user.xedit=i+1;
i=newuserdat(cfg,&user);
JS_RESUMEREQUEST(cx, rc);
if(i==0) {
userobj=js_CreateUserObject(cx, obj, cfg, NULL, &user, /* client: */NULL, /* global_user: */FALSE);
JS_SET_RVAL(cx, arglist, OBJECT_TO_JSVAL(userobj));
} else
JS_SET_RVAL(cx, arglist, INT_TO_JSVAL(i));
return(JS_TRUE);
}
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;
rc=JS_SUSPENDREQUEST(cx);
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_RESUMEREQUEST(cx, rc);
return(JS_TRUE);
}
static JSBool
js_exec(JSContext *cx, uintN argc, jsval *arglist)
{
jsval *argv=JS_ARGV(cx, arglist);
JSVALUE_TO_MSTRING(cx, argv[0], cmd, NULL);
HANDLE_PENDING(cx);
if(cmd==NULL) {
JS_ReportError(cx, "Illegal NULL command");
return JS_FALSE;
}
rc=JS_SUSPENDREQUEST(cx);
JS_RESUMEREQUEST(cx, rc);
return(JS_TRUE);
}
static JSBool
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;
JS_SET_RVAL(cx, arglist, JSVAL_VOID);
if(argc<1)
return(JS_TRUE);
if((array=JS_NewArrayObject(cx,0,NULL))==NULL)
return(JS_FALSE);
JSVALUE_TO_MSTRING(cx, argv[0], cmd, NULL);
HANDLE_PENDING(cx);
if(cmd==NULL) {
JS_ReportError(cx, "Illegal NULL command");
return JS_FALSE;
}
rc=JS_SUSPENDREQUEST(cx);
JS_RESUMEREQUEST(cx, rc);
return(JS_TRUE);
while(!feof(fp)) {
if(fgets(str,sizeof(str),fp)==NULL)
break;
JS_RESUMEREQUEST(cx, rc);
if((js_str=JS_NewStringCopyZ(cx,str))==NULL) {
rc=JS_SUSPENDREQUEST(cx);
val=STRING_TO_JSVAL(js_str);
if(!JS_SetElement(cx, array, line++, &val)) {
rc=JS_SUSPENDREQUEST(cx);
rc=JS_SUSPENDREQUEST(cx);
}
pclose(fp);
JS_RESUMEREQUEST(cx, rc);
JS_SET_RVAL(cx, arglist, OBJECT_TO_JSVAL(array));
return(JS_TRUE);
}
static JSBool
js_chksyspass(JSContext *cx, uintN argc, jsval *arglist)
JSObject *obj=JS_THIS_OBJECT(cx, arglist);
jsval *argv=JS_ARGV(cx, arglist);
scfg_t* cfg;
JS_SET_RVAL(cx, arglist, JSVAL_VOID);
if((cfg=(scfg_t*)JS_GetPrivate(cx,obj))==NULL)
return(JS_FALSE);
JSVALUE_TO_ASTRING(cx, argv[0], pass, LEN_PASS+2, NULL); // +2 is so overly long passwords fail.
JS_SET_RVAL(cx, arglist, BOOLEAN_TO_JSVAL(stricmp(pass,cfg->sys_pass)==0));
return(JS_TRUE);
}
static JSBool
js_chkname(JSContext *cx, uintN argc, jsval *arglist)
JSObject *obj=JS_THIS_OBJECT(cx, arglist);
jsval *argv=JS_ARGV(cx, arglist);
char* str;
scfg_t* cfg;
JS_SET_RVAL(cx, arglist, JSVAL_VOID);
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);
rc=JS_SUSPENDREQUEST(cx);
JS_SET_RVAL(cx, arglist, BOOLEAN_TO_JSVAL(check_name(cfg,str)));
JS_RESUMEREQUEST(cx, rc);
return(JS_TRUE);
}
static JSBool
js_chkpid(JSContext *cx, uintN argc, jsval *arglist)
{
jsval *argv=JS_ARGV(cx, arglist);
int32 pid=0;
jsrefcount rc;
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_RESUMEREQUEST(cx, rc);
return(JS_TRUE);
}
static JSBool
js_killpid(JSContext *cx, uintN argc, jsval *arglist)
{
jsval *argv=JS_ARGV(cx, arglist);
int32 pid=0;
jsrefcount rc;
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)));
JS_RESUMEREQUEST(cx, rc);
return(JS_TRUE);
}
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")
,311
},
{"alias", js_alias, 1, JSTYPE_STRING, JSDOCSTR("alias")
,JSDOCSTR("returns name of user that matches alias (if found in <tt>ctrl/alias.cfg</tt>)")
,310
{"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")
,310
{"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>")
,310
},
{"trashcan", js_trashcan, 2, JSTYPE_BOOLEAN, JSDOCSTR("basename, find_string")
,JSDOCSTR("search <tt>text/<i>basename</i>.can</tt> for pseudo-regexp")
,310
{"findstr", js_findstr, 2, JSTYPE_BOOLEAN, JSDOCSTR("path/filename, find_string")
,JSDOCSTR("search any file for pseudo-regexp")
,310
{"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")
,310
{"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")
,310
{"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.")
,310
{"secondstr", js_secondstr, 0, JSTYPE_STRING, JSDOCSTR("seconds")
,JSDOCSTR("convert elapsed time in seconds into a string in <tt>hh:mm:ss</tt> format")
,310
{"spamlog", js_spamlog, 6, JSTYPE_BOOLEAN, JSDOCSTR("[protocol, action, reason, host, ip, to, from]")
,310
{"hacklog", js_hacklog, 5, JSTYPE_BOOLEAN, JSDOCSTR("[protocol, user, text, host, ip, port]")
,JSDOCSTR("log a suspected hack attempt")
,310
{"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")
,311
{"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")
,311
{"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")
,310
{"get_telegram", js_get_telegram, 1, JSTYPE_STRING, JSDOCSTR("user_number")
,JSDOCSTR("returns any short text messages waiting for the specified user")
,311
{"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")
,310
{"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. As of 3.16c, the global "
"client object is used if the argument is omitted)")
,310
},
{"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")
,311
},
{"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>)")
,311
{"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")
,311
{"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
#ifdef BUILD_JSDOCS
"status (see <tt>nodedefs.js</tt> for valid values)"
,"current user action (see <tt>nodedefs.js</tt>)"
,"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)
jsval idval;
uint node_num;
jsint tiny;
node_t node;
scfg_t* cfg;
JSObject* sysobj;
JSObject* node_list;
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=(uintptr_t)JS_GetPrivate(cx,obj)>>1;
rc=JS_SUSPENDREQUEST(cx);
JS_RESUMEREQUEST(cx, rc);
JS_RESUMEREQUEST(cx, rc);
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;