-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconvert.pl
More file actions
executable file
·196 lines (181 loc) · 5.95 KB
/
convert.pl
File metadata and controls
executable file
·196 lines (181 loc) · 5.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
#!/usr/bin/perl
# Jeff Leggett for SDX to Sterling Migration
# July 2007
# NOTE: Rough functionality is complete, some fleshing out
# will be needed for the MBX configuration
#
# Josh Forester
# Updates:
# Added printout of virtual root sections.
# Moved USERXGROUP tags to inside loop so they are printed for each group
# the user is in.
#
# Areas to look at in future:
# 1. inner MBXVIRTUAL may represent single virtual root, and so all instances
# should be wrapped by outer rather than having multiple inner-outers
# 2. SHA hash may need slight modification for XML export
# 3. POLICY_ID will need to be changed to a policy created for access control
# 4. all values in USER need to be verified in case literals are needed
# 5. email isn't parsed from LDIF
# 6. printout of XML for mailbox and associated permission.
# xml for permission and associated group.
# (see FullNewTransmissionImp1.0.xml)
#
use strict;
use warnings;
use XML::Writer;
#my ($NAME, $UID, $PWD, $GN, $SN);
#my ($CN,$TMP,$TMP1,$GRPNAME);
#our $UC = 0; our $GC = 0;
#my (@CN, @SN, @UID, @PWD, @GN, @GRPNAME);
our @USERS;
our @GROUPS;
sub ParseLDIF {
my ($NAME, $UID, $PWD, $GN, $SN);
my ($CN,$TMP,$TMP1,$GRPNAME);
our $UC = 0;
our $GC = 0;
our (@CN, @SN, @UID, @PWD, @GN, @GRPNAME);
my $ldiffile = $ARGV[0];
die "usage: $0 ldiffile\n" unless $ldiffile;
open (LDIFFILE, $ldiffile) || die "$ldiffile: $!";
my $userevent = 0;
my $grpevent = 0;
while (<LDIFFILE>) {
chomp;
#print "PREPARSE LINE: $_";
if (/^dn: uid/) { $userevent = 1; next; }
if ($userevent) {
if ($_ =~ /^uid/) {
($NAME,$UID) = split /: /, $_, 2;
$UID[$UC] = $UID; next;
}
if ($_ =~ /^user/) {
($NAME, $PWD) = split /: /, $_, 2;
$PWD[$UC] = $PWD; next;
}
if ($_ =~ /^give/) {
($NAME, $GN) = split /: /,$_, 2;
$GN[$UC] = $GN; next;
}
if ($_ =~ /^sn/) {
($NAME,$SN) = split /: /, $_, 2;
$SN[$UC] = $SN; next;
}
if ($_ =~ /^$/) { $userevent = 0; $UC++; next; }
}
if (/^dn: cn/) { $grpevent = 1; next; }
if ($grpevent) {
if ($_ =~ /^cn/) {
($NAME, $CN) = split /: /, $_, 2;
$CN[$GC] = $CN; next;
}
if ($_ =~ /^uniquemember/) {
# print "PRESPLIT LINE: $_ \n";
($NAME, $TMP1) = split /: /, $_;
# print "NAME: $NAME, PRE_SPLIT: $TMP1\n";
($TMP,$GRPNAME) = split /=/, $TMP1;
# print "NAME: $TMP, PRE_SPLIT: $GRPNAME\n";
if ($GRPNAME eq "") { $GRPNAME = ""; }
$GRPNAME[$GC] = $GRPNAME[$GC] . ":" . $GRPNAME; next;
}
}
if ($_ =~ /^$/) { $grpevent = 0; $GC++; next; }
}
close (LDIFFILE);
#print "USERS:\n";
for (my $I=0; $I<scalar(@UID); $I++) {
$USERS[$I] = "$UID[$I]:$PWD[$I]:$GN[$I]:$SN[$I]";
# print "$USERS[$I]\n";
}
#print "GROUPS:\n";
for (my $I=0; $I<$GC; $I++) {
$GROUPS[$I] = "$CN[$I]$GRPNAME[$I]";
# print "$GROUPS[$I]\n";
}
}
our $writer = new XML::Writer(DATA_MODE => 1);
sub StartXML {
$writer->xmlDecl("UTF-8");
$writer->startTag('SI_RESOURCES','xmlns' => 'http://www.stercomm.com/SI/SI_IE_Resources', 'xmlns:xsi'=>'http://www.w3.org/2001/XMLSchema-instance','GISVersion'=>'4.1.0-1969');
}
sub EndXML {
$writer->endTag('SI_RESOURCES');
$writer->end();
}
sub OutputUsersGroupsXML {
my ($UID, $PWD, $GN, $SN);
$writer->startTag('USERS');
$writer->startTag('USER');
for (my $I=0; $I<scalar(@USERS); $I++) { # Need = ?
($UID,$PWD,$GN,$SN) = split /:/, $USERS[$I];
$writer->startTag('METADATA');
$writer->dataElement('USER_ID' => $UID);
$writer->dataElement('PASSWORD' => $PWD);
$writer->dataElement('LANG' => '');
$writer->dataElement('EMAIL' => '');
$writer->dataElement('FNAME' => $GN);
$writer->dataElement('LNAME' => $SN);
$writer->dataElement('PAGER' => '');
$writer->dataElement('VERSION' => '');
$writer->dataElement('DOWNLOAD_TIME' => '');
$writer->dataElement('SUPER' => '' );
$writer->dataElement('PARENT_ID' => '');
$writer->dataElement('ENTITY_ID' => '');
$writer->dataElement('STATUS' => '1');
$writer->dataElement('TIMEOUT' => '' );
$writer->dataElement('POLICY_ID' => 'ACPolicy');
$writer->dataElement('PWD_MOD_DATE' => '' );
$writer->dataElement('DASH_USER_ID' => '');
$writer->dataElement('CONFIRM_VALUE' => '');
$writer->dataElement('MODIFIED' => '');
$writer->dataElement('CREATED' => '');
$writer->dataElement('LAST_LOGIN' => '');
$writer->dataElement('DISABLED' => '');
$writer->dataElement('SECURITY_CODE' => '');
$writer->dataElement('CHANGE_PASS_NEXT' => '');
$writer->endTag('METADATA');
$writer->startTag('USERDEPENDENTS');
$writer->startTag('USERXGROUPS');
for (my $J=0; $J<scalar(@GROUPS); $J++) {
my $GRPNAME = $GROUPS[$J];
if ( $GRPNAME =~ /$UID/ ) {
($GRPNAME,my $USERSINGROUP) = split /:/, $GRPNAME,2;
$writer->startTag('USERXGROUP');
$writer->startTag('METADATA');
$writer->dataElement('GROUP_ID' => $GRPNAME);
$writer->dataElement('USER_SUB_GROUP_ID' => $UID);
$writer->dataElement('REC_TYPE' => '');
$writer->dataElement('STATUS' => '1');
$writer->endTag('METADATA');
$writer->endTag('USERXGROUP');
}
}
$writer->endTag('USERXGROUPS');
$writer->endTag('USERDEPENDENTS');
}
$writer->endTag('USER');
$writer->endTag('USERS');
# write out virtual root info
for (my $I=0; $I<scalar(@USERS); $I++) { # Need = ?
($UID,$PWD,$GN,$SN) = split /:/, $USERS[$I];
$writer->startTag('MBXVIRTUAL');
$writer->startTag('MBXVIRTUAL');
$writer->startTag('MBXVIRTUALROOT');
$writer->dataElement('USER_ID' => $UID);
$writer->dataElement('ROOT_MAILBOX_PATH' => '/dev_sdx');
$writer->endTag('MBXVIRTUALROOT');
$writer->startTag('MAILBOX');
$writer->dataElement('BASEPATH' => '/dev_sdx');
$writer->endTag('MAILBOX');
$writer->endTag('MBXVIRTUAL');
$writer->endTag('MBXVIRTUAL');
}
}
# Hehe, the actual MAIN section - modules written for re-use in expanding
# it later
ParseLDIF();
StartXML();
OutputUsersGroupsXML();
#OutpoutMBXXML();
EndXML();