#!/usr/bin/perl
#
# add_account -- Create a Mac OS X export file of a new lab account
#
# Copyright (c) 2001 by The Regents of the University of California
# Author: Jose L. Hales-Garcia, UCLA Department of Statistics
#
$roster_workfile = "../internal_worklist.txt";
open (ROSTER, "$roster_workfile") or "Die can't locate $roster_workfile.\n";
$firstline = <ROSTER>;
close (ROSTER);
chomp($firstline);
($new_comment, $try_shortname, $new_password) = split("\t", $firstline);
if (($new_comment !~ /^Unassigned Account/) or ($new_password ne "unassigned")) {
die "First line not ok.\n";
}
print STDOUT "First available lab ID is: $try_shortname\n";
print STDOUT "Do you wish to use this ID?[y/n] ";
$reply = <STDIN>;
chomp($reply);
if ($reply ne "y") {
die "You didn't answer yes (y). Ok, bye.\n";
}
print STDOUT "Please enter the student's 9 digit UCID number: ";
$try_password = <STDIN>;
chomp($try_password);
if ($try_password !~ /\d\d\d\d\d\d\d\d\d/) {
die "Student UCID must be 9 numeric characters.\n$try_password doesn't fit. Please try again.\n";
}
if ($check_ifexists = `grep $try_password $roster_workfile`) {
die "Quitting. Account for $try_password already exists.\n$check_ifexists";
}
print STDOUT "Please enter the student's last name: ";
$try_lastname = <STDIN>;
chomp($try_lastname);
if (length($try_lastname) < 2) {
die "Need a last name at least two characters long..\nPlease try again.\n";
}
print STDOUT "Please enter the student's first name: ";
$try_firstname = <STDIN>;
chomp($try_firstname);
if (length($try_firstname) < 2) {
die "Need a first name at least two characters long..\nPlease try again.\n";
}
$try_name = $try_lastname . ", " . $try_firstname;
$try_name =~ tr/[a-zA-Z]*/[A-Z]/;
$filler = " " x (35 - length($try_name));
$try_entry = $try_name . $filler . "\t$try_shortname\t$try_password";
print "This is the record being entered:\n";
print "$try_entry\n";
print "Is it to your satisfaction? [y/n] ";
$reply = <STDIN>;
chomp($reply);
if ($reply ne "y") {
die "You didn't answer yes (y). Ok, bye.\n";
}
$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
$userdata = <<EOUD;
<uglist>
<user
loginEnabled = "canLogin"
isAdminUser = "notAdmin"
uid = "$try_shortname"
gid = "9999"
shell = "/bin/tcsh"
comment = "$try_name" >
<nameList>
<name
text = "$try_shortname" />
<name
text = "Student $try_shortname" />
</nameList>
<pass
format = "clearText"
text = "$try_password" />
</user>
</uglist>
EOUD
# Create the import .xml file
open (EXPORT, ">../export/$try_shortname.xml");
print EXPORT "$metadata";
print EXPORT "$userdata";
close EXPORT;
# Update the internal worklist
`cp $roster_workfile $roster_workfile.backup`;
open (BACKUPLIST, "$roster_workfile.backup");
open (COPYLIST, ">$roster_workfile");
$skip = <BACKUPLIST>;
while (<BACKUPLIST>) {
print COPYLIST $_;
}
close(BACKUPLIST);
close(COPYLIST);
open (ADDTOLIST, ">> $roster_workfile");
print ADDTOLIST "$try_entry\n";
close ADDTOLIST;