remove-all-rules.sh 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #!/bin/sh
  2. # Copyright (C) 2016 Desktopd Developers.
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. cd "`dirname "$0"`"
  15. configPath="./config"
  16. [ -f "$configPath" ] || {
  17. printf "No such configuration file: %s\n" "$configPath"
  18. exit 1
  19. }
  20. . "$configPath"
  21. [ "$cloudflareAuthEmail" ] && [ "$cloudflareAuthKey" ] || {
  22. printf "Invalid configuration file: %s\n" "$configPath"
  23. exit 1
  24. }
  25. dataDir="./data"
  26. exitListPath="${dataDir}/exit-list"
  27. exitListCachePath="${dataDir}/exit-list.cache"
  28. whitelistDBDir="${dataDir}/whitelist-db"
  29. version='1.0'
  30. faqURI='https://www.torproject.org/docs/faq-abuse.html.en'
  31. curlUserAgent="Mozilla/5.0 (compatible; ExitWhitelister/${version}; +${faqURI})"
  32. cloudflareEndpointAPI='https://api.cloudflare.com/client/v4'
  33. # Whitelist ID
  34. removeWhitelistById () {
  35. # DELETE
  36. curl \
  37. -A "$curlUserAgent" \
  38. -H "X-Auth-Email: ${cloudflareAuthEmail}" \
  39. -H "X-Auth-Key: ${cloudflareAuthKey}" \
  40. -X DELETE \
  41. "${cloudflareEndpointAPI}/user/firewall/access_rules/rules/${1}"
  42. }
  43. for path in "$whitelistDBDir"/*
  44. do [ -f "$path" ] || continue
  45. id="`cat "$path"`"
  46. [ "$id" ] || continue
  47. echo "Removing the rule for $id (`basename "$path"`)..."
  48. removeWhitelistById "$id" >/dev/null || {
  49. removeWhitelistById "$id"
  50. echo
  51. echo "!!! Failed!"
  52. }
  53. sleep 0.1
  54. done
  55. # vim: set ts=4 noet ai