-
Notifications
You must be signed in to change notification settings - Fork 2
/
lighttpd.xsl
187 lines (166 loc) · 6.87 KB
/
lighttpd.xsl
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
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE xsl:stylesheet [
<!ENTITY nl " ">
<!ENTITY quot "'">
<!ENTITY sp " ">
<!ENTITY sp2 "&sp;&sp;">
<!ENTITY sp3 "&sp;&sp;&sp;">
]>
<xsl:stylesheet
xmlns:str="http://exslt.org/strings"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:ya="urn:yandex-functions"
exclude-result-prefixes="ya"
extension-element-prefixes="str"
version="1.0">
<!--
==========================================================
Автогенератор конфигурационных файлов
Веб-сервер: lighttpd
Автор: Yuriy Belyakov <belyan@yandex-team.ru>
Репозиторий: https://svn.yandex.ru/common/autoconf/
==========================================================
-->
<xsl:include href="common.xsl"/>
<!-- Конфигурационный файл -->
<xsl:template match="conf"/>
<xsl:template match="conf[string(hosts/host/name)]">
<xsl:text># Automatically generated file. Do not edit it manually.</xsl:text>
<xsl:text>&nl;&nl;</xsl:text>
<xsl:text>$HTTP["host"] =~ </xsl:text>
<xsl:apply-templates select="hosts"/>
<xsl:text> {</xsl:text>
<xsl:apply-templates select="." mode="root"/>
<xsl:apply-templates select="." mode="xscript"/>
<xsl:apply-templates select="." mode="access"/>
<xsl:text>&nl;</xsl:text>
<xsl:text>}</xsl:text>
<xsl:apply-templates select="hosts/host" mode="aliases"/>
<xsl:text>&nl;</xsl:text>
<xsl:apply-templates select="hosts/host" mode="testing"/>
<xsl:text>&nl;</xsl:text>
</xsl:template>
<!-- Список хостов -->
<xsl:template match="hosts">
<xsl:text>"^(</xsl:text>
<xsl:apply-templates select="host"/>
<xsl:text>)(:\d+)?$"</xsl:text>
</xsl:template>
<!-- Хост -->
<xsl:template match="host">
<xsl:variable name="host-name" select="name"/>
<xsl:variable name="host-sld" select="ya:if(string(@sld), @sld, $default/sld)"/>
<xsl:variable name="host-tld" select="ya:if(string(@tld), @tld, $default/tld)"/>
<xsl:if test="position() > 1">
<xsl:text>|</xsl:text>
</xsl:if>
<xsl:apply-templates select="$host-name">
<xsl:with-param name="sld" select="$host-sld"/>
<xsl:with-param name="tld" select="$host-tld"/>
</xsl:apply-templates>
<xsl:text>|</xsl:text>
<xsl:apply-templates select="$host-name">
<xsl:with-param name="sld" select="$host-sld"/>
<xsl:with-param name="tld" select="$host-tld"/>
<xsl:with-param name="mode">regexp</xsl:with-param>
</xsl:apply-templates>
</xsl:template>
<!-- Имя хоста -->
<xsl:template match="host/name">
<xsl:param name="sld"/>
<xsl:param name="tld"/>
<xsl:param name="mode"/>
<xsl:variable name="host-name">
<xsl:if test="$mode = 'www'">
<xsl:text>www.</xsl:text>
</xsl:if>
<xsl:value-of select="."/>
<xsl:text>.</xsl:text>
<xsl:if test="$mode = 'regexp'">
<xsl:text>[a-z0-9\-]+</xsl:text>
<xsl:text>.</xsl:text>
</xsl:if>
<xsl:if test="$mode = 'testing'">
<xsl:text>rage</xsl:text>
<xsl:text>.</xsl:text>
</xsl:if>
<xsl:value-of select="$sld"/>
<xsl:text>.</xsl:text>
<xsl:value-of select="$tld"/>
</xsl:variable>
<xsl:value-of select="str:replace($host-name, '.', '\.')"/>
</xsl:template>
<!-- Корневая папка -->
<xsl:template match="conf" mode="root">
<xsl:text>&nl;&sp;</xsl:text>
<xsl:text>server.document-root = "/usr/local/www5/</xsl:text>
<xsl:choose>
<xsl:when test="string(@project)">
<xsl:value-of select="@project"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$default/project"/>
</xsl:otherwise>
</xsl:choose>
<xsl:text>"&nl;</xsl:text>
</xsl:template>
<!-- XScript -->
<xsl:template match="conf" mode="xscript">
<xsl:text>&nl;&sp;</xsl:text>
<xsl:text>fastcgi.server = (</xsl:text>
<xsl:text>&nl;&sp2;</xsl:text>
<xsl:text>".xml" => ((</xsl:text>
<xsl:text>&nl;&sp3;</xsl:text>
<xsl:text>"socket" => "/tmp/xscript-multiple/xscript-</xsl:text>
<xsl:choose>
<xsl:when test="string(@xscript)">
<xsl:value-of select="@xscript"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$default/xscript"/>
</xsl:otherwise>
</xsl:choose>
<xsl:text>.sock",</xsl:text>
<xsl:text>&nl;&sp3;</xsl:text>
<xsl:text>"check-local" => "enable",</xsl:text>
<xsl:text>&nl;&sp3;</xsl:text>
<xsl:text>"allow-x-send-file" => "enable"</xsl:text>
<xsl:text>&nl;&sp2;</xsl:text>
<xsl:text>))</xsl:text>
<xsl:text>&nl;&sp;</xsl:text>
<xsl:text>)</xsl:text>
</xsl:template>
<!-- Доступ к папкам -->
<xsl:template match="conf" mode="access">
<xsl:text>&nl;&nl;&sp;</xsl:text>
<xsl:text>$HTTP["url"] =~ "^/(lego|xml)/.*" {</xsl:text>
<xsl:text>&nl;&sp2;</xsl:text>
<xsl:text>url.access-deny = ( "" )</xsl:text>
<xsl:text>&nl;&sp;</xsl:text>
<xsl:text>}</xsl:text>
</xsl:template>
<!-- TODO: Алиасы хоста -->
<xsl:template match="host" mode="aliases"/>
<!-- Тестинг -->
<xsl:template match="host" mode="testing">
<xsl:variable name="host-name" select="name"/>
<xsl:variable name="host-sld" select="ya:if(string(@sld), @sld, $default/sld)"/>
<xsl:variable name="host-tld" select="ya:if(string(@tld), @tld, $default/tld)"/>
<xsl:text>&nl;&nl;</xsl:text>
<xsl:text>$HTTP["host"] =~ "^</xsl:text>
<xsl:apply-templates select="$host-name">
<xsl:with-param name="sld" select="$host-sld"/>
<xsl:with-param name="tld" select="$host-tld"/>
<xsl:with-param name="mode">testing</xsl:with-param>
</xsl:apply-templates>
<xsl:text>(:\d+)?$" {</xsl:text>
<xsl:text>&nl;&sp;</xsl:text>
<xsl:text>setenv.add-environment += (</xsl:text>
<xsl:text>&nl;&sp2;</xsl:text>
<xsl:text>"XSCRIPT_ENVIRONMENT" => "testing"</xsl:text>
<xsl:text>&nl;&sp;</xsl:text>
<xsl:text>)</xsl:text>
<xsl:text>&nl;</xsl:text>
<xsl:text>}</xsl:text>
</xsl:template>
</xsl:stylesheet>