1#!/usr/local/bin/perl 2# move.cgi 3# Swap two rules in some chain 4 5require './firewall-lib.pl'; 6&ReadParse(); 7# what version IP protocaol version to use? 8if (&get_ipvx_version() == 6) { 9 require './firewall6-lib.pl'; 10 } 11else { 12 require './firewall4-lib.pl'; 13 } 14&lock_file($ipvx_save); 15@tables = &get_iptables_save(); 16$table = $tables[$in{'table'}]; 17&can_edit_table($table->{'name'}) || &error($text{'etable'}); 18$r = $table->{'rules'}; 19$c = $r->[$in{'idx'}]->{'chain'}; 20@rules = grep { lc($_->{'chain'}) eq lc($c) } @$r; 21$pos = &indexof($r->[$in{'idx'}], @rules); 22&can_jump($r->[$in{'idx'}]) || &error($text{'ejump'}); 23if ($in{'down'}) { 24 # Swap with next rule in this chain 25 $nxt = $rules[$pos+1]->{'index'}; 26 &can_jump($r->[$nxt]) || &error($text{'ejump'}); 27 ($r->[$in{'idx'}], $r->[$nxt]) = ($r->[$nxt], $r->[$in{'idx'}]); 28 } 29else { 30 # Swap with previous rule in this chain 31 $prv = $rules[$pos-1]->{'index'}; 32 &can_jump($r->[$prv]) || &error($text{'ejump'}); 33 ($r->[$in{'idx'}], $r->[$prv]) = ($r->[$prv], $r->[$in{'idx'}]); 34 } 35&run_before_command(); 36&save_table($table); 37&run_after_command(); 38©_to_cluster(); 39&unlock_file($ipvx_save); 40&webmin_log("move", "rule", undef, { 'table' => $table->{'name'}, 41 'chain' => $r->[$in{'idx'}]->{'chain'} }); 42&redirect("index.cgi?version=${ipvx_arg}&table=$in{'table'}"); 43 44