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.

137 lines
3.3 KiB

  1. #!/bin/sh /etc/rc.common
  2. START=82
  3. USE_PROCD=1
  4. ETEBASE_INI="/var/etc/etebase/server.ini"
  5. etebase_print_uci_allow_all_ips_of() {
  6. local ifstat="$(ifstatus "$1")"
  7. for ip in $(echo "${ifstat}" | jsonfilter -e '@["ipv4-address"].*.address')
  8. do echo "allowed_host_${ip//[^0-9]/_} = ${ip}"
  9. done
  10. for ip in $(echo "${ifstat}" | jsonfilter -e '@["ipv6-address"].*.address')
  11. do echo "allowed_host_${ip//[^0-9A-Fa-f]/_} = [${ip}]"
  12. done
  13. for ip in $(echo "${ifstat}" | \
  14. jsonfilter -e '@["ipv6-prefix-assignment"].*["local-address"].address')
  15. do echo "allowed_host_${ip//[^0-9A-Fa-f]/_} = [${ip}]"
  16. done
  17. }
  18. etebase_validate_global() {
  19. cd /usr/share/etebase/ >/dev/null || return
  20. uci_load_validate etebase django "global" "$1" \
  21. 'secret_file:file:secret.txt' \
  22. 'static_url:string:static/' \
  23. 'language_code:string:en-us' \
  24. 'time_zone:string:UTC' \
  25. 'debug:bool:false' \
  26. ;
  27. }
  28. etebase_print_global() {
  29. printf "\n[global]\n"
  30. echo "secret_file = ${secret_file}"
  31. echo "static_root = /www/etebase/static" #sic!
  32. echo "static_url = ${static_url}"
  33. echo "language_code = ${language_code}"
  34. echo "time_zone = ${time_zone}"
  35. echo "debug = ${debug}"
  36. }
  37. etebase_validate_allowed_hosts() {
  38. cd /usr/share/etebase/ >/dev/null || return
  39. uci_load_validate etebase django "allowed_hosts" "$1" \
  40. 'uci_allow_all_ips_of:network' \
  41. 'allowed_host:host' \
  42. ;
  43. }
  44. etebase_print_allowed_hosts() {
  45. printf "\n[allowed_hosts]\n"
  46. local iface
  47. for iface in ${uci_allow_all_ips_of}
  48. do etebase_print_uci_allow_all_ips_of "${iface}"
  49. done
  50. local host
  51. for host in ${allowed_host}
  52. do echo "allowed_host_${host//[^0-9A-Za-z]/_} = ${host}"
  53. done
  54. }
  55. etebase_validate_database() {
  56. cd /usr/share/etebase/ >/dev/null || return
  57. uci_load_validate etebase django "database" "$1" \
  58. 'engine:hostname:django.db.backends.sqlite3' \
  59. 'name:file:db.sqlite3' \
  60. ;
  61. }
  62. etebase_print_database() {
  63. printf "\n[database]\n"
  64. echo "engine = ${engine}"
  65. echo "name = ${name}"
  66. }
  67. etebase_init() { # This must print ONLY configuration lines:
  68. echo "; This file is re-created from /etc/config/etebase "
  69. etebase_validate_global etebase_print_global
  70. etebase_validate_allowed_hosts etebase_print_allowed_hosts
  71. etebase_validate_database etebase_print_database
  72. } >"${ETEBASE_INI}"
  73. start_service() {
  74. mkdir -p /var/etc/etebase/
  75. etebase_init
  76. logger -p 'daemon.info' -t 'etebase_init' 'starting ...'
  77. ln -sf /etc/uwsgi/vassals/etebase.available /var/etc/etebase/uwsgi.ini
  78. }
  79. stop_service() {
  80. rm -f /var/etc/etebase/uwsgi.ini "${ETEBASE_INI}"
  81. }
  82. reload_service() {
  83. etebase_init
  84. logger -p 'daemon.info' -t 'etebase_init' 'reloading ...'
  85. kill -SIGHUP "$(cat "/var/etc/etebase/master.pid")" 2>/dev/null
  86. #if the server is in on-demand mode, the ini files are reloaded then, too.
  87. }
  88. service_triggers() {
  89. procd_open_validate
  90. etebase_validate_global "$@"
  91. etebase_validate_allowed_hosts "$@"
  92. etebase_validate_database "$@"
  93. procd_close_validate
  94. config_load etebase
  95. config_list_foreach "allowed_hosts" "uci_allow_all_ips_of" procd_add_reload_interface_trigger
  96. procd_add_reload_trigger etebase
  97. }