Wednesday, 30 July 2014

Customize web page on Cisco router using TCL

The aim of the article is to help you customize a web page that runs on Cisco router. Please download the package from this link. And upload each file onto flash disk of your router.
https://drive.google.com/file/d/0B5tzzJsbkWkIQ19SeG9vSExmT0U/edit?usp=sharing
We will use the basic template that downloaded from cisco beyond website. Also, with the help of EEM, setup and run the website coded by TCL.
Turn off http server functions first, and then set the configurations below:
Router#configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#no ip http server
Router(config)#event manager directory user policy “flash:/”
Router(config)#event manager policy http_server.tcl
Router(config)#end
Router#event manager run http_server.tcl
Open browser, type the ip address of the router:
It will trigger the “http_server.tcl” , let’t see that’s inside:
 if {$filename == ""} {set filename "index.html"}
if we didn’t specify path, it will redirect us to “index.html”, let’s have a look this file:
<script type="text/javascript">
document.location = "chap4e3.tcl";
</script>

By using the script file : chap4e3.tcl, in this file we run ”show clock ” and have user input whatever cisco command they want in the form, and give the value to “runcli.tcl” file to display results:


design a background script to display the results given by cli command:

ipsla.tcl:

set ipaddr [lindex $parmlist 1]
if {[catch {cli_open} output]} {
    error $output $errorInfo
    } else {
            array set cli_fd $output
    }
if {[catch {cli_exec $cli_fd(fd) "enable"} output]} {
    error $output $errorInfo
    }
if {[catch {cli_exec $cli_fd(fd) "show ip sla monitor statistics"} ipslashowcmd]} {
    error $ipslashowcmd $errorInfo
    }
if {[catch {cli_close $cli_fd(fd) $cli_fd(tty_id)} output]} {
    error $output $errorInfo
    }
   
set ipslaoutput [string map {"\r\n" "\n" "\"" "&#148;" "<" "&#060;" ">"
"&#062;" "'" "&#146;"} $ipslashowcmd]   
   
set header "<html>
<head>
<title>IP SLA Measurement Results Page</title>
<script>
function clear_field(field, value) {if(field.value == value) field.value = '';}
function init_field(field, value) {if(field.value == '') field.value = value;}
</script>
</head>
<body>
IP SLA Measurement Results Page<br><br>
We are monitoring : <br>
$ipaddr<br><br>
The Latest results:<br>
<textarea name='body' style='WIDTH: 710px; HEIGHT: 465px; color:#000000; font-
family: courier; font-size: 8pt'>$ipslaoutput</textarea>
</body>
</html>"

set middle ""
set footer ""
set httpheader "HTTP/1.1 200 OK

Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: binary
"

puts $httpsock $httpheader$header$middle$footer




No comments:

Post a Comment