Newer
Older
{"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
#ifndef JSDOOR
{"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", js_get_node, 1, JSTYPE_OBJECT, JSDOCSTR("node_number")
,JSDOCSTR("read a node data record all at once (and leaving the record unlocked) "
"returning an object matching the elements of <tt>system.node_list</tt>")
,31702
},
{"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

Rob Swindell
committed
{"notify", js_notify, 2, JSTYPE_BOOLEAN, JSDOCSTR("user_number, subject [,message_text]")
,JSDOCSTR("notify a user or operator via both email and a short text message about an important event")
,31801
},
{"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
},

Rob Swindell
committed
{"del_user", js_del_user, 1, JSTYPE_BOOLEAN, JSDOCSTR("user_number")
,JSDOCSTR("delete the specified user account")
,316
},
#endif
{"exec", js_sys_exec, 0, 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
#ifndef JSDOOR
{"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")
#endif
{"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;
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);
js_system_private_t* sys;
if((sys = (js_system_private_t*)js_GetClassPrivate(cx,sysobj,&js_system_class))==NULL)
return JS_FALSE;
node_num=(uintptr_t)JS_GetPrivate(cx,obj)>>1;
rc=JS_SUSPENDREQUEST(cx);
if(getnodedat(sys->cfg, node_num, &node, /* lockit: */FALSE, &sys->nodefile)) {
JS_RESUMEREQUEST(cx, rc);
JS_RESUMEREQUEST(cx, rc);
sys->nodegets++;
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
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, sys->cfg->node_path[node_num-1]))==NULL)
return(JS_FALSE);
*vp = STRING_TO_JSVAL(js_str);
break;
}
return(JS_TRUE);
}
static JSBool js_node_set(JSContext *cx, JSObject *obj, jsid id, JSBool strict, jsval *vp)
jsval idval;
jsint tiny;
node_t node;
JSObject* sysobj;
JSObject* node_list;
if((node_list=JS_GetParent(cx, obj))==NULL)
return(JS_FALSE);
if((sysobj=JS_GetParent(cx, node_list))==NULL)
return(JS_FALSE);
js_system_private_t* sys;
if((sys = (js_system_private_t*)js_GetClassPrivate(cx,sysobj,&js_system_class))==NULL)
return JS_FALSE;
node_num=(uintptr_t)JS_GetPrivate(cx,obj)>>1;
rc=JS_SUSPENDREQUEST(cx);
if(getnodedat(sys->cfg, node_num, &node, /* lockit: */TRUE, &sys->nodefile)) {
JS_RESUMEREQUEST(cx, rc);
JS_RESUMEREQUEST(cx, rc);
if(JSVAL_IS_NUMBER(*vp))
JS_IdToValue(cx, id, &idval);
tiny = JSVAL_TO_INT(idval);
rc=JS_SUSPENDREQUEST(cx);
switch(tiny) {
case NODE_PROP_STATUS:
node.status=(BYTE)val;
break;
case NODE_PROP_ERRORS:
node.errors=(BYTE)val;
break;
case NODE_PROP_ACTION:
node.action=(BYTE)val;
break;
case NODE_PROP_USERON:
node.useron=(WORD)val;
break;
case NODE_PROP_CONNECTION:
node.connection=(WORD)val;
node.misc=(WORD)val;
node.aux=(WORD)val;
break;
case NODE_PROP_EXTAUX:
node.extaux=val;
break;
}
putnodedat(sys->cfg,node_num,&node, /* closeit: */FALSE, sys->nodefile);
JS_RESUMEREQUEST(cx, rc);
return(JS_TRUE);
}
static jsSyncPropertySpec js_node_properties[] = {
/* name, tinyid, flags, ver */
{ "status", NODE_PROP_STATUS, JSPROP_ENUMERATE, 310 },
{ "errors", NODE_PROP_ERRORS, JSPROP_ENUMERATE, 310 },
{ "action", NODE_PROP_ACTION, JSPROP_ENUMERATE, 310 },
{ "useron", NODE_PROP_USERON, JSPROP_ENUMERATE, 310 },
{ "connection", NODE_PROP_CONNECTION, JSPROP_ENUMERATE, 310 },
{ "misc", NODE_PROP_MISC, JSPROP_ENUMERATE, 310 },
{ "aux", NODE_PROP_AUX, JSPROP_ENUMERATE, 310 },
{ "extaux", NODE_PROP_EXTAUX, JSPROP_ENUMERATE, 310 },
{ "dir", NODE_PROP_DIR, JSPROP_ENUMERATE|JSPROP_READONLY, 315 },
static JSBool js_node_resolve(JSContext *cx, JSObject *obj, jsid id)
if(id != JSID_VOID && id != JSID_EMPTY) {
jsval idval;
JS_IdToValue(cx, id, &idval);
if(JSVAL_IS_STRING(idval)) {
JSSTRING_TO_MSTRING(cx, JSVAL_TO_STRING(idval), name, NULL);
HANDLE_PENDING(cx, name);
ret=js_SyncResolve(cx, obj, name, js_node_properties, NULL, NULL, 0);
if(name)
free(name);
return(ret);
}
static JSBool js_node_enumerate(JSContext *cx, JSObject *obj)
{
static JSClass js_node_class = {
"Node" /* name */
,JSCLASS_HAS_PRIVATE /* flags */
,JS_PropertyStub /* addProperty */
,JS_PropertyStub /* delProperty */
,js_node_get /* getProperty */
,js_node_set /* setProperty */
,js_node_enumerate /* enumerate */
,js_node_resolve /* resolve */
,JS_ConvertStub /* convert */
,JS_FinalizeStub /* finalize */
};
#define LAZY_INTEGER(PropName, PropValue) \
if(name==NULL || strcmp(name, (PropName))==0) { \
val=UINT_TO_JSVAL((PropValue)); \
JS_DefineProperty(cx, obj, (PropName), val, NULL,NULL,JSPROP_ENUMERATE); \
if(name) { \
free(name); \
return(JS_TRUE); \
} \
#define LAZY_STRING(PropName, PropValue) \
if(name==NULL || strcmp(name, (PropName))==0) { \
if((js_str=JS_NewStringCopyZ(cx, (PropValue)))!=NULL) { \
JS_DefineProperty(cx, obj, PropName, STRING_TO_JSVAL(js_str), NULL, NULL, JSPROP_ENUMERATE); \
if(name) { \
free(name); \
return(JS_TRUE); \
} \
} \
else if(name) { \
free(name); \
return(JS_TRUE); \
#define LAZY_STRFUNC(PropName, Function, PropValue) \
if(name==NULL || strcmp(name, (PropName))==0) { \
Function; \
if((js_str=JS_NewStringCopyZ(cx, (PropValue)))!=NULL) { \
JS_DefineProperty(cx, obj, PropName, STRING_TO_JSVAL(js_str), NULL, NULL, JSPROP_ENUMERATE); \
if(name) { \
free(name); \
return(JS_TRUE); \
} \
} \
else if(name) { \
free(name); \
return(JS_TRUE); \
#define LAZY_STRFUNC_TRUNCSP(PropName, Function, PropValue) \
if(name==NULL || strcmp(name, (PropName))==0) { \
Function; \
if((js_str=JS_NewStringCopyZ(cx, truncsp(PropValue)))!=NULL) { \
JS_DefineProperty(cx, obj, PropName, STRING_TO_JSVAL(js_str), NULL, NULL, JSPROP_ENUMERATE); \
if(name) { \
free(name); \
return(JS_TRUE); \
} \
} \
else if(name) { \
free(name); \
return(JS_TRUE); \
static JSBool js_system_resolve(JSContext *cx, JSObject *obj, jsid id)
{
char* name=NULL;
jsval val;
char str[256];
JSString* js_str;
JSBool ret;
#ifndef JSDOOR
JSObject* newobj;
JSObject* nodeobj;
uint i;
#endif
if(id != JSID_VOID && id != JSID_EMPTY) {
jsval idval;
JS_IdToValue(cx, id, &idval);
if(JSVAL_IS_STRING(idval)) {
JSSTRING_TO_MSTRING(cx, JSVAL_TO_STRING(idval), name, NULL);
HANDLE_PENDING(cx, name);
/****************************/
/* static string properties */
LAZY_STRING("version", VERSION);
LAZY_STRFUNC("revision", sprintf(str,"%c",REVISION), str);
LAZY_STRFUNC_TRUNCSP("beta_version", SAFECOPY(str, beta_version), str);
if(name==NULL || strcmp(name, "full_version")==0) {
sprintf(str,"%s%c%s",VERSION,REVISION,beta_version);
truncsp(str);
if((js_str=JS_NewStringCopyZ(cx, str))!=NULL) {
val = STRING_TO_JSVAL(js_str);
JS_SetProperty(cx, obj, "full_version", &val);
if(name) return(JS_TRUE);
}
else if(name) return(JS_TRUE);
}
/* Numeric version properties */
LAZY_INTEGER("version_num", VERSION_NUM);
LAZY_INTEGER("version_hex", VERSION_HEX);
LAZY_STRING("architecture", ARCHITECTURE_DESC);
LAZY_STRFUNC("msgbase_lib", sprintf(str,"SMBLIB %s",smb_lib_ver()), str);
LAZY_STRFUNC("compiled_with", DESCRIBE_COMPILER(str), str);
LAZY_STRFUNC("compiled_when", sprintf(str,"%s %.5s",__DATE__,__TIME__), str);
LAZY_STRING("copyright", COPYRIGHT_NOTICE);
LAZY_STRING("js_version", (char *)JS_GetImplementationVersion());
LAZY_STRING("os_version", os_version(str));
#ifndef JSDOOR
/* fido_addr_list property */
if(name==NULL || strcmp(name, "fido_addr_list")==0) {
js_system_private_t* sys;
if((sys = (js_system_private_t*)js_GetClassPrivate(cx,obj,&js_system_class))==NULL)
return JS_FALSE;
if((newobj=JS_NewArrayObject(cx, 0, NULL))==NULL)
return(JS_FALSE);
if(!JS_SetParent(cx, newobj, obj))
return(JS_FALSE);
if(!JS_DefineProperty(cx, obj, "fido_addr_list", OBJECT_TO_JSVAL(newobj)
, NULL, NULL, JSPROP_ENUMERATE))
return(JS_FALSE);
for(i=0;i<sys->cfg->total_faddrs;i++) {
val=STRING_TO_JSVAL(JS_NewStringCopyZ(cx,smb_faddrtoa(&sys->cfg->faddr[i],str)));
JS_SetElement(cx, newobj, i, &val);
}
if(name) return(JS_TRUE);
}
js_system_private_t* sys;
if((sys = (js_system_private_t*)js_GetClassPrivate(cx,obj,&js_system_class))==NULL)
return JS_FALSE;
newobj = JS_DefineObject(cx, obj, "stats", &js_sysstats_class, NULL
,JSPROP_ENUMERATE|JSPROP_READONLY);
JS_SetPrivate(cx, newobj, sys);
#ifdef BUILD_JSDOCS
js_DescribeSyncObject(cx,newobj,"System statistics",310);
js_CreateArrayOfStrings(cx, newobj, "_property_desc_list", sysstat_prop_desc, JSPROP_READONLY);
#endif
/* node_list property */
if(name==NULL || strcmp(name, "node_list")==0) {
js_system_private_t* sys;
if((sys = (js_system_private_t*)js_GetClassPrivate(cx,obj,&js_system_class))==NULL)
return JS_FALSE;
if((newobj=JS_NewArrayObject(cx, 0, NULL))==NULL)
return(JS_FALSE);
if(!JS_SetParent(cx, newobj, obj))
return(JS_FALSE);
if(!JS_DefineProperty(cx, obj, "node_list", OBJECT_TO_JSVAL(newobj)
, NULL, NULL, JSPROP_ENUMERATE))
return(JS_FALSE);
for(i=0;i<sys->cfg->sys_nodes && i<sys->cfg->sys_lastnode;i++) {
nodeobj = JS_NewObject(cx, &js_node_class, NULL, newobj);
if(nodeobj==NULL)
return(JS_FALSE);
/* Store node number */
/* We have to shift it to make it look like a pointer to JS. :-( */
if(!JS_SetPrivate(cx, nodeobj, (char*)(((uintptr_t)i+1)<<1)))
#ifdef BUILD_JSDOCS
if(i==0) {
js_DescribeSyncObject(cx,nodeobj,"BBS node listing",310);
js_CreateArrayOfStrings(cx, nodeobj, "_property_desc_list", node_prop_desc, JSPROP_READONLY);
}
#endif
val=OBJECT_TO_JSVAL(nodeobj);
if(!JS_SetElement(cx, newobj, i, &val))
return(JS_FALSE);
}
if(name) return(JS_TRUE);
#endif
ret = js_SyncResolve(cx, obj, name, js_system_properties, js_system_functions, NULL, 0);
if(name) free(name);
return ret;
static JSBool js_system_enumerate(JSContext *cx, JSObject *obj)
{
return(js_system_resolve(cx, obj, JSID_VOID));
static void js_system_finalize(JSContext *cx, JSObject *obj)
{
js_system_private_t* sys;
if((sys = (js_system_private_t*)JS_GetPrivate(cx, obj)) == NULL)
return;
CLOSE_OPEN_FILE(sys->nodefile);
free(sys);
JS_SetPrivate(cx, obj, NULL);
}
JSClass js_system_class = {
"System" /* name */
,JSCLASS_HAS_PRIVATE /* flags */
,JS_PropertyStub /* addProperty */
,JS_PropertyStub /* delProperty */
,js_system_get /* getProperty */
,js_system_set /* setProperty */
,js_system_enumerate /* enumerate */
,js_system_resolve /* resolve */
,JS_ConvertStub /* convert */
,js_system_finalize /* finalize */
JSObject* DLLCALL js_CreateSystemObject(JSContext* cx, JSObject* parent
,scfg_t* cfg, time_t uptime, char* host_name, char* socklib_desc)
{
jsval val;
JSObject* sysobj;
JSString* js_str;
char str[256];
sysobj = JS_DefineObject(cx, parent, "system", &js_system_class, NULL
,JSPROP_ENUMERATE|JSPROP_READONLY);
if(sysobj==NULL)
js_system_private_t* sys;
if((sys = calloc(sizeof(*sys), 1)) == NULL)
return NULL;
sys->cfg = cfg;
sys->nodefile = -1;
if(!JS_SetPrivate(cx, sysobj, sys))
return(NULL);
/****************************/
/* static string properties */
#ifndef JSDOOR
if((js_str=JS_NewStringCopyZ(cx, host_name))==NULL)
return(NULL);
val = STRING_TO_JSVAL(js_str);
if(!JS_SetProperty(cx, sysobj, "host_name", &val))
return(NULL);
#endif
if((js_str=JS_NewStringCopyZ(cx, socklib_version(str, socklib_desc)))==NULL)
return(NULL);
val = STRING_TO_JSVAL(js_str);
if(!JS_SetProperty(cx, sysobj, "socket_lib", &val))
return(NULL);
#ifndef JSDOOR
val=DOUBLE_TO_JSVAL((double)uptime);
if(!JS_SetProperty(cx, sysobj, "uptime", &val))
return(NULL);
#endif
#ifdef BUILD_JSDOCS
js_DescribeSyncObject(cx,sysobj,"Global system-related properties and methods",310);
js_CreateArrayOfStrings(cx, sysobj, "_property_desc_list", sys_prop_desc, JSPROP_READONLY);