123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225 |
- our $VERSION = '2011.10.30';
- use 5.010;
- use strict;
- use warnings;
- use Getopt::Long;
- use Pod::Usage;
- my $ignorecomments;
- {
- my $help;
- my $man;
- my %GetOptions = (
- 'help|?' => \$help,
- 'man' => \$man
- );
- $GetOptions{'ignorecomments'} = \$ignorecomments;
- GetOptions (%GetOptions) or pod2usage (2);
- pod2usage (1) if ($help);
- pod2usage (-exitstatus => 0, -ignorecomments => 2) if ($man);
- (scalar (@ARGV) == 2) or
- die ("Need two file parameters.\n");
- }
- my %convert_logic = (
-
- 'allowremoteoper' => [ 'Options' ],
- 'chrootdir' => [ 'Options' ],
- 'connectipv4' => [ 'Options' ],
- 'connectipv6' => [ 'Options' ],
- 'connectretry' => [ 'Limits' ],
- 'maxconnections' => [ 'Limits' ],
- 'maxconnectionsip' => [ 'Limits' ],
- 'maxjoins' => [ 'Limits' ],
- 'maxnicklength' => [ 'Limits' ],
- 'nodns' => [ 'Options', 'DNS', 1 ],
- 'noident' => [ 'Options', 'Ident', 1 ],
- 'nopam' => [ 'Options', 'PAM', 1 ],
- 'opercanusemode' => [ 'Options' ],
- 'operservermode' => [ 'Options' ],
- 'pingtimeout' => [ 'Limits' ],
- 'pongtimeout' => [ 'Limits' ],
- 'predefchannelsonly' => [ 'Options' ],
- 'sslcertfile' => [ 'SSL', 'CertFile' ],
- 'ssldhfile' => [ 'SSL', 'DHFile' ],
- 'sslkeyfile' => [ 'SSL', 'KeyFile' ],
- 'sslkeyfilepassword' => [ 'SSL', 'KeyFilePassword' ],
- 'sslports' => [ 'SSL', 'Ports' ],
- 'syslogfacility' => [ 'Options' ],
- 'webircpassword' => [ 'Options' ],
- );
- my $oldvars = join ('|', keys %convert_logic);
- my ($old_file, $new_file) = @ARGV;
- my ($old_fh, $new_fh);
- if ($old_file eq '-') {
- $old_fh = *STDIN;
- } else {
- (-f $old_file) or
- die ("Not a file: '$old_file'.\n");
- open ($old_fh, '<', $old_file) or
- die ("Canno read '$old_file': $!.\n");
- }
- my $section = '';
- my $set_section = '';
- my @content = <$old_fh>;
- ($old_file eq '-') or close ($old_fh);
- sub insert_line ($$) {
-
-
- my ($before, $content) = @_;
- while ($before > 0 && $content[--$before] =~ /^\s*#/) {
- }
- splice @content, $before+1, 0, $content;
- }
- for (my $i = 0; $i < scalar (@content); $i++) {
- my $line = $content[$i];
- if ($line =~ /^\s*\[([a-z]+)\]/i) {
- $set_section = $section = lc $1;
- } elsif ($line =~ /^\s*(,|#|$)/) {
-
- } elsif (
- $section eq 'global' &&
- $line =~ /^(\s*)(;\s*)?($oldvars)(\s*=\s*)(.*?)$/i
- ) {
- my ($left, $comment, $var, $middle, $value) =
- ($1 // '', $2 // '', $3, $4, $5 // '');
- my ($new_section, $new_var, $invert) = @{$convert_logic{lc $var}};
- $new_var //= $var;
- ($comment && $ignorecomments) and
- next;
- if ($set_section ne $new_section) {
-
- insert_line ($i, "[$new_section]\n"); $i++;
- $set_section = $new_section;
- }
- $invert and
- ($value = ($value =~ /^(yes|true|[1-9]\d*)\s*$/) ? 'no' : 'yes');
- $content[$i] = "$left$comment$new_var$middle$value\n";
- } elsif ($set_section ne $section) {
-
- die if ($section ne 'global');
- insert_line ($i, "[Global]\n"); $i++;
- $set_section = $section;
- }
- }
- if ($new_file eq '-') {
- $new_fh = *STDOUT;
- } else {
- open ($new_fh, '>', $new_file) or
- die ("Canno write '$new_file': $!.\n");
- print $new_fh @content;
- }
- ($new_file eq '-') or close ($new_fh);
- exit 0;
- __END__
|