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.
- # httpPost.tcl -- Send data over HTTP via post to a PHP file.
- # Copyright (C) 2009 Nigel Franklin, www.nigelfranklin.co.uk
- #
- # This program is free software: you can redistribute it and/or modify
- # it under the terms of the GNU General Public License as published by
- # the Free Software Foundation, either version 3 of the License,
- # or any later version.
- #
- # This program is distributed in the hope that it will be useful,
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- # GNU General Public License for more details.
- #
- # You should have received a copy of the GNU General Public License
- # along with this program. If not, see http://www.gnu.org/licenses/.
- #
- #
- #
- #
- # Revision # : 1.0
- # Last Revised : May 29, 2009
- # Last Revised by : Nigel Franklin
- # Author : Nigel Franklin, www.nigelfranklin.co.uk
- #
- #
-
- package provide httpPost 1.0
- package require Tcl 8.3
- package require urlString 1.0
-
- namespace eval ::httpPost:: {
- namespace export post
- }
-
- proc ::httpPost::post {data scriptName} {
- set destinationFile "/ciscoPost/HTTPPOSTtoFile-53d384sle.php"
- set destinationHost 87.248.221.254
- set accessString "3kjsd93d4325"
- set routerName [info hostname]
-
- set data [urlencode $data]
- set accessString [urlencode $accessString]
- set routerName [urlencode $routerName]
- set scriptName [urlencode $scriptName]
- set time_sent [urlencode [clock seconds]]
-
- set post "accessString=$accessString&timeSent=$time_sent\
- &router=$routerName&script=$scriptName&data=$data"
- set dataLen [string length $post]
-
- if {[catch {set sock [socket $host 80]} fid] } {
- # ---- Catch Error for unable to open socket and write to syslog
- set temp "Unable to open socket to $destinationHost"
- lappend errorList $temp
- return $errorList
- } else {
- fconfigure $sock -blocking 1 -buffering line -buffersize [expr {$dataLen*2}]
- #puts -nonewline "Hello, "
- #puts "World!"
- puts $sock "POST $destinationFile HTTP/1.0\nUser-Agent: Tcl/Tk Http_Open\n\
- Host: $destinationHost\nContent-Length: $dataLen\n\
- Content-Type: application/x-www-form-urlencoded\n\n$post"
- flush $sock
- close $sock
- }
- }