pagemod.go 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*
  2. GNU GENERAL PUBLIC LICENSE
  3. Version 3, 29 June 2007
  4. Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
  5. Everyone is permitted to copy and distribute verbatim copies
  6. of this license document, but changing it is not allowed.
  7. http-wokou, An HTTP Proxying framework for bypassing DNS Security
  8. Copyright (C) 2024 Russell Hrubesky, ChiralWorks Software LLC
  9. This program is free software: you can redistribute it and/or modify
  10. it under the terms of the GNU General Public License as published by
  11. the Free Software Foundation, either version 3 of the License, or
  12. (at your option) any later version.
  13. This program is distributed in the hope that it will be useful,
  14. but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. GNU General Public License for more details.
  17. You should have received a copy of the GNU General Public License
  18. along with this program. If not, see <https://www.gnu.org/licenses/>.
  19. */
  20. package httpserver
  21. import (
  22. "encoding/json"
  23. "log"
  24. "os"
  25. )
  26. type PageMod struct {
  27. Target string `json:"target"`
  28. Search string `json:"search"`
  29. Sub string `json:"sub"`
  30. }
  31. type AllPageMods struct {
  32. Content []*PageMod `json:"modifications"`
  33. }
  34. /*
  35. Load page modifications from the config/pagemod directory
  36. :param loc: the path to the pagemods directory
  37. */
  38. func LoadPageMods(loc string) *AllPageMods {
  39. b, err := os.ReadFile(loc)
  40. if err != nil {
  41. log.Fatal("Couldnt load the page modification config from: ", loc, ". Error: ", err)
  42. }
  43. var pgMod AllPageMods
  44. err = json.Unmarshal(b, &pgMod)
  45. if err != nil {
  46. log.Fatal("There was an error loading the configuration: ", err)
  47. }
  48. return &pgMod
  49. }