-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathbtrfsman_defrag.cgi
81 lines (56 loc) · 2.01 KB
/
btrfsman_defrag.cgi
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
#!/usr/bin/perl
# btrfsman_defrag.cgi
# BTRFS Manager - Defrag Filesystem
require './btrfsman-lib.pl';
&ReadParse();
ui_print_header(undef, $text{'defrag_title'}, "", undef, 1, 1);
if($in){
print $text{'txt_arg'}, $in, $text{'txt_p'};
}
$act = $in{'act'};
$point = $in{'point'};
$opt = $in{'opt'};
if ($point =~ /[ %&<>!\x27\x60\x3B\x3A\x\n\r\l]/) {
print "not a safe string to use as directory";
}
if (($act eq 'defrag') && ($point) ) {
if ($point) {
$cmd = "btrfs fi defrag $opt $point 2>&1";
print $text{txt_executing}, $cmd, $text{'txt_p'};
$result=`$cmd`;
print $cmd, $text{'txt_p'}, $text{'defrag_started'}, $text{'txt_p'} ;
}
}
else{
defragmp_menu();
defrag_filemenu();
}
ui_print_footer('/', 'Webmin index', '', 'Module menu');
sub defragmp_menu {
print $text{'label_defragmp_h'};
$result = `mount |grep btrfs`;
$result =~ s/\n/<br>/g;
@splitres = split /<br>/, $result;
print $text{'index_youhave1'}, scalar (@splitres), $text{'index_youhave3'};
$did=0;
for (@splitres){
print ui_columns_start([ @splitres[$did], ""]);
$drivea = @splitres[$did];
@driveb = split /on /, $drivea;
@drivec = split / /, @driveb[1];
@mountedrive[$did] = @drivec[0];
print ui_columns_row([$text{'index_mountp'}, @mountedrive[$did]]) ;
print ui_columns_end();
print ui_buttons_start();
print ui_buttons_row("btrfsman_defrag.cgi", $text{'label_bt_defragstartmp'}, $text{'label_bt_defragstartmp_help'}, ui_hidden('act', 'defrag'), ui_hidden('point', @mountedrive[$did]), ui_textbox('options','-r'));
print ui_buttons_end();
print "<p><p>";
$did++;
}
}
sub defrag_filemenu{
print $text{'label_defragfile_h'};
print ui_buttons_start();
print ui_buttons_row("btrfsman_defrag.cgi", $text{'label_bt_defragstartfile'}, $text{'label_bt_defragstartfile_help'}, ui_hidden('act', 'defragfile'), ui_filebox('file'), ui_textbox('options','-r'));
print ui_buttons_end();
}