#!/usr/bin/perl 
=item
command to update all the sites:

for  i in  `ls /etc/httpd/conf.d/opals/*.conf`;do echo $i;sudo opals-20160304-140315/script/update/20160210/updateHttpConf -c $i;done
=cut
use lib '/www/opals/module';
#use Opals::Context("/etc/opals/conf/_MY_SITE_");

use strict;
use DBI;
use Getopt::Std;

    my %options = ();
    getopts("c:",\%options);
    my $httpConf = $options{c};
    $httpConf=~ s/^http:\/\///g;
    
    my $confTxt="";

    my $rewriteRule=<<_STR_;

    RewriteEngine on
    RewriteRule   /ebook/reader/([^/]+) /bin/ebook/reader?bid=\$1 [PT] 
    RewriteRule   /ebook/([^/]+)/([^/]+) /bin/ebook/file?bid=\$1&fid=\$2 [PT]
    RewriteRule   /doc/([^/]+) /bin/util/getFile?fileId=\$1 [PT]

_STR_


    open CONF, $httpConf || die "Cannot open file $httpConf";
    while (<CONF>) {
        my $str=$_;
        next if($str =~ m/RewriteEngine|RewriteRule/g);
        $confTxt .=$_;
    }
    close CONF;
    
    $confTxt =~ s/(.*)[\s]*<\/VirtualHost>/$1\n$rewriteRule<\/VirtualHost>/g;
    open CONF, ">$httpConf";
    #open CONF, ">/tmp/httpconf";
    print CONF $confTxt;
    close CONF;

exit 0;
    




