Handle hostnames with upper-case letters
[webmin.git] / bacula-backup / list.cgi
1 #!/usr/local/bin/perl
2 # Returns a list of files and directories under some directory
3
4 $trust_unknown_referers = 1;
5 require './bacula-backup-lib.pl';
6 &ReadParse();
7 print "Content-type: text/plain\n\n";
8
9 # Get the parent directory ID
10 $dbh = &connect_to_database();
11 $cmd = $dbh->prepare("select PathId from Path where Path = ?");
12 $d = $in{'dir'} eq "/" ? "/" : $in{'dir'}."/";
13 $wind = &unix_to_dos($d);
14 $cmd->execute($wind);
15 ($pid) = $cmd->fetchrow();
16 $cmd->finish();
17
18 if ($in{'job'} ne "") {
19         $jobsql = "and Job.JobId = $in{'job'}";
20         }
21
22 if ($in{'volume'}) {
23         # Search just within one volume
24         # Subdirectories of directory, that are on this volume
25         $cmd1 = $dbh->prepare("
26                 select Path.Path
27                 from Path, File, Job, JobMedia, Media
28                 where File.PathId = Path.PathId
29                 and File.JobId = Job.JobId
30                 and Job.JobId = JobMedia.JobId
31                 and JobMedia.MediaId = Media.MediaId
32                 and Media.VolumeName = ?
33                 $jobsql
34                 ");
35         $cmd1->execute($in{'volume'}) || die "db error : ".$dbh->errstr;
36         while(($f) = $cmd1->fetchrow()) {
37                 $f = &dos_to_unix($f);
38                 if ($f =~ /^(\Q$d\E[^\/]+\/)/) {
39                         push(@rv, $1);
40                         }
41                 }
42         $cmd1->finish();
43
44         # Files in directory, that are on this volume
45         $cmd2 = $dbh->prepare("
46                 select Filename.Name
47                 from File, Filename, Job, JobMedia, Media
48                 where File.FilenameId = Filename.FilenameId
49                 and File.PathId = ?
50                 and File.JobId = Job.JobId
51                 and Job.JobId = JobMedia.JobId
52                 and JobMedia.MediaId = Media.MediaId
53                 and Media.VolumeName = ?
54                 $jobsql
55                 ");
56         $cmd2->execute($pid, $in{'volume'}) || die "db error : ".$dbh->errstr;
57         while(($f) = $cmd2->fetchrow()) {
58                 push(@rv, "$d$f") if ($f =~ /\S/);
59                 }
60         $cmd2->finish();
61         }
62 else {
63         # Search all files
64         # Subdirectories of directory
65         $cmd1 = $dbh->prepare("
66                 select Path
67                 from Path, File, Job
68                 where File.PathId = Path.PathId
69                 and File.JobId = Job.JobId
70                 $jobsql
71                 ");
72         $cmd1->execute() || die "db error : ".$dbh->errstr;
73         while(($f) = $cmd1->fetchrow()) {
74                 $f = &dos_to_unix($f);
75                 if ($f =~ /^(\Q$d\E[^\/]+\/)/) {
76                         push(@rv, $1);
77                         }
78                 }
79         $cmd1->finish();
80
81         # Files in directory
82         $cmd2 = $dbh->prepare("
83                 select Filename.Name
84                 from File, Filename, Job
85                 where File.FilenameId = Filename.FilenameId
86                 and File.PathId = ?
87                 and File.JobId = Job.JobId
88                 $jobsql
89                 ");
90         $cmd2->execute($pid) || die "db error : ".$dbh->errstr;
91         while(($f) = $cmd2->fetchrow()) {
92                 push(@rv, "$d$f") if ($f =~ /\S/);
93                 }
94         $cmd2->finish();
95         }
96
97 # Return output
98 @rv = &unique(@rv);
99 print "\n";
100 foreach $f (@rv) {
101         print $f,"\n";
102         }
103