MOON
Server: Apache/2.2.31 (Unix) mod_ssl/2.2.31 OpenSSL/0.9.8e-fips-rhel5 mod_bwlimited/1.4
System: Linux csr818.wilogic.com 2.6.18-419.el5xen #1 SMP Fri Feb 24 22:50:37 UTC 2017 x86_64
User: digitals (531)
PHP: 5.4.45
Disabled: NONE
Upload Files
File: //scripts.20110531.215904.25158/regsrep.pl
#!/usr/bin/perl
# cpanel - regsrep.pl                             Copyright(c) 2010 cPanel, Inc.
#                                                           All rights Reserved.
# copyright@cpanel.net                                         http://cpanel.net
# This code is subject to the cPanel license. Unauthorized copying is prohibited

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

use Cpanel::SafeFile;
use Cpanel::Logger ();

my $logger = Cpanel::Logger->new();

sub regsrep {
   my($file,$old,$new,$useregex,$search,$replace) = @_;
   my(@CFILE);
   my $filelock = Cpanel::SafeFile::safeopen(\*FH,"+<","$file");
   if( !$filelock ) {
       $logger->warn("Could not edit $file");
       return;
   }
   while(<FH>) {
      if ($_ =~ /^$/ || $_ eq "\n" || $_ eq "\r\n") {
         push(@CFILE,$_);
      } elsif($_ =~ /$old/) {
         my $result = $1;
         my $mnew = $new;
         $mnew =~ s/\$1/${result}/g;
         next if ($new eq "-1");

         if ($search ne "") {
            $mnew =~ s/${search}/${replace}/g;
         }

         if ($useregex) {
            $mnew = $_;
            $mnew =~ s/${old}/${new}/g;
            $mnew =~ s/\n//g;
         }
         push(@CFILE,"${mnew}\n");
      } else {
         push(@CFILE,$_);
      }
   }
   seek(FH,0,0);
   print FH join("",@CFILE);
   truncate(FH,tell(FH));
   Cpanel::SafeFile::safeclose(\*FH,$filelock);
}
1;