3 # Revert all changed config files, after asking for confirmation
7 require './webminlog-lib.pl';
8 our (%text, %in, %access);
10 my $act = &get_action($in{'id'});
12 if ($in{'annosave'}) {
13 # Just saving an annotation
14 $in{'anno'} =~ s/\r//g;
15 &save_annotation($act, $in{'anno'});
16 &redirect("view.cgi?id=$in{'id'}&search=".&urlize($in{'search'}));
20 $access{'rollback'} || &error($text{'rollback_ecannot'});
21 &can_user($act->{'user'}) || &error($text{'view_ecannot'});
22 &can_mod($act->{'module'}) || &error($text{'view_ecannot'});
23 my %r = map { $_, 1 } split(/\0/, $in{'r'});
24 %r || &error($text{'rollback_enone'});
25 my @files = grep { $r{$_->{'file'}} } &list_files($act);
27 &ui_print_header(undef, $text{'rollback_title'}, "");
31 foreach my $f (@files) {
32 next if ($done{$f->{'file'}});
33 if (-d $f->{'file'} || $f->{'type'} == 1) {
35 print &text('rollback_skipdir',"<tt>$f->{'file'}</tt>");
37 elsif (-l $f->{'file'} && $f->{'type'} == 2 ||
38 !-e $f->{'file'} && $f->{'type'} == 2 ||
39 !-l $f->{'file'} && $f->{'type'} == 2) {
40 # Modify or create link
41 &lock_file($f->{'file'});
42 &unlink_file($f->{'file'});
43 &symlink_file($f->{'data'}, $f->{'file'});
44 &unlock_file($f->{'file'});
45 print &text('rollback_madelink',
46 "<tt>$f->{'file'}</tt>",
47 "<tt>$f->{'data'}</tt>");
49 elsif (-e $f->{'file'} && -l $f->{'file'} &&
51 # Remove link and create file
52 &lock_file($f->{'file'});
53 &unlink_file($f->{'file'});
55 &open_tempfile($fh, ">$f->{'file'}");
56 &print_tempfile($fh, $f->{'data'});
58 &unlock_file($f->{'file'});
59 print &text('rollback_madefile',
60 "<tt>$f->{'file'}</tt>");
62 elsif ($f->{'type'} == -1) {
63 if (-e $f->{'file'}) {
65 &unlink_logged($f->{'file'});
66 print &text('rollback_deleted',
67 "<tt>$f->{'file'}</tt>");
70 print &text('rollback_nodeleted',
71 "<tt>$f->{'file'}</tt>");
75 # Replace file with old contents
77 &open_lock_tempfile($fh, ">$f->{'file'}");
78 &print_tempfile($fh, $f->{'data'});
80 print &text('rollback_modfile',
81 "<tt>$f->{'file'}</tt>");
84 $done{$f->{'file'}}++;
86 my %minfo = &get_module_info($act->{'module'});
87 &webmin_log("rollback", undef, $in{'id'},
88 { 'desc' => &get_action_description($act),
89 'mdesc' => $minfo{'desc'} });
92 # Show the user what will be done
93 print &ui_form_start("rollback.cgi");
94 print &ui_hidden("id", $in{'id'});
95 print &ui_hidden("search", $in{'search'});
96 foreach my $r (keys %r) {
97 print &ui_hidden("r", $r);
99 print $text{'rollback_rusure'},"<p>\n";
102 foreach my $f (@files) {
103 next if ($done{$f->{'file'}});
104 print &ui_table_start("<tt>$f->{'file'}</tt>", "width=100%", 2);
105 print "<tr> <td colspan=2>";
106 if (-d $f->{'file'} || $f->{'type'} == 1) {
108 print &text('rollback_isdir');
110 elsif (-l $f->{'file'} && $f->{'type'} == 2 ||
111 !-e $f->{'file'} && $f->{'type'} == 2) {
112 # Was a link, and is one now
113 my $lnk = readlink($f->{'file'});
114 if (!-e $f->{'file'}) {
115 print &text('rollback_clink', "<tt>$f->{'data'}</tt>");
118 elsif ($lnk ne $f->{'data'}) {
119 print &text('rollback_link', "<tt>$f->{'data'}</tt>", "<tt>$lnk</tt>");
123 print &text('rollback_nolink');
126 elsif (-e $f->{'file'} && -l $f->{'file'} &&
128 # Was a file, but is now a link
129 my $lnk = readlink($f->{'file'});
130 print &text('rollback_makefile', "<tt>$lnk</tt>");
131 print "<pre>$f->{'data'}</pre>";
134 elsif (!-l $f->{'file'} && $f->{'type'} == 2) {
135 # Was a link, but is now a file
136 print &text('rollback_makelink', "<tt>$f->{'data'}</tt>");
139 elsif ($f->{'type'} == -1) {
141 if (-e $f->{'file'}) {
142 print &text('rollback_delete',
143 "<tt>$f->{'file'}</tt>");
147 print &text('rollback_nodelete',
148 "<tt>$f->{'file'}</tt>");
151 elsif (!-e $f->{'file'}) {
153 print $text{'rollback_fillfile'};
154 print "<pre>$f->{'data'}</pre>";
158 # Was a file, and is one now
159 my $qnew = quotemeta($f->{'file'});
160 my $temp = &transname();
161 open(TEMP, ">$temp");
162 print TEMP $f->{'data'};
164 my $out = &backquote_command("diff $qnew $temp");
166 print $text{'rollback_changes'};
167 print "<pre>$out</pre>";
171 print $text{'rollback_nochanges'};
174 $done{$f->{'file'}}++;
175 print "</td> </tr>\n";
176 print &ui_table_end();
180 print &ui_form_end([ [ "confirm", $text{'rollback_ok'} ] ]);
183 print "<b>$text{'rollback_none'}</b>\n";
184 print &ui_form_end();
187 &ui_print_footer("view.cgi?id=$in{'id'}&search=".&urlize($in{'search'}),
188 $text{'view_return'},
189 "", $text{'index_return'});