/////////////////////////////////////////////////////////////// // file : ImportNewUsers.wcc // date : 10/01/2002
// about: import new users from comma delimited file // // usage: wcrun -r ImportNewUsers newusers.txt // // notes: // ----- // 1) newusers.txt must be in the format:
// // user name,password,security // // 2) You can't use this from a MENU because of the // LoginSystem() command below. If you want to use
// this from a MENU, you need to change this program // ///////////////////////////////////////////////////////////////
#include "userutil.wch"
// set this option FALSE if you do not want to use // the DEFAULT user template
dim UseDefaultUser as Boolean = TRUE
Function ProcessImportFile(fname as string) as boolean
ProcessImportFile = FALSE
if (fname = "") then print "! file name required"
exit function end if
// open file
dim h as integer = open fname for Input if (h = 0) then
print "! Error opening file: ";fname exit function end if
print "* Reading comma delimited file..."
dim line as string
dim total as integer = 0 dim linenum as integer = 0
do while not eof(h) input #h, line line = trim(line) inc(linenum)
if line <> "" then // skip blanks dim uname as string = ""
dim upwd as string = "" dim usec as string = ""
dim comma as integer = instr(line,",") if (comma > 0) then
uname = trim(mid(line,1,comma-1)) line = mid(line,comma+1)
comma = instr(line,",") if (comma > 0) then
upwd = trim(mid(line,1,comma-1)) usec = trim(mid(line,comma+1))
end if end if
if (uname = "") then
print "! no user name in line ";linenum exit do end if
if (usec = "") then print "! no user security in line ";linenum
exit do end if if (upwd = "") then
print "! no user password in line ";linenum exit do end if
dim sp as TSecurityProfile if not GetSecurityProfileByName(usec,sp) then
print "! security '";usec;"' not found in line ";linenum exit do
end if
dim newuser as tuser if LookupName(uname, newuser.info) then
print "* User '";uname;"' already exist in line# "; print linenum;" Skipping"
else clear newuser
if (UseDefaultUser) then InitializeDefaultUser(newuser, FALSE)
newuser.info.id = 0
newuser.password = upwd newuser.info.name = uname
newuser.security(1) = usec
if (not AddNewUser(newuser)) then
print "! Error: ";Hex(GetLastError());
print " Adding user. line: ";linenum else
print "+ new user '";newuser.info.name;
print "' added, user id: ";newuser.info.id inc(total)
end if end if end if loop close #h
print "* Total users added: ";total
ProcessImportFile = TRUE
end function
/////////////////////////////////////////////////////////////// // Main Program
///////////////////////////////////////////////////////////////
if not LoginSystem() then print "error with system login" end end if
ProcessImportFile(Paramstr(1)) LogoutUser()
|