fork 0k-charms
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.

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