1
0

radsecproxy.init 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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. }