Sends data via the HTTP POST method using raw sockets, alternatively you could import and use the HTTP package which is already loaded on cisco routers, tmpsys:/lib/tcl/http.tcl.
Is an alternate method to the sending of an email to alert/update someone.


  1. # httpPost.tcl -- Send data over HTTP via post to a PHP file.
  2. # Copyright (C) 2009 Nigel Franklin, www.nigelfranklin.co.uk
  3. #
  4. # This program is free software: you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License as published by
  6. # the Free Software Foundation, either version 3 of the License,
  7. # or any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public License
  15. # along with this program. If not, see http://www.gnu.org/licenses/.
  16. #
  17. #
  18. #
  19. #
  20. # Revision # : 1.0
  21. # Last Revised : May 29, 2009
  22. # Last Revised by : Nigel Franklin
  23. # Author : Nigel Franklin, www.nigelfranklin.co.uk
  24. #
  25. #
  26.  
  27. package provide httpPost 1.0
  28. package require Tcl 8.3
  29. package require urlString 1.0
  30.  
  31. namespace eval ::httpPost:: {
  32. namespace export post
  33. }
  34.  
  35. proc ::httpPost::post {data scriptName} {
  36. set destinationFile "/ciscoPost/HTTPPOSTtoFile-53d384sle.php"
  37. set destinationHost 87.248.221.254
  38. set accessString "3kjsd93d4325"
  39. set routerName [info hostname]
  40. set data [urlencode $data]
  41. set accessString [urlencode $accessString]
  42. set routerName [urlencode $routerName]
  43. set scriptName [urlencode $scriptName]
  44. set time_sent [urlencode [clock seconds]]
  45. set post "accessString=$accessString&timeSent=$time_sent\
  46. &router=$routerName&script=$scriptName&data=$data"
  47. set dataLen [string length $post]
  48. if {[catch {set sock [socket $host 80]} fid] } {
  49. # ---- Catch Error for unable to open socket and write to syslog
  50. set temp "Unable to open socket to $destinationHost"
  51. lappend errorList $temp
  52. return $errorList
  53. } else {
  54. fconfigure $sock -blocking 1 -buffering line -buffersize [expr {$dataLen*2}]
  55. #puts -nonewline "Hello, "
  56. #puts "World!"
  57. puts $sock "POST $destinationFile HTTP/1.0\nUser-Agent: Tcl/Tk Http_Open\n\
  58. Host: $destinationHost\nContent-Length: $dataLen\n\
  59. Content-Type: application/x-www-form-urlencoded\n\n$post"
  60. flush $sock
  61. close $sock
  62. }
  63. }