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.

136 lines
3.4 KiB

  1. #!/bin/sh /etc/rc.common
  2. START=82
  3. USE_PROCD=1
  4. ETESYNC_INI="/var/etc/etesync-server/etesync-server.ini"
  5. etesync_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. etesync_validate_global() {
  19. cd /usr/share/etesync-server/ >/dev/null || return
  20. uci_load_validate etesync_server django "global" "$1" \
  21. 'secret_file:file:secret.txt' \
  22. 'static_url:string:/etesync/static' \
  23. 'language_code:string:en-us' \
  24. 'time_zone:string:UTC' \
  25. 'debug:bool:false' \
  26. ;
  27. }
  28. etesync_print_global() {
  29. printf "\n[global]\n"
  30. echo "secret_file = ${secret_file}"
  31. echo "static_root = /www/etesync/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. etesync_validate_allowed_hosts() {
  38. uci_load_validate etesync_server django "allowed_hosts" "$1" \
  39. 'uci_allow_all_ips_of:network' \
  40. 'allowed_host:host' \
  41. ;
  42. }
  43. etesync_print_allowed_hosts() {
  44. printf "\n[allowed_hosts]\n"
  45. local iface
  46. for iface in ${uci_allow_all_ips_of}
  47. do etesync_print_uci_allow_all_ips_of "${iface}"
  48. done
  49. local host
  50. for host in ${allowed_host}
  51. do echo "allowed_host_${host//[^0-9A-Za-z]/_} = ${host}"
  52. done
  53. }
  54. etesync_validate_database() {
  55. cd /usr/share/etesync-server/ >/dev/null || return
  56. uci_load_validate etesync_server django "database" "$1" \
  57. 'engine:hostname:django.db.backends.sqlite3' \
  58. 'name:file:db.sqlite3' \
  59. ;
  60. }
  61. etesync_print_database() {
  62. printf "\n[database]\n"
  63. echo "engine = ${engine}"
  64. echo "name = ${name}"
  65. }
  66. etesync_init() { # This must print ONLY configuration lines:
  67. echo "; This file is re-created from /etc/config/etesync_server "
  68. etesync_validate_global etesync_print_global
  69. etesync_validate_allowed_hosts etesync_print_allowed_hosts
  70. etesync_validate_database etesync_print_database
  71. } >"${ETESYNC_INI}"
  72. start_service() {
  73. mkdir -p /var/etc/etesync-server/
  74. etesync_init
  75. logger -p 'daemon.info' -t 'etesync-server_init' 'starting ...'
  76. ln -sf /etc/uwsgi/vassals/etesync-server.available \
  77. /var/etc/etesync-server/uwsgi.ini
  78. }
  79. stop_service() {
  80. rm -f /var/etc/etesync-server/uwsgi.ini "${ETESYNC_INI}"
  81. }
  82. reload_service() {
  83. etesync_init
  84. logger -p 'daemon.info' -t 'etesync-server_init' 'reloading ...'
  85. kill -SIGHUP "$(cat "/var/etc/etesync-server/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. etesync_validate_global "$@"
  91. etesync_validate_allowed_hosts "$@"
  92. etesync_validate_database "$@"
  93. procd_close_validate
  94. config_load etesync_server
  95. config_list_foreach "allowed_hosts" "uci_allow_all_ips_of" \
  96. procd_add_reload_interface_trigger
  97. procd_add_reload_trigger etesync_server
  98. }