-
Notifications
You must be signed in to change notification settings - Fork 1
/
install-config
executable file
·267 lines (206 loc) · 9.2 KB
/
install-config
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
#!/usr/bin/perl -w
# -*-cperl-*-
# $Id$
# $URL$
use strict;
my $WD = `pwd`;
chomp $WD;
my $TMP_DIR = ($ENV{'LIMESTONE_TMP_DIR'} or $WD."/tmp");
my $FILES_DIR = ($ENV{'LIMESTONE_FILES_DIR'} or $WD."/files");
my $LOGS_DIR = ($ENV{'LIMESTONE_LOGS_DIR'} or $WD."/aproot/logs");
my $PLOG_PATH = ($ENV{'PLOG_PATH'} or $WD."/plog.pl");
my $NON_VHOST_CONF_DIR_RELATIVE = "conf/lime-nonvhost";
my $VHOST_CONF_DIR_RELATIVE = "conf/lime-vhost";
my $NON_VHOST_CONF_DIR = "${WD}/aproot/${NON_VHOST_CONF_DIR_RELATIVE}";
my $VHOST_CONF_DIR = "${WD}/aproot/${VHOST_CONF_DIR_RELATIVE}";
my $ORIG_HTTPD_CONFIG = "aproot/conf/original/httpd.conf";
my $HTTPD_CONFIG = "aproot/conf/httpd.conf";
my $NEW_HTTPD_CONFIG = "aproot/conf/httpd.conf.new";
my $LIMESTONE_CONFIG = "${NON_VHOST_CONF_DIR}/001-limestone.conf";
my $LOGROTATE_CONFIG = "logrotate.conf";
my $LOGROTATE_CONFIG_NEW = "logrotate.conf.new";
my ($CONF_PGSQL_VHOST, $CONF_MYSQL_VHOST) = ("no", "no");
my $listen_address =
exists($ENV{'LIMESTONE_LISTEN_IP'}) ?
($ENV{'LIMESTONE_LISTEN_IP'} . ':') : '';
# make directories
my @dirs2create = ($TMP_DIR, $FILES_DIR, $NON_VHOST_CONF_DIR, $VHOST_CONF_DIR);
my $dir2create;
foreach $dir2create (@dirs2create) {
-d $dir2create or mkdir($dir2create) or die ("couldn't make $dir2create");
}
sub print_limestone_config ($$$$$$$$$) {
my ($config_fh, $vhost_port, $db_driver, $db_host,
$db_port, $db_sock, $db_name, $db_user, $db_pass) = @_;
my $ROOT_PATH = "/";
my $host_domain = $ENV{'LIMESTONE_HOST_DOMAIN'};
my $port_part_of_host;
if ($vhost_port) {
$port_part_of_host = ":${vhost_port}";
} else {
$port_part_of_host = "";
$vhost_port = 80;
}
print $config_fh qq/DBDriver $db_driver\n/;
if ($db_driver eq "pgsql") {
print $config_fh qq/DBDParams "host=$db_host /;
print $config_fh qq/port=$db_port / if $db_port;
print $config_fh qq/dbname=$db_name user=$db_user password=$db_pass"\n/;
} elsif ($db_driver eq "mysql") {
print $config_fh qq/ DBDParams "/;
if ($db_sock) {
print $config_fh "sock=$db_sock ";
} else {
print $config_fh "host=$db_host ";
print $config_fh "port=$db_port " if $db_port;
}
print $config_fh qq/dbname=$db_name user=$db_user pass=$db_pass"\n/;
}
;
print $config_fh <<EOF
LoadModule dav_repos_module modules/libmod_dav_repos.so
# NOTE: The first number in the LogFormat string refers to our internal LogFormat version.
# Whenever you make a change to LogFormat you should increment the version number.
LogFormat "3 %h %{Host}i %u %t %D %{LIMESTONE_RESOURCE_UUID}e %{UNIQUE_ID}e \\"%r\\" %{Destination}i %>s %b \\"%{Referer}i\\" \\"%{User-Agent}i\\"" limestone
# This 'plog' format is easy to parse and insert into database. This format should mimic the
# 'limestone' format as closely as possible. As such, the version number matches. This is just
# to help correlate versions and is not a functional requirement of plog.
LogFormat "log_version:3\\nhttp_version:%H\\nremote_ip:%h\\nrequest_id:%{UNIQUE_ID}e\\nrequest_method:%m\\nrequest_uri:%U\\nrequest_referer:%{Referer}i\\nvirtual_host:%{Host}i\\ndestination_uri:%{Destination}i\\nreceived_time:%{%F %R:%S %z}t\\nresponse_microseconds:%D\\nrequest_firstline:%r\\nresponse_status:%>s\\nresource_uuid:%{LIMESTONE_RESOURCE_UUID}e\\nresponse_size:%b\\nauth_user:%u\\nuser_agent:%{User-Agent}i\\n" plog
CustomLog "$LOGS_DIR/access_log" limestone
# plog.pl will take command line options here if desired
CustomLog "| $PLOG_PATH -user $db_user -password $db_pass -database $db_name -host $db_host -port $db_port -schema plog_$db_user -debug 1 -tracelog $LOGS_DIR/plog_dbtrace.log" plog
ErrorLog "$LOGS_DIR/error_log"
PidFile "$LOGS_DIR/httpd.pid"
CoreDumpDirectory $LOGS_DIR
MaxMemFree 262144
DAVLimestoneIndexCSS http://www.$host_domain${port_part_of_host}/css/style.css
DAVDBMSTmpDir $TMP_DIR
DAVDBMSFileDir $FILES_DIR
# To allow depth: infinity PROPFINDs required by some clients.
DAVDepthInfinity on
<Location ${ROOT_PATH}>
DAV repos
ModMimeUsePathInfo on
DAVResponseRewriteCond Request-URI /\\!lime/root.*
DAVResponseRewriteRule (.*) /!lime/root\$1
# work around the fact that the response rewrite system doesn't allow for multiple conditions for a rule. the next rule will undo this one.
DAVResponseRewriteCond Host ^(drive\\.)?www\\.$host_domain.*
DAVResponseRewriteRule (.*) /home/\$1
# keep this tied to the one right above
DAVResponseRewriteCond Host ^(drive\\.)?[^.]+\\.$host_domain.*
DAVResponseRewriteRule ^/home/[^/]*/?(.*) /\$1
DAVResponseRewriteCond Host ^(drive\\.)?[^.]+\\.[^.]+\\.$host_domain.*
DAVResponseRewriteRule ^/home/[^/]*/bits/[^/]*/?(.*) /\$1
AuthType Digest
AuthName "users\@limebits.com"
BrowserMatch ".*MSIE.*" AuthDigestEnableQueryStringHack=On
BrowserMatch "^CFNetwork" redirect-carefully
BrowserMatch "^Dreamweaver-WebDAV-SCM1" redirect-carefully
BrowserMatch "^gnome-vfs/1.0" redirect-carefully
BrowserMatch "Microsoft Data Access Internet Publishing Provider" redirect-carefully
BrowserMatch "Microsoft-WebDAV-MiniRedir/5.1.2600" redirect-carefully
BrowserMatch "Mozilla/2.0 (compatible; MS FrontPage 4.0)" redirect-carefully
BrowserMatch "MS FrontPage" redirect-carefully
BrowserMatch "^OmniFocus" redirect-carefully
BrowserMatch "^WebDAVFS/1.[012345]" redirect-carefully
BrowserMatch "^WebDrive" redirect-carefully
BrowserMatch "^XML Spy" redirect-carefully
AuthDigestProvider dbd
Require valid-user
#SQL query to verify a user
#(note: DBD drivers recognise both stdio-like %s and native syntax)
#Digest Authentication with mod_authn_dbd *requires* the query to have 2 parameters - user and realm.
#We dont store the realm in database, hence the useless construct ' name != %s ' to dummify realm !
AuthDBDUserRealmQuery "WITH entered AS ( SELECT %s::text as username ) SELECT u.pwhash FROM principals p, users u, entered e WHERE p.resource_id = u.principal_id AND (p.name = e.username OR u.email = e.username) AND e.username != %s"
# gzip content-encoding
SetOutputFilter DEFLATE
# Netscape 4.x has some problems...
BrowserMatch ^Mozilla/4 gzip-only-text/html
# Netscape 4.06-4.08 have some more problems
BrowserMatch ^Mozilla/4\.0[678] no-gzip
# MSIE masquerades as Netscape, but it is fine
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
# Don't compress images
SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)\$ no-gzip dont-vary
# Make sure proxies don't deliver the wrong content
Header append Vary User-Agent env=!dont-vary
</Location>
DeflateCompressionLevel 3
DeflateFilterNote Input instream
DeflateFilterNote Output outstream
DeflateFilterNote Ratio ratio
LogFormat '"\%r" \%{outstream}n/\%{instream}n (\%{ratio}n\%\%)' deflate
CustomLog $LOGS_DIR/deflate_log deflate
NameVirtualHost *:${vhost_port}
Listen ${listen_address}${vhost_port}
<VirtualHost *:${vhost_port}>
ServerName ${host_domain}${port_part_of_host}
Include ${VHOST_CONF_DIR_RELATIVE}/*.conf
</VirtualHost>
EOF
;
}
sub print_logrotate_config($) {
my ($config_fh) = @_;
print $config_fh <<EOF
${LOGS_DIR}/*log {
weekly
missingok
compress
delaycompress
notifempty
sharedscripts
postrotate
if [ -f stamps/apache-start ]; then
./aproot/bin/apachectl graceful
fi
endscript
}
EOF
;
}
sub rename_or_die($$) {
my ($src, $dest) = @_;
rename($src, $dest) or
die("couldn't rename $src to $dest");
}
my @mysql_args = grep /mysql/, @ARGV;
my @pgsql_args = grep /pgsql/, @ARGV;
die "mysql no longer supported" if ($#mysql_args > -1);
die "Only pgsql is supported. Please specify pgsql." if ($#pgsql_args < 0);
open(LIMESTONE_CONFIG, '>', $LIMESTONE_CONFIG) or die("couldn't open $LIMESTONE_CONFIG");
my $LSPORT = $ENV{'LIMESTONE_PGSQL_VHOST_PORT'};
my $DBHOST = $ENV{'LIMESTONE_PGSQL_DB_HOST'};
my $DBPORT = $ENV{'LIMESTONE_PGSQL_DB_PORT'} || 5432;
my $DBNAME = $ENV{'LIMESTONE_PGSQL_DB_NAME'};
my $DBUSER = $ENV{'LIMESTONE_PGSQL_DB_USER'};
my $DBPASS = $ENV{'LIMESTONE_PGSQL_DB_PASS'};
print_limestone_config
(*LIMESTONE_CONFIG, $LSPORT, "pgsql", $DBHOST, $DBPORT, 0, $DBNAME, $DBUSER, $DBPASS);
close(LIMESTONE_CONFIG) or die("couldn't close $LIMESTONE_CONFIG");
open(ORIG_HTTPD_CONFIG, $ORIG_HTTPD_CONFIG) or die("couldn't open $ORIG_HTTPD_CONFIG");
open(NEW_HTTPD_CONFIG, '>', $NEW_HTTPD_CONFIG) or die("couldn't open $NEW_HTTPD_CONFIG");
while (<ORIG_HTTPD_CONFIG>) {
s/^Listen 80$/#Listen 80/;
s|(CustomLog "logs/access_log" common$)|#$1|;
if ($ENV{'HTTPD_USER'}) {
s/(^User ).*/${1}$ENV{'HTTPD_USER'}/;
}
if ($ENV{'HTTPD_GROUP'}) {
s/(^Group ).*/${1}$ENV{'HTTPD_GROUP'}/;
}
if ($ENV{'HTTPD_SERVERADMIN'}) {
s/(^ServerAdmin ).*/${1}$ENV{'HTTPD_SERVERADMIN'}/;
}
print NEW_HTTPD_CONFIG;
}
print NEW_HTTPD_CONFIG "\nInclude ${NON_VHOST_CONF_DIR_RELATIVE}/*.conf\n";
close(ORIG_HTTPD_CONFIG) or die("couldn't close $ORIG_HTTPD_CONFIG");
close(NEW_HTTPD_CONFIG) or die("couldn't close $NEW_HTTPD_CONFIG");
open(LOGROTATE_CONFIG_NEW, '>', $LOGROTATE_CONFIG_NEW) or
die("couldn't open $LOGROTATE_CONFIG_NEW");
print_logrotate_config(*LOGROTATE_CONFIG_NEW);
close(LOGROTATE_CONFIG_NEW);
rename_or_die($NEW_HTTPD_CONFIG, $HTTPD_CONFIG);
rename_or_die($LOGROTATE_CONFIG_NEW, $LOGROTATE_CONFIG);
exit 0;