3 # Swap two rules in some chain
5 require './firewall-lib.pl';
7 &lock_file($iptables_save_file);
8 @tables = &get_iptables_save();
9 $table = $tables[$in{'table'}];
10 &can_edit_table($table->{'name'}) || &error($text{'etable'});
11 $r = $table->{'rules'};
12 $c = $r->[$in{'idx'}]->{'chain'};
13 @rules = grep { lc($_->{'chain'}) eq lc($c) } @$r;
14 $pos = &indexof($r->[$in{'idx'}], @rules);
15 &can_jump($r->[$in{'idx'}]) || &error($text{'ejump'});
17 # Swap with next rule in this chain
18 $nxt = $rules[$pos+1]->{'index'};
19 &can_jump($r->[$nxt]) || &error($text{'ejump'});
20 ($r->[$in{'idx'}], $r->[$nxt]) = ($r->[$nxt], $r->[$in{'idx'}]);
23 # Swap with previous rule in this chain
24 $prv = $rules[$pos-1]->{'index'};
25 &can_jump($r->[$prv]) || &error($text{'ejump'});
26 ($r->[$in{'idx'}], $r->[$prv]) = ($r->[$prv], $r->[$in{'idx'}]);
28 &run_before_command();
32 &unlock_file($iptables_save_file);
33 &webmin_log("move", "rule", undef, { 'table' => $table->{'name'},
34 'chain' => $r->[$in{'idx'}]->{'chain'} });
35 &redirect("index.cgi?table=$in{'table'}");