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.

129 lines
3.3 KiB

  1. #!/bin/sh /etc/rc.common
  2. # Copyright (C) 2015 OpenWrt.org
  3. START=90
  4. STOP=10
  5. USE_PROCD=1
  6. PROG=/usr/sbin/clamd
  7. CLAMD_CONFIGFILE="/tmp/clamav/clamd.conf"
  8. validate_clamav_section() {
  9. uci_load_validate clamav clamav "$1" "$2" \
  10. 'clamd_config_file:string' \
  11. 'LogFile:string' \
  12. 'LogFileMaxSize:string' \
  13. 'LogVerbose:string' \
  14. 'ExtendedDetectionInfo:string' \
  15. 'LogTime:string' \
  16. 'OfficialDatabaseOnly:string' \
  17. 'StreamMinPort:uinteger' \
  18. 'StreamMaxPort:uinteger' \
  19. 'MaxThreads:uinteger' \
  20. 'ReadTimeout:uinteger' \
  21. 'CommandReadTimeout:uinteger' \
  22. 'MaxDirectoryRecursion:uinteger' \
  23. 'FollowDirectorySymlinks:string' \
  24. 'FollowFileSymlinks:string' \
  25. 'SelfCheck:uinteger' \
  26. 'DetectPUA:string' \
  27. 'ScanPE:string' \
  28. 'DisableCertCheck:string' \
  29. 'ScanELF:string' \
  30. 'AlertBrokenExecutables:string' \
  31. 'ScanOLE2:string' \
  32. 'ScanPDF:string' \
  33. 'ScanSWF:string' \
  34. 'ScanMail:string' \
  35. 'ScanPartialMessages:string' \
  36. 'ScanArchive:string' \
  37. 'TemporaryDirectory:string' \
  38. 'AlertEncrypted:string' \
  39. 'MaxFileSize:string' \
  40. 'LocalSocket:string' \
  41. 'TCPSocket:port' \
  42. 'TCPAddr:ipaddr' \
  43. 'User:string' \
  44. 'ExitOnOOM:string' \
  45. 'DatabaseDirectory:string'
  46. }
  47. start_clamav_instance() {
  48. [ "$2" = 0 ] || {
  49. echo "validation failed"
  50. return 1
  51. }
  52. mkdir -p "$DatabaseDirectory"
  53. mkdir -p /etc/clamav/
  54. mkdir -p /var/run/clamav/
  55. chmod a+rw /var/run/clamav
  56. mkdir -p "$(dirname $CLAMD_CONFIGFILE)"
  57. ln -sf "$clamd_config_file" "$CLAMD_CONFIGFILE"
  58. {
  59. echo "LogFile " "$LogFile"
  60. echo "LogFileMaxSize " "$LogFileMaxSize"
  61. echo "LogVerbose " "$LogVerbose"
  62. echo "ExtendedDetectionInfo " "$ExtendedDetectionInfo"
  63. echo "LogTime " "$LogTime"
  64. echo "OfficialDatabaseOnly " "$OfficialDatabaseOnly"
  65. echo "StreamMinPort " "$StreamMinPort"
  66. echo "StreamMaxPort " "$StreamMaxPort"
  67. echo "MaxThreads " "$MaxThreads"
  68. echo "ReadTimeout " "$ReadTimeout"
  69. echo "CommandReadTimeout " "$CommandReadTimeout"
  70. echo "MaxDirectoryRecursion " "$MaxDirectoryRecursion"
  71. echo "FollowDirectorySymlinks " "$FollowDirectorySymlinks"
  72. echo "FollowFileSymlinks " "$FollowFileSymlinks"
  73. echo "SelfCheck " "$SelfCheck"
  74. echo "DetectPUA " "$DetectPUA"
  75. echo "ScanPE " "$ScanPE"
  76. echo "DisableCertCheck " "$DisableCertCheck"
  77. echo "ScanELF " "$ScanELF"
  78. echo "AlertBrokenExecutables " "$AlertBrokenExecutables"
  79. echo "ScanOLE2 " "$ScanOLE2"
  80. echo "ScanPDF " "$ScanPDF"
  81. echo "ScanSWF " "$ScanSWF"
  82. echo "ScanMail " "$ScanMail"
  83. echo "ScanPartialMessages " "$ScanPartialMessages"
  84. echo "ScanArchive " "$ScanArchive"
  85. echo "TemporaryDirectory " "$TemporaryDirectory"
  86. echo "AlertEncrypted " "$AlertEncrypted"
  87. echo "MaxFileSize " "$MaxFileSize"
  88. echo "User " "$User"
  89. echo "ExitOnOOM " "$ExitOnOOM"
  90. echo "DatabaseDirectory " "$DatabaseDirectory"
  91. } > "$CLAMD_CONFIGFILE"
  92. if [ -n "$LocalSocket" ]; then
  93. echo "LocalSocket " "$LocalSocket" >>"$CLAMD_CONFIGFILE"
  94. fi
  95. if [ -n "$TCPSocket" ]; then
  96. echo "TCPAddr" "$TCPAddr" >>"$CLAMD_CONFIGFILE"
  97. echo "TCPSocket " "$TCPSocket" >>"$CLAMD_CONFIGFILE"
  98. fi
  99. procd_open_instance
  100. procd_set_param command $PROG -c $CLAMD_CONFIGFILE
  101. procd_set_param file $CLAMD_CONFIGFILE
  102. procd_close_instance
  103. }
  104. start_service()
  105. {
  106. validate_clamav_section clamav start_clamav_instance
  107. }
  108. stop_service()
  109. {
  110. service_stop $PROG
  111. }
  112. service_triggers()
  113. {
  114. procd_add_reload_trigger "clamav"
  115. procd_add_validation validate_clamav_section
  116. }