directories.pm 7.7 KB

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