#!/usr/bin/perl
#
# newaccounts -- Create batch export file of new Mac OS X accounts.
#
# Copyright (c) 2001 by The Regents of the University of California
# Author: Jose L. Hales-Garcia, UCLA Department of Statistics
#
`clear`;
print STDOUT "I will make an xml file suitable for importing student accounts using Server Admin.\n";
print STDOUT "My output will go to STDOUT so you will need to redirect it to a file.\n";
print STDOUT "You will also need to scrutinize this output since, if used, it will delete data in Netinfo.\n\n";
print STDOUT "I need a tab delimited file with two fields in this order:\n";
print STDOUT "Student UCID, Student name\n";
print STDOUT "Student UCID will be made the student's password\n";
print STDOUT "Student name will be put in the comment field for our internal use\n";
print STDOUT "Give me the location of the student roster file: ";
$rosterfile = <STDIN>;
open (ROSTER, "$rosterfile") or die "Can't open $rosterfile\n";
print STDOUT "I need the starting uid (no less than 10000) to begin assigning to the students: ";
$starting_uid = <STDIN>;
print STDOUT "I need the ending uid (no greater then 11500) to end assigning to the students: ";
$ending_uid = <STDIN>;
die "Keep the uids in the proper ranges." if (($starting_uid < 9999) or ($starting_uid > $ending_uid) or ($ending_uid > 11501));
$shortname = $starting_uid;
$metadata = <<EOMD;
<?XML version="1.0"?>
<!DOCTYPE MacOSXServer100 [
<!ELEMENT uglist ( user | group)* >
<!ELEMENT user ( nameList? pass? homeDir? pluginDataList ) >
<!ATTLIST user
comment CDATA #IMPLIED
uid CDATA #IMPLIED
gid CDATA #IMPLIED
shell CDATA #IMPLIED
loginEnabled ( canLogin | noLogin ) "canLogin"
isAdminUser ( isAdmin | notAdmin ) "notAdmin"
>
<!ELEMENT nameList name* >
<!ELEMENT name EMPTY >
<!ATTLIST name
text CDATA
>
<!ELEMENT pass EMPTY >
<!ATTLIST pass
format ( encrypted | clearText | crypt ) "clearText"
text CDATA
>
<!ELEMENT homeDir EMPTY >
<!ATTLIST homeDir
sharePoint CDATA
path CDATA
>
<!ELEMENT pluginDataList pluginData* >
<!ELEMENT pluginData EMPTY >
<!ATTLIST pluginData
signature CDATA #REQUIRED
data CDATA #REQUIRED
>
<!ELEMENT group memberName* >
<!ATTLIST group
name CDATA #REQUIRED
gid CDATA #IMPLIED
>
<!ELEMENT memberName EMPTY >
<!ATTLIST memberName
name CDATA #REQUIRED
>
]>
EOMD
print "$metadata";
print "<uglist>\n";
while (<ROSTER>) {
$longname = "Student $shortname";
chomp;
($password, $comment) = split("\t",$_);
$comment =~ s/\s*$//g;
$users{$shortname}{shortname} = $shortname;
$users{$shortname}{longname} = $longname;
$users{$shortname}{uid} = $shortname;
$users{$shortname}{password} = $password;
$users{$shortname}{comment} = $comment;
$shortname++;
}
close(ROSTER);
foreach $key (sort keys %users) {
$userdata = <<EOUD;
<user
loginEnabled = "canLogin"
isAdminUser = "notAdmin"
uid = "$users{$key}{uid}"
gid = "9999"
shell = "/bin/tcsh"
comment = "$users{$key}{comment}" >
<nameList>
<name
text = "$users{$key}{shortname}" />
<name
text = "$users{$key}{longname}" />
</nameList>
<pass
format = "clearText"
text = "$users{$key}{password}" />
</user>
EOUD
print "$userdata";
}
print "</uglist>";