-
Notifications
You must be signed in to change notification settings - Fork 0
/
tntnet-conf2xml.pl
executable file
·187 lines (167 loc) · 3.74 KB
/
tntnet-conf2xml.pl
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
#!/usr/bin/perl -w
=head1 NAME
=head1 SYNOPSIS
=head1 DESCRIPTION
=head1 OPTIONS
=head1 AUTHOR
Tommi ME<auml>kitalo, Tntnet.org
=cut
use strict;
my ($mappings, $listeners, $settings, $appconfigs, $comppath) = ("", "", "", "", "");
my %keywords = (
MaxRequestSize => 'maxRequestSize',
MaxRequestTime => 'maxRequestTime',
User => 'user',
Group => 'group',
Dir => 'dir',
Chroot => 'chrootdir',
PidFile => 'pidFile',
Daemon => 'daemon',
MinThreads => 'minThreads',
MaxThreads => 'maxThreads',
ThreadStartDelay => 'threadStartDelay',
QueueSize => 'queueSize',
CompPath => 'compPath',
BufferSize => 'socketBufferSize',
SocketReadTimeout => 'socketReadTimeout',
SocketWriteTimeout => 'socketWriteTimeout',
KeepAliveTimeout => 'keepAliveTimeout',
KeepAliveMax => 'keepAliveMax',
SessionTimeout => 'sessionTimeout',
ListenBacklog => 'listenBacklog',
ListenRetry => 'listenRetry',
EnableCompression => 'enableCompression',
MimeDb => 'mimeDb',
MinCompressSize => 'minCompressSize',
MaxUrlMapCache => 'maxUrlMapCache',
DefaultContentType => 'defaultContentType',
AccessLog => 'accessLog',
ErrorLog => 'errorLog',
MaxBackgroundTasks => 'maxBackgroundTasks',
MimeDb => 'mimeDb',
DocumentRoot => 'documentRoot',
);
my %obsolete = (
PropertyFile => 'logproperties',
);
while (<>)
{
chomp;
s/ *#.*//g;
my ($keyword, @params) = grep { defined($_) } /"([^"]*)"|([^"\s]+)/g;
next unless $keyword;
@params = map { s/^(["'])(.*)(\1)/$2/; $_; } @params;
if ($keyword =~ /^(V?)MapUrl$/)
{
my $vhost = shift @params if ($1);
my ($url, $target, $pathinfo, @args) = @params;
$mappings .= <<EOF;
<mapping>
<target>$target</target>
<url>$url</url>
EOF
$mappings .= <<EOF if $pathinfo;
<pathinfo>$pathinfo</pathinfo>
EOF
$mappings .= <<EOF if $vhost;
<vhost>$vhost</vhost>
EOF
if (@args)
{
$mappings .= <<EOF;
<args>
EOF
foreach (@args)
{
$mappings .= <<EOF;
<arg>$_</arg>
EOF
}
$mappings .= <<EOF;
</args>
EOF
}
$mappings .= <<EOF;
</mapping>
EOF
}
elsif ($keyword eq "Listen")
{
my ($ip, $port) = @params;
$ip =~ s/"//g;
$listeners .= <<EOF;
<listener>
<ip>$ip</ip>
<port>$port</port>
</listener>
EOF
}
elsif ($keyword eq "SslListen")
{
my ($ip, $port, $certificate, $key) = @params;
$ip =~ s/"//g;
$listeners .= <<EOF;
<listener>
<ip>$ip</ip>
<port>$port</port>
<certificate>$certificate</certificate>
EOF
$listeners .= <<EOF if $key;
<key>$key</key>
EOF
$listeners .= <<EOF;
</listener>
EOF
}
elsif ($keyword eq "CompPath")
{
$comppath .= <<EOF;
<entry>$params[0]</entry>
EOF
}
elsif ($keywords{$keyword})
{
$settings .= <<EOF;
<$keywords{$keyword}>$params[0]</$keywords{$keyword}>
EOF
}
elsif (!$obsolete{$keyword})
{
$appconfigs .= <<EOF;
<$keyword>$params[0]</$keyword>
EOF
}
}
print <<EOF;
<?xml version="1.0" encoding="UTF-8"?>
<tntnet>
<mappings>
$mappings </mappings>
EOF
print <<EOF;
EOF
print <<EOF if $listeners;
<listeners>
$listeners </listeners>
EOF
print $settings;
print <<EOF if $comppath;
<compPath>
$comppath </compPath>
EOF
print <<EOF;
<logging>
<rootlogger>INFO</rootlogger>
<loggers>
<logger>
<category>tntnet</category>
<level>INFO</level>
</logger>
</loggers>
<!-- <file>tntnet.log</file> --> <!--uncomment if you want to log to a file -->
<!-- <maxfilesize>1MB</maxfilesize> -->
<!-- <maxbackupindex>2</maxbackupindex> -->
<!-- <host>localhost:1234</host> --> <!-- # send log-messages with udp -->
</logging>
$appconfigs</tntnet>
EOF