Handle hostnames with upper-case letters
[webmin.git] / burner / burner-lib.pl
1 #!/usr/local/bin/perl
2 # burner-lib.pl
3 # Common functions for managing the CD burning profiles
4
5 BEGIN { push(@INC, ".."); };
6 use WebminCore;
7 &init_config();
8 %access = &get_module_acl();
9 &foreign_require("fdisk", "fdisk-lib.pl");
10
11 # list_profiles()
12 # Returns a list of all burn profiles available for use.
13 # Each profile can be for an ISO, a list of directory mappings, or a list of
14 # audio track files
15 sub list_profiles
16 {
17 local @rv;
18 opendir(DIR, $module_config_directory);
19 foreach $f (sort { $a cmp $b } readdir(DIR)) {
20         next if ($f !~ /^(\S+)\.burn$/);
21         push(@rv, &get_profile($1));
22         }
23 closedir(DIR);
24 return @rv;
25 }
26
27 # get_profile(id)
28 sub get_profile
29 {
30 local %burn;
31 &read_file("$module_config_directory/$_[0].burn", \%burn);
32 $burn{'id'} = $_[0];
33 $burn{'file'} = "$module_config_directory/$_[0].burn";
34 return \%burn;
35 }
36
37 # save_profile(&profile)
38 sub save_profile
39 {
40 $_[0]->{'id'} = time() if (!$_[0]->{'id'});
41 &write_file("$module_config_directory/$_[0]->{'id'}.burn", $_[0]);
42 }
43
44 # delete_profile(&profile)
45 sub delete_profile
46 {
47 unlink("$module_config_directory/$_[0]->{'id'}.burn");
48 }
49
50 # list_cdrecord_devices()
51 # Returns a list of all possible CD burner devices
52 sub list_cdrecord_devices
53 {
54 local (@rv, %done);
55
56 # First get from CDrecord
57 open(SCAN, "$config{'cdrecord'} $config{'extra'} -scanbus 2>/dev/null |");
58 while(<SCAN>) {
59         if (/^\s+(\S+)\s+\d+\)\s+'(.*)'\s+'(.*)'\s+'(.*)'\s+(.*)/) {
60                 push(@rv, { 'dev' => $1,
61                             'name' => "$2$3$4",
62                             'type' => $5 });
63                 $done{$1}++;
64                 }
65         }
66 close(SCAN);
67
68 # Then add all cdrom devices
69 local $uname = `uname -r 2>&1`;
70 if ($uname =~ /^2\.(\d+)\./ && $1 >= 6) {
71         local $disk;
72         foreach $disk (&fdisk::list_disks_partitions(1)) {
73                 if ($disk->{'media'} eq "cdrom" &&
74                     !$done{$disk->{'device'}}) {
75                         push(@rv, { 'dev' => $disk->{'device'},
76                                     'name' => $disk->{'model'},
77                                     'type' => uc($disk->{'media'}) });
78                         }
79                 }
80         }
81
82 return @rv;
83 }
84
85 @cdr_drivers = ( 'cdd2600', 'plextor', 'plextor-scan', 'generic-mmc',
86                  'generic-mmc-raw', 'ricoh-mp6200', 'yamaha-cdr10x',
87                  'teac-cdr55', 'sony-cdu920', 'sony-cdu948', 'taiyo-yuden',
88                  'toshiba' );
89
90 # can_use_profile(&profile)
91 # Returns 1 if some burn profile can be used
92 sub can_use_profile
93 {
94 return 1 if ($access{'profiles'} eq '*');
95 local %can = map { $_, 1 } split(/\s+/, $access{'profiles'});
96 return $can{$_[0]->{'id'}};
97 }
98
99 # can_directory(file)
100 # Returns 1 if some file is in an allowed directory
101 sub can_directory
102 {
103 local @dirs = split(/\s+/, $access{'dirs'});
104 return 1 if ($dirs[0] eq "/");
105 local $path = &resolve_links($_[0]);
106 local $d;
107 foreach $d (@dirs) {
108         return 1 if (&is_under_directory(&resolve_links($d), $path));
109         }
110 return 0;
111 }
112
113 1;
114