2 Unix SMB/CIFS implementation.
4 provide access to system functions
6 Copyright (C) Andrew Tridgell 2005
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #include "scripting/ejs/smbcalls.h"
25 #include "lib/ejs/ejs.h"
28 return the list of configured network interfaces
30 static int ejs_sys_interfaces(MprVarHandle eid, int argc, struct MprVar **argv)
32 int i, count = iface_count();
33 struct MprVar ret = mprObject("interfaces");
34 for (i=0;i<count;i++) {
35 mprAddArray(&ret, i, mprString(iface_n_ip(i)));
42 return the hostname from gethostname()
44 static int ejs_sys_hostname(MprVarHandle eid, int argc, struct MprVar **argv)
47 if (gethostname(name, sizeof(name)-1) == -1) {
48 ejsSetErrorMsg(eid, "gethostname failed - %s", strerror(errno));
51 mpr_Return(eid, mprString(name));
57 return current time as a 64 bit nttime value
59 static int ejs_sys_nttime(MprVarHandle eid, int argc, struct MprVar **argv)
61 struct timeval tv = timeval_current();
62 struct MprVar v = mprCreateNumberVar(timeval_to_nttime(&tv));
68 return a ldap time string from a nttime
70 static int ejs_sys_ldaptime(MprVarHandle eid, int argc, struct MprVar **argv)
74 if (argc != 1 || !mprVarIsNumber(argv[0]->type)) {
75 ejsSetErrorMsg(eid, "sys_ldaptime invalid arguments");
78 t = nt_time_to_unix(mprVarToNumber(argv[0]));
79 s = ldap_timestring(mprMemCtx(), t);
80 mpr_Return(eid, mprString(s));
87 setup C functions that be called from ejs
89 void smb_setup_ejs_system(void)
91 ejsDefineCFunction(-1, "sys_interfaces", ejs_sys_interfaces, NULL, MPR_VAR_SCRIPT_HANDLE);
92 ejsDefineCFunction(-1, "sys_hostname", ejs_sys_hostname, NULL, MPR_VAR_SCRIPT_HANDLE);
93 ejsDefineCFunction(-1, "sys_nttime", ejs_sys_nttime, NULL, MPR_VAR_SCRIPT_HANDLE);
94 ejsDefineCFunction(-1, "sys_ldaptime", ejs_sys_ldaptime, NULL, MPR_VAR_SCRIPT_HANDLE);