forked from webmin/webmin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
burner-lib.pl
executable file
·114 lines (100 loc) · 2.58 KB
/
burner-lib.pl
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
#!/usr/local/bin/perl
# burner-lib.pl
# Common functions for managing the CD burning profiles
BEGIN { push(@INC, ".."); };
use WebminCore;
&init_config();
%access = &get_module_acl();
&foreign_require("fdisk", "fdisk-lib.pl");
# list_profiles()
# Returns a list of all burn profiles available for use.
# Each profile can be for an ISO, a list of directory mappings, or a list of
# audio track files
sub list_profiles
{
local @rv;
opendir(DIR, $module_config_directory);
foreach $f (sort { $a cmp $b } readdir(DIR)) {
next if ($f !~ /^(\S+)\.burn$/);
push(@rv, &get_profile($1));
}
closedir(DIR);
return @rv;
}
# get_profile(id)
sub get_profile
{
local %burn;
&read_file("$module_config_directory/$_[0].burn", \%burn);
$burn{'id'} = $_[0];
$burn{'file'} = "$module_config_directory/$_[0].burn";
return \%burn;
}
# save_profile(&profile)
sub save_profile
{
$_[0]->{'id'} = time() if (!$_[0]->{'id'});
&write_file("$module_config_directory/$_[0]->{'id'}.burn", $_[0]);
}
# delete_profile(&profile)
sub delete_profile
{
unlink("$module_config_directory/$_[0]->{'id'}.burn");
}
# list_cdrecord_devices()
# Returns a list of all possible CD burner devices
sub list_cdrecord_devices
{
local (@rv, %done);
# First get from CDrecord
open(SCAN, "$config{'cdrecord'} $config{'extra'} -scanbus 2>/dev/null |");
while(<SCAN>) {
if (/^\s+(\S+)\s+\d+\)\s+'(.*)'\s+'(.*)'\s+'(.*)'\s+(.*)/) {
push(@rv, { 'dev' => $1,
'name' => "$2$3$4",
'type' => $5 });
$done{$1}++;
}
}
close(SCAN);
# Then add all cdrom devices
local $uname = `uname -r 2>&1`;
if ($uname =~ /^2\.(\d+)\./ && $1 >= 6) {
local $disk;
foreach $disk (&fdisk::list_disks_partitions(1)) {
if ($disk->{'media'} eq "cdrom" &&
!$done{$disk->{'device'}}) {
push(@rv, { 'dev' => $disk->{'device'},
'name' => $disk->{'model'},
'type' => uc($disk->{'media'}) });
}
}
}
return @rv;
}
@cdr_drivers = ( 'cdd2600', 'plextor', 'plextor-scan', 'generic-mmc',
'generic-mmc-raw', 'ricoh-mp6200', 'yamaha-cdr10x',
'teac-cdr55', 'sony-cdu920', 'sony-cdu948', 'taiyo-yuden',
'toshiba' );
# can_use_profile(&profile)
# Returns 1 if some burn profile can be used
sub can_use_profile
{
return 1 if ($access{'profiles'} eq '*');
local %can = map { $_, 1 } split(/\s+/, $access{'profiles'});
return $can{$_[0]->{'id'}};
}
# can_directory(file)
# Returns 1 if some file is in an allowed directory
sub can_directory
{
local @dirs = split(/\s+/, $access{'dirs'});
return 1 if ($dirs[0] eq "/");
local $path = &resolve_links($_[0]);
local $d;
foreach $d (@dirs) {
return 1 if (&is_under_directory(&resolve_links($d), $path));
}
return 0;
}
1;