You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

401 lines
8.3 KiB

  1. #!/bin/bash
  2. exname=$(basename $0)
  3. prefix_cmd="
  4. . /etc/shlib
  5. include common
  6. include parse
  7. . ../lib/common
  8. "
  9. # mock
  10. relation-get() {
  11. local key="$1"
  12. echo "$CFG" | shyaml get-value "$key" 2>/dev/null
  13. }
  14. export -f relation-get
  15. cfg-get-value() {
  16. local key="$1"
  17. shyaml get-value "$key" 2>/dev/null
  18. }
  19. export -f cfg-get-value
  20. get_service_relations() {
  21. printf "%s\0" "${RELATIONS[@]}"
  22. }
  23. export -f get_service_relations
  24. export state_tmpdir=$(mktemp -d -t tmp.XXXXXXXXXX)
  25. trap "rm -rf \"$state_tmpdir\"" EXIT
  26. ##
  27. ## Tests
  28. ##
  29. try "
  30. apache_vhost_statement publish_dir ,http, '\
  31. ' www.example.com"
  32. noerror
  33. is out '<VirtualHost *:80>
  34. ServerAdmin contact@www.example.com
  35. ServerName www.example.com
  36. ServerSignature Off
  37. CustomLog /var/log/apache2/www.example.com_access.log combined
  38. ErrorLog /var/log/apache2/www.example.com_error.log
  39. ErrorLog syslog:local2
  40. ##
  41. ## Publish directory /var/www/www.example.com
  42. ##
  43. DocumentRoot /var/www/www.example.com
  44. <Directory />
  45. Options FollowSymLinks
  46. AllowOverride None
  47. </Directory>
  48. <Directory /var/www/www.example.com>
  49. Options Indexes FollowSymLinks MultiViews
  50. AllowOverride all
  51. Allow from all
  52. </Directory>
  53. ## Forbid any cache, this is only usefull on dev server.
  54. #Header set Cache-Control "no-cache"
  55. #Header set Access-Control-Allow-Origin "*"
  56. #Header set Access-Control-Allow-Methods "POST, GET, OPTIONS"
  57. #Header set Access-Control-Allow-Headers "origin, content-type, accept"
  58. </VirtualHost>' RTRIM
  59. ##
  60. ## Aliases
  61. ##
  62. try "
  63. apache_vhost_statement publish_dir ,http, '
  64. server-aliases:
  65. - toto
  66. ' www.example.com"
  67. noerror
  68. is out reg 'ServerAlias toto'
  69. try "
  70. apache_vhost_statement publish_dir ,http, '
  71. server-aliases:
  72. - toto
  73. - titi
  74. ' www.example.com"
  75. noerror
  76. is out reg 'ServerAlias toto'
  77. is out reg 'ServerAlias titi'
  78. ##
  79. ## Creds
  80. ##
  81. try "
  82. apache_vhost_statement publish_dir ,http, '' www.example.com
  83. " "credentials allow all"
  84. noerror
  85. is out reg 'Allow from all'
  86. try "
  87. apache_vhost_statement publish_dir ,http, '
  88. creds:
  89. toto: xxx
  90. titi: yyy
  91. ' www.example.com
  92. " "credentials with basic auth user/pass"
  93. noerror
  94. is out reg 'AuthType basic'
  95. is out reg 'Require valid-user'
  96. ##
  97. ## proxy
  98. ##
  99. try "
  100. apache_vhost_statement web_proxy ,http, '
  101. target: popo:3333
  102. creds:
  103. toto: titi
  104. ' www.example.com
  105. " "proxy explicit target"
  106. noerror
  107. is out reg 'ProxyPass / http://popo:3333/'
  108. is out part '
  109. <Location / >
  110. AuthType basic
  111. AuthName "private"
  112. AuthUserFile /etc/apache2/sites-enabled/www.example.com.passwd
  113. Require valid-user
  114. ProxyPassReverse /
  115. </Location>
  116. '
  117. ##
  118. ## ssl
  119. ##
  120. try "
  121. apache_vhost_statement web_proxy ,https, '
  122. ssl: true
  123. target: popo:3333
  124. ' www.example.com
  125. " "ssl default generation (ssl-cert-snakeoil)"
  126. noerror
  127. is out reg 'VirtualHost \*:443'
  128. is out reg '<IfModule mod_ssl.c>'
  129. is out reg 'SSLEngine On'
  130. is out reg 'SSLProxyEngine On'
  131. is out reg 'ssl-cert-snakeoil'
  132. is out reg 'CustomLog /var/log/apache2/s-www.example.com_access.log combined'
  133. try "
  134. RELATIONS=()
  135. apache_vhost_statement web_proxy ,https, '
  136. ssl:
  137. ca-cert: a
  138. key: b
  139. cert: c
  140. target: popo:3333
  141. ' www.example.com
  142. " "ssl providing keys inline"
  143. noerror
  144. is out reg 'SSLCertificateFile /etc/ssl/certs/www.example.com.pem'
  145. is out reg 'SSLCertificateKeyFile /etc/ssl/private/www.example.com.key'
  146. is out reg 'SSLCACertificateFile /etc/ssl/certs/www.example.com-ca.pem'
  147. ##
  148. ## CustomRules
  149. ##
  150. try "
  151. apache_vhost_statement web_proxy ,https, '
  152. ssl:
  153. ca-cert: a
  154. key: b
  155. cert: c
  156. apache-custom-rules: |
  157. RewriteEngine On
  158. RewriteCond %{QUERY_STRING} !skin=formanoo
  159. RewriteRule ^(/web/webclient/home.*)$ $1?skin=formanoo [L,QSA,R=302]
  160. target: popo:3333
  161. ' www.example.com
  162. " "custom rules"
  163. noerror
  164. is out reg 'RewriteEngine On'
  165. ##
  166. ## double def
  167. ##
  168. try "
  169. apache_vhost_statement web_proxy ,https,http, '
  170. ssl:
  171. ca-cert: a
  172. key: b
  173. cert: c
  174. apache-custom-rules: |
  175. RewriteEngine On
  176. RewriteCond %{QUERY_STRING} !skin=formanoo
  177. RewriteRule ^(/web/webclient/home.*)$ $1?skin=formanoo [L,QSA,R=302]
  178. target: popo:3333
  179. ' www.example.com
  180. " "both http and https"
  181. noerror
  182. is out '<VirtualHost *:80>
  183. ServerAdmin contact@www.example.com
  184. ServerName www.example.com
  185. ServerSignature Off
  186. CustomLog /var/log/apache2/www.example.com_access.log combined
  187. ErrorLog /var/log/apache2/www.example.com_error.log
  188. ErrorLog syslog:local2
  189. ##
  190. ## Custom rules
  191. ##
  192. RewriteEngine On
  193. RewriteCond %{QUERY_STRING} !skin=formanoo
  194. RewriteRule ^(/web/webclient/home.*)$ ?skin=formanoo [L,QSA,R=302]
  195. ##
  196. ## Proxy declaration towards popo:3333
  197. ##
  198. <IfModule mod_proxy.c>
  199. ProxyRequests Off
  200. <Proxy *>
  201. Order deny,allow
  202. Allow from all
  203. </Proxy>
  204. ProxyVia On
  205. ProxyPass / http://popo:3333/ retry=0
  206. <Location / >
  207. Allow from all
  208. ProxyPassReverse /
  209. </Location>
  210. </IfModule>
  211. RequestHeader set "X-Forwarded-Proto" "http"
  212. ## Fix IE problem (httpapache proxy dav error 408/409)
  213. SetEnv proxy-nokeepalive 1
  214. ## Forbid any cache, this is only usefull on dev server.
  215. #Header set Cache-Control "no-cache"
  216. #Header set Access-Control-Allow-Origin "*"
  217. #Header set Access-Control-Allow-Methods "POST, GET, OPTIONS"
  218. #Header set Access-Control-Allow-Headers "origin, content-type, accept"
  219. </VirtualHost>
  220. <IfModule mod_ssl.c>
  221. <VirtualHost *:443>
  222. ServerAdmin contact@www.example.com
  223. ServerName www.example.com
  224. ServerSignature Off
  225. CustomLog /var/log/apache2/s-www.example.com_access.log combined
  226. ErrorLog /var/log/apache2/s-www.example.com_error.log
  227. ErrorLog syslog:local2
  228. ##
  229. ## Custom rules
  230. ##
  231. RewriteEngine On
  232. RewriteCond %{QUERY_STRING} !skin=formanoo
  233. RewriteRule ^(/web/webclient/home.*)$ ?skin=formanoo [L,QSA,R=302]
  234. ##
  235. ## Proxy declaration towards popo:3333
  236. ##
  237. <IfModule mod_proxy.c>
  238. ProxyRequests Off
  239. <Proxy *>
  240. Order deny,allow
  241. Allow from all
  242. </Proxy>
  243. ProxyVia On
  244. ProxyPass / http://popo:3333/ retry=0
  245. <Location / >
  246. Allow from all
  247. ProxyPassReverse /
  248. </Location>
  249. SSLProxyEngine On
  250. </IfModule>
  251. RequestHeader set "X-Forwarded-Proto" "https"
  252. ## Fix IE problem (httpapache proxy dav error 408/409)
  253. SetEnv proxy-nokeepalive 1
  254. ## Forbid any cache, this is only usefull on dev server.
  255. #Header set Cache-Control "no-cache"
  256. #Header set Access-Control-Allow-Origin "*"
  257. #Header set Access-Control-Allow-Methods "POST, GET, OPTIONS"
  258. #Header set Access-Control-Allow-Headers "origin, content-type, accept"
  259. ##
  260. ## SSL Configuration
  261. ##
  262. SSLEngine On
  263. SSLCertificateFile /etc/ssl/certs/www.example.com.pem
  264. SSLCertificateKeyFile /etc/ssl/private/www.example.com.key
  265. SSLCACertificateFile /etc/ssl/certs/www.example.com-ca.pem
  266. SSLVerifyClient None
  267. </VirtualHost>
  268. </IfModule>' RTRIM
  269. ##
  270. ## single def no domain
  271. ##
  272. try "
  273. apache_vhost_statement publish_dir ,http, '
  274. apache-custom-rules: |
  275. RewriteEngine On
  276. RewriteCond %{QUERY_STRING} !skin=formanoo
  277. RewriteRule ^(/web/webclient/home.*)$ $1?skin=formanoo [L,QSA,R=302]
  278. target: popo:3333
  279. ' ""
  280. " "http without domain"
  281. noerror
  282. is out '<VirtualHost *:80>
  283. ServerAdmin webmaster@localhost
  284. ServerSignature Off
  285. CustomLog /var/log/apache2/access.log combined
  286. ErrorLog /var/log/apache2/error.log
  287. ErrorLog syslog:local2
  288. ##
  289. ## Custom rules
  290. ##
  291. RewriteEngine On
  292. RewriteCond %{QUERY_STRING} !skin=formanoo
  293. RewriteRule ^(/web/webclient/home.*)$ ?skin=formanoo [L,QSA,R=302]
  294. ##
  295. ## Publish directory /var/www/html
  296. ##
  297. DocumentRoot /var/www/html
  298. <Directory />
  299. Options FollowSymLinks
  300. AllowOverride None
  301. </Directory>
  302. <Directory /var/www/html>
  303. Options Indexes FollowSymLinks MultiViews
  304. AllowOverride all
  305. Allow from all
  306. </Directory>
  307. ## Forbid any cache, this is only usefull on dev server.
  308. #Header set Cache-Control "no-cache"
  309. #Header set Access-Control-Allow-Origin "*"
  310. #Header set Access-Control-Allow-Methods "POST, GET, OPTIONS"
  311. #Header set Access-Control-Allow-Headers "origin, content-type, accept"
  312. </VirtualHost>' RTRIM