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.

142 lines
3.4 KiB

  1. #!/bin/sh /etc/rc.common
  2. # Copyright (C) 2006-2011 OpenWrt.org
  3. START=70
  4. USE_PROCD=1
  5. PROG=/usr/sbin/radsecproxy
  6. CONFFILE=/var/etc/radsecproxy.conf
  7. LIST_SEP="
  8. "
  9. append_params() {
  10. local param
  11. local value
  12. local section="$1"
  13. shift
  14. for param in $*; do
  15. config_get value "$section" "$param"
  16. [ -z "$value" ] && {
  17. param=$(echo $param | tr [A-Z] [a-z])
  18. config_get value "$section" "$param"
  19. }
  20. IFS="$LIST_SEP"
  21. for value in $value; do
  22. [ -n "$value" ] && echo " $param '$value'" >> "$CONFFILE"
  23. done
  24. unset IFS
  25. done
  26. }
  27. append_bools() {
  28. local param
  29. local value
  30. local section="$1"
  31. shift
  32. for param in $*; do
  33. config_get_bool value "$section" "$param"
  34. [ -z "$value" ] && {
  35. param=$(echo $param | tr [A-Z] [a-z])
  36. config_get_bool value "$section" "$param"
  37. }
  38. [ -n "$value" ] && {
  39. [ "$value" -eq 0 ] && echo " $param off" >> "$CONFFILE"
  40. [ "$value" -eq 1 ] && echo " $param on" >> "$CONFFILE"
  41. }
  42. done
  43. }
  44. radsecproxy_options() {
  45. local cfg="$1"
  46. append_params "$cfg" \
  47. Include PidFile LogLevel LogDestination FTicksReporting FTicksMAC FTicksKey \
  48. FTicksSyslogFacility ListenUDP ListenTCP ListenTLS ListenDTLS SourceUDP \
  49. SourceTCP SourceTLS SourceDTLS TTLAttribute AddTTL
  50. append_bools "$cfg" \
  51. LoopPrevention IPv4Only IPv6Only
  52. }
  53. tls_block() {
  54. local cfg="$1"
  55. local name
  56. config_get name "$cfg" name
  57. echo "tls '$name' {" >> "$CONFFILE"
  58. append_params "$cfg" \
  59. Include CACertificateFile CACertificatePath certificateFile certificateKeyFile \
  60. certificateKeyPassword cacheExpiry policyOID
  61. append_bools "$cfg" \
  62. CRLCheck
  63. echo "}" >> "$CONFFILE"
  64. }
  65. rewrite_block() {
  66. local cfg="$1"
  67. local name
  68. config_get name "$cfg" name
  69. echo "rewrite '$name' {" >> "$CONFFILE"
  70. append_params "$cfg" \
  71. Include addAttribute addVendorAttribute removeAttribute removeVendorAttribute \
  72. modifyAttribute
  73. echo "}" >> "$CONFFILE"
  74. }
  75. client_block() {
  76. local cfg="$1"
  77. local name
  78. config_get name "$cfg" name
  79. echo "client '$name' {" >> "$CONFFILE"
  80. append_params "$cfg" \
  81. Include host type secret tls matchCertificateAttribute duplicateInterval \
  82. AddTTL fticksVISCOUNTRY fticksVISINST rewrite rewriteIn rewriteOut \
  83. rewriteAttribute
  84. append_bools "$cfg" \
  85. IPv4Only IPv6Only certificateNameCheck
  86. echo "}" >> "$CONFFILE"
  87. }
  88. server_block() {
  89. local cfg="$1"
  90. local name
  91. config_get name "$cfg" name
  92. echo "server '$name' {" >> "$CONFFILE"
  93. append_params "$cfg" \
  94. Include host port type secret tls matchCertificateAttribute \
  95. AddTTL rewrite rewriteIn rewriteOut retryCount dynamicLookupCommand \
  96. retryInterval
  97. append_bools "$cfg" \
  98. IPv4Only IPv6Only certificateNameCheck statusServer LoopPrevention
  99. echo "}" >> "$CONFFILE"
  100. }
  101. realm_block() {
  102. local cfg="$1"
  103. local name
  104. config_get name "$cfg" name
  105. echo "realm '$name' {" >> "$CONFFILE"
  106. append_params "$cfg" \
  107. Include server accountingServer replyMessage
  108. append_bools "$cfg" \
  109. accountingResponse
  110. echo "}" >> "$CONFFILE"
  111. }
  112. start_service() {
  113. mkdir -p $(dirname $CONFFILE)
  114. echo "# auto-generated config file from /etc/config/radsecproxy" > $CONFFILE
  115. config_load 'radsecproxy'
  116. config_foreach radsecproxy_options options
  117. config_foreach tls_block tls
  118. config_foreach rewrite_block rewrite
  119. config_foreach client_block client
  120. config_foreach server_block server
  121. config_foreach realm_block realm
  122. procd_open_instance
  123. procd_set_param command $PROG -f -c $CONFFILE
  124. procd_set_param file $CONFFILE
  125. procd_set_param respawn
  126. procd_close_instance
  127. }
  128. service_triggers() {
  129. procd_add_reload_trigger 'radsecproxy'
  130. }