]> bicyclesonthemoon.info Git - yplom/proxy/blob - configure.pl
Support for 206 Partial content.
[yplom/proxy] / configure.pl
1 #!/usr/bin/perl
2
3 # configure.pl
4 # 02.01.2016
5 #
6 # The proxy software, when run on a server, will use different directories,
7 # host names, tcp ports, etc. than the server on which this software was
8 # originally written.
9 # These things are defined in the file 'settings'.
10 # This script is called from the makefile. It reads the settings file and
11 # inserts the information in the source files.
12 #
13 #    Copyright (C) 2015-2016  Balthasar SzczepaƄski
14 #
15 #    This program is free software: you can redistribute it and/or modify
16 #    it under the terms of the GNU Affero General Public License as
17 #    published by the Free Software Foundation, either version 3 of the
18 #    License, or (at your option) any later version.
19 #
20 #    This program is distributed in the hope that it will be useful,
21 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
22 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23 #    GNU Affero General Public License for more details.
24 #
25 #    You should have received a copy of the GNU Affero General Public License
26 #    along with this program.  If not, see <http://www.gnu.org/licenses/>.
27
28 unless ($ARGV[0]) {
29         print STDERR "Configfile missing.\n";
30         exit 1;
31 }
32
33 unless (open $configfile, "<", $ARGV[0]) {
34         print STDERR "Cannot open configfile\n";
35         exit 2;
36 }
37
38 # Read the config file, line format:
39 # some_name = some value # some comment
40 while (defined(my $line = <$configfile>)) {
41         $line =~ s/[\r\n]//g;
42         $line =~ s/#.*$//; #comment
43         if ($line =~ /^[ \t]*([a-zA-Z0-9_\-\.]+)[ \t]*=[ \t]*([^ \t](.*[^ \t])?)[ \t]*$/){
44                 my $name=$1;
45                 my $value=$2;
46                 $set{$name}=$value;
47         }
48 }
49 close ($configfile);
50
51 # Now generate things to be inserted.
52
53 $def{'UNLOCK_LOG'}        = "use constant UNLOCK_LOG         => '".$set{'log_path'}."unlock.log';";
54 $def{'CURL_PATH'}         = "use constant CURL_PATH          => '".$set{'curl'}."';";
55 $def{'GZIP_PATH'}         = "use constant GZIP_PATH          => '".$set{'gzip'}."';";
56 $def{'DATA_PATH'}         = "use constant DATA_PATH          => '".$set{'data_path'}."';";
57 $def{'LOG_PATH'}          = "use constant LOG_PATH           => '".$set{'log_path'}."';";
58 $def{'TEMP_PATH'}         = "use constant TEMP_PATH          => '".$set{'tmp_path'}."';";
59 $def{'PASS_PATH'}         = "use constant PASS_PATH          => '".$set{'data_path'}."pass/';";
60 $def{'ARCH_PATH'}         = "use constant ARCH_PATH          => '".$set{'data_path'}."archive/';";
61 $def{'ACCESS_PATH'}       = "use constant ACCESS_PATH        => '".$set{'data_path'}."access/';";
62 $def{'UNLOCK_PROXY_URL'}  = "use constant UNLOCK_PROXY_URL   => 'http://".$set{'unlock_domain'}.$set{'unlock_path'}."';";
63 $def{'UNLOCK_PROXY_URL_S'}= "use constant UNLOCK_PROXY_URL_S => 'https://".$set{'unlock_domain'}.$set{'unlock_path'}."';";
64 $def{'UNLOCK_PROXY_HOST'} = "use constant UNLOCK_PROXY_HOST  => qr/".$set{'unlock_domain_regex'}."/;";
65 $def{'UNLOCK_PROXY_PATH'} = "use constant UNLOCK_PROXY_PATH  => qr/".$set{'unlock_path_regex'}."/;";
66 $def{'BLOCK_HOST'}        = "use constant BLOCK_HOST         => qr/".$set{'block_host_regex'}."/;";
67 $def{'BLOCK_PORT'}        = 'use constant BLOCK_PORT         => qr/^((0*'.$set{'http_proxy_port'}.')|('.$set{'https_proxy_port'}.')|('.$set{'ssl_proxy_port'}.'))$/;';
68 $def{'TIMEOUT_UNLOCK'}    = "use constant TIMEOUT_UNLOCK     => ".$set{'timeout_unlock'}.";";
69 $def{'TIMEOUT_INACT'}     = "use constant TIMEOUT_INACT      => ".$set{'timeout_inact'}.";";
70 $def{'TIMEOUT_ARCH'}      = "use constant TIMEOUT_ARCH       => ".$set{'timeout_arch'}.";";
71 $def{'LOG_SIZE_LIMIT'}    = "use constant LOG_SIZE_LIMIT     => ".$set{'log_size_limit'}.";";
72 $def{'LOGS_UNCOMPRESSED'} = "use constant LOGS_UNCOMPRESSED  => ".$set{'logs_uncompressed'}.";";
73 $def{'LOGS_TOTAL'}        = "use constant LOGS_TOTAL         => ".$set{'logs_total'}.";";
74 $def{'REWRITE_URL'}       = "use constant REWRITE_URL        => '".$set{'https_proxy_domain'}.":".$set{'https_proxy_port'}."';";
75 $def{'LIB'} = "use lib '".$set{'lib_path'}."';";
76
77
78 $def{'PATH'} = "\$ENV{'PATH'} = '".$set{'path'}."';";
79
80 $def{'PERL'} = "#!".$set{'perl'};
81
82 $def{'PROXY_PL'}         = '#define PROXY_PL         "'.$set{'bin_path'}.'proxy.pl"';
83 $def{'PROXY_PL_ERRLOG'}  = '#define PROXY_PL_ERRLOG  "'.$set{'log_path'}.'proxy-stderr.log"';
84 $def{'ACCESS_PL'}        = '#define ACCESS_PL        "'.$set{'bin_path'}.'access.pl"';
85 $def{'ACCESS_PL_ERRLOG'} = '#define ACCESS_PL_ERRLOG "'.$set{'log_path'}.'access-stderr.log"';
86
87 $def{'VIRTUAL_HOST_HTTP'} = '<VirtualHost _default_:'.$set{'http_proxy_port'}.'>';
88 $def{'VIRTUAL_HOST_HTTPS'}= '<VirtualHost _default_:'.$set{'https_proxy_port'}.'>';
89 $def{'SERVER_ADMIN'}      = "\tServerAdmin           ".$set{'server_admin'};
90 $def{'SERVER_NAME_HTTP'}  = "\tServerName            ".$set{'http_proxy_domain'};
91 $def{'SERVER_NAME_HTTPS'} = "\tServerName            ".$set{'https_proxy_domain'};
92 $def{'DOCUMENT_ROOT'}     = "\tDocumentRoot          ".$set{'www_path'};
93 $def{'CGI_ALIAS'}         = "\tScriptAliasMatch (.*) ".$set{'bin_path'}.'proxy$1';
94 $def{'SSL_CERT'}          = "\tSSLCertificateFile    ".$set{'ssl_cert'};
95 $def{'SSL_KEY'}           = "\tSSLCertificateKEYFile ".$set{'ssl_key'};
96 $def{'CUSTOM_LOG_HTTP'}   = "\tCustomLog             ".$set{'log_path'}.'http.log combined';
97 $def{'ERROR_LOG_HTTP'}    = "\tErrorLog              ".$set{'log_path'}.'http-err.log';
98 $def{'CUSTOM_LOG_HTTPS'}  = "\tCustomLog             ".$set{'log_path'}.'https.log combined';
99 $def{'ERROR_LOG_HTTPS'}   = "\tErrorLog              ".$set{'log_path'}.'https-err.log';
100 $def{'LISTEN_HTTP'}       = '# Listen '.$set{'http_proxy_port'};
101 $def{'LISTEN_HTTPS'}      = '# Listen '.$set{'https_proxy_port'};
102
103 $def{'HTTP_PORT_SSL'}     = 'http_port '.$set{'ssl_proxy_port'};
104 $def{'EXTERNAL_ACL'}      = 'external_acl_type unlocked-check ttl=15 negative_ttl=0 %SRC '.$set{'bin_path'}.'access';
105 $def{'EXTERNAL_REWRITE'}  = 'url_rewrite_program '.$set{'bin_path'}.'rewrite';
106 $def{'UNLOCK_DOMAIN_ACL'} = 'acl unlockdomain dstdomain '.$set{'unlock_domain'};
107
108 $def{'RM_ACCESS_CRONTAB'} = $set{'rm_access_crontab'}.' '.$set{'rm'}.' '.$set{'data_path'}.'access/*';
109 $def{'CLEARARCH_CRONTAB'} = $set{'cleararch_crontab'}.' '.$set{'bin_path'}.'cleararch >> '.$set{'log_path'}.'cleararch.log';
110 $def{'OLDLOGS_CRONTAB'}   = $set{'oldlogs_crontab'}.' '.$set{'bin_path'}.'oldlogs';
111
112
113 $def{'CC'} = 'CC='.$set{'gcc'};
114 $def{'CF'} = 'CF='.$set{'c_flags'};
115 $def{'PL'} = 'PL='.$set{'perl'};
116 $def{'MV'} = 'MV='.$set{'mv'};
117 $def{'CP'} = 'CM='.$set{'cp'};
118 $def{'RM'} = 'RM='.$set{'rm'};
119 $def{'OD'} = 'OD='.$set{'bin_path'};
120 $def{'LD'} = 'LD='.$set{'lib_path'};
121 $def{'CM'} = 'CM='.$set{'chmod'};
122
123
124 # Now go through input file, find lines to be replaced. Format:
125 # ###SOME_NAME;
126 # If found - replace.
127
128 while (defined($line = <STDIN>)) {
129         $line =~ s/[\r\n]//g;
130         if ($line =~ /###([a-zA-Z0-9_]+);/) {
131                 print "$def{$1}\n";
132         }
133         else {
134                 print "$line\n";
135         }
136 }