blob: 6f20e6feb88d2a9147a20066bbf9262bbc8e7928 [file] [log] [blame]
Lucas Eckels9bd90e62012-08-06 15:07:02 -07001%file_chmod1 = (
2 'name' => 'chmod1',
3 'content' => "This file should have permissions 444\n",
4 'perm' => 'r--r--r--',
5 'time' => 'Jan 11 10:00',
6 'dostime' => '01-11-10 10:00AM',
7);
8
9%file_chmod2 = (
10 'name' => 'chmod2',
11 'content' => "This file should have permissions 666\n",
12 'perm' => 'rw-rw-rw-',
13 'time' => 'Feb 1 8:00',
14 'dostime' => '02-01-10 08:00AM',
15);
16
17%file_chmod3 = (
18 'name' => 'chmod3',
19 'content' => "This file should have permissions 777\n",
20 'perm' => 'rwxrwxrwx',
21 'time' => 'Feb 1 8:00',
22 'dostime' => '02-01-10 08:00AM',
23);
24
25%file_chmod4 = (
26 'type' => 'd',
27 'name' => 'chmod4',
28 'content' => "This file should have permissions 001\n",
29 'perm' => '--S--S--t',
30 'time' => 'May 4 4:31',
31 'dostime' => '05-04-10 04:31AM'
32);
33
34%file_chmod5 = (
35 'type' => 'd',
36 'name' => 'chmod5',
37 'content' => "This file should have permissions 110\n",
38 'perm' => '--s--s--T',
39 'time' => 'May 4 4:31',
40 'dostime' => '05-04-10 04:31AM'
41);
42
43%link_link = (
44 'type' => 'l',
45 'name' => 'link -> file.txt',
46 'size' => '8',
47 'perm' => 'rwxrwxrwx',
48 'time' => 'Jan 6 4:42'
49);
50
51%link_link_absolute = (
52 'type' => 'l',
53 'name' => 'link_absolute -> /data/ftp/file.txt',
54 'size' => '15',
55 'perm' => 'rwxrwxrwx',
56 'time' => 'Jan 6 4:45'
57);
58
59%dir_dot = (
60 'type' => "d",
61 'name' => ".",
62 'hlink' => "4",
63 'time' => "Apr 27 5:12",
64 'size' => "20480",
65 'dostime' => "04-27-10 05:12AM",
66 'perm' => "rwxrwxrwx"
67);
68
69%dir_ddot = (
70 'type' => "d",
71 'name' => "..",
72 'hlink' => "4",
73 'size' => "20480",
74 'time' => "Apr 23 3:12",
75 'dostime' => "04-23-10 03:12AM",
76 'perm' => "rwxrwxrwx"
77);
78
79%dir_weirddir_txt = (
80 'type' => "d",
81 'name' => "weirddir.txt",
82 'hlink' => "2",
83 'size' => "4096",
84 'time' => "Apr 23 3:12",
85 'dostime' => "04-23-10 03:12AM",
86 'perm' => "rwxr-xrwx"
87);
88
89%dir_UNIX = (
90 'type' => "d",
91 'name' => "UNIX",
92 'hlink' => "11",
93 'size' => "4096",
94 'time' => "Nov 01 2008",
95 'dostime' => "11-01-08 11:11AM",
96 'perm' => "rwx--x--x"
97);
98
99%dir_DOS = (
100 'type' => "d",
101 'name' => "DOS",
102 'hlink' => "11",
103 'size' => "4096",
104 'time' => "Nov 01 2008",
105 'dostime' => "11-01-08 11:11AM",
106 'perm' => "rwx--x--x"
107);
108
109%dir_dot_NeXT = (
110 'type' => "d",
111 'name' => ".NeXT",
112 'hlink' => "4",
113 'size' => "4096",
114 'time' => "Jan 23 2:05",
115 'dostime' => "01-23-05 02:05AM",
116 'perm' => "rwxrwxrwx"
117);
118
119%file_empty_file_dat = (
120 'name' => "empty_file.dat",
121 'content' => "",
122 'perm' => "rw-r--r--",
123 'time' => "Apr 27 11:01",
124 'dostime' => "04-27-10 11:01AM"
125);
126
127%file_file_txt = (
128 'name' => "file.txt",
129 'content' => "This is content of file \"file.txt\"\n",
130 'time' => "Apr 27 11:01",
131 'dostime' => "04-27-10 11:01AM",
132 'perm' => "rw-r--r--"
133);
134
135%file_someothertext_txt = (
136 'name' => "someothertext.txt",
137 'content' => "Some junk ;-) This file does not really exist.\n",
138 'time' => "Apr 27 11:01",
139 'dostime' => "04-27-10 11:01AM",
140 'perm' => "rw-r--r--"
141);
142
143%lists = (
144 '/fully_simulated/' => {
145 'files' => [ \%dir_dot, \%dir_ddot, \%dir_DOS, \%dir_UNIX ],
146 'eol' => "\r\n",
147 'type' => "unix"
148 },
149 '/fully_simulated/UNIX/' => {
150 'files' => [ \%dir_dot, \%dir_ddot,
151 \%file_chmod1, \%file_chmod2, \%file_chmod3, \%file_chmod4, \%file_chmod5,
152 \%file_empty_file_dat, \%file_file_txt,
153 \%link_link, \%link_link_absolute, \%dir_dot_NeXT,
154 \%file_someothertext_txt, \%dir_weirddir_txt ],
155 'eol' => "\r\n",
156 'type' => 'unix'
157 },
158 '/fully_simulated/DOS/' => {
159 'files' => [ \%dir_dot, \%dir_ddot,
160 \%file_chmod1, \%file_chmod2, \%file_chmod3, \%file_chmod4, \%file_chmod5,
161 \%file_empty_file_dat, \%file_file_txt,
162 \%dir_dot_NeXT, \%file_someothertext_txt, \%dir_weirddir_txt ],
163 'eol' => "\r\n",
164 'type' => 'dos'
165 }
166);
167
168sub ftp_createcontent($) {
169 my (%list) = @_;
170
171 $type = $$list{'type'};
172 $eol = $$list{'eol'};
173 $list_ref = $$list{'files'};
174
175 my @diroutput;
176 my @contentlist;
177 if($type eq "unix") {
178 for(@$list_ref) {
179 my %file = %$_;
180 my $line = "";
181 my $ftype = $file{'type'} ? $file{'type'} : "-";
182 my $fperm = $file{'perm'} ? $file{'perm'} : "rwxr-xr-x";
183 my $fuser = $file{'user'} ? sprintf("%15s", $file{'user'}) : "ftp-default";
184 my $fgroup = $file{'group'} ? sprintf("%15s", $file{'group'}) : "ftp-default";
185 my $fsize = "";
186 if($file{'type'} eq "d") {
187 $fsize = $file{'size'} ? sprintf("%7s", $file{'size'}) : sprintf("%7d", 4096);
188 }
189 else {
190 $fsize = sprintf("%7d", length $file{'content'});
191 }
192 my $fhlink = $file{'hlink'} ? sprintf("%4d", $file{'hlink'}) : " 1";
193 my $ftime = $file{'time'} ? sprintf("%10s", $file{'time'}) : "Jan 9 1933";
194 push(@contentlist, "$ftype$fperm $fhlink $fuser $fgroup $fsize $ftime $file{'name'}$eol");
195 }
196
197 return @contentlist;
198 }
199 elsif($type =~ /^dos$/) {
200 for(@$list_ref) {
201 my %file = %$_;
202 my $line = "";
203 my $time = $file{'dostime'} ? $file{'dostime'} : "06-25-97 09:12AM";
204 my $size_or_dir;
205 if($file{'type'} =~ /^d$/) {
206 $size_or_dir = " <DIR> ";
207 }
208 else {
209 $size_or_dir = sprintf("%20d", length $file{'content'});
210 }
211 push(@contentlist, "$time $size_or_dir $file{'name'}$eol");
212 }
213 return @contentlist;
214 }
215}
216
217sub wildcard_filesize($$) {
218 my ($list_type, $file) = @_;
219 $list = $lists{$list_type};
220 if($list) {
221 my $files = $list->{'files'};
222 for(@$files) {
223 my %f = %$_;
224 if ($f{'name'} eq $file) {
225 if($f{'content'}) {
226 return length $f{'content'};
227 }
228 elsif ($f{'type'} ne "d"){
229 return 0;
230 }
231 else {
232 return -1;
233 }
234 }
235 }
236 }
237 return -1;
238}
239sub wildcard_getfile($$) {
240 my ($list_type, $file) = @_;
241 $list = $lists{$list_type};
242 if($list) {
243 my $files = $list->{'files'};
244 for(@$files) {
245 my %f = %$_;
246 if ($f{'name'} eq $file) {
247 if($f{'content'}) {
248 return (length $f{'content'}, $f{'content'});
249 }
250 elsif ($f{'type'} ne "d"){
251 return (0, "");
252 }
253 else {
254 return (-1, 0);
255 }
256 }
257 }
258 }
259 return (-1, 0);
260}
261
262sub ftp_contentlist {
263 my $listname = $_[0];
264 $list = $lists{$listname};
265 return ftp_createcontent(\$list);
266}