1 | #!/usr/bin/perl
|
---|
2 | #
|
---|
3 | # genlogon.pl
|
---|
4 | #
|
---|
5 | # Perl script to generate user logon scripts on the fly, when users
|
---|
6 | # connect from a Windows client. This script should be called from smb.conf
|
---|
7 | # with the %U, %G and %L parameters. I.e:
|
---|
8 | #
|
---|
9 | # root preexec = genlogon.pl %U %G %L
|
---|
10 | #
|
---|
11 | # The script generated will perform
|
---|
12 | # the following:
|
---|
13 | #
|
---|
14 | # 1. Log the user connection to /var/log/samba/netlogon.log
|
---|
15 | # 2. Set the PC's time to the Linux server time (which is maintained
|
---|
16 | # daily to the National Institute of Standard's Atomic clock on the
|
---|
17 | # internet.
|
---|
18 | # 3. Connect the user's home drive to H: (H for Home).
|
---|
19 | # 4. Connect common drives that everyone uses.
|
---|
20 | # 5. Connect group-specific drives for certain user groups.
|
---|
21 | # 6. Connect user-specific drives for certain users.
|
---|
22 | # 7. Connect network printers.
|
---|
23 |
|
---|
24 | # Log client connection
|
---|
25 | #($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
|
---|
26 | ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
|
---|
27 | open LOG, ">>/var/log/samba/netlogon.log";
|
---|
28 | print LOG "$mon/$mday/$year $hour:$min:$sec - User $ARGV[0] logged into $ARGV[1]\n";
|
---|
29 | close LOG;
|
---|
30 |
|
---|
31 | # Start generating logon script
|
---|
32 | open LOGON, ">/shared/netlogon/$ARGV[0].bat";
|
---|
33 | print LOGON "\@ECHO OFF\r\n";
|
---|
34 |
|
---|
35 | # Connect shares just use by Software Development group
|
---|
36 | if ($ARGV[1] eq "SOFTDEV" || $ARGV[0] eq "softdev")
|
---|
37 | {
|
---|
38 | print LOGON "NET USE M: \\\\$ARGV[2]\\SOURCE\r\n";
|
---|
39 | }
|
---|
40 |
|
---|
41 | # Connect shares just use by Technical Support staff
|
---|
42 | if ($ARGV[1] eq "SUPPORT" || $ARGV[0] eq "support")
|
---|
43 | {
|
---|
44 | print LOGON "NET USE S: \\\\$ARGV[2]\\SUPPORT\r\n";
|
---|
45 | }
|
---|
46 |
|
---|
47 | # Connect shares just used by Administration staff
|
---|
48 | if ($ARGV[1] eq "ADMIN" || $ARGV[0] eq "admin")
|
---|
49 | {
|
---|
50 | print LOGON "NET USE L: \\\\$ARGV[2]\\ADMIN\r\n";
|
---|
51 | print LOGON "NET USE K: \\\\$ARGV[2]\\MKTING\r\n";
|
---|
52 | }
|
---|
53 |
|
---|
54 | # Now connect Printers. We handle just two or three users a little
|
---|
55 | # differently, because they are the exceptions that have desktop
|
---|
56 | # printers on LPT1: - all other user's go to the LaserJet on the
|
---|
57 | # server.
|
---|
58 | if ($ARGV[0] eq 'jim'
|
---|
59 | || $ARGV[0] eq 'yvonne')
|
---|
60 | {
|
---|
61 | print LOGON "NET UsE LPT2: \\\\$ARGV[2]\\LJET3\r\n";
|
---|
62 | print LOGON "NET USE LPT3: \\\\$ARGV[2]\\FAXQ\r\n";
|
---|
63 | }
|
---|
64 | else
|
---|
65 | {
|
---|
66 | print LOGON "NET USE LPT1: \\\\$ARGV[2]\\LJET3\r\n";
|
---|
67 | print LOGON "NET USE LPT3: \\\\$ARGV[2]\\FAXQ\r\n";
|
---|
68 | }
|
---|
69 |
|
---|
70 | # All done! Close the output file.
|
---|
71 | close LOGON;
|
---|