validate_config.awk 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. # AWK file for validating uci specification files
  2. #
  3. # Copyright (C) 2006 by Fokus Fraunhofer <[email protected]>
  4. #
  5. # This program is free software; you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License as published by
  7. # the Free Software Foundation; either version 2 of the License, or
  8. # (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. # General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program; if not, write to the Free Software
  17. # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  18. #
  19. function is_int(value) {
  20. valid = 1
  21. if (value !~ /^[0-9]*$/) { valid = 0 }
  22. return valid
  23. }
  24. function is_netmask(value) {
  25. return is_ip(value)
  26. }
  27. function is_ip(value) {
  28. valid = 1
  29. if ((value != "") && (value !~ /^[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*$/)) valid = 0
  30. else {
  31. split(value, ipaddr, "\\.")
  32. for (i = 1; i <= 4; i++) {
  33. if ((ipaddr[i] < 0) || (ipaddr[i] > 255)) valid = 0
  34. }
  35. }
  36. return valid
  37. }
  38. function is_wep(value) {
  39. valid = 1
  40. if (value !~ /^[0-9A-Fa-f]*$/) {
  41. valid = 0
  42. } else if ((length(value) != 0) && (length(value) != 10) && (length(value) != 26)) {
  43. valid = 0
  44. } else if (value ~ /0$/) {
  45. valid = 0
  46. }
  47. return valid
  48. }
  49. function is_hostname(value) {
  50. valid = 1
  51. if (value !~ /^[0-9a-zA-z\.\-]*$/) {
  52. valid = 0
  53. }
  54. return valid;
  55. }
  56. function is_string(value) {
  57. return 1;
  58. }
  59. function is_mac(value) {
  60. valid = 1
  61. if ((value != "") && (value !~ /^[0-9a-fA-F][0-9a-fA-F]:[0-9a-fA-F][0-9a-fA-F]:[0-9a-fA-F][0-9a-fA-F]:[0-9a-fA-F][0-9a-fA-F]:[0-9a-fA-F][0-9a-fA-F]:[0-9a-fA-F][0-9a-fA-F]$/)) {
  62. valid = 0
  63. }
  64. return valid
  65. }
  66. function is_port(value) {
  67. valid = 1
  68. if (value !~ /^[0-9]*$/) {
  69. valid = 0
  70. }
  71. return valid
  72. }
  73. function is_ports(value) {
  74. valid = 1
  75. n = split(value ",", ports, ",")
  76. for (i = 1; i <= n; i++) {
  77. if ((ports[i] !~ /^[0-9]*$/) && (ports[i] !~ /^[0-9][0-9]*-[0-9][0-9]*$/)) {
  78. valid = 0
  79. }
  80. }
  81. return valid
  82. }
  83. function is_wpapsk(value) {
  84. valid = 1
  85. if (length(value) > 64) {
  86. valid = 0
  87. }
  88. if ((length(value) != 0) && (length(value) < 8)) {
  89. valid = 0
  90. }
  91. if ((length(value) == 64) && (value ~ /[^0-9a-fA-F]/)) {
  92. valid = 0
  93. }
  94. return valid
  95. }