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.

119 lines
3.1 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. 'User:string' \
  42. 'ExitOnOOM:string' \
  43. 'DatabaseDirectory:string'
  44. }
  45. start_clamav_instance() {
  46. [ "$2" = 0 ] || {
  47. echo "validation failed"
  48. return 1
  49. }
  50. mkdir -p "$DatabaseDirectory"
  51. mkdir -p /etc/clamav/
  52. mkdir -p /var/run/clamav/
  53. chmod a+rw /var/run/clamav
  54. mkdir -p "$(dirname $CLAMD_CONFIGFILE)"
  55. ln -sf "$clamd_config_file" "$CLAMD_CONFIGFILE"
  56. {
  57. echo "LogFile " "$LogFile"
  58. echo "LogFileMaxSize " "$LogFileMaxSize"
  59. echo "LogVerbose " "$LogVerbose"
  60. echo "ExtendedDetectionInfo " "$ExtendedDetectionInfo"
  61. echo "LogTime " "$LogTime"
  62. echo "OfficialDatabaseOnly " "$OfficialDatabaseOnly"
  63. echo "StreamMinPort " "$StreamMinPort"
  64. echo "StreamMaxPort " "$StreamMaxPort"
  65. echo "MaxThreads " "$MaxThreads"
  66. echo "ReadTimeout " "$ReadTimeout"
  67. echo "CommandReadTimeout " "$CommandReadTimeout"
  68. echo "MaxDirectoryRecursion " "$MaxDirectoryRecursion"
  69. echo "FollowDirectorySymlinks " "$FollowDirectorySymlinks"
  70. echo "FollowFileSymlinks " "$FollowFileSymlinks"
  71. echo "SelfCheck " "$SelfCheck"
  72. echo "DetectPUA " "$DetectPUA"
  73. echo "ScanPE " "$ScanPE"
  74. echo "DisableCertCheck " "$DisableCertCheck"
  75. echo "ScanELF " "$ScanELF"
  76. echo "AlertBrokenExecutables " "$AlertBrokenExecutables"
  77. echo "ScanOLE2 " "$ScanOLE2"
  78. echo "ScanPDF " "$ScanPDF"
  79. echo "ScanSWF " "$ScanSWF"
  80. echo "ScanMail " "$ScanMail"
  81. echo "ScanPartialMessages " "$ScanPartialMessages"
  82. echo "ScanArchive " "$ScanArchive"
  83. echo "TemporaryDirectory " "$TemporaryDirectory"
  84. echo "AlertEncrypted " "$AlertEncrypted"
  85. echo "MaxFileSize " "$MaxFileSize"
  86. echo "LocalSocket " "$LocalSocket"
  87. echo "User " "$User"
  88. echo "ExitOnOOM " "$ExitOnOOM"
  89. echo "DatabaseDirectory " "$DatabaseDirectory"
  90. } > "$CLAMD_CONFIGFILE"
  91. procd_open_instance
  92. procd_set_param command $PROG -c $CLAMD_CONFIGFILE
  93. procd_set_param file $CLAMD_CONFIGFILE
  94. procd_close_instance
  95. }
  96. start_service()
  97. {
  98. validate_clamav_section clamav start_clamav_instance
  99. }
  100. stop_service()
  101. {
  102. service_stop $PROG
  103. }
  104. service_triggers()
  105. {
  106. procd_add_reload_trigger "clamav"
  107. procd_add_validation validate_clamav_section
  108. }