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.

101 lines
3.0 KiB

  1. #!/bin/sh
  2. yggConfig="/etc/yggdrasil.conf"
  3. first_boot_genConfig()
  4. {
  5. . /usr/share/libubox/jshn.sh
  6. boardcfg=$(ubus call system board)
  7. yggcfg=$(yggdrasil -genconf -json | grep NodeInfo -v)
  8. json_load "$boardcfg"
  9. json_get_var kernel kernel
  10. json_get_var hostname hostname
  11. json_get_var system system
  12. json_get_var model model
  13. json_get_var board_name board_name
  14. json_load "$yggcfg"
  15. json_add_string "IfName" "ygg0"
  16. json_add_object "NodeInfo"
  17. json_add_string "kernel" "$kernel"
  18. json_add_string "hostname" "$hostname"
  19. json_add_string "system" "$system"
  20. json_add_string "model" "$model"
  21. json_add_string "board_name" "$board_name"
  22. json_close_object
  23. json_dump
  24. }
  25. if [ ! -e ${yggConfig} ]; then
  26. echo "first_boot: adding system board details to NodeInfo[] in NEW config: ${yggConfig}" | logger -t yggdrasil
  27. first_boot_genConfig > ${yggConfig}
  28. # create the network interface
  29. uci -q batch <<-EOF >/dev/null
  30. set network.yggdrasil=interface
  31. set network.yggdrasil.ifname=ygg0
  32. set network.yggdrasil.proto=none
  33. EOF
  34. # create the firewall zone
  35. uci -q batch <<-EOF >/dev/null
  36. add firewall zone
  37. set firewall.@zone[-1].name=yggdrasil
  38. add_list firewall.@zone[-1].network=yggdrasil
  39. set firewall.@zone[-1].input=REJECT
  40. set firewall.@zone[-1].output=ACCEPT
  41. set firewall.@zone[-1].forward=REJECT
  42. set firewall.@zone[-1].conntrack=1
  43. set firewall.@zone[-1].family=ipv6
  44. EOF
  45. # allow ICMP from yggdrasil zone, e.g. ping6
  46. uci -q batch <<-EOF >/dev/null
  47. add firewall rule
  48. set firewall.@rule[-1].name='Allow-ICMPv6-yggdrasil'
  49. set firewall.@rule[-1].src=yggdrasil
  50. set firewall.@rule[-1].proto=icmp
  51. add_list firewall.@rule[-1].icmp_type=echo-request
  52. add_list firewall.@rule[-1].icmp_type=echo-reply
  53. add_list firewall.@rule[-1].icmp_type=destination-unreachable
  54. add_list firewall.@rule[-1].icmp_type=packet-too-big
  55. add_list firewall.@rule[-1].icmp_type=time-exceeded
  56. add_list firewall.@rule[-1].icmp_type=bad-header
  57. add_list firewall.@rule[-1].icmp_type=unknown-header-type
  58. set firewall.@rule[-1].limit='1000/sec'
  59. set firewall.@rule[-1].family=ipv6
  60. set firewall.@rule[-1].target=ACCEPT
  61. EOF
  62. # allow SSH from yggdrasil zone, needs to be explicitly enabled
  63. uci -q batch <<-EOF >/dev/null
  64. add firewall rule
  65. set firewall.@rule[-1].enabled=0
  66. set firewall.@rule[-1].name='Allow-SSH-yggdrasil'
  67. set firewall.@rule[-1].src=yggdrasil
  68. set firewall.@rule[-1].proto=tcp
  69. set firewall.@rule[-1].dest_port=22
  70. set firewall.@rule[-1].target=ACCEPT
  71. EOF
  72. # allow LuCI access from yggdrasil zone, needs to be explicitly enabled
  73. uci -q batch <<-EOF >/dev/null
  74. add firewall rule
  75. set firewall.@rule[-1].enabled=0
  76. set firewall.@rule[-1].name='Allow-HTTP-yggdrasil'
  77. set firewall.@rule[-1].src=yggdrasil
  78. set firewall.@rule[-1].proto=tcp
  79. set firewall.@rule[-1].dest_port=80
  80. set firewall.@rule[-1].target=ACCEPT
  81. EOF
  82. uci commit firewall
  83. uci commit network
  84. else
  85. :
  86. fi
  87. exit 0