#!/usr/bin/perl
# cpanel - autofixer2/pureftpd_bind                Copyright(c) 2013 cPanel, Inc.
#                                                            All rights Reserved.
# copyright@cpanel.net                                         http://cpanel.net
# This code is subject to the cPanel license. Unauthorized copying is prohibited

use strict;

BEGIN {
    unshift @INC, "/usr/local/cpanel";
}

use Cpanel::SafeFile ();
use Cpanel::Version  ();

exit unless $Cpanel::Version::MAJORVERSION == 11.36;

my $conf_file = "/var/cpanel/conf/pureftpd/main";

if ( my $lock = Cpanel::SafeFile::safeopen( my $fh, "+<", $conf_file ) ) {
    my @lines   = <$fh>;
    my $changed = 0;
    foreach my $line (@lines) {
        if ( $line =~ /^Bind:\s+127\.0\.0\.1,21$/ ) {
            $line    = "Bind: 21\n";
            $changed = 1;
        }
    }
    if ($changed) {
        seek( $fh, 0, 0 );
        print {$fh} @lines;
        truncate( $fh, tell($fh) );
    }
    Cpanel::SafeFile::safeclose( $fh, $lock );

    exit unless $changed;

    system("/usr/local/cpanel/bin/build_ftp_conf");
    system("/usr/local/cpanel/scripts/restartsrv_ftpd");
}
