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.

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