wwwfault.tcl 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. #!/usr/local/bin/wish
  2. #package require -exact Tk $tcl_version
  3. package require Tk 8.4
  4. puts ""
  5. puts ""
  6. puts "---------------------------------------"
  7. puts "Released under GPLv3.0"
  8. puts "Copyrights © 2022-2026 Daniele Bonini"
  9. puts "This software is supplied AS-IS, without WARRENTY."
  10. puts "Welcome in WWWFAULT!!"
  11. puts "---------------------------------------"
  12. puts ""
  13. puts ""
  14. cd ~/util/bin
  15. # Variable and Proc declarations
  16. variable urlfile
  17. array set cmdslbl {}
  18. array set cmds {}
  19. proc scanUrls {} {
  20. global filename
  21. global cmdslbl
  22. global cmds
  23. # Resetting arrays and listbox
  24. if {[array size cmdslbl] > 0} {
  25. array set cmdslbl {}
  26. }
  27. if {[array size cmds] > 0} {
  28. array set cmds {}
  29. }
  30. if {[.fr.lb size] > 0} {
  31. .fr.lb delete 0 [ .fr.lb size ]
  32. }
  33. if {$filename == ""} {
  34. return
  35. }
  36. if { [file exists $filename] == 0 } {
  37. .fr.lb insert end "No url to scan."
  38. tk_messageBox -message "No url to scan."
  39. return
  40. }
  41. # Reading url list
  42. set fh [open $filename "r"]
  43. set intli 0
  44. set li 0
  45. while {[gets $fh str] >= 0} {
  46. if {"[string range $str 0 0]" == "\#"} {
  47. continue
  48. }
  49. set str [string trim $str]
  50. set cmdpath [pwd]/urlchecker.sh
  51. set newurl $str
  52. set cmds($intli) $cmdpath
  53. set cmdres [exec $cmds($intli) $newurl]
  54. if {[string range $cmdres 0 1] == "0"} {
  55. set cmdslbl($intli) "$newurl failed"
  56. } else {
  57. set cmdslbl($intli) "$newurl valid"
  58. }
  59. .fr.lb insert 0 $cmdslbl($intli)
  60. incr intli
  61. update
  62. }
  63. close $fh
  64. }
  65. proc shutdown {} {
  66. # perform necessary housework for ensuring that application files
  67. # are in proper state, lock files are removed, etc.
  68. puts stdout "Good Bye, from WWWFAULT.."
  69. exit
  70. }
  71. # Main Frame
  72. frame .fr
  73. pack .fr -fill both -expand 1
  74. set today [clock seconds]
  75. set filename "~/urls/urls.txt"
  76. entry .fr.txt -width 65 -textvariable filename
  77. button .fr.bscan -height 1 -text "Scan Urls" -command { scanUrls }
  78. listbox .fr.lb -yscrollcommand { .fr.sb set }
  79. place .fr.lb -height 120
  80. scrollbar .fr.sb -command {.fr.lb yview} -orient vertical
  81. #ListBox
  82. bind .fr.lb <<ListboxSelect>>
  83. # Close Button
  84. button .fr.bclose -text "Exit" -command { shutdown }
  85. grid .fr.bclose -sticky sw -ipadx 20 -padx 0 -pady 40
  86. # Set frame and controls position
  87. grid configure .fr -row 0 -rowspan 6 -column 0 -columnspan 4
  88. grid configure .fr.txt -column 1 -columnspan 2 -row 0 -rowspan 1
  89. grid configure .fr.bscan -column 2 -columnspan 1 -row 0 -rowspan 1
  90. grid configure .fr.lb -column 1 -columnspan 2 -row 1 -rowspan 1
  91. grid configure .fr.sb -column 2 -columnspan 1 -row 1 -rowspan 1
  92. grid configure .fr.bclose -column 1 -columnspan 2 -row 5 -rowspan 1
  93. grid .fr.txt -sticky w
  94. grid .fr.txt -ipadx 20 -pady 10 -ipady 5
  95. grid .fr.bscan -sticky e
  96. grid .fr.lb -sticky nsew
  97. place .fr.sb -width 5
  98. grid .fr.sb -sticky nes
  99. grid .fr.lb -ipadx 20 -pady 20 -columnspan 2
  100. grid .fr.sb -ipadx 5 -padx 1 -pady 20
  101. grid .fr.bclose -sticky sw -ipadx 20 -padx 0 -pady 40
  102. grid .fr -sticky w -padx 20
  103. # Window
  104. wm title . "wwwfault: your url validator"
  105. image create photo imgobj -file wwwfault.png
  106. wm iconphoto . imgobj
  107. wm resizable . 0 0
  108. wm attributes . -fullscreen 0
  109. wm geometry . 600x380
  110. wm protocol . WM_DELETE_WINDOW { shutdown }